Mercurial > repos > iuc > gem_escher_visualization
comparison gem_extract_exchange.py @ 0:b79cf44068bc draft default tip
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
author | iuc |
---|---|
date | Fri, 13 Dec 2024 21:32:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b79cf44068bc |
---|---|
1 import argparse | |
2 | |
3 import cobra | |
4 | |
5 | |
6 def read_model(model_location): | |
7 model = cobra.io.read_sbml_model(model_location) | |
8 return model | |
9 | |
10 | |
11 def get_exchange_reactions_info(model): | |
12 exchange_reactions = model.exchanges | |
13 exchange_reactions_info = [] | |
14 for reaction in exchange_reactions: | |
15 exchange_reactions_info.append( | |
16 [ | |
17 reaction.id, | |
18 reaction.name, | |
19 reaction.reaction, | |
20 reaction.lower_bound, | |
21 reaction.upper_bound | |
22 ]) | |
23 txt_object = ( | |
24 "reaction_id;reaction_name;reaction_stoichiometry;" | |
25 "lower_bound;upper_bound\n" | |
26 ) | |
27 for reaction in exchange_reactions_info: | |
28 txt_object += ";".join([str(x) for x in reaction]) + "\n" | |
29 return txt_object | |
30 | |
31 | |
32 def __main__(): | |
33 | |
34 # Parsing arguments | |
35 parser = argparse.ArgumentParser( | |
36 prog="GEM ", | |
37 description="This program retrieves the exchange fluxes " | |
38 "of a GEM model to be used in Galaxy.", | |
39 epilog="Adding an epilog, but doubt it's needed.", | |
40 ) | |
41 parser.add_argument( | |
42 "-m", | |
43 "--cb_model_location", | |
44 dest="cb_model_location", | |
45 action="store", | |
46 type=str, | |
47 default=None, | |
48 required=True, | |
49 help="The model to use." | |
50 ) | |
51 parser.add_argument( | |
52 "-output", | |
53 "--output", | |
54 dest="out_file", | |
55 action="store", | |
56 type=str, | |
57 default=None, | |
58 required=True, | |
59 help="The output file." | |
60 ) | |
61 args = parser.parse_args() | |
62 | |
63 # Reading model from file | |
64 try: | |
65 cb_model = read_model(args.cb_model_location) | |
66 except Exception as e: | |
67 raise Exception( | |
68 "The model could not be read. Ensure it is in correct SBML format." | |
69 ) from e | |
70 | |
71 # Getting exchange reactions info | |
72 answer = get_exchange_reactions_info(cb_model) | |
73 | |
74 # Writing exchange reactions info to file | |
75 with open(args.out_file, "w") as outfile: | |
76 outfile.write(str(answer)) | |
77 | |
78 | |
79 if __name__ == "__main__": | |
80 __main__() |