annotate get_infos.py @ 8:06366f104f78 draft default tip

planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
author tduigou
date Fri, 29 Sep 2023 09:05:17 +0000
parents 33be348bf9d6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
1 from argparse import ArgumentParser
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
2 from libsbml import (
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
3 readSBMLFromFile
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
4 )
2
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
5 from requests import get as r_get
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
6
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
7
8
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
8 def get_biomass_rxn(sbml_doc):
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
9 '''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
10 Returns the biomass reaction of the model
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
11
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
12 Parameters
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
13 ----------
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
14 sbml_doc: libsbml.SBMLDocument
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
15 SBML model
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
16
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
17 Returns
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
18 -------
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
19 biomass_rxn: libsbml.Reaction
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
20 Biomass reaction
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
21 '''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
22 reactions = sbml_doc.getModel().getListOfReactions()
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
23 # Search for 'biomass' keyword in reaction name
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
24 for rxn in reactions:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
25 if 'biomass' in rxn.getName().lower():
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
26 return rxn
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
27 # Search for 'biomass' keyword in products
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
28 # AND not in reactants
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
29 for rxn in reactions:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
30 in_reactants = False
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
31 for reac in rxn.getListOfReactants():
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
32 if 'biomass' in reac.getSpecies().lower():
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
33 in_reactants = True
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
34 break
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
35 if not in_reactants:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
36 for prod in rxn.getListOfProducts():
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
37 if 'biomass' in prod.getSpecies().lower():
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
38 return rxn
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
39 return None
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
40
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
41
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
42 def get_taxon_id(hostid):
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
43 '''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
44 Returns the taxonomy ID of the host organism
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
45
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
46 Parameters
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
47 ----------
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
48 hostid: str
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
49 Extended name of the host organism
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
50
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
51 Returns
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
52 -------
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
53 taxid: str
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
54 Taxonomy ID of the host organism
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
55 '''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
56 taxid = get_taxon_id(hostid)
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
57 hostname = ''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
58 # Extended Name
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
59 server = 'http://bigg.ucsd.edu/api/v2/models/'
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
60 ext = hostid
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
61 r = r_get(server+ext, headers={ "Content-Type" : "application/json"})
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
62 if not r.ok:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
63 print(f"Warning: unable to retrieve host name for id {hostid}")
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
64 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
65 try:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
66 hostname = r.json()["organism"]
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
67 except KeyError:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
68 print(f"Warning: unable to retrieve host name for id {hostid}")
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
69 if not hostname:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
70 taxid = ''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
71 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
72 # TAXON ID
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
73 server = 'https://rest.ensembl.org'
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
74 ext = f'/taxonomy/id/{hostname}?'
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
75 r = r_get(server+ext, headers={ "Content-Type" : "application/json"})
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
76 if not r.ok:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
77 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
78 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
79 try:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
80 taxid = r.json()["id"]
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
81 except KeyError:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
82 print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
83 taxid = ''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
84 return taxid
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
85
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
86
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
87 def args():
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
88 parser = ArgumentParser('Returns cell informations')
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
89 parser.add_argument(
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
90 'infile',
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
91 type=str,
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
92 help='SBML input file (xml)'
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
93 )
7
33be348bf9d6 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 1a86e55d9e8c539de5fe8110ba85a2489473bde4
tduigou
parents: 4
diff changeset
94 # argument to tag file from BiGG
33be348bf9d6 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 1a86e55d9e8c539de5fe8110ba85a2489473bde4
tduigou
parents: 4
diff changeset
95 parser.add_argument(
33be348bf9d6 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 1a86e55d9e8c539de5fe8110ba85a2489473bde4
tduigou
parents: 4
diff changeset
96 '--bigg',
33be348bf9d6 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 1a86e55d9e8c539de5fe8110ba85a2489473bde4
tduigou
parents: 4
diff changeset
97 action='store_true',
33be348bf9d6 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 1a86e55d9e8c539de5fe8110ba85a2489473bde4
tduigou
parents: 4
diff changeset
98 help='Tag file from BiGG'
33be348bf9d6 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 1a86e55d9e8c539de5fe8110ba85a2489473bde4
tduigou
parents: 4
diff changeset
99 )
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
100 parser.add_argument(
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
101 '--comp',
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
102 type=str,
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
103 help='Path to store cell compartments'
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
104 )
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
105 parser.add_argument(
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
106 '--biomass',
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
107 type=str,
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
108 help='Path to store biomass reaction ID'
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
109 )
2
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
110 parser.add_argument(
8
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
111 '--biomass-id',
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
112 type=str,
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
113 help='ID of biomass reaction'
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
114 )
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
115 parser.add_argument(
2
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
116 '--hostid',
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
117 type=str,
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
118 help='Extended name of the host organism'
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
119 )
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
120 parser.add_argument(
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
121 '--taxid',
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
122 type=str,
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
123 help='Path to store host taxonomy ID'
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
124 )
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
125 params = parser.parse_args()
8
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
126 return params
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
127
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
128
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
129 def entry_point():
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
130
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
131 params = args()
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
132
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
133 sbml_doc = readSBMLFromFile(params.infile)
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
134
8
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
135 compartments = sbml_doc.getModel().getListOfCompartments()
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
136 comp_str = ''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
137 for comp in compartments:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
138 comp_str += f'{comp.getId()}\t{comp.getName()}\n'
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
139 if params.comp:
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
140 with open(params.comp, 'w') as f:
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
141 f.write('#ID\tNAME\n')
8
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
142 f.write(comp_str)
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
143 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
144 print('Compartments:')
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
145 for comp in compartments:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
146 print(f'{comp.getId()}\t{comp.getName()}'.replace('\n', ' | '))
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
147
8
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
148 if params.biomass_id:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
149 biomass_rxn = sbml_doc.getModel().getReaction(params.biomass_id)
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
150 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
151 biomass_rxn = get_biomass_rxn(sbml_doc)
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
152 if not biomass_rxn:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
153 print('Warning: unable to retrieve biomass reaction')
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
154 biomass_id = ''
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
155 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
156 biomass_id = biomass_rxn.getId()
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
157 if params.biomass:
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
158 with open(params.biomass, 'w') as f:
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
159 f.write('#ID\n')
8
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
160 f.write(f'{biomass_id}\n')
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
161 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
162 print(f'Biomass reaction ID: {biomass_id}')
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
163
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
164 # Model from BiGG
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
165 if params.bigg:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
166 taxid = get_taxon_id(params.hostid)
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
167 # Model from user
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
168 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
169 taxid = params.hostid
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
170
2
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
171 if params.taxid:
4
4c773948a490 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
172 with open(params.taxid, 'w') as f:
4c773948a490 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
173 f.write('#ID\n')
4c773948a490 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents: 2
diff changeset
174 f.write(f'{taxid}\n')
8
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
175 else:
06366f104f78 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents: 7
diff changeset
176 print(f'Taxonomy ID: {taxid}')
2
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
177
52649039cf3f planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit d1f5bac36c249e0767ed0bb968a1f4b5843256e3
tduigou
parents: 1
diff changeset
178
1
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
179 if __name__ == "__main__":
e276119e73c8 planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit eadd9bb9edbc70361b9e8d7900e6743b37142ee3
tduigou
parents:
diff changeset
180 entry_point()