Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of a central logger (#159) #278

Merged
merged 12 commits into from
Sep 28, 2023
18 changes: 9 additions & 9 deletions goatools/anno/annoreader_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import collections as cx
import logging

from goatools.evidence_codes import EvidenceCodes
from goatools.anno.opts import AnnoOptions
from goatools.godag.consts import NAMESPACE2NS
from goatools.gosubdag.go_tasks import get_go2parents_go2obj
from ..anno.opts import AnnoOptions
from ..base import logger
from ..evidence_codes import EvidenceCodes
from ..godag.consts import NAMESPACE2NS
from ..gosubdag.go_tasks import get_go2parents_go2obj

__copyright__ = (
"Copyright (C) 2016-present, DV Klopfenstein, H Tang. All rights reserved."
Expand Down Expand Up @@ -148,13 +149,12 @@ def _get_1ns_assn(self, namespace_usr):
if len(self.namespaces) == 1:
nspc = next(iter(self.namespaces))
if namespace_usr is not None and nspc != namespace_usr:
print(f"**WARNING: IGNORING {namespace_usr}; ONLY {nspc} WAS LOADED")
logger.warning("IGNORING %s; ONLY %s WAS LOADED", namespace_usr, nspc)
return nspc, self.associations
if namespace_usr is None:
print(
"**ERROR get_id2gos: GODAG NOT LOADED. USING: {NSs}".format(
NSs=" ".join(sorted(self.namespaces))
)
logger.error(
"get_id2gos: GODAG NOT LOADED. USING: %s",
" ".join(sorted(self.namespaces)),
)
return namespace_usr, self.associations

Expand Down
8 changes: 5 additions & 3 deletions goatools/anno/idtogos_reader.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Reads a Annotation File in text format with data in id2gos line"""

import sys
from goatools.anno.annoreader_base import AnnoReaderBase
from goatools.anno.init.reader_idtogos import InitAssc

from ..base import logger
from .annoreader_base import AnnoReaderBase
from .init.reader_idtogos import InitAssc

__copyright__ = "Copyright (C) 2016-2019, DV Klopfenstein, H Tang. All rights reserved."
__author__ = "DV Klopfenstein"
Expand Down Expand Up @@ -35,7 +37,7 @@ def wr_id2gos(fout_txt, id2gos):

def prt_summary_anno2ev(self, prt=sys.stdout):
"""Print a summary of all Evidence Codes seen in annotations"""
prt.write(f"**NOTE: No evidence codes in associations: {self.filename}\n")
logger.info("No evidence codes in associations: %s", self.filename)

# pylint: disable=unused-argument
def reduce_annotations(self, associations, options):
Expand Down
23 changes: 11 additions & 12 deletions goatools/anno/init/reader_idtogos.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Reads a Annotation File in text format with data in id2gos line"""

from sys import stdout
import timeit
import datetime
import collections as cx
from goatools.godag.consts import NAMESPACE2NS

from ...base import logger
from ...godag.consts import NAMESPACE2NS

__copyright__ = (
"Copyright (C) 2016-present, DV Klopfenstein, H Tang. All rights reserved."
Expand Down Expand Up @@ -39,7 +40,7 @@ def init_associations(self, namespaces):
if self.godag is None:
if namespaces is not None:
# pylint: disable=superfluous-parens
print(f"**WARNING: GODAG NOT LOADED. IGNORING namespaces={namespaces}")
logger.warning("GODAG NOT LOADED. IGNORING namespaces=%s", namespaces)
return nts
if namespaces == {"BP", "MF", "CC"}:
return nts
Expand All @@ -56,7 +57,7 @@ def _init_dflt(self):
nts.append(ntobj(DB_ID=itemid, GO_ID=goid))
return nts

def _init_w_godag(self, prt=stdout):
def _init_w_godag(self):
"""Get a list of namedtuples, one for each annotation."""
nts = []
ntobj = cx.namedtuple("ntanno", self.flds + ["NS"])
Expand All @@ -65,12 +66,12 @@ def _init_w_godag(self, prt=stdout):
to_add = set()
for goid in gos:
if goid not in s_godag:
prt.write(f"**WARNING: {goid} NOT FOUND IN DAG\n")
logger.warning("%s NOT FOUND IN DAG", goid)
continue
goobj = s_godag[goid]
if goobj.is_obsolete:
if self.obsolete == "keep":
prt.write(f"**WARNING: {goid} obsolete in DAG, kept\n")
logger.warning("%s obsolete in DAG, kept", goid)
to_add.add(goid)
elif self.obsolete == "replace":
to_replace = set()
Expand All @@ -79,16 +80,14 @@ def _init_w_godag(self, prt=stdout):
if "consider" in goobj.__dict__ and goobj.consider:
to_replace |= goobj.consider
if to_replace:
prt.write(
f"**WARNING: {goid} obsolete in DAG, replaced by {to_replace}\n"
logger.warning(
"%s obsolete in DAG, replaced by %s", goid, to_replace
)
else:
prt.write(
f"**WARNING: {goid} obsolete in DAG, no replacement\n"
)
logger.warning("%s obsolete in DAG, no replacement", goid)
to_add |= to_replace
elif self.obsolete == "skip":
prt.write(f"**WARNING: {goid} obsolete in DAG, skipped\n")
logger.warning("%s obsolete in DAG, skipped", goid)
else:
to_add.add(goid)
for goid in to_add:
Expand Down
Loading