Skip to content

Commit

Permalink
Add total warning count
Browse files Browse the repository at this point in the history
  • Loading branch information
ddomingof committed Oct 7, 2018
1 parent 2b34504 commit bd108ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pathme/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pathme.kegg.utils import download_kgml_files, get_kegg_pathway_ids
from pathme.reactome.rdf_sparql import get_reactome_statistics, reactome_to_bel
from pathme.reactome.utils import untar_file
from pathme.utils import get_files_in_folder, make_downloader, statistics_to_df, summarize_helper
from pathme.utils import CallCounted, get_files_in_folder, make_downloader, statistics_to_df, summarize_helper
from pathme.wikipathways.rdf_sparql import get_wp_statistics, wikipathways_to_pickles
from pathme.wikipathways.utils import get_file_name_from_url, get_wikipathways_files, unzip_file
from pybel import from_pickle
Expand Down Expand Up @@ -136,6 +136,8 @@ def to_bel(connection, debug, only_canonical):
if debug:
log.setLevel(logging.DEBUG)

logging.warning = CallCounted(logging.warning)

log.info('Initiating HGNC Manager')
hgnc_manager = HgncManager()

Expand All @@ -148,7 +150,11 @@ def to_bel(connection, debug, only_canonical):

wikipathways_to_pickles(resource_files, resource_folder, hgnc_manager)

log.info('WikiPathways exported in %.2f seconds', time.time() - t)
log.info(
'WikiPathways exported in %.2f seconds. A total of {} warnings regarding entities that could not be converted '
'to standard identifiers were found.',
time.time() - t, logging.warning.counter
)


@wikipathways.command()
Expand Down
12 changes: 12 additions & 0 deletions src/pathme/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
log = logging.getLogger(__name__)


class CallCounted:
"""Decorator to determine number of calls for a method."""

def __init__(self, method):
self.method = method
self.counter = 0

def __call__(self, *args, **kwargs):
self.counter += 1
return self.method(*args, **kwargs)


def get_files_in_folder(path: str) -> List[str]:
"""Return the files in a given folder.
Expand Down

0 comments on commit bd108ed

Please sign in to comment.