Skip to content

Commit

Permalink
Add comments and debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ddomingof committed Oct 4, 2018
1 parent 2588c8f commit 6bb5ab1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/pathme/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import click
from bio2bel_chebi import Manager as ChebiManager
from bio2bel_hgnc import Manager as HgncManager
from pybel import from_pickle
from tqdm import tqdm

from pathme.constants import *
Expand All @@ -20,6 +19,7 @@
from pathme.utils import 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

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -127,12 +127,13 @@ def download():

@wikipathways.command()
@click.option('-c', '--connection', help="Defaults to {}".format(DEFAULT_CACHE_CONNECTION))
@click.option('-v', '--verbose', is_flag=True)
@click.option('-d', '--debug', is_flag=True, default=False, help='Debug mode')
@click.option('-x', '--only-canonical', default=True, help='Parse only canonical pathways')
def to_bel(connection, verbose, only_canonical):
def to_bel(connection, debug, only_canonical):
"""Convert WikiPathways to BEL."""
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(name)s - %(message)s")
if verbose:

if debug:
log.setLevel(logging.DEBUG)

log.info('Initiating HGNC Manager')
Expand Down
8 changes: 6 additions & 2 deletions src/pathme/wikipathways/convert_to_bel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def convert_to_bel(nodes: Dict[str, Dict], complexes: Dict[str, Dict], interacti
contact='daniel.domingo.fernandez@scai.fraunhofer.de',
)

log.warning('Parsing %s', pathway_info['title'])

nodes = nodes_to_bel(nodes, hgnc_manager)
nodes.update(complexes_to_bel(complexes, nodes, graph))

Expand Down Expand Up @@ -62,7 +64,7 @@ def node_to_bel(node: Dict, hgnc_manager: Manager) -> BaseEntity:
identifier = uri_id

if isinstance(identifier, set):
print('Multiple identifier {}'.format(node['identifier']))
log.warning('Multiple identifier {}'.format(node['identifier']))
# TODO: print the wikipathways bps that return a set because they are probably wrong.
identifier = list(identifier)[0]

Expand All @@ -76,7 +78,7 @@ def node_to_bel(node: Dict, hgnc_manager: Manager) -> BaseEntity:

# TODO: Deal with multiple names. Print for now to identify possible errors
if isinstance(name, set):
print('Multiple name {}'.format(node['name']))
log.warning('Multiple name {}'.format(node['name']))
name = list(name)[0]

if 'Protein' in node_types:
Expand Down Expand Up @@ -140,6 +142,7 @@ def add_edges(graph: BELGraph, participants, nodes, att: Dict):
edge_types = att['interaction_types']
_, _, namespace, interaction_id = parse_id_uri(uri_id)

# Add reaction if the edge type is a Conversion
if 'Conversion' in edge_types:
reactants = set()
products = set()
Expand All @@ -161,6 +164,7 @@ def add_edges(graph: BELGraph, participants, nodes, att: Dict):
reaction_node = reaction(reactants=reactants, products=products)
graph.add_node_from_data(reaction_node)

# Else it is a simple edge, process it
else:
for source, target in participants:
if source in nodes:
Expand Down
2 changes: 1 addition & 1 deletion src/pathme/wikipathways/rdf_sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def get_wp_statistics(resource_files, resource_folder, hgnc_manager) -> Tuple[


def rdf_wikipathways_to_bel(rdf_graph, hgnc_manager) -> BELGraph:
"""Convert RDF graph to BELGraph
"""Convert RDF graph to BELGraph.
:param rdf_graph: RDF graph
:param bio2bel_hgnc.Manager: HGNC manager
Expand Down

0 comments on commit 6bb5ab1

Please sign in to comment.