Mercurial > repos > pablocarb > synbiodesign
comparison rpviz/sbml2lists.py @ 16:fe78fd6b315a draft
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
author | pablocarb |
---|---|
date | Tue, 11 Jun 2019 11:42:40 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:785b6253af1f | 16:fe78fd6b315a |
---|---|
1 #!/usr/bin/env python | |
2 # coding: utf-8 | |
3 '''To visualize a SBML file''' | |
4 # In[3]: | |
5 | |
6 | |
7 import libsbml | |
8 import os | |
9 from .smile2picture import picture | |
10 #import networkx as nx | |
11 #import matplotlib.pyplot as plt | |
12 | |
13 | |
14 | |
15 # In[4]: | |
16 def sbml2list(file): | |
17 | |
18 #open the SBML using libsbml | |
19 | |
20 doc = libsbml.readSBML(file) | |
21 name=os.path.basename(file) | |
22 | |
23 | |
24 # In[8]: | |
25 | |
26 | |
27 #return the model from the SBML document using libsbml | |
28 model = doc.model | |
29 | |
30 | |
31 # In[9]: | |
32 | |
33 | |
34 #we will use the groups package to return the retropath pathway | |
35 #that is all the reactions that are associated with the heterologous | |
36 #pathway | |
37 groups = model.getPlugin('groups') | |
38 | |
39 | |
40 # In[10]: | |
41 | |
42 | |
43 #in the rpFBA script, rp_pathway is the default name | |
44 rp_pathway = groups.getGroup('rp_pathway') | |
45 | |
46 | |
47 # In[63]: | |
48 | |
49 rlist=[] | |
50 LR=[] | |
51 | |
52 heterologous_pathway_dG_prime_o = {} | |
53 | |
54 | |
55 #loop through all the members of the rp_pathway | |
56 for member in rp_pathway.getListOfMembers(): | |
57 #fetch the reaction according to the member id | |
58 reaction = model.getReaction(member.getIdRef()) | |
59 rlist.append(reaction) | |
60 LR.append(str(reaction)) | |
61 #get the annotation of the reaction | |
62 #includes the MIRIAM annotation and the IBISBA ones | |
63 annotation = reaction.getAnnotation() | |
64 ibisba_annotation = annotation.getChild('RDF').getChild('Ibisba').getChild('ibisba') | |
65 #extract one of the ibisba annotation values | |
66 heterologous_pathway_dG_prime_o[member.getIdRef()] = ibisba_annotation.getChild('dG_prime_o').getAttrValue('value') | |
67 | |
68 | |
69 | |
70 # In[64]: | |
71 | |
72 heterologous_pathway_dG_prime_o | |
73 | |
74 Lreact=[] | |
75 Lprod=[] | |
76 | |
77 for reaction in range(len(rlist)): | |
78 Lreact.append([p.species for p in rlist[reaction].reactants]) #get list of reactants id | |
79 Lprod.append([p.species for p in rlist[reaction].products]) #get list of products id | |
80 | |
81 mem = [] | |
82 for member in rp_pathway.getListOfMembers(): | |
83 reac = model.getReaction(member.getIdRef()) | |
84 for pro in reac.getListOfProducts(): | |
85 mem.append(pro.getSpecies()) | |
86 Lprod.append(pro.getSpecies()) | |
87 for rea in reac.getListOfReactants(): | |
88 mem.append(rea.getSpecies()) | |
89 Lreact.append(rea.getSpecies()) | |
90 | |
91 #mem = list(set([i for i in mem if i[0:3]!='MNX'])) | |
92 species_smiles = {} | |
93 species_links={} | |
94 species_names={} | |
95 #loop through all the members of the rp_pathway | |
96 for member in list(set([i for i in mem])): | |
97 #fetch the species according to the member id | |
98 reaction = model.getSpecies(member) | |
99 spname=reaction.getName() | |
100 if spname: | |
101 species_names[member]=spname | |
102 #get the annotation of the species | |
103 #includes the MIRIAM annotation and the IBISBA ones | |
104 annotation = reaction.getAnnotation() | |
105 ibisba_annotation = annotation.getChild('RDF').getChild('Ibisba').getChild('ibisba') | |
106 #extract one of the ibisba annotation values | |
107 smiles = ibisba_annotation.getChild('smiles').getChild(0).toXMLString() | |
108 if smiles: | |
109 species_smiles[member] = smiles | |
110 link_annotation=annotation.getChild('RDF').getChild('Description').getChild('is').getChild('Bag') | |
111 for i in range(link_annotation.getNumChildren()): | |
112 str_annot = link_annotation.getChild(i).getAttrValue(0) #Here we get the attribute at location "0". It works since there is only one | |
113 if str_annot.split('/')[-2]=='metanetx.chemical': | |
114 species_links[member]=str_annot #here is the MNX code returned | |
115 | |
116 | |
117 # In[64]: | |
118 | |
119 image=picture(species_smiles) | |
120 | |
121 return(LR, Lreact, Lprod, name, species_smiles,image, species_names, species_links) | |
122 | |
123 | |
124 | |
125 | |
126 #Cytoscape Network | |
127 #from nxvisualizer import network | |
128 #network(LR,Lreact,Lprod,name,species_smiles,image) | |
129 | |
130 #Convert network to json file | |
131 #from network2json import network2 #to convert the lists in a json network | |
132 #network2(LR,Lreact,Lprod,name,species_smiles,image,species_names,species_links) |