Mercurial > repos > tduigou > get_sbml_model
annotate get_infos.py @ 11:062f51695ae0 draft
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
author | tduigou |
---|---|
date | Tue, 01 Apr 2025 09:59:21 +0000 |
parents | dc1167469d62 |
children | 1aadcfdae10b |
rev | line source |
---|---|
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
1 from argparse import ArgumentParser |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
2 from libsbml import readSBMLFromFile |
9
6a2871e89352
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents:
8
diff
changeset
|
3 from taxonid import get_taxonid |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
4 from requests import get as r_get |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
5 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
6 |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
7 def get_biomass_rxn(sbml_doc): |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
8 """ |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
9 Returns the biomass reaction of the model |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
10 |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
11 Parameters |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
12 ---------- |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
13 sbml_doc: libsbml.SBMLDocument |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
14 SBML model |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
15 |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
16 Returns |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
17 ------- |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
18 biomass_rxn: libsbml.Reaction |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
19 Biomass reaction |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
20 """ |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
21 reactions = sbml_doc.getModel().getListOfReactions() |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
22 # 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
|
23 for rxn in reactions: |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
24 if "biomass" in rxn.getName().lower(): |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
25 return rxn |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
26 # 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
|
27 # AND not in reactants |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
28 for rxn in reactions: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
29 in_reactants = False |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
30 for reac in rxn.getListOfReactants(): |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
31 if "biomass" in reac.getSpecies().lower(): |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
32 in_reactants = True |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
33 break |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
34 if not in_reactants: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
35 for prod in rxn.getListOfProducts(): |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
36 if "biomass" in prod.getSpecies().lower(): |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
37 return rxn |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
38 return None |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
39 |
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 def args(): |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
42 parser = ArgumentParser("Returns cell informations") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
43 parser.add_argument("infile", type=str, help="SBML input file (xml)") |
11
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
44 parser.add_argument("--biomassid", type=str, help="ID of biomass reaction") |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
45 parser.add_argument("--taxonid", type=str, help="Taxonomy ID") |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
46 parser.add_argument("--standalone", action="store_true", help="Standalone mode, e.g. do not retrieve taxonomy ID on Internet (true if --taxonid is provided)") |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
47 parser.add_argument("--compartments-outfile", type=str, help="Path to store cell compartments") |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
48 parser.add_argument("--biomassid-outfile", type=str, help="Path to store biomass reaction ID") |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
49 parser.add_argument("--taxonid-outfile", type=str, help="Path to store host taxonomy ID") |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
50 params = parser.parse_args() |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
51 return params |
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 |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
54 def get_organism_from_bigg_model(model_id): |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
55 """Try to retrieve organism info from BiGG Models for a given model ID.""" |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
56 url = f"http://bigg.ucsd.edu/api/v2/models/{model_id}" |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
57 try: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
58 response = r_get(url) |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
59 if response.status_code == 200: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
60 data = response.json() |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
61 organism = data.get("organism") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
62 return organism |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
63 except Exception as e: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
64 print(f"Error querying BiGG: {e}") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
65 return None |
9
6a2871e89352
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents:
8
diff
changeset
|
66 |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
67 def get_taxon_id(input_name): |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
68 """Try BiGG model name first, then NCBI directly.""" |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
69 print(f"Trying input: {input_name}") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
70 |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
71 # Try resolving as a BiGG model |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
72 organism = get_organism_from_bigg_model(input_name) |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
73 if organism: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
74 print(f"Model '{input_name}' maps to organism: {organism}") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
75 taxon_id = get_taxonid(organism) |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
76 if taxon_id: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
77 return taxon_id |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
78 |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
79 # If not a model, try directly as an organism name |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
80 print(f"Trying NCBI search with input: {input_name}") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
81 return get_taxonid(input_name) |
9
6a2871e89352
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents:
8
diff
changeset
|
82 |
6a2871e89352
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 537d7fefe58984b8f7ca66010153a2fdc35ddf4b
tduigou
parents:
8
diff
changeset
|
83 |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
84 def entry_point(): |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
85 params = args() |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
86 |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
87 # test if the file exists |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
88 with open(params.infile): |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
89 pass |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
90 |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
91 sbml_doc = readSBMLFromFile(params.infile) |
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
92 |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
93 compartments = sbml_doc.getModel().getListOfCompartments() |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
94 comp_str = "" |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
95 for comp in compartments: |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
96 comp_str += f"{comp.getId()}\t{comp.getName()}\n" |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
97 print("Compartments:") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
98 for comp in compartments: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
99 print(f"{comp.getId()}\t{comp.getName()}".replace("\n", " | ")) |
11
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
100 if params.compartments_outfile: |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
101 with open(params.compartments_outfile, "w") as f: |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
102 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
|
103 f.write(comp_str) |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
104 |
11
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
105 if params.biomassid: |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
106 biomass_rxn = sbml_doc.getModel().getReaction(params.biomassid) |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
107 else: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
108 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
|
109 if not biomass_rxn: |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
110 print("Warning: unable to retrieve biomass reaction") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
111 biomass_id = "" |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
112 else: |
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
113 biomass_id = biomass_rxn.getId() |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
114 print(f"Biomass reaction ID: {biomass_id}") |
11
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
115 if params.biomassid_outfile: |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
116 with open(params.biomassid_outfile, "w") as f: |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
117 f.write("#ID\n") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
118 f.write(f"{biomass_id}\n") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
119 |
11
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
120 if params.taxonid: |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
121 taxid = params.taxonid |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
122 elif params.standalone: |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
123 taxid = -1 |
8
768ed7cc0978
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
tduigou
parents:
7
diff
changeset
|
124 else: |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
125 model_id = sbml_doc.getModel().getId() |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
126 if model_id: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
127 taxid = get_taxon_id(sbml_doc.getModel().getId()) |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
128 if taxid == -1: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
129 # Try with model name |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
130 model_name = sbml_doc.getModel().getName() |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
131 if model_name: |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
132 taxid = get_taxon_id(sbml_doc.getModel().getName()) |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
133 print(f"Taxonomy ID: {taxid}") |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
134 |
11
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
135 if params.taxonid_outfile: |
062f51695ae0
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
tduigou
parents:
10
diff
changeset
|
136 with open(params.taxonid_outfile, "w") as f: |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
137 f.write("#ID\n") |
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
138 f.write(f"{taxid}\n") |
2
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
139 |
fa893f77dc22
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 18fcec17fb6415ad5a59b9bcfa853e755c768e6f
tduigou
parents:
1
diff
changeset
|
140 |
1
ceffb29b60c9
planemo upload commit 9c19f737cd6e2152151c8bf97a53ab1afe51a4a0
tduigou
parents:
diff
changeset
|
141 if __name__ == "__main__": |
10
dc1167469d62
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 94f89a44e330ccfccc8d94b5e7acf583c9d39343
tduigou
parents:
9
diff
changeset
|
142 entry_point() |