Skip to content

Commit b84ea3d

Browse files
authored
Merge pull request #37 from COMBAT-TB/dev
Fixes for KEGG and Reactome.
2 parents 3024179 + efff776 commit b84ea3d

7 files changed

Lines changed: 69 additions & 39 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='tb2neo',
8-
version='0.0.8',
8+
version='0.0.9',
99
url='https://github.com/COMBAT-TB/tb2neo',
1010
description='Builds a M.tb annotation graph database from GFF files',
1111
long_description=long_description,

tb2neo/dbconn.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
import zipfile
88

9-
from bioservices import KEGG, ChEMBL, QuickGO, reactome
9+
from bioservices import KEGG, ChEMBL, QuickGO, ReactomeOld
1010
from pandas import read_csv
1111
from py2neo import Graph
1212
from tqdm import tqdm
@@ -28,7 +28,7 @@
2828
chembl = ChEMBL(verbose=False)
2929
quick_go = QuickGO(verbose=False)
3030
quick_go.url = 'http://www.ebi.ac.uk/QuickGO-Old'
31-
reactome_old = reactome.ReactomeOld(verbose=False)
31+
reactome_old = ReactomeOld(verbose=False)
3232
kegg = KEGG(verbose=False)
3333

3434
# watch("neo4j.bolt")
@@ -769,35 +769,63 @@ def create_kegg_pathways_nodes():
769769
:return:
770770
"""
771771
sys.stdout.write("Creating KEGG Pathways...")
772+
773+
def map_pathway_to_proteins(pathway_genes, path):
774+
for g_id in pathway_genes:
775+
g_id = "Rv" + \
776+
g_id.strip("RVBD_") if "RV" in g_id else g_id
777+
# Protein parent is stored as an array
778+
gene = Gene.select(graph, g_id).first()
779+
if gene:
780+
for protein in gene.encodes:
781+
protein.pathway.add(path)
782+
graph.push(protein)
783+
path.protein.add(protein)
784+
graph.push(path)
785+
772786
# TODO: Add mtc
773787
organisms = ['mtu']
774788
for organism in organisms:
775789
kegg.organism = organism
776790
pathway_ids = kegg.pathwayIds
777791
for path in tqdm(pathway_ids):
778792
data = kegg.parse(kegg.get(path))
793+
accession = path[path.find(organism):].strip()
779794
if isinstance(data, dict) is True:
780795
pathway = Pathway()
781-
pathway.accession = path[path.find(organism):].strip()
796+
pathway.accession = accession
782797
pathway._class = data.get('CLASS')
783798
pathway.name = data['PATHWAY_MAP'].get(path.strip("path:"))
784799
pathway.summation = data.get('DESCRIPTION')
785800
pathway.species = data.get('ORGANISM')
786801
graph.create(pathway)
787802
if data.get('GENE'):
788-
for g_id in data['GENE'].keys():
789-
g_id = "Rv" + \
790-
g_id.strip("RVBD_") if "RV" in g_id else g_id
791-
# Protein parent is stored as an array
792-
gene = Gene.select(graph, g_id).first()
793-
if gene:
794-
for protein in gene.encodes:
795-
protein.pathway.add(pathway)
796-
graph.push(protein)
797-
pathway.protein.add(protein)
798-
graph.push(pathway)
803+
map_pathway_to_proteins(data['GENE'].keys(), pathway)
799804
else:
800-
sys.stderr.write("Data is: {}\n".format(data))
805+
res_split = data.split("\n")
806+
807+
# accession = res_split[0].split()[1]
808+
name = res_split[1].split("-")[0].strip('NAME').strip()
809+
summation = res_split[2].strip("DESCRIPTION").strip()
810+
_class = res_split[3].strip("CLASS").strip()
811+
# Create Pathway
812+
pathway = Pathway()
813+
pathway.accession = accession
814+
pathway.name = name
815+
pathway.summation = summation
816+
pathway._class = _class
817+
graph.create(pathway)
818+
819+
gene_str_list = [
820+
s.split() for s in res_split if
821+
"Rv" in s and 'Myco' not in s
822+
]
823+
genes = {
824+
g for l in gene_str_list for g in l if
825+
str(g).isalnum() and 'Rv' in g
826+
}
827+
828+
map_pathway_to_proteins(genes, pathway)
801829
sys.stdout.write("\nCreated KEGG Pathway Nodes.")
802830

803831

tb2neo/stringstitch.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,14 @@ def fetch_string_data(gene, output_format='json', method='network',
4545
def load_string_data():
4646
df = read_csv(UNIPROT_DATA).fillna("")
4747
for entry in df.values:
48-
try:
49-
gene = eu_mapping(from_=entry[0], to='TUBERCULIST_ID')[0]
50-
except TypeError:
51-
print(f"A TypeError occurred for: {entry[0]}")
48+
rv_tag = eu_mapping(from_=entry[0], to='TUBERCULIST_ID')
49+
gene = rv_tag[0] if rv_tag else None
50+
data = fetch_string_data(gene=gene) if gene else None
51+
if data:
52+
for ppi in data:
53+
create_ppi(ppi["stringId_A"], ppi["stringId_B"], ppi["score"])
5254
else:
53-
data = fetch_string_data(gene=gene) if gene else None
54-
if data:
55-
for ppi in data:
56-
create_ppi(
57-
ppi["stringId_A"], ppi["stringId_B"], ppi["score"]
58-
)
55+
print(f"Nothing was found for {gene} with entry: {entry[0]}")
5956

6057

6158
def fetch_stitch_data():

tb2neo/uniprot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ def eu_mapping(from_, to):
120120
if len(_map) != 0:
121121
xref_id = _map[from_]
122122
else:
123-
raise ValueError("Can't map {} to {}".format(from_, to))
123+
print(f"Can't map {from_} to {to}!")
124124
return xref_id

test/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_load_kegg_pathways(cli_runner):
102102
assert result.exit_code == 0
103103

104104

105-
@pytest.mark.skip(reason="'NoneType' object is not subscriptable")
105+
# @pytest.mark.skip(reason="'NoneType' object is not subscriptable")
106106
def test_load_reactome_pathways(cli_runner):
107107
result = cli_runner.invoke(load_reactome_pathways)
108108
assert result.exit_code == 0

test/test_dbconn.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"""
44
import pytest
55

6-
from tb2neo.dbconn import graph, split_gene_names, create_chromosome_nodes, \
7-
create_publication_nodes
8-
from tb2neo.model.core import Gene, Chromosome
6+
from tb2neo.dbconn import (create_chromosome_nodes, create_publication_nodes,
7+
graph, split_gene_names)
8+
from tb2neo.model.core import Chromosome, Gene
99
from test_cli import UNIPROT_DATA
1010

1111

@@ -29,8 +29,8 @@ def test_db_nodes():
2929
def test_rv0001():
3030
gene = Gene.select(graph, "Rv0001").first()
3131
assert gene.name == "dnaA"
32-
assert gene.category is not ""
33-
assert gene.residues is not ""
32+
assert gene.category != ""
33+
assert gene.residues != ""
3434

3535

3636
@pytest.mark.parametrize("test_input,expected", [
@@ -58,3 +58,13 @@ def test_split_gene_name(test_input, expected):
5858
def test_create_publication_nodes():
5959
res = create_publication_nodes(uniprot_data=UNIPROT_DATA)
6060
assert isinstance(res, set)
61+
62+
63+
# @pytest.mark.skip(reason="")
64+
def test_ppi_score():
65+
cypher_q = f"MATCH (pa:Protein {{ uniquename: 'P9WQD9' }})"
66+
cypher_q += f"-[r:INTERACTS_WITH]->"
67+
cypher_q += f"(pb:Protein {{ uniquename: 'P9WIE5' }}) "
68+
cypher_q += f"RETURN r.score"
69+
data = graph.run(cypher_q).data()[0]
70+
assert data['r.score'] == 0.881

test/test_uniprot.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from tb2neo.gffproc import get_locus_tags
6-
from tb2neo.uniprot import query_uniprot, eu_mapping
6+
from tb2neo.uniprot import eu_mapping, query_uniprot
77
from test_cli import TEST_GFF
88

99

@@ -21,8 +21,3 @@ def test_search_uniprot():
2121
])
2222
def test_eu_mapping(test_input, expected):
2323
assert isinstance(test_input, expected) is True
24-
25-
26-
def test_eu_mapping_error():
27-
with pytest.raises(ValueError):
28-
eu_mapping(None, to="PDB_ID")

0 commit comments

Comments
 (0)