Mercurial > repos > iuc > gem_check_memote
annotate gem_flux_distribution.py @ 0:927af80d5e38 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:42 +0000 |
parents | |
children |
rev | line source |
---|---|
0
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
1 import argparse |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
2 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
3 import cobra |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
4 import pandas as pd |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
5 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
6 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
7 def __main__(): |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
8 parser = argparse.ArgumentParser( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
9 prog="FluxDistribution", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
10 description="This program calculates the flux distribution of a GEM", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
11 epilog="Adding an epilog, but doubt it's needed.", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
12 ) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
13 parser.add_argument( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
14 "-m", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
15 "--cb_model_location", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
16 dest="cb_model_location", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
17 action="store", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
18 type=str, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
19 default=None, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
20 required=True, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
21 help="The model to use." |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
22 ) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
23 parser.add_argument( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
24 "-output", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
25 "--output", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
26 dest="out_file", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
27 action="store", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
28 type=str, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
29 default=None, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
30 required=True, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
31 help="The output file." |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
32 ) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
33 parser.add_argument( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
34 "-u", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
35 "--uptake_constraints_file", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
36 dest="uptake_constraints_file", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
37 action="store", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
38 type=str, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
39 default=None, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
40 required=False, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
41 help="File containing new uptake constraits." |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
42 ) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
43 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
44 args = parser.parse_args() |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
45 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
46 try: |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
47 cb_model = cobra.io.read_sbml_model(args.cb_model_location) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
48 except Exception as e: |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
49 raise Exception( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
50 "The model could not be read. Ensure " |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
51 "it is in correct SBML format." |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
52 ) from e |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
53 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
54 if args.uptake_constraints_file is not None\ |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
55 and args.uptake_constraints_file != "None": |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
56 constraints_df = pd.read_csv( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
57 args.uptake_constraints_file, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
58 sep=";", |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
59 header=0, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
60 index_col=False |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
61 ) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
62 for _, row in constraints_df.iterrows(): |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
63 cb_model.reactions.get_by_id( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
64 row["reaction_id"] |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
65 ).lower_bound = row["lower_bound"] |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
66 cb_model.reactions.get_by_id( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
67 row["reaction_id"] |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
68 ).upper_bound = row["upper_bound"] |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
69 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
70 # do pFBA |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
71 solution = cobra.flux_analysis.pfba(cb_model) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
72 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
73 # make a dataframe with the reaction names, |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
74 # reaction ids, and flux distribution |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
75 flux_distribution = pd.DataFrame( |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
76 columns=["reaction_name", "reaction_id", "flux"] |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
77 ) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
78 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
79 flux_distribution["reaction_name"] = \ |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
80 [reaction.name for reaction in cb_model.reactions] |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
81 flux_distribution["reaction_id"] = \ |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
82 [reaction.id for reaction in cb_model.reactions] |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
83 flux_distribution["flux"] = \ |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
84 [solution.fluxes[reaction.id] for reaction in cb_model.reactions] |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
85 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
86 flux_distribution.to_csv(args.out_file, sep=";", index=False) |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
87 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
88 |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
89 if __name__ == "__main__": |
927af80d5e38
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
iuc
parents:
diff
changeset
|
90 __main__() |