Quick Start¶
In [3]:
%matplotlib inline
import site
site.addsitedir(r'C:\Users\Ciaran\Documents\pycotools')
from pycotools import model, models, viz, tasks, misc
import os
import pandas
C:\Users\Ciaran\Documents\pycotools\pycotools\viz.py:117: FutureWarning: The pandas.parser module is deprecated and will be removed in a future version. Please import from the pandas.io.parser instead
from pandas.parser import CParserError
root:INFO:25: Initializing pycotools
root:INFO:26: Initializing logging System
root:INFO:27: logging config file at: C:\Users\Ciaran\Documents\pycotools\pycotools\logging_config.conf
Create Michaelis-Menten Model¶
In [4]:
working_directory = r'C:\Users\Ciaran\Documents\PycotoolsQuickStart'
copasi_file = os.path.join(working_directory, 'quick_start_model.cps')
if os.path.isfile(copasi_file):
os.remove(copasi_file)
kf = 0.01
kb = 0.1
kcat = 0.03
with model.Build(copasi_file) as m:
m.name = 'Michaelis-Menten'
m.add('compartment', name='Cell')
m.add('metabolite', name='P', concentration=0)
m.add('metabolite', name='S', concentration=50)
m.add('metabolite', name='E', concentration=15)
m.add('metabolite', name='ES', concentration=0)
m.add('reaction', name='S bind E', expression='S + E -> ES', rate_law='kf*S*E',
parameter_values={'kf': kf})
m.add('reaction', name='S unbind E', expression='ES -> S + E', rate_law='kb*ES',
parameter_values={'kb': kb})
m.add('reaction', name='ES produce P', expression='ES -> P', rate_law='kcat*ES',
parameter_values={'kcat': kcat})
michaelis_menten = model.Model(copasi_file)
michaelis_menten
Out[4]:
Model(name=Michaelis-Menten, time_unit=s, volume_unit=ml, quantity_unit=mmol)
Simulate Michaelis-Menten model¶
In [70]:
TC = tasks.TimeCourse(michaelis_menten, end=100, step_size=0.01, intervals=0.01*100,
report_name='MM-time-course.csv')
Plot results¶
In [36]:
viz.PlotTimeCourse(TC, separate=False)
Out[36]:
<pycotools.viz.PlotTimeCourse at 0xdb36128>

In [37]:
metabolite_names = [i.name for i in michaelis_menten.metabolites]
[viz.PlotTimeCourse(TC, x=i, separate=False) for i in metabolite_names]
Out[37]:
[<pycotools.viz.PlotTimeCourse at 0xdc52be0>,
<pycotools.viz.PlotTimeCourse at 0xd9fde48>,
<pycotools.viz.PlotTimeCourse at 0xe3de5c0>,
<pycotools.viz.PlotTimeCourse at 0xdf4e3c8>]




Inspect the model¶
In [38]:
print 'model has {} metabolites, {} reactions and {} local parameters'.format(
len(michaelis_menten.metabolites),
len(michaelis_menten.reactions),
len(michaelis_menten.local_parameters)
)
model has 4 metabolites, 3 reactions and 3 local parameters
Prepare Time Course Results for Parameter Estimation¶
Since copasi headers from copasi output looks like this:
In [39]:
pandas.read_csv(TC.report_name, sep='\t').head()
Out[39]:
Time | [E] | [ES] | [P] | [S] | |
---|---|---|---|---|---|
0 | 0.00 | 15.0000 | 0.000000 | 0.000000 | 50.0000 |
1 | 0.01 | 14.9253 | 0.074708 | 0.000011 | 49.9253 |
2 | 0.02 | 14.8511 | 0.148837 | 0.000045 | 49.8511 |
3 | 0.03 | 14.7775 | 0.222392 | 0.000100 | 49.7775 |
4 | 0.04 | 14.7044 | 0.295378 | 0.000178 | 49.7044 |
And we need exact match between variable names and data file headers, we
can use the misc.correct_copasi_timecourse_headers
function to
automatically format the simulated time course data for us
In [71]:
misc.correct_copasi_timecourse_headers(TC.report_name)
Out[71]:
Time | E | ES | P | S | |
---|---|---|---|---|---|
0 | 0.00 | 15.000000 | 0.000000 | 0.000000 | 50.0000 |
1 | 0.01 | 14.925200 | 0.074755 | 0.000011 | 49.9252 |
2 | 0.02 | 14.851000 | 0.148929 | 0.000045 | 49.8510 |
3 | 0.03 | 14.777400 | 0.222528 | 0.000100 | 49.7774 |
4 | 0.04 | 14.704300 | 0.295557 | 0.000178 | 49.7043 |
5 | 0.05 | 14.631700 | 0.368023 | 0.000278 | 49.6317 |
6 | 0.06 | 14.559700 | 0.439929 | 0.000399 | 49.5597 |
7 | 0.07 | 14.488200 | 0.511282 | 0.000541 | 49.4882 |
8 | 0.08 | 14.417200 | 0.582086 | 0.000705 | 49.4172 |
9 | 0.09 | 14.346800 | 0.652346 | 0.000890 | 49.3468 |
10 | 0.10 | 14.276800 | 0.722068 | 0.001096 | 49.2768 |
11 | 0.11 | 14.207400 | 0.791256 | 0.001323 | 49.2074 |
12 | 0.12 | 14.138500 | 0.859916 | 0.001571 | 49.1385 |
13 | 0.13 | 14.070100 | 0.928052 | 0.001839 | 49.0701 |
14 | 0.14 | 14.002200 | 0.995669 | 0.002127 | 49.0022 |
15 | 0.15 | 13.934800 | 1.062770 | 0.002436 | 48.9348 |
16 | 0.16 | 13.867900 | 1.129360 | 0.002764 | 48.8679 |
17 | 0.17 | 13.801400 | 1.195450 | 0.003113 | 48.8014 |
18 | 0.18 | 13.735500 | 1.261040 | 0.003481 | 48.7355 |
19 | 0.19 | 13.670000 | 1.326130 | 0.003869 | 48.6700 |
20 | 0.20 | 13.605000 | 1.390730 | 0.004276 | 48.6050 |
21 | 0.21 | 13.540500 | 1.454840 | 0.004703 | 48.5405 |
22 | 0.22 | 13.476400 | 1.518470 | 0.005148 | 48.4764 |
23 | 0.23 | 13.412800 | 1.581630 | 0.005613 | 48.4128 |
24 | 0.24 | 13.349600 | 1.644300 | 0.006097 | 48.3496 |
25 | 0.25 | 13.286900 | 1.706510 | 0.006599 | 48.2869 |
26 | 0.26 | 13.224600 | 1.768250 | 0.007120 | 48.2246 |
27 | 0.27 | 13.162800 | 1.829530 | 0.007659 | 48.1628 |
28 | 0.28 | 13.101400 | 1.890360 | 0.008217 | 48.1014 |
29 | 0.29 | 13.040500 | 1.950720 | 0.008793 | 48.0405 |
... | ... | ... | ... | ... | ... |
9971 | 99.71 | 0.361069 | 1.191130 | 13.447800 | 35.3611 |
9972 | 99.72 | 0.360986 | 1.190860 | 13.448200 | 35.3610 |
9973 | 99.73 | 0.360904 | 1.190580 | 13.448500 | 35.3609 |
9974 | 99.74 | 0.360822 | 1.190310 | 13.448900 | 35.3608 |
9975 | 99.75 | 0.360740 | 1.190030 | 13.449200 | 35.3607 |
9976 | 99.76 | 0.360657 | 1.189760 | 13.449600 | 35.3607 |
9977 | 99.77 | 0.360575 | 1.189480 | 13.449900 | 35.3606 |
9978 | 99.78 | 0.360493 | 1.189210 | 13.450300 | 35.3605 |
9979 | 99.79 | 0.360411 | 1.188940 | 13.450700 | 35.3604 |
9980 | 99.80 | 0.360328 | 1.188660 | 13.451000 | 35.3603 |
9981 | 99.81 | 0.360246 | 1.188390 | 13.451400 | 35.3602 |
9982 | 99.82 | 0.360164 | 1.188110 | 13.451700 | 35.3602 |
9983 | 99.83 | 0.360082 | 1.187840 | 13.452100 | 35.3601 |
9984 | 99.84 | 0.360000 | 1.187560 | 13.452400 | 35.3600 |
9985 | 99.85 | 0.359918 | 1.187290 | 13.452800 | 35.3599 |
9986 | 99.86 | 0.359836 | 1.187020 | 13.453100 | 35.3598 |
9987 | 99.87 | 0.359754 | 1.186740 | 13.453500 | 35.3598 |
9988 | 99.88 | 0.359672 | 1.186470 | 13.453900 | 35.3597 |
9989 | 99.89 | 0.359589 | 1.186200 | 13.454200 | 35.3596 |
9990 | 99.90 | 0.359507 | 1.185920 | 13.454600 | 35.3595 |
9991 | 99.91 | 0.359425 | 1.185650 | 13.454900 | 35.3594 |
9992 | 99.92 | 0.359344 | 1.185380 | 13.455300 | 35.3593 |
9993 | 99.93 | 0.359262 | 1.185100 | 13.455600 | 35.3593 |
9994 | 99.94 | 0.359180 | 1.184830 | 13.456000 | 35.3592 |
9995 | 99.95 | 0.359098 | 1.184560 | 13.456300 | 35.3591 |
9996 | 99.96 | 0.359016 | 1.184280 | 13.456700 | 35.3590 |
9997 | 99.97 | 0.358934 | 1.184010 | 13.457100 | 35.3589 |
9998 | 99.98 | 0.358852 | 1.183740 | 13.457400 | 35.3589 |
9999 | 99.99 | 0.358770 | 1.183460 | 13.457800 | 35.3588 |
10000 | 100.00 | 0.358688 | 1.183190 | 13.458100 | 35.3587 |
10001 rows × 5 columns
Do parameter estimations¶
Spread computation over multiple model copies
In [74]:
PE = tasks.MultiParameterEstimation(michaelis_menten, TC.report_name, method='genetic_algorithm_sr',
copy_number=3, pe_number=20, population_size=50,
number_of_generations=100, metabolites=[], overwrite_config_file=True)
PE.write_config_file()
PE.setup()
PE.results_directory
PE.run()
Out[74]:
'C:\\Users\\Ciaran\\Documents\\PycotoolsQuickStart\\MultipleParameterEstimationResults'
Visualize data¶
In [64]:
viz.Boxplots(PE, log10=True, num_per_plot=8)
Out[64]:
<pycotools.viz.Boxplots at 0xdd35518>

In [65]:
viz.Boxplots(PE, log10=True, num_per_plot=8, truncate_mode='ranks', theta=range(10))
Out[65]:
<pycotools.viz.Boxplots at 0xdd35198>

In [66]:
viz.LikelihoodRanks(PE, log10=True)
Out[66]:
<pycotools.viz.LikelihoodRanks at 0x11a3fa90>

In [67]:
viz.PlotTimeCourseEnsemble(PE, truncate_mode='ranks', theta=range(10))
pycotools.viz:INFO:1353: Plotting "E"
pycotools.viz:INFO:1353: Plotting "ES"
pycotools.viz:INFO:1353: Plotting "P"
pycotools.viz:INFO:1353: Plotting "S"
Out[67]:
<pycotools.viz.PlotTimeCourseEnsemble at 0x17b1ad68>




In [51]:
viz.Scatters(PE, x='all', y='all', log10=True, truncate_mode='ranks', theta=range(10))
pycotools.viz:INFO:2404: Plotting "(ES produce P).kcat" Vs "(ES produce P).kcat"
pycotools.viz:INFO:2404: Plotting "(ES produce P).kcat" Vs "(S bind E).kf"
pycotools.viz:INFO:2404: Plotting "(ES produce P).kcat" Vs "(S unbind E).kb"
pycotools.viz:INFO:2404: Plotting "(ES produce P).kcat" Vs "RSS"
pycotools.viz:INFO:2404: Plotting "(S bind E).kf" Vs "(ES produce P).kcat"
pycotools.viz:INFO:2404: Plotting "(S bind E).kf" Vs "(S bind E).kf"
pycotools.viz:INFO:2404: Plotting "(S bind E).kf" Vs "(S unbind E).kb"
pycotools.viz:INFO:2404: Plotting "(S bind E).kf" Vs "RSS"
pycotools.viz:INFO:2404: Plotting "(S unbind E).kb" Vs "(ES produce P).kcat"
pycotools.viz:INFO:2404: Plotting "(S unbind E).kb" Vs "(S bind E).kf"
pycotools.viz:INFO:2404: Plotting "(S unbind E).kb" Vs "(S unbind E).kb"
pycotools.viz:INFO:2404: Plotting "(S unbind E).kb" Vs "RSS"
pycotools.viz:INFO:2404: Plotting "RSS" Vs "(ES produce P).kcat"
pycotools.viz:INFO:2404: Plotting "RSS" Vs "(S bind E).kf"
pycotools.viz:INFO:2404: Plotting "RSS" Vs "(S unbind E).kb"
pycotools.viz:INFO:2404: Plotting "RSS" Vs "RSS"
Out[51]:
<pycotools.viz.Scatters at 0xd8147f0>
















Profile Likelihoods¶
In [75]:
PL = tasks.ProfileLikelihood(michaelis_menten, parameter_path=PE.results_directory, index=0, run=True,
max_active=4, number_of_steps=10, log10=True)
print(PL.results_directory)
pycotools.tasks:INFO:4541: running C:\Users\Ciaran\Documents\PycotoolsQuickStart\ProfileLikelihoods\0\(S_bind_E).kf.cps
pycotools.tasks:INFO:4541: running C:\Users\Ciaran\Documents\PycotoolsQuickStart\ProfileLikelihoods\0\(ES_produce_P).kcat.cps
pycotools.tasks:INFO:4541: running C:\Users\Ciaran\Documents\PycotoolsQuickStart\ProfileLikelihoods\0\(S_unbind_E).kb.cps
C:\Users\Ciaran\Documents\PycotoolsQuickStart\ProfileLikelihoods
In [78]:
viz.PlotProfileLikelihood(PL, interpolation='cubic', log10=True, show_original_rss=True)
Out[78]:
<pycotools.viz.PlotProfileLikelihood at 0x140a2978>



Best Parameters¶
original parameters: * kf: 0.01 * kb: 0.1 * kcat: 0.03
Best estimated parameters:
In [80]:
viz.Parse(PE).data.iloc[0]
Out[80]:
(ES produce P).kcat 0.029980
(S bind E).kf 0.010006
(S unbind E).kb 0.100343
RSS 0.348595
Name: 0, dtype: float64