Skip to content

Commit

Permalink
Bug fixes in KEGG particular case composites
Browse files Browse the repository at this point in the history
  • Loading branch information
ddomingof committed Jul 8, 2019
1 parent 2fabe7a commit bb994da
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 41 deletions.
16 changes: 11 additions & 5 deletions src/pathme/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import networkx as nx
from bio2bel_chebi import Manager as ChebiManager
from bio2bel_hgnc import Manager as HgncManager
from pybel import from_pickle, to_pickle
from pybel.struct.mutation import collapse_all_variants, collapse_to_genes, remove_isolated_list_abundances
from pybel.struct.summary import count_functions
from tqdm import tqdm

from pathme.constants import *
from pathme.export_utils import spia_export_helper, get_paths_in_folder, get_universe_graph
from pathme.kegg.convert_to_bel import kegg_to_pickles
Expand All @@ -18,10 +23,6 @@
from pathme.utils import CallCounted, 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, iterate_wikipathways_paths, unzip_file
from pybel import from_pickle, to_pickle
from pybel.struct.mutation import collapse_all_variants, collapse_to_genes, remove_isolated_list_abundances
from pybel.struct.summary import count_functions
from tqdm import tqdm

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -59,11 +60,16 @@ def download(connection):
@kegg.command()
@click.option('-f', '--flatten', is_flag=True, default=False)
@click.option('-e', '--export-folder', default=KEGG_BEL, show_default=True)
def bel(flatten, export_folder):
@click.option('-v', '--debug', is_flag=True, default=False, help='Debug mode')
def bel(flatten, export_folder, debug):
"""Convert KEGG to BEL."""
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(name)s - %(message)s")
logger.setLevel(logging.INFO)

if debug:
click.echo("Debug mode on")
logger.setLevel(logging.DEBUG)

t = time.time()

logger.info('Initiating HGNC Manager')
Expand Down
99 changes: 63 additions & 36 deletions src/pathme/kegg/convert_to_bel.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ def map_to_bel_node(graph, node):
name = attribute['map_name']
identifier = attribute[KEGG_ID]

if not name:
log.debug(f"KEGG API does not provide information about {node}. Using identifier.")
name = identifier

if name.startswith('TITLE:'):
name = name.strip('TITLE:')

Expand Down Expand Up @@ -514,43 +518,60 @@ def add_simple_edge(graph, u, v, relation_type):

# If the object is a gene, miRNA, RNA, or protein, add protein modification
if isinstance(v, CentralDogma):
v_modified = v.with_variants(pmod(KEGG_MODIFICATIONS[relation_type[1]]))

# Add increases edge if pmod subtype is coupled with activation subtype
if relation_type[0] == 'activation':
graph.add_increases(
u, v_modified,
citation=KEGG_CITATION, evidence='Extracted from KEGG',
subject_modifier=activity() if isinstance(u, ACTIVITY_ALLOWED_MODIFIERS) else None,
# Add the activity function if subject is one of the following nodes (BEL 2.0 specifications)
annotations={},
)

# Add decreases edge if pmod subtype is coupled with inhibition subtype
elif relation_type[0] == 'inhibition':
graph.add_decreases(
u, v_modified,
citation=KEGG_CITATION, evidence='Extracted from KEGG',
subject_modifier=activity() if isinstance(u, ACTIVITY_ALLOWED_MODIFIERS) else None,
# Add the activity function if subject is one of the following nodes (BEL 2.0 specifications)
annotations={},
)

# TODO: add pmod of v activates v
# TODO: how to represent abundance modification in BEL?
v = v.with_variants(pmod(KEGG_MODIFICATIONS[relation_type[1]]))

# Add increases edge if pmod subtype is coupled with activation subtype
if relation_type[0] == 'activation':
graph.add_increases(
u, v,
citation=KEGG_CITATION, evidence='Extracted from KEGG',
subject_modifier=activity() if isinstance(u, ACTIVITY_ALLOWED_MODIFIERS) else None,
# Add the activity function if subject is one of the following nodes (BEL 2.0 specifications)
annotations={},
)
return

# Add decreases edge if pmod subtype is coupled with inhibition subtype
elif relation_type[0] == 'inhibition':
graph.add_decreases(
u, v,
citation=KEGG_CITATION, evidence='Extracted from KEGG',
subject_modifier=activity() if isinstance(u, ACTIVITY_ALLOWED_MODIFIERS) else None,
# Add the activity function if subject is one of the following nodes (BEL 2.0 specifications)
annotations={},
)
return

# Found multiple relationship which cannot be combined into one logic (e.g., ['inhibition', 'indirect effect'])
else:
# Create all relationships in the list
for relation in relation_type:
add_simple_edge(graph, u, v, relation)

return

# Found multiple relationship which cannot be combined into one logic (e.g., ['inhibition', 'indirect effect'])
else:
# Create all relationships in the list
for relation in relation_type:
add_simple_edge(graph, u, v, relation)

return

"""Handle differently the relationships"""
# If only one pmod relation subtype
elif relation_type in {'phosphorylation', 'glycosylation', 'ubiquitination', 'methylation'}:
if relation_type in {'phosphorylation', 'glycosylation', 'ubiquitination', 'methylation'}:

# If the object is a gene, miRNA, RNA, or protein, add protein modification
if isinstance(v, CentralDogma):
v_modified = v.with_variants(pmod(KEGG_MODIFICATIONS[relation_type]))
graph.add_increases(
u, v_modified,
citation=KEGG_CITATION, evidence='Extracted from KEGG',
subject_modifier=activity() if isinstance(u, ACTIVITY_ALLOWED_MODIFIERS) else None,
annotations={},
)
v = v.with_variants(pmod(KEGG_MODIFICATIONS[relation_type]))
graph.add_increases(
u, v,
citation=KEGG_CITATION, evidence='Extracted from KEGG',
subject_modifier=activity() if isinstance(u, ACTIVITY_ALLOWED_MODIFIERS) else None,
annotations={},
)
return

# Subject activity decreases protein modification (i.e. dephosphorylation) of object
elif relation_type == 'dephosphorylation':
Expand All @@ -564,6 +585,7 @@ def add_simple_edge(graph, u, v, relation_type):
subject_modifier=activity() if isinstance(u, ACTIVITY_ALLOWED_MODIFIERS) else None,
annotations={},
)
return

# Subject increases activity of object
elif relation_type == 'activation':
Expand All @@ -573,6 +595,7 @@ def add_simple_edge(graph, u, v, relation_type):
object_modifier=activity() if isinstance(v, ACTIVITY_ALLOWED_MODIFIERS) else None,
annotations={},
)
return

# Catalytic activity of subject increases transformation of reactant(s) to product(s)
elif relation_type in {'reversible', 'irreversible'}:
Expand All @@ -582,6 +605,7 @@ def add_simple_edge(graph, u, v, relation_type):
subject_modifier=activity('cat') if isinstance(u, ACTIVITY_ALLOWED_MODIFIERS) else None,
annotations={},
)
return

# Subject decreases activity of object
elif relation_type == 'inhibition':
Expand All @@ -591,10 +615,12 @@ def add_simple_edge(graph, u, v, relation_type):
object_modifier=activity() if isinstance(v, ACTIVITY_ALLOWED_MODIFIERS) else None,
annotations={},
)
return

# Indirect effect and binding/association are noted to be equivalent relation types
elif relation_type in {'indirect effect', 'binding/association'}:
elif relation_type in {'indirect effect', 'binding/association', 'compound'}:
graph.add_association(u, v, citation=KEGG_CITATION, evidence='Extracted from KEGG', annotations={})
return

# Subject increases expression of object
elif relation_type == 'expression':
Expand All @@ -603,6 +629,7 @@ def add_simple_edge(graph, u, v, relation_type):
if isinstance(v, CentralDogma):
v = v.get_rna()
graph.add_increases(u, v, citation=KEGG_CITATION, evidence='Extracted from KEGG', annotations={})
return

# Subject decreases expression of object
elif relation_type == 'repression':
Expand All @@ -611,12 +638,12 @@ def add_simple_edge(graph, u, v, relation_type):
if isinstance(v, CentralDogma):
v = v.get_rna()
graph.add_decreases(u, v, citation=KEGG_CITATION, evidence='Extracted from KEGG', annotations={})
return

elif relation_type in {'dissociation', 'hidden compound', 'missing interaction', 'state change'}:
pass
return

else:
raise ValueError('Unexpected relation type {}'.format(relation_type))
raise ValueError(f'Unexpected relation type {relation_type} between {u} and {v}')


def get_bel_types(path, hgnc_manager, chebi_manager, flatten=None):
Expand Down

0 comments on commit bb994da

Please sign in to comment.