Mercurial > repos > tduigou > get_sbml_model
comparison get_infos.py @ 13:6bcd8f09158d draft default tip
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit 8ab0b9452a029b409b18b80243958b4901bdeb3d
author | tduigou |
---|---|
date | Tue, 01 Apr 2025 10:00:36 +0000 |
parents | 1aadcfdae10b |
children |
comparison
equal
deleted
inserted
replaced
12:1aadcfdae10b | 13:6bcd8f09158d |
---|---|
39 | 39 |
40 | 40 |
41 def args(): | 41 def args(): |
42 parser = ArgumentParser("Returns cell informations") | 42 parser = ArgumentParser("Returns cell informations") |
43 parser.add_argument("infile", type=str, help="SBML input file (xml)") | 43 parser.add_argument("infile", type=str, help="SBML input file (xml)") |
44 parser.add_argument("--hostname-or-id", type=str, help="Hostname or model ID") | 44 parser.add_argument("--biomassid", type=str, help="ID of biomass reaction") |
45 parser.add_argument("--comp", type=str, help="Path to store cell compartments") | 45 parser.add_argument("--taxonid", type=str, help="Taxonomy ID") |
46 parser.add_argument("--biomass", type=str, help="Path to store biomass reaction ID") | 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)") |
47 parser.add_argument("--biomass-id", type=str, help="ID of biomass reaction") | 47 parser.add_argument("--compartments-outfile", type=str, help="Path to store cell compartments") |
48 parser.add_argument("--taxid", type=str, help="Path to store host taxonomy ID") | 48 parser.add_argument("--biomassid-outfile", type=str, help="Path to store biomass reaction ID") |
49 parser.add_argument("--taxonid-outfile", type=str, help="Path to store host taxonomy ID") | |
49 params = parser.parse_args() | 50 params = parser.parse_args() |
50 return params | 51 return params |
51 | 52 |
52 | 53 |
53 def get_organism_from_bigg_model(model_id): | 54 def get_organism_from_bigg_model(model_id): |
94 for comp in compartments: | 95 for comp in compartments: |
95 comp_str += f"{comp.getId()}\t{comp.getName()}\n" | 96 comp_str += f"{comp.getId()}\t{comp.getName()}\n" |
96 print("Compartments:") | 97 print("Compartments:") |
97 for comp in compartments: | 98 for comp in compartments: |
98 print(f"{comp.getId()}\t{comp.getName()}".replace("\n", " | ")) | 99 print(f"{comp.getId()}\t{comp.getName()}".replace("\n", " | ")) |
99 if params.comp: | 100 if params.compartments_outfile: |
100 with open(params.comp, "w") as f: | 101 with open(params.compartments_outfile, "w") as f: |
101 f.write("#ID\tNAME\n") | 102 f.write("#ID\tNAME\n") |
102 f.write(comp_str) | 103 f.write(comp_str) |
103 | 104 |
104 if params.biomass_id: | 105 if params.biomassid: |
105 biomass_rxn = sbml_doc.getModel().getReaction(params.biomass_id) | 106 biomass_rxn = sbml_doc.getModel().getReaction(params.biomassid) |
106 else: | 107 else: |
107 biomass_rxn = get_biomass_rxn(sbml_doc) | 108 biomass_rxn = get_biomass_rxn(sbml_doc) |
108 if not biomass_rxn: | 109 if not biomass_rxn: |
109 print("Warning: unable to retrieve biomass reaction") | 110 print("Warning: unable to retrieve biomass reaction") |
110 biomass_id = "" | 111 biomass_id = "" |
111 else: | 112 else: |
112 biomass_id = biomass_rxn.getId() | 113 biomass_id = biomass_rxn.getId() |
113 print(f"Biomass reaction ID: {biomass_id}") | 114 print(f"Biomass reaction ID: {biomass_id}") |
114 if params.biomass: | 115 if params.biomassid_outfile: |
115 with open(params.biomass, "w") as f: | 116 with open(params.biomassid_outfile, "w") as f: |
116 f.write("#ID\n") | 117 f.write("#ID\n") |
117 f.write(f"{biomass_id}\n") | 118 f.write(f"{biomass_id}\n") |
118 | 119 |
119 if params.hostname_or_id: | 120 if params.taxonid: |
120 taxid = get_taxon_id(params.hostname_or_id) | 121 taxid = params.taxonid |
122 elif params.standalone: | |
123 taxid = -1 | |
121 else: | 124 else: |
122 model_id = sbml_doc.getModel().getId() | 125 model_id = sbml_doc.getModel().getId() |
123 taxid = -1 | |
124 if model_id: | 126 if model_id: |
125 taxid = get_taxon_id(sbml_doc.getModel().getId()) | 127 taxid = get_taxon_id(sbml_doc.getModel().getId()) |
126 if taxid == -1: | 128 if taxid == -1: |
127 # Try with model name | 129 # Try with model name |
128 model_name = sbml_doc.getModel().getName() | 130 model_name = sbml_doc.getModel().getName() |
129 if model_name: | 131 if model_name: |
130 taxid = get_taxon_id(sbml_doc.getModel().getName()) | 132 taxid = get_taxon_id(sbml_doc.getModel().getName()) |
131 print(f"Taxonomy ID: {taxid}") | 133 print(f"Taxonomy ID: {taxid}") |
132 | 134 |
133 if params.taxid: | 135 if params.taxonid_outfile: |
134 with open(params.taxid, "w") as f: | 136 with open(params.taxonid_outfile, "w") as f: |
135 f.write("#ID\n") | 137 f.write("#ID\n") |
136 f.write(f"{taxid}\n") | 138 f.write(f"{taxid}\n") |
137 | 139 |
138 | 140 |
139 if __name__ == "__main__": | 141 if __name__ == "__main__": |