Mercurial > repos > iuc > gem_flux_distribution
annotate gem_knockout.py @ 0:1c71660496fb 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:33:11 +0000 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 
0
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
1 import argparse | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
2 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
3 import cobra | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
4 import pandas as pd | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
5 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
6 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
7 def __main__(): | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
8 parser = argparse.ArgumentParser( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
9 prog="FluxDistribution", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
10 description="Performs FBA knockout analysis on a GEM.", | 
| 
 
1c71660496fb
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.", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
12 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
13 parser.add_argument( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
14 "-m", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
15 "--cb_model_location", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
16 dest="cb_model_location", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
17 action="store", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
18 type=str, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
19 default=None, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
20 required=True, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
21 help="The model to use." | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
22 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
23 parser.add_argument( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
24 "-output", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
25 "--output", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
26 dest="out_file", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
27 action="store", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
28 type=str, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
29 default=None, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
30 required=True, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
31 help="The output file." | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
32 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
33 parser.add_argument( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
34 "-k", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
35 "--knockout_type", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
36 dest="knockout_type", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
37 action="store", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
38 type=str, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
39 default="single", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
40 required=False, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
41 help="Type of knockout to perform, single or double" | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
42 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
43 parser.add_argument( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
44 "-g", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
45 "--gene_knockouts", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
46 dest="gene_knockouts", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
47 action="store", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
48 type=str, default=None, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
49 required=False, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
50 help="List of genes to knock out. Defaults to all." | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
51 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
52 parser.add_argument( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
53 "-u", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
54 "--uptake_constraints_file", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
55 dest="uptake_constraints_file", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
56 action="store", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
57 type=str, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
58 default=None, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
59 required=False, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
60 help="File containing new uptake constraits." | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
61 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
62 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
63 args = parser.parse_args() | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
64 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
65 # Reading the model | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
66 try: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
67 cb_model = cobra.io.read_sbml_model(args.cb_model_location) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
68 except Exception as e: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
69 raise Exception( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
70 "The model could not be read. " | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
71 "Ensure it is in correct SBML format." | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
72 ) from e | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
73 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
74 # Verifying the genes are present in the model | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
75 gene_ids = [gene.id for gene in cb_model.genes] | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
76 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
77 genes_to_knockout_1 = args.gene_knockouts.split(',')\ | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
78 if args.gene_knockouts is not None else [] | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
79 gene_bool = [ | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
80 True if gene in gene_ids else False for gene in genes_to_knockout_1 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
81 ] | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
82 if not all(gene_bool): | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
83 print( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
84 f'Found {sum(gene_bool)} of {len(genes_to_knockout_1)} genes ' | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
85 'in the model.' | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
86 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
87 raise Exception( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
88 "One or more of the genes to knockout are not present " | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
89 "in the model." | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
90 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
91 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
92 # Adding all genes to knockout if none are specified | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
93 if genes_to_knockout_1 is None or len(genes_to_knockout_1) == 0: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
94 genes_to_knockout_1 = [gene.id for gene in cb_model.genes] | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
95 # Applying uptake constraints | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
96 if (args.uptake_constraints_file is not None | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
97 and args.uptake_constraints_file != "None"): | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
98 constraints_df = pd.read_csv( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
99 args.uptake_constraints_file, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
100 sep=";", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
101 header=0, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
102 index_col=False | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
103 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
104 for index, row in constraints_df.iterrows(): | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
105 reaction = cb_model.reactions.get_by_id(row["reaction_id"]) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
106 reaction.lower_bound = row["lower_bound"] | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
107 reaction.upper_bound = row["upper_bound"] | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
108 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
109 result = pd.DataFrame(columns=[ | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
110 "reaction_id", "ko_gene_id_1", "ko_gene_id_2", | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
111 "reaction", "wildtype_flux", "knockout_flux" | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
112 ]) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
113 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
114 if args.knockout_type == "single": | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
115 genes_to_knockout_2 = [0] | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
116 elif args.knockout_type == "double": | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
117 genes_to_knockout_2 = genes_to_knockout_1.copy() | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
118 else: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
119 raise Exception( | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
120 f"Invalid knockout type {args.knockout_type}. " | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
121 "Only single and double are allowed." | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
122 ) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
123 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
124 # Wildtype pFBA | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
125 with cb_model as model: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
126 wildtype_solution = model.optimize() | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
127 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
128 # Performing gene knockouts | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
129 for gene1 in genes_to_knockout_1: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
130 for gene2 in genes_to_knockout_2: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
131 with cb_model as model: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
132 model.genes.get_by_id(gene1).knock_out() | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
133 if args.knockout_type == "double": | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
134 model.genes.get_by_id(gene2).knock_out() | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
135 solution = model.optimize() | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
136 for reaction in model.reactions: | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
137 result = pd.concat([result, pd.DataFrame([{ | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
138 "reaction_id": reaction.id, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
139 "ko_gene_id_1": gene1, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
140 "ko_gene_id_2": gene2 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
141 if args.knockout_type == "double" else None, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
142 "reaction": reaction.reaction, | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
143 "wildtype_flux": wildtype_solution.fluxes[reaction.id], | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
144 "knockout_flux": solution.fluxes[reaction.id], | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
145 }])], ignore_index=True) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
146 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
147 # Writing the results to file | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
148 result.to_csv(args.out_file, sep=";", index=False) | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
149 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
150 | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
151 if __name__ == "__main__": | 
| 
 
1c71660496fb
planemo upload for repository https://github.com/AlmaasLab/elixir-galaxy-tools-systemsbiology commit 3f7bec1264a86e1488ee1315dbac0f44675f5171
 
iuc 
parents:  
diff
changeset
 | 
152 __main__() | 
