Skip to content

Commit

Permalink
Add namespace and metadata information
Browse files Browse the repository at this point in the history
  • Loading branch information
ddomingof committed Jul 1, 2019
1 parent bace30d commit 522d212
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/pathme/kegg/convert_to_bel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get_all_reactions, get_all_relationships, get_complex_components, get_entity_nodes, get_reaction_pathway_edges,
import_xml_etree,
)
from pathme.utils import add_bel_metadata

__all__ = [
'kegg_to_bel',
Expand Down Expand Up @@ -49,6 +50,8 @@ def kegg_to_bel(path, hgnc_manager, chebi_manager, flatten=False):
contact='daniel.domingo.fernandez@scai.fraunhofer.de'
)

add_bel_metadata(graph)

graph.graph['pathway_id'] = root.attrib['name']

# Parse file and get entities and interactions
Expand Down
4 changes: 3 additions & 1 deletion src/pathme/reactome/convert_to_bel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from pathme.constants import UNKNOWN, REACTOME_CITATION
from pathme.reactome.utils import get_valid_node_parameters, process_multiple_proteins
from pathme.utils import parse_id_uri
from pathme.utils import add_bel_metadata, parse_id_uri

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -56,6 +56,8 @@ def convert_to_bel(nodes: Dict[str, Dict], interactions: List[Tuple[str, str, Di
contact='daniel.domingo.fernandez@scai.fraunhofer.de',
)

add_bel_metadata(graph)

graph.graph['pathway_id'] = identifier

nodes = nodes_to_bel(nodes, graph, hgnc_manager, chebi_manager)
Expand Down
32 changes: 30 additions & 2 deletions src/pathme/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import collections
import itertools as itt
import logging
import os
import pickle
from typing import Dict, Iterable, List, Optional, Set, Tuple
from urllib.parse import urlparse
Expand All @@ -16,9 +15,10 @@
import pybel
import rdflib
from pybel import BELGraph, from_pickle
from pybel.constants import GRAPH_NAMESPACE_URL
from pybel.struct.summary import count_functions, count_relations

from pathme.constants import BEL_STATS_COLUMN_NAMES, UNKNOWN
from pathme.constants import *
from pathme.export_utils import get_paths_in_folder

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -515,3 +515,31 @@ def summarize_helper(graphs: Iterable[BELGraph]):
summary_str = graph.summary_str()

click.echo(summary_str)


def add_bel_metadata(graph: BELGraph) -> None:
"""Add namespaces and annotations to a given bel graph."""
graph.graph[GRAPH_NAMESPACE_URL] = {
CHEBI.upper(): "https://raw.githubusercontent.com/pharmacome/terminology/b46b65c3da259b6e86026514dfececab7c22a11b/external/chebi-names.belns",
HGNC: "https://raw.githubusercontent.com/pharmacome/terminology/b46b65c3da259b6e86026514dfececab7c22a11b/external/hgnc-names.belns",
"GO": "https://raw.githubusercontent.com/pharmacome/terminology/b46b65c3da259b6e86026514dfececab7c22a11b/external/go-names.belns",
}

graph.namespace_pattern["NCBIGENE"] = "^\d+$"
graph.namespace_pattern[UNIPROT.upper()] = \
"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\.\d+)?$"
graph.namespace_pattern[PUBCHEM.upper()] = ".*"
graph.namespace_pattern[EXPASY] = ".*"
graph.namespace_pattern[ENTREZ] = ".*"
graph.namespace_pattern[ENSEMBL] = ".*"
graph.namespace_pattern[WIKIPEDIA] = ".*"
graph.namespace_pattern[MIRBASE.upper()] = ".*"
graph.namespace_pattern[INTERPRO.upper()] = ".*"
graph.namespace_pattern[PFAM.upper()] = ".*"
graph.namespace_pattern[BRENDA.upper()] = ".*"

graph.namespace_pattern[KEGG.upper()] = ".*"
graph.namespace_pattern[REACTOME.upper()] = ".*"
graph.namespace_pattern[WIKIPATHWAYS.upper()] = ".*"

graph.annotation_list['database'] = {KEGG, REACTOME, WIKIPATHWAYS}
4 changes: 3 additions & 1 deletion src/pathme/wikipathways/convert_to_bel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .utils import check_multiple, evaluate_wikipathways_metadata, get_valid_gene_identifier
from ..constants import HGNC
from ..utils import parse_id_uri
from ..utils import add_bel_metadata, parse_id_uri

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -48,6 +48,8 @@ def convert_to_bel(
contact='daniel.domingo.fernandez@scai.fraunhofer.de',
)

add_bel_metadata(graph)

pathway_id = graph.graph['pathway_id'] = pathway_info['pathway_id']

nodes = {
Expand Down

0 comments on commit 522d212

Please sign in to comment.