|
6 | 6 | import sys |
7 | 7 | import zipfile |
8 | 8 |
|
9 | | -from bioservices import KEGG, ChEMBL, QuickGO, reactome |
| 9 | +from bioservices import KEGG, ChEMBL, QuickGO, ReactomeOld |
10 | 10 | from pandas import read_csv |
11 | 11 | from py2neo import Graph |
12 | 12 | from tqdm import tqdm |
|
28 | 28 | chembl = ChEMBL(verbose=False) |
29 | 29 | quick_go = QuickGO(verbose=False) |
30 | 30 | quick_go.url = 'http://www.ebi.ac.uk/QuickGO-Old' |
31 | | -reactome_old = reactome.ReactomeOld(verbose=False) |
| 31 | +reactome_old = ReactomeOld(verbose=False) |
32 | 32 | kegg = KEGG(verbose=False) |
33 | 33 |
|
34 | 34 | # watch("neo4j.bolt") |
@@ -769,35 +769,63 @@ def create_kegg_pathways_nodes(): |
769 | 769 | :return: |
770 | 770 | """ |
771 | 771 | 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 | + |
772 | 786 | # TODO: Add mtc |
773 | 787 | organisms = ['mtu'] |
774 | 788 | for organism in organisms: |
775 | 789 | kegg.organism = organism |
776 | 790 | pathway_ids = kegg.pathwayIds |
777 | 791 | for path in tqdm(pathway_ids): |
778 | 792 | data = kegg.parse(kegg.get(path)) |
| 793 | + accession = path[path.find(organism):].strip() |
779 | 794 | if isinstance(data, dict) is True: |
780 | 795 | pathway = Pathway() |
781 | | - pathway.accession = path[path.find(organism):].strip() |
| 796 | + pathway.accession = accession |
782 | 797 | pathway._class = data.get('CLASS') |
783 | 798 | pathway.name = data['PATHWAY_MAP'].get(path.strip("path:")) |
784 | 799 | pathway.summation = data.get('DESCRIPTION') |
785 | 800 | pathway.species = data.get('ORGANISM') |
786 | 801 | graph.create(pathway) |
787 | 802 | 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) |
799 | 804 | 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) |
801 | 829 | sys.stdout.write("\nCreated KEGG Pathway Nodes.") |
802 | 830 |
|
803 | 831 |
|
|
0 commit comments