Mercurial > repos > tduigou > get_sbml_model
annotate get_infos.py @ 8:768ed7cc0978 draft
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
author | tduigou |
---|---|
date | Fri, 29 Sep 2023 09:03:09 +0000 |
parents | 8dc4d3964ab5 |
children | 6a2871e89352 |
rev | line source |
---|---|
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
1 from argparse import ArgumentParser |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
2 from libsbml import ( |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
3 readSBMLFromFile |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
4 ) |
2
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
5 from requests import get as r_get |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
6 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
7 |
8
768ed7cc0978
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): |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
9 ''' |
768ed7cc0978
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 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
11 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
12 Parameters |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
13 ---------- |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
14 sbml_doc: libsbml.SBMLDocument |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
15 SBML model |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
16 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
17 Returns |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
18 ------- |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
19 biomass_rxn: libsbml.Reaction |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
20 Biomass reaction |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
21 ''' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
22 reactions = sbml_doc.getModel().getListOfReactions() |
768ed7cc0978
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 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
24 for rxn in reactions: |
768ed7cc0978
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(): |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
26 return rxn |
768ed7cc0978
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 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
28 # AND not in reactants |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
29 for rxn in reactions: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
30 in_reactants = False |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
31 for reac in rxn.getListOfReactants(): |
768ed7cc0978
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(): |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
33 in_reactants = True |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
34 break |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
35 if not in_reactants: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
36 for prod in rxn.getListOfProducts(): |
768ed7cc0978
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(): |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
38 return rxn |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
39 return None |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
40 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
41 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
42 def get_taxon_id(hostid): |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
43 ''' |
768ed7cc0978
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 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
45 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
46 Parameters |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
47 ---------- |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
48 hostid: str |
768ed7cc0978
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 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
50 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
51 Returns |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
52 ------- |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
53 taxid: str |
768ed7cc0978
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 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
55 ''' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
56 taxid = get_taxon_id(hostid) |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
57 hostname = '' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
58 # Extended Name |
768ed7cc0978
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/' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
60 ext = hostid |
768ed7cc0978
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"}) |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
62 if not r.ok: |
768ed7cc0978
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}") |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
64 else: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
65 try: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
66 hostname = r.json()["organism"] |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
67 except KeyError: |
768ed7cc0978
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}") |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
69 if not hostname: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
70 taxid = '' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
71 else: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
72 # TAXON ID |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
73 server = 'https://rest.ensembl.org' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
74 ext = f'/taxonomy/id/{hostname}?' |
768ed7cc0978
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"}) |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
76 if not r.ok: |
768ed7cc0978
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}") |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
78 else: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
79 try: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
80 taxid = r.json()["id"] |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
81 except KeyError: |
768ed7cc0978
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}") |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
83 taxid = '' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
84 return taxid |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
85 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
86 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
87 def args(): |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
88 parser = ArgumentParser('Returns cell informations') |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
89 parser.add_argument( |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
90 'infile', |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
91 type=str, |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
92 help='SBML input file (xml)' |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
93 ) |
7
8dc4d3964ab5
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents:
4
diff
changeset
|
94 # argument to tag file from BiGG |
8dc4d3964ab5
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents:
4
diff
changeset
|
95 parser.add_argument( |
8dc4d3964ab5
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents:
4
diff
changeset
|
96 '--bigg', |
8dc4d3964ab5
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents:
4
diff
changeset
|
97 action='store_true', |
8dc4d3964ab5
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents:
4
diff
changeset
|
98 help='Tag file from BiGG' |
8dc4d3964ab5
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 09fcdb371be214b222a2e1c540d7c6e7489ca258
tduigou
parents:
4
diff
changeset
|
99 ) |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
100 parser.add_argument( |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
101 '--comp', |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
102 type=str, |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
103 help='Path to store cell compartments' |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
104 ) |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
105 parser.add_argument( |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
106 '--biomass', |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
107 type=str, |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
108 help='Path to store biomass reaction ID' |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
109 ) |
2
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
110 parser.add_argument( |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
111 '--biomass-id', |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
112 type=str, |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
113 help='ID of biomass reaction' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
114 ) |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
115 parser.add_argument( |
2
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
116 '--hostid', |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
117 type=str, |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
118 help='Extended name of the host organism' |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
119 ) |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
120 parser.add_argument( |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
121 '--taxid', |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
122 type=str, |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
123 help='Path to store host taxonomy ID' |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
124 ) |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
125 params = parser.parse_args() |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
126 return params |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
127 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
128 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
129 def entry_point(): |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
130 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
131 params = args() |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
132 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
133 sbml_doc = readSBMLFromFile(params.infile) |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
134 |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
135 compartments = sbml_doc.getModel().getListOfCompartments() |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
136 comp_str = '' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
137 for comp in compartments: |
768ed7cc0978
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
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
139 if params.comp: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
140 with open(params.comp, 'w') as f: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
141 f.write('#ID\tNAME\n') |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
142 f.write(comp_str) |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
143 else: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
144 print('Compartments:') |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
145 for comp in compartments: |
768ed7cc0978
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
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
147 |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
148 if params.biomass_id: |
768ed7cc0978
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) |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
150 else: |
768ed7cc0978
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) |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
152 if not biomass_rxn: |
768ed7cc0978
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') |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
154 biomass_id = '' |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
155 else: |
768ed7cc0978
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
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
157 if params.biomass: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
158 with open(params.biomass, 'w') as f: |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
159 f.write('#ID\n') |
8
768ed7cc0978
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') |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
161 else: |
768ed7cc0978
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}') |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
163 |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
164 # Model from BiGG |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
165 if params.bigg: |
768ed7cc0978
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) |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
167 # Model from user |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
168 else: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
169 taxid = params.hostid |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
170 |
2
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
171 if params.taxid: |
4
1482291aaa5c
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: |
1482291aaa5c
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 4a0b08beb8cdf51ab295a1f5f8c586d6bbaf5586
tduigou
parents:
2
diff
changeset
|
173 f.write('#ID\n') |
1482291aaa5c
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
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
175 else: |
768ed7cc0978
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
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
177 |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
178 |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
179 if __name__ == "__main__": |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
180 entry_point() |