Simulating Deletions


In [1]:
import pandas
from time import time

import cobra.test
from cobra.flux_analysis import \
    single_gene_deletion, single_reaction_deletion, \
    double_gene_deletion, double_reaction_deletion

cobra_model = cobra.test.create_test_model("textbook")
ecoli_model = cobra.test.create_test_model("ecoli")

Single Deletions

Perform all single gene deletions on a model


In [2]:
growth_rates, statuses = single_gene_deletion(cobra_model)

These can also be done for only a subset of genes


In [3]:
gr, st = single_gene_deletion(cobra_model,
                              cobra_model.genes[:20])
pandas.DataFrame.from_dict({"growth_rates": gr,
                            "status": st})


Out[3]:
growth_rates status
b0116 0.782351 optimal
b0118 0.873922 optimal
b0351 0.873922 optimal
b0356 0.873922 optimal
b0474 0.873922 optimal
b0726 0.858307 optimal
b0727 0.858307 optimal
b1241 0.873922 optimal
b1276 0.873922 optimal
b1478 0.873922 optimal
b1849 0.873922 optimal
b2296 0.873922 optimal
b2587 0.873922 optimal
b3115 0.873922 optimal
b3732 0.374230 optimal
b3733 0.374230 optimal
b3734 0.374230 optimal
b3735 0.374230 optimal
b3736 0.374230 optimal
s0001 0.211141 optimal

This can also be done for reactions


In [4]:
gr, st = single_reaction_deletion(cobra_model,
                                  cobra_model.reactions[:20])
pandas.DataFrame.from_dict({"growth_rates": gr,
                            "status": st})


Out[4]:
growth_rates status
ACALD 8.739215e-01 optimal
ACALDt 8.739215e-01 optimal
ACKr 8.739215e-01 optimal
ACONTa -3.963237e-27 optimal
ACONTb 6.162976e-33 optimal
ACt2r 8.739215e-01 optimal
ADK1 8.739215e-01 optimal
AKGDH 8.583074e-01 optimal
AKGt2r 8.739215e-01 optimal
ALCD2x 8.739215e-01 optimal
ATPM 9.166475e-01 optimal
ATPS4r 3.742299e-01 optimal
Biomass_Ecoli_core 0.000000e+00 optimal
CO2t 4.616696e-01 optimal
CS -5.916457e-30 optimal
CYTBD 2.116629e-01 optimal
D_LACt2 8.739215e-01 optimal
ENO -3.266892e-18 optimal
ETOHt2r 8.739215e-01 optimal
EX_ac_e 8.739215e-01 optimal

Double Deletions

Double deletions run in a similar way. Passing in return_frame=True will cause them to format the results as a pandas Dataframe


In [5]:
double_gene_deletion(cobra_model, cobra_model.genes[-5:],
                     return_frame=True)


Out[5]:
b2464 b0008 b2935 b2465 b3919
b2464 0.873922 0.864759 0.873922 0.873922 0.704037
b0008 0.864759 0.873922 0.873922 0.873922 0.704037
b2935 0.873922 0.873922 0.873922 0.000000 0.704037
b2465 0.873922 0.873922 0.000000 0.873922 0.704037
b3919 0.704037 0.704037 0.704037 0.704037 0.704037

By default, the double deletion function will automatically use multiprocessing, splitting the task over up to 4 cores if they are available. The number of cores can be manually sepcified as well. Setting use of a single core will disable use of the multiprocessing library, which often aids debuggging.


In [6]:
start = time()  # start timer()
double_gene_deletion(ecoli_model, ecoli_model.genes[:200],
                     number_of_processes=2)
t1 = time() - start
print("Double gene deletions for 200 genes completed in "
      "%.2f sec with 2 cores" % t1)

start = time()  # start timer()
double_gene_deletion(ecoli_model, ecoli_model.genes[:200],
                     number_of_processes=1)
t2 = time() - start
print("Double gene deletions for 200 genes completed in "
      "%.2f sec with 1 core" % t2)

print("Speedup of %.2fx" % (t2 / t1))


Double gene deletions for 200 genes completed in 11.13 sec with 2 cores
Double gene deletions for 200 genes completed in 14.14 sec with 1 core
Speedup of 1.27x

Double deletions can also be run for reactions


In [7]:
double_reaction_deletion(cobra_model,
                         cobra_model.reactions[2:7],
                         return_frame=True)


Out[7]:
ACKr ACONTa ACONTb ACt2r ADK1
ACKr 0.873922 0 0 0.873922 0.873922
ACONTa 0.000000 0 0 0.000000 0.000000
ACONTb 0.000000 0 0 0.000000 0.000000
ACt2r 0.873922 0 0 0.873922 0.873922
ADK1 0.873922 0 0 0.873922 0.873922