diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 7e2147a..9cb8c7d --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,10 @@ # Simulink Code Generation slprj/ +# data dirs +/mcmc_simbio/exp_data/Zach_IFFL_raw +mcmc_simbio/exp_data/from_Tierra_Bio_2018_oct + # Session info octave-workspace @@ -26,3 +30,78 @@ octave-workspace # .DS_store files .DS_Store + +*.sublime-project +*.sublime-workspace + +*.txt +*.todo + +# Image files +*.png +*.tiff +*.eps +*.jpg +*.svg +# *.fig +# data files +*.gc +*.xlsx +# *.csv + +# movie files +*.mp4 + +youngha_data_conversion/ +html/ + +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# MATLAB Crash Dumps # +###################### +Crash_logs_*/ +manual_txtlsim_parameters.m + +# reaction files I use +*.reactions* +designing_masterVector_for_IFFL + + +# directories +/animations/ \ No newline at end of file diff --git a/ChangeLog b/ChangeLog old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/Pending b/Pending old mode 100644 new mode 100755 diff --git a/README b/README deleted file mode 100644 index 0588c08..0000000 --- a/README +++ /dev/null @@ -1,23 +0,0 @@ -This is the main directory for the TX-TL cell-free expression toolbox. -The subdiretories here contain models and code that can be used in -working with the TX-TL system. - -Contents: - - ChangeLog - list of changes that have been made - Makefile - makefile for creating distributions - Pending - (obsolete) list of pending tasks. See wiki version - aux/ - auxiliary function - components/ - component models - core/ - core functionality - data/ - default directory for wetlab experiment data - doc/ - toolbox documentation - examples/ - examples that use the toolbox - models/ - (obsolete) old directory structure. To be deleted. - modules/ - additional modules to the toolbox (e.g. parameter estimation) - tests/ - unit tests - tmp/ - temporarily stored filled (mostly script generated) - txtl_init.m - script to initalize toolbox (mainly setting up the path) - unused/ - old files that are no longer used and scheduled to be deleted - - diff --git a/README.md b/README.md new file mode 100755 index 0000000..c6fa4b3 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# Introduction + +This package contains two related toolboxes that work with MATALB Simbiology models: txtlsim and mcmc_simbio. + +The first toolbox is called txtlsim (ref), and can be used to simulate the chemical reations that occur in the Transcription-Translation (TX-TL) cell-free gene expression system developed at the University of Minnesota (Vincent Noireaux) and Caltech (Richard Murray) (refs). The main features of this toolbox are its ability to track the loading of enzymatic machinery, the consumption of resources, the ease of setting up models, the automatic accounting of retroactivity effects, and the extensibility the reaction networks generated. + +The second toolbox is called mcmc_simbio. This is a concurrent Bayesian parameter inference toolbox for MATLAB Simbiology models. The Bayesian parameter inference is performed using a modification of Aslak Grinsted's MATLAB implementation of the affine invariant ensemble Metropolis-Hastings MCMC sampler (ref). We have added support for what we call 'concurrent' parameter inference, which refers to the capability to estimate a common set of parameters that get used simultaneously and in arbitrary combinations in multiple experiments/models. More information can be found below. + +# The Toolboxes + +## Getting the toolbox and running some simple examples + +Clone the repository using + +``` +git clone https://github.com/BuildACell/txtlsim.git +``` + +into a directory you wish to put the toolbox in. Alternatively, if you do not plan to version control the toolbox, you can simply download it as a zip file using the green button on the [main page](https://github.com/BuildACell/txtlsim). + +Lets call the directory where you cloned or downloaded the repository `trunk`, i.e., this is where directories like `core`, `components`, `examples` and `mcmc_simbio` are. Open MATLAB, and set the current working directory to `trunk`. Type in `txtl_init` and `mcmc_init` into the MATLAB command line. This initializes the txtlsim and mcmc_simbio toolboxes. + +Check if both the toolboxes are installed properly by running the follwoing examples: + +### txtlsim examples +Start with typing in `geneexpr` into the command window. This should run a constitutive gene expression example in the toolbox, and you should see a plot with three subplots (protein; mRNA and DNA; and resource usage) appear. There should not be any error messages in the command window. + +Next, run the `negautoreg` example in the command line. Again, you should see a plot of the species in the system, and no errors. This example simulates the negative autoregulation circuit. + +Type in `edit TXTL_tutorial` into the command line to open the tutorial file. You can also use the MATLAB publisher button to publish this file, and look at it in the MATLAB help file markup. We recommend running through the examples in this file, and exploring the reactions, species, etc set up in this file. Familiarity with the MATLAB Simbiology command line is helpful here. To learn more about Simbiology, go to the [Getting Started Using the Simbiology Command Line](https://www.mathworks.com/help/simbio/gs/simbiology-command-line-tutorial.html) page. + +### mcmc_simbio examples + +Next, open and explore the mcmc_simbio estimation examples given in the files `proj_mcmc_tutorial`, `proj_mcmc_tutorial_II`, and `proj_mcmc_tutorial_III` in the `trunk\mcmc_simbio\proj\` directory. We strongly recommend you skim through the `mcmc_info.m` and `data_info` files (`trunk\mcmc_simbio\models_and_supporting_files\` or type `help mcmc_info` and `help data_info` into the MATLAB command line) to gain an understanding of some of the key functionalities of the parameter inference toolbox. Along with the three tutorial files, the `mcmc_info.m` and the `data_info.m` files provide an initial idea of the capabilities of the toolbox. + +## References + +More information can be found in the following references: + +Z. A. Tuza, V. Singhal, J. Kim and R. M. Murray, "An in silico modeling toolbox for rapid prototyping of circuits in a biomolecular “breadboard” system," 52nd IEEE Conference on Decision and Control, Firenze, 2013, pp. 1404-1410. +doi: 10.1109/CDC.2013.6760079 + + +Vipul Singhal, 2018 +California Institute of Technology \ No newline at end of file diff --git a/auxiliary/WriteODEFunction_externalParameters.m b/auxiliary/WriteODEFunction_externalParameters.m old mode 100644 new mode 100755 diff --git a/auxiliary/barweb.m b/auxiliary/barweb.m old mode 100644 new mode 100755 diff --git a/auxiliary/boundedline/.gitignore b/auxiliary/boundedline/.gitignore new file mode 100755 index 0000000..c2bfeef --- /dev/null +++ b/auxiliary/boundedline/.gitignore @@ -0,0 +1,45 @@ +# MATLAB # +########## +# Editor autosave files +*~ +*.asv +# Compiled MEX binaries (all platforms) +*.mex* + +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/auxiliary/boundedline/Inpaint_nans/.gitignore b/auxiliary/boundedline/Inpaint_nans/.gitignore new file mode 100755 index 0000000..e492200 --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/.gitignore @@ -0,0 +1,37 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo.html b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo.html new file mode 100755 index 0000000..de6698a --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo.html @@ -0,0 +1,161 @@ + + + + + + inpaint_nans_demo + + + +
% Surface fit artifact removal
+[x,y] = meshgrid(0:.01:1);
+z0 = exp(x+y);
+
+znan = z0;
+znan(20:50,40:70) = NaN;
+znan(30:90,5:10) = NaN;
+znan(70:75,40:90) = NaN;
+
+z = inpaint_nans(znan,3);
+
+% Comparison to griddata
+k = isnan(znan);
+zk = griddata(x(~k),y(~k),z(~k),x(k),y(k));
+zg = znan;
+zg(k) = zk;
+
+close all
+figure
+surf(z0)
+title 'Original surface'
+
+figure
+surf(znan)
+title 'Artifacts (large holes) in surface'
+
+figure
+surf(zg)
+title(['Griddata inpainting (',num2str(sum(isnan(zg(:)))),' NaNs remain)'])
+
+figure
+surf(z)
+title 'Inpainted surface'
+
+figure
+surf(zg-z0)
+title 'Griddata error surface'
+
+figure
+surf(z-z0)
+title 'Inpainting error surface (Note z-axis scale)'
+
+ + + \ No newline at end of file diff --git a/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo.png b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo.png new file mode 100755 index 0000000..954751b Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo.png differ diff --git a/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_01.png b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_01.png new file mode 100755 index 0000000..ad81599 Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_01.png differ diff --git a/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_02.png b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_02.png new file mode 100755 index 0000000..a810f13 Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_02.png differ diff --git a/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_03.png b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_03.png new file mode 100755 index 0000000..023f803 Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_03.png differ diff --git a/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_04.png b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_04.png new file mode 100755 index 0000000..12fcd8c Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_04.png differ diff --git a/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_05.png b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_05.png new file mode 100755 index 0000000..fa40492 Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_05.png differ diff --git a/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_06.png b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_06.png new file mode 100755 index 0000000..5465081 Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/demo/html/inpaint_nans_demo_06.png differ diff --git a/auxiliary/boundedline/Inpaint_nans/demo/inpaint_nans_demo_old.m b/auxiliary/boundedline/Inpaint_nans/demo/inpaint_nans_demo_old.m new file mode 100755 index 0000000..f478bbf --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/demo/inpaint_nans_demo_old.m @@ -0,0 +1,42 @@ +% Surface fit artifact removal +[x,y] = meshgrid(0:.01:1); +z0 = exp(x+y); + +znan = z0; +znan(20:50,40:70) = NaN; +znan(30:90,5:10) = NaN; +znan(70:75,40:90) = NaN; + +z = inpaint_nans(znan,3); + +% Comparison to griddata +k = isnan(znan); +zk = griddata(x(~k),y(~k),z(~k),x(k),y(k)); +zg = znan; +zg(k) = zk; + +close all +figure +surf(z0) +title 'Original surface' + +figure +surf(znan) +title 'Artifacts (large holes) in surface' + +figure +surf(zg) +title(['Griddata inpainting (',num2str(sum(isnan(zg(:)))),' NaNs remain)']) + +figure +surf(z) +title 'Inpainted surface' + +figure +surf(zg-z0) +title 'Griddata error surface' + +figure +surf(z-z0) +title 'Inpainting error surface (Note z-axis scale)' + diff --git a/auxiliary/boundedline/Inpaint_nans/doc/Nomination comments.rtf b/auxiliary/boundedline/Inpaint_nans/doc/Nomination comments.rtf new file mode 100755 index 0000000..4173630 --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/doc/Nomination comments.rtf @@ -0,0 +1,39 @@ +{\rtf1\mac\ansicpg10000\cocoartf102 +{\fonttbl\f0\fswiss\fcharset77 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\margl1440\margr1440\vieww10780\viewh13720\viewkind0 +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural + +\f0\fs24 \cf0 Nomination comments:\ +\ +Inpaint_nans fills a hole in matlab. (Yes, the pun was intentional.) But there\ +is indeed a niche that inpaint_nans falls into.\ +\ +The alternative to inpaint_nans is griddata (interp1 can be used for the 1-d \ +problems) but griddata fails to extrapolate well. Griddata also has serious\ +problems when its data already lies on a grid, due to its use of a Delaunay \ +triangulation. The other serious problem with the use of griddata is the\ +triangulation itself. The shape of the hole to be filled can sometimes result\ +in triangles with a poor aspect ratio (long, thin triangles) which are in turn\ +poor for interpolation. In fact, Griddata can even leave interior points\ +uninterpolated (see the tests.)\ +\ +A future plan for inpaint_nans is to add an option that will use a locally\ +anisotropic membrane model. This will allow better modeling for certain\ +classes of wavy surfaces. I'm also highly tempted to remove method 5.\ +I've never really liked it, having put it in at the request of one user. It has\ +no valid theory behind it in the context of inpaint_nans.\ +\ +In the interest of openness, I'll also say what inpaint_nans does not do. It\ +does not handle non-uniform grids. It is limited by the amount of memory \ +in the size of the arrays it can handle, although some of the methods were\ +explicitly provided to be more memory efficient than others. Inpaint_nans\ +also makes heavy use of sparse matrices, so surprisingly large problems\ +are accessible.\ +\ +Finally, while inpaint_nans does work for 1-d problems, they are not my\ +target. Interp1 (with 'spline' as the method) is as accurate, and should be\ +faster in general.\ +\ +John\ +} \ No newline at end of file diff --git a/auxiliary/boundedline/Inpaint_nans/doc/methods_of_inpaint_nans.m b/auxiliary/boundedline/Inpaint_nans/doc/methods_of_inpaint_nans.m new file mode 100755 index 0000000..db956cb --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/doc/methods_of_inpaint_nans.m @@ -0,0 +1,187 @@ +%{ + +The methods of inpaint_nans + +Digital inpainting is the craft of replacing missing elements in an +"image" array. A Google search on the words "digita inpainting" will turn +up many hits. I just tried this search and found 18300 hits. + +If you wish to do inpainting in matlab, one place to start is with my +inpaint_nans code. Inpaint_nans is on the file exchange: + +http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4551&objectType=file + +It looks for NaN elements in an array (or vector) and attempts to interpolate +(or extrapolate) smoothly to replace those elements. + +The name "inpainting" itself comes from the world of art restoration. +Damaged paintings are restored by an artist/craftsman skilled in matching +the style of the original artist to fill in any holes in the painting. + +In digital inpainting, the goal is to interpolate in from the boundaries +of a hole to smoothly replace an artifact. Obviously, where the hole is +large the digitally inpainted repair may not be an accurate approximation +to the original. + +Inpaint_nans itself is really only a boundary value solver. The basic idea +is to formulate a partial differential equation (PDE) that is assumed to +apply in the domain of the artifact to be inpainted. The perimeter of the +hole supplies boundary values for the PDE. Then the PDE is approximated +using finite difference methods (the array elements are assumed to be +equally spaced in each dimension) and then a large (and very sparse) linear +system of equations is solved for the NaN elements in the array. + +I've chosen a variety of simple differental equation models the user can +specify to be solved. All the methods current use a basically elliptic +PDE. This means that the resulting linear system will generally be well +conditioned. It does mean that the solution will generally be fairly smooth, +and over large holes, it will tend towards an average of the boundary +elements. These are characteristics of the elliptic PDEs chosen. (My hope +is to expand these options in the future.) + +%} + +%% + +% Lets formulate a simple problem, and see how we could solve it using +% some of these ideas. +A = [0 0 0 0;1 NaN NaN 4;2 3 5 8]; + +% Although we can't plot this matrix using the functions surf or mesh, +% surely we can visualize what the fudamental shape is. + +% There are only two unknown elements, the artifacts that inpaint_nans +% would fill in: A(2,2) and A(2,3). + +% For an equally spaced grid, the Laplacian equation (or Poisson's equation +% of heat conduction at steady state if you prefer. Or, for the fickle, +% Ficke's law of diffusion would apply.) All of these result in the PDE +% +% u_xx + u_yy = 0 +% +% where u_xx is the second partial derivative of u with respect to x, +% and u_yy is the second partial with respect to y. +% +% Approximating this PDE using finite differences for the partial +% derivatives, implies that at any node in the grid, we could replace +% it by the average of its 4 neighbors. Thus the two NaN elements +% generate two linear equations: +% +% A(2,2) = (A(1,2) + A(3,2) + A(2,1) + A(2,3)) / 4 +% A(2,3) = (A(1,3) + A(3,3) + A(2,2) + A(2,4)) / 4 +% +% Since we know all the parameters but A(2,2) and A(2,3), substitute their +% known values. +% +% A(2,2) = (0 + 3 + 1 + A(2,3)) / 4 +% A(2,3) = (0 + 5 + A(2,2) + 4) / 4 +% +% Or, +% +% 4*A(2,2) - A(2,3) = 4 +% -A(2,2) + 4*A(2,3) = 9 +% +% We can solve for the unkowns now using +u = [4 -1;-1 4]\[4;9] + +A(2,2) = u(1); +A(2,3) = u(2); + +% and finally plot the surface +close +surf(A) +title 'A simply inpainted surface' + +% Neat huh? For an arbitrary number of NaN elements in an array, +% the above scheme is all there is to method 2 of inpaint_nans, +% together with a very slick application of sparse linear algebra +% in Matlab. + +% Method 0 is very similar, but I've optimized it to build as +% small a linear system as possible for those cases where an array +% has only a few NaN elements. + +% Method 1 is another subtle variation on this scheme, but it +% tries to be slightly smoother at some cost of efficiency, while +% still not modifying the known (non-NaN) elements of the array. + +% Method 5 of inpaint_nans is also very similar to method 2, except +% that it uses a simple average of all 8 neighbors of an element. +% Its not actually an approximation to our PDE. + +% Method 3 is yet another variation on this theme, except the PDE +% model used is one more suited to a model of a thin plate than for +% heat diffusion. Here the governing PDE is: +% +% u_xxxx + 2*u_xxyy + u_yyyy = 0 +% +% again discretized into a linear system of equations. + +%% + +% Finally, method 4 of inpaint_nans has a different underlying +% model. Pretend that each element in the array was connected to +% its immediate neighbors to the left, right, up, and down by +% "springs". They are also connected to their neighbors at 45 +% degree angles by springs with a weaker spring constant. Since +% the potential energy stored in a spring is proportional to its +% extension, we can formulate this again as a linear system of +% equations to be solved. For the example above, we would generate +% the set of equations: + +% A(2,2) - A(1,2) = 0 +% A(2,2) - A(2,1) = 0 +% A(2,2) - A(3,2) = 0 +% A(2,2) - A(2,3) = 0 +% (A(2,2) - A(1,1))/sqrt(2) = 0 +% (A(2,2) - A(1,3))/sqrt(2) = 0 +% (A(2,2) - A(3,1))/sqrt(2) = 0 +% (A(2,2) - A(3,3))/sqrt(2) = 0 +% A(2,3) - A(1,3) = 0 +% A(2,3) - A(2,2) = 0 +% A(2,3) - A(3,3) = 0 +% A(2,3) - A(2,4) = 0 +% (A(2,3) - A(1,2))/sqrt(2) = 0 +% (A(2,3) - A(1,4))/sqrt(2) = 0 +% (A(2,3) - A(3,2))/sqrt(2) = 0 +% (A(2,3) - A(3,4))/sqrt(2) = 0 + +% Substitute for the known elements to get + +% A(2,2) - 0 = 0 +% A(2,2) - 1 = 0 +% A(2,2) - 3 = 0 +% A(2,2) - A(2,3) = 0 +% (A(2,2) - 0)/sqrt(2) = 0 +% (A(2,2) - 0)/sqrt(2) = 0 +% (A(2,2) - 2)/sqrt(2) = 0 +% (A(2,2) - 5)/sqrt(2) = 0 +% A(2,3) - 0 = 0 +% A(2,3) - A(2,2) = 0 +% A(2,3) - 5 = 0 +% A(2,3) - 4 = 0 +% (A(2,3) - 0)/sqrt(2) = 0 +% (A(2,3) - 0)/sqrt(2) = 0 +% (A(2,3) - 3)/sqrt(2) = 0 +% (A(2,3) - 8)/sqrt(2) = 0 + +% This system is also solvable now: +r2 = 1/sqrt(2); +M=[1 0;1 0;1 0;1 -1;r2 0;r2 0;r2 0;r2 0;0 1;-1 1;0 1;0 1;0 r2;0 r2;0 r2;0 r2]; +v = M\[0 1 3 0 0 0 2*r2 5*r2 0 0 5 4 0 0 3*r2 8*r2]' + +A(2,2) = v(1); +A(2,3) = v(2); + +% and finally plot the surface +surf(A) +title 'A simply inpainted surface using a spring model' + +%% + +% Why did I provide this approach, based on a spring metaphor? +% As you should have observed, methods 2 and 4 are really quite close +% in what they do for internal NaN elements. Its on the perimeter that +% they differ significantly. The diffusion/Laplacian model will +% extrapolate smoothly, and as linearly as possible. The spring model +% will tend to extrapolate as a constant function. \ No newline at end of file diff --git a/auxiliary/boundedline/Inpaint_nans/garden50.jpg b/auxiliary/boundedline/Inpaint_nans/garden50.jpg new file mode 100755 index 0000000..37e1e99 Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/garden50.jpg differ diff --git a/auxiliary/boundedline/Inpaint_nans/inpaint_nans.m b/auxiliary/boundedline/Inpaint_nans/inpaint_nans.m new file mode 100755 index 0000000..2460b51 --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/inpaint_nans.m @@ -0,0 +1 @@ +function B=inpaint_nans(A,method) % INPAINT_NANS: in-paints over nans in an array % usage: B=INPAINT_NANS(A) % default method % usage: B=INPAINT_NANS(A,method) % specify method used % % Solves approximation to one of several pdes to % interpolate and extrapolate holes in an array % % arguments (input): % A - nxm array with some NaNs to be filled in % % method - (OPTIONAL) scalar numeric flag - specifies % which approach (or physical metaphor to use % for the interpolation.) All methods are capable % of extrapolation, some are better than others. % There are also speed differences, as well as % accuracy differences for smooth surfaces. % % methods {0,1,2} use a simple plate metaphor. % method 3 uses a better plate equation, % but may be much slower and uses % more memory. % method 4 uses a spring metaphor. % method 5 is an 8 neighbor average, with no % rationale behind it compared to the % other methods. I do not recommend % its use. % % method == 0 --> (DEFAULT) see method 1, but % this method does not build as large of a % linear system in the case of only a few % NaNs in a large array. % Extrapolation behavior is linear. % % method == 1 --> simple approach, applies del^2 % over the entire array, then drops those parts % of the array which do not have any contact with % NaNs. Uses a least squares approach, but it % does not modify known values. % In the case of small arrays, this method is % quite fast as it does very little extra work. % Extrapolation behavior is linear. % % method == 2 --> uses del^2, but solving a direct % linear system of equations for nan elements. % This method will be the fastest possible for % large systems since it uses the sparsest % possible system of equations. Not a least % squares approach, so it may be least robust % to noise on the boundaries of any holes. % This method will also be least able to % interpolate accurately for smooth surfaces. % Extrapolation behavior is linear. % % Note: method 2 has problems in 1-d, so this % method is disabled for vector inputs. % % method == 3 --+ See method 0, but uses del^4 for % the interpolating operator. This may result % in more accurate interpolations, at some cost % in speed. % % method == 4 --+ Uses a spring metaphor. Assumes % springs (with a nominal length of zero) % connect each node with every neighbor % (horizontally, vertically and diagonally) % Since each node tries to be like its neighbors, % extrapolation is as a constant function where % this is consistent with the neighboring nodes. % % method == 5 --+ See method 2, but use an average % of the 8 nearest neighbors to any element. % This method is NOT recommended for use. % % % arguments (output): % B - nxm array with NaNs replaced % % % Example: % [x,y] = meshgrid(0:.01:1); % z0 = exp(x+y); % znan = z0; % znan(20:50,40:70) = NaN; % znan(30:90,5:10) = NaN; % znan(70:75,40:90) = NaN; % % z = inpaint_nans(znan); % % % See also: griddata, interp1 % % Author: John D'Errico % e-mail address: woodchips@rochester.rr.com % Release: 2 % Release date: 4/15/06 % I always need to know which elements are NaN, % and what size the array is for any method [n,m]=size(A); A=A(:); nm=n*m; k=isnan(A(:)); % list the nodes which are known, and which will % be interpolated nan_list=find(k); known_list=find(~k); % how many nans overall nan_count=length(nan_list); % convert NaN indices to (r,c) form % nan_list==find(k) are the unrolled (linear) indices % (row,column) form [nr,nc]=ind2sub([n,m],nan_list); % both forms of index in one array: % column 1 == unrolled index % column 2 == row index % column 3 == column index nan_list=[nan_list,nr,nc]; % supply default method if (nargin<2) || isempty(method) method = 0; elseif ~ismember(method,0:5) error 'If supplied, method must be one of: {0,1,2,3,4,5}.' end % for different methods switch method case 0 % The same as method == 1, except only work on those % elements which are NaN, or at least touch a NaN. % is it 1-d or 2-d? if (m == 1) || (n == 1) % really a 1-d case work_list = nan_list(:,1); work_list = unique([work_list;work_list - 1;work_list + 1]); work_list(work_list <= 1) = []; work_list(work_list >= nm) = []; nw = numel(work_list); u = (1:nw)'; fda = sparse(repmat(u,1,3),bsxfun(@plus,work_list,-1:1), ... repmat([1 -2 1],nw,1),nw,nm); else % a 2-d case % horizontal and vertical neighbors only talks_to = [-1 0;0 -1;1 0;0 1]; neighbors_list=identify_neighbors(n,m,nan_list,talks_to); % list of all nodes we have identified all_list=[nan_list;neighbors_list]; % generate sparse array with second partials on row % variable for each element in either list, but only % for those nodes which have a row index > 1 or < n L = find((all_list(:,2) > 1) & (all_list(:,2) < n)); nl=length(L); if nl>0 fda=sparse(repmat(all_list(L,1),1,3), ... repmat(all_list(L,1),1,3)+repmat([-1 0 1],nl,1), ... repmat([1 -2 1],nl,1),nm,nm); else fda=spalloc(n*m,n*m,size(all_list,1)*5); end % 2nd partials on column index L = find((all_list(:,3) > 1) & (all_list(:,3) < m)); nl=length(L); if nl>0 fda=fda+sparse(repmat(all_list(L,1),1,3), ... repmat(all_list(L,1),1,3)+repmat([-n 0 n],nl,1), ... repmat([1 -2 1],nl,1),nm,nm); end end % eliminate knowns rhs=-fda(:,known_list)*A(known_list); k=find(any(fda(:,nan_list(:,1)),2)); % and solve... B=A; B(nan_list(:,1))=fda(k,nan_list(:,1))\rhs(k); case 1 % least squares approach with del^2. Build system % for every array element as an unknown, and then % eliminate those which are knowns. % Build sparse matrix approximating del^2 for % every element in A. % is it 1-d or 2-d? if (m == 1) || (n == 1) % a 1-d case u = (1:(nm-2))'; fda = sparse(repmat(u,1,3),bsxfun(@plus,u,0:2), ... repmat([1 -2 1],nm-2,1),nm-2,nm); else % a 2-d case % Compute finite difference for second partials % on row variable first [i,j]=ndgrid(2:(n-1),1:m); ind=i(:)+(j(:)-1)*n; np=(n-2)*m; fda=sparse(repmat(ind,1,3),[ind-1,ind,ind+1], ... repmat([1 -2 1],np,1),n*m,n*m); % now second partials on column variable [i,j]=ndgrid(1:n,2:(m-1)); ind=i(:)+(j(:)-1)*n; np=n*(m-2); fda=fda+sparse(repmat(ind,1,3),[ind-n,ind,ind+n], ... repmat([1 -2 1],np,1),nm,nm); end % eliminate knowns rhs=-fda(:,known_list)*A(known_list); k=find(any(fda(:,nan_list),2)); % and solve... B=A; B(nan_list(:,1))=fda(k,nan_list(:,1))\rhs(k); case 2 % Direct solve for del^2 BVP across holes % generate sparse array with second partials on row % variable for each nan element, only for those nodes % which have a row index > 1 or < n % is it 1-d or 2-d? if (m == 1) || (n == 1) % really just a 1-d case error('Method 2 has problems for vector input. Please use another method.') else % a 2-d case L = find((nan_list(:,2) > 1) & (nan_list(:,2) < n)); nl=length(L); if nl>0 fda=sparse(repmat(nan_list(L,1),1,3), ... repmat(nan_list(L,1),1,3)+repmat([-1 0 1],nl,1), ... repmat([1 -2 1],nl,1),n*m,n*m); else fda=spalloc(n*m,n*m,size(nan_list,1)*5); end % 2nd partials on column index L = find((nan_list(:,3) > 1) & (nan_list(:,3) < m)); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,3), ... repmat(nan_list(L,1),1,3)+repmat([-n 0 n],nl,1), ... repmat([1 -2 1],nl,1),n*m,n*m); end % fix boundary conditions at extreme corners % of the array in case there were nans there if ismember(1,nan_list(:,1)) fda(1,[1 2 n+1])=[-2 1 1]; end if ismember(n,nan_list(:,1)) fda(n,[n, n-1,n+n])=[-2 1 1]; end if ismember(nm-n+1,nan_list(:,1)) fda(nm-n+1,[nm-n+1,nm-n+2,nm-n])=[-2 1 1]; end if ismember(nm,nan_list(:,1)) fda(nm,[nm,nm-1,nm-n])=[-2 1 1]; end % eliminate knowns rhs=-fda(:,known_list)*A(known_list); % and solve... B=A; k=nan_list(:,1); B(k)=fda(k,k)\rhs(k); end case 3 % The same as method == 0, except uses del^4 as the % interpolating operator. % del^4 template of neighbors talks_to = [-2 0;-1 -1;-1 0;-1 1;0 -2;0 -1; ... 0 1;0 2;1 -1;1 0;1 1;2 0]; neighbors_list=identify_neighbors(n,m,nan_list,talks_to); % list of all nodes we have identified all_list=[nan_list;neighbors_list]; % generate sparse array with del^4, but only % for those nodes which have a row & column index % >= 3 or <= n-2 L = find( (all_list(:,2) >= 3) & ... (all_list(:,2) <= (n-2)) & ... (all_list(:,3) >= 3) & ... (all_list(:,3) <= (m-2))); nl=length(L); if nl>0 % do the entire template at once fda=sparse(repmat(all_list(L,1),1,13), ... repmat(all_list(L,1),1,13) + ... repmat([-2*n,-n-1,-n,-n+1,-2,-1,0,1,2,n-1,n,n+1,2*n],nl,1), ... repmat([1 2 -8 2 1 -8 20 -8 1 2 -8 2 1],nl,1),nm,nm); else fda=spalloc(n*m,n*m,size(all_list,1)*5); end % on the boundaries, reduce the order around the edges L = find((((all_list(:,2) == 2) | ... (all_list(:,2) == (n-1))) & ... (all_list(:,3) >= 2) & ... (all_list(:,3) <= (m-1))) | ... (((all_list(:,3) == 2) | ... (all_list(:,3) == (m-1))) & ... (all_list(:,2) >= 2) & ... (all_list(:,2) <= (n-1)))); nl=length(L); if nl>0 fda=fda+sparse(repmat(all_list(L,1),1,5), ... repmat(all_list(L,1),1,5) + ... repmat([-n,-1,0,+1,n],nl,1), ... repmat([1 1 -4 1 1],nl,1),nm,nm); end L = find( ((all_list(:,2) == 1) | ... (all_list(:,2) == n)) & ... (all_list(:,3) >= 2) & ... (all_list(:,3) <= (m-1))); nl=length(L); if nl>0 fda=fda+sparse(repmat(all_list(L,1),1,3), ... repmat(all_list(L,1),1,3) + ... repmat([-n,0,n],nl,1), ... repmat([1 -2 1],nl,1),nm,nm); end L = find( ((all_list(:,3) == 1) | ... (all_list(:,3) == m)) & ... (all_list(:,2) >= 2) & ... (all_list(:,2) <= (n-1))); nl=length(L); if nl>0 fda=fda+sparse(repmat(all_list(L,1),1,3), ... repmat(all_list(L,1),1,3) + ... repmat([-1,0,1],nl,1), ... repmat([1 -2 1],nl,1),nm,nm); end % eliminate knowns rhs=-fda(:,known_list)*A(known_list); k=find(any(fda(:,nan_list(:,1)),2)); % and solve... B=A; B(nan_list(:,1))=fda(k,nan_list(:,1))\rhs(k); case 4 % Spring analogy % interpolating operator. % list of all springs between a node and a horizontal % or vertical neighbor hv_list=[-1 -1 0;1 1 0;-n 0 -1;n 0 1]; hv_springs=[]; for i=1:4 hvs=nan_list+repmat(hv_list(i,:),nan_count,1); k=(hvs(:,2)>=1) & (hvs(:,2)<=n) & (hvs(:,3)>=1) & (hvs(:,3)<=m); hv_springs=[hv_springs;[nan_list(k,1),hvs(k,1)]]; end % delete replicate springs hv_springs=unique(sort(hv_springs,2),'rows'); % build sparse matrix of connections, springs % connecting diagonal neighbors are weaker than % the horizontal and vertical springs nhv=size(hv_springs,1); springs=sparse(repmat((1:nhv)',1,2),hv_springs, ... repmat([1 -1],nhv,1),nhv,nm); % eliminate knowns rhs=-springs(:,known_list)*A(known_list); % and solve... B=A; B(nan_list(:,1))=springs(:,nan_list(:,1))\rhs; case 5 % Average of 8 nearest neighbors % generate sparse array to average 8 nearest neighbors % for each nan element, be careful around edges fda=spalloc(n*m,n*m,size(nan_list,1)*9); % -1,-1 L = find((nan_list(:,2) > 1) & (nan_list(:,3) > 1)); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,2), ... repmat(nan_list(L,1),1,2)+repmat([-n-1, 0],nl,1), ... repmat([1 -1],nl,1),n*m,n*m); end % 0,-1 L = find(nan_list(:,3) > 1); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,2), ... repmat(nan_list(L,1),1,2)+repmat([-n, 0],nl,1), ... repmat([1 -1],nl,1),n*m,n*m); end % +1,-1 L = find((nan_list(:,2) < n) & (nan_list(:,3) > 1)); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,2), ... repmat(nan_list(L,1),1,2)+repmat([-n+1, 0],nl,1), ... repmat([1 -1],nl,1),n*m,n*m); end % -1,0 L = find(nan_list(:,2) > 1); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,2), ... repmat(nan_list(L,1),1,2)+repmat([-1, 0],nl,1), ... repmat([1 -1],nl,1),n*m,n*m); end % +1,0 L = find(nan_list(:,2) < n); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,2), ... repmat(nan_list(L,1),1,2)+repmat([1, 0],nl,1), ... repmat([1 -1],nl,1),n*m,n*m); end % -1,+1 L = find((nan_list(:,2) > 1) & (nan_list(:,3) < m)); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,2), ... repmat(nan_list(L,1),1,2)+repmat([n-1, 0],nl,1), ... repmat([1 -1],nl,1),n*m,n*m); end % 0,+1 L = find(nan_list(:,3) < m); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,2), ... repmat(nan_list(L,1),1,2)+repmat([n, 0],nl,1), ... repmat([1 -1],nl,1),n*m,n*m); end % +1,+1 L = find((nan_list(:,2) < n) & (nan_list(:,3) < m)); nl=length(L); if nl>0 fda=fda+sparse(repmat(nan_list(L,1),1,2), ... repmat(nan_list(L,1),1,2)+repmat([n+1, 0],nl,1), ... repmat([1 -1],nl,1),n*m,n*m); end % eliminate knowns rhs=-fda(:,known_list)*A(known_list); % and solve... B=A; k=nan_list(:,1); B(k)=fda(k,k)\rhs(k); end % all done, make sure that B is the same shape as % A was when we came in. B=reshape(B,n,m); % ==================================================== % end of main function % ==================================================== % ==================================================== % begin subfunctions % ==================================================== function neighbors_list=identify_neighbors(n,m,nan_list,talks_to) % identify_neighbors: identifies all the neighbors of % those nodes in nan_list, not including the nans % themselves % % arguments (input): % n,m - scalar - [n,m]=size(A), where A is the % array to be interpolated % nan_list - array - list of every nan element in A % nan_list(i,1) == linear index of i'th nan element % nan_list(i,2) == row index of i'th nan element % nan_list(i,3) == column index of i'th nan element % talks_to - px2 array - defines which nodes communicate % with each other, i.e., which nodes are neighbors. % % talks_to(i,1) - defines the offset in the row % dimension of a neighbor % talks_to(i,2) - defines the offset in the column % dimension of a neighbor % % For example, talks_to = [-1 0;0 -1;1 0;0 1] % means that each node talks only to its immediate % neighbors horizontally and vertically. % % arguments(output): % neighbors_list - array - list of all neighbors of % all the nodes in nan_list if ~isempty(nan_list) % use the definition of a neighbor in talks_to nan_count=size(nan_list,1); talk_count=size(talks_to,1); nn=zeros(nan_count*talk_count,2); j=[1,nan_count]; for i=1:talk_count nn(j(1):j(2),:)=nan_list(:,2:3) + ... repmat(talks_to(i,:),nan_count,1); j=j+nan_count; end % drop those nodes which fall outside the bounds of the % original array L = (nn(:,1)<1)|(nn(:,1)>n)|(nn(:,2)<1)|(nn(:,2)>m); nn(L,:)=[]; % form the same format 3 column array as nan_list neighbors_list=[sub2ind([n,m],nn(:,1),nn(:,2)),nn]; % delete replicates in the neighbors list neighbors_list=unique(neighbors_list,'rows'); % and delete those which are also in the list of NaNs. neighbors_list=setdiff(neighbors_list,nan_list,'rows'); else neighbors_list=[]; end \ No newline at end of file diff --git a/auxiliary/boundedline/Inpaint_nans/inpaint_nans_bc.m b/auxiliary/boundedline/Inpaint_nans/inpaint_nans_bc.m new file mode 100755 index 0000000..d6ae57e --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/inpaint_nans_bc.m @@ -0,0 +1 @@ +function B=inpaint_nans_bc(A,method,bcclass) % INPAINT_NANS_BC: in-paints over nans in an array, with spherical or toroidal boundary conditions % usage: B=inpaint_nsns_bc(A) % default method % usage: B=inpaint_nsns_bc(A,method) % specify method used % usage: B=inpaint_nsns_bc(A,method,bcclass) % specify class of boundary conditions applied % % Solves approximation to one of several pdes to % interpolate and extrapolate holes in an array. % Depending upon the boundary conditions specified, % the array will effectively be treated as if it lies % on either the surface of a sphere or a toroid. % % arguments (input): % A - nxm array with some NaNs to be filled in % % method - (OPTIONAL) scalar numeric flag - specifies % which approach (or physical metaphor to use % for the interpolation.) All methods are capable % of extrapolation, some are better than others. % There are also speed differences, as well as % accuracy differences for smooth surfaces. % % The methods employed here are a subset of the % methods of the original inpaint_nans. % % methods {0,1} use a simple plate metaphor. % method 4 uses a spring metaphor. % % method == 0 --> (DEFAULT) see method 1, but % this method does not build as large of a % linear system in the case of only a few % NaNs in a large array. % Extrapolation behavior is linear. % % method == 1 --> simple approach, applies del^2 % over the entire array, then drops those parts % of the array which do not have any contact with % NaNs. Uses a least squares approach, but it % does not modify known values. % In the case of small arrays, this method is % quite fast as it does very little extra work. % Extrapolation behavior is linear. % % method == 4 --> Uses a spring metaphor. Assumes % springs (with a nominal length of zero) % connect each node with every neighbor % (horizontally, vertically and diagonally) % Since each node tries to be like its neighbors, % extrapolation is as a constant function where % this is consistent with the neighboring nodes. % % DEFAULT: 0 % % bcclass - (OPTIONAL) character flag, indicating how % the array boundaries will be treated in the % inpainting operation. bcclass may be either % 'sphere' or 'toroid', or any simple contraction % of these words. % % bcclass = 'sphere' --> The first and last rows % of the array will be treated as if they are % at the North and South poles of a sphere. % Adjacent to those rows will be singular % phantom nodes at each pole. % % bcclass = 'toroid' --> The first and last rows % of the array will be treated as if they are % adjacent to ech other. As well, the first and % last columns will be adjacent to each other. % % DEFAULT: 'sphere' % % arguments (output): % B - nxm array with NaNs replaced % % % Example: % [x,y] = meshgrid(0:.01:1); % z0 = exp(x+y); % znan = z0; % znan(20:50,40:70) = NaN; % znan(30:90,5:10) = NaN; % znan(70:75,40:90) = NaN; % % z = inpaint_nans(znan); % % % See also: griddata, interp1 % % Author: John D'Errico % e-mail address: woodchips@rochester.rr.com % Release: 2 % Release date: 4/15/06 % I always need to know which elements are NaN, % and what size the array is for any method [n,m]=size(A); A=A(:); nm=n*m; k=isnan(A(:)); % list those nodes which are known, and which will % be interpolated nan_list=find(k); known_list=find(~k); % how many nans overall nan_count=length(nan_list); % convert NaN indices to (r,c) form % nan_list==find(k) are the unrolled (linear) indices % (row,column) form [nr,nc]=ind2sub([n,m],nan_list); % both forms of index in one array: % column 1 == unrolled index % column 2 == row index % column 3 == column index nan_list=[nan_list,nr,nc]; % supply default method if (nargin<2) || isempty(method) method = 0; elseif ~ismember(method,[0 1 4]) error('INPAINT_NANS_BC:improperargument', ... 'If supplied, method must be one of: {0,1,4}.') end % supply default value for bcclass if (nargin < 3) || isempty(bcclass) bcclass = 'sphere'; elseif ~ischar(bcclass) error('INPAINT_NANS_BC:improperargument', ... 'If supplied, bcclass must be ''sphere'' or ''toroid''') else % it was a character string valid = {'sphere' 'toroid'}; % check to see if it is valid [bcclass,errorclass] = validstring(arg,valid); if ~isempty(errorclass) error('INPAINT_NANS_BC:improperargument', ... 'If supplied, bcclass must be ''sphere'' or ''toroid''') end end % choice of methods switch method case 0 % The same as method == 1, except only work on those % elements which are NaN, or at least touch a NaN. % horizontal and vertical neighbors only talks_to = [-1 0;0 -1;1 0;0 1]; neighbors_list=identify_neighbors(n,m,nan_list,talks_to); % list of all nodes we have identified all_list=[nan_list;neighbors_list]; % generate sparse array with second partials on row % variable for each element in either list, but only % for those nodes which have a row index > 1 or < n L = find((all_list(:,2) > 1) & (all_list(:,2) < n)); nl=length(L); if nl>0 fda=sparse(repmat(all_list(L,1),1,3), ... repmat(all_list(L,1),1,3)+repmat([-1 0 1],nl,1), ... repmat([1 -2 1],nl,1),nm,nm); else fda=spalloc(n*m,n*m,size(all_list,1)*5); end % 2nd partials on column index L = find((all_list(:,3) > 1) & (all_list(:,3) < m)); nl=length(L); if nl>0 fda=fda+sparse(repmat(all_list(L,1),1,3), ... repmat(all_list(L,1),1,3)+repmat([-n 0 n],nl,1), ... repmat([1 -2 1],nl,1),nm,nm); end % eliminate knowns rhs=-fda(:,known_list)*A(known_list); k=find(any(fda(:,nan_list(:,1)),2)); % and solve... B=A; B(nan_list(:,1))=fda(k,nan_list(:,1))\rhs(k); case 1 % least squares approach with del^2. Build system % for every array element as an unknown, and then % eliminate those which are knowns. % Build sparse matrix approximating del^2 for % every element in A. % Compute finite difference for second partials % on row variable first [i,j]=ndgrid(1:n,1:m); ind=i(:)+(j(:)-1)*n; np=n*m; switch bcclass case 'sphere' % we need to have two phantom nodes at the poles np = np + 2; end fda=sparse(repmat(ind,1,3),[ind-1,ind,ind+1], ... repmat([1 -2 1],np,1),n*m,n*m); % now second partials on column variable [i,j]=ndgrid(1:n,2:(m-1)); ind=i(:)+(j(:)-1)*n; np=n*(m-2); fda=fda+sparse(repmat(ind,1,3),[ind-n,ind,ind+n], ... repmat([1 -2 1],np,1),nm,nm); % eliminate knowns rhs=-fda(:,known_list)*A(known_list); k=find(any(fda(:,nan_list),2)); % and solve... B=A; B(nan_list(:,1))=fda(k,nan_list(:,1))\rhs(k); case 4 % Spring analogy % interpolating operator. % list of all springs between a node and a horizontal % or vertical neighbor hv_list=[-1 -1 0;1 1 0;-n 0 -1;n 0 1]; hv_springs=[]; for i=1:4 hvs=nan_list+repmat(hv_list(i,:),nan_count,1); k=(hvs(:,2)>=1) & (hvs(:,2)<=n) & (hvs(:,3)>=1) & (hvs(:,3)<=m); hv_springs=[hv_springs;[nan_list(k,1),hvs(k,1)]]; end % delete replicate springs hv_springs=unique(sort(hv_springs,2),'rows'); % build sparse matrix of connections, springs % connecting diagonal neighbors are weaker than % the horizontal and vertical springs nhv=size(hv_springs,1); springs=sparse(repmat((1:nhv)',1,2),hv_springs, ... repmat([1 -1],nhv,1),nhv,nm); % eliminate knowns rhs=-springs(:,known_list)*A(known_list); % and solve... B=A; B(nan_list(:,1))=springs(:,nan_list(:,1))\rhs; end % all done, make sure that B is the same shape as % A was when we came in. B=reshape(B,n,m); end % mainline % ==================================================== % end of main function % ==================================================== % ==================================================== % begin subfunctions % ==================================================== function neighbors_list=identify_neighbors(n,m,nan_list,talks_to) % identify_neighbors: identifies all the neighbors of % those nodes in nan_list, not including the nans % themselves % % arguments (input): % n,m - scalar - [n,m]=size(A), where A is the % array to be interpolated % nan_list - array - list of every nan element in A % nan_list(i,1) == linear index of i'th nan element % nan_list(i,2) == row index of i'th nan element % nan_list(i,3) == column index of i'th nan element % talks_to - px2 array - defines which nodes communicate % with each other, i.e., which nodes are neighbors. % % talks_to(i,1) - defines the offset in the row % dimension of a neighbor % talks_to(i,2) - defines the offset in the column % dimension of a neighbor % % For example, talks_to = [-1 0;0 -1;1 0;0 1] % means that each node talks only to its immediate % neighbors horizontally and vertically. % % arguments(output): % neighbors_list - array - list of all neighbors of % all the nodes in nan_list if ~isempty(nan_list) % use the definition of a neighbor in talks_to nan_count=size(nan_list,1); talk_count=size(talks_to,1); nn=zeros(nan_count*talk_count,2); j=[1,nan_count]; for i=1:talk_count nn(j(1):j(2),:)=nan_list(:,2:3) + ... repmat(talks_to(i,:),nan_count,1); j=j+nan_count; end % form the same format 3 column array as nan_list neighbors_list=[sub2ind([n,m],nn(:,1),nn(:,2)),nn]; % delete replicates in the neighbors list neighbors_list=unique(neighbors_list,'rows'); % and delete those which are also in the list of NaNs. neighbors_list=setdiff(neighbors_list,nan_list,'rows'); else neighbors_list=[]; end end % function identify_neighbors function [str,errorclass] = validstring(arg,valid) % validstring: compares a string against a set of valid options % usage: [str,errorclass] = validstring(arg,valid) % % If a direct hit, or any unambiguous shortening is found, that % string is returned. Capitalization is ignored. % % arguments: (input) % arg - character string, to be tested against a list % of valid choices. Capitalization is ignored. % % valid - cellstring array of alternative choices % % Arguments: (output) % str - string - resulting choice resolved from the % list of valid arguments. If no unambiguous % choice can be resolved, then str will be empty. % % errorclass - string - A string argument that explains % the error. It will be one of the following % possibilities: % % '' --> No error. An unambiguous match for arg % was found among the choices. % % 'No match found' --> No match was found among % the choices provided in valid. % % 'Ambiguous argument' --> At least two ambiguous % matches were found among those provided % in valid. % % % Example: % valid = {'off' 'on' 'The sky is falling'} % % % See also: parse_pv_pairs, strmatch, strcmpi % % Author: John D'Errico % e-mail: woodchips@rochester.rr.com % Release: 1.0 % Release date: 3/25/2010 ind = strmatch(lower(arg),lower(valid)); if isempty(ind) % No hit found errorclass = 'No match found'; str = ''; elseif (length(ind) > 1) % Ambiguous arg, hitting more than one of the valid options errorclass = 'Ambiguous argument'; str = ''; return else errorclass = ''; str = valid{ind}; end end % function validstring \ No newline at end of file diff --git a/auxiliary/boundedline/Inpaint_nans/inpaint_nans_demo.m b/auxiliary/boundedline/Inpaint_nans/inpaint_nans_demo.m new file mode 100755 index 0000000..2163cc0 --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/inpaint_nans_demo.m @@ -0,0 +1,43 @@ +%% Surface Fit Artifact Removal + +%% Construct the Surface +[x,y] = meshgrid(0:.01:1); +z0 = exp(x+y); + +close all +figure +surf(z0) +title 'Original surface' + +znan = z0; +znan(20:50,40:70) = NaN; +znan(30:90,5:10) = NaN; +znan(70:75,40:90) = NaN; + +figure +surf(znan) +title 'Artifacts (large holes) in surface' + +%% In-paint Over NaNs +z = inpaint_nans(znan,3); +figure +surf(z) +title 'Inpainted surface' + +figure +surf(z-z0) +title 'Inpainting error surface (Note z-axis scale)' + +%% Comapre to GRIDDATA +k = isnan(znan); +zk = griddata(x(~k),y(~k),z(~k),x(k),y(k)); +zg = znan; +zg(k) = zk; + +figure +surf(zg) +title(['Griddata inpainting (',num2str(sum(isnan(zg(:)))),' NaNs remain)']) + +figure +surf(zg-z0) +title 'Griddata error surface' diff --git a/auxiliary/boundedline/Inpaint_nans/monet_adresse.jpg b/auxiliary/boundedline/Inpaint_nans/monet_adresse.jpg new file mode 100755 index 0000000..bceff7e Binary files /dev/null and b/auxiliary/boundedline/Inpaint_nans/monet_adresse.jpg differ diff --git a/auxiliary/boundedline/Inpaint_nans/test/test_main.m b/auxiliary/boundedline/Inpaint_nans/test/test_main.m new file mode 100755 index 0000000..1dde28e --- /dev/null +++ b/auxiliary/boundedline/Inpaint_nans/test/test_main.m @@ -0,0 +1,178 @@ +%% Repair to an image with 50% random artifacts + +% Garden at Sainte-Adresse (Monet, 1867) +garden = imread('monet_adresse.jpg'); +G = double(garden); +G(rand(size(G))<0.50) = NaN; +Gnan = G; + +G(:,:,1) = inpaint_nans(G(:,:,1),2); +G(:,:,2) = inpaint_nans(G(:,:,2),2); +G(:,:,3) = inpaint_nans(G(:,:,3),2); + +figure +subplot(1,3,1) +image(garden) +title 'Garden at Sainte-Adresse (Monet)' + +subplot(1,3,2) +image(uint8(Gnan)) +title 'Corrupted - 50%' + +subplot(1,3,3) +image(uint8(G)) +title 'Inpainted Garden' + +%% Surface fit artifact removal + +[x,y] = meshgrid(0:.01:1); +z0 = exp(x+y); + +znan = z0; +znan(20:50,40:70) = NaN; +znan(30:90,5:10) = NaN; +znan(70:75,40:90) = NaN; + +tic,z = inpaint_nans(znan,3);toc + +tic +k = isnan(znan); +zk = griddata(x(~k),y(~k),z(~k),x(k),y(k)); +zg = znan; +zg(k) = zk; +toc + +figure +surf(z0) +title 'Original surface' + +figure +surf(znan) +title 'Artifacts (large holes) in surface' + +figure +surf(zg) +title(['Griddata inpainting (',num2str(sum(isnan(zg(:)))),' NaNs remain)']) + +figure +surf(z) +title 'Inpainted surface' + +figure +surf(zg-z0) +title 'Griddata error surface' + +figure +surf(z-z0) +title 'Inpainting error surface (Note z-axis scale)' + +%% Comparison of methods + +[x,y] = meshgrid(-1:.02:1); +r = sqrt(x.^2 + y.^2); +z = exp(-(x.^2+ y.^2)); + +z(r>=0.9) = NaN; + +z((r<=.5) & (x<0)) = NaN; + +figure +pcolor(z); +title 'Surface provided to inpaint_nans' + +% Method 0 +tic,z0 = inpaint_nans(z,0);toc + +% Method 1 +tic,z1 = inpaint_nans(z,1);toc + +% Method 2 +tic,z2 = inpaint_nans(z,2);toc + +% Method 3 +tic,z3 = inpaint_nans(z,3);toc + +% Method 4 +tic,z4 = inpaint_nans(z,4);toc + +% Method 5 +tic,z5 = inpaint_nans(z,5);toc + +figure +surf(z0) +colormap copper +hold on +h = surf(z); +set(h,'facecolor','r') +hold off +title 'Method 0 (Red was provided)' + +figure +surf(z1) +hold on +h = surf(z); +set(h,'facecolor','r') +hold off +title 'Method 1 (Red was provided)' + +figure +surf(z2) +hold on +h = surf(z); +set(h,'facecolor','r') +hold off +title 'Method 2 (Red was provided) - least accurate, but fastest' + +figure +surf(z3) +hold on +h = surf(z); +set(h,'facecolor','r') +hold off +title 'Method 3 (Red was provided) - Slow, but accurate' + +figure +surf(z4) +hold on +h = surf(z); +set(h,'facecolor','r') +hold off +title 'Method 4 (Red was provided) - designed for constant extrapolation!' + +figure +h = surf(z5); +set(h,'facecolor','y') +hold on +h = surf(z); +set(h,'facecolor','r') +hold off +title 'Method 5 (Red was provided)' + + +%% 1-d "inpainting" using interp1 + +x = linspace(0,3*pi,100); +y0 = sin(x); +y = y0; +% Drop out 2/3 of the data +y(1:3:end) = NaN; +y(2:3:end) = NaN; + +% inpaint_nans +y_inpaint = inpaint_nans(y,1); + +% interpolate using interp1 +k = isnan(y); +y_interp1c = y; +y_interp1s = y; +y_interp1c(k) = interp1(x(~k),y(~k),x(k),'cubic'); +y_interp1s(k) = interp1(x(~k),y(~k),x(k),'spline'); + +figure +plot(x,y,'ro',x,y_inpaint,'b+') +legend('sin(x), missing 2/3 points','inpaint-nans','Location','North') + +figure +plot(x,y0-y_inpaint,'r-',x,y0-y_interp1c,'b--',x,y0-y_interp1s,'g--') +title 'Inpainting residuals' +legend('Inpaint-nans','Pchip','Spline','Location','North') diff --git a/auxiliary/boundedline/README.md b/auxiliary/boundedline/README.md new file mode 100755 index 0000000..4adc2a7 --- /dev/null +++ b/auxiliary/boundedline/README.md @@ -0,0 +1,88 @@ +## boundeline.m Documentation + +The boundedline function is a Matlab utility to plot error bounds, confidence intervals, etc. for a line or lines. Advantages include: +- allows x-y input similar to plot, where one call can create multiple lines at once, either by listing consecutive x-y pairs or by using using matrices for x and/or y. +- can add bounds in either the x- or y-direction, leading to support of plots where the x axis represents the dependent variable +- can render the shaded bounds either with transparency or as a lighter opaque patch, allowing flexibility with different renderers (helpful when OpenGL acts up, as it often does on my own computer). +- Can use linespec definitions, a colormap, or the default color order, as well as varying color intensity for the shaded bounds, for flexible color of lines and bounds +- returns handles of lines and patches for future modification if necessary + +### Syntax + +``` +[hl, hp] = boundedline(x, y, b) +[hl, hp] = boundedline(x, y, b, linespec) +[hl, hp] = boundedline(x1, y1, b1, linespec1, x2, y2, b2, linespec2) +[hl, hp] = boundedline(..., 'alpha') +[hl, hp] = boundedline(..., ax) +[hl, hp] = boundedline(..., 'transparency', trans) +[hl, hp] = boundedline(..., 'orientation', orient) +[hl, hp] = boundedline(..., 'cmap', cmap) +``` + +See function help for description of input and output variables. + +### Examples + +Plot with opaque bounds. In this example, the bounds on the first line +vary over x, while the bounds on the second line are constant for all x. +An outline is added to the bounds so the overlapping region can be seen +more clearly. + +```matlab +x = linspace(0, 2*pi, 50); +y1 = sin(x); +y2 = cos(x); +e1 = rand(size(y1))*.5+.5; +e2 = [.25 .5]; + +ax(1) = subplot(2,2,1); +[l,p] = boundedline(x, y1, e1, '-b*', x, y2, e2, '--ro'); +outlinebounds(l,p); +title('Opaque bounds, with outline'); +``` +![boundedline1](boundedline_readme_01.png) + + +For our second axis, we use the same 2 lines, and this time assign +x-varying bounds to both lines. Rather than using the LineSpec syntax, +this example uses the default color order to assign the colors of the +lines and patches. + +```matlab +ax(2) = subplot(2,2,2); +boundedline(x, [y1;y2], rand(length(y1),2,2)*.5+.5, 'alpha'); +title('Transparent bounds'); +``` + +![boundedline2](boundedline_readme_02.png) + +The bounds can also be assigned to a horizontal orientation, for a case +where the x-axis represents the dependent variable. In this case, the +scalar error bound value applies to both lines and both sides of the +lines. + +```matlab +ax(3) = subplot(2,2,3); +boundedline([y1;y2], x, e1(1), 'orientation', 'horiz') +title('Horizontal bounds'); +``` + +![boundedline3](boundedline_readme_03.png) + + Rather than use a LineSpec or the default color order, a colormap array + can be used to assign colors. In this case, increasingly-narrower bounds + are added on top of the same line. + +```matlab +ax(4) = subplot(2,2,4); +boundedline(x, repmat(y1, 4,1), permute(0.5:-0.1:0.2, [3 1 2]), ... + 'cmap', cool(4), ... + 'transparency', 0.5); +title('Multiple bounds using colormap'); + +set(ax([1 2 4]), 'xlim', [0 2*pi]); +set(ax(3), 'ylim', [0 2*pi]); +``` + +![boundedline4](boundedline_readme_04.png) diff --git a/auxiliary/boundedline/boundedline/.gitignore b/auxiliary/boundedline/boundedline/.gitignore new file mode 100755 index 0000000..e492200 --- /dev/null +++ b/auxiliary/boundedline/boundedline/.gitignore @@ -0,0 +1,37 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/auxiliary/boundedline/boundedline/boundedline.m b/auxiliary/boundedline/boundedline/boundedline.m new file mode 100755 index 0000000..c94b597 --- /dev/null +++ b/auxiliary/boundedline/boundedline/boundedline.m @@ -0,0 +1,466 @@ +function varargout = boundedline(varargin) +%BOUNDEDLINE Plot a line with shaded error/confidence bounds +% +% [hl, hp] = boundedline(x, y, b) +% [hl, hp] = boundedline(x, y, b, linespec) +% [hl, hp] = boundedline(x1, y1, b1, linespec1, x2, y2, b2, linespec2) +% [hl, hp] = boundedline(..., 'alpha') +% [hl, hp] = boundedline(..., ax) +% [hl, hp] = boundedline(..., 'transparency', trans) +% [hl, hp] = boundedline(..., 'orientation', orient) +% [hl, hp] = boundedline(..., 'nan', nanflag) +% [hl, hp] = boundedline(..., 'cmap', cmap) +% +% Input variables: +% +% x, y: x and y values, either vectors of the same length, matrices +% of the same size, or vector/matrix pair where the row or +% column size of the array matches the length of the vector +% (same requirements as for plot function). +% +% b: npoint x nside x nline array. Distance from line to +% boundary, for each point along the line (dimension 1), for +% each side of the line (lower/upper or left/right, depending +% on orientation) (dimension 2), and for each plotted line +% described by the preceding x-y values (dimension 3). If +% size(b,1) == 1, the bounds will be the same for all points +% along the line. If size(b,2) == 1, the bounds will be +% symmetrical on both sides of the lines. If size(b,3) == 1, +% the same bounds will be applied to all lines described by +% the preceding x-y arrays (only applicable when either x or +% y is an array). Bounds cannot include Inf, -Inf, or NaN, +% +% linespec: line specification that determines line type, marker +% symbol, and color of the plotted lines for the preceding +% x-y values. +% +% 'alpha': if included, the bounded area will be rendered with a +% partially-transparent patch the same color as the +% corresponding line(s). If not included, the bounded area +% will be an opaque patch with a lighter shade of the +% corresponding line color. +% +% ax: handle of axis where lines will be plotted. If not +% included, the current axis will be used. +% +% transp: Scalar between 0 and 1 indicating with the transparency or +% intensity of color of the bounded area patch. Default is +% 0.2. +% +% orient: direction to add bounds +% 'vert': add bounds in vertical (y) direction (default) +% 'horiz': add bounds in horizontal (x) direction +% +% nanflag: Sets how NaNs in the boundedline patch should be handled +% 'fill': fill the value based on neighboring values, +% smoothing over the gap +% 'gap': leave a blank space over/below the line +% 'remove': drop NaNs from patches, creating a linear +% interpolation over the gap. Note that this +% applies only to the bounds; NaNs in the line will +% remain. +% +% cmap: n x 3 colormap array. If included, lines will be colored +% (in order of plotting) according to this colormap, +% overriding any linespec or default colors. +% +% Output variables: +% +% hl: handles to line objects +% +% hp: handles to patch objects +% +% Example: +% +% x = linspace(0, 2*pi, 50); +% y1 = sin(x); +% y2 = cos(x); +% e1 = rand(size(y1))*.5+.5; +% e2 = [.25 .5]; +% +% ax(1) = subplot(2,2,1); +% [l,p] = boundedline(x, y1, e1, '-b*', x, y2, e2, '--ro'); +% outlinebounds(l,p); +% title('Opaque bounds, with outline'); +% +% ax(2) = subplot(2,2,2); +% boundedline(x, [y1;y2], rand(length(y1),2,2)*.5+.5, 'alpha'); +% title('Transparent bounds'); +% +% ax(3) = subplot(2,2,3); +% boundedline([y1;y2], x, e1(1), 'orientation', 'horiz') +% title('Horizontal bounds'); +% +% ax(4) = subplot(2,2,4); +% boundedline(x, repmat(y1, 4,1), permute(0.5:-0.1:0.2, [3 1 2]), ... +% 'cmap', cool(4), 'transparency', 0.5); +% title('Multiple bounds using colormap'); + + +% Copyright 2010 Kelly Kearney + +%-------------------- +% Parse input +%-------------------- + +% Alpha flag + +isalpha = cellfun(@(x) ischar(x) && strcmp(x, 'alpha'), varargin); +if any(isalpha) + usealpha = true; + varargin = varargin(~isalpha); +else + usealpha = false; +end + +% Axis + +isax = cellfun(@(x) isscalar(x) && ishandle(x) && strcmp('axes', get(x,'type')), varargin); +if any(isax) + hax = varargin{isax}; + varargin = varargin(~isax); +else + hax = gca; +end + +% Transparency + +[found, trans, varargin] = parseparam(varargin, 'transparency'); + +if ~found + trans = 0.2; +end + +if ~isscalar(trans) || trans < 0 || trans > 1 + error('Transparency must be scalar between 0 and 1'); +end + +% Orientation + +[found, orient, varargin] = parseparam(varargin, 'orientation'); + +if ~found + orient = 'vert'; +end + +if strcmp(orient, 'vert') + isvert = true; +elseif strcmp(orient, 'horiz') + isvert = false; +else + error('Orientation must be ''vert'' or ''horiz'''); +end + + +% Colormap + +[hascmap, cmap, varargin] = parseparam(varargin, 'cmap'); + + +% NaN flag + +[found, nanflag, varargin] = parseparam(varargin, 'nan'); +if ~found + nanflag = 'fill'; +end +if ~ismember(nanflag, {'fill', 'gap', 'remove'}) + error('Nan flag must be ''fill'', ''gap'', or ''remove'''); +end + +% X, Y, E triplets, and linespec + +[x,y,err,linespec] = deal(cell(0)); +while ~isempty(varargin) + if length(varargin) < 3 + error('Unexpected input: should be x, y, bounds triplets'); + end + if all(cellfun(@isnumeric, varargin(1:3))) + x = [x varargin(1)]; + y = [y varargin(2)]; + err = [err varargin(3)]; + varargin(1:3) = []; + else + error('Unexpected input: should be x, y, bounds triplets'); + end + if ~isempty(varargin) && ischar(varargin{1}) + linespec = [linespec varargin(1)]; + varargin(1) = []; + else + linespec = [linespec {[]}]; + end +end + +%-------------------- +% Reformat x and y +% for line and patch +% plotting +%-------------------- + +% Calculate y values for bounding lines + +plotdata = cell(0,7); + +htemp = figure('visible', 'off'); +for ix = 1:length(x) + + % Get full x, y, and linespec data for each line (easier to let plot + % check for properly-sized x and y and expand values than to try to do + % it myself) + + try + if isempty(linespec{ix}) + hltemp = plot(x{ix}, y{ix}); + else + hltemp = plot(x{ix}, y{ix}, linespec{ix}); + end + catch + close(htemp); + error('X and Y matrices and/or linespec not appropriate for line plot'); + end + + linedata = get(hltemp, {'xdata', 'ydata', 'marker', 'linestyle', 'color'}); + + nline = size(linedata,1); + + % Expand bounds matrix if necessary + + if nline > 1 + if ndims(err{ix}) == 3 + err2 = squeeze(num2cell(err{ix},[1 2])); + else + err2 = repmat(err(ix),nline,1); + end + else + err2 = err(ix); + end + + % Figure out upper and lower bounds + + [lo, hi] = deal(cell(nline,1)); + for iln = 1:nline + + x2 = linedata{iln,1}; + y2 = linedata{iln,2}; + nx = length(x2); + + if isvert + lineval = y2; + else + lineval = x2; + end + + sz = size(err2{iln}); + + if isequal(sz, [nx 2]) + lo{iln} = lineval - err2{iln}(:,1)'; + hi{iln} = lineval + err2{iln}(:,2)'; + elseif isequal(sz, [nx 1]) + lo{iln} = lineval - err2{iln}'; + hi{iln} = lineval + err2{iln}'; + elseif isequal(sz, [1 2]) + lo{iln} = lineval - err2{iln}(1); + hi{iln} = lineval + err2{iln}(2); + elseif isequal(sz, [1 1]) + lo{iln} = lineval - err2{iln}; + hi{iln} = lineval + err2{iln}; + elseif isequal(sz, [2 nx]) % not documented, but accepted anyways + lo{iln} = lineval - err2{iln}(:,1); + hi{iln} = lineval + err2{iln}(:,2); + elseif isequal(sz, [1 nx]) % not documented, but accepted anyways + lo{iln} = lineval - err2{iln}; + hi{iln} = lineval + err2{iln}; + elseif isequal(sz, [2 1]) % not documented, but accepted anyways + lo{iln} = lineval - err2{iln}(1); + hi{iln} = lineval + err2{iln}(2); + else + error('Error bounds must be npt x nside x nline array'); + end + + end + + % Combine all data (xline, yline, marker, linestyle, color, lower bound + % (x or y), upper bound (x or y) + + plotdata = [plotdata; linedata lo hi]; + +end +close(htemp); + +% Override colormap + +if hascmap + nd = size(plotdata,1); + cmap = repmat(cmap, ceil(nd/size(cmap,1)), 1); + cmap = cmap(1:nd,:); + plotdata(:,5) = num2cell(cmap,2); +end + + +%-------------------- +% Plot +%-------------------- + +% Setup of x and y, plus line and patch properties + +nline = size(plotdata,1); +[xl, yl, xp, yp, marker, lnsty, lncol, ptchcol, alpha] = deal(cell(nline,1)); + +for iln = 1:nline + xl{iln} = plotdata{iln,1}; + yl{iln} = plotdata{iln,2}; +% if isvert +% xp{iln} = [plotdata{iln,1} fliplr(plotdata{iln,1})]; +% yp{iln} = [plotdata{iln,6} fliplr(plotdata{iln,7})]; +% else +% xp{iln} = [plotdata{iln,6} fliplr(plotdata{iln,7})]; +% yp{iln} = [plotdata{iln,2} fliplr(plotdata{iln,2})]; +% end + + [xp{iln}, yp{iln}] = calcpatch(plotdata{iln,1}, plotdata{iln,2}, isvert, plotdata{iln,6}, plotdata{iln,7}, nanflag); + + marker{iln} = plotdata{iln,3}; + lnsty{iln} = plotdata{iln,4}; + + if usealpha + lncol{iln} = plotdata{iln,5}; + ptchcol{iln} = plotdata{iln,5}; + alpha{iln} = trans; + else + lncol{iln} = plotdata{iln,5}; + ptchcol{iln} = interp1([0 1], [1 1 1; lncol{iln}], trans); + alpha{iln} = 1; + end +end + +% Plot patches and lines + +if verLessThan('matlab', '8.4.0') + [hp,hl] = deal(zeros(nline,1)); +else + [hp,hl] = deal(gobjects(nline,1)); +end + + +for iln = 1:nline + hp(iln) = patch(xp{iln}, yp{iln}, ptchcol{iln}, 'facealpha', alpha{iln}, 'edgecolor', 'none', 'parent', hax); +end + +for iln = 1:nline + hl(iln) = line(xl{iln}, yl{iln}, 'marker', marker{iln}, 'linestyle', lnsty{iln}, 'color', lncol{iln}, 'parent', hax); +end + +%-------------------- +% Assign output +%-------------------- + +nargoutchk(0,2); + +if nargout >= 1 + varargout{1} = hl; +end + +if nargout == 2 + varargout{2} = hp; +end + +%-------------------- +% Parse optional +% parameters +%-------------------- + +function [found, val, vars] = parseparam(vars, param) + +isvar = cellfun(@(x) ischar(x) && strcmpi(x, param), vars); + +if sum(isvar) > 1 + error('Parameters can only be passed once'); +end + +if any(isvar) + found = true; + idx = find(isvar); + val = vars{idx+1}; + vars([idx idx+1]) = []; +else + found = false; + val = []; +end + +%---------------------------- +% Calculate patch coordinates +%---------------------------- + +function [xp, yp] = calcpatch(xl, yl, isvert, lo, hi, nanflag) + +ismissing = isnan([xl;yl;lo;hi]); + +% If gap method, split + +if any(ismissing(:)) && strcmp(nanflag, 'gap') + + tmp = [xl;yl;lo;hi]; + + idx = find(any(ismissing,1)); + n = diff([0 idx length(xl)]); + + tmp = mat2cell(tmp, 4, n); + isemp = cellfun('isempty', tmp); + tmp = tmp(~isemp); + + tmp = cellfun(@(a) a(:,~any(isnan(a),1)), tmp, 'uni', 0); + isemp = cellfun('isempty', tmp); + tmp = tmp(~isemp); + + xl = cellfun(@(a) a(1,:), tmp, 'uni', 0); + yl = cellfun(@(a) a(2,:), tmp, 'uni', 0); + lo = cellfun(@(a) a(3,:), tmp, 'uni', 0); + hi = cellfun(@(a) a(4,:), tmp, 'uni', 0); +else + xl = {xl}; + yl = {yl}; + lo = {lo}; + hi = {hi}; +end + +[xp, yp] = deal(cell(size(xl))); + +for ii = 1:length(xl) + + iseq = ~verLessThan('matlab', '8.4.0') && isequal(lo{ii}, hi{ii}); % deal with zero-width bug in R2014b/R2015a + + if isvert + if iseq + xp{ii} = [xl{ii} nan(size(xl{ii}))]; + yp{ii} = [lo{ii} fliplr(hi{ii})]; + else + xp{ii} = [xl{ii} fliplr(xl{ii})]; + yp{ii} = [lo{ii} fliplr(hi{ii})]; + end + else + if iseq + xp{ii} = [lo{ii} fliplr(hi{ii})]; + yp{ii} = [yl{ii} nan(size(yl{ii}))]; + else + xp{ii} = [lo{ii} fliplr(hi{ii})]; + yp{ii} = [yl{ii} fliplr(yl{ii})]; + end + end + + if strcmp(nanflag, 'fill') + xp{ii} = inpaint_nans(xp{ii}', 4); + yp{ii} = inpaint_nans(yp{ii}', 4); + elseif strcmp(nanflag, 'remove') + isn = isnan(xp{ii}) | isnan(yp{ii}); + xp{ii} = xp{ii}(~isn); + yp{ii} = yp{ii}(~isn); + end + +end + +if strcmp(nanflag, 'gap') + [xp, yp] = singlepatch(xp, yp); +else + xp = xp{1}; + yp = yp{1}; +end + diff --git a/auxiliary/boundedline/boundedline/outlinebounds.m b/auxiliary/boundedline/boundedline/outlinebounds.m new file mode 100755 index 0000000..36724bd --- /dev/null +++ b/auxiliary/boundedline/boundedline/outlinebounds.m @@ -0,0 +1,43 @@ +function hnew = outlinebounds(hl, hp) +%OUTLINEBOUNDS Outline the patch of a boundedline +% +% hnew = outlinebounds(hl, hp) +% +% This function adds an outline to the patch objects created by +% boundedline, matching the color of the central line associated with each +% patch. +% +% Input variables: +% +% hl: handles to line objects from boundedline +% +% hp: handles to patch objects from boundedline +% +% Output variables: +% +% hnew: handle to new line objects + +% Copyright 2012 Kelly Kearney + + +hnew = zeros(size(hl)); +for il = 1:numel(hp) + col = get(hl(il), 'color'); + xy = get(hp(il), {'xdata','ydata'}); + ax = ancestor(hl(il), 'axes'); + + nline = size(xy{1},2); + if mod(size(xy{1}, 1), 2) == 0 + % Insert a NaN between upper and lower lines, so they're disconnected + L = size(xy{1}, 1) / 2; + xy{1} = [xy{1}(1:L, :); nan(1, nline); xy{1}(L+1:end, :)]; + xy{2} = [xy{2}(1:L, :); nan(1, nline); xy{2}(L+1:end, :)]; + end + if nline > 1 + xy{1} = reshape([xy{1}; nan(1,nline)], [], 1); + xy{2} = reshape([xy{2}; nan(1,nline)], [], 1); + end + hnew(il) = line(xy{1}, xy{2}, 'parent', ax, 'linestyle', '-', 'color', col); + +end + diff --git a/auxiliary/boundedline/boundedline_readme.png b/auxiliary/boundedline/boundedline_readme.png new file mode 100755 index 0000000..c125d08 Binary files /dev/null and b/auxiliary/boundedline/boundedline_readme.png differ diff --git a/auxiliary/boundedline/boundedline_readme_01.png b/auxiliary/boundedline/boundedline_readme_01.png new file mode 100755 index 0000000..60c15b1 Binary files /dev/null and b/auxiliary/boundedline/boundedline_readme_01.png differ diff --git a/auxiliary/boundedline/boundedline_readme_02.png b/auxiliary/boundedline/boundedline_readme_02.png new file mode 100755 index 0000000..d955b68 Binary files /dev/null and b/auxiliary/boundedline/boundedline_readme_02.png differ diff --git a/auxiliary/boundedline/boundedline_readme_03.png b/auxiliary/boundedline/boundedline_readme_03.png new file mode 100755 index 0000000..588a2fa Binary files /dev/null and b/auxiliary/boundedline/boundedline_readme_03.png differ diff --git a/auxiliary/boundedline/boundedline_readme_04.png b/auxiliary/boundedline/boundedline_readme_04.png new file mode 100755 index 0000000..9808fb8 Binary files /dev/null and b/auxiliary/boundedline/boundedline_readme_04.png differ diff --git a/auxiliary/boundedline/catuneven/.gitignore b/auxiliary/boundedline/catuneven/.gitignore new file mode 100755 index 0000000..e492200 --- /dev/null +++ b/auxiliary/boundedline/catuneven/.gitignore @@ -0,0 +1,37 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/auxiliary/boundedline/catuneven/catuneven.m b/auxiliary/boundedline/catuneven/catuneven.m new file mode 100755 index 0000000..c63439a --- /dev/null +++ b/auxiliary/boundedline/catuneven/catuneven.m @@ -0,0 +1,53 @@ +function b = catuneven(dim, padval, varargin) +%CATUNEVEN Concatenate unequally-sized arrays, padding with a value +% +% This function is similar to cat, except it does not require the arrays to +% be equally-sized along non-concatenated dimensions. Instead, all arrays +% are padded to be equally-sized using the value specified. +% +% b = catuneven(dim, padval, a1, a2, ...) +% +% Input variables: +% +% dim: dimension along which to concatenate +% +% padval: value used as placeholder when arrays are expanded +% +% a#: arrays to be concatenated, numerical +% +% Output variables: +% +% b: concatenated array + +% Copyright 2013 Kelly Kearney + +ndim = max(cellfun(@ndims, varargin)); +ndim = max(ndim, dim); + +for ii = 1:ndim + sz(:,ii) = cellfun(@(x) size(x, ii), varargin); +end +maxsz = max(sz, [], 1); + +nv = length(varargin); +val = cell(size(varargin)); +for ii = 1:nv + sztmp = maxsz; + sztmp(dim) = sz(ii,dim); + + idx = cell(ndim,1); + [idx{:}] = ind2sub(sz(ii,:), 1:numel(varargin{ii})); + + idxnew = sub2ind(sztmp, idx{:}); + + val{ii} = ones(sztmp) * padval; + val{ii}(idxnew) = varargin{ii}; + +end + +b = cat(dim, val{:}); + + + + + diff --git a/auxiliary/boundedline/singlepatch/.gitignore b/auxiliary/boundedline/singlepatch/.gitignore new file mode 100755 index 0000000..e492200 --- /dev/null +++ b/auxiliary/boundedline/singlepatch/.gitignore @@ -0,0 +1,37 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/auxiliary/boundedline/singlepatch/singlepatch.m b/auxiliary/boundedline/singlepatch/singlepatch.m new file mode 100755 index 0000000..d7258e3 --- /dev/null +++ b/auxiliary/boundedline/singlepatch/singlepatch.m @@ -0,0 +1,65 @@ +function varargout = singlepatch(varargin) +%SINGLEPATCH Concatenate patches to be plotted as one +% +% [xp, yp, zp, ...] = singlepatch(x, y, z, ...) +% +% Concatenates uneven vectors of x and y coordinates by replicating the +% last point in each polygon. This allows patches with different numbers +% of vertices to be plotted as one, which is often much, much more +% efficient than plotting lots of individual patches. +% +% Input variables: +% +% x: cell array, with each cell holding a vector of coordinates +% associates with a single patch. The input variables must all be +% of the same size, and usually will correspond to x, y, z, and c +% data for the patches. +% +% Output variables: +% +% xp: m x n array of coordinates, where m is the maximum length of the +% vectors in x and n is numel(x). + +% Copyright 2015 Kelly Kearney + +if nargin ~= nargout + error('Must supply the same number of input variables as output variables'); +end + +nv = nargin; +vars = varargin; + +sz = cellfun(@size, vars{1}(:), 'uni', 0); +sz = cat(1, sz{:}); + +if all(sz(:,1) == 1) + for ii = 1:nv + vars{ii} = catuneven(1, NaN, vars{ii}{:})'; + end +% x = catuneven(1, NaN, x{:})'; +% y = catuneven(1, NaN, y{:})'; +elseif all(sz(:,2) == 1) + for ii = 1:nv + vars{ii} = catuneven(2, NaN, vars{ii}{:}); + end +% x = catuneven(2, NaN, x{:}); +% y = catuneven(2, NaN, y{:}); +else + error('Inputs must be cell arrays of vectors'); +end + +[ii,jj] = find(isnan(vars{1})); + +ind = accumarray(jj, ii, [size(vars{1},2) 1], @min); +ij1 = [ii jj]; +ij2 = [ind(jj)-1 jj]; +idx1 = sub2ind(size(vars{1}), ij1(:,1), ij1(:,2)); +idx2 = sub2ind(size(vars{1}), ij2(:,1), ij2(:,2)); + +for ii = 1:nv + vars{ii}(idx1) = vars{ii}(idx2); +end + +varargout = vars; + + diff --git a/auxiliary/calcAdditionalData.m b/auxiliary/calcAdditionalData.m old mode 100644 new mode 100755 diff --git a/auxiliary/calculateDerivatives.m b/auxiliary/calculateDerivatives.m old mode 100644 new mode 100755 diff --git a/auxiliary/convertIDsToNames.m b/auxiliary/convertIDsToNames.m old mode 100644 new mode 100755 diff --git a/auxiliary/csvimport.m b/auxiliary/csvimport.m old mode 100644 new mode 100755 diff --git a/auxiliary/data_importer.m b/auxiliary/data_importer.m old mode 100644 new mode 100755 diff --git a/auxiliary/exportForParameterEst.m b/auxiliary/exportForParameterEst.m old mode 100644 new mode 100755 diff --git a/auxiliary/expression_endtime.m b/auxiliary/expression_endtime.m old mode 100644 new mode 100755 diff --git a/auxiliary/expression_rate.m b/auxiliary/expression_rate.m old mode 100644 new mode 100755 diff --git a/auxiliary/expression_rate_peak.m b/auxiliary/expression_rate_peak.m old mode 100644 new mode 100755 diff --git a/auxiliary/findStringInAList.m b/auxiliary/findStringInAList.m old mode 100644 new mode 100755 diff --git a/auxiliary/getDefaultMergedExpFileStruct.m b/auxiliary/getDefaultMergedExpFileStruct.m old mode 100644 new mode 100755 diff --git a/auxiliary/getStdMean.m b/auxiliary/getStdMean.m old mode 100644 new mode 100755 diff --git a/auxiliary/globalize_params.m b/auxiliary/globalize_params.m new file mode 100755 index 0000000..0a628c2 --- /dev/null +++ b/auxiliary/globalize_params.m @@ -0,0 +1,77 @@ +function [m] = globalize_params(m) +% globalize_params change the scope of all the parameters from the reaction +% to the model. +% delete the locally scoped parameters and add parameters at the model +% object level. +% Vipul Singhal, Nov 2017 + +% main loop over all the reactions +R = length(m.reactions); +for r = 1:R + + rx = m.reactions(r); % reaction class object + + % check if the reaction has an internal parameter object. + if ~isempty(rx.KineticLaw.Parameters) + % nothing to do if there are no reaction scoped parameters. + + % get the parameter names + % parnames = get(rx.kineticlaw.getparameters, 'Name'); % dont need to use this. + % use this instead: + parnames = rx.KineticLaw.ParameterVariableNames; + + % for each paramter name, get its value, then delete it. + P = length(parnames); + pvals = zeros(1, P); + for p = 1:P + % get the parameter values (to copy over to the global params) + pvals(p) = rx.KineticLaw.Parameters(p).Value; + % alt: get(rx.kineticlaw.getparameters, 'Value'), this returns a + % cell array of numbers, also put this outside the P loop. + end + + for p = 1:P + % delete the parameter objects + pTarget = sbioselect(rx, 'type', 'parameter', 'Name', parnames{p}); + pTarget.delete; + end + % Note that deleting the parameter objects does not remove the + % parameter variable name property of the KineticLaw object. + + % now if reversible, setup the Kd parameter and the rule that Kd=kr/kf + if rx.Reversible + + parname_base = parnames{1}(1:end-2); + + % assume a form like TXTL_UTR_UTR1_F, and so we want to remove the '_F' at the end. + %todo: check if this is the format of all the parameters. + if isempty(sbioselect(m,'Type','Parameter', 'Name', [parname_base '_Kd'])) + addparameter(m, [parname_base '_Kd'], pvals(2)/pvals(1)) ; + end + + if isempty(sbioselect(m,'Type','Parameter', 'Name', parnames{1})) + addparameter(m, parnames{1}, pvals(1)); + end + + if isempty(sbioselect(m,'Type','Parameter', 'Name', parnames{2})) + addparameter(m, parnames{2}, pvals(2)) ; + end + + ruleStr = [parnames{2} ' = ' parname_base '_Kd*' parnames{1}]; + if isempty(sbioselect(m,'Type','Rule', 'Rule', ruleStr)) + addrule(m, ruleStr, 'initialAssignment'); + end + else + % irreversible reaction, just add the parameter to the model scope. + % + if isempty(sbioselect(m,'Type','Parameter', 'Name', parnames{1})) + addparameter(m, parnames{1}, pvals(1)); + end + + end + end + +end + +end + diff --git a/auxiliary/herrorbar.m b/auxiliary/herrorbar.m old mode 100644 new mode 100755 diff --git a/auxiliary/hverrorbar.m b/auxiliary/hverrorbar.m old mode 100644 new mode 100755 diff --git a/auxiliary/integrateMGData.m b/auxiliary/integrateMGData.m old mode 100644 new mode 100755 diff --git a/auxiliary/lhsu.m b/auxiliary/lhsu.m old mode 100644 new mode 100755 diff --git a/auxiliary/listmodelparts.m b/auxiliary/listmodelparts.m new file mode 100755 index 0000000..01886e1 --- /dev/null +++ b/auxiliary/listmodelparts.m @@ -0,0 +1,15 @@ +function listmodelparts(m) +%listmodelparts list the insides of a model +% list the species, the reactions, the global parameters, the parameters +% and which reactions they are tied to, the rules and the events. +% input: model object, m. + +m.species +m.Reactions +m.Parameters +gp = getparam(m); +gp(:, [1, 3]) +m.Rules +m.Events +end + diff --git a/auxiliary/mergeWholeExpFile.m b/auxiliary/mergeWholeExpFile.m old mode 100644 new mode 100755 diff --git a/auxiliary/parseGetEqOutput.m b/auxiliary/parseGetEqOutput.m old mode 100644 new mode 100755 diff --git a/auxiliary/plotCustomSpecies.m b/auxiliary/plotCustomSpecies.m old mode 100644 new mode 100755 diff --git a/auxiliary/plotCustomSpecies2.m b/auxiliary/plotCustomSpecies2.m old mode 100644 new mode 100755 index 3db2005..8d7bfde --- a/auxiliary/plotCustomSpecies2.m +++ b/auxiliary/plotCustomSpecies2.m @@ -1,12 +1,23 @@ function varargout = plotCustomSpecies2(mobj, x_ode, t_ode, cellofspecies, varargin) -% plotting routine: input list of species, mobj cell array, data cell array, title containing what is being plotted and what speie is being varied, and cell array of parameter values +% plotting routine: input list of species, mobj cell array, data cell array, +% title containing what is being plotted and what speie is being varied, +% and cell array of parameter values numvarargs = length(varargin); -optargs = {{}, [],[],[]}; +optargs = {{}, [],[],[], []}; optargs(1:numvarargs) = varargin; -[legendList, saveflag, folderName, figureName] = optargs{:}; +[legendList, saveflag, folderName, figureName, fighandle] = optargs{:}; scrsz = get(0,'screensize'); - figure('position',[50 50 scrsz(3)/1.1 scrsz(4)/1.3])%,'name','simulation plot window','numbertitle','off') + if ~isempty(fighandle) + figure(fighandle )%,'name','simulation plot window','numbertitle','off') + set(fighandle, 'position',[50 50 scrsz(3)/1.1 scrsz(4)/1.3]); + + else + figure( 'position',[50 50 scrsz(3)/1.1 scrsz(4)/1.3]) + %,'name','simulation plot window','numbertitle','off') + end + + if iscell(mobj) colororder1 = lines; @@ -69,7 +80,8 @@ else - warning('txtltoolbox:plotcustomspecies','mobj and other things must be cell arrays, noting will be plotted') + warning('txtltoolbox:plotcustomspecies',... + 'mobj and other things must be cell arrays, nothing will be plotted') end diff --git a/auxiliary/plotEverything.m b/auxiliary/plotEverything.m old mode 100644 new mode 100755 diff --git a/auxiliary/processMGData.m b/auxiliary/processMGData.m old mode 100644 new mode 100755 diff --git a/auxiliary/processProteinData.m b/auxiliary/processProteinData.m old mode 100644 new mode 100755 diff --git a/auxiliary/replaceMissingData.m b/auxiliary/replaceMissingData.m old mode 100644 new mode 100755 diff --git a/auxiliary/stdshade.m b/auxiliary/stdshade.m old mode 100644 new mode 100755 diff --git a/auxiliary/strjoin.m b/auxiliary/strjoin.m old mode 100644 new mode 100755 diff --git a/auxiliary/twofactors.m b/auxiliary/twofactors.m new file mode 100755 index 0000000..079d40f --- /dev/null +++ b/auxiliary/twofactors.m @@ -0,0 +1,11 @@ +function [num1, num2] = twofactors(n) +%twofactors decompose a number into approximately equal factors +% if prime, just return 1 and number itself +% Vipul singhal +pf = factor(n); +numpf = length(pf); +mid = ceil(numpf/2); +num1 = prod(pf(1:mid)); +num2 = prod(pf(mid+1:end)); +end + diff --git a/auxiliary/wholeExpfileReader.m b/auxiliary/wholeExpfileReader.m old mode 100644 new mode 100755 diff --git a/components/txtl_5UTR_bcd2.m b/components/txtl_5UTR_bcd2.m old mode 100644 new mode 100755 diff --git a/components/txtl_5UTR_utr1.m b/components/txtl_5UTR_utr1.m old mode 100644 new mode 100755 diff --git a/components/txtl_5UTR_utr1b.m b/components/txtl_5UTR_utr1b.m new file mode 100644 index 0000000..4f9a026 --- /dev/null +++ b/components/txtl_5UTR_utr1b.m @@ -0,0 +1,84 @@ +% txtl_5UTR_utr1b.m - UTR1b ribosome binding site file +% VS, Aug 2017 +% +% This file contains a description of the UTR1 ribosome binding site. +% Calling the function txtl_5UTR_UTR1b() will set up the reactions for +% translation with the measured binding rates and translation rates. + +% Written by Vipul Singhal 2017 +% +% Copyright (c) 2012 by California Institute of Technology +% All rights reserved. +% +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are +% met: +% +% 1. Redistributions of source code must retain the above copyright +% notice, this list of conditions and the following disclaimer. +% +% 2. Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in the +% documentation and/or other materials provided with the distribution. +% +% 3. The name of the author may not be used to endorse or promote products +% derived from this software without specific prior written permission. +% +% THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +% IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +% DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +% INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +% STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +% IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +% POSSIBILITY OF SUCH DAMAGE. + +function varargout = txtl_5UTR_utr1b(mode, tube, rna, protein, varargin) + + % Create strings for reactants and products + RNA = ['[' rna.Name ']']; % RNA species name for reactions + Ribobound = ['Ribo:' rna.Name]; % Name of bound complex + + % importing the corresponding parameters + paramObj = txtl_component_config('utr1b'); + +%%%%%%%%%%%%%%%%%%% DRIVER MODE: Setup Species %%%%%%%%%%%%%%%%%%%%%%%%%%%% +if strcmp(mode.add_dna_driver, 'Setup Species') + + utrRbsData = varargin{1}; + defaultBasePairs = {'rbs','spacer';paramObj.RBS_Length,paramObj.spacer_Length}; + utrRbsData = txtl_setup_default_basepair_length(tube,utrRbsData,defaultBasePairs); + RiboBound = ['Ribo:' rna.Name]; + coreSpecies = {'Ribo',RiboBound}; + % empty cellarray for amount => zero amount + txtl_addspecies(tube, coreSpecies, cell(1,size(coreSpecies,2)), 'Internal'); + varargout{1} = sbioselect(tube, 'Name', RiboBound); + varargout{2} = utrRbsData; + +%%%%%%%%%%%%%%%%%%% DRIVER MODE: Setup Reactions %%%%%%%%%%%%%%%%%%%%%%%%%% +elseif strcmp(mode.add_dna_driver, 'Setup Reactions') + + % Set up the binding reaction + txtl_addreaction(tube,['[' rna.Name '] + Ribo <-> [Ribo:' rna.Name ']'],... + 'MassAction',{'TXTL_UTR_UTR1_F',paramObj.Ribosome_Binding_F; + 'TXTL_UTR_UTR1_R',paramObj.Ribosome_Binding_R}); + + + + + + +%%%%%%%%%%%%%%%%%%% DRIVER MODE: error handling %%%%%%%%%%%%%%%%%%%%%%%%%%% +else + error('txtltoolbox:txtl_5UTR_utr1:undefinedmode', ... + 'The possible modes are ''Setup Species'' and ''Setup Reactions''.'); +end + +% Automatically use MATLAB mode in Emacs (keep at end of file) +% Local variables: +% mode: matlab +% End: + diff --git a/components/txtl_param_AraC.csv b/components/txtl_param_AraC.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_ClpP.csv b/components/txtl_param_ClpP.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_ClpX.csv b/components/txtl_param_ClpX.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_LuxR_REMOVE.csv b/components/txtl_param_LuxR_REMOVE.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_NRII_H139N.csv b/components/txtl_param_NRII_H139N.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_NRII_L16R.csv b/components/txtl_param_NRII_L16R.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_RFP.csv b/components/txtl_param_RFP.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_bcd2.csv b/components/txtl_param_bcd2.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_cLambda.csv b/components/txtl_param_cLambda.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_deCFP.csv b/components/txtl_param_deCFP.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_deGFP.csv b/components/txtl_param_deGFP.csv index 2241015..93ba93e 100644 --- a/components/txtl_param_deGFP.csv +++ b/components/txtl_param_deGFP.csv @@ -3,4 +3,4 @@ Gene_Length, Numeric, 674 LVA_tag_Length, Numeric, 40 Terminator_Length, Numeric, 30 -Protein_Maturation, Expression, log(2)/(5*60), protein maturation rate is 5 min +Protein_Maturation, Expression, 0.0023001, diff --git a/components/txtl_param_lacI.csv b/components/txtl_param_lacI.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_lasR.csv b/components/txtl_param_lasR.csv index 6d7b672..fa9e931 100644 --- a/components/txtl_param_lasR.csv +++ b/components/txtl_param_lasR.csv @@ -2,6 +2,6 @@ Gene_Length, Numeric, 647 LVA_tag_Length, Numeric, 40 Terminator_Length, Numeric, 100 -Protein_Inducer_Forward, Numeric, 2e-1, V. Sotiropoulos 2007 BMC Sys Bio Table 1 -Protein_Inducer_Reverse, Numeric, 0.05, V. Sotiropoulos 2007 BMC Sys Bio Table 1 +Protein_Inducer_Forward, Numeric, 1, +Protein_Inducer_Reverse, Numeric, 4.4241e+05, Inducer_Degradation, Numeric, 2.67e-6, diff --git a/components/txtl_param_luxR.csv b/components/txtl_param_luxR.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_p28_tetR.csv b/components/txtl_param_p28_tetR.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_p70.csv b/components/txtl_param_p70.csv index 55a40e6..1f2e2f6 100644 --- a/components/txtl_param_p70.csv +++ b/components/txtl_param_p70.csv @@ -1,5 +1,5 @@ -RNAPbound_Forward, Numeric, 20, -RNAPbound_Reverse, Numeric, 400, calculated +RNAPbound_Forward, Numeric, 4.4817 , exp(1.5) +RNAPbound_Reverse, Numeric, 729416 , R = KD*F old was 2074 Promoter_Length, Numeric, 55 Thio_Length, Numeric, 500 diff --git a/components/txtl_param_p70pr1.csv b/components/txtl_param_p70pr1.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_pBAD.csv b/components/txtl_param_pBAD.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_pGlnA.csv b/components/txtl_param_pGlnA.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_pJ23119.csv b/components/txtl_param_pJ23119.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_pOR1OR2.csv b/components/txtl_param_pOR1OR2_REMOVE.csv old mode 100644 new mode 100755 similarity index 100% rename from components/txtl_param_pOR1OR2.csv rename to components/txtl_param_pOR1OR2_REMOVE.csv diff --git a/components/txtl_param_pOR2OR1.csv b/components/txtl_param_pOR2OR1.csv new file mode 100644 index 0000000..fcc11de --- /dev/null +++ b/components/txtl_param_pOR2OR1.csv @@ -0,0 +1,9 @@ +RNAPbound_Forward, Expression, 4.4817, +RNAPbound_Reverse, Expression, 3.5015e+06, + +Promoter_Length, Numeric, 50 +Thio_Length, Numeric, 500 +Junk_Length, Numeric, 0 + +DNA_Sequestration_F, Numeric, 2.5e-1, V. Sotiropoulos 2007 BMC Sys Bio Table 1 12.86e-1 +DNA_Sequestration_R, Numeric, 1.11e-4, V. Sotiropoulos 2007 BMC Sys Bio Table 1 1.11e-4 diff --git a/components/txtl_param_plac.csv b/components/txtl_param_plac.csv index cd66ba1..e07f177 100644 --- a/components/txtl_param_plac.csv +++ b/components/txtl_param_plac.csv @@ -1,5 +1,5 @@ -RNAPbound_Forward, Expression, 20, -RNAPbound_Reverse, Expression, 400, +RNAPbound_Forward, Expression, 4.4817, +RNAPbound_Reverse, Expression, 1.6276e+05, Promoter_Length, Numeric, 50 Thio_Length, Numeric, 500 diff --git a/components/txtl_param_plambda.csv b/components/txtl_param_plambda.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_plas.csv b/components/txtl_param_plas.csv index 2ebeb5d..b33d547 100644 --- a/components/txtl_param_plas.csv +++ b/components/txtl_param_plas.csv @@ -1,13 +1,13 @@ -RNAPbound_Forward, Expression, 0.001, estimate -RNAPbound_Reverse, Expression, 10, estimate +RNAPbound_Forward, Expression, 1, TXTL_PLAS_RNAPbound_F +RNAPbound_Reverse, Expression, 1.0686e+13, TXTL_PLAS_RNAPbound_R -RNAPbound_Forward_actv, Expression, 20, estimate -RNAPbound_Reverse_actv, Expression, 400, estimate +RNAPbound_Forward_actv, Expression, 1, TXTL_PLAS_TFRNAPbound_F +RNAPbound_Reverse_actv, Expression, 2981, TXTL_PLAS_TFRNAPbound_R Promoter_Length, Numeric, 100 Thio_Length, Numeric, 500 Junk_Length, Numeric, 0 -activation_F, Numeric, 1 -activation_R, Numeric, 0.02 +activation_F, Numeric, 1, TXTL_PLAS_TFBIND_F +activation_R, Numeric, 148.41, TXTL_PLAS_TFBIND_R diff --git a/components/txtl_param_plas_ptet.csv b/components/txtl_param_plas_ptet.csv index 0127082..98f0032 100644 --- a/components/txtl_param_plas_ptet.csv +++ b/components/txtl_param_plas_ptet.csv @@ -1,8 +1,8 @@ -RNAPbound_Forward, Expression, 20, estimate plasR -RNAPbound_Reverse, Expression, 400, estimate +RNAPbound_Forward, Expression, 1, TXTL_PLAS_RNAPbound_F +RNAPbound_Reverse, Expression, 1.0686e+13, TXTL_PLAS_RNAPbound_R -RNAPbound_Forward_2, Expression, 20, estimate ptet -RNAPbound_Reverse_2, Expression, 400, estimate +RNAPbound_Forward_2, Expression, 4.4817, UNUSED +RNAPbound_Reverse_2, Expression, 2.3739e+09, UNUSED Promoter_Length, Numeric, 100 Thio_Length, Numeric, 500 @@ -11,23 +11,15 @@ Gene_Length, Numeric, 647 LVA_tag_Length, Numeric, 40 Terminator_Length, Numeric, 100 -Protein_Inducer_Forward, Numeric, 2e-1, 3OC12HSL -Protein_Inducer_Reverse, Numeric, 0.05, -Inducer_Degradation, Numeric, 2.67e-6, +activation_F, Numeric, 1, 3OC12HSL TXTL_PLAS_TFBIND_F +activation_R, Numeric, 148.41, TXTL_PLAS_TFBIND_R -Protein_Inducer_Forward_2, Numeric, 1e-5, aTc -Protein_Inducer_Reverse_2, Numeric, 1.0e-1, -Inducer_Degradation_2, Numeric, 2.67e-8, +RNAPbound_Forward_actv, Numeric, 1, 3OC12HSL TXTL_PLAS_TFRNAPbound_F +RNAPbound_Reverse_actv, Numeric, 2981, TXTL_PLAS_TFRNAPbound_R -activation_F, Numeric, 1, 3OC12HSL -activation_R, Numeric, 0.02 +DNA_Sequestration_F, Numeric, 3.721, TXTL_PTET_sequestration_F +DNA_Sequestration_R, Numeric, 2.2569, TXTL_PTET_sequestration_R -RNAPbound_Forward_actv, Numeric, 1, 3OC12HSL -RNAPbound_Reverse_actv, Numeric, 0.02 - -DNA_Sequestration_F, Numeric, 2.5e-1, from ptet file -DNA_Sequestration_R, Numeric, 1.11e-4, - -Combinatorial_activ_knockoff_F, Numeric, 1, document or estimate, -Combinatorial_activ_knockoff_R, Numeric, 0.1, document or estimate, +Combinatorial_activ_knockoff_F, Numeric, 4.0363e+08, TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F, +Combinatorial_activ_knockoff_R, Numeric, 1, TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F, diff --git a/components/txtl_param_plux.csv b/components/txtl_param_plux.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_ptet.csv b/components/txtl_param_ptet.csv index 3053c9d..fb184e3 100644 --- a/components/txtl_param_ptet.csv +++ b/components/txtl_param_ptet.csv @@ -1,9 +1,9 @@ -RNAPbound_Forward, Expression, 20, -RNAPbound_Reverse, Expression, 400, +RNAPbound_Forward, Expression, 4.4817, +RNAPbound_Reverse, Expression, 2.3739e+09, Promoter_Length, Numeric, 50 Thio_Length, Numeric, 500 Junk_Length, Numeric, 0 -DNA_Sequestration_F, Numeric, 2.5e-1, V. Sotiropoulos 2007 BMC Sys Bio Table 1 12.86e-1 -DNA_Sequestration_R, Numeric, 1.11e-4, V. Sotiropoulos 2007 BMC Sys Bio Table 1 1.11e-4 +DNA_Sequestration_F, Numeric, 3.721, +DNA_Sequestration_R, Numeric, 2.2569, diff --git a/components/txtl_param_sfGFP.csv b/components/txtl_param_sfGFP.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_sigma28.csv b/components/txtl_param_sigma28.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_sigma54.csv b/components/txtl_param_sigma54.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_t7RNAP.csv b/components/txtl_param_t7RNAP.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_t7prom.csv b/components/txtl_param_t7prom.csv old mode 100644 new mode 100755 diff --git a/components/txtl_param_tetR.csv b/components/txtl_param_tetR.csv index fd54074..988f551 100644 --- a/components/txtl_param_tetR.csv +++ b/components/txtl_param_tetR.csv @@ -2,8 +2,8 @@ Gene_Length, Numeric, 647 LVA_tag_Length, Numeric, 40 Terminator_Length, Numeric, 100 -Dimmerization_Forward, Numeric, 1, V. Sotiropoulos 2007 BMC Sys Bio Table 1 -Dimmerization_Reverse, Numeric, 1, V. Sotiropoulos 2007 BMC Sys Bio Table 1 +Dimmerization_Forward, Numeric, 4.2503, +Dimmerization_Reverse, Numeric, 0.00019296, -Protein_Inducer_Forward, Numeric, 1e-5, V. Sotiropoulos 2007 BMC Sys Bio Table 1 -Protein_Inducer_Reverse, Numeric, 1.0e-1, V. Sotiropoulos 2007 BMC Sys Bio Table 1 +Protein_Inducer_Forward, Numeric, 4.8404, +Protein_Inducer_Reverse, Numeric, 0.6551, diff --git a/components/txtl_param_utr1.csv b/components/txtl_param_utr1.csv index 9b26b9e..9c4d3ca 100644 --- a/components/txtl_param_utr1.csv +++ b/components/txtl_param_utr1.csv @@ -1,5 +1,7 @@ -Ribosome_Binding_F, Expression, .2 -Ribosome_Binding_R, Expression, 4 +Ribosome_Binding_F, Expression, 0.81873 +Ribosome_Binding_R, Expression, 59219 RBS_Length, Numeric, 30, spacer_Length, Numeric, 200 + + diff --git a/components/txtl_param_utr1b.csv b/components/txtl_param_utr1b.csv new file mode 100644 index 0000000..bc9b84d --- /dev/null +++ b/components/txtl_param_utr1b.csv @@ -0,0 +1,5 @@ +Ribosome_Binding_F, Expression, 0.81873 +Ribosome_Binding_R, Expression, 0.86433 + +RBS_Length, Numeric, 30, +spacer_Length, Numeric, 200 diff --git a/components/txtl_prom_p28.m b/components/txtl_prom_p28.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_p28_ptet.m b/components/txtl_prom_p28_ptet.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_p70.m b/components/txtl_prom_p70.m old mode 100644 new mode 100755 index 551e2c0..4d406a4 --- a/components/txtl_prom_p70.m +++ b/components/txtl_prom_p70.m @@ -69,8 +69,8 @@ % empty cellarray for amount => zero amount txtl_addspecies(tube, coreSpecies, cell(1,size(coreSpecies,2)), 'Internal'); - - txtl_transcription(mode, tube, dna, rna, RNAP, RNAPbound); + + txtl_transcription(mode, tube, dna, rna, RNAP, RNAPbound); %%%%%%%%%%%%%%%%%%% DRIVER MODE: Setup Reactions %%%%%%%%%%%%%%%%%%%%%%%%%% elseif strcmp(mode.add_dna_driver, 'Setup Reactions') @@ -82,6 +82,9 @@ error('the number of argument should be 5 or 8, not %d',nargin); end + + + % Parameters that describe this promoter parameters = {'TXTL_P70_RNAPbound_F',paramObj.RNAPbound_Forward;... 'TXTL_P70_RNAPbound_R',paramObj.RNAPbound_Reverse}; diff --git a/components/txtl_prom_p70pr1.m b/components/txtl_prom_p70pr1.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_pBAD.m b/components/txtl_prom_pBAD.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_pBAD_ptet.m b/components/txtl_prom_pBAD_ptet.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_pGlnA.m b/components/txtl_prom_pGlnA.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_pJ23119.m b/components/txtl_prom_pJ23119.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_pOR1OR2.m b/components/txtl_prom_pOR1OR2_REMOVE.m old mode 100644 new mode 100755 similarity index 100% rename from components/txtl_prom_pOR1OR2.m rename to components/txtl_prom_pOR1OR2_REMOVE.m diff --git a/components/txtl_prom_pOR2OR1.m b/components/txtl_prom_pOR2OR1.m new file mode 100644 index 0000000..f7934ac --- /dev/null +++ b/components/txtl_prom_pOR2OR1.m @@ -0,0 +1,127 @@ +% txtl_prom_OR1OR2.m - promoter information for pOR1OR2 promoter +% VS July 2014 +% +% This file contains a description of the ptet promoter. +% Calling the function txtl_prom_pOR1OR2() will set up the reactions for +% transcription with the measured binding rates and transription rates. + +% Written by Richard Murray, Sep 2012 +% +% Copyright (c) 2012 by California Institute of Technology +% All rights reserved. +% +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are +% met: +% +% 1. Redistributions of source code must retain the above copyright +% notice, this list of conditions and the following disclaimer. +% +% 2. Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in the +% documentation and/or other materials provided with the distribution. +% +% 3. The name of the author may not be used to endorse or promote products +% derived from this software without specific prior written permission. +% +% THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +% IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +% DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +% INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +% STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +% IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +% POSSIBILITY OF SUCH DAMAGE. + +function varargout = txtl_prom_pOR2OR1(mode, tube, dna, rna,varargin) + +% Create strings for reactants and products +DNA = ['[' dna.Name ']']; % DNA species name for reactions +RNA = ['[' rna.Name ']']; % RNA species name for reactions +RNAP = 'RNAP'; % RNA polymerase name for reactions +RNAPbound = ['RNAP:' dna.Name]; +% importing the corresponding parameters +paramObj = txtl_component_config('pOR2OR1'); + + +%%%%%%%%%%%%%%%%%%% DRIVER MODE: Setup Species %%%%%%%%%%%%%%%%%%%%%%%%%%%% +if strcmp(mode.add_dna_driver, 'Setup Species') + + promoterData = varargin{1}; + if nargin==8 + prom_spec = varargin{2}; + rbs_spec = varargin{3}; + gene_spec = varargin{4}; + elseif nargin~=5 + error('the number of argument should be 5 or 8, not %d',nargin); + end + defaultBasePairs = {'pOR2OR1','junk','thio';... + paramObj.Promoter_Length,paramObj.Junk_Length,paramObj.Thio_Length}; + promoterData = txtl_setup_default_basepair_length(tube,promoterData,... + defaultBasePairs); + + varargout{1} = promoterData; + + coreSpecies = {RNAP,RNAPbound}; + % empty cellarray for amount => zero amount + txtl_addspecies(tube, coreSpecies, cell(1,size(coreSpecies,2)), 'Internal'); +% if mode.utr_attenuator_flag +% txtl_transcription_RNAcircuits(mode, tube, dna, rna, RNAP, RNAPbound, prom_spec, rbs_spec, gene_spec ); +% else + txtl_transcription(mode, tube, dna, rna, RNAP, RNAPbound); +% end + + %%%%%%%%%%%%%%%%%%% DRIVER MODE: Setup Reactions %%%%%%%%%%%%%%%%%%%%%%%%%% +elseif strcmp(mode.add_dna_driver,'Setup Reactions') + listOfSpecies = varargin{1}; + if nargin==8 + prom_spec = varargin{2}; + rbs_spec = varargin{3}; + gene_spec = varargin{4}; + elseif nargin~=5 + error('the number of argument should be 5 or 8, not %d',nargin); + end + % Parameters that describe this promoter + parameters = {'TXTL_POR2OR1_RNAPbound_F',paramObj.RNAPbound_Forward;... + 'TXTL_POR2OR1_RNAPbound_R',paramObj.RNAPbound_Reverse}; + % Set up binding reaction + txtl_addreaction(tube,[DNA ' + ' RNAP ' <-> [' RNAPbound ']'],... + 'MassAction',parameters); + +% if mode.utr_attenuator_flag +% txtl_transcription_RNAcircuits(mode, tube, dna, rna, RNAP, RNAPbound, prom_spec, rbs_spec, gene_spec ); +% else + txtl_transcription(mode, tube, dna, rna, RNAP, RNAPbound); +% end + + + matchStr = regexp(listOfSpecies,'(^protein cLambda.*dimer$)','tokens','once'); + listOfcLambdadimer = vertcat(matchStr{:}); + + + % repression of ptet by tetR dimer + if ~isempty(listOfcLambdadimer) + for k = 1:size(listOfcLambdadimer,1) + txtl_addreaction(tube,... + [DNA ' + ' listOfcLambdadimer{k} ' <-> [' dna.name ':' listOfcLambdadimer{k} ']'],... + 'MassAction',{'pOR2OR1_sequestration_F',getDNASequestrationRates(paramObj,'F');... + 'pOR1OR2_sequestration_R',getDNASequestrationRates(paramObj,'R')}); + + end + end + + %%%%%%%%%%%%%%%%%%% DRIVER MODE: error handling %%%%%%%%%%%%%%%%%%%%%%%%%%% +else + error('txtltoolbox:txtl_prom_pOR2OR1:undefinedmode', ... + 'The possible modes are ''Setup Species'' and ''Setup Reactions''.'); +end +end + + +% Automatically use MATLAB mode in Emacs (keep at end of file) +% Local variables: +% mode: matlab +% End: diff --git a/components/txtl_prom_plac.m b/components/txtl_prom_plac.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_plambda.m b/components/txtl_prom_plambda.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_plas.m b/components/txtl_prom_plas.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_plas_ptet.m b/components/txtl_prom_plas_ptet.m index deb3816..01f7903 100644 --- a/components/txtl_prom_plas_ptet.m +++ b/components/txtl_prom_plas_ptet.m @@ -74,7 +74,9 @@ txtl_addspecies(tube, coreSpecies, cell(1,size(coreSpecies,2)),'Internal'); % if mode.utr_attenuator_flag -% txtl_transcription_RNAcircuits(mode, tube, dna, rna, RNAP, [RNAPbound ':' P3 ],prom_spec, rbs_spec, gene_spec,{P3} ); +% txtl_transcription_RNAcircuits(mode, tube, dna, rna, RNAP, +% [RNAPbound... +% ':' P3 ],prom_spec, rbs_spec, gene_spec,{P3} ); % else % txtl_transcription(mode, tube, dna, rna, RNAP,[RNAPbound ':' P3 ],{P3}); % end @@ -97,8 +99,22 @@ matchStr = regexp(listOfSpecies,'(^protein tetR.*dimer$)','tokens','once'); listOftetRdimer = vertcat(matchStr{:}); - % we dont allow for activation by non inducer bound activator. in a - % future leaky expression mode, those type of reactions would get activated. + + % June 8, 2019: add leaky expression. Maybe in a future release this + % will be a mode. But for now we just have it as the default. The leaky + % expression parameter was estimated to be 35 in log space. This is the + % value being put into the txtlsim paper. + % Note that based on the logic of the combinatorial promoter, + % this parameter value cannot be the ptet promoter + % unrepressed expression value. that is too high to be leaky. This is + % the plas leaky espression value. + % + % leaky expression + parameters = {'TXTL_PLAS_RNAPbound_F',paramObj.RNAPbound_Forward;... + 'TXTL_PLAS_RNAPbound_R',paramObj.RNAPbound_Reverse}; + txtl_addreaction(tube,[DNA ' + ' RNAP ' <-> [' RNAPbound ']'],... + 'MassAction',parameters); + p = regexp(listOfSpecies,'^OC12HSL:protein lasR(-lva)?$', 'match'); listOfactivators = vertcat(p{:}); @@ -119,8 +135,8 @@ % bound listOfSpecies_justAdded = get(tube.species, 'name'); activ_bound = ['^(RNAP:' dna.name '|' dna.name '):(OC12HSL:protein lasR(-lva)?)$']; -% tetR dimer binds to the string after the activated lasR binds. and -% the AGTP and CUTP bind before. +% tetR dimer binds to the string after (at the end of the string) the activated lasR. and +% the AGTP and CUTP bind before (ie, at the start of the string, / earlier in the string). % I.e., dont want the following species to to get recognized % 'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer' % 'AGTP:CUTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer' @@ -147,16 +163,16 @@ % repressor binding to DNA txtl_addreaction(tube,... ['[' dna.name '] + ' listOftetRdimer{k} ' <-> [' dna.name ':' listOftetRdimer{k} ']'],... - 'MassAction',{'ptet_sequestration_F',getDNASequestrationRates(paramObj,'F');... - 'ptet_sequestration_R',getDNASequestrationRates(paramObj,'R')}); + 'MassAction',{'TXTL_PTET_sequestration_F',getDNASequestrationRates(paramObj,'F');... + 'TXTL_PTET_sequestration_R',getDNASequestrationRates(paramObj,'R')}); for i = 1:size(list_of_repressible_dna) %repressor binding to activated dna txtl_addreaction(tube,... [list_of_repressible_dna{i} ' + ' listOftetRdimer{k} ' <-> ['... list_of_repressible_dna{i} ':' listOftetRdimer{k} ']'],... - 'MassAction',{'ptet_sequestration_F',getDNASequestrationRates(paramObj,'F');... - 'ptet_sequestration_R',getDNASequestrationRates(paramObj,'R')}); + 'MassAction',{'TXTL_PTET_sequestration_F',getDNASequestrationRates(paramObj,'F');... + 'TXTL_PTET_sequestration_R',getDNASequestrationRates(paramObj,'R')}); % repressor knocking off activator % use the tokens captured previously to set up the reacion @@ -171,14 +187,18 @@ txtl_addreaction(tube,... ['[' list_of_repressible_dna{i} ':' listOftetRdimer{k} '] <-> ['... dna.name ':' listOftetRdimer{k} '] + [' token2 ']'],... - 'MassAction',{'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F',paramObj.Combinatorial_activ_knockoff_F;... - 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_R',paramObj.Combinatorial_activ_knockoff_R}); + 'MassAction',{'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F',... + paramObj.Combinatorial_activ_knockoff_F;... + 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_R',... + paramObj.Combinatorial_activ_knockoff_R}); else txtl_addreaction(tube,... ['[' list_of_repressible_dna{i} ':' listOftetRdimer{k} '] <-> ['... dna.name ':' listOftetRdimer{k} '] + RNAP + [' token2 ']'],... - 'MassAction',{'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F',paramObj.Combinatorial_activ_knockoff_F;... - 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_R',paramObj.Combinatorial_activ_knockoff_R}); + 'MassAction',{'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F',... + paramObj.Combinatorial_activ_knockoff_F;... + 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_R',... + paramObj.Combinatorial_activ_knockoff_R}); end @@ -224,7 +244,9 @@ function setup_promoter_reactions(mode, tube, dna,rna, RNAP, RNAPbound,... prom_spec, rbs_spec, gene_spec, TF, paramObj) % !TODO generalize this function to be used with all activator files. remove any -% plas specificity. VS aug 2017 +% plas specificity. VS aug 2017 -- Note to future self: an activator class +% would work really well here. Basically we must have activator, repressor, +% etc classes. txtl_addreaction(tube, ... [dna.Name ' + ' TF ' <-> [' dna.Name ':' TF ']' ],... @@ -236,16 +258,26 @@ function setup_promoter_reactions(mode, tube, dna,rna, RNAP, RNAPbound,... 'MassAction',{'TXTL_PLAS_TFRNAPbound_F',paramObj.RNAPbound_Forward_actv;... 'TXTL_PLAS_TFRNAPbound_R',paramObj.RNAPbound_Reverse_actv}); +txtl_addreaction(tube, ... + [RNAPbound ' + ' TF ' <-> [' RNAPbound ':' TF ']' ],... + 'MassAction',{'TXTL_PLAS_TFBIND_F',paramObj.activation_F;... + 'TXTL_PLAS_TFBIND_R',paramObj.activation_R}); % this line was added Jun 8, 2019 % % if mode.utr_attenuator_flag % mode.add_dna_driver = 'Setup Species'; -% txtl_transcription_RNAcircuits(mode, tube, dna, rna, RNAP, [RNAPbound ':' TF],prom_spec, rbs_spec, gene_spec,{TF} ); +% txtl_transcription_RNAcircuits(mode, tube, dna, rna, RNAP,... +% [RNAPbound ':' TF],prom_spec, rbs_spec, gene_spec,{TF} ); % mode.add_dna_driver = 'Setup Reactions'; -% txtl_transcription_RNAcircuits(mode, tube, dna, rna, RNAP, [RNAPbound ':' TF],prom_spec, rbs_spec, gene_spec,{TF} ); +% txtl_transcription_RNAcircuits(mode, tube, dna, rna, RNAP, ... +% [RNAPbound ':' TF],prom_spec, rbs_spec, gene_spec,{TF} ); % else mode.add_dna_driver = 'Setup Species'; + + txtl_transcription(mode, tube, dna, rna, RNAP,RNAPbound); %added on Jun 30, 2019 txtl_transcription(mode, tube, dna, rna, RNAP,[RNAPbound ':' TF ],{TF}); mode.add_dna_driver = 'Setup Reactions'; + + txtl_transcription(mode, tube, dna, rna, RNAP,RNAPbound); %added on Jun 30, 2019 txtl_transcription(mode, tube, dna, rna, RNAP,[RNAPbound ':' TF ],{TF}); % end diff --git a/components/txtl_prom_plux.m b/components/txtl_prom_plux.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_ptet.m b/components/txtl_prom_ptet.m old mode 100644 new mode 100755 index 98e3809..645df79 --- a/components/txtl_prom_ptet.m +++ b/components/txtl_prom_ptet.m @@ -99,8 +99,8 @@ for k = 1:size(listOftetRdimer,1) txtl_addreaction(tube,... [DNA ' + ' listOftetRdimer{k} ' <-> [' dna.name ':' listOftetRdimer{k} ']'],... - 'MassAction',{'ptet_sequestration_F',getDNASequestrationRates(paramObj,'F');... - 'ptet_sequestration_R',getDNASequestrationRates(paramObj,'R')}); + 'MassAction',{'TXTL_PTET_sequestration_F',getDNASequestrationRates(paramObj,'F');... + 'TXTL_PTET_sequestration_R',getDNASequestrationRates(paramObj,'R')}); end end diff --git a/components/txtl_prom_t7.m b/components/txtl_prom_t7.m old mode 100644 new mode 100755 diff --git a/components/txtl_prom_t7_placI.m b/components/txtl_prom_t7_placI.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_AraC.m b/components/txtl_protein_AraC.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_ClpP.m b/components/txtl_protein_ClpP.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_ClpX.m b/components/txtl_protein_ClpX.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_LuxR.m b/components/txtl_protein_LuxR.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_NRII_H139N.m b/components/txtl_protein_NRII_H139N.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_NRII_L16R.m b/components/txtl_protein_NRII_L16R.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_RFP.m b/components/txtl_protein_RFP.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_betaGal.m b/components/txtl_protein_betaGal.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_cLambda.m b/components/txtl_protein_cLambda.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_deCFP.m b/components/txtl_protein_deCFP.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_deGFP.m b/components/txtl_protein_deGFP.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_lacI.m b/components/txtl_protein_lacI.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_lasR.m b/components/txtl_protein_lasR.m old mode 100644 new mode 100755 index 66dd413..419ad1a --- a/components/txtl_protein_lasR.m +++ b/components/txtl_protein_lasR.m @@ -73,8 +73,8 @@ for k = 1:size(listOfProtein,1) txtl_addreaction(tube,['[' listOfProtein{k} '] + OC12HSL <-> [OC12HSL:' listOfProtein{k} ']'],... - 'MassAction',{'TXTL_INDUCER_LUXR_AHL_F',paramObj.Protein_Inducer_Forward;... - 'TXTL_INDUCER_LUXR_AHL_R',paramObj.Protein_Inducer_Reverse}); + 'MassAction',{'TXTL_INDUCER_LASR_AHL_F',paramObj.Protein_Inducer_Forward;... + 'TXTL_INDUCER_LASR_AHL_R',paramObj.Protein_Inducer_Reverse}); end diff --git a/components/txtl_protein_sfGFP.m b/components/txtl_protein_sfGFP.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_sigma28.m b/components/txtl_protein_sigma28.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_sigma54.m b/components/txtl_protein_sigma54.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_t7RNAP.m b/components/txtl_protein_t7RNAP.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_tetR.m b/components/txtl_protein_tetR.m old mode 100644 new mode 100755 diff --git a/components/txtl_protein_tetRmonomeric.m b/components/txtl_protein_tetRmonomeric.m old mode 100644 new mode 100755 diff --git a/config/B32_config.csv b/config/B32_config.csv old mode 100644 new mode 100755 diff --git a/config/E1_config.csv b/config/E1_config.csv new file mode 100644 index 0000000..8f56e05 --- /dev/null +++ b/config/E1_config.csv @@ -0,0 +1 @@ +NTPmodel,Numeric,2, NTP model in use -- this should be 2, AAmodel,Numeric,2, AA model in use -- this should be 2, Transcription_Rate, Expression, 139.1288, or 66.6863, Translation_Rate, Expression, 1.6852, , ,,,, DNA_RecBCD_Forward, Numeric,0.4, NOT USED (update later), DNA_RecBCD_Reverse, Numeric,0.1, NOT USED (update later), DNA_RecBCD_complex_deg, Numeric,0.5, NOT USED (update later), ,,,, Protein_ClpXP_Forward, Numeric,0.5, NOT USED (update later), Protein_ClpXP_Reverse, Numeric,0.0001, NOT USED (update later), Protein_ClpXP_complex_deg, Numeric,0.1, NOT USED (update later), ,,,, RNAP_S70_F, Numeric,100, NOT USED, RNAP_S70_R, Numeric,0.01, NOT USED, ,,,, GamS_RecBCD_F, Numeric,0.001, NOT USED (update later), GamS_RecBCD_R, Numeric,0.09, NOT USED (update later), ,,,, TL_AA_Forward,Expression,0.7408, !TODO: document, TL_AA_Reverse,Expression,521.4430, !TODO: document, TL_AGTP_Forward,Expression,0.3012, !TODO: document, TL_AGTP_Reverse,Expression,602590, !TODO: document, ,,,, RNA_deg,Expression,0.012277, s^-1 12 min half life (VN PRL) , RNase_F,Expression,1, nM^-1 s^-1 see derivation on wiki, RNase_R,Expression,10270, s^-1 see derivation on wiki, ,,,, Ribosome_Binding_F, Expression,0.81873, , Ribosome_Binding_R, Expression,59219, , ,,,, NTP_Forward_1,Expression,1, , NTP_Reverse_1,Expression,19.028, , NTP_Forward_2,Expression,1, , NTP_Reverse_2,Expression,1199001.8776, , ,,,, RNAPbound_termination_rate, Numeric,27.1262, , Ribobound_termination_rate, Numeric,220.9640, , ,,,, RecBCD_ic, Numeric,5, , RNAP_ic, Numeric,7.4, used to be 4.2287 now TRY exp(2) = 7.4, Ribo_ic, Numeric,30, , RNase_ic, Numeric,658.4575, , ,,,, ATP_degradation_rate, Numeric,7.3575e-05, , ATP_degradation_start_time, Numeric,9604.6, , ATP_regeneration_rate, Numeric,0.02, , ,,,, AGTP_Concentration, Expression,3000000, ATP and GTP are at 1.5mM each (JoVE), CUTP_Concentration, Expression,1800000, CTP and UTP are at 0.9mM each (JovE), AA_Concentration, Expression,30000000, 20 tyes of AAs, $20% usability$ 30mM JoVE \ No newline at end of file diff --git a/config/E2_config.csv b/config/E2_config.csv new file mode 100644 index 0000000..5ed37e1 --- /dev/null +++ b/config/E2_config.csv @@ -0,0 +1,53 @@ +Transcription_Rate, Expression, 12.418, , +Translation_Rate, Expression, 23.826, , +,,,, +TL_AA_Forward,Expression,0.7408, , +TL_AA_Reverse,Expression,521.4430, , +TL_AGTP_Forward,Expression,0.3012, , +TL_AGTP_Reverse,Expression,602590, , +,,,, +RNA_deg,Expression,0.087664, s^-1 12 min half life (VN PRL) , +RNase_F,Expression,1, nM^-1 s^-1 see derivation on wiki, +RNase_R,Expression,3.6914e+06, s^-1 see derivation on wiki, +,,,, +Ribosome_Binding_F, Expression,0.81873, , +Ribosome_Binding_R, Expression,52.976, , +,,,, +NTP_Forward_1,Expression,1, , +NTP_Reverse_1,Expression,19.028, , +NTP_Forward_2,Expression,1, , +NTP_Reverse_2,Expression,1199001.8776, , +,,,, +RNAPbound_termination_rate, Numeric,1.7912, , +Ribobound_termination_rate, Numeric,12.984, , +,,,, +RNAP_ic, Numeric,4.7367, used to be 4.2287 now TRY exp(2) = 7.4, +Ribo_ic, Numeric,266.42, , +RNase_ic, Numeric,30269, , +,,,, +ATP_degradation_rate, Numeric,4.8663e-05, , +ATP_degradation_start_time, Numeric,6529.5, , +ATP_regeneration_rate, Numeric,0.02, , +,,,, +AGTP_Concentration, Expression,3000000, ATP and GTP are at 1.5mM each (JoVE), +CUTP_Concentration, Expression,1800000, CTP and UTP are at 0.9mM each (JovE), +AA_Concentration, Expression,30000000, 20 tyes of AAs, $20% usability$ 30mM JoVE +,,,, +RecBCD_ic, Numeric,5, NOT USED, +,,,, +DNA_RecBCD_Forward, Numeric,0.4, NOT USED (update later), +DNA_RecBCD_Reverse, Numeric,0.1, NOT USED (update later), +DNA_RecBCD_complex_deg, Numeric,0.5, NOT USED (update later), +,,,, +Protein_ClpXP_Forward, Numeric,0.5, NOT USED (update later), +Protein_ClpXP_Reverse, Numeric,0.0001, NOT USED (update later), +Protein_ClpXP_complex_deg, Numeric,0.1, NOT USED (update later), +,,,, +RNAP_S70_F, Numeric,100, NOT USED, +RNAP_S70_R, Numeric,0.01, NOT USED, +,,,, +GamS_RecBCD_F, Numeric,0.001, NOT USED (update later), +GamS_RecBCD_R, Numeric,0.09, NOT USED (update later), +,,,, +NTPmodel,Numeric,2, NTP model in use -- this should be 2, +AAmodel,Numeric,2, AA model in use -- this should be 2, diff --git a/config/E30VNPRL_config.csv b/config/E30VNPRL_config.csv old mode 100644 new mode 100755 index e156030..4810912 --- a/config/E30VNPRL_config.csv +++ b/config/E30VNPRL_config.csv @@ -1,4 +1,4 @@ -NTPmodel,Numeric,2, NTP model in use !TODO: document, AAmodel,Numeric,2, AA model in use !TODO: document, Transcription_Rate, Expression, 1.5/(RNA_Length), 1 NTP/second VN PRL, Translation_Rate, Expression, 4/(Protein_Length), >4 AA/second VN PRL, ,,,, DNA_RecBCD_Forward, Numeric,0.4, !TODO: document, DNA_RecBCD_Reverse, Numeric,0.1, !TODO: document, DNA_RecBCD_complex_deg, Numeric,0.5, !TODO: document, ,,,, Protein_ClpXP_Forward, Numeric,0.5, !TODO: document, Protein_ClpXP_Reverse, Numeric,0.0001, !TODO: document, Protein_ClpXP_complex_deg, Numeric,0.1, !TODO: document, ,,,, RNAP_S70_F, Numeric,100, really fast, RNAP_S70_R, Numeric,0.01,, ,,,, GamS_RecBCD_F, Numeric,0.001, ! !TODO document, GamS_RecBCD_R, Numeric,0.09, !TODO: document, ,,,, TL_AA_Forward,Expression,300, !TODO: document, TL_AA_Reverse,Expression,.10, !TODO: document, +NTPmodel,Numeric,2, NTP model in use !TODO: document, AAmodel,Numeric,2, AA model in use !TODO: document, Transcription_Rate, Expression, 7.5, 1.5 NTP/second VN PRL, Translation_Rate, Expression, 4, >4 AA/second VN PRL, ,,,, DNA_RecBCD_Forward, Numeric,0.4, !TODO: document, DNA_RecBCD_Reverse, Numeric,0.1, !TODO: document, DNA_RecBCD_complex_deg, Numeric,0.5, !TODO: document, ,,,, Protein_ClpXP_Forward, Numeric,0.5, !TODO: document, Protein_ClpXP_Reverse, Numeric,0.0001, !TODO: document, Protein_ClpXP_complex_deg, Numeric,0.1, !TODO: document, ,,,, RNAP_S70_F, Numeric,100, really fast, RNAP_S70_R, Numeric,0.01,, ,,,, GamS_RecBCD_F, Numeric,0.001, ! !TODO document, GamS_RecBCD_R, Numeric,0.09, !TODO: document, ,,,, TL_AA_Forward,Expression,300, !TODO: document, TL_AA_Reverse,Expression,.10, !TODO: document, TL_AGTP_Forward,Expression,30, !TODO: document, TL_AGTP_Reverse,Expression,10, !TODO: document, ,,,, RNA_deg,Expression,1/360, s^-1 12 min half life (VN PRL) , RNase_F,Expression,10, nM^-1 s^-1 see derivation on wiki, RNase_R,Expression,2000, s^-1 see derivation on wiki, ,,,, Ribosome_Binding_F, Expression,.0022, TODO, Ribosome_Binding_R, Expression,400, TODO, ,,,, NTP_Forward_1,Expression,1, !TODO: document, NTP_Reverse_1,Expression,1.20E+05, !TODO: document , NTP_Forward_2,Expression,1000, !TODO: document, NTP_Reverse_2,Expression,1.20E+8, !TODO: document, ,,,, RNAPbound_termination_rate, Numeric,0.05, !TODO: document, Ribobound_termination_rate, Numeric,50, !TODO: document, @@ -7,6 +7,7 @@ RNAP_ic, Numeric,100, !TODO: carry out MCMC and check lit, Ribo_ic, Numeric,30, !TODO: carry out MCMC and check lit, RNase_ic, Numeric,100, !TODO: carry out MCMC and check lit, ,,,, -ATP_degradation_rate, Numeric,0.0002, !TODO: document, -ATP_degradation_start_time, Numeric,5400, in seconds !TODO: document, +ATP_degradation_rate, Numeric,0.002, !TODO: document, +ATP_degradation_start_time, Numeric,10800, in seconds !TODO: document, +ATP_regeneration_rate, Numeric,0.002, !TODO: document, ,,,, AGTP_Concentration, Expression,3000000, ATP and GTP are at 1.5mM each (JoVE), CUTP_Concentration, Expression,1800000, CTP and UTP are at 0.9mM each (JovE), AA_Concentration, Expression,30000000, 20 tyes of AAs, $20% usability$ 30mM JoVE \ No newline at end of file diff --git a/config/E30_config.csv b/config/E30_config.csv old mode 100644 new mode 100755 index 040aeaf..647c360 --- a/config/E30_config.csv +++ b/config/E30_config.csv @@ -1,7 +1,7 @@ NTPmodel,Numeric,2, NTP model in use, see documentation AAmodel,Numeric,2, AA model in use, see documentation -Transcription_Rate, Expression, 1/(RNA_Length), 1 NTP/second VN PRL -Translation_Rate, Expression, 4/(Protein_Length), >4 AA/second VN PRL +Transcription_Rate, Expression, 1, 1 NTP/second VN PRL +Translation_Rate, Expression, 4, >4 AA/second VN PRL ,,,, DNA_RecBCD_Forward, Numeric, 0.4, TODO DNA_RecBCD_Reverse, Numeric, 0.1, TODO diff --git a/config/E32_config.csv b/config/E32_config.csv old mode 100644 new mode 100755 index 5a23f7d..d8a547a --- a/config/E32_config.csv +++ b/config/E32_config.csv @@ -1,4 +1,4 @@ -NTPmodel,Numeric,2, NTP model in use !TODO: document, AAmodel,Numeric,2, AA model in use !TODO: document, Transcription_Rate, Expression, 4/(RNA_Length), 1 NTP/second VN PRL, Translation_Rate, Expression, 500/(Protein_Length), >4 AA/second VN PRL, ,,,, DNA_RecBCD_Forward, Numeric,0.4, !TODO: document, DNA_RecBCD_Reverse, Numeric,0.1, !TODO: document, DNA_RecBCD_complex_deg, Numeric,0.5, !TODO: document, ,,,, Protein_ClpXP_Forward, Numeric,0.5, !TODO: document, Protein_ClpXP_Reverse, Numeric,0.0001, !TODO: document, Protein_ClpXP_complex_deg, Numeric,0.1, !TODO: document, ,,,, RNAP_S70_F, Numeric,100, really fast, RNAP_S70_R, Numeric,0.01,, ,,,, GamS_RecBCD_F, Numeric,0.001, ! !TODO document, GamS_RecBCD_R, Numeric,0.09, !TODO: document, ,,,, TL_AA_Forward,Expression,300, !TODO: document, TL_AA_Reverse,Expression,.010, !TODO: document, +NTPmodel,Numeric,2, NTP model in use !TODO: document, AAmodel,Numeric,2, AA model in use !TODO: document, Transcription_Rate, Expression, 4, 1 NTP/second VN PRL, Translation_Rate, Expression, 50, >4 AA/second VN PRL, ,,,, DNA_RecBCD_Forward, Numeric,0.4, !TODO: document, DNA_RecBCD_Reverse, Numeric,0.1, !TODO: document, DNA_RecBCD_complex_deg, Numeric,0.5, !TODO: document, ,,,, Protein_ClpXP_Forward, Numeric,0.5, !TODO: document, Protein_ClpXP_Reverse, Numeric,0.0001, !TODO: document, Protein_ClpXP_complex_deg, Numeric,0.1, !TODO: document, ,,,, RNAP_S70_F, Numeric,100, really fast, RNAP_S70_R, Numeric,0.01,, ,,,, GamS_RecBCD_F, Numeric,0.001, ! !TODO document, GamS_RecBCD_R, Numeric,0.09, !TODO: document, ,,,, TL_AA_Forward,Expression,300, !TODO: document, TL_AA_Reverse,Expression,.010, !TODO: document, TL_AGTP_Forward,Expression,30, !TODO: document, TL_AGTP_Reverse,Expression,1, !TODO: document, ,,,, RNA_deg,Expression,0.5/360, s^-1 12 min half life (VN PRL) , RNase_F,Expression,.1, nM^-1 s^-1 see derivation on wiki, RNase_R,Expression,2, s^-1 see derivation on wiki, ,,,, Ribosome_Binding_F, Expression,.2, TODO, Ribosome_Binding_R, Expression,4, TODO, ,,,, NTP_Forward_1,Expression,0.1, !TODO: document, NTP_Reverse_1,Expression,1.20E+05, !TODO: document , NTP_Forward_2,Expression,100, !TODO: document, NTP_Reverse_2,Expression,1.20E+8, !TODO: document, ,,,, RNAPbound_termination_rate, Numeric,0.05, !TODO: document, Ribobound_termination_rate, Numeric,0.005, !TODO: document, ,,,, RecBCD_ic, Numeric,5, !TODO: carry out MCMC and check lit, diff --git a/config/E3_config.csv b/config/E3_config.csv new file mode 100644 index 0000000..85fd589 --- /dev/null +++ b/config/E3_config.csv @@ -0,0 +1,50 @@ +Transcription_Rate, Expression, 22.669, , +Translation_Rate, Expression, 31.062, , +,,,, +TL_AA_Forward,Expression,0.74082, , +TL_AA_Reverse,Expression,521.4430, , +TL_AGTP_Forward,Expression,0.3012, , +TL_AGTP_Reverse,Expression,602590, , +,,,, +RNA_deg,Expression,0.79844, s^-1 12 min half life (VN PRL) , +RNase_F,Expression,1, nM^-1 s^-1 see derivation on wiki, +RNase_R,Expression,6.1681e+06, s^-1 see derivation on wiki, +,,,, +NTP_Forward_1,Expression,1, , +NTP_Reverse_1,Expression,19.028, , +NTP_Forward_2,Expression,1, , +NTP_Reverse_2,Expression,1199001.8776, , +,,,, +RNAPbound_termination_rate, Numeric,78.241, , +Ribobound_termination_rate, Numeric,16.993, , +,,,, +RNAP_ic, Numeric,365.04, , +Ribo_ic, Numeric,365.04, , +RNase_ic, Numeric,9897.1, , +,,,, +ATP_degradation_rate, Numeric,5.616e-05, , +ATP_degradation_start_time, Numeric,23156, , +ATP_regeneration_rate, Numeric,0.02, , +,,,, +AGTP_Concentration, Expression,3000000, ATP and GTP are at 1.5mM each (JoVE), +CUTP_Concentration, Expression,1800000, CTP and UTP are at 0.9mM each (JovE), +AA_Concentration, Expression,30000000, 20 tyes of AAs, $20% usability$ 30mM JoVE +,,,, +RecBCD_ic, Numeric,5, NOT USED, +,,,, +DNA_RecBCD_Forward, Numeric,0.4, NOT USED (update later), +DNA_RecBCD_Reverse, Numeric,0.1, NOT USED (update later), +DNA_RecBCD_complex_deg, Numeric,0.5, NOT USED (update later), +,,,, +Protein_ClpXP_Forward, Numeric,0.5, NOT USED (update later), +Protein_ClpXP_Reverse, Numeric,0.0001, NOT USED (update later), +Protein_ClpXP_complex_deg, Numeric,0.1, NOT USED (update later), +,,,, +RNAP_S70_F, Numeric,100, NOT USED, +RNAP_S70_R, Numeric,0.01, NOT USED, +,,,, +GamS_RecBCD_F, Numeric,0.001, NOT USED (update later), +GamS_RecBCD_R, Numeric,0.09, NOT USED (update later), +,,,, +NTPmodel,Numeric,2, NTP model in use -- this should be 2, +AAmodel,Numeric,2, AA model in use -- this should be 2, diff --git a/config/E9_config.csv b/config/E9_config.csv old mode 100644 new mode 100755 index 087beb6..5ba9187 --- a/config/E9_config.csv +++ b/config/E9_config.csv @@ -1,7 +1,7 @@ NTPmodel,Numeric,2, NTP model in use, see documentation AAmodel,Numeric,2, AA model in use, see documentation -Transcription_Rate, Expression, log(2)/(RNA_Length/50), 50 NTP/second transcription -Translation_Rate, Expression, log(2)/(Protein_Length/0.64), 1.5 AA/second translation +Transcription_Rate, Expression, log(2), +Translation_Rate, Expression, log(2), DNA_RecBCD_Forward, Numeric, 0.4, DNA_RecBCD_Reverse, Numeric, 0.1, diff --git a/config/Emcmc2017_config.csv b/config/Emcmc2017_config.csv new file mode 100755 index 0000000..7d0a381 --- /dev/null +++ b/config/Emcmc2017_config.csv @@ -0,0 +1,13 @@ +NTPmodel,Numeric,2, NTP model in use !TODO: document, AAmodel,Numeric,2, AA model in use !TODO: document, Transcription_Rate, Expression, 1.5, 1.5 NTP/second VN PRL, Translation_Rate, Expression, 4, >4 AA/second VN PRL, ,,,, DNA_RecBCD_Forward, Numeric,0.4, !TODO: document, DNA_RecBCD_Reverse, Numeric,0.1, !TODO: document, DNA_RecBCD_complex_deg, Numeric,0.5, !TODO: document, ,,,, Protein_ClpXP_Forward, Numeric,0.5, !TODO: document, Protein_ClpXP_Reverse, Numeric,0.0001, !TODO: document, Protein_ClpXP_complex_deg, Numeric,0.1, !TODO: document, ,,,, RNAP_S70_F, Numeric,1, really fast, RNAP_S70_R, Numeric,0.01,, ,,,, GamS_RecBCD_F, Numeric,0.001, ! !TODO document, GamS_RecBCD_R, Numeric,0.09, !TODO: document, ,,,, TL_AA_Forward,Expression,1, !TODO: document, TL_AA_Reverse,Expression,.10, !TODO: document, +TL_AGTP_Forward,Expression,1, !TODO: document, TL_AGTP_Reverse,Expression,10, !TODO: document, ,,,, RNA_deg,Expression,1/360, s^-1 12 min half life (VN PRL) , RNase_F,Expression,1, nM^-1 s^-1 see derivation on wiki, RNase_R,Expression,2000, s^-1 see derivation on wiki, ,,,, Ribosome_Binding_F, Expression,.0022, TODO, Ribosome_Binding_R, Expression,4, TODO, ,,,, NTP_Forward_1,Expression,1, !TODO: document, NTP_Reverse_1,Expression,10, !TODO: document , +NTP_Forward_2,Expression,10, !TODO: document, NTP_Reverse_2,Expression,100, !TODO: document, ,,,, RNAPbound_termination_rate, Numeric,0.05, !TODO: document, +Ribobound_termination_rate, Numeric,50, !TODO: document, +,,,, RecBCD_ic, Numeric,5, !TODO: carry out MCMC and check lit, +RNAP_ic, Numeric,100, !TODO: carry out MCMC and check lit, +Ribo_ic, Numeric,30, !TODO: carry out MCMC and check lit, +RNase_ic, Numeric,100, !TODO: carry out MCMC and check lit, +,,,, +ATP_degradation_rate, Numeric,0.0002, !TODO: document, +ATP_degradation_start_time, Numeric,10800, in seconds !TODO: document, +ATP_regeneration_rate, Numeric,0.002, !TODO: document, +,,,, AGTP_Concentration, Expression,3000000, ATP and GTP are at 1.5mM each (JoVE), CUTP_Concentration, Expression,1800000, CTP and UTP are at 0.9mM each (JovE), AA_Concentration, Expression,30000000, 20 tyes of AAs, $20% usability$ 30mM JoVE \ No newline at end of file diff --git a/config/Emcmc2018_config.csv b/config/Emcmc2018_config.csv new file mode 100755 index 0000000..39f57d9 --- /dev/null +++ b/config/Emcmc2018_config.csv @@ -0,0 +1 @@ +NTPmodel,Numeric,2, NTP model in use !TODO: document, AAmodel,Numeric,2, AA model in use !TODO: document, Transcription_Rate, Expression, 6.1, need to get about 400nM of RNA, Translation_Rate, Expression, 24, >4 AA/second VN PRL, ,,,, DNA_RecBCD_Forward, Numeric,0.4, !TODO: document, DNA_RecBCD_Reverse, Numeric,0.1, !TODO: document, DNA_RecBCD_complex_deg, Numeric,0.5, !TODO: document, ,,,, Protein_ClpXP_Forward, Numeric,0.5, !TODO: document, Protein_ClpXP_Reverse, Numeric,0.0001, !TODO: document, Protein_ClpXP_complex_deg, Numeric,0.1, !TODO: document, ,,,, RNAP_S70_F, Numeric,1, really fast, RNAP_S70_R, Numeric,0.01,, ,,,, GamS_RecBCD_F, Numeric,0.001, ! !TODO document, GamS_RecBCD_R, Numeric,0.09, !TODO: document, ,,,, TL_AA_Forward,Expression,0.7408, !TODO: document TL_AA_Reverse,Expression,521.4302, !TODO: document, TL_AGTP_Forward,Expression,0.3012, !TODO: document, TL_AGTP_Reverse,Expression,602400, !TODO: document, ,,,, RNA_deg,Expression,014.53, s^-1 12 min half life (VN PRL), RNase_F,Expression,1, nM^-1 s^-1 see derivation on wiki, RNase_R,Expression,6.532200, s^-1 see derivation on wiki, ,,,, Ribosome_Binding_F, Expression,0.8187, TODO, Ribosome_Binding_R, Expression,421.4700*0.8187, TODO, ,,,, NTP_Forward_1,Expression,1, !TODO: document, NTP_Reverse_1,Expression,19.0278, !TODO: document , NTP_Forward_2,Expression,1, !TODO: document, NTP_Reverse_2,Expression,1199000, !TODO: document, ,,,, RNAPbound_termination_rate, Numeric,20.0374, !TODO: document, Ribobound_termination_rate, Numeric,38.2385, !TODO: document, ,,,, RecBCD_ic, Numeric,5, !TODO: carry out MCMC and check lit, RNAP_ic, Numeric,9.0194, !TODO: carry out MCMC and check lit, Ribo_ic, Numeric,44.3395, !TODO: carry out MCMC and check lit, RNase_ic, Numeric,32219, !TODO: carry out MCMC and check lit, ,,,, ATP_degradation_rate, Numeric,.000048661, !TODO: document, ATP_degradation_start_time, Numeric,5777.6e+03, in seconds !TODO: document, ATP_regeneration_rate, Numeric,0.0200, !TODO: document, ,,,, AGTP_Concentration, Expression,3000000, ATP and GTP are at 1.5mM each (JoVE), CUTP_Concentration, Expression,1800000, CTP and UTP are at 0.9mM each (JovE), AA_Concentration, Expression,30000000, 20 tyes of AAs, $20% usability$ 30mM JoVE \ No newline at end of file diff --git a/core/createFrateRules.m b/core/createFrateRules.m new file mode 100755 index 0000000..e2b97ed --- /dev/null +++ b/core/createFrateRules.m @@ -0,0 +1,35 @@ +function createFrateRules(Mobj, rxstr, varargin) +% This function takes a mobj, a reaction string, deleted the parameter associated +% with the reaction, and creates a global parameter that informs the rate fo that reaction +% +% m: model object +% rxstr: a string for the exact reaction whose parameters are are trying to bind +% pname: a string that has the letters F, R or Kd appended to it, and is an +% identifier for the parameters +rx = sbioselect(Mobj, 'reaction', ... + rxstr); % + +if rx.reversible + error('Expecting an irreversible reaction') +else + parname = get(rx.kineticlaw.getparameters, 'Name'); + Fval = get(rx.kineticlaw.getparameters, 'Value'); +end + +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', parname); +pTarget.delete; + +nvararg = length(varargin); +optargs = {parname, Fval}; +optargs(1:nvararg) = varargin; +[pname, Fval] = optargs{:}; + +% when there is only one parameter in the given reaction, parnames is a string + +rx.KineticLaw.ParameterVariableNames = pname; +% I am guessing this needs to be a string. + + if isempty(sbioselect(Mobj,'Type','Parameter', 'Name', pname)) + addparameter(Mobj, pname, Fval); + end +end \ No newline at end of file diff --git a/core/createKdRules.m b/core/createKdRules.m new file mode 100755 index 0000000..939d664 --- /dev/null +++ b/core/createKdRules.m @@ -0,0 +1,40 @@ +function createKdRules(Mobj, rxstr, pname, Kdval, Fval) +% This function takes a mobj, a reversible reaction string, deletes all +% parameters associated with the reaction, and uses another ordered list +% of parameter names, Kd values and F rate values to make globally scoped +% parameters associated with those reactions. it adds a rule which ties the +% F and R rates via the Kd +% +% m: model object +% rxstr: a string for the exact reaction whose parameters are are trying to bind +% pname: a cell of string that is an identifier for the parameters +% Kdval and Fval are the Kd and forward rate parameter, used to determine +% the reverse rate parameter + + +rx = sbioselect(Mobj, 'reaction', ... + rxstr); % +parnames = get(rx.kineticlaw.getparameters, 'Name'); +for i = 1:length(parnames) +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', parnames{i}); +pTarget.delete; +end +rx.KineticLaw.ParameterVariableNames = {[pname '_F'],[pname '_R']}; + +if isempty(sbioselect(Mobj,'Type','Parameter', 'Name', [pname '_Kd'])) +addparameter(Mobj, [pname '_Kd'], Kdval) ; +end + +if isempty(sbioselect(Mobj,'Type','Parameter', 'Name', [pname '_F'])) +addparameter(Mobj, [pname '_F'], Fval); +end + +if isempty(sbioselect(Mobj,'Type','Parameter', 'Name', [pname '_R'])) +addparameter(Mobj, [pname '_R'], 0) ; +end +ruleStr = [pname '_R = ' pname '_Kd*' pname '_F']; +if isempty(sbioselect(Mobj,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj, ruleStr, 'initialAssignment'); +end +end + diff --git a/core/findspecies.m b/core/findspecies.m old mode 100644 new mode 100755 diff --git a/core/getparam.m b/core/getparam.m new file mode 100755 index 0000000..7075fd5 --- /dev/null +++ b/core/getparam.m @@ -0,0 +1,66 @@ +function [params, paramtable] = getparam(m1) +% uses model object, and returns a table of its reactions and parameters. + +% because there can be multiple parameters of the same name, but in +% different reactions, we need to be careful and label the parameters +% by the reaction. Because the TXTL modeling toolbox does not name its +% reactions (it should!), we will use the entire reaction as the label. + + +% First, make a list of reaction scoped parameters +count = 0; +for i = 1:length(m1.reactions) + + rx = get(m1.reactions(i), 'reaction'); %reaction string + + p = m1.reactions(i).KineticLaw.getparameters ; + for j = 1:length(p) + count = count+1; + params{count,1} = get(p(j), 'Name'); + params{count,2} = get(p(j), 'Value'); + params{count,3} = rx; + params{count,4} = m1.reactions(i); + params{count,5} = p(j); + + rObj(count) = m1.reactions(i); + pNum(count) = count; + rName{count} = rx; + pObj(count) = p(j); + pName{count} = get(p(j), 'Name'); + pVal(count) = get(p(j), 'Value'); + end +end + +% then add global parameters which are not already in some reaction +% to this list (April 4: why would global params (like 'TXTL_clpx_deg' and +% 'AGTPdeg_F' be in reaction scope too? Im confused. +for i = 1:length(m1.parameters) + idx = find(strcmp(m1.parameters(i).Name, params(:,1)),1); + + if isempty(idx) + count = count+1; + params{count,1} = m1.parameters(i).Name; + params{count,2} = m1.parameters(i).value; + params{count,3} = 'global'; + params{count,4} = ''; + params{count,5} = m1.parameters(i); + + rObj(count) = NaN; % create a reaction null -> null (based on the type of rest of the column. wow!) + pNum(count) = count; + rName{count} = 'global'; + pObj(count) = m1.parameters(i); + pName{count} = m1.parameters(i).Name; + pVal(count) = m1.parameters(i).value; + + end +end + +% finally, compile a table array, to be output witht he standard cell +% array. Tables are often convenient. +[pNum, pName, pVal, rName, rObj, pObj ] = deal(pNum', pName', pVal', rName', rObj', pObj' ); +paramtable = table(pNum, pName, pVal, rName, rObj, pObj ); + + + + +end diff --git a/core/setparam.m b/core/setparam.m new file mode 100755 index 0000000..96ba20a --- /dev/null +++ b/core/setparam.m @@ -0,0 +1,45 @@ +function p = setparam(m, rStr, pStr, pVal) +%setparam: Set parameters in a model object +% m is model object, rStr is a single string of the reaction +% pStr is a single parameter name string, or a 2 by 1 cell of parameter +% strings +% pVal is a scalar, or a 2 by 1 vector of parameter values. + +if iscell(pStr) + if strcmp(rStr, 'global') + param1 = pStr{1}; + param2 = pStr{2}; + p1 = sbioselect(m.parameters, 'Name', param1); + p2 = sbioselect(m.parameters, 'Name', param2); + set(p1, 'Value', pVal(1)); + set(p2, 'Value', pVal(2)); + p = [p1;p2]; + else + param1 = pStr{1}; + param2 = pStr{2}; + rObj = sbioselect(m,'Type','reaction','reaction',rStr); + p1 = sbioselect(rObj,'Type','parameter','Name',param1); + p2 = sbioselect(rObj,'Type','parameter','Name',param2); + set(p1, 'Value', pVal(1)); + set(p2, 'Value', pVal(2)); + p = [p1;p2]; + end +elseif ischar(pStr) + % rStr needs to be a string, pVal needs to be a scalar + if strcmp(rStr, 'global') + param1 = pStr; + p = sbioselect(m.parameters, 'Name', param1); + set(p, 'Value', pVal(1)); + else + param1 = pStr; + rObj = sbioselect(m,'Type','reaction','reaction',rStr); + p = sbioselect(rObj,'Type','parameter','Name',param1); + set(p, 'Value', pVal(1)); + end +else + error('parameter strings must be cells or a string') +end + + +end + diff --git a/core/txtl_RNA_config.m b/core/txtl_RNA_config.m old mode 100644 new mode 100755 diff --git a/core/txtl_add_dna.m b/core/txtl_add_dna.m old mode 100644 new mode 100755 diff --git a/core/txtl_addreaction.m b/core/txtl_addreaction.m old mode 100644 new mode 100755 index 881d569..6265416 --- a/core/txtl_addreaction.m +++ b/core/txtl_addreaction.m @@ -27,7 +27,6 @@ function txtl_addreaction(tube,reactionEq,kineticLaw,parameters,varargin) reactionEq = strjoin(mergeStr,''); end - end %%% Vesicule mode %%% diff --git a/core/txtl_addspecies.m b/core/txtl_addspecies.m old mode 100644 new mode 100755 diff --git a/core/txtl_buffer.m b/core/txtl_buffer.m old mode 100644 new mode 100755 diff --git a/core/txtl_combine.m b/core/txtl_combine.m old mode 100644 new mode 100755 index 838732b..c2138a3 --- a/core/txtl_combine.m +++ b/core/txtl_combine.m @@ -128,6 +128,18 @@ Mobj.Species(i).InitialAmount = Mobj.Species(i).InitialAmount / totalvol; end +Mobj.UserData.energymode = 'regeneration'; +% See: +% https://www.mathworks.com/help/simbio/ug/selecting-absolute- +% tolerance-and-relative-tolerance-for-simulation.html +cs1 = getconfigset(Mobj); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); +% set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +% set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +% set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', 6*3600*1.0e-6*0.1); +% set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 + return % Copy a list of objects to a model diff --git a/core/txtl_component_config.m b/core/txtl_component_config.m old mode 100644 new mode 100755 diff --git a/core/txtl_dimerize.m b/core/txtl_dimerize.m old mode 100644 new mode 100755 index 0f2c0be..1585146 --- a/core/txtl_dimerize.m +++ b/core/txtl_dimerize.m @@ -53,21 +53,23 @@ function txtl_dimerize(mode, tube,protein,varargin) elseif strcmp(mode.add_dna_driver, 'Setup Reactions') reactionRate = varargin{1}; - + regIX = regexp(protein.Name,'^protein ', 'end'); + protstr = protein.Name((regIX+1):end); if isempty(reactionRate) error('txtltoolbox:txtl_dimerize:unspecifiedRR', ... 'Please specify dimerization reaction rates as an input vector'); elseif reactionRate(2) == 0 || length(reactionRate) == 1 Robj = addreaction(tube, ['2 [' protein.Name '] -> [' protein.Name 'dimer]']); Kobj = addkineticlaw(Robj,'MassAction'); - Pobj = addparameter(Kobj, 'kf', reactionRate(1)); - set(Kobj, 'ParameterVariableNames','kf'); + Pobj = addparameter(Kobj, ['TXTL_DIMER_' protstr '_' 'F'], reactionRate(1)); + set(Kobj, 'ParameterVariableNames',['TXTL_DIMER_' protstr '_' 'F']); else Robj = addreaction(tube, ['2 [' protein.Name '] <-> [' protein.Name 'dimer]']); Kobj = addkineticlaw(Robj,'MassAction'); - Pobjf = addparameter(Kobj, 'kf', reactionRate(1)); - Pobjr = addparameter(Kobj, 'kr', reactionRate(2)); - set(Kobj, 'ParameterVariableNames', {'kf', 'kr'}); + Pobjf = addparameter(Kobj, ['TXTL_DIMER_' protstr '_' 'F'], reactionRate(1)); + Pobjr = addparameter(Kobj, ['TXTL_DIMER_' protstr '_' 'R'], reactionRate(2)); + set(Kobj, 'ParameterVariableNames', {['TXTL_DIMER_' protstr '_' 'F'],... + ['TXTL_DIMER_' protstr '_' 'R']}); end %%%%%%%%%%%%%%%%%%% DRIVER MODE: error handling %%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/core/txtl_dna_degradation.m b/core/txtl_dna_degradation.m old mode 100644 new mode 100755 diff --git a/core/txtl_enzyme_resource_degradation.m b/core/txtl_enzyme_resource_degradation.m old mode 100644 new mode 100755 index 9c8b88a..366172d --- a/core/txtl_enzyme_resource_degradation.m +++ b/core/txtl_enzyme_resource_degradation.m @@ -1,15 +1,59 @@ function txtl_enzyme_resource_degradation(modelObj) +% -atp_deg_rate = modelObj.UserData.ReactionConfig.ATP_degradation_rate; -atp_deg_time = modelObj.UserData.ReactionConfig.ATP_degradation_start_time; -% After some time, ATP regeneration stops, leading to an overall decrease in -% ATP concentrations. c.f. V Noireaux 2003. -parameterObj = addparameter(modelObj, 'AGTPdeg_F', 0, 'ConstantValue', false); -evt2 = addevent(modelObj, ['time <= ' num2str(atp_deg_time)] , 'AGTPdeg_F = 0'); -evt3 = addevent(modelObj, ['time > ' num2str(atp_deg_time)], ['AGTPdeg_F = ' num2str(atp_deg_rate)]); -reactionObj = addreaction(modelObj,'AGTP -> AGTP_USED'); -kineticlawObj = addkineticlaw(reactionObj, 'MassAction'); -set(kineticlawObj, 'ParameterVariableName', 'AGTPdeg_F'); +if isfield(modelObj.UserData, 'energymode') && strcmp(modelObj.UserData.energymode, 'regeneration') + atp_deg_rate = modelObj.UserData.ReactionConfig.ATP_degradation_rate; + atp_regen_time = modelObj.UserData.ReactionConfig.ATP_degradation_start_time; + atp_reg_rate = modelObj.UserData.ReactionConfig.ATP_regeneration_rate; + % After some time, ATP regeneration stops, leading to an overall decrease in + % ATP concentrations. c.f. V Noireaux 2003 + parameterObj = addparameter(modelObj, 'AGTPreg_varying', atp_reg_rate, 'ConstantValue', false); + + % time of the regenration system turn off + parameterObj = addparameter(modelObj, 'AGTPdeg_time', atp_regen_time, 'ConstantValue', true); + + parameterObj = addparameter(modelObj, 'AGTPreg_ON', atp_reg_rate, 'ConstantValue', true); + parameterObj = addparameter(modelObj, 'AGTPdeg_rate', atp_deg_rate, 'ConstantValue', true); + + + evt2 = addevent(modelObj, 'time <= AGTPdeg_time' , 'AGTPreg_varying = AGTPreg_ON'); + + evt3 = addevent(modelObj, 'time > AGTPdeg_time',... + 'AGTPreg_varying = 0'); + + % constantly active first order degradation. + reactionObj = addreaction(modelObj,'AGTP -> AGMP'); + kineticlawObj = addkineticlaw(reactionObj, 'MassAction'); + set(kineticlawObj, 'ParameterVariableName', 'AGTPdeg_rate'); + + % regeneration system + reactionObj = addreaction(modelObj,'AGMP -> AGTP'); + kineticlawObj = addkineticlaw(reactionObj, 'MassAction'); + set(kineticlawObj, 'ParameterVariableName', 'AGTPreg_varying'); + +else + + atp_deg_rate = modelObj.UserData.ReactionConfig.ATP_degradation_rate; + atp_deg_time = modelObj.UserData.ReactionConfig.ATP_degradation_start_time; + + % After some time, ATP regeneration stops, leading to an overall decrease in + % ATP concentrations. c.f. V Noireaux 2003. + parameterObj = addparameter(modelObj, 'AGTPdeg_F', 0, 'ConstantValue', false); + + parameterObj = addparameter(modelObj, 'AGTPdeg_time', atp_deg_time, 'ConstantValue', true); + + parameterObj = addparameter(modelObj, 'AGTPdeg_rate', atp_deg_rate, 'ConstantValue', true); + + evt2 = addevent(modelObj, 'time <= AGTPdeg_time' , 'AGTPdeg_F = 0'); + + evt3 = addevent(modelObj, 'time > AGTPdeg_time',... + ['AGTPdeg_F = AGTPdeg_rate']);% '=' num2str(atp_deg_rate)] + + reactionObj = addreaction(modelObj,'AGTP -> AGTP_USED'); + + kineticlawObj = addkineticlaw(reactionObj, 'MassAction'); + set(kineticlawObj, 'ParameterVariableName', 'AGTPdeg_F'); +end end \ No newline at end of file diff --git a/core/txtl_extract.m b/core/txtl_extract.m old mode 100644 new mode 100755 diff --git a/core/txtl_getDefaultPlotDataStruct.m b/core/txtl_getDefaultPlotDataStruct.m old mode 100644 new mode 100755 diff --git a/core/txtl_mrna_degradation.m b/core/txtl_mrna_degradation.m old mode 100644 new mode 100755 index 3fa4192..beb8898 --- a/core/txtl_mrna_degradation.m +++ b/core/txtl_mrna_degradation.m @@ -33,7 +33,7 @@ function txtl_mrna_degradation(mode, tube, dna, rna, rbs_spec) complexF = degRate/10; complexR = degRate/40; end - + length_over_2 = round(rna.UserData/2); % Setup RNA degradation reactions, by searching for strings with rna in % them, and then degrading those strings. listOfSpecies = get(tube.species, 'name'); @@ -57,17 +57,25 @@ function txtl_mrna_degradation(mode, tube, dna, rna, rbs_spec) productspecies = []; for j = 1:length(nonRNAlist) - if strcmp(nonRNAlist{j}, '2AGTP') - nonRNAlist{j} = '2 AGTP'; - elseif strcmp(nonRNAlist{j}, 'term_Ribo') + % if in the complex we have term_Ribo, then we need to + % return Ribo, not create nonsensical species term_Ribo. + if strcmp(nonRNAlist{j}, 'term_Ribo') nonRNAlist{j} = 'Ribo'; end - productspecies = [productspecies ' + ' nonRNAlist{j}]; end - txtl_addreaction(tube,[RNAcomplexes{i} ':RNase -> RNase' productspecies],... - 'MassAction',{'TXTL_RNAdeg_F',degRate}); + if isfield(tube.UserData, 'energymode') && strcmp(tube.UserData.energymode, 'regeneration') + + txtl_addreaction(tube,[RNAcomplexes{i} ':RNase -> RNase + '... + num2str(length_over_2) ' AGMP + ' num2str(length_over_2) ' CUMP '... + productspecies],... + 'MassAction',{'TXTL_RNAdeg_kc',degRate}); + + else + txtl_addreaction(tube,[RNAcomplexes{i} ':RNase -> RNase ' productspecies],... + 'MassAction',{'TXTL_RNAdeg_kc',degRate}); + end end end diff --git a/core/txtl_newtube.m b/core/txtl_newtube.m old mode 100644 new mode 100755 diff --git a/core/txtl_parsespec.m b/core/txtl_parsespec.m old mode 100644 new mode 100755 diff --git a/core/txtl_plot.m b/core/txtl_plot.m old mode 100644 new mode 100755 diff --git a/core/txtl_plot_gui.fig b/core/txtl_plot_gui.fig deleted file mode 100644 index 56dd2a5..0000000 Binary files a/core/txtl_plot_gui.fig and /dev/null differ diff --git a/core/txtl_plot_gui.m b/core/txtl_plot_gui.m old mode 100644 new mode 100755 diff --git a/core/txtl_protein_degradation.m b/core/txtl_protein_degradation.m old mode 100644 new mode 100755 index 583aeb6..c7de118 --- a/core/txtl_protein_degradation.m +++ b/core/txtl_protein_degradation.m @@ -75,7 +75,7 @@ This tag consists of a short peptide sequence (AANDENYALVA) and is attached % Protein monomer binds with protein ClpX*P protease reactionRate = varargin{1}; - p1 = regexp(listOfSpecies,'^protein ClpX(-lva)*?$', 'match'); % test whether the star causes problems + p1 = regexp(listOfSpecies,'^protein ClpX(-lva)?*$', 'match'); % test whether the star causes problems listOfProtein = vertcat(p1{:}); for k = 1:size(listOfProtein,1) diff --git a/core/txtl_reaction_config.m b/core/txtl_reaction_config.m old mode 100644 new mode 100755 index 7ec24d7..7f45cd4 --- a/core/txtl_reaction_config.m +++ b/core/txtl_reaction_config.m @@ -40,6 +40,7 @@ Ribo_ic; RNase_ic; ATP_degradation_rate; + ATP_regeneration_rate; ATP_degradation_start_time end diff --git a/core/txtl_runsim.m b/core/txtl_runsim.m old mode 100644 new mode 100755 index e38cfd1..27bf155 --- a/core/txtl_runsim.m +++ b/core/txtl_runsim.m @@ -1,41 +1,41 @@ - - -% Written by Zoltan A Tuza, Sep 2012 +% +% +% Written by Zoltan A Tuza and Vipul Singhal, Sep 2012 % % Copyright (c) 2012 by California Institute of Technology % All rights reserved. % - - +% +% %%%%%% DEFAULT MODE %%%%%% % [t_ode, x_ode, modelObj, simData] = txtl_runsim(modelObj, configsetObj, time_vector, data, simData) - +% % Input combinations: % modelObj (this runs a parameter estimation mode, no simulation) % modelObj, configsetObj % modelObj, configsetObj, simData % modelObj, configsetObj, time_vector, data - - +% +% % Output combinations: % simData % t_ode, x_ode % t_ode, x_ode, modelObj % t_ode, x_ode, modelObj, simData - +% %%%%%% EVENTS MODE %%%%%% % [t_ode, x_ode, modelObj, simData] = txtl_runsim(modelObj, configsetObj, eventTriggers, eventFcns, time_vector, data, simData, 'events') - +% % Input combinations: % modelObj, configsetObj, eventTriggers, eventFcns, 'events' % modelObj, configsetObj, eventTriggers, eventFcns, time_vector, data, 'events' % modelObj, configsetObj, eventTriggers, eventFcns, time_vector, data, simData, 'events' - - +% +% % when using this, it is Necessary to use the model object returned by this % function in subsequent calls / plotting. This is because the first call to % this function sets the reactions in the modelObject. - +% % Redistribution and use in source and binary forms, with or without % modification, are permitted provided that the following conditions are diff --git a/core/txtl_runsim_events.m b/core/txtl_runsim_events.m old mode 100644 new mode 100755 diff --git a/core/txtl_runsim_sensitivity.m b/core/txtl_runsim_sensitivity.m old mode 100644 new mode 100755 diff --git a/core/txtl_setup_default_basepair_length.m b/core/txtl_setup_default_basepair_length.m old mode 100644 new mode 100755 diff --git a/core/txtl_setup_new_protein_added.m b/core/txtl_setup_new_protein_added.m old mode 100644 new mode 100755 diff --git a/core/txtl_tetramerize.m b/core/txtl_tetramerize.m old mode 100644 new mode 100755 diff --git a/core/txtl_transcription.m b/core/txtl_transcription.m old mode 100644 new mode 100755 index 229172d..8f2bb18 --- a/core/txtl_transcription.m +++ b/core/txtl_transcription.m @@ -7,7 +7,7 @@ % Written by Richard Murray, 9 Sep 2012 % Edited by Vipul Singhal, 2012 - 2017 -% +% % Copyright (c) 2012 by California Institute of Technology % All rights reserved. % @@ -65,66 +65,149 @@ function txtl_transcription(mode, varargin) % calculate the transcription rate from information in the config file % and the length of the gene to be transcribed - ktxExpression = strrep(tube.Userdata.ReactionConfig.Transcription_Rate,... - 'RNA_Length','rna.UserData'); - ktx = eval(ktxExpression); %kt/rna_length = 1.5(ntps^-1) / rnalength(ntp) - - % compute the consumption reaction rate - ntpcnt = round(rna.UserData/2); - % ntpcnt = rna.length/2. That way we can keep AGTP - %= atp + gtp. - NTPConsumptionRate = {'TXTL_NTP_consumption',(ntpcnt-1)*ktx}; - - % write down the string for the transcription equation - RNAPbound_term = ['term_' RNAPbound]; - transcriptionEq = ... - ['[CUTP:AGTP:' RNAPbound '] -> ' RNAPbound_term ' + ' rna.Name]; - % add the consumption and termination reactions. + % add global elongation parameter, + txglob = sbioselect(tube, 'Name', 'TX_elong_glob', 'Type', 'Parameter'); + if isempty(txglob) + addparameter(tube, 'TX_elong_glob',tube.Userdata.ReactionConfig.Transcription_Rate); + end + + + % then add the dependent parameters for both the tx and the consumption + % reactions, also at the global scope, and tie the three parameters via + % a couple of initial assignment rules. + + % start with grabbing the name strings for the RNA + temp = regexp(rna.name, 'RNA (\w*)--(\w*)', 'tokens'); + rnaspec = [temp{1}{1} '_' temp{1}{2}]; + + % use this sting to name the transcription and consumption reactions + txparamname = ['TX_transcription_' rnaspec]; + ntpconsname = ['TX_NTPcons_' rnaspec]; + + % get the RNA length, which decides what the actual mRNA production + % rate is + RNAlength = rna.UserData; + % add the transcription parameter in the model scope, with the length + % adjusted value. + if isempty(sbioselect(tube, 'Type', 'Parameter', 'Name', txparamname)) + addparameter(tube, txparamname,tube.Userdata.ReactionConfig.Transcription_Rate/RNAlength); + end + + % compute the consumption reaction rate as follows + % ntpcnt = rna.length/4. + ntpcnt = round(RNAlength/4); % + % add the ntp consumption parameter in the global scope. + if isempty(sbioselect(tube, 'Type', 'Parameter', 'Name', ntpconsname)) + addparameter(tube, ntpconsname,tube.Userdata.ReactionConfig.Transcription_Rate/RNAlength*(ntpcnt-1)); + end + + + % how to think about this: 1 nM of AGTP is 0.5nM of ATP, 0.5nM of GTP. + % Since the reaction rnap:dna:agtp:cutp -> rnap:dna_term + mrna uses + % 2nM of NTPs to make 1nM of mRNA, if the mrna is 1000ntp long, then we + % still need to consume 998nM of ntp. The rate at which the above + % reaction took place is kt/1000. + % + % so now we consider the ntp consumption reaction. + % rnap:dna:agtp:cutp -> rnap:dna + % each time this reaction fires, it uses 2nM of ntp. so it needs to + % fire 998/2 = 499 times for each time the earlier reaction fires. Now + % 499 is 1000/2 - 1, thus we define ntpcnt = rnalength/2, and the + % reaction of the consumption reaction is ktx/rnalength*(ntpcnt-1) + + % now we actually add the rule that sets the transcription rate and the + % ntp consumption rate. + ruleStr = [txparamname ' = TX_elong_glob/' num2str(RNAlength)]; + if isempty(sbioselect(tube,'Type','Rule', 'Rule', ruleStr)) + addrule(tube, ruleStr, 'initialAssignment'); + end + + ruleStr = [ntpconsname ... + ' = TX_elong_glob/' num2str(RNAlength) '*(' num2str(ntpcnt) '-1)']; + if isempty(sbioselect(tube,'Type','Rule', 'Rule', ruleStr)) + addrule(tube, ruleStr, 'initialAssignment'); + end + + % write down the string for the transcription equation depending on the + % mode of transcription. ie, if we have the energy regeneration mode, + % then we model AGMP, otherwise we do the usual... except, with and + % without energy mode ends up being exactly the same for + % teranscription. ... + if isfield(tube.UserData, 'energymode') && strcmp(tube.UserData.energymode, 'regeneration') + + RNAPbound_term = ['term_' RNAPbound]; + transcriptionEq = ... + ['[CUTP:AGTP:' RNAPbound '] -> ' RNAPbound_term ' + '... + rna.Name]; + + else + RNAPbound_term = ['term_' RNAPbound]; + transcriptionEq = ... + ['[CUTP:AGTP:' RNAPbound '] -> ' RNAPbound_term ' + ' rna.Name]; + + end + + % add the actual transcription reaction. Note that we use addreaction ( + % a simbiology function) as opposed to the txtl toolbox wrapper + % txtl_addreaction, because we want to specify a model scoped parameter + % as a parmeter, and not create a reaction scoped parameter. + reactionObj = addreaction(tube,transcriptionEq); + addkineticlaw (reactionObj, 'MassAction'); + reactionObj.KineticLaw.ParameterVariableNames = txparamname; + + + % add the consumption reactions + reactionObj = addreaction(tube,['[CUTP:AGTP:' RNAPbound '] -> ' RNAPbound]); + addkineticlaw (reactionObj, 'MassAction'); + reactionObj.KineticLaw.ParameterVariableNames = ntpconsname; + + + + % add the termination reactions if nargin < 6 error('the number of argument should be at least 6, not %d',nargin); elseif nargin > 6 extraSpecies = varargin{6}; - % processing the extraSpecies + % processing the extraSpecies, like activators, inducers etc. extraStr = extraSpecies{1}; for k=2:size(extraSpecies,2) extraStr = [extraStr ' + ' extraSpecies{k}]; end - % consumption reaction in the extra species case - txtl_addreaction(tube,['[CUTP:AGTP:' RNAPbound '] -> ' RNAPbound],... - 'MassAction',NTPConsumptionRate); - - txtl_addreaction(tube,['[' RNAPbound_term '] -> ' RNAP ' + ' dna.Name ' + ' extraStr],... - 'MassAction',{'TXTL_RNAPBOUND_TERMINATION_RATE', tube.UserData.ReactionConfig.RNAPbound_termination_rate}); + + % the termination reaction parameter is reaction scoped, and can be + % globalized with the globalize_params function. + txtl_addreaction(tube,['[' RNAPbound_term '] -> '... + RNAP ' + ' dna.Name ' + ' extraStr],... + 'MassAction',... + {'TXTL_RNAPBOUND_TERMINATION_RATE', ... + tube.UserData.ReactionConfig.RNAPbound_termination_rate}); else - % consumption reaction - txtl_addreaction(tube,['[CUTP:AGTP:' RNAPbound '] -> ' RNAPbound],... - 'MassAction',NTPConsumptionRate); - %termination reaction txtl_addreaction(tube,['[' RNAPbound_term '] -> ' RNAP ' + ' dna.Name],... - 'MassAction',{'TXTL_RNAPBOUND_TERMINATION_RATE', tube.UserData.ReactionConfig.RNAPbound_termination_rate}); + 'MassAction',... + {'TXTL_RNAPBOUND_TERMINATION_RATE', ... + tube.UserData.ReactionConfig.RNAPbound_termination_rate}); end % define the nucleotide binding parameters - NTPparameters = {'TXTL_NTP_RNAP_F', tube.UserData.ReactionConfig.NTP_Forward_1; - 'TXTL_NTP_RNAP_R', tube.UserData.ReactionConfig.NTP_Reverse_1}; - NTPparameters_fast = {'TXTL_NTP_RNAP_F', tube.UserData.ReactionConfig.NTP_Forward_2; - 'TXTL_NTP_RNAP_R', tube.UserData.ReactionConfig.NTP_Reverse_2}; + NTPparameters_step1 = {'TXTL_NTP_RNAP_1_F', tube.UserData.ReactionConfig.NTP_Forward_1; + 'TXTL_NTP_RNAP_1_R', tube.UserData.ReactionConfig.NTP_Reverse_1}; + NTPparameters_step2 = {'TXTL_NTP_RNAP_2_F', tube.UserData.ReactionConfig.NTP_Forward_2; + 'TXTL_NTP_RNAP_2_R', tube.UserData.ReactionConfig.NTP_Reverse_2}; % add the nucleotide binding reaction txtl_addreaction(tube,['[' RNAPbound '] + AGTP <-> [AGTP:' RNAPbound ']'],... - 'MassAction',NTPparameters_fast); + 'MassAction',NTPparameters_step1); txtl_addreaction(tube,['[' RNAPbound '] + CUTP <-> [CUTP:' RNAPbound ']'],... - 'MassAction',NTPparameters_fast); + 'MassAction',NTPparameters_step1); txtl_addreaction(tube,['[AGTP:' RNAPbound '] + CUTP <-> [CUTP:AGTP:' RNAPbound ']'],... - 'MassAction',NTPparameters); + 'MassAction',NTPparameters_step2); txtl_addreaction(tube,['[CUTP:' RNAPbound '] + AGTP <-> [CUTP:AGTP:' RNAPbound ']'],... - 'MassAction',NTPparameters); + 'MassAction',NTPparameters_step2); + - % add the actual transcription reaction - txtl_addreaction(tube,transcriptionEq,'MassAction',{'TXTL_transcription_rate1',ktx}); %%%%%%%%%%%%%%%%%%% DRIVER MODE: error handling %%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/core/txtl_transcription_RNAcircuits.m b/core/txtl_transcription_RNAcircuits.m old mode 100644 new mode 100755 diff --git a/core/txtl_translation.m b/core/txtl_translation.m old mode 100644 new mode 100755 index 3c3a4a6..2b86c5f --- a/core/txtl_translation.m +++ b/core/txtl_translation.m @@ -4,17 +4,17 @@ % Redistribution and use in source and binary forms, with or without % modification, are permitted provided that the following conditions are % met: -% +% % 1. Redistributions of source code must retain the above copyright % notice, this list of conditions and the following disclaimer. % -% 2. Redistributions in binary form must reproduce the above copyright -% notice, this list of conditions and the following disclaimer in the +% 2. Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in the % documentation and/or other materials provided with the distribution. % -% 3. The name of the author may not be used to endorse or promote products +% 3. The name of the author may not be used to endorse or promote products % derived from this software without specific prior written permission. -% +% % THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR % IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED % WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -35,80 +35,116 @@ function txtl_translation(mode, tube, dna, rna, protein, Ribobound) %%%%%%%%%%%%%%%%%%% DRIVER MODE: Setup Species %%%%%%%%%%%%%%%%%%%%%%%%%%%% if strcmp(mode.add_dna_driver, 'Setup Species') - % Set up the species for translation - Ribobound_term = ['term_' Ribobound.Name ]; - coreSpecies = {'AA',['AA:2AGTP:' Ribobound.Name],Ribobound_term, 'Ribo'}; + % Set up the species for translation + Ribobound_term = ['term_' Ribobound.Name ]; + coreSpecies = {'AA',['AA:AGTP:' Ribobound.Name],Ribobound_term, 'Ribo'}; % empty cellarray for amount => zero amount txtl_addspecies(tube, coreSpecies, cell(1,size(coreSpecies,2)), 'Internal'); -%%%%%%%%%%%%%%%%%%% DRIVER MODE: Setup Reactions %%%%%%%%%%%%%%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%%% DRIVER MODE: Setup Reactions %%%%%%%%%%%%%%%%%%%%%%%%%% elseif strcmp(mode.add_dna_driver, 'Setup Reactions') + %% Resource binding AAparameters = {'TL_AA_F',tube.UserData.ReactionConfig.TL_AA_Forward; - 'TL_AA_R',tube.UserData.ReactionConfig.TL_AA_Reverse}; + 'TL_AA_R',tube.UserData.ReactionConfig.TL_AA_Reverse}; AGTPparameters = {'TL_AGTP_F',tube.UserData.ReactionConfig.TL_AGTP_Forward; - 'TL_AGTP_R',tube.UserData.ReactionConfig.TL_AGTP_Reverse}; - - % translation rate - ktlExpression = strrep(tube.UserData.ReactionConfig.Translation_Rate,... - 'Protein_Length','protein.UserData'); - ktl_rbs = eval(ktlExpression); - - % define termination complex. - Ribobound_term = ['term_' Ribobound.Name ]; + 'TL_AGTP_R',tube.UserData.ReactionConfig.TL_AGTP_Reverse}; + + % resource binding + txtl_addreaction(tube, ... + ['[' Ribobound.Name '] + AA <-> [AA:' Ribobound.Name ']'],... + 'MassAction',AAparameters); + txtl_addreaction(tube, ... + ['[AA:' Ribobound.Name '] + AGTP <-> [AA:AGTP:' Ribobound.Name ']'],... + 'MassAction',AGTPparameters); + + + %% create the rules for the global parameters for the TL reaction and the consumption reaction + + % add global elongation parameter + tlglob = sbioselect(tube, 'Name', 'TL_elong_glob', 'Type', 'Parameter'); + if isempty(tlglob) + addparameter(tube, 'TL_elong_glob',tube.UserData.ReactionConfig.Translation_Rate); + end + + % grab the name strings for the protein + temp = regexp(protein.name, 'protein (\w*)', 'tokens'); + protspec = [temp{1}{1}]; + + % use this sting to name the translation and consumption reactions + tlparamname = ['TL_translation_' protspec]; + resourceconsname = ['TL_REScons_' protspec]; + + % get the protein length, which decides what the actual protein production + % rate is + proteinlength = round(protein.UserData); % this is in amino acids not nucleotides. + + % add the transcription parameter in the model scope, with the length + % adjusted value. The value specified here actually does not matter + % because we will use a rule to set it. + addparameter(tube, tlparamname,0); - % AA consumption models - if tube.UserData.ReactionConfig.AAmodel == 1 - % multimolecular binding, bad idea - aacnt = floor(protein.UserData/100); % get number of K amino acids - if (aacnt == 0) - aastr = ''; - else - aastr = int2str(aacnt); - end + % add the aa consumption parameter in the global scope. the value it is + % initialized to does not matter, since a rule will set it. + addparameter(tube, resourceconsname, 0); + + % now we actually add the rule that sets the translation rate and the + % aa consumption rate. + ruleStr = [tlparamname ' = TL_elong_glob/' num2str(proteinlength)]; + if isempty(sbioselect(tube,'Type','Rule', 'Rule', ruleStr)) + addrule(tube, ruleStr, 'initialAssignment'); + end + + % do the same for the consumption reactions + ruleStr = [resourceconsname ... + ' = TL_elong_glob/' num2str(proteinlength) '*(' num2str(proteinlength) '-1)']; + if isempty(sbioselect(tube,'Type','Rule', 'Rule', ruleStr)) + addrule(tube, ruleStr, 'initialAssignment'); + end + + + Ribobound_term = ['term_' Ribobound.Name ]; + % add the reaction + if isfield(tube.UserData, 'energymode') && strcmp(tube.UserData.energymode, 'regeneration') + + reactionObj = addreaction(tube, ... + ['[AA:AGTP:' Ribobound.Name '] -> ' Ribobound_term ' + ' protein.Name ' + AGMP' ]); + addkineticlaw (reactionObj, 'MassAction'); + reactionObj.KineticLaw.ParameterVariableNames = tlparamname; + + % add the consumption reactions. + reactionObj = addreaction(tube, ... + ['[AA:AGTP:' Ribobound.Name '] -> ' Ribobound_term ' + AGMP']); + addkineticlaw (reactionObj, 'MassAction'); + reactionObj.KineticLaw.ParameterVariableNames = resourceconsname; + - txtl_addreaction(tube,... - ['[' Ribobound.Name '] + ' aastr ' AA <-> [AA:' Ribobound.Name ']'],... - 'MassAction',AAparameters); else - % consumption reaction usage, a much better method. - % resource binding - txtl_addreaction(tube, ... - ['[' Ribobound.Name '] + AA <-> [AA:' Ribobound.Name ']'],... - 'MassAction',AAparameters); - txtl_addreaction(tube, ... - ['[AA:' Ribobound.Name '] + 2 AGTP <-> [AA:2AGTP:' Ribobound.Name ']'],... - 'MassAction',AGTPparameters); + reactionObj = addreaction(tube, ... + ['[AA:AGTP:' Ribobound.Name '] -> ' Ribobound_term ' + ' protein.Name ]); + addkineticlaw (reactionObj, 'MassAction'); + reactionObj.KineticLaw.ParameterVariableNames = tlparamname; - % consumption reaction - aacnt = floor(protein.UserData/100); - aa_consump_rate = (aacnt-1)*ktl_rbs; - txtl_addreaction(tube, ... - ['[AA:2AGTP:' Ribobound.Name '] -> ' Ribobound_term],... - 'MassAction',{'TXTL_TL_AA_consumption',aa_consump_rate}); + % add the consumption reactions. + reactionObj = addreaction(tube, ... + ['[AA:AGTP:' Ribobound.Name '] -> ' Ribobound_term]); + addkineticlaw (reactionObj, 'MassAction'); + reactionObj.KineticLaw.ParameterVariableNames = resourceconsname; end - % Translation (creation of protein and termination complex) - txtl_addreaction(tube, ... - ['[AA:2AGTP:' Ribobound.Name '] -> ' Ribobound_term ' + ' protein.Name ],... - 'MassAction',{'TXTL_TL_rate',ktl_rbs}); - % translation termination reaction - txtl_addreaction(tube,['[' Ribobound_term '] -> ' rna.Name ' + Ribo'],... - 'MassAction',{'TXTL_RIBOBOUND_TERMINATION_RATE', tube.UserData.ReactionConfig.Ribobound_termination_rate}); - % !TODO add these parameters to the config files and the parameter class + %%%%% - % old translation -% txtl_addreaction(tube, ... -% ['[AA:AGTP:' Ribobound.Name '] -> ' rna.Name ' + ' protein.Name ' + Ribo'],... -% 'MassAction',{'TXTL_TL_rate',ktl_rbs}); -%%%%%%%%%%%%%%%%%%% DRIVER MODE: error handling %%%%%%%%%%%%%%%%%%%%%%%%%%% + % translation termination reaction + txtl_addreaction(tube,['[' Ribobound_term '] -> ' rna.Name ' + Ribo'],... + 'MassAction',{'TXTL_RIBOBOUND_TERMINATION_RATE', tube.UserData.ReactionConfig.Ribobound_termination_rate}); + %%%%%%%%%%%%%%%%%%% DRIVER MODE: error handling %%%%%%%%%%%%%%%%%%%%%%%%%%% else error('txtltoolbox:txtl_translation:undefinedmode', ... - 'The possible modes are ''Setup Species'' and ''Setup Reactions''.'); -end - + 'The possible modes are ''Setup Species'' and ''Setup Reactions''.'); +end + end \ No newline at end of file diff --git a/core/txtl_tx_cascade.m b/core/txtl_tx_cascade.m old mode 100644 new mode 100755 diff --git a/core/txtl_utr_1SNP10UTR1.m b/core/txtl_utr_1SNP10UTR1.m old mode 100644 new mode 100755 diff --git a/core/txtl_utr_SNP10UTR1.m b/core/txtl_utr_SNP10UTR1.m old mode 100644 new mode 100755 diff --git a/core/txtl_utr_rbs.m b/core/txtl_utr_rbs.m old mode 100644 new mode 100755 diff --git a/data/charac_ZachIFFL1.m b/data/charac_ZachIFFL1.m old mode 100644 new mode 100755 diff --git a/data/charac_ZachIFFL1_inducersweep.m b/data/charac_ZachIFFL1_inducersweep.m old mode 100644 new mode 100755 diff --git a/data/charac_ZachIFFL1_level1sweep.m b/data/charac_ZachIFFL1_level1sweep.m old mode 100644 new mode 100755 diff --git a/data/charac_ZachIFFL1_level3sweep.m b/data/charac_ZachIFFL1_level3sweep.m old mode 100644 new mode 100755 diff --git a/data/charac_ZachIFFL1_tetRsweep.m b/data/charac_ZachIFFL1_tetRsweep.m old mode 100644 new mode 100755 diff --git a/data/charac_plas.m b/data/charac_plas.m old mode 100644 new mode 100755 diff --git a/data/charac_plasR_inducerSweep.m b/data/charac_plasR_inducerSweep.m old mode 100644 new mode 100755 diff --git a/data/charac_ptet.m b/data/charac_ptet.m old mode 100644 new mode 100755 diff --git a/data/charac_ptet_DNAsweep.m b/data/charac_ptet_DNAsweep.m old mode 100644 new mode 100755 diff --git a/data/e15_pr_gfp_pr_gfp_mg_grad_082113_data.csv b/data/e15_pr_gfp_pr_gfp_mg_grad_082113_data.csv old mode 100644 new mode 100755 diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100755 index 0000000..7b6a4cc --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1,104 @@ +##--------------------------------------------------- +## Remove autosaves generated by the Matlab editor +## We have git for backups! +##--------------------------------------------------- + +# .mat data files +*.mat + +# Windows default autosave extension +*.asv + +# OSX / *nix default autosave extension +*.m~ + +# Compiled MEX binaries (all platforms) +*.mex* + +# Simulink Code Generation +slprj/ + +# data dirs +/mcmc_simbio/exp_data/Zach_IFFL_raw +mcmc_simbio/exp_data/from_Tierra_Bio_2018_oct + +# Session info +octave-workspace + +# Simulink autosave extension +.autosave + +# .DS_store files +.DS_Store + +*.sublime-project +*.sublime-workspace + +*.txt +*.todo +*.pdf + +# Image files +*.png +*.tiff +*.eps +*.jpg +*.svg +# *.fig +# data files +*.gc +*.xlsx +# *.csv + +# movie files +*.mp4 + +youngha_data_conversion/ +html/ + +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# MATLAB Crash Dumps # +###################### +Crash_logs_*/ +manual_txtlsim_parameters.m + +# reaction files I use +*.reactions* +designing_masterVector_for_IFFL diff --git a/doc/Config_E6_screenshot.png b/doc/Config_E6_screenshot.png old mode 100644 new mode 100755 diff --git a/doc/GeneExpressionPlotActuallyProducedByCode.png b/doc/GeneExpressionPlotActuallyProducedByCode.png old mode 100644 new mode 100755 diff --git a/doc/Makefile b/doc/Makefile old mode 100644 new mode 100755 diff --git a/doc/NegativeAutoregulationPlotActuallyProducedByCode.png b/doc/NegativeAutoregulationPlotActuallyProducedByCode.png old mode 100644 new mode 100755 diff --git a/doc/appendix.tex b/doc/appendix.tex old mode 100644 new mode 100755 diff --git a/doc/core_functionalities.tex b/doc/core_functionalities.tex old mode 100644 new mode 100755 diff --git a/doc/currentTODOlist.html b/doc/currentTODOlist.html old mode 100644 new mode 100755 diff --git a/doc/examples.tex b/doc/examples.tex old mode 100644 new mode 100755 diff --git a/doc/extractTODOlist b/doc/extractTODOlist deleted file mode 100755 index f6c1b10..0000000 --- a/doc/extractTODOlist +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -# m http://www.linuxweblog.com/bash-argument-numbers-check -EXPECTED_ARGS=1 -E_BADARGS=65 -if [ $# -gt $EXPECTED_ARGS ] -then - echo "Usage: ./extract [starting_directory]" >&2 - exit $E_BADARGS -fi - -# By default, start in the current working directory, but if they provide -# an argument, use that instead. -if [ $# -eq $EXPECTED_ARGS ] -then - startingDir=$1 -else - startingDir="." -fi - -# Start creating the HTML document -echo "" -echo "" -echo "" - -# The output of the find command will look like -# ./Telephone.java:20: // todo: Document - -find $startingDir -name "*.m" -exec grep -Hin TODO {} + | -# Allows the script to read in piped in arguments -while read data; do - - # The location of the file is the first argument - fileLoc=`echo "$data" | cut -d ":" -f 1` - fileName=`basename $fileLoc` - - # the line number is the second - lineNumber=`echo "$data" | cut -d ":" -f 2` - - # all arguments after the second colon are the comment. Eliminate the TODO - # text with a simple find and replace. - # Note: only handles todo and TODO, would need some more logic to handle other cases - comment=`echo "$data" | cut -d ":" -f 3- | sed -e 's/^[ ]*//' -e 's/[\/*]*[ ]*//' -e 's/TODO/todo/' -e 's/todo[:]*[ ]*//'` - echo "" - echo " " - echo " " - echo "" -done - -# Finish off the HTML document -echo "
LocationComment
$fileName ($lineNumber)$comment
" -echo "" - -exit 0 diff --git a/doc/geneExpr schematic.png b/doc/geneExpr schematic.png old mode 100644 new mode 100755 diff --git a/doc/gene_expression_1nM.png b/doc/gene_expression_1nM.png old mode 100644 new mode 100755 diff --git a/doc/induction.png b/doc/induction.png old mode 100644 new mode 100755 diff --git a/doc/installation.tex b/doc/installation.tex old mode 100644 new mode 100755 diff --git a/doc/intro.tex b/doc/intro.tex old mode 100644 new mode 100755 diff --git a/doc/negauto_1nM_toolbox.png b/doc/negauto_1nM_toolbox.png old mode 100644 new mode 100755 diff --git a/doc/negautoreg_induction schematic.png b/doc/negautoreg_induction schematic.png old mode 100644 new mode 100755 diff --git a/doc/txtl_template.m b/doc/txtl_template.m deleted file mode 100644 index 909085c..0000000 --- a/doc/txtl_template.m +++ /dev/null @@ -1,44 +0,0 @@ -% txtl_runsim_events.m - template file for MATLAB functions - -% -% This file is a template that includes the boilerplate for creating a -% MATLAB function with all of the BSD licensing information at the top. - - -% -% Copyright (c) 2012 by California Institute of Technology -% All rights reserved. -% -% Redistribution and use in source and binary forms, with or without -% modification, are permitted provided that the following conditions are -% met: -% -% 1. Redistributions of source code must retain the above copyright -% notice, this list of conditions and the following disclaimer. -% -% 2. Redistributions in binary form must reproduce the above copyright -% notice, this list of conditions and the following disclaimer in the -% documentation and/or other materials provided with the distribution. -% -% 3. The name of the author may not be used to endorse or promote products -% derived from this software without specific prior written permission. -% -% THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -% IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -% DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -% INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -% STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -% IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -% POSSIBILITY OF SUCH DAMAGE. - - - - -% Automatically use MATLAB mode in Emacs (keep at end of file) -% Local variables: -% mode: matlab -% End: diff --git a/doc/usersmanual.pdf b/doc/usersmanual.pdf old mode 100644 new mode 100755 diff --git a/doc/usersmanual.tex b/doc/usersmanual.tex old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/calibrate_lacI_tetR.m b/examples/CompanionFiles/calibrate_lacI_tetR.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/plotGeneticToggle.m b/examples/CompanionFiles/plotGeneticToggle.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/plotGeneticToggle2.m b/examples/CompanionFiles/plotGeneticToggle2.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/plotGeneticToggle2_troubleshoot.m b/examples/CompanionFiles/plotGeneticToggle2_troubleshoot.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/rawdata_CSHL.m b/examples/CompanionFiles/rawdata_CSHL.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_param_lacItoggleSwitch.csv b/examples/CompanionFiles/txtl_param_lacItoggleSwitch.csv old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_param_lacItoggleSwitch2.csv b/examples/CompanionFiles/txtl_param_lacItoggleSwitch2.csv old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_param_tetRtoggleSwitch.csv b/examples/CompanionFiles/txtl_param_tetRtoggleSwitch.csv old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_param_tetRtoggleSwitch2.csv b/examples/CompanionFiles/txtl_param_tetRtoggleSwitch2.csv old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_param_tetRtoggleSwitch5.csv b/examples/CompanionFiles/txtl_param_tetRtoggleSwitch5.csv old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_prom_placI2.m b/examples/CompanionFiles/txtl_prom_placI2.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_prom_placI3.m b/examples/CompanionFiles/txtl_prom_placI3.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_prom_ptet2.m b/examples/CompanionFiles/txtl_prom_ptet2.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_prom_ptet3.m b/examples/CompanionFiles/txtl_prom_ptet3.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_prom_ptet5.m b/examples/CompanionFiles/txtl_prom_ptet5.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_protein_MFP.m b/examples/CompanionFiles/txtl_protein_MFP.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_protein_lacI2.m b/examples/CompanionFiles/txtl_protein_lacI2.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_protein_lacI3.m b/examples/CompanionFiles/txtl_protein_lacI3.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_protein_lacI4.m b/examples/CompanionFiles/txtl_protein_lacI4.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_protein_tetR2.m b/examples/CompanionFiles/txtl_protein_tetR2.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_protein_tetR3.m b/examples/CompanionFiles/txtl_protein_tetR3.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_protein_tetR4.m b/examples/CompanionFiles/txtl_protein_tetR4.m old mode 100644 new mode 100755 diff --git a/examples/CompanionFiles/txtl_protein_tetR5.m b/examples/CompanionFiles/txtl_protein_tetR5.m old mode 100644 new mode 100755 diff --git a/examples/TXTL_workshop_scripts.m b/examples/TXTL_workshop_scripts.m old mode 100644 new mode 100755 diff --git a/examples/geneexpr.m b/examples/geneexpr.m index 609bf46..bf41a6f 100644 --- a/examples/geneexpr.m +++ b/examples/geneexpr.m @@ -7,17 +7,14 @@ % Set up the standard TXTL tubes % These load up the RNAP, Ribosome and degradation enzyme concentrations -tube1 = txtl_extract('E30VNPRL'); -tube2 = txtl_buffer('E30VNPRL'); +tube1 = txtl_extract('E2'); +tube2 = txtl_buffer('E2'); % Now set up a tube that will contain our DNA tube3 = txtl_newtube('gene_expression'); % Define the DNA strands (defines TX-TL species + reactions) -dna_deGFP = txtl_add_dna(tube3, ... - 'p70(50)', 'utr1(20)', 'deGFP(1000)', ... % promoter, rbs, gene - 30, ... % concentration (nM) - 'plasmid'); % type +dna_deGFP = txtl_add_dna(tube3, 'pOR2OR1(50)', 'utr1(20)', 'deGFP(1000)', 20, 'plasmid'); % type % Mix the contents of the individual tubes Mobj = txtl_combine([tube1, tube2, tube3]); diff --git a/examples/geneexpr_2.m b/examples/geneexpr_2.m old mode 100644 new mode 100755 diff --git a/examples/geneexpr_function.m b/examples/geneexpr_function.m old mode 100644 new mode 100755 diff --git a/examples/geneexpr_test_regen_mode.m b/examples/geneexpr_test_regen_mode.m new file mode 100755 index 0000000..2e90577 --- /dev/null +++ b/examples/geneexpr_test_regen_mode.m @@ -0,0 +1,42 @@ +% geneexpr.m - basic gene expression reaction +% R. M. Murray, 9 Sep 2012 +% +% This file contains a simple example of setting up a TXTL simulation +% for gene expression using the standard TXTL control plasmid. +% +% Set up the standard TXTL tubes +% These load up the RNAP, Ribosome and degradation enzyme concentrations +close all +clear all + +tube1 = txtl_extract('Emcmc2018'); +tube2 = txtl_buffer('Emcmc2018'); +% Now set up a tube that will contain our DNA +tube3 = txtl_newtube('gene_expression'); +% Define the DNA strands (defines TX-TL species + reactions) +dna_deGFP = txtl_add_dna(tube3, 'p70(50)', 'utr1(20)', 'deGFP(1000)', 30,... + 'plasmid'); % type +% Mix the contents of the individual tubes +Mobj = txtl_combine([tube1, tube2, tube3]); +% create a regeneration mode field +Mobj.UserData.energymode = 'regeneration'; +% +% Run a simulaton +% +% At this point, the entire experiment is set up and loaded into 'Mobj'. +% So now we just use standard Simbiology and MATLAB commands to run +% and plot our results! +% +% tau = sbioselect(Mobj, 'Name', 'AGTPdeg_time', 'Type', 'Parameter') ; +% tau.Value = 3600*4; +% Mobj.UserData.energymode = 'regeneration'; +tic +[simData] = txtl_runsim(Mobj,14*60*60); +toc +% plot the result +txtl_plot(simData,Mobj); + +% Automatically use matlab mode in emacs (keep at end of file) +% Local variables: +% mode: matlab +% End: diff --git a/examples/genetic_toggle_switch.m b/examples/genetic_toggle_switch.m old mode 100644 new mode 100755 diff --git a/examples/genetic_toggle_switch_function.m b/examples/genetic_toggle_switch_function.m old mode 100644 new mode 100755 diff --git a/examples/genetic_toggle_switch_gradient.m b/examples/genetic_toggle_switch_gradient.m old mode 100644 new mode 100755 diff --git a/examples/incoherent_ff_loop.m b/examples/incoherent_ff_loop.m old mode 100644 new mode 100755 diff --git a/examples/incoherent_ff_loop_function.m b/examples/incoherent_ff_loop_function.m old mode 100644 new mode 100755 diff --git a/examples/incoherent_ff_loop_gradient.m b/examples/incoherent_ff_loop_gradient.m old mode 100644 new mode 100755 diff --git a/examples/induction.m b/examples/induction.m old mode 100644 new mode 100755 diff --git a/examples/induction_open_loop.m b/examples/induction_open_loop.m old mode 100644 new mode 100755 diff --git a/examples/lacoperon.m b/examples/lacoperon.m old mode 100644 new mode 100755 diff --git a/examples/main_derivative_1.m b/examples/main_derivative_1.m old mode 100644 new mode 100755 diff --git a/examples/negautoreg.m b/examples/negautoreg.m old mode 100644 new mode 100755 diff --git a/examples/negautoreg_function.m b/examples/negautoreg_function.m old mode 100644 new mode 100755 diff --git a/examples/phosphor_insulator_function.m b/examples/phosphor_insulator_function.m old mode 100644 new mode 100755 diff --git a/examples/phosphor_insulator_gradient.m b/examples/phosphor_insulator_gradient.m old mode 100644 new mode 100755 diff --git a/examples/plas_ptet_test.m b/examples/plas_ptet_test.m old mode 100644 new mode 100755 diff --git a/examples/repressilator.m b/examples/repressilator.m old mode 100644 new mode 100755 diff --git a/examples/tutorial.m b/examples/tutorial.m new file mode 100644 index 0000000..d0cd0d3 --- /dev/null +++ b/examples/tutorial.m @@ -0,0 +1,63 @@ +%% Tutorial I: Basic usage example +% In this first tutorial, we discuss a simple usage of txtlsim. + +%% +% Before working through this tutorial, we suggest some familiarity with +% how MATLAB Simbiology works. Some useful tutorials can be found +% . As a minimum, we suggest working through the first two tutorials in +% the Modeling and Simulation section: +%% +% * +% * + +%% Initializing the toolbox +% Set the working directory to the trunk directory of the +% toolbox. The trunk directory is where folders like "core", "config", "examples" and +% "components" live. Here is a snapshot of this directory on our computer. +% +% <> +% +% Use this command to add the sub-directories needed to your matlab path. To +% be run each time you begin a new MATLAB session where you plan to run +% txtlsim. +txtl_init; + +%% Negative Autoregulation - A simple example +% Here we demonstrate the setup of a genetic circuit where a transcription +% factor represses its own expression. +% +% Set up the standard TXTL "tubes". These are Simbiology model objects +% containing extract, buffer and DNA specific information. Before they are +% combined into a single object, we use the term 'tube' to refer to them. +% The following two commands set up the first two model objects with +% extract and buffer specific parameters. +% ``E2'' refers to a configuration .csv file where the parameters are stored. +% These files are kept in the "config'' directory in the trunk directory. +tube1 = txtl_extract('E2'); +tube2 = txtl_buffer('E2'); + +% Now set up a tube that will contain our DNA +tube3 = txtl_newtube('negautoreg'); % name the circuit +txtl_add_dna(tube3, 'ptet(50)', 'utr1(20)', 'tetR(1200)', 1, 'plasmid'); +txtl_add_dna(tube3, 'ptet(50)', 'utr1(20)', 'deGFP(1000)', 1, 'plasmid'); + +% Mix the contents of the individual tubes +Mobj = txtl_combine([tube1, tube2, tube3]); + +% Run a simulaton, and return a Simbiology simData class object +[simData] = txtl_runsim(Mobj,14*60*60); + +t_ode = simData.Time; % A number-of-timepoints length vector +x_ode = simData.Data; % a number-of-timepoints by number-of-species matrix + +%% Plot the result +% The following function plots the proteins, RNA and resources in the +% toolbox. In the next section we delve deeper into the object oriented +% structure of the model, and how to plot arbitrary species in the model. +txtl_plot(simData,Mobj); + +%% +% Alternate usage: +%% +% txtl_plot(t_ode, x_ode, Mobj); \ No newline at end of file diff --git a/examples/tutorial_.m b/examples/tutorial_.m new file mode 100644 index 0000000..0f289a4 --- /dev/null +++ b/examples/tutorial_.m @@ -0,0 +1,143 @@ +%% Tutorial ... +% tutorial_iii.m - Understanding component code files, and parameter config files. +% +% In this tutorial, we describe the component code files, and the parameter +% configuration files. This should allow you to create new component files +% and add them to the toolbox if needed. +% +% +% We recommend you read through tutorials i and ii before trying +% this one out. +% All the tutorials can be found on the index page, +% . +% +% Vipul Singhal + +%% todos +% +% +% + +%% Initializing the toolbox +% Remember to set the working directory to the trunk directory of the +% toolbox. +% +% Use this command to add the subdirectories needed to your matlab path. To +% be run each time you begin a new TXTL toolbox session. +txtl_init; + +%% IFFL example +% The code below can be used to set up the constitutive GFP production +% example. +% +% Set up the standard TXTL tubes +% These load up the RNAP, Ribosome and degradation enzyme concentrations +% ``E2'' refers to a configuration file +tube1 = txtl_extract('E3'); +tube2 = txtl_buffer('E3'); + +% Now set up a tube that will contain our DNA +tube3 = txtl_newtube('lastetIFFL'); + + +% Define the DNA strands, and all the relevant reactions +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'lasR(1000)', 5, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas(50)', 'utr1(20)', 'tetR(1000)', 0.2, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas_ptet(50)', 'utr1(20)', 'deGFP(1000)', 2, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); +txtl_addspecies(m, 'OC12HSL', 1000); +txtl_addspecies(m, 'aTc', 1000); + +% Mix the contents of the individual tubes +Mobj = txtl_combine([tube1, tube2, tube3]); + +% Run a simulaton +% + +tic +[simData] = txtl_runsim(Mobj,14*60*60); +toc +t_ode = simData.Time; +x_ode = simData.Data; + +%% plot the result +% The following function plots the proteins, RNA and resources in the +% toolbox. In the next section we delve deeper into the object oriented +% structure of the model, and how to plot arbitrary species in the model. +txtl_plot(simData,Mobj); + +%% Model Structure +% The model is organized as a model object, with sub objects specifying +% Parameters, Reactions, Species, etc. Type in +Mobj + +%% +% We can see the number of instances of the various subclasses of the +% model object. We can explore further by typing +Mobj.Species + +%% +% Proteins, RNA and DNA generally follow the convention +% protein CDS, RNA 5'UTR--CDS, DNA promoter--5' UTR--CDS, with +% variations possible. There are also simply named `core' species like +% RNAP, Ribo, RNase, etc. Finally we denote bound complexes with a colon, +% for example, Species 1:Species 2. +%% +% We also see that each of them has certain +% other associated properties. You can explore further by accessing +% individual species using their index, and using the `get' and `set' commands +% to get and set the properties of the species. For example, try typing +Mobj.Species(1) + +%% +% This gives you the first species in the model. You can find out what +% properties as associated with this species by typing in +get(Mobj.Species(1)) + +%% +% and then using the set command to set its initial concentration to 50 +% units: +set(Mobj.Species(1), 'InitialAmount', 50) + +%% +% Learn more about the get and set commands by typing in +%% +% help get +% help set + + +%% +% You may read more about how model objects are arranged in Simbiology by +% working through the +% . Feel free to browse the reactions and other subproperties by +% individually typing in commands like +%% +% +% Mobj.reactions +% get(Mobj.Reactions) +% get(Mobj.Reactions(1)) +% Mobj.Reactions(1).ReactionRate +% Mobj.Reactions(1).KineticLaw +% get(Mobj.Reactions(1).KineticLaw) +%% +% and so on. +%% Plotting individual species +% You can also plot the trajectories of any of the species in the model. +% Use the function findspecies to get the index of the species object of interest. For +% example, if you want to plot the trajectory of the dimerized tetR +% protein, you could type in + +tetRindex = findspecies(Mobj, 'protein deGFP'); +figure +plot(simData.Time/3600, simData.data(:,tetRindex)); +title('Un-matured protein concentration') +ylabel('concentration, nM') +xlabel('time, h') +curraxis = axis; +axis([curraxis(1:2) 0 curraxis(4)]) + diff --git a/examples/tutorial_IVx.m b/examples/tutorial_IVx.m new file mode 100644 index 0000000..cad3f83 --- /dev/null +++ b/examples/tutorial_IVx.m @@ -0,0 +1,158 @@ +%% Tutorial IV +% In this tutorial, we will discuss a few different circuits. + + +% In this tutorial, we go over some of the various circuit components that +% can be used to build circuit models. We also discuss variations like +% using linear DNA and protection from DNA degradation, and ClpX. +% We also discuss the parameters and reactions in the +% models, so that you may gain greater familiarity with the +% +% +% We recommend you read through tutorials i and ii before trying +% this one out. +% All the tutorials can be found on the index page, +% . +% +% Vipul Singhal + +%% todos +% # linear DNA degradation example. -- recBCD, gamS. Zach paper. +% # ClpX degradation example. (from tech report) +% # activator example + inducer (use our characterization) +% # combinatorial promoter example + inducers. (use our characterization) +% #repressor example (use our characterization, and lacI too, find a characterization of lacI in TXTL/ or just relative to tetR.) +% # rbs varying example (use the mutalik paper to estimate the RBSs) +% # constitutive promoter example (use the anderson promoter library to +% # estimate promoter strength ) +% # genetic toggle with the data collected. (anushka, enrique) +% # Can look at the TXTL2.0 paper for possible data. +% maybe wan to split this into multiple smaller links? No need. just have a +% contents page. +% + + + +%% Initializing the toolbox +% Remember to set the working directory to the trunk directory of the +% toolbox. +% +% Use this command to add the subdirectories needed to your matlab path. To +% be run each time you begin a new TXTL toolbox session. +txtl_init; + +%% IFFL example +% The code below can be used to set up the constitutive GFP production +% example. +% +% Set up the standard TXTL tubes +% These load up the RNAP, Ribosome and degradation enzyme concentrations +% ``E2'' refers to a configuration file +tube1 = txtl_extract('E3'); +tube2 = txtl_buffer('E3'); + +% Now set up a tube that will contain our DNA +tube3 = txtl_newtube('lastetIFFL'); + + +% Define the DNA strands, and all the relevant reactions +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'lasR(1000)', 5, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas(50)', 'utr1(20)', 'tetR(1000)', 0.2, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas_ptet(50)', 'utr1(20)', 'deGFP(1000)', 2, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); +txtl_addspecies(m, 'OC12HSL', 1000); +txtl_addspecies(m, 'aTc', 1000); + +% Mix the contents of the individual tubes +Mobj = txtl_combine([tube1, tube2, tube3]); + +% Run a simulaton +% + +tic +[simData] = txtl_runsim(Mobj,14*60*60); +toc +t_ode = simData.Time; +x_ode = simData.Data; + +%% plot the result +% The following function plots the proteins, RNA and resources in the +% toolbox. In the next section we delve deeper into the object oriented +% structure of the model, and how to plot arbitrary species in the model. +txtl_plot(simData,Mobj); + +%% Model Structure +% The model is organized as a model object, with sub objects specifying +% Parameters, Reactions, Species, etc. Type in +Mobj + +%% +% We can see the number of instances of the various subclasses of the +% model object. We can explore further by typing +Mobj.Species + +%% +% Proteins, RNA and DNA generally follow the convention +% protein CDS, RNA 5'UTR--CDS, DNA promoter--5' UTR--CDS, with +% variations possible. There are also simply named `core' species like +% RNAP, Ribo, RNase, etc. Finally we denote bound complexes with a colon, +% for example, Species 1:Species 2. +%% +% We also see that each of them has certain +% other associated properties. You can explore further by accessing +% individual species using their index, and using the `get' and `set' commands +% to get and set the properties of the species. For example, try typing +Mobj.Species(1) + +%% +% This gives you the first species in the model. You can find out what +% properties as associated with this species by typing in +get(Mobj.Species(1)) + +%% +% and then using the set command to set its initial concentration to 50 +% units: +set(Mobj.Species(1), 'InitialAmount', 50) + +%% +% Learn more about the get and set commands by typing in +%% +% help get +% help set + + +%% +% You may read more about how model objects are arranged in Simbiology by +% working through the +% . Feel free to browse the reactions and other subproperties by +% individually typing in commands like +%% +% +% Mobj.reactions +% get(Mobj.Reactions) +% get(Mobj.Reactions(1)) +% Mobj.Reactions(1).ReactionRate +% Mobj.Reactions(1).KineticLaw +% get(Mobj.Reactions(1).KineticLaw) +%% +% and so on. +%% Plotting individual species +% You can also plot the trajectories of any of the species in the model. +% Use the function findspecies to get the index of the species object of interest. For +% example, if you want to plot the trajectory of the dimerized tetR +% protein, you could type in + +tetRindex = findspecies(Mobj, 'protein deGFP'); +figure +plot(simData.Time/3600, simData.data(:,tetRindex)); +title('Un-matured protein concentration') +ylabel('concentration, nM') +xlabel('time, h') +curraxis = axis; +axis([curraxis(1:2) 0 curraxis(4)]) + diff --git a/examples/tutorial_ii.m b/examples/tutorial_ii.m new file mode 100644 index 0000000..d15462a --- /dev/null +++ b/examples/tutorial_ii.m @@ -0,0 +1,245 @@ +%% Tutorial II: Model details: the species, reactions, and object oriented structure +% This tutorial is a continuation of the first tutorial. We use the same +% negative autoregulation circuit, but now discuss the species, reactions, +% and other details of the model. +% + +%% Create the model +txtl_init; +tube1 = txtl_extract('E2'); +tube2 = txtl_buffer('E2'); +tube3 = txtl_newtube('negautoreg'); % name the circuit +txtl_add_dna(tube3, 'ptet(50)', 'utr1(20)', 'tetR(1200)', 1, 'plasmid'); +txtl_add_dna(tube3, 'ptet(50)', 'utr1(20)', 'deGFP(1000)', 1, 'plasmid'); +Mobj = txtl_combine([tube1, tube2, tube3]); +[simData] = txtl_runsim(Mobj,14*60*60); +t_ode = simData.Time; +x_ode = simData.Data; +txtl_plot(t_ode, x_ode, Mobj); + + +%% Model structure +% The model is organized as a Simbiology model object |Mobj|. To see an overview of +% the structure of |Mobj|, type in +Mobj +%% +% We see that the model has 1 compartment 2 events, 88 parameters, 54 reactions +% 8 rules and 48 species. We can explore the various components of the +% model by typing +%% +% Mobj.Species +% Mobj.Reactions +% Mobj.Events +% Mobj.Rules +%% +% For example, look at the first 30 species and their initial concentrations +% by typing in: +model_species = Mobj.species; +model_species(1:30) + +%% +% Looking at some of the species in the model, we see +% that there is a naming pattern to the species. For instance, the RNA, DNA +% and protein species are +%% +% The DNA follows the pattern |DNA promoter--UTR--CDS|, where promoter, UTR and +% CDS are the specifications of the promoter, the 5' untranslated region and +% the coding sequence. In our example, we have +%% +% DNA ptet--utr1--deGFP +% DNA ptet--utr1--deGFP +%% +% Similarly, the RNA and proteins have the specification patterns +% |RNA UTR--CDS| and |protein CDS|: +%% +% RNA utr1--tetR +% RNA utr1--deGFP +% protein deGFP +% protein deGFP* +% protein tetR +% protein tetRdimer +%% +% We also have other species like |RNAP| (RNA polymerase, |Ribo| +% (ribosome), |AGTP| (a lumped species representing one unit of ATP and one +% of GTP). Species can bind to each other to form new species, and the +% resulting complexes are denoted by concatenating the constituent species +% with a colon (|:|). For example, the following species are complexes: +%% +% Ribosome bound to RNA: +%% +% Ribo:RNA utr1--tetR +%% +% RNA polymerase bound to DNA, and CUTP and AGTP bound to the resulting +% complex. +%% +% RNAP:DNA ptet--utr1--tetR +% CUTP:AGTP:RNAP:DNA ptet--utr1--tetR +% +%% +% The species, reactions, parameters etc are all Simbiology objects, and we +% can query their properties using the MATLAB |get| and |set| functions. +% For example, |protein tetR| is the 8th species, so we can look at its +% properties using +get(Mobj.Species(8)) +% +%% +% To list which properties can be set by the user, use +set(Mobj.Species(8)) + +%% +% And set values using the syntax +set(Mobj.Species(8), 'InitialAmount', 50) % initial tetR protein concentration set to 50 +%% +% Learn more about the get and set commands by typing in +%% +% help get +% help set + +%% +% Again, we suggest getting familiarized with Simbiology +% . +%% +% To look at the at the reactions of the model object, type in +%% +% Mobj.reactions +%% +% into the command line. We see that the reactions can be divided into +% transcription, translation, RNA degradation and miscellaneous reactions. +% For example, the reactions associated with the TetR repressor are: +%% +% +% Index: Reaction: +% TetR induction, dimerization and repression: +% 1 [protein tetRdimer] + 2 aTc <-> [2 aTc:protein tetRdimer] +% 2 2 [protein tetR] <-> [protein tetRdimer] +% 12 [DNA ptet--utr1--tetR] + [protein tetRdimer] <-> [DNA ptet--utr1--tetR:protein tetRdimer] +% +% Transctiption reactions: RNAP binding, nucleotide binding in two steps, +% transcription (with consumption reaction) and termination +% 4 [DNA ptet--utr1--tetR] + RNAP <-> [RNAP:DNA ptet--utr1--tetR] +% 5 [CUTP:AGTP:RNAP:DNA ptet--utr1--tetR] -> [term_RNAP:DNA ptet--utr1--tetR] + [RNA utr1--tetR] +% 6 [CUTP:AGTP:RNAP:DNA ptet--utr1--tetR] -> [RNAP:DNA ptet--utr1--tetR] +% 7 [term_RNAP:DNA ptet--utr1--tetR] -> RNAP + [DNA ptet--utr1--tetR] +% 8 [RNAP:DNA ptet--utr1--tetR] + AGTP <-> [AGTP:RNAP:DNA ptet--utr1--tetR] +% 9 [RNAP:DNA ptet--utr1--tetR] + CUTP <-> [CUTP:RNAP:DNA ptet--utr1--tetR] +% 10 [AGTP:RNAP:DNA ptet--utr1--tetR] + CUTP <-> [CUTP:AGTP:RNAP:DNA ptet--utr1--tetR] +% 11 [CUTP:RNAP:DNA ptet--utr1--tetR] + AGTP <-> [CUTP:AGTP:RNAP:DNA ptet--utr1--tetR] +% +% Translation reactions: Ribosome binding, AA and nucleotide binding, +% translation (with consumption reaction), termination +% 3 [RNA utr1--tetR] + Ribo <-> [Ribo:RNA utr1--tetR] +% 13 [Ribo:RNA utr1--tetR] + AA <-> [AA:Ribo:RNA utr1--tetR] +% 14 [AA:Ribo:RNA utr1--tetR] + AGTP <-> [AA:AGTP:Ribo:RNA utr1--tetR] +% 15 [AA:AGTP:Ribo:RNA utr1--tetR] -> [term_Ribo:RNA utr1--tetR] + [protein tetR] +% 16 [AA:AGTP:Ribo:RNA utr1--tetR] -> [term_Ribo:RNA utr1--tetR] +% 17 [term_Ribo:RNA utr1--tetR] -> [RNA utr1--tetR] + Ribo +% +% RNase mediated RNA degradation +% 18 [RNA utr1--tetR] + RNase <-> [RNA utr1--tetR:RNase] +% 19 [RNA utr1--tetR:RNase] -> RNase +% 20 [Ribo:RNA utr1--tetR] + RNase <-> [Ribo:RNA utr1--tetR:RNase] +% 21 [Ribo:RNA utr1--tetR:RNase] -> RNase + Ribo +% 22 [AA:AGTP:Ribo:RNA utr1--tetR] + RNase <-> [AA:AGTP:Ribo:RNA utr1--tetR:RNase] +% 23 [AA:AGTP:Ribo:RNA utr1--tetR:RNase] -> RNase + AA + AGTP + Ribo +% 24 [term_Ribo:RNA utr1--tetR] + RNase <-> [term_Ribo:RNA utr1--tetR:RNase] +% 25 [term_Ribo:RNA utr1--tetR:RNase] -> RNase + Ribo +% 26 [AA:Ribo:RNA utr1--tetR] + RNase <-> [AA:Ribo:RNA utr1--tetR:RNase] +% 27 [AA:Ribo:RNA utr1--tetR:RNase] -> RNase + AA + Ribo + +%% +% The properties of the first reaction can be listed using + get(Mobj.Reactions(1)) +%% +% Use the commands +%% +% Mobj.Reactions(1). +%% +% to navigate the properties of the reaction. Note that the |Procuct| and +% |Reactant| properties point to the respective species objects and the +% |Parent| property points to the model object: +Mobj.Reactions(1).Reactants % list of species objects that are the reactants. +Mobj.Reactions(1).Parent % the model object the reaction belongs to. + +%% +% The |KineticLaw| property points to the Simbiology |KineticLaw| object +% associated with this reaction. This object holds information associated +% with the type of reaction kinetics used by this reaction, and of the +% parameters associated with this reaction. Query it using: +get(Mobj.Reactions(1).KineticLaw) +%% +% And query the (forward and reverse binding rate) parameters of this reaction using +get(Mobj.Reactions(1).KineticLaw.Parameters(1)) +get(Mobj.Reactions(1).KineticLaw.Parameters(2)) + +%% +% We recommend playing with these commands and gaining some failiarity with +% the structure of the model. + +%% Plotting individual species +% Now that we know more about how the underlying model is organized, we can +% plot individual species by querying their concentration trajectoriees. Do this +% using the function findspecies to get the index of the species object of interest. For +% example, if you want to plot the trajectory of the dimerized tetR +% protein, you could type in +tetRindex = findspecies(Mobj, 'protein tetRdimer'); +figure +plot(simData.Time/3600, simData.data(:,tetRindex)); +title('Dimerized tetR concentration') +ylabel('concentration, nM') +xlabel('time, h') +curraxis = axis; +axis([curraxis(1:2) 0 curraxis(4)]) + +%% Plotting multiple species +% You can, of course, plot any subset of the species in the model, and +% arrange them into a plot using MATLAB's subplot command. For example, say +% we would like to explore the ribosome dynamics. Looking at the species +% list above, we make a list of all the complexes with the ribosome species +% in them. + +riboList = {'RNAP', '', '', '', '' +'RNAP:DNA ptet--utr1--tetR',... +'AGTP:RNAP:DNA ptet--utr1--tetR',... +'CUTP:RNAP:DNA ptet--utr1--tetR',... +'CUTP:AGTP:RNAP:DNA ptet--utr1--tetR',... +'term_RNAP:DNA ptet--utr1--tetR' +'RNAP:DNA ptet--utr1--deGFP',... +'AGTP:RNAP:DNA ptet--utr1--deGFP',... +'CUTP:RNAP:DNA ptet--utr1--deGFP',... +'CUTP:AGTP:RNAP:DNA ptet--utr1--deGFP',... +'term_RNAP:DNA ptet--utr1--deGFP'}; + +%% +% We can plot the dynamics of these species as follows. + +plotix = simData.Time/3600 < 2; +timevec = simData.Time(simData.Time/3600 < 2)/3600; + +figure('Position', [50 50 1400 700]) +subplot(3, 5, [2 3 4]) +spIndex = findspecies(Mobj, riboList{1, 1}); +plot(timevec,... + simData.data(plotix,spIndex),... + 'LineWidth', 2, 'LineStyle', ':'); +title('Free ribosome concentration') +ylabel('concentration, nM') +xlabel('time, h') +hold on + +for i = 6:15 + subplot(3, 5, i) + rowix = 1+floor((i-1)/5); + colix = mod(i, 5); + if colix == 0 + colix = 5; + end + spIndex = findspecies(Mobj, riboList{rowix, colix}); + plot(timevec,... + simData.data(plotix,spIndex),... + 'LineWidth', 2, 'LineStyle', ':'); + legend(riboList{rowix, colix}) + ylabel('concentration, nM') + xlabel('time, h') + +end \ No newline at end of file diff --git a/examples/tutorial_iii.m b/examples/tutorial_iii.m new file mode 100644 index 0000000..aac4780 --- /dev/null +++ b/examples/tutorial_iii.m @@ -0,0 +1,104 @@ +%% Tutorial III: Model details: Events, parameter scope and rules. +% This tutorial is a continuation of the first two tutorials. We use the same +% negative autoregulation circuit, but now discuss more details about the +% model structure. +% +% Vipul Singhal + +%% Create the model +txtl_init; +tube1 = txtl_extract('E2'); +tube2 = txtl_buffer('E2'); +tube3 = txtl_newtube('negautoreg'); % name the circuit +txtl_add_dna(tube3, 'ptet(50)', 'utr1(20)', 'tetR(1200)', 1, 'plasmid'); +txtl_add_dna(tube3, 'ptet(50)', 'utr1(20)', 'deGFP(1000)', 1, 'plasmid'); +Mobj = txtl_combine([tube1, tube2, tube3]); +[simData] = txtl_runsim(Mobj,14*60*60); +t_ode = simData.Time; +x_ode = simData.Data; +txtl_plot(t_ode, x_ode, Mobj); + +%% Simbiology events used to model ATP and GTP degradation. +% The model has an event that sets the regeneration rate of AGTP (a species +% used to account for one unit of ATP and one of GTP) to 0 after a fixed +% period of time. The degradaton and regeneration reactions are: +degrx = sbioselect(Mobj.reactions, 'Reaction', 'AGTP -> AGMP'); +regrx = sbioselect(Mobj.reactions, 'Reaction', 'AGMP -> AGTP'); +%% +% with parameters |AGTPdeg_rate| and |AGTPreg_varying| respectively. These +% can be seen by typing in +%% +% get(degrx.KineticLaw) +% get(regrx.KineticLaw) +%% +% Note that these parameters are globally scoped, in that the local Parameters +% field in the KineticLaw is empty (|degrx.KineticLaw.Parameters| returns empty, +% and indeed the parameter is found at the model scope, which can be +% verified by typing in |Mobj.Parameters|. You may verify this for +% yourself. The globally scoped model parameters are +Mobj.Parameters + +%% +% You might find it helpful to learn more about parameter scoping +% . + +%% +% And the kinetics of the degradation reaction are: +get(degrx.KineticLaw) + +%% +% There are four parameters associated with these two reactions: +prm = Mobj.Parameters(end-3:end) +%% +% From time +% |t = 0 to AGTPdeg_time| seconds, the parameter +% |AGTPreg_varying = AGTPreg_ON|, but once +% |time > AGTPdeg_time| seconds, a simbiology event sets the the parameter +% |AGTPreg_varying = 0|. +% The degradation rate parameter |AGTPdeg_rate| is always at a constant +% value. +%% +% This timing based behavior is implemented using Simbiology events, and +% can be verified by typing in +Mobj.Events + + +%% Locally scoped parameters. +% Most other parameters in the model are locally scoped. I.e., to view the +% parameters associated with most reactions, you must access it through the +% reaction's KineticLaw object, as shown below. +%% +Mobj.Reactions(1) +%% +get(Mobj.Reactions(1).KineticLaw) +%% +Mobj.Reactions(1).KineticLaw.Parameters +%% +% and so on. +%% Simbiology Rules +% Finally, Simbiology allows us to define rules that bind different +% components of the model together. In our model, rules are used to tie +% together the elongation rate parameter to the transcription rate, and to +% the resource consumption rate: +%% +% Mobj.Rules +%% +% gives +%% +% +% SimBiology Rule Array +% +% Index: RuleType: Rule: +% 1 initialAssignment TX_transcription_utr1_tetR = TX_elong_glob/1220 +% 2 initialAssignment TX_NTPcons_utr1_tetR = TX_elong_glob/1220*(305-1) +% 3 initialAssignment TL_translation_tetR = TL_elong_glob/400 +% 4 initialAssignment TL_REScons_tetR = TL_elong_glob/400*(400-1) +% 5 initialAssignment TX_transcription_utr1_deGFP = TX_elong_glob/1020 +% 6 initialAssignment TX_NTPcons_utr1_deGFP = TX_elong_glob/1020*(255-1) +% 7 initialAssignment TL_translation_deGFP = TL_elong_glob/333 +% 8 initialAssignment TL_REScons_deGFP = TL_elong_glob/333*(333-1) + +%% +% Looking at the first rule, for example, we see that the transcription rate of the +% tetR mRNA is the global elongation rate |TX_elong_glob| divided by the +% length of the RNA to be transcribed. diff --git a/examples/tutorial_iix.m b/examples/tutorial_iix.m new file mode 100644 index 0000000..d817606 --- /dev/null +++ b/examples/tutorial_iix.m @@ -0,0 +1,105 @@ +%% Tutorial IIx--The Incoherent Feedforward loop +% In this tutorial, we build the incoherent feedforward loop, and discuss +% the various components of the model in detail. We recommend you read through the +% tutorial before starting on this one. +% +% Vipul Singhal, Mar 2018 + + +%% Initializing the toolbox +% Remember to set the working directory to the trunk directory of the +% toolbox. +% +% Use this command to add the subdirectories needed to your matlab path. To +% be run each time you begin a new TXTL toolbox session. +txtl_init; + +%% IFFL example +% The code below can be used to set up an IFFL example with lasR as the +% activator, tetR as the repressor, and deGFP as the reporter. +% +% Set up the standard TXTL tubes +% These load up the RNAP, Ribosome and degradation enzyme concentrations +% ``E2'' refers to a configuration file +tube1 = txtl_extract('E3'); +tube2 = txtl_buffer('E3'); + +% Now set up a tube that will contain our DNA +tube3 = txtl_newtube('lastetIFFL'); + + +% Define the DNA strands, and all the relevant reactions +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1b(20)', 'lasR(1000)', 1, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas(50)', 'utr1b(20)', 'tetR(1000)', 0.1, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas_ptet(50)', 'utr1b(20)', 'deGFP(1000)', 1, 'plasmid'); + +% Mix the contents of the individual tubes +Mobj = txtl_combine([tube1, tube2, tube3]); + +txtl_addspecies(Mobj, 'OC12HSL', 1000); +txtl_addspecies(Mobj, 'aTc', 100); + +% Run a simulaton +tic +[simData] = txtl_runsim(Mobj,14*60*60); +toc +t_ode = simData.Time; +x_ode = simData.Data; + +%% Plot the result +% The following function plots the proteins, RNA and resources in the +% toolbox. In the next section we delve deeper into the object oriented +% structure of the model, and how to plot arbitrary species in the model. +txtl_plot(simData,Mobj); + +%% Model Structure +% The model is organized as a model object, with sub objects specifying +% Parameters, Reactions, Species, etc. Type in +Mobj + +%% +% and the individual properties of the model object may be explored by +% typing, for example, +Mobj.Events + + +%% The effect of varying aTc +% we will vary the aTc inducer in the IFFL circuit, and plot the +% results of these variations. We will use MATLAB cell arrays to store the +% variations of the models. +close all +initATC = [1 10 100 1000]; +m = cell(length(initATC), 1); +simData = cell(length(initATC), 1); +t_ode = cell(length(initATC), 1); +x_ode = cell(length(initATC), 1); + +tube1 = txtl_extract('E3'); +tube2 = txtl_buffer('E3'); +for i = 1:length(initATC) + tube3 = txtl_newtube('lastetIFFL'); + txtl_add_dna(tube3, ... + 'plac(50)', 'utr1b(20)', 'lasR(1000)', 1, 'plasmid'); + txtl_add_dna(tube3, ... + 'plas(50)', 'utr1b(20)', 'tetR(1000)', 0.1, 'plasmid'); + txtl_add_dna(tube3, ... + 'plas_ptet(50)', 'utr1b(20)', 'deGFP(1000)', 1, 'plasmid'); + m{i} = txtl_combine([tube1, tube2, tube3]); + txtl_addspecies(m{i}, 'OC12HSL', 1000); + txtl_addspecies(m{i}, 'aTc', initATC(i)); + [simData{i}] = txtl_runsim(m{i},6*60*60); + t_ode{i} = simData{i}.Time; + x_ode{i} = simData{i}.Data; +end + + +speciesList = {'aTc' +'protein tetRdimer' +'RNA utr1b--deGFP' +'protein deGFP*'}; + +plotCustomSpecies2(m, x_ode,t_ode, speciesList, {'1nM', '10nM', '100nM', '1000nM'}) diff --git a/examples/tutorial_iv.m b/examples/tutorial_iv.m new file mode 100644 index 0000000..8863aad --- /dev/null +++ b/examples/tutorial_iv.m @@ -0,0 +1,93 @@ +%% Tutorial IV +% In this tutorial, we will discuss a few different circuits. + +%% +% # linear DNA degradation example. -- recBCD, gamS. Zach paper. +% # ClpX degradation example. (from tech report) +% # activator example + inducer (use our characterization) +% # combinatorial promoter example + inducers. (use our characterization) +% #repressor example (use our characterization, and lacI too, find a characterization of lacI in TXTL/ or just relative to tetR.) +% # rbs varying example (use the mutalik paper to estimate the RBSs) +% # constitutive promoter example (use the anderson promoter library to +% # estimate promoter strength ) +% # genetic toggle with the data collected. (anushka, enrique) +% # Can look at the TXTL2.0 paper for possible data. +% maybe wan to split this into multiple smaller links? No need. just have a +% contents page. +% + +%% Initializing the toolbox +txtl_init; + +%% Constitutive expression with linear DNA + +%% Constitutive expression with linear RNA, and protection from endonucleases. + +%% The incoherent feedforward loop +tube1 = txtl_extract('E3'); +tube2 = txtl_buffer('E3'); +% Now set up a tube that will contain our DNA +tube3 = txtl_newtube('lastetIFFL'); +% Define the DNA strands, and all the relevant reactions +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'lasR(1000)', .5, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas(50)', 'utr1(20)', 'tetR(1000)', 0.1, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas_ptet(50)', 'utr1(20)', 'deGFP(1000)-lva', 2, 'plasmid'); + +% Mix the contents of the individual tubes +Mobj = txtl_combine([tube1, tube2, tube3]); +txtl_addspecies(Mobj, 'OC12HSL', 500); +txtl_addspecies(Mobj, 'aTc', 200); +txtl_addspecies(Mobj, 'protein ClpX*', 0) +[simData_no_clpx] = txtl_runsim(Mobj,14*60*60); +txtl_plot(simData_no_clpx,Mobj); +gfp_index_no_clpx = findspecies(Mobj, 'protein deGFP-lva*'); + +%% The incoherent feedforward loop with ClpX mediated degradation +close all +tube1 = txtl_extract('E3'); +tube2 = txtl_buffer('E3'); +% Now set up a tube that will contain our DNA +tube3 = txtl_newtube('lastetIFFL'); +% Define the DNA strands, and all the relevant reactions +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'lasR(1000)', 0.5, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas(50)', 'utr1(20)', 'tetR(1000)', 0.1, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas_ptet(50)', 'utr1(20)', 'deGFP(1000)-lva', 2, 'plasmid'); +% Mix the contents of the individual tubes +Mobj = txtl_combine([tube1, tube2, tube3]); +txtl_addspecies(Mobj, 'OC12HSL', 500); +txtl_addspecies(Mobj, 'aTc', 200); +txtl_addspecies(Mobj, 'protein ClpX*', 500) +[simData_with_clpx] = txtl_runsim(Mobj,14*60*60); +txtl_plot(simData_with_clpx,Mobj); +gfp_index_with_clpx = findspecies(Mobj, 'protein deGFP-lva*'); +%% Plot the deGFP trajectories for the with- and without- ClpX cases +figure + +withoutclpx = plot(simData_no_clpx.Time/3600, ... + simData_no_clpx.data(:,gfp_index_no_clpx), ... + 'LineWidth', 2, 'Color', 'r'); +hold on +withclpx = plot(simData_with_clpx.Time/3600, ... + simData_with_clpx.data(:,gfp_index_with_clpx), ... + 'LineWidth', 2, 'Color', 'b'); +title('matured GFP concentration',... + 'FontSize', 14) +ylabel('concentration, nM',... + 'FontSize', 14) +xlabel('time, h',... + 'FontSize', 14) +legend([withoutclpx, withclpx], {'without ClpX', 'with ClpX'},... + 'FontSize', 14, 'Location', 'NorthWest') +curraxis = axis; +axis([curraxis(1:2) 0 curraxis(4)]) + +%% The Incoherent Feedforward loop +% Set up the standard TXTL tubes +% These load up the RNAP, Ribosome and degradation enzyme concentrations +% ``E2'' refers to a configuration file diff --git a/examples/tutorial_iv_.m b/examples/tutorial_iv_.m new file mode 100644 index 0000000..ef2fa0e --- /dev/null +++ b/examples/tutorial_iv_.m @@ -0,0 +1,157 @@ +%% Tutorial IV +% tutorial_iv.m - Circuit components and variations. +% +% In this tutorial, we go over some of the various circuit components that +% can be used to build circuit models. We also discuss variations like +% using linear DNA and protection from DNA degradation, and ClpX. +% We also discuss the parameters and reactions in the +% models, so that you may gain greater familiarity with the +% +% +% We recommend you read through tutorials i and ii before trying +% this one out. +% All the tutorials can be found on the index page, +% . +% +% Vipul Singhal + +%% todos +% # linear DNA degradation example. -- recBCD, gamS. Zach paper. +% # ClpX degradation example. (from tech report) +% # activator example + inducer (use our characterization) +% # combinatorial promoter example + inducers. (use our characterization) +% #repressor example (use our characterization, and lacI too, find a characterization of lacI in TXTL/ or just relative to tetR.) +% # rbs varying example (use the mutalik paper to estimate the RBSs) +% # constitutive promoter example (use the anderson promoter library to +% # estimate promoter strength ) +% # genetic toggle with the data collected. (anushka, enrique) +% # Can look at the TXTL2.0 paper for possible data. +% maybe wan to split this into multiple smaller links? No need. just have a +% contents page. +% + + + +%% Initializing the toolbox +% Remember to set the working directory to the trunk directory of the +% toolbox. +% +% Use this command to add the subdirectories needed to your matlab path. To +% be run each time you begin a new TXTL toolbox session. +txtl_init; + +%% IFFL example +% The code below can be used to set up the constitutive GFP production +% example. +% +% Set up the standard TXTL tubes +% These load up the RNAP, Ribosome and degradation enzyme concentrations +% ``E2'' refers to a configuration file +tube1 = txtl_extract('E3'); +tube2 = txtl_buffer('E3'); + +% Now set up a tube that will contain our DNA +tube3 = txtl_newtube('lastetIFFL'); + + +% Define the DNA strands, and all the relevant reactions +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'lasR(1000)', 5, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas(50)', 'utr1(20)', 'tetR(1000)', 0.2, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas_ptet(50)', 'utr1(20)', 'deGFP(1000)', 2, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); +txtl_addspecies(m, 'OC12HSL', 1000); +txtl_addspecies(m, 'aTc', 1000); + +% Mix the contents of the individual tubes +Mobj = txtl_combine([tube1, tube2, tube3]); + +% Run a simulaton +% + +tic +[simData] = txtl_runsim(Mobj,14*60*60); +toc +t_ode = simData.Time; +x_ode = simData.Data; + +%% plot the result +% The following function plots the proteins, RNA and resources in the +% toolbox. In the next section we delve deeper into the object oriented +% structure of the model, and how to plot arbitrary species in the model. +txtl_plot(simData,Mobj); + +%% Model Structure +% The model is organized as a model object, with sub objects specifying +% Parameters, Reactions, Species, etc. Type in +Mobj + +%% +% We can see the number of instances of the various subclasses of the +% model object. We can explore further by typing +Mobj.Species + +%% +% Proteins, RNA and DNA generally follow the convention +% protein CDS, RNA 5'UTR--CDS, DNA promoter--5' UTR--CDS, with +% variations possible. There are also simply named `core' species like +% RNAP, Ribo, RNase, etc. Finally we denote bound complexes with a colon, +% for example, Species 1:Species 2. +%% +% We also see that each of them has certain +% other associated properties. You can explore further by accessing +% individual species using their index, and using the `get' and `set' commands +% to get and set the properties of the species. For example, try typing +Mobj.Species(1) + +%% +% This gives you the first species in the model. You can find out what +% properties as associated with this species by typing in +get(Mobj.Species(1)) + +%% +% and then using the set command to set its initial concentration to 50 +% units: +set(Mobj.Species(1), 'InitialAmount', 50) + +%% +% Learn more about the get and set commands by typing in +%% +% help get +% help set + + +%% +% You may read more about how model objects are arranged in Simbiology by +% working through the +% . Feel free to browse the reactions and other subproperties by +% individually typing in commands like +%% +% +% Mobj.reactions +% get(Mobj.Reactions) +% get(Mobj.Reactions(1)) +% Mobj.Reactions(1).ReactionRate +% Mobj.Reactions(1).KineticLaw +% get(Mobj.Reactions(1).KineticLaw) +%% +% and so on. +%% Plotting individual species +% You can also plot the trajectories of any of the species in the model. +% Use the function findspecies to get the index of the species object of interest. For +% example, if you want to plot the trajectory of the dimerized tetR +% protein, you could type in + +tetRindex = findspecies(Mobj, 'protein deGFP'); +figure +plot(simData.Time/3600, simData.data(:,tetRindex)); +title('Un-matured protein concentration') +ylabel('concentration, nM') +xlabel('time, h') +curraxis = axis; +axis([curraxis(1:2) 0 curraxis(4)]) + diff --git a/generate_paper_figs/.gitignore b/generate_paper_figs/.gitignore new file mode 100644 index 0000000..7a8f9dd --- /dev/null +++ b/generate_paper_figs/.gitignore @@ -0,0 +1,5 @@ +# git ignore file for the projects directory +/proj_*/ +/html/ +/old_files/ +/explore_*/ \ No newline at end of file diff --git a/generate_paper_figs/Core_characterization_plots.m b/generate_paper_figs/Core_characterization_plots.m new file mode 100644 index 0000000..44fa2f9 --- /dev/null +++ b/generate_paper_figs/Core_characterization_plots.m @@ -0,0 +1,726 @@ +% Plotting the core mechanism characterization results for the paper: +% +% A MATLAB Toolbox for Modeling Genetic Circuits in Cell-Free Systems +% by Vipul Singhal, Zoltan A. Tuza, Zachary S. Sun, and Richard M. Murray +% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Instructions +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 1. Check that the working directory is the one where folders like core, +% components, mcmc_simbio, config etc are. This is the trunk directory. +% 2. Download datasets, and place in the mcmc_simbio/projects directory. +% You need around 8 GB +% of free hard disk space to download the full dataset. Download at: +% https://www.dropbox.com/s/alx379b65ga40mh/core_characterization_files.zip?dl=0 +% Extract the project folders and place them in the projects directory. +% See lines 55, 85, 117, etc for examples of what the final path should +% look like. +% 3. Make sure you have 8 GB of free ram. Otherwise, just run each case +% (the for loop around line 41 below) separately, and the RAM usage should +% never go over 3GB or so. +% 4. The plots should be saved in the a subdirectory of the respective +% project directory. The subdirectory is given by the final timestamp of that +% case. So for example, for the runN = 0 case, +% the project directory is +% ./mcmc_simbio/projects/proj_vnprl (line 55) +% and the subdirectory is +% simdata_20200513_063545_4_19 (line 66) + +close all +clear all +figsave = false; +jpgsave = true; +txtldir = txtl_init; +mcmc_init; +% ----------------------------------------------------------------------- % +% Select Run number +% Change [0 1 2 3 4 5] to [0] to run a single run (run 0 in this case) at a time +% This way, instead of 8GB of RAM, you only need 3 GB of RAM. +% ----------------------------------------------------------------------- % +for runN = [0 1 2 3 4 5] % or 0 1 2 3 4 5 + % note that run 0 is a special run that has the same parameters as run 3, + % but uses composite data. + % ----------------------------------------------------------------------- % + % Load the models and the data + % ----------------------------------------------------------------------- % + % H = run 1 + % I = run 2 + % F = run 3 + % D = run 4 + % G = run 5 + % set the run specific information. + switch runN + case 0 + projdir = './mcmc_simbio/projects/proj_vnprl'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_vnprl_F3(mobj); + di = data_VNPRL2011; + ts14 = '20200510_045912_1_95'; %300 + ts15 = '20200510_045912_2_48'; %600 + ts16 = '20200512_192355_1_43'; + ts17 = '20200512_192355_2_38'; + ts18 = '20200513_063545_1_33'; + ts19 = '20200513_063545_2_29'; + ts20 = '20200513_063545_3_24'; + ts21 = '20200513_063545_4_19'; + tstamp = {ts14 ts15 ts16 ts17 ts18 ts19 ts20 ts21}; % + nIterID = {1:30 1:30 1:10 1:10 1:15 1:15 1:15 1:15};% + parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + parorder= [2 3 1 4 5 8 10 11 12 13 7 6 9]; + case 1 % alt code: H + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_H'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_H(mobj); + di = data_dsg2014_full; + ts1 = '20190211_122853_1_290'; + ts2 = '20190215_102557_1_232'; + ts3 = '20190215_102557_2_174'; + ts4 = '20190215_102557_3_116'; + tstamp = {ts1 ts2 ts3 ts4}; % + nIterID = {1:10 1:20 1:20 1:20};% + parnames = ... + [{'TX_{cat}' }%1 + {'\tau_{atp}' } + {'\delta_{atp}' } + {'\alpha_{atp}' }%4 + {'pol_{Kd}' } + {'pol_{term}' }%6 + {'n_{Kd1}' } + {'n_{Kd2}' }%8 + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' }%11 + {'RNase' } + {'TL_{cat}' }% 13 + {'GFP_{mat}' }%14 + {'Ribo_{Kd}' } + {'aa_{Kd}' } + {'TL_n_{Kd}' }%17 + {'Ribo_{term}' } + {'Ribo' }];%19 + parorder = [2 3 4 1 5 6 11 7 8 13 15 18 19 16 17 10 9 12 14 ]; + case 2 %alt code: I + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_I'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_I(mobj); + di = data_dsg2014_full; + ts1 = '20190211_123400_1_290'; + ts2 = '20190211_214449_1_29'; + tstamp = {ts1 ts2}; % + nIterID = {1:9 1:20};% + parnames = ... + [{'TX_{cat}' }% 1 + {'\tau_{atp}' } + {'\delta_{atp}' } + {'\alpha_{atp}' } %4 + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } %8 + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'GFP_{mat}' }%12 + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + + parorder = [2 3 4 1 5 6 9 11 13 14 15 8 7 10 12]; + case 3 % alt code: F1 + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_F1'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_F1(mobj); + di = data_dsg2014_full; + ts1 = '20190210_184039_1_195'; + ts2 = '20190210_184039_2_20'; + ts3 = '20190211_054328_1_20'; + ts4 = '20190211_140024_1_20'; + ts5 = '20190212_053457_1_20'; + ts6 = '20190212_114314_1_20'; + tstamp = {ts6};%ts1 ts2 ts3 ts4 ts5 + nIterID = {1:22};%1:10 1:10 1:15 1:27 1:11 + parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + parorder= [2 3 1 4 5 8 10 11 12 13 7 6 9]; + case 4% D + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_D'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_D(mobj); + di = data_dsg2014_full; + ts1 = '20190209_184946_1_44'; + ts2 = '20190210_072127_1_20'; + tstamp = {ts1 ts2}; + nIterID = {1:24 1:16}; + parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + + parorder= [1 2 3 5 7 8 9 10 4 6]; + case 5 + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_G'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_G(mobj); + di = data_dsg2014_full; + ts1 = '20190209_191801_1_127'; + ts2 = '20190210_030032_1_127'; + ts3 = '20190210_123436_1_32'; + ts4 = '20190210_185320_1_3'; + nIterID = {1:20 1:40 1:28};% 1:80 + tstamp = {ts1 ts2 ts3};% ts4 + parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo' }]; + + + parorder= [1 2 3 4 5 6]; + end + + + addpath(projdir) + mi = mcmc_info.model_info; + ri = mcmc_info.runsim_info; + mai = mcmc_info.master_info; + load([projdir '/simdata_' tstamp{end} '/full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + tsToSave = tstamp{end}; + mai.masterVector + marray = mcmc_get_walkers(tstamp,nIterID, projdir); + + %% Plot the results + + switch runN + case 0 + mcmc_plot(marray(parorder, 1:5:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + % last 4k iterations are burned in. + mcmc_plot(marray(parorder, 1:end,(end-200):50:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 1 + % note that the original data is not thinned. Usually we thin the + % iterations by 10. Here, due to the sheer size of the data, we + % thin by 50 + mcmc_plot(marray(parorder, 1:end,1:70:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 14,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + mcmc_plot(marray(parorder, 1:end,(end-4000):1000:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 14,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 2 + mcmc_plot(marray(parorder, 1:5:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 14,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + mcmc_plot(marray(parorder, 1:end,(end-1500):500:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 14,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 3 + mcmc_plot(marray(parorder, 1:5:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + mcmc_plot(marray(parorder, 1:end,(end-3000):500:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 4 + mcmc_plot(marray(parorder, 1:2:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + % last 4k iterations are burned in. + mcmc_plot(marray(parorder, 1:end,(end-1000):500:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 5 + aa = 1; + mcmc_plot(marray(parorder, 1:3:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 20,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + mcmc_plot(marray(parorder, 1:end,(end-2500):250:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 20,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + end + + %% + % ----------------------------------------------------------------------- % + % Plot the trajectories. + % ----------------------------------------------------------------------- % + if runN ~= 5 + workingDir = [pwd '/mcmc_simbio/exp_data/public_data/']; + % run merger + %all_data_merger; + load([workingDir 'mergedExperimentFiles.mat']) + colorCodes = {'r','b','g','c','m','k',[1 1 .5],[.7 .5 .2],[0 1 .2],[.35 .8 .8],[.9 0 .4],[1 .2 .2]}; + + RFUumConvert = 1.723; % (1.723 a.u. = 1 nM) + RFUumConvertMG = 7.75; % (7.75 a.u. = 1 nM) + if runN == 0 + ylims = [1000 50 12000]; + else + ylims = [1000 50 12000].*[1 10 1.8]; + end + lengthToPlotArray = [21, 76, 76]; + miToUse = [1 2 2]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) + msToPlot = [1 1 2]; + timeinterval = [6 8 8]; + % + titleArray = {'RNA deg'; + 'mRNA expression'; + 'deGFP expression'}; + legLoc = {'NorthEast','NorthEast','NorthWest'}; + + legends = [{fliplr({'1000nM', '800nM', '600nM', '200nM', '75nM', '37.5nM'})}; + {{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; + dosesToPlot = {{[1 2 4 5 7 9]} + {[1 2 3 4]} + {[1 2 3 4]}}; + + % clear marray + yLab = {'RNA, nM', 'RNA, nM', 'deGFP, nM'} + % + mvarray = masterVecArray(marray(:,:,(end-300):100:end), mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + for miID = 1:length(mi) + + currmi = mi(miID); + ms = currmi.measuredSpecies; + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, currmi.measuredSpecies); + end + + t_vec_mins=mergedExpFile(1).t_vec/60; + + figure + set(0,'Units','normalized') + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.4, 0.6]) + for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + % experimental data + + + subplot(3, 2, (count-1)*2+1) + if count == 1 % for the RNA use the data info. + % + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(currdi.dataArray(1:lengthToPlot, msToPlot(count), 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + hold on + end + grid on + title([titleArray{count} ' (Exp)']) + ylabel(yLab{count}, 'FontSize', 14) + axis([0 (lengthToPlot-1)*timeinterval(count), 0 ylims(count)]) + ax = gca; + ax.FontSize = 14; + + elseif count == 2 % for the MG aptamer and the deGFP, use the scripts provided by Zoltan. + %%%%% MG KINETICS WITH CORRECT BACKGROUNDS SUBTRACTED + plotSelect=[ 5, 7, 8, 10]; + mgBackground = mergedExpFile(1).Data_mean(:,1:11,1); + mgNoBgMean=mergedExpFile(1).Data_mean(:,12:22,1)-mgBackground; + + if runN == 0 + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG/10; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG/10; + end + else + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG; + end + end + + % figure('Name','MG kinetics'); + hold on + % errorbar(repmat(t_vec_mins,1,length(plotSelect)),mgNoBgMean(:,plotSelect),mgNoBgErr(:,plotSelect)); + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + h = stdshade(t_vec_mins, ... + mgNoBgMean(:,plotSelect), ... + mgNoBgErr(:,plotSelect), ... + 0.3, ... + colorzCell); + title([titleArray{count} ' (Exp)']) + %h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,plotSelect+11,1) + % /RFUumConvertMG,mergedExpFile(1).noBg_std(:,plotSelect+11)/RFUumConvertMG,0.3,colorCodes); + axis([0 (lengthToPlot-1)*timeinterval(count), ... + 0, ... + ylims(count)]) + ylabel('RNA, nM') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', ... + 'pr-gfp-mg15 %0.2g nM')); + %legend(h,legendStr,'Location','NorthEast') + ax = gca; + ax.FontSize = 14; + elseif count == 3 + plotSelect=[5, 7, 8, 10]; + % figure('Name','GFP kinetics'); + hold on + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + if runN == 0 + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert/1.8,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3)/1.8,0.3,colorzCell); + else + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3),0.3,colorzCell); + end + + axis([0 (lengthToPlot-1)*timeinterval(count),0,ylims(count)]) + title([titleArray{count} ' (Exp)']) + xlabel('time, minutes') + ylabel('deGFP (uM)') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', 'pr-gfp-mg15 %0.2g nM')); + ax = gca; + ax.FontSize = 14; + %legend(h,legendStr,'Location','NorthWest') + end + + % simulation results + subplot(3, 2, (count-1)*2+2) + + for dID = dosesToPlot{count}{:} + + [linehandle(dID), ptchhandle] =... + boundedline(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + std(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID)... + +eps*randn(lengthToPlot, 1, 50), 0,3)); + set(ptchhandle, ... + 'FaceColor', colorz(dID+2, :),... + 'FaceAlpha', 0.25); + set(linehandle(dID), ... + 'Color', colorz(dID+2, :),... + 'LineWidth', 1.5); + + hold on + end + grid on + title([titleArray{count} ' (Fit)']) + + legend(linehandle(dosesToPlot{count}{:}), legends{count, :}, 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + specificproj = [projdir '/simdata_' tsToSave]; +% print(gcf, '-djpeg', '-r600', [specificproj '/traj' tsToSave]) +% print(gcf, '-dpng', '-r600', [specificproj '/traj' tsToSave]) + print(gcf, '-djpeg', '-r200', [specificproj '/traj_lowres_' tsToSave]) + print(gcf, '-dpng', '-r200', [specificproj '/traj_lowres_' tsToSave]) + + else + + workingDir = [pwd '/mcmc_simbio/exp_data/public_data/']; + % run merger + %all_data_merger; + load([workingDir 'mergedExperimentFiles.mat']) + + colorCodes = {'r','b','g','c','m','k',[1 1 .5],[.7 .5 .2],[0 1 .2],[.35 .8 .8],[.9 0 .4],[1 .2 .2]}; + + RFUumConvert = 1.723; % (1.723 a.u. = 1 nM) + RFUumConvertMG = 7.75; % (7.75 a.u. = 1 nM) + + ylims = [50 12000].*[10 1.8]; + + lengthToPlotArray = [76, 76]; + miToUse = [1 1]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) + msToPlot = [1 2]; + timeinterval = [8 8]; + % + titleArray = {'mRNA expression'; + 'deGFP expression'}; + legLoc = {'NorthEast','NorthWest'}; + + legends = [{{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; + dosesToPlot = {{[1 2 3 4]} + {[1 2 3 4]}}; + + % clear marray + yLab = {'RNA, nM', 'deGFP, nM'} + mvarray = masterVecArray(marray(:,:,(end-300):100:end), mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % resimulate, + % ms = {{'protein deGFP*'}}; + for miID = 1:length(mi) + currmi = mi(miID); + ms = currmi.measuredSpecies; + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, currmi.measuredSpecies); + end + + t_vec_mins=mergedExpFile(1).t_vec/60; + + figure + set(0,'Units','normalized') + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.4, 0.6]) + for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + % experimental data + subplot(2, 2, (count-1)*2+1) + if count == 1 % for the MG aptamer and the deGFP, use the scripts provided by Zoltan. + %%%%% MG KINETICS WITH CORRECT BACKGROUNDS SUBTRACTED + plotSelect=[ 5, 7, 8, 10]; + mgBackground = mergedExpFile(1).Data_mean(:,1:11,1); + mgNoBgMean=mergedExpFile(1).Data_mean(:,12:22,1)-mgBackground; + + + + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG; + end + + + hold on + % errorbar(repmat(t_vec_mins,1,length(plotSelect)),mgNoBgMean(:,plotSelect),mgNoBgErr(:,plotSelect)); + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + h = stdshade(t_vec_mins, ... + mgNoBgMean(:,plotSelect), ... + mgNoBgErr(:,plotSelect), ... + 0.3, ... + colorzCell); + title([titleArray{count} ' (Exp)']) + %h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,plotSelect+11,1) + % /RFUumConvertMG,mergedExpFile(1).noBg_std(:,plotSelect+11)/RFUumConvertMG,0.3,colorCodes); + axis([0 (lengthToPlot-1)*timeinterval(count), ... + 0, ... + ylims(count)]) + ylabel('RNA, nM') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', ... + 'pr-gfp-mg15 %0.2g nM')); + %legend(h,legendStr,'Location','NorthEast') + ax = gca; + ax.FontSize = 14; + elseif count == 2 + plotSelect=[5, 7, 8, 10]; + % figure('Name','GFP kinetics'); + hold on + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + if runN == 0 + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert/1.8,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3)/1.8,0.3,colorzCell); + else + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3),0.3,colorzCell); + end + + axis([0 (lengthToPlot-1)*timeinterval(count),0,ylims(count)]) + title([titleArray{count} ' (Exp)']) + xlabel('time, minutes') + ylabel('deGFP (uM)') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', 'pr-gfp-mg15 %0.2g nM')); + ax = gca; + ax.FontSize = 14; + %legend(h,legendStr,'Location','NorthWest') + end + + % simulation results + subplot(2, 2, (count-1)*2+2) + + for dID = dosesToPlot{count}{:} + + [linehandle(dID), ptchhandle] =... + boundedline(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + std(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID)... + +eps*randn(lengthToPlot, 1, 50), 0,3)); + set(ptchhandle, ... + 'FaceColor', colorz(dID+2, :),... + 'FaceAlpha', 0.25); + set(linehandle(dID), ... + 'Color', colorz(dID+2, :),... + 'LineWidth', 1.5); + + % + % plot(tv(1:lengthToPlot)/60,... + % mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + % 'LineWidth', 1.5,... + % 'Color', colorz(dID+2, :)) + hold on + end + grid on + title([titleArray{count} ' (Fit)']) + + legend(linehandle(dosesToPlot{count}{:}), legends{count, :},... + 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + specificproj = [projdir '/simdata_' tsToSave]; +% print(gcf, '-djpeg', '-r600', [specificproj '/traj' tsToSave]) +% print(gcf, '-dpng', '-r600', [specificproj '/traj' tsToSave]) + print(gcf, '-djpeg', '-r200', [specificproj '/traj_lowres_' tsToSave]) + print(gcf, '-dpng', '-r200', [specificproj '/traj_lowres_' tsToSave]) +% print(gcf, '-depsc', [specificproj '/traj_eps_' tsToSave]) + + + end +end diff --git a/generate_paper_figs/Core_characterization_plots.m.orig b/generate_paper_figs/Core_characterization_plots.m.orig new file mode 100644 index 0000000..f7753fa --- /dev/null +++ b/generate_paper_figs/Core_characterization_plots.m.orig @@ -0,0 +1,1286 @@ +<<<<<<< HEAD +% Runs 1 to 5 plots +% Purpose: Fit models to the DSG ACS 2014 data. +% +% Author: +% Vipul Singhal +% California Institute of Technology +% +% 1. Gene Circuit Performance Characterization +% and Resource Usage in a Cell-Free ?Breadboard? +% Siegal-Gaskins, et. al +% + +% ----------------------------------------------------------------------- % +% Select Run number +% ----------------------------------------------------------------------- % +runN = 1; % or 2, 3, 4, 5. +% note that run 0 is a special run that has the same parameters as run 3, +% but uses composite data. +% ----------------------------------------------------------------------- % +% Load the models and the data +% ----------------------------------------------------------------------- % +txtldir = txtl_init; +mcmc_init; + +% H = run 1 +% I = run 2 +% F = run 3 +% D = run 4 +% G = run 5 + +figsavedir = './generate_paper_figs' +% set the run specific information. +switch runN + case 0 + projdir = './mcmc_simbio/projects/proj_vnprl'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_vnprl_F3(mobj); + di = data_VNPRL2011; + ts14 = '20200510_045912_1_95'; + ts15 = '20200510_045912_2_48'; + ts16 = '20200512_192355_1_43'; + ts17 = '20200512_192355_2_38'; + ts18 = '20200513_063545_1_33'; + ts19 = '20200513_063545_2_29'; + ts20 = '20200513_063545_3_24'; + ts21 = '20200513_063545_4_19'; + tstamp = {ts14 ts15 ts16 ts17 ts18 ts19 ts20 ts21}; % + nIterID = {1:30 1:21 1:10 1:10 1:15 1:15 1:15 1:15};% + parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + + case 1 % alt code: H + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_H'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_H(mobj); + di = data_dsg2014_full; + ts1 = '20190211_122853_1_290'; %0.005 + ts2 = '20190215_102557_1_232'; + ts3 = '20190215_102557_2_174'; + ts4 = '20190215_102557_3_116'; + tstamp = {ts1 ts2 ts3 ts4}; % + nIterID = {1:10 1:20 1:20 1:20};% + parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'\alpha_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'n_{Kd1}' } + {'n_{Kd2}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'GFP_{mat}' } + {'Ribo_{Kd}' } + {'aa_{Kd}' } + {'TL_n_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + + case 2 %alt code: I + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_I'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_I(mobj); + di = data_dsg2014_full; + ts1 = '20190211_123400_1_290'; + ts2 = '20190211_214449_1_29'; + tstamp = {ts1 ts2}; % + nIterID = {1:9 1:20};% + parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'\alpha_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'GFP_{mat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + case 3 % alt code: F1 + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_F1'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_F1(mobj); + di = data_dsg2014_full; + ts1 = '20190210_184039_1_195'; + ts2 = '20190210_184039_2_20'; + ts3 = '20190211_054328_1_20'; + ts4 = '20190211_140024_1_20'; + ts5 = '20190212_053457_1_20'; + tstamp = {ts1 ts2 ts3 ts4}; + nIterID = {1:10 1:10 1:15 1:27 1:11}; + parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + case 4 + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_D'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_D(mobj); + di = data_dsg2014_full; + ts1 = '20190209_184946_1_44'; + ts2 = '20190210_072127_1_20'; + tstamp = {ts1 ts2}; + nIterID = {1:24 1:16}; + parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + case 5 + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_G'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_G(mobj); + di = data_dsg2014_full; + ts1 = '20190209_191801_1_127'; + ts2 = '20190210_030032_1_127'; + ts3 = '20190210_123436_1_32'; + ts4 = '20190210_185320_1_3'; + nIterID = {1:20 1:29 1:28 1:80}; + tstamp = {ts1 ts2 ts3 ts4}; + parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo' }]; +end + + +addpath(projdir) +figsave = false; +jpgsave = true; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +load([projdir '/simdata_' tstamp{end} '/full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +tsToSave = tstamp{end}; +mai.masterVector +marray = mcmc_get_walkers(tstamp,nIterID, projdir); + +% ----------------------------------------------------------------------- % +% Set data and input directories +% ----------------------------------------------------------------------- % + +%% just the troublesome parameter ranges. + +mcmc_plot(marray(:, 1:20:end,:), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,'fontsize', 12,... + 'projdir', figsavedir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); +%% +%% +%% + +% ----------------------------------------------------------------------- % +% Plot the parameter distributions, and Markov chains. +% ----------------------------------------------------------------------- % +% close all +mcmc_plot(marray(:, 1:100:end,:), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring','WithTransient'); +%% +mcmc_plot(marray(:, 1:end,(end-200):100:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring','small_hypercube_initialization'); +%% + close all +mcmc_plot(marray(:, :,(end-250):50:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'BurnedIn'); +%% + close all +mcmc_plot(marray(selected_params, :,(end-250):50:end), parnames(selected_params),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 22,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'BurnedIn_smallfont2'); +%% + +for ess = 320:20:500 +mcmc_plot(marray(:, 1:end,(end-800):200:end), parnames(:),... + 'savematlabfig', figsave, 'scatter', false,'ess', ess,... + 'plotChains', false,... + 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['BurnedIn_jul31_ess_' num2str(ess)]); + pause(30) + close all + figure + plot(1:10, 1:10) + close +end + + +%% +% ----------------------------------------------------------------------- % +% Plot the trajectories. +% ----------------------------------------------------------------------- % + +workingDir = [pwd '/mcmc_simbio/exp_data/public_data/']; + +% run merger +%all_data_merger; +load([workingDir 'mergedExperimentFiles.mat']) + +colorCodes = {'r','b','g','c','m','k',[1 1 .5],[.7 .5 .2],[0 1 .2],[.35 .8 .8],[.9 0 .4],[1 .2 .2]}; + +RFUumConvert = 1.723; % (1.723 a.u. = 1 nM) +RFUumConvertMG = 7.75; % (7.75 a.u. = 1 nM) + + +ylims = [1000 50 12000]; +lengthToPlotArray = [21, 76, 76]; + + +% +% ss = get(0, 'screensize'); +% set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3 ss(4)/1.4]); +miToUse = [1 2 2]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) +msToPlot = [1 1 2]; +timeinterval = [6 8 8]; +% +titleArray = {'RNA deg'; + 'mRNA expression'; + 'deGFP expression'}; +legLoc = {'NorthEast','NorthEast','NorthWest'}; + +legends = [{fliplr({'1000nM', '800nM', '600nM', '200nM', '75nM', '37.5nM'})}; + {{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; +dosesToPlot = {{[1 2 4 5 7 9]} + {[1 2 3 4]} + {[1 2 3 4]}}; + +% clear marray +yLab = {'RNA, nM', 'RNA, nM', 'deGFP, nM'} +%% +mvarray = masterVecArray(marray(:,:,(end-300):100:end), mai); + + +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + +% resimulate, +% ms = {{'protein deGFP*'}}; +for miID = 1:length(mi) + + currmi = mi(miID); + ms = currmi.measuredSpecies; + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, currmi.measuredSpecies); +end + +t_vec_mins=mergedExpFile(1).t_vec/60; + + +%% + +figure +set(0,'Units','normalized') +set(gcf,'Units', 'normalized') +set(gcf, 'Position', [0.05, 0.1, 0.4, 0.6]) +for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + + % experimental data + subplot(3, 2, (count-1)*2+1) + if count == 1 % for the RNA use the data info. + % + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(currdi.dataArray(1:lengthToPlot, msToPlot(count), 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + grid on + title([titleArray{count} ' (Exp)']) + ylabel(yLab{count}, 'FontSize', 14) + axis([0 (lengthToPlot-1)*timeinterval(count), 0 ylims(count)]) + ax = gca; + ax.FontSize = 14; + + elseif count == 2 % for the MG aptamer and the deGFP, use the scripts provided by Zoltan. + %%%%% MG KINETICS WITH CORRECT BACKGROUNDS SUBTRACTED + plotSelect=[ 5, 7, 8, 10]; + mgBackground = mergedExpFile(1).Data_mean(:,1:11,1); + mgNoBgMean=mergedExpFile(1).Data_mean(:,12:22,1)-mgBackground; + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG/10; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG/10; + end +% figure('Name','MG kinetics'); + hold on + % errorbar(repmat(t_vec_mins,1,length(plotSelect)),mgNoBgMean(:,plotSelect),mgNoBgErr(:,plotSelect)); + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + h = stdshade(t_vec_mins, ... + mgNoBgMean(:,plotSelect), ... + mgNoBgErr(:,plotSelect), ... + 0.3, ... + colorzCell); + title([titleArray{count} ' (Exp)']) + %h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,plotSelect+11,1)/RFUumConvertMG,mergedExpFile(1).noBg_std(:,plotSelect+11)/RFUumConvertMG,0.3,colorCodes); + axis([0 (lengthToPlot-1)*timeinterval(count), ... + 0, ... + ylims(count)]) + ylabel('RNA, nM') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', ... + 'pr-gfp-mg15 %0.2g nM')); + %legend(h,legendStr,'Location','NorthEast') + ax = gca; + ax.FontSize = 14; + elseif count == 3 + plotSelect=[5, 7, 8, 10]; +% figure('Name','GFP kinetics'); + hold on + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert/1.8,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3)/1.8,0.3,colorzCell); + axis([0 (lengthToPlot-1)*timeinterval(count),0,ylims(count)]) + title([titleArray{count} ' (Exp)']) + xlabel('Time [mins]') + ylabel('deGFP (uM)') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', 'pr-gfp-mg15 %0.2g nM')); + ax = gca; + ax.FontSize = 14; + %legend(h,legendStr,'Location','NorthWest') + end + + % simulation results + subplot(3, 2, (count-1)*2+2) + + for dID = dosesToPlot{count}{:} + + [linehandle(dID), ptchhandle] =... + boundedline(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + std(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID)... + +eps*randn(lengthToPlot, 1, 50), 0,3)); + set(ptchhandle, ... + 'FaceColor', colorz(dID+2, :),... + 'FaceAlpha', 0.25); + set(linehandle(dID), ... + 'Color', colorz(dID+2, :),... + 'LineWidth', 1.5); + +% +% plot(tv(1:lengthToPlot)/60,... +% mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... +% 'LineWidth', 1.5,... +% 'Color', colorz(dID+2, :)) + hold on + end + grid on + title([titleArray{count} ' (Fit)']) + + legend(linehandle(dosesToPlot{count}{:}), legends{count, :}, 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; +end + + + + + + + + +% ----------------------------------------------------------------------- % + +% ----------------------------------------------------------------------- % +======= +% Plotting the core mechanism characterization results +% Purpose: Fit models to the DSG ACS 2014 data and to the composite data. +% +% Author: +% Vipul Singhal +% California Institute of Technology +% +% 1. Gene Circuit Performance Characterization +% and Resource Usage in a Cell-Free ?Breadboard? +% Siegal-Gaskins, et. al +% +txtldir = txtl_init; +mcmc_init; +% ----------------------------------------------------------------------- % +% Select Run number +% ----------------------------------------------------------------------- % +for runN = [0 1 2 3 4 5] % or 2, 3, 4, 5. + % note that run 0 is a special run that has the same parameters as run 3, + % but uses composite data. + % ----------------------------------------------------------------------- % + % Load the models and the data + % ----------------------------------------------------------------------- % + + + % H = run 1 + % I = run 2 + % F = run 3 + % D = run 4 + % G = run 5 + + % set the run specific information. + switch runN + case 0 + projdir = './mcmc_simbio/projects/proj_vnprl'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_vnprl_F3(mobj); + di = data_VNPRL2011; + ts14 = '20200510_045912_1_95'; %300 + ts15 = '20200510_045912_2_48'; %600 + ts16 = '20200512_192355_1_43'; + ts17 = '20200512_192355_2_38'; + ts18 = '20200513_063545_1_33'; + ts19 = '20200513_063545_2_29'; + ts20 = '20200513_063545_3_24'; + ts21 = '20200513_063545_4_19'; + tstamp = {ts14 ts15 ts16 ts17 ts18 ts19 ts20 ts21}; % + nIterID = {1:30 1:30 1:10 1:10 1:15 1:15 1:15 1:15};% + parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + parorder= [2 3 1 4 5 8 10 11 12 13 7 6 9]; + case 1 % alt code: H + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_H'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_H(mobj); + di = data_dsg2014_full; + ts1 = '20190211_122853_1_290'; + ts2 = '20190215_102557_1_232'; + ts3 = '20190215_102557_2_174'; + ts4 = '20190215_102557_3_116'; + tstamp = {ts1 ts2 ts3 ts4}; % + nIterID = {1:10 1:20 1:20 1:20};% + parnames = ... + [{'TX_{cat}' }%1 + {'\tau_{atp}' } + {'\delta_{atp}' } + {'\alpha_{atp}' }%4 + {'pol_{Kd}' } + {'pol_{term}' }%6 + {'n_{Kd1}' } + {'n_{Kd2}' }%8 + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' }%11 + {'RNase' } + {'TL_{cat}' }% 13 + {'GFP_{mat}' }%14 + {'Ribo_{Kd}' } + {'aa_{Kd}' } + {'TL_n_{Kd}' }%17 + {'Ribo_{term}' } + {'Ribo' }];%19 + parorder = [2 3 4 1 5 6 11 7 8 13 15 18 19 16 17 10 9 12 14 ]; + case 2 %alt code: I + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_I'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_I(mobj); + di = data_dsg2014_full; + ts1 = '20190211_123400_1_290'; + ts2 = '20190211_214449_1_29'; + tstamp = {ts1 ts2}; % + nIterID = {1:9 1:20};% + parnames = ... + [{'TX_{cat}' }% 1 + {'\tau_{atp}' } + {'\delta_{atp}' } + {'\alpha_{atp}' } %4 + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } %8 + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'GFP_{mat}' }%12 + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + + parorder = [2 3 4 1 5 6 9 11 13 14 15 8 7 10 12]; + case 3 % alt code: F1 + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_F1'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_F1(mobj); + di = data_dsg2014_full; + ts1 = '20190210_184039_1_195'; + ts2 = '20190210_184039_2_20'; + ts3 = '20190211_054328_1_20'; + ts4 = '20190211_140024_1_20'; + ts5 = '20190212_053457_1_20'; + ts6 = '20190212_114314_1_20'; + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6}; + nIterID = {1:10 1:10 1:15 1:27 1:11 1:22}; + parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + parorder= [2 3 1 4 5 8 10 11 12 13 7 6 9]; + + + case 4% D + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_D'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_D(mobj); + di = data_dsg2014_full; + ts1 = '20190209_184946_1_44'; + ts2 = '20190210_072127_1_20'; + tstamp = {ts1 ts2}; + nIterID = {1:24 1:16}; + parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + + parorder= [1 2 3 5 7 8 9 10 4 6]; + case 5 + projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_G'; + mobj = model_dsg2014_regen; + mcmc_info = mcmc_info_dsg2014_regen_G(mobj); + di = data_dsg2014_full; + ts1 = '20190209_191801_1_127'; + ts2 = '20190210_030032_1_127'; + ts3 = '20190210_123436_1_32'; + ts4 = '20190210_185320_1_3'; + nIterID = {1:20 1:40 1:28};% 1:80 + tstamp = {ts1 ts2 ts3};% ts4 + parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo' }]; + + + parorder= [1 2 3 4 5 6]; + end + + + addpath(projdir) + figsave = false; + jpgsave = true; + + mi = mcmc_info.model_info; + ri = mcmc_info.runsim_info; + mai = mcmc_info.master_info; + load([projdir '/simdata_' tstamp{end} '/full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + tsToSave = tstamp{end}; + mai.masterVector + marray = mcmc_get_walkers(tstamp,nIterID, projdir); + + %% Plot the results + + switch runN + case 0 + mcmc_plot(marray(parorder, 1:5:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + % last 4k iterations are burned in. + mcmc_plot(marray(parorder, 1:end,(end-200):50:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 1 + % note that the original data is not thinned. Usually we thin the + % iterations by 10. Here, due to the sheer size of the data, we + % thin by 50 + mcmc_plot(marray(parorder, 1:end,1:70:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 14,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + mcmc_plot(marray(parorder, 1:end,(end-4000):1000:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 14,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 2 + mcmc_plot(marray(parorder, 1:5:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 14,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + mcmc_plot(marray(parorder, 1:end,(end-1500):500:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 14,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 3 + mcmc_plot(marray(parorder, 1:5:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + mcmc_plot(marray(parorder, 1:end,(end-3000):500:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 4 + mcmc_plot(marray(parorder, 1:2:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + % last 4k iterations are burned in. + mcmc_plot(marray(parorder, 1:end,(end-1000):500:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + case 5 + aa = 1; + mcmc_plot(marray(parorder, 1:3:end,1:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,... + 'plotDistribution', false, ... + 'fontsize', 20,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['all_iter_run' num2str(runN)]); + + mcmc_plot(marray(parorder, 1:end,(end-2500):250:end), parnames(parorder),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 20,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['burnedin_run' num2str(runN)]); + end + + %% + % ----------------------------------------------------------------------- % + % Plot the trajectories. + % ----------------------------------------------------------------------- % + if runN ~= 5 + + + workingDir = [pwd '/mcmc_simbio/exp_data/public_data/']; + % run merger + %all_data_merger; + load([workingDir 'mergedExperimentFiles.mat']) + + colorCodes = {'r','b','g','c','m','k',[1 1 .5],[.7 .5 .2],[0 1 .2],[.35 .8 .8],[.9 0 .4],[1 .2 .2]}; + + RFUumConvert = 1.723; % (1.723 a.u. = 1 nM) + RFUumConvertMG = 7.75; % (7.75 a.u. = 1 nM) + + if runN == 0 + ylims = [1000 50 12000]; + else + ylims = [1000 50 12000].*[1 10 1.8]; + end + + lengthToPlotArray = [21, 76, 76]; + + % + miToUse = [1 2 2]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) + msToPlot = [1 1 2]; + timeinterval = [6 8 8]; + % + titleArray = {'RNA deg'; + 'mRNA expression'; + 'deGFP expression'}; + legLoc = {'NorthEast','NorthEast','NorthWest'}; + + legends = [{fliplr({'1000nM', '800nM', '600nM', '200nM', '75nM', '37.5nM'})}; + {{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; + dosesToPlot = {{[1 2 4 5 7 9]} + {[1 2 3 4]} + {[1 2 3 4]}}; + + % clear marray + yLab = {'RNA, nM', 'RNA, nM', 'deGFP, nM'} + % + mvarray = masterVecArray(marray(:,:,(end-300):100:end), mai); + + + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + + % resimulate, + % ms = {{'protein deGFP*'}}; + for miID = 1:length(mi) + + currmi = mi(miID); + ms = currmi.measuredSpecies; + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, currmi.measuredSpecies); + end + + t_vec_mins=mergedExpFile(1).t_vec/60; + + figure + set(0,'Units','normalized') + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.4, 0.6]) + for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + % experimental data + + + subplot(3, 2, (count-1)*2+1) + if count == 1 % for the RNA use the data info. + % + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(currdi.dataArray(1:lengthToPlot, msToPlot(count), 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + hold on + end + grid on + title([titleArray{count} ' (Exp)']) + ylabel(yLab{count}, 'FontSize', 14) + axis([0 (lengthToPlot-1)*timeinterval(count), 0 ylims(count)]) + ax = gca; + ax.FontSize = 14; + + + + elseif count == 2 % for the MG aptamer and the deGFP, use the scripts provided by Zoltan. + %%%%% MG KINETICS WITH CORRECT BACKGROUNDS SUBTRACTED + plotSelect=[ 5, 7, 8, 10]; + mgBackground = mergedExpFile(1).Data_mean(:,1:11,1); + mgNoBgMean=mergedExpFile(1).Data_mean(:,12:22,1)-mgBackground; + + + + + if runN == 0 + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG/10; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG/10; + end + else + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG; + end + end + + % figure('Name','MG kinetics'); + hold on + % errorbar(repmat(t_vec_mins,1,length(plotSelect)),mgNoBgMean(:,plotSelect),mgNoBgErr(:,plotSelect)); + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + h = stdshade(t_vec_mins, ... + mgNoBgMean(:,plotSelect), ... + mgNoBgErr(:,plotSelect), ... + 0.3, ... + colorzCell); + title([titleArray{count} ' (Exp)']) + %h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,plotSelect+11,1) + % /RFUumConvertMG,mergedExpFile(1).noBg_std(:,plotSelect+11)/RFUumConvertMG,0.3,colorCodes); + axis([0 (lengthToPlot-1)*timeinterval(count), ... + 0, ... + ylims(count)]) + ylabel('RNA, nM') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', ... + 'pr-gfp-mg15 %0.2g nM')); + %legend(h,legendStr,'Location','NorthEast') + ax = gca; + ax.FontSize = 14; + elseif count == 3 + plotSelect=[5, 7, 8, 10]; + % figure('Name','GFP kinetics'); + hold on + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + if runN == 0 + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert/1.8,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3)/1.8,0.3,colorzCell); + else + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3),0.3,colorzCell); + end + + axis([0 (lengthToPlot-1)*timeinterval(count),0,ylims(count)]) + title([titleArray{count} ' (Exp)']) + xlabel('time, minutes') + ylabel('deGFP (uM)') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', 'pr-gfp-mg15 %0.2g nM')); + ax = gca; + ax.FontSize = 14; + %legend(h,legendStr,'Location','NorthWest') + end + + % simulation results + subplot(3, 2, (count-1)*2+2) + + for dID = dosesToPlot{count}{:} + + [linehandle(dID), ptchhandle] =... + boundedline(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + std(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID)... + +eps*randn(lengthToPlot, 1, 50), 0,3)); + set(ptchhandle, ... + 'FaceColor', colorz(dID+2, :),... + 'FaceAlpha', 0.25); + set(linehandle(dID), ... + 'Color', colorz(dID+2, :),... + 'LineWidth', 1.5); + + % + % plot(tv(1:lengthToPlot)/60,... + % mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + % 'LineWidth', 1.5,... + % 'Color', colorz(dID+2, :)) + hold on + end + grid on + title([titleArray{count} ' (Fit)']) + + legend(linehandle(dosesToPlot{count}{:}), legends{count, :}, 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + specificproj = [projdir '/simdata_' tsToSave]; +% print(gcf, '-djpeg', '-r600', [specificproj '/traj' tsToSave]) +% print(gcf, '-dpng', '-r600', [specificproj '/traj' tsToSave]) + print(gcf, '-djpeg', '-r200', [specificproj '/traj_lowres_' tsToSave]) + print(gcf, '-dpng', '-r200', [specificproj '/traj_lowres_' tsToSave]) + + + + + + + % ----------------------------------------------------------------------- % + + % --------------------- + + else + + + + workingDir = [pwd '/mcmc_simbio/exp_data/public_data/']; + % run merger + %all_data_merger; + load([workingDir 'mergedExperimentFiles.mat']) + + colorCodes = {'r','b','g','c','m','k',[1 1 .5],[.7 .5 .2],[0 1 .2],[.35 .8 .8],[.9 0 .4],[1 .2 .2]}; + + RFUumConvert = 1.723; % (1.723 a.u. = 1 nM) + RFUumConvertMG = 7.75; % (7.75 a.u. = 1 nM) + + ylims = [50 12000].*[10 1.8]; + + lengthToPlotArray = [76, 76]; + + % + miToUse = [1 1]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) + msToPlot = [1 2]; + timeinterval = [8 8]; + % + titleArray = {'mRNA expression'; + 'deGFP expression'}; + legLoc = {'NorthEast','NorthWest'}; + + legends = [{{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; + dosesToPlot = {{[1 2 3 4]} + {[1 2 3 4]}}; + + % clear marray + yLab = {'RNA, nM', 'deGFP, nM'} + % + mvarray = masterVecArray(marray(:,:,(end-300):100:end), mai); + + + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + + % resimulate, + % ms = {{'protein deGFP*'}}; + for miID = 1:length(mi) + currmi = mi(miID); + ms = currmi.measuredSpecies; + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, currmi.measuredSpecies); + end + + t_vec_mins=mergedExpFile(1).t_vec/60; + + figure + set(0,'Units','normalized') + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.4, 0.6]) + for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + % experimental data + + + subplot(2, 2, (count-1)*2+1) + % if count == 1 % for the RNA use the data info. + % + % for dID = dosesToPlot{count}{:} + % plot(tv(1:lengthToPlot)/60,... + % mean(currdi.dataArray(1:lengthToPlot, msToPlot(count), 1, dID),3),... + % 'LineWidth', 1.5,... + % 'Color', colorz(dID+2, :)) + % hold on + % end + % grid on + % title([titleArray{count} ' (Exp)']) + % ylabel(yLab{count}, 'FontSize', 14) + % axis([0 (lengthToPlot-1)*timeinterval(count), 0 ylims(count)]) + % ax = gca; + % ax.FontSize = 14; + % + % end + + + if count == 1 % for the MG aptamer and the deGFP, use the scripts provided by Zoltan. + %%%%% MG KINETICS WITH CORRECT BACKGROUNDS SUBTRACTED + plotSelect=[ 5, 7, 8, 10]; + mgBackground = mergedExpFile(1).Data_mean(:,1:11,1); + mgNoBgMean=mergedExpFile(1).Data_mean(:,12:22,1)-mgBackground; + + + + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG; + end + + + hold on + % errorbar(repmat(t_vec_mins,1,length(plotSelect)),mgNoBgMean(:,plotSelect),mgNoBgErr(:,plotSelect)); + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + h = stdshade(t_vec_mins, ... + mgNoBgMean(:,plotSelect), ... + mgNoBgErr(:,plotSelect), ... + 0.3, ... + colorzCell); + title([titleArray{count} ' (Exp)']) + %h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,plotSelect+11,1) + % /RFUumConvertMG,mergedExpFile(1).noBg_std(:,plotSelect+11)/RFUumConvertMG,0.3,colorCodes); + axis([0 (lengthToPlot-1)*timeinterval(count), ... + 0, ... + ylims(count)]) + ylabel('RNA, nM') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', ... + 'pr-gfp-mg15 %0.2g nM')); + %legend(h,legendStr,'Location','NorthEast') + ax = gca; + ax.FontSize = 14; + elseif count == 2 + plotSelect=[5, 7, 8, 10]; + % figure('Name','GFP kinetics'); + hold on + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + if runN == 0 + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert/1.8,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3)/1.8,0.3,colorzCell); + else + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3),0.3,colorzCell); + end + + axis([0 (lengthToPlot-1)*timeinterval(count),0,ylims(count)]) + title([titleArray{count} ' (Exp)']) + xlabel('time, minutes') + ylabel('deGFP (uM)') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', 'pr-gfp-mg15 %0.2g nM')); + ax = gca; + ax.FontSize = 14; + %legend(h,legendStr,'Location','NorthWest') + end + + % simulation results + subplot(2, 2, (count-1)*2+2) + + for dID = dosesToPlot{count}{:} + + [linehandle(dID), ptchhandle] =... + boundedline(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + std(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID)... + +eps*randn(lengthToPlot, 1, 50), 0,3)); + set(ptchhandle, ... + 'FaceColor', colorz(dID+2, :),... + 'FaceAlpha', 0.25); + set(linehandle(dID), ... + 'Color', colorz(dID+2, :),... + 'LineWidth', 1.5); + + % + % plot(tv(1:lengthToPlot)/60,... + % mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + % 'LineWidth', 1.5,... + % 'Color', colorz(dID+2, :)) + hold on + end + grid on + title([titleArray{count} ' (Fit)']) + + legend(linehandle(dosesToPlot{count}{:}), legends{count, :},... + 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + specificproj = [projdir '/simdata_' tsToSave]; +% print(gcf, '-djpeg', '-r600', [specificproj '/traj' tsToSave]) +% print(gcf, '-dpng', '-r600', [specificproj '/traj' tsToSave]) + print(gcf, '-djpeg', '-r200', [specificproj '/traj_lowres_' tsToSave]) + print(gcf, '-dpng', '-r200', [specificproj '/traj_lowres_' tsToSave]) + print(gcf, '-depsc', [specificproj '/traj_eps_' tsToSave]) + + + + + + % ----------------------------------------------------------------------- % + + % --------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + end + +end +>>>>>>> 88bc0f02b494c72e2513162c77a1e4ff4e719796 diff --git a/generate_paper_figs/Fig5_IFFL_characterization_Cv6.m b/generate_paper_figs/Fig5_IFFL_characterization_Cv6.m new file mode 100644 index 0000000..d0332a2 --- /dev/null +++ b/generate_paper_figs/Fig5_IFFL_characterization_Cv6.m @@ -0,0 +1,355 @@ +% Generate Incoherent Feed-Forward Loop characterization plots from the paper: +% +% A MATLAB Toolbox for Modeling Genetic Circuits in Cell-Free Systems +% by Vipul Singhal, Zoltan A. Tuza, Zachary S. Sun, and Richard M. Murray +% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Instructions +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% 1. check that the working directory is the one where folders like core, +% components, mcmc_simbio, config etc are. This is the trunk directory. +% 2. Download dataset, and place in the correct directory. You need around 800mb +% of free hard disk space to download the full dataset. Download at: +% https://www.dropbox.com/sh/9zn7666ll6fm4po/AAB1nS2Vi3Aej7vmPD-kQBhXa?dl=0 +% 3. Make sure you have 7 GB of free ram. Otherwise, set the flag +% 'small_ram' to true, and you will plot the same things but with only +% 4 GB of ram needed. This only plots the last few iterations of the MCMC. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Set flags +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +small_ram = true; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Set directories and load data and files. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +txtl_init +mcmc_init + +saveFinalFigs = [pwd '\generate_papaer_figs\charac'] +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v6']; +% Set working directory to the txtlsim toolbox directory. +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Load model, mcmc_info, and data_info (experimental data) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v6(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% load simulation data +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +tsIDtouse = 1; +switch tsIDtouse + case 1 + ts31 = '20200612_214710_1_1476'; + ts32 = '20200614_005043_1_1476'; + ts33 = '20200614_005043_2_2214'; + ts34 = '20200614_005043_3_2953'; + ts35 = '20200614_005043_4_3691'; + ts36 = '20200614_005043_5_2953'; + ts37 = '20200615_233435_1_2953'; + ts38 = '20200616_183409_1_2953'; + ts39 = '20200616_183409_2_2214'; + ts40 = '20200619_213706_1_2214'; + ts41 = '20200619_213706_2_1476'; + ts42 = '20200621_100025_1_4429'; + ts43 = '20200622_121135_1_4429'; + ts44 = '20200623_175503_1_4429'; + ts45 = '20200627_132326_1_3691'; + ts46 = '20200627_132326_2_2953'; + ts47 = '20200627_132326_3_2583'; + ts48 = '20200627_132326_4_2214'; + ts49 = '20200703_000710_1_2030'; + ts50 = '20200703_000710_2_1845'; + ts51 = '20200703_000710_3_1661'; + ts52 = '20200703_000710_4_1476'; + ts53 = '20200710_230144_1_1476'; + ts54 = '20200710_230144_2_1292'; + ts55 = '20200716_111111_1_1292'; + ts56 = '20200716_111111_2_1107'; + ts57 = '20200723_011054_1_1107'; + ts58 = '20200723_011054_2_923'; + ts59 = '20200723_011054_3_738'; + if small_ram + tstamp = {ts47 ts48 ts49 ts50 ts51 ts52 ts53 ts54 ts55 ts56 ... + ts57 ts58 ts59}; + nIterID = {1:40 1:29 1:40 1:40 1:40 1:40 1:100 1:21 1:100 1:60 ... + 1:100 1:100 1:3}; + else + tstamp = ... + {ts31 ts32 ts33 ts34 ts35 ts36... + ts37 ts38 ts39 ts40 ts41 ts42 ts43 ts44 ts45 ts46 ... + ts47 ts48 ts49 ts50 ts51 ts52 ts53 ts54 ts55 ts56 ... + ts57 ts58 ts59}; + nIterID = ... + {1:3 1:10 1:10 1:10 1:10 1:5 ... + 1:22 1:40 1:39 1:40 1:2 1:10 1:36 1:100 1:40 1:40 ... + 1:40 1:29 1:40 1:40 1:40 1:40 1:100 1:21 1:100 1:60 ... + 1:100 1:100 1:68}; + end + load([projdir '\simdata_' tstamp{end} '\full_variable_set_'... + tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray = mcmc_get_walkers(tstamp,nIterID, projdir); + +parnames = [... + {'TX_{cat}'} + {'TL_{cat}'} + {'\tau_{atp}'} + {'pol_{Kd, tet}'} + {'rep_{Kd, tet}'} + {'aTc_{Kd}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% plot the trace plot and the posterior (marginal) plot +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false,'plotDistribution', false,... + 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% marray is a # parameters x # walkers x # mcmc samples array. You can +% subset this for plotting, especially when plotting the posterior distribution +%(which needs a lot of ram), like so: +mcmc_plot(marray(:, 1:end,1:100:end), parnames(:),... + 'plotDistribution', true,... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +mvarray = masterVecArray(marray, mai); +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + samplePoints = ceil(size(mvarray, 3) * [1]); + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); +end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% generate the endpoint and trajectory figs +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end +ylims = {[15 5 5 10 15]}; +lengthToPlotArray = [61]; +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount); + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.05, 0.2, 0.9]) + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + subplot(5, 2, (count-1)*2+1) + for dID = 1:length(legends(count, :)) + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + hold on + end + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.35, 0.5]) + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLab = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLims = [0.0625 4 + 2e-06 2 + 0.01 10000 + 0.03125 2 + 0.01 10000]; + doseArray =... + [ 4 2 1 0.5 0.25 0.125 0.0625 + 2 0.2 0.02 0.002 0.0002 2e-05 2e-06 + 10000 1000 100 10 1 0.1 0.01 + 2 1 0.5 0.25 0.125 0.0625 0.03125 + 10000 1000 100 10 1 0.1 0.01]; + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca; + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + hold on + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca; + ax.XScale = 'log'; + ax.XLim = xLims(count, :); + hold on + ax = gca; + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16; + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + end +end diff --git a/generate_paper_figs/Fig5_IFFL_prediction_Cv6.m b/generate_paper_figs/Fig5_IFFL_prediction_Cv6.m new file mode 100644 index 0000000..b2f93b1 --- /dev/null +++ b/generate_paper_figs/Fig5_IFFL_prediction_Cv6.m @@ -0,0 +1,329 @@ +% Generate Incoherent Feed-Forward Loop prediction plots from the paper: +% +% A MATLAB Toolbox for Modeling Genetic Circuits in Cell-Free Systems +% by Vipul Singhal, Zoltan A. Tuza, Zachary S. Sun, and Richard M. Murray +% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Instructions +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 1. Check that the working directory is the one where folders like core, +% components, mcmc_simbio, config etc are. This is the trunk directory. +% 2. Download datasets, and place in the mcmc_simbio/projects directory. +% You need around 800mb +% of free hard disk space to download the full dataset. Download at: +% https://www.dropbox.com/sh/9zn7666ll6fm4po/AAB1nS2Vi3Aej7vmPD-kQBhXa?dl=0 +% and +% https://www.dropbox.com/sh/sycgp5dr2arxop0/AACjd9owdihvQEQpQwdHFb-ya?dl=0 +% 3. Make sure you have 3 GB of free ram. Otherwise, set the flag +% 'small_ram' to true, and you will plot the same things but with only +% 0.8GB of ram needed. This only plots the last few iterations of the MCMC. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Set flags +small_ram = false; +txtl_init +mcmc_init + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% These two datasets must be downloaded from the dropbox links above, and +% placed in the mcmc_simbio/projects directory +trainingEdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v6']; +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_predictionA']; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% the array of parameters with all the fixed parameters and the +% parameters from the training E dataset. +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mIFFL = model_txtl_lastetIFFL; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_predictionA(mIFFL); +di = ZachIFFL_testdata('all_trajectories'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% load simulation data +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +tsIDtouse = 1; +switch tsIDtouse + case 1 + ts31 = '20200612_214710_1_1476'; + ts32 = '20200614_005043_1_1476'; + ts33 = '20200614_005043_2_2214'; + ts34 = '20200614_005043_3_2953'; + ts35 = '20200614_005043_4_3691'; + ts36 = '20200614_005043_5_2953'; + ts37 = '20200615_233435_1_2953'; + ts38 = '20200616_183409_1_2953'; + ts39 = '20200616_183409_2_2214'; + ts40 = '20200619_213706_1_2214'; + ts41 = '20200619_213706_2_1476'; + ts42 = '20200621_100025_1_4429'; + ts43 = '20200622_121135_1_4429'; + ts44 = '20200623_175503_1_4429'; + ts45 = '20200627_132326_1_3691'; + ts46 = '20200627_132326_2_2953'; + ts47 = '20200627_132326_3_2583'; + ts48 = '20200627_132326_4_2214'; + ts49 = '20200703_000710_1_2030'; + ts50 = '20200703_000710_2_1845'; + ts51 = '20200703_000710_3_1661'; + ts52 = '20200703_000710_4_1476'; + ts53 = '20200710_230144_1_1476'; + ts54 = '20200710_230144_2_1292'; + ts55 = '20200716_111111_1_1292'; + ts56 = '20200716_111111_2_1107'; + ts57 = '20200723_011054_1_1107'; + ts58 = '20200723_011054_2_923'; + ts59 = '20200723_011054_3_738'; + if small_ram + tstamp = {ts57 ts58 ts59}; + nIterID = {1:100 1:100 1:3}; + else + tstamp = ... + {ts31 ts32 ts33 ts34 ts35 ts36... + ts37 ts38 ts39 ts40 ts41 ts42 ts43 ts44 ts45 ts46 ... + ts47 ts48 ts49 ts50 ts51 ts52 ts53 ts54 ts55 ts56 ... + ts57 ts58 ts59}; + nIterID = ... + {1:3 1:10 1:10 1:10 1:10 1:5 ... + 1:22 1:40 1:39 1:40 1:2 1:10 1:36 1:100 1:40 1:40 ... + 1:40 1:29 1:40 1:40 1:40 1:40 1:100 1:21 1:100 1:60 ... + 1:100 1:100 1:68}; + end +end + + +tsToSave = '20200525_011005_1_327'; % DO NOT CHANGE. this is where the prediction data is kept. +load([pwd '\mcmc_simbio\projects\proj_ZSIFFL_predictionCv3'... + '\simdata_' tsToSave '\full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'ri'); +data_info = di; % overwrite with new di, with all three trajectories, not just the mean. +mai = mcmc_info.master_info; +marray = mcmc_get_walkers(tstamp,nIterID, trainingEdir); + +% +%% +mvarray = masterVecArray(marray([1:3 5:15], :,:), mai); +for miID = 1:5 %1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + ms = currmi.measuredSpecies; +end +%% +ms = {{'protein deGFP*'}}; +NN = 50; % number of trajectories. +da = cell(NN, 1); +idxnotused = cell(NN, 1); +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + dose = currmi.dosedVals'; + if miID == 2 + dose(end, 1) = 0; + end + [da{miID}, idxnotused{miID}] = simulatecurves(currmi.emo,marrayOrd(:,:)', NN, dose, tv, ms); +end +%% + +% +ylims = {3*[4, 4, 4, 4, 12]}; +lengthToPlotArray = [81]; +for outercount = 1:length(lengthToPlotArray) +% outercount = outercount+1; + lengthToPlot = lengthToPlotArray(outercount); + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.05, 0.2, 0.9]) + miToUse = [1 2 3 4 5]; + titleArray = {'3OC12'; + 'lasR DNA'; + 'aTc'; + 'tetR DNA'; + 'deGFP DNA'}; + + legends = [{'10uM', '1uM', '.1uM', '10nM', '1nM', '.1nM', '0nM'}; + {'2nM', '1nM', '.5nM', '.25nM', '125pM', '62.5pM', '0pM'}; + {'10uM', '1uM', '.1uM', '10nM', '1nM', '0.1nM', '0nM'}; + {'1nM', '.1nM', '.01nM', '1pM', '.1pM', '10fM', '0fM'}; + {'4nM', '2nM', '1nM', '.5nM', '.25nM', '.125nM', '0nM'}]; + ms = currmi.measuredSpecies; + mvarray = masterVecArray(marray([1:3 5:15],:,:), mai); + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + dose = currmi.dosedVals'; + if miToUse(count) == 2 + dose(end, 1) = 0; + end + %[da{count}, idxnotused{count}] = simulatecurves(currmi.emo,marrayOrd(:,:)', 30, dose, tv, ms); + + subplot(5, 2, (count-1)*2+1) + for dID = 1:length(legends(count, :)) + plot(tv(1:lengthToPlot)/60, 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, :, dID),3), 'LineWidth', 1.5, 'Color', colorz(dID+2, :)) + hold on + end + title([titleArray{count} ' varying (Experiment)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*6, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + dID; + plot(tv(1:lengthToPlot)/60, 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3), 'LineWidth', 1.5, 'Color', colorz(dID+2, :)) + hold on + end + title([titleArray{count} ' varying (Prediction)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 13) + legend('boxoff') + + % ylabel('deGFP, nM') + axis([0 (lengthToPlot-1)*6 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + % UNCOMMEENT TO SAVE + % print([saveFinalFigs 'prediction_traj_N' num2str(NN) '_' num2str((lengthToPlot-1)*6) 'min'],'-djpeg') + + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + exp_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + doseArray(1, end) = 0.1/100; % 30c12 + doseArray(2, end) = 0.0625/4; % lasR dna + doseArray(3, end) = 0.1/100; % aTc + doseArray(4, end) = 0.00001/100; % tetR dna + doseArray(5, end) = 0.125/4; % deGFP dna + + + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.35, 0.5]) + + xTickLabels = [{'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'1', '10^{-2}', '10^{-4}', '0'}; + {'4', '1', '2^{-2}', '0'}]; + titleArray = {'3OC12'; + 'lasR DNA'; + 'aTc'; + 'tetR DNA'; + 'deGFP DNA'}; + xLab = {'3OC12, uM'; + 'lasR DNA, nM'; + 'aTc, uM'; + 'tetR DNA, nM'; + 'deGFP DNA, nM'}; + + for count = 1:length(miToUse) + + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + + hold on + if count ==1 + legend('Experiment', 'Prediction', 'Location', 'NorthWest', ... + 'FontSize', 18) + end + + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 18 + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + end + % UNCOMMEENT TO SAVE + %print([saveFinalFigs 'prediction_endpoint_N' num2str(NN) '_' num2str((lengthToPlot-1)*6) 'min'],'-djpeg') +end diff --git a/html/txtl_tutorial.html b/html/txtl_tutorial.html old mode 100644 new mode 100755 index 21f0cf2..61af71c --- a/html/txtl_tutorial.html +++ b/html/txtl_tutorial.html @@ -6,7 +6,7 @@ TXTL Tutorial

TXTL Tutorial

txtl_tutorial.m - basic usage of the TXTL modeling toolbox Vipul Singhal, 28 July 2017

This file contains a simple tutorial of the TXTL modeling toolbox. You will learn about setting up a negative autoregulation circuit, simulating it, plotting the results, creating variations of the circuit, and understanding the object structure of the models.

Contents

Initializing the toolbox

Use this command to add the subdirectories needed to your matlab path. To be run each time you begin a new TXTL toolbox session.

txtl_init;
-

Negative Autoregulation - A simple example

Here we demonstrate the setup of a genetic circuit where a transcription factor represses its own expression.

Set up the standard TXTL tubes These load up the RNAP, Ribosome and degradation enzyme concentrations ``E30VNPRL'' refers to a configuration file

tube1 = txtl_extract('E30VNPRL');
+  

TXTL Tutorial

txtl_tutorial.m - basic usage of the TXTL modeling toolbox

Vipul Singhal, 28 July 2017

This file contains a simple tutorial of the TXTL modeling toolbox. You will learn about setting up a negative autoregulation circuit, simulating it, plotting the results, creating variations of the circuit, and understanding the object structure of the models.

Contents

Initializing the toolbox

Use this command to add the subdirectories needed to your matlab path. To be run each time you begin a new TXTL toolbox session.

txtl_init;
+

Negative Autoregulation - A simple example

Here we demonstrate the setup of a genetic circuit where a transcription factor represses its own expression.

Set up the standard TXTL tubes These load up the RNAP, Ribosome and degradation enzyme concentrations ``E30VNPRL'' refers to a configuration file

tube1 = txtl_extract('E30VNPRL');
 tube2 = txtl_buffer('E30VNPRL');
 
 % Now set up a tube that will contain our DNA
 tube3 = txtl_newtube('gene_expression');
 
 % Define the DNA strands, and all the relevant reactions
-txtl_add_dna(tube3, 'ptet(50)', 'rbs(20)', 'tetR(1200)', 1, 'plasmid');
-txtl_add_dna(tube3, 'ptet(50)', 'rbs(20)', 'deGFP(1000)', 1, 'plasmid');
+txtl_add_dna(tube3, 'ptet(50)', 'utr1(20)', 'tetR(1200)', 1, 'plasmid');
+txtl_add_dna(tube3, 'ptet(50)', 'utr1(20)', 'deGFP(1000)', 1, 'plasmid');
 
 % Mix the contents of the individual tubes
 Mobj = txtl_combine([tube1, tube2, tube3]);
@@ -93,90 +93,28 @@
 toc
 t_ode = simData.Time;
 x_ode = simData.Data;
-
Elapsed time is 1.134961 seconds.
-

plot the result

The following function plots the proteins, RNA and resources in the toolbox. In the next section we delve deeper into the object oriented structure of the model, and how to plot arbitrary species in the model.

txtl_plot(simData,Mobj);
-
Current plot held
-

Model Structure

The model is organized as a model object, with sub objects specifying Parameters, Reactions, Species, etc. Type in

Mobj
-
-   SimBiology Model - mix_of_E30VNPRL_E30VNPRL_gene_expression 
-
-   Model Components:
-     Compartments:      1
-     Events:            2
-     Parameters:        73
-     Reactions:         47
-     Rules:             0
-     Species:           43
+
Error using SimBiology.Model/addparameter
+NAME TX_elong_glob is being used by another SimBiology parameter object. Specify a different NAME. Type 'help SimBiology.Model.addparameter' for more information.
 
-

There is one comaprtment, 2 events, 73 parameters, 47 Reactions, no rules and 43 Species in the toolbox. We can explore further by typing, for example,

Mobj.Species
-
-   SimBiology Species Array
-
-   Index:    Compartment:    Name:                                     InitialAmount:    InitialAmountUnits:
-   1         contents        RNAP                                      100               
-   2         contents        protein sigma70                           35                
-   3         contents        protein sigma28                           20                
-   4         contents        Ribo                                      50                
-   5         contents        RNAP70                                    0                 
-   6         contents        RNase                                     100               
-   7         contents        AGTP                                      3.18005e+06       
-   8         contents        CUTP                                      1.90803e+06       
-   9         contents        AA                                        3.18005e+07       
-   10        contents        protein tetR                              0                 
-   11        contents        aTc                                       0                 
-   12        contents        protein tetRdimer                         0                 
-   13        contents        RNA rbs--tetR                             0                 
-   14        contents        Ribo:RNA rbs--tetR                        0                 
-   15        contents        DNA ptet--rbs--tetR                       1                 
-   16        contents        RNAP70:DNA ptet--rbs--tetR                0                 
-   17        contents        CUTP:AGTP:RNAP70:DNA ptet--rbs--tetR      0                 
-   18        contents        term_RNAP70:DNA ptet--rbs--tetR           0                 
-   19        contents        AA:AGTP:Ribo:RNA rbs--tetR                0                 
-   20        contents        protein deGFP                             0                 
-   21        contents        protein deGFP*                            0                 
-   22        contents        RNA rbs--deGFP                            0                 
-   23        contents        Ribo:RNA rbs--deGFP                       0                 
-   24        contents        DNA ptet--rbs--deGFP                      1                 
-   25        contents        RNAP70:DNA ptet--rbs--deGFP               0                 
-   26        contents        CUTP:AGTP:RNAP70:DNA ptet--rbs--deGFP     0                 
-   27        contents        term_RNAP70:DNA ptet--rbs--deGFP          0                 
-   28        contents        AA:AGTP:Ribo:RNA rbs--deGFP               0                 
-   29        contents        RNAP28                                    0                 
-   30        contents        2 aTc:protein tetRdimer                   0                 
-   31        contents        AGTP:RNAP70:DNA ptet--rbs--tetR           0                 
-   32        contents        CUTP:RNAP70:DNA ptet--rbs--tetR           0                 
-   33        contents        DNA ptet--rbs--tetR:protein tetRdimer     0                 
-   34        contents        RNA rbs--tetR:RNase                       0                 
-   35        contents        AA:AGTP:Ribo:RNA rbs--tetR:RNase          0                 
-   36        contents        Ribo:RNA rbs--tetR:RNase                  0                 
-   37        contents        AGTP:RNAP70:DNA ptet--rbs--deGFP          0                 
-   38        contents        CUTP:RNAP70:DNA ptet--rbs--deGFP          0                 
-   39        contents        DNA ptet--rbs--deGFP:protein tetRdimer    0                 
-   40        contents        RNA rbs--deGFP:RNase                      0                 
-   41        contents        AA:AGTP:Ribo:RNA rbs--deGFP:RNase         0                 
-   42        contents        Ribo:RNA rbs--deGFP:RNase                 0                 
-   43        contents        AGTP_UNUSE                                0                 
+Error in txtl_transcription (line 70)
+    addparameter(tube, 'TX_elong_glob',tube.Userdata.ReactionConfig.Transcription_Rate);
 
-

We see that there are 43 species in the model, and they have somewhat different syntax for specification. Proteins, RNA and DNA generally follow the convention protein CDS, RNA 5'UTR--CDS, DNA promoter--5' UTR--CDS, with variations possible. There are also simply named `core' species like RNAP, Ribo, RNase, etc. Finally we denote bound complexes with a colon, for example, Species 1:Species 2.

We also see that each of them has certain other associated properties. You can explore further by accessing individual species using their index, and using the `get' and `set' commands to get and set the properties of the species. For example, try typing

Mobj.Species(1)
-
-   SimBiology Species Array
+Error in txtl_prom_ptet (line 92)
+    txtl_transcription(mode, tube, dna, rna, RNAP, RNAPbound);
 
-   Index:    Compartment:    Name:    InitialAmount:    InitialAmountUnits:
-   1         contents        RNAP     100               
+Error in txtl_add_dna (line 203)
+        eval(['txtl_prom_' promoterName '(mode, tube, dna, rna, listOfSpecies,prom_spec, utr_spec, cds_spec)']);
 
-

This gives you the first species in the model. You can find out what properties as associated with this species by typing in

get(Mobj.Species(1))
-
            Annotation: ''
-     BoundaryCondition: 0
-        ConstantAmount: 0
-         InitialAmount: 100.0001
-    InitialAmountUnits: ''
-                  Name: 'RNAP'
-                 Notes: ''
-                Parent: [1x1 SimBiology.Compartment]
-                   Tag: ''
-                  Type: 'species'
-              UserData: []
+Error in txtl_runsim (line 161)
+        txtl_add_dna(modelObj, m.DNAinfo{i}{1}, m.DNAinfo{i}{2}, ...
 
+Error in txtl_tutorial (line 45)
+[simData] = txtl_runsim(Mobj,14*60*60);
+

plot the result

The following function plots the proteins, RNA and resources in the toolbox. In the next section we delve deeper into the object oriented structure of the model, and how to plot arbitrary species in the model.

txtl_plot(simData,Mobj);
+

Model Structure

The model is organized as a model object, with sub objects specifying Parameters, Reactions, Species, etc. Type in

Mobj
+

There is one comaprtment, 2 events, 73 parameters, 47 Reactions, no rules and 43 Species in the toolbox. We can explore further by typing, for example,

Mobj.Species
+

We see that there are 43 species in the model, and they have somewhat different syntax for specification. Proteins, RNA and DNA generally follow the convention protein CDS, RNA 5'UTR--CDS, DNA promoter--5' UTR--CDS, with variations possible. There are also simply named `core' species like RNAP, Ribo, RNase, etc. Finally we denote bound complexes with a colon, for example, Species 1:Species 2.

We also see that each of them has certain other associated properties. You can explore further by accessing individual species using their index, and using the `get' and `set' commands to get and set the properties of the species. For example, try typing

Mobj.Species(1)
+

This gives you the first species in the model. You can find out what properties as associated with this species by typing in

get(Mobj.Species(1))
 

and then using the set command to set its initial concentration to 50 units:

set(Mobj.Species(1), 'InitialAmount', 50)
 

Learn more about the get and set commands by typing in

help get
 help set
@@ -186,7 +124,7 @@
 Mobj.Reactions(1).ReactionRate
 Mobj.Reactions(1).KineticLaw
 get(Mobj.Reactions(1).KineticLaw)
-

and so on.

Plotting individual species

You can also plot the trajectories of any of the species in the model. Use the function findspecies to get the index of the species object of interest. For example, if you want to plot the trajectory of the dimerized tetR protein, you could type in

tetRindex = findspecies(Mobj, 'protein tetRdimer');
+

and so on.

Plotting individual species

You can also plot the trajectories of any of the species in the model. Use the function findspecies to get the index of the species object of interest. For example, if you want to plot the trajectory of the dimerized tetR protein, you could type in

tetRindex = findspecies(Mobj, 'protein tetRdimer');
 figure
 plot(simData.Time/3600, simData.data(:,tetRindex));
 title('Dimerized tetR concentration')
@@ -195,10 +133,11 @@
 curraxis = axis;
 axis([curraxis(1:2) 0 curraxis(4)])
 %
-

EMACS editor support (ignore)

Automatically use matlab mode in emacs (keep at end of file) Local variables: mode: matlab End:

+ % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase1.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase1.m new file mode 100755 index 0000000..444b9f2 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase1.m @@ -0,0 +1,466 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_mtet_phase1(mtet) +% Phase 1 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. + +% +% The parameters are shared between these five circuits (experiments). +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + + + + + +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +% !! NEED TO CHECK IF AT THE PICKED POINT THE TRAJECTORIES LOOK OK. + +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 % fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 % fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 % fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19% TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22% fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25% fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 % from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" + + +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] + +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... + aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... + 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + +%% +% Names of parameters and species to actually estimate. +% As mentioned above, I have planned this out in the file +% ZachIFFL_estimation_strategy.txt + +% 'TX_elong_glob' , 'fix' +% 'TL_elong_glob' , 'fix' +% 'AGTPdeg_time' , 'fix' +% 'AGTPreg_ON' , 'fix' +% 'AGTPdeg_rate' , 'fix' +% 'TXTL_PROT_deGFP_MATURATION' , 'fix' +% 'TXTL_UTR_UTR1_Kd' , 'fix' +% 'TXTL_PTET_RNAPbound_Kd' , 'est' +% 'TXTL_PTET_RNAPbound_F' , 'fix' +% 'TXTL_NTP_RNAP_1_Kd' , 'fix' +% 'TXTL_NTP_RNAP_2_Kd' , 'fix' +% 'TXTL_PTET_sequestration_Kd' , 'est' +% 'TXTL_PTET_sequestration_F' , 'est' +% 'TL_AA_Kd' , 'fix' +% 'TL_AGTP_Kd' , 'fix' +% 'TXTL_RNAdeg_Kd' , 'fix' +% 'TXTL_INDUCER_TETR_ATC_Kd' , 'est' +% 'TXTL_INDUCER_TETR_ATC_F' , 'est' +% 'TXTL_DIMER_tetR_Kd' , 'est' +% 'TXTL_DIMER_tetR_F' , 'est' +% 'TXTL_UTR_UTR1_F' , 'fix' +% 'TXTL_PLAC_RNAPbound_Kd' , 'fix' +% 'TXTL_PLAC_RNAPbound_F' , 'fix' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , 'fix' +% 'TXTL_NTP_RNAP_1_F' , 'fix' +% 'TXTL_NTP_RNAP_2_F' , 'fix' +% 'TL_AA_F' , 'fix' +% 'TL_AGTP_F' , 'fix' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , 'fix' +% 'TXTL_RNAdeg_F' , 'fix' +% 'TXTL_RNAdeg_kc' , 'fix' + +% Thus, the 7 estimated parameters are: +% 'TXTL_PTET_RNAPbound_Kd' , 'est' +% 'TXTL_PTET_sequestration_Kd' , 'est' +% 'TXTL_PTET_sequestration_F' , 'est' +% 'TXTL_INDUCER_TETR_ATC_Kd' , 'est' +% 'TXTL_INDUCER_TETR_ATC_F' , 'est' +% 'TXTL_DIMER_tetR_Kd' , 'est' +% 'TXTL_DIMER_tetR_F' , 'est' + + + + +estParamsIX = [7, 11, 12, 16:19]'; +estParams = activeNames(estParamsIX,1); +[estParams num2cell(log(cell2mat(activeNames(estParamsIX,3))))] + +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; + +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo},... + 'modelObj', {mtet1, mtet2, mtet3},... % array of model objects (different topologies) + 'modelName', mtet.name,...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies }, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase1_b.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase1_b.m new file mode 100755 index 0000000..d6d2e7e --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase1_b.m @@ -0,0 +1,401 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_mtet_phase1_b(mtet) +% Phase 1 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. + +% +% The parameters are shared between these five circuits (experiments). +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +% !! NEED TO CHECK IF AT THE PICKED POINT THE TRAJECTORIES LOOK OK. + +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 % fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 % fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(-5) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 % fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(-25) exp(25)] %16 % TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(-25) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19% TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22% fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25% fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 % from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% fixed as a result of mcmc_info_ZSIFFL_mtet_phase1 --> estimated [7, 11, 12, 16:19] +% of these, [7, 12, 17, 19] are fixed, and in this estimation we estimate +% 11, 16, 18. +preFixedParams2 = {... +7 'TXTL_PTET_RNAPbound_Kd' , exp(14) +12 'TXTL_PTET_sequestration_F' , exp(1.314) +17 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) +19 'TXTL_DIMER_tetR_F' , exp(1.447)}; +activeNames(cell2mat(preFixedParams2(:,1)),2) = preFixedParams2(:,3); + +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] + +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... + aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... + 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff + +%% + +estParamsIX = [ 11, 16 18]'; +estParams = activeNames(estParamsIX,1); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; + +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo},... + 'modelObj', {mtet1, mtet2, mtet3},... % array of model objects (different topologies) + 'modelName', mtet.name,...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies }, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase2.m new file mode 100755 index 0000000..9709257 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_mtet_phase2.m @@ -0,0 +1,513 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_mtet_phase2(mtet, mlac) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; + + +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(18)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(15)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(12)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(12)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" + + +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] + +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... + aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... + 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +% Thus, the 10 estimated parameters are: + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% + + +estParamsIX = [1 2 3 7 11 16 21 31 32 33]'; +estParams = activeNames(estParamsIX,1); + +[estParams num2cell(log(cell2mat(activeNames(estParamsIX,3))))] + +activeNames +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionA.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionA.m new file mode 100755 index 0000000..c25aba1 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionA.m @@ -0,0 +1,539 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_predictionA(mIFFL) +% This file is, in some sense, "fake". Essentially we set up an estimation +% problem so we can use all the functions and machinery to generate +% prediction plots. There is no estimation happening here. We will use +% parameters estimated from trainingE, which is also the example this file +% is based on. +% +% There is only one topology in this example: the IFFL. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +oc12info = ['This is the 3OC12 perturbation in the IFFL. \n ']; +lasrinfo = ['This is the pLac-lasR DNA perturbation in the IFFL. \n ']; +atcinfo = ['This is the aTc perturbation in the IFFL. \n ']; +tetrinfo = ['This is the pLas-tetR DNA perturbation in the IFFL. \n ']; +gfpinfo = ['This is the pLas-tetO-deGFP DNA perturbation in the IFFL. \n ']; + + + + + + + + + + + + + +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged so that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimated parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +% add the combinatorial activator knockoff parameter +% 'TXTL_PLAS_TFBIND_Kd', exp(6) +% 'TXTL_PLAS_TFBIND_F', exp(0) % % + +multiplier = 1000000; +plasTFbind_KD = exp(6); +plasTFbind_F = exp(0); +activeNames = [activeNames; + {'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_Kd', 1/(plasTFbind_KD*multiplier) , [exp(-20) exp(20)] + 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F', (plasTFbind_KD*plasTFbind_F*multiplier), [exp(-20) exp(20)]}]; +% reverse rate = 1 +% forward rate / reverse rate = exp(6)*100/exp(0) ~= exp(10.5) = 1/kD => KD +% = exp(-10.6) +% forward rate = exp(10.5) +% + +%% Next, remove the ptet rnap binding and the forward rate reacton parameters. +% these parameters are not present in the model +activeNames = activeNames(setdiff(1:44, [7, 8]), :); + + +%% +estParamsIX = [21 23 28 31 33 37 39 40]'-2; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. +[activeNames(:,1) num2cell(log(cell2mat(activeNames(:, 2))))] +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. +paramMap = (1:42)'; + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + +%% next we define the dosing strategy. +dosedNames = {... + 'OC12HSL'; + 'DNA plac--utr1--lasR'; + 'aTc' + 'DNA plas--utr1--tetR'; + 'DNA plas_ptet--utr1--deGFP';}; + +dosedVals = [... + 1000 1000 1000 1000 1000 1000 1000; + 1 1 1 1 1 1 1; + 10000 , 10000, 10000, 10000, 10000, 10000, 10000; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 1 1 1 1 1 1 1]; +dosedVals1 = dosedVals; +dosedVals1(1, :) = [10000 1000 100 10 1 0.1 0]; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedVals2 = dosedVals; +dosedVals2(2, :) = [2 1 .5 .25 .125 .0625 0]; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedVals3 = dosedVals; +dosedVals3(3, :) = [10000 1000 100 10 1 0.1 0]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedVals4 = dosedVals; +dosedVals4(4, :) = [1 0.1 0.01 0.001 0.0001 0.00001 0]; +dosedVals4(3, :) = [0 0 0 0 0 0 0]; %set aTc to 0 too. +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + +dosedVals5 = dosedVals; +dosedVals5(5, :) = [4 2 1 .5 .25 .125 0]; +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + +% OC12HSL = 1uM +% plac-lasR = 1nM +% plas-tetR = 0.1nM +% plastetO - gfp = 1nM +% aTc = 10uM + +% DNA plac--utr1--lasR +% DNA plas--utr1--tetR +% DNA plas_ptet--utr1--deGFP +% OC12HSL +% aTc + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mIFFL1 = copyobj(mIFFL); +mIFFL2 = copyobj(mIFFL); +mIFFL3 = copyobj(mIFFL); +mIFFL4 = copyobj(mIFFL); +mIFFL5 = copyobj(mIFFL); +model_info = struct(... + 'circuitInfo',{oc12info, lasrinfo, atcinfo, tetrinfo, gfpinfo},... + 'modelObj', {mIFFL1, mIFFL2, mIFFL3, mIFFL4, mIFFL5},... + ... % array of model objects (different topologies) + 'modelName', {mIFFL1.name, mIFFL2.name, mIFFL3.name, mIFFL4.name, mIFFL5.name},... + ...; % model names. + 'namesUnord', {activeNames(paramMap,1),activeNames(paramMap,1),... + activeNames(paramMap,1),activeNames(paramMap,1), activeNames(paramMap,1)},... + ... % names of parameters per model, unordered. + 'paramMaps', {paramMap, paramMap, paramMap, paramMap, paramMap},... + ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames, dosedNames, dosedNames, dosedNames, dosedNames},... + ... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... + ... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies ,... + measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... + ... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1, 2, 3, 4, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionA_F_v4.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionA_F_v4.m new file mode 100644 index 0000000..b767fb8 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionA_F_v4.m @@ -0,0 +1,539 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_predictionA_F_v4(mIFFL) +% This file is, in some sense, "fake". Essentially we set up an estimation +% problem so we can use all the functions and machinery to generate +% prediction plots. There is no estimation happening here. We will use +% parameters estimated from trainingE, which is also the example this file +% is based on. +% +% There is only one topology in this example: the IFFL. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +oc12info = ['This is the 3OC12 perturbation in the IFFL. \n ']; +lasrinfo = ['This is the pLac-lasR DNA perturbation in the IFFL. \n ']; +atcinfo = ['This is the aTc perturbation in the IFFL. \n ']; +tetrinfo = ['This is the pLas-tetR DNA perturbation in the IFFL. \n ']; +gfpinfo = ['This is the pLas-tetO-deGFP DNA perturbation in the IFFL. \n ']; + + + + + + + + + + + + + +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged so that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimated parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +% add the combinatorial activator knockoff parameter +% 'TXTL_PLAS_TFBIND_Kd', exp(6) +% 'TXTL_PLAS_TFBIND_F', exp(0) % % + +multiplier = 1000000; +plasTFbind_KD = exp(6); +plasTFbind_F = exp(0); +activeNames = [activeNames; + {'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_Kd', 1/(plasTFbind_KD*multiplier) , [exp(-20) exp(20)] + 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F', (plasTFbind_KD*plasTFbind_F*multiplier), [exp(-20) exp(20)]}]; +% reverse rate = 1 +% forward rate / reverse rate = exp(6)*100/exp(0) ~= exp(10.5) = 1/kD => KD +% = exp(-10.6) +% forward rate = exp(10.5) +% + +%% Next, remove the ptet rnap binding and the forward rate reacton parameters. +% these parameters are not present in the model +activeNames = activeNames(setdiff(1:44, [7, 8]), :); + + +%% +estParamsIX = [21 23 28 31 33 37 39 40]'-2; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. +[activeNames(:,1) num2cell(log(cell2mat(activeNames(:, 2))))] +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. +paramMap = (1:42)'; + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + +%% next we define the dosing strategy. +dosedNames = {... + 'OC12HSL'; + 'DNA plac--utr1--lasR'; + 'aTc' + 'DNA plas--utr1--tetR'; + 'DNA plas_ptet--utr1--deGFP';}; + +dosedVals = [... + 1000 1000 1000 1000 1000 1000 1000; + 1 1 1 1 1 1 1; + 10000 , 10000, 10000, 10000, 10000, 10000, 10000; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 1 1 1 1 1 1 1]; +dosedVals1 = dosedVals; +dosedVals1(1, :) = [10000 1000 100 10 1 0.1 0]; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedVals2 = dosedVals; +dosedVals2(2, :) = [2 1 .5 .25 .125 .0625 0]; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedVals3 = dosedVals; +dosedVals3(3, :) = [10000 1000 100 10 1 0.1 0]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedVals4 = dosedVals; +dosedVals4(4, :) = [1 0.1 0.01 0.001 0.0001 0.00001 0]; +dosedVals4(3, :) = [0 0 0 0 0 0 0]; %set aTc to 0 too. +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + +dosedVals5 = dosedVals; +dosedVals5(5, :) = [4 2 1 .5 .25 .125 0]; +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + +% OC12HSL = 1uM +% plac-lasR = 1nM +% plas-tetR = 0.1nM +% plastetO - gfp = 1nM +% aTc = 10uM + +% DNA plac--utr1--lasR +% DNA plas--utr1--tetR +% DNA plas_ptet--utr1--deGFP +% OC12HSL +% aTc + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mIFFL1 = copyobj(mIFFL); +mIFFL2 = copyobj(mIFFL); +mIFFL3 = copyobj(mIFFL); +mIFFL4 = copyobj(mIFFL); +mIFFL5 = copyobj(mIFFL); +model_info = struct(... + 'circuitInfo',{oc12info, lasrinfo, atcinfo, tetrinfo, gfpinfo},... + 'modelObj', {mIFFL1, mIFFL2, mIFFL3, mIFFL4, mIFFL5},... + ... % array of model objects (different topologies) + 'modelName', {mIFFL1.name, mIFFL2.name, mIFFL3.name, mIFFL4.name, mIFFL5.name},... + ...; % model names. + 'namesUnord', {activeNames(paramMap,1),activeNames(paramMap,1),... + activeNames(paramMap,1),activeNames(paramMap,1), activeNames(paramMap,1)},... + ... % names of parameters per model, unordered. + 'paramMaps', {paramMap, paramMap, paramMap, paramMap, paramMap},... + ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames, dosedNames, dosedNames, dosedNames, dosedNames},... + ... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... + ... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies ,... + measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... + ... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1, 2, 3, 4, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionCv3.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionCv3.m new file mode 100644 index 0000000..09af04b --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_predictionCv3.m @@ -0,0 +1,532 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_predictionCv3(mIFFL) +% This file is, in some sense, "fake". Essentially we set up an estimation +% problem so we can use all the functions and machinery to generate +% prediction plots. There is no estimation happening here. We will use +% parameters estimated from trainingE, which is also the example this file +% is based on. +% +% There is only one topology in this example: the IFFL. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +oc12info = ['This is the 3OC12 perturbation in the IFFL. \n ']; +lasrinfo = ['This is the pLac-lasR DNA perturbation in the IFFL. \n ']; +atcinfo = ['This is the aTc perturbation in the IFFL. \n ']; +tetrinfo = ['This is the pLas-tetR DNA perturbation in the IFFL. \n ']; +gfpinfo = ['This is the pLas-tetO-deGFP DNA perturbation in the IFFL. \n ']; + + + + + + + + + + + + + +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged so that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimated parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +% add the combinatorial activator knockoff parameter +% 'TXTL_PLAS_TFBIND_Kd', exp(6) +% 'TXTL_PLAS_TFBIND_F', exp(0) % % + +multiplier = 1000000; +plasTFbind_KD = exp(6); +plasTFbind_F = exp(0); +activeNames = [activeNames; + {'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_Kd', 1/(plasTFbind_KD*multiplier) , [exp(-20) exp(20)] + 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F', (plasTFbind_KD*plasTFbind_F*multiplier), [exp(-20) exp(20)]}]; +% reverse rate = 1 +% forward rate / reverse rate = exp(6)*100/exp(0) ~= exp(10.5) = 1/kD => KD +% = exp(-10.6) +% forward rate = exp(10.5) +% + +%% Next, remove the ptet rnap binding and the forward rate reacton parameters. +% these parameters are not present in the model +activeNames = activeNames(setdiff(1:44, [7, 8]), :); + + +%% +% subtract 2 from the indices of any parameters that show up after the two +% deleted parameters. +estParamsIX = [1 2 3 [11 16 21 23 28 31 33 35 37 39 40]-2]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. +[activeNames(:,1) num2cell(log(cell2mat(activeNames(:, 2))))] +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. +paramMap = (1:42)'; + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + +%% next we define the dosing strategy. +dosedNames = {... + 'OC12HSL'; + 'DNA plac--utr1--lasR'; + 'aTc' + 'DNA plas--utr1--tetR'; + 'DNA plas_ptet--utr1--deGFP';}; + +dosedVals = [... + 1000 1000 1000 1000 1000 1000 1000; + 1 1 1 1 1 1 1; + 10000 , 10000, 10000, 10000, 10000, 10000, 10000; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 1 1 1 1 1 1 1]; +dosedVals1 = dosedVals; +dosedVals1(1, :) = [10000 1000 100 10 1 0.1 0]; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedVals2 = dosedVals; +dosedVals2(2, :) = [2 1 .5 .25 .125 .0625 0]; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedVals3 = dosedVals; +dosedVals3(3, :) = [10000 1000 100 10 1 0.1 0]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedVals4 = dosedVals; +dosedVals4(4, :) = [1 0.1 0.01 0.001 0.0001 0.00001 0]; +dosedVals4(3, :) = [0 0 0 0 0 0 0]; %set aTc to 0 too. +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + +dosedVals5 = dosedVals; +dosedVals5(5, :) = [4 2 1 .5 .25 .125 0]; +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + +% OC12HSL = 1uM +% plac-lasR = 1nM +% plas-tetR = 0.1nM +% plastetO - gfp = 1nM +% aTc = 10uM + +% DNA plac--utr1--lasR +% DNA plas--utr1--tetR +% DNA plas_ptet--utr1--deGFP +% OC12HSL +% aTc + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 40; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =2; % actual: 2 - 30 ish, +npoints = 4e2; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 2; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mIFFL1 = copyobj(mIFFL); +mIFFL2 = copyobj(mIFFL); +mIFFL3 = copyobj(mIFFL); +mIFFL4 = copyobj(mIFFL); +mIFFL5 = copyobj(mIFFL); +model_info = struct(... + 'circuitInfo',{oc12info, lasrinfo, atcinfo, tetrinfo, gfpinfo},... + 'modelObj', {mIFFL1, mIFFL2, mIFFL3, mIFFL4, mIFFL5},... % array of model objects (different topologies) + 'modelName', {mIFFL1.name, mIFFL2.name, mIFFL3.name, mIFFL4.name, mIFFL5.name},...; % model names. + 'namesUnord', {activeNames(paramMap,1),activeNames(paramMap,1),activeNames(paramMap,1),activeNames(paramMap,1), activeNames(paramMap,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap, paramMap, paramMap, paramMap, paramMap}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames, dosedNames, dosedNames, dosedNames, dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1, 2, 3, 4, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training.m new file mode 100755 index 0000000..df1f4c4 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training.m @@ -0,0 +1,513 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training(mtet, mlac) +% !! todo -- set the parameters estimated from phase 1 and 2. then this will be +% ready to run. + +% The full estimation problem for the characterization of the IFFL. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In phase 2, we fixed the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimated: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also included the pLac data into the estimation problem, since the +% plac part is involved. +% +% In this final phase, we estimate: +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; + + +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" + + +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] + +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... + aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... + 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +1 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +1 , 'TXTL_PTET_sequestration_Kd' , exp(12) , [exp(3) exp(15)] +1 , 'TXTL_PTET_sequestration_F' , exp(1.5) , [exp(-2) exp(5)] +1 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13) , [exp(0) exp(18)] +1 , 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6) , [exp(-2) exp(5)] +1 , 'TXTL_DIMER_tetR_Kd' , exp(13) , [exp(7) exp(17)] +1 , 'TXTL_DIMER_tetR_F' , exp(2.6) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); + +% Thus, the 10 estimated parameters are: + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% + + +estParamsIX = [1 2 3 7 11 16 21 31 32 33]'; +estParams = activeNames(estParamsIX,1); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + + + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full.m new file mode 100755 index 0000000..443c1c9 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full.m @@ -0,0 +1,550 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_full(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; + + +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(-5) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + + + +estParamsIX = [7 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullB.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullB.m new file mode 100755 index 0000000..5806488 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullB.m @@ -0,0 +1,550 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullB(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; + + +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + + + +estParamsIX = [23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC.m new file mode 100755 index 0000000..fdb68b9 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC.m @@ -0,0 +1,548 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullC(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(7)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(7)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(5) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + + + +estParamsIX = [1 2 7 11 16 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v2.m new file mode 100644 index 0000000..ed2cc52 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v2.m @@ -0,0 +1,589 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullC_v2(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(7)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(7)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(5) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + + +%% set the parameter ranges from training D_v2 + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 25]) + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 25]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([2, 10.5]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([2 10]) + 31, 'RNAP' , exp(6), exp([4 8]) + 33, 'Ribo' , exp(8), exp([2.5 12]) + 37, 'TXTL_PLAS_RNAPbound_Kd' , exp(30), exp([25 40]) + 39, 'TXTL_PLAS_TFBIND_Kd' , exp(7), exp([4 9]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , exp(7), exp([3 12]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +% the parameters fixed after training full C were rep kd = -0.5, atc kd = +% -2, 3OC12kd = 13 + + +fixed_after_training_C = ... + {... + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 11, 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] + 35, 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(18)] %36-1 + }; + +activeNames(cell2mat(fixed_after_training_C(:,1)),2) = fixed_after_training_C(:,3); +activeNames(cell2mat(fixed_after_training_C(:,1)),3) = fixed_after_training_C(:,4); + +estParamsIX = [1 2 7 11 16 21 23 28 31 33 35 37 39 40]'; %relative toD_V2, 11, and 35 are the new ones +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v3.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v3.m new file mode 100644 index 0000000..1314df4 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v3.m @@ -0,0 +1,599 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullC_v3(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(7)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(7)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(5) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + + +%% set the parameter ranges from training D_v2 + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 25]) + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 25]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([2, 10.5]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([2 10]) + 31, 'RNAP' , exp(6), exp([4 8]) + 33, 'Ribo' , exp(8), exp([2.5 12]) + 37, 'TXTL_PLAS_RNAPbound_Kd' ,exp(30), exp([25 40]) + 39, 'TXTL_PLAS_TFBIND_Kd' ,exp(7), exp([4 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' ,exp(7), exp([3 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +% the parameters fixed after training full C were rep kd = -0.5, atc kd = +% -2, 3OC12kd = 13 + + +fixed_after_training_C = ... + {... + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 11, 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] + 35, 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2) ,[exp(5) exp(18)] %36-1 + }; + +activeNames(cell2mat(fixed_after_training_C(:,1)),2) = fixed_after_training_C(:,3); +activeNames(cell2mat(fixed_after_training_C(:,1)),3) = fixed_after_training_C(:,4); + +%% +agtp_time = ... + {... + 3, 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(11)] %3 from est params above + }; + +activeNames(cell2mat(agtp_time(:,1)),2) = agtp_time(:,3); +activeNames(cell2mat(agtp_time(:,1)),3) = agtp_time(:,4); + +%% +estParamsIX = [1 2 3 7 11 16 21 23 28 31 33 35 37 39 40]'; %relative toD_V2, 11, and 35 are the new ones +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v4.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v4.m new file mode 100644 index 0000000..85ebf4b --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v4.m @@ -0,0 +1,596 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullC_v4(mtet, mlac, mlas) +% Expanded from v3. mainly the lasR and tf kd limits. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(7)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(7)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(5) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + + +%% set the parameter ranges from training D_v2 + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 28]) + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 28]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([2, 15]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([2 15]) + 31, 'RNAP' , exp(6), exp([4 12]) + 33, 'Ribo' , exp(8), exp([2.5 15]) + 37, 'TXTL_PLAS_RNAPbound_Kd' ,exp(30), exp([22 42]) + 39, 'TXTL_PLAS_TFBIND_Kd' ,exp(7), exp([0 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' ,exp(7), exp([0 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +% the parameters fixed after training full C were rep kd = -0.5, atc kd = +% -2, 3OC12kd = 13 + + +fixed_after_training_C = ... + {... + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 11, 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] + 35, 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2) ,[exp(5) exp(18)] %36-1 + }; + +activeNames(cell2mat(fixed_after_training_C(:,1)),2) = fixed_after_training_C(:,3); +activeNames(cell2mat(fixed_after_training_C(:,1)),3) = fixed_after_training_C(:,4); + +%% +agtp_time = ... + {... + 3, 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(11)] %3 from est params above + }; + +activeNames(cell2mat(agtp_time(:,1)),2) = agtp_time(:,3); +activeNames(cell2mat(agtp_time(:,1)),3) = agtp_time(:,4); + +%% +estParamsIX = [1 2 3 7 11 16 21 23 28 31 33 35 37 39 40]'; %relative toD_V2, 11, and 35 are the new ones +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v5.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v5.m new file mode 100644 index 0000000..707a965 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v5.m @@ -0,0 +1,596 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullC_v5(mtet, mlac, mlas) +% Expanded from v3. mainly the lasR and tf kd limits. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(7)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(7)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(5) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + + +%% set the parameter ranges from training D_v2 + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 28]) + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 28]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([0, 20]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([0 20]) + 31, 'RNAP' , exp(6), exp([4 12]) + 33, 'Ribo' , exp(8), exp([2.5 18]) + 37, 'TXTL_PLAS_RNAPbound_Kd' ,exp(30), exp([20 45]) + 39, 'TXTL_PLAS_TFBIND_Kd' ,exp(7), exp([0 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' ,exp(7), exp([0 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +% the parameters fixed after training full C were rep kd = -0.5, atc kd = +% -2, 3OC12kd = 13 + + +fixed_after_training_C = ... + {... + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(3)] + 11, 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] + 35, 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2) ,[exp(0) exp(18)] %36-1 + }; + +activeNames(cell2mat(fixed_after_training_C(:,1)),2) = fixed_after_training_C(:,3); +activeNames(cell2mat(fixed_after_training_C(:,1)),3) = fixed_after_training_C(:,4); + +%% +agtp_time = ... + {... + 3, 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(11)] %3 from est params above + }; + +activeNames(cell2mat(agtp_time(:,1)),2) = agtp_time(:,3); +activeNames(cell2mat(agtp_time(:,1)),3) = agtp_time(:,4); + +%% +estParamsIX = [1 2 3 7 11 16 21 23 28 31 33 35 37 39 40]'; %relative toD_V2, 11, and 35 are the new ones +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v6.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v6.m new file mode 100644 index 0000000..dffd1a9 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullC_v6.m @@ -0,0 +1,596 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullC_v6(mtet, mlac, mlas) +% Expanded from v3. mainly the lasR and tf kd limits. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(7)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(7)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(5) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + + +%% set the parameter ranges from training D_v2 + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 28]) + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 28]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([0, 20]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([0 20]) + 31, 'RNAP' , exp(6), exp([4 12]) + 33, 'Ribo' , exp(8), exp([2.5 18]) + 37, 'TXTL_PLAS_RNAPbound_Kd' ,exp(30), exp([20 45]) + 39, 'TXTL_PLAS_TFBIND_Kd' ,exp(7), exp([0 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' ,exp(7), exp([0 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +% the parameters fixed after training full C were rep kd = -0.5, atc kd = +% -2, 3OC12kd = 13 + + +fixed_after_training_C = ... + {... + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(3)] + 11, 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] + 35, 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2) ,[exp(-10) exp(18)] %36-1 + }; + +activeNames(cell2mat(fixed_after_training_C(:,1)),2) = fixed_after_training_C(:,3); +activeNames(cell2mat(fixed_after_training_C(:,1)),3) = fixed_after_training_C(:,4); + +%% +agtp_time = ... + {... + 3, 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(11)] %3 from est params above + }; + +activeNames(cell2mat(agtp_time(:,1)),2) = agtp_time(:,3); +activeNames(cell2mat(agtp_time(:,1)),3) = agtp_time(:,4); + +%% +estParamsIX = [1 2 3 7 11 16 21 23 28 31 33 35 37 39 40]'; %relative toD_V2, 11, and 35 are the new ones +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD.m new file mode 100755 index 0000000..b51fcc7 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD.m @@ -0,0 +1,557 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullD(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + + +estParamsIX = [1 2 7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD_v2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD_v2.m new file mode 100644 index 0000000..8cfa12b --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD_v2.m @@ -0,0 +1,582 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullD_v2(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); +%% + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 25]) + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 25]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([2, 10.5]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([2 10]) + 31, 'RNAP' , exp(6), exp([4 8]) + 33, 'Ribo' , exp(8), exp([2.5 12]) + 37, 'TXTL_PLAS_RNAPbound_Kd' , exp(30), exp([25 40]) + 39, 'TXTL_PLAS_TFBIND_Kd' , exp(7), exp([4 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , exp(7), exp([3 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +estParamsIX = [1 2 7 16 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD_v3.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD_v3.m new file mode 100644 index 0000000..982e262 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullD_v3.m @@ -0,0 +1,582 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullD_v2(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); +%% + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 25]) + 16, 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-10) exp(3)] + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 25]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([2, 10.5]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([2 10]) + 31, 'RNAP' , exp(6), exp([4 8]) + 33, 'Ribo' , exp(8), exp([2.5 12]) + 37, 'TXTL_PLAS_RNAPbound_Kd' , exp(30), exp([25 40]) + 39, 'TXTL_PLAS_TFBIND_Kd' , exp(7), exp([4 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , exp(7), exp([3 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +estParamsIX = [1 2 7 16 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullE.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullE.m new file mode 100755 index 0000000..c0ce12b --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullE.m @@ -0,0 +1,566 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullE(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + + + +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullE_v2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullE_v2.m new file mode 100644 index 0000000..8928cec --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullE_v2.m @@ -0,0 +1,573 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullE_v2(mtet, mlac, mlas) +% See evernote note 045 May 2020 IFFL prediction issues +% for an explanaton. Basically identical to training E , with the exception +% that the tau parameters is fixed to 9.7 instead of 10.1. this means that +% the deg time is 4.6 h instead of 6.7 hours. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +trainingEv2_params = ... +{... +3 , 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(12)] %3 from est params above +}; +activeNames(cell2mat(trainingEv2_params(:,1)),2) = trainingEv2_params(:,3); +activeNames(cell2mat(trainingEv2_params(:,1)),3) = trainingEv2_params(:,4); + + + +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF.m new file mode 100644 index 0000000..5925b26 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF.m @@ -0,0 +1,602 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullF(mtet, mlac, mlas) +% Same as training E, but with better parameter search ranges. +% This uses Distribution C defined in the evernote note 050 MAR 2020 parameter csv setting notes +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. + +% This is the set of parameter values from the "%% FINALLY USED VALUES +% SECTION %%%%%" in the file analysis_vnprl_F2.m + +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +%% Here, we set all the parameters from the "distribution C" in +% the evernote note 050 MAR 2020 parameter csv setting notes +% Thing we will set is the parameter ranges from distribution C. + +original_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , 2.4155e+07, [ 3.269e+06 7.2005e+10] + 21, 'TXTL_PLAC_RNAPbound_Kd' , 36316, [ 148.41 7.2005e+10] + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', 78.241, [ 1 1.6275e+05] + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', 16.993, [ 1 1.6275e+05] + 31, 'RNAP' , 365.04, [ 2.7183 3.269e+06] + 33, 'Ribo' , 365.04, [ 2.7183 3.269e+06] + 37, 'TXTL_PLAS_RNAPbound_Kd' , 1.0686e+13, [7.2005e+10 2.3539e+17] + 39, 'TXTL_PLAS_TFBIND_Kd' , 148.41, [ 1 22026] + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , 2981, [ 1 3.269e+06] + }; + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 25]) + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 25]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([2, 10.5]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([2 10]) + 31, 'RNAP' , exp(6), exp([4 8]) + 33, 'Ribo' , exp(8), exp([2.5 12]) + 37, 'TXTL_PLAS_RNAPbound_Kd' , exp(30), exp([25 40]) + 39, 'TXTL_PLAS_TFBIND_Kd' , exp(7), exp([4 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , exp(7), exp([3 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +%% + +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v2.m new file mode 100644 index 0000000..589f2b8 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v2.m @@ -0,0 +1,602 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullF_v2(mtet, mlac, mlas) +% Same as training E, but with better parameter search ranges. +% This uses Distribution C defined in the evernote note 050 MAR 2020 parameter csv setting notes +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. + +% This is the set of parameter values from the "%% FINALLY USED VALUES +% SECTION %%%%%" in the file analysis_vnprl_F2.m + +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +%% Here, we set all the parameters from the "distribution C" in +% the evernote note 050 MAR 2020 parameter csv setting notes +% Thing we will set is the parameter ranges from distribution C. + +original_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , 2.4155e+07, [ 3.269e+06 7.2005e+10] + 21, 'TXTL_PLAC_RNAPbound_Kd' , 36316, [ 148.41 7.2005e+10] + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', 78.241, [ 1 1.6275e+05] + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', 16.993, [ 1 1.6275e+05] + 31, 'RNAP' , 365.04, [ 2.7183 3.269e+06] + 33, 'Ribo' , 365.04, [ 2.7183 3.269e+06] + 37, 'TXTL_PLAS_RNAPbound_Kd' , 1.0686e+13, [7.2005e+10 2.3539e+17] + 39, 'TXTL_PLAS_TFBIND_Kd' , 148.41, [ 1 22026] + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , 2981, [ 1 3.269e+06] + }; + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 25]) + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 25]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([2, 10.5]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([2 10]) + 31, 'RNAP' , exp(6), exp([4 8]) + 33, 'Ribo' , exp(8), exp([2.5 12]) + 37, 'TXTL_PLAS_RNAPbound_Kd' , exp(30), exp([25 40]) + 39, 'TXTL_PLAS_TFBIND_Kd' , exp(7), exp([4 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , exp(7), exp([3 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +%% + +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v3.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v3.m new file mode 100644 index 0000000..00f0faa --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v3.m @@ -0,0 +1,600 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullF_v3(mtet, mlac, mlas) +% %relative to v2, increase the pol limit a bit. +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. + +% This is the set of parameter values from the "%% FINALLY USED VALUES +% SECTION %%%%%" in the file analysis_vnprl_F2.m + +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +%% Here, we set all the parameters from the "distribution C" in +% the evernote note 050 MAR 2020 parameter csv setting notes +% Thing we will set is the parameter ranges from distribution C. + +original_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , 2.4155e+07, [ 3.269e+06 7.2005e+10] + 21, 'TXTL_PLAC_RNAPbound_Kd' , 36316, [ 148.41 7.2005e+10] + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', 78.241, [ 1 1.6275e+05] + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', 16.993, [ 1 1.6275e+05] + 31, 'RNAP' , 365.04, [ 2.7183 3.269e+06] + 33, 'Ribo' , 365.04, [ 2.7183 3.269e+06] + 37, 'TXTL_PLAS_RNAPbound_Kd' , 1.0686e+13, [7.2005e+10 2.3539e+17] + 39, 'TXTL_PLAS_TFBIND_Kd' , 148.41, [ 1 22026] + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , 2981, [ 1 3.269e+06] + }; + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([17, 25]) + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([17, 25]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([2, 10.5]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([2 10]) + 31, 'RNAP' , exp(6), exp([4 12]) + 33, 'Ribo' , exp(8), exp([2.5 12]) + 37, 'TXTL_PLAS_RNAPbound_Kd' , exp(30), exp([25 40]) + 39, 'TXTL_PLAS_TFBIND_Kd' , exp(7), exp([4 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , exp(7), exp([3 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +%% + +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v4.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v4.m new file mode 100644 index 0000000..9faf145 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v4.m @@ -0,0 +1,600 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullF_v4(mtet, mlac, mlas) +% %relative to v2, increase the pol limit a bit. +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. + +% This is the set of parameter values from the "%% FINALLY USED VALUES +% SECTION %%%%%" in the file analysis_vnprl_F2.m + +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +%% Here, we set all the parameters from the "distribution C" in +% the evernote note 050 MAR 2020 parameter csv setting notes +% Thing we will set is the parameter ranges from distribution C. + +original_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , 2.4155e+07, [ 3.269e+06 7.2005e+10] + 21, 'TXTL_PLAC_RNAPbound_Kd' , 36316, [ 148.41 7.2005e+10] + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', 78.241, [ 1 1.6275e+05] + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', 16.993, [ 1 1.6275e+05] + 31, 'RNAP' , 365.04, [ 2.7183 3.269e+06] + 33, 'Ribo' , 365.04, [ 2.7183 3.269e+06] + 37, 'TXTL_PLAS_RNAPbound_Kd' , 1.0686e+13, [7.2005e+10 2.3539e+17] + 39, 'TXTL_PLAS_TFBIND_Kd' , 148.41, [ 1 22026] + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , 2981, [ 1 3.269e+06] + }; + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([18, 28]) + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([18, 28]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([1, 12]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([5 14]) + 31, 'RNAP' , exp(6), exp([5 12]) + 33, 'Ribo' , exp(8), exp([4 14]) + 37, 'TXTL_PLAS_RNAPbound_Kd' , exp(30), exp([22 42]) + 39, 'TXTL_PLAS_TFBIND_Kd' , exp(7), exp([0 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , exp(7), exp([0 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +%% + +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v5.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v5.m new file mode 100644 index 0000000..1b502eb --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_fullF_v5.m @@ -0,0 +1,600 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_fullF_v5(mtet, mlac, mlas) +% %relative to v2, increase the pol limit a bit. +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. + +% This is the set of parameter values from the "%% FINALLY USED VALUES +% SECTION %%%%%" in the file analysis_vnprl_F2.m + +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(9.7) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. + +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); + +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); + +%% Here, we set all the parameters from the "distribution C" in +% the evernote note 050 MAR 2020 parameter csv setting notes +% Thing we will set is the parameter ranges from distribution C. + +original_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , 2.4155e+07, [ 3.269e+06 7.2005e+10] + 21, 'TXTL_PLAC_RNAPbound_Kd' , 36316, [ 148.41 7.2005e+10] + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', 78.241, [ 1 1.6275e+05] + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', 16.993, [ 1 1.6275e+05] + 31, 'RNAP' , 365.04, [ 2.7183 3.269e+06] + 33, 'Ribo' , 365.04, [ 2.7183 3.269e+06] + 37, 'TXTL_PLAS_RNAPbound_Kd' , 1.0686e+13, [7.2005e+10 2.3539e+17] + 39, 'TXTL_PLAS_TFBIND_Kd' , 148.41, [ 1 22026] + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , 2981, [ 1 3.269e+06] + }; + +new_estimated_params = ... + {... + 7, 'TXTL_PTET_RNAPbound_Kd' , exp(20), exp([18, 28]) + 21, 'TXTL_PLAC_RNAPbound_Kd' , exp(20), exp([18, 28]) + 23, 'TXTL_RNAPBOUND_TERMINATION_RATE', exp(7), exp([1, 16]) + 28, 'TXTL_RIBOBOUND_TERMINATION_RATE', exp(7), exp([5 16]) + 31, 'RNAP' , exp(6), exp([5 16]) + 33, 'Ribo' , exp(8), exp([4 16]) + 37, 'TXTL_PLAS_RNAPbound_Kd' , exp(30), exp([22 45]) + 39, 'TXTL_PLAS_TFBIND_Kd' , exp(7), exp([0 20]) + 40, 'TXTL_PLAS_TFRNAPbound_Kd' , exp(7), exp([0 20]) + }; + +activeNames(cell2mat(new_estimated_params(:,1)),2) = new_estimated_params(:,3); +activeNames(cell2mat(new_estimated_params(:,1)),3) = new_estimated_params(:,4); + +%% +%% + +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full_2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full_2.m new file mode 100755 index 0000000..cc57496 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full_2.m @@ -0,0 +1,556 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_full_2(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; + + +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 + 'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 + 'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 + 'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]}%43-1 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_training_full.m +%% DO THIS!!!! +% % The values estimated are: +% mtet_phase2_params = ... +% {... +% 1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] % 1 from est params above +% 2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] % 2 from est params above +% 3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] % 3 from est params above +% 31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] % 31 from est params above +% 32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] % 32 from est params above +% 33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] % 33 from est params above +% 21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] % 21 from est params above +% 7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +% 11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +% 16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +% }; +% activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +% activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% +estParamsIX = [7 21 31 33 35:42]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full_play.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full_play.m new file mode 100755 index 0000000..f6c350d --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_ZSIFFL_training_full_play.m @@ -0,0 +1,548 @@ +function [mcmc_info, varargout] = mcmc_info_ZSIFFL_training_full_play(mtet, mlac, mlas) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +forwardoffset = 4 +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; + +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; + +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; + +placinfo = ['This is the plac constitutive expression circuit. \n ']; + +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. + + +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% + +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. + +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. + +% parameters of the master vector we fix and estimate + +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 131 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 + + +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... + 2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 + 8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 + -10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 + 13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 + 2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 + 15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 + 0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 + 1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 + 8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 + 3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 + 8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 + 2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 + 3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; + +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; + +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, + 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above + 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above + 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above + 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 + 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above + 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above + 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE + 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 + 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE + 'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE + 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above + 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE + 'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE + 'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE + 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 + 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above + 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above + 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 + 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 + 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 + 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 + 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above + 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 + 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above + 'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above + 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above + 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above + 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 + 'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 + 'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 + 'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 + 'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 pol_{F,las} + 'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 plas_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 plas-pol_{tf, Kd} < + 'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} + 'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]}%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); + +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. + +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); + +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 148 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' + + +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); + +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m + +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); + +%% finally, we set some parameters to try to raise the ceiling of the gene expression. +% this is to make the values match for the 3OC12HSL training data. +explore_params = ... +{... +23 , 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8+forwardoffset), [exp(-3) exp(12)] +28 , 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3 +forwardoffset), [exp(-3) exp(12)] +1 , 'TX_elong_glob' , exp(2.6 ), [exp(0) exp(5 +forwardoffset)] +2 , 'TL_elong_glob' , exp(3.5), [exp(0) exp(6 +forwardoffset)]}; +activeNames(cell2mat(explore_params(:,1)),2) = explore_params(:,3); +activeNames(cell2mat(explore_params(:,1)),3) = explore_params(:,4); + +%% + +estParamsIX = [7 21 23 28 31 33 35:42]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); + +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. + +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. + +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; + +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 + + +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))); + + +%% next we define the dosing strategy. + +dosedNames1 = {'DNA ptet--utr1--deGFP'}; +dosedVals1 = [4 2 1 0.5 0.25 0.125 0.0625]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = ones(1,size(dosedVals1,2)); %dtempvec/(sum(dtempvec)); + +dosedNames2 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'}; +dosedVals2 = [1 1 1 1 1 1 1; + 2 0.2 0.02 0.002 0.0002 0.00002 0.000002]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = ones(1,size(dosedVals2,2)); %dtempvec/(sum(dtempvec)); + +dosedNames3 = {'DNA ptet--utr1--deGFP'; + 'DNA plac--utr1--tetR'; + 'aTc'}; +dosedVals3 = [1 1 1 1 1 1 1; + 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1; + 10000 1000 100 10 1 0.1 0.01]; +doseWeights3 = ones(1,size(dosedVals3,2)); %dtempvec/(sum(dtempvec)); + +dosedNames4 = {'DNA plac--utr1--deGFP'}; +dosedVals4 = [2 1 0.5 0.25 0.125 0.0625 0.0313]; + +doseWeights4 = ones(1,size(dosedVals4,2)); %dtempvec/(sum(dtempvec)); + + +dosedNames5 = {... + 'DNA plac--utr1--lasR'; + 'DNA plas--utr1--deGFP'; + 'OC12HSL'}; +dosedVals5 = [1 1 1 1 1 1 1; + 1 1 1 1 1 1 1; + 10000 , 1000, 100, 10, 1, 0.1, 0.01]; + +doseWeights5 = ones(1,size(dosedVals5,2)); %dtempvec/(sum(dtempvec)); + + + + +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 1; % this is the index of the measured species in the data array + + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 30; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 1.1 to 4 ish +niter =3; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +mtet1 = copyobj(mtet); +mtet2 = copyobj(mtet); +mtet3 = copyobj(mtet); +model_info = struct(... + 'circuitInfo',{ptetinfo, tetrinfo, atcinfo, placinfo, plasinfo},... + 'modelObj', {mtet1, mtet2, mtet3, mlac, mlas},... % array of model objects (different topologies) + 'modelName', {mtet1.name, mtet2.name, mtet3.name, mlac.name, mlas.name},...; % model names. + 'namesUnord', {activeNames(paramMap_ptet,1),activeNames(paramMap_tetR,1),activeNames(paramMap_aTc,1),activeNames(paramMap_plac,1), activeNames(paramMap_plas,1)},... % names of parameters per model, unordered. + 'paramMaps', {paramMap_ptet, paramMap_tetR, paramMap_aTc, paramMap_plac, paramMap_plas}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2, dosedNames3, dosedNames4, dosedNames5},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2, dosedVals3, dosedVals4, dosedVals5},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2, doseWeights3, doseWeights4, doseWeights5}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies, measuredSpecies, measuredSpecies , measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx, msIx,msIx, msIx, msIx},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 1, 1, 1, 1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1,3,4, 2, 5}); % each dataToMapTo property within an element of the +% model_info array is a vector of length # of geometries. +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR +% a cell array of vectors specifying parameter +% groupings. +% The vectors contain indices to the +% parameters in (non fixed subset of) the master +% vector that need to be grouped. +% I.e., They contain indexes of the subvector +% logp = +% master_info.mastervector(~master_info.fixedParams) +% and to the rows of the paramRanges matrix and the +% estNames cell array of strings. +% +% parameter grouping so that these parameters +% get INITIALIZED to the same values. +% +% every parameter index must show up in at least +% one group, even if that is the only parameter in +% that group. If the semanticGroups field is empty, +% then all parameters are assumed to be in their +% distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 2 + varargout{1} = activeNames; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3i.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3i.m new file mode 100755 index 0000000..ca65b67 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3i.m @@ -0,0 +1,201 @@ +function mcmc_info = mcmc_info_constgfp3i(modelObj) +% mcmc_info_constgfp3i.m +% This file contains information on how to set up a constitutive GFP +% experiment using the Simbiology model generated by the function +% model_protein3. It is the simplest possible example of the parameter inference +% problem, and does not utilize the concurrent parameter inference capabilities +% of mcmc_simbio. It has a single variant (geometry) of a single model +% (topology), and a simple set of parameters to be estimated. It is to be +% used with the project files proj_mcmc_tutorial.m and +% proj_protein_constgfp3i.m. +% +% The model to be used is set up by the file model_protein3.m in the +% models_and_supporting_files directory, and has equations +% +% % dG + pol <-> dG_pol (kf, kr) +% dG_pol -> dG + pol + pG (kc) +% +% where dG is the GFP protein DNA, pol is a species signifying the +% transcription and translation machinery, and pG is the GFP protein output +% of the model. +% +% In the experiment, the initial dG concentration is set to different +% values (10, 30 and 60). I.e., the dosedNames in mcmc_info.model_info +% has a single species 'dG' in it, and the dosedVals is the row vector +% [10 30 60]. For each dose, the corresponding pG trajectories are +% measured. In the parameter inference problem, these simulated model +% trajectories are compared to artificial 'data' trajectories obtained from +% simulating the model. +% +% We fix kf to 5, and estimate the rest of the parameters. +% +% Type help mcmc_info to read more about the mcmc_info struct array. + +%% Start here. +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [' dG + pol <-> dG_pol (kf, kr \n'... ) + 'dG_pol -> dG + pol + ppG (kc)\n'... + 'single topology, single geometry.']; + +rkfdG = 5; % rate of kfdG, in nM-1 . s-1 +rkrdG = 300; % rate of krdG, in s-1 +rkc = 0.012; %rate of kc, in s-1 +cpol = 100; % concentration of pol, in nM + +% names of the parameters and species in the model whose values are to be +% set by the values in the master vector. Since there is only one topology +% and geometry, the master vector also only has four entries. +activeNames = ... + {'kfdG' + 'krdG' + 'kcp' + 'pol'}; + +% The value of kfdG will be fixed, so only three params and species get +% estimated. Thus, the MCMC algorithm only searches a 3D space. +estParams = {'krdG' + 'kcp' + 'pol'}; + +% The master vector is a vector of parameter values that is to be +% distributed to the model-experiment pairs. Here, since there is only one +% topology-geometry pair, it matches the activeNames array above. In +% general the master vector will collect the full set of parameters and +% species that are to be set across all the topologies and geometries (both +% as fixed and to-be-estimated values) +masterVector = log([rkfdG + rkrdG + rkc + cpol]); + +% The fixedParams vector sets the index of the parameters in the +% masterVector that stay constant withing the MCMC estimation problem. This +% value within the master vector must be set to the actual value it will +% need to be in all the simulations. (All other values within the master +% vector can be arbitrary because they will be set to various proposed values +% during the estimation procedure) +fixedParams = [1]; + +% The estParamsIx array contains the indices of the parameters that are to +% be estimated in the model. The line below will always be the same, since +% the fixedParams and the estParamsIx form a partition of the indices of +% masterVector. +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% The paramMap array here is simply a column vector of the same length as +% the masterVector. In general, for each unique model topology, there will +% be one paramMap. Please type help mcmc_info in the command line to learn +% more about specifying the paramMaps array. See, for example, +% mcmc_info_constgfp3tetR1.m for an example of a multiple topology +% estimation problem. +paramMap = (1:length(masterVector))'; + +% The paramRanges array is an array of size length(estParamsIx) x 2, and +% contains the upper and lower bounds for each parameter to be estimated. +% We note that the parameters in masterVector are log transformed, and +% therefore, so are the bounds. Here we pick a range of parameter values that are +% +- 3 away from the nominal parameter values in the masterVector. +paramRanges = [masterVector(estParamsIx)-3 masterVector(estParamsIx)+3]; + +% The dataIndices array specifies which dataset within the data_info struct +% each geometry within the given topology points to. Since we only have one +% topology-geometry pair, and we will be generating data specifically for +% this +dataIndices = 1; + +%% next we define the dosing strategy. +dosedNames = {'dG'}; % name string of the species to be dosed. +dosedVals = [10 30 60]; % values that species is to take. + +measuredSpecies = {{'pG'}}; % species to be measured. Note the double cell. +msIx = 1; % column index of the data_info.dataArray array that +% corresponds to the measured species. + + +%% setup the MCMC simulation parameters + +stdev = 10; % the standard deviation in the likelihood function. + +tightening = 1; % See mcmc_info for more info. + +nW =200; % number of walkers. good values: 200 - 400 ish + +stepsize = 1.1; % MCMC step size. try: 1.1 to 4 ish. DO NOT USE 1. + +niter = 10; % actual: 2 - 50 ish. Number of times to loop the MCMC. See mcmc_info + +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) + +thinning = 10; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + +%% ignore this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3ii.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3ii.m new file mode 100755 index 0000000..fdedf45 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3ii.m @@ -0,0 +1,226 @@ +function mcmc_info = mcmc_info_constgfp3ii(modelObj) +% mcmc_info_constgfp3ii.m +% This file contains information on how to set up a constitutive GFP +% experiment using the Simbiology model generated by the function +% model_protein3. It is a simple example of the concurrent +% parameter inference problem, which involves a single circuit (i.e., one +% topology) being run in two different environments. Thus, the two models +% (one in each environment) should have different values estimated for the +% environment specific parameters, but the same value for the circuit +% specific parameters. In this sense, we have two geometries (type +% help mcmc_info in the command window for more information on topologies +% and geometries).that jointly estimate the circuit specific parameters +% but estimate individual values for the environment specific parameters +% between the two geometries. The mcmc_info struct generated by this file +% is to be used with the following project files: +% +% proj_protein_constgfp3ii.m +% proj_protein_constgfp3ii_function.m +% proj_mcmc_tutorial_II.m +% +% +% The model to be used is set up by the file model_protein3.m in the +% models_and_supporting_files directory, and has equations +% +% % dG + pol <-> dG_pol (kf, kr) +% dG_pol -> dG + pol + pG (kc) +% +% where dG is the GFP protein DNA, pol is a species signifying the +% transcription and translation machinery, and pG is the GFP protein output +% of the model. +% +% In the experiment, the initial dG concentration is set to different +% values (10, 30 and 60). I.e., the dosedNames in mcmc_info.model_info +% has a single species 'dG' in it, and the dosedVals is the row vector +% [10 30 60]. For each dose, the corresponding pG trajectories are +% measured. In the parameter inference problem, these simulated model +% trajectories are compared to artificial 'data' trajectories obtained from +% simulating the model. +% +% We fix kf to 5, and estimate the rest of the parameters. The circuit (i.e. +% part) specific parameter is kr, and this gets jointly estimated between the +% two models (one model in each environment) and the environment specific +% parameters are the initial concentration of pol, and the rate kc, and +% each environment has its own value for these. Thus, there are six +% parameters in the master vector, (kf, kr, kc1, kc2, pol1, pol2), of which +% the first is fixed at a value of 5, and the remaining five are to be +% estimated. Also, the first two parameters (kf and kr) are to be shared +% between the two topologies, while the remaining 4 are to be applied to +% individual topologies as defined by the paramMaps in the code below. +% +% Type help mcmc_info to read more about the mcmc_info struct array. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [' D + pol <-> D__pol (k_f, k_r \n'... ) + 'D__pol -> D + pol + protien (kc)\n'... + 'single topology, two geometries.']; + +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkcp1 = 0.012; %s-1 +rkcp2 = 0.024; %s-1 +cpol1 = 100; % nM +cpol2 = 200; % nM + +namesUnord = ... + {'kfdG' + 'krdG' + 'kcp' + 'pol'}; + +estParams = {'krdG' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% fixedParams vector +fixedParams = [1]; % just the rkfdG parameter is fixed + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% There are two geometries for this topology, and so two columns in the +% paramMaps field of the model_info struct. +paramMap1 = [1 2 3 5]'; +paramMap2 = [1 2 4 6]'; +paramMap = [paramMap1 paramMap2]; + +% log transformed parameter ranges +paramRanges = [masterVector(estParamsIx)-3 masterVector(estParamsIx)+3]; + +% The two geometries map to the first and second elements of the data_info +% struct array. +dataIndices = [1 2]; + +%% next we define the dosing strategy. +dosedNames = {'dG'}; +dosedVals = [10 30 60]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 400; % the standard deviation in the likelihood function. + +tightening = 1; % default is 1. Type in help mcmc_info for more information + +nW = 1200; % number of walkers. good values: 200 - 400 + +stepsize = 1.15; % MCMC step size. try: 1.1 to 4 ish. DO NOT USE 1. + +niter = 20; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" + +npoints = 1200*10*10; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + +% params is small) + +thinning = 10; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {namesUnord}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +%% IGNORE this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. + +% Note to self (please ignore this). I tried the following: +% semanticGroups = {1, [2 4] [3 5]}; % cant do this, then the points never +% get differentiated at all. need some jitter I think. think about this.... +semanticGroups = num2cell((1:length(estParams))'); +%num2cell((1:5)'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3tetR1.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3tetR1.m new file mode 100755 index 0000000..3cdcee7 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3tetR1.m @@ -0,0 +1,296 @@ +function mcmc_info = mcmc_info_constgfp3tetR1(constmobj, tetRmobj) +% mcmc_info_constgfp3tetR1 - set up concurrent parameter inference for a +% set of common parameters informed by a constitutive gene expression +% circuit and a tetR repression circuit. More information on terminology +% and this file can be found by typing help mcmc_info in the command +% window. Before going through this file, we encourage you to read through +% and work through the tutorials on the constitutive gene expression: +% +% proj_mcmc_tutorial.m +% proj_mcmc_tutorial_II.m +% +% (and optionally also look at the very similar files: +% proj_protein_constgfp3i.m +% proj_protein_constgfp3ii.m) +% +% and most importantly the associated mcmc_info files +% +% mcmc_info_constgfp3i.m +% mcmc_info_constgfp3ii.m +% +% to get a good idea of how mcmc_info files are set up, and set some +% context for the complexity of this file. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% This example demonstrates a slightly more complex example of the +% concurrence feature of the mcmc_simbio Bayesian Parameter inference +% toolbox. Here, we have two circuits: the constitutive gene expression +% circuit with model +% +% D + pol <-> D__pol (kfdG, krdG) +% D__pol -> D + pol + protien (kcp) +% +% and the tetR repression circuit with model +% +% D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT; kcp) +% D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG; kcp) +% 2 T <-> T2 (kfdimTet, krdimTet) +% D_G + T2 <-> D_G:T2 (kfseqTet, krseqTet) +% +% Here each model is a different topology (thus there is only one +% geometry associated with each topology). The paramters that are shared +% between the two topologies are: kfdG, krdG, kcp, pol. The remaining +% parameters are specific to the topology-geometry pair they appear in (in +% this case all the remaining parameters appear in the TetR repression +% circuit topology. Furthermore, we will set the forward rate parameters in +% all the reversible reaction to be fixed parameters, and therefore only +% estimate the reverse rate parameters. +% +% This file is used in proj_constgfp3tetR1.m. The data used by this file is +% artificially generated using the data_artificial_v2 function. +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo1 = ... + [' D + pol <-> D__pol (k_f, k_r) \n'... + 'D__pol -> D + pol + protien (kc)\n']; + +circuitInfo2 = ... + ['D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT, kcpT) \n'... + 'D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG, kcpG) \n'... + '2 T <-> T2 (kfdim, krdim)\n'... + 'D_G + T2 <-> D_G:T2 (kfseq, krseq) \n']; + +cpol = 100; % nM +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkfdT = 5; +rkrdT = 300; +rkcp = 0.012; %s-1 +rkfdimTet = 20; % nM-1s-1 +rkrdimTet = 10; % s-1 +rkfseqTet = 20; % nM-1s-1 +rkrseqTet = 10; % s-1 + +% Each topology has its own set of active names. These are the parameters +% and species that are set from values taken from the master vector (using +% indices drawn from paramMaps). +activeNames1 = {'kfdG' + 'krdG' + 'kcp' + 'pol'}; +activeNames2 = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kcp' + 'pol'}; + +% This is the masterVector, each unique parameter only appears here once. +% The forward rate parameters (rkfdG, rkfdT, rkfdimTet, rkfseqTet) are not +% estimated, and their values are fixed to the values above. The remaining +% parameters are estimated during the MCMC procedure. +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); + +% fixedParams vector +fixedParams = [1 3 5 7]; + +% The indices of the elements of the master vector that are to be +% estimated. There are a total of six unique species and parameters that +% are to be estimated. Thus, the MCMC algorithm explores a 6 dimensional +% space to perform the fitting. +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% The names of the estiamted parameters and species in this case are: +% {'krdG'} {'krdT'} {'krdimTet'} {'krseqTet'} {'kcp'} {'pol'} +estParams = activeNames2(estParamsIx); + +% There are two topologies, and each topology has its own paramMaps matrix +% (composed of a single column vector) +% The first topology uses the 1st, 2nd, 9th and 10th elements of the master +% vector, which map to 'kfdG', 'krdG', 'kcp', and 'pol' in that topology. +paramMap1 = [1 2 9 10]'; + +% The second topology uses all the elements of the master vector, and maps +% them to the species and parameters in activeNames2. +paramMap2 = (1:length(masterVector))'; + +% mastervec(estParamsIx) is the subset of elements of the master vector +% that are being estimated. These values are log transformed (to allow them +% to take values on the entire real line), and we set the range of values +% to be within a 6D hypercupe of width 6 (in log space) centered on the +% nominal values given above. +paramRanges = [masterVector(estParamsIx)-3 masterVector(estParamsIx)+3]; + +%% Set data indices to map the models to corresponding data in the data_info struct. +% data indices tell us which data set to use for each topology - geometry pair +% from the data_info struct array. +dataIndices1 = 1; +dataIndices2 = 2; + +%% next we define the dosing strategy. +% each of the two topologies has its own dosing strategy. + +% topology 1 only has the initial DNA (dG) concentration as the species to be +% dosed. +dosedNames1 = {'dG'}; +dosedVals1 = [10 30 60]; + +% topology 2 has two species being dosed, the initial tetR DNA (dT) +% concentration and the initial GFP DNA concentration (dG). dT takes three +% possible values: 0.1, 2 and 8, while dG takes two values: 10 and 30 +% (arbitrary units), leading to a total of 3 x 2 = 6 dose combinations +% (reflected as the 6 columns of dosedVals2). + +dosedNames2 = {'dT'; 'dG'}; % this needs to be a column array + +dosedVals2 = [0.1 0.1 2 2 8 8 ; + 10 30 10 30 10 30]; + +%% Set the measured species in the model and data. +% Both the topologies have the same measured species: pG. +measuredSpecies1 = {{'pG'}}; +measuredSpecies2 = {{'pG'}}; + +% the msIx1 and msIx2 are used to map the measuredSpecies (above) to the +% corresponding columns of the data_info.dataArray data matrix. +msIx1 = 1; % +msIx2 = 1; + +%% setup the MCMC simulation parameters + +% +% >> (sum(di(1).dataArray(:)) + sum(di(2).dataArray(:)))/10 +% +% ans = +% +% 1.6505e+04 +% so overall we have 1.6 x 10^5 as the full signal magnitude (this is assuming +% no dose or topology reweighting). stdev of 1e2 makes +% a factor of 1000 or 0.1% as the noise model. +% lets try this. I tired 1x10^4, this led to extremely broad distributions +% and loose fits. That is fine for a start -- high 'temperature'. + + +stdev = 1e2; % try this out. this could be great! or bad... +tightening = 1; % default is 1. Type in help mcmc_info for more information +nW = 3200*16;% number of walkers. good values: 200 - 400 +stepsize = 1.3; % MCMC step size. try: 1.1 to 4. DO NOT USE 1. +niter = 10; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" +npoints = 3200*32*10*10; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + +% params is small) +thinning = 10; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {constmobj, tetRmobj},... + ... % array of model objects (different topologies) + 'modelName', {constmobj.name, tetRmobj.name},...; % model names. + 'namesUnord', {activeNames1, activeNames2}, ... + ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ...% paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames1, dosedNames2},... + ...% cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... + ...% cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... + 'dataToMapTo', {dataIndices1, dataIndices2}); +...% each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +%% IGNORE this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. +semanticGroups = num2cell((1:length(estParamsIx))'); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3tetR1.m.orig b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3tetR1.m.orig new file mode 100755 index 0000000..771b802 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp3tetR1.m.orig @@ -0,0 +1,302 @@ +function mcmc_info = mcmc_info_constgfp3tetR1(constmobj, tetRmobj) +% mcmc_info_constgfp3tetR1 - set up concurrent parameter inference for a +% set of common parameters informed by a constitutive gene expression +% circuit and a tetR repression circuit. More information on terminology +% and this file can be found by typing help mcmc_info in the command +% window. Before going through this file, we encourage you to read through +% and work through the tutorials on the constitutive gene expression: +% +% proj_mcmc_tutorial.m +% proj_mcmc_tutorial_II.m +% +% (and optionally also look at the very similar files: +% proj_protein_constgfp3i.m +% proj_protein_constgfp3ii.m) +% +% and most importantly the associated mcmc_info files +% +% mcmc_info_constgfp3i.m +% mcmc_info_constgfp3ii.m +% +% to get a good idea of how mcmc_info files are set up, and set some +% context for the complexity of this file. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% This example demonstrates a slightly more complex example of the +% concurrence feature of the mcmc_simbio Bayesian Parameter inference +% toolbox. Here, we have two circuits: the constitutive gene expression +% circuit with model +% +% D + pol <-> D__pol (kfdG, krdG) +% D__pol -> D + pol + protien (kcp) +% +% and the tetR repression circuit with model +% +% D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT; kcp) +% D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG; kcp) +% 2 T <-> T2 (kfdimTet, krdimTet) +% D_G + T2 <-> D_G:T2 (kfseqTet, krseqTet) +% +% Here each model is a different topology (thus there is only one +% geometry associated with each topology). The paramters that are shared +% between the two topologies are: kfdG, krdG, kcp, pol. The remaining +% parameters are specific to the topology-geometry pair they appear in (in +% this case all the remaining parameters appear in the TetR repression +% circuit topology. Furthermore, we will set the forward rate parameters in +% all the reversible reaction to be fixed parameters, and therefore only +% estimate the reverse rate parameters. +% +% This file is used in proj_constgfp3tetR1.m. The data used by this file is +% artificially generated using the data_artificial_v2 function. +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo1 = ... + [' D + pol <-> D__pol (k_f, k_r) \n'... + 'D__pol -> D + pol + protien (kc)\n']; + +circuitInfo2 = ... + ['D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT, kcpT) \n'... + 'D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG, kcpG) \n'... + '2 T <-> T2 (kfdim, krdim)\n'... + 'D_G + T2 <-> D_G:T2 (kfseq, krseq) \n']; + +cpol = 100; % nM +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkfdT = 5; +rkrdT = 300; +rkcp = 0.012; %s-1 +rkfdimTet = 20; % nM-1s-1 +rkrdimTet = 10; % s-1 +rkfseqTet = 20; % nM-1s-1 +rkrseqTet = 10; % s-1 + +% Each topology has its own set of active names. These are the parameters +% and species that are set from values taken from the master vector (using +% indices drawn from paramMaps). +activeNames1 = {'kfdG' + 'krdG' + 'kcp' + 'pol'}; +activeNames2 = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kcp' + 'pol'}; + +% This is the masterVector, each unique parameter only appears here once. +% The forward rate parameters (rkfdG, rkfdT, rkfdimTet, rkfseqTet) are not +% estimated, and their values are fixed to the values above. The remaining +% parameters are estimated during the MCMC procedure. +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); + +% fixedParams vector +fixedParams = [1 3 5 7]; + +% The indices of the elements of the master vector that are to be +% estimated. There are a total of six unique species and parameters that +% are to be estimated. Thus, the MCMC algorithm explores a 6 dimensional +% space to perform the fitting. +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% The names of the estiamted parameters and species in this case are: +% {'krdG'} {'krdT'} {'krdimTet'} {'krseqTet'} {'kcp'} {'pol'} +estParams = activeNames2(estParamsIx); + +% There are two topologies, and each topology has its own paramMaps matrix +% (composed of a single column vector) +% The first topology uses the 1st, 2nd, 9th and 10th elements of the master +% vector, which map to 'kfdG', 'krdG', 'kcp', and 'pol' in that topology. +paramMap1 = [1 2 9 10]'; + +% The second topology uses all the elements of the master vector, and maps +% them to the species and parameters in activeNames2. +paramMap2 = (1:length(masterVector))'; + +% mastervec(estParamsIx) is the subset of elements of the master vector +% that are being estimated. These values are log transformed (to allow them +% to take values on the entire real line), and we set the range of values +% to be within a 6D hypercupe of width 6 (in log space) centered on the +% nominal values given above. +paramRanges = [masterVector(estParamsIx)-3 masterVector(estParamsIx)+3]; + +%% Set data indices to map the models to corresponding data in the data_info struct. +% data indices tell us which data set to use for each topology - geometry pair +% from the data_info struct array. +dataIndices1 = 1; +dataIndices2 = 2; + +%% next we define the dosing strategy. +% each of the two topologies has its own dosing strategy. + +% topology 1 only has the initial DNA (dG) concentration as the species to be +% dosed. +dosedNames1 = {'dG'}; +dosedVals1 = [10 30 60]; + +% topology 2 has two species being dosed, the initial tetR DNA (dT) +% concentration and the initial GFP DNA concentration (dG). dT takes three +% possible values: 0.1, 2 and 8, while dG takes two values: 10 and 30 +% (arbitrary units), leading to a total of 3 x 2 = 6 dose combinations +% (reflected as the 6 columns of dosedVals2). + +dosedNames2 = {'dT'; 'dG'}; % this needs to be a column array + +dosedVals2 = [0.1 0.1 2 2 8 8 ; + 10 30 10 30 10 30]; + +%% Set the measured species in the model and data. +% Both the topologies have the same measured species: pG. +measuredSpecies1 = {{'pG'}}; +measuredSpecies2 = {{'pG'}}; + +% the msIx1 and msIx2 are used to map the measuredSpecies (above) to the +% corresponding columns of the data_info.dataArray data matrix. +msIx1 = 1; % +msIx2 = 1; + +%% setup the MCMC simulation parameters +<<<<<<< HEAD +stdev = 1; % the standard deviation in the likelihood function. +tightening = 1; % default is 1. Type in help mcmc_info for more information +nW = 3200;% number of walkers. good values: 200 - 400 +stepsize = 1.3; % MCMC step size. try: 1.1 to 4. DO NOT USE 1. +niter = 10; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" +npoints = 3200*10*20; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +======= +% +% >> (sum(di(1).dataArray(:)) + sum(di(2).dataArray(:)))/10 +% +% ans = +% +% 1.6505e+04 +% so overall we have 1.6 x 10^5 as the data number. stdev of 1e2 makes +% a factor of 1000 or 0.1% as the noise model. +% lets try this. I tired 1x10^4, this led to extremely broad distributions +% and loose fits. That is fine for a start -- high 'temperature'. + + +stdev = 1e2; % try this out. this could be great! or bad... +tightening = 1; % default is 1. Type in help mcmc_info for more information +nW = 3200*32;% number of walkers. good values: 200 - 400 +stepsize = 1.3; % MCMC step size. try: 1.1 to 4. DO NOT USE 1. +niter = 10; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" +npoints = 3200*32*10*5; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +>>>>>>> minmcmcv4 +% params is small) +thinning = 5; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {constmobj, tetRmobj},... + ... % array of model objects (different topologies) + 'modelName', {constmobj.name, tetRmobj.name},...; % model names. + 'namesUnord', {activeNames1, activeNames2}, ... + ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ...% paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames1, dosedNames2},... + ...% cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... + ...% cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... + 'dataToMapTo', {dataIndices1, dataIndices2}); +...% each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +%% IGNORE this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. +semanticGroups = num2cell((1:length(estParamsIx))'); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp5i.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp5i.m new file mode 100755 index 0000000..c5dbbf1 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp5i.m @@ -0,0 +1,153 @@ +function mcmc_info = mcmc_info_constgfp5i(modelObj) +% tetR repression, kf(s) fixed. Separate estimation of ESPs and +% CSPs. +% +% ~~~ MODEL ~~~ + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + ['dG + pol <-> dG_pol -> dG + pol + mG \n'... + 'mG + ribo <-> mG_ribo -> mG + ribo + pG \n'... + 'mG -> null \n']; + + +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 + +rkfpG = 10; % nM-1s-1 +rkrpG = 300; % s-1 + +cpol = 100; % nM +cribo = 50; %nM +rkcm = 0.001; %s-1 +rkcp = 1/36; +rdel_m = log(2)/720; % 12 min half life of mrna + +activeNames = ... + {'kfdG' + 'krdG' + 'kfpG' + 'krpG' + 'kcm' + 'kcp' + 'del_m' + 'pol' + 'ribo'}; + + masterVector = log([... + rkfdG + rkrdG + rkfpG + rkrpG + rkcm + rkcp + rdel_m + cpol + cribo]); + +% fixedParams vector +fixedParams = [1 3]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = {'krdG' + 'krpG' + 'kcm' + 'kcp' + 'del_m' + 'pol' + 'ribo'}; + +paramMap = [1:length(masterVector)]'; +paramRanges = [masterVector(estParamsIx)-3 masterVector(estParamsIx)+3]; + +dataIndices = [1]; + +%% next we define the dosing strategy. +dosedNames = {'dG'}; +dosedVals = [10 30 60]; +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 40; % actual: 200 - 600 ish +stepsize = 3; % actual: 1.1 to 4 ish +niter = 4; % actual: 2 - 30 ish, +npoints = 4e2; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 1; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp5ii.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp5ii.m new file mode 100755 index 0000000..98a5f9d --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_constgfp5ii.m @@ -0,0 +1,178 @@ +function mcmc_info = mcmc_info_constgfp5ii(modelObj) +% Single topology: constitutive gfp circuit +% 2 geometries (extracts) +% kf(s) fixed. +% separate ESPs and joint CSPs. +% +% MODEL: tetRrepression 2. +% dG + pol <-> dG_pol -> dG + pol + mG +% mG + ribo <-> mG_ribo -> mG + ribo + pG +% mG -> null +% + +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + ['dG + pol <-> dG_pol -> dG + pol + mG \n'... + 'mG + ribo <-> mG_ribo -> mG + ribo + pG \n'... + 'mG -> null \n']; + + + +rkfdG = 1; % nM-1s-1 +rkrdG = 60; % s-1 + +rkfpG = 2; % nM-1s-1 +rkrpG = 60; % s-1 + +cpol1 = 100; % nM +cribo1 = 50; %nM +rkcm1 = 0.001; %s-1 +rkcp1 = 1/36; +rdel_m1 = log(2)/720; % 12 min half life of mrna + +cpol2 = cpol1*2; +cribo2 = cribo1*2; +rkcm2 = rkcm1*2; +rkcp2 = rkcp1*2; +rdel_m2 = rdel_m1*2; + + +activeNames = ... + {'kfdG' + 'krdG' + 'kfpG' + 'krpG' + 'kcm' + 'kcp' + 'del_m' + 'pol' + 'ribo'}; + +masterVector = log([... + rkfdG + rkrdG + rkfpG + rkrpG + rkcm1 + rkcp1 + rdel_m1 + cpol1 + cribo1 + rkcm2 + rkcp2 + rdel_m2 + cpol2 + cribo2]); +% fixedParams vector +fixedParams = [1 3]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = {'krdG' + 'krpG' + 'kcm1' + 'kcp1' + 'del_m1' + 'pol1' + 'ribo1' + 'kcm2' + 'kcp2' + 'del_m2' + 'pol2' + 'ribo2'}; + +paramMap1 = [1:4 5:9]'; +paramMap2 = [1:4 10:14]'; +paramMap = [paramMap1, paramMap2]; +paramRanges = [masterVector(estParamsIx)-5 masterVector(estParamsIx)+3]; + + +dataIndices = [1 2]; + +%% next we define the dosing strategy. +dosedNames = {'dG'}; +dosedVals = [10 30 60]; +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.1; % actual: 1.1 to 4 ish +niter = 40; % actual: 2 - 30 ish, +npoints = 8e4; % actual: 1e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 20; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... %paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_mrna.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_mrna.m new file mode 100755 index 0000000..a987080 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_mrna.m @@ -0,0 +1,184 @@ +function mcmc_info = mcmc_info_dsg2014_mrna(modelObj) + % Define the mcmc_info struct for the dsg2014 dataset, for the estimation + % of the mrna parameters, using only measurements of the mrna for + % the estimation. The data is from figure 1 of the paper: + % Gene Circuit Performance Characterization and Resource Usage in a + % Cell-Free “Breadboard” by Siegal-Gaskins et al. + % + % INPUTS: A Simbiology model object. + % + % OUTPUTS: You should set up an mcmc_info struct with the fields: + % + % The strust has fields: + % + % 'circuitInfo': A human readable despription of the circuit. (optional) + % + % 'modelObj': The simbiology model object + % + % 'modelName': The name property of the Simbiology model object. (optional) + % + % 'namesUnord': List of species and parameters that are to be estimated. These + % are strings naming things in the model object. + % + % 'paramRanges': A length(mcmc_info.namesUnord) x 2 matrix of log transformed + % upper and lower bounds for the parameters and species concentrations. + % + % 'dosedNames': A cell array of strings of species names for species that are + % dosed in the model. + % + % 'dosedVals': A matrix of dose values of size # of dosed species by + % # of dose combinations. + % + % 'measuredSpecies': A 1 x number of measured output variables. This is a + % cell array of cell arrays of the strings of species whose concentrations + % are to be added to get the measured variable. + % + % 'stdev': MCMC likelihood function standard deviation + % + % 'tightening': A division factor for the standard deviation. + % + % 'nW': Number of Walkers + % + % 'stepSize': MCMC step size + % + % 'nIter': Number of MCMC iterations. + % + % 'nPoints': Number of MCMC points per iteration. + % + % 'thinning': Number of steps to skip before taking an MCMC sample. + % + % 'parallel': Boolean variable specifying whether parallel computing is used. + % + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... +['This is a simple constitutive gene expression model \n'... +'built using the TXTL modeling toolbox. It models DNA binding \n'... +'to RNAP and nucleotides, followed by transcription. The resulting\n'... +'mRNA can degrade and participate in translation. The former is \n'... +'modeled as a enzymatic reaction involving every complex containing \n'... +'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... +'and ATP, and finally elongation and termination resulting in protein.']; + +%% make a list of parameters and species to estimate + +% parameters and typical values. +pcells = [{'TX_elong_glob', 5.1288 } % 1 3 + {'AGTPdeg_time' 7200 } % 4 10 + {'AGTPdeg_rate' 0.00022425 } % -10 -7 + {'TXTL_P70_RNAPbound_Kd' 12.39 } % -1 7 + {'TXTL_P70_RNAPbound_F' 17.001 } % 1 7 + {'TXTL_RNAPBOUND_TERMINATION_RATE' 0.076026 } % -5 -1 + {'TXTL_NTP_RNAP_1_Kd' 2.142 } % -2 2 + {'TXTL_NTP_RNAP_1_F' 9.8854 } % 1 4 + {'TXTL_NTP_RNAP_2_Kd' 13.33 } % 1 4 + {'TXTL_NTP_RNAP_2_F' 0.75935 } % -2 2 + {'TXTL_RNAdeg_Kd' 2185.8 } % 5 10 + {'TXTL_RNAdeg_F' 1 } % -5 2 + {'TXTL_RNAdeg_kc' 0.0022382 }]; % -7 -3 + +% species and typical values. +estNames = [pcells(:,1) + {'RNAP';... + 'RNase'}]; +estVals = [cell2mat(pcells(:,2)) + 42.247 + 81.795]; + +% parameter and species ranges to search, in log base e space. +paramranges = [1 3 + 4 10 + -10 -7 + -1 7 + 1 7 + -5 -1 + -2 2 + 1 4 + 1 4 + -2 2 + 5 10 + -5 2 + -7 -3 + 1.5 6 + 2 7]; + + +%% Define the species to set the initial concentration of and what values to +% vary it over. +dosedNames = {'DNA p70--utr1--deGFP'}; +dosedVals = [0.5 2 5 20]; + + +%% create the measured species cell array +% this is a 1x2 cell array. each element of this cell array contains +% further cell arrays. The first such cell array is a list of all the bound +% and free versions of the RNA. The second cell array contains a single +% cell, which contains the GFP string. +% all the species in the inner cell arrays get summed, and compared to the +% corresponding column (dimension 2) of the experimental data array. +measuredSpecies = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:2AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:2AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 40; % actual: 200 - 600 ish +stepsize = 2; % actual: 2 to 4 ish +niter = 2; % actual: 2 - 20 ish, +npoints = 1e2; % actual: 1e5 ish +thinning = 1; % actual: 10 to 40 ish + + +%% pull all this together into an output struct. +mcmc_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... + 'modelName', {modelObj.name},...; + 'namesUnord', {estNames}, ... + 'paramRanges', {paramranges},... + 'dosedNames', {dosedNames},... + 'dosedVals', {dosedVals},... + 'measuredSpecies', {measuredSpecies}, ... + 'stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + + + + + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_mrna_v2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_mrna_v2.m new file mode 100755 index 0000000..177f87c --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_mrna_v2.m @@ -0,0 +1,184 @@ +function mcmc_info = mcmc_info_dsg2014_mrna_v2(modelObj) + % Define the mcmc_info struct for the dsg2014 dataset, for the estimation + % of the mrna parameters, using only measurements of the mrna for + % the estimation. The data is from figure 1 of the paper: + % Gene Circuit Performance Characterization and Resource Usage in a + % Cell-Free “Breadboard” by Siegal-Gaskins et al. + % + % INPUTS: A Simbiology model object. + % + % OUTPUTS: You should set up an mcmc_info struct with the fields: + % + % The struct has fields: + % + % 'circuitInfo': A human readable despription of the circuit. (optional) + % + % 'modelObj': The simbiology model object + % + % 'modelName': The name property of the Simbiology model object. (optional) + % + % 'namesUnord': List of species and parameters that are to be estimated. These + % are strings naming things in the model object. + % + % 'paramRanges': A length(mcmc_info.namesUnord) x 2 matrix of log transformed + % upper and lower bounds for the parameters and species concentrations. + % + % 'dosedNames': A cell array of strings of species names for species that are + % dosed in the model. + % + % 'dosedVals': A matrix of dose values of size # of dosed species by + % # of dose combinations. + % + % 'measuredSpecies': A 1 x number of measured output variables. This is a + % cell array of cell arrays of the strings of species whose concentrations + % are to be added to get the measured variable. + % + % 'stdev': MCMC likelihood function standard deviation + % + % 'tightening': A division factor for the standard deviation. + % + % 'nW': Number of Walkers + % + % 'stepSize': MCMC step size + % + % 'nIter': Number of MCMC iterations. + % + % 'nPoints': Number of MCMC points per iteration. + % + % 'thinning': Number of steps to skip before taking an MCMC sample. + % + % 'parallel': Boolean variable specifying whether parallel computing is used. + % + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... +['This is a simple constitutive gene expression model \n'... +'built using the TXTL modeling toolbox. It models DNA binding \n'... +'to RNAP and nucleotides, followed by transcription. The resulting\n'... +'mRNA can degrade and participate in translation. The former is \n'... +'modeled as a enzymatic reaction involving every complex containing \n'... +'mRNA. The latter involves binging to Ribosomes, followed by amino acids \n'... +'and ATP, and finally elongation and termination resulting in protein.'] + +%% make a list of parameters and species to estimate + +% parameters and typical values. +pcells = [{'TX_elong_glob', 5.1288 } % 1 3 + {'AGTPdeg_time' 7200 } % 4 10 + {'AGTPdeg_rate' 0.00022425 } % -10 -7 + {'TXTL_P70_RNAPbound_Kd' 12.39 } % -1 7 + {'TXTL_P70_RNAPbound_F' 17.001 } % 1 7 + {'TXTL_RNAPBOUND_TERMINATION_RATE' 0.076026 } % -5 -1 + {'TXTL_NTP_RNAP_1_Kd' 2.142 } % -2 2 + {'TXTL_NTP_RNAP_1_F' 9.8854 } % 1 4 + {'TXTL_NTP_RNAP_2_Kd' 13.33 } % 1 4 + {'TXTL_NTP_RNAP_2_F' 0.75935 } % -2 2 + {'TXTL_RNAdeg_Kd' 2185.8 } % 5 10 + {'TXTL_RNAdeg_F' 1 } % -5 2 + {'TXTL_RNAdeg_kc' 0.0022382 }]; % -7 -3 + +% species and typical values. +estNames = [pcells(:,1) + {'RNAP';... + 'RNase'}]; +estVals = [cell2mat(pcells(:,2)) + 42.247 + 81.795]; + +% parameter and species ranges to search, in log base e space. +paramranges = [1 3 + 4 10 + -10 -7 + -1 7 + 1 7 + -5 -1 + -2 2 + 1 4 + 1 4 + -2 2 + 5 10 + -5 2 + -7 -3 + 1.5 6 + 2 7]; + + +%% Define the species to set the initial concentration of and what values to +% vary it over. +dosedNames = {'DNA p70--utr1--deGFP'}; +dosedVals = [0.5 2 5 20]; + + +%% create the measured species cell array +% this is a 1x2 cell array. each element of this cell array contains +% further cell arrays. The first such cell array is a list of all the bound +% and free versions of the RNA. The second cell array contains a single +% cell, which contains the GFP string. +% all the species in the inner cell arrays get summed, and compared to the +% corresponding column (dimension 2) of the experimental data array. +measuredSpecies = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:2AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:2AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 600; % actual: 200 - 600 ish +stepsize = 1.2; % actual: 2 to 4 ish +niter = 30; % actual: 2 - 20 ish, +npoints = 4e4; % actual: 1e5 ish +thinning = 10; % actual: 10 to 40 ish + + +%% pull all this together into an output struct. +mcmc_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... + 'modelname', {m.name},...; + 'namesUnord', {estNames}, ... + 'paramRanges', {paramranges},... + 'dosedNames', {dosedNames},... + 'dosedVals', {dosedVals},... + 'measuredSpecies', {measuredSpecies}, ... + 'stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + + + + + + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_protein.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_protein.m new file mode 100755 index 0000000..bbf3326 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_protein.m @@ -0,0 +1,158 @@ +function mcmc_info = mcmc_info_dsg2014_protein(modelObj) + + % Define the mcmc_info struct for the dsg2014 dataset, for the estimation + % of the protein parameters, using only measurements of the protein for + % the estimation. The data is from figure 1 of the paper: + % Gene Circuit Performance Characterization and Resource Usage in a + % Cell-Free “Breadboard” by Siegal-Gaskins et al. + % + % INPUTS: A Simbiology model object. + % + % OUTPUTS: You should set up an mcmc_info struct with the fields: + % + % The strust has fields: + % + % 'circuitInfo': A human readable despription of the circuit. (optional) + % + % 'modelObj': The simbiology model object + % + % 'modelName': The name property of the Simbiology model object. (optional) + % + % 'namesUnord': List of species and parameters that are to be estimated. These + % are strings naming things in the model object. + % + % 'paramRanges': A length(mcmc_info.namesUnord) x 2 matrix of log transformed + % upper and lower bounds for the parameters and species concentrations. + % + % 'dosedNames': A cell array of strings of species names for species that are + % dosed in the model. + % + % 'dosedVals': A matrix of dose values of size # of dosed species by + % # of dose combinations. + % + % 'measuredSpecies': A 1 x number of measured output variables. This is a + % cell array of cell arrays of the strings of species whose concentrations + % are to be added to get the measured variable. + % + % 'stdev': MCMC likelihood function standard deviation + % + % 'tightening': A division factor for the standard deviation. + % + % 'nW': Number of Walkers + % + % 'stepSize': MCMC step size + % + % 'nIter': Number of MCMC iterations. + % + % 'nPoints': Number of MCMC points per iteration. + % + % 'thinning': Number of steps to skip before taking an MCMC sample. + % + % 'parallel': Boolean variable specifying whether parallel computing is used. + % + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... +['This is a simple constitutive gene expression model \n'... +'built using the TXTL modeling toolbox. It models DNA binding \n'... +'to RNAP and nucleotides, followed by transcription. The resulting\n'... +'mRNA can degrade and participate in translation. The former is \n'... +'modeled as a enzymatic reaction involving every complex containing \n'... +'mRNA. The latter involves binging to Ribosomes, followed by amino acids \n'... +'and ATP, and finally elongation and termination resulting in protein.'] + +pcells = [{'TL_elong_glob' 4 +'TXTL_PROT_deGFP_MATURATION' 0.00231049 +'TXTL_UTR_UTR1_Kd' 20 +'TXTL_UTR_UTR1_F' 0.2 +'TL_AA_Kd' 0.1 +'TL_AA_F' 1 +'TL_AGTP_Kd' 10 +'TL_AGTP_F' 1 +'TXTL_RIBOBOUND_TERMINATION_RATE' 0.1}]; +estNames = [pcells(:,1) + {'Ribo'}]; % 3 8 +estVals = [cell2mat(pcells(:,2)) + 100]; + + +% b = [estVals/10 estVals*10] ; +% paramranges = log(b); + +paramranges = [0 6 + -7 -3 + -1 7 + -3 3 + -1 6 + -1 6 + -1 6 + -1 6 + -6 1 + 2 7]; + +%% next we define the dosing strategy. +dosedNames = {'DNA p70--utr1--deGFP'}; +dosedVals = [0.5 2 5 20]; + + +%% create the measured species cell array +% this is a 1x2 cell array. each element of this cell array contains +% further cell arrays. The first such cell array is a list of all the bound +% and free versions of the RNA. The second cell array contains a single +% cell, which contains the GFP string. +% all the species in the inner cell arrays get summed, and compared to the +% corresponding column (dimension 2) of the experimental data array. +measuredSpecies = {{'protein deGFP*'}}; + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 100; % actual: 200 - 600 ish +stepsize = 3; % actual: 1.1 to 4 ish +niter = 2; % actual: 2 - 30 ish, +npoints = 3e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of params is small) +thinning = 2; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +mcmc_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... + 'modelname', {m.name},...; + 'namesUnord', {estNames}, ... + 'paramRanges', {paramranges},... + 'dosedNames', {dosedNames},... + 'dosedVals', {dosedVals},... + 'measuredSpecies', {measuredSpecies}, ... + 'stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + + + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_protein_v2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_protein_v2.m new file mode 100755 index 0000000..b1e5c71 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_protein_v2.m @@ -0,0 +1,389 @@ +function mcmc_info = mcmc_info_dsg2014_protein_v2(modelObj) + % version2 mcmc_info struct. Compatible with multimodel parameter inference. + % key differences with version 1: + % model parameters specified now include the ones to be estimated and the + % ones to keep fixed. + % split the old mcmc_info struct into 3 structs: + % runsim_info: information on the mcmc algorithm parameters + % model_info: array of models, and associated properties like parameters, + % and the matrices of indices from the master vector + % to the model parameters. + % master_info: contains the master vector, and a spec for which parameters + % get estimated. + % + % Version 1's help text: (!TODO: write this version's full help file.) + % + % Define the mcmc_info struct for the dsg2014 dataset, for the estimation + % of the protein parameters, using only measurements of the protein for + % the estimation. The data is from figure 1 of the paper: + % Gene Circuit Performance Characterization and Resource Usage in a + % Cell-Free “Breadboard” by Siegal-Gaskins et al. + % + % INPUTS: A Simbiology model object. + % + % OUTPUTS: You should set up an mcmc_info struct with the fields: + % + % The strust has fields: + % + % 'circuitInfo': A human readable despription of the circuit. (optional) + % + % 'modelObj': The simbiology model object + % + % 'modelName': The name property of the Simbiology model object. (optional) + % + % 'namesUnord': List of species and parameters that are to be estimated. These + % are strings naming things in the model object. + % + % 'paramRanges': A length(mcmc_info.namesUnord) x 2 matrix of log transformed + % upper and lower bounds for the parameters and species concentrations. + % + % 'dosedNames': A cell array of strings of species names for species that are + % dosed in the model. + % + % 'dosedVals': A matrix of dose values of size # of dosed species by + % # of dose combinations. + % + % 'measuredSpecies': A 1 x number of measured output variables. This is a + % cell array of cell arrays of the strings of species whose concentrations + % are to be added to get the measured variable. + % + % 'stdev': MCMC likelihood function standard deviation + % + % 'tightening': A division factor for the standard deviation. + % + % 'nW': Number of Walkers + % + % 'stepSize': MCMC step size + % + % 'nIter': Number of MCMC iterations. + % + % 'nPoints': Number of MCMC points per iteration. + % + % 'thinning': Number of steps to skip before taking an MCMC sample. + % + % 'parallel': Boolean variable specifying whether parallel computing is used. + % + + % Copyright (c) 2018, Vipul Singhal, Caltech + % Permission is hereby granted, free of charge, to any person obtaining a copy + % of this software and associated documentation files (the "Software"), to deal + % in the Software without restriction, including without limitation the rights + % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + % copies of the Software, and to permit persons to whom the Software is + % furnished to do so, subject to the following conditions: + + % The above copyright notice and this permission notice shall be included in all + % copies or substantial portions of the Software. + + % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + % SOFTWARE. + + % User readable description of the circuit. Will be used in the log file generated + % from the MCMC inference procedure. + circuitInfo = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + + + + activeNames = {'TX_elong_glob' + 'AGTPdeg_time' + 'AGTPdeg_rate' + 'TXTL_P70_RNAPbound_Kd' + 'TXTL_P70_RNAPbound_F' + 'TXTL_RNAPBOUND_TERMINATION_RATE' + 'TXTL_NTP_RNAP_1_Kd' + 'TXTL_NTP_RNAP_1_F' + 'TXTL_NTP_RNAP_2_Kd' + 'TXTL_NTP_RNAP_2_F' + 'TXTL_RNAdeg_Kd' + 'TXTL_RNAdeg_F' + 'TXTL_RNAdeg_kc' + 'RNAP' + 'RNase' + 'TL_elong_glob' + 'TXTL_PROT_deGFP_MATURATION' + 'TXTL_UTR_UTR1_Kd' + 'TXTL_UTR_UTR1_F' + 'TL_AA_Kd' + 'TL_AA_F' + 'TL_AGTP_Kd' + 'TL_AGTP_F' + 'TXTL_RIBOBOUND_TERMINATION_RATE' + 'Ribo'}; + + +estParams = {'TL_elong_glob' + 'TXTL_PROT_deGFP_MATURATION' + 'TXTL_UTR_UTR1_Kd' + 'TXTL_UTR_UTR1_F' + 'TL_AA_Kd' + 'TL_AA_F' + 'TL_AGTP_Kd' + 'TL_AGTP_F' + 'TXTL_RIBOBOUND_TERMINATION_RATE' + 'Ribo'}; + + + + % get 10 sets of parameter values (= 10 points) from a previously estimated sims: + % get parameter values from a few different mcmc points from the runs of + % the file proj_acs_dsg2014_protein + marray = mcmc_get_walkers({'20180121_131114'}, {5}, ... + ['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/'... + 'mcmc_simbio/projects/proj_acs_dsg2014_mrna']); + + + nPrevPoints = 5; + minit = marray(:, ((end-nPrevPoints+1) : end), end); % Final set of walker positions. + minit = minit(:,:); % nparam x npoints, nparam is the tx params, ie, 15. npoints is 10. + + % fixedParams vector + fixedParams = [1:numel(minit)]'; + + % master vector + logp = zeros(10,1); + + masterVector = [minit(:) + logp]; % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology. + % + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + % + % + + TLparamIX = [(length(masterVector)-length(logp)+1) : length(masterVector)]'; + paramMap = [reshape((1:numel(minit))', 15, numel(minit)/15); + repmat(TLparamIX, 1, numel(minit)/15)]; + + % parameter ranges for the logp (the parameters within the master vector that + % are to be estimated.) + + % 20180218_225205 -> 3 successful runs + % 20180219_021944 -> 10 successpul runs, comtinued from 20180218_225205 + % used: +% paramRanges = [4 8 +% -7 -3 +% -1 7 +% -3 3 +% -1 6 +% -1 6 +% -1 6 +% -1 6 +% -6 -1 +% 2 7]; + +% '20180219_154541', 10 successful runs, started from +% 20180219_021944, but with the parameter intiial points constrained to: + +% paramRanges = [5 8 +% -4 0 +% 0 6 +% -1 3 +% 0 6 +% 0 6 +% -1 6 +% -1 6 +% -1.5 2 +% 6 8]; + + +% New run '20180221_011619' started from 20180219_154541 but with the +% parameter intiial points constrained to: +paramRanges = [3 8 + -4 0 + -2 8 + -2 4 + -2 8 + -2 8 + 4 8 + -3 2 + -1.5 -0.5 + 3 9]; + +% New run _______ started from 20180221_011619 but with the +% parameter intiial points constrained to: +paramRanges = [5 9 + -4 0 + -2 10 + -1 3 + -2 10 + -3 10 + 2 7 + -3 4 + -1.2 -0.8 + 5 8]; + + +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. +% Here we have 1 model, and 10 geometries, all pointing to the same data: +% at data index 1 in the data_info array created by data_dsg2014.m +dataIndices = ones(nPrevPoints,1); + +%% next we define the dosing strategy. +dosedNames = {'DNA p70--utr1--deGFP'}; +dosedVals = [0.5 2 5 20]; + + +%% create the measured species cell array +% this is a 1x2 cell array. each element of this cell array contains +% further cell arrays. The first such cell array is a list of all the bound +% and free versions of the RNA. The second cell array contains a single +% cell, which contains the GFP string. +% all the species in the inner cell arrays get summed, and compared to the +% corresponding column (dimension 2) of the experimental data array. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 2; % this is the index of the measured species in the data array +% from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.3; % actual: 1.1 to 4 ish +niter = 10; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 4; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % each paramMap is a matrix mapping models to the master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:10)'); %arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... % master vector is the set of all parameters that get distributed + ... % across all models and topologies. not just the estimated params + 'paramRanges', {paramRanges},... % paramRanges are the ranges of parameter values for the values in the + ... % master vector that are estimated. ie, are specified by estParamIx as defined above. + 'fixedParams', {fixedParams},... % indexes of the parameters that are fixed (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their distinct + % groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. + + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_A.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_A.m new file mode 100755 index 0000000..9218b6c --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_A.m @@ -0,0 +1,365 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_A(modelObj) + % Define the mcmc_info struct for the dsg2014 dataset, for the estimation + % of the mrna parameters, using only measurements of the mrna for + % the estimation. The data is from figure 1 of the paper: + % Gene Circuit Performance Characterization and Resource Usage in a + % Cell-Free “Breadboard” by Siegal-Gaskins et al. + % + % mcmc_info struct. Written for concurrent multi + % model - experiment parameter inference. + % This mcmc info has parameter inference from two experiments: + % 1) rna degradation using purified dna + % 2) translation + transcription + rna degradation + % + % mcmc_info has the following substructures: + % + % runsim_info: information on the mcmc algorithm parameters + % model_info: array of models, and associated properties like parameters, + % and the matrices of indices from the master vector + % to the model parameters. + % master_info: contains the master vector, and a spec for which parameters + % get estimated. + % + % Copyright (c) 2018, Vipul Singhal, Caltech + % Permission is hereby granted, free of charge, to any person obtaining a copy + % of this software and associated documentation files (the "Software"), to deal + % in the Software without restriction, including without limitation the rights + % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + % copies of the Software, and to permit persons to whom the Software is + % furnished to do so, subject to the following conditions: + + % The above copyright notice and this permission notice shall be included in all + % copies or substantial portions of the Software. + + % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + % SOFTWARE. + + % User readable description of the circuit. Will be used in the log file generated + % from the MCMC inference procedure. + + +% List of all parameters +% {'TX_elong_glob' +% 'AGTPdeg_time' +% 'AGTPdeg_rate' +% 'AGTPreg_ON' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_P70_RNAPbound_F' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_1_F' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_NTP_RNAP_2_F' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_F' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_PROT_deGFP_MATURATION' +% 'TXTL_UTR_UTR1_Kd' +% 'TXTL_UTR_UTR1_F' +% 'TL_AA_Kd' +% 'TL_AA_F' +% 'TL_AGTP_Kd' +% 'TL_AGTP_F' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo'}; + + % paramters to estimate: +% 'TX_elong_glob' +% 'AGTPdeg_time' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_UTR_UTR1_Kd' +% 'TL_AA_Kd' +% 'TL_AGTP_Kd' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo' + +% and in repeat 2, drop 'TL_AA_Kd', 'TL_AGTP_Kd' +% 'TXTL_NTP_RNAP_1_Kd', 'TXTL_NTP_RNAP_2_Kd' + + circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + + circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + + %{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' 2000 [100 10000] + 'TXTL_RNAdeg_F' 0.02 [0.01 100] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] + 'RNase' 100 [10 1000]}; + activeNames2 = {... + 'TX_elong_glob' 10.5 [0.5 100] + 'AGTPdeg_time' 7200 [1800 42000] + 'AGTPdeg_rate' 0.0002 [1e-5 1e-2] + 'AGTPreg_ON' 0.02 [0.005 0.2] + 'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] + 'TXTL_P70_RNAPbound_F' 20 [1e-5 100] + 'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] + 'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] + 'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] + 'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] + 'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] + 'TXTL_RNAdeg_Kd' 2000 [100 10000] + 'TXTL_RNAdeg_F' 0.01 [0.1 1000] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] + 'RNAP' 100 [5 500] + 'RNase' 100 [10 1000] + 'TL_elong_glob' 20 [4 200] + 'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] + 'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] + 'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] + 'TL_AA_Kd' 100000 [10 1e8] + 'TL_AA_F' 0.001 [1e-5 20] + 'TL_AGTP_Kd' 100000 [1e2 1e8] + 'TL_AGTP_F' 1e-5 [1e-7 1] + 'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] + 'Ribo' 30 [5 1000]}; + + + + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 5:17 19:26 ]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + % !!!!!!! this is a huge mistake. god dammit. ugh. + % master vector is NOT zeros!!!!! the fixed species end up bein + % zeros!!!! + % jesus. I just wasted 100 bucks doing simulations what turned out to + % be bogus because of this bug. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + +%% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1));%dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2));%dtempvec/(sum(dtempvec)); +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + +measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; +msIx1 = 1; % this is the index of the measured species in the data array +% from data_dsg2014. There are two species: 1: mRNA and 2: GFP. +msIx2 = [1,2]; + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 300; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 10; % actual: 2 - 30 ish, +npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.01}, ... + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. weight the rnadeg + ...% experiment to be 20% as important as the MGA-GFP experiment + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 1 + varargout{1} = activeNames2; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_A1.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_A1.m new file mode 100755 index 0000000..c3d5c26 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_A1.m @@ -0,0 +1,362 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_A1(modelObj) +% expanded parameter ranges. +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. + + +% List of all parameters +% {'TX_elong_glob' +% 'AGTPdeg_time' +% 'AGTPdeg_rate' +% 'AGTPreg_ON' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_P70_RNAPbound_F' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_1_F' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_NTP_RNAP_2_F' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_F' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_PROT_deGFP_MATURATION' +% 'TXTL_UTR_UTR1_Kd' +% 'TXTL_UTR_UTR1_F' +% 'TL_AA_Kd' +% 'TL_AA_F' +% 'TL_AGTP_Kd' +% 'TL_AGTP_F' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo'}; + +% paramters to estimate: +% 'TX_elong_glob' +% 'AGTPdeg_time' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_UTR_UTR1_Kd' +% 'TL_AA_Kd' +% 'TL_AGTP_Kd' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo' + +% and in repeat 2, drop 'TL_AA_Kd', 'TL_AGTP_Kd' +% 'TXTL_NTP_RNAP_1_Kd', 'TXTL_NTP_RNAP_2_Kd' + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' 2000 [100 1e5] + 'TXTL_RNAdeg_F' 0.01 [0.01 10000] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] + 'RNase' 100 [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. originals in regen_A file. + 'TX_elong_glob' 10.5 [0.5 300] + 'AGTPdeg_time' 7200 [1800 42000] + 'AGTPdeg_rate' 0.0002 [1e-5 1e-2] + 'AGTPreg_ON' 0.02 [0.005 0.2] + 'TXTL_P70_RNAPbound_Kd' 20 [0.1 1e6] + 'TXTL_P70_RNAPbound_F' 20 [1e-5 300] + 'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] + 'TXTL_NTP_RNAP_1_Kd' 100000 [1 1e6] + 'TXTL_NTP_RNAP_1_F' 0.0001 [1e-5 100] + 'TXTL_NTP_RNAP_2_Kd' 1e6 [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' 1e-5 [1e-6 1000] + 'TXTL_RNAdeg_Kd' 2000 [100 1e5] + 'TXTL_RNAdeg_F' 0.01 [0.01 10000] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] + 'RNAP' 100 [5 5000] + 'RNase' 100 [1 10000] + 'TL_elong_glob' 20 [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] + 'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] + 'TXTL_UTR_UTR1_F' 0.2 [1e-5 100] + 'TL_AA_Kd' 100000 [.1 1e6] + 'TL_AA_F' 0.001 [1e-5 20] + 'TL_AGTP_Kd' 100000 [.1 1e7] + 'TL_AGTP_F' 1e-5 [1e-5 100] + 'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 20000] + 'Ribo' 30 [10 10000]}; + + + + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 5:17 19:26 ]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1= ones(size(dosedVals1));% = dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1, 0.01}, ... + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. weight the rnadeg + ...% experiment to be 20% as important as the MGA-GFP experiment + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_B.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_B.m new file mode 100755 index 0000000..bf7f060 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_B.m @@ -0,0 +1,339 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_B(modelObj) +% compared to the first file, mcmc_info_dsg2014_regen_B +% here we have a smaller set of parameters that get estimated. +% + % Define the mcmc_info struct for the dsg2014 dataset, for the estimation + % of the mrna parameters, using only measurements of the mrna for + % the estimation. The data is from figure 1 of the paper: + % Gene Circuit Performance Characterization and Resource Usage in a + % Cell-Free “Breadboard” by Siegal-Gaskins et al. + % + % mcmc_info struct. Written for concurrent multi + % model - experiment parameter inference. + % This mcmc info has parameter inference from two experiments: + % 1) rna degradation using purified dna + % 2) translation + transcription + rna degradation + % + % mcmc_info has the following substructures: + % + % runsim_info: information on the mcmc algorithm parameters + % model_info: array of models, and associated properties like parameters, + % and the matrices of indices from the master vector + % to the model parameters. + % master_info: contains the master vector, and a spec for which parameters + % get estimated. + % + % Copyright (c) 2018, Vipul Singhal, Caltech + % Permission is hereby granted, free of charge, to any person obtaining a copy + % of this software and associated documentation files (the "Software"), to deal + % in the Software without restriction, including without limitation the rights + % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + % copies of the Software, and to permit persons to whom the Software is + % furnished to do so, subject to the following conditions: + + % The above copyright notice and this permission notice shall be included in all + % copies or substantial portions of the Software. + + % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + % SOFTWARE. + + % User readable description of the circuit. Will be used in the log file generated + % from the MCMC inference procedure. + + +% List of all parameters +% {'TX_elong_glob' +% 'AGTPdeg_time' +% 'AGTPdeg_rate' +% 'AGTPreg_ON' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_P70_RNAPbound_F' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_1_F' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_NTP_RNAP_2_F' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_F' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_PROT_deGFP_MATURATION' +% 'TXTL_UTR_UTR1_Kd' +% 'TXTL_UTR_UTR1_F' +% 'TL_AA_Kd' +% 'TL_AA_F' +% 'TL_AGTP_Kd' +% 'TL_AGTP_F' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo'}; + + % paramters to estimate: +% 'TX_elong_glob' +% 'AGTPdeg_time' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_UTR_UTR1_Kd' +% 'TL_AA_Kd' +% 'TL_AGTP_Kd' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo' + +% and in repeat 2, drop 'TL_AA_Kd', 'TL_AGTP_Kd' +% 'TXTL_NTP_RNAP_1_Kd', 'TXTL_NTP_RNAP_2_Kd' + + circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + + circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + + %{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' 2000 [100 10000] + 'TXTL_RNAdeg_F' 0.02 [0.01 100] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] + 'RNase' 100 [10 1000]}; + activeNames2 = {... + 'TX_elong_glob' 10.5 [0.5 30] + 'AGTPdeg_time' 7200 [1800 18000] + 'AGTPdeg_rate' 0.0002 [1e-5 1e-2] + 'AGTPreg_ON' 0.02 [0.005 0.2] + 'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] + 'TXTL_P70_RNAPbound_F' 20 [1e-5 100] + 'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] + 'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] + 'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] + 'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] + 'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] + 'TXTL_RNAdeg_Kd' 2000 [100 10000] + 'TXTL_RNAdeg_F' 0.01 [0.1 1000] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] + 'RNAP' 100 [5 500] + 'RNase' 100 [10 1000] + 'TL_elong_glob' 20 [4 200] + 'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] + 'TXTL_UTR_UTR1_Kd' 20 [1 1e5] + 'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] + 'TL_AA_Kd' 100000 [10 1e8] + 'TL_AA_F' 0.001 [1e-5 1] + 'TL_AGTP_Kd' 100000 [1e2 1e8] + 'TL_AGTP_F' 1e-5 [1e-7 1] + 'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] + 'Ribo' 30 [5 1000]}; + + + + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 5:17 19:26 ]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + masterVector = zeros(length(activeNames2), 1); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + +%% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; + +%% create the measured species cell array +measuredSpecies = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:2AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:2AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; +msIx1 = 1; % this is the index of the measured species in the data array +% from data_dsg2014. There are two species: 1: mRNA and 2: GFP. +msIx2 = [1,2]; + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 50; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 20; % actual: 2 - 30 ish, +npoints = 1e3; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 2; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 1 + varargout{1} = activeNames2; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_C.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_C.m new file mode 100755 index 0000000..6e63fc3 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_C.m @@ -0,0 +1,388 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_C(modelObj) + % Define the mcmc_info struct for the dsg2014 dataset, for the estimation + % of the mrna parameters, using only measurements of the mrna for + % the estimation. The data is from figure 1 of the paper: + % Gene Circuit Performance Characterization and Resource Usage in a + % Cell-Free “Breadboard” by Siegal-Gaskins et al. + % + % This file is different from mcmc_info_dsg2014_regen_A in that the + % forward rate parameters are all fixed here, hopefully making the mcmc + % estimation problem significantly more tractable! (23 dimensions in + % the A version of this file is very non-trivial to search, due to the + % curse of dimensionality. + % + % mcmc_info struct. Written for concurrent multi + % model - experiment parameter inference. + % This mcmc info has parameter inference from two experiments: + % 1) rna degradation using purified dna + % 2) transcription + rna degradation + % + % mcmc_info has the following substructures: + % + % runsim_info: information on the mcmc algorithm parameters + % model_info: array of models, and associated properties like parameters, + % and the matrices of indices from the master vector + % to the model parameters. + % master_info: contains the master vector, and a spec for which parameters + % get estimated. + % + % Copyright (c) 2018, Vipul Singhal, Caltech + % Permission is hereby granted, free of charge, to any person obtaining a copy + % of this software and associated documentation files (the "Software"), to deal + % in the Software without restriction, including without limitation the rights + % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + % copies of the Software, and to permit persons to whom the Software is + % furnished to do so, subject to the following conditions: + + % The above copyright notice and this permission notice shall be included in all + % copies or substantial portions of the Software. + + % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + % SOFTWARE. + + % User readable description of the circuit. Will be used in the log file generated + % from the MCMC inference procedure. + + +% List of all parameters +% {'TX_elong_glob' +% 'AGTPdeg_time' +% 'AGTPdeg_rate' +% 'AGTPreg_ON' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_P70_RNAPbound_F' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_1_F' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_NTP_RNAP_2_F' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_F' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_PROT_deGFP_MATURATION' +% 'TXTL_UTR_UTR1_Kd' +% 'TXTL_UTR_UTR1_F' +% 'TL_AA_Kd' +% 'TL_AA_F' +% 'TL_AGTP_Kd' +% 'TL_AGTP_F' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo'}; + + % paramters to estimate: +% 'TX_elong_glob' +% 'AGTPdeg_time' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_UTR_UTR1_Kd' +% 'TL_AA_Kd' +% 'TL_AGTP_Kd' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo' + +% and in repeat 2, drop 'TL_AA_Kd', 'TL_AGTP_Kd' +% 'TXTL_NTP_RNAP_1_Kd', 'TXTL_NTP_RNAP_2_Kd' + + circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + + circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + + %{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + + activeNames2 = {... + 'TX_elong_glob' 10.5 [0.5 100] %1 + 'AGTPdeg_time' 7200 [1800 42000] + 'AGTPdeg_rate' 0.0002 [1e-5 1e-2] + 'AGTPreg_ON' 0.02 [0.005 0.2] %4 + 'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] + 'TXTL_P70_RNAPbound_F' 20 [1e-3 100] + 'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] %7 + 'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] + 'TXTL_NTP_RNAP_1_F' 5 [1e-3 100] + 'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] %10 + 'TXTL_NTP_RNAP_2_F' 5 [1e-3 100] + 'TXTL_RNAdeg_Kd' 2000 [100 10000] + 'TXTL_RNAdeg_F' 5 [0.1 100] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] %14 + 'RNAP' 100 [5 500] + 'RNase' 100 [10 1000] + 'TL_elong_glob' 20 [4 200] %17 + 'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] + 'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] + 'TXTL_UTR_UTR1_F' 5 [1e-3 100] %20 + 'TL_AA_Kd' 100000 [10 1e8] + 'TL_AA_F' 5 [1e-3 100] + 'TL_AGTP_Kd' 100000 [1e2 1e8] %23 + 'TL_AGTP_F' 5 [1e-3 100] + 'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] + 'Ribo' 30 [5 1000]}; + activeNames1 = activeNames2([12:14 16],:) + + +% {... +% 'TXTL_RNAdeg_Kd' 2000 [100 10000] +% 'TXTL_RNAdeg_F' 0.01 [0.01 100] +% 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] +% 'RNase' 100 [10 1000]}; + + + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 5 7 8 10 12 14 15 16 17 19 21 23 25 26]'; + + +% Skipping the following: +% activeNames2(setdiff(1:26, estParamsIX),:) +% +% ans = +% +% 103 cell array +% +% {'AGTPdeg_rate' } {[2.0000e-04]} {12 double} +% {'AGTPreg_ON' } {[ 0.0200]} {12 double} +% {'TXTL_P70_RNAPbo?'} {[ 20]} {12 double} +% {'TXTL_NTP_RNAP_1_F'} {[1.0000e-04]} {12 double} +% {'TXTL_NTP_RNAP_2_F'} {[1.0000e-05]} {12 double} +% {'TXTL_RNAdeg_F' } {[ 0.0100]} {12 double} +% {'TXTL_PROT_deGFP?'} {[ 0.0023]} {12 double} +% {'TXTL_UTR_UTR1_F' } {[ 0.2000]} {12 double} +% {'TL_AA_F' } {[1.0000e-03]} {12 double} +% {'TL_AGTP_F' } {[1.0000e-05]} {12 double} + + estParams = activeNames2(estParamsIX,1); + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = zeros(length(activeNames2), 1); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimenesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + +%% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; + dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; + dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = dtempvec/(sum(dtempvec)); +%% create the measured species cell array +% remember to change this! esp the 2AGTP. +measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + +measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; +msIx1 = 1; % this is the index of the measured species in the data array +% from data_dsg2014. There are two species: 1: mRNA and 2: GFP. +msIx2 = [1,2]; + +%% setup the MCMC simulation parameters +stdev = 100; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 300; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 10; % actual: 2 - 30 ish, +npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + +model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {0.1, 1}, ... + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. weight the rnadeg + ...% experiment to be 20% as important as the MGA-GFP experiment + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +% estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + +if nargout == 1 + varargout{1} = activeNames2; + +end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_C1.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_C1.m new file mode 100755 index 0000000..d7b7b11 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_C1.m @@ -0,0 +1,375 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_C1(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. + + +% List of all parameters +% {'TX_elong_glob' +% 'AGTPdeg_time' +% 'AGTPdeg_rate' +% 'AGTPreg_ON' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_P70_RNAPbound_F' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_1_F' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_NTP_RNAP_2_F' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_F' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_PROT_deGFP_MATURATION' +% 'TXTL_UTR_UTR1_Kd' +% 'TXTL_UTR_UTR1_F' +% 'TL_AA_Kd' +% 'TL_AA_F' +% 'TL_AGTP_Kd' +% 'TL_AGTP_F' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo'}; + +% paramters to estimate: +% 'TX_elong_glob' +% 'AGTPdeg_time' +% 'TXTL_P70_RNAPbound_Kd' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' +% 'TXTL_NTP_RNAP_1_Kd' +% 'TXTL_NTP_RNAP_2_Kd' +% 'TXTL_RNAdeg_Kd' +% 'TXTL_RNAdeg_kc' +% 'RNAP' +% 'RNase' +% 'TL_elong_glob' +% 'TXTL_UTR_UTR1_Kd' +% 'TL_AA_Kd' +% 'TL_AGTP_Kd' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' +% 'Ribo' + +% and in repeat 2, drop 'TL_AA_Kd', 'TL_AGTP_Kd' +% 'TXTL_NTP_RNAP_1_Kd', 'TXTL_NTP_RNAP_2_Kd' + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' 2000 [100 1e5] + 'TXTL_RNAdeg_F' 0.01 [0.01 10000] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] + 'RNase' 100 [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' 10.5 [0.5 300] % 1 + 'AGTPdeg_time' exp(9.57) [1800 42000] % DO NOT FIX THIS. + 'AGTPdeg_rate' 0.0002 [1e-5 1e-2] % set from before + 'AGTPreg_ON' 0.02 [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' 200 [0.1 1e6] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] % 7 + 'TXTL_NTP_RNAP_1_Kd' 100000 [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' 1e6 [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' 2000 [100 1e5] + 'TXTL_RNAdeg_F' 1 [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-5.4) [1e-4 1] %set to exp(-5.4) + 'RNAP' 100 [5 5000] % 15 + 'RNase' 100 [1 10000] + 'TL_elong_glob' 20 [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' 100000 [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' 100000 [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 20000] + 'Ribo' 30 [10 10000]}; %26 + + + + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 5 7 8 10 12 15 16 17 19 21 23 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.01}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_D.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_D.m new file mode 100755 index 0000000..5386343 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_D.m @@ -0,0 +1,357 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_D(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] + 'RNase' exp(6.4899) [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. + 'AGTPdeg_rate' exp(-9.5172) [1e-5 1e-2] % set from before + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] %set to exp(-5.4) + 'RNAP' exp(1.4419) [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 10000] + 'TL_elong_glob' exp(0.5219) [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] + 'Ribo' exp(7.3081) [10 10000]}; %26 + + % +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. + +% 1. The minimal sim (regen_D) +% also fix: +% {'TXTL_RNAdeg_Kd' } +% and the AGTP params: +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% leaving only + + +% {'TXTL_RNAdeg_kc' } +% {'RNase' } +% {'TX_elong_glob' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'RNAP' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% 10 parameters to estimate. + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 5 7 14 15 16 17 19 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.3}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_E.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_E.m new file mode 100755 index 0000000..84ab683 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_E.m @@ -0,0 +1,356 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_E(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] + 'RNase' exp(6.4899) [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. + 'AGTPdeg_rate' exp(-9.5172) [1e-5 1e-2] % set from before + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] %set to exp(-5.4) + 'RNAP' exp(1.4419) [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 10000] + 'TL_elong_glob' exp(0.5219) [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] + 'Ribo' exp(7.3081) [10 10000]}; %26 + + % +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. + +% 2. regen_E: +% fix the AGTP params: +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% leaving only + +% {'TX_elong_glob' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNase' } +% {'RNAP' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% 11 parameters to estimate. RNA deg here allows the algorithm to tune the RNA timescale. + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 5 7 12 14 15 16 17 19 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.3}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_F.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_F.m new file mode 100755 index 0000000..98b505f --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_F.m @@ -0,0 +1,353 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_F(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] + 'RNase' exp(6.4899) [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. + 'AGTPdeg_rate' exp(-9.5172) [1e-5 1e-2] % set from before + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] %set to exp(-5.4) + 'RNAP' exp(1.4419) [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 10000] + 'TL_elong_glob' exp(0.5219) [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] + 'Ribo' exp(7.3081) [10 10000]}; %26 + + % +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. + +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.3}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_F1.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_F1.m new file mode 100755 index 0000000..76fcbb5 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_F1.m @@ -0,0 +1,353 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_F1(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] + 'RNase' exp(6.4899) [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. + 'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % set from before + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 1e7] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 1000] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] %set to exp(-5.4) + 'RNAP' exp(1.4419) [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 10000] + 'TL_elong_glob' exp(0.5219) [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.05 1e7] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] + 'Ribo' exp(7.3081) [10 10000]}; %26 + + % +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. + +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.3}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_G.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_G.m new file mode 100755 index 0000000..dba01d6 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_G.m @@ -0,0 +1,357 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_G(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] + 'RNase' exp(6.4899) [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. + 'AGTPdeg_rate' exp(-9.5172) [1e-5 1e-2] % set from before + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] %set to exp(-5.4) + 'RNAP' exp(1.4419) [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 10000] + 'TL_elong_glob' exp(0.5219) [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] + 'Ribo' exp(7.3081) [10 10000]}; %26 + + +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } + +% are fixed at the values above. + +% 1. The minimal sim (regen_D) +% also fix the remaining rna deg params +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNase' } +% and the AGTP params: +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% leaving only + +% {'TX_elong_glob' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'RNAP' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 5 15 17 19 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo2},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_H.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_H.m new file mode 100755 index 0000000..11d5443 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_H.m @@ -0,0 +1,322 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_H(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] + 'RNase' exp(6.4899) [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) [1800 42000] + 'AGTPdeg_rate' exp(-9.5172) [1e-6 1e-1] + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] % + 'RNAP' exp(1.4419) [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 10000] + 'TL_elong_glob' exp(0.5219) [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0001 0.2] %18 + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] % + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] + 'Ribo' exp(7.3081) [1 10000]}; %26 + + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 3 4 5 7 8 10 12 14 15 16 17 18 19 21 23 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.6}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_I.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_I.m new file mode 100755 index 0000000..39bdb5c --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_dsg2014_regen_I.m @@ -0,0 +1,322 @@ +function [mcmc_info, varargout] = mcmc_info_dsg2014_regen_I(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] + 'RNase' exp(6.4899) [1 10000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) [1800 42000] + 'AGTPdeg_rate' exp(-9.5172) [1e-6 1e-1] + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] % + 'RNAP' exp(1.4419) [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 10000] + 'TL_elong_glob' exp(0.5219) [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0001 0.2] %18 + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] % + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] + 'Ribo' exp(7.3081) [1 10000]}; %26 + + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 3 4 5 7 12 14 15 16 17 18 19 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.6}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_test015.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015.m new file mode 100755 index 0000000..299970b --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015.m @@ -0,0 +1,227 @@ +function mcmc_info = mcmc_info_test015(modelObj) +% mcmc_info_constgfp3ii.m +% This file contains information on how to set up a constitutive GFP +% experiment using the Simbiology model generated by the function +% model_protein3. It is a simple example of the concurrent +% parameter inference problem, which involves a single circuit (i.e., one +% topology) being run in two different environments. Thus, the two models +% (one in each environment) should have different values estimated for the +% environment specific parameters, but the same value for the circuit +% specific parameters. In this sense, we have two geometries (type +% help mcmc_info in the command window for more information on topologies +% and geometries).that jointly estimate the circuit specific parameters +% but estimate individual values for the environment specific parameters +% between the two geometries. The mcmc_info struct generated by this file +% is to be used with the following project files: +% +% proj_protein_constgfp3ii.m +% proj_protein_constgfp3ii_function.m +% proj_mcmc_tutorial_II.m +% +% +% The model to be used is set up by the file model_protein3.m in the +% models_and_supporting_files directory, and has equations +% +% % dG + pol <-> dG_pol (kf, kr) +% dG_pol -> dG + pol + pG (kc) +% +% where dG is the GFP protein DNA, pol is a species signifying the +% transcription and translation machinery, and pG is the GFP protein output +% of the model. +% +% In the experiment, the initial dG concentration is set to different +% values (10, 30 and 60). I.e., the dosedNames in mcmc_info.model_info +% has a single species 'dG' in it, and the dosedVals is the row vector +% [10 30 60]. For each dose, the corresponding pG trajectories are +% measured. In the parameter inference problem, these simulated model +% trajectories are compared to artificial 'data' trajectories obtained from +% simulating the model. +% +% We fix kf to 5, and estimate the rest of the parameters. The circuit (i.e. +% part) specific parameter is kr, and this gets jointly estimated between the +% two models (one model in each environment) and the environment specific +% parameters are the initial concentration of pol, and the rate kc, and +% each environment has its own value for these. Thus, there are six +% parameters in the master vector, (kf, kr, kc1, kc2, pol1, pol2), of which +% the first is fixed at a value of 5, and the remaining five are to be +% estimated. Also, the first two parameters (kf and kr) are to be shared +% between the two topologies, while the remaining 4 are to be applied to +% individual topologies as defined by the paramMaps in the code below. +% +% Type help mcmc_info to read more about the mcmc_info struct array. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [' D + pol <-> D__pol (k_f, k_r \n'... ) + 'D__pol -> D + pol + protien (kc)\n'... + 'single topology, two geometries.']; + +rkfdG = 1; % nM-1s-1 +rkrdG = 1; % s-1 +rkcp1 = 1; %s-1 +rkcp2 = 1; %s-1 +cpol1 = 1; % nM +cpol2 = 1; % nM + +namesUnord = ... + {'kfdG' + 'krdG' + 'kcp' + 'pol'}; + +estParams = {'kfdG' + 'krdG' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% fixedParams vector +fixedParams = []; % just the rkfdG parameter is fixed + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% There are two geometries for this topology, and so two columns in the +% paramMaps field of the model_info struct. +paramMap1 = [1 2 3 5]'; +paramMap2 = [1 2 4 6]'; +paramMap = [paramMap1 paramMap2]; + +% log transformed parameter ranges +paramRanges = [masterVector(estParamsIx)-15 masterVector(estParamsIx)+10]; + +% The two geometries map to the first and second elements of the data_info +% struct array. +dataIndices = [1 3]; + +%% next we define the dosing strategy. +dosedNames = {'dG'}; +dosedVals = [1 2 5 10 20]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 400; % the standard deviation in the likelihood function. + +tightening = 1; % default is 1. Type in help mcmc_info for more information + +nW = 1200; % number of walkers. good values: 200 - 400 + +stepsize = 1.15; % MCMC step size. try: 1.1 to 4 ish. DO NOT USE 1. + +niter = 20; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" + +npoints = 1200*10*10; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + +% params is small) + +thinning = 1; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {namesUnord}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +%% IGNORE this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. + +% Note to self (please ignore this). I tried the following: +% semanticGroups = {1, [2 4] [3 5]}; % cant do this, then the points never +% get differentiated at all. need some jitter I think. think about this.... +semanticGroups = num2cell((1:length(estParams))'); +%num2cell((1:5)'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_E1E2same.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_E1E2same.m new file mode 100755 index 0000000..cac44a6 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_E1E2same.m @@ -0,0 +1,227 @@ +function mcmc_info = mcmc_info_test015_E1E2same(modelObj) +% mcmc_info_constgfp3ii.m +% This file contains information on how to set up a constitutive GFP +% experiment using the Simbiology model generated by the function +% model_protein3. It is a simple example of the concurrent +% parameter inference problem, which involves a single circuit (i.e., one +% topology) being run in two different environments. Thus, the two models +% (one in each environment) should have different values estimated for the +% environment specific parameters, but the same value for the circuit +% specific parameters. In this sense, we have two geometries (type +% help mcmc_info in the command window for more information on topologies +% and geometries).that jointly estimate the circuit specific parameters +% but estimate individual values for the environment specific parameters +% between the two geometries. The mcmc_info struct generated by this file +% is to be used with the following project files: +% +% proj_protein_constgfp3ii.m +% proj_protein_constgfp3ii_function.m +% proj_mcmc_tutorial_II.m +% +% +% The model to be used is set up by the file model_protein3.m in the +% models_and_supporting_files directory, and has equations +% +% % dG + pol <-> dG_pol (kf, kr) +% dG_pol -> dG + pol + pG (kc) +% +% where dG is the GFP protein DNA, pol is a species signifying the +% transcription and translation machinery, and pG is the GFP protein output +% of the model. +% +% In the experiment, the initial dG concentration is set to different +% values (10, 30 and 60). I.e., the dosedNames in mcmc_info.model_info +% has a single species 'dG' in it, and the dosedVals is the row vector +% [10 30 60]. For each dose, the corresponding pG trajectories are +% measured. In the parameter inference problem, these simulated model +% trajectories are compared to artificial 'data' trajectories obtained from +% simulating the model. +% +% We fix kf to 5, and estimate the rest of the parameters. The circuit (i.e. +% part) specific parameter is kr, and this gets jointly estimated between the +% two models (one model in each environment) and the environment specific +% parameters are the initial concentration of pol, and the rate kc, and +% each environment has its own value for these. Thus, there are six +% parameters in the master vector, (kf, kr, kc1, kc2, pol1, pol2), of which +% the first is fixed at a value of 5, and the remaining five are to be +% estimated. Also, the first two parameters (kf and kr) are to be shared +% between the two topologies, while the remaining 4 are to be applied to +% individual topologies as defined by the paramMaps in the code below. +% +% Type help mcmc_info to read more about the mcmc_info struct array. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [' D + pol <-> D__pol (k_f, k_r \n'... ) + 'D__pol -> D + pol + protien (kc)\n'... + 'single topology, two geometries.']; + +rkfdG = 1; % nM-1s-1 +rkrdG = 1; % s-1 +rkcp1 = 1; %s-1 +rkcp2 = 1; %s-1 +cpol1 = 1; % nM +cpol2 = 1; % nM + +namesUnord = ... + {'kfdG' + 'krdG' + 'kcp' + 'pol'}; + +estParams = {'kfdG' + 'krdG' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% fixedParams vector +fixedParams = []; % just the rkfdG parameter is fixed + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% There are two geometries for this topology, and so two columns in the +% paramMaps field of the model_info struct. +paramMap1 = [1 2 3 5]'; +paramMap2 = [1 2 4 6]'; +paramMap = [paramMap1 paramMap2]; + +% log transformed parameter ranges +paramRanges = [masterVector(estParamsIx)-15 masterVector(estParamsIx)+10]; + +% The two geometries map to the first and second elements of the data_info +% struct array. +dataIndices = [3 3]; + +%% next we define the dosing strategy. +dosedNames = {'dG'}; +dosedVals = [1 2 5 10 20]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 400; % the standard deviation in the likelihood function. + +tightening = 1; % default is 1. Type in help mcmc_info for more information + +nW = 1200; % number of walkers. good values: 200 - 400 + +stepsize = 1.15; % MCMC step size. try: 1.1 to 4 ish. DO NOT USE 1. + +niter = 20; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" + +npoints = 1200*10*10; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + +% params is small) + +thinning = 1; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {namesUnord}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +%% IGNORE this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. + +% Note to self (please ignore this). I tried the following: +% semanticGroups = {1, [2 4] [3 5]}; % cant do this, then the points never +% get differentiated at all. need some jitter I think. think about this.... +semanticGroups = num2cell((1:length(estParams))'); +%num2cell((1:5)'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1.m new file mode 100755 index 0000000..94c6353 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1.m @@ -0,0 +1,166 @@ +function mcmc_info = mcmc_info_test015_corr1(modelObj, rkcp, cpol) +% Single topology: tetR repression circuit +% 2 geometries (extracts) +% kf(s) fixed. +% Separate estimation of ESPs and CSPs. +% +% ~~~ MODEL ~~~ +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [ 'D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT, kcpT) \n'... + 'D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG, kcpG) \n'... + '2 T <-> T2 (kfdim, krdim)\n'... + 'D_G + T2 <-> D_G:T2 (kfseq, krseq) \n'... + 'single topology, single geometry.']; + +%cpol = exp(1.0212); % nM +rkfdG = 1; % nM-1s-1 +rkrdG = 1; % s-1 +rkfdT =1; +rkrdT = 1; +%rkcp = exp( -7.6000); %s-1 +rkfdimTet = 1; % nM-1s-1 +rkrdimTet = 1; % s-1 +rkfseqTet = 1; % nM-1s-1 +rkrseqTet = 1; % s-1 + +activeNames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kcp' + 'pol'}; + +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); +% fixedParams vector +fixedParams = [9 10]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet'}; + +paramMap = [1:length(masterVector)]'; +paramRanges = [masterVector(estParamsIx)-20 masterVector(estParamsIx)+15]; + + +dataIndices = [6]; + +%% next we define the dosing strategy. +dosedNames = {'dT'; 'dG'}; +dosedVals = flipud([ 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 + 0 0.2500 0.5000 0.7500 1.0000 2.0000 5.0000 10.0000]); + + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 20; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... %paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix.m new file mode 100755 index 0000000..c40692e --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix.m @@ -0,0 +1,192 @@ +function mcmc_info = mcmc_info_test015_corr1_Ffix(modelObj, rkcp, cpol) +% Single topology: tetR repression circuit +% 2 geometries (extracts) +% kf(s) fixed. +% Separate estimation of ESPs and CSPs. +% +% ~~~ MODEL ~~~ +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [ 'D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT, kcpT) \n'... + 'D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG, kcpG) \n'... + '2 T <-> T2 (kfdim, krdim)\n'... + 'D_G + T2 <-> D_G:T2 (kfseq, krseq) \n'... + 'single topology, single geometry.']; + +% good starting values? seems like it! +% SimBiology Parameter Array +% +% Index: Name: Value: ValueUnits: +% 1 kfdT 1 +% 2 krdT 6 +% 3 kcp 0.012 +% 4 kfdG 1 +% 5 krdG 6 +% 6 kfdimTet 2 +% 7 krdimTet 4 +% 8 kfseqTet 2 +% 9 krseqTet 4 +% +% mobj.Parameters.Value +% Undefined function or variable 'Value'. +% +% mobj.Parameters(1).Value +% +% ans = +% +% 1 +% +% log([1 6 .012 1 6 2 4 2 4 100]) +% +% ans = +% +% 0 1.7918 -4.4228 0 1.7918 0.6931 1.3863 0.6931 1.3863 4.6052 + +%cpol = exp(1.0212); % nM +rkfdG = 1; % nM-1s-1 +rkrdG = 6; % s-1 +rkfdT = 1; % +rkrdT = 6; +%rkcp = exp( -7.6000); %s-1 +rkfdimTet = 2; % nM-1s-1 +rkrdimTet = 4; % s-1 +rkfseqTet = 2; % nM-1s-1 +rkrseqTet = 4; % s-1 + +activeNames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kcp' + 'pol'}; + +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); +% fixedParams vector +fixedParams = [5 9 10]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = activeNames(estParamsIx); %{'kfdG' +% 'krdG' +% 'krdT' +% 'krdimTet' +% 'krseqTet'}; + +paramMap = [1:length(masterVector)]'; +paramRanges = [masterVector(estParamsIx)-10 masterVector(estParamsIx)+5]; + + +dataIndices = [6]; + +%% next we define the dosing strategy. +dosedNames = {'dT'; 'dG'}; +dosedVals = flipud([ 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 + 0 0.2500 0.5000 0.7500 1.0000 2.0000 5.0000 10.0000]); + + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 20; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... %paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix2.m new file mode 100755 index 0000000..60cbdfa --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix2.m @@ -0,0 +1,192 @@ +function mcmc_info = mcmc_info_test015_corr1_Ffix2(modelObj, rkcp, cpol) +% Single topology: tetR repression circuit +% 2 geometries (extracts) +% kf(s) fixed. +% Separate estimation of ESPs and CSPs. +% +% ~~~ MODEL ~~~ +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [ 'D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT, kcpT) \n'... + 'D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG, kcpG) \n'... + '2 T <-> T2 (kfdim, krdim)\n'... + 'D_G + T2 <-> D_G:T2 (kfseq, krseq) \n'... + 'single topology, single geometry.']; + +% good starting values? seems like it! +% SimBiology Parameter Array +% +% Index: Name: Value: ValueUnits: +% 1 kfdT 1 +% 2 krdT 6 +% 3 kcp 0.012 +% 4 kfdG 1 +% 5 krdG 6 +% 6 kfdimTet 2 +% 7 krdimTet 4 +% 8 kfseqTet 2 +% 9 krseqTet 4 +% +% mobj.Parameters.Value +% Undefined function or variable 'Value'. +% +% mobj.Parameters(1).Value +% +% ans = +% +% 1 +% +% log([1 6 .012 1 6 2 4 2 4 100]) +% +% ans = +% +% 0 1.7918 -4.4228 0 1.7918 0.6931 1.3863 0.6931 1.3863 4.6052 + +%cpol = exp(1.0212); % nM +rkfdG = 1; % nM-1s-1 +rkrdG = 6; % s-1 +rkfdT = 1; % +rkrdT = 6; +%rkcp = exp( -7.6000); %s-1 +rkfdimTet = 2; % nM-1s-1 +rkrdimTet = 4; % s-1 +rkfseqTet = 2; % nM-1s-1 +rkrseqTet = 4; % s-1 + +activeNames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kcp' + 'pol'}; + +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); +% fixedParams vector +fixedParams = [1 3 5 7 9 10]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = activeNames(estParamsIx); %{'kfdG' +% 'krdG' +% 'krdT' +% 'krdimTet' +% 'krseqTet'}; + +paramMap = [1:length(masterVector)]'; +paramRanges = [masterVector(estParamsIx)-10 masterVector(estParamsIx)+5]; + + +dataIndices = [6]; + +%% next we define the dosing strategy. +dosedNames = {'dT'; 'dG'}; +dosedVals = flipud([ 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 + 0 0.2500 0.5000 0.7500 1.0000 2.0000 5.0000 10.0000]); + + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 20; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... %paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix3.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix3.m new file mode 100755 index 0000000..d51b1f1 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_corr1_Ffix3.m @@ -0,0 +1,192 @@ +function mcmc_info = mcmc_info_test015_corr1_Ffix3(modelObj, rkcp, cpol) +% Single topology: tetR repression circuit +% 2 geometries (extracts) +% kf(s) fixed. +% Separate estimation of ESPs and CSPs. +% +% ~~~ MODEL ~~~ +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [ 'D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT, kcpT) \n'... + 'D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG, kcpG) \n'... + '2 T <-> T2 (kfdim, krdim)\n'... + 'D_G + T2 <-> D_G:T2 (kfseq, krseq) \n'... + 'single topology, single geometry.']; + +% good starting values? seems like it! +% SimBiology Parameter Array +% +% Index: Name: Value: ValueUnits: +% 1 kfdT 1 +% 2 krdT 6 +% 3 kcp 0.012 +% 4 kfdG 1 +% 5 krdG 6 +% 6 kfdimTet 2 +% 7 krdimTet 4 +% 8 kfseqTet 2 +% 9 krseqTet 4 +% +% mobj.Parameters.Value +% Undefined function or variable 'Value'. +% +% mobj.Parameters(1).Value +% +% ans = +% +% 1 +% +% log([1 6 .012 1 6 2 4 2 4 100]) +% +% ans = +% +% 0 1.7918 -4.4228 0 1.7918 0.6931 1.3863 0.6931 1.3863 4.6052 + +%cpol = exp(1.0212); % nM +rkfdG = 1; % nM-1s-1 +rkrdG = 6; % s-1 +rkfdT = 1; % +rkrdT = 6; +%rkcp = exp( -7.6000); %s-1 +rkfdimTet = 1; % nM-1s-1 +rkrdimTet = 4; % s-1 +rkfseqTet = 1; % nM-1s-1 +rkrseqTet = 4; % s-1 + +activeNames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kcp' + 'pol'}; + +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); +% fixedParams vector +fixedParams = [3 5 7 9 10]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = activeNames(estParamsIx); %{'kfdG' +% 'krdG' +% 'krdT' +% 'krdimTet' +% 'krseqTet'}; + +paramMap = [1:length(masterVector)]'; +paramRanges = [masterVector(estParamsIx)-10 masterVector(estParamsIx)+5]; + + +dataIndices = [6]; + +%% next we define the dosing strategy. +dosedNames = {'dT'; 'dG'}; +dosedVals = flipud([ 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 + 0 0.2500 0.5000 0.7500 1.0000 2.0000 5.0000 10.0000]); + + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 20; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... %paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_kfdgfix.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_kfdgfix.m new file mode 100755 index 0000000..c0ae13a --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_test015_kfdgfix.m @@ -0,0 +1,226 @@ +function mcmc_info = mcmc_info_test015_kfdgfix(modelObj) +% mcmc_info_constgfp3ii.m +% This file contains information on how to set up a constitutive GFP +% experiment using the Simbiology model generated by the function +% model_protein3. It is a simple example of the concurrent +% parameter inference problem, which involves a single circuit (i.e., one +% topology) being run in two different environments. Thus, the two models +% (one in each environment) should have different values estimated for the +% environment specific parameters, but the same value for the circuit +% specific parameters. In this sense, we have two geometries (type +% help mcmc_info in the command window for more information on topologies +% and geometries).that jointly estimate the circuit specific parameters +% but estimate individual values for the environment specific parameters +% between the two geometries. The mcmc_info struct generated by this file +% is to be used with the following project files: +% +% proj_protein_constgfp3ii.m +% proj_protein_constgfp3ii_function.m +% proj_mcmc_tutorial_II.m +% +% +% The model to be used is set up by the file model_protein3.m in the +% models_and_supporting_files directory, and has equations +% +% % dG + pol <-> dG_pol (kf, kr) +% dG_pol -> dG + pol + pG (kc) +% +% where dG is the GFP protein DNA, pol is a species signifying the +% transcription and translation machinery, and pG is the GFP protein output +% of the model. +% +% In the experiment, the initial dG concentration is set to different +% values (10, 30 and 60). I.e., the dosedNames in mcmc_info.model_info +% has a single species 'dG' in it, and the dosedVals is the row vector +% [10 30 60]. For each dose, the corresponding pG trajectories are +% measured. In the parameter inference problem, these simulated model +% trajectories are compared to artificial 'data' trajectories obtained from +% simulating the model. +% +% We fix kf to 5, and estimate the rest of the parameters. The circuit (i.e. +% part) specific parameter is kr, and this gets jointly estimated between the +% two models (one model in each environment) and the environment specific +% parameters are the initial concentration of pol, and the rate kc, and +% each environment has its own value for these. Thus, there are six +% parameters in the master vector, (kf, kr, kc1, kc2, pol1, pol2), of which +% the first is fixed at a value of 5, and the remaining five are to be +% estimated. Also, the first two parameters (kf and kr) are to be shared +% between the two topologies, while the remaining 4 are to be applied to +% individual topologies as defined by the paramMaps in the code below. +% +% Type help mcmc_info to read more about the mcmc_info struct array. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [' D + pol <-> D__pol (k_f, k_r \n'... ) + 'D__pol -> D + pol + protien (kc)\n'... + 'single topology, two geometries.']; + +rkfdG = exp(-4.3); % nM-1s-1 +rkrdG = 1; % s-1 +rkcp1 = 1; %s-1 +rkcp2 = 1; %s-1 +cpol1 = 1; % nM +cpol2 = 1; % nM + +namesUnord = ... + {'kfdG' + 'krdG' + 'kcp' + 'pol'}; + +estParams = {'krdG' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% fixedParams vector +fixedParams = [1]; % just the rkfdG parameter is fixed + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% There are two geometries for this topology, and so two columns in the +% paramMaps field of the model_info struct. +paramMap1 = [1 2 3 5]'; +paramMap2 = [1 2 4 6]'; +paramMap = [paramMap1 paramMap2]; + +% log transformed parameter ranges +paramRanges = [masterVector(estParamsIx)-15 masterVector(estParamsIx)+10]; + +% The two geometries map to the first and second elements of the data_info +% struct array. +dataIndices = [1 3]; + +%% next we define the dosing strategy. +dosedNames = {'dG'}; +dosedVals = [1 2 5 10 20]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 400; % the standard deviation in the likelihood function. + +tightening = 1; % default is 1. Type in help mcmc_info for more information + +nW = 1200; % number of walkers. good values: 200 - 400 + +stepsize = 1.15; % MCMC step size. try: 1.1 to 4 ish. DO NOT USE 1. + +niter = 20; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" + +npoints = 1200*10*10; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + +% params is small) + +thinning = 1; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {namesUnord}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +%% IGNORE this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. + +% Note to self (please ignore this). I tried the following: +% semanticGroups = {1, [2 4] [3 5]}; % cant do this, then the points never +% get differentiated at all. need some jitter I think. think about this.... +semanticGroups = num2cell((1:length(estParams))'); +%num2cell((1:5)'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_tetR_1i.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_tetR_1i.m new file mode 100755 index 0000000..e99eed9 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_tetR_1i.m @@ -0,0 +1,164 @@ +function mcmc_info = mcmc_info_tetR_1i(modelObj) +% Single topology: tetR repression circuit +% 2 geometries (extracts) +% kf(s) fixed. +% Separate estimation of ESPs and CSPs. +% +% ~~~ MODEL ~~~ +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [ 'D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT, kcpT) \n'... + 'D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG, kcpG) \n'... + '2 T <-> T2 (kfdim, krdim)\n'... + 'D_G + T2 <-> D_G:T2 (kfseq, krseq) \n'... + 'single topology, single geometry.']; + + +cpol = 100; % nM +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkfdT = 5; +rkrdT = 300; +rkcp = 0.012; %s-1 +rkfdimTet = 20; % nM-1s-1 +rkrdimTet = 10; % s-1 +rkfseqTet = 20; % nM-1s-1 +rkrseqTet = 10; % s-1 + +activeNames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kcp' + 'pol'}; + +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); +% fixedParams vector +fixedParams = [1 3 5 7]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = {'krdG' + 'krdT' + 'krdimTet' + 'krseqTet' + 'kcp' + 'pol'}; + +paramMap = [1:length(masterVector)]'; +paramRanges = [masterVector(estParamsIx)-3 masterVector(estParamsIx)+3]; + + +dataIndices = [1]; + +%% next we define the dosing strategy. +dosedNames = {'dT'; 'dG'}; +dosedVals = [0.5 0.5 0.5 2 2 2 8 8 8; + 10 30 60 10 30 60 10 30 60]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 20; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... %paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_tetR_1ii.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_tetR_1ii.m new file mode 100755 index 0000000..647a02e --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_tetR_1ii.m @@ -0,0 +1,170 @@ +function mcmc_info = mcmc_info_tetR_1ii(modelObj) +% Single topology: tetR repression circuit +% 2 geometries (extracts) +% kf(s) fixed. +% Separate estimation of ESPs and CSPs. +% +% ~~~ MODEL ~~~ +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [ 'D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT, kcpT) \n'... + 'D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG, kcpG) \n'... + '2 T <-> T2 (kfdim, krdim)\n'... + 'D_G + T2 <-> D_G:T2 (kfseq, krseq) \n'... + 'single topology, single geometry.']; + + +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkfdT = 5; +rkrdT = 300; +rkfdimTet = 20; % nM-1s-1 +rkrdimTet = 10; % s-1 +rkfseqTet = 20; % nM-1s-1 +rkrseqTet = 10; % s-1 +rkcp1 = 0.012; %s-1 +rkcp2 = 0.024; %s-1 +cpol1 = 100; % nM +cpol2 = 200; % nM +activeNames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kcp' + 'pol'}; + +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp1 +rkcp2 +cpol1 +cpol2]); +% fixedParams vector +fixedParams = [1 3 5 7]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = {'krdG' + 'krdT' + 'krdimTet' + 'krseqTet' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + +paramMap1 = [1:8 9 11]'; +paramMap2 = [1:8 10 12]'; +paramMap = [paramMap1, paramMap2]; +paramRanges = [masterVector(estParamsIx)-3 masterVector(estParamsIx)+3]; + +dataIndices = [1 2]; + +%% next we define the dosing strategy. +dosedNames = {'dT'; 'dG'}; +dosedVals = [0.5 0.5 0.5 2 2 2 8 8 8; + 10 30 60 10 30 60 10 30 60]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 10; % actual: 2 - 30 ish, +npoints = 2e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... %paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_calib.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_calib.m new file mode 100755 index 0000000..17dc41f --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_calib.m @@ -0,0 +1,195 @@ +function mcmc_info = mcmc_info_tierra2018_calib(modelObj) +% mcmc_info_tierra2018_calib.m +% Calibration: constitutive expression at 1, 2, 4, 8nM of pTet DNA +% Performed jointly over the two extracts. Initial try just set the kfdG +% to 1, and compute the krdG (along with the ESPs.) at the calibration +% step. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [' D + pol <-> D__pol (k_f, k_r \n'... ) + 'D__pol -> D + pol + protien (kc)\n'... + 'single topology, two geometries.']; + +namesUnord = ... + {'kfdG' + 'krdG' + 'kcp' + 'pol'}; + +estParams = {'krdG' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + +% !TODO notes: try to get starting numbers that get you close to the data in +% simulation. +% rkfdG = 5; % nM-1s-1 +% rkrdG = 300; % s-1 +% rkcp1 = 0.012; %s-1 +% rkcp2 = 0.024; %s-1 +% cpol1 = 100; % nM +% cpol2 = 200; % nM + +% changed to this because this is close the data. So we might be able to +% get much better fits this way. + +rkfdG = 10; % nM-1s-1 +rkrdG = 120; % s-1 +rkcp1 = 0.12; %s-1 +rkcp2 = 0.12;%0.24; %s-1 +cpol1 = 1.5; %4; % nM +cpol2 = 1.5; % nM + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% -0.6931 +% 3.4012 +% -2.1203 +% -1.4271 +% 1.3863 +% 0.4055 +% fixedParams vector +fixedParams = [1]; % just the rkfdG parameter is fixed + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% There are two geometries for this topology, and so two columns in the +% paramMaps field of the model_info struct. +paramMap1 = [1 2 3 5]'; +paramMap2 = [1 2 4 6]'; +paramMap = [paramMap1 paramMap2]; +lbshift = [-10;-8;-8;-8;-8];% [-8;-2;-5;-5;-5]; +ubshift = [+22;18;18;10;10];%[27;27;26;18;18]; +%lb and ub shifts are picked by looking at the corner plot. +% cornerplot20181105_112220_tierra_calib_t1.jpg + +% log transformed parameter ranges +paramRanges = [masterVector(estParamsIx)+lbshift... + masterVector(estParamsIx)+ubshift]; +exp(paramRanges) +% paramRanges = +% +% 10.6115 22.6115 +% -5.1203 11.8797 +% -1.9271 11.5729 +% 1.8863 9.3863 +% -0.5945 10.4055 + +% The two geometries map to the first and second elements of the data_info +% struct array. +dataIndices = [3 4]; % generated by the file data_info_tierra2018.m + +%% next we define the dosing strategy. +dosedNames = {'dG'}; +dosedVals = [1 2 4 8]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % the standard deviation in the likelihood function. + +tightening = 1; % default is 1. Type in help mcmc_info for more information + +nW = 400; % number of walkers. good values: 200 - 400 + +stepsize = 1.2; % MCMC step size. try: 1.1 to 4 ish. DO NOT USE 1. + +niter = 10; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" + +npoints = 8e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) + +thinning = 40; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {namesUnord}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices,... + 'doseWeighting', [6 3 1.5 1] ,... + 'experimentWeighting', 1); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +%% IGNORE this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. + +% Note to self (please ignore this). I tried the following: +% semanticGroups = {1, [2 4] [3 5]}; % cant do this, then the points never +% get differentiated at all. need some jitter I think. think about this.... +semanticGroups = num2cell((1:length(estParams))'); +%num2cell((1:5)'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_calib_B.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_calib_B.m new file mode 100755 index 0000000..9845e6a --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_calib_B.m @@ -0,0 +1,192 @@ +function mcmc_info = mcmc_info_tierra2018_calib_B(modelObj) +% mcmc_info_tierra2018_calib.m +% Calibration: constitutive expression at 1, 2, 4, 8nM of pTet DNA +% Performed jointly over the two extracts. Initial try just set the kfdG +% to 1, and compute the krdG (along with the ESPs.) at the calibration +% step. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + [' D + pol <-> D__pol (k_f, k_r \n'... ) + 'D__pol -> D + pol + protien (kc)\n'... + 'single topology, two geometries.']; + +namesUnord = ... + {'kfdG' + 'krdG' + 'kcp' + 'pol'}; + +estParams = {'kfdG' + 'krdG' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + +% !TODO notes: try to get starting numbers that get you close to the data in +% simulation. +% rkfdG = 5; % nM-1s-1 +% rkrdG = 300; % s-1 +% rkcp1 = 0.012; %s-1 +% rkcp2 = 0.024; %s-1 +% cpol1 = 100; % nM +% cpol2 = 200; % nM + +% changed to this because this is close the data. So we might be able to +% get much better fits this way. + +rkfdG = 10; % nM-1s-1 +rkrdG = 120; % s-1 +rkcp1 = 0.12; %s-1 +rkcp2 = 0.12;%0.24; %s-1 +cpol1 = 1.5; %4; % nM +cpol2 = 1.5; % nM + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% -0.6931 +% 3.4012 +% -2.1203 +% -1.4271 +% 1.3863 +% 0.4055 +% fixedParams vector +fixedParams = []; % just the rkfdG parameter is fixed + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +% There are two geometries for this topology, and so two columns in the +% paramMaps field of the model_info struct. +paramMap1 = [1 2 3 5]'; +paramMap2 = [1 2 4 6]'; +paramMap = [paramMap1 paramMap2]; +lbshift = [-18;-12;0;0;-5;-5];% [-8;-2;-5;-5;-5]; +ubshift = [+5;+24;22;22;15;15];%[27;27;26;18;18]; +%lb and ub shifts are picked by looking at the corner plot. +% cornerplot20181105_112220_tierra_calib_t1.jpg + +% log transformed parameter ranges +paramRanges = [masterVector(estParamsIx)+lbshift... + masterVector(estParamsIx)+ubshift]; +exp(paramRanges); +% paramRanges = +% +% 10.6115 22.6115 +% -5.1203 11.8797 +% -1.9271 11.5729 +% 1.8863 9.3863 +% -0.5945 10.4055 + +% The two geometries map to the first and second elements of the data_info +% struct array. +dataIndices = [3 4]; % generated by the file data_info_tierra2018.m + +%% next we define the dosing strategy. +dosedNames = {'dG'}; +dosedVals = [1 2 4 8]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % the standard deviation in the likelihood function. + +tightening = 2; % default is 1. Type in help mcmc_info for more information + +nW = 400; % number of walkers. good values: 200 - 400 + +stepsize = 1.2; % MCMC step size. try: 1.1 to 4 ish. DO NOT USE 1. + +niter = 40; % try: 2 - 50. Number of times to loop the MCMC. "help mcmc_info" + +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) + +thinning = 20; % good values: 10 to 40 ish. +% Number of steps to skip before recording positions of the walkers. + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {namesUnord}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % paramMap: matrix mapping elements in the + ... % master vector to the parameters or species given + ... % by active names for a given topology. + ... % Type help mcmc_info for more information. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices,... + 'doseWeighting', [1 1 1 1] ,... %[1*0.2 1/2*0.367 1/4*0.633 1/8] + 'experimentWeighting', 1); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +%% IGNORE this for now. It has a subtle use, and we will update the +% documentation to describe how this is used in a future release. +% Note to self (please ignore this). I tried the following: +% semanticGroups = {1, [2 4] [3 5]}; % cant do this, then the points never +% get differentiated at all. need some jitter I think. think about this.... +% semanticGroups = num2cell((1:length(estParams))'); +semanticGroups = {1; 2; [3, 4]; [5, 6]}; +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_corr.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_corr.m new file mode 100755 index 0000000..c13584f --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_tierra2018_corr.m @@ -0,0 +1,180 @@ +function mcmc_info = mcmc_info_tierra2018_corr(modelObj, esps, csps) +% mcmc_info_tierra2018_corr.m +% Correction: This is just an aTc induction model whose ESPs have been fixed by +% the calibration step and only the CSPs are estimated. +% The model used is found in the .m file: model_aTc_induc1.m +% There is no parameter sharing of any kind. +% The data corresponds to the extract eEC5, and the experimental conditions +% are +% 4 nM ptetO1-deGFP +% 0.4 nM placO1-tetR +% 10, 1, 0.1, 0.01, 0.001 uM aTc +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% User readable description of the circuit. Will be used in the log file generated +% from the MCMC inference procedure. +circuitInfo = ... + ['D_T + P <-> D_T:P -> D_T + P + T\n'... + 'D_G + P <-> D_G:P -> D_G + P + G\n'... + '2 T <-> T2\n'... + 'D_G + T2 <-> D_G:T2\n'... + '2 aTc <-> aTc2\n'... + 'aTc2 + T2 <-> aTc2:T2\n'... + 'single topology, single geometry.']; + +cpol = esps(2); % nM +rkfdG = 0.5; % nM-1s-1 +rkrdG = csps(1); % s-1 +rkfdT = .2; +rkrdT = 30; +rkcp = esps(1); %s-1 +rkfdimTet = .5; % nM-1s-1 +rkrdimTet = 20; % s-1 +rkfseqTet = .5; % nM-1s-1 +rkrseqTet = 20; % s-1 +% rkfdimaTc = .5; +% rkrdimaTc = 2; +rkfseqaTc = .5; +rkrseqaTc = 20; +activeNames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet' + 'kfseqaTc' + 'krseqaTc' + 'kcp' + 'pol'}; + +% 'kfdimaTc' +% 'krdimaTc' +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkfseqaTc +rkrseqaTc +rkcp +cpol]); +% rkfdimaTc +% rkrdimaTc + +% fixedParams vector +fixedParams = [1 3 5 7 9 11 12]; + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +estParams = {'krdG' + 'krdT' + 'krdimTet' + 'krseqTet' + 'rkrseqaTc'}; + % an 8 dimensional space gets searched. Initialize carefully (even 8 *can* be bad) +% 'rkrdimaTc' + + +paramMap = [1:length(masterVector)]'; +paramRanges = [masterVector(estParamsIx)-5 masterVector(estParamsIx)+5]; + + +dataIndices = [1]; + +%% next we define the dosing strategy. +dosedNames = {'dT'; 'dG'; 'aTc2'}; +dosedVals = [0.4 0.4 0.4 0.4 0.4; + 4 4 4 4 4; + 10000 1000 100 10 1]; + +measuredSpecies = {{'pG'}}; +msIx = 1; % + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = .1; % i have no idea what a good value is +nW = 200; % actual: 200 - 600 ish +stepsize = 1.4; % actual: 1.1 to 4 ish +niter = 10; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 20; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... %paramMap: matrix mapping models to master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an +% element of the model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... + 'fixedParams', {fixedParams},... + 'semanticGroups', {semanticGroups}); + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end + diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl2011.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl2011.m new file mode 100755 index 0000000..654b57c --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl2011.m @@ -0,0 +1,343 @@ +function mcmc_info = mcmc_info_vnprl2011(modelObj) + % version2 mcmc_info struct. Compatible with multimodel parameter inference. + % This mcmc info has two linked estimation problems: + % 1) mg aptamer and protein estimation (constitutive gene expression) + % 2) RNA degradation + % + % key differences with version 1: + % model parameters specified now include the ones to be estimated and the + % ones to keep fixed. + % split the old mcmc_info struct into 3 structs: + % runsim_info: information on the mcmc algorithm parameters + % model_info: array of models, and associated properties like parameters, + % and the matrices of indices from the master vector + % to the model parameters. + % master_info: contains the master vector, and a spec for which parameters + % get estimated. + % + % Copyright (c) 2018, Vipul Singhal, Caltech + % Permission is hereby granted, free of charge, to any person obtaining a copy + % of this software and associated documentation files (the "Software"), to deal + % in the Software without restriction, including without limitation the rights + % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + % copies of the Software, and to permit persons to whom the Software is + % furnished to do so, subject to the following conditions: + + % The above copyright notice and this permission notice shall be included in all + % copies or substantial portions of the Software. + + % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + % SOFTWARE. + + % User readable description of the circuit. Will be used in the log file generated + % from the MCMC inference procedure. + circuitInfo1 = ... + ['This is a simple constitutive gene expression model \n '... + 'built using the TXTL modeling toolbox. It models DNA binding \n '... + 'to RNAP and nucleotides, followed by transcription. The resulting\n '... + 'mRNA can degrade and participate in translation. The former is \n '... + 'modeled as a enzymatic reaction involving every complex containing \n '... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n '... + 'and ATP, and finally elongation and termination resulting in protein.']; + + + + %{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + + + + activeNames = {'TX_elong_glob' + 'AGTPdeg_time' + 'AGTPdeg_rate' + 'TXTL_P70_RNAPbound_Kd' + 'TXTL_P70_RNAPbound_F' + 'TXTL_RNAPBOUND_TERMINATION_RATE' + 'TXTL_NTP_RNAP_1_Kd' + 'TXTL_NTP_RNAP_1_F' + 'TXTL_NTP_RNAP_2_Kd' + 'TXTL_NTP_RNAP_2_F' + 'TXTL_RNAdeg_Kd' + 'TXTL_RNAdeg_F' + 'TXTL_RNAdeg_kc' + 'RNAP' + 'RNase' + 'TL_elong_glob' + 'TXTL_PROT_deGFP_MATURATION' + 'TXTL_UTR_UTR1_Kd' + 'TXTL_UTR_UTR1_F' + 'TL_AA_Kd' + 'TL_AA_F' + 'TL_AGTP_Kd' + 'TL_AGTP_F' + 'TXTL_RIBOBOUND_TERMINATION_RATE' + 'Ribo'}; + + +estParams = {'TL_elong_glob' + 'TXTL_PROT_deGFP_MATURATION' + 'TXTL_UTR_UTR1_Kd' + 'TXTL_UTR_UTR1_F' + 'TL_AA_Kd' + 'TL_AA_F' + 'TL_AGTP_Kd' + 'TL_AGTP_F' + 'TXTL_RIBOBOUND_TERMINATION_RATE' + 'Ribo'}; + + + + % get 10 sets of parameter values (= 10 points) from a previously estimated sims: + % get parameter values from a few different mcmc points from the runs of + % the file proj_acs_dsg2014_protein + marray = mcmc_get_walkers({'20180121_131114'}, {5}, ... + ['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/'... + 'mcmc_simbio/projects/proj_acs_dsg2014_mrna']); + + + nPrevPoints = 5; + minit = marray(:, ((end-nPrevPoints+1) : end), end); % Final set of walker positions. + minit = minit(:,:); % nparam x npoints, nparam is the tx params, ie, 15. npoints is 10. + + % fixedParams index vector + fixedParams = (1:numel(minit))'; + + % master vector + logp = zeros(10,1); + + masterVector = [minit(:) + logp]; % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology. + % + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + % + % + + TLparamIX = ((length(masterVector)-length(logp)+1) : length(masterVector))'; + paramMap = [reshape((1:numel(minit))', 15, numel(minit)/15); + repmat(TLparamIX, 1, numel(minit)/15)]; + + % parameter ranges for the logp (the parameters within the master vector that + % are to be estimated.) + + % 20180218_225205 -> 3 successful runs + % 20180219_021944 -> 10 successpul runs, comtinued from 20180218_225205 + % used: +% paramRanges = [4 8 +% -7 -3 +% -1 7 +% -3 3 +% -1 6 +% -1 6 +% -1 6 +% -1 6 +% -6 -1 +% 2 7]; + +% '20180219_154541', 10 successful runs, started from +% 20180219_021944, but with the parameter intiial points constrained to: + +% paramRanges = [5 8 +% -4 0 +% 0 6 +% -1 3 +% 0 6 +% 0 6 +% -1 6 +% -1 6 +% -1.5 2 +% 6 8]; + + +% New run '20180221_011619' started from 20180219_154541 but with the +% parameter intiial points constrained to: +% paramRanges = [3 8 +% -4 0 +% -2 8 +% -2 4 +% -2 8 +% -2 8 +% 4 8 +% -3 2 +% -1.5 -0.5 +% 3 9]; + +% New run _______ started from 20180221_011619 but with the +% parameter intiial points constrained to: +paramRanges = [5 9 + -4 0 + -2 10 + -1 3 + -2 10 + -3 10 + 2 7 + -3 4 + -1.2 -0.8 + 5 8]; + + +% data indices tell us which data set to use for each topology (model) - geometry pair +% from the data_info struct array. +% Here we have 1 model, and 10 geometries, all pointing to the same data: +% at data index 1 in the data_info array created by data_dsg2014.m +dataIndices = ones(nPrevPoints,1); + +%% next we define the dosing strategy. +dosedNames = {'DNA p70--utr1--deGFP'}; +dosedVals = [0.5 2 5 20]; + + +%% create the measured species cell array +% this is a 1x2 cell array. each element of this cell array contains +% further cell arrays. The first such cell array is a list of all the bound +% and free versions of the RNA. The second cell array contains a single +% cell, which contains the GFP string. +% all the species in the inner cell arrays get summed, and compared to the +% corresponding column (dimension 2) of the experimental data array. +measuredSpecies = {{'protein deGFP*'}}; +msIx = 2; % this is the index of the measured species in the data array +% from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.3; % actual: 1.1 to 4 ish +niter = 10; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 4; % actual: 10 to 40 ish + +%% pull all this together into an output struct. +% the mcmc info struct now is an array struct, the way struct should be used! + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +% for now we simply make the model_info have just one model (topology). +% But the code will be written in a way such that multiple models can be used. + +model_info = struct(... + 'circuitInfo',{circuitInfo1},... + 'modelObj', {modelObj},... % array of model objects (different topologies) + 'modelName', {modelObj.name},...; % model names. + 'namesUnord', {activeNames}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap}, ... % each paramMap is a matrix mapping models to the master vector. + 'dosedNames', {dosedNames},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx},... + 'dataToMapTo', dataIndices); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + + +semanticGroups = num2cell((1:10)'); %arrayfun(@num2str, 1:10, 'UniformOutput', false); + + +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParams},... % indexes of the parameters that are fixed (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their distinct + % groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl2011_mrna.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl2011_mrna.m new file mode 100755 index 0000000..af78ea8 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl2011_mrna.m @@ -0,0 +1,250 @@ +function mcmc_info = mcmc_info_vnprl2011_mrna(modelObj) + % version2 mcmc_info struct. Compatible with multimodel parameter inference. + % This mcmc info has two linked estimation problems: + % 1) transcription estimation + % 2) RNA degradation + % + % There is a second file in this series, mcmc_info_vnprl2011_protein, + % that tries to fit the protein data, with the mRNA parameters fixed to + % a few values found in this estimation. + % + % Finally there is a third file in this series that starts from all the + % parameters estimated in both the first and second estimations, and + % tries to fit all the parameters to all the data simultaneously within + % a relatively narrow range around the pre-fit parameters. + % + % Copyright (c) 2018, Vipul Singhal, Caltech + % Permission is hereby granted, free of charge, to any person obtaining a copy + % of this software and associated documentation files (the "Software"), to deal + % in the Software without restriction, including without limitation the rights + % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + % copies of the Software, and to permit persons to whom the Software is + % furnished to do so, subject to the following conditions: + + % The above copyright notice and this permission notice shall be included in all + % copies or substantial portions of the Software. + + % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + % SOFTWARE. + + % User readable description of the circuit. Will be used in the log file generated + % from the MCMC inference procedure. + circuitInfo1 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.']; + + circuitInfo2 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n ']; + + + + %{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model + %% + activeNames1 = {... + 'TX_elong_glob' 1 [0.5 10] + 'AGTPdeg_time' 7200 [1800 18000] + 'AGTPdeg_rate' 0.0002 [1e-5 1e-1] + 'TXTL_P70_RNAPbound_Kd' 12 [0.1 1000] + 'TXTL_P70_RNAPbound_F' 17 [0.1 100] + 'TXTL_RNAPBOUND_TERMINATION_RATE' 0.07 [1e-4 10] + 'TXTL_NTP_RNAP_1_Kd' 2 [0.1 1000] + 'TXTL_NTP_RNAP_1_F' 10 [0.1 100] + 'TXTL_NTP_RNAP_2_Kd' 10 [0.1 1000] + 'TXTL_NTP_RNAP_2_F' 1 [0.1 100] + 'TXTL_RNAdeg_Kd' 2000 [1 5000] + 'TXTL_RNAdeg_F' 1 [0.1 1000] + 'TXTL_RNAdeg_kc' 0.001 [1e-4 1] + 'RNAP' 30 [5 500] + 'RNase' 200 [10 1000]}; + + activeNames2 = {... + 'TXTL_RNAdeg_Kd' 2000 [1 5000] + 'TXTL_RNAdeg_F' 1 [0.1 1000] + 'TXTL_RNAdeg_kc' 0.001 [1e-4 1] + 'RNase' 200 [10 1000]}; + %% + % Names of parameters and species to actually estimate. + estParams = activeNames1(:,1); + % fixedParams vector + fixedParams = []; % none + masterVector = zeros(length(activeNames1(:,1)), 1); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [1:length(activeNames1(:,1))]'; + paramMap2 = [11 12 13 15]'; + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames1(:,3))); + + +%% next we define the dosing strategy. + dosedNames1 = {'DNA p70--utr1--deGFP'}; + dosedVals1 = [0.5 2 5 20]; + + dosedNames2 = {'RNA utr1--deGFP'}; + dosedVals2 = [37.5 75 150 200 600 700 800 900 1000]; +%% create the measured species cell array +measuredSpecies = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:2AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:2AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; +msIx = 1; % this is the index of the measured species in the data array +% from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + + +%% setup the MCMC simulation parameters +stdev = 1; % i have no idea what a good value is +tightening = 1; % i have no idea what a good value is +nW = 400; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 1.1 to 4 ish +niter = 20; % actual: 2 - 30 ish, +npoints = 4e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of +% params is small) +thinning = 10; % actual: 10 to 40 ish + +%% pull all this together into an output struct. + +runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping models to master vector. + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'measuredSpecies', {measuredSpecies, measuredSpecies}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', msIx,... % maps measuredSpecies to the species in data array + 'dataToMapTo', {1, 3}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + +semanticGroups = num2cell((1:length(estParams))'); +%arrayfun(@num2str, 1:10, 'UniformOutput', false); +estParamsIx = setdiff((1:length(masterVector))', fixedParams); + +%% master parameter vector, param ranges, +master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParams},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups});% EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + +% how the parameter distribution flow works: +% WALKER INITIALIZATION +% reduced master vector -- semanticGroups --> +% master vector -- paramMaps --> +% full parameter vector for each topo-geom pair -- orderingIx --> +% reordered vector for exported model simulation. +% +% param ranges: reduced param ranges matrix (by sematicGroups) +% compute initial parameter distributons +% then expand in the same way as above. +% once the parameters have been estimated, there is no need to +% reorder them, since the master vector was never reordered. +% can use the master_info.estNames for the names and +% master_info.mastervector(~master_info.fixedParams) for the +% parameter values. +% sematic + + +mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F2.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F2.m new file mode 100755 index 0000000..a8b1792 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F2.m @@ -0,0 +1,356 @@ +function [mcmc_info, varargout] = mcmc_info_vnprl_F2(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-7 10] + 'RNase' exp(6.4899) [1 100000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. + 'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % set from before + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 1e7] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 1000] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] %set to exp(-5.4) + 'RNAP' exp(1.4419) [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 100000] + 'TL_elong_glob' exp(0.5219) [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.005 1e7] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] + 'Ribo' exp(7.3081) [1 10000]}; %26 + displayThings = [activeNames2(:,1) num2cell(log(cell2mat(activeNames2(:,2)))) num2cell(log(cell2mat(activeNames2(:,3)))) ] + % +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. + +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + estARRAY = [activeNames2(estParamsIX,[1]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] + fixARRAY = [activeNames2(fixedParamsIX,[1]) num2cell(log(cell2mat(activeNames2(fixedParamsIX,2))))] + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.6}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F3.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F3.m new file mode 100755 index 0000000..393423a --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F3.m @@ -0,0 +1,386 @@ +function [mcmc_info, varargout] = mcmc_info_vnprl_F3(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-7 10] + 'RNase' exp(6.4899) [1 100000]}; + activeNames2_F3 = {... + 'TX_elong_glob' exp(2.55) [exp(0.3) exp(4.8)] % 1 + 'AGTPdeg_time' exp(8.8350) exp([6.76 10.91]) % DO NOT FIX THIS. + 'AGTPdeg_rate' exp(-10) exp([-12.3 -7.6 ]) % set from before + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' exp(13.75) exp([11.25 16.25]) % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(1.95) exp([-4.1 8]) % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(15.6) exp([12.5 18.7]) + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-2.1) exp([-5.3 1.1]) %set to exp(-5.4) + 'RNAP' exp(1.4419) exp([-2.44 5.62]) % 15 + 'RNase' exp(10.5) exp([6.6 14.4]) + 'TL_elong_glob' exp(3.35) exp([0.1 6.6]) + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(5.75) exp([-5 16.5]) + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(2.45) exp([1.9 3]) + 'Ribo' exp(5) exp([1 9])}; %26 + + % this is the expanded set using the F2 parameters as starting + % point + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(4.9354) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.17) exp([6.76 10.91])%!CHANGED[1800 42000] + 'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % + 'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 exp(16.25)] %!CHANGED[0.01 1e7] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) exp([-4.1 8])%!CHANGED[0.1 1000] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1.3222e+08] %!CHANGED[100 1e7] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] % + 'RNAP' exp(1.4419) exp([-2.44 10])% !cCHANGED [0.1 5000] % 15 + 'RNase' exp(6.4899) [1 1.7941e+06]%!CHANGED[1 100000] + 'TL_elong_glob' exp(0.5219) [0.1 735.1] %!CHNAGED [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 + 'TXTL_UTR_UTR1_Kd' exp(11.189) [0.005 1.4651e+07]%!CHANGED [0.005 1e7] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] % + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] + 'Ribo' exp(7.3081) [1 10000]}; %26 + displayThings = [activeNames2(:,1) num2cell(log(cell2mat(activeNames2(:,2)))) num2cell(log(cell2mat(activeNames2(:,3)))) ] + % +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. + +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + estARRAY = [activeNames2(estParamsIX,[1]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] + fixARRAY = [activeNames2(fixedParamsIX,[1]) num2cell(log(cell2mat(activeNames2(fixedParamsIX,2))))] + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.6}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F3_original.m b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F3_original.m new file mode 100644 index 0000000..6657c46 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/mcmc_info_vnprl_F3_original.m @@ -0,0 +1,356 @@ +function [mcmc_info, varargout] = mcmc_info_vnprl_F3(modelObj) +% from regen_A1, with the parameters with posterior distributions that are +% very flat set to some value in that flat distribution. The psoterior +% distirbutions used are from the parameter set "case 4" in +% manual_txtlsim_parameters +% ts2temp = '20190205_145620_2_218'; +% ts3temp = '20190205_222248_1_218'; +% ts4temp = '20190206_043320_1_218'; +% ts6temp = '20190207_154246_1_218'; +% +% Define the mcmc_info struct for the dsg2014 dataset, for the estimation +% of the mrna parameters, using only measurements of the mrna for +% the estimation. The data is from figure 1 of the paper: +% Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free “Breadboard” by Siegal-Gaskins et al. +% +% mcmc_info struct. Written for concurrent multi +% model - experiment parameter inference. +% This mcmc info has parameter inference from two experiments: +% 1) rna degradation using purified dna +% 2) translation + transcription + rna degradation +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + + +circuitInfo1 = ... + ['This is simple enzymatic rna degradation. Note that here mRNA can \n'... + 'to ribosomes and other species, but these offer no protection. '... + 'from rna degradation. \n '] + +circuitInfo2 = ... + ['This is a simple constitutive gene expression model \n'... + 'built using the TXTL modeling toolbox. It models DNA binding \n'... + 'to RNAP and nucleotides, followed by transcription. The resulting\n'... + 'mRNA can degrade and participate in translation. The former is \n'... + 'modeled as a enzymatic reaction involving every complex containing \n'... + 'mRNA. The latter involves binding to Ribosomes, followed by amino acids \n'... + 'and ATP, and finally elongation and termination resulting in protein.'] + +%{ + % activeNames has the mRNA parameters and the protein parameters. + % first half (up to RNase) are TX and the rest are TL. + % TX params are fixed from previous sims. + % + % ordering requirements: + % ensure that the following two orderings match up: + % activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) + % + % ie, activeNames == masterVector(paramMaps) + % + % This gets satisfied when two conditions hold: + % + % The fixed parameters in the master vector must be arranged to that + % for every paramMap and every corresponding activeNames list, the + % fixed params subset of the elements gets mapped correctly. + % + % for the estimaed parameters, again, the estimated parameters need to + % populate the master vector in a way such that the condition + % activeNames == masterVector(paramMaps) holds for all the activeNames + % arrays (each topology will have one), and for each paramMap column + % (geometry) for each topology. + % + % + % of course, the masterVector is built as follows: + % masterVector(estparamIX) == logp + % masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] + % + % So this is all a bit complicated... + % Basically we need to make sure that after we build master vector from + % the fixed parameters (from the previous simulations), when we access + % them using paramMaps, we get the ones corresponding to the names in + % activeNames. + %} + + % names of the parameters and species to set allow for setting in the + % exported model. These are both the set parameters and the to estimate + % parameters. + % Here for example we have for the mrna deg sim we only care about + % setting the rna deg parameters. + %% + + activeNames1 = {... + 'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-4.4) [1e-7 10] + 'RNase' exp(6.4899) [1 100000]}; + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(2.55) [exp(2.3) exp(2.8)] % 1 + 'AGTPdeg_time' exp(8.8350) exp([8.76 8.91]) % DO NOT FIX THIS. + 'AGTPdeg_rate' exp(-10) exp([-10.3 -9.6 ]) % set from before + 'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' exp(13.75) exp([13.25 14.25]) % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(1.95) exp([-2.1 6]) % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(15.6) exp([14.5 16.7]) + 'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-2.1) exp([-3.3 -0.9]) %set to exp(-5.4) + 'RNAP' exp(1.4419) exp([-0.44 3.62]) % 15 + 'RNase' exp(10.5) exp([8.6 12.4]) + 'TL_elong_glob' exp(3.35) exp([2.1 4.6]) + 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(5.75) exp([-3 14.5]) + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(2.45) exp([1.9 3]) + 'Ribo' exp(5) exp([3 7])}; %26 + displayThings = [activeNames2(:,1) num2cell(log(cell2mat(activeNames2(:,2)))) num2cell(log(cell2mat(activeNames2(:,3)))) ] + % +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. + +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } + + %% + % Names of parameters and species to actually estimate. + estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; + estParams = activeNames2(estParamsIX,1); + % skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION + % fixedParams vector + fixedParamsIX = setdiff((1:26)', estParamsIX); + + estARRAY = [activeNames2(estParamsIX,[1]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] + fixARRAY = [activeNames2(fixedParamsIX,[1]) num2cell(log(cell2mat(activeNames2(fixedParamsIX,2))))] + + % for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) + + + % since activeNames2 is a superset of activeNames1, we can just use + % activeNames2 as the master vector. + masterVector = log(cell2mat(activeNames2(:,2))); % log transformed. + + % paramMap is a matrix mapping the parameters in the master vector to the + % (unordered) list of parameters in the model. (obvioulsy within the code + % these parameters get ordered before they are used in the exported model) + % More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list + % of parameters for the first geometry within that topology, as specified by + % namesUnord. Note that namesUnord is just all the active parameters in + % the model, not just the estimated ones. + % One such matrix exists for each topology. It has dimnesions + % length(model_info(i).namesUnord) x number of geometries associated with that topo. + paramMap1 = [12 13 14 16]'; + paramMap2 = (1:length(masterVector))'; + + + % parameter ranges (for the to-be-estimated parameters in the master + % vector) + paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); + + + %% next we define the dosing strategy. + + dosedNames1 = {'RNA utr1--deGFP'}; + dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +% dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; + doseWeights1 = ones(size(dosedVals1)); %dtempvec/(sum(dtempvec)); + dosedNames2 = {'DNA p70--utr1--deGFP'}; + dosedVals2 = [0.5 2 5 20]; +% dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; + doseWeights2 = ones(size(dosedVals2)); %dtempvec/(sum(dtempvec)); + %% create the measured species cell array + % remember to change this! esp the 2AGTP. + measuredSpecies1 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}}; + + measuredSpecies2 = {{'[RNA utr1--deGFP]',... + '[Ribo:RNA utr1--deGFP]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP]', ... + '[term_Ribo:RNA utr1--deGFP]',... + '[AA:Ribo:RNA utr1--deGFP]'... + '[RNA utr1--deGFP:RNase]',... + '[Ribo:RNA utr1--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA utr1--deGFP:RNase]', ... + '[term_Ribo:RNA utr1--deGFP:RNase]',... + '[AA:Ribo:RNA utr1--deGFP:RNase]'}, {'protein deGFP*'}}; + msIx1 = 1; % this is the index of the measured species in the data array + % from data_dsg2014. There are two species: 1: mRNA and 2: GFP. + msIx2 = [1,2]; + + %% setup the MCMC simulation parameters + stdev = 100; % i have no idea what a good value is + tightening = 1; % i have no idea what a good value is + nW = 300; % actual: 200 - 600 ish + stepsize = 1.5; % actual: 1.1 to 4 ish + niter = 10; % actual: 2 - 30 ish, + npoints = 1e4; % actual: 2e4 to 2e5 ish (or even 1e6 of the number of + % params is small) + thinning = 10; % actual: 10 to 40 ish + + %% pull all this together into an output struct. + + runsim_info = struct('stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepSize', {stepsize}, ... + 'nIter', {niter}, ... + 'nPoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', false); + + model_info = struct(... + 'circuitInfo',{circuitInfo1, circuitInfo2},... + 'modelObj', {modelObj,modelObj},... % array of model objects (different topologies) + 'modelName', modelObj.name,...; % model names. + 'namesUnord', {activeNames1(:,1),activeNames2(:,1)}, ... % names of parameters per model, unordered. + 'paramMaps', {paramMap1, paramMap2}, ... % paramMap is a matrix mapping master vector elements to namesUnord + 'dosedNames', {dosedNames1, dosedNames2},... % cell arrays of species. cell array corresponds + ... % to a model. + 'dosedVals', {dosedVals1, dosedVals2},... % matrices of dose vals + 'doseWeighting', {doseWeights1, doseWeights2}, ... + ... % OPTIONAL FIELD. reweight the importance of the curves corresponding to the different doses. + 'measuredSpecies', {measuredSpecies1, measuredSpecies2}, ... % cell array of cell arrays of + ... % species names. the elements of the inner + ... % cell array get summed. + 'measuredSpeciesIndex', {msIx1, msIx2},... % maps measuredSpecies to the species in data array + 'experimentWeighting', {1 0.6}, ... % + ... % relative importance of the different topologies. + ... %geometries in a given topology are weighted with + ...% the same level of importance for now. + 'dataToMapTo', {3,1}); % each dataToMapTo property within an element of the + % model_info array is a vector of length # of geometries. + % data indices tell us which data set to use for each topology (model) - geometry pair + % from the data_info struct array. + + + semanticGroups = num2cell((1:length(estParams))'); + %arrayfun(@num2str, 1:10, 'UniformOutput', false); + % estParamsIx = setdiff((1:length(masterVector))', fixedParamsIX); + + %% master parameter vector, param ranges, + master_info = struct(... + 'estNames', {estParams},... + 'masterVector', {masterVector},... + 'paramRanges', {paramRanges},... % + 'fixedParams', {fixedParamsIX},... % indexes of the fixed params (withing master vector) + 'semanticGroups', {semanticGroups}); % EITHER EMPTY OR + % a cell array of vectors specifying parameter + % groupings. + % The vectors contain indices to the + % parameters in (non fixed subset of) the master + % vector that need to be grouped. + % I.e., They contain indexes of the subvector + % logp = + % master_info.mastervector(~master_info.fixedParams) + % and to the rows of the paramRanges matrix and the + % estNames cell array of strings. + % + % parameter grouping so that these parameters + % get INITIALIZED to the same values. + % + % every parameter index must show up in at least + % one group, even if that is the only parameter in + % that group. If the semanticGroups field is empty, + % then all parameters are assumed to be in their + % distinct groups. + + + % how the parameter distribution flow works: + % WALKER INITIALIZATION + % reduced master vector -- semanticGroups --> + % master vector -- paramMaps --> + % full parameter vector for each topo-geom pair -- orderingIx --> + % reordered vector for exported model simulation. + % + % param ranges: reduced param ranges matrix (by sematicGroups) + % compute initial parameter distributons + % then expand in the same way as above. + % once the parameters have been estimated, there is no need to + % reorder them, since the master vector was never reordered. + % can use the master_info.estNames for the names and + % master_info.mastervector(~master_info.fixedParams) for the + % parameter values. + % sematic + + + mcmc_info = struct('runsim_info', runsim_info, ... + 'model_info', model_info,... + 'master_info', master_info); + + + if nargout == 1 + varargout{1} = activeNames2; + + end + +end \ No newline at end of file diff --git a/mcmc_simbio/models_and_supporting_files/model_aTc_induc1.m b/mcmc_simbio/models_and_supporting_files/model_aTc_induc1.m new file mode 100755 index 0000000..327045d --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_aTc_induc1.m @@ -0,0 +1,141 @@ +function mobj = model_aTc_induc1 +% aTc derepression (induction) of a circuit involving +% repression with enzymatic one step protein production +% The 1 at the end of the aTc_induc1 is used because this uses +% a transcriptional model of type 1. +% +% ~~~ MODEL ~~~ +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% 2 aTc <-> aTc2 +% aTc2 + T2 <-> aTc2:T2 + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% 2 aTc <-> aTc2 +% aTc2 + T2 <-> aTc2:T2 +% + +p = inputParser; +addParameter(p, 'simtime', 8*3600); +parse(p); +p = p.Results; +%% setup model +mobj = sbiomodel('aTcInduc1'); +%% setup model reactions + +rxn = addreaction(mobj,'dT + pol <-> dT_pol'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfdT','krdT'}; +addparameter(mobj, 'kfdT', 1); +addparameter(mobj, 'krdT', 60); + +rxn = addreaction(mobj,'dT_pol -> dT + pol + pT'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kcp'}; +addparameter(mobj, 'kcp', 0.12); + +rxn = addreaction(mobj,'dG + pol <-> dG_pol'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfdG','krdG'}; +addparameter(mobj, 'kfdG', 0.5); +addparameter(mobj, 'krdG', 30); + +rxn = addreaction(mobj,'dG_pol -> dG + pol + pG'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kcp'}; +% already added to model. + +rxn = addreaction(mobj,'2 pT <-> pT2'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfdimTet','krdimTet'}; +addparameter(mobj, 'kfdimTet', .2); +addparameter(mobj, 'krdimTet', 4); + +rxn = addreaction(mobj,'dG + pT2 <-> dG_pT2'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfseqTet','krseqTet'}; +addparameter(mobj, 'kfseqTet', .2); +addparameter(mobj, 'krseqTet', 4); + +% rxn = addreaction(mobj,'2 aTc <-> aTc2'); +% Kobj = addkineticlaw(rxn,'MassAction'); +% Kobj.ParameterVariableNames = {'kfdimaTc','krdimaTc'}; +% addparameter(mobj, 'kfdimaTc', .2); +% addparameter(mobj, 'krdimaTc', 4); + +rxn = addreaction(mobj,'aTc2 + pT2 <-> aTc2_pT2'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfseqaTc','krseqaTc'}; +addparameter(mobj, 'kfseqaTc', .2); +addparameter(mobj, 'krseqaTc', 4); + +% setup model species initial concentrations. +specie = sbioselect(mobj, 'name', 'dT'); +specie.InitialAmount = 0.4; + +specie = sbioselect(mobj, 'name', 'dG'); +specie.InitialAmount = 4; + +specie = sbioselect(mobj, 'name', 'pT'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'pG'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'pol'); +specie.InitialAmount = 100; + +specie = sbioselect(mobj, 'name', 'dT_pol'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'dG_pol'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'pT2'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'dG_pT2'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'aTc2'); +specie.InitialAmount = 0; + +% specie = sbioselect(mobj, 'name', 'aTc'); +% specie.InitialAmount = 1000; + +specie = sbioselect(mobj, 'name', 'aTc2_pT2'); +specie.InitialAmount = 0; + +%% Run the model + +cs = getconfigset(mobj, 'active'); +set(cs, 'StopTime', p.simtime); + +sd = sbiosimulate(mobj); + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_basic.m b/mcmc_simbio/models_and_supporting_files/model_basic.m new file mode 100755 index 0000000..c413224 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_basic.m @@ -0,0 +1,184 @@ +function [varargout] = model_basic(varargin) +% model_basic: mrna-protein constitutive gene expression, mass action, Simbiology. +% This function runs a simple model and generates a plot, and optionally +% returns a simbiology model, the corresponding exported model object, +% an mcmc_info struct (with the ordered estimated species and parameters +% appended as a field too. +% +% INPUTS - Name value pairs, all optional. (defaults kick in if these are +% not specified) +% 1) 'mcmc_info', VALUE, where VALUE is a valid mcmc_info struct. See documentation +% in the file !TODO for how to specify this. You +% can also see how it was specified within this fucntion (as a default). +% 2) 'simtime', VALUE, where t_end is a numeric (double) specifying the time +% to the end of the simulation. +% +% OUTPUTS - generates a simbiology plot, and returns the following optional +% arguments in order: +% m: a model object, +% em: an exported model object, +% mi: an mcmc info struct. +% + +% +% THIS MODEL: +% P + D <-> PD (kPDf, kPDr) +% PD -> P + D + m (kTX) +% m + R <-> mR (kmRf, kmRr) +% mR -> m + R + G (kTL) +% G -> null (kGd) +% m -> null (kmd) +% +% + +% setup some defaults (defining the experiment structure suing the +% mcmc_info structure) +% setup the default mcmc_info object +estNames = {'kPDr' + 'kTX' + 'kmRr' + 'kTL' + 'kGd' + 'kmd' + 'P' + 'R'}; +paramranges = log([0.5 50 + 0.005 5 + 0.5 50 + 0.005 5 + 0.005 5 + 0.005 5 + 0.1 500 + 0.1 500]); + +dosedNames = {'D'}; %to be really sneaky, can try to dose mrna as well. +% Fairly intractable experimentally though. + +dosedVals = [1]; % variations include multiple concentrations: +% [0.5, 1], [0.1, 1, 10], [0.1, 1, 10, 100] and a study of how +% identifiability changes with these variations. + +measuredSpecies = {{'m', 'mR'}, 'G'}; % the first species is a sum of the +% ribosome bound RNA and free RNA, and the second is just the GFP. + +stdev = 1; % the ideal value of this is investigated in the project file +% titled proj_basic_model.m + +tightening = 1; % i have no idea what a good value is +nW = 300; % actual: 200 - 600 ish +stepsize = 1.5; % actual: 2 to 4 ish +niter = 30; % actual: 2 - 20 ish, +npoints = 2e4; % actual: 1e5 ish +thinning = 10; % actual: 10 to 40 ish + +mi = struct(... + 'names_unord', {estNames}, ... + 'paramranges', {paramranges},... + 'dosednames', {dosedNames},... + 'dosedvals', {dosedVals},... + 'measuredspecies', {measuredSpecies}, ... + 'stdev', {stdev}, ... + 'tightening', {tightening}, ... + 'nW', {nW}, ... + 'stepsize', {stepsize}, ... + 'niter', {niter}, ... + 'npoints', {npoints}, ... + 'thinning', {thinning}, ... + 'parallel', true); + +p = inputParser ; +p.addParameter(p, 'mcmc_info', mi); +p.addParameter(p, 'simtime', 200); + +m1 = sbiomodel('constitutive_expression'); + +r1 = addreaction(m1,'P + D <-> PD'); +Kobj = addkineticlaw(r1,'MassAction'); +Kobj.ParameterVariableNames = {'kPDf','kPDr'}; +addparameter(m1, 'kPDf', 1) +addparameter(m1, 'kPDr', 5) + +r2 = addreaction(m1,'PD -> P + D + m'); +Kobj = addkineticlaw(r2,'MassAction'); +Kobj.ParameterVariableNames = {'kTX'}; +addparameter(m1, 'kTX', 1) + +r3 = addreaction(m1,'m + R <-> mR'); +Kobj = addkineticlaw(r3,'MassAction'); +Kobj.ParameterVariableNames = {'kmRf','kmRr'}; +addparameter(m1, 'kmRf', 1) +addparameter(m1, 'kmRr', 5) + +r4 = addreaction(m1,'mR -> m + R + G'); +Kobj = addkineticlaw(r4,'MassAction'); +Kobj.ParameterVariableNames = {'kTL'}; +addparameter(m1, 'kTL', 1) + +r5 = addreaction(m1,'G -> null'); +Kobj = addkineticlaw(r5,'MassAction'); +Kobj.ParameterVariableNames = {'kGd'}; +addparameter(m1, 'kGd', 1) + +r6 = addreaction(m1,'m -> null'); +Kobj = addkineticlaw(r6,'MassAction'); +Kobj.ParameterVariableNames = {'kmd'}; +addparameter(m1, 'kmd', .1) + + +pol = sbioselect(m1, 'name', 'P'); +pol.InitialAmount = 10; + +dna = sbioselect(m1, 'name', 'D'); +dna.InitialAmount = 5; + +ribo = sbioselect(m1, 'name', 'R'); +ribo.InitialAmount = 50; +m1.species +%% + +cs = getconfigset(m1, 'active'); + set(cs, 'StopTime', p.simtime); + +sd = sbiosimulate(m1); +sbioplot(sd); + + +%% DONT TOUCH THIS SECTION +% export and accelerate simbiology model object using estimated species +% and dosing species names + +% select the parameters and species objects using the name array +ep = sbioselect(m1, 'Type', 'parameter', 'Name', ... + mi.names_unord);% est parameters + +es = sbioselect(m1, 'Type', 'species', 'Name', ... + mi.names_unord);% est species + +aps = [ep; es]; % active parameters and species + +% reorder the parameter and species so they are in the same order as that +% in the model. +eno = cell(length(aps), 1);% est names ordered + +for i = 1:length(aps) + eno{i} = aps(i).Name; +end + +% +ds = sbioselect(m1, 'Type', 'species', 'Name', mi.dosednames); + +emo = export(m1, [ep; es; ds]); % exported model object, dosed species names. +SI = emo.SimulationOptions; +SI.StopTime = p.simtime; +accelerate(emo); + +mi.names_ord = eno; +mi.emo = emo; % !TODO: remove ? + +% process variable outputs +nout = nargout; +outstuff = {m1, emo, mi}; +varargout(1:nout) = outstuff(1:nout); % REMOVE: i think this should work. + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_dsg2014.m b/mcmc_simbio/models_and_supporting_files/model_dsg2014.m new file mode 100755 index 0000000..566dfba --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_dsg2014.m @@ -0,0 +1,128 @@ +function m = model_dsg2014(varargin) +% model_dsg2014 Constitutive gene expression model using the TXTL modeling toolbox +% +% ~~~ INPUTS ~~~ +% +% Optional name-value pair input arguments: +% 'timeVector': A vector of timepoints to set up the model for. Default is 1:100. +% 'paramInfo': A param_info struct that is used to set parameter values in the model object. +% This struct has fields: +% 'paramNames': A string corresponding to the parameter name, or +% a 1 by 2 cell array of strings of forward and backward +% reaction rate parameters for reversible reactions. +% 'paramVals': A numerical value of the parameter, or a 1 by 2 vector +% for reversible reactions. +% 'reactionString': This is either the reaction string or the +% string 'global'. If the paramNames is a 1 x 2 cell array +% and the paramVals is a +% then the reaction is reversible, and if the paramNames is +% a string, then it is a irreversible reaction. When this +% argument is 'global', we always have a string and a scalar +% for paramNames and paramVals respectively. +% 'reactionString': this is either the reaction string or the +% string 'global'. +% 'paramRanges': Non-negative orthant values for the parameter upper and +% lower bounds. For each parameter this is either a +% 2 by 1 vector (for irreversible reactions) or a 2 by 2 +% matrix, where the first and second rows are the upper +% and lower bounds respectively, and the first and second +% columns are the bounds for the forward and reverse rate +% parameters respectively. If nothing is specified, then +% the bounds for a parameter with value VAL is [VAL/10; VAL*10] +% 'paramNotes' Human readable notes. +% +% +% ~~~ OUTPUTS ~~~ +% +% m: a Simbiology Model Object +% +% emo: An exported Simbiology Model Object. +% +% mi: An updated mcmc_info struct. The following fields are added to the mcmc_info struct +% names_ord: An ordered list of species and parameters to be estimated. +% emo: Exported model Object. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser; +p.addParameter('paramInfo', [], @isstruct); +p.addParameter('timeVector', 1:100, @isnumeric); +p.parse(varargin{:}); +p = p.Results; +tv = p.timeVector; + + + +%% ################## EDIT THIS SECTION AS NEEDED #################### + +% Specify the parameter config files, dna string and initial concentration, +% inducers etc. See the TXTL Modeling toolbox documentation for more information. + +% setup model object (this model uses the txtl toolbox at +tube1 = txtl_extract('Emcmc2017'); +tube2 = txtl_buffer('Emcmc2017'); +tube3 = txtl_newtube('gene_expression'); +txtl_add_dna(tube3, ... + 'p70(50)', 'utr1(20)', 'deGFP(1000)', 20, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); + +%% MOST LIKELY YOU WILL NOT NEED TO TOUCH THIS SECTION +% See: +% https://www.mathworks.com/help/simbio/ug/selecting-absolute- +% tolerance-and-relative-tolerance-for-simulation.html +cs1 = getconfigset(m); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); +set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', tv(end)*1.0e-6*0.1); +set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 + +tic + [~] = txtl_runsim(m,tv(end)); +toc + + +% +%% DONT TOUCH THIS SECTION +% modify the base model to get it ready for parameter estimation. +% Change the scope of the reversible reaction parameters from the +% reaction to the model level scope. This is needed for adding rules +% between the parameters (like Kd rules). +% The rules are needed because in parameter esitmation when you change some +% base parameter (like Kd) the parameters that are associated should also +% change. Just like for the reversible reactions, the irreversible +% reaction params need to be model scoped because +% for the elongation rate the parameter is tied to NTP consumption rates + +globalize_params(m) + +%% Optionally set parameters for in the model object +if ~isempty(p.paramInfo) + pinf = p.paramInfo; + % set the parameters + for i = 1:length(pinf, 1) + setparam(m, pinf.reactionString(i), pinf.paramNames(i), pinf.paramVals(i)); + end +end + + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_dsg2014_regen.m b/mcmc_simbio/models_and_supporting_files/model_dsg2014_regen.m new file mode 100755 index 0000000..342266f --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_dsg2014_regen.m @@ -0,0 +1,136 @@ +function m = model_dsg2014_regen(varargin) +% model_dsg2014 Constitutive gene expression model using the TXTL modeling toolbox +% +% ~~~ INPUTS ~~~ +% +% Optional name-value pair input arguments: +% 'timeVector': A vector of timepoints to set up the model for. Default is 1:100. +% 'paramInfo': A param_info struct that is used to set parameter values in the model object. +% This struct has fields: +% 'paramNames': A string corresponding to the parameter name, or +% a 1 by 2 cell array of strings of forward and backward +% reaction rate parameters for reversible reactions. +% 'paramVals': A numerical value of the parameter, or a 1 by 2 vector +% for reversible reactions. +% 'reactionString': This is either the reaction string or the +% string 'global'. If the paramNames is a 1 x 2 cell array +% and the paramVals is a +% then the reaction is reversible, and if the paramNames is +% a string, then it is a irreversible reaction. When this +% argument is 'global', we always have a string and a scalar +% for paramNames and paramVals respectively. +% 'reactionString': this is either the reaction string or the +% string 'global'. +% 'paramRanges': Non-negative orthant values for the parameter upper and +% lower bounds. For each parameter this is either a +% 2 by 1 vector (for irreversible reactions) or a 2 by 2 +% matrix, where the first and second rows are the upper +% and lower bounds respectively, and the first and second +% columns are the bounds for the forward and reverse rate +% parameters respectively. If nothing is specified, then +% the bounds for a parameter with value VAL is [VAL/10; VAL*10] +% 'paramNotes' Human readable notes. +% +% +% ~~~ OUTPUTS ~~~ +% +% m: a Simbiology Model Object +% +% emo: An exported Simbiology Model Object. +% +% mi: An updated mcmc_info struct. The following fields are added to the mcmc_info struct +% names_ord: An ordered list of species and parameters to be estimated. +% emo: Exported model Object. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser; +p.addParameter('paramInfo', [], @isstruct); +p.addParameter('timeVector', 1:100, @isnumeric); +p.addParameter('plotmode', false, @islogical); +p.addParameter('initialDNA', 0, @isnumeric); +p.parse(varargin{:}); +p = p.Results; +tv = p.timeVector; + + + +%% ################## EDIT THIS SECTION AS NEEDED #################### + +% Specify the parameter config files, dna string and initial concentration, +% inducers etc. See the TXTL Modeling toolbox documentation for more information. + +% setup model object (this model uses the txtl toolbox at +tube1 = txtl_extract('Emcmc2018'); +tube2 = txtl_buffer('Emcmc2018'); +tube3 = txtl_newtube('gene_expression'); +txtl_add_dna(tube3, ... + 'p70(50)', 'utr1(20)', 'deGFP(1000)', p.initialDNA, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); +m.UserData.energymode = 'regeneration'; +% MOST LIKELY YOU WILL NOT NEED TO TOUCH THIS SECTION +% See: +% https://www.mathworks.com/help/simbio/ug/selecting-absolute- +% tolerance-and-relative-tolerance-for-simulation.html +cs1 = getconfigset(m); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); +set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', tv(end)*1.0e-6*0.1); +set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 + +tic + [~] = txtl_runsim(m,tv(end)); +toc +if p.plotmode + [simData] = txtl_runsim(m,14*60*60); + txtl_plot(simData,m); +end + + + +% +%% DONT TOUCH THIS SECTION +% modify the base model to get it ready for parameter estimation. +% Change the scope of the reversible reaction parameters from the +% reaction to the model level scope. This is needed for adding rules +% between the parameters (like Kd rules). +% The rules are needed because in parameter esitmation when you change some +% base parameter (like Kd) the parameters that are associated should also +% change. Just like for the reversible reactions, the irreversible +% reaction params need to be model scoped because +% for the elongation rate the parameter is tied to NTP consumption rates + +globalize_params(m) + +%% Optionally set parameters for in the model object +if ~isempty(p.paramInfo) + pinf = p.paramInfo; + % set the parameters + for i = 1:size(pinf, 1) + setparam(m, pinf(i).reactionString, pinf(i).paramNames, pinf(i).paramVals); + end +end + + + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_protein3.m b/mcmc_simbio/models_and_supporting_files/model_protein3.m new file mode 100755 index 0000000..ada614a --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_protein3.m @@ -0,0 +1,53 @@ +function mobj = model_protein3(varargin) +% model_protein3 Constitutive gene expression model using a single +% enzymatic step. +% +% ~~~ MODEL ~~~ +% D + pol <-> D__pol (k_f, k_r ) +% D__pol -> D + pol + protien (kc) +% + + +%% set input defaults +p = inputParser ; +addParameter(p, 'simtime', 1.6*3600); +parse(p); +p = p.Results; + +%% setup model +mobj = sbiomodel('expression'); + +%% setup model reactions +r1 = addreaction(mobj,'dG + pol <-> dG_pol'); +Kobj = addkineticlaw(r1,'MassAction'); +Kobj.ParameterVariableNames = {'kfdG','krdG'}; +addparameter(mobj, 'kfdG', 10); +addparameter(mobj, 'krdG', 600); + +r2 = addreaction(mobj,'dG_pol -> dG + pol + pG'); +Kobj = addkineticlaw(r2,'MassAction'); +Kobj.ParameterVariableNames = {'kcp'}; +addparameter(mobj, 'kcp', 0.012); + +% setup model species initial concentrations. +P = sbioselect(mobj, 'name', 'dG'); +P.InitialAmount = 0; + +C = sbioselect(mobj, 'name', 'pol'); +C.InitialAmount = 0; + +E = sbioselect(mobj, 'name', 'dG_pol'); +E.InitialAmount = 0; + +S = sbioselect(mobj, 'name', 'pG'); +S.InitialAmount = 0; + +%% Run the model + +cs = getconfigset(mobj, 'active'); +set(cs, 'StopTime', p.simtime); + +sd = sbiosimulate(mobj); + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_protein5.m b/mcmc_simbio/models_and_supporting_files/model_protein5.m new file mode 100755 index 0000000..ecd2613 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_protein5.m @@ -0,0 +1,116 @@ +function mobj = model_protein5 +% enzymatic mrna and protein production and first order mrna degradation +% +% ~~~ MODEL ~~~ +% D + pol <-> D__pol (k_fd, k_rd) +% D__pol -> D + pol + mrna (kcm) +% +% mrna + ribo <-> mrna__ribo (k_fm, k_rm) +% mrna__ribo <-> mrna + ribo + protein (kcp) +% +% mrna -> null (kcx) +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser ; +addParameter(p, 'simtime', 2*3600); +parse(p); +p = p.Results; + + +% Model Parameter values +cpol = 100; % nM +cribo = 50; %nM + +rkfdG = 10; % nM-1s-1 +rkrdG = 600; % s-1 +rkcm = 0.001; %s-1 + +rkfpG = 10; % nM-1s-1 +rkrpG = 300; % s-1 +rkcp = 1/36; + +rdel_m = log(2)/720; % 12 min half life of mrna + +%% setup model reactions + +% setup model +mobj = sbiomodel('expression'); +% GFP TXTL +rxn = addreaction(mobj,'dG + pol <-> dG_pol'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfdG','krdG'}; +addparameter(mobj, 'kfdG', rkfdG); +addparameter(mobj, 'krdG', rkrdG); + +rxn = addreaction(mobj,'dG_pol -> dG + pol + mG'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kcm'}; +addparameter(mobj, 'kcm', rkcm); + +rxn = addreaction(mobj,'mG + ribo <-> mG_ribo'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfpG','krpG'}; +addparameter(mobj, 'kfpG', rkfpG); +addparameter(mobj, 'krpG', rkrpG); + +rxn = addreaction(mobj,'mG_ribo -> mG + ribo + pG'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kcp'}; +addparameter(mobj, 'kcp', rkcp); + +rxn = addreaction(mobj,'mG -> null'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'del_m'}; +addparameter(mobj, 'del_m', rdel_m); + +% setup model species initial concentrations. + +specie = sbioselect(mobj, 'name', 'dG'); +specie.InitialAmount = 30; + +specie = sbioselect(mobj, 'name', 'pG'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'mG'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'pol'); +specie.InitialAmount = cpol; + +specie = sbioselect(mobj, 'name', 'ribo'); +specie.InitialAmount = cribo; + +specie = sbioselect(mobj, 'name', 'dG_pol'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'mG_ribo'); +specie.InitialAmount = 0; + + +%% Run the model + +cs = getconfigset(mobj, 'active'); +set(cs, 'StopTime', p.simtime); + +sd = sbiosimulate(mobj); + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_tetR_repression1.m b/mcmc_simbio/models_and_supporting_files/model_tetR_repression1.m new file mode 100755 index 0000000..c6733bf --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_tetR_repression1.m @@ -0,0 +1,113 @@ +function mobj = model_tetR_repression1 +% repression with enzymatic one step protein production +% +% ~~~ MODEL ~~~ +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% D_T + P <-> D_T:P -> D_T + P + T +% D_G + P <-> D_G:P -> D_G + P + G +% 2 T <-> T2 +% D_G + T2 <-> D_G:T2 +% +p = inputParser ; +addParameter(p, 'simtime', 2*3600); +parse(p); +p = p.Results; +%% setup model +mobj = sbiomodel('tetRepression1'); +%% setup model reactions + +rxn = addreaction(mobj,'dT + pol <-> dT_pol'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfdT','krdT'}; +addparameter(mobj, 'kfdT',1); +addparameter(mobj, 'krdT', 6); + +rxn = addreaction(mobj,'dT_pol -> dT + pol + pT'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kcp'}; +addparameter(mobj, 'kcp', 0.012); + +rxn = addreaction(mobj,'dG + pol <-> dG_pol'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfdG','krdG'}; +addparameter(mobj, 'kfdG', 1); +addparameter(mobj, 'krdG', 6); + +rxn = addreaction(mobj,'dG_pol -> dG + pol + pG'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kcp'}; +% already added to model. + +rxn = addreaction(mobj,'2 pT <-> pT2'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfdimTet','krdimTet'}; +addparameter(mobj, 'kfdimTet', 2); +addparameter(mobj, 'krdimTet', 4); + +rxn = addreaction(mobj,'dG + pT2 <-> dG_pT2'); +Kobj = addkineticlaw(rxn,'MassAction'); +Kobj.ParameterVariableNames = {'kfseqTet','krseqTet'}; +addparameter(mobj, 'kfseqTet', 2); +addparameter(mobj, 'krseqTet', 4); + +% setup model species initial concentrations. +% setup model species initial concentrations. +specie = sbioselect(mobj, 'name', 'dT'); +specie.InitialAmount = 2; + +specie = sbioselect(mobj, 'name', 'dG'); +specie.InitialAmount = 10; + +specie = sbioselect(mobj, 'name', 'pT'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'pG'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'pol'); +specie.InitialAmount = 100; + +specie = sbioselect(mobj, 'name', 'dT_pol'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'dG_pol'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'pT2'); +specie.InitialAmount = 0; + +specie = sbioselect(mobj, 'name', 'dG_pT2'); +specie.InitialAmount = 0; + +%% Run the model + +cs = getconfigset(mobj, 'active'); +set(cs, 'StopTime', p.simtime); + +sd = sbiosimulate(mobj); + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_txtl_lastetIFFL.m b/mcmc_simbio/models_and_supporting_files/model_txtl_lastetIFFL.m new file mode 100755 index 0000000..9fa0c16 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_txtl_lastetIFFL.m @@ -0,0 +1,140 @@ +function m = model_txtl_lastetIFFL(varargin) +% model_txtl_pLacLasR_pLasdeGFP: txtlsim model containing: +% pLastetO-UTR1-deGFP +% pLac-UTR1-LasR +% 3OC12HSL +% pLas-UTR1-tetR +% aTc +% +% +% ~~~ INPUTS ~~~ +% +% Optional name-value pair input arguments: +% 'timeVector': A vector of timepoints to set up the model for. Default is 1:100. +% 'paramInfo': A param_info struct that is used to set parameter values in the model object. +% This struct has fields: +% 'paramNames': A string corresponding to the parameter name, or +% a 1 by 2 cell array of strings of forward and backward +% reaction rate parameters for reversible reactions. +% 'paramVals': A numerical value of the parameter, or a 1 by 2 vector +% for reversible reactions. +% 'reactionString': This is either the reaction string or the +% string 'global'. If the paramNames is a 1 x 2 cell array +% and the paramVals is a +% then the reaction is reversible, and if the paramNames is +% a string, then it is a irreversible reaction. When this +% argument is 'global', we always have a string and a scalar +% for paramNames and paramVals respectively. +% 'reactionString': this is either the reaction string or the +% string 'global'. +% 'paramRanges': Non-negative orthant values for the parameter upper and +% lower bounds. For each parameter this is either a +% 2 by 1 vector (for irreversible reactions) or a 2 by 2 +% matrix, where the first and second rows are the upper +% and lower bounds respectively, and the first and second +% columns are the bounds for the forward and reverse rate +% parameters respectively. If nothing is specified, then +% the bounds for a parameter with value VAL is [VAL/10; VAL*10] +% 'paramNotes' Human readable notes. +% +% +% ~~~ OUTPUTS ~~~ +% +% m: a Simbiology Model Object +% +% emo: An exported Simbiology Model Object. +% +% mi: An updated mcmc_info struct. The following fields are added to the mcmc_info struct +% names_ord: An ordered list of species and parameters to be estimated. +% emo: Exported model Object. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser; +p.addParameter('paramInfo', [], @isstruct); +p.addParameter('timeVector', 1:100, @isnumeric); +p.parse(varargin{:}); +p = p.Results; +tv = p.timeVector; + + +%% ################## EDIT THIS SECTION AS NEEDED #################### + +% Specify the parameter config files, dna string and initial concentration, +% inducers etc. See the TXTL Modeling toolbox documentation for more information. + +% setup model object (this model uses the txtl toolbox at +tube1 = txtl_extract('Emcmc2018'); +tube2 = txtl_buffer('Emcmc2018'); +tube3 = txtl_newtube('lastetIFFL'); +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'lasR(1000)', 0, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas(50)', 'utr1(20)', 'tetR(1000)', 0, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas_ptet(50)', 'utr1(20)', 'deGFP(1000)', 0, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); +txtl_addspecies(m, 'OC12HSL', 0); +txtl_addspecies(m, 'aTc', 0); +m.UserData.energymode = 'regeneration'; +%% MOST LIKELY YOU WILL NOT NEED TO TOUCH THIS SECTION +% See: +% https://www.mathworks.com/help/simbio/ug/selecting-absolute- +% tolerance-and-relative-tolerance-for-simulation.html +cs1 = getconfigset(m); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); +set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', tv(end)*1.0e-6*0.1); +set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 + +tic + [~] = txtl_runsim(m,tv(end)); +toc + + + +% +%% DONT TOUCH THIS SECTION +% modify the base model to get it ready for parameter estimation. +% Change the scope of the reversible reaction parameters from the +% reaction to the model level scope. This is needed for adding rules +% between the parameters (like Kd rules). +% The rules are needed because in parameter esitmation when you change some +% base parameter (like Kd) the parameters that are associated should also +% change. Just like for the reversible reactions, the irreversible +% reaction params need to be model scoped because +% for the elongation rate the parameter is tied to NTP consumption rates + +globalize_params(m) + +%% Optionally set parameters for in the model object +if ~isempty(p.paramInfo) + pinf = p.paramInfo; + % set the parameters + for i = 1:length(pinf, 1) + setparam(m, pinf.reactionString(i), pinf.paramNames(i), pinf.paramVals(i)); + end +end + + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_txtl_pLacLasR_pLasdeGFP.m b/mcmc_simbio/models_and_supporting_files/model_txtl_pLacLasR_pLasdeGFP.m new file mode 100755 index 0000000..ea4b15d --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_txtl_pLacLasR_pLasdeGFP.m @@ -0,0 +1,135 @@ +function m = model_txtl_pLacLasR_pLasdeGFP(varargin) +% model_txtl_pLacLasR_pLasdeGFP: txtlsim model containing: +% pLas-UTR1-deGFP +% pLac-UTR1-LasR +% 3OC12HSL +% +% +% ~~~ INPUTS ~~~ +% +% Optional name-value pair input arguments: +% 'timeVector': A vector of timepoints to set up the model for. Default is 1:100. +% 'paramInfo': A param_info struct that is used to set parameter values in the model object. +% This struct has fields: +% 'paramNames': A string corresponding to the parameter name, or +% a 1 by 2 cell array of strings of forward and backward +% reaction rate parameters for reversible reactions. +% 'paramVals': A numerical value of the parameter, or a 1 by 2 vector +% for reversible reactions. +% 'reactionString': This is either the reaction string or the +% string 'global'. If the paramNames is a 1 x 2 cell array +% and the paramVals is a +% then the reaction is reversible, and if the paramNames is +% a string, then it is a irreversible reaction. When this +% argument is 'global', we always have a string and a scalar +% for paramNames and paramVals respectively. +% 'reactionString': this is either the reaction string or the +% string 'global'. +% 'paramRanges': Non-negative orthant values for the parameter upper and +% lower bounds. For each parameter this is either a +% 2 by 1 vector (for irreversible reactions) or a 2 by 2 +% matrix, where the first and second rows are the upper +% and lower bounds respectively, and the first and second +% columns are the bounds for the forward and reverse rate +% parameters respectively. If nothing is specified, then +% the bounds for a parameter with value VAL is [VAL/10; VAL*10] +% 'paramNotes' Human readable notes. +% +% +% ~~~ OUTPUTS ~~~ +% +% m: a Simbiology Model Object +% +% emo: An exported Simbiology Model Object. +% +% mi: An updated mcmc_info struct. The following fields are added to the mcmc_info struct +% names_ord: An ordered list of species and parameters to be estimated. +% emo: Exported model Object. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser; +p.addParameter('paramInfo', [], @isstruct); +p.addParameter('timeVector', 1:100, @isnumeric); +p.parse(varargin{:}); +p = p.Results; +tv = p.timeVector; + + +%% ################## EDIT THIS SECTION AS NEEDED #################### + +% Specify the parameter config files, dna string and initial concentration, +% inducers etc. See the TXTL Modeling toolbox documentation for more information. + +% setup model object (this model uses the txtl toolbox at +tube1 = txtl_extract('Emcmc2018'); +tube2 = txtl_buffer('Emcmc2018'); +tube3 = txtl_newtube('pLacLasR_pLasdeGFP'); +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'lasR(1000)', 0, 'plasmid'); +txtl_add_dna(tube3, ... + 'plas(50)', 'utr1(20)', 'deGFP(1000)', 0, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); +txtl_addspecies(m, 'OC12HSL', 0); +m.UserData.energymode = 'regeneration'; +%% MOST LIKELY YOU WILL NOT NEED TO TOUCH THIS SECTION +% See: +% https://www.mathworks.com/help/simbio/ug/selecting-absolute- +% tolerance-and-relative-tolerance-for-simulation.html +cs1 = getconfigset(m); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); +set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', tv(end)*1.0e-6*0.1); +set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 + +tic + [~] = txtl_runsim(m,tv(end)); +toc + + + +% +%% DONT TOUCH THIS SECTION +% modify the base model to get it ready for parameter estimation. +% Change the scope of the reversible reaction parameters from the +% reaction to the model level scope. This is needed for adding rules +% between the parameters (like Kd rules). +% The rules are needed because in parameter esitmation when you change some +% base parameter (like Kd) the parameters that are associated should also +% change. Just like for the reversible reactions, the irreversible +% reaction params need to be model scoped because +% for the elongation rate the parameter is tied to NTP consumption rates + +globalize_params(m) + +%% Optionally set parameters for in the model object +if ~isempty(p.paramInfo) + pinf = p.paramInfo; + % set the parameters + for i = 1:length(pinf, 1) + setparam(m, pinf.reactionString(i), pinf.paramNames(i), pinf.paramVals(i)); + end +end + + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_txtl_pLacdeGFP.m b/mcmc_simbio/models_and_supporting_files/model_txtl_pLacdeGFP.m new file mode 100755 index 0000000..edfb28b --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_txtl_pLacdeGFP.m @@ -0,0 +1,132 @@ +function m = model_txtl_pLacdeGFP(varargin) +% model_txtl_ptetdeGFP_pLactetR_aTc: txtlsim model containing: +% ptet-UTR1-deGFP +% pLac-UTR1-tetR +% aTc +% +% +% ~~~ INPUTS ~~~ +% +% Optional name-value pair input arguments: +% 'timeVector': A vector of timepoints to set up the model for. Default is 1:100. +% 'paramInfo': A param_info struct that is used to set parameter values in the model object. +% This struct has fields: +% 'paramNames': A string corresponding to the parameter name, or +% a 1 by 2 cell array of strings of forward and backward +% reaction rate parameters for reversible reactions. +% 'paramVals': A numerical value of the parameter, or a 1 by 2 vector +% for reversible reactions. +% 'reactionString': This is either the reaction string or the +% string 'global'. If the paramNames is a 1 x 2 cell array +% and the paramVals is a +% then the reaction is reversible, and if the paramNames is +% a string, then it is a irreversible reaction. When this +% argument is 'global', we always have a string and a scalar +% for paramNames and paramVals respectively. +% 'reactionString': this is either the reaction string or the +% string 'global'. +% 'paramRanges': Non-negative orthant values for the parameter upper and +% lower bounds. For each parameter this is either a +% 2 by 1 vector (for irreversible reactions) or a 2 by 2 +% matrix, where the first and second rows are the upper +% and lower bounds respectively, and the first and second +% columns are the bounds for the forward and reverse rate +% parameters respectively. If nothing is specified, then +% the bounds for a parameter with value VAL is [VAL/10; VAL*10] +% 'paramNotes' Human readable notes. +% +% +% ~~~ OUTPUTS ~~~ +% +% m: a Simbiology Model Object +% +% emo: An exported Simbiology Model Object. +% +% mi: An updated mcmc_info struct. The following fields are added to the mcmc_info struct +% names_ord: An ordered list of species and parameters to be estimated. +% emo: Exported model Object. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser; +p.addParameter('paramInfo', [], @isstruct); +p.addParameter('timeVector', 1:100, @isnumeric); +p.parse(varargin{:}); +p = p.Results; +tv = p.timeVector; + + +%% ################## EDIT THIS SECTION AS NEEDED #################### + +% Specify the parameter config files, dna string and initial concentration, +% inducers etc. See the TXTL Modeling toolbox documentation for more information. + +% setup model object (this model uses the txtl toolbox at +tube1 = txtl_extract('Emcmc2018'); +tube2 = txtl_buffer('Emcmc2018'); +tube3 = txtl_newtube('pLacdeGFP'); +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'deGFP(1000)', 0, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); +m.UserData.energymode = 'regeneration'; +%% MOST LIKELY YOU WILL NOT NEED TO TOUCH THIS SECTION +% See: +% https://www.mathworks.com/help/simbio/ug/selecting-absolute- +% tolerance-and-relative-tolerance-for-simulation.html +cs1 = getconfigset(m); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); +set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', tv(end)*1.0e-6*0.1); +set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 + +tic + [~] = txtl_runsim(m,tv(end)); +toc + + + +% +%% DONT TOUCH THIS SECTION +% modify the base model to get it ready for parameter estimation. +% Change the scope of the reversible reaction parameters from the +% reaction to the model level scope. This is needed for adding rules +% between the parameters (like Kd rules). +% The rules are needed because in parameter esitmation when you change some +% base parameter (like Kd) the parameters that are associated should also +% change. Just like for the reversible reactions, the irreversible +% reaction params need to be model scoped because +% for the elongation rate the parameter is tied to NTP consumption rates + +globalize_params(m) + +%% Optionally set parameters for in the model object +if ~isempty(p.paramInfo) + pinf = p.paramInfo; + % set the parameters + for i = 1:length(pinf, 1) + setparam(m, pinf.reactionString(i), pinf.paramNames(i), pinf.paramVals(i)); + end +end + + +end + diff --git a/mcmc_simbio/models_and_supporting_files/model_txtl_ptetdeGFP_pLactetR_aTc.m b/mcmc_simbio/models_and_supporting_files/model_txtl_ptetdeGFP_pLactetR_aTc.m new file mode 100755 index 0000000..c355c70 --- /dev/null +++ b/mcmc_simbio/models_and_supporting_files/model_txtl_ptetdeGFP_pLactetR_aTc.m @@ -0,0 +1,135 @@ +function m = model_txtl_ptetdeGFP_pLactetR_aTc(varargin) +% model_txtl_ptetdeGFP_pLactetR_aTc: txtlsim model containing: +% ptet-UTR1-deGFP +% pLac-UTR1-tetR +% aTc +% +% +% ~~~ INPUTS ~~~ +% +% Optional name-value pair input arguments: +% 'timeVector': A vector of timepoints to set up the model for. Default is 1:100. +% 'paramInfo': A param_info struct that is used to set parameter values in the model object. +% This struct has fields: +% 'paramNames': A string corresponding to the parameter name, or +% a 1 by 2 cell array of strings of forward and backward +% reaction rate parameters for reversible reactions. +% 'paramVals': A numerical value of the parameter, or a 1 by 2 vector +% for reversible reactions. +% 'reactionString': This is either the reaction string or the +% string 'global'. If the paramNames is a 1 x 2 cell array +% and the paramVals is a +% then the reaction is reversible, and if the paramNames is +% a string, then it is a irreversible reaction. When this +% argument is 'global', we always have a string and a scalar +% for paramNames and paramVals respectively. +% 'reactionString': this is either the reaction string or the +% string 'global'. +% 'paramRanges': Non-negative orthant values for the parameter upper and +% lower bounds. For each parameter this is either a +% 2 by 1 vector (for irreversible reactions) or a 2 by 2 +% matrix, where the first and second rows are the upper +% and lower bounds respectively, and the first and second +% columns are the bounds for the forward and reverse rate +% parameters respectively. If nothing is specified, then +% the bounds for a parameter with value VAL is [VAL/10; VAL*10] +% 'paramNotes' Human readable notes. +% +% +% ~~~ OUTPUTS ~~~ +% +% m: a Simbiology Model Object +% +% emo: An exported Simbiology Model Object. +% +% mi: An updated mcmc_info struct. The following fields are added to the mcmc_info struct +% names_ord: An ordered list of species and parameters to be estimated. +% emo: Exported model Object. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser; +p.addParameter('paramInfo', [], @isstruct); +p.addParameter('timeVector', 1:100, @isnumeric); +p.parse(varargin{:}); +p = p.Results; +tv = p.timeVector; + + +%% ################## EDIT THIS SECTION AS NEEDED #################### + +% Specify the parameter config files, dna string and initial concentration, +% inducers etc. See the TXTL Modeling toolbox documentation for more information. + +% setup model object (this model uses the txtl toolbox at +tube1 = txtl_extract('Emcmc2018'); +tube2 = txtl_buffer('Emcmc2018'); +tube3 = txtl_newtube('pTetdeGFP_pLacTetR_aTc'); +txtl_add_dna(tube3, ... + 'ptet(50)', 'utr1(20)', 'deGFP(1000)', 0, 'plasmid'); +txtl_add_dna(tube3, ... + 'plac(50)', 'utr1(20)', 'tetR(1000)', 0, 'plasmid'); +m = txtl_combine([tube1, tube2, tube3]); +txtl_addspecies(m, 'aTc', 0); +m.UserData.energymode = 'regeneration'; +%% MOST LIKELY YOU WILL NOT NEED TO TOUCH THIS SECTION +% See: +% https://www.mathworks.com/help/simbio/ug/selecting-absolute- +% tolerance-and-relative-tolerance-for-simulation.html +cs1 = getconfigset(m); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); +set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', tv(end)*1.0e-6*0.1); +set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 + +tic + [~] = txtl_runsim(m,tv(end)); +toc + + + +% +%% DONT TOUCH THIS SECTION +% modify the base model to get it ready for parameter estimation. +% Change the scope of the reversible reaction parameters from the +% reaction to the model level scope. This is needed for adding rules +% between the parameters (like Kd rules). +% The rules are needed because in parameter esitmation when you change some +% base parameter (like Kd) the parameters that are associated should also +% change. Just like for the reversible reactions, the irreversible +% reaction params need to be model scoped because +% for the elongation rate the parameter is tied to NTP consumption rates + +globalize_params(m) + +%% Optionally set parameters for in the model object +if ~isempty(p.paramInfo) + pinf = p.paramInfo; + % set the parameters + for i = 1:length(pinf, 1) + setparam(m, pinf.reactionString(i), pinf.paramNames(i), pinf.paramVals(i)); + end +end + + +end + diff --git a/mcmc_simbio/projects/.gitignore b/mcmc_simbio/projects/.gitignore new file mode 100755 index 0000000..bf7e0ef --- /dev/null +++ b/mcmc_simbio/projects/.gitignore @@ -0,0 +1,5 @@ +# git ignore file for the projects directory +/proj_*/ +/html/ + +/explore_*/ \ No newline at end of file diff --git a/mcmc_simbio/projects/IFFL_predictionA.m b/mcmc_simbio/projects/IFFL_predictionA.m new file mode 100755 index 0000000..f517ee8 --- /dev/null +++ b/mcmc_simbio/projects/IFFL_predictionA.m @@ -0,0 +1,848 @@ +%% Prediction script for the IFFL. +% Vipul Singhal, Jun 2019 +% +% % best way to do this is to set up a proper project, complete with dosing +% % etc. That will export the model for you too. +% +% % Generate model object +% mIFFL = model_txtl_lastetIFFL; +% +% % Get Data +% di = ZachIFFL_testdata; +% +% +% +% % set parameters that will be fixed. And the ones that will be sampled from +% % the training set E are labeled with "sample from training E". +% +% % the values tagged with verifiedAgainstTrainingE below are in agreement +% % with the values in trainingE and in mcmc_info_ZSIFFL_predictionA +% +% activeNames_used_to_construct_things = {... +% 'TX_elong_glob', exp(3.121) % % verifiedAgainstTrainingE +% 'TL_elong_glob', exp(3.436) % % verifiedAgainstTrainingE +% 'AGTPdeg_time', exp(10.05) % % verifiedAgainstTrainingE +% 'AGTPreg_ON', exp( -3.9120) % % verifiedAgainstTrainingE +% 'AGTPdeg_rate', exp(-9.7873) % % from the vnprl_F2 set, verifiedAgainstTrainingE +% 'TXTL_INDUCER_LASR_AHL_Kd', exp(13) % % verifiedAgainstTrainingE +% 'TXTL_INDUCER_LASR_AHL_F', exp(0) % % verifiedAgainstTrainingE +% 'TXTL_UTR_UTR1_Kd', exp(0.0542) % % from the vnprl_F2 set, verifiedAgainstTrainingE +% 'TXTL_PLAC_RNAPbound_Kd', exp(10.5) % sample from training E OR exp(10.5) ?? +% 'TXTL_PLAC_RNAPbound_F', exp( 1.5000) % % verifiedAgainstTrainingE +% 'TXTL_NTP_RNAP_1_Kd', exp( 2.9459) % % verifiedAgainstTrainingE +% 'TXTL_NTP_RNAP_2_Kd', exp( 13.9970) % % verifiedAgainstTrainingE +% 'TL_AA_Kd', exp( 6.5566) % % verifiedAgainstTrainingE +% 'TL_AGTP_Kd', exp( 14.5090) % % verifiedAgainstTrainingE +% 'TXTL_RNAdeg_Kd', exp(15.6349) % % from the vnprl_F2 set verifiedAgainstTrainingE +% 'TXTL_INDUCER_TETR_ATC_Kd', exp(-2) % % verifiedAgainstTrainingE +% 'TXTL_INDUCER_TETR_ATC_F', exp(1.577) % % verifiedAgainstTrainingE +% 'TXTL_DIMER_tetR_Kd', exp(-10) % % verifiedAgainstTrainingE +% 'TXTL_DIMER_tetR_F', exp(1.447) % % verifiedAgainstTrainingE +% 'TXTL_PLAS_RNAPbound_Kd', exp(32) % sample from training E +% 'TXTL_PLAS_RNAPbound_F', exp(0) % % verifiedAgainstTrainingE +% 'TXTL_PLAS_TFBIND_Kd', exp(6) % sample from training E +% 'TXTL_PLAS_TFRNAPbound_Kd', exp(9) % sample from training E +% 'TXTL_PROT_deGFP_MATURATION', exp( -6.0748) % % verifiedAgainstTrainingE +% 'TXTL_UTR_UTR1_F', exp( -0.2000) % % verifiedAgainstTrainingE +% 'TXTL_PLAS_TFRNAPbound_F', exp(0) % % verifiedAgainstTrainingE +% 'TXTL_PLAS_TFBIND_F', exp(0) % % verifiedAgainstTrainingE +% 'TXTL_RNAPBOUND_TERMINATION_RATE', 0.15 % sample from training E +% 'TXTL_NTP_RNAP_1_F', exp( 0) % % verifiedAgainstTrainingE +% 'TXTL_NTP_RNAP_2_F', exp( 0) % % verifiedAgainstTrainingE +% 'TXTL_PTET_sequestration_Kd', exp(-0.5) % % verifiedAgainstTrainingE +% 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_Kd', 0.1 % reverse rate here is actually the ASSOCIATION. % ?? +% 'TXTL_PTET_sequestration_F', exp(1.314) % % verifiedAgainstTrainingE +% 'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F', 1 % forward rate is the dissociation. want this to be 100 - 1000x higher than the % ?? +% 'TL_AA_F', exp( -0.3000) % % verifiedAgainstTrainingE +% 'TL_AGTP_F', exp( -1.2000) % % verifiedAgainstTrainingE +% 'TXTL_RIBOBOUND_TERMINATION_RATE', 40 % sample from training E +% 'TXTL_RNAdeg_F', exp(0) % % verifiedAgainstTrainingE +% 'TXTL_RNAdeg_kc', exp(-0.2251) % % from the vnprl_F2 set verifiedAgainstTrainingE +% 'RNAP', exp(5.9) % sample from training E OR exp(5.9) verifiedAgainstTrainingE, but can sample +% 'RNase', exp(9.2) % % verifiedAgainstTrainingE +% 'Ribo', exp(5.9)... % sample from training E OR exp(9.2) verifiedAgainstTrainingE, but can sample +% }; +% +% %% Export model and get it ready for simulation. +% +% +% +% +% %% +% +% titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +% mcmc_trajectories(mi(1).emo,... +% di(mi(1).dataToMapTo),... +% mi(1),... +% (mod1(mi(1).paramMaps(mi(1).orderingIx,1))'),... +% titls',... +% {},... +% 'SimMode', 'curves') +% % +% +% titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +% titls_array = cell(length(titls), 1, length(mi(2).measuredSpeciesIndex)); +% for i = 1:length(mi(2).measuredSpeciesIndex) +% for j = 1:length(titls) +% titls_array(j, 1, i) = titls(j); +% end +% end +% mcmc_trajectories(mi(2).emo,... +% di(mi(2).dataToMapTo),... +% mi(2),... +% (mod1(mi(2).orderingIx)'),... +% titls_array,... +% {},... +% 'SimMode', 'curves') +% % Set random seed, and sample model parameters randomly from the trainingE +% % dataset. +% +% % Generate trajectories from the sampled values, along with means and +% % standard deviations. +% +% % Generate trajectories in collated mode, without the standard deviations. +% +% % + +%% Code construction: + +% The best way to predict using the parameters estimated in the training E +% example is to set up an estimation problem with all the parameters is +% training E to be estimated, run it for a small amount of time, then +% instead of using the paramters estimated, use the parameters from +% training E. + +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_predictionA' +% +% Directory where the project file is stored: +% '/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/mcmc_simbio/projects/proj_ZSIFFL_predictionA' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20190613_131814' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20190613_131814_1_327'). + +% the training E project directory +close all +clear all +saveFinalFigs = '/Users/vipulsinghal/Dropbox/Documents/a_Journal_Papers/Drafts/txtl_bmc_bioinformatics/figs/Jul20_2019_v2/' +finafigmode = true +trainingEdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_trainingE']; +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_predictionA']; + +% the array of parameters with all the fixed parameters and the +% parameters from the training E dataset. +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mIFFL = model_txtl_lastetIFFL; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_predictionA(mIFFL); +di = ZachIFFL_testdata('all_trajectories'); + +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20190512_033129_1_1476'; + ts2 = '20190512_064547_1_1476'; + ts3 = '20190512_094712_1_1845'; + ts4 = '20190512_113712_1_1845'; + ts5 = '20190512_155207_1_1845'; + tstamp = {ts1 ts2 ts3 ts4 ts5}; + nIterID = {1:3 1:8 1:2 1:5 1:7}; + % load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + % 'mi',... + % 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = '20190630_183715_1_327'; +tsToSave = '20190630_183715_1_327'; +tsToSave = '20190720_124011_1_327'; +load(['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/mcmc_simbio/projects/proj_ZSIFFL_predictionA'... + '/simdata_' tsToSave '/full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +data_info = di; % overwrite with new di, with all three trajectories, not just the mean. +mai = mcmc_info.master_info; +% mi = mcmc_info.model_info +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, trainingEdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = [... + {'pol_{Kd, tet}'} % 7 + {'pol_{Kd, lac}'} % 21 + {'pol_{term}'} % 23 + {'Ribo_{term}'} % 28 + {'pol'} % 31 + {'Ribo'} % 33 + {'pol_{Kd,las}'} % 37 + {'plas_{tf, Kd}'} % 39 + {'plas-pol_{tf, Kd}'} ]; % 40 +% verified jun 13, 2019. + +%% +% +% 'RNAP' +% 'Ribo' +% 'RecBCD' +% 'RNase' +% 'AGTP' +% 'CUTP' +% 'AA' +% +% +% 'protein lasR' +% 'OC12HSL:protein lasR' +% +% +% 'RNA utr1--lasR' +% 'Ribo:RNA utr1--lasR' +% +% +% 'DNA plac--utr1--lasR' +% 'RNAP:DNA plac--utr1--lasR' +% 'CUTP:AGTP:RNAP:DNA plac--utr1--lasR' +% 'term_RNAP:DNA plac--utr1--lasR' +% +% +% 'AA:AGTP:Ribo:RNA utr1--lasR' +% 'term_Ribo:RNA utr1--lasR' +% +% +% 'protein tetR' +% 'aTc' +% 'protein tetRdimer' +% +% +% 'RNA utr1--tetR' +% 'Ribo:RNA utr1--tetR' +% +% +% 'DNA plas--utr1--tetR' +% 'RNAP:DNA plas--utr1--tetR' +% +% +% 'AA:AGTP:Ribo:RNA utr1--tetR' +% 'term_Ribo:RNA utr1--tetR' +% +% +% 'protein deGFP' +% 'protein deGFP*' +% +% +% 'RNA utr1--deGFP' +% 'Ribo:RNA utr1--deGFP' +% +% +% 'DNA plas_ptet--utr1--deGFP' +% 'RNAP:DNA plas_ptet--utr1--deGFP' +% +% +% 'AA:AGTP:Ribo:RNA utr1--deGFP' +% 'term_Ribo:RNA utr1--deGFP' +% +% +% 'OC12HSL' +% +% +% 'AGTP:RNAP:DNA plac--utr1--lasR' +% 'CUTP:RNAP:DNA plac--utr1--lasR' +% +% +% 'AA:Ribo:RNA utr1--lasR' +% +% +% 'AGMP' +% +% +% 'RNA utr1--lasR:RNase' +% 'CUMP' +% 'Ribo:RNA utr1--lasR:RNase' +% 'AA:AGTP:Ribo:RNA utr1--lasR:RNase' +% 'term_Ribo:RNA utr1--lasR:RNase' +% 'AA:Ribo:RNA utr1--lasR:RNase' +% +% +% '2 aTc:protein tetRdimer' +% +% +% 'DNA plas--utr1--tetR:OC12HSL:protein lasR' +% 'RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +% +% +% 'CUTP:AGTP:RNAP:DNA plas--utr1--tetR' +% 'term_RNAP:DNA plas--utr1--tetR' +% +% +% 'CUTP:AGTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +% 'term_RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +% +% 'AGTP:RNAP:DNA plas--utr1--tetR' +% 'CUTP:RNAP:DNA plas--utr1--tetR' +% +% +% 'AGTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +% 'CUTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +% +% +% 'AA:Ribo:RNA utr1--tetR' +% +% +% 'RNA utr1--tetR:RNase' +% 'Ribo:RNA utr1--tetR:RNase' +% 'AA:AGTP:Ribo:RNA utr1--tetR:RNase' +% 'term_Ribo:RNA utr1--tetR:RNase' +% 'AA:Ribo:RNA utr1--tetR:RNase' +% +% +% 'DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'CUTP:AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'term_RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'CUTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% +% +% 'DNA plas_ptet--utr1--deGFP:protein tetRdimer' +% 'DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer' +% 'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer' +% +% +% 'AA:Ribo:RNA utr1--deGFP' +% +% +% 'RNA utr1--deGFP:RNase' +% 'Ribo:RNA utr1--deGFP:RNase' +% 'AA:AGTP:Ribo:RNA utr1--deGFP:RNase' +% 'term_Ribo:RNA utr1--deGFP:RNase' +% 'AA:Ribo:RNA utr1--deGFP:RNase' + +%% +mvarray = masterVecArray(marray(2:end,:,:), mai); +% clear marray +for miID = 1:5 %1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'mean', 'separateExpSim', true,'collateDoses', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', [num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + % here we plot the individual trajectories for each species. + + end + ms = currmi.measuredSpecies; + +end + + +%% +% +% ms = {{'protein lasR'}; +% {'OC12HSL:protein lasR'}; +% {'OC12HSL'}; +% {'RNA utr1--lasR'; +% 'Ribo:RNA utr1--lasR'; +% 'AA:Ribo:RNA utr1--lasR'; +% 'AA:AGTP:Ribo:RNA utr1--lasR'; +% 'term_Ribo:RNA utr1--lasR'}; +% {'protein tetR'}; +% {'protein tetRdimer'}; +% {'DNA plas_ptet--utr1--deGFP:protein tetRdimer'; +% 'DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer'; +% 'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer'}; +% {'DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'CUTP:AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'term_RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'CUTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR'}; +% {'protein deGFP*', 'protein deGFP'}}; +% +% for miID = 1:5 +% currmi = mi(miID); +% currdi = data_info(currmi.dataToMapTo); +% tv = currdi.timeVector; +% dose = currmi.dosedVals'; +% [da{miID}, idxnotused{miID}] = simulatecurves(currmi.emo,marrayOrd(:,:)', 20, dose, tv, ms); +% end +% +% % {'2 aTc:protein tetRdimer'}; +% % {'aTc'}; +% +% close all +% currda = da{4}; +% specieslabels = {'lasR', 'AHL:lasR','AHL', 'lasR RNA', 'tetR', 'tetRdimer',... +% 'repressed_comb_prom', 'activated_comb_prom', 'GFP'}; % 'aTc:tetR','aTc', +% doselabels = {'1nM', '0.1nM', '0.01nM', '0.001nM', '0.0001nM', '0.00001nM', '0nM'}; +% figure +% nSp = size(currda, 2); +% [fac1, fac2] = twofactors(nSp); +% +% for speciesGrp = 1:nSp +% subplot(fac1, fac2, speciesGrp) +% for dID = 1:length(doselabels) +% plot(tv, mean(currda(:, speciesGrp, :, dID), 3) + 0.01*randn(length(tv),1), 'LineWidth', 1.5) +% hold on +% end +% title([specieslabels{speciesGrp}]) +% legend(doselabels) +% end +% +% %% same thing, explore the lasR activation dynamics. +% % why is there significant activation even at 0.03nM lasR. +% %should it not just be close to 0 expression? +% +% +% ms = {{'protein lasR'}; +% {'OC12HSL:protein lasR'}; +% {'OC12HSL'}; +% {'RNA utr1--lasR'; +% 'Ribo:RNA utr1--lasR'; +% 'AA:Ribo:RNA utr1--lasR'; +% 'AA:AGTP:Ribo:RNA utr1--lasR'; +% 'term_Ribo:RNA utr1--lasR'}; +% {'protein tetR'}; +% {'protein tetRdimer'}; +% {'DNA plas_ptet--utr1--deGFP:protein tetRdimer'; +% 'DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer'; +% 'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer'}; +% {'DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'CUTP:AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'term_RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +% 'CUTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR'}; +% {'protein deGFP*', 'protein deGFP'}}; +% +% % {'2 aTc:protein tetRdimer'}; +% % {'aTc'}; +% for miID = 1:5 +% +% currmi = mi(miID); +% currdi = data_info(currmi.dataToMapTo); +% tv = currdi.timeVector; +% dose = currmi.dosedVals'; +% if miID == 2 +% dose(end, 1) = 0 +% end +% +% [da{miID}, idxnotused{miID}] = simulatecurves(currmi.emo,marrayOrd(:,:)', 20, dose, tv, ms); +% end +% close all +%% +% currda = da{4}; +% specieslabels = {'lasR', 'AHL:lasR','AHL', 'lasR RNA', 'tetR', 'tetRdimer',... +% 'repressed_comb_prom', 'activated_comb_prom', 'GFP'}; % 'aTc:tetR','aTc', +% doselabels = {'2nM', '1nM', '0.5nM', '0.25nM', '0.125nM', '0.0625nM', '0.03125nM'}; +% figure +% nSp = size(currda, 2); +% [fac1, fac2] = twofactors(nSp); +% +% for speciesGrp = 1:nSp +% subplot(fac1, fac2, speciesGrp) +% for dID = 1:length(doselabels) +% plot(tv, mean(currda(:, speciesGrp, :, dID), 3) + 0.01*randn(length(tv),1), 'LineWidth', 1.5) +% hold on +% end +% title([specieslabels{speciesGrp}]) +% legend(doselabels) +% end + +% I dont think this can be fixed. Maybe if we had the lasR DNA perturbation +% data. Don't have that. Not gonna sweat it. + +%% Generate prediction figure +% Next, We plot the collated results: two columns, one for data, the other +% for the predictions. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +NN = 50; % number of trajectories. +da = cell(NN, 1); +idxnotused = cell(NN, 1); +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + dose = currmi.dosedVals'; + if miID == 2 + dose(end, 1) = 0; + end + [da{miID}, idxnotused{miID}] = simulatecurves(currmi.emo,marrayOrd(:,:)', NN, dose, tv, ms); +end +%% plot the trajectories figure. +close all + + +% +ylims = {[4, 4, 4, 4, 12]; + 2*[4, 4, 4, 4, 12]; + 3*[4, 4, 4, 4, 12]}; + + +lengthToPlotArray = [31, 41, 81]; +for outercount = 1:length(lengthToPlotArray) +% outercount = outercount+1; + lengthToPlot = lengthToPlotArray(outercount) + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.1]); + + miToUse = [1 2 3 4 5]; + titleArray = {'3OC12'; + 'lasR DNA'; + 'aTc'; + 'tetR DNA'; + 'deGFP DNA'}; + + legends = [{'10uM', '1uM', '.1uM', '10nM', '1nM', '.1nM', '0nM'}; + {'2nM', '1nM', '.5nM', '.25nM', '125pM', '62.5pM', '0pM'}; + {'10uM', '1uM', '.1uM', '10nM', '1nM', '0.1nM', '0nM'}; + {'1nM', '.1nM', '.01nM', '1pM', '.1pM', '10fM', '0fM'}; + {'4nM', '2nM', '1nM', '.5nM', '.25nM', '.125nM', '0nM'}]; + ms = currmi.measuredSpecies; + mvarray = masterVecArray(marray(2:end,:,:), mai); +% lengthToPlot = 31; % 180 min = 31 + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + % samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + % marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + tv = currdi.timeVector; + dose = currmi.dosedVals'; + if miToUse(count) == 2 + dose(end, 1) = 0; + end + %[da{count}, idxnotused{count}] = simulatecurves(currmi.emo,marrayOrd(:,:)', 30, dose, tv, ms); + + subplot(5, 2, (count-1)*2+1) + for dID = 1:length(legends(count, :)) + plot(tv(1:lengthToPlot)/60, 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, :, dID),3), 'LineWidth', 1.5, 'Color', colorz(dID+2, :)) + hold on + end + title([titleArray{count} ' varying (Experiment)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*6, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + dID; + plot(tv(1:lengthToPlot)/60, 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3), 'LineWidth', 1.5, 'Color', colorz(dID+2, :)) + hold on + end + title([titleArray{count} ' varying (Prediction)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 13) + legend('boxoff') + + % ylabel('deGFP, nM') + axis([0 (lengthToPlot-1)*6 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + +% print([saveFinalFigs 'prediction_traj_N' num2str(NN) '_' num2str((lengthToPlot-1)*6) 'min'],'-depsc') +% print([saveFinalFigs 'prediction_traj_N' num2str(NN) '_' num2str((lengthToPlot-1)*6) 'min'],'-djpeg') +% +% print([saveFinalFigs 'prediction_traj_N' num2str(NN) '_' num2str((lengthToPlot-1)*6) 'min'],'-dpng') + % + + % + % Now generate the plots + % + % build the data array + + figure + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + exp_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + doseArray(1, end) = 0.1/100; % 30c12 + doseArray(2, end) = 0.0625/4; % lasR dna + doseArray(3, end) = 0.1/100; % aTc + doseArray(4, end) = 0.00001/100; % tetR dna + doseArray(5, end) = 0.125/4; % deGFP dna + + + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + + + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/2.5 ss(4)/2]); + + + xTickLabels = [{'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'1', '10^{-2}', '10^{-4}', '0'}; + {'4', '1', '2^{-2}', '0'}]; + titleArray = {'3OC12'; + 'lasR DNA'; + 'aTc'; + 'tetR DNA'; + 'deGFP DNA'}; + xLab = {'3OC12, uM'; + 'lasR DNA, nM'; + 'aTc, uM'; + 'tetR DNA, nM'; + 'deGFP DNA, nM'}; + + for count = 1:length(miToUse) + + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + + + +% +% ax = semilogx(doseArray(count, :), ... +% exp_endpoints(count, :)/1000, ... +% 'LineWidth', 2); +% hold on +% errorbar(doseArray(count, :), ... +% sim_endpoints(count, :), ... +% sim_endpointsSD(count, :), 'LineWidth', 2) + hold on + if count ==1 + legend('Experiment', 'Prediction', 'Location', 'NorthWest', ... + 'FontSize', 18) + end + + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 18 + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + print([saveFinalFigs 'prediction_end_N' num2str(NN) '_' num2str((lengthToPlot-1)*6) 'min'],'-depsc') +% print([saveFinalFigs 'prediction_end_N' num2str(NN) '_' num2str((lengthToPlot-1)*6) 'min'],'-djpeg') +% print([saveFinalFigs 'prediction_end_N' num2str(NN) '_' num2str((lengthToPlot-1)*6) 'min'],'-dpng') +end + +close all + +%% + +% +% +% +% +% % get the simulated data endpoints. +% title([titleArray{count} ' varying (Experiment)']) +% ylabel('deGFP, uM', 'FontSize', 14) +% axis([0 (lengthToPlot-1)*6, 0 ylims(count)]) +% if count ==length(miToUse) +% xlabel('time, minutes', 'FontSize', 14) +% end +% ax = gca; +% ax.FontSize = 14; +% +% subplot(5, 2, (count-1)*2+2) +% for dID = 1:length(legends(count, :)) +% dID; +% plot(tv(1:lengthToPlot)/60, 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3), 'LineWidth', 1.5, 'Color', colorz(dID+2, :)) +% hold on +% end +% title([titleArray{count} ' varying (Prediction)']) +% legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 13) +% legend('boxoff') +% +% % ylabel('deGFP, nM') +% axis([0 (lengthToPlot-1)*6 0 ylims(count)]) +% if count ==length(miToUse) +% xlabel('time, minutes', 'FontSize', 14) +% end +% ax = gca; +% ax.FontSize = 14; +% +% +% +% + + + + +%% Simulate and plot all the species in the system that could be of interest. +% The geometry that is failing is, for example, number 3, 4. +% SimBiology Species Array +% +% Index: Compartment: Name: InitialAmount: InitialAmountUnits: +% 1 contents RNAP 100 +% 2 contents Ribo 30 +% 3 contents RecBCD 5 +% 4 contents RNase 100 +% 5 contents AGTP 3.18005e+06 +% 6 contents CUTP 1.90803e+06 +% 7 contents AA 3.18005e+07 +% 8 contents protein lasR 0 +% 9 contents OC12HSL:protein lasR 0 +% 10 contents RNA utr1--lasR 0 +% 11 contents Ribo:RNA utr1--lasR 0 +% 12 contents DNA plac--utr1--lasR 0 +% 13 contents RNAP:DNA plac--utr1--lasR 0 +% 14 contents CUTP:AGTP:RNAP:DNA plac--utr1--lasR 0 +% 15 contents term_RNAP:DNA plac--utr1--lasR 0 +% 16 contents AA:AGTP:Ribo:RNA utr1--lasR 0 +% 17 contents term_Ribo:RNA utr1--lasR 0 +% 18 contents protein tetR 0 +% 19 contents aTc 0 +% 20 contents protein tetRdimer 0 +% 21 contents RNA utr1--tetR 0 +% 22 contents Ribo:RNA utr1--tetR 0 +% 23 contents DNA plas--utr1--tetR 0 +% 24 contents RNAP:DNA plas--utr1--tetR 0 +% 25 contents AA:AGTP:Ribo:RNA utr1--tetR 0 +% 26 contents term_Ribo:RNA utr1--tetR 0 +% 27 contents protein deGFP 0 +% 28 contents protein deGFP* 0 +% 29 contents RNA utr1--deGFP 0 +% 30 contents Ribo:RNA utr1--deGFP 0 +% 31 contents DNA plas_ptet--utr1--deGFP 0 +% 32 contents RNAP:DNA plas_ptet--utr1--deGFP 0 +% 33 contents AA:AGTP:Ribo:RNA utr1--deGFP 0 +% 34 contents term_Ribo:RNA utr1--deGFP 0 +% 35 contents OC12HSL 0 +% 36 contents AGTP:RNAP:DNA plac--utr1--lasR 0 +% 37 contents CUTP:RNAP:DNA plac--utr1--lasR 0 +% 38 contents AA:Ribo:RNA utr1--lasR 0 +% 39 contents AGMP 0 +% 40 contents RNA utr1--lasR:RNase 0 +% 41 contents CUMP 0 +% 42 contents Ribo:RNA utr1--lasR:RNase 0 +% 43 contents AA:AGTP:Ribo:RNA utr1--lasR:RNase 0 +% 44 contents term_Ribo:RNA utr1--lasR:RNase 0 +% 45 contents AA:Ribo:RNA utr1--lasR:RNase 0 +% 46 contents 2 aTc:protein tetRdimer 0 +% 47 contents DNA plas--utr1--tetR:OC12HSL:protein lasR 0 +% 48 contents RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR 0 +% 49 contents CUTP:AGTP:RNAP:DNA plas--utr1--tetR 0 +% 50 contents term_RNAP:DNA plas--utr1--tetR 0 +% 51 contents CUTP:AGTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR 0 +% 52 contents term_RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR 0 +% 53 contents AGTP:RNAP:DNA plas--utr1--tetR 0 +% 54 contents CUTP:RNAP:DNA plas--utr1--tetR 0 +% 55 contents AGTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR 0 +% 56 contents CUTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR 0 +% 57 contents AA:Ribo:RNA utr1--tetR 0 +% 58 contents RNA utr1--tetR:RNase 0 +% 59 contents Ribo:RNA utr1--tetR:RNase 0 +% 60 contents AA:AGTP:Ribo:RNA utr1--tetR:RNase 0 +% 61 contents term_Ribo:RNA utr1--tetR:RNase 0 +% 62 contents AA:Ribo:RNA utr1--tetR:RNase 0 +% 63 contents DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR 0 +% 64 contents RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR 0 +% 65 contents CUTP:AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR 0 +% 66 contents term_RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR 0 +% 67 contents AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR 0 +% 68 contents CUTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR 0 +% 69 contents DNA plas_ptet--utr1--deGFP:protein tetRdimer 0 +% 70 contents DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer 0 +% 71 contents RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer 0 +% 72 contents AA:Ribo:RNA utr1--deGFP 0 +% 73 contents RNA utr1--deGFP:RNase 0 +% 74 contents Ribo:RNA utr1--deGFP:RNase 0 +% 75 contents AA:AGTP:Ribo:RNA utr1--deGFP:RNase 0 +% 76 contents term_Ribo:RNA utr1--deGFP:RNase 0 +% 77 contents AA:Ribo:RNA utr1--deGFP:RNase + + diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase1.m b/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase1.m new file mode 100755 index 0000000..e138ee1 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase1.m @@ -0,0 +1,195 @@ + + + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet']; +addpath(projdir) + +jpgsave = false; +figsave = true; + +% Load model, mcmc_info, and data_info. +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mcmc_info = mcmc_info_ZSIFFL_mtet_phase1(mtet); +di = data_ZSIFFL; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 2; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190420_045130_1_92790'; + ts2 = '20190420_070950_1_30930'; + tstamp = {ts1 ts2}; + nIterID = {1:2, 1}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + case 2 + ts1 = '20190420_045130_1_92790'; + ts2 = '20190420_071438_1_30930'; + ts3 = '20190420_071438_2_15465'; + ts4 = '20190420_155505_1_7732'; + ts5 = '20190420_155505_2_3093'; + ts6 = '20190420_155505_3_1546'; + ts7 = '20190420_155505_4_773'; + ts8 = '20190420_155505_5_309'; + ts9 = '20190420_155505_6_155'; + ts10 = '20190420_155505_7_77'; + ts11 = '20190420_155505_8_31'; +% +% tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; +% nIterID = {1:2, 1:10 1:8 1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; + + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; + nIterID = {1:2, 1:10 1:8 1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + +% conclusions from case 2: +% [{'pol_{Kd, tet}' } OK +% {'rep_{Kd}'} expand lower bound from ~3 to maybe -5? +% {'rep_F' } OK +% {'ATC_{Kd}' } expand upper bound from 18 to 25? +% {'ATC_F' } OK +% {'dim_{Kd}' } expand lower bound from 7 to -3 +% {'dim_F' } + +end +tsToSave = ts11; +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full + + +parnames = ... + [{'pol_{Kd, tet}' } + {'rep_{Kd}'} + {'rep_F' } + {'ATC_{Kd}' } + {'ATC_F' } + {'dim_{Kd}' } + {'dim_F' } + ]; +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% +%% +if plotflag +% close all + % Plot trace and corner (posterior distribution) plots + mcmc_plot(marray(:, 1:40:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +%% + +% parRanges([6,7, 9], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') +% +% paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +% parRanges(paramIndices, :) = [... +% 2.3 2.95; %1 +% 8.6 8.95; %2 +% -10.1 -9.7; %3 +% 13 15; %4 +% -1 5 ; %5 +% 15.59 15.73; %6 +% -0.2966 0.1031; %7 +% 0.7 2.2; %8 pol +% 8.385 8.622;%9 RNase +% 3.18 3.69; % 10 -- TLcat +% -3 13.5;%RiboKd +% 2 3;% Ribo term +% 3 4.6 ];% Ribo +% marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% +% CandidateParams = marray_cut(:,1:100:end,end) +% figure +% [C,lags,ESS]=eacorr(marray(:, :,1:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% + %% + + + mvarray = masterVecArray(marray_cut, mai); + clear marray + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'RNAspike'); + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); + clear mvarray + titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'MGa_deGFP'); +end +marrayOrd(:,1:5,end) +clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase1_b.m b/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase1_b.m new file mode 100755 index 0000000..c0e2524 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase1_b.m @@ -0,0 +1,258 @@ + + +% clear all +% clear all + +%% +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet']; + +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +addpath(projdir) + +jpgsave = true; +figsave = true; + +% Load model, mcmc_info, and data_info. +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mcmc_info = mcmc_info_ZSIFFL_mtet_phase1(mtet); +di = data_ZSIFFL; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 3; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190420_045130_1_92790'; + ts2 = '20190420_070950_1_30930'; + tstamp = {ts1 ts2}; + nIterID = {1:2, 1}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + case 2 + ts1 = '20190420_045130_1_92790'; + ts2 = '20190420_071438_1_30930'; + ts3 = '20190420_071438_2_15465'; + ts4 = '20190420_155505_1_7732'; + ts5 = '20190420_155505_2_3093'; + ts6 = '20190420_155505_3_1546'; + ts7 = '20190420_155505_4_773'; + ts8 = '20190420_155505_5_309'; + ts9 = '20190420_155505_6_155'; + ts10 = '20190420_155505_7_77'; + ts11 = '20190420_155505_8_31'; + % + % tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; + % nIterID = {1:2, 1:10 1:8 1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; + + tstamp = {ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; + nIterID = {1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + % conclusions from case 2: + % [{'pol_{Kd, tet}' } OK + % {'rep_{Kd}'} expand lower bound from ~3 to maybe -5? + % {'rep_F' } OK + % {'ATC_{Kd}' } expand upper bound from 18 to 25? + % {'ATC_F' } OK + % {'dim_{Kd}' } expand lower bound from 7 to -3 + % {'dim_F' } + + case 3 + ts1 = '20190421_155749_1_773'; + ts2 = '20190421_155749_2_309'; + ts3 = '20190422_142534_1_773'; + ts4 = '20190422_214228_1_773'; + ts5 = '20190424_104801_1_773'; + + tstamp = {ts1 ts2 ts3 ts4 ts5}; + nIterID = {1:10 1:2 1:4 1:7 1:14}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts5; +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full + + +parnames = ... + [ {'rep_{Kd}'} + {'ATC_{Kd}' } + {'dim_{Kd}' } ]; +% +%% +if plotflag + % close all + % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,(end - 70):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); + % + + % {'rep_{Kd}'} -1.16, -0.92 + % + + parIDs = [1 2 3]; + parRanges(parIDs, :) = [-1.16, -0.92 ; + -4 -0.5; + -15 -8.5] + + marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') + + + + + % We can literally pick any point in this cartesian product. + % parRanges(parIDs, :) = [-1.16, -0.92 ; + % -4 -0.5; + % -15 -8.5] + + + % parRanges([1, 2, 3], :) = [15.59 15.73 ; + % -0.2966 0.1031; + % 8.385 8.622]; + % marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); + % + % mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... + % 'savematlabfig', figsave, 'savejpeg', false,... + % 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + % mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); + % mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + % + % paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; + % parRanges(paramIndices, :) = [... + % 2.3 2.95; %1 + % 8.6 8.95; %2 + % -10.1 -9.7; %3 + % 13 15; %4 + % -1 5 ; %5 + % 15.59 15.73; %6 + % -0.2966 0.1031; %7 + % 0.7 2.2; %8 pol + % 8.385 8.622;%9 RNase + % 3.18 3.69; % 10 -- TLcat + % -3 13.5;%RiboKd + % 2 3;% Ribo term + % 3 4.6 ];% Ribo + % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); + % + % mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... + % 'savematlabfig', figsave, 'savejpeg', false,... + % 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + % + % CandidateParams = marray_cut(:,1:100:end,end) + % figure + % [C,lags,ESS]=eacorr(marray(:, :,1:end));%10000:end + % plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + % grid on + % xlabel('lags') + % ylabel('autocorrelation'); + % text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... + % ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') + % title('Markov Chain Auto Correlation') + % + %% Plot trajectories. + + % rebuild the master vector array, either via mcmc_cut or just using + % all estimated points. + + % mvarray = masterVecArray(marray_cut, mai); + mvarray = masterVecArray(marray, mai); + clear marray + + for miID = 1:length(mi) + currmi = mi(miID); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', [extrastring num2str(miID) ' ' num2str(msID)]); + end + +% +% % +% marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +% clear mvarray +% titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +% titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); +% ms = {'MG aptamer', 'deGFP'}; +% for i = 1:length(mi(2).measuredSpeciesIndex) +% for j = 1:length(titls) +% titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +% titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +% end +% end +% mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +% titls_array, {},... +% 'SimMode', 'meanstd', 'separateExpSim', true,... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'MGa_deGFP'); + end +% marrayOrd(:,1:5,end) +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase2.m b/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase2.m new file mode 100755 index 0000000..66c6b15 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_mtet_phase2.m @@ -0,0 +1,235 @@ + + +% clear all + + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet_phase2']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_mtet_phase2(mtet, mlac); + +di = data_ZSIFFL; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 2; +plotflag = true; +switch tsIDtouse + + case 1 + ts1 = '20190427_170334_1_2058'; + ts2 = '20190427_170334_2_1029'; + + tstamp = {ts1 ts2}; + nIterID = {1:10 1:3}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + case 2 + ts1 = '20190428_142033_1_2058'; + ts2 = '20190428_142033_2_1029'; + ts3 = '20190429_083138_1_1029'; + ts4 = '20190429_200219_1_1029'; + ts5 = '20190429_200219_2_412'; + ts6 = '20190430_141254_1_412'; + ts7 = '20190430_141254_2_206'; + ts8 = '20190501_042829_1_617'; + ts9 = '20190501_123015_1_617'; + ts10 = '20190502_105714_1_412'; + ts11 = '20190503_073640_1_412'; + ts12 = '20190503_113414_1_412'; + ts13 = '20190503_170440_1_412'; + ts14 = '20190504_155258_1_412'; + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11 ts12 ts13 ts14}; + nIterID = {1:10 1:2 1:4 1:5 1:3 1:5 1:5 1:4 1:8 1:11 1 1 11 13}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts14; +mai.masterVector + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full + + +parnames = ... + [... + {'tx_{cat}'} + {'tl_cat'} + {'tau'} + {'pol_{Kd,tet}'} + {'rep_{Kd}'} + {'ATC_{Kd}' } + {'pol_{Kd,lac}' } + {'pol'} + {'RNase'} + {'Ribo'}]; +% {'TL_elong_glob' } +% {'AGTPdeg_time' } +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_PLAC_RNAPbound_Kd' } +% {'RNAP' } +% {'RNase' } +% {'Ribo' } + +% if plotflag + mcmc_plot(marray(:, 1:end,(end-(100)):10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllW_last150_thin10'); + %% +% mcmc_plot(marray(:, 1:5:end,1:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +%% + +% {'rep_{Kd}'} -1.16, -0.92 +% + +% parIDs = [1 2 3]; +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') + + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') +% +% paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +% parRanges(paramIndices, :) = [... +% 2.3 2.95; %1 +% 8.6 8.95; %2 +% -10.1 -9.7; %3 +% 13 15; %4 +% -1 5 ; %5 +% 15.59 15.73; %6 +% -0.2966 0.1031; %7 +% 0.7 2.2; %8 pol +% 8.385 8.622;%9 RNase +% 3.18 3.69; % 10 -- TLcat +% -3 13.5;%RiboKd +% 2 3;% Ribo term +% 3 4.6 ];% Ribo +% marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% +% CandidateParams = marray_cut(:,1:100:end,end) +% figure +% [C,lags,ESS]=eacorr(marray(:, :,1:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% + %% Plot trajectories. + + % rebuild the master vector array, either via mcmc_cut or just using + % all estimated points. + + % mvarray = masterVecArray(marray_cut, mai); + mvarray = masterVecArray(marray, mai); +% clear marray + % + for miID = 1:length(mi) + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', [extrastring num2str(miID) ' ' num2str(msID)]); + end + % +% end +marrayOrd(:,1:5,end) +clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_testA.m b/mcmc_simbio/projects/analysis_ZSIFFL_testA.m new file mode 100755 index 0000000..7473ca4 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_testA.m @@ -0,0 +1,260 @@ + +% analysis_ZSIFFL_testA.m +% In this file, we simulate the IFFL for the full set of test experiments +% (5 in all). We will be drawing upon parameters from the parameter set of +% training_fullE, which is in itself a culmination of a lot of previous +% training. +% We will define a new model, the IFFL, and an associated MCMC info, from +% which dosing info etc will be taken for mcmc_trajectories to plot the +% information. + +clear all +close all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_testA']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullE(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20190512_033129_1_1476'; + ts2 = '20190512_064547_1_1476'; + ts3 = '20190512_094712_1_1845'; + tstamp = {ts1 ts2}; + nIterID = {1:3 1:8 1:2}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = [... + {'pol_{Kd, tet}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots + mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'Without_transient'); +% % % % %% +% + mcmc_plot(marray(:, 1:end,(end - 20):4:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + + % actually i think it is better to just set te parameters using gaussian balls, + % and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + + % Plot trajectories. + + % rebuild the master vector array, either via mcmc_cut or just using + % all estimated points. + + % +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); + mvarray = masterVecArray(marray, mai); +% clear marray + % + for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', [extrastring num2str(miID) ' ' num2str(msID)]); + end + % +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_full.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_full.m new file mode 100755 index 0000000..277f968 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_full.m @@ -0,0 +1,270 @@ + + +% clear all +close all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_training']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_full(mtet, mlac, mlas); + +di = data_ZSIFFL; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% +% plot data from existing simulations. +tsIDtouse = 2; +plotflag = true; +switch tsIDtouse + + case 1 % was hitting an expression ceiling here. also, not really activating. + ts1 = '20190503_170158_1_3691'; + ts2 = '20190503_170158_2_1845'; + ts3 = '20190503_170158_3_1107'; + ts4 = '20190504_153702_1_1107'; + ts5 = '20190504_153702_2_738'; + ts6 = '20190505_023615_1_738'; + + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6}; + nIterID = {1:10 1:10 1:7 1:10 1:10 1:7}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); + + + case 2 % this is after including the termination parameters. + ts1 = '20190507_064919_1_1845'; + ts2 = '20190507_102955_1_1845'; + + tstamp = {ts1 ts2}; + nIterID = {1:6 1:6}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); + +end +tsToSave = ts2; +mai.masterVector + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full + + +parnames = ... + [{'pol_{Kd,tet}'} + {'pol_{Kd,lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; +% activeNames(estParamsIX,:) +% +% ans = +% +% 123 cell array +% +% {'TXTL_PTET_RNAPbound_Kd' } {[1.5713e+07]} {12 double} +% {'TXTL_PLAC_RNAPbound_Kd' } {[3.6316e+04]} {12 double} +% {'RNAP' } {[ 365.0375]} {12 double} +% {'Ribo' } {[ 365.0375]} {12 double} +% {'TXTL_INDUCER_LASR_AHL_Kd'} {[ 0.1353]} {12 double} +% {'TXTL_INDUCER_LASR_AHL_F' } {[ 3.6693]} {12 double} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 0.1353]} {12 double} +% {'TXTL_PLAS_RNAPbound_F' } {[ 3.6693]} {12 double} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0.1353]} {12 double} +% {'TXTL_PLAS_TFRNAPbound_Kd'} {[ 7.3891]} {12 double} +% {'TXTL_PLAS_TFRNAPbound_F' } {[ 3.6693]} {12 double} +% {'TXTL_PLAS_TFBIND_F' } {[ 3.6693]} {12 double} +% +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% % % % mcmc_plot(marray(:, 1:end,(end-120):5:end), parnames(:),... +% % % % 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% % % % 'projdir', projdir, 'tstamp', tsToSave,... +% % % % 'extrafignamestring', 'AllWalkers'); +% % % % %% + mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +% % % % % + +% {'rep_{Kd}'} -1.16, -0.92 +% + +% parIDs = [1 2 3]; +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') + + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + + % actually i think it is better to just set te parameters using gaussian balls, + % and fix as many as possible, and jsut explore the Plas and OC12 Kds. +%% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + + % Plot trajectories. + + % rebuild the master vector array, either via mcmc_cut or just using + % all estimated points. + + +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut', mai); + mvarray = masterVecArray(marray, mai); +% clear marray + % + for miID = length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', [extrastring num2str(miID) ' ' num2str(msID)]); + end + % +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullB.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullB.m new file mode 100755 index 0000000..f08a0e2 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullB.m @@ -0,0 +1,245 @@ + + +% clear all +close all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_trainingB']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullB(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20190508_001705_1_1845'; + ts2 = '20190508_213950_1_1107'; + ts3 = '20190509_024244_1_738'; + ts4 = '20190509_062932_1_738'; + tstamp = {ts1 ts2 ts3 ts4}; + nIterID = {1:7 1:9 1:6 1:2}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = ts4; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... + [{'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; +% activeNames(estParamsIX,:) +% +% ans = +% +% 123 cell array +% +% {'TXTL_PTET_RNAPbound_Kd' } {[1.5713e+07]} {12 double} +% {'TXTL_PLAC_RNAPbound_Kd' } {[3.6316e+04]} {12 double} +% {'RNAP' } {[ 365.0375]} {12 double} +% {'Ribo' } {[ 365.0375]} {12 double} +% {'TXTL_INDUCER_LASR_AHL_Kd'} {[ 0.1353]} {12 double} +% {'TXTL_INDUCER_LASR_AHL_F' } {[ 3.6693]} {12 double} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 0.1353]} {12 double} +% {'TXTL_PLAS_RNAPbound_F' } {[ 3.6693]} {12 double} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0.1353]} {12 double} +% {'TXTL_PLAS_TFRNAPbound_Kd'} {[ 7.3891]} {12 double} +% {'TXTL_PLAS_TFRNAPbound_F' } {[ 3.6693]} {12 double} +% {'TXTL_PLAS_TFBIND_F' } {[ 3.6693]} {12 double} +% +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% % % % mcmc_plot(marray(:, 1:end,(end-120):5:end), parnames(:),... +% % % % 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% % % % 'projdir', projdir, 'tstamp', tsToSave,... +% % % % 'extrafignamestring', 'AllWalkers'); +% % % % %% + mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +% % % % % + +% {'rep_{Kd}'} -1.16, -0.92 +% + +% parIDs = [1 2 3]; +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') + + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + + % actually i think it is better to just set te parameters using gaussian balls, + % and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + + % Plot trajectories. + + % rebuild the master vector array, either via mcmc_cut or just using + % all estimated points. + + +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut', mai); + mvarray = masterVecArray(marray, mai); +% clear marray + % + for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', [extrastring num2str(miID) ' ' num2str(msID)]); + end + % +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC.m new file mode 100755 index 0000000..8cfc6b1 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC.m @@ -0,0 +1,265 @@ + + +clear all +close all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_trainingC']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20190509_092707_1_1476'; + ts2 = '20190509_160552_1_1476'; + ts3 = '20190509_160552_2_738'; + ts4 = '20190509_160552_3_554'; + ts5 = '20190510_064333_1_369'; + ts6 = '20190510_064333_2_185'; + ts7 = '20190510_064333_3_74'; + ts8 = '20190511_014023_1_74'; + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8}; + nIterID = {1:8 1:20 1:20 1:20 1:20 1:20 1:8 1:5}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = ts8; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... + [{'k_{tx}'} + {'k_{tl}'} + {'pol_{Kd, tet}'} + {'rep_{tet}'} + {'atc_{Kd}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PTET_sequestration_Kd' } {[-10]} {[ 5]} +% {'TXTL_INDUCER_TETR_ATC_Kd' } {[-15]} {[ 5]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_INDUCER_LASR_AHL_Kd' } {[ 5]} {[20]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:10:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'AllWalkers'); +% % % % %% +%% + mcmc_plot(marray(:, 1:end,(end-40):end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +% % % % % +%% + + +parIDs = [4 5 11]; +% parRanges(parIDs, :) = [-1 0 ; +% -4 0; +% 11 15] + parRanges(parIDs, :) = [-1 0 ; + -3 -1; + 11.5 14.5] + + marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); + + mcut0 = marray_cut(parIDs, :,:); + mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); + + + mcmc_plot(marray_cut, parnames(:),... + 'savematlabfig', figsave, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); + mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') + + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + + % actually i think it is better to just set te parameters using gaussian balls, + % and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + + % Plot trajectories. + + % rebuild the master vector array, either via mcmc_cut or just using + % all estimated points. + + %% +% mvarray = masterVecArray(marray_gauss, mai); + mvarray = masterVecArray(marray_cut, mai); + %mvarray = masterVecArray(marray, mai); +% clear marray + % + for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', [extrastring num2str(miID) ' ' num2str(msID)]); + end + % +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v2.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v2.m new file mode 100644 index 0000000..46012b2 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v2.m @@ -0,0 +1,506 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\May_2020\ZSIFFL_training_fullC_v2\' + +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v2']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = false; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v2(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. + + +% +% ts1 = '20200518_175057_1_7381'; +% nIterID1 = {1:3}; +% marray1 = mcmc_get_walkers({ts1},nIterID1, projdir); +% marray1 = marray1(:,1:1000, :); + +tsIDtouse = 1; +plotflag = true; + +switch tsIDtouse + case 1 % this is after including the termination parameters. + + ts2 = '20200521_005205_1_73814'; + ts3 = '20200519_011552_2_5536'; + ts4 = '20200519_181148_1_5536'; + ts5 = '20200519_181148_2_3691'; + ts6 = '20200519_181148_3_2953'; + ts7 = '20200520_173710_1_73814'; + tstamp = {ts2};% ts3 ts4 ts5 ts6 ts7 + nIterID = {1:8}; % 1:15 1:4 1:8 + load([projdir '\simdata_' tstamp{end} '\full_variable_set_'... + tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full;%cat(3, marray1, marray_full(:,:,1:end)); + +clear marray_full +parnames = [... + {'TX_{cat}'} + {'TL_{cat}'} + {'pol_{Kd, tet}'} + {'rep_{Kd, tet}'} + {'aTc_{Kd}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +close all +mcmc_plot(marray(:, 1:end,1:10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); + +% %% +% mcmc_plot(marray(:, 1:20:end,15:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters_'); + +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.8, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.1]); + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/2.5 ss(4)/2]); + + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + xLab = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v3.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v3.m new file mode 100644 index 0000000..0708a5c --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v3.m @@ -0,0 +1,562 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\trainingC_v3\' +% D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\trainingC_v3 +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = true; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v3(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. + + +% +% ts1 = '20200518_175057_1_7381'; +% nIterID1 = {1:3}; +% marray1 = mcmc_get_walkers({ts1},nIterID1, projdir); +% marray1 = marray1(:,1:1000, :); + +tsIDtouse = 1; +plotflag = true; + +switch tsIDtouse + case 1 % this is after including the termination parameters. + + ts2 = '20200521_154748_1_73814';%100, 100 + ts3 = '20200521_154748_2_36907'; %100, 200 % mostly random walking until here + ts4 = '20200521_154748_3_14763'; %80, 280, % here things slowly start to converge + ts5 = '20200522_224032_1_7381'; %50, 330 + ts6='20200523_044512_1_7381';%50, 380 + ts7 = '20200523_044512_2_5536'; %30, 410 + ts8 = '20200523_135237_1_5536'; %50, 460 + ts9 = '20200523_200855_1_3691'; %100, 560 + ts10 = '20200523_200855_2_2214';%30 , 590 + ts11 = '20200524_123605_1_2214';%10, 600 + ts12 = '20200524_140951_1_2214';%20, 620 + ts13 = '20200524_163232_1_2214';%20, 640 + ts14 = '20200524_185508_1_2214';%40, 680 + ts15 = '20200524_233515_1_2214';%100, 780 + ts16 = '20200525_114752_1_1329'; %20, 800 + tstamp = {ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11 ts12 ts13 ts14 ... + ts15 ts16}; + nIterID = {1:10 1:10 1:8 1:5 1:5 1:3 1:5 1:10 1:4 1 1:2 1:2 1:4 ... + 1:10 1:2}; + load([projdir '\simdata_' tstamp{end} '\full_variable_set_'... + tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full;%cat(3, marray1, marray_full(:,:,1:end)); + +clear marray_full +parnames = [... + {'TX_{cat}'} + {'TL_{cat}'} + {'\tau_{atp}'} + {'pol_{Kd, tet}'} + {'rep_{Kd, tet}'} + {'aTc_{Kd}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); +%% +mcmc_plot(marray(:, 1:end,580:10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in_oversampled'); +%% +mcmc_plot(marray(:, 1:end,end), parnames(:),... + 'ess', 100, 'scatter', false, 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in_ess100'); +% %% +% mcmc_plot(marray(:, 1:20:end,15:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters_'); + +%% +mcmc_plot(marray(:, 1:50:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +% % % % % +%% +% +%% + + +marray_thin = marray(:, :, end-300:15:end); +marray_flat = marray_thin(:,:)'; + + +parslices = [... + {'TX_{cat}'} {[0 6]} + {'TL_{cat}'} {[0 6]} + {'\tau_{atp}'} {[9.6 9.9]} + {'pol_{Kd, tet}'} {[17 23]} + {'rep_{Kd, tet}'} {[-4 1]} + {'aTc_{Kd}'} {[-10 5]} + {'pol_{Kd, lac}'} {[16 23]} + {'pol_{term}'} {[2 10.5]} + {'Ribo_{term}'} {[2 10]} + {'pol'} {[4 8]} + {'Ribo'} {[2 12]} + {'3OC12_{Kd}'} {[5 16]} + {'pol_{Kd,las}'} {[25 40]} + {'plas_{tf, Kd}'} {[4 8]} + {'plas-pol_{tf, Kd}'} {[3 10]}]; +% pol kd is cartesian with pol term, rnaseKd, rnase cat. BUT NOT POL. +% cartesian with rnaseKd, rnase cat and POL +cutted_marray = mcmc_cut(marray_flat, 1:15, flipud(cell2mat(parslices(:, 2))')); +size(cutted_marray) + +% +mcmc_plot(cutted_marray(:,:), parnames(:)) + + + + +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.1]); + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg', '-r600') + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r600') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/2.5 ss(4)/2]); + + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + xLab = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg', '-r600') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r600') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v4.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v4.m new file mode 100644 index 0000000..8d280b5 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v4.m @@ -0,0 +1,600 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\trainingC_v4\' +% D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\trainingC_v3 +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v4']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = true; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v4(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. + + +% +% ts1 = '20200518_175057_1_7381'; +% nIterID1 = {1:3}; +% marray1 = mcmc_get_walkers({ts1},nIterID1, projdir); +% marray1 = marray1(:,1:1000, :); + +tsIDtouse = 1; +plotflag = true; + +switch tsIDtouse + case 1 % this is after including the termination parameters. + + ts2 = '20200521_154748_1_73814';%100, 100 + ts3 = '20200521_154748_2_36907'; %100, 200 % mostly random walking until here + ts4 = '20200521_154748_3_14763'; %80, 280, % here things slowly start to converge + ts5 = '20200522_224032_1_7381'; %50, 330 + ts6='20200523_044512_1_7381';%50, 380 + ts7 = '20200523_044512_2_5536'; %30, 410 + ts8 = '20200523_135237_1_5536'; %50, 460 + ts9 = '20200523_200855_1_3691'; %100, 560 + ts10 = '20200523_200855_2_2214';%30 , 590 + ts11 = '20200524_123605_1_2214';%10, 600 + ts12 = '20200524_140951_1_2214';%20, 620 + ts13 = '20200524_163232_1_2214';%20, 640 + ts14 = '20200524_185508_1_2214';%40, 680 + ts15 = '20200524_233515_1_2214';%100, 780 + ts16 = '20200525_114752_1_1329'; %20, 800 + ts17 = '20200603_044203_1_2214'; %200, changed to 500 walkers. %%cumulativefrom17 200 + ts18 = '20200603_044203_2_1845';%70 %%cumulativefrom17 270 + ts19 = '20200604_073858_1_1845'; %200 %%cumulativefrom17 470 + ts20 = '20200604_073858_2_1476'; % 50 %%cumulativefrom17 520 + ts21 = '20200605_045501_1_1476';% 200 %%cumulativefrom17 720 + ts22 = '20200605_045501_2_1181'% 200 %%cumulativefrom17 920 + ts23 = '20200605_045501_3_1033'% 200 %%cumulativefrom17 1120 + ts24 = '20200605_045501_4_886'% 200 %%cumulativefrom17 1320 + ts25 = '20200605_045501_5_738'% 200 %%cumulativefrom17 1520 + ts26 = '20200605_045501_6_591';% 200 %%cumulativefrom17 1590 + ts27 = '20200605_045501_7_443';% 200 + + tstamp = {ts17 ... + ts18 ts19 ts20 ts21 ts22 ts23 ts24 ts25 ts26 ts27}; + nIterID = {1:20 1:7 1:20 1:5 1:20 1:20 1:20 1:20 1:20 1:20 1:20}; + load([projdir '\simdata_' tstamp{end} '\full_variable_set_'... + tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full;%cat(3, marray1, marray_full(:,:,1:end)); + +clear marray_full +parnames = [... + {'TX_{cat}'} + {'TL_{cat}'} + {'\tau_{atp}'} + {'pol_{Kd, tet}'} + {'rep_{Kd, tet}'} + {'aTc_{Kd}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); +%% +mcmc_plot(marray(:, 1:end,end-600:40:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in_oversampled'); +%% +mcmc_plot(marray(:, 1:end,end), parnames(:),... + 'ess', 100, 'scatter', false, 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in_ess100'); +% %% +% mcmc_plot(marray(:, 1:20:end,15:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters_'); + +%% +mcmc_plot(marray(:, 1:50:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +% % % % % +%% +% +%% + + +marray_thin = marray(:, :, end-300:15:end); +marray_flat = marray_thin(:,:)'; + + +parslices = [... + {'TX_{cat}'} {[0 6]} + {'TL_{cat}'} {[0 6]} + {'\tau_{atp}'} {[9.6 9.9]} + {'pol_{Kd, tet}'} {[17 23]} + {'rep_{Kd, tet}'} {[-4 1]} + {'aTc_{Kd}'} {[-10 5]} + {'pol_{Kd, lac}'} {[16 23]} + {'pol_{term}'} {[2 10.5]} + {'Ribo_{term}'} {[2 10]} + {'pol'} {[4 8]} + {'Ribo'} {[2 12]} + {'3OC12_{Kd}'} {[5 16]} + {'pol_{Kd,las}'} {[25 40]} + {'plas_{tf, Kd}'} {[4 8]} + {'plas-pol_{tf, Kd}'} {[3 10]}]; +% pol kd is cartesian with pol term, rnaseKd, rnase cat. BUT NOT POL. +% cartesian with rnaseKd, rnase cat and POL +cutted_marray = mcmc_cut(marray_flat, 1:15, flipud(cell2mat(parslices(:, 2))')); +size(cutted_marray) + +% +mcmc_plot(cutted_marray(:,:), parnames(:)) + + + + +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.05, 0.2, 0.9]) + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + +% print([saveFinalFigs tsToSave 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') +% print([saveFinalFigs tsToSave 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') +% print([saveFinalFigs tsToSave '_lowres_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r200') +% print([saveFinalFigs tsToSave '_medres_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r300') +% print([saveFinalFigs tsToSave '_hires_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r400') +% +% print([saveFinalFigs tsToSave '_hires_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpdf') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.35, 0.5]) + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLab = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLims = [0.0625 4 + 2e-06 2 + 0.01 10000 + 0.03125 2 + 0.01 10000]; + doseArray =... + [ 4 2 1 0.5 0.25 0.125 0.0625 + 2 0.2 0.02 0.002 0.0002 2e-05 2e-06 + 10000 1000 100 10 1 0.1 0.01 + 2 1 0.5 0.25 0.125 0.0625 0.03125 + 10000 1000 100 10 1 0.1 0.01]; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + ax.XLim = xLims(count, :); + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-depsc') +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-djpeg') +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng') +% print([saveFinalFigs tsToSave '_lowres_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r200') +% print([saveFinalFigs tsToSave '_medres_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r300') +% print([saveFinalFigs tsToSave '_hires_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r400') +% print([saveFinalFigs tsToSave '_hires_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpdf') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v5.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v5.m new file mode 100644 index 0000000..81d6fe3 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v5.m @@ -0,0 +1,602 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\trainingC_v5\' +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v5']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = true; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v5(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. + + +% +% ts1 = '20200518_175057_1_7381'; +% nIterID1 = {1:3}; +% marray1 = mcmc_get_walkers({ts1},nIterID1, projdir); +% marray1 = marray1(:,1:1000, :); + +tsIDtouse = 1; +plotflag = true; + +switch tsIDtouse + case 1 % this is after including the termination parameters. + + ts2 = '20200521_154748_1_73814';%100, 100 + ts3 = '20200521_154748_2_36907'; %100, 200 % mostly random walking until here + ts4 = '20200521_154748_3_14763'; %80, 280, % here things slowly start to converge + ts5 = '20200522_224032_1_7381'; %50, 330 + ts6='20200523_044512_1_7381';%50, 380 + ts7 = '20200523_044512_2_5536'; %30, 410 + ts8 = '20200523_135237_1_5536'; %50, 460 + ts9 = '20200523_200855_1_3691'; %100, 560 + ts10 = '20200523_200855_2_2214';%30 , 590 + ts11 = '20200524_123605_1_2214';%10, 600 + ts12 = '20200524_140951_1_2214';%20, 620 + ts13 = '20200524_163232_1_2214';%20, 640 + ts14 = '20200524_185508_1_2214';%40, 680 + ts15 = '20200524_233515_1_2214';%100, 780 + ts16 = '20200525_114752_1_1329'; %20, 800 + ts17 = '20200603_044203_1_2214'; %200, changed to 500 walkers. %%cumulativefrom17 200 + ts18 = '20200603_044203_2_1845';%70 %%cumulativefrom17 270 + ts19 = '20200604_073858_1_1845'; %200 %%cumulativefrom17 470 + ts20 = '20200604_073858_2_1476'; % 50 %%cumulativefrom17 520 + ts21 = '20200605_045501_1_1476';% 200 %%cumulativefrom17 720 + ts22 = '20200605_045501_2_1181';% 200 %%cumulativefrom17 920 + ts23 = '20200605_045501_3_1033';% 200 %%cumulativefrom17 1120 + ts24 = '20200605_045501_4_886';% 200 %%cumulativefrom17 1320 + ts25 = '20200605_045501_5_738';% 200 %%cumulativefrom17 1520 + ts26 = '20200605_045501_6_591';% 200 %%cumulativefrom17 1590 + ts27 = '20200605_045501_7_443';% 200 + ts28 = '20200609_190458_1_1033'; %50 + ts29 = '20200610_000545_1_1033'; + ts30 = '20200610_000545_2_738'; + tstamp = {ts17 ... + ts18 ts19 ts20 ts21 ts22 ts23 ts24 ts25 ts26 ts27 ts28 ts29 ts30}; + nIterID = {1:20 1:7 1:20 1:5 1:20 1:20 1:20 1:20 1:20 1:20 1:20 1:5 1:40 1:28}; + load([projdir '\simdata_' tstamp{end} '\full_variable_set_'... + tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full;%cat(3, marray1, marray_full(:,:,1:end)); + +clear marray_full +parnames = [... + {'TX_{cat}'} + {'TL_{cat}'} + {'\tau_{atp}'} + {'pol_{Kd, tet}'} + {'rep_{Kd, tet}'} + {'aTc_{Kd}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); +%% +mcmc_plot(marray(:, 1:end,end-600:60:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in_oversampled'); +%% +mcmc_plot(marray(:, 1:end,end), parnames(:),... + 'ess', 100, 'scatter', false, 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in_ess100'); +% %% +% mcmc_plot(marray(:, 1:20:end,15:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters_'); + +%% +mcmc_plot(marray(:, 1:50:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +% % % % % +%% +% +%% + + +marray_thin = marray(:, :, end-300:15:end); +marray_flat = marray_thin(:,:)'; + + +parslices = [... + {'TX_{cat}'} {[0 6]} + {'TL_{cat}'} {[0 6]} + {'\tau_{atp}'} {[9.6 9.9]} + {'pol_{Kd, tet}'} {[17 23]} + {'rep_{Kd, tet}'} {[-4 1]} + {'aTc_{Kd}'} {[-10 5]} + {'pol_{Kd, lac}'} {[16 23]} + {'pol_{term}'} {[2 10.5]} + {'Ribo_{term}'} {[2 10]} + {'pol'} {[4 8]} + {'Ribo'} {[2 12]} + {'3OC12_{Kd}'} {[5 16]} + {'pol_{Kd,las}'} {[25 40]} + {'plas_{tf, Kd}'} {[4 8]} + {'plas-pol_{tf, Kd}'} {[3 10]}]; +% pol kd is cartesian with pol term, rnaseKd, rnase cat. BUT NOT POL. +% cartesian with rnaseKd, rnase cat and POL +cutted_marray = mcmc_cut(marray_flat, 1:15, flipud(cell2mat(parslices(:, 2))')); +size(cutted_marray) + +% +mcmc_plot(cutted_marray(:,:), parnames(:)) + + + + +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.05, 0.2, 0.9]) + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + +% print([saveFinalFigs tsToSave 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') +% print([saveFinalFigs tsToSave 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') +% print([saveFinalFigs tsToSave '_lowres_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r200') +% print([saveFinalFigs tsToSave '_medres_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r300') +% print([saveFinalFigs tsToSave '_hires_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r400') +% +% print([saveFinalFigs tsToSave '_hires_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpdf') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.35, 0.5]) + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLab = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLims = [0.0625 4 + 2e-06 2 + 0.01 10000 + 0.03125 2 + 0.01 10000]; + doseArray =... + [ 4 2 1 0.5 0.25 0.125 0.0625 + 2 0.2 0.02 0.002 0.0002 2e-05 2e-06 + 10000 1000 100 10 1 0.1 0.01 + 2 1 0.5 0.25 0.125 0.0625 0.03125 + 10000 1000 100 10 1 0.1 0.01]; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + ax.XLim = xLims(count, :); + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-depsc') +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-djpeg') +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng') +% print([saveFinalFigs tsToSave '_lowres_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r200') +% print([saveFinalFigs tsToSave '_medres_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r300') +% print([saveFinalFigs tsToSave '_hires_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r400') +% print([saveFinalFigs tsToSave '_hires_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpdf') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v6.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v6.m new file mode 100644 index 0000000..c2d3a80 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullC_v6.m @@ -0,0 +1,654 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\trainingC_v6\' +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v6']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = false; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v6(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. + + +% +% ts1 = '20200518_175057_1_7381'; +% nIterID1 = {1:3}; +% marray1 = mcmc_get_walkers({ts1},nIterID1, projdir); +% marray1 = marray1(:,1:1000, :); + +tsIDtouse = 1; +plotflag = true; + +switch tsIDtouse + case 1 % this is after including the termination parameters. + + ts2 = '20200521_154748_1_73814';%100, 100 + ts3 = '20200521_154748_2_36907'; %100, 200 % mostly random walking until here + ts4 = '20200521_154748_3_14763'; %80, 280, % here things slowly start to converge + ts5 = '20200522_224032_1_7381'; %50, 330 + ts6='20200523_044512_1_7381';%50, 380 + ts7 = '20200523_044512_2_5536'; %30, 410 + ts8 = '20200523_135237_1_5536'; %50, 460 + ts9 = '20200523_200855_1_3691'; %100, 560 + ts10 = '20200523_200855_2_2214';%30 , 590 + ts11 = '20200524_123605_1_2214';%10, 600 + ts12 = '20200524_140951_1_2214';%20, 620 + ts13 = '20200524_163232_1_2214';%20, 640 + ts14 = '20200524_185508_1_2214';%40, 680 + ts15 = '20200524_233515_1_2214';%100, 780 + ts16 = '20200525_114752_1_1329'; %20, 800 + ts17 = '20200603_044203_1_2214'; %200, changed to 500 walkers. %%cumulativefrom17 200 + ts18 = '20200603_044203_2_1845';%70 %%cumulativefrom17 270 + ts19 = '20200604_073858_1_1845'; %200 %%cumulativefrom17 470 + ts20 = '20200604_073858_2_1476'; % 50 %%cumulativefrom17 520 + ts21 = '20200605_045501_1_1476';% 200 %%cumulativefrom17 720 + ts22 = '20200605_045501_2_1181';% 200 %%cumulativefrom17 920 + ts23 = '20200605_045501_3_1033';% 200 %%cumulativefrom17 1120 + ts24 = '20200605_045501_4_886';% 200 %%cumulativefrom17 1320 + ts25 = '20200605_045501_5_738';% 200 %%cumulativefrom17 1520 + ts26 = '20200605_045501_6_591';% 200 %%cumulativefrom17 1590 + 130 + ts27 = '20200605_045501_7_443';% 200 %%cumulativefrom17 1790 + 130 + ts28 = '20200609_190458_1_1033'; %50 %%cumulativefrom17 1840 + 130 + ts29 = '20200610_000545_1_1033'; %400 %%cumulativefrom17 2240 + 130 + ts30 = '20200610_000545_2_738'; %280 %%cumulativefrom17 2520 + 130 + % v6 starts here. + ts31 = '20200612_214710_1_1476'; % 30 %%cumulativefrom17 2550 + 130, windows update after 3 iters + ts32 = '20200614_005043_1_1476';%100 %%cumulativefrom17 2650 + 130 + ts33 = '20200614_005043_2_2214';%100 %%cumulativefrom17 2750 + 130 + ts34 = '20200614_005043_3_2953';%100 %%cumulativefrom17 2850 + 130 + ts35 = '20200614_005043_4_3691';%100 %%cumulativefrom17 2950 + 130 + ts36 = '20200614_005043_5_2953';%50 %%cumulativefrom17 3000 + 130 + ts37 ='20200615_233435_1_2953';%220 %%cumulativefrom17 3220 + 130 + ts38 = '20200616_183409_1_2953';%400 %%cumulativefrom17 3620 + 130 + ts39 = '20200616_183409_2_2214';%390 %%cumulativefrom17 4010 + 130 + ts40 = '20200619_213706_1_2214';%370 %%cumulativefrom17 4380 + 130 + ts41 = '20200619_213706_2_1476'; + ts42 = '20200621_100025_1_4429'; + ts43 = '20200622_121135_1_4429'; + ts44 = '20200623_175503_1_4429'; + ts45 = '20200627_132326_1_3691'; + ts46 = '20200627_132326_2_2953'; + ts47 = '20200627_132326_3_2583'; + ts48 = '20200627_132326_4_2214'; + ts49 = '20200703_000710_1_2030'; + ts50 = '20200703_000710_2_1845'; + ts51 = '20200703_000710_3_1661'; + ts52 = '20200703_000710_4_1476'; + ts53 = '20200710_230144_1_1476'; + ts54 = '20200710_230144_2_1292'; + ts55 = '20200716_111111_1_1292'; + ts56 = '20200716_111111_2_1107'; + ts57 = '20200723_011054_1_1107'; + ts58 = '20200723_011054_2_923'; + ts59 = '20200723_011054_3_738'; + tstamp = ... + {ts17 ts18 ts19 ts20 ts21 ts22 ts23 ts24 ts25 ts26... + ts27 ts28 ts29 ts30 ts31 ts32 ts33 ts34 ts35 ts36... + ts37 ts38 ts39 ts40 ts41 ts42 ts43 ts44 ts45 ts46 ... + ts47 ts48 ts49 ts50 ts51 ts52 ts53 ts54 ts55 ts56 ... + ts57 ts58 ts59}; + nIterID = ... + {1:20 1:7 1:20 1:5 1:20 1:20 1:20 1:20 1:20 1:20 ... + 1:20 1:5 1:40 1:28 1:3 1:10 1:10 1:10 1:10 1:5 ... + 1:22 1:40 1:39 1:40 1:2 1:10 1:36 1:100 1:40 1:40 ... + 1:40 1:29 1:40 1:40 1:40 1:40 1:100 1:21 1:100 1:60 ... + 1:100 1:100 1:3}; + % Just plot v6. if you want to plot everything from ts 17, use the + % list above. + tstamp = ... + {ts31 ts32 ts33 ts34 ts35 ts36... + ts37 ts38 ts39 ts40 ts41 ts42 ts43 ts44 ts45 ts46 ... + ts47 ts48 ts49 ts50 ts51 ts52 ts53 ts54 ts55 ts56 ... + ts57 ts58 ts59}; + nIterID = ... + {1:3 1:10 1:10 1:10 1:10 1:5 ... + 1:22 1:40 1:39 1:40 1:2 1:10 1:36 1:100 1:40 1:40 ... + 1:40 1:29 1:40 1:40 1:40 1:40 1:100 1:21 1:100 1:60 ... + 1:100 1:100 1:3}; + load([projdir '\simdata_' tstamp{end} '\full_variable_set_'... + tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full;%cat(3, marray1, marray_full(:,:,1:end)); + +clear marray_full +parnames = [... + {'TX_{cat}'} + {'TL_{cat}'} + {'\tau_{atp}'} + {'pol_{Kd, tet}'} + {'rep_{Kd, tet}'} + {'aTc_{Kd}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'3OC12_{Kd}'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false,'plotDistribution', false,... + 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave); +%% +mcmc_plot(marray(:, 1:end,end-600:100:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in_oversampled'); +%% +mcmc_plot(marray(:, 1:end,end), parnames(:),... + 'ess', 100, 'scatter', false, 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in_ess100'); +% %% +% mcmc_plot(marray(:, 1:20:end,15:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters_'); + +%% +mcmc_plot(marray(:, 1:50:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +% % % % % +%% +% +%% + + +% marray_thin = marray(:, :, end-600:60:end); +% marray_flat = marray_thin(:,:)'; +% +% +% parslices = [... +% {'TX_{cat}'} {[0 6]} +% {'TL_{cat}'} {[0 6]} +% {'\tau_{atp}'} {[9.6 9.9]} +% {'pol_{Kd, tet}'} {[17 23]} +% {'rep_{Kd, tet}'} {[-4 1]} +% {'aTc_{Kd}'} {[-10 5]} +% {'pol_{Kd, lac}'} {[16 23]} +% {'pol_{term}'} {[2 10.5]} +% {'Ribo_{term}'} {[2 10]} +% {'pol'} {[4 8]} +% {'Ribo'} {[2 12]} +% {'3OC12_{Kd}'} {[5 16]} +% {'pol_{Kd,las}'} {[25 40]} +% {'plas_{tf, Kd}'} {[4 8]} +% {'plas-pol_{tf, Kd}'} {[3 10]}]; +% % pol kd is cartesian with pol term, rnaseKd, rnase cat. BUT NOT POL. +% % cartesian with rnaseKd, rnase cat and POL +% cutted_marray = mcmc_cut(marray_flat, 1:15, flipud(cell2mat(parslices(:, 2))')); +% size(cutted_marray) + +% +% mcmc_plot(cutted_marray(:,:), parnames(:)) + + + + +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. +%% +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.05, 0.2, 0.9]) + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + +% print([saveFinalFigs tsToSave 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') +% print([saveFinalFigs tsToSave 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') +% print([saveFinalFigs tsToSave '_lowres_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r200') +% print([saveFinalFigs tsToSave '_medres_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r300') +% print([saveFinalFigs tsToSave '_hires_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r400') +% +% print([saveFinalFigs tsToSave '_hires_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpdf') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.35, 0.5]) + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLab = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLims = [0.0625 4 + 2e-06 2 + 0.01 10000 + 0.03125 2 + 0.01 10000]; + doseArray =... + [ 4 2 1 0.5 0.25 0.125 0.0625 + 2 0.2 0.02 0.002 0.0002 2e-05 2e-06 + 10000 1000 100 10 1 0.1 0.01 + 2 1 0.5 0.25 0.125 0.0625 0.03125 + 10000 1000 100 10 1 0.1 0.01]; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + ax.XLim = xLims(count, :); + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-depsc') +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-djpeg') +% print([saveFinalFigs tsToSave 'fitting_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng') +% print([saveFinalFigs tsToSave '_lowres_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r200') +% print([saveFinalFigs tsToSave '_medres_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r300') +% print([saveFinalFigs tsToSave '_hires_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r400') +% print([saveFinalFigs tsToSave '_hires_end_' ... +% num2str((lengthToPlot-1)*8) 'min'],'-dpdf') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullD.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullD.m new file mode 100755 index 0000000..a7fed05 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullD.m @@ -0,0 +1,254 @@ + + +clear all +close all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_trainingD']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullD(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20190511_062400_1_738'; + ts2 = '20190511_131947_1_369'; + ts3 = '20190511_131947_2_74' + tstamp = {ts1 ts2 ts3}; + nIterID = {1:11 1:20 1}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... + [{'k_{tx}'} + {'k_{tl}'} + {'pol_{Kd, tet}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:10:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'AllWalkers'); +% % % % %% +% + mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + + % actually i think it is better to just set te parameters using gaussian balls, + % and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + + % Plot trajectories. + + % rebuild the master vector array, either via mcmc_cut or just using + % all estimated points. + + % +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); + mvarray = masterVecArray(marray, mai); +% clear marray + % + for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', [extrastring num2str(miID) ' ' num2str(msID)]); + end + % +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullD_v2.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullD_v2.m new file mode 100644 index 0000000..44bfcbe --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullD_v2.m @@ -0,0 +1,504 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\May_2020\' + +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = false; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullD_v2(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. + + + +ts1 = '20200518_175057_1_7381'; +nIterID1 = {1:3}; +marray1 = mcmc_get_walkers({ts1},nIterID1, projdir); +marray1 = marray1(:,1:1000, :); + +tsIDtouse = 1; +plotflag = true; + +switch tsIDtouse + case 1 % this is after including the termination parameters. + + ts2 = '20200519_011552_1_7381'; + ts3 = '20200519_011552_2_5536'; + ts4 = '20200519_181148_1_5536'; + ts5 = '20200519_181148_2_3691'; + ts6 = '20200519_181148_3_2953'; + ts7 = '20200520_173710_1_73814'; + tstamp = {ts2 ts3 ts4};% ts5 ts6 ts7 + nIterID = {1:20 1:6 1:15}; % 1:15 1:4 1:8 + load([projdir '\simdata_' tstamp{end} '\full_variable_set_'... + tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = cat(3, marray1, marray_full(:,:,1:end)); + +clear marray_full +parnames = [... + {'TX_{cat}'} + {'TL_{cat}'} + {'pol_{Kd, tet}'} + {'aTc_{Kd}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +close all +mcmc_plot(marray(:, 1:end,end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); + +%% +mcmc_plot(marray(:, 1:20:end,15:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters_'); + +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.8, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.1]); + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/2.5 ss(4)/2]); + + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + xLab = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullE.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullE.m new file mode 100755 index 0000000..9681da0 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullE.m @@ -0,0 +1,496 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\trainingE_v2\' + +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_trainingE_v2']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = true; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullE(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20190512_033129_1_1476';%5 iters per run, so 30/2 + ts2 = '20190512_064547_1_1476';%110/2 + ts3 = '20190512_094712_1_1845';%130/2 + ts4 = '20190512_113712_1_1845';%180/2 + ts5 = '20190512_155207_1_1845';%250/2=125 + + ts6 = '20200525_181748_1_1845';%145 changed the tau from 10.1 to 9.7. E_v2 + ts7 = '20200525_201859_1_1845'; %195 + ts8 = '20200525_201859_2_1476';%215 + ts9 = '20200526_033216_1_738'; %315 + ts10 = '20200526_033216_2_369';%375 + ts11 = '20200526_204312_1_258';% 435 + ts12 = '20200527_033000_1_37'; % 445 + ts13 = '20200527_045239_1_74';% 485 + ts14 = '20200527_045239_2_52';% 525 + ts15 = '20200527_045239_3_74'; %535 + + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11 ts12 ts13 ts14 ts15}; + nIterID = {1:3 1:8 1:2 1:5 1:7 1:2 1:5 1:2 1:10 1:6 1:6 1 1:4 1:4 1}; + load([projdir '/simdata_' tstamp{end} '/full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = [... + {'pol_{Kd, tet}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% + +%% +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'wit_transient'); + +%% +close all +mcmc_plot(marray(:, 1:end,(end - 50):10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); + +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.1]); + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/2.5 ss(4)/2]); + + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + xLab = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF.m new file mode 100644 index 0000000..08bfeb8 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF.m @@ -0,0 +1,507 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\May_2020' + +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingF']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = false; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20200510_082735_1_1476'; + ts2 = '20200511_052714_1_1476'; + ts3 = '20200511_052714_2_738'; + ts4 = '20200511_052714_3_369'; + ts5 = '20200511_052714_4_148'; + ts6 = '20200513_222442_1_738'; + ts7 = '20200514_165204_1_738'; + ts8 = '20200514_183027_1_738'; + ts9 = '20200515_023833_1_738'; + ts10 = '20200515_052639_1_738'; + ts11 = '20200515_184104_1_738'; + ts12 = '20200516_062411_1_738'; + ts13 = '20200516_175823_1_738'; + ts14 = '20200516_183508_1_738'; + ts15 = '20200517_054605_1_738'; + ts16 = '20200517_072406_1_738'; + ts17 = '20200517_172041_1_738'; + ts18 = '20200518_002303_1_738'; + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11 ... + ts12 ts13 ts14 ts15 ts16}; + tstamp = {ts1 ts2 ts3 ts6 ts7 ts8 ts9 ts10 ts11 ... + ts12 ts13 ts14 ts15 ts16 ts17 ts18}; + nIterID = {1:2 1:10 1:10 1:10 1:10 1:10 1:2 1:5 1:4 1:20 1:5 ... + 1:12 1 1 1:2 1:15}; + nIterID = {1:2 1:10 1:10 1:10 1:2 1:5 1:4 1:20 1:5 ... + 1:12 1 1 1:2 1:15 1:7 1:25}; + load([projdir '\simdata_' ts18 '\full_variable_set_' ts18 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = [... + {'pol_{Kd, tet}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +close all +mcmc_plot(marray(:, 1:end,300:250:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); + +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +%% +mcmc_plot(marray(:, 1:10:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'notsofewChains_all_iters'); + +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here +close all + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.1]); + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/2.5 ss(4)/2]); + + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + xLab = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v2.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v2.m new file mode 100644 index 0000000..79ed218 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v2.m @@ -0,0 +1,492 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\May_2020' + +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v2']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = false; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20200527_151014_1_1476'; + ts2 = '20200527_151014_2_738'; + + tstamp = {ts1 ts2}; + + nIterID = {1:10 1:4}; + + load([projdir '\simdata_' tstamp{end} '\full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = [... + {'pol_{Kd, tet}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir); + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +close all +mcmc_plot(marray(:, 1:end,300:250:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); + +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +%% +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'notsofewChains_all_iters'); + +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here +close all + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.1]); + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/2.5 ss(4)/2]); + + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + xLab = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v3.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v3.m new file mode 100644 index 0000000..0e806bd --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v3.m @@ -0,0 +1,496 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\May_2020' + +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v3']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = false; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20200527_224901_1_1476'; + ts2 = '20200527_224901_2_738'; + ts3 = '20200527_224901_3_554'; + ts4 = '20200527_224901_4_369'; + tstamp = {ts1 ts2 ts3 ts4}; + + nIterID = {1:10 1:10 1:10 1:2}; + + load([projdir '\simdata_' tstamp{end} '\full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = [... + {'pol_{Kd, tet}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir); + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +mcmc_plot(marray(:, 1:end,end-200:10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); + +%% +mcmc_plot(marray(:, 1:20:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'fewChains_all_iters'); + +%% +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'notsofewChains_all_iters'); + +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here +close all + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.9, 0.8]) + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + + print([saveFinalFigs 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.9, 0.8]) + + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + xLab = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs 'fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v4.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v4.m new file mode 100644 index 0000000..8e491bf --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v4.m @@ -0,0 +1,534 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\fullFv4\slim_' + +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v4']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF_v4(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20200528_165131_1_738'; + ts2 = '20200528_165131_2_554'; + ts3 = '20200528_165131_3_369'; + ts4 = '20200529_040611_1_369'; + ts5 = '20200529_040611_2_258'; + ts6 = '20200529_040611_3_148'; + ts7 = '20200530_033747_1_148'; + ts8 = '20200530_033747_2_74'; + ts9 = '20200530_163844_1_74'; + ts10='20200530_163844_2_55'; + ts11='20200530_163844_3_37'; + ts12 = '20200531_214346_1_74'; + ts13 = '20200531_214346_2_111'; + ts14 = '20200531_214346_3_74'; + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11 ts12 ts13 ts14}; + nIterID = {1:10 1:10 1 1:10 1:10 1:5 1:15 1:7 1:20 1:20 1:20 1:30 1:30 1:30}; + load([projdir '\simdata_' tstamp{end} '\full_variable_set_'... + tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = [... + {'pol_{Kd, tet}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', true,... + 'projdir', projdir); + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +mcmc_plot(marray(:, 1:end,end-900:200:end), parnames(:),... + 'plotChains', false, ... + 'savematlabfig', figsave, 'savejpeg', jpgsave,'fontsize', 16,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'Burned_in'); +%% +mcmc_plot(marray(:, 1:end,end-200:20:end), parnames(:),... + 'ess', 80, 'scatter', false, ... + 'plotChains', false, ... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'Burned_in'); + +%% + +close all + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'plotDistribution', false, ... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'notsofewChains_all_iters'); + +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.05, 0.2, 0.9]) + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs tsToSave 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs tsToSave 'fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs tsToSave '_lowres_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r200') + print([saveFinalFigs tsToSave '_medres_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r300') + print([saveFinalFigs tsToSave '_hires_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r400') + + print([saveFinalFigs tsToSave '_hires_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpdf') + + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:length(miToUse) + currmi = mi(miToUse(i)); + currdi = data_info(currmi.dataToMapTo); + doseArray(i, :) = currdi.dosedVals; + end + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.35, 0.5]) + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLab = {'pTet-deGFP DNA (nM)'; + 'pLac-tetR DNA (nM)'; + 'aTc (uM)'; + 'pLac-deGFP DNA (nM)'; + '3OC12 (uM)'}; + xLims = [0.0625 4 + 2e-06 2 + 0.01 10000 + 0.03125 2 + 0.01 10000]; + doseArray =... + [ 4 2 1 0.5 0.25 0.125 0.0625 + 2 0.2 0.02 0.002 0.0002 2e-05 2e-06 + 10000 1000 100 10 1 0.1 0.01 + 2 1 0.5 0.25 0.125 0.0625 0.03125 + 10000 1000 100 10 1 0.1 0.01]; + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca; + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + ax.XLim = xLims(count, :); + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 14 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs tsToSave 'fitting_end_' ... + num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs tsToSave 'fitting_end_' ... + num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs tsToSave 'fitting_end_' ... + num2str((lengthToPlot-1)*8) 'min'],'-dpng') + print([saveFinalFigs tsToSave '_lowres_end_' ... + num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r200') + print([saveFinalFigs tsToSave '_medres_end_' ... + num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r300') + print([saveFinalFigs tsToSave '_hires_end_' ... + num2str((lengthToPlot-1)*8) 'min'],'-dpng', '-r400') + print([saveFinalFigs tsToSave '_hires_end_' ... + num2str((lengthToPlot-1)*8) 'min'],'-dpdf') + +end +% diff --git a/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v5.m b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v5.m new file mode 100644 index 0000000..a4188f6 --- /dev/null +++ b/mcmc_simbio/projects/analysis_ZSIFFL_training_fullF_v5.m @@ -0,0 +1,498 @@ + + +clear all +close all +saveFinalFigs = 'D:\Dropbox\Documents\a_Journal_Papers\Drafts\txtl_bmc_bioinformatics\figs\fullFv5\' + +finafigmode = true +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v5']; +addpath(projdir) +sls = regexp(projdir, '\', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF_v5(mtet, mlac, mlas); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 % this is after including the termination parameters. + ts1 = '20200528_165131_1_738'; + ts2 = '20200528_165131_2_554'; + ts3 = '20200528_165131_3_369'; + ts4 = '20200529_040611_1_369'; + ts5 = '20200529_040611_2_258'; + ts6 = '20200529_040611_3_148'; + ts7 = '20200529_171720_1_148'; + ts8 = '20200529_171720_2_74'; + + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8};% + nIterID = {1:10 1:10 1 1:10 1:10 1:5 1:10 1:10};% + load([projdir '\simdata_' tstamp{end} '\full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = [... + {'pol_{Kd, tet}'} + {'pol_{Kd, lac}'} + {'pol_{term}'} + {'Ribo_{term}'} + {'pol'} + {'Ribo'} + {'pol_{Kd,las}'} + {'plas_{tf, Kd}'} + {'plas-pol_{tf, Kd}'} ]; + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir); + +% [activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +% +% ans = +% +% 143 cell array +% +% {'TX_elong_glob' } {[ 0]} {[ 5]} +% {'TL_elong_glob' } {[ 0]} {[ 6]} +% {'TXTL_PTET_RNAPbound_Kd' } {[ 0]} {[22]} +% {'TXTL_PLAC_RNAPbound_Kd' } {[ 5]} {[17]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 0]} {[12]} +% {'RNAP' } {[ 1]} {[15]} +% {'Ribo' } {[ 1]} {[15]} +% {'TXTL_PLAS_RNAPbound_Kd' } {[ 25]} {[40]} +% {'TXTL_PLAS_TFBIND_Kd' } {[ 0]} {[10]} +% {'TXTL_PLAS_TFRNAPbound_Kd' } {[ 0]} {[15]} + +% if plotflag +% % % % +% % % % close all +% % % % % % close all +% % % % %% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'Without_transient'); +% % % % %% +% +%% +mcmc_plot(marray(:, 1:end,end-300:50:end), parnames(:),... + 'plotChains', false, ... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +%% + +close all + +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... + 'plotDistribution', false, ... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'notsofewChains_all_iters'); + +% % % % % +%% +% +% +% parIDs = [4 5 11]; +% % parRanges(parIDs, :) = [-1 0 ; +% % -4 0; +% % 11 15] +% parRanges(parIDs, :) = [-1 0 ; +% -3 -1; +% 11.5 14.5] +% +% marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +% +% mcut0 = marray_cut(parIDs, :,:); +% mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +% +% +% mcmc_plot(marray_cut, parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% + + + +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] + + +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% Here, we try to plot the trajectories for different sets of parameters. +% I will basically cut the parameters to different subsets, and plot the +% results to check if the lasR model is even working. if it is, then it +% will be clear that it just needs more simulation / fixing of the F rates +% and an estimation of the Kds. +% + + + +% % % % +% % % % paramIndices = (1:12); +% % % % parRanges(paramIndices, :) = [... +% % % % 10.5 20.5; %1 pol_{Kd,tet} +% % % % 7 13; %2 pol_{Kd,lac} +% % % % 4 6.1; %3 pol % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % 5.7 12; %4 Ribo % 5.9 in mcmc_info_ZSIFFL_training_full (from mtet phase 1, 2 etc) +% % % % -20 20 ; %5 3OC12_{Kd} % correlated with plas_{tf, F} +% % % % 0 2; %6 3OC12_{F} % just gaussian. +% % % % -20 20; %7 pol_{Kd,las} +% % % % -2 2.2; %8 pol_{F,las} +% % % % -20.5 20;%9 plas_{tf, Kd} < +% % % % -20 20; % 10 -- plas-pol_{tf, Kd} < +% % % % -2 5;% plas-pol_{tf, F} +% % % % -2.5 1.5;% plas_{tf, F} +% % % % ]; +% % % % marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% % % % size(marray_cut) + +% actually i think it is better to just set te parameters using gaussian balls, +% and fix as many as possible, and jsut explore the Plas and OC12 Kds. +% +% % mean and sd parameter. +% gaussianMeanSD = ... +% [16.57 0.1; ...% +% 10.5 0.1; ...% pol_{Kd,lac} +% 5.9 0.1; ...% pol +% 5.9 0.1; ...% Ribo +% 12 1; ...% 3OC12_{Kd} +% 0 1 ; ...% 3OC12_{F} +% 35 4; ...% pol_{Kd,las} +% 3 2; ...% pol_{F,las} +% 5 5; ...% plas_{tf, Kd} < +% 8 5; ...% plas-pol_{tf, Kd} < +% 0 2; ...% plas-pol_{tf, F} +% 0 4; ...%plas_{tf, F} +% ]; +% +% marray_gauss = cell2mat(arrayfun(@(mu, sig) mu + sig*randn(1, 100),... +% gaussianMeanSD(:, 1), gaussianMeanSD(:, 2), ... +% 'UniformOutput', false)); +% +% + + +% Plot trajectories. + +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. + +% +% mvarray = masterVecArray(marray_gauss, mai); +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +% clear marray +% +for miID = 1:length(mi)%1: + currmi = mi(miID); + dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); + + % titles array: # dose combs x (exp, sim) ==2 x # measured species. + nms = length(currmi.measuredSpeciesIndex); + ndc = size(currmi.dosedVals,2); %# dose combinations + titls_array = cell(ndc, 2, nms); + currdi = data_info(currmi.dataToMapTo); + dn = currdi.dosedNames; %usually the last one will be the thing that is changing... + % can generalize to use all dose info if it becomes needed. + for msID = 1:nms + % for each measured species (ms), plot the trajectories over + % all the doses, for both experiment and simulation + if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) + if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; + else + error('what is your data type?') + end + elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) + ms = data_info(currmi.dataToMapTo).measuredNames{msID}; + else + error('what is your data type?') + end + for dcID = 1:ndc + dosestr = []; + + for dnID = 1:length(dn) + dosestr = ... + [dosestr ' ' dn{dnID} ' '... + num2str(currdi.dosedVals(dnID, dcID))]; + end + % dose combination by (exp, sim) by measured species ID + titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; + titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; + end + end + titls_array + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + + if finafigmode == false + mcmc_trajectories(currmi.emo, currdi, currmi, marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', ... + [extrastring num2str(miID) ' ' num2str(msID)]);%,'collateDoses', true, + end + +end +% +% end +marrayOrd(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +% clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% now make the collated trajectory figure and the endpoints figure for the paper. +% also, replot the markov chain trace plots and the posterior distribution +% plots here with proper font sizes. + +% resimulate, but with just the matured degfp. +ms = {{'protein deGFP*'}}; +for miID = 1:5 + currmi = mi(miID); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals' + vi = get(currmi.emo, 'ValueInfo') + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, ms); +end + + +%% here + + +ylims = {[7.5, 2, 2, 5, 7.5]; + [7.5, 2, 2, 5, 7.5]; + [15 5 5 10 15]}; + + +lengthToPlotArray = [24, 31, 61]; % 180 min = 24 +for outercount = 1:length(lengthToPlotArray) + lengthToPlot = lengthToPlotArray(outercount) + + figure + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.9, 0.8]) + miToUse = [1 2 3 4 5]; + + titleArray = {'pTet-deGFP DNA'; + 'pLac-TetR DNA'; + 'aTc'; + 'pLac-deGFP DNA'; + '3OC12HSL'}; + + legends = [{'4nM', '2nM', '1nM', '0.5nM', '250pM', '125pM', '0nM'} + {'2nM', '.2nM', '.02nM', '2pM', '0.2pM', '20fM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'} + {'2nM', '1nM', '.5nM', '.25nM', '.125nM', '62.5pM', '0nM'}; + {'10uM', '1uM', '0.1uM', '10nM', '1nM', '0.1nM', '0nM'}]; + + + + % clear marray + colorz = flipud(parula(length(legends(1, :))+2)); + for count = 1:length(miToUse) %1:length(mi)%1: + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + + + + + subplot(5, 2, (count-1)*2+1) + + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(currdi.dataArray(1:lengthToPlot, 1, 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Exp)']) + ylabel('deGFP, uM', 'FontSize', 14) + axis([0 (lengthToPlot-1)*8, 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + + + subplot(5, 2, (count-1)*2+2) + for dID = 1:length(legends(count, :)) + + plot(tv(1:lengthToPlot)/60,... + 0.001*mean(da{count}(1:lengthToPlot, 1, :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + + title([titleArray{count} ' (Fit)']) + legend(legends(count, :), 'Location', 'NorthWest', 'FontSize', 10) + legend('boxoff') + + axis([0 (lengthToPlot-1)*8 0 ylims{outercount}(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + print([saveFinalFigs tsToSave '_fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs tsToSave '_fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + + print([saveFinalFigs tsToSave '_fitting_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + % create the endpoint plots + % The first location is empty, for the IFFL schematic. + figure + exp_endpoints = zeros(size(legends)); % number of experiments by number of doses. + exp_endpointsSD = zeros(size(legends)); + sim_endpoints = zeros(size(legends)); + sim_endpointsSD = zeros(size(legends)); + doseArray = zeros(size(legends)); + for i = 1:5 + doseArray(i, :) = data_info(i).dosedVals; + end + % doseArray(1, end) = 0.1/100; % 30c12 + % doseArray(2, end) = 0.0625/4; % lasR dna + % doseArray(3, end) = 0.1/100; % aTc + % doseArray(4, end) = 0.00001/100; % tetR dna + % doseArray(5, end) = 0.125/4; % deGFP dna + + + % build the data array + for count = 1:length(miToUse) + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + + % get the experimental data endpoints + for dID = 1:length(legends(count, :)) + exp_endpoints(count, dID) = ... + 0.001*mean(currdi.dataArray(lengthToPlot, 1, :, dID),3); + exp_endpointsSD(count, dID) = ... + std(0.001*currdi.dataArray(lengthToPlot, 1, :, dID),0,3); + sim_endpoints(count, dID) = ... + 0.001*mean(da{count}(lengthToPlot, 1, :, dID), 3, 'omitnan'); + sim_endpointsSD(count, dID) = ... + std(0.001*da{count}(lengthToPlot, 1, :, dID),0, 3, 'omitnan'); + end + end + % + + % Now generate the plots + % close all + + % + set(0,'Units','normalized') + figure + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.9, 0.8]) + + + xTickLabels = [{'4', '1', '2^{-2}', '2^{-4}'}; + {'2', '.02', '.0002', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}; + {'2', '0.5', '0.125', '0'}; + {'10', '10^{-1}', '10^{-3}', '0'}]; + titleArray = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + xLab = {'pTet deGFP DNA'; + 'tetR DNA'; + 'aTc'; + 'pLac deGFP DNA'; + '3OC12'}; + + for count = 1:length(miToUse) + subplot(2, 3, (count+1)) + ax = gca + ax.XScale = 'log'; + errorbar(doseArray(count, :),... + exp_endpoints(count, :),... + exp_endpointsSD(count, :),... + 'LineWidth', 2); + + hold on + + errorbar(doseArray(count, :), ... + sim_endpoints(count, :), ... + sim_endpointsSD(count, :), ... + 'LineWidth', 2) + ax = gca + ax.XScale = 'log'; + hold on + ax = gca + ax.XTick = fliplr(doseArray(count, 1:2:end)); + ax.XTickLabel = fliplr(xTickLabels(count, :)); + ax.FontSize = 16 + + % title(titleArray{count}) + ylabel('deGFP, uM'); + xlabel(xLab{count}); + + end + + print([saveFinalFigs tsToSave '_fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') + print([saveFinalFigs tsToSave '_fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') + print([saveFinalFigs tsToSave '_fitting_end_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + +end +% diff --git a/mcmc_simbio/projects/analysis_regen_C1.m b/mcmc_simbio/projects/analysis_regen_C1.m new file mode 100755 index 0000000..7350418 --- /dev/null +++ b/mcmc_simbio/projects/analysis_regen_C1.m @@ -0,0 +1,489 @@ + + + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_C1']; +addpath(projdir) + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_C1(mobj); +di = data_dsg2014_full; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 3; +plotflag = true; +switch tsIDtouse + case 1 % these were all messed up because the master vector was a bunch of zeros (log(1)'s) + % done on AWS, LHS initialization. + ts1temp = '20190208_075812_1_217593'; % 1800 steps with ladder [1.4 1.2 1]*1.2 + ts2temp = '20190208_075812_2_108797'; + ts3temp = '20190208_075812_3_21759'; + + nIterID = {1:7, 1:7, 1:6}; + tstamp = {ts1temp ts2temp ts3temp}; + load([projdir '/simdata_' ts1temp '/full_variable_set_' ts1temp '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + case 2 % feb 9, 3.10 pm. step 1.15, temp 0.05 (1088), 1200 walkers, 33 steps per iter, 20 iter. + ts1 = '20190209_070634_1_1088'; + nIterID = {1:13} + tstamp = {ts1}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + case 3 + ts1 = '20190209_091205_1_231'; + nIterID = {1:5} + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end + +mai.masterVector + + +marray = mcmc_get_walkers(tstamp,nIterID, projdir); +parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'n_{Kd1}' } + {'n_{Kd2}' } + {'RNAse_{Kd}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'aa_{Kd}' } + {'TL_n_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:50:end,:), parnames(:)); +% mcmc_plot(marray(1:6, 1:20:end,1:end), parnames(1:6)); +% mcmc_plot(marray(6+(1:8), 1:20:end,1:end), parnames(6+(1:8))); + + figure + [C,lags,ESS]=eacorr(marray(:, :,:));%10000:end + plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + grid on + xlabel('lags') + ylabel('autocorrelation'); + text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... + ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') + title('Markov Chain Auto Correlation') + % + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 1, length(mi(2).measuredSpeciesIndex)); + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = titls(j); + end + end + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.8, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls', {},... + 'SimMode', 'meanstd');%, 'savematlabfig', false, 'savejpeg', false + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); + mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd'); +end +marrayOrd(:,1:5,end) +flagz = ones(26, 1); +flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +[mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +% plot trajectories +lgds = {}; +% aaa =... +% [{[ 2.1904]} {[ 2.1904]} {'TX_elong_glob' } +% {[ 6.1017]} {[ 6.1017]} {'TL_elong_glob' } +% {[ 6.7502]} {[ 6.7502]} {'AGTPdeg_time' } +% {[ -8.9816]} {[ -8.9816]} {'AGTPdeg_rate' } +% {[ -1.9799]} {[ -1.9799]} {'TXTL_PROT_deGFP_?'} +% {[ -1.4155]} {[ -1.4155]} {'TXTL_UTR_UTR1_Kd' } +% {[ 1.0949]} {[ 1.0949]} {'TXTL_UTR_UTR1_F' } +% {[ 1.8325]} {[ 1.8325]} {'TXTL_P70_RNAPbou?'} +% {[ 4.5064]} {[ 4.5064]} {'TXTL_P70_RNAPbou?'} +% {[ -2.297]} {[ -2.297]} {'TXTL_RNAPBOUND_T?'} +% {[0.096026]} {[0.096026]} {'TXTL_NTP_RNAP_1_Kd'} +% {[ 2.1533]} {[ 2.1533]} {'TXTL_NTP_RNAP_1_F' } +% {[ 2.2435]} {[ 2.2435]} {'TXTL_NTP_RNAP_2_Kd'} +% {[-0.83904]} {[-0.83904]} {'TXTL_NTP_RNAP_2_F' } +% {[ 3.4805]} {[ 3.4805]} {'TL_AA_Kd' } +% {[-0.22471]} {[-0.22471]} {'TL_AA_F' } +% {[ 5.6524]} {[ 5.6524]} {'TL_AGTP_Kd' } +% {[ 0.97604]} {[ 0.97604]} {'TL_AGTP_F' } +% {[-0.95634]} {[-0.95634]} {'TXTL_RIBOBOUND_T?'} +% {[ 8.5748]} {[ 8.5748]} {'TXTL_RNAdeg_Kd' } +% {[ -0.5005]} {[ -0.5005]} {'TXTL_RNAdeg_F' } +% {[ -5.1466]} {[ -5.1466]} {'TXTL_RNAdeg_kc' } +% {[ 2.2309]} {[ 2.2309]} {'RNAP' } +% {[ 6.7048]} {[ 6.7048]} {'Ribo' } +% {[ 4.5145]} {[ 4.5145]} {'RNase' }]; +%% +activeNames1 = {... + 'TXTL_RNAdeg_Kd' 2000 [100 10000] + 'TXTL_RNAdeg_F' 0.02 [0.01 100] + 'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] + 'RNase' 100 [10 1000]}; + +simulatecurves(... + mi(1).emo,... + log(cell2mat(activeNames1(:,2))'),... + 1,... + di(mi(1).dataToMapTo).dosedVals', ... + di((mi(1).dataToMapTo)).timeVector, ... + mi(1).measuredSpecies) + +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +mcmc_trajectories(mi(1).emo,... + di(mi(1).dataToMapTo),... + mi(1),... + log(cell2mat(activeNames1(:,2))'),... + titls',... + {},... + 'SimMode', 'curves') +%% +figure +debugda = simulatecurves(... + mi(1).emo,... + log(cell2mat(activeNames1(:,2))'),... + 1,... + di(mi(1).dataToMapTo).dosedVals', ... + di((mi(1).dataToMapTo)).timeVector, ... + mi(1).measuredSpecies); + +for i = 1:size(debugda, 4) + subplot(size(debugda, 4), 1, i) + plot(di((mi(1).dataToMapTo)).timeVector, debugda(:,1,1,i)); + title(di(mi(1).dataToMapTo).dosedVals(i)); +end +%% +debugsd = simulate(mi(1).emo); +speciesnames = debugsd.DataNames; +figure +for i = 1:30 + subplot(6, 5, i) + currdata = simulatecurves(... + mi(1).emo,... + log(cell2mat(activeNames1(:,2))'),... + 1,... + di(mi(1).dataToMapTo).dosedVals', ... + di((mi(1).dataToMapTo)).timeVector, ... + {speciesnames(i)}); + plot(di((mi(1).dataToMapTo)).timeVector, currdata(:,1,1,1)); + title(speciesnames{i}) + + +end + + +%% + activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on + ...% posterior plots. + 'TX_elong_glob' exp(3.4) [0.5 300] % 1 + 'AGTPdeg_time' exp(9.57) [1800 42000] % set to exp(9.57) + 'AGTPdeg_rate' 0.0002 [1e-5 1e-2] % set from before + 'AGTPreg_ON' 0.02 [0.005 0.2] %4 % set from before + 'TXTL_P70_RNAPbound_Kd' 200 [0.1 1e6] % + 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) + 'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] % 7 + 'TXTL_NTP_RNAP_1_Kd' exp(12.5) [1 1e6] + 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 + 'TXTL_NTP_RNAP_2_Kd' exp(3) [0.1 1e7] + 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 + 'TXTL_RNAdeg_Kd' exp(7.6) [100 1e5] + 'TXTL_RNAdeg_F' 1 [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) + 'TXTL_RNAdeg_kc' exp(-5.4) [1e-4 1] %set to exp(-5.4) + 'RNAP' exp(5.8) [5 5000] % 15 + 'RNase' exp(5.3) [1 10000] + 'TL_elong_glob' 20 [0.1 500] + 'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] %18 % set from before + 'TXTL_UTR_UTR1_Kd' exp(4.5) [0.05 1e5] + 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) + 'TL_AA_Kd' exp(7.5) [.1 1e6] % 21 + 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) + 'TL_AGTP_Kd' exp(7.5) [.1 1e7] % 23 + 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) + 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5) [0.1 20000] + 'Ribo' exp(3.5) [10 10000]}; %26 + + % these are unordered parameters, from the fits from case 4, from + % regen_A. (file: manual_txtlsim_params) + close all + + pix = 34 +% mvarray load from case 4 of regen A analysis file: +% manual_txtlsim_parameters. + paramsToTest = mvarray(:,1:5:end,end); + + + +simulatecurves(... + mi(1).emo,... + log(cell2mat(activeNames2(mi(1).paramMaps,2))'),... + 1,... + di(mi(1).dataToMapTo).dosedVals', ... + di((mi(1).dataToMapTo)).timeVector, ... + mi(1).measuredSpecies) + + +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +mcmc_trajectories(mi(1).emo,... + di(mi(1).dataToMapTo),... + mi(1),... + (paramsToTest(mi(1).paramMaps(mi(1).orderingIx,1),pix)'),... + titls',... + {},... + 'SimMode', 'curves') +% + +titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 1, length(mi(2).measuredSpeciesIndex)); +for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = titls(j); + end +end +mcmc_trajectories(mi(2).emo,... + di(mi(2).dataToMapTo),... + mi(2),... + (paramsToTest(mi(2).orderingIx,pix)'),... + titls_array,... + {},... + 'SimMode', 'curves') + + + +%% +% sets that do well +close all +clc +activeNames2(:,1) +found1 = [ 5.5354 + 9.57 + -8.5172 + -3.912 + 9.514 + 1.5 + 3.3005 + 2.9459 + 0 + 13.997 + 0 + 9.237 + 0 + -5.4 + 2.4419 + 6.4899 + 5.1219 + -6.0748 + 11.189 + -0.2 + 6.5566 + -0.3 + 14.509 + -1.2 + 5.398 + 2.7081]; % mrna expression shape is fantastic. expression level is a bit high. manually adjusting: + mod1 = [ ... + 4.9354 % tx elong, verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 9.17 % AGTPdeg_time, verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + -9.5172 % AGTPdeg_rate, verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + -3.912 % AGTPreg_ON, verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 9.514 % 'TXTL_P70_RNAPbound_Kd', verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 1.5 % 'TXTL_P70_RNAPbound_F', verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 3.3005 % rnap termination rate, verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 2.9459%'TXTL_NTP_RNAP_1_Kd' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 0%'TXTL_NTP_RNAP_1_F' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 13.997%'TXTL_NTP_RNAP_2_Kd' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 0%'TXTL_NTP_RNAP_2_F' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 9.237%'TXTL_RNAdeg_Kd' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 %freeze + 0%'TXTL_RNAdeg_F' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 % freeze + -4.4%'TXTL_RNAdeg_kc' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 %freeze + 1.4419%'RNAP' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 % rnap + 6.4899%'RNase' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 %freeze + 0.5219%'TL_elong_glob' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + -6.0748%'TXTL_PROT_deGFP_MATURATION' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 11.189%'TXTL_UTR_UTR1_Kd' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + -0.2%'TXTL_UTR_UTR1_F' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 6.5566%'TL_AA_Kd' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + -0.3%'TL_AA_F' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 14.509%'TL_AGTP_Kd' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + -1.2%'TL_AGTP_F' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + 5.398%'TXTL_RIBOBOUND_TERMINATION_RATE' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 % ribo termination rate + 7.3081 ]; %'Ribo' , verified in mcmc_info_dsg2014_regen_D.m on Aug 26, 2019 + +% wow there is a trade off between the ribo number and the tl elongation +% rate. thats awesome. there is a linear vs saturation regime argument that +% needs to be made here. +% if protein expression at high dna fits, but at low dna the sim are much +% higher than the exp, then in the model the ribo is saturated, and the tl +% elongation rate is too high. if you increase the ribo count, all the +% expression levels go super high, but now the ribo is not saturated, and +% so the high dna protein conc goes much higher than the low dna protein +% conc. --> now lower the elongation rate, and everything scaled back down +% proportionately. this applied to both rna and protein. this along with +% non identifiability is a short note / section in this paper. --> the +% relative expression at diff dna conc allows for identifiability between +% the ribo count and the tl elongation rate, all else fixed. this, adding +% one extra trajectory from 1 -> 2 trajectories (ie 2 diff dna conc) +% increases the identifiability. + +% parameter tradeoffs and non identifiability paper -- can describe a +% general case of this above. for a tx, tl and rna deg example system. + +% +% +% +% +% ok, so with these parameter values the rna deg fits almost perfectly. the +% transcription and translation fit well for the highest dose. So we can +% start using these values as initial points. +% also some observations/guesses: NTP and aa binding F rates and Kds +% probaby do not matter too much, and just serve to make the model much +% harder to fit. just get rid of these by fixing them to the values in mod1 +% above. +% +% so set up the following sims: +% for all sims: + +% +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. + +% 1. The minimal sim (regen_D) +% also fix: +% {'TXTL_RNAdeg_Kd' } +% and the AGTP params: +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% leaving only + + +% {'TX_elong_glob' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% 10 parameters to estimate. +% can do this for both acsdsg and vnprl (vnprl has only 30nM ish for rna +% production. everything else is about the same, maybe use the figure in +% that paper to also scale the protein production levels by the one hour +% measurement. + +% 2. regen_E: +% fix the AGTP params: +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% leaving only + +% {'TX_elong_glob' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'RNAP' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNase' } +% 11 parameters to estimate. RNA deg here allows the algorithm to tune the RNA timescale. + +% 3. regen_F: +% estimate all 13 remaining params: +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TX_elong_glob' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'RNAP' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNase' } + + +% regen_G: (rna deg topology removed. +% {'TX_elong_glob' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'RNAP' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'Ribo' } + +% Do all of these at c5.9xlarge or m5.24xlarge, with step 1.18, temperature 0.001, 1200 +% walkers, and 20 iter at 100*1200 points per iter. + +% and even among these 6, prioritize regen_D on both the ACS dsg data and +% the vnprl data. BOSS -- just do those two to start, and email RMM the +% results! +% Plot with separate sim and exp, with max normalized y axes + + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +mcmc_trajectories(mi(1).emo,... + di(mi(1).dataToMapTo),... + mi(1),... + (mod1(mi(1).paramMaps(mi(1).orderingIx,1))'),... + titls',... + {},... + 'SimMode', 'curves') +% + +titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 1, length(mi(2).measuredSpeciesIndex)); +for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = titls(j); + end +end +mcmc_trajectories(mi(2).emo,... + di(mi(2).dataToMapTo),... + mi(2),... + (mod1(mi(2).orderingIx)'),... + titls_array,... + {},... + 'SimMode', 'curves') diff --git a/mcmc_simbio/projects/analysis_regen_D.m b/mcmc_simbio/projects/analysis_regen_D.m new file mode 100755 index 0000000..bcb5e25 --- /dev/null +++ b/mcmc_simbio/projects/analysis_regen_D.m @@ -0,0 +1,230 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_D']; +addpath(projdir) + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_D(mobj); +di = data_dsg2014_full; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190209_184946_1_44'; + ts2 = '20190210_072127_1_20'; + tstamp = {ts1 ts2}; + nIterID = {1:24 1:16}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + +% {'TX_elong_glob' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } + +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots + mcmc_plot(marray(:, 1:5:end,92*50:30:end), parnames(:),... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); + mcmc_plot(marray(:, 1:6:end,3600:30:end), parnames(:),... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'SemiBurnedIn'); + + mcmc_plot(marray(:, 1:10:end,1:50:end), parnames(:),... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); + + figure + [C,lags,ESS]=eacorr(marray(:, :,92*50:end));%10000:end + plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + grid on + xlabel('lags') + ylabel('autocorrelation'); + text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... + ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') + title('Markov Chain Auto Correlation') + + + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.95, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', ts1,... + 'extrafignamestring', 'RNAspike'); + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', ts1,... + 'extrafignamestring', 'MGa_deGFP'); +end +marrayOrd(:,1:5,end) +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + + + +%% + +% +% +% +% % In this file we try to find a set of parameter values that allow the +% % model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% % Vipul Singhal, 2019 +% +% % simulate txtl model with custom parameter values, and look at the species +% % plots as specified by mcmc_info object. +% +% % Set working directory to the txtlsim toolbox directory. +% projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_D']; +% addpath(projdir) +% +% % Load model, mcmc_info, and data_info. +% mobj = model_dsg2014_regen; +% mcmc_info = mcmc_info_dsg2014_regen_D(mobj); +% di = data_dsg2014_full; +% +% mi = mcmc_info.model_info; +% ri = mcmc_info.runsim_info; +% mai = mcmc_info.master_info; +% +% % plot data from existing simulations. +% tsIDtouse = 1; +% plotflag = true; +% switch tsIDtouse +% case 1 +% ts1 = '20190209_184946_1_44'; +% ts2 = '20190210_072127_1_20'; +% tstamp = {ts1}; +% nIterID = {1:20}; +% load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +% 'mi',... +% 'mcmc_info', 'data_info', 'mai', 'ri'); +% end +% +% mai.masterVector +% marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +% marray = marray_full(:,:,1:end); +% parnames = ... +% [{'TX_{cat}' } +% {'pol_{Kd}' } +% {'pol_{term}' } +% {'RNAse_{cat}' } +% {'pol' } +% {'RNase' } +% {'TL_{cat}' } +% {'Ribo_{Kd}' } +% {'Ribo_{term}' } +% {'Ribo' }]; +% % +% +% if plotflag +% close all +% % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:50:end,:), parnames(:)); +% % mcmc_plot(marray(1:6, 1:20:end,1:end), parnames(1:6)); +% % mcmc_plot(marray(6+(1:8), 1:20:end,1:end), parnames(6+(1:8))); +% +% figure +% [C,lags,ESS]=eacorr(marray(:, :,:));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% % +% titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +% titls_array = cell(length(titls), 1, length(mi(2).measuredSpeciesIndex)); +% for i = 1:length(mi(2).measuredSpeciesIndex) +% for j = 1:length(titls) +% titls_array(j, 1, i) = titls(j); +% end +% end +% mvarray = masterVecArray(marray, mai); +% samplePoints = ceil(size(mvarray, 3) * [.8, 1]); +% % +% marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +% mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +% titls', {},... +% 'SimMode', 'meanstd');%, 'savematlabfig', false, 'savejpeg', false +% +% marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +% mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +% titls_array, {},... +% 'SimMode', 'meanstd'); +% end +% marrayOrd(:,1:5,end) +% % flagz = ones(26, 1); +% % flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% % [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_regen_E.m b/mcmc_simbio/projects/analysis_regen_E.m new file mode 100755 index 0000000..170d7dd --- /dev/null +++ b/mcmc_simbio/projects/analysis_regen_E.m @@ -0,0 +1,121 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_E']; +addpath(projdir) + +jpgsave = false; +figsave = false; + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_E(mobj); +di = data_dsg2014_full; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190209_193419_1_22'; + ts2 = '20190210_072219_1_20'; + ts3 = '20190210_184717_1_2'; + tstamp = {ts1 ts2 ts3}; + nIterID = {1:14 1:10 1:8}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); + mcmc_plot(marray(:, 1:6:end,4000:10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); + + mcmc_plot(marray(:, 1:10:end,1:20:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); + figure + [C,lags,ESS]=eacorr(marray(:, :,4000:end));%10000:end + plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + grid on + xlabel('lags') + ylabel('autocorrelation'); + text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... + ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') + title('Markov Chain Auto Correlation') + + + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1,... + 'extrafignamestring', 'RNAspike'); + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1,... + 'extrafignamestring', 'MGa_deGFP'); +end +marrayOrd(:,1:5,end) +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_regen_F.m b/mcmc_simbio/projects/analysis_regen_F.m new file mode 100755 index 0000000..8ca7d76 --- /dev/null +++ b/mcmc_simbio/projects/analysis_regen_F.m @@ -0,0 +1,137 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_F']; +addpath(projdir) + +jpgsave = true; +figsave = true; + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_F(mobj); +di = data_dsg2014_full; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190210_184039_1_195'; + ts2 = '20190210_184039_2_20'; + ts3 = '20190211_054328_1_20'; + tstamp = {ts1 ts2 ts3}; + nIterID = {1:10 1:10 1:14}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); + mcmc_plot(marray(:, 1:3:end,3500:10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); + + mcmc_plot(marray(:, 1:10:end,1:20:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); + figure + [C,lags,ESS]=eacorr(marray(:, :,3500:end));%10000:end + plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + grid on + xlabel('lags') + ylabel('autocorrelation'); + text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... + ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') + title('Markov Chain Auto Correlation') +% + + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1,... + 'extrafignamestring', 'RNAspike'); + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1,... + 'extrafignamestring', 'MGa_deGFP'); +end +marrayOrd(:,1:5,end) +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_regen_F1.m b/mcmc_simbio/projects/analysis_regen_F1.m new file mode 100755 index 0000000..f64c44e --- /dev/null +++ b/mcmc_simbio/projects/analysis_regen_F1.m @@ -0,0 +1,153 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. + +% Set working directory to the txtlsim toolbox directory. + +projdir = './mcmc_simbio/projects/proj_acs_dsg2014_regen_F1'; + + + +addpath(projdir) + +jpgsave = true; +figsave = false; +plotflag = true; + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_F1(mobj); +di = data_dsg2014_full; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 1; +switch tsIDtouse + case 1 + ts1 = '20190210_184039_1_195'; + ts2 = '20190210_184039_2_20'; + ts3 = '20190211_054328_1_20'; + ts4 = '20190211_140024_1_20'; + ts5 = '20190212_053457_1_20'; + ts6 = '20190212_114314_1_20'; + tstamp = {ts1 ts2 ts3 ts4 ts5}; + nIterID = {1:10 1:10 1:15 1:27 1:11 1:22}; + load([projdir '/simdata_' tstamp{end} '/full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = tstamp{end}; +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +% mcmc_plot(marray(:, 1:end,8000:20:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts5, 'extrafignamestring', 'BurnedInAllWalkers'); + + +mcmc_plot(marray(:, 1:end,(end-4000):1000:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcmc_plot(marray(:, 1:end,(end-4000):500:end), parnames(:),... +% 'scatter', false, 'ess', 120, ... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn_ess'); + +mcmc_plot(marray(:, 1:10:end,1:10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTransient'); +% figure +% [C,lags,ESS]=eacorr(marray(:, :,(end-2000):500:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% + + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts5,... + 'extrafignamestring', 'RNAspike'); + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts5,... + 'extrafignamestring', 'MGa_deGFP'); +end +marrayOrd(:,1:5,end) +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_regen_G.m b/mcmc_simbio/projects/analysis_regen_G.m new file mode 100755 index 0000000..88b2d3a --- /dev/null +++ b/mcmc_simbio/projects/analysis_regen_G.m @@ -0,0 +1,99 @@ + + + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_G']; +addpath(projdir) + +jpgsave = true; +figsave = true; + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_G(mobj); +di = data_dsg2014_full; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190209_191801_1_127'; + ts2 = '20190210_030032_1_127'; + ts3 = '20190210_123436_1_32'; + ts4 = '20190210_185320_1_3'; + nIterID = {1:20 1:29 1:28 1:80}; + tstamp = {ts1 ts2 ts3}; + load([projdir '/simdata_' ts1temp '/full_variable_set_' ts1temp '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + +end + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:, :, 1:end); +parnames = ... + [{'TX_{cat}' } + {'pol_{Kd}' } + {'pol' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo' }]; +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:10:end,1:50:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +mcmc_plot(marray(:, 1:3:end,(120*50):50:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +% mcmc_plot(marray(6+(1:8), 1:20:end,1:end), parnames(6+(1:8))); + + figure + [C,lags,ESS]=eacorr(marray(:, :,(120*50):end));%10000:end + plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + grid on + xlabel('lags') + ylabel('autocorrelation'); + text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... + ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') + title('Markov Chain Auto Correlation') + % + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 1, length(mi(1).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true); +end +marrayOrd(:,1:5,end) +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] +% \ No newline at end of file diff --git a/mcmc_simbio/projects/analysis_regen_H.m b/mcmc_simbio/projects/analysis_regen_H.m new file mode 100755 index 0000000..baea76a --- /dev/null +++ b/mcmc_simbio/projects/analysis_regen_H.m @@ -0,0 +1,195 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_H']; +addpath(projdir) + +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_H(mobj); +di = data_dsg2014_full; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 3; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190211_122853_1_290'; + ts2 = '20190211_213614_1_29'; + ts3 = '20190213_141754_1_116'; + tstamp = {ts1 ts2 ts3}; + nIterID = {1:10 1:10 1:20}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + case 2 + ts1 = '20190211_122853_1_290'; %0.005 + ts2 = '20190213_173314_1_174'; % 0.003 + ts3 = '20190213_173314_2_58'; % 0.001 + ts4 = '20190213_173314_3_52'; %0.009 + ts5 = '20190213_173314_4_41'; % 0.007 + ts6 = '20190213_173314_5_29'; % 0.005 + + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6}; + nIterID = {1:10 1:5 1:5 1:5 1:5 1:5}; + load([projdir '/simdata_' ts6 '/full_variable_set_' ts6 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + case 3 + ts1 = '20190211_122853_1_290'; %0.005 + ts2 = '20190215_102557_1_232'; + ts3 = '20190215_102557_2_174'; + ts4 = '20190215_102557_3_116'; + + tstamp = {ts1 ts2 ts3 ts4}; + nIterID = {1:10 1:20 1:20 1:20}; + load([projdir '/simdata_' ts2 '/full_variable_set_' ts2 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'\alpha_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'n_{Kd1}' } + {'n_{Kd2}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'GFP_{mat}' } + {'Ribo_{Kd}' } + {'aa_{Kd}' } + {'TL_n_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; +% + +% +% +% {'TX_{cat}' } {'TX_elong_glob' } +% {'\tau_{atp}' } {'AGTPdeg_time' } +% {'\delta_{atp}'} {'AGTPdeg_rate' } +% {'\alpha_{atp}'} {'AGTPreg_ON' } +% {'pol_{Kd}' } {'TXTL_P70_RNAPbound_Kd' } +% {'pol_{term}' } {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'n_{Kd1}' } {'TXTL_NTP_RNAP_1_Kd' } +% {'n_{Kd2}' } {'TXTL_NTP_RNAP_2_Kd' } +% {'RNAse_{Kd}' } {'TXTL_RNAdeg_Kd' } +% {'RNAse_{cat}' } {'TXTL_RNAdeg_kc' } +% {'pol' } {'RNAP' } +% {'RNase' } {'RNase' } +% {'TL_{cat}' } {'TL_elong_glob' } +% {'GFP_{mat}' } {'TXTL_PROT_deGFP_MATURATION' } +% {'Ribo_{Kd}' } {'TXTL_UTR_UTR1_Kd' } +% {'aa_{Kd}' } {'TL_AA_Kd' } +% {'TL_n_{Kd}' } {'TL_AGTP_Kd' } +% {'Ribo_{term}' } {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } {'Ribo' } +% +%% +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +% mcmc_plot(marray(:, 1:end,5000:5:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedInAllWalkers'); + +% +% mcmc_plot(marray(:, 1:20:end,5000:10:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); + + mcmc_plot(marray(:, 1:end,(end-2000):10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts2, 'extrafignamestring', 'last300'); + + mcmc_plot(marray(:, 1:30:end,1:10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts2, 'extrafignamestring', 'WithTransient'); +% +% mcmc_plot(marray(:, 1:end,(end-4000):50:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +% +% mcmc_plot(marray(:, 1:40:end,(end-4000):10:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +% figure +% [C,lags,ESS]=eacorr(marray(:, :,5000:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% +%% + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts2,... + 'extrafignamestring', 'RNAspike'); + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts2,... + 'extrafignamestring', 'MGa_deGFP'); + %% +end +marrayOrd(:,1:5,end) +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_regen_I.m b/mcmc_simbio/projects/analysis_regen_I.m new file mode 100755 index 0000000..7cccca1 --- /dev/null +++ b/mcmc_simbio/projects/analysis_regen_I.m @@ -0,0 +1,167 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_I']; +addpath(projdir) + +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_I(mobj); +di = data_dsg2014_full; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190211_123400_1_290'; + ts2 = '20190211_214449_1_29'; + tstamp = {ts1 ts2}; + nIterID = {1:9 1:20}; + load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + +end + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'\alpha_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'GFP_{mat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; +% + +% +% +% {'TX_{cat}' } {'TX_elong_glob' } +% {'\tau_{atp}' } {'AGTPdeg_time' } +% {'\delta_{atp}'} {'AGTPdeg_rate' } +% {'\alpha_{atp}'} {'AGTPreg_ON' } +% {'pol_{Kd}' } {'TXTL_P70_RNAPbound_Kd' } +% {'pol_{term}' } {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'n_{Kd1}' } {'TXTL_NTP_RNAP_1_Kd' } +% {'n_{Kd2}' } {'TXTL_NTP_RNAP_2_Kd' } +% {'RNAse_{Kd}' } {'TXTL_RNAdeg_Kd' } +% {'RNAse_{cat}' } {'TXTL_RNAdeg_kc' } +% {'pol' } {'RNAP' } +% {'RNase' } {'RNase' } +% {'TL_{cat}' } {'TL_elong_glob' } +% {'GFP_{mat}' } {'TXTL_PROT_deGFP_MATURATION' } +% {'Ribo_{Kd}' } {'TXTL_UTR_UTR1_Kd' } +% {'aa_{Kd}' } {'TL_AA_Kd' } +% {'TL_n_{Kd}' } {'TL_AGTP_Kd' } +% {'Ribo_{term}' } {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } {'Ribo' } +% +%% +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +% mcmc_plot(marray(:, 1:end,5000:5:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedInAllWalkers'); + +% +% mcmc_plot(marray(:, 1:20:end,5000:10:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); + + mcmc_plot(marray(:, 1:end,(end-2000):20:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'last100'); + + mcmc_plot(marray(:, 1:20:end,1:10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +% +% mcmc_plot(marray(:, 1:end,(end-4000):50:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +% +% mcmc_plot(marray(:, 1:40:end,(end-4000):10:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +% figure +% [C,lags,ESS]=eacorr(marray(:, :,5000:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% +%% + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [0.8 0.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1,... + 'extrafignamestring', 'RNAspike'); + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', true,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', ts1,... + 'extrafignamestring', 'MGa_deGFP'); + %% +end +marrayOrd(:,1:5,end) +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] diff --git a/mcmc_simbio/projects/analysis_test015calib.m b/mcmc_simbio/projects/analysis_test015calib.m new file mode 100755 index 0000000..e2b6000 --- /dev/null +++ b/mcmc_simbio/projects/analysis_test015calib.m @@ -0,0 +1,429 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. +close all +clear all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_test015']; +addpath(projdir) + +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +mobj = model_protein3; +mcmc_info = mcmc_info_test015(mobj); +di = data_test015; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 3.2; + +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190313_091216_1_0p32242'; + ts2 = '20190313_101830_1_0p32242'; + ts3 = '20190313_130351_1_0p32242'; + ts4='20190313_153908_1_0p32242'; + ts5 = '20190313_171758_1_0p064484'; + ts6 = '20190314_004559_1_0p12897'; + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6}; + + nIterID = {1:9 1:20 1:20 1:5 1:60 1:30}; + load([projdir '/simdata_' ts6 '/full_variable_set_' ts6 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + case 2 + ts1 = '20190314_161518_1_322'; + ts2 = '20190314_161518_2_242'; + ts3 = '20190314_161518_3_161'; + ts4 = '20190314_161518_4_81'; + ts5 = '20190315_102139_1_242'; + ts6 = '20190315_102139_2_81'; + ts7 = '20190316_033531_1_81'; + ts8 = '20190316_044847_1_81'; + ts9 = '20190316_092219_1_242'; + ts10 = '20190318_082039_1_32'; + ts11 = '20190318_082039_2_23'; + ts12 = '20190318_082039_3_10'; + ts13 = '20190318_143245_1_10'; + ts14 = '20190318_143245_2_6'; + ts15 = '20190318_143245_3_3'; + ts16 = '20190319_071743_1_32'; + ts17 = '20190319_105547_1_10' + + tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11 ts12 ts13 ts14 ts15 ts16 ts17}; + tsToSave = ts17; + nIterID = {1:20 1:20 1:20 1:20 1:30 1:6 1:7 1:24 1:50 1:15 1:15 1:9 1:45 1:45 1:39 1:29 1:33}; + load([projdir '/simdata_' tsToSave '/full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + case 3 + + ts13 = '20190318_143245_1_10'; + + ts14 = '20190318_143245_2_6'; + ts15 = '20190318_143245_3_3'; + ts16 = '20190319_071743_1_32'; + + ts17 = '20190319_105547_1_10' + tstamp = {ts13 ts14 ts15 ts16 ts17}; + tsToSave = ts17; + nIterID = {1:45 1:45 1:39 1:29 1:33}; + load([projdir '/simdata_' tsToSave '/full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + case 3.1 + + ts13 = '20190318_143245_1_10'; + + ts14 = '20190318_143245_2_6'; + ts15 = '20190318_143245_3_3'; + + ts17 = '20190319_105547_1_10' + tstamp = {ts13 ts14 ts15 ts17}; + tsToSave = ts17; + nIterID = {1:45 1:45 1:39 1:33}; + load([projdir '/simdata_' tsToSave '/full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + % these sims suggest that kcp2 should be -2.8 to -3 (==-3.001). pretty tight! + % pol2 : +2.6 to +2.8. (== 2.655) + + % for ESP 1: 2 for kcp1. for pol 1: -0.2 to -0.4 + % the esps, can also try -3.6 to -3.9 (-3.66) for kcp1 and + % 3.3 (+-0.2) (==3.26) for the pol1. This second point is more compatible + % with the ESP2 point I think. moving to the corr code now: + % analysis file for test015_corr1_Ffix3 + + case 3.2 + + ts17 = '20190319_105547_1_10'; + ts18 = '20190319_153606_1_10'; + ts19 = '20190319_152204_1_10'; + ts20 = '20190319_153210_1_16'; + tstamp = {ts17 ts18 ts19 ts20}; + tsToSave = ts20; + nIterID = {1:35 1:74 1:80 1:80}; + load([projdir '/simdata_' tsToSave '/full_variable_set_'... + tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + % 20190319_153606_1_10 +end + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... + {'kfdG' + 'krdG' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + + +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +%% +% close +% marray_red = marray(:, :,((end-2600):10:end)); +% mstack = marray_red(:, :)'; +% ixs = find(mstack(:, 4)>-2.89 & mstack(:, 4)<-2.85 &... +% mstack(:, 6)>2.63 & mstack(:, 6)<2.65); +% mcmc_plot(mstack(ixs,:), parnames(:)) +% + +% mcmc_plot(marray(:, 1:end,1:100:end), parnames(:),... %uncomment this +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +% mcmc_plot(marray(:, 1:end,(end-6000):500:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +% mcmc_plot(marray(:, 1:20:end,(end-24000):500:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +% +% mcmc_plot(marray(:, 1:20:end,1:100:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +% mcmc_plot(marray([1 2 3 5], 1:10:end,1:100:end), parnames([1 2 3 5]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTr_E1'); +% mcmc_plot(marray([1 2 3 5], 1:end,(end-2000):100:end), parnames([1 2 3 5]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E1'); + +% mcmc_plot(marray([1 2 4 6], 1:10:end,1:100:end), parnames([1 2 4 6]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTr_E2'); +% mcmc_plot(marray([1 2 4 6], 1:end,(end-2000):100:end), parnames([1 2 4 6]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E2'); + + +% figure +% [C,lags,ESS]=eacorr(marray(:, :,8000:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% +%% + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'E1'); + + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,2),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(2)), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'E2'); +%% +end + + +%% +% get a random point from the estimated parameter sets +% [parnames, mat2cell(marray(:, [1:12:240],end), ones(6,1), ones(1,20))] +% +% ans = +% +% 621 cell array +% +% Columns 1 through 14 +% +% {'kfdG'} {[ -2.0574]} {[-4.6507]} {[-3.9888]} {[ 1.1461]} {[ -4.5084]} {[ -3.6959]} {[-0.1910]} {[-3.9767]} {[ -3.3438]} {[-2.8501]} {[-0.9583]} {[ 1.1404]} {[-10.2457]} +% {'krdG'} {[-12.3652]} {[-1.6276]} {[-9.9750]} {[-2.4359]} {[-12.2308]} {[-10.5998]} {[-9.9598]} {[-7.3686]} {[-11.6602]} {[ 1.4934]} {[ 1.2494]} {[-7.1829]} {[-10.6801]} +% {'kcp1'} {[ 3.6547]} {[-3.3864]} {[ 1.6081]} {[ 5.6473]} {[ 3.0718]} {[ -3.7681]} {[ 5.8442]} {[ 6.7586]} {[ 8.2938]} {[-1.7960]} {[-3.5343]} {[-3.7404]} {[ 3.4331]} +% {'kcp2'} {[ 1.1577]} {[ 6.1950]} {[-2.8704]} {[-3.1807]} {[ -1.9671]} {[ -0.5470]} {[ 3.1399]} {[-2.8587]} {[ -3.0283]} {[ 6.7610]} {[ 1.6672]} {[ 4.4217]} {[ 3.5146]} +% {'pol1'} {[ -1.6481]} {[ 4.2446]} {[ 0.2897]} {[-4.7253]} {[ 0.7588]} {[ 8.6459]} {[-3.5217]} {[ 0.2230]} {[ -0.4036]} {[ 2.7609]} {[ 3.9028]} {[ 6.0991]} {[ 6.4998]} +% {'pol2'} {[ -0.8519]} {[ 1.2191]} {[ 2.6442]} {[ 2.6753]} {[ 2.0417]} {[ 0.8476]} {[-2.7737]} {[ 2.6192]} {[ 2.6895]} {[-0.5681]} {[-1.4208]} {[-4.0794]} {[ 6.8263]} +% +% Columns 15 through 21 +% +% {[-3.1836]} {[-1.0828]} {[-3.5680]} {[-4.5238]} {[ -3.5820]} {[ 9.8297]} {[ 9.1477]} +% {[-4.5015]} {[-4.8491]} {[-4.1115]} {[-3.8101]} {[-13.2259]} {[-12.1666]} {[ -9.7015]} +% {[ 4.3357]} {[ 4.0316]} {[ 4.3941]} {[ 1.4003]} {[ 2.6556]} {[ 0.4588]} {[-11.3254]} +% {[-3.0056]} {[ 2.2533]} {[-2.9253]} {[-2.2433]} {[ -3.0114]} {[ 2.4327]} {[ 5.3693]} +% {[-0.5535]} {[-2.5742]} {[-0.1758]} {[ 0.8345]} {[ -0.1398]} {[-13.4085]} {[ 9.8451]} +% {[ 2.6449]} {[-1.8759]} {[ 2.6335]} {[ 2.3418]} {[ 2.6971]} {[-10.3830]} {[ 9.4620]} + +%% +% [parnames, mat2cell(marray(:, [25],end), ones(6,1), ones(1,1))] +% +% ans = +% +% 62 cell array +% +% {'kfdG'} {[-3.9888]} +% {'krdG'} {[-9.9750]} +% {'kcp1'} {[ 1.6081]} +% {'kcp2'} {[-2.8704]} +% {'pol1'} {[ 0.2897]} +% {'pol2'} {[ 2.6442]} + +% the esps we will use are: +% {'kcp2'} {[-2.8704]} +% {'pol2'} {[ 2.6442]} + +% and the CSPfixed esps for that are: +% {'kcp1'} {[ 1.6081]} +% {'pol1'} {[ 0.2897]} + + +% ok no good: lets try again. +% I constrained all the points to +% ixs = find(mstack(:, 4)>-3.1 & mstack(:, 4)<-2.8 &... +% mstack(:, 6)>2.5 & mstack(:, 6)<2.8); +% and generated the corner plot. + +% With these constraints, some of the compatible parameter values for the +% ESP1s are (compatible == there exists a point in CSP space for which the +% there is at least one point in E1 and one in E2 . + +% kcp1 = -3.795 to -3.71 || pol1 = 2.9 to 9.7 +% another set is: the trapezoid with vertices: + +% X,Y +% 0.59, 0.369 +% 3.033, -1.59 +% 9.83, 0.369 +% 9.83, -1.59 + + + + + + + + +%% +%% +%% get points that are within a tight range of the ESP2 fixed points. +%(for use with the corr steps) +% +% marray_red = marray(:, :,1:200:end); +% mstack = marray_red(:, :)'; +% +% % these sims suggest that kcp2 should be -2.8 to -3 (==-3.001). pretty tight! +% % pol2 : +2.6 to +2.8. (== 2.655) +% +% % for ESP 1: 2 for kcp1. for pol 1: -0.2 to -0.4 +% % the esps, can also try -3.6 to -3.9 (-3.66) for kcp1 and +% % 3.3 (+-0.2) (==3.26) for the pol1. This second point is more compatible +% % with the ESP2 point I think. moving to the corr code now: +% % analysis file for test015_corr1_Ffix3 +% +% epsi = 0.1; +% kc1 = -3.66; +% pol1 = 3.26; +% kc2 = -2.87; +% pol2 = 2.6442; +% +% ixs = find(mstack(:, 4)>(kc2-epsi) & mstack(:, 4)<(kc2+epsi) &... +% mstack(:, 6)>(pol2-epsi) & mstack(:, 6)<(pol2+epsi)); +% +% % ixs = find(mstack(:, 4)>kc2-epsi & mstack(:, 4)pol2-epsi & mstack(:, 6)kc1-epsi & mstack(:, 3)pol1-epsi & mstack(:, 5)kcp2val-epsi & mstack(:, 4)pol2val-epsi & mstack(:, 6)(kfdg-epsi) & mstack(:, 1)<(kfdg+epsi) &... + mstack(:, 2)>(krdg-epsi) & mstack(:, 2)<(krdg+epsi)); + +% ixs = find(mstack(:, 4)>kc2-epsi & mstack(:, 4)pol2-epsi & mstack(:, 6)kc1-epsi & mstack(:, 3)pol1-epsi & mstack(:, 5)-2.89 & mstack(:, 4)<-2.85 &... +% mstack(:, 6)>2.63 & mstack(:, 6)<2.65); +% mcmc_plot(mstack(ixs,:), parnames(:)) +% + + mcmc_plot(marray(:, 1:end,1:20:end), parnames(:),... %uncomment this + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); + mcmc_plot(marray(:, 1:end,(end-1000):20:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); + +% + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'E1'); + + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,2),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(2)), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'E2'); +%% +end + + + + + diff --git a/mcmc_simbio/projects/analysis_test015calib_kdfgfix.m b/mcmc_simbio/projects/analysis_test015calib_kdfgfix.m new file mode 100755 index 0000000..3920688 --- /dev/null +++ b/mcmc_simbio/projects/analysis_test015calib_kdfgfix.m @@ -0,0 +1,220 @@ + +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. +close all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_test015_kfdgfix']; +addpath(projdir) + +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +mobj = model_protein3; +mcmc_info = mcmc_info_test015_kfdgfix(mobj); +di = data_test015; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 1; + +plotflag = true; +switch tsIDtouse + + case 1 + ts1 = '20190315_152003_1_242'; + ts2 = '20190315_152003_2_161'; + ts3 = '20190315_152003_3_81'; + tstamp = {ts1 ts2 ts3}; + tsToSave = ts1; + nIterID = {1:30 1:30 1:23}; + load([projdir '/simdata_' tsToSave '/full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + {'krdG' + 'kcp1' + 'kcp2' + 'pol1' + 'pol2'}; + + +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +%% +% close +% marray_red = marray(:, :,(end-16000:50:end)); +% mstack = marray_red(:, :)'; +% ixs = find(mstack(:, 1)>-4.7 & mstack(:, 1)<-3.45); +% mcmc_plot(mstack(ixs,:), parnames(:)) +%% + + mcmc_plot(marray(:, 1:10:end,1:100:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +mcmc_plot(marray(:, 1:end,(end-10000):500:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +% +% mcmc_plot(marray([1 2 3 5], 1:10:end,1:100:end), parnames([1 2 3 5]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTr_E1'); +% mcmc_plot(marray([1 2 3 5], 1:end,(end-2000):100:end), parnames([1 2 3 5]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E1'); + +% mcmc_plot(marray([1 2 4 6], 1:10:end,1:100:end), parnames([1 2 4 6]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTr_E2'); +% mcmc_plot(marray([1 2 4 6], 1:end,(end-2000):100:end), parnames([1 2 4 6]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E2'); + + +% figure +% [C,lags,ESS]=eacorr(marray(:, :,8000:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% +% %% + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'E1'); + + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,2),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(2)), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'E2'); +end + + +%% +% get a random point from the estimated parameter sets +% [parnames, mat2cell(marray(:, [1:12:240],end), ones(6,1), ones(1,20))] +% +% ans = +% +% 621 cell array +% +% Columns 1 through 14 +% +% {'kfdG'} {[ -2.0574]} {[-4.6507]} {[-3.9888]} {[ 1.1461]} {[ -4.5084]} {[ -3.6959]} {[-0.1910]} {[-3.9767]} {[ -3.3438]} {[-2.8501]} {[-0.9583]} {[ 1.1404]} {[-10.2457]} +% {'krdG'} {[-12.3652]} {[-1.6276]} {[-9.9750]} {[-2.4359]} {[-12.2308]} {[-10.5998]} {[-9.9598]} {[-7.3686]} {[-11.6602]} {[ 1.4934]} {[ 1.2494]} {[-7.1829]} {[-10.6801]} +% {'kcp1'} {[ 3.6547]} {[-3.3864]} {[ 1.6081]} {[ 5.6473]} {[ 3.0718]} {[ -3.7681]} {[ 5.8442]} {[ 6.7586]} {[ 8.2938]} {[-1.7960]} {[-3.5343]} {[-3.7404]} {[ 3.4331]} +% {'kcp2'} {[ 1.1577]} {[ 6.1950]} {[-2.8704]} {[-3.1807]} {[ -1.9671]} {[ -0.5470]} {[ 3.1399]} {[-2.8587]} {[ -3.0283]} {[ 6.7610]} {[ 1.6672]} {[ 4.4217]} {[ 3.5146]} +% {'pol1'} {[ -1.6481]} {[ 4.2446]} {[ 0.2897]} {[-4.7253]} {[ 0.7588]} {[ 8.6459]} {[-3.5217]} {[ 0.2230]} {[ -0.4036]} {[ 2.7609]} {[ 3.9028]} {[ 6.0991]} {[ 6.4998]} +% {'pol2'} {[ -0.8519]} {[ 1.2191]} {[ 2.6442]} {[ 2.6753]} {[ 2.0417]} {[ 0.8476]} {[-2.7737]} {[ 2.6192]} {[ 2.6895]} {[-0.5681]} {[-1.4208]} {[-4.0794]} {[ 6.8263]} +% +% Columns 15 through 21 +% +% {[-3.1836]} {[-1.0828]} {[-3.5680]} {[-4.5238]} {[ -3.5820]} {[ 9.8297]} {[ 9.1477]} +% {[-4.5015]} {[-4.8491]} {[-4.1115]} {[-3.8101]} {[-13.2259]} {[-12.1666]} {[ -9.7015]} +% {[ 4.3357]} {[ 4.0316]} {[ 4.3941]} {[ 1.4003]} {[ 2.6556]} {[ 0.4588]} {[-11.3254]} +% {[-3.0056]} {[ 2.2533]} {[-2.9253]} {[-2.2433]} {[ -3.0114]} {[ 2.4327]} {[ 5.3693]} +% {[-0.5535]} {[-2.5742]} {[-0.1758]} {[ 0.8345]} {[ -0.1398]} {[-13.4085]} {[ 9.8451]} +% {[ 2.6449]} {[-1.8759]} {[ 2.6335]} {[ 2.3418]} {[ 2.6971]} {[-10.3830]} {[ 9.4620]} + +%% +% [parnames, mat2cell(marray(:, [25],end), ones(6,1), ones(1,1))] +% +% ans = +% +% 62 cell array +% +% {'kfdG'} {[-3.9888]} +% {'krdG'} {[-9.9750]} +% {'kcp1'} {[ 1.6081]} +% {'kcp2'} {[-2.8704]} +% {'pol1'} {[ 0.2897]} +% {'pol2'} {[ 2.6442]} + +% the esps we will use are: +% {'kcp2'} {[-2.8704]} +% {'pol2'} {[ 2.6442]} + +% and the CSPfixed esps for that are: +% {'kcp1'} {[ 1.6081]} +% {'pol1'} {[ 0.2897]} + + + + + + +%% +%% +%% + + + + + + + + + + diff --git a/mcmc_simbio/projects/analysis_test015corr1.m b/mcmc_simbio/projects/analysis_test015corr1.m new file mode 100755 index 0000000..a008ad6 --- /dev/null +++ b/mcmc_simbio/projects/analysis_test015corr1.m @@ -0,0 +1,246 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. +close all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_test015_corr1']; +addpath(projdir) + +jpgsave = true; +figsave = false; + +% Load model, mcmc_info, and data_info. +mobj = model_tetR_repression1; +mcmc_info = mcmc_info_test015_corr1(mobj, exp(-7.6), exp(1.0212)); +di = data_test015; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190314_050144_1_0p20762'; + ts2 = '20190314_072843_1_0p083047'; + tstamp = {ts1 ts2}; + tsToSave = ts2; + nIterID = {1:20 1:3}; + load([projdir '/simdata_' tsToSave '/full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); +end + + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'kfdimTet' + 'krdimTet' + 'kfseqTet' + 'krseqTet'}; + + +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots + % mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); + + mcmc_plot(marray(:, 1:end,1:50:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTr_E2'); + % mcmc_plot(marray(:, 1:end,(end-400):10:end), parnames(:),... + % 'savematlabfig', figsave, 'savejpeg', jpgsave,... + % 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E2'); + + + + % figure + % [C,lags,ESS]=eacorr(marray(:, :,8000:end));%10000:end + % plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + % grid on + % xlabel('lags') + % ylabel('autocorrelation'); + % text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... + % ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') + % title('Markov Chain Auto Correlation') + % + % + mvarray = masterVecArray(marray, mai); + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'GFP'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial tetR DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial tetR DNA, MCMC samples']}; + end + end + mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'E2'); +end + + +%% +% get a random point from the estimated parameter sets +% [parnames, mat2cell(marray(:, [1:12:240],end), ones(6,1), ones(1,20))] +% +% ans = +% +% 621 cell array +% +% Columns 1 through 11 +% +% {'kfdG'} {[-9.9230]} {[-10.0279]} {[-10.0490]} {[ 0.9135]} {[-9.8466]} {[ 2.5695]} {[-12.3827]} {[-9.6395]} {[-9.5673]} {[ -9.9738]} +% {'krdG'} {[-7.8902]} {[ -8.0737]} {[-14.2225]} {[ 4.1679]} {[-8.7788]} {[ 5.7239]} {[ -6.6774]} {[-7.5997]} {[-7.5270]} {[-10.8543]} +% {'kcp1'} {[-5.8553]} {[ -5.9863]} {[ -5.7237]} {[ 5.9874]} {[-5.2996]} {[-10.1357]} {[ -7.3498]} {[ 6.4347]} {[ 5.1633]} {[-10.4953]} +% {'kcp2'} {[-8.2237]} {[ -8.0306]} {[ -7.3076]} {[ -5.8253]} {[-7.1465]} {[ -6.3534]} {[ 0.5973]} {[-8.8182]} {[-8.5993]} {[ -7.0679]} +% {'pol1'} {[-0.3304]} {[ -0.2121]} {[ -0.3397]} {[-11.3549]} {[-0.5816]} {[ 3.7748]} {[ 3.0265]} {[-1.0331]} {[-1.0991]} {[ 3.8026]} +% {'pol2'} {[ 1.5239]} {[ 1.3512]} {[ 0.6652]} {[ -0.7377]} {[ 0.5284]} {[ -0.2976]} {[ 2.0457]} {[ 2.0093]} {[ 1.7829]} {[ 0.4793]} +% +% Columns 12 through 21 +% +% {[ 2.5067]} {[-10.3252]} {[-3.4820]} {[ -9.9379]} {[-12.1544]} {[-10.1121]} {[-10.0937]} {[-9.9760]} {[-10.0684]} {[ 4.1603]} +% {[ 5.8421]} {[ -4.5220]} {[ 1.8388]} {[ -7.8741]} {[ -7.9822]} {[ -8.2681]} {[-12.5256]} {[-8.3245]} {[ -9.4601]} {[ 7.3636]} +% {[-9.9686]} {[ 5.9437]} {[-0.9758]} {[-10.2922]} {[ -6.5860]} {[ -6.3789]} {[ -5.6945]} {[-5.4273]} {[ 4.5807]} {[ 9.1865]} +% {[-4.7680]} {[ 9.5168]} {[ 8.4722]} {[ -7.6000]} {[ 9.3837]} {[ -8.0744]} {[ -7.1395]} {[-7.6876]} {[ -7.6084]} {[ 1.3875]} +% {[ 3.5909]} {[ -0.3403]} {[-4.2267]} {[ 3.7324]} {[ 1.9430]} {[ -0.0146]} {[ -0.3272]} {[-0.4369]} {[ -0.5857]} {[-14.5707]} +% {[-1.7568]} {[ -0.0170]} {[-6.8525]} {[ 1.0212]} {[ 1.8255]} {[ 1.4176]} {[ 0.5867]} {[ 1.0151]} {[ 0.9188]} {[ -8.0192]} + + +% [parnames, mat2cell(marray(:, [157],end), ones(6,1), ones(1,1))] + +% ans = +% +% 62 cell array +% +% {'kfdG'} {[ -9.9379]} +% {'krdG'} {[ -7.8741]} +% {'kcp1'} {[-10.2922]} +% {'kcp2'} {[ -7.6000]} +% {'pol1'} {[ 3.7324]} +% {'pol2'} {[ 1.0212]} + +% the esps we used are: +% {'kcp2'} {[ -7.6000]} +% {'pol2'} {[ 1.0212]} + +% and the CSPfixed esps for that are: +% {'kcp1'} {[-10.2922]} +% {'pol1'} {[ 3.7324]} + +% The ESPs when the CSPs are not fixed are: +% we can try are: +% [ 5.9874] +% [-11.3549] +% +% or +% +% [ 5.9437] +% [ -0.3403] +% +% or +% +% [-0.9758] +% [-4.2267] +% +% or +% +% [ 9.1865] +% [-14.5707] +%% +%% +%% Now we perform correction step 2 without CSP fixing, and then with. + +figure +% The ESPs we use are +kcp1 = exp( 5.9874); +pol1 = exp(-11.3549); + +espvec = [ 5.9874; -11.3549] + +% next we simulate the results with the estimated test CSP params and +% the non CSP fixing ESPs above. + +% create a master info + +szm = size(marray); +mvarray_corr21 = repmat(mai.masterVector, [1, szm(2:end)]) ; +eparray = repmat(espvec, [1, szm(2:end)]) ; +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +mvarray_corr21(estParamsIx, :, :) = marray; +mvarray_corr21(mai.fixedParams, :, :) = eparray; + +samplePoints = ceil(size(mvarray_corr21, 3) * [.9, 1]); +% +marrayOrd = mvarray_corr21(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'GFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; + end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... + titls_array, {},... + 'SimMode', 'meanstd', 'separateExpSim', false,... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave,... + 'extrafignamestring', 'E2'); + +% and plot these. + + +% and finally with the CSP fixing ESPs + + + + + + + + + + + + + diff --git a/mcmc_simbio/projects/analysis_test015corr1_Ffix.m b/mcmc_simbio/projects/analysis_test015corr1_Ffix.m new file mode 100755 index 0000000..18c7113 --- /dev/null +++ b/mcmc_simbio/projects/analysis_test015corr1_Ffix.m @@ -0,0 +1,401 @@ + +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 + +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. +close all + +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_test015_corr1_Ffix']; +addpath(projdir) + +jpgsave = false; +figsave = false; + +% Load model, mcmc_info, and data_info. +mobj = model_tetR_repression1; +mcmc_info = mcmc_info_test015_corr1_Ffix(mobj, exp(-2.8704), exp(2.6442)); + + +% {'kcp2'} {[-2.8704]} +% {'pol2'} {[ 2.6442]} + + +di = data_test015; + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. +tsIDtouse = 2; +plotflag = true; +switch tsIDtouse + case 1 + ts1 = '20190314_123130_1_0p20762'; + ts2 = '20190314_123130_2_0p10381'; + tstamp = {ts1 ts2}; + tsToSave = ts2; + nIterID = {1:10 1:3}; + load([projdir '/simdata_' tsToSave '/full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + case 2 + ts1 = '20190315_031445_1_104'; + ts2 = '20190315_040723_1_104' + tstamp = {ts1 ts2}; + tsToSave = ts2; + nIterID = {1:6 1:12}; + load([projdir '/simdata_' tsToSave '/full_variable_set_' tsToSave '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + + +end + + +mai.masterVector + + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +parnames = ... + {'kfdG' + 'krdG' + 'kfdT' + 'krdT' + 'krdimTet' + 'kfseqTet' + 'krseqTet'}; + + +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% + +if plotflag + close all + % Plot trace and corner (posterior distribution) plots + % + + % elements of marray: + % {'kfdG' + % 'krdG' + % 'kfdT' + % 'krdT' + % 'krdimTet' + % 'kfseqTet' + % 'krseqTet'}; + % want to restrict the kfdg and krdg by the values that would be the bounds + % when the ESP2 values are fixed. + % ie, + +% +% +% mcmc_plot(marray(:, 1:end,(end-3000):50:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E2'); +% mcmc_plot(marray(:, 1:10:end,1:10:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTr_E2'); +% + + + % figure + % [C,lags,ESS]=eacorr(marray(:, :,8000:end));%10000:end + % plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + % grid on + % xlabel('lags') + % ylabel('autocorrelation'); + % text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... + % ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') + % title('Markov Chain Auto Correlation') + % + % + %% +% mvarray = masterVecArray(marray, mai); +% samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% % +% marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +% titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +% titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +% ms = {'GFP'}; +% for i = 1:length(mi(1).measuredSpeciesIndex) +% for j = 1:length(titls) +% titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; +% titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; +% end +% end +% mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... +% titls_array, {},... +% 'SimMode', 'meanstd', 'separateExpSim', false,... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'E2'); +end + +% mi.namesOrd +% +% ans = +% +% 101 cell array +% +% {'kfdT' } +% {'krdT' } +% {'kcp' } +% {'kfdG' } +% {'krdG' } +% {'kfdimTet'} +% {'krdimTet'} +% {'kfseqTet'} +% {'krseqTet'} +% {'pol' } + +%% +%% +% get a random point from the estimated parameter sets +% [parnames, mat2cell(marray(:, [1:12:240],end), ones(6,1), ones(1,20))] +% +% ans = +% +% 621 cell array +% +% Columns 1 through 14 +% +% {'kfdG'} {[ -2.0574]} {[-4.6507]} {[-3.9888]} {[ 1.1461]} {[ -4.5084]} {[ -3.6959]} {[-0.1910]} {[-3.9767]} {[ -3.3438]} {[-2.8501]} {[-0.9583]} {[ 1.1404]} {[-10.2457]} +% {'krdG'} {[-12.3652]} {[-1.6276]} {[-9.9750]} {[-2.4359]} {[-12.2308]} {[-10.5998]} {[-9.9598]} {[-7.3686]} {[-11.6602]} {[ 1.4934]} {[ 1.2494]} {[-7.1829]} {[-10.6801]} +% {'kcp1'} {[ 3.6547]} {[-3.3864]} {[ 1.6081]} {[ 5.6473]} {[ 3.0718]} {[ -3.7681]} {[ 5.8442]} {[ 6.7586]} {[ 8.2938]} {[-1.7960]} {[-3.5343]} {[-3.7404]} {[ 3.4331]} +% {'kcp2'} {[ 1.1577]} {[ 6.1950]} {[-2.8704]} {[-3.1807]} {[ -1.9671]} {[ -0.5470]} {[ 3.1399]} {[-2.8587]} {[ -3.0283]} {[ 6.7610]} {[ 1.6672]} {[ 4.4217]} {[ 3.5146]} +% {'pol1'} {[ -1.6481]} {[ 4.2446]} {[ 0.2897]} {[-4.7253]} {[ 0.7588]} {[ 8.6459]} {[-3.5217]} {[ 0.2230]} {[ -0.4036]} {[ 2.7609]} {[ 3.9028]} {[ 6.0991]} {[ 6.4998]} +% {'pol2'} {[ -0.8519]} {[ 1.2191]} {[ 2.6442]} {[ 2.6753]} {[ 2.0417]} {[ 0.8476]} {[-2.7737]} {[ 2.6192]} {[ 2.6895]} {[-0.5681]} {[-1.4208]} {[-4.0794]} {[ 6.8263]} +% +% Columns 15 through 21 +% +% {[-3.1836]} {[-1.0828]} {[-3.5680]} {[-4.5238]} {[ -3.5820]} {[ 9.8297]} {[ 9.1477]} +% {[-4.5015]} {[-4.8491]} {[-4.1115]} {[-3.8101]} {[-13.2259]} {[-12.1666]} {[ -9.7015]} +% {[ 4.3357]} {[ 4.0316]} {[ 4.3941]} {[ 1.4003]} {[ 2.6556]} {[ 0.4588]} {[-11.3254]} +% {[-3.0056]} {[ 2.2533]} {[-2.9253]} {[-2.2433]} {[ -3.0114]} {[ 2.4327]} {[ 5.3693]} +% {[-0.5535]} {[-2.5742]} {[-0.1758]} {[ 0.8345]} {[ -0.1398]} {[-13.4085]} {[ 9.8451]} +% {[ 2.6449]} {[-1.8759]} {[ 2.6335]} {[ 2.3418]} {[ 2.6971]} {[-10.3830]} {[ 9.4620]} + +%% +% [parnames, mat2cell(marray(:, [25],end), ones(6,1), ones(1,1))] +% +% ans = +% +% 62 cell array +% +% {'kfdG'} {[-3.9888]} +% {'krdG'} {[-9.9750]} +% {'kcp1'} {[ 1.6081]} +% {'kcp2'} {[-2.8704]} +% {'pol1'} {[ 0.2897]} +% {'pol2'} {[ 2.6442]} + +% the esps we will use are: +% {'kcp2'} {[-2.8704]} +% {'pol2'} {[ 2.6442]} + +% and the CSPfixed esps for that are: +% {'kcp1'} {[ 1.6081]} +% {'pol1'} {[ 0.2897]} + +% The ESPs when the CSPs are not fixed are: +% we can try are: + +% [-3.7404] +% [ 6.0991] +% +% +% [ 3.4331] +% [ 6.4998] +% +% [ 0.4588] +% [-13.4085] +% +% [-11.3254] +% [ 9.8451] +%% +%% +%% Now we perform correction step 2 without CSP fixing, and then with. + +% figure +% % The ESPs we use are +% kcp1 = -3.7404; +% pol1 =3.0991; +% % +% espvec = [ kcp1; pol1]; +% fixparamvec = [log(2); espvec]; +% % +% % % next we simulate the results with the estimated test CSP params and +% % % the non CSP fixing ESPs above. +% % +% % % create a master info +% % +% szm = size(marray); +% mvarray_corr21 = repmat(mai.masterVector, [1, szm(2:end)]) ; +% fixarray = repmat(fixparamvec, [1, szm(2:end)]) ; +% estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +% mvarray_corr21(estParamsIx, :, :) = marray; +% mvarray_corr21(mai.fixedParams, :, :) = fixarray; +% +% samplePoints = ceil(size(mvarray_corr21, 3) * [.9, 1]); +% % +% marrayOrd = mvarray_corr21(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +% titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +% titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +% ms = {'GFP'}; +% for i = 1:length(mi(1).measuredSpeciesIndex) +% for j = 1:length(titls) +% titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; +% titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; +% end +% end +% mcmc_trajectories(mi(1).emo, data_info(4), mi(1), marrayOrd,... +% titls_array, {},... +% 'SimMode', 'meanstd', 'separateExpSim', false,... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'E2'); + +% and plot these. + +%% +% and finally with the CSP fixing ESPs + +% figure +% % The ESPs we use are +% kcp1 = 1.6081; +% pol1 = 0.2897; +% % +% espvec = [ kcp1; pol1]; +% fixparamvec = [log(2); espvec]; +% % +% % % next we simulate the results with the estimated test CSP params and +% % % the non CSP fixing ESPs above. +% % +% % % create a master info +% % +% szm = size(marray); +% mvarray_corr21 = repmat(mai.masterVector, [1, szm(2:end)]) ; +% fixarray = repmat(fixparamvec, [1, szm(2:end)]) ; +% estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +% mvarray_corr21(estParamsIx, :, :) = marray; +% mvarray_corr21(mai.fixedParams, :, :) = fixarray; +% +% samplePoints = ceil(size(mvarray_corr21, 3) * [.9, 1]); +% % +% marrayOrd = mvarray_corr21(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +% titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +% titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +% ms = {'GFP'}; +% for i = 1:length(mi(1).measuredSpeciesIndex) +% for j = 1:length(titls) +% titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; +% titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; +% end +% end +% mcmc_trajectories(mi(1).emo, data_info(4), mi(1), marrayOrd,... +% titls_array, {},... +% 'SimMode', 'meanstd', 'separateExpSim', false,... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'E2'); +% +% +% + + + +%% +%% +%% +%% +%% +%% +%% +% lets try to restrict the test csps to the kfdg and krdg that are +% compatible with the esp1 and esp2. + +% Step 1 : grab C_test 10 points that satisfy both the ESP2 set restricton and the +% CSP-of-calib restrictions. +close all +load('ESP2 points', 'ESP2_tilda') + +% now for 20 points in ESP2_tilda, get the CSP and ESP1, and for those +% CSPs, get the corresponding subset of test csps. +% +% then generate 20 plots of the trajectories from these 20 points. And see +% which fit the data. + + + +ixs_calib = find(ESP2_tilda(:, 4)>-2.875 & ESP2_tilda(:, 4)<-2.865 &... + ESP2_tilda(:, 6)>2.64 & ESP2_tilda(:, 6)<2.65); + +ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +ix_to_use = randperm(length(ESP2_tilda2), 20); + + +% test params: +marray_thin = marray(:, :,1:200:end); +mstacked = marray_thin(:,:)'; +epsilon = .10; +ixs = cell(length(ix_to_use),1); +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +for i = 1:length(ix_to_use) + curr_calib = ESP2_tilda(ix_to_use(i), :); + % find the elements of mstacked that are within the set + kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon]; + kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon]; + ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)-3.02 & ESP2_tilda(:, 4)<-2.72 &... +% ESP2_tilda(:, 6)>2.49 & ESP2_tilda(:, 6)<2.80); +% length(ESP2_tilda2) +% ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +% % % close all +% % % epsi_calib = 0.05 +% % % ixs_calib = find(ESP2_tilda(:, 4)>(rkcp2-epsi_calib) & ESP2_tilda(:, 4)<(rkcp2+epsi_calib) &... +% % % ESP2_tilda(:, 6)>(cpol2-epsi_calib) & ESP2_tilda(:, 6)<(cpol2+epsi_calib)) +% % % +% % % ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +% % % length(ESP2_tilda2) +% % % ix_to_use = randperm(length(ESP2_tilda2), 20); +% % % +% % % % ix_to_use = 1:length(ESP2_tilda2) +% % % +% % % % test params: +% % % marray_thin = marray(:, :,1:20:end); +% % % mstacked = marray_thin(:,:)'; +% % % epsilon = .4; +% % % ixs = cell(length(ix_to_use),1); +% % % estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +% % % count = 0; +% % % for i = 1:length(ix_to_use) +% % % curr_calib = ESP2_tilda(ix_to_use(i), :); +% % % % find the elements of mstacked that are within the set +% % % kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon]; +% % % kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon]; +% % % ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)(rkcp2-epsi_calib) & ESP2_tilda(:, 4)<(rkcp2+epsi_calib) &... +% % ESP2_tilda(:, 6)>(cpol2-epsi_calib) & ESP2_tilda(:, 6)<(cpol2+epsi_calib)) +% +% ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +% length(ESP2_tilda2) +% ix_to_use = randperm(length(ESP2_tilda2), 20); +% +% % ix_to_use = 1:length(ESP2_tilda2) +% +% % test params: +% marray_thin = marray(:, :,1:20:end); +% mstacked = marray_thin(:,:)'; +% epsilon = .5; +% ixs = cell(length(ix_to_use),1); +% estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +% count = 0; +% for i = 1:length(ix_to_use) +% curr_calib = ESP2_tilda(ix_to_use(i), :); +% % find the elements of mstacked that are within the set +% kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon]; +% kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon]; +% ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)(rkcp2-epsi_calib) & CSP_fixed_pts(:, 4)<(rkcp2+epsi_calib) &... + CSP_fixed_pts(:, 6)>(cpol2-epsi_calib) & CSP_fixed_pts(:, 6)<(cpol2+epsi_calib)); + +CSP_fixed_pts2 = CSP_fixed_pts(ixs_calib,:); +length(CSP_fixed_pts2) +ix_to_use = randperm(length(CSP_fixed_pts2), 4); +CSP_fixed_pts2(ix_to_use,:) +% ix_to_use = 1:length(ESP2_tilda2) +%% +% test params: +marray_thin = marray(:, 1:end,1:800:end); +mstacked = marray_thin(:,:)'; +epsilon = 2; +ixs = cell(length(ix_to_use),1); +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +count = 0; +for i = 1:length(ix_to_use) + curr_calib = CSP_fixed_pts2(ix_to_use(i), :) + % find the elements of mstacked that are within the set + kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon] + kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon] + ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2) % RNAse_{cat} -- 7 + % 3.5, 10.75 ---> % RNase -- 9 + % because we do not want to be hitting the boundaries of the parameter + % ranges, there is a biased concentration of points at these + % boundaries. + parRanges = mai.paramRanges; + parRanges([7,9], :) = [-1.863, 1.9;3.5, 10.75] + marray_cut = mcmc_cut(marray, [7, 9], flipud((parRanges([7 9], :))')); + + mcmc_plot(marray_cut(:, 1:end,10000:500:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + + % next we restrict the covarying points to small cartesian squares. + % RNAse_cat (index 7) ---> -0.2966 0.1031 + % RNase (index 9) ---> 8.298 8.738 + parRanges([7,9], :) = [-0.2966 0.1031; 8.298 8.738]; + marray_cut = mcmc_cut(marray, [7,9], flipud((parRanges([7 9], :))')); + + mcmc_plot(marray_cut(:, 1:end,ceil(end/3):10:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + + % next we restrict the covarying points to small cartesian squares. + % RNAse_Kd (index 6) ---> 15.59 15.73 + % RNAse_cat (index 7) ---> -0.2966 0.1031 + % RNase (index 9) ---> 8.385 8.622 + parRanges([6,7, 9], :) = [15.59 15.73 ; + -0.2966 0.1031; + 8.385 8.622]; + marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); + + mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); + mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') + +% an attempt at sequential elimination of covariation. The three parameters +% RNase KD, RNase Cat, and RNase covary mutually. We want to find *a* +% volumme hyper cube within the covarying plane. Ideally of maximized mass, +% but otherwise any volume will do. + +% Looks like RNase Kd (15.59 15.73) and RNAse (8.385 8.622) gives a square, +% but the other two covary: the Kd with the cat, and the cat with the +% rnase. + +% as long as I pick values within the first square, it should stay a +% square. So lets try to squarify the other two. + +% KD vs cat +% Kd: 15.65 15.73 +% cat: -0.1224 0.02126 + +% rnase vs cat +% rnase: 8.386 8.461, +% cat: -0.039 0.022 --> Kd further restricted to ... nope, the KD vs cat +% range is cartesian, so no further restriction needed due to the cat being +% further restricted. +% + +% The intersection of these sets should give us the cube: +% Kd: 15.65 15.73 +% cat: -0.039 0.02126 +% rnase: 8.386 8.461 + +% lets try this. + parRanges([6,7, 9], :) = [15.65 15.73 ; + -0.039 0.02126; + 8.386 8.461 ]; + marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); + + mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + + % nope, I do not get a cube. Need to think about this. I think it is a + % tilted hyperplane in space, and just ntersecting a cube with it is + % not going to give a filled up cube. but even then, its projection + % should be a bunch of squares, no? need to think about it. this is + % very interesting. Think about what happens to a tilted plane when you + % try to intersect a hypercube with it. Also, it is just 3d, can try to + % just plot it in 3d. oh yeah, lol. + +% Actually yeah, see the mcmc_3D plot above, it explains this. + + +%% FINALLY USED VALUES SECTION %%%%% +% Ok, next up, we are going to restrict most parameters to some ranges, and +% then pick parameter values at random from the set of remaining points. +% TX cat: 2.3 2.95 + % RNAse_Kd (index 6) ---> 15.59 15.73 + % RNAse_cat (index 7) ---> -0.2966 0.1031 + % RNase (index 9) ---> 8.385 8.622 + close all + paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; + parRanges(paramIndices, :) = [... + 2.3 2.95; %1 + 8.6 8.95; %2 + -10.1 -9.7; %3 + 13 15; %4 + -1 5 ; %5 + 15.59 15.73; %6 + -0.2966 0.1031; %7 + 0.7 2.2; %8 pol + 8.385 8.622;%9 RNase + 3.18 3.69; % 10 -- TLcat + -3 13.5;%RiboKd + 2 3;% Ribo term + 3 4.6 ];% Ribo + marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); + + mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); + + + CandidateParams = marray_cut(:,1:100:end,end) +% figure +% [C,lags,ESS]=eacorr(marray(:, :,1:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% +%% +% mvarray = masterVecArray(marray_cut, mai); % instead of marray_cut, +% lets see what trajectories we get with just marray. +% this is because marray_cut is, in some sense, biased because we had +% human-in-the-loop eyeballing. + +% CRITICAL: the arrays can be quite large, and eat up all the ram in the +% computer. For this reason, delete arrays as you no longer need them. + mvarray = masterVecArray(marray(:,:,1:50:end), mai); + clear marray + samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + % + marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); + titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); + ms = {'RNA'}; + for i = 1:length(mi(1).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; + end + end +% mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +% titls_array, {},... +% 'SimMode', 'meanstd', 'separateExpSim', true,... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'RNAspike'); + + marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +% clear mvarray + titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); + titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); + ms = {'MG aptamer', 'deGFP'}; + for i = 1:length(mi(2).measuredSpeciesIndex) + for j = 1:length(titls) + titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; + titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; + end + end + +% mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +% titls_array, {},... +% 'SimMode', 'meanstd', 'separateExpSim', true,... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave,... +% 'extrafignamestring', 'MGa_deGFP'); +end +% marrayOrd(:,1:5,end) +clear marrayOrd +% flagz = ones(26, 1); +% flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +% [mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] + +%% remake the trajectory plots so that they are 1. collated and 2. less broad. +% same type of code as analysis_ZSIFFL_training_fullE.m + + +% resimulate, +% ms = {{'protein deGFP*'}}; +for miID = 1:length(mi) + + currmi = mi(miID); + ms = currmi.measuredSpecies; + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, currmi.measuredSpecies); +end +%% + + +ylims = [1000 50 12000]; + +% here, each of the two mi have different length data. +% the first mi is the spike in rna +% the second mi is the mrna and gfp expression +lengthToPlotArray = [21, 76, 76]; + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.6]); + miToUse = [1 2 2]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) + msToPlot = [1 1 2]; + timeinterval = [6 8 8]; + % + titleArray = {'RNA deg'; + 'mRNA expression'; + 'deGFP expression'}; + legLoc = {'NorthEast','NorthEast','NorthWest'}; + + legends = [{fliplr({'1000nM', '800nM', '600nM', '200nM', '75nM', '37.5nM'})}; + {{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; + dosesToPlot = {{[1 2 4 5 7 9]} + {[1 2 3 4]} + {[1 2 3 4]}}; + + % clear marray + yLab = {'RNA, nM', 'RNA, nM', 'deGFP, nM'} + + + for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + subplot(3, 2, (count-1)*2+1) + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(currdi.dataArray(1:lengthToPlot, msToPlot(count), 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + title([titleArray{count} ' (Exp)']) + ylabel(yLab{count}, 'FontSize', 14) + axis([0 (lengthToPlot-1)*timeinterval(count), 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + subplot(3, 2, (count-1)*2+2) + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + hold on + end + title([titleArray{count} ' (Fit)']) + + legend(legends{count, :}, 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + +% print([saveFinalFigs 'vnprl_F2_traj_' num2str((lengthToPlot-1)*8) 'min'],'-depsc') +% print([saveFinalFigs 'vnprl_F2_traj_' num2str((lengthToPlot-1)*8) 'min'],'-djpeg') +% +% print([saveFinalFigs 'vnprl_F2_traj_' num2str((lengthToPlot-1)*8) 'min'],'-dpng') + +% end + +%% redo the plot in the previous cell, but with shading of the standard deviation +% the experimental data is actually from Dan Gaskins and Zoltan Tuza's +% paper. + +% The data is stored in the directory +% mcmc_simbio/exp_data/public_data/ +% and the code is in the file all_data_compare.m +% We adapt the code + + + % code we will use is: + [linehandle, ptchhandle] =... + boundedline(tv, summst(:,msi,1, dosei),... + spreadst(:,msi,1, dosei)); + set(ptchhandle, ... + 'FaceColor', p.SpreadColor,... + 'FaceAlpha', p.FaceAlpha); + set(linehandle, ... + 'Color', p.LineColor,... + 'LineStyle', p.LineStyle,... + 'LineWidth', p.LineWidth); + hold on + + + +ylims = [1000 50 12000]; + +% here, each of the two mi have different length data. +% the first mi is the spike in rna +% the second mi is the mrna and gfp expression +lengthToPlotArray = [21, 76, 76]; + + figure + ss = get(0, 'screensize'); + set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3.5 ss(4)/1.6]); + miToUse = [1 2 2]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) + msToPlot = [1 1 2]; + timeinterval = [6 8 8]; + % + titleArray = {'RNA deg'; + 'mRNA expression'; + 'deGFP expression'}; + legLoc = {'NorthEast','NorthEast','NorthWest'}; + + legends = [{fliplr({'1000nM', '800nM', '600nM', '200nM', '75nM', '37.5nM'})}; + {{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; + dosesToPlot = {{[1 2 4 5 7 9]} + {[1 2 3 4]} + {[1 2 3 4]}}; + + % clear marray + yLab = {'RNA, nM', 'RNA, nM', 'deGFP, nM'} + + + for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + subplot(3, 2, (count-1)*2+1) + for dID = dosesToPlot{count}{:} + + [linehandle, ptchhandle] = ... + boundedline(tv(1:lengthToPlot)/60, summst(:,msi,1, dosei),... + spreadst(:,msi,1, dosei)); + + plot(tv(1:lengthToPlot)/60, ... + mean(currdi.dataArray(1:lengthToPlot, msToPlot(count), 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + [linehandle, ptchhandle] =... + boundedline(tv, summst(:,msi,1, dosei),... + spreadst(:,msi,1, dosei)); + + + title([titleArray{count} ' (Exp)']) + ylabel(yLab{count}, 'FontSize', 14) + axis([0 (lengthToPlot-1)*timeinterval(count), 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + + subplot(3, 2, (count-1)*2+2) + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + hold on + end + title([titleArray{count} ' (Fit)']) + + legend(legends{count, :}, 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; + end + + + +%% find a parameter point that gives good looking fits + +% Reaction Strings + +% [{[ 6.0913]} {'TX_elong_glob' } {'[CUTP:AGTP:RNAP:DNA p70--utr1--deGFP] -> [term_RNAP:DNA p70--utr1--deGFP] + [RNA utr1--deGFP]'} +% {[ 24.4062]} {'TL_elong_glob' } {'[AA:AGTP:Ribo:RNA utr1--deGFP] -> [term_Ribo:RNA utr1--deGFP] + [protein deGFP] + AGMP'} +% {[5.7776e+03]} {'AGTPdeg_time' } {'global'} +% {[ 0.0200]} {'AGTPreg_ON' } {'global'} +% {[4.8661e-05]} {'AGTPdeg_rate' } {'AGTP -> AGMP'} +% {[ 0.0023]} {'TXTL_PROT_deGFP_MATURATION' } {'[protein deGFP] -> [protein deGFP*]'} +% {[ 421.4700]} {'TXTL_UTR_UTR1_Kd' } {''} +% {[ 0.8187]} {'TXTL_UTR_UTR1_F' } +% {[ 462.8714]} {'TXTL_P70_RNAPbound_Kd' } +% {[ 4.4817]} {'TXTL_P70_RNAPbound_F' } +% {[ 20.0374]} {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {[ 19.0278]} {'TXTL_NTP_RNAP_1_Kd' } +% {[ 1]} {'TXTL_NTP_RNAP_1_F' } +% {[1.1990e+06]} {'TXTL_NTP_RNAP_2_Kd' } +% {[ 1]} {'TXTL_NTP_RNAP_2_F' } +% {[ 703.8744]} {'TL_AA_Kd' } +% {[ 0.7408]} {'TL_AA_F' } +% {[2.0007e+06]} {'TL_AGTP_Kd' } +% {[ 0.3012]} {'TL_AGTP_F' } +% {[ 38.2385]} {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {[6.5322e+06]} {'TXTL_RNAdeg_Kd' } +% {[ 1]} {'TXTL_RNAdeg_F' } +% {[ 0.1453]} {'TXTL_RNAdeg_kc' } +% {[ 9.0194]} {'RNAP' } +% {[ 44.3395]} {'Ribo' } +% {[3.2219e+04]} {'RNase' } + + + +% the parameters to set in the model are the parameters in the mcmc_info +% constructor file, then we can use the resulting model with the txtl_plot +% command to generate a prediction. +%% +parvals = struct('paramNames', mi(2).namesOrd,... + 'paramVals', num2cell((marrayOrd(:, end, end))),... + 'reactionString', 'global'... + ); +% simulate model with that parameter point +Mobj = model_dsg2014_regen('plotmode', true, 'initialDNA', 30, 'paramInfo', parvals) +% plot trajectories for that model . + +doseStruct = struct('dosedNames', {{'DNA p70--utr1--deGFP'}}, ... + 'dosedVals', 30); + +mcmc_plot_txtl(Mobj, parvals,doseStruct, ... + 'model_info', mi(2), 'master_info', mai) % there is only a single geometry, so the +% 'which_geometry' argument does not need to be specified. + diff --git a/mcmc_simbio/projects/analysis_vnprl_F2_v2.m b/mcmc_simbio/projects/analysis_vnprl_F2_v2.m new file mode 100755 index 0000000..a95c984 --- /dev/null +++ b/mcmc_simbio/projects/analysis_vnprl_F2_v2.m @@ -0,0 +1,311 @@ +% File: analysis_vnprl_F2_v2.m +% +% Purpose: Plot the VNPRL 2011 + ACS 2014 papers data. +% +% Plot the fits to that data that were performed using mcmc_simbio. +% +% Author: +% Vipul Singhal +% +% The relevant literature for this data is: +% +% 1. Gene Circuit Performance Characterization and Resource Usage in a +% Cell-Free Breadboard, Siegal-Gaskins, et. al +% +% 2. Coarse-Grained Dynamics of Protein Synthesis in a Cell-Free System +% Karzbrun et. al + + +% ----------------------------------------------------------------------- % +% Set data and input directories +% ----------------------------------------------------------------------- % + +% set flags for whether to save the plots generated (default is false -- +% images are large, make sure there is enough RAM / Hard disk space) +jpgsave = false; + +% Set the working directory to be the +txtldir = txtl_init; % txtl_init is in the trunk, so this sets everything +mcmc_init; + +projdir = [pwd '/mcmc_simbio/projects/proj_vnprl']; + +addpath(projdir) + +% this dataset is ~5GB. So worth storing it on an external drive. Change +% the directory below accordingly. +external_drive_where_data_is_stored = '/Volumes/vs_mark1/CALTECH/2020_FEB/proj_vnprl'; +if ~isempty(external_drive_where_data_is_stored) + data_dir = external_drive_where_data_is_stored; + addpath(data_dir) +else + data_dir = projdir; +end + + +% ----------------------------------------------------------------------- % +% Load the models and the data +% ----------------------------------------------------------------------- % + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_vnprl_F2(mobj); +di = data_VNPRL2011; % change this. + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; + +mai = mcmc_info.master_info; + +% plot data from existing simulations. + +ts1 = '20190218_135635_1_24'; +ts2 = '20190218_135635_2_12'; +ts3 = '20190219_093714_1_7'; +ts4 = '20190219_093714_2_2'; +ts5 = '20190220_022918_1_2'; +ts6 = '20190220_102006_1_2'; +ts7 = '20190221_074748_1_2'; +ts8 = '20190223_024333_1_2'; + +tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8}; % +nIterID = {1:25 1:25 1:20 1:20 1:16 1:31 1:80 1:20}; % +load([data_dir '/simdata_' ts8 '/full_variable_set_' ts8 '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + +tsToSave = ts8; +mai.masterVector + +marray_full = mcmc_get_walkers(tstamp,nIterID, data_dir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + + +%% + +% ----------------------------------------------------------------------- % +% Plot the parameter distributions, and Markov chains. +% ----------------------------------------------------------------------- % +mcmc_plot(marray(:, 1:10:end,1:1000:end), parnames(:),... + 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring','WithTransient_jul31'); +%% +mcmc_plot(marray(:, 1:end,(end-10000):4800:end), parnames(:),... + 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'BurnedIn_jul31'); +%% +mcmc_plot(marray(:, 1:end,(end-10000):3000:end), parnames(:),... + 'scatter', false,'ess', 100, 'plotChains', false,... + 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'BurnedIn_kde'); + +%% +% ----------------------------------------------------------------------- % +% Plot the trajectories. +% ----------------------------------------------------------------------- % + +workingDir = [pwd '/mcmc_simbio/exp_data/public_data/']; + +% run merger +%all_data_merger; +load([workingDir 'mergedExperimentFiles.mat']) + +colorCodes = {'r','b','g','c','m','k',[1 1 .5],[.7 .5 .2],[0 1 .2],[.35 .8 .8],[.9 0 .4],[1 .2 .2]}; + +RFUumConvert = 1.723; % (1.723 a.u. = 1 nM) +RFUumConvertMG = 7.75; % (7.75 a.u. = 1 nM) + + +ylims = [1000 50 12000]; +lengthToPlotArray = [21, 76, 76]; + +figure +ss = get(0, 'screensize'); +set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3 ss(4)/1.4]); +miToUse = [1 2 2]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) +msToPlot = [1 1 2]; +timeinterval = [6 8 8]; +% +titleArray = {'RNA deg'; + 'mRNA expression'; + 'deGFP expression'}; +legLoc = {'NorthEast','NorthEast','NorthWest'}; + +legends = [{fliplr({'1000nM', '800nM', '600nM', '200nM', '75nM', '37.5nM'})}; + {{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; +dosesToPlot = {{[1 2 4 5 7 9]} + {[1 2 3 4]} + {[1 2 3 4]}}; + +% clear marray +yLab = {'RNA, nM', 'RNA, nM', 'deGFP, nM'} + + + +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + +% resimulate, +% ms = {{'protein deGFP*'}}; +for miID = 1:length(mi) + + currmi = mi(miID); + ms = currmi.measuredSpecies; + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, currmi.measuredSpecies); +end + +t_vec_mins=mergedExpFile(1).t_vec/60; + +for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + + % experimental data + subplot(3, 2, (count-1)*2+1) + if count == 1 % for the RNA use the data info. + % + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(currdi.dataArray(1:lengthToPlot, msToPlot(count), 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + grid on + title([titleArray{count} ' (Exp)']) + ylabel(yLab{count}, 'FontSize', 14) + axis([0 (lengthToPlot-1)*timeinterval(count), 0 ylims(count)]) + ax = gca; + ax.FontSize = 14; + + elseif count == 2 % for the MG aptamer and the deGFP, use the scripts provided by Zoltan. + %%%%% MG KINETICS WITH CORRECT BACKGROUNDS SUBTRACTED + plotSelect=[ 5, 7, 8, 10]; + mgBackground = mergedExpFile(1).Data_mean(:,1:11,1); + mgNoBgMean=mergedExpFile(1).Data_mean(:,12:22,1)-mgBackground; + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG/10; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG/10; + end +% figure('Name','MG kinetics'); + hold on + % errorbar(repmat(t_vec_mins,1,length(plotSelect)),mgNoBgMean(:,plotSelect),mgNoBgErr(:,plotSelect)); + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + h = stdshade(t_vec_mins, ... + mgNoBgMean(:,plotSelect), ... + mgNoBgErr(:,plotSelect), ... + 0.3, ... + colorzCell); + title([titleArray{count} ' (Exp)']) + %h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,plotSelect+11,1)/RFUumConvertMG,mergedExpFile(1).noBg_std(:,plotSelect+11)/RFUumConvertMG,0.3,colorCodes); + axis([0 (lengthToPlot-1)*timeinterval(count), ... + 0, ... + ylims(count)]) + ylabel('RNA, nM') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', ... + 'pr-gfp-mg15 %0.2g nM')); + %legend(h,legendStr,'Location','NorthEast') + ax = gca; + ax.FontSize = 14; + elseif count == 3 + plotSelect=[5, 7, 8, 10]; +% figure('Name','GFP kinetics'); + hold on + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert/1.8,mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3)/1.8,0.3,colorzCell); + axis([0 (lengthToPlot-1)*timeinterval(count),0,ylims(count)]) + title([titleArray{count} ' (Exp)']) + xlabel('Time [mins]') + ylabel('deGFP (uM)') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', 'pr-gfp-mg15 %0.2g nM')); + ax = gca; + ax.FontSize = 14; + %legend(h,legendStr,'Location','NorthWest') + end + + + % simulation results + subplot(3, 2, (count-1)*2+2) + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + hold on + end + grid on + title([titleArray{count} ' (Fit)']) + + legend(legends{count, :}, 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; +end + + + + + + + + +% ----------------------------------------------------------------------- % + +% ----------------------------------------------------------------------- % \ No newline at end of file diff --git a/mcmc_simbio/projects/analysis_vnprl_F3.m b/mcmc_simbio/projects/analysis_vnprl_F3.m new file mode 100644 index 0000000..898a35b --- /dev/null +++ b/mcmc_simbio/projects/analysis_vnprl_F3.m @@ -0,0 +1,382 @@ +% File: analysis_vnprl_F3.m +% +% Purpose: Plot the VNPRL 2011 + ACS 2014 papers data. +% +% Plot the fits to that data that were performed using mcmc_simbio. +% +% Author: +% Vipul Singhal +% California Institute of Technology +% +% The relevant literature for this data is: +% +% 1. Gene Circuit Performance Characterization +% and Resource Usage in a Cell-Free ?Breadboard? +% Siegal-Gaskins, et. al +% +% 2. Coarse-Grained Dynamics of Protein Synthesis in a Cell-Free System +% Karzbrun et. al + +% ----------------------------------------------------------------------- % +% Set data and input directories +% ----------------------------------------------------------------------- % +% Set the working directory to be the +txtldir = txtl_init; % txtl_init is in the trunk, so this sets everything +% nicely as long as you do not move things around. +mcmc_init; + +projdir = './mcmc_simbio/projects/proj_vnprl'; + +addpath(projdir) + +figsave = false; +jpgsave = true; +% ----------------------------------------------------------------------- % +% Load the models and the data +% ----------------------------------------------------------------------- % + +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_vnprl_F3(mobj); +di = data_VNPRL2011; % change this. + +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% plot data from existing simulations. + + +ts1 = '20200420_205718_1_1191'; +ts2 = '20200420_205718_2_476'; +ts3 = '20200420_205718_3_119'; +ts4 = '20200421_112043_1_119'; +ts5 = '20200422_074403_1_71'; +ts6 = '20200422_074403_2_24'; +ts7 = '20200423_165501_1_48'; +ts8 = '20200424_135910_1_48'; % up until here is the old F3. +ts9 = '20200503_231938_1_48';% 130 %this is the first F3 with the union ranges. +ts10 = '20200504_063238_1_95'; % 120 +% ts11 = '20200504_141525_1_286'; +ts12 = '20200506_045247_1_143'; % 90 % this one skips ts11, +% and is continued from ts 10, iter 12 (not the full 14) +% the reason was that anything later as a starting point kept leading the +% MCMC into a parameter set which caused matlab to crash. No idea how or +% why that is possible, given that I have exception handled the +% ill-conditioned cases. +ts13 = '20200506_145656_1_48'; %100 % but only using 8. +ts14 = '20200510_045912_1_95'; +ts15 = '20200510_045912_2_48'; +ts16 = '20200512_192355_1_43'; +ts17 = '20200512_192355_2_38'; +ts18 = '20200513_063545_1_33'; +ts19 = '20200513_063545_2_29'; +ts20 = '20200513_063545_3_24'; +ts21 = '20200513_063545_4_19'; + +% tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11 ts12}; % +% nIterID = {1:10 1:10 1:6 1:40 1:30 1:30 1:40 1:40 1:13 1:13 1:2 1:7};% + +tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts12 ts13 ts14 ts15}; % +tstamp = {ts14 ts15 ts16 ts17 ts18 ts19 ts20 ts21}; % +nIterID = {1:10 1:10 1:6 1:40 1:30 1:30 1:40 1:40 1:13 1:12 1:9 1:8 1:30 1:21};% +nIterID = {1:30 1:21 1:10 1:10 1:15 1:15 1:15 1:15};% +load([projdir '/simdata_' tstamp{end} '/full_variable_set_' tstamp{end} '.mat'], ... + 'mi',... + 'mcmc_info', 'data_info', 'mai', 'ri'); + +tsToSave = tstamp{end}; +mai.masterVector + +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'\delta_{atp}' } + {'pol_{Kd}' } + {'pol_{term}' } + {'RNAse_{Kd}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{term}' } + {'Ribo' }]; + +%% just the troublesome parameter ranges. + close all +mcmc_plot(marray(:, 1:end,(end-600):200:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', true,'fontsize', 12,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'troublesome_ranges'); +%% +selected_params = [1,8,10, 13, 6, 7]; + +%% + +% ----------------------------------------------------------------------- % +% Plot the parameter distributions, and Markov chains. +% ----------------------------------------------------------------------- % +% close all +mcmc_plot(marray(:, 1:100:end,:), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring','WithTransient'); +%% +mcmc_plot(marray(:, 1:end,(end-200):100:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring','small_hypercube_initialization'); +%% + close all +mcmc_plot(marray(:, :,(end-250):50:end), parnames(:),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'BurnedIn'); +%% + close all +mcmc_plot(marray(selected_params, :,(end-250):50:end), parnames(selected_params),... + 'savematlabfig', figsave, 'savejpeg', jpgsave,... + 'plotChains', false,'fontsize', 22,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', 'BurnedIn_smallfont2'); +%% + +for ess = 320:20:500 +mcmc_plot(marray(:, 1:end,(end-800):200:end), parnames(:),... + 'savematlabfig', figsave, 'scatter', false,'ess', ess,... + 'plotChains', false,... + 'savejpeg', jpgsave,... + 'projdir', projdir, 'tstamp', tsToSave, ... + 'extrafignamestring', ['BurnedIn_jul31_ess_' num2str(ess)]); + pause(30) + close all + figure + plot(1:10, 1:10) + close +end + + +%% +% ----------------------------------------------------------------------- % +% Plot the trajectories. +% ----------------------------------------------------------------------- % + +workingDir = [pwd '/mcmc_simbio/exp_data/public_data/']; + +% run merger +%all_data_merger; +load([workingDir 'mergedExperimentFiles.mat']) + +colorCodes = {'r','b','g','c','m','k',[1 1 .5],[.7 .5 .2],[0 1 .2],[.35 .8 .8],[.9 0 .4],[1 .2 .2]}; + +RFUumConvert = 1.723; % (1.723 a.u. = 1 nM) +RFUumConvertMG = 7.75; % (7.75 a.u. = 1 nM) + + +ylims = [1000 50 12000]; +lengthToPlotArray = [21, 76, 76]; + + +% +% ss = get(0, 'screensize'); +% set(gcf, 'Position', [ss(3)*(1-1/1.3) ss(4)*(1-1/1.3) ss(3)/3 ss(4)/1.4]); +miToUse = [1 2 2]; % mi 1 has one plot (RNA) and mi 2 has 2 plots (RNA and protein) +msToPlot = [1 1 2]; +timeinterval = [6 8 8]; +% +titleArray = {'RNA deg'; + 'mRNA expression'; + 'deGFP expression'}; +legLoc = {'NorthEast','NorthEast','NorthWest'}; + +legends = [{fliplr({'1000nM', '800nM', '600nM', '200nM', '75nM', '37.5nM'})}; + {{'0.5nM', '2nM', '5nM', '20nM'}}; + {{'0.5nM', '2nM', '5nM', '20nM'}};]; +dosesToPlot = {{[1 2 4 5 7 9]} + {[1 2 3 4]} + {[1 2 3 4]}}; + +% clear marray +yLab = {'RNA, nM', 'RNA, nM', 'deGFP, nM'} +%% +mvarray = masterVecArray(marray(:,:,(end-300):100:end), mai); + + +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); + +% resimulate, +% ms = {{'protein deGFP*'}}; +for miID = 1:length(mi) + + currmi = mi(miID); + ms = currmi.measuredSpecies; + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); + dose = currmi.dosedVals'; + vi = get(currmi.emo, 'ValueInfo'); + for i = 1:length(vi) + vi(i) + end + currmi.dosedNames + currmi.dosedVals + + dose + + [da{miID}, idxnotused{miID}] = ... + simulatecurves(currmi.emo,marrayOrd(:,:)', 50, dose, tv, currmi.measuredSpecies); +end + +t_vec_mins=mergedExpFile(1).t_vec/60; + + +%% + +figure +set(0,'Units','normalized') +set(gcf,'Units', 'normalized') +set(gcf, 'Position', [0.05, 0.1, 0.4, 0.6]) +for count = 1:length(miToUse) %1:length(mi)%1: + colorz = flipud(parula(max(dosesToPlot{count}{:})+2)); + currmi = mi(miToUse(count)); + currdi = data_info(currmi.dataToMapTo); + tv = currdi.timeVector; + lengthToPlot = lengthToPlotArray(count); + + % experimental data + subplot(3, 2, (count-1)*2+1) + if count == 1 % for the RNA use the data info. + % + for dID = dosesToPlot{count}{:} + plot(tv(1:lengthToPlot)/60,... + mean(currdi.dataArray(1:lengthToPlot, msToPlot(count), 1, dID),3),... + 'LineWidth', 1.5,... + 'Color', colorz(dID+2, :)) + + hold on + end + grid on + title([titleArray{count} ' (Exp)']) + ylabel(yLab{count}, 'FontSize', 14) + axis([0 (lengthToPlot-1)*timeinterval(count), 0 ylims(count)]) + ax = gca; + ax.FontSize = 14; + + elseif count == 2 % for the MG aptamer and the deGFP, use the scripts provided by Zoltan. + %%%%% MG KINETICS WITH CORRECT BACKGROUNDS SUBTRACTED + plotSelect=[ 5, 7, 8, 10]; + mgBackground = mergedExpFile(1).Data_mean(:,1:11,1); + mgNoBgMean=mergedExpFile(1).Data_mean(:,12:22,1)-mgBackground; + for i=1:11 + mgNoBgMean(:,i)=mean([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],2)/RFUumConvertMG/10; + + mgNoBgErr(:,i)=std([ ... + expFile(1).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,12+i,1)-mgBackground(:,i) ... + expFile(2).Data(:,35+i,1)-mgBackground(:,i) ... + ],0,2)/sqrt(3)/RFUumConvertMG/10; + end +% figure('Name','MG kinetics'); + hold on + % errorbar(repmat(t_vec_mins,1,length(plotSelect)),mgNoBgMean(:,plotSelect),mgNoBgErr(:,plotSelect)); + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + + + h = stdshade(t_vec_mins, ... + mgNoBgMean(:,plotSelect), ... + mgNoBgErr(:,plotSelect), ... + 0.3, ... + colorzCell); + title([titleArray{count} ' (Exp)']) + %h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,plotSelect+11,1) +% /RFUumConvertMG,mergedExpFile(1).noBg_std(:,plotSelect+11)/RFUumConvertMG,0.3,colorCodes); + axis([0 (lengthToPlot-1)*timeinterval(count), ... + 0, ... + ylims(count)]) + ylabel('RNA, nM') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', ... + 'pr-gfp-mg15 %0.2g nM')); + %legend(h,legendStr,'Location','NorthEast') + ax = gca; + ax.FontSize = 14; + elseif count == 3 + plotSelect=[5, 7, 8, 10]; +% figure('Name','GFP kinetics'); + hold on + for dID = dosesToPlot{count}{:} + colorzCell{dID} = colorz(dID+2, :); + end + h = stdshade(t_vec_mins,mergedExpFile(1).noBg_mean(:,11+plotSelect,2)/RFUumConvert/1.8,... + mergedExpFile(1).noBg_std(:,11+plotSelect,2)/RFUumConvert/sqrt(3)/1.8,0.3,colorzCell); + axis([0 (lengthToPlot-1)*timeinterval(count),0,ylims(count)]) + title([titleArray{count} ' (Exp)']) + xlabel('Time [mins]') + ylabel('deGFP (uM)') + grid on + legendStr = cellstr(num2str(mergedExpFile(1).concentrations(plotSelect)', 'pr-gfp-mg15 %0.2g nM')); + ax = gca; + ax.FontSize = 14; + %legend(h,legendStr,'Location','NorthWest') + end + + % simulation results + subplot(3, 2, (count-1)*2+2) + + for dID = dosesToPlot{count}{:} + + [linehandle(dID), ptchhandle] =... + boundedline(tv(1:lengthToPlot)/60,... + mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... + std(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID)... + +eps*randn(lengthToPlot, 1, 50), 0,3)); + set(ptchhandle, ... + 'FaceColor', colorz(dID+2, :),... + 'FaceAlpha', 0.25); + set(linehandle(dID), ... + 'Color', colorz(dID+2, :),... + 'LineWidth', 1.5); + +% +% plot(tv(1:lengthToPlot)/60,... +% mean(da{miToUse(count)}(1:lengthToPlot, msToPlot(count), :, dID), 3),... +% 'LineWidth', 1.5,... +% 'Color', colorz(dID+2, :)) + hold on + end + grid on + title([titleArray{count} ' (Fit)']) + + legend(linehandle(dosesToPlot{count}{:}), legends{count, :},... + 'Location', legLoc{count}, 'FontSize', 14) + legend('boxoff') + axis([0 (lengthToPlot-1)*timeinterval(count) 0 ylims(count)]) + if count ==length(miToUse) + xlabel('time, minutes', 'FontSize', 14) + end + ax = gca; + ax.FontSize = 14; +end + + + + + + + + +% ----------------------------------------------------------------------- % + +% ----------------------------------------------------------------------- % \ No newline at end of file diff --git a/mcmc_simbio/projects/explore_acs_dsg2014_regen_A.m b/mcmc_simbio/projects/explore_acs_dsg2014_regen_A.m new file mode 100755 index 0000000..007f441 --- /dev/null +++ b/mcmc_simbio/projects/explore_acs_dsg2014_regen_A.m @@ -0,0 +1,101 @@ +% Explore all the data collected on AWS (m5, c5 instances, usually 4x, +% 12x and 24x large) and on the local machine (Mac Book Pro, mid 2015, +% quad core 15 inch, academic individual license) + +%% Sim set 1: 24 core machine (m5.12xlarge) +% Explore the simulations from the 24 core machine, where we used 3200 +% walkers. +tstamptouse1 = '10pct_20190203_173126'; +tstamptouse2 = 'pt1pct_20190203_173126'; +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_A']; +marray = mcmc_get_walkers({tstamptouse1, tstamptouse2}, {1:16, 1:13}, projdir); + +msubsamp = marray(:, 1:100:end, :); +% +% load([projdir... +% '/simdata_' tstamptouse1 '/full_variable_set_' tstamptouse1], 'mi',... +% 'mcmc_info', 'data_info', 'mai', 'ri') +% +% plot the trace plots +parnames = ... + [{'TX_{cat}' } + {'\tau_{atp}' } + {'pol_{Kd}' } + {'pol_{kf}' } + {'pol_{term}' } + {'n_{Kd1}' } + {'n_{kf1}' } + {'n_{Kd2}' } + {'n_{kf2}' } + {'RNAse_{Kd}' } + {'RNAse_{kf}' } + {'RNAse_{cat}' } + {'pol' } + {'RNase' } + {'TL_{cat}' } + {'Ribo_{Kd}' } + {'Ribo_{kf}' } + {'aa_{Kd}' } + {'aa_{kf}' } + {'TL_n_{Kd}' } + {'TL_n_{kf}' } + {'Ribo_{term}' } + {'Ribo' }]; + +%% +mcmc_plot(msubsamp(1:10, :,:), parnames(1:10),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', ['20190203_173126']); + +%% +mfinal = marray(:,1:10:end,(end-20):end); +mfinal = mfinal(:,:)'; +%% +mcmc_plot(mfinal(:,1:10), parnames(1:10),... + 'savematlabfig', false, 'savejpeg', false,... + 'projdir', projdir, 'tstamp', ['20190203_173126']); + +% plot the autocorrelation plot + + +% plot the corner plot + +% plot the trajectory fits. + + + + + + + + + + + + + + +%% Sim set 2: 48 core machine (m5.24xlarge) + +tstamptouse = tstamp_appended; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +mcmc_plot(marray([1 2 4], :,:), mai.estNames([1 2 4]),... + 'savematlabfig', false, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse); + +titls = {}; +lgds = {}; +mvarray = masterVecArray(marray, mai); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,:); +mcmc_trajectories(mi(1).emo, di(mi(2).dataToMapTo), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'meanstd', 'savematlabfig', false, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse); + +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,:); +titls = {}; +mcmc_trajectories(mi(2).emo, di(mi(2).dataToMapTo), mi(2), marrayOrd,... + titls, lgds,... + 'SimMode', 'meanstd', 'savematlabfig', false, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse); + diff --git a/mcmc_simbio/projects/proj_VNPRL_mrna.m b/mcmc_simbio/projects/proj_VNPRL_mrna.m new file mode 100755 index 0000000..474f3ef --- /dev/null +++ b/mcmc_simbio/projects/proj_VNPRL_mrna.m @@ -0,0 +1,150 @@ +%% proj_VNPRL_mrna.m +% Fitting +% +% We set up the estimation of the data from the PRL paper: +% Karzbrun, Eyal, Jonghyeon Shin, Roy H. Bar-Ziv, and Vincent Noireaux. +% "Coarse-Grained Dynamics of Protein Synthesis in a Cell-Free System." +% Physical Review Letters 106, no. 4 (January 24, 2011): 48104. +% https://doi.org/10.1103/PhysRevLett.106.048104. +% +% Some of the main conclusions of that paper were: +% - Transcriptional Elongation rate: 1 ntp/s +% - Translational Elongation rate: >4 aa/s +% - mRNA exponential decay, even when purified RNA is in excess of 200nM +% - mRNA degradation half life: 10 - 14 min +% - 30nM RNAP conc +% - 1.5nM RNAP - promoter Kd +% - Protein production linear in mRNA (TL machinery not saturated) +% - 1uM protein in 1h, And anywhere between 3 to 10 uM by the end (5 ish +% hours) +% - dp/dt|max is about 30 to 40 nM / min for proteins +% - For 30 nM of DNA, mRNA steady state is 20 - 30 nM. +% +% This mcmc has two linked estimation problems: +% 1) transcription estimation +% 2) RNA degradation +% +% We rescale the mRNA data from the paper titled: +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, +% to make it compatible with the conclusions of the PRL paper (30nM peak +% mRNA expression), and use this rescaled data as the data to fit our models to. +% In this sense, the ACS paper serves to give a "typical" shape of mRNA expression +% and acts as a rough guide to estimate parameters for TXTL. +% +% Vipul Singhal, California Institute of Technology +% 2018 + + + +%% initialize the directory where things are stored. +[tstamp, projdir, st] = project_init; +% data_init + +%% data_info struct. +di = data_VNPRL2011; +da1 = squeeze(di(1).dataArray); +da2 = squeeze(di(2).dataArray); +ntrej = 30; +figure + +subplot(2, 2,2) % MGa +tv1hrs = di(1).timeVector(1:end-ntrej)/3600; +mga1 = squeeze(da1(1:end-ntrej,1,:)); +plot(tv1hrs, mga1); +xlabel('hours') +ylabel('MGa, nM') +title('MG aptamer/10, ACS DSG 2014') + +subplot(2, 2,1) % dgfp post interp +dgfp1 = diff(squeeze(da1(1:end-ntrej+1,2,:)))... + ./... + diff(di(1).timeVector(1:end-ntrej+1)); +plot(tv1hrs,dgfp1); +xlabel('hours') +ylabel('dgfp/dt, nM/s') +title('dgfp/dt, post interpolation') + +subplot(2, 2,3) % dgfp pre interp +tv2hrs = di(2).timeVector(1:end-ntrej)/3600; +dgfp2 = da2((1:end-ntrej),:); + +plot(tv2hrs,dgfp2); +xlabel('hours') +ylabel('dgfp/dt, nM/s') +title('dgfp/dt, pre interpolation') + + +subplot(2, 2,4) % gfp +gfp = squeeze(da1(1:end-ntrej,2,:)); +plot(tv2hrs, gfp); +xlabel('hours') +ylabel('GFP, nM') +title('GFP/1.8, ACS DSG 2014') + +close all +%% repopulate the data info structs' data array and time vector with these +% truncated-in-time data sets. (truncated to show only the data before 10 +% hours) +da1 = di(1).dataArray; +da2 = di(2).dataArray; +tv1 = di(1).timeVector; +tv2 = di(2).timeVector; + +ix1 = tv1<10*3600; +tv1 = tv1(ix1); +da1 = da1(ix1, :, :, :); +di(1).dataArray = da1; +di(1).timeVector = tv1; + +ix2 = tv2<10*3600; +tv2 = tv2(ix2); +da2 = da2(ix2, :, :, :); +di(2).dataArray = da2; +di(2).timeVector = tv2; + + +%% construct simbiology model object, and simulate with parameters +% to bring it close to what is expected from the PRL paper. + +% define a parameter info struct + + + + + +mobj = model_dsg2014; % use the same model as dsg2014. (this is just +% the basic constitutive production model) + + + + +%% %% setup the mcmc_info struct - capture all the mcmc information +% except the data and the model. +mcmc_info = mcmc_info_vnprl2011_mrna(mobj); +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% set up the MCMC estimation +% mcmc20180225_220513_ID3 + marray = mcmc_get_walkers({'20180225_220513'}, {3}, projdir); +% marray_cut = mcmc_cut(marray, (1:10), flipud((mai.paramRanges)')); +% if size(marray_cut, 2) < ri.nW +% error('too few initial points'); +% elseif size(marray_cut, 2) > ri.nW +% marray_cut = marray_cut(:,1:ri.nW, :); +% end +%% + + +mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', marray(:,:,end)); +% 'UserInitialize', marray_cut(:,:,end) +%'InitialDistribution', 'gaussian' 'UserInitialize', marray_cut(:,:,end)); + + + + + + + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_mtet.m b/mcmc_simbio/projects/proj_ZSIFFL_mtet.m new file mode 100755 index 0000000..0fc016f --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_mtet.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_mtet(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 40); +p.addParameter('nPoints', 30*20); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_mtet_phase1_b(mtet); % cange to mcmc_info_ZSIFFL_mtet_phase1 for the original. + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_mtet_phase2.m b/mcmc_simbio/projects/proj_ZSIFFL_mtet_phase2.m new file mode 100755 index 0000000..b044323 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_mtet_phase2.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_mtet_phase2(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 40); +p.addParameter('nPoints', 30*20); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlac = model_txtl_pLacdeGFP; +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_mtet_phase2(mtet, mlac); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_predictionA.m b/mcmc_simbio/projects/proj_ZSIFFL_predictionA.m new file mode 100755 index 0000000..3ee120f --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_predictionA.m @@ -0,0 +1,405 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_predictionA(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*60); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mIFFL = model_txtl_lastetIFFL; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_predictionA(mIFFL); +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = ZachIFFL_testdata; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_predictionA_F_v4.m b/mcmc_simbio/projects/proj_ZSIFFL_predictionA_F_v4.m new file mode 100644 index 0000000..bd3553f --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_predictionA_F_v4.m @@ -0,0 +1,405 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_predictionA_F_v4(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 20); +p.addParameter('nPoints', 20*20); +p.addParameter('thinning', 1); +p.addParameter('nIter', 1); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mIFFL = model_txtl_lastetIFFL; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_predictionA_F_v4(mIFFL); +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = ZachIFFL_testdata; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_predictionCv3.m b/mcmc_simbio/projects/proj_ZSIFFL_predictionCv3.m new file mode 100644 index 0000000..7da96e1 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_predictionCv3.m @@ -0,0 +1,405 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_predictionCv3(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.1); +p.addParameter('nW', 40); +p.addParameter('nPoints', 40*30); +p.addParameter('thinning', 2); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mIFFL = model_txtl_lastetIFFL; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_predictionCv3(mIFFL); +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = ZachIFFL_testdata; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_training.m b/mcmc_simbio/projects/proj_ZSIFFL_training.m new file mode 100755 index 0000000..0bdd4d5 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_training.m @@ -0,0 +1,414 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_training(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_full(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingB.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingB.m new file mode 100755 index 0000000..81ef207 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingB.m @@ -0,0 +1,414 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingB(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullB(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingC.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingC.m new file mode 100755 index 0000000..23b28e2 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingC.m @@ -0,0 +1,414 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingC(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v2.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v2.m new file mode 100644 index 0000000..a53caae --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v2.m @@ -0,0 +1,414 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingC_v2(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v2(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v3.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v3.m new file mode 100644 index 0000000..de511ba --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v3.m @@ -0,0 +1,453 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingC_v3(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('pausemode', true); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v3(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.001, 0.0001, 0.00001] + percentLadder = {'_pt1pct', '_pt01pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v4.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v4.m new file mode 100644 index 0000000..4538617 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v4.m @@ -0,0 +1,453 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingC_v4(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('pausemode', true); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v4(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.001, 0.0001, 0.00001] + percentLadder = {'_pt1pct', '_pt01pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v5.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v5.m new file mode 100644 index 0000000..b87b431 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v5.m @@ -0,0 +1,453 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingC_v5(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('pausemode', true); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v5(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.001, 0.0001, 0.00001] + percentLadder = {'_pt1pct', '_pt01pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v6.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v6.m new file mode 100644 index 0000000..35c0748 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingC_v6.m @@ -0,0 +1,453 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingC_v6(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('pausemode', true); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullC_v6(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.001, 0.0001, 0.00001] + percentLadder = {'_pt1pct', '_pt01pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '\simdata_' p.prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '\simdata_' prevtstamp]; + SS = load([specificprojdir '\full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingD.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingD.m new file mode 100755 index 0000000..b0d3698 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingD.m @@ -0,0 +1,414 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingD(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullD(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingD_v2.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingD_v2.m new file mode 100644 index 0000000..689a42e --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingD_v2.m @@ -0,0 +1,414 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingD_v2(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullD_v2(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingE.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingE.m new file mode 100755 index 0000000..3a83ceb --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingE.m @@ -0,0 +1,414 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingE(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullE(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingE_v2.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingE_v2.m new file mode 100644 index 0000000..1cbee16 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingE_v2.m @@ -0,0 +1,414 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingE_v2(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullE_v2(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingF.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingF.m new file mode 100644 index 0000000..9509841 --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingF.m @@ -0,0 +1,423 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingF(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', [2]); +p.addParameter('multiplier', 1); +p.addParameter('pausemode', false); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v2.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v2.m new file mode 100644 index 0000000..527dd0f --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v2.m @@ -0,0 +1,423 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingF_v2(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', [2]); +p.addParameter('multiplier', 1); +p.addParameter('pausemode', false); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF_v2(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v3.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v3.m new file mode 100644 index 0000000..c120c4e --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v3.m @@ -0,0 +1,423 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingF_v3(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', [2]); +p.addParameter('multiplier', 1); +p.addParameter('pausemode', false); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF_v3(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v4.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v4.m new file mode 100644 index 0000000..8a7cf2e --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v4.m @@ -0,0 +1,423 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingF_v4(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', [2]); +p.addParameter('multiplier', 1); +p.addParameter('pausemode', false); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF_v4(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v5.m b/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v5.m new file mode 100644 index 0000000..be0772b --- /dev/null +++ b/mcmc_simbio/projects/proj_ZSIFFL_trainingF_v5.m @@ -0,0 +1,423 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_ZSIFFL_trainingF_v5(varargin) +% data collected by Zach Sun and Shaobin Guo. +% Vipul Singhal, +% California Institute of Technology +% 2019 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.4); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', [2]); +p.addParameter('multiplier', 1); +p.addParameter('pausemode', false); +p.addParameter('stepLadder', linspace(1.1, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mlac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_training_fullF_v5(mtet, mlac, mlas); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_ZSIFFL; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'pausemode', p.pausemode,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'pausemode', p.pausemode,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_A.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_A.m new file mode 100755 index 0000000..c762adf --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_A.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_A(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_A(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_A1.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_A1.m new file mode 100755 index 0000000..4a1b54e --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_A1.m @@ -0,0 +1,419 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_A1(varargin) +% expanded parameter ranges +% +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_A1(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_C.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_C.m new file mode 100755 index 0000000..dc6e8a6 --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_C.m @@ -0,0 +1,386 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_C(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, +% +% This file differs from proj_acs_dsg2014_regen_A in that the forward rate +% parameters are all fixed. + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(1.5, 1, 3), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. + +p.addParameter('temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_C('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_C('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_C(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) + if ~p.temperatureLadder + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp); + end + else + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'10pct_', 'pt1pct_', 'pt001pct_'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [percentLadder{ll} '_' tstamp]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp); + end + else +% prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + % + + + end + end +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tLaddStr '_' tstamp]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_C('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_C('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_C('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_C('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*50,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_C1.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_C1.m new file mode 100755 index 0000000..3eeb4fb --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_C1.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_C1(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_C1(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_D.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_D.m new file mode 100755 index 0000000..4595535 --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_D.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_D(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_D(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_E.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_E.m new file mode 100755 index 0000000..e098271 --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_E.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_E(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_E(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_F.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_F.m new file mode 100755 index 0000000..d23cfdc --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_F.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_F(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_F(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_F1.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_F1.m new file mode 100755 index 0000000..c4b1a37 --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_F1.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_F1(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_F1(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_G.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_G.m new file mode 100755 index 0000000..a1b4985 --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_G.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_G(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_G(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_H.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_H.m new file mode 100755 index 0000000..f133683 --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_H.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_H(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_H(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_acs_dsg2014_regen_I.m b/mcmc_simbio/projects/proj_acs_dsg2014_regen_I.m new file mode 100755 index 0000000..7b14013 --- /dev/null +++ b/mcmc_simbio/projects/proj_acs_dsg2014_regen_I.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_I(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_I(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_mcmc_tutorial.m b/mcmc_simbio/projects/proj_mcmc_tutorial.m new file mode 100755 index 0000000..103c425 --- /dev/null +++ b/mcmc_simbio/projects/proj_mcmc_tutorial.m @@ -0,0 +1,121 @@ +%% First tutorial file for the mcmc_simbio package +% proj_mcmc_tutorial.m - Basic toturial of the mcmc_simbio package +% demonstrating the estimation of parameters for a constitutive gene +% expression circuit modeled as a single enzymatic reaction. + +%% Initializing the toolbox +% If you have not already initialized the txtlsim and mcmc_simbio +% toolboxes, initialize them by running the txtl_init and mcmc_init +% commands in the command line. You need your working directory to be the +% main directory where the txtlsim toolbox is stored (i.e., the directory +% in which directories like core, components, mcmc_simbio etc are stored). + +%% Run project_init +% This creates a directory within the projects directory where +% the results of the simulation will be stored. The name of the directory +% will be the same as the name of this file (proj_mcmc_tutorial, in this +% case). it also creates a timestamped subdirectory within this directory, +% where the actual results are stored. If the top level directory +% (proj_mcmc_tutorial) already exists, then only the subdirectory is +% created. +[tstamp, projdir, st] = project_init; + +%% Define the MATLAB Simbiology model +% We use the file model_protein3.m to define a constitutive gene expression +% model using a single enzymatic step. The reactions and species that it +% sets up are: +% +% dG + pol <-> dG_pol (k_f, k_r) +% dG_pol -> dG + pol + pG (kc) +mobj = model_protein3; + +% The species of the model can be visualized as follows: +mobj.species + +% The reactions may be visualized as +mobj.reactions +% For more on MATLAB Simbiology, see the Simbiology +% page. + +%% Defining the experiment / model arrangement. +% We can define the experimental setup and how it related to data, the +% Simbiology model and the estimation problem using what we call an +% mcmc_info struct. For this example, we will be using an +% mcmc_info_constgfp3i.m file to generate the mcmc_info struct that we need +% to define our parameter inference problem. +% Please enter 'help mcmc_info' into the command window prompt to read more +% about this struct. Also, open the mcmc_info_constgfp3i file (edit +% mcmc_info_constgfp3i) to view how it is set up. + +mcmc_info = mcmc_info_constgfp3i(mobj); + +%% Creating artificial data to fit the model to. +% Instead of using real data, we will create artificial data for +% demonstration purposes. We will use the data_artificial_v2 fucntion to do +% this. + +% Get the model_info struct needed to generate the artificial data +mi = mcmc_info.model_info; + +% A list of nominal parameter values to use to generate the data. +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkcp1 = 0.012; %s-1 +cpol1 = 100; % nM + +% Arrange the parameters in a log transformed vector. +masterVector = log([rkfdG + rkrdG + rkcp1 + cpol1]); + +% Supply the experimental setup information to the data_artificial_v2 +% function so that it can generate the data_info struct that contains the +% artificial data. +% type 'help data_artificial_v2' into the command window prompt to read +% more about this function. For our purposes we simply note that we need to +% specify our Simbiology model object, a set of timepoints to report the +% output trajectories for, the list of measured species' names for our +% model, the list of dosed species' names, the matrix of dosed values, the +% names of the species and parameters to set values for in the model +% (namesUnord), and the non-log-transformed values as a vector. All of +% these arguments must be encapsulated in cells. + +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies}, ... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector), [exp(masterVector(1:end-2)); 0.024; 200]}); + +da_extract1 = di(1).dataArray; +tv = di(1).timeVector; + +%% Plot the artificial data +% we can plot the data using the mcmc_trajectories function. See its help +% file for usage information. +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); + +%% Run the MCMC +ri = mcmc_info.runsim_info; + +mai = mcmc_info.master_info; + +mi1 = mcmc_runsim_v2(tstamp, projdir, di(1), mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', 2); % 'InitialDistribution', 'gaussian' + +%% plot stuff +tstamptouse = tstamp; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +mcmc_plot(marray, mai.estNames, 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse); +titls = {'dna 10'; 'dna 30';'dna 60'}; +lgds = {}; +mvarray1 = masterVecArray(marray, mai); +marrayOrd = mvarray1(mi1.paramMaps(mi1.orderingIx, 1),:,:); +fhandle = mcmc_trajectories(mi1.emo, di(1), mi1, marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse); + + +% Vipul Singhal, +% California Institute of Technology +% 2018 diff --git a/mcmc_simbio/projects/proj_mcmc_tutorial_II.m b/mcmc_simbio/projects/proj_mcmc_tutorial_II.m new file mode 100755 index 0000000..6280f21 --- /dev/null +++ b/mcmc_simbio/projects/proj_mcmc_tutorial_II.m @@ -0,0 +1,203 @@ +%% Second tutorial for the mcmc_simbio package +% proj_mcmc_tutorial_II.m - tutorial of the mcmc_simbio package +% demonstrating the estimation of parameters for a constitutive gene +% expression circuit modeled as a single enzymatic reaction. In this +% example, we demonstrate the concurrent parameter +% estimation capability, where we have the constitutive expression circuit +% in two environments, with each environment having its own environment +% specific parameters (ESPs), while the circuit having a single set of +% circuit specific parameters. + +%% Initializing the toolbox +% If you have not already initialized the txtlsim and mcmc_simbio +% toolboxes, initialize them by running the txtl_init and mcmc_init +% commands in the command line. You need your working directory to be the +% main directory where the txtlsim toolbox is stored (i.e., the directory +% in which directories like core, components, mcmc_simbio etc are stored). + +%% Run project_init +% This creates a directory within the projects directory where +% the results of the simulation will be stored. The name of the directory +% will be the same as the name of this file (proj_mcmc_tutorial_II, in this +% case). it also creates a timestamped subdirectory within this directory, +% where the actual results are stored. If the top level directory +% (proj_mcmc_tutorial_II) already exists, then only the subdirectory is +% created. +delete(gcp('nocreate')) +parpool(47) +[tstamp, projdir, st] = project_init; +prevtstamp = '20190131_181526' +%% Define the MATLAB Simbiology model +% We use the file model_protein3.m to define a constitutive gene expression +% model using a single enzymatic step. The reactions and species that it +% sets up are: +% +% dG + pol <-> dG_pol (k_f, k_r) +% dG_pol -> dG + pol + pG (kc) + +mobj = model_protein3; + +% The species of the model can be visualized as follows: +mobj.species + +% The reactions may be visualized as +mobj.reactions +% For more on MATLAB Simbiology, see the Simbiology +% page. + +%% Defining the experiment / model arrangement. +% We can define the experimental setup and how it related to data, the +% Simbiology model and the estimation problem using what we call an +% mcmc_info struct. For this example, we will be using an +% mcmc_info_constgfp3ii.m file to generate the mcmc_info struct that we need +% to define our parameter inference problem. +% Please enter 'help mcmc_info' into the command window prompt to read more +% about this struct. Also, open the mcmc_info_constgfp3ii file (enter 'edit +% mcmc_info_constgfp3ii' into the command prompt) to learn how it is set up. + +mcmc_info = mcmc_info_constgfp3ii(mobj); + +%% Creating artificial data to fit the model to. +% Instead of using real data, we will create artificial data for +% demonstration purposes. We will use the data_artificial_v2 fucntion to do +% this. + +% Get the model_info struct needed to generate the artificial data +mi = mcmc_info.model_info; + +% A list of nominal parameter values to use to generate the data. +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkcp1 = 0.012; %s-1 +rkcp2 = 0.024; %s-1 +cpol1 = 100; % nM +cpol2 = 200; % nM + +% Arrange the parameters in a log transformed vector. +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% Supply the experimental setup information to the data_artificial_v2 +% function so that it can generate the data_info struct that contains the +% artificial data. +% type 'help data_artificial_v2' into the command window prompt to read +% more about this function. For our purposes we simply note that we need to +% specify our Simbiology model object, a set of timepoints to report the +% output trajectories for, the list of measured species' names for our +% model, the list of dosed species' names, the matrix of dosed values, the +% names of the species and parameters to set values for in the model +% (namesUnord), and the non-log-transformed values as a vector. All of +% these arguments must be encapsulated in cells. + +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies},... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector([1:2 3 5])), exp(masterVector([1:2 4 6]))}); + + +da_extract1 = di(1).dataArray; +da_extract2 = di(2).dataArray; +tv = di(1).timeVector; + +%% Plot the artificial data +% we can plot the data using the mcmc_trajectories function. See its help +% file for usage information. +%mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); + +%% Run the MCMC +ri = mcmc_info.runsim_info; + +mai = mcmc_info.master_info; + + +specificprojdir = [projdir '/simdata_' prevtstamp]; + +% load mcmc_info and the updated model_info +SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + +marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); +% assume the projdir where this data is stored is the same one as the +% one created at the start of this file + +%% +pID = 1:length(mai.estNames); +marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); +if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); +else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); +end + +%% + +% now run the simulation. + +mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false); +% +% mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... +% 'InitialDistribution', 'LHS', 'multiplier', 2,... +% 'pausemode', false); +% 'InitialDistribution', 'gaussian' +% 'UserInitialize', marray_cut(:,:,end) + +%% plot stuff + + + +% load([pwd '/mcmc_simbio/projects/proj_mcmc_tutorial_II/'... +% 'simdata_20180802_221756/full_variable_set_20180802_221756']) +%% +% projdir = [pwd '/mcmc_simbio/projects/proj_mcmc_tutorial_II'] +% di = data_info +% tstamptouse = tstamp; +% marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +% mcmc_plot(marray([1 2 4], :,:), mai.estNames([1 2 4]),... +% 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse,... +% 'extrafignamestring', '_extract1'); +% % +% figure +% mcmc_plot(marray([1 3 5], :,:), mai.estNames([1 3 5]),... +% 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse,... +% 'extrafignamestring', '_extract2'); +% titls = {'E1 dG 10';'E1 dG 30';'E1 dG 60';}; +% lgds = {}; +% mvarray = masterVecArray(marray, mai); +% marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +% fhandle = mcmc_trajectories(mi(1).emo, di(1), mi(1), marrayOrd,... +% titls, lgds,... +% 'SimMode', 'meanstd', 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... +% '_extract1'); +% marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 2),:,:); +% titls = {'E2 dG 10';'E2 dG 30';'E2 dG 60';}; +% fhandle = mcmc_trajectories(mi(1).emo, di(2), mi(1), marrayOrd,... +% titls, lgds,... +% 'SimMode', 'meanstd', 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... +% '_extract2'); + +% +% load([pwd '/mcmc_simbio/projects/proj_mcmc_tutorial_II/'... +% 'simdata_20190131_181526/full_variable_set_20190131_181526']) +%% + + +% Vipul Singhal, +% California Institute of Technology +% 2018 diff --git a/mcmc_simbio/projects/proj_mcmc_tutorial_III.m b/mcmc_simbio/projects/proj_mcmc_tutorial_III.m new file mode 100755 index 0000000..6fdca89 --- /dev/null +++ b/mcmc_simbio/projects/proj_mcmc_tutorial_III.m @@ -0,0 +1,222 @@ +%% Second tutorial for the mcmc_simbio package +% proj_mcmc_tutorial_III.m - tutorial of the mcmc_simbio package +% demonstrating the estimation of parameters shared between two different +% circuits. In the language of the concurrent parameter inference +% problem (type 'help mcmc_info' into the command prompt window to +% read more), we say that there are two +% network topologies, with each topology having one geometry associated +% with it. +% +% This example demonstrates a slightly more complex example of the +% concurrence feature of the mcmc_simbio Bayesian parameter inference +% toolbox. Here, we have two circuits: the constitutive gene expression +% circuit with model +% +% D + pol <-> D__pol (kfdG, krdG) +% D__pol -> D + pol + protien v(kcp) +% +% and the tetR repression circuit with model +% +% D_T + P <-> D_T:P -> D_T + P + T (kfdT, krdT; kcp) +% D_G + P <-> D_G:P -> D_G + P + G (kfdG, krdG; kcp) +% 2 T <-> T2 (kfdimTet, krdimTet) +% D_G + T2 <-> D_G:T2 (kfseqTet, krseqTet) +% +% Here each model is a different topology with only one +% geometry associated with it. The paramters that are shared +% between the two topologies are: kfdG, krdG, kcp, pol. The remaining +% parameters are specific to the topology-geometry pair they appear in (in +% this case all the remaining parameters appear in the tetR repression +% circuit topology). Furthermore, we set the forward rate parameters in +% all the reversible reaction to be fixed parameters, and therefore only +% estimate the reverse rate parameters. + +%% Initializing the toolbox +% If you have not already initialized the txtlsim and mcmc_simbio +% toolboxes, initialize them by running the txtl_init and mcmc_init +% commands in the command line. You need your working directory to be the +% main directory where the txtlsim toolbox is stored (i.e., the directory +% in which directories like core, components, mcmc_simbio etc are stored). + +%% Run project_init +% This creates a directory within the projects directory where +% the results of the simulation will be stored. The name of the directory +% will be the same as the name of this file (proj_mcmc_tutorial_III, in this +% case). it also creates a timestamped subdirectory within this directory, +% where the actual results are stored. If the top level directory +% (proj_mcmc_tutorial_III) already exists, then only the subdirectory is +% created. + +[tstamp, projdir, st] = project_init; +prevtstamp = '20190201_170033' + + delete(gcp('nocreate')) + parpool(46) +%% Define the MATLAB Simbiology model +% We use the file model_protein3.m to define a constitutive gene expression +% model using a single enzymatic step. +m_constgfp = model_protein3; +m_tetRrep = model_tetR_repression1; + +%% Defining the experiment / model arrangement. +% We can define the experimental setup and how it is related to data, the +% Simbiology model and the estimation problem using what we call an +% mcmc_info struct. For this example, we will be using an +% mcmc_info_constgfp3tetR1.m file to generate the mcmc_info struct that we need +% to define our parameter inference problem. +% Please enter 'help mcmc_info' into the command window prompt to read more +% about this struct. Also, open the mcmc_info_constgfp3tetR1 file (enter 'edit +% mcmc_info_constgfp3tetR1' into the command prompt) to learn how it is set up. +mcmc_info = mcmc_info_constgfp3tetR1(m_constgfp, m_tetRrep); + +%% Creating artificial data to fit the model to. +% Instead of using real data, we will create artificial data for +% demonstration purposes. We will use the data_artificial_v2 fucntion to do +% this. + +% Get the model_info struct needed to generate the artificial data +mi = mcmc_info.model_info; + +% A list of nominal parameter values to use to generate the data. + +cpol = 100; % nM +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkfdT = 5; +rkrdT = 300; +rkcp = 0.012; %s-1 +rkfdimTet = 20; % nM-1s-1 +rkrdimTet = 10; % s-1 +rkfseqTet = 20; % nM-1s-1 +rkrseqTet = 10; % s-1 + +% Arrange the parameters in a log transformed vector. +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); + +% Supply the experimental setup information to the data_artificial_v2 +% function so that it can generate the data_info struct that contains the +% artificial data. +% type 'help data_artificial_v2' into the command window prompt to read +% more about this function. For our purposes we simply note that we need to +% specify our Simbiology model object, a set of timepoints to report the +% output trajectories for, the list of measured species' names for our +% model, the list of dosed species' names, the matrix of dosed values, the +% names of the species and parameters to set values for in the model +% (namesUnord), and the non-log-transformed values as a vector. All of +% these arguments must be encapsulated in cells. + +di = data_artificial_v2(... + {m_constgfp, m_tetRrep},... % the two model objects + {0:180:7200, 0:180:7200},... % time vectors for the two data sets + {mi(1).measuredSpecies, mi(2).measuredSpecies},... + ... % measured species setup in mcmc_info.model_info + {mi(1).dosedNames, mi(2).dosedNames},... % dosed species + {mi(1).dosedVals, mi(2).dosedVals,},... % dosing values + {mi(1).namesUnord, mi(2).namesUnord},... + ... % names of species and parameters to set in each model + {exp(masterVector([1 2 9 10])), exp(masterVector)}); + % values to use for the names in namesUnord. + + +da_constgfp = di(1).dataArray; +da_tetRrep = di(2).dataArray; +tv = di(1).timeVector; + +%% Plot the artificial data +% we can plot the data using the mcmc_trajectories function. See its help +% file for usage information. +%mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); + +%% Run the MCMC +ri = mcmc_info.runsim_info; + +mai = mcmc_info.master_info; + +specificprojdir = [projdir '/simdata_' prevtstamp]; + +% load mcmc_info and the updated model_info +SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + +marray = mcmc_get_walkers({prevtstamp}, ... + {ceil((SS.mcmc_info.runsim_info.nIter)/4):(SS.mcmc_info.runsim_info.nIter)},... + projdir); +% assume the projdir where this data is stored is the same one as the +% one created at the start of this file + +%% +pID = 1:length(mai.estNames); +marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); +if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/4, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); +else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); +end + +%% + +% now run the simulation. +mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false); + +% mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... +% 'InitialDistribution', 'LHS', 'multiplier', 2,... +% 'pausemode', true); + +% 'InitialDistribution', 'gaussian' +% +%% plot stuff +% +% These functions simply generate some standard plots from the data that is +% saved in the timestamped subdirectory of the directory specified in +% projdir. You can open that directory to view the results, including a log +% file. +% +% tstamptouse = tstamp; +% marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +% +% % plot parameter distribution corner plot, and markov chains. +% mcmc_plot(marray, mai.estNames,... +% 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse,... +% 'extrafignamestring', '_tutorialIII'); +% +% % plot individual trajectories of the data and the model fits for both +% % models. +% titls = {'dG 10';'dG 30';'dG 60';}; +% lgds = {}; +% mvarray = masterVecArray(marray, mai); +% marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +% fhandle = mcmc_trajectories(mi(1).emo, di(1), mi(1), marrayOrd,... +% titls, lgds,... +% 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... +% '_contgfp'); +% marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx, 1),:,:); +% titls = {'dG 10 dT 0.1';'dG 30 dT 0.1';'dG 10 dT 2';'dG 30 dT 2';... +% 'dG 10 dT 8';'dG 30 dT 8';}; +% fhandle = mcmc_trajectories(mi(2).emo, di(2), mi(2), marrayOrd,... +% titls, lgds,... +% 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... +% '_tetRrep'); + +% Vipul Singhal, +% California Institute of Technology +% 2018 diff --git a/mcmc_simbio/projects/proj_protein_constgfp3i.m b/mcmc_simbio/projects/proj_protein_constgfp3i.m new file mode 100755 index 0000000..6ea5532 --- /dev/null +++ b/mcmc_simbio/projects/proj_protein_constgfp3i.m @@ -0,0 +1,134 @@ +%% MCMC toolbox demo - proj_protein_constgfp3i.m +% +% const gfp 3, artificial data, separate, 2 extracts. Check if the CSPs line up exactly. +% kf fixed +% Vipul Singhal, +% California Institute of Technology +% 2018 + +%% initialize the directory where things are stored. +% close all +% clear all +% clc +[tstamp1, projdir, st] = project_init; + +%% We first define the model, mcmc_info struct, and the data_info struct. + +mobj = model_protein3; + +mcmc_info = mcmc_info_constgfp3i(mobj); + +mi = mcmc_info.model_info; + +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkcp1 = 0.012; %s-1 +cpol1 = 100; % nM + +masterVector = log([rkfdG + rkrdG + rkcp1 + cpol1]); + +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies}, ... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector), [exp(masterVector(1:end-2)); 0.024; 200]}); + +da_extract1 = di(1).dataArray; +da_extract2 = di(2).dataArray; +tv = di(1).timeVector; + +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); + + +% Run the MCMC +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +% marray = mcmc_get_walkers({'20180311_223247'}, {10}, projdir); +% marray_cut = mcmc_cut(marray, (1:10), flipud((mai.paramRanges)')); +% if size(marray_cut, 2) < ri.nW +% error('too few initial points'); +% elseif size(marray_cut, 2) > ri.nW +% marray_cut = marray_cut(:,1:ri.nW, :); +% end +%% + +mi1 = mcmc_runsim_v2(tstamp1, projdir, di(1), mcmc_info,... + 'InitialDistribution', 'LHS'); % 'InitialDistribution', 'gaussian' +% 'UserInitialize', marray_cut(:,:,end) + +%% plot stuff +tstamptouse = tstamp1; %'20180311_223247'; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +mcmc_plot(marray, mai.estNames, 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse); +% mcmc_plot(marray, mi1.namesUnord,'ks', true, 'scatter', false); +% mcmc_plot(marray, mi1.namesUnord,'transparency', 0.05); +titls = {'dna 10'; 'dna 30';'dna 60'}; +lgds = {}; +mvarray1 = masterVecArray(marray, mai); +marrayOrd = mvarray1(mi1.paramMaps(mi1.orderingIx, 1),:,:); +fhandle = mcmc_trajectories(mi1.emo, di(1), mi1, marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse); +% %% 3D plot +% pToPlot = [2 3 1]; +% labellist = mai.estNames; +% for plotID = 1:size(pToPlot, 1) +% mstacked = marray1(:,:)'; +% figure +% XX = mstacked(1:2:end, [pToPlot(plotID,1)]); +% YY = mstacked(1:2:end, [pToPlot(plotID,2)]); +% ZZ = mstacked(1:2:end, [pToPlot(plotID,3)]); +% scatter3(XX,YY,ZZ) +% xlabel(labellist{pToPlot(plotID,1)}, 'FontSize', 20) +% ylabel(labellist{pToPlot(plotID,2)}, 'FontSize', 20) +% zlabel(labellist{pToPlot(plotID,3)}, 'FontSize', 20) +% title('covariation in Extract 1', 'FontSize', 20) +% saveas(gcf, [projdir '/simdata_' tstamp1 '/3dfig_ext1_' num2str(plotID) '_' tstamp1]); +% end +% +% +% mi2 = mcmc_runsim_v2(tstamp2, projdir, di(2), mcmc_info,... +% 'InitialDistribution', 'LHS'); % 'InitialDistribution', 'gaussian' +% % 'UserInitialize', marray_cut(:,:,end) +% +% %% plot stuff +% tstamptouse = tstamp2; %'20180311_223247'; +% marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +% mcmc_plot(marray, mai.estNames, 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse); +% % mcmc_plot(marray, mi1.namesUnord,'ks', true, 'scatter', false); +% % mcmc_plot(marray, mi1.namesUnord,'transparency', 0.05); +% titls = {'dna 10'; 'dna 30';'dna 60'}; +% lgds = {}; +% mvarray1 = masterVecArray(marray, mai); +% marrayOrd = mvarray2(mi1.paramMaps(mi1.orderingIx, 1),:,:); +% fhandle = mcmc_trajectories(mi2.emo, di(2), mi2, marrayOrd, titls, lgds,... +% 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... +% 'projdir', projdir, 'tstamp', tstamptouse); +% %% 3D plot +% pToPlot = [2 3 1]; +% labellist = mai.estNames; +% for plotID = 1:size(pToPlot, 1) +% mstacked = marray2(:,:)'; +% figure +% XX = mstacked(1:2:end, [pToPlot(plotID,1)]); +% YY = mstacked(1:2:end, [pToPlot(plotID,2)]); +% ZZ = mstacked(1:2:end, [pToPlot(plotID,3)]); +% scatter3(XX,YY,ZZ) +% xlabel(labellist{pToPlot(plotID,1)}, 'FontSize', 20) +% ylabel(labellist{pToPlot(plotID,2)}, 'FontSize', 20) +% zlabel(labellist{pToPlot(plotID,3)}, 'FontSize', 20) +% title('covariation in Extract 2', 'FontSize', 20) +% saveas(gcf, [projdir '/simdata_' tstamptouse '/3dfig_ext2_' num2str(plotID) '_' tstamptouse]); +% end + +% marray = mcmc_get_walkers({'20180311_224651'}, {10}, projdir); +% marray_cut = mcmc_cut(marray, (1:10), flipud((mai.paramRanges)')); +% if size(marray_cut, 2) < ri.nW +% error('too few initial points'); +% elseif size(marray_cut, 2) > ri.nW +% marray_cut = marray_cut(:,1:ri.nW, :); +% end diff --git a/mcmc_simbio/projects/proj_protein_constgfp3ii.m b/mcmc_simbio/projects/proj_protein_constgfp3ii.m new file mode 100755 index 0000000..2af6ff2 --- /dev/null +++ b/mcmc_simbio/projects/proj_protein_constgfp3ii.m @@ -0,0 +1,150 @@ +%% MCMC toolbox demo - proj_protein_constgfp3i.m +% +% const gfp 3, artificial data, separate, 2 extracts. Check if the +% CSPs line up exactly. +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +%% initialize the directory where things are stored. +% close all +% clear all +% clc +[tstamp, projdir, st] = project_init; + +%% We first define the model, mcmc_info struct, and the data_info +% struct. + +mobj = model_protein3; + +mcmc_info = mcmc_info_constgfp3ii(mobj); + +mi = mcmc_info.model_info; + + +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkcp1 = 0.012; %s-1 +rkcp2 = 0.024; %s-1 +cpol1 = 100; % nM +cpol2 = 200; % nM + + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% supply parameter vectors to this function to generate simulated +% data. +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies},... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector([1:2 3 5])), exp(masterVector([1:2 4 6]))}); + +da_extract1 = di(1).dataArray; +da_extract2 = di(2).dataArray; +tv = di(1).timeVector; + +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); + +% Run the MCMC +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +%% +mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS'); + +%% plot stuff +tstamptouse = tstamp; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +mcmc_plot(marray([1 2 4], :,:), mai.estNames([1 2 4]),... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse,... + 'extrafignamestring', '_extract1'); +figure +mcmc_plot(marray([1 3 5], :,:), mai.estNames([1 3 5]),... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse,... + 'extrafignamestring', '_extract2'); +titls = {'E1 dG 10';'E1 dG 30';'E1 dG 60';}; +lgds = {}; +mvarray = masterVecArray(marray, mai); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(1), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... + '_extract1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 2),:,:); +titls = {'E2 dG 10';'E2 dG 30';'E2 dG 60';}; +fhandle = mcmc_trajectories(mi(1).emo, di(2), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... + '_extract2'); + +mstacked = marray(:,:)'; + + + +pToPlot = [ 2 4 1 ;]; +% CSP on the vertical axis to conform to schematics in presentations. + +labellist = mai.estNames; +for plotID = 1:size(pToPlot, 1) + figure + XX = mstacked(1:end, [pToPlot(plotID,1)]); + YY = mstacked(1:end, [pToPlot(plotID,2)]); + ZZ = mstacked(1:end, [pToPlot(plotID,3)]); + scatter3(XX,YY,ZZ) + xlabel(labellist{pToPlot(plotID,1)}, 'FontSize', 20) + ylabel(labellist{pToPlot(plotID,2)}, 'FontSize', 20) + zlabel(labellist{pToPlot(plotID,3)}, 'FontSize', 20) + title('covariation in Extract 1', 'FontSize', 20) + saveas(gcf, [projdir '/simdata_' tstamptouse '/3dfig_ext1_'... + num2str(plotID) '_' tstamptouse]); +end +% +pToPlot = [3 5 1]; +for plotID = 1:size(pToPlot, 1) + figure + XX = mstacked(1:end, [pToPlot(plotID,1)]); + YY = mstacked(1:end, [pToPlot(plotID,2)]); + ZZ = mstacked(1:end, [pToPlot(plotID,3)]); + scatter3(XX,YY,ZZ) + xlabel(labellist{pToPlot(plotID,1)}, 'FontSize', 20) + ylabel(labellist{pToPlot(plotID,2)}, 'FontSize', 20) + zlabel(labellist{pToPlot(plotID,3)}, 'FontSize', 20) + title('covariation in Extract 2', 'FontSize', 20) + saveas(gcf, [projdir '/simdata_' tstamptouse '/3dfig_ext2_'... + num2str(plotID) '_' tstamptouse]); +end + + + + + + + + +titls = {'dna 1'; 'dna 2';'dna 5'}; +lgds = {}; +mvarray = masterVecArray(marray, mai); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(1), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... + '_extract1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 2),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(2), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... + '_extract2'); + +%% \ No newline at end of file diff --git a/mcmc_simbio/projects/proj_protein_constgfp3ii_function.m b/mcmc_simbio/projects/proj_protein_constgfp3ii_function.m new file mode 100755 index 0000000..9db43ac --- /dev/null +++ b/mcmc_simbio/projects/proj_protein_constgfp3ii_function.m @@ -0,0 +1,132 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_protein_constgfp3ii_linux(varargin) + +%% MCMC toolbox demo - proj_protein_constgfp3i.m +% +% const gfp 3, artificial data, separate, 2 extracts. Check if the CSPs line up exactly. +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +%% initialize the directory where things are stored. +% close all +% clear all +% clc +p = inputParser; +p.addOptional('prevtstamp', []); +p.addParameter('stepSize', []); +p.addParameter('nW', []); +p.addParameter('nPoints', []); +p.addParameter('thinning', []); +p.addParameter('nIter', []); +p.addParameter('parallel', []); +p.addParameter('stdev', []); + +p.addParameter('multiplier', 1); +p.parse(varargin{:}); +p = p.Results; + +[tstamp, projdir, st] = project_init; + +%% We first define the model, mcmc_info struct, and the data_info struct. + +mobj = model_protein3; + +mcmc_info = mcmc_info_constgfp3ii(mobj); + +mi = mcmc_info.model_info; + + +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkcp1 = 0.012; %s-1 +rkcp2 = 0.024; %s-1 +cpol1 = 100; % nM +cpol2 = 200; % nM + + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% supply parameter vectors to this function to generate simulated data. +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies}, ... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector([1:2 3 5])), exp(masterVector([1:2 4 6]))}); + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end + +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end + +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end + +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end + +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end + +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end + +%% +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + + +if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier); +else + + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + + % load mcmc_info and the updated model_info + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + error('too few initial points'); + elseif size(marray_cut, 2) > ri.nW + marray_cut = marray_cut(:,1:ri.nW, :); + end + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', marray_cut(:,:,end), 'multiplier', p.multiplier); +end + + % keep this commented unless using to copy paste into the linux server + % window +% [mi,mai, ri, tstamp, projdir, di] = proj_protein_constgfp3ii_linux(... +% 'prevtstamp', '20180402_160013',... +% 'stepSize', 1.01, 'nW', 400, 'nPoints', 2e4, 'thinning', 30,... +% 'nIter', 80, 'parallel', true, 'multiplier', 2, 'stdev', 5); +end + + + + diff --git a/mcmc_simbio/projects/proj_protein_constgfp5i.m b/mcmc_simbio/projects/proj_protein_constgfp5i.m new file mode 100755 index 0000000..6b87cf3 --- /dev/null +++ b/mcmc_simbio/projects/proj_protein_constgfp5i.m @@ -0,0 +1,109 @@ +%% MCMC toolbox demo - proj_protein_constgfp3iv.m +% +% const gfp 3, +% artificial data, +% separate, 2 extracts. +% Check if the CSPs line up exactly. +% kf fixed. +% +% This file was modeled after the file proj_protein_constgfp3i.m. +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +%% initialize the directory where things are stored. + close all +% clear all +% clc +[tstamp1, projdir, st] = project_init; + +%% We first define the model, mcmc_info struct, and the data_info struct. +% for the two extracts +mobj = model_protein5; +mcmc_info = mcmc_info_constgfp5ii(mobj); +mi = mcmc_info.model_info; + +cpol = 100; % nM +cribo = 50; %nM + +rkfdG = 10; % nM-1s-1 +rkrdG = 600; % s-1 +rkcm = 0.001; %s-1 + +rkfpG = 10; % nM-1s-1 +rkrpG = 300; % s-1 +rkcp = 1/36; + +rdel_m = log(2)/720; % 12 min half life of mrna + + masterVector = log([... + rkfdG;rkrdG;rkfpG;rkrpG;rkcm;rkcp;rdel_m;cpol;cribo]); + +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies}, ... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector), [exp(masterVector(1:end-5)); 2*exp(masterVector((end-4):end))]}); + +da_extract1 = di(1).dataArray; +da_extract2 = di(2).dataArray; +tv = di(1).timeVector; + +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); + + +%% +% Run the MCMC +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% +mi1 = mcmc_runsim_v2(tstamp1, projdir, di(1), mcmc_info,... + 'InitialDistribution', 'LHS'); + +%% plot stuff +tstamptouse = tstamp1; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +mcmc_plot(marray, mai.estNames, 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); +% mcmc_plot(marray, mi1.namesUnord,'ks', true, 'scatter', false); +% mcmc_plot(marray, mi1.namesUnord,'transparency', 0.05); +titls = {'E1 dG 10';'E1 dG 30';'E1 dG 60'}; +lgds = {}; +mvarray1 = masterVecArray(marray, mai); + +% paramMaps accesses the full mastervec (as opposed to just the estimated values) +% to give the full vector of (unordered) values for a model. +marrayOrd = mvarray1(mi1(1).paramMaps(mi1(1).orderingIx, 1),:,:); + +fhandle = mcmc_trajectories(mi1(1).emo, di(1), mi1(1), marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); + +% %% 3D plot +% % the 3d saving here is trickier: 11 Choose 3 is 165. So for 2 extracts, there are 330 plots. +% % this is too many. Not going to plot any at the moment. + +%% Estimate the parameters for the second extract. +[tstamp2, projdir, st] = project_init; +mi2 = mcmc_runsim_v2(tstamp2, projdir, di(2), mcmc_info,... + 'InitialDistribution', 'LHS'); + +%% plot stuff +tstamptouse = tstamp2; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +mcmc_plot(marray, mai.estNames, 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); +% mcmc_plot(marray, mi2.namesUnord,'ks', true, 'scatter', false); +% mcmc_plot(marray, mi2.namesUnord,'transparency', 0.05); +titls = {'E2 dG 10';'E2 dG 30';'E2 dG 60'}; +lgds = {}; +mvarray2 = masterVecArray(marray, mai); + +% paramMaps accesses the full mastervec (as opposed to just the estimated values) +% to give the full vector of (unordered) values for a model. +marrayOrd = mvarray2(mi2(1).paramMaps(mi2(1).orderingIx, 1),:,:); + +fhandle = mcmc_trajectories(mi2(1).emo, di(2), mi2(1), marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract2'); + diff --git a/mcmc_simbio/projects/proj_protein_constgfp5ii.m b/mcmc_simbio/projects/proj_protein_constgfp5ii.m new file mode 100755 index 0000000..c73d422 --- /dev/null +++ b/mcmc_simbio/projects/proj_protein_constgfp5ii.m @@ -0,0 +1,98 @@ +%% MCMC toolbox demo - proj_protein_constgfp3i.m +% +% const gfp 3, artificial data, separate, 2 extracts. Check if the CSPs line up exactly. +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +%% initialize the directory where things are stored. +% close all +% clear all +% clc +[tstamp, projdir, st] = project_init; + +%% We first define the model, mcmc_info struct, and the data_info struct. + +mobj = model_protein5; + +mcmc_info = mcmc_info_constgfp5ii(mobj); + +mi = mcmc_info.model_info; + + + +rkfdG = 1; % nM-1s-1 +rkrdG = 60; % s-1 + +rkfpG = 2; % nM-1s-1 +rkrpG = 60; % s-1 + +cpol1 = 100; % nM +cribo1 = 50; %nM +rkcm1 = 0.001; %s-1 +rkcp1 = 1/36; +rdel_m1 = log(2)/720; % 12 min half life of mrna +cpol2 = cpol1*2; +cribo2 = cribo1*2; +rkcm2 = rkcm1*2; +rkcp2 = rkcp1*2; +rdel_m2 = rdel_m1*2; + +masterVector = log([... + rkfdG;rkrdG;rkfpG;rkrpG;rkcm1;rkcp1;rdel_m1;cpol1;cribo1;rkcm2;... + rkcp2;rdel_m2;cpol2;cribo2]); + +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies}, ... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector([1:4 5:9])), exp(masterVector([1:4 10:14]))}); + +da_extract1 = di(1).dataArray; +da_extract2 = di(2).dataArray; +tv = di(1).timeVector; +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); +% Run the MCMC +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +marray = mcmc_get_walkers({'20180322_155221'}, {20}, projdir); +pID = 1:length(mai.estNames); +marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); +if size(marray_cut, 2) < ri.nW + error('too few initial points'); +elseif size(marray_cut, 2) > ri.nW + marray_cut = marray_cut(:,1:ri.nW, :); +end +%% +mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', marray_cut(:,:,end), 'multiplier', 2); +% 'UserInitialize', marray_cut(:,:,end) +% 'InitialDistribution', 'LHS' + +%% plot stuff +tstamptouse = tstamp; +close all +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); + +mcmc_plot(marray([1:2 3:7], :,1:6:end), mai.estNames([1:2 3:7]),... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); +figure +mcmc_plot(marray([1:2 8:12], :,1:6:end), mai.estNames([1:2 8:12]),... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract2'); + +titls = {'E1 dG 10';'E1 dG 30';'E1 dG 60'}; + +lgds = {}; +mvarray = masterVecArray(marray, mai); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(1), mi(1), marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 2),:,:); +titls = {'E2 dG 10';'E2 dG 30';'E2 dG 60'}; +fhandle = mcmc_trajectories(mi(1).emo, di(2), mi(1), marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract2'); + diff --git a/mcmc_simbio/projects/proj_test015.m b/mcmc_simbio/projects/proj_test015.m new file mode 100755 index 0000000..3676841 --- /dev/null +++ b/mcmc_simbio/projects/proj_test015.m @@ -0,0 +1,412 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015(varargin) +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_protein3; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_test015(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_test015; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_test015_20190312.m b/mcmc_simbio/projects/proj_test015_20190312.m new file mode 100755 index 0000000..0d9cbf9 --- /dev/null +++ b/mcmc_simbio/projects/proj_test015_20190312.m @@ -0,0 +1,412 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015_20190312(varargin) +% proj_acs_dsg2014 +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 800); +p.addParameter('nPoints', 800*200); +p.addParameter('thinning', 1); +p.addParameter('nIter', 10); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1 0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_F1(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_dsg2014_full; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_test015_E1E2same.m b/mcmc_simbio/projects/proj_test015_E1E2same.m new file mode 100755 index 0000000..0e3e5c5 --- /dev/null +++ b/mcmc_simbio/projects/proj_test015_E1E2same.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015_E1E2same(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_protein3; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_test015_E1E2same(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_test015; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_test015_corona.m b/mcmc_simbio/projects/proj_test015_corona.m new file mode 100644 index 0000000..004898e --- /dev/null +++ b/mcmc_simbio/projects/proj_test015_corona.m @@ -0,0 +1,409 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015_corona(varargin) +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 30); +p.addParameter('nPoints', 30*40); +p.addParameter('thinning', 2); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.01]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +%% construct simbiology model object(s) +mobj = model_protein3; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_test015(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_test015; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_test015_corr1.m b/mcmc_simbio/projects/proj_test015_corr1.m new file mode 100755 index 0000000..4ac6247 --- /dev/null +++ b/mcmc_simbio/projects/proj_test015_corr1.m @@ -0,0 +1,418 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015_corr1(varargin) + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 40); +p.addParameter('nPoints', 100*40); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); + +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', 0.002); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach + +p.addParameter('rkcp', exp([-2.8704])); +p.addParameter('cpol', exp([ 2.6442])); + + +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_tetR_repression1; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_test015_corr1(mobj, p.rkcp, p.cpol); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_test015; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_test015_corr1_Ffix.m b/mcmc_simbio/projects/proj_test015_corr1_Ffix.m new file mode 100755 index 0000000..c6d1e8d --- /dev/null +++ b/mcmc_simbio/projects/proj_test015_corr1_Ffix.m @@ -0,0 +1,422 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015_corr1_Ffix(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 40); +p.addParameter('nPoints', 100*40); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); + +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', 0.002); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach + +p.addParameter('rkcp', exp([-2.8704])); +p.addParameter('cpol', exp([ 2.6442])); + +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_tetR_repression1; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_test015_corr1_Ffix(mobj, p.rkcp, p.cpol); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_test015; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temperature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_test015_corr1_Ffix2.m b/mcmc_simbio/projects/proj_test015_corr1_Ffix2.m new file mode 100755 index 0000000..06c2f40 --- /dev/null +++ b/mcmc_simbio/projects/proj_test015_corr1_Ffix2.m @@ -0,0 +1,431 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015_corr1_Ffix2(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 40); +p.addParameter('nPoints', 100*40); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); + +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', 0.002); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach + +p.addParameter('rkcp', exp([-2.8704])); +p.addParameter('cpol', exp([ 2.6442])); + +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5,... +% 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter',... +% 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_tetR_repression1; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_test015_corr1_Ffix2(mobj, p.rkcp, p.cpol); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_test015; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning(['too few initial points, using a few timesteps from previous',... + 'runs to create initial walker positions.']); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2,... + size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp},... + {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning(['too few initial points, using a few timesteps from previous',... + 'runs to create initial walker positions.']); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, ... + size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning(['too few initial points, using a few timesteps from previous ',... + 'runs to create initial walker positions.']); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2,... + size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temperature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_test015_corr1_Ffix3.m b/mcmc_simbio/projects/proj_test015_corr1_Ffix3.m new file mode 100755 index 0000000..37f8e35 --- /dev/null +++ b/mcmc_simbio/projects/proj_test015_corr1_Ffix3.m @@ -0,0 +1,431 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015_corr1_Ffix3(varargin) +% We fix the forward rates for all csp parameters, except the kfdg and +% krdg. I think CSP fixing might work here! +% +% +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 40); +p.addParameter('nPoints', 100*40); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', false); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); + +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', 0.002); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach + +p.addParameter('rkcp', exp(-2.8704)); +p.addParameter('cpol', exp( 2.6442)); + +% other values, in particular at the line of covartiation: +% rkcp, cpol (log) +% -1.068, 1.33 +% -0.2447, 0.5928 +% 0.7937, -0.5113 +% 2.987, -2.662 +% 3.635, -3.342 + +% + +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_tetR_repression1; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_test015_corr1_Ffix3(mobj, p.rkcp, p.cpol); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_test015; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temperature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_test015_kfdgfix.m b/mcmc_simbio/projects/proj_test015_kfdgfix.m new file mode 100755 index 0000000..f8a35a5 --- /dev/null +++ b/mcmc_simbio/projects/proj_test015_kfdgfix.m @@ -0,0 +1,417 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_test015_kfdgfix(varargin) +% proj_acs_dsg2014 +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2018 + +p = inputParser; +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 100); +p.addParameter('nPoints', 100*100); +p.addParameter('thinning', 1); +p.addParameter('nIter', 2); +p.addParameter('parallel', true); +p.addParameter('stdev', 1); +p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder', linspace(2, 1, 4), @isnumeric); % A vector of multipliers for the +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.1]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_protein3; + +%% setup the mcmc_info struct +mcmc_info = mcmc_info_test015_kfdgfix(mobj); + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_test015; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + + + +% copy paste into the terminal if using matlab with no display. +% make sure these stay commented!!! +% proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +% 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.4, 'nW', 16*3200, 'nPoints', ... +% 16*3200*10*10, 'thinning', 1, 'nIter', 5, 'parallel', true, ... +% 'poolsize', 48, 'temperatureLadder', true) + +% proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 800, 'nPoints', ... +% 800*10*20, 'thinning', 1, 'nIter', 10, 'parallel', true, ... +% 'poolsize', 23, 'temperatureLadder', [0.5, 0.005 0.05 0.0005 0.005 0.00005],... +% 'stepLadder', linspace(2, 1, 5)) +% +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*3,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +% 'stepLadder', linspace(2, 1, 2)) + +end + diff --git a/mcmc_simbio/projects/proj_tetR1i.m b/mcmc_simbio/projects/proj_tetR1i.m new file mode 100755 index 0000000..b8bdf25 --- /dev/null +++ b/mcmc_simbio/projects/proj_tetR1i.m @@ -0,0 +1,170 @@ +%% MCMC toolbox demo - proj_protein_constgfp3iv.m +% +% const gfp 3, +% artificial data, +% separate, 2 extracts. +% Check if the CSPs line up exactly. +% kf fixed. +% +% This file was modeled after the file proj_protein_constgfp3i.m. +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +%% initialize the directory where things are stored. + close all +% clear all +% clc +[tstamp1, projdir, st] = project_init; + +%% We first define the model, mcmc_info struct, and the data_info struct. +% for the two extracts +mobj = model_tetR_repression1; +mcmc_info = mcmc_info_tetR_1i(mobj); +mi = mcmc_info.model_info; + +cpol = 100; % nM +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkfdT = 5; +rkrdT = 300; +rkcp = 0.012; %s-1 +rkfdimTet = 20; % nM-1s-1 +rkrdimTet = 10; % s-1 +rkfseqTet = 20; % nM-1s-1 +rkrseqTet = 10; % s-1 + +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkcp +cpol]); + +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies}, ... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector), [exp(masterVector(1:end-2)); 0.024; 200]}); + +da_extract1 = di(1).dataArray; +da_extract2 = di(2).dataArray; +tv = di(1).timeVector; + +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); + + +%% +% Run the MCMC +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% +mi1 = mcmc_runsim_v2(tstamp1, projdir, di(1), mcmc_info,... + 'InitialDistribution', 'LHS'); + +%% plot stuff +figure +tstamptouse = tstamp1; +marray1 = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +mcmc_plot(marray1, mai.estNames, 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); +% mcmc_plot(marray, mi1.namesUnord,'ks', true, 'scatter', false); +% mcmc_plot(marray, mi1.namesUnord,'transparency', 0.05); +titls = {'E1 dT 0.5 dG 10';'E1 dT 0.5 dG 30';'E1 dT 0.5 dG 60'; +'E1 dT 2 dG 10';'E1 dT 2 dG 30';'E1 dT 2 dG 60'; +'E1 dT 8 dG 10';'E1 dT 8 dG 30';'E1 dT 8 dG 60';}; +lgds = {}; +mvarray1 = masterVecArray(marray1, mai); + +% paramMaps accesses the full mastervec (as opposed to just the estimated values) +% to give the full vector of (unordered) values for a model. +marrayOrd = mvarray1(mi1(1).paramMaps(mi1(1).orderingIx, 1),:,:); + +fhandle = mcmc_trajectories(mi1(1).emo, di(1), mi1(1), marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); + +%% 3D plot +% the 3d saving here is trickier: 6 Choose 3 is 20. So for 2 extracts, there are 40 plots. +% this is too many. I think I am going to just plot some small subset of the 3-wise plots. +% in particular, I am interested in the covariation of the two ESPs wrt the CSPs! I do not really +% care about the covariation within the CSPs. Cool realization! +pToPlot = [5 6 1; 5 6 2; 5 6 3; 5 6 4;]; +% I am also mildly curious about the covatiation of the tetR repression system parameters +% All of these are CSPs. +pToPlot = [pToPlot; 2 3 4]; + +% labellist = {'kf' 'kr' 'kc1' 'Pol1' 'kc2' 'Pol2' }; +labellist = mai.estNames; +for plotID = 1:size(pToPlot, 1) + mstacked = marray1(:,:)'; + figure + XX = mstacked(1:2:end, [pToPlot(plotID,1)]); + YY = mstacked(1:2:end, [pToPlot(plotID,2)]); + ZZ = mstacked(1:2:end, [pToPlot(plotID,3)]); + scatter3(XX,YY,ZZ) + xlabel(labellist{pToPlot(plotID,1)}, 'FontSize', 20) + ylabel(labellist{pToPlot(plotID,2)}, 'FontSize', 20) + zlabel(labellist{pToPlot(plotID,3)}, 'FontSize', 20) + title('covariation in Extract 1', 'FontSize', 20) + saveas(gcf, [projdir '/simdata_' tstamp1 '/3dfig_ext1_' num2str(plotID) '_' tstamp1]); +end + + +%% Estimate the parameters for the second extract. +[tstamp2, projdir, st] = project_init; +mi2 = mcmc_runsim_v2(tstamp2, projdir, di(2), mcmc_info,... + 'InitialDistribution', 'LHS'); + +%% plot stuff +tstamptouse = tstamp2; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +marray2 = marray; +mcmc_plot(marray2, mai.estNames, 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); +% mcmc_plot(marray, mi2.namesUnord,'ks', true, 'scatter', false); +% mcmc_plot(marray, mi2.namesUnord,'transparency', 0.05); +titls = {'E2 dT 0.5 dG 10';'E2 dT 0.5 dG 30';'E2 dT 0.5 dG 60'; +'E2 dT 2 dG 10';'E2 dT 2 dG 30';'E2 dT 2 dG 60'; +'E2 dT 8 dG 10';'E2 dT 8 dG 30';'E2 dT 8 dG 60';}; +lgds = {}; +mvarray2 = masterVecArray(marray2, mai); + +% paramMaps accesses the full mastervec (as opposed to just the estimated values) +% to give the full vector of (unordered) values for a model. +marrayOrd = mvarray2(mi2(1).paramMaps(mi2(1).orderingIx, 1),:,:); + +fhandle = mcmc_trajectories(mi2(1).emo, di(2), mi2(1), marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract2'); +%% +% the 3d saving here is trickier: 6 Choose 3 is 20. So for 2 extracts, there are 40 plots. +% this is too many. I think I am going to just plot some small subset of the 3-wise plots. +% in particular, I am interested in the covariation of the two ESPs wrt the CSPs! I do not really +% care about the covariation within the CSPs. Cool realization! +pToPlot = [5 6 1; 5 6 2; 5 6 3; 5 6 4;]; + +% I am also mildly curious about the covatiation of the tetR repression system parameters +% All of these are CSPs. +pToPlot = [pToPlot; 2 3 4]; + +% labellist = {'kf' 'kr' 'kc1' 'Pol1' 'kc2' 'Pol2' }; +labellist = mai.estNames; +for plotID = 1:size(pToPlot, 1) + mstacked = marray2(:,:)'; + figure + XX = mstacked(1:2:end, [pToPlot(plotID,1)]); + YY = mstacked(1:2:end, [pToPlot(plotID,2)]); + ZZ = mstacked(1:2:end, [pToPlot(plotID,3)]); + scatter3(XX,YY,ZZ) + xlabel(labellist{pToPlot(plotID,1)}, 'FontSize', 20) + ylabel(labellist{pToPlot(plotID,2)}, 'FontSize', 20) + zlabel(labellist{pToPlot(plotID,3)}, 'FontSize', 20) + title('covariation in Extract 2', 'FontSize', 20) + saveas(gcf, [projdir '/simdata_' tstamp2 '/3dfig_ext2_' num2str(plotID) '_' tstamp2]); +end \ No newline at end of file diff --git a/mcmc_simbio/projects/proj_tetR1ii.m b/mcmc_simbio/projects/proj_tetR1ii.m new file mode 100755 index 0000000..dbb7bf6 --- /dev/null +++ b/mcmc_simbio/projects/proj_tetR1ii.m @@ -0,0 +1,126 @@ +%% MCMC toolbox demo - +% artificial data, separate, 2 extracts. Check if the CSPs line up exactly. +% +% Vipul Singhal, +% California Institute of Technology +% 2018 + +%% initialize the directory where things are stored. +% close all +% clear all +% clc +[tstamp, projdir, st] = project_init; + +%% We first define the model, mcmc_info struct, and the data_info struct. + +mobj = model_tetR_repression1; + +mcmc_info = mcmc_info_tetR_1ii(mobj); + +mi = mcmc_info.model_info; + +rkfdG = 5; % nM-1s-1 +rkrdG = 300; % s-1 +rkfdT = 5; +rkrdT = 300; +rkfdimTet = 20; % nM-1s-1 +rkrdimTet = 10; % s-1 +rkfseqTet = 20; % nM-1s-1 +rkrseqTet = 10; % s-1 +rkcp1 = 0.012; %s-1 +rkcp2 = 0.024; %s-1 +cpol1 = 100; % nM +cpol2 = 200; % nM +activeNames = ... + {'kfdG'; 'krdG'; 'kfdT'; 'krdT'; 'kfdimTet'; 'krdimTet'; 'kfseqTet';... + 'krseqTet'; 'kcp'; 'pol'}; + +masterVector = log([... +rkfdG ;rkrdG;rkfdT;rkrdT;rkfdimTet;rkrdimTet;rkfseqTet;rkrseqTet;rkcp1;rkcp2;cpol1;cpol2]); + +di = data_artificial_v2({mobj}, {0:180:7200}, {mi.measuredSpecies}, ... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector([1:9 11])), exp(masterVector([1:8 10 12]))}); + +da_extract1 = di(1).dataArray; +da_extract2 = di(2).dataArray; +tv = di(1).timeVector; +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); +% Run the MCMC +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS'); + +%% plot stuff +close all +tstamptouse = tstamp; +marray = mcmc_get_walkers({tstamptouse}, {8:ri.nIter}, projdir); +mcmc_plot(marray([1:4 5 7], :,:), mai.estNames([1:4 5 7]), 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); +figure +mcmc_plot(marray([1:4 6 8], :,:), mai.estNames([1:4 6 8]), 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract2'); +titls = {'E1 dT 0.5 dG 10';'E1 dT 0.5 dG 30';'E1 dT 0.5 dG 60'; +'E1 dT 2 dG 10';'E1 dT 2 dG 30';'E1 dT 2 dG 60'; +'E1 dT 8 dG 10';'E1 dT 8 dG 30';'E1 dT 8 dG 60';}; +lgds = {}; +mvarray = masterVecArray(marray, mai); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(1), mi(1), marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 2),:,:); +titls = {'E2 dT 0.5 dG 10';'E2 dT 0.5 dG 30';'E2 dT 0.5 dG 60'; +'E2 dT 2 dG 10';'E2 dT 2 dG 30';'E2 dT 2 dG 60'; +'E2 dT 8 dG 10';'E2 dT 8 dG 30';'E2 dT 8 dG 60';}; +fhandle = mcmc_trajectories(mi(1).emo, di(2), mi(1), marrayOrd, titls, lgds,... + 'SimMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring', '_extract2'); + +%% 3D plot +% the 3d saving here is trickier: 6 Choose 3 is 20. So for 2 extracts, there are 40 plots. +% this is too many. I think I am going to just plot some small subset of the 3-wise plots. +% in particular, I am interested in the covariation of the two ESPs wrt the CSPs! I do not really +% care about the covariation within the CSPs. Cool realization! + +% mstacked = mvarray(:,:)'; % <---- THIS IS WRONG! use: +mstacked = marray(:,:)'; + + +pToPlot = [ 5 7 1 ; 5 7 2 ; 5 7 3 ; 5 7 4 ;]; +% CSP on the vertical axis to conform to schematics in presentations. + +% I am also mildly curious about the covatiation of the tetR repression system parameters +% All of these are CSPs. +pToPlot = [pToPlot; 2 3 4]; +labellist = mai.estNames; +for plotID = 1:size(pToPlot, 1) + figure + XX = mstacked(1:end, [pToPlot(plotID,1)]); + YY = mstacked(1:end, [pToPlot(plotID,2)]); + ZZ = mstacked(1:end, [pToPlot(plotID,3)]); + scatter3(XX,YY,ZZ) + xlabel(labellist{pToPlot(plotID,1)}, 'FontSize', 20) + ylabel(labellist{pToPlot(plotID,2)}, 'FontSize', 20) + zlabel(labellist{pToPlot(plotID,3)}, 'FontSize', 20) + title('covariation in Extract 1', 'FontSize', 20) + saveas(gcf, [projdir '/simdata_' tstamptouse '/3dfig_ext1_' num2str(plotID) '_' tstamptouse]); +end +% +pToPlot = [6 8 1; 6 8 2 ; 6 8 3; 6 8 4;]; +for plotID = 1:size(pToPlot, 1) + figure + XX = mstacked(1:end, [pToPlot(plotID,1)]); + YY = mstacked(1:end, [pToPlot(plotID,2)]); + ZZ = mstacked(1:end, [pToPlot(plotID,3)]); + scatter3(XX,YY,ZZ) + xlabel(labellist{pToPlot(plotID,1)}, 'FontSize', 20) + ylabel(labellist{pToPlot(plotID,2)}, 'FontSize', 20) + zlabel(labellist{pToPlot(plotID,3)}, 'FontSize', 20) + title('covariation in Extract 2', 'FontSize', 20) + saveas(gcf, [projdir '/simdata_' tstamptouse '/3dfig_ext2_' num2str(plotID) '_' tstamptouse]); +end + + + diff --git a/mcmc_simbio/projects/proj_tierra2018_calibration.m b/mcmc_simbio/projects/proj_tierra2018_calibration.m new file mode 100755 index 0000000..42ee225 --- /dev/null +++ b/mcmc_simbio/projects/proj_tierra2018_calibration.m @@ -0,0 +1,129 @@ +% proj_tierra2018_calibration +% The calibration step for the Tierra Biosciences dataset. +% +% Script for the correction of aTc data from Tierra biosciences can be +% found in the file proj_tierra2018_correction. +% +% Overview: this demo uses the following files: +% +% +% - mcmc_info_tierra2018_calib +% Constructs the mcmc_info struct. +% +% - model_protein3.m +% Constructs a constitutive expression model. +% + +close all +[tstamp, projdir, st] = project_init; + +mobj = model_protein3; + +mcmc_info = mcmc_info_tierra2018_calib(mobj); + +mi = mcmc_info.model_info; + +%% Get experimental data +% di = data_info_tierra2018; +close all +di = tierradataset; +di(3).timeVector = di(3).timeVector(1:81); +di(4).timeVector = di(4).timeVector(1:81); +di(3).dataArray = di(3).dataArray(1:81, :,:,:)/10; +di(4).dataArray = di(4).dataArray(1:81, :,:,:)/10; + +mcmc_trajectories([], di(3:4), [], [], [], [], 'just_data_info', true); + +% Manually find a set of parameters that get you in the approximate realm of +% the experimental data (Otherwise a lot more computation is needed.. +% completely doable, but takes some time / cluster access, which I do not +% currently have). + +% manually pick parameter values +rkfdG = 0.5; % nM-1s-1 +rkrdG = 30; % s-1 +rkcp1 = 0.12; %s-1 +rkcp2 = 0.24; %s-1 +cpol1 = 4; % nM +cpol2 = 1.5; % nM + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% simulate the data +di_artificial = data_artificial_v2({mobj}, {di(3).timeVector}, {mi.measuredSpecies},... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector([1:2 3 5])), exp(masterVector([1:2 4 6]))}); + +da_extract1 = di_artificial(1).dataArray; +da_extract2 = di_artificial(2).dataArray; +tv = di_artificial(1).timeVector; + +% Plot the data against experimental data from the previous step. + +mcmc_trajectories([], di_artificial, [], [], [], [], 'just_data_info', true); + +%% +ri = mcmc_info.runsim_info; + +mai = mcmc_info.master_info; + +%% +% '20181105_224005'}, {1:8} +% 20181106_010736 +% latest sim: 20181106_101841, 4iters, +% + +% 20181106_141312 % 5iter +%20181106_145414 %12iter +marraytemp = mcmc_get_walkers({'20181106_145414'}, {1:12}, projdir); +% next iter NOT run yet, nov 5, 11 am. +msz=size(marraytemp); %5 46 440 + +initialization_matrix = [marraytemp(:,:,end)]; +clear marraytemp + +tic +%% +mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'pausemode', true,... + 'multiplier', 4, 'UserInitialize', initialization_matrix); +%'UserInitialize', initialization_matrix +% 'InitialDistribution', 'LHS' + +toc +%% Save Stuff + +tstamptouse = tstamp; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); + +% plot parameter distribution corner plot, and markov chains. +mcmc_plot(marray, mai.estNames,... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse,... + 'extrafignamestring', '_tierra_calib_t1'); + +%% + +titls = {'dG 1';'dG 2';'dG 4';'dG 8'}; +lgds = {}; +mvarray = masterVecArray(marray, mai); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(3), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'meanstd', 'ExpMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... + '_tierra_calib_t1'); + +%% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 2),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(4), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'meanstd','ExpMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... + '_tierra_calib_t1'); \ No newline at end of file diff --git a/mcmc_simbio/projects/proj_tierra2018_calibration_B.m b/mcmc_simbio/projects/proj_tierra2018_calibration_B.m new file mode 100755 index 0000000..c93e968 --- /dev/null +++ b/mcmc_simbio/projects/proj_tierra2018_calibration_B.m @@ -0,0 +1,150 @@ +% proj_tierra2018_calibration_B +% The calibration step for the Tierra Biosciences dataset. +% Second data set that Abel sent me on Nov 6 2018. +% Here we first try to correct the tetR Repression data +% using the calibration from the pTet constututive expression data. +% +% Script for the correction of tetR data from Tierra biosciences can be +% found in the file proj_tierra2018_correction_B. +% +% Overview: this demo uses the following files: +% +% +% - mcmc_info_tierra2018_calib +% Constructs the mcmc_info struct. +% +% - model_protein3.m +% Constructs a constitutive expression model. +% + +close all +[tstamp, projdir, st] = project_init; + +mobj = model_protein3; + +mcmc_info = mcmc_info_tierra2018_calib_B(mobj); + +mi = mcmc_info.model_info; + +% Get experimental data +% di = data_info_tierra2018; +close all +di = tierradataset('dataset11062018'); +% load the constitutive expression data +di(3).timeVector = di(3).timeVector(1:41); +di(4).timeVector = di(4).timeVector(1:41); +di(3).dataArray = di(3).dataArray(1:41, :,:,:)/10; +di(4).dataArray = di(4).dataArray(1:41, :,:,:)/10; + +mcmc_trajectories([], di(3:4), [], [], [], [], 'just_data_info', true); + +% Manually find a set of parameters that get you in the approximate realm of +% the experimental data (Otherwise a lot more computation is needed.. +% completely doable, but takes some time / cluster access, which I do not +% currently have). +%% +% manually pick parameter values +rkfdG = 0.5; % nM-1s-1 +rkrdG = 30; % s-1 +rkcp1 = 0.12; %s-1 +rkcp2 = 0.24; %s-1 +cpol1 = 4; % nM +cpol2 = 1.5; % nM + +masterVector = log([... +rkfdG +rkrdG +rkcp1 +rkcp2 +cpol1 +cpol2]); + +% simulate the data +di_artificial = data_artificial_v2({mobj}, {di(3).timeVector}, {mi.measuredSpecies},... + {mi.dosedNames}, {mi.dosedVals}, {mi.namesUnord},... + {exp(masterVector([1:2 3 5])), exp(masterVector([1:2 4 6]))}); + +da_extract1 = di_artificial(1).dataArray; +da_extract2 = di_artificial(2).dataArray; +tv = di_artificial(1).timeVector; + +% Plot the data against experimental data from the previous step. + +mcmc_trajectories([], di_artificial, [], [], [], [], 'just_data_info', true); + +%% +ri = mcmc_info.runsim_info; + +mai = mcmc_info.master_info; + +%% + +% 20181110_144647, 12 iter, nW: 200, mai.paramRanges: +% -0.2125 14.7875 +% -7.1203 7.8797 +% -7.1203 7.8797 +% -4.5945 10.4055 +% -4.5945 10.4055 + +% 20181110_160929, 12 iter, nW: 200, mai.paramRanges: +% -5.2125 22.7875 +% -10.1203 7.8797 +% -10.1203 7.8797 +% -7.5945 10.4055 +% -7.5945 10.4055 + +% 20181110_192828, nIter: 6, nW = 200 +% -5.2125 22.7875 +% -10.1203 12.8797 +% -10.1203 12.8797 +% -7.5945 10.4055 +% -7.5945 10.4055 + + % 20181111_191438 nIter = 20 + % 20181111_211323 = 10 +marraytemp = mcmc_get_walkers({'20181111_211323'}, {1:10}, projdir); +msz=size(marraytemp); %5 46 440 +initialization_matrix = marraytemp(:,:,end); +clear marraytemp + +tic +%% + +mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'pausemode', true,... + 'multiplier', 1.7,'UserInitialize', initialization_matrix); +%'UserInitialize', initialization_matrix +% 'InitialDistribution', 'LHS' +% 'UserInitialize', initialization_matrix + +toc +%% Save Stuff + +tstamptouse = tstamp; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); + +% plot parameter distribution corner plot, and markov chains. +mcmc_plot(marray, mai.estNames,... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse,... + 'extrafignamestring', '_tierra_calib_testB'); + +%% + +titls = {'dG 1';'dG 2';'dG 4';'dG 8'}; +lgds = {}; +mvarray = masterVecArray(marray, mai); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(3), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'meanstd', 'ExpMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... + '_tierra_calib_testB'); + +%% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 2),:,:); +fhandle = mcmc_trajectories(mi(1).emo, di(4), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'meanstd','ExpMode', 'curves', 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse, 'extrafignamestring',... + '_tierra_calib_testB'); \ No newline at end of file diff --git a/mcmc_simbio/projects/proj_tierra2018_correction1.m b/mcmc_simbio/projects/proj_tierra2018_correction1.m new file mode 100755 index 0000000..e829d82 --- /dev/null +++ b/mcmc_simbio/projects/proj_tierra2018_correction1.m @@ -0,0 +1,196 @@ +% proj_tierra2018_correction1 +% The first correction step step for the Tierra Biosciences dataset. +% We first do CSP fixing in the calibration data, and generate the Fixed ESPs +% in the calibration datasets for both E2 (for correction step 1) and E1 +% (for correction step 2). +% +% This file performs Correction step 1. +% Here we fix the ESPs in E2. +% +% Overview: this demo uses the following files: +% +% - data_info_constructor_tierra2018.m +% Constructs the data info object. +% +% - mcmc_info_tierra2018_calib +% Constructs the mcmc_info struct. +% +% - model_protein3.m +% Constructs a constitutive expression model. +% +% + +close all +clear all + + +[tstamp, projdir, st] = project_init; + +%% Get the ESP parameters form the calibration data. +% 11.6.18 +% In the calibration data, the krdG is the CSP, and so we fix its value to +% its meadian value from the simulation with ID 20181106_010736 +% with 40iter and 1.5 stepsize and tightening 1 +% (or the more fine version: 20181106_101841, stepsize 1.1, +% 4iter, and tightening 10. .) +% +% Actually Use this: 20181105_112220, 10iter. This is because +% the above ones were are very large parameter values, and I think +% integration tolerance systematic errors might be occuring. +% + +calib_projdir = ... + ['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/'... + 'mcmc_simbio/projects/proj_tierra2018_calibration']; +marraytemp = mcmc_get_walkers({'20181105_112220'}, {1:10}, calib_projdir); + +msz=size(marraytemp) +marraytemp2 = marraytemp(:, :)'; +clear marraytemp +msz=size(marraytemp2) + +% take the median value for the krdg parameter, +% and use the index of that value to pick the point to use. +[sorted_krdg, Ix] = sort(marraytemp2(:,1)); +mediansIx = Ix(ceil(length(Ix)/2)); +median_fullparam_log = marraytemp2(mediansIx, :) +format short g +median_fullparam = exp(median_fullparam_log) + +% Using these, we can pick the ESPs for both the reference and +% candidate extracts: +ref_esp_ix = [2,4]; +can_esp_ix = [3,5]; + +ref_esp = median_fullparam(ref_esp_ix); +can_esp = median_fullparam(can_esp_ix); +csp_cutpoint = median_fullparam(1); +% set the model esp parameters to the can_esp + +%% + +mobj = model_aTc_induc1; + +mcmc_info = mcmc_info_tierra2018_corr(mobj, can_esp, csp_cutpoint); + +mi = mcmc_info.model_info; + +%% Get experimental data +di = tierradataset; +di(5).timeVector = di(5).timeVector(1:121); +di(6).timeVector = di(6).timeVector(1:121); +di(5).dataArray = di(5).dataArray(1:121, :,:,:); +di(6).dataArray = di(6).dataArray(1:121, :,:,:); + +mcmc_trajectories([], di(6), [], [], [], [], 'just_data_info', true); + +% Manually find a set of parameters that get you in the approximate realm of +% the experimental data (Otherwise a lot more computation is needed.. +% completely doable, but takes some time / cluster access, which I do not +% currently have). + +% manually pick parameter values +cpol = can_esp(2); % nM +rkfdG = .5; % nM-1s-1 +rkrdG = csp_cutpoint(1); % s-1 +rkfdT = .2; +rkrdT = 30; +rkcp = can_esp(1); %s-1 +frate = .5; +rrate = 20; +rkfdimTet = frate ; % nM-1s-1 +rkrdimTet = rrate; % s-1 +rkfseqTet = frate ; % nM-1s-1 +rkrseqTet = rrate; % s-1 +% rkfdimaTc = frate ; +% rkrdimaTc = rrate; +rkfseqaTc = frate ; +rkrseqaTc = rrate; + +masterVector = log([... +rkfdG +rkrdG +rkfdT +rkrdT +rkfdimTet +rkrdimTet +rkfseqTet +rkrseqTet +rkfseqaTc +rkrseqaTc +rkcp +cpol]); + +% rkfdimaTc +% rkrdimaTc + +% simulate the data +% di_artificial = data_artificial_v2({mobj}, {di(6).timeVector}, ... +% {mi.measuredSpecies},... +% {mi.dosedNames}, {mi.dosedVals}, ... +% {mi.namesUnord},... +% {exp(masterVector), exp(masterVector)}); + + di_artificial = data_artificial_v2(mobj, di(6).timeVector, ... + mi.measuredSpecies,... + mi.dosedNames, mi.dosedVals, ... + mi.namesUnord,... + exp(masterVector)); +da_test_cand = di_artificial(1).dataArray; +tv = di_artificial(1).timeVector; + +% Plot the data against experimental data from the previous step. + +mcmc_trajectories([], di_artificial, [], [], [], [], 'just_data_info', true); +ri = mcmc_info.runsim_info; + +mai = mcmc_info.master_info; +%% +marraytemp = mcmc_get_walkers({'20181107_135851'}, {1:2}, projdir); +% next iter NOT run yet, nov 5, 11 am. +msz=size(marraytemp); %5 46 440 + +initialization_matrix = [marraytemp(:,:,end)]; +clear marraytemp + +mi = mcmc_runsim_v2(tstamp, projdir, di(6), mcmc_info,... + 'pausemode', true,... + 'multiplier', 2,'UserInitialize', initialization_matrix); +% +% 'InitialDistribution', 'LHS' + + +%% +tstamptouse = tstamp;%'20181107_084423'; +projdir_usethis = projdir; +%['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/mcmc_simbio/projects/proj_tierra2018_correction1'] + +addpath(projdir_usethis) +%load(['full_variable_set_' tstamptouse]) + +% tstamptouse = tstamp; +marray = mcmc_get_walkers({tstamptouse}, {1:10}, projdir_usethis); + +% plot parameter distribution corner plot, and markov chains. +mcmc_plot(marray, mai.estNames,... + 'savematlabfig', true, 'savejpeg', true,... + 'projdir', projdir_usethis, 'tstamp', tstamptouse,... + 'extrafignamestring', '_tierra_corr1_t1'); + +%% + +titls = {'aTc 10000';'aTc 1000';'aTc 100';'aTc 10';'aTc 1'}; +lgds = {}; +mvarray = masterVecArray(marray, mai); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx, 1),:,:); +% +fhandle = mcmc_trajectories(mi(1).emo, di(6), mi(1), marrayOrd,... + titls, lgds,... + 'SimMode', 'meanstd', 'ExpMode', 'curves', 'savematlabfig', true,... + 'savejpeg', true,... + 'projdir', projdir, 'tstamp', tstamptouse,... + 'extrafignamestring', '_tierra_corr_t1'); + + +%% \ No newline at end of file diff --git a/mcmc_simbio/projects/proj_tierra2018_correction2.m b/mcmc_simbio/projects/proj_tierra2018_correction2.m new file mode 100755 index 0000000..bf93ad5 --- /dev/null +++ b/mcmc_simbio/projects/proj_tierra2018_correction2.m @@ -0,0 +1,596 @@ +% correction step 2 for the tierra data test 1 +% (direct aTc correction for calibration via constitutive expression +% of the ptet promoter. ) +% +% Vipul Singhal, Caltech, 2018 +% + + +%% get the ESPs from the calibration experiments (this is the same as in the +% first part of the file: +% ['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017'... +% '/mcmc_simbio/projects/proj_tierra2018_correction1.m'] +calib_projdir = ... + ['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/'... + 'mcmc_simbio/projects/proj_tierra2018_calibration']; +marraytemp = mcmc_get_walkers({'20181105_112220'}, {1:10}, calib_projdir); + +msz=size(marraytemp) +marraytemp2 = marraytemp(:, :)'; +clear marraytemp +msz=size(marraytemp2) + +% take the median value for the krdg parameter, +% and use the index of that value to pick the point to use. +[sorted_krdg, Ix] = sort(marraytemp2(:,1)); +mediansIx = Ix(ceil(length(Ix)/2)); +median_fullparam_log = marraytemp2(mediansIx, :) +format short g +median_fullparam = exp(median_fullparam_log) + +% Using these, we can pick the ESPs for both the reference and +% candidate extracts: +ref_esp_ix = [2,4]; +can_esp_ix = [3,5]; + +ref_esp = median_fullparam(ref_esp_ix); +can_esp = median_fullparam(can_esp_ix); +csp_cutpoint = median_fullparam(1); + +%% get the CSPs from correction step 1: + +% use the CSPs such that the krdG value is the closest to the +% one fixed in the calibration step. +projdir_corr1 = ['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/'... + 'mcmc_simbio/projects/proj_tierra2018_correction1']; +tstamp_corr1 = '20181107_145154'; +% 10 iterations +num_iter = 10; +load([projdir_corr1 '/simdata_' tstamp_corr1... + '/full_variable_set_' tstamp_corr1 '.mat']) +% do this properly, with only the right variables. + +%% correction step 1 runsim info and master info +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% +marray_corr1 = mcmc_get_walkers({tstamp_corr1}, {1:num_iter}, projdir_corr1); +marray_corr1=marray_corr1(:, :, 51:100); +msz=size(marray_corr1) + +%% +% code to use from test015: +mstacked_corr1 = marray_corr1(:,:)'; +log(csp_cutpoint) + +% the corresponding CSPs are: +tol = 2; % pretty bad tol. +% ie, the param for csp estimated from the calibration experiment is +% totally off from the set of values used in the correction step. oh well. +% this does not violate the parameter consistency theorem in any way, but +% might lead to a future result. + +cc = intersect(find(mstacked_corr1(:, 1)>log(csp_cutpoint)-tol),... + find(mstacked_corr1(:, 1) 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.01 0.002]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +eval(['mcmc_info = mcmc_info_vnprl_' p.ver '(mobj);']) + + +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_VNPRL2011; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +if ~isempty(p.parallel) + mcmc_info.runsim_info.parallel = p.parallel; +end + + +if mcmc_info.runsim_info.parallel + if ~isempty(p.poolsize) + delete(gcp('nocreate')) + parpool(p.poolsize) + else + delete(gcp('nocreate')) + parpool + end +end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + +end + diff --git a/mcmc_simbio/projects/proj_vnprl_cluster.m b/mcmc_simbio/projects/proj_vnprl_cluster.m new file mode 100644 index 0000000..c6c4972 --- /dev/null +++ b/mcmc_simbio/projects/proj_vnprl_cluster.m @@ -0,0 +1,399 @@ +function [mi,mai, ri, tstamp, projdir, di] = proj_vnprl_cluster(varargin) +% proj_acs_dsg2014 +% Cluster computing version of proj_vnprl +% This will just use F2, and not have 'version' as an argument, since that +% requires an eval, and the MATLAB auto parser will probably not be able to +% detect that. +% +% In this project, we fit RNA degradation and mRNA expression to data from +% the paper +% Gene Circuit Performance Characterization and Resource Usage in a Cell-Free “Breadboard” +% ACS Synth. Biol., 2014, 3 (6), pp 416–425, DOI: 10.1021/sb400203p, + +% Vipul Singhal, +% California Institute of Technology +% 2022 + +p = inputParser; + +% p.addParameter('ver', 'F2', @ischar); +p.addParameter('prevtstamp', []); +p.addParameter('prevtstampID', []); +p.addParameter('stepSize', 1.2); +p.addParameter('nW', 1000); +p.addParameter('nPoints', 1000*200); +p.addParameter('thinning', 10); +p.addParameter('nIter', 10); +% p.addParameter('parallel', true); +p.addParameter('stdev', 1); +% p.addParameter('poolsize', []); +p.addParameter('multiplier', 1); +p.addParameter('stepLadder',1 , @isnumeric); % A vector of multipliers for the..linspace(2, 1, 4) +% step size. Must have length > 0.5*nIter, since only the first nIter/2 +% iterations get their step sizes changed. +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', false) +p.addParameter('temperatureLadder', [0.01 0.002]); % can be a boolean: true or false, +% or can be a vector of multipliers to allow for a simulated annealing type +% approach +p.parse(varargin{:}); +p = p.Results; + +% data_init +% proj_acs_dsg2014_regen_A('nW', 50, 'nPoints', 50*10*5, 'nIter', 5, 'parallel', false, 'multiplier', 2, 'thinning', 10) +% proj_acs_dsg2014_regen_A('nW', 6400, 'nPoints', 6400*10*20, 'nIter', 20, 'poolsize', 36, 'multiplier', 3, 'thinning', 10) +%% construct simbiology model object(s) +mobj = model_dsg2014_regen; + +%% setup the mcmc_info struct +% eval(['mcmc_info = mcmc_info_vnprl_' p.ver '(mobj);']) % this will need to be attached. + +mcmc_info = mcmc_info_vnprl_F2(mobj); +mi = mcmc_info.model_info; + +%% setup the data_info struct +di = data_VNPRL2011; +% modify di to only contain the mRNA data. +% di.dataArray = di.dataArray(:, 1, :, :); % pick out only the mrna +% di.measuredNames = di.measuredNames(1); +% di.dataUnits = di.dataUnits(1); +% di.dataInfo = ['Modified to only have mRNA data. \n',... +% di.dataInfo]; + +% Run the MCMC +if ~isempty(p.stepSize) + mcmc_info.runsim_info.stepSize = p.stepSize; +end +if ~isempty(p.nW) + mcmc_info.runsim_info.nW = p.nW; +end +if ~isempty(p.nPoints) + mcmc_info.runsim_info.nPoints = p.nPoints; +end +if ~isempty(p.thinning) + mcmc_info.runsim_info.thinning = p.thinning; +end +if ~isempty(p.nIter) + mcmc_info.runsim_info.nIter = p.nIter; +end +% if ~isempty(p.parallel) +% mcmc_info.runsim_info.parallel = p.parallel; +% end + + +% if mcmc_info.runsim_info.parallel +% if ~isempty(p.poolsize) +% delete(gcp('nocreate')) +% parpool(p.poolsize) +% else +% delete(gcp('nocreate')) +% parpool +% end +% end +if ~isempty(p.stdev) + mcmc_info.runsim_info.stdev = p.stdev; +end +if ~isempty(p.multiplier) + if ~isempty(p.stepLadder) && isvector(p.stepLadder) && isnumeric(p.stepLadder) + p.multiplier = 1; + end + +end + +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; + +%% Compute total signal strength +% compute total signal for the data of interest, taking dose and +% topology weighting into account. +tsig = 0; % total signal. +for kk = 1:length(mi) + currda = di(mi(kk).dataToMapTo).dataArray; % current data array + % renormalize the data to make the weight of the measured + % species the same. + meanVals = mean(mean(mean(currda, 1), 3), 4); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); + for jj = 1:size(currda, 2) + currda(:, jj, :, :) = relWt(jj)*currda(:, jj, :, :); + end + dv = mi(kk).dosedVals; + % reweight data by dose and experient. + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + if isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + else + error('Doses weights must be the same length as the number of doses') + end + end + else + currda = ... + currda(:, :, :, ii)... + *mi(kk).experimentWeighting; + end + end + elseif isfield(mi(kk), 'doseWeighting') + if ~isempty(mi(kk).doseWeighting) + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + for ii = 1:size(dv,2) + currda(:, :, :, ii) = ... + mi(kk).doseWeighting(ii)... + *currda(:, :, :, ii); + end + else + error('Doses weights must be the same length as the number of doses') + end + end + end + tsig = tsig + sum(sum(sum(sum(currda)))); % total signal is "tsig" +end + +%% run the mcmc simulations +% prevtstamp = {'20180120_172922'}; +% simID = {'1'}; +% marray = mcmc_get_walkers(prevtstamp, {simID}, projdir); +% mtemp = marray(:,:); + + + + + + + +if islogical(p.temperatureLadder) % if p.temperatureLadder is logical + if ~p.temperatureLadder % if p.temperatureLadder is false + %% initialize the directory where things are stored. + [tstamp, projdir, st] = project_init; + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + + mi = mcmc_runsim_v2(tstamp, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 2,... + 'pausemode', false, 'stepLadder', p.stepLadder,... + 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % if p.temperatureLadder is true + % begin temperature ladder: Initial temp is 10% of the total signal + % then we do 0.1%, then finally 0.001% + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*[0.1 0.001, 0.00001] + percentLadder = {'_10pct', '_pt1pct', '_pt001pct'}; + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + % tLaddStr = num2str(tladder(ll)); + % if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + % dotLoc = regexp(tLaddStr, '\.'); + % tLaddStr(dotLoc) = 'p'; + % end + + tstamp_appended = [tstamp '_' num2str(ll) '_' percentLadder{ll}]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 % first temperature. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1, ... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else % subsequent temperatures. + % prevtstamp = [percentLadder{ll-1} tstamp]; + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + end + + %p.temperatureLadder NOT logical +elseif isnumeric(p.temperatureLadder) && isvector(p.temperatureLadder) + + % begin temperature ladder: + disp('Using temperature ladder for MCMC at the following temperatures.'); + tladder = tsig*p.temperatureLadder + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + for ll = 1:length(tladder) + if tladder(ll)>=1 + tLaddStr = num2str(round(tladder(ll))); + fprintf('Current temperature: %d \n', round(tladder(ll))); + else + tLaddStr = num2str(tladder(ll)); + if ~isempty(regexp(tLaddStr, '\.', 'ONCE')) + dotLoc = regexp(tLaddStr, '\.'); + tLaddStr(dotLoc) = 'p'; + end + fprintf('Current temperature: %d \n', tladder(ll)); + end + tstamp_appended = [tstamp '_' num2str(ll) '_' tLaddStr]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% Set the standard deviation %%% + mcmc_info.runsim_info.stdev = tladder(ll); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [~, projdir, ~] = project_init('saveStr', tstamp_appended); + if ll ==1 + % a previous time stamp is NOT provided, start with latin + % hypercube sampling. + if isempty(p.prevtstamp) + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'InitialDistribution', 'LHS', 'multiplier', p.multiplier,... + 'stepLadder', p.stepLadder,... + 'literalStepLadder', p.literalStepLadder); + else + % a previous time stamp IS provided, use it as a starting + % point. The data for that time stamp must be in the same + % directory as the projdir for this project. + specificprojdir = [projdir '/simdata_' p.prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' p.prevtstamp], 'mcmc_info'); + if isempty(p.prevtstampID) + marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + else + marray = mcmc_get_walkers({p.prevtstamp}, {p.prevtstampID},... + projdir); + end + + +% marray = mcmc_get_walkers({p.prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... +% projdir); + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + if size(marray_cut, 2) < ri.nW + warning('too few initial points, using a few timesteps from previous runs to create initial walker positions.'); + walker_timepoints = ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) + minit = marray_cut(:,:, walker_timepoints(1)); + for i = 2:length(walker_timepoints) + minit = [minit marray_cut(:,:,walker_timepoints(i)) ]; + end + minit = minit(:, 1:ri.nW); + else % there are enough points, just pick the number needed. + minit = marray_cut(:,1:ri.nW,end); + end + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', p.prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + else + % get the final location of the walkers from the previous + % iteration (ll - 1). + specificprojdir = [projdir '/simdata_' prevtstamp]; + SS = load([specificprojdir '/full_variable_set_' prevtstamp], 'mcmc_info'); + marray = mcmc_get_walkers({prevtstamp}, {SS.mcmc_info.runsim_info.nIter},... + projdir); + % assume the projdir where this data is stored is the same one as the + % one created at the start of this file + + pID = 1:length(mai.estNames); + marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); + minit = marray_cut(:,1:ri.nW,end); + % now run the simulation. + mi = mcmc_runsim_v2(tstamp_appended, projdir, di, mcmc_info,... + 'UserInitialize', minit, 'multiplier', 1,... + 'stepLadder', p.stepLadder, 'prevtstamp', prevtstamp,... + 'literalStepLadder', p.literalStepLadder); + end + % define tstamp for the next iter. + prevtstamp = tstamp_appended; + + end + + +else + error('temterature ladder need to be specified as a boolean or a numeric vector') +end + +end + diff --git a/mcmc_simbio/projects/runsummareis.m b/mcmc_simbio/projects/runsummareis.m new file mode 100644 index 0000000..aee6b42 --- /dev/null +++ b/mcmc_simbio/projects/runsummareis.m @@ -0,0 +1,7848 @@ +% proj_ZSIFFL_trainingG_v1('stepSize', 1.1,... +% 'nW', 200,... +% 'nPoints', 100*200,... +% 'thinning', 10,... +% 'nIter', 100,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 14,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0004 0.0003 0.0002 0.00015 0.000125 0.0001]) +% +% +% +% ----------------------------------------------------- +% +% +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.1,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 100,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00015 0.000125 0.0001],... +% 'prevtstamp', '20200716_111111_2_1107',... +% 'prevtstampID', 60) +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.1,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 100,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.000175 0.00015],... +% 'prevtstamp', '20200710_230144_2_1292',... +% 'prevtstampID', 21) +% +% +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.1,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 100,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 14,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0002 0.000175],... +% 'prevtstamp', '20200703_000710_4_1476',... +% 'prevtstampID', 40) +% +% +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.1,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.000275 0.00025 0.000225 0.0002],... +% 'prevtstamp', '20200627_132326_4_2214',... +% 'prevtstampID', 29) +% +% +% tladder = +% +% 1.0e+03 * +% +% 2.0299 1.8454 1.6608 1.4763 +% +% Current temperature: 2030 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v6' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v6' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200703_000710' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200703_000710_1_2030'). +% +% ############################################ +% % ---------------------------------------------------------------- +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.15,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0005 0.0004 0.00035 0.0003 0.00025 0.0002],... +% 'prevtstamp', '20200623_175503_1_4429',... +% 'prevtstampID', 100) +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.15,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 100,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0006],... +% 'prevtstamp', '20200622_121135_1_4429',... +% 'prevtstampID', 36) +% +% +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.15,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 100,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0006],... +% 'prevtstamp', '20200621_100025_1_4429',... +% 'prevtstampID', 10) +% +% +% % need to run 0.0005 or 0.0006 for a while, because the 3oc12 Kd is not going to its correct region. +% % this is an example of reannealing. I looked at the 3OC12 trace plots at +% % ts35 = '20200614_005043_4_3691';%100 %%cumulativefrom17 2950 + 130 +% % which used 0.0005. +% % Can probably raise the step size to 1.25 or 1.3 for this one. +% proj_ZSIFFL_trainingC_v6('stepSize', 1.15,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 100,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 14,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0006],... +% 'prevtstamp', '20200619_213706_2_1476',... +% 'prevtstampID', 2) +% +% +% +% +% % --------------------------------------------------------------------------- +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.15,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 14,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0003 0.0002 0.0002 0.000175 0.00015 0.000125],... +% 'prevtstamp', '20200616_183409_2_2214',... +% 'prevtstampID', 39) +% +% tladder = +% +% 1.0e+03 * +% +% 2.2144 1.4763 1.4763 1.2917 1.1072 0.9227 +% +% Current temperature: 2214 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v6' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v6' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200619_213706' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200619_213706_1_2214'). +% +% ############################################ +% +% +% % ----------------------------------------------------- +% +% +% +% +% +% +% % made step size a bit smaller too. since rejection rate was like 85% in the prev step size. at the first temp. +% proj_ZSIFFL_trainingC_v6('stepSize', 1.15,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0004 0.0003 0.0002],... +% 'prevtstamp', '20200615_233435_1_2953',... +% 'prevtstampID', 22) %20200615_233435_1_2953_ID22 +% tladder = +% +% 1.0e+03 * +% +% 2.9526 2.2144 1.4763 +% +% Current temperature: 2953 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v6' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v6' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200616_183409' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200616_183409_1_2953'). +% +% ############################################ +% +% +% % 20200614_005043_5_2953 iter 5 +% proj_ZSIFFL_trainingC_v6('stepSize', 1.25,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0004 0.0003 0.0002],... +% 'prevtstamp', '20200614_005043_5_2953',... +% 'prevtstampID', 5)% terminated because i accidentally unplugged the PC. Lol. +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.1,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0002 0.0003 0.0004 0.0005 0.0004 0.0003 0.0002],... +% 'prevtstamp', '20200612_214710_1_1476',... +% 'prevtstampID', 3) +% tladder = +% +% 1.0e+03 * +% +% 1.4763 2.2144 2.9526 3.6907 2.9526 2.2144 1.4763 +% +% Current temperature: 1476 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v6' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v6' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200614_005043' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200614_005043_1_1476'). +% +% ############################################ +% +% +% +% +% % --------------------------------------------------------------- +% % windows update stopped the run +% +% proj_ZSIFFL_trainingC_v6('stepSize', 1.1,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0002 0.0003 0.0004 0.0005 0.0004 0.0003 0.0002],... +% 'prevtstamp', '20200610_000545_2_738',... +% 'prevtstampID', 28) +% +% tladder = +% +% 1.0e+03 * +% +% 1.4763 2.2144 2.9526 3.6907 2.9526 2.2144 1.4763 +% +% Current temperature: 1476 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v6' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v6' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200612_214710' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200612_214710_1_1476'). +% +% ############################################ +% +% +% +% +% +% +% +% +% +% +% % --------------------------------------------------------------- +% +% % --------------------------------------------------------------- +% +% % --------------------------------------------------------------- +% +% % --------------------------------------------------------------- +% +% % --------------------------------------------------------------- +% +% % --------------------------------------------------------------- +% +% % --------------------------------------------------------------- +% +% % --------------------------------------------------------------- +% % the 3OC12KD was moving towards 0 too slowly. going to raise the temp and have it converge at +% % that higher temp first. then anneal to lower temps. Plot: +% % ts17 = '20200603_044203_1_2214'; %200, changed to 500 walkers. %%cumulativefrom17 200 +% % ts18 = '20200603_044203_2_1845';%70 %%cumulativefrom17 270 +% % ts19 = '20200604_073858_1_1845'; %200 %%cumulativefrom17 470 +% % ts20 = '20200604_073858_2_1476'; % 50 %%cumulativefrom17 520 +% % ts21 = '20200605_045501_1_1476';% 200 %%cumulativefrom17 720 +% % ts22 = '20200605_045501_2_1181';% 200 %%cumulativefrom17 920 +% % ts23 = '20200605_045501_3_1033';% 200 %%cumulativefrom17 1120 +% % ts24 = '20200605_045501_4_886';% 200 %%cumulativefrom17 1320 +% % ts25 = '20200605_045501_5_738';% 200 %%cumulativefrom17 1520 +% % ts26 = '20200605_045501_6_591';% 200 %%cumulativefrom17 1590 +% % ts27 = '20200605_045501_7_443';% 200 +% % ts28 = '20200609_190458_1_1033'; %50 +% % ts29 = '20200610_000545_1_1033'; +% % ts30 = '20200610_000545_2_738'; +% % tstamp = {ts17 ... +% % ts18 ts19 ts20 ts21 ts22 ts23 ts24 ts25 ts26 ts27 ts28 ts29 ts30}; +% % nIterID = {1:20 1:7 1:20 1:5 1:20 1:20 1:20 1:20 1:20 1:20 1:20 1:5 1:40 1:28}; +% +% % to see! +% proj_ZSIFFL_trainingC_v5('stepSize', 1.1,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00014 0.0001 0.00014 0.0001 0.00014 0.0001 0.00014 0.0001 ],... +% 'prevtstamp', '20200609_190458_1_1033',... +% 'prevtstampID', 5) +% +% tladder = +% +% 1.0e+03 * +% +% 1.0334 0.7381 1.0334 0.7381 1.0334 0.7381 1.0334 0.7381 +% +% Current temperature: 1033 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v5' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v5' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200610_000545' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200610_000545_1_1033'). +% %--------------------------------------------------------------- +% +% % current +% %relax the parameter ranges! +% proj_ZSIFFL_trainingC_v5('stepSize', 1.2,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00014 0.0001 0.00014 0.0001 0.00014 0.0001 0.00014 0.0001 ],... +% 'prevtstamp', '20200605_045501_7_443',... +% 'prevtstampID', 20) +% +% tladder = +% +% 1.0e+03 * +% +% 1.0334 0.7381 1.0334 0.7381 1.0334 0.7381 1.0334 0.7381 +% +% Current temperature: 1033 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v5' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v5' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200609_190458' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200609_190458_1_1033'). +% +% ############################################ +% +% +% +% +% +% +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% % ----------------------------------------------------------------- +% proj_ZSIFFL_trainingC_v4('stepSize', 1.2,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0002 0.00016 0.00014 0.00012 0.0001 0.00008 0.00006],... +% 'prevtstamp', '20200604_073858_2_1476',... +% 'prevtstampID', 5) +% tladder = +% +% 1.0e+03 * +% +% 1.4763 1.1810 1.0334 0.8858 0.7381 0.5905 0.4429 +% +% % ------------------------------------------------------- +% proj_ZSIFFL_trainingC_v4('stepSize', 1.2,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00025 0.0002 0.00016 0.00014 0.00012 0.0001 0.00008 0.00006],... +% 'prevtstamp', '20200603_044203_2_1845',... +% 'prevtstampID', 7) +% % ----------------------------------------------------------------------- +% proj_ZSIFFL_trainingC_v4('stepSize', 1.2,... +% 'nW', 500,... +% 'nPoints', 100*500,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0003 0.00025 0.0002 0.00016 0.00014 0.00012 0.0001 0.00008 0.00006],... +% 'prevtstamp', '20200525_114752_1_1329',... +% 'prevtstampID', 2) +% tladder = +% +% 1.0e+03 * +% +% 2.2144 1.8454 1.4763 1.1810 1.0334 0.8858 0.7381 0.5905 0.4429 +% +% Current temperature: 2214 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v4' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v4' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200603_044203' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200603_044203_1_2214'). +% +% +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% % --------------------------------------------------------- +% proj_ZSIFFL_trainingF_v4('stepSize', 1.2,... +% 'nW', 200,... +% 'nPoints', 100*200,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00001 0.000015 0.00001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200530_163844_3_37',... +% 'prevtstampID', 20) +% +% % just continuing from v4. +% proj_ZSIFFL_trainingF_v4('stepSize', 1.2,... +% 'nW', 200,... +% 'nPoints', 100*200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00001 0.0000075 0.000005],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200530_033747_2_74',... +% 'prevtstampID', 7) +% +% % just continuing from v4. +% proj_ZSIFFL_trainingF_v4('stepSize', 1.2,... +% 'nW', 200,... +% 'nPoints', 100*200,... +% 'thinning', 10,... +% 'nIter', 15,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00002 0.00001 0.0000075 0.000005],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200529_040611_3_148',... +% 'prevtstampID', 5) +% +% +% +% +% +% % --------------------------------------------------------- +% +% proj_ZSIFFL_trainingF_v5('stepSize', 1.2,... +% 'nW', 200,... +% 'nPoints', 100*200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00002 0.00001 0.0000075 0.000005],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200529_040611_3_148',... +% 'prevtstampID', 5) +% % ran the first two of this to full. but acutally I dont think i want to expand the ranges. +% % the previous ranges are ok. +% tladder = +% +% 147.6283 73.8141 55.3606 36.9071 +% +% Current temperature: 148 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v5' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v5' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200529_171720' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200529_171720_1_148'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 1733.255869 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 1714.860324 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 1716.809535 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 1724.710128 seconds. +% Iteration number 5. +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 16). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 1701.854840 seconds. +% Iteration number 6. +% Pausing for 5 minutes to cool the CPU before starting run number 6. +% starting mcmc 6 +% current step size: 1.200000e+00 +% ending mcmc 6 +% Elapsed time is 1712.434500 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 1685.503761 seconds. +% Iteration number 8. +% Pausing for 5 minutes to cool the CPU before starting run number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 1691.480490 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 1673.494287 seconds. +% Iteration number 10. +% Pausing for 5 minutes to cool the CPU before starting run number 10. +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 16). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 1658.910324 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 74 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v5' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v5' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200529_222651' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200529_171720_2_74'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 1666.573252 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 1689.891939 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 1679.672888 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 1679.763085 seconds. +% Iteration number 5. +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 16). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 1716.745386 seconds. +% Iteration number 6. +% Pausing for 5 minutes to cool the CPU before starting run number 6. +% starting mcmc 6 +% current step size: 1.200000e+00 +% ending mcmc 6 +% Elapsed time is 1662.689971 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 1593.271627 seconds. +% Iteration number 8. +% Pausing for 5 minutes to cool the CPU before starting run number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 1560.813107 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 1574.856654 seconds. +% Iteration number 10. +% Pausing for 5 minutes to cool the CPU before starting run number 10. +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 16). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 1589.653241 seconds. +% +% % -------------------------------------------------- +% % the pol upper limit was limiting things. also, 100 iters at 200 walkers is perfect. +% proj_ZSIFFL_trainingF_v4('stepSize', 1.2,... +% 'nW', 200,... +% 'nPoints', 100*200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001 0.000075 0.00005 0.000035 0.00002],... +% 'stepLadder', [1]) +% tladder = +% +% 738.1415 553.6061 369.0707 258.3495 147.6283 +% +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v4' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v4' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200528_165131' +% +% Project directory does not exist. Creating it, and using this to store data +% (in a subdirectory named 'simdata_20200528_165131_1_738'). +% +% +% % -------------------------------------------------------- +% % the pol upper limit was limiting things. also, 100 iters at 200 walkers is perfect. +% proj_ZSIFFL_trainingF_v3('stepSize', 1.2,... +% 'nW', 200,... +% 'nPoints', 100*200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0002 0.0001 0.000075 0.00005 0.000035 0.00002],... +% 'stepLadder', [1]) +% tladder = +% +% 1.0e+03 * +% +% 1.4763 0.7381 0.5536 0.3691 0.2583 0.1476 +% +% Current temperature: 1476 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200527_224901' +% +% Project directory does not exist. Creating it, and using this to store data +% (in a subdirectory named 'simdata_20200527_224901_1_1476'). +% +% ############################################ +% +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 14.195716 seconds. +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 14.557499 seconds. +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 15.305348 seconds. +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 11.417738 seconds. +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 13.707813 seconds. +% 600 points out of 600 are integrable. Need 200 walkers. +% Step size ladder being used, skipping burn in phase +% +% ans = +% +% 1 +% +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 1541.497343 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 1576.963598 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 1607.745375 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 1585.472600 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 1584.316339 seconds. +% Iteration number 6. +% Pausing for 5 minutes to cool the CPU before starting run number 6. +% starting mcmc 6 +% current step size: 1.200000e+00 +% ending mcmc 6 +% Elapsed time is 1608.715737 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 1561.542199 seconds. +% Iteration number 8. +% Pausing for 5 minutes to cool the CPU before starting run number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 1609.173530 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 1610.572522 seconds. +% Iteration number 10. +% Pausing for 5 minutes to cool the CPU before starting run number 10. +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 1615.652927 seconds. +% +% initialization_used = +% +% 'LHS' +% +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200528_034033' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200527_224901_2_738'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 1687.816284 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 1650.268113 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 1670.410327 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 1671.276670 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 1643.537627 seconds. +% Iteration number 6. +% Pausing for 5 minutes to cool the CPU before starting run number 6. +% starting mcmc 6 +% current step size: 1.200000e+00 +% ending mcmc 6 +% Elapsed time is 1668.498196 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 1683.241815 seconds. +% Iteration number 8. +% Pausing for 5 minutes to cool the CPU before starting run number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 1727.843888 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 1752.417364 seconds. +% Iteration number 10. +% Pausing for 5 minutes to cool the CPU before starting run number 10. +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 1761.394344 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 554 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200528_084732' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200527_224901_3_554'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 1830.269250 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 1860.361478 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 1975.606293 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 1930.130077 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 1943.453326 seconds. +% Iteration number 6. +% Pausing for 5 minutes to cool the CPU before starting run number 6. +% starting mcmc 6 +% current step size: 1.200000e+00 +% ending mcmc 6 +% Elapsed time is 2021.022547 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 2104.785617 seconds. +% Iteration number 8. +% Pausing for 5 minutes to cool the CPU before starting run number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 2220.351267 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 2374.974797 seconds. +% Iteration number 10. +% Pausing for 5 minutes to cool the CPU before starting run number 10. +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 2699.324960 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 369 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200528_150155' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200527_224901_4_369'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 2619.929782 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 2950.872142 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% +% GWMCMC 11.0% [****····································] 00:00:40 +% 73% rejected +% 25 +% 24.9 +% 4.18 +% 8.6 +% 10.9 +% 10.1 +% 28.9 +% 5.9 +% 15 +% +% +% % this has both 9.7 as the tau and the las limits relaxed to 20. see evernote. +% proj_ZSIFFL_trainingF_v2('stepSize', 1.2,... +% 'nW', 200,... +% 'nPoints', 100*200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0002 0.0001 0.0001 0.00005 0.00005 0.000025],... +% 'stepLadder', [1]) +% +% tladder = +% +% 1.0e+03 * +% +% 1.4763 0.7381 0.7381 0.3691 0.3691 0.1845 +% +% Current temperature: 1476 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200527_151014' +% +% Project directory does not exist. Creating it, and using this to store data +% (in a subdirectory named 'simdata_20200527_151014_1_1476'). +% +% ############################################ +% +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 13.442223 seconds. +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 13.517321 seconds. +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 14.067345 seconds. +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 11.149971 seconds. +% Testing integrability for dose number 1. +% Testing integrability for dose number 2. +% Testing integrability for dose number 3. +% Testing integrability for dose number 4. +% Testing integrability for dose number 5. +% Testing integrability for dose number 6. +% Testing integrability for dose number 7. +% Elapsed time is 13.229422 seconds. +% 600 points out of 600 are integrable. Need 200 walkers. +% Step size ladder being used, skipping burn in phase +% +% ans = +% +% 1 +% +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 1579.520505 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 1723.842851 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 1778.020447 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 1753.187650 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 1728.074410 seconds. +% Iteration number 6. +% Pausing for 5 minutes to cool the CPU before starting run number 6. +% starting mcmc 6 +% current step size: 1.200000e+00 +% ending mcmc 6 +% Elapsed time is 1693.210388 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 1677.295291 seconds. +% Iteration number 8. +% Pausing for 5 minutes to cool the CPU before starting run number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 1630.838864 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 1635.793370 seconds. +% Iteration number 10. +% Pausing for 5 minutes to cool the CPU before starting run number 10. +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 1583.805603 seconds. +% +% initialization_used = +% +% 'LHS' +% +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200527_201627' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200527_151014_2_738'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 1644.988380 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 1638.944014 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 1644.486967 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 1661.804370 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 1696.801386 seconds. +% +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% % TODO +% % these are not done.. idk if i will have the time. maybe sneak these in sometim. +% % check if LHS comes to the same solution: +% proj_ZSIFFL_trainingE_v2('stepSize', 1.2,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 20,... +% 'temperatureLadder', [0.0002 0.0001 0.00005],... +% 'stepLadder', [1]) +% +% % check if the stuck chains and the chains in the other line move to the main line at high temps. +% proj_ZSIFFL_trainingE_v2('stepSize', 1.04,... +% 'nW', 480,... +% 'nPoints', 100*480,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 26,... +% 'temperatureLadder', [0.001 0.0002 0.0001 0.00005],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200527_033000_1_37',... +% 'prevtstampID', 1) +% +% +% +% +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% %------------------------------------------------------------ +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% %------------------------------------------------------------ +% proj_ZSIFFL_trainingE_v2('stepSize', 1.04,... +% 'nW', 480,... +% 'nPoints', 100*480,... +% 'thinning', 10,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 26,... +% 'temperatureLadder', [0.00001 0.000007 0.00001 0.00003 0.00003 0.00003 0.00003],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200527_033000_1_37',... +% 'prevtstampID', 1) +% +% tladder = +% +% 73.8141 51.6699 73.8141 221.4424 221.4424 221.4424 221.4424 +% +% Current temperature: 74 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200527_045239' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200527_045239_1_74'). +% . +% . +% . +% . +% . +% . +% . +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200527_132349' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200527_045239_3_74'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.040000e+00 +% ending mcmc 1 +% Elapsed time is 3798.456496 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.040000e+00 +% +% GWMCMC 43.0% [*****************·······················] 00:00:49 +% 82% rejected +% 22.6 +% 9.16 +% 3.98 +% 2.77 +% 9.66 +% 8.53 +% 31.5 +% 4.47 +% 13.1 +% +% +% +% +% +% +% +% +% +% +% %------------------------------------------------------------ +% +% proj_ZSIFFL_trainingE_v2('stepSize', 1.05,... +% 'nW', 480,... +% 'nPoints', 100*480,... +% 'thinning', 10,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'temperatureLadder', [0.000005 0.000007 0.00001 0.00003 0.00003 0.00003 0.00003],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200526_204312_1_258',... +% 'prevtstampID', 6) +% tladder = +% +% 36.9071 51.6699 73.8141 221.4424 221.4424 221.4424 221.4424 +% +% Current temperature: 37 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200527_033000' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200527_033000_1_37'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.050000e+00 +% ending mcmc 1 +% Elapsed time is 3992.590295 seconds. +% +% +% %------------------------------------ +% +% +% +% +% +% +% +% +% +% +% +% proj_ZSIFFL_trainingE_v2('stepSize', 1.07,... +% 'nW', 480,... +% 'nPoints', 100*480,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 26,... +% 'temperatureLadder', [0.000035 0.00002 0.00001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200526_033216_2_369',... +% 'prevtstampID', 6) +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200526_204312' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200526_204312_1_258'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.070000e+00 +% ending mcmc 1 +% Elapsed time is 3608.104743 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.070000e+00 +% ending mcmc 2 +% Elapsed time is 3671.618699 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.070000e+00 +% ending mcmc 3 +% Elapsed time is 3716.979950 seconds. +% Iteration number 4. +% starting mcmc 4 +% current step size: 1.070000e+00 +% ending mcmc 4 +% Elapsed time is 3670.435221 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.070000e+00 +% ending mcmc 5 +% Elapsed time is 3623.805290 seconds. +% +% % ---------------------------------------------------------- +% +% proj_ZSIFFL_trainingE_v2('stepSize', 1.07,... +% 'nW', 480,... +% 'nPoints', 100*480,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 22,... +% 'temperatureLadder', [0.0001 0.00005 0.00002 0.00001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200525_201859_2_1476',... +% 'prevtstampID', 2) +% +% +% tladder = +% +% 738.1415 369.0707 147.6283 73.8141 +% +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200526_033216' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200526_033216_1_738'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.070000e+00 +% ending mcmc 1 +% Elapsed time is 3764.578412 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.070000e+00 +% ending mcmc 2 +% Elapsed time is 3776.959224 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.070000e+00 +% ending mcmc 3 +% Elapsed time is 3791.021571 seconds. +% Iteration number 4. +% starting mcmc 4 +% current step size: 1.070000e+00 +% ending mcmc 4 +% Elapsed time is 3811.608027 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.070000e+00 +% ending mcmc 5 +% Elapsed time is 3784.770744 seconds. +% Iteration number 6. +% starting mcmc 6 +% current step size: 1.070000e+00 +% ending mcmc 6 +% Elapsed time is 3796.370411 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.070000e+00 +% ending mcmc 7 +% Elapsed time is 3800.666527 seconds. +% Iteration number 8. +% starting mcmc 8 +% current step size: 1.070000e+00 +% ending mcmc 8 +% Elapsed time is 3774.052860 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.070000e+00 +% ending mcmc 9 +% Elapsed time is 3755.500666 seconds. +% Iteration number 10. +% starting mcmc 10 +% current step size: 1.070000e+00 +% ending mcmc 10 +% Elapsed time is 3690.292679 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 369 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200526_140215' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200526_033216_2_369'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.070000e+00 +% ending mcmc 1 +% Elapsed time is 3695.899260 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.070000e+00 +% ending mcmc 2 +% Elapsed time is 3854.531759 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.070000e+00 +% ending mcmc 3 +% Elapsed time is 3891.521085 seconds. +% Iteration number 4. +% starting mcmc 4 +% current step size: 1.070000e+00 +% ending mcmc 4 +% Elapsed time is 3852.394801 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.070000e+00 +% ending mcmc 5 +% Elapsed time is 3893.928171 seconds. +% Iteration number 6. +% starting mcmc 6 +% current step size: 1.070000e+00 +% ending mcmc 6 +% Elapsed time is 3765.807443 seconds. +% +% +% % -------------------------------------------------------------- +% +% proj_ZSIFFL_trainingE_v2('stepSize', 1.1,... +% 'nW', 480,... +% 'nPoints', 100*480,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 22,... +% 'temperatureLadder', [ 0.00025 0.0002 0.00015 0.0001 0.00008 0.00005 0.00002 0.00001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20200525_181748_1_1845',... +% 'prevtstampID', 2) +% +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 1.8454 1.4763 1.1072 0.7381 0.5905 0.3691 0.1476 0.0738 +% +% Current temperature: 1845 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200525_201859' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200525_201859_1_1845'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.100000e+00 +% ending mcmc 1 +% Elapsed time is 3524.319948 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.100000e+00 +% ending mcmc 2 +% Elapsed time is 3561.751503 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.100000e+00 +% ending mcmc 3 +% Elapsed time is 3375.998114 seconds. +% Iteration number 4. +% starting mcmc 4 +% current step size: 1.100000e+00 +% ending mcmc 4 +% Elapsed time is 3449.591700 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.100000e+00 +% ending mcmc 5 +% Elapsed time is 3404.951576 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 1476 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200526_010804' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200525_201859_2_1476'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.100000e+00 +% ending mcmc 1 +% Elapsed time is 3504.807797 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.100000e+00 +% ending mcmc 2 +% Elapsed time is 3588.091873 seconds. +% +% % ----------------------------------------------------------------------- +% +% +% proj_ZSIFFL_trainingE_v2('stepSize', 1.1,... +% 'nW', 480,... +% 'nPoints', 100*480,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [ 0.00025 0.0001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190512_155207_1_1845',... +% 'prevtstampID', 7) +% +% Current temperature: 1845 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingE_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingE_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200525_181748' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200525_181748_1_1845'). +% +% ############################################ +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.100000e+00 +% ending mcmc 1 +% Elapsed time is 3549.535720 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.100000e+00 +% ending mcmc 2 +% Elapsed time is 3489.609662 seconds. +% +% +% +% % ----------------------------------------------------------------------- +% +% +% % ----------------------------------------------------------------------- +% +% +% % ----------------------------------------------------------------------- +% +% +% +% +% % ----------------------------------------------------------------------- +% +% % running on the default profile! temps sitting at 70 - 75C. seems to do a run in 3825 seconds. +% % with 24 coes in eco mode, this time is: 3900. so not really a significant increase. +% % and temperature wise eco mode is a lot better +% +% +% +% +% % ----------------------------------------------------------------------- +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 20,... +% 'pausemode', false,... +% 'temperatureLadder', [0.00018 0.00012 0.00008 0.00004 0.00002],... +% 'prevtstamp', '20200524_233515_1_2214',... +% 'prevtstampID', 10) +% +% +% +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 20). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 20 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 1.3287 0.8858 0.5905 0.2953 0.1476 +% +% Current temperature: 1329 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200525_114752' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200525_114752_1_1329'). +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 4139.217076 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 4251.798351 seconds. +% % ----------------------------------------------------------------------- +% +% +% +% % 16 threads, eco mode +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 16,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0003 0.0003],... +% 'prevtstamp', '20200524_185508_1_2214',... +% 'prevtstampID', 4) +% % run 1: 4303 seconds, +% % run 2: 4419 seconds +% % instantaneous ensemble average effective clock speed: 1950 MHz (instantaneous averages over 32 threads) +% % time average of ensemble average effective clock speed: 1823 +% +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 2.2144 2.2144 +% +% Current temperature: 2214 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200524_233515' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200524_233515_1_2214'). +% +% +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 4303.465326 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 4392.309262 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 4291.811187 seconds. +% Iteration number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 4258.890747 seconds. +% Iteration number 5. +% Mixup round! The step size for this iteration is set to +% 1 * 1.200000e+00 = 1.200000e+00. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 4419.825923 seconds. +% Iteration number 6. +% starting mcmc 6 +% current step size: 1.200000e+00 +% ending mcmc 6 +% Elapsed time is 4370.744514 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 4395.382659 seconds. +% Iteration number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 4422.488004 seconds. +% +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% +% +% +% % 20 threads, eco mode +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 20,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0003 0.0003],... +% 'prevtstamp', '20200524_163232_1_2214',... +% 'prevtstampID', 2) +% % time per run: 4122 seconds, run 2: 3917, run 3: 4019 +% % instantaneous ensemble average effective clock speed: 2350 MHz (instantaneous averages over 32 threads) +% % time average of ensemble average effective clock speed: 2250, 2216 +% +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 20 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 2.2144 2.2144 +% +% Current temperature: 2214 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200524_185508' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200524_185508_1_2214'). +% +% +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % 22 threads, eco mode +% +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 22,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0003 0.0003],... +% 'prevtstamp', '20200524_140951_1_2214',... +% 'prevtstampID', 2) +% +% % time per run: 4076 seconds, run 2: 4066 seconds +% % instantaneous ensemble average effective clock speed: 2500 MHz (instantaneous averages over 32 threads) +% % time average of ensemble average effective clock speed: 2401 +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 4076.818058 seconds. +% +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200524_163232' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200524_163232_1_2214'). +% +% ############################################ +% +% +% +% +% +% +% +% +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% %-------------------------------------------------------------------- +% +% +% +% % 30 cores eco mode +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 30,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0003 0.0003],... +% 'prevtstamp', '20200524_123605_1_2214',... +% 'prevtstampID', 1) +% +% % 30 threads. lets see how this goes. +% % time per run: 4120 seconds, run 2: 4082 +% % average effective clock speed: 2700-3200 +% % average of average effective clock speed: 2975 +% +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200524_140951' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200524_140951_1_2214'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 4120.322531 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 4082.624658 seconds. +% +% ############################################ +% +% +% +% +% +% +% +% +% +% +% +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ------------------------------------------------- +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 16,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0003 0.0002],... +% 'prevtstamp', '20200523_200855_2_2214',... +% 'prevtstampID', 4) +% % QUESTION IS IF THE TIME TAKEN WILL BE MORE OR LESS WITH 16 CORES. ALSO TRY +% % 20 CORES, AND 32 CORES. THEN WE WILL HAVE A NICE SET OF DATA POINTS. +% % time for a run = 4500 seconds +% % effective clock speed: 1900MHz (all 32 threads) +% +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 2.2144 1.4763 +% +% Current temperature: 2214 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200524_123605' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200524_123605_1_2214'). +% +% ############################################ +% +% %---------% ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ---------------------------------------------------------------- +% +% +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'stepLadder', [],... +% 'poolsize', 24,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0005 0.0003 0.0002],... +% 'prevtstamp', '20200523_135237_1_5536',... +% 'prevtstampID', 5) +% +% % NOTE THE 24 THREADS: time for a run: 4000 seconds +% % Effecti=ve clock speed: 2700MHz. all 32threads +% % time averaged is probably around 2600? +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 3.6907 2.2144 1.4763 +% +% +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 24). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 24 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 3.6907 2.2144 1.4763 +% +% Current temperature: 3691 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200523_200855' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200523_200855_1_3691'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 3948.928533 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 3948.995872 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 3989.391465 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 4038.652555 seconds. +% Iteration number 5. +% Mixup round! The step size for this iteration is set to +% 1 * 1.200000e+00 = 1.200000e+00. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 4075.281491 seconds. +% Iteration number 6. +% Pausing for 5 minutes to cool the CPU before starting run number 6. +% starting mcmc 6 +% current step size: 1.200000e+00 +% ending mcmc 6 +% Elapsed time is 4170.121697 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 4125.102159 seconds. +% Iteration number 8. +% Pausing for 5 minutes to cool the CPU before starting run number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 3963.097530 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 3954.981484 seconds. +% Iteration number 10. +% Pausing for 5 minutes to cool the CPU before starting run number 10. +% Mixup round! The step size for this iteration is set to +% 1 * 1.200000e+00 = 1.200000e+00. +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 3957.902806 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 2214 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200524_074349' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200523_200855_2_2214'). +% +% ############################################ +% +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 24). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 24 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% ending mcmc 1 +% Elapsed time is 3999.003327 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.200000e+00 +% ending mcmc 2 +% Elapsed time is 4055.004786 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.200000e+00 +% ending mcmc 3 +% Elapsed time is 4036.793049 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 4078.355643 seconds. +% Iteration number 5. +% Mixup round! The step size for this iteration is set to +% 1 * 1.200000e+00 = 1.200000e+00. +% starting mcmc 5 +% current step size: 1.200000e+00 +% +% +% +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% % ----------------------------------------------------------------------- +% %---------------------------------------------------------------------------------------- +% +% +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.00075 0.0005 0.0005 0.00025 0.00025],... +% 'prevtstamp', '20200523_044512_2_5536',... +% 'prevtstampID', 3) +% +% +% +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 16). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 5.5361 3.6907 3.6907 1.8454 1.8454 +% +% Current temperature: 5536 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200523_135237' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200523_135237_1_5536'). +% +% ############################################ +% +% +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.320000e+00 +% ending mcmc 1 +% Elapsed time is 3319.830474 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.280000e+00 +% ending mcmc 2 +% Elapsed time is 3544.020435 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.240000e+00 +% ending mcmc 3 +% Elapsed time is 3835.236316 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 4269.744037 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 4283.711301 seconds. +% +% +% -------------------------------------------------------- +% +% +% +% +% +% +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.001 0.00075 0.00075 0.0005 0.0005 0.00025 0.00025],... +% 'prevtstamp', '20200522_224032_1_7381',... +% 'prevtstampID', 5) +% +% +% +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 7.3814 5.5361 5.5361 3.6907 3.6907 1.8454 1.8454 +% +% Current temperature: 7381 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200523_044512' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200523_044512_1_7381'). +% +% ############################################ +% +% +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.320000e+00 +% ending mcmc 1 +% Elapsed time is 3477.701745 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.280000e+00 +% ending mcmc 2 +% Elapsed time is 3779.390779 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.240000e+00 +% ending mcmc 3 +% Elapsed time is 3912.653680 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% ending mcmc 4 +% Elapsed time is 4289.022254 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.200000e+00 +% ending mcmc 5 +% Elapsed time is 4315.906966 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 5536 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200523_102506' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200523_044512_2_5536'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.320000e+00 +% ending mcmc 1 +% Elapsed time is 3410.332140 seconds. +% Iteration number 2. +% Pausing for 5 minutes to cool the CPU before starting run number 2. +% starting mcmc 2 +% current step size: 1.280000e+00 +% ending mcmc 2 +% Elapsed time is 3666.679864 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.240000e+00 +% ending mcmc 3 +% Elapsed time is 3937.126962 seconds. +% Iteration number 4. +% Pausing for 5 minutes to cool the CPU before starting run number 4. +% starting mcmc 4 +% current step size: 1.200000e+00 +% +% +% ----------------------------------------- +% +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.001 0.00075 0.0005 0.0002 0.0001],... +% 'prevtstamp', '20200521_154748_3_14763',... +% 'prevtstampID', 8) +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 15 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 7.3814 5.5361 3.6907 1.4763 0.7381 +% +% Current temperature: 7381 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200522_224032' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200522_224032_1_7381'). +% %--------------------------------------------------------------------------------- +% +% +% +% +% proj_ZSIFFL_trainingC_v3('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 15,... +% 'temperatureLadder', [0.01 0.005 0.002 0.001 0.00075 0.0005 0.0002 0.0001]) +% +% +% +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 15). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 15 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+04 * +% +% 7.3814 3.6907 1.4763 0.7381 0.5536 0.3691 0.1476 0.0738 +% +% Current temperature: 73814 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v3' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v3' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200521_154748' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200521_154748_1_73814'). +% +% ############################################ +% +% %--------------------------------------------------------- +% +% +% +% +% +% +% proj_ZSIFFL_trainingC_v2('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'temperatureLadder', [0.01 0.005 0.002 0.001 0.00075 0.0005 0.0002 0.0001]) +% +% tladder = +% +% 1.0e+04 * +% +% 7.3814 3.6907 1.4763 0.7381 0.5536 0.3691 0.1476 0.0738 +% +% Current temperature: 73814 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingC_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingC_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200521_005205' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200521_005205_1_73814'). +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% %------------------------------------------------------------------------ +% +% proj_ZSIFFL_trainingD_v2('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'temperatureLadder', [0.0004 0.0002 0.0001],... +% 'prevtstamp', '20200520_173710_1_73814',... +% 'prevtstampID', 9) +% +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 16). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 2.9526 1.4763 0.7381 +% +% Current temperature: 2953 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingD_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200520_230212' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200520_230212_1_2953'). +% +% ############################################ +% +% %------------------------------------------------------------------------------------ +% +% +% +% +% % too hot. not a good fit. see evernote 040 MAY 2020 ZSIFFL +% proj_ZSIFFL_trainingD_v2('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'temperatureLadder', [0.01 0.005 0.0025 0.001],... +% 'prevtstamp', '20200519_181148_3_2953',... +% 'prevtstampID', 4) +% +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+04 * +% +% 7.3814 3.6907 1.8454 0.7381 +% +% Current temperature: 73814 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingD_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200520_173710' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200520_173710_1_73814'). +% +% ############################################ +% +% +% +% +% +% +% +% +% % Looks like the chains arent mixing as well. so i think we try raising the temps a lot (to 0.01) and scale down to 0.001. +% +% +% +% proj_ZSIFFL_trainingD_v2('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 15,... +% 'parallel', true, ... +% 'poolsize', 14,... +% 'temperatureLadder', [0.00075 0.0005 0.0004 0.0003 0.0002 0.0001],... +% 'prevtstamp', '20200519_011552_2_5536',... +% 'prevtstampID', 6) +% +% +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 5.5361 3.6907 2.9526 2.2144 1.4763 0.7381 +% +% Current temperature: 5536 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingD_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200519_181148' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200519_181148_1_5536'). +% +% ############################################ +% +% tladder = +% +% 1.0e+03 * +% +% 5.5361 3.6907 2.9526 2.2144 1.4763 0.7381 +% +% Current temperature: 5536 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingD_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200519_181148' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200519_181148_1_5536'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.320000e+00 +% ending mcmc 1 +% Elapsed time is 2210.174466 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.320000e+00 +% ending mcmc 2 +% Elapsed time is 2214.431175 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.280000e+00 +% ending mcmc 3 +% Elapsed time is 2142.348140 seconds. +% Iteration number 4. +% starting mcmc 4 +% current step size: 1.280000e+00 +% ending mcmc 4 +% Elapsed time is 2261.987848 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.240000e+00 +% ending mcmc 5 +% Elapsed time is 2372.090672 seconds. +% Iteration number 6. +% starting mcmc 6 +% current step size: 1.240000e+00 +% ending mcmc 6 +% Elapsed time is 2409.592600 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 2599.087726 seconds. +% Iteration number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 2823.869639 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 2802.134105 seconds. +% Iteration number 10. +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 2553.171344 seconds. +% Iteration number 11. +% starting mcmc 11 +% current step size: 1.200000e+00 +% ending mcmc 11 +% Elapsed time is 2531.097156 seconds. +% Iteration number 12. +% starting mcmc 12 +% current step size: 1.200000e+00 +% ending mcmc 12 +% Elapsed time is 2533.969690 seconds. +% Iteration number 13. +% starting mcmc 13 +% current step size: 1.200000e+00 +% ending mcmc 13 +% Elapsed time is 2536.949839 seconds. +% Iteration number 14. +% starting mcmc 14 +% current step size: 1.200000e+00 +% ending mcmc 14 +% Elapsed time is 2572.635250 seconds. +% Iteration number 15. +% starting mcmc 15 +% current step size: 1.200000e+00 +% ending mcmc 15 +% Elapsed time is 2517.574239 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 3691 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingD_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200520_043019' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200519_181148_2_3691'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.320000e+00 +% ending mcmc 1 +% Elapsed time is 2063.881000 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.320000e+00 +% ending mcmc 2 +% Elapsed time is 2064.260924 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.280000e+00 +% ending mcmc 3 +% Elapsed time is 2191.519664 seconds. +% Iteration number 4. +% starting mcmc 4 +% current step size: 1.280000e+00 +% ending mcmc 4 +% Elapsed time is 2223.035443 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.240000e+00 +% ending mcmc 5 +% Elapsed time is 2341.746961 seconds. +% Iteration number 6. +% starting mcmc 6 +% current step size: 1.240000e+00 +% ending mcmc 6 +% Elapsed time is 2399.007359 seconds. +% Iteration number 7. +% starting mcmc 7 +% current step size: 1.200000e+00 +% ending mcmc 7 +% Elapsed time is 2566.596137 seconds. +% Iteration number 8. +% starting mcmc 8 +% current step size: 1.200000e+00 +% ending mcmc 8 +% Elapsed time is 2564.533153 seconds. +% Iteration number 9. +% starting mcmc 9 +% current step size: 1.200000e+00 +% ending mcmc 9 +% Elapsed time is 2555.117758 seconds. +% Iteration number 10. +% starting mcmc 10 +% current step size: 1.200000e+00 +% ending mcmc 10 +% Elapsed time is 2571.915896 seconds. +% Iteration number 11. +% starting mcmc 11 +% current step size: 1.200000e+00 +% ending mcmc 11 +% Elapsed time is 2568.428106 seconds. +% Iteration number 12. +% starting mcmc 12 +% current step size: 1.200000e+00 +% ending mcmc 12 +% Elapsed time is 2598.123690 seconds. +% Iteration number 13. +% starting mcmc 13 +% current step size: 1.200000e+00 +% ending mcmc 13 +% Elapsed time is 2617.615356 seconds. +% Iteration number 14. +% starting mcmc 14 +% current step size: 1.200000e+00 +% ending mcmc 14 +% Elapsed time is 2641.267944 seconds. +% Iteration number 15. +% starting mcmc 15 +% current step size: 1.200000e+00 +% ending mcmc 15 +% Elapsed time is 2731.392442 seconds. +% +% initialization_used = +% +% 'User_initialized' +% +% Current temperature: 2953 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingD_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200520_144159' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200519_181148_3_2953'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.320000e+00 +% ending mcmc 1 +% Elapsed time is 2229.921641 seconds. +% Iteration number 2. +% starting mcmc 2 +% current step size: 1.320000e+00 +% ending mcmc 2 +% Elapsed time is 2195.816288 seconds. +% Iteration number 3. +% starting mcmc 3 +% current step size: 1.280000e+00 +% ending mcmc 3 +% Elapsed time is 2336.074255 seconds. +% Iteration number 4. +% starting mcmc 4 +% current step size: 1.280000e+00 +% ending mcmc 4 +% Elapsed time is 2408.353332 seconds. +% Iteration number 5. +% starting mcmc 5 +% current step size: 1.240000e+00 +% +% GWMCMC 40.0% [****************························] 00:00:12 +% 78% rejected +% 4.6 +% 1.86 +% 19.8 +% -2.19 +% 19.8 +% 9.68 +% 9.46 +% 6.29 +% 10.6 +% 34 +% 4.34 +% 7.18 +% % =------------------------------------------------------------------------ +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% proj_ZSIFFL_trainingD_v2('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'temperatureLadder', [0.001 0.00075 0.0005 0.0004 0.0003 0.0002 0.0001],... +% 'prevtstamp', '20200518_175057_1_7381',... +% 'prevtstampID', 3) +% Connected to the parallel pool (number of workers: 14). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 14 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 7.3814 5.5361 3.6907 2.9526 2.2144 1.4763 0.7381 +% +% Current temperature: 7381 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingD_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200519_011218' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200519_011218_1_7381'). +% +% ############################################ +% ------------------------------------------ +% +% proj_ZSIFFL_trainingD_v2('stepSize', 1.2,... +% 'nW', 4000,... +% 'nPoints', 50*4000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 15,... +% 'temperatureLadder', [0.001 0.00075 0.0005 0.0004 0.0003 0.0002 0.0001]) +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% Connected to the parallel pool (number of workers: 15). +% +% ans = +% +% ProcessPool with properties: +% +% Connected: true +% NumWorkers: 15 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 7.3814 5.5361 3.6907 2.9526 2.2144 1.4763 0.7381 +% +% Current temperature: 7381 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingD_v2' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingD_v2' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200518_175057' +% +% Project directory does not exist. Creating it, and using this to store data +% (in a subdirectory named 'simdata_20200518_175057_1_7381'). +% +% ############################################ +% +% ------------------------------------------------------------------ +% % mcmc20200518_002303_1_738_ID25 +% seems to run at 68C at 4.05Ghz, 1.275V, +% (note the 18 cores, ) +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 100,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'pausemode', false,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200517_172041_1_738',... +% 'prevtstampID', 7) +% +% +% +% running at 4.05GHz, at 1.1875vCore +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200517_072406_1_738',... +% 'prevtstampID', 15) +% +% +% +% +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200517_054605_1_738',... +% 'prevtstampID', 2) +% running at 4.15GHz, 1.275vCore +% was running at 72-73C +% +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200517_072406' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200517_072406_1_738'). +% +% ending mcmc 1 +% Elapsed time is 2266.359544 seconds. +% ending mcmc 2 +% Elapsed time is 2209.799429 seconds. +% ending mcmc 3 +% Elapsed time is 2234.486761 seconds. +% ending mcmc 4 +% Elapsed time is 2215.601278 seconds. +% ending mcmc 5 +% Elapsed time is 2199.181304 seconds. +% ending mcmc 6 +% Elapsed time is 2225.188544 seconds. +% ending mcmc 7 +% Elapsed time is 2216.940259 seconds. +% ending mcmc 8 +% Elapsed time is 2231.308278 seconds. +% ending mcmc 9 +% Elapsed time is 2342.891549 seconds. +% ending mcmc 10 +% Elapsed time is 2358.553416 seconds. +% ending mcmc 11 +% Elapsed time is 2372.324346 seconds. +% ending mcmc 12 +% Elapsed time is 2319.315386 seconds. +% ending mcmc 13 +% Elapsed time is 2304.523491 seconds. +% ending mcmc 14 +% Elapsed time is 2357.569565 seconds. +% ending mcmc 15 +% Elapsed time is 2327.228624 seconds. +% -0-------------------------------------------------------------- +% +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200516_183508_1_738',... +% 'prevtstampID', 1) +% +% +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 738.1415 +% +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200517_054605' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200517_054605_1_738'). +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% -0--------------------------------------------0- +% +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 15,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200516_175823_1_738',... +% 'prevtstampID', 1) +% +% +% +% NOT POSSIBLLE TO apply OC on startup, for obvious reasons. +% It’s not possible to apply RM at startup. +% I ran into this issue as well and just bit the bullet and went the bios route +% I believe that was a design decision to avoid boot-loops for +% unstable OC. It can be difficult to boot into safe mode these days... +% +% % this is with the intel math kernel set to not discriminate between AMD and +% Intel. +% +% 4.15GhZ, 1.25 +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200516_062411_1_738',... +% 'prevtstampID', 19) +% +% How-To force Matlab to use a fast codepath on AMD Ryzen/TR CPUs - up to 250% +% performance gains +% Tips +% FINAL UPDATE: Version R2020a released in March 2020 uses the AVX2 codepath on +% compatible AMD CPUs automatically. +% Hence, if you are running this version, you do not need to manually set the +% environmental variable on your system anymore. +% +% THANKS MATLAB! This is great! +% +% For previous generations of Matlab, you can still follow the below procedures. +% +% ----- +% +% Hello everyone. +% +% I wanted to briefly present my tweak here, as I think it might be of interest for +% many in this community. Applying the tweak takes less than a minute. +% +% What is it? +% +% Matlab runs notoriously slow on AMD CPUs for operations that use the Intel Math +% Kernel Library (MKL). +% This is because the Intel MKL uses a discriminative CPU Dispatcher that does not +% use efficient codepath +% according to SIMD support by the CPU, but based on the result of a vendor string +% query. If the CPU is from AMD, +% the MKL does not use SSE3-SSE4 or AVX1/2 extensions but falls back to SSE1 no ma +% tter whether the AMD CPU supports +% more efficient SIMD extensions like AVX2 or not. +% +% The method provided here does enforce AVX2 support by the MKL, independent of the +% vendor string result. +% +% EDIT: Before you start I have a short request for you that you could help me wit +% h and serve your own interest. +% Matlab will not implement this fix as it is based on an unofficial debug mode of +% the MKL. If you think that +% Matlab should offer a permanent solution that serves all users independently of +% whether they use Intel or AMD CPUs, +% please make a feature request at Matlab to implement a nummeric library (e.g. +% OpenBLAS) that does not +% discriminate against non Intel CPUs. Mathworks will not make this change +% without people advocating for it. Thanks! +% +% tl;dr: +% +% WINDOWS: +% +% You'll read below "How To" force the MKL to use AVX2 on AMD Ryzen or Threadripper +% CPUs. Performance gains +% on my 2600x are between 20% and 300% depending on the type of numeric operation. +% +% Benchmark result comparison. +% +% Benchmark taken from here +% +% Post image +% Integrated benchmark results: +% +% Post image +% Feedback is appreciated in the comments section. +% +% Disclaimer: I OF COURSE DO NOT TAKE RESPONSIBILITY FOR ISSUES RESULTING IN USING +% THIS TWEAK. +% USE ON AMD RYZEN OR THREADRIPPER ONLY. DOES NOT WORK ON INTEL OR OLDER AMD CPUs. +% +% Solution 1 (Windows - no admin rights needed): +% +% Create a .bat file with the following lines to start Matlab in AVX2 Mode +% +% @echo off +% set MKL_DEBUG_CPU_TYPE=5 +% matlab.exe +% This is straight forward. You open Notepad, copy and paste the above three +% lines and save +% the file as Matlab-AVX2. Notepad will save the file as Matlab-AVX2.txt. +% Now replace the extension ".txt" with ".bat". +% +% If you double-click that file, Matlab will start the MKL in AVX2 Mode. +% If you start it the +% normal way, it will remain as always. +% +% You can also download the .bat file from my HiDrive if you trust me (which +% you of course +% should not, as I am a random guy in the Internet). If you delete the startup +% batch file provided in the download or the one you created yourself, its +% gone and your computer will be as it has been before. +% +% (Optional Download: https://my.hidrive.com/lnk/EHAACFje ) --> also incl. +% improved benchmark +% script +% +% Solution 2 (Windows - admin rights needed): If you are happy with the results +% (which you will be :-)), you should make the setting permanent by entering +% MKL_DEBUG_CPU_TYPE=5 into the System Environment Variables. This has several +% advantages, one of them being that it applies to all instances of Matlab and +% not just the one opened using the .bat file. +% +% Post image +% Image courtesy, Dr. F. Haiss, and many thanks for testing on a Threadripper! +% +% You can do this either by editing the Environmental Variables as shown above, +% or by opening a command prompt (CMD) with admin rights and typing in: +% +% setx /M MKL_DEBUG_CPU_TYPE 5 +% Doing this will make the change permanent and available to ALL Programs using +% the MKL on your system until you delete the entry again from the variables.' +% +% -------------------------------------------------------------------------------- +% -------------------- +% +% +% +% 4.15ghz, 1.25 V +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200515_184104_1_738',... +% 'prevtstampID', 5) +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 16 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 738.1415 +% +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200516_062411' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200516_062411_1_738'). +% +% ############################################ +% +% +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 14,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200515_052639_1_738',... +% 'prevtstampID', 20) +% +% +% +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200515_023833_1_738',... +% 'prevtstampID', 4) +% +% +% +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 14,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200514_183027_1_738',... +% 'prevtstampID', 5) +% +% +% ------------------------------------------------------------------------ +% +% % Visualize this, and decide on the step ladder including the error bars etc. +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 16,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200514_165204_1_738',... +% 'prevtstampID', 2) +% 20200514_165204_1_738 +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200514_183027' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200514_183027_1_738'). +% +% ############################################ +% +% +% +% % Visualize this, and decide on the step ladder including the error bars etc. +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 50*1000,... +% 'thinning', 10,... +% 'nIter', 50,... +% 'parallel', true, ... +% 'poolsize', 12,... +% 'pausemode', true,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200513_222442_1_738',... +% 'prevtstampID', 12) +% %20200513_222442_1_738_ID12 +% +% +% +% +% +% +% +% +% % Visualize this, and decide on the step ladder including the error bars etc. +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 50,... +% 'parallel', true, ... +% 'poolsize', 14,... +% 'temperatureLadder', [0.0001],... +% 'prevtstamp', '20200511_052714_2_738',... +% 'prevtstampID', 10) +% +% +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% connected to 14 workers. +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 14 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 738.1415 +% +% Current temperature: 738 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF' +% +% Directory where the project file is stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects' +% +% Directory where data will be stored: +% 'D:\txtl\txtlsim\mcmc_simbio\projects\proj_ZSIFFL_trainingF' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200513_222442' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200513_222442_1_738'). +% +% ############################################ +% +% +% % --------------------------------- +% % looks like the second one is the best one. so that is the temp we +% will run things at for a while +% %20200511_05271 +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 100*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0002 0.0001 0.00005 0.00002],... +% 'prevtstamp', '20200510_082735_1_1476',... +% 'prevtstampID', 2) +% % expected end time: 40 hours from 2 am May 12: so at Wed may 13, 9.30 pm. +% +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 18 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 1.4763 0.7381 0.3691 0.1476 +% +% Current temperature: 1476 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_ZSIFFL_trainingF' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_ZSIFFL_trainingF' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200511_052714' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200511_052714_1_1476'). +% +% ############################################ +% +% +% +% % ZSIFFL training thread +% 20200510_082735_1_1476 +% only ran the first 2 iters for the first temp +% proj_ZSIFFL_trainingF('stepSize', 1.2,... +% 'nW', 1000,... +% 'nPoints', 200*1000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 4,... +% 'temperatureLadder', [0.0002 0.0001 0.00005 0.00002]) +% % This is far too long. it taked 10 hours per iteration. +% I need it down to something like 1h. +% % One thing is to up the parallel pool ot 8 workers. +% % Then to lower the number of computations per iteration to +% +% +% % --------------------------------- +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% +% % --------------------------------- +% +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 15,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0014 0.0012 0.001 0.0008],... +% 'stepLadder', [],... +% 'prevtstamp', '20200512_192355_2_38',... +% 'prevtstampID', 10) +% +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% connected to 18 workers. +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 18 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 33.3346 28.5725 23.8104 19.0484 +% +% Current temperature: 33 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200513_063545' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200513_063545_1_33'). +% +% ############################################ +% % --------------------------------- +% +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0018 0.0016],... +% 'stepLadder', [],... +% 'prevtstamp', '20200510_045912_2_48',... +% 'prevtstampID', 30) +% +% +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 18 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 42.8588 38.0967 33.3346 28.5725 23.8104 +% +% Current temperature: 43 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200512_192355' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200512_192355_1_43'). +% +% ############################################ +% +% +% %---------------------------- +% +% +% % once the 0.002 is done, terminate. and do the remaining 30 in a more graded manner: +% % 10iter x 0.003, +% % 10iter x 0.002, +% % 10iter x 0.001, +% % 10iter x 0.0008 +% % 10iter x 0.0007 +% % 10iter x 0.0005 +% % == 60 hours of runtime. See if can finish in 30 hours using a slightly +% bigger machine. +% % that should give nice highly converged values. the only thing to +% be careful about is not to +% % lower the temp too quickly. +% % this is the first run with the fixed parameter ranges. +% % +% % '20200510_045912_1_95' +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.004 0.002],... +% 'stepLadder', [],... +% 'prevtstamp', '20200506_145656_1_48',... +% 'prevtstampID', 8) % currently running as of may 11, 2 pm. +% % expected end time: around Wed early morning hours. may 13 +% +% +% %---------------------------- +% % # this failed too. I had to fix the pol limits, i had put exp(5000) as the upper +% limit, not 5000 (which is like exp 8.5). +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [],... +% 'prevtstamp', '20200506_145656_1_48',... +% 'prevtstampID', 8) +% +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 8 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 47.6209 +% +% Current temperature: 48 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200507_094448' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200507_094448_1_48'). +% +% ############################################ +% +% +% +% +% ---- +% % this failed on the first iter. back tracking to iter 8 on the previous tstamp ID. +% +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [],... +% 'prevtstamp', '20200506_145656_1_48',... +% 'prevtstampID', 10) +% +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 8 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 47.6209 +% +% Current temperature: 48 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200507_071350' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200507_071350_1_48'). +% +% ############################################ +% +% +% ------------------------------------------------------------------------------ +% ------------- +% ------------------------------------------------------------------------------- +% ------------ +% ------------------------------------------------------------------------------- +% ------------ +% ------------------------------------------------------------------------------- +% ------------ +% +% ----- +% +% +% GWMCMC 80.0% [********************************········] 00:00:07 +% 68% rejected +% 0.938 +% 7.6 +% -13 +% 3.18 +% 0.283 +% 13.7 +% -4.97 +% 5.65 +% 11.6 +% 3.43 +% 12 +% 3.98 +% 8.41 +% +% GWMCMC 80.9% [********************************········] 00:00:06 +% 68% rejected +% 1.22 +% 7.83 +% -12.7 +% 3.46 +% 1.08 +% 13.4 +% -5.06 +% 4.95 +% 11.3 +% 2.99 +% 10.3 +% 3.79 +% 8.25 +% +% Warning: A worker aborted during execution of the parfor loop. The parfor loop will +% now run again on the remaining workers. +% > In parallel_function (line 605) +% In gwmcmc_vse (line 251) +% In mcmc_runsim_v2 (line 318) +% In proj_vnprl (line 359) +% Operation terminated by user during distcomp.remoteparfor/getCompleteIntervals (line 227) +% +% +% % prev one failed after 9 iterations. but no error yet. going to go back to 0.002 +% temp. that seemed to work... +% % maybe it keeps working. +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [],... +% 'prevtstamp', '20200506_045247_1_143',... +% 'prevtstampID', 9) +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 8 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 47.6209 +% +% Current temperature: 48 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200506_145656' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200506_145656_1_48'). +% +% ------------------------------------------------------------------------- +% ------------------ +% ------------------------------------------------------------------------- +% ------------------ +% ------------------------------------------------------------------------- +% ------------------ +% ------------------------------------------------------------------------- +% ------------------ +% +% +% % #TAKING A FEW STEPS BACK. AWAY FROM WHATEVER THE HECK WAS GOING ON. +% CAN INVESTIGATE MORE SOMETIME. +% % IF THIS DOES NOT WORK, I WILL GO BACK TO THE SMALLER PARAMETER RANGES. +% ACTUALLY JUST START THE IFFL FITTING. +% % THE VNPRL IS GOOD ENOUGH +% +% +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.006 0.004],... +% 'stepLadder', [],... +% 'prevtstamp', '20200504_063238_1_95',... +% 'prevtstampID', 12) +% +% tladder = +% +% 142.8627 95.2418 +% +% Current temperature: 143 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200506_045247' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200506_045247_1_143'). +% +% ############################################ +% +% % stuck value: +% % GWMCMC 70.0% [****************************············] 00:00:08 +% % 62% rejected +% % 1.53 +% % 9.84 +% % -6.21 +% % 1.4 +% % -3.44 +% % 12 +% % 0.446 +% % 22.1 +% % 4.39 +% % 5.81 +% % 10.6 +% % 3.93 +% % 1.52 +% % GWMCMC 70.9% [****************************············] 00:00:08 +% % 62% rejected +% % 1.53 +% % 9.84 +% % -6.21 +% % 1.4 +% % -3.44 +% % 12 +% % 0.446 +% % 22.1 +% % 4.39 +% % 5.81 +% % 10.6 +% % 3.93 +% % 1.52 +% % GWMCMC 71.8% [****************************············] 00:00:07 +% % 62% rejected +% % 1.53 +% % 9.84 +% % -6.21 +% % 1.4 +% % -3.44 +% % 12 +% % 0.446 +% % 22.1 +% % 4.39 +% % 5.81 +% % 10.6 +% % 3.93 +% % 1.52 +% % GWMCMC 72.7% [*****************************···········] 00:00:07 +% % 62% rejected +% % 1.53 +% % 9.84 +% % -6.21 +% % 1.4 +% % -3.44 +% % 12 +% % 0.446 +% % 22.1 +% % 4.39 +% % 5.81 +% % 10.6 +% % 3.93 +% % 1.52 +% -------- +% -------------------------------------------------------------------------- +% ----------------- +% ------------------------------------------------------------------------- +% ------------------ +% ------------------------------------------------------------------------- +% ------------------ +% ------------------------------------------------------------------------- +% ------------------ +% % SOMEHOW THIS TEMP IS JUST NOT WORKING. I AM GOING TO LOWER THE TEMP SLIGHTLY. +% MAYBE TO JUST 0.008. +% +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.012 0.008 0.004],... +% 'stepLadder', [],... +% 'prevtstamp', '20200504_141525_1_286',... +% 'prevtstampID', 4) +% connected to 18 workers. +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 18 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 285.7253 190.4835 95.2418 +% +% Current temperature: 286 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200505_025140' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200505_025140_1_286'). +% --------------------------------------------------------------------- +% ---------------------- +% ---------------------------------------------------------------------- +% --------------------- +% --------------------------------------------------------------------- +% ---------------------- +% --------------------------------------------------------------------- +% --------------------- +% ---------------------------------------------------------------------- +% --------------------- +% +% Warning: A worker aborted during execution of the parfor loop. +% The parfor loop will now run +% again on the remaining +% workers. +% > In parallel_function (line 605) +% In gwmcmc_vse (line 251) +% In mcmc_runsim_v2 (line 318) +% In proj_vnprl (line 359) +% +% # WORKER ABORTED on the previour run (20200504_141525_1_286) on +% ID 4. wasted 8 hours of +% runtime. +% This is bs. These mistakes are the expensive ones. Might need to +% lower the machine size +% so we can absorb these mistakes. +% I dont check on the machine as often. +% % I am going to up the temperature even more temporarily to get +% good mixing. then will +% lower the temp back down to 95 then 48. +% +% % ssh -i ".ssh/vipulsinghal_112118.pem" ubuntu@spatial-analysis-2.genome.sg +% +% % 20200504_141525_1_286 +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.012 0.008 0.004],... +% 'stepLadder', [],... +% 'prevtstamp', '20200504_063238_1_95',... +% 'prevtstampID', 14) +% +% connected to 18 workers. +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 18 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 285.7253 190.4835 95.2418 +% +% Current temperature: 286 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200504_141525' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200504_141525_1_286'). +% +% ############################################ +% %------------------------------------------------------------------ +% -------------------------- +% +% % 20200504_063238_1_95 +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.004],... +% 'stepLadder', [],... +% 'prevtstamp', '20200503_231938_1_48',... +% 'prevtstampID', 13) % seems like this is a good temp. 20200504_063238_1_95 +% +% ------------------------------------------------------------------- +% +% % looking at the first 12 simdatas, i thik the temp is too low. +% going to raise it slightly. +% maybe from 0.002 to 0.004. +% +% % committed everything to git. the commit id is +% 3b5f619bde2245a1d22b85d54abba228860619c8 +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [],... +% 'prevtstamp', '20200424_135910_1_48',... +% 'prevtstampID', 40) % +% +% +% Current temperature: 48 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200503_231938' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200503_231938_1_48'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% +% +% +% +% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% +% +% %%%%% MODIFICATION TO THE VNPRL F3 FILE TO take the union of its +% ranges with those of F2. +% +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [],... +% 'prevtstamp', '20200423_165501_1_48',... +% 'prevtstampID', 40) % +% +% tladder = +% +% 47.6209 +% +% Current temperature: 48 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200424_135910' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200424_135910_1_48'). +% +% ############################################ +% +% -------------------------------- +% +% +% % 20200423_165501_1_48 +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [],... +% 'prevtstamp', '20200422_074403_2_24',... +% 'prevtstampID', 30) % +% tladder = +% +% 47.6209 +% +% Current temperature: 48 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200423_165501' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200423_165501_1_48'). +% +% ############################################ +% ---------------------------------------------------------------------- +% -------------------- +% ---------------------------------------------------------------------- +% -------------------- +% ---------------------------------------------------------------------- +% -------------------- +% %20200422_074403 +% +% % 20200422_074403_2_24 +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.003 0.001],... +% 'stepLadder', [],... +% 'prevtstamp', '20200421_112043_1_119',... +% 'prevtstampID', 40) % +% +% tladder = +% +% 71.4313 23.8104 +% +% Current temperature: 71 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200422_074403' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200422_074403_1_71'). +% +% +% --------------------------------------------------------------------- +% --------------------- +% ---------------------------------------------------------------------- +% -------------------- +% --------------------------------------------------------------------- +% --------------------- +% % with the new parameter ranges: +% +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.005],... +% 'stepLadder', [],... +% 'prevtstamp', '20200420_205718_3_119',... +% 'prevtstampID', 8) % +% +% +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 18 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 119.0522 +% +% Current temperature: 119 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200421_112043' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200421_112043_1_119'). +% +% ############################################ +% +% User initialized intitial walker positions, skipping burn in phase +% Iteration number 1. +% starting mcmc 1 +% current step size: 1.200000e+00 +% +% +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------------------------ +% proj_vnprl('ver', 'F3',... +% 'stepSize', 1.2,... +% 'nW', 2000,... +% 'nPoints', 101*2000,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.05 0.02 0.005 0.002],... +% 'stepLadder', []) % +% +% estARRAY = +% +% 13x2 cell array +% +% {'TX_elong_glob' } {[ 2.5500]} +% {'AGTPdeg_time' } {[ 8.8350]} +% {'AGTPdeg_rate' } {[ -10]} +% {'TXTL_P70_RNAPbound_Kd' } {[13.7500]} +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} {[ 1.9500]} +% {'TXTL_RNAdeg_Kd' } {[15.6000]} +% {'TXTL_RNAdeg_kc' } {[-2.1000]} +% {'RNAP' } {[ 1.4419]} +% {'RNase' } {[10.5000]} +% {'TL_elong_glob' } {[ 3.3500]} +% {'TXTL_UTR_UTR1_Kd' } {[ 5.7500]} +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} {[ 2.4500]} +% {'Ribo' } {[ 5]} +% +% +% fixARRAY = +% +% 13x2 cell array +% +% {'AGTPreg_ON' } {[-3.9120]} +% {'TXTL_P70_RNAPbound_F' } {[ 1.5000]} +% {'TXTL_NTP_RNAP_1_Kd' } {[ 2.9459]} +% {'TXTL_NTP_RNAP_1_F' } {[ 0]} +% {'TXTL_NTP_RNAP_2_Kd' } {[13.9970]} +% {'TXTL_NTP_RNAP_2_F' } {[ 0]} +% {'TXTL_RNAdeg_F' } {[ 0]} +% {'TXTL_PROT_deGFP_MATURATION'} {[-6.0748]} +% {'TXTL_UTR_UTR1_F' } {[-0.2000]} +% {'TL_AA_Kd' } {[ 6.5566]} +% {'TL_AA_F' } {[-0.3000]} +% {'TL_AGTP_Kd' } {[14.5090]} +% {'TL_AGTP_F' } {[-1.2000]} +% +% Parallel pool using the 'local' profile is shutting down. +% Parallel pool using the 'local' profile is shutting down. +% Starting parallel pool (parpool) using the 'local' profile ... +% connected to 18 workers. +% +% ans = +% +% Pool with properties: +% +% Connected: true +% NumWorkers: 18 +% Cluster: local +% AttachedFiles: {} +% AutoAddClientPath: true +% IdleTimeout: 30 minutes (30 minutes remaining) +% SpmdEnabled: true +% +% Using temperature ladder for MCMC at the following temperatures. +% +% tladder = +% +% 1.0e+03 * +% +% 1.1905 0.4762 0.1191 0.0476 +% +% Current temperature: 1191 +% ############################################ +% +% File and directory info: +% +% Project name: +% 'proj_vnprl' +% +% Directory where the project file is stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects' +% +% Directory where data will be stored: +% '/home/ubuntu/anaconda3/matlab/txtlsim/mcmc_simbio/projects/proj_vnprl' +% +% Timestamp for this run (yyyymmdd_HHMMSS): +% '20200420_205718' +% +% Project directory already exists, using this to store data +% (in a subdirectory named 'simdata_20200420_205718_1_1191'). +% +% ############################################ +% +% Testing integrability for dose number 1. +% +% +% +% % after the runs, we changed the parameters FROM: +% activeNames2 = {... % changes made to ranges on feb 8, 2019. +% setting parameters based on +% ...% posterior plots. +% 'TX_elong_glob' exp(2.55) [exp(2.3) exp(2.8)] % 1 +% 'AGTPdeg_time' exp(8.8350) exp([8.76 8.91]) +% % DO NOT FIX THIS. +% 'AGTPdeg_rate' exp(-10) exp([-10.3 -9.6 ]) +% % set from before +% 'AGTPreg_ON' exp(-3.912) [0.005 0.2] +% %4 % set from before +% 'TXTL_P70_RNAPbound_Kd' exp(13.75) exp([13.25 14.25]) % +% 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +% 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(1.95) exp([-2.1 6]) % 7 +% 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +% 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +% 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +% 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +% 'TXTL_RNAdeg_Kd' exp(15.6) exp([14.5 16.7]) +% 'TXTL_RNAdeg_F' exp(0) [0.01 10000] +% % set to 1 (1 is right +% in the middle of the broad posterior density, and so not entirely arbitrary. ) +% 'TXTL_RNAdeg_kc' exp(-2.1) exp([-3.3 -0.9]) %set to exp(-5.4) +% 'RNAP' exp(1.4419) exp([-0.44 3.62]) % 15 +% 'RNase' exp(10.5) exp([8.6 12.4]) +% 'TL_elong_glob' exp(3.35) exp([2.1 4.6]) +% 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 +% % set from before +% 'TXTL_UTR_UTR1_Kd' exp(5.75) exp([-3 14.5]) +% 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +% 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +% 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +% 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +% 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +% 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(2.45) exp([1.9 3]) +% 'Ribo' exp(5) exp([3 7])}; %26 +% % TO: +% activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +% ...% posterior plots. +% 'TX_elong_glob' exp(2.55) [exp(0.3) exp(4.8)] % 1 +% 'AGTPdeg_time' exp(8.8350) exp([6.76 10.91]) +% % DO NOT FIX THIS. +% 'AGTPdeg_rate' exp(-10) exp([-12.3 -7.6 ]) +% % set from before +% 'AGTPreg_ON' exp(-3.912) [0.005 0.2] +% %4 % set from before +% 'TXTL_P70_RNAPbound_Kd' exp(13.75) exp([11.25 16.25]) % +% 'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +% 'TXTL_RNAPBOUND_TERMINATION_RATE' exp(1.95) exp([-4.1 8]) % 7 +% 'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +% 'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +% 'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +% 'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +% 'TXTL_RNAdeg_Kd' exp(15.6) exp([12.5 18.7]) +% 'TXTL_RNAdeg_F' exp(0) [0.01 10000] +% % set to 1 (1 is right in the middle of the broad posterior density, +% and so not entirely arbitrary. ) +% 'TXTL_RNAdeg_kc' exp(-2.1) exp([-5.3 1.1]) %set to exp(-5.4) +% 'RNAP' exp(1.4419) exp([-2.44 5.62]) % 15 +% 'RNase' exp(10.5) exp([6.6 14.4]) +% 'TL_elong_glob' exp(3.35) exp([0.1 6.6]) +% 'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 +% % set from before +% 'TXTL_UTR_UTR1_Kd' exp(5.75) exp([-5 16.5]) +% 'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +% 'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +% 'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +% 'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +% 'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +% 'TXTL_RIBOBOUND_TERMINATION_RATE' exp(2.45) exp([1.9 3]) +% 'Ribo' exp(5) exp([1 9])}; %26 +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------------------------ +% ------------------------------------------------------------------------ +% +% +% ----------- +% +% % April 20, 2019 +% % ssh -i ~/.ssh/vipul_key_2019_sg.pem +% ubuntu@ec2-3-0-202-120.ap-southeast-1.compute.amazonaws.com +% +% % full_variable_set_20190420_045130_1_92790.mat +% proj_ZSIFFL_mtet('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 50*1200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.03 0.01 0.005 0.001],... +% 'stepLadder', [1]) % as of april 20, 2019 +% % for some reason every spot instance type I try gets booted. ... +% might have to start using on demand instances. +% % goddammit. just do what you need to do. I suppose. +% +% +% % simdata_20190420_070950_1_30930 +% % ec2-13-250-204-106.ap-southeast-1.compute.amazonaws.com +% proj_ZSIFFL_mtet('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 40*1200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.01 0.005 0.001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190420_045130_1_92790',... +% 'prevtstampID', 2) %term by aws i give up on m4.4 +% +% % simdata_20190420_071051_1_30930 +% % 20190420_071438_2_15465 +% % ec2-13-251-44-234.ap-southeast-1.compute.amazonaws.com +% proj_ZSIFFL_mtet('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 40*1200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.01 0.005 0.001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190420_045130_1_92790',... +% 'prevtstampID', 2) %term at 0.005 iter 8 +% +% % _20190420_155505_1_7732 +% proj_ZSIFFL_mtet('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 50*1200,... +% 'thinning', 5,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0025 0.001 0.0005 0.00025 0.0001 0.00005 0.000025 0.00001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190420_071438_2_15465',... +% 'prevtstampID', 8) +% +% +% % got some useful info from the above sim, expanding the parameter ranges. +% proj_ZSIFFL_mtet('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00025 0.0001],... +% 'stepLadder', [1]) % terminated at 20190421_155749_2_309 at ID2 +% +% +% % ec2-13-251-129-176.ap-southeast-1.compute.amazonaws.com +% proj_ZSIFFL_mtet('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00025],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190421_155749_2_309',... +% 'prevtstampID', 2) % 20190422_142534_1_773 +% +% % _20190422_214228_1_773 +% proj_ZSIFFL_mtet('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00025],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190422_142534_1_773',... +% 'prevtstampID', 4) % terminated at by aws. : mcmc20190422_214228_1_773_ID7 +% +% % ec2-13-251-60-253.ap-southeast-1.compute.amazonaws.com +% % start from : mcmc20190422_214228_1_773_ID7 +% % 20190424_104801_1_773 +% proj_ZSIFFL_mtet('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00025],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190422_214228_1_773',... +% 'prevtstampID', 7) +% +% +% % ec2-18-138-103-128.ap-southeast-1.compute.amazonaws.com +% proj_ZSIFFL_mtet_phase2('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0005, 0.00025],... +% 'stepLadder', [1]) %terminated at mcmc20190427_170334_2_1029_ID6 +% % there was a bug in the parameter ranges of the ptet sequestration. +% +% % rerunning itvapril 28, 10 pm. +% proj_ZSIFFL_mtet_phase2('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0005, 0.00025],... +% 'stepLadder', [1]) +% +% % mcmc20190429_083138_1_1029_ID4.mat +% proj_ZSIFFL_mtet_phase2('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00025 0.0001 0.00005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190428_142033_2_1029',... +% 'prevtstampID', 2) % continuing from mcmc20190428_142033_2_1029_ID2 +% +% % 20190429_200219_1_1029 +% proj_ZSIFFL_mtet_phase2('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00025 0.0001 0.00005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190429_083138_1_1029',... +% 'prevtstampID', 4) %it ended on 0.0001 (20190429_200219_2_412) at iter 3. +% (spot termination.) +% +% %ec2-3-0-49-41.ap-southeast-1.compute.amazonaws.com (started April 27) +% % 20190430_141254_1_412 +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0001 0.00005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190429_200219_2_412',... +% 'prevtstampID', 3) %completed +% +% +% % 20190501_042829_1_617 +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00015],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190430_141254_2_206',... +% 'prevtstampID', 5) %spot termination at iter 4. +% % spot termination at 4 iters. new id: +% ec2-3-0-201-215.ap-southeast-1.compute.amazonaws.com +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00015],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190501_042829_1_617',... +% 'prevtstampID', 4) %terminated at oter 9 by spot instance unavailability. +% +% % simdata_20190502_042614_1_412 +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190501_123015_1_617',... +% 'prevtstampID', 9) +% +% % 20190502_105714_1_412 +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190502_042614_1_412',... +% 'prevtstampID', 1) % got terminated at mcmc20190502_105714_1_412_ID11.mat +% +% % 20190503_054023_1_412 -- FAILED +% +% % 20190503_073640_1_412 +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190502_105714_1_412',... +% 'prevtstampID', 11) %--- terminated at iter 1 +% +% % 20190503_113414_1_412 +% % ec2-18-138-124-192.ap-southeast-1.compute.amazonaws.com +% % this is a new instance. +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 50*1200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190503_073640_1_412',... +% 'prevtstampID', 1) %terminated at 1. spot termination. +% +% +% % 20190503_170440_1_412 +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 50*1200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190503_113414_1_412',... +% 'prevtstampID', 1) %termintaed at iter 11 +% +% % 20190504_155258_1_412 +% proj_ZSIFFL_mtet_phase2('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 50*1200,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190503_170440_1_412',... +% 'prevtstampID', 11) +% +% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% %%%%%%%%%%%%% +% % 2019-05-01 +% % ec2-18-138-124-89.ap-southeast-1.compute.amazonaws.com (started May 1) +% % simdata_20190501_074926_1_1107 +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00015 0.00025 0.0005 0.00025 0.00015],... +% 'stepLadder', [1]) % spot terminated at temp 1, iter 1. +% +% % new IP: ec2-13-229-148-173.ap-southeast-1.compute.amazonaws.com +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00015 0.00025 0.0005 0.00025 0.00015],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190501_074926_1_1107',... +% 'prevtstampID', 1) +% +% +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0005 0.00025 0.00015 0.0001 0.0001 0.0001 0.0001],... +% 'stepLadder', [1]) +% +% % ec2-3-1-24-17.ap-southeast-1.compute.amazonaws.com +% %%%%% 20190503_053402_1_3691 +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 10,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0005 0.00025 0.00015 0.0001],... +% 'stepLadder', [1]) % ---- FAILED. KILLED. c4.8 is failing me. +% spot requensts are failing me. +% +% +% +% % ec2-3-1-26-130.ap-southeast-1.compute.amazonaws.com +% % 20190503_170158_1_3691 +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.0005 0.00025 0.00015 0.0001],... +% 'stepLadder', [1]) % TERMINATED as of may 4, 1 am. +% +% % spot terminated at 20190503_170158_3_1107 iter 7, which is temp 00015 +% % so just going to run temp 0.00015 0.0001 now. +% % 20190504_153702_1_1107 +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.00015 0.0001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190503_170158_3_1107',... +% 'prevtstampID', 7) % +% +% +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.0001 0.000075],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190504_153702_2_738',... +% 'prevtstampID', 10) +% +% +% +% +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %---------------------------------------------------% +% % 20190507_064919_1_1845 +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.00025 0.0001 0.000075],... +% 'stepLadder', [1]) % terminated at 1 - 6 +% +% % ec2-13-251-60-17.ap-southeast-1.compute.amazonaws.com +% % 20190507_102955_1_1845 +% % extended the unactivated plas Kd. +% % 1438a6f1b3b4fa4f874086c62d5a6e141e05c83d <- commit ID. +% proj_ZSIFFL_training('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.00025 0.0001 0.000075],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190507_064919_1_1845',... +% 'prevtstampID', 6) % +% +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %---------------------------------------------------% +% +% +% %%%%%% 20190508_001705_1_1845 +% % ec2-13-251-63-66.ap-southeast-1.compute.amazonaws.com +% % may 8, 8.15 am. +% proj_ZSIFFL_trainingB('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 8,... +% 'temperatureLadder', [0.00025 0.0001 0.000075],... +% 'stepLadder', [1]) % terminated at iter 7 due to spot instance unavailability. +% +% % ec2-18-138-243-147.ap-southeast-1.compute.amazonaws.com +% %anywhere. +% % 20190508_213950_1_1107 +% proj_ZSIFFL_trainingB('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.00015 0.00010 0.000075],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190508_001705_1_1845',... +% 'prevtstampID', 7) % -- changed to an r.24xlarge. mem optimized, +% but with 48 physical cores. +% +% % 20190509_024244_1_738 +% proj_ZSIFFL_trainingB('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.00010 0.000075],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190508_213950_1_1107',... +% 'prevtstampID', 9) +% +% % ec2-13-251-106-164.ap-southeast-1.compute.amazonaws.com +% % 48 cores +% % 20190509_062932_1_738 +% proj_ZSIFFL_trainingB('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 60,... +% 'temperatureLadder', [0.00010 0.000075],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190509_024244_1_738',... +% 'prevtstampID', 6) %CURRENT -- +% +% % 20190509_083808_1_738 +% proj_ZSIFFL_trainingB('stepSize', 1.3,... +% 'nW', 400,... +% 'nPoints', 50*400,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.00010 0.000075],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190509_062932_1_738',... +% 'prevtstampID', 2) +% +% +% +% % ---- +% % 20190509_092707_1_1476 +% % ec2-3-0-206-195.ap-southeast-1.compute.amazonaws.com +% proj_ZSIFFL_trainingC('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 25*1200,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0002 , 0.00010 0.000075],... +% 'stepLadder', [1]) +% +% proj_ZSIFFL_trainingC('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 25*1200,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0002 , 0.00010 0.000075],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190509_092707_1_1476',... +% 'prevtstampID', 8) +% +% % 20190510_064333_1_369 +% proj_ZSIFFL_trainingC('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 25*1200,... +% 'thinning', 5,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.00005 0.000025 0.00001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190509_160552_3_554',... +% 'prevtstampID', 20) +% +% +% proj_ZSIFFL_trainingC('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 25*1200,... +% 'thinning', 5,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.00001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190510_064333_3_74',... +% 'prevtstampID', 8) +% +% +% % +% % 20190511_062400_1_738 +% proj_ZSIFFL_trainingD('stepSize', 1.3,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0001 0.00005 0.00001],... +% 'stepLadder', [1]) +% +% % 20190511_131947_1_369 +% proj_ZSIFFL_trainingD('stepSize', 1.3,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [ 0.00005 0.00001],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190511_062400_1_738',... +% 'prevtstampID', 11)% terminated at iter 1 of 0.00001, ie, temp = 74. +% rejection % v high. +% +% % simdata_20190512_023235_1_1476 -- temp increased to lower the +% rejection percentage. it was at 90+% +% proj_ZSIFFL_trainingD('stepSize', 1.2,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [ 0.0002],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190511_131947_2_74',... +% 'prevtstampID', 1) +% +% proj_ZSIFFL_trainingE('stepSize', 1.2,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [ 0.0002],... +% 'stepLadder', [1]) +% +% +% % 20190512_054951_1_1476 +% proj_ZSIFFL_trainingE('stepSize', 1.2,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [ 0.0002],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190512_033129_1_1476',... +% 'prevtstampID', 3) % current +% +% proj_ZSIFFL_trainingE('stepSize', 1.1,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [ 0.00025],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190512_064547_1_1476',... +% 'prevtstampID', 8) % next. +% +% +% proj_ZSIFFL_trainingE('stepSize', 1.1,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [ 0.00025],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190512_094712_1_1845',... +% 'prevtstampID', 2) +% +% % 20190512_155207_1_1845 +% proj_ZSIFFL_trainingE('stepSize', 1.1,... +% 'nW', 480,... +% 'nPoints', 50*480,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [ 0.00025],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190512_113712_1_1845',... +% 'prevtstampID', 5) +% +% % 20190513_052603_1_1845 +% proj_ZSIFFL_trainingE('stepSize', 1.1,... +% 'nW', 480,... +% 'nPoints', 100*480,... +% 'thinning', 10,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [ 0.00025],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190512_155207_1_1845',... +% 'prevtstampID', 7) +% +% +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %---------------------------------------------------% +% +% +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %---------------------------------------------------% +% +% +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %---------------------------------------------------% +% +% +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %--------------------------------------------------- +% %---------------------------------------------------% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% % and another new machine. 24 physical cores. +% % ec2-3-1-27-61.ap-southeast-1.compute.amazonaws.com +% % %%%%%%%%%%%%%%%%%%%%%%%%% SILVER - AEROGEL +% % %%%%%%%%%%%%%%%%%%%%%%%%% SILVER - AEROGEL +% % %%%%%%%%%%%%%%%%%%%%%%%%% SILVER - AEROGEL +% % %%%%%%%%%%%%%%%%%%%%%%%%% SILVER - AEROGEL +% % %%%%%%%%%%%%%%%%%%%%%%%%% SILVER - AEROGEL +% % %%%%%%%%%%%%%%%%%%%%%%%%% SILVER - AEROGEL +% +% +% % 20190318_150814_1_208 +% proj_test015_corr1_Ffix3('stepSize', 1.05,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.01 0.005 0.001 0.0005],... +% 'stepLadder', [1], ... +% 'rkcp', exp(-1.068),... +% 'cpol', exp(1.33)) %done +% +% +% proj_test015_corr1_Ffix3('stepSize', 1.05,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.001],... +% 'stepLadder', [1], ... +% 'rkcp', exp(-1.068),... +% 'cpol', exp(1.33),... +% 'prevtstamp', '20190318_150814_4_10',... +% 'prevtstampID', 20) % . continuing at a higehr (optimal) temp -- RUNNING> +% % 0.001 is a really really good temperature. the 0.0005 is too low, +% and o.005 is too high. +% % +% +% % 20190319_143938_1_16 terminated at 4 iters. +% proj_test015_corr1_Ffix3('stepSize', 1.1,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 80,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.00075],... +% 'stepLadder', [1], ... +% 'rkcp', exp(-1.068),... +% 'cpol', exp(1.33),... +% 'prevtstamp', '20190319_065336_1_21',... +% 'prevtstampID', 40) % just terminate +% +% proj_test015('stepSize', 1.1,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 80,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.0003],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190319_105547_1_10',... +% 'prevtstampID', 35) %DONE. +% +% proj_test015_corr1_Ffix3('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [1], ... +% 'rkcp', exp(0.5168),... +% 'cpol', exp(-0.2199)) +% +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% +% +% +% %---------- +% % --------- ec2-13-229-144-125.ap-southeast-1.compute.amazonaws.com +% % --------- %%%%%%%%%%%%%%%%%%%%% BLUE-WHITE +% +% % NEW MACINE -- 48 physical cores +% +% % expect 2h10min per 30. say I want to be done in 12 - 13 h. +% then need to run 6 sets of 30. +% % 20190318_143245 +% proj_test015('stepSize', 1.02,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 45,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0003 0.0002 0.0001 0.00005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190318_082039_3_10',... +% 'prevtstampID', 9) % 24 workers? this is a 48 worker machine!!!... lol. I am absurd. +% +% +% %20190319_071743_1_32 +% +% proj_test015('stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 80,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190318_143245_3_3',... +% 'prevtstampID', 39) %% terminated at 6.52 pm mar 19.. +% +% %20190319_105547_1_10 +% proj_test015('stepSize', 1.1,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0003],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190319_071743_1_32',... +% 'prevtstampID', 29) % +% +% proj_test015('stepSize', 1.1,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 80,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0003],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190319_105547_1_10',... +% 'prevtstampID', 35) %done +% +% +% proj_test015('stepSize', 1.03,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190319_152204_1_10',... +% 'prevtstampID', 80) %-- terminated at 12.49pm mar 20 +% +% +% % 20190320_044942_1_104 IMPORTANT!!!!!! final try. +% proj_test015_corr1_Ffix3('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.005 0.003 0.001],... +% 'stepLadder', [1], ... +% 'rkcp', exp(0.5168),... +% 'cpol', exp(-0.2199)) +% +% +% +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% +% +% +% +% % ---------------------- FINAL MACINE -- 48 cores. +% %%%%%%%%%%%%%%%%%% WHITE BLACK. +% % ec2-13-251-38-128.ap-southeast-1.compute.amazonaws.com +% +% % continued from : +% proj_test015_corr1_Ffix3('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.00075],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190318_140222_5_2',... +% 'prevtstampID', 20) % -- done +% +% proj_test015('stepSize', 1.1,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 80,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190319_105547_1_10',... +% 'prevtstampID', 35) % done +% +% +% proj_test015('stepSize', 1.04,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190319_153210_1_16',... +% 'prevtstampID', 80) % TERMINATE at ----- +% +% +% %20190320_044411_1_42 +% proj_test015_corr1_Ffix3('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [1], ... +% 'rkcp', exp(0.5168),... +% 'cpol', exp(-0.2199)) % terminated at 1.10pm mar 20. +% +% +% proj_test015_E1E2same('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.03 0.01 0.005 0.001],... +% 'stepLadder', [1]) % TERMINATE -- bug in the proj file. +% +% %20190320_082004_1_1453 +% proj_test015_E1E2same('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.03 0.01 0.005 0.002 0.002 0.002],... +% 'stepLadder', [1]) %. +% +% +% +% +% +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% % ---------- OLD MACHINES::: +% +% % -------- +% +% proj_test015('stepSize', 1.05,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 15,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.001 0.0007 0.0003 0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190316_092219_1_242',... +% 'prevtstampID', 50) % 24 workers? this is a 48 worker machine!!!... +% lol. I am absurd. terminated at 9 on 0.0003 +% +% +% % 20190318_140222_1_208 to +% % 20190318_140222_5_2 +% proj_test015_corr1_Ffix3('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01 0.005 0.001 0.0005 0.0001],... +% 'stepLadder', [1]) % --10.40 am expected end +% % 0.001 is probably a good temp. check!! actually maybe something +% like 0.00075? might be a good compromise! +% +% +% ------------------------- +% ____----------_________----------- +% +% +% +% proj_test015('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01 0.0075 0.005 0.0025],... +% 'stepLadder', [1]) % done! +% +% proj_test015_corr1_Ffix('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 6,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.005],... +% 'stepLadder', [1]) % +% +% proj_test015_corr1_Ffix('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 12,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.005 0.002],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190315_031445_1_104',... +% 'prevtstampID', 6) % all 12,, then 10. +% +% +% proj_test015_corr1_Ffix2('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01 0.007 0.005 0.004 0.003 0.002 0.001],... +% 'stepLadder', [1]) % terminated at ... +% +% +% % going to continue the calib estimation. +% +% proj_test015('stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0075 0.0025],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190314_161518_4_81',... +% 'prevtstampID', 20) %terminated at 0.0025, iter 8. 0.0075 complete at 30. pretty clean, +% can try to use. starting the kfdg fixed one next. +% +% % proj_test015_kfdgfix +% +% proj_test015_kfdgfix('stepSize', 1.25,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0075 0.005 0.0025],... +% 'stepLadder', [1]) % COMPLETE> +% +% +% % ---- switching to a smaller cheaper machine. going to redo test015, +% and clean it up massivelu. +% +% %20190316_033531_1_81 +% proj_test015('stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 44,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0025],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190315_102139_2_81',... +% 'prevtstampID', 6) +% +% +% % 20190316_044847_1_81 +% proj_test015('stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 24,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.0025],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190316_033531_1_81',... +% 'prevtstampID', 7) +% +% +% % 20190316_092219_1_242 +% proj_test015('stepSize', 1.1,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 50,... +% 'parallel', true, ... +% 'poolsize', 24,... +% 'temperatureLadder', [0.0075],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190316_044847_1_81',... +% 'prevtstampID', 24) % ---> continued above. much tighter temo and step size +% +% %--------------------------------------------------- +% % ----__-------------- +% +% % ALL HAD A FATAL ERROR +% % tightened the square. searching a smaller, better conditioned space now. +% % can expand later. should be good. +% proj_test015_corr1_Ffix('stepSize', 1.3,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01 0.005],... +% 'stepLadder', [1]) % +% +% % ----- corrections ----- with forward rate parameters fixed. +% % somehow the LHS region was too big. too much ill conditioning. +% +% % 20190314_083312_1_0p20762 +% % terminated at 0.01 at 9 iters. +% proj_test015_corr1_Ffix('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 12,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01 0.0075 0.005 0.0025],... +% 'stepLadder', [1]) % done +% +% proj_test015_corr1_Ffix('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 12,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.005],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190314_083312_1_0p20762',... +% 'prevtstampID', 9) % done +% +% +% % ----- corrections ----- +% +% % 20190314_050144_1_0p20762 +% proj_test015_corr1('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1]) % done +% +% % 20190314_072843_1_0p083047 +% proj_test015_corr1('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.004],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190314_050144_1_0p20762',... +% 'prevtstampID', 20) %stopped at 5 +% +% % 20190314_080601_1_0p062285 +% proj_test015_corr1('stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.003],... +% 'stepLadder', [1], ... +% 'prevtstamp', '20190314_072843_1_0p083047',... +% 'prevtstampID', 5) %stopped at 3 +% +% +% % ---------- calibration ------- +% % 20190313_091216_1_0p32242 +% proj_test015('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1]) % ran for 9 iterations. +% +% +% % extended the parameter range limits. -15 to 10. +% % 20190313_101830_1_0p32242 +% proj_test015('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190313_091216_1_0p32242',... +% 'prevtstampID', 9) % complete +% +% % 20190313_130351_1_0p32242 +% proj_test015('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190313_101830_1_0p32242',... +% 'prevtstampID', 20) % complete +% +% % 20190313_153908_1_0p32242 +% proj_test015('stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190313_130351_1_0p32242',... +% 'prevtstampID', 20) % done +% +% % 20190313_171758_1_0p064484 +% proj_test015('stepSize', 1.1,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 80,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190313_153908_1_0p32242',... +% 'prevtstampID', 5) % terminated at 60 +% +% % 20190313_171758_1_0p064484 +% proj_test015('stepSize', 1.1,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.004],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190313_171758_1_0p064484',... +% 'prevtstampID', 60) % done +% +% +% +% %%%%%%%% +% +% % ec2-3-1-25-154.ap-southeast-1.compute.amazonaws.com +% % 20190221_074748_1_2 +% proj_vnprl('ver', 'F2',... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 80,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190220_102006_1_2',... +% 'prevtstampID', 31) % complete. +% +% % 20190223_024333_1_2 +% proj_vnprl('ver', 'F2',... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190221_074748_1_2') % +% +% +% ----------------------- +% +% +% % massive ram requirements. should be cool. +% % 20190217_160345_1_48 +% proj_vnprl('ver', 'F2',... +% 'stepSize', 1.2,... +% 'nW', 9600,... +% 'nPoints', 100*9600,... +% 'thinning', 1,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.002 0.001 0.0005],... +% 'stepLadder', [1]) % terminated after 0.002. +% +% +% % 20190218_135635_1_24 +% % 20190218_135635_2_12 +% proj_vnprl('ver', 'F2',... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 25,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.001 0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190217_160345_1_48') % ran both temps. +% +% %20190219_093714_1_7 +% % 20190219_093714_2_2 +% proj_vnprl('ver', 'F2',... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0003 0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190218_135635_2_12') % done +% +% % 20190220_022918_1_2 +% proj_vnprl('ver', 'F2',... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190219_093714_2_2') % spot termination @ iter 16 +% +% +% % 20190220_102006_1_2 +% proj_vnprl('ver', 'F2',... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 36,... +% 'temperatureLadder', [0.0001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190220_022918_1_2',... +% 'prevtstampID', 16) +% +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------% +% ------------ +% ------------ +% ------------ +% ------------ +% % ec2-3-1-26-166.ap-southeast-1.compute.amazonaws.com +% +% % 20190215_102557_1_232 +% proj_acs_dsg2014_regen_H(... +% 'stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 36,... +% 'temperatureLadder', [0.004 0.003 0.002],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190211_122853_1_290') % starting at 6.19 pm , feb 15. +% % 7 hours per 10 iters, 60 iters == 42hours = 1.12*42 = 47 dollars. +% OK. 2 days - done sun afternoon. +% % this is what simulated annealing will cost for this largest model. so be it. +% % also, can terminate early +% +% +% proj_acs_dsg2014_regen_H(... +% 'stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 0,... +% 'parallel', true, ... +% 'poolsize', 36,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190215_102557_3_116') +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% +% +% +% % THis instance's ID is ec2-13-251-16-236.ap-southeast-1.compute.amazonaws.com +% % The idea here is to do simulated annealing proper, 5 iters per temp, slowly lower. +% % look for global convergence. +% +% +% +% % continues from ec2-13-251-26-66.ap-southeast-1.compute.amazonaws.com, sim id: +% % 20190211_122853_1_290 +% +% +% % 20190213_173314_1_174 +% proj_acs_dsg2014_regen_H(... +% 'stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 5,... +% 'parallel', true, ... +% 'poolsize', 36,... +% 'temperatureLadder', [0.003 0.001 0.0009 0.0007 0.0005 0.0003],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190211_122853_1_290') % starting at 1.30 am , feb 14. +% +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------% +% ------------ +% ------------ +% ------------ +% ------------ +% - +% +% +% % this instance's ID is ec2-13-251-105-32.ap-southeast-1.compute.amazonaws.com +% +% +% % continues from ec2-13-251-26-66.ap-southeast-1.compute.amazonaws.com. +% % I am continuing % 20190211_213614_1_29 (ie, regen H, temp 0.0005) +% % 30 more iterations, at 200 steps per iteration. raise temp a bit and decrease step size +% % to raise the acceptance probability. \\ +% % 20190213_135919_1_29 +% proj_acs_dsg2014_regen_H(... +% 'stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 36,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190211_213614_1_29') % starting at 10 pm, feb 13. +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ % +% ------------ +% ------------ +% ------------ +% ------------ +% +% % ec2-3-1-25-179.ap-southeast-1.compute.amazonaws.com +% +% % NEW public DNS: +% % ec2-13-251-1-51.ap-southeast-1.compute.amazonaws.com +% +% % private: +% % ip-172-31-14-169.ap-southeast-1.compute.internal +% +% % this is with 11 params, +% % the only thing not in here is the agtp deg rate and turn on time. +% % 20190209_193419_1_22 +% proj_acs_dsg2014_regen_E(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.001],... +% 'stepLadder', [1]) % terminated at 14 +% +% +% % upweighted the tx+tl from 0.03 to 0.3. (10x increase) +% % 20190210_072219_1_20 -- started feb 10, 3.23 pm +% proj_acs_dsg2014_regen_E(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190209_193419_1_22',... +% 'prevtstampID', 14) %%%%% terminated at 13 iters. +% % 20 runs, about 16 hours to run them +% % -- expected end time is 8 am tomorrow morning. (monday) +% % verified as accurate. +% +% +% % started at 2.48 am on monday, feb 11. +% % 20190210_184717_1_2 +% proj_acs_dsg2014_regen_E(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190210_072219_1_20',... +% 'prevtstampID', 13) %-- expected end time -- 6 / 7 pm mon feb 11. +% +% +% % 20190211_123400_1_290 +% proj_acs_dsg2014_regen_I(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.005 0.0005 0.00005],... +% 'stepLadder', [1]) %-- terminated at the first temp, at iter 9 +% % spot instance termination. +% +% % 20190211_214449_1_29 +% proj_acs_dsg2014_regen_I(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0005 0.00005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190211_123400_1_290',... +% 'prevtstampID', 9) % 11 pm for the 0.0005 to end, +% % then another 18 hours (ie, 5 pm tomorrow feb 13) for the 0.00005 to end. +% % just terminate at 11 pm on feb 12. dont need to do the 0.00005 for now. +% %terminating after the completion of 0.0005. +% +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% % ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% +% % ec2-13-251-126-71.ap-southeast-1.compute.amazonaws.com +% % NEW public DNS: +% % ec2-13-251-26-66.ap-southeast-1.compute.amazonaws.com +% +% % private DNS: +% % ip-172-31-9-187.ap-southeast-1.compute.internal +% +% % simdata_20190209_070634_1_1088 +% proj_acs_dsg2014_regen_C1(... +% 'stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 100*400,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.05],... +% 'stepLadder', [1]) +% %---- ran for 14 iters. +% % then realized that both experiment and dose +% % weighting were messing us up. +% +% % 20190209_091205_1_231 +% proj_acs_dsg2014_regen_C1(... +% 'stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 50*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190209_070634_1_1088',... +% 'prevtstampID', 14) +% %---- ran for 6 iters. +% % acceptance probability was around 45% too high. need to halve it. +% +% % 20190209_104120_1_23 -- rejection prob is about 71%, not bad. +% proj_acs_dsg2014_regen_C1(... +% 'stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.001],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190209_091205_1_231',... +% 'prevtstampID', 6) % terminated at 17 iters. moved the data to my mac. +% % need to plot to see the results. +% +% +% % feb 10, 3 am , +% % starting a 6 parameter run, with only the tx and tl data, no rna deg +% +% % 20190209_191801_1_127 +% proj_acs_dsg2014_regen_G(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [1]) +% +% % 20190210_030032_1_127 +% proj_acs_dsg2014_regen_G(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190209_191801_1_127') %%%%% done. +% +% %20190210_123436_1_32 +% proj_acs_dsg2014_regen_G(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 60,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190210_030032_1_127') +% +% %%expected end time: 10.15 am monday morning. feb 11. +% % terminating at iter 27 at 2.50 am. feb 11.. going to restart at a lower temperature. +% +% % 20190210_185320_1_3 +% proj_acs_dsg2014_regen_G(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 80,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.00005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190210_123436_1_32',... +% 'prevtstampID', 27) % done to completion. +% +% % 20190211_122853_1_290 +% proj_acs_dsg2014_regen_H(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.005 0.0005 0.00005],... +% 'stepLadder', [1]) % terminated at the end of temp1, +% %after the full 10 iters. (due to spot instance i think. regenerated new public IP.) +% +% % 20190211_213614_1_29 +% proj_acs_dsg2014_regen_H(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.0005 0.00005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190211_122853_1_290') % . expected end time: 10pm feb 12... done. +% +% % Ok so the 0.00005 is too low. the 0.0005 is a good value, +% still allows for some mixing. 0.005 is too hot, +% % the error stays too high. +% % so the next iteration will be contintued from 0.0005, on a +% c5.9xlarge. or a larger machine? +% % next instance where this continues is +% ec2-13-251-105-32.ap-southeast-1.compute.amazonaws.com above. +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% % ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% % 48 core machine. lets go! +% % ec2-13-251-59-146.ap-southeast-1.compute.amazonaws.com +% proj_acs_dsg2014_regen_C1(... +% 'stepSize', 1.15,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.001],... +% 'stepLadder', [1]) +% +% % 20190209_110209_1_21 -- rejection prob is about 80%. good! +% proj_acs_dsg2014_regen_C1(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 100*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.001],... +% 'stepLadder', [1]) +% +% % setting up a new sim: regen_D: +% % 20190209_184946_1_44 +% proj_acs_dsg2014_regen_D(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.002],... +% 'stepLadder', [1]) +% +% % upweighted the tx+tl from 0.03 to 0.3. (10x increase) +% % and a 4 x decrease in temperature. should really tighten up the +% % fits. +% %20190210_072127_1_20 -- started feb 10, 3.22 pm +% proj_acs_dsg2014_regen_D(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190209_184946_1_44',... +% 'prevtstampID', 24) %% DONE at 2.30 am mon feb 11. +% % this will end at about 4am on monday morning +% % thats not good. going to terminate this, and +% % restart at a lower temperature, so it terminates in the day sometime. +% % (ideally in the morning, at like 10 am after I wake up.) +% +% % 20190210_184039 +% proj_acs_dsg2014_regen_F(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.005 0.0005 0.00005],... +% 'stepLadder', [1]) %30 iters -- 16 - 17 hours projected time, +% % expected end time mon feb 11, 6 - 7 pm. terminated at 1.30 pm. +% aftr 2 temperatures (full 10 iters) +% % ie, 0.00005 was never done. +% +% +% +% % simdata_20190211_054328_1_20 +% % goal: complete decorrelation of the chains. +% % -- maybe even redo it for another 20 iters after this. +% proj_acs_dsg2014_regen_F(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 20,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190210_184039_2_20') % terminated at 15. +% +% % 20190211_140024_1_20 +% proj_acs_dsg2014_regen_F1(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 30,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190211_054328_1_20',... +% 'prevtstampID', 15) % . - +% % expected end time -- around 1 - 2 pm feb 12. terminate at 1.30pm, +% % and maybe restart the sim for another 10 iterations. +% % terminating at 29 iterations. +% +% % 20190212_053457_1_20 +% proj_acs_dsg2014_regen_F1(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 11,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190211_140024_1_20',... +% 'prevtstampID', 29) +% +% % 20190212_114314_1_20 +% proj_acs_dsg2014_regen_F1(... +% 'stepSize', 1.2,... +% 'nW', 1200,... +% 'nPoints', 200*1200,... +% 'thinning', 1,... +% 'nIter', 22,... +% 'parallel', true, ... +% 'poolsize', 48,... +% 'temperatureLadder', [0.0005],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190212_053457_1_20') +% ------------ +% ------------ +% ------------ +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% % ------------ END OF ACTIVE SETS> historical records below: +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% ------------ +% +% ------------ +% ------------ +% ------------ +% +% % SHUT ALL these down, feb 9, 2019. +% +% +% %used to generate the right model object: +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 50,... +% 'nPoints', 10*50,... +% 'thinning', 1,... +% 'nIter', 2,... +% 'parallel', false, ... +% 'poolsize', 2,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1]) +% +% +% ------------ +% ------------ +% ------------ +% ------------ +% %ec2-3-1-26-49.ap-southeast-1.compute.amazonaws.com +% proj_acs_dsg2014_regen_A('stepSize', 1.2,... +% 'nW', 400,... +% 'nPoints', 200*400,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190206_043320_1_218') +% +% % ------ new session on the same machine. here, we have expanded the param ranges, +% % and defined a new project with these expanded ranges. +% % again, just testing the step size and the temperature combinations. +% proj_acs_dsg2014_regen_A1(... +% 'stepSize', 1.05,... +% 'nW', 400,... +% 'nPoints', 100*400,... +% 'thinning', 1,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [10 5 1 0.1 0.01 0.001],... +% 'stepLadder', [6 3 2 1.7 1.4 1.2 1.1 1 0.75 0.5],... +% 'literalStepLadder', true) % expected end time 10.30 pm feb 8 +% +% ------------ +% ------------ +% ------------ +% ------------- +% +% %ec2-13-251-35-115.ap-southeast-1.compute.amazonaws.com +% % 20190208_041042_1: +% proj_acs_dsg2014_regen_A('stepSize', 1.4,... +% 'nW', 400,... +% 'nPoints', 200*400,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190206_043320_1_218') +% +% +% % 20190208_041042_1_17407: +% proj_acs_dsg2014_regen_A('stepSize', 3.4,... +% 'nW', 400,... +% 'nPoints', 200*400,... +% 'thinning', 1,... +% 'nIter', 4,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.8],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190207_155723_1_218') % 96% rejection, did 2 iter +% +% %20190208_044547_1_17407 +% proj_acs_dsg2014_regen_A('stepSize', 2.4,... +% 'nW', 400,... +% 'nPoints', 200*400,... +% 'thinning', 1,... +% 'nIter', 1,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.8],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190208_041042_1_17407',... +% 'prevtstampID', 2) % +% +% %20190208_051536_1_108797 +% proj_acs_dsg2014_regen_A('stepSize', 2.4,... +% 'nW', 400,... +% 'nPoints', 200*400,... +% 'thinning', 1,... +% 'nIter', 2,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [5],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190208_044547_1_17407',... +% 'prevtstampID', 2) % +% +% %'20190208_054905' +% % -20190208_054905_1_217593, and so on. [[[[[TEMP LADDER]]]]] +% proj_acs_dsg2014_regen_A('stepSize', 1.05,... +% 'nW', 400,... +% 'nPoints', 100*400,... +% 'thinning', 1,... +% 'nIter', 10,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [10 5 1 0.1 0.01 0.001],... +% 'stepLadder', [6 3 2 1.7 1.4 1.2 1.1 1 0.75 0.5],... +% 'prevtstamp', '20190208_051536_1_108797',... +% 'literalStepLadder', true) % expected end time -- 11.30 pm feb8. +% ------------- +% ------------ +% ------------ +% ------------ +% +% % ec2-13-251-129-65.ap-southeast-1.compute.amazonaws.com +% % '20190207_162351_1_218': +% proj_acs_dsg2014_regen_A('stepSize', 1.8,... +% 'nW', 400,... +% 'nPoints', 200*400,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.01],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190206_043320_1_218') %--->'20190207_162351_1_218' +% +% %20190208_035625_1_2176 +% proj_acs_dsg2014_regen_A('stepSize', 1.8,... +% 'nW', 400,... +% 'nPoints', 200*400,... +% 'thinning', 1,... +% 'nIter', 40,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [0.1],... +% 'stepLadder', [1],... +% 'prevtstamp', '20190208_031916_1_218', ... +% 'prevtstampID', 1) %--- terminated at 15 iterations +% ----- +% +% % fixed params, temp ladder, step ladder, LHS init, regen_C1. +% % 20190208_075812_1 +% proj_acs_dsg2014_regen_C1(... +% 'stepSize', 1.05,... +% 'nW', 400,... +% 'nPoints', 200*400,... +% 'thinning', 1,... +% 'nIter', 7,... +% 'parallel', true, ... +% 'poolsize', 18,... +% 'temperatureLadder', [10 5 1 0.1 0.01 0.001],... +% 'stepLadder', [4 2 1.7 1.4 1.2 1.1 1],... +% 'literalStepLadder', true) % expected end time -- 11.30 pm feb8. +% +% +% +% diff --git a/mcmc_simbio/src/MPinterval.m b/mcmc_simbio/src/MPinterval.m new file mode 100755 index 0000000..3775ba6 --- /dev/null +++ b/mcmc_simbio/src/MPinterval.m @@ -0,0 +1,56 @@ +function [bds, mx, mp, BW] = MPinterval(vec, varargin) +%[bds, mx, mp ] = MPinterval(vec, varargin) compute the smallest interval containing maximum probability estimate for a given +%probability mass +% OUTPUTS +% bds are the lower and upper bounds of the interval. +% mx is the sample at which the maximum probability occurs +% mp is the probability +% INPUTS +% vec is the vector of samples +% mass is a number from 0 to 1. 0 returns just the map estimate, and bds = +% [mx mx], 1 returns the entire interval +% nBins is the number of bins to use. + +p = inputParser; +p.addParameter('mass',0.2,@isnumeric); +npoints = round(length(vec)/1000); +p.addParameter('npoints',npoints,@isnumeric); +p.addParameter('bw',[],@isnumeric); +p.parse(varargin{:}); +p=p.Results; + +% compute density, mp, and interval + +if isempty(p.bw) + [F,XI,BW]=ksdensity(vec, 'npoints', p.npoints); +else + [F,XI]=ksdensity(vec, 'npoints', p.npoints, 'bandwidth', p.bw); + BW = p.bw; +end + +[mp, mxi] = max(F); % mxi is the index of the bin at which the max occurs +mx = XI(mxi); +currmass = 0; +currL = mxi; +currR = mxi; +while (currmass < p.mass) && currL>1 && currR= F(currR) + currL = currL - 1 ; + else + currR =currR + 1; + end + newIdx = currL:currR; + try + currmass = trapz(XI(newIdx), F(newIdx)); + catch + disp('error...') + end + +end + +bds = [XI(currL) XI(currR)]; +% note that the limits of the XI need not coincide with the limits of the +% the samples, since XI is the support of the gaussian fitted to the +% samples. +end + diff --git a/mcmc_simbio/src/catMC.m b/mcmc_simbio/src/catMC.m new file mode 100755 index 0000000..955d81e --- /dev/null +++ b/mcmc_simbio/src/catMC.m @@ -0,0 +1,10 @@ +function mcat = catMC(datafiles) +%catMC Take Markov Chains from GWMCMC and concat them + +load(datafiles{1}, 'm'); +mcat = m; +for i = 2:length(datafiles) + load(datafiles{i}, 'm'); + mcat = cat(3, mcat, m); +end + diff --git a/mcmc_simbio/src/computeDataStats.m b/mcmc_simbio/src/computeDataStats.m new file mode 100755 index 0000000..f16eab2 --- /dev/null +++ b/mcmc_simbio/src/computeDataStats.m @@ -0,0 +1,45 @@ +function [summst, spreadst] = computeDataStats(dataArray, dispmode) +% da: data array +% datasummary: mean, median or none +% dataspread: curves, std or none. +% rD: replicates dimension + +switch dispmode + case 'mean' + summst = mean(dataArray, 3); + spreadst = []; + case 'median' + % sum over the time dimension + % tD MUST be 1 for this to work.. I tried being fully general, + % but what is the point? It's unnecessarily difficult. + % compute the indexes of the median (in terms of sum / integral) + % curves over the replicates + [ix, mdvals] = medianIndex(sum(dataArray, 1), 3); + % again, rD MUST be 3. + summst = medianReplicate(dataArray, ix); + % spreadstatistic is the empty vector + spreadst = []; + case 'meanstd' + summst = mean(dataArray, 3); + spreadst = std(dataArray, 0, 3); + case 'meancurves' + summst = mean(dataArray, 3); + spreadst = dataArray; + case 'medianstd' + [ix, mdvals] = medianIndex(sum(dataArray, 1), 3); + summst = medianReplicate(dataArray, ix); + spreadst = std(dataArray, 0, 3); + case 'mediancurves' + [ix, mdvals] = medianIndex(sum(dataArray, 1), 3); + summst = medianReplicate(dataArray, ix); + spreadst = allButMedianCurve(dataArray, ix); + case 'curves' + summst = []; + spreadst = dataArray; + + otherwise + error(['Invalid data display mode. Must be one of: ''mean'','... + ' ''median'' , ''meanstd'',''medianstd'', ''meancurves'','... + ' ''mediancurves'', ''curves''.']) +end +end diff --git a/mcmc_simbio/src/computeFitOption.m b/mcmc_simbio/src/computeFitOption.m new file mode 100755 index 0000000..1daaa59 --- /dev/null +++ b/mcmc_simbio/src/computeFitOption.m @@ -0,0 +1,19 @@ +function currda = computeFitOption(da, fo) + % fo is the fit option. + % da is the data array + switch fo + case 'FitMedian' + % Compute the curvewise median of the data. + [ix, mdvals] = medianIndex(sum(da, 1), 3); + currda = medianReplicate(da, ix); + case 'FitMean' + currda = mean(da, 3); + case 'FitAll' + currda = da; + otherwise + error(... + ['Invalid fit option. Read the documentation'... + ' for how to specify inputs.']) + end + +end \ No newline at end of file diff --git a/mcmc_simbio/src/create_mobj_RNAdeg.m b/mcmc_simbio/src/create_mobj_RNAdeg.m new file mode 100755 index 0000000..2388225 --- /dev/null +++ b/mcmc_simbio/src/create_mobj_RNAdeg.m @@ -0,0 +1,265 @@ +function [ Mobj1 ] = create_mobj_RNAdeg(extract, varargin) +% commit test +%create_mobj_geneexpr Create a standard TXTL toolbox gene expression +%circuit +% [ Mobj1 ] = create_mobj_geneexpr(extract, speciesGroups, globalKdRules) +% +% Input Arguments: +% +% extract = a string specifying the extract batch for the txtl Modeling +% toolbox, example: 'E30VNPRL' +% +% speciesGroups = a structure containing info on additional species to be +% created which are the sum of some of the existing species. The main +% example of this is TotalRNA, which is the sum of all the GFP RNA in +% the system. +% +% globalKdRules is a struct which looks like this: +% globalKdRules = +% +% 2x1 struct array with fields: +% +% rxStr +% paramName +% kdVal +% fVal +% +% globalKdRules(1) +% rxStr: '[RNA rbs--deGFP] + Ribo <-> [Ribo:RNA...' +% paramName: 'TXTL_RBS_Ribo_deGFP' +% kdVal: 452.1739 +% fVal: 0.2300 +% +% See the file function_design_script for an example of the construction of +% the struct. +% +% OUTPUT Arguments +% Mobj1: a Simbiology model Object containing the constitutive gene +% expression circuit. +% +if nargin > 1 + tspan = varargin{1}; + customtime = true; +end + +% Create the standard model object +tube1 = txtl_extract(extract); +tube2 = txtl_buffer(extract); +tube3 = txtl_newtube('gene_expression'); +txtl_add_dna(tube3, ... + 'p70(50)', 'rbs(20)', 'deGFP(1000)', 0, 'plasmid'); +Mobj1 = txtl_combine([tube1, tube2, tube3]); +cs1 = getconfigset(Mobj1); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); + +set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', tspan(end)*1.0e-6*0.1); +set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 +tic +if customtime + [simData1] = txtl_runsim(Mobj1,tspan(end)); + else +[simData1] = txtl_runsim(Mobj1,8*60*60); +end +toc + +%% Globalize irreverisble reactions too +rxstr = {'[protein deGFP] -> [protein deGFP*]' + '[term_RNAP70:DNA p70--rbs--deGFP] -> RNAP70 + [DNA p70--rbs--deGFP]' + '[RNA rbs--deGFP:RNase] -> RNase' + '[AA:AGTP:Ribo:RNA rbs--deGFP:RNase] -> AGTP + AA + Ribo + RNase' + '[Ribo:RNA rbs--deGFP:RNase] -> Ribo + RNase'}; + +pname_cat = {'TXTL_PROT_deGFP_MATURATION' +'TXTL_RNAPBOUND_TERMINATION_RATE' +'TXTL_RNAdeg_catalysis' +'TXTL_RNAdeg_catalysis' +'TXTL_RNAdeg_catalysis'}; + +k_cat = {0.00231049 +0.05 +0.00277778 +0.00277778 +0.00277778}; + +globalCatalysisParams = struct('rxStr', rxstr,... + 'paramName', pname_cat,... + 'paramValue', k_cat); + + +for k = 1: length(globalCatalysisParams) +createFrateRules(Mobj1, globalCatalysisParams(k).rxStr,... + globalCatalysisParams(k).paramName,... + globalCatalysisParams(k).paramValue); +end + +%% Define the parameters to move to global scope to allow for Kd estimation +rxstr = {'[RNA rbs--deGFP] + Ribo <-> [Ribo:RNA rbs--deGFP]'; + '[DNA p70--rbs--deGFP] + RNAP70 <-> [RNAP70:DNA p70--rbs--deGFP]' + 'RNAP + [protein sigma70] <-> RNAP70' + '[RNAP70:DNA p70--rbs--deGFP] + AGTP <-> [AGTP:RNAP70:DNA p70--rbs--deGFP]' + '[RNAP70:DNA p70--rbs--deGFP] + CUTP <-> [CUTP:RNAP70:DNA p70--rbs--deGFP]' + '[AGTP:RNAP70:DNA p70--rbs--deGFP] + CUTP <-> [CUTP:AGTP:RNAP70:DNA p70--rbs--deGFP]' + '[CUTP:RNAP70:DNA p70--rbs--deGFP] + AGTP <-> [CUTP:AGTP:RNAP70:DNA p70--rbs--deGFP]' + '[Ribo:RNA rbs--deGFP] + AA + AGTP <-> [AA:AGTP:Ribo:RNA rbs--deGFP]' + '[RNA rbs--deGFP] + RNase <-> [RNA rbs--deGFP:RNase]' + '[AA:AGTP:Ribo:RNA rbs--deGFP] + RNase <-> [AA:AGTP:Ribo:RNA rbs--deGFP:RNase]' + '[Ribo:RNA rbs--deGFP] + RNase <-> [Ribo:RNA rbs--deGFP:RNase]'}; + +pname = {'TXTL_RBS_Ribo_deGFP'; + 'TXTL_P70_RNAPbound_deGFP' + 'TXTL_RNAP_S70' + 'TXTL_NTP_RNAP_1' + 'TXTL_NTP_RNAP_1' + 'TXTL_NTP_RNAP_2' + 'TXTL_NTP_RNAP_2' + 'TXTL_AA' + 'TXTL_RNAdeg' + 'TXTL_RNAdeg' + 'TXTL_RNAdeg'}; +% using defaults from above. +Kdval = {104/0.23; + 725.07/0.06; + 0.1/10; + 1.2e+10 / 100000; + 1.2e+10 / 100000; + 1.2e7 / 100; + 1.2e7 / 100; + 325046 / 9.055; + 2000 / 10; + 2000 / 10; + 2000 / 10}; +Fval = {0.23; + 0.06; + 10; + 100000; + 100000; + 100; + 100; + 9.055; + 10; + 10; + 10}; + +globalKdRules = struct('rxStr', rxstr,... + 'paramName', pname,... + 'kdVal', Kdval,... + 'fVal', Fval); + + +% Create Kd rules, adding parameters to the global scope +for k = 1: length(globalKdRules) +createKdRules(Mobj1, globalKdRules(k).rxStr,... + globalKdRules(k).paramName,... + globalKdRules(k).kdVal,... + globalKdRules(k).fVal); +end + + + +%% +speciesGroups = struct('summedSpeciesName', {'TotalRNA'},... + 'speciesToSum', {{'[RNA rbs--deGFP]', '[Ribo:RNA rbs--deGFP]',... + '[AA:AGTP:Ribo:RNA rbs--deGFP]', '[RNA rbs--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA rbs--deGFP:RNase]', '[Ribo:RNA rbs--deGFP:RNase]'}}); + +% Create the rule for total RNA (or total whatever) +for i = 1:length(speciesGroups) + expr = [speciesGroups(i).summedSpeciesName ' = ']; + nSpToSum = length(speciesGroups(i).speciesToSum); + for j = 1:nSpToSum-1 + expr = [expr speciesGroups(i).speciesToSum{j} ' + ']; + end + expr = [expr speciesGroups(i).speciesToSum{nSpToSum}]; + txtl_addspecies(Mobj1, speciesGroups(i).summedSpeciesName, 0); + ruleObj = addrule(Mobj1, expr, 'repeatedAssignment'); +end + +%% Create a rule for consumption reaction using length based formula + +%%%% FOR TX +% calculate tx rate. the rna len can be extracted from the userdata if +% desired. dont need to do that just yet. +rnalen = 20 + 1000; %utr length and gene length in base pairs. +elongrate = 1.5 ; % the parameter name is k_elon. this gets varied in estimation. +rx = sbioselect(Mobj1, 'reaction', ... + '[CUTP:AGTP:RNAP70:DNA p70--rbs--deGFP] -> [term_RNAP70:DNA p70--rbs--deGFP] + [RNA rbs--deGFP]'); % +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', 'TXTL_transcription_rate1'); +pTarget.delete; +rx.KineticLaw.ParameterVariableNames = 'TXTL_transcription_rate1'; + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'TXTL_transcription_rate1')) +addparameter(Mobj1, 'TXTL_transcription_rate1', elongrate/rnalen); +end + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'k_elon')) +addparameter(Mobj1, 'k_elon', elongrate); +end + +ruleStr = ['TXTL_transcription_rate1 = k_elon/' num2str(rnalen)]; + +if isempty(sbioselect(Mobj1,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj1, ruleStr, 'initialAssignment'); +end + +rx = sbioselect(Mobj1, 'reaction', ... + '[CUTP:AGTP:RNAP70:DNA p70--rbs--deGFP] -> RNAP70 + [DNA p70--rbs--deGFP]'); % +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', 'TXTL_NTP_consumption'); +pTarget.delete; +rx.KineticLaw.ParameterVariableNames = 'TXTL_k_con_TX'; + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'TXTL_k_con_TX')) +addparameter(Mobj1, 'TXTL_k_con_TX', (rnalen/4-1)*(elongrate/rnalen)); +end + +ruleStr = ['TXTL_k_con_TX = (' num2str(rnalen) '/4-1)*(k_elon/' num2str(rnalen) ')']; +if isempty(sbioselect(Mobj1,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj1, ruleStr, 'initialAssignment'); +end + +%%%% FOR TL +genelen = 1000; %utr length and gene length in base pairs. +elongrate_prot = 4 ; % the parameter name is k_elon. this gets varied in estimation. + +rx = sbioselect(Mobj1, 'reaction', ... + '[AA:AGTP:Ribo:RNA rbs--deGFP] -> [RNA rbs--deGFP] + [protein deGFP] + Ribo'); % + +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', 'TXTL_TL_rate'); +pTarget.delete; +rx.KineticLaw.ParameterVariableNames = 'TXTL_TL_rate'; + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'TXTL_TL_rate')) +addparameter(Mobj1, 'TXTL_TL_rate', elongrate_prot/genelen); +end + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'k_elon_prot')) +addparameter(Mobj1, 'k_elon_prot', elongrate_prot); +end + +ruleStr = ['TXTL_TL_rate = k_elon_prot/' num2str(genelen)]; + +if isempty(sbioselect(Mobj1,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj1, ruleStr, 'initialAssignment'); +end + +rx = sbioselect(Mobj1, 'reaction', ... + '[AA:AGTP:Ribo:RNA rbs--deGFP] -> [RNA rbs--deGFP] + Ribo'); % + +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', 'TXTL_TL_AA_consumption'); +pTarget.delete; +rx.KineticLaw.ParameterVariableNames = 'TXTL_k_con_TL'; + + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'TXTL_k_con_TL')) +addparameter(Mobj1, 'TXTL_k_con_TL', (genelen-1)*(elongrate_prot/genelen)); +end + +ruleStr = ['TXTL_k_con_TL = (' num2str(genelen) '-1)*(k_elon_prot/' num2str(genelen) ')']; +if isempty(sbioselect(Mobj1,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj1, ruleStr, 'initialAssignment'); +end + +end + diff --git a/mcmc_simbio/src/create_mobj_geneexpr.m b/mcmc_simbio/src/create_mobj_geneexpr.m new file mode 100755 index 0000000..edc80c1 --- /dev/null +++ b/mcmc_simbio/src/create_mobj_geneexpr.m @@ -0,0 +1,267 @@ +function [ Mobj1 ] = create_mobj_geneexpr(extract, varargin) +% commit test +%create_mobj_geneexpr Create a standard TXTL toolbox gene expression +%circuit +% [ Mobj1 ] = create_mobj_geneexpr(extract, speciesGroups, globalKdRules) +% +% Input Arguments: +% +% extract = a string specifying the extract batch for the txtl Modeling +% toolbox, example: 'E30VNPRL' +% +% speciesGroups = a structure containing info on additional species to be +% created which are the sum of some of the existing species. The main +% example of this is TotalRNA, which is the sum of all the GFP RNA in +% the system. +% +% globalKdRules is a struct which looks like this: +% globalKdRules = +% +% 2x1 struct array with fields: +% +% rxStr +% paramName +% kdVal +% fVal +% +% globalKdRules(1) +% rxStr: '[RNA rbs--deGFP] + Ribo <-> [Ribo:RNA...' +% paramName: 'TXTL_RBS_Ribo_deGFP' +% kdVal: 452.1739 +% fVal: 0.2300 +% +% See the file function_design_script for an example of the construction of +% the struct. +% +% OUTPUT Arguments +% Mobj1: a Simbiology model Object containing the constitutive gene +% expression circuit. +% +if nargin > 1 + tspan = varargin{1}; + customtime = true; +end + +% Create the standard model object +tube1 = txtl_extract(extract); +tube2 = txtl_buffer(extract); +tube3 = txtl_newtube('gene_expression'); +txtl_add_dna(tube3, ... + 'p70(50)', 'rbs(20)', 'deGFP(1000)', 1, 'plasmid'); +Mobj1 = txtl_combine([tube1, tube2, tube3]); +cs1 = getconfigset(Mobj1); +set(cs1.RuntimeOptions, 'StatesToLog', 'all'); + +set(cs1.SolverOptions, 'AbsoluteToleranceScaling', 1); +set(cs1.SolverOptions, 'AbsoluteTolerance', 1.0e-6); +set(cs1.SolverOptions, 'AbsoluteToleranceStepSize', tspan(end)*1.0e-6*0.1); +set(cs1.SolverOptions, 'RelativeTolerance', 1.0e-6); +% try: AbsoluteToleranceStepSize = AbsoluteTolerance * StopTime * 0.1 +tic +if customtime + [simData1] = txtl_runsim(Mobj1,tspan(end)); + else +[simData1] = txtl_runsim(Mobj1,8*60*60); +end +toc + +%% Globalize irreverisble reactions too +rxstr = {'[protein deGFP] -> [protein deGFP*]' + '[term_RNAP70:DNA p70--rbs--deGFP] -> RNAP70 + [DNA p70--rbs--deGFP]' + '[RNA rbs--deGFP:RNase] -> RNase' + '[AA:AGTP:Ribo:RNA rbs--deGFP:RNase] -> AGTP + AA + Ribo + RNase' + '[Ribo:RNA rbs--deGFP:RNase] -> Ribo + RNase'}; + +pname_cat = {'TXTL_PROT_deGFP_MATURATION' +'TXTL_RNAPBOUND_TERMINATION_RATE' +'TXTL_RNAdeg_catalysis' +'TXTL_RNAdeg_catalysis' +'TXTL_RNAdeg_catalysis'}; + +k_cat = {0.00231049 +0.05 +0.00277778 +0.00277778 +0.00277778}; + +globalCatalysisParams = struct('rxStr', rxstr,... + 'paramName', pname_cat,... + 'paramValue', k_cat); + + +for k = 1: length(globalCatalysisParams) +createFrateRules(Mobj1, globalCatalysisParams(k).rxStr,... + globalCatalysisParams(k).paramName,... + globalCatalysisParams(k).paramValue); +end + +%% Define the parameters to move to global scope to allow for Kd estimation +rxstr = {'[RNA rbs--deGFP] + Ribo <-> [Ribo:RNA rbs--deGFP]'; + '[DNA p70--rbs--deGFP] + RNAP70 <-> [RNAP70:DNA p70--rbs--deGFP]' + 'RNAP + [protein sigma70] <-> RNAP70' + '[RNAP70:DNA p70--rbs--deGFP] + AGTP <-> [AGTP:RNAP70:DNA p70--rbs--deGFP]' + '[RNAP70:DNA p70--rbs--deGFP] + CUTP <-> [CUTP:RNAP70:DNA p70--rbs--deGFP]' + '[AGTP:RNAP70:DNA p70--rbs--deGFP] + CUTP <-> [CUTP:AGTP:RNAP70:DNA p70--rbs--deGFP]' + '[CUTP:RNAP70:DNA p70--rbs--deGFP] + AGTP <-> [CUTP:AGTP:RNAP70:DNA p70--rbs--deGFP]' + '[Ribo:RNA rbs--deGFP] + AA + AGTP <-> [AA:AGTP:Ribo:RNA rbs--deGFP]' + '[RNA rbs--deGFP] + RNase <-> [RNA rbs--deGFP:RNase]' + '[AA:AGTP:Ribo:RNA rbs--deGFP] + RNase <-> [AA:AGTP:Ribo:RNA rbs--deGFP:RNase]' + '[Ribo:RNA rbs--deGFP] + RNase <-> [Ribo:RNA rbs--deGFP:RNase]'}; + +pname = {'TXTL_RBS_Ribo_deGFP'; + 'TXTL_P70_RNAPbound_deGFP' + 'TXTL_RNAP_S70' + 'TXTL_NTP_RNAP_1' + 'TXTL_NTP_RNAP_1' + 'TXTL_NTP_RNAP_2' + 'TXTL_NTP_RNAP_2' + 'TXTL_AA' + 'TXTL_RNAdeg' + 'TXTL_RNAdeg' + 'TXTL_RNAdeg'}; + +% using defaults from above. +Kdval = {104/0.23; + 725.07/0.06; + 0.1/10; + 1.2e+10 / 100000; + 1.2e+10 / 100000; + 1.2e7 / 100; + 1.2e7 / 100; + 325046 / 9.055; + 2000 / 10; + 2000 / 10; + 2000 / 10}; + +Fval = {0.23; + 0.06; + 10; + 100000; + 100000; + 100; + 100; + 9.055; + 10; + 10; + 10}; + +globalKdRules = struct('rxStr', rxstr,... + 'paramName', pname,... + 'kdVal', Kdval,... + 'fVal', Fval); + + +% Create Kd rules, adding parameters to the global scope +for k = 1: length(globalKdRules) +createKdRules(Mobj1, globalKdRules(k).rxStr,... + globalKdRules(k).paramName,... + globalKdRules(k).kdVal,... + globalKdRules(k).fVal); +end + + + +%% +speciesGroups = struct('summedSpeciesName', {'TotalRNA'},... + 'speciesToSum', {{'[RNA rbs--deGFP]', '[Ribo:RNA rbs--deGFP]',... + '[AA:AGTP:Ribo:RNA rbs--deGFP]', '[RNA rbs--deGFP:RNase]',... + '[AA:AGTP:Ribo:RNA rbs--deGFP:RNase]', '[Ribo:RNA rbs--deGFP:RNase]'}}); + +% Create the rule for total RNA (or total whatever) +for i = 1:length(speciesGroups) + expr = [speciesGroups(i).summedSpeciesName ' = ']; + nSpToSum = length(speciesGroups(i).speciesToSum); + for j = 1:nSpToSum-1 + expr = [expr speciesGroups(i).speciesToSum{j} ' + ']; + end + expr = [expr speciesGroups(i).speciesToSum{nSpToSum}]; + txtl_addspecies(Mobj1, speciesGroups(i).summedSpeciesName, 0); + ruleObj = addrule(Mobj1, expr, 'repeatedAssignment'); +end + +%% Create a rule for consumption reaction using length based formula + +%%%% FOR TX +% calculate tx rate. the rna len can be extracted from the userdata if +% desired. dont need to do that just yet. +rnalen = 20 + 1000; %utr length and gene length in base pairs. +elongrate = 1.5 ; % the parameter name is k_elon. this gets varied in estimation. +rx = sbioselect(Mobj1, 'reaction', ... + '[CUTP:AGTP:RNAP70:DNA p70--rbs--deGFP] -> [term_RNAP70:DNA p70--rbs--deGFP] + [RNA rbs--deGFP]'); % +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', 'TXTL_transcription_rate1'); +pTarget.delete; +rx.KineticLaw.ParameterVariableNames = 'TXTL_transcription_rate1'; + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'TXTL_transcription_rate1')) +addparameter(Mobj1, 'TXTL_transcription_rate1', elongrate/rnalen); +end + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'k_elon')) +addparameter(Mobj1, 'k_elon', elongrate); +end + +ruleStr = ['TXTL_transcription_rate1 = k_elon/' num2str(rnalen)]; + +if isempty(sbioselect(Mobj1,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj1, ruleStr, 'initialAssignment'); +end + +rx = sbioselect(Mobj1, 'reaction', ... + '[CUTP:AGTP:RNAP70:DNA p70--rbs--deGFP] -> RNAP70 + [DNA p70--rbs--deGFP]'); % +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', 'TXTL_NTP_consumption'); +pTarget.delete; +rx.KineticLaw.ParameterVariableNames = 'TXTL_k_con_TX'; + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'TXTL_k_con_TX')) +addparameter(Mobj1, 'TXTL_k_con_TX', (rnalen/4-1)*(elongrate/rnalen)); +end + +ruleStr = ['TXTL_k_con_TX = (' num2str(rnalen) '/4-1)*(k_elon/' num2str(rnalen) ')']; +if isempty(sbioselect(Mobj1,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj1, ruleStr, 'initialAssignment'); +end + +%%%% FOR TL +genelen = 1000; %utr length and gene length in base pairs. +elongrate_prot = 4 ; % the parameter name is k_elon. this gets varied in estimation. + +rx = sbioselect(Mobj1, 'reaction', ... + '[AA:AGTP:Ribo:RNA rbs--deGFP] -> [RNA rbs--deGFP] + [protein deGFP] + Ribo'); % + +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', 'TXTL_TL_rate'); +pTarget.delete; +rx.KineticLaw.ParameterVariableNames = 'TXTL_TL_rate'; + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'TXTL_TL_rate')) +addparameter(Mobj1, 'TXTL_TL_rate', elongrate_prot/genelen); +end + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'k_elon_prot')) +addparameter(Mobj1, 'k_elon_prot', elongrate_prot); +end + +ruleStr = ['TXTL_TL_rate = k_elon_prot/' num2str(genelen)]; + +if isempty(sbioselect(Mobj1,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj1, ruleStr, 'initialAssignment'); +end + +rx = sbioselect(Mobj1, 'reaction', ... + '[AA:AGTP:Ribo:RNA rbs--deGFP] -> [RNA rbs--deGFP] + Ribo'); % + +pTarget = sbioselect(rx, 'type', 'parameter', 'Name', 'TXTL_TL_AA_consumption'); +pTarget.delete; +rx.KineticLaw.ParameterVariableNames = 'TXTL_k_con_TL'; + + +if isempty(sbioselect(Mobj1,'Type','Parameter', 'Name', 'TXTL_k_con_TL')) +addparameter(Mobj1, 'TXTL_k_con_TL', (genelen-1)*(elongrate_prot/genelen)); +end + +ruleStr = ['TXTL_k_con_TL = (' num2str(genelen) '-1)*(k_elon_prot/' num2str(genelen) ')']; +if isempty(sbioselect(Mobj1,'Type','Rule', 'Rule', ruleStr)) + addrule(Mobj1, ruleStr, 'initialAssignment'); +end + +end + diff --git a/mcmc_simbio/src/curvewiseMedian.m b/mcmc_simbio/src/curvewiseMedian.m new file mode 100755 index 0000000..12ec50f --- /dev/null +++ b/mcmc_simbio/src/curvewiseMedian.m @@ -0,0 +1,17 @@ +function medianval = curvewiseMedian(dataMat) + % Compute the median of a set of curves given in dataMat + % (of dimensions #points x #curves) using the max value of + % each curve to order the curves. If there is an even number + % of curves, then the larger curve is used. + + + [mx, I] = sort(max(dataMat)); + if mod(numel(I), 2)==0 + ix = I(numel(I)/2+1); + else + ix = I((numel(I)+1)/2); + end + medianval = dataMat(:,ix); +end + + diff --git a/mcmc_simbio/src/data_artificial.m b/mcmc_simbio/src/data_artificial.m new file mode 100755 index 0000000..7085b07 --- /dev/null +++ b/mcmc_simbio/src/data_artificial.m @@ -0,0 +1,210 @@ +% function [data_info] = data_artificial(mobj, mi, tv, varargin) +% % use simbiology model object to generate artificial data. +% % +% % Dosing and measurement strategy are defined by the mcmc_info struct (mi), +% % and the time points defined by the vector tv. Additional +% % name-value pair arguments can be specified. +% % +% % REQUIRED INPUTS +% % mobj: simbiology model object. +% % +% % mi: mcmc_info struct. Type 'help mcmc_info' in the command line to read more +% % about this. +% % +% % tv: a vector of timepoints which the data in the output data array will +% % correspond to. These are the poitns at which the model will be simulated to +% % compute the data values. +% % +% % +% % OPTIONAL NAME VALUE PAIR ARGUMENTS - used to populate the data_info struct. +% % +% % 'dataInfo': Human readable description of the data. Should be specified using +% % the format that makes it printable with the function fprintf. (so newline +% % characters \n at the ver least, for example.). If not specified, its value is +% % simply 'Artificial Data' +% % +% % 'timeUnits': String specifying the units of the time axis. Default is 'seconds' +% % +% % 'measuredNames': A 1 x number of measured species cell array of the strings +% % specifying which species are dosed. If not specified, the strings from the +% % mcmc_info struct will be used. When the measured species there is an aggregate +% % of a number of species in the model, a string [xxxxxx ' + ...'] is used, where +% % xxxx is the first string within the list of species whose concentrations get +% % added. +% % +% % 'dataUnits': A cell array of strings specifying the units of the measured +% % species. If not specified, the default is 'nM'. +% % +% % 'dosedNames': A 1 x number of dosed species cell array of the strings specifying +% % which species are dosed. These strings should correspond to the strings in +% % the dosedNames field in the mcmc_info struct. If this is not specified, then +% % those very values from the mcmc_info struct are used. +% % +% % 'doseUnits': A cell array of strings specifying the units of the +% % dosed species. If not specified, the default is 'nM'. +% % +% % 'params', VALUE, where VALUE is a vector of nonnegative parameter values, +% % ordered according to mi.names_unord (the unordered array of parameter and +% % species names. ) +% % Note that the parameter values are NOT log transformed, ie, they all lie +% % in the nonnegative orthant. Parameter +% % values are an optional argument, and if this argument is not specified, +% % then the geometric mean of the rows (each of which has 2 elements) of +% % exp(mi.paramranges) will be as the parameter value. +% % +% % 'noise', VALUE; where VALUE is a vector of standard deviations of the gaussian +% % noise added to the data, each element corresponding to one measured +% % species. +% % +% % 'replicates', VALUE, where VALUE is a positive interger of the number +% % of replicates. +% % +% % OUTPUTS: This function returns a data_info struct with fields +% % ------------------------------------------ +% % +% % 'dataInfo': A human readable text description of the data. If not specified +% % as a name value pair input argument, the string 'Artificial Data' is used. +% % +% % 'timeVector': vector of timepoints, same as tv, a required positional input. +% % +% % 'timeUnits': units of the time vector. Allowed options are: +% % 'seconds', 'minutes', 'hours', 'days', 'weeks'. If no units are specified +% % as a name value input, then the units are specified as 'seconds'. +% % +% % 'dataArray': An array contianing the raw data that is generated by simulating +% % the data according to the mcmc_info struct. Typically has dimensions +% % corresponding to timepoints x measured outputs x replicates x doses. +% % +% % 'measuredNames': A 1 x number of measured species cell array of the strings +% % specifying which species are dosed. These are not strings corresponding to +% % the species in the model. Takes from the corresponding name value pair input +% % argument. If not specified, the values are taken from the mcmc_info struct. +% % +% % 'dataUnits': A 1 x number measured species cell array of units corresponding to +% % the raw data in the dataArray. If no units are specified, then nM are used. +% % +% % 'dimensionLabels': a 1 by length(size(data_info.dataArray)) cell array of +% % labels for the dimensions of the dataArray. +% % +% % 'dosedNames': A 1 x number of dosed species cell array of the strings specifying +% % which species are dosed. These are not strings corresponding to the species +% % in the model. See mcmc_info constructor functions for that. +% % +% % 'dosedVals': A matrix of dose values of size +% % # of dosed species by # of dose combinations +% % +% % 'doseUnits': A 1 x number of dosed species cell array of strings specifying the +% % units of the dosed species. If no units are +% % +% % ------------------------------------------ +% % +% % +% +% % Copyright (c) 2018, Vipul Singhal, Caltech +% % Permission is hereby granted, free of charge, to any person obtaining a copy +% % of this software and associated documentation files (the "Software"), to deal +% % in the Software without restriction, including without limitation the rights +% % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% % copies of the Software, and to permit persons to whom the Software is +% % furnished to do so, subject to the following conditions: +% +% % The above copyright notice and this permission notice shall be included in all +% % copies or substantial portions of the Software. +% +% % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% % SOFTWARE. +% +% +% +% pdefaults = geomean(exp(mi.paramranges), 2); % !TODO check this +% ms = mi.measuredSpecies; +% noisedefaults = zeros(length(ms), 1); +% dimensionLabels = {'time points', 'measured species', 'replicates', 'doses'}; +% p = inputParser; +% +% addParameter(p, 'replicates', 1, @isnumeric); % +% addParameter(p, 'params', pdefaults, @isnumeric); +% addParameter(p, 'noise', noisedefaults, @isnumeric); % the default is 0 +% addParameter(p, 'timeUnits', 'seconds', @ischar); +% addParameter(p, 'dataUnits', 'nM'); +% addParameter(p, 'dosedVals', mi.dosedVals); +% addParameter(p, 'dosedNames', mi.dosedNames); +% addParameter(p, 'doseUnits', 'nM'); +% addParameter(p, 'params', pdefaults); +% addParameter(p, 'dataInfo', ['Artificial Data']); +% addParameter(p, 'measuredNames', mi.measuredSpecies); % default: empty strings +% addParameter(p, 'dimensionLabels', dimensionLabels); +% +% parse(p, varargin{:}); +% p = p.Results; +% +% configsetObj = getconfigset(mobj, 'active'); +% set(configsetObj, 'StopTime', tv(end)); +% +% noisevec = p.noise; +% % initialize the data array +% da = zeros(length(tv), length(mi.measuredSpecies),... +% p.replicates, size(mi.dosedVals, 2)); +% ms = mi.measuredSpecies; +% % for each dose, simulate the model +% +% dv = mi.dosedVals; +% +% % set parameters and species initial concentrations in the model +% paramnames = mi.names_unord; +% paramvals = p.params; +% for i = 1:length(paramnames) +% p1 = sbioselect(mobj.parameters, 'Name', paramnames{i}); +% if ~isempty(p1) +% set(p1, 'Value', paramvals(i); +% end +% end +% +% for i = 1:length(paramnames) +% s1 = sbioselect(mobj.species, 'Name', paramnames{i}); +% if ~isempty(s1) +% set(s1, 'InitialValue', paramvals(i)) +% end +% end +% +% % set dose values, simulate model, and populate output data array. +% for dID = 1:size(dv, 2) +% % set the dose value using the mcmc_info struct +% for i = 1:length(p.dosedNames) +% s1 = sbioselect(mobj.species, 'Name', p.dosedNames{i}); +% if ~isempty(s1) +% set(s1, 'InitialValue', p.dosedVals(i)) +% end +% end +% +% % simulate the model. +% sd = sbiosimulate(mobj); +% sd = resample(sd, tv); +% for msID = 1:length(ms) +% measuredSpecies = ms{msID}; +% spSD = selectbyname(sd, measuredSpecies); +% summed_trajectories = sum(spSD.Data, 2); +% % add noise if needed. +% for rID = 1:p.replicates +% da(:, msID, rID, dID) = ... +% summed_trajectories + noisevec(msID)*randn(length(tv), 1); +% end +% end +% end +% +% % make the data_info struct +% di = struct('dataInfo', {p.dataInfo}, ... +% 'timeVector' {tv}, ... +% 'timeUnits', {p.timeUnits} +% 'dataArray' {da},... +% 'measuredNames', {p.measuredNames},... +% 'dataUnits', {p.dataUnits} +% 'dimensionLabels', {p.dimensionLabels}, ... +% 'dosedNames' {p.dosedNames},... +% 'dosedVals', {p.dosedVals}, ... +% 'doseUnits', {p.doseUnits}) diff --git a/mcmc_simbio/src/data_artificial_v2.m b/mcmc_simbio/src/data_artificial_v2.m new file mode 100755 index 0000000..98bc2c9 --- /dev/null +++ b/mcmc_simbio/src/data_artificial_v2.m @@ -0,0 +1,338 @@ +function [di] = data_artificial_v2(mobj, tv, measuredSpecies, ... + dosedNames, dosedVals, activeNames, activeValues, varargin) +% [di] = data_artificial_v2(mobj, tv, measuredSpecies, ... +% dosedNames, dosedVals, activeNames, activeValues, varargin) +% use simbiology model object to generate artificial data. +% +% There are two ways to define the inputs. In the SCALAR MODE, we have: +% +% mobj: simbiology model object +% +% tv: a vector of timepoints which the data in the output data array will +% correspond to. These are the poitns at which the model will be simulated to +% compute the data values. +% +% measuredSpecies: this is a cell array of cell arrays of strings. The +% species in the inner cell array get summed to create the measured +% species. The order of the outer cell array defines the ordering of the +% second dimension of the dataArray property of the data_info struct that +% is output. +% +% dosedNames: Cell array of species that get dosed. +% +% dosedVals: matrix of size #number of dosed species x number of dose +% combinations. +% +% activeNames: cell array of parameters and species names to set in the +% model. +% +% activeValues: vector of corresponding values. Note that the parameter +% values are NOT log transformed, ie, they all lie in the nonnegative orthant. +% +% In the CELL MODE, the main difference is that the data_info output struct +% an now be a non singleton array of length nDatasets. The activeValues +% input is now a cell array of numerical vectors. It has dimensions +% nDatasets x 1 or 1 x nDatasets. +% +% mobj: A 1x1 cell containing a simbiology model object, or a row or column +% cell array of length nDatasets containing model objects. +% +% tv: A 1x1 cell containing a vector of timepoints, or a row or column +% cell array of length nDatasets containing vectors of timepoints. See +% scalar version documentation above for more info. +% +% measuredSpecies: A 1x1 cell containing a cell array of cell arrays of +% strings, or a row or column cell array of length nDatasets containing +% cell array of cell arrays of strings. See scalar version documentation +% above for more info. +% +% dosedNames: A 1x1 cell containing a Cell array of species that get dosed, +% or a row or column cell array of length nDatasets containing +% cell arrays of species that get dosed. See scalar version documentation +% above for more info. +% +% dosedVals: A 1x1 cell containing a matrix of size +% #number of dosed species x number of dose combinations, +% or a row or column cell array of length nDatasets containing +% matrix of size #number of dosed species x number of dose combinations. +% See scalar version documentation above for more info. +% +% activeNames: A 1x1 cell containing a cell array of parameters and species +% names to set, or a row or column cell array of length nDatasets containing +% cell arrays of parameters and species names to set. See scalar version +% documentation above for more info. +% +% activeValues: A 1x1 cell containing a vector of corresponding values, +% or a row or column cell array of length nDatasets containing +% vectors of corresponding values. See scalar version documentation +% above for more info. +% +% +% OPTIONAL NAME VALUE PAIR ARGUMENTS - used to populate the data_info struct. +% If cell mode is active, then all of these are correspindingly encapsulated +% in a 1x1 cell or a row or column cell array of length nDatasets. +% +% 'dataInfo': Human readable description of the data. Should be specified using +% the format that makes it printable with the function fprintf. (so newline +% characters \n at the ver least, for example.). If not specified, its value is +% simply 'Artificial Data'. +% +% 'timeUnits': String specifying the units of the time axis. Default is 'seconds' +% +% 'dataUnits': A cell array of strings specifying the units of the measured +% species. If not specified, the default is 'nM'. +% +% 'doseUnits': A cell array of strings specifying the units of the +% dosed species. If not specified, the default is 'nM'. +% +% 'noise', VALUE; where VALUE is a vector of standard deviations of the gaussian +% noise added to the data, each element corresponding to one measured +% species. +% +% 'replicates', VALUE, where VALUE is a positive interger of the number +% of replicates. +% +% +% OUTPUTS: This function returns a data_info struct with fields +% ------------------------------------------ +% +% 'dataInfo': A human readable text description of the data. If not specified +% as a name value pair input argument, the string 'Artificial Data' is used. +% +% 'timeVector': vector of timepoints, same as tv, a required positional input. +% +% 'timeUnits': units of the time vector. Allowed options are: +% 'seconds', 'minutes', 'hours', 'days', 'weeks'. If no units are specified +% as a name value input, then the units are specified as 'seconds'. +% +% 'dataArray': An array contianing the raw data that is generated by simulating +% the data according to the mcmc_info struct. Typically has dimensions +% corresponding to timepoints x measured outputs x replicates x doses. +% +% 'measuredNames': A 1 x number of measured species cell array of the strings +% specifying which species are dosed. These are not strings corresponding to +% the species in the model. Takes from the corresponding name value pair input +% argument. If not specified, the values are taken from the mcmc_info struct. +% +% 'dataUnits': A 1 x number measured species cell array of units corresponding to +% the raw data in the dataArray. If no units are specified, then nM are used. +% +% 'dimensionLabels': a 1 by length(size(data_info.dataArray)) cell array of +% labels for the dimensions of the dataArray. +% +% 'dosedNames': A 1 x number of dosed species cell array of the strings specifying +% which species are dosed. These are not strings corresponding to the species +% in the model. See mcmc_info constructor functions for that. +% +% 'dosedVals': A matrix of dose values of size +% # of dosed species by # of dose combinations +% +% 'doseUnits': A 1 x number of dosed species cell array of strings specifying the +% units of the dosed species. If no units are +% + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + + +% check the sizes of things: +if iscell(activeValues) + nDatasets = length(activeValues); + cellMode = true; +else + nDatasets = 1; + cellMode = false; +end + +if nDatasets == 1 + assert(~iscell(mobj) && length(mobj) == 1); + assert(~iscell(tv) ); + assert(~iscell(dosedVals)); +end + +if cellMode + + p = inputParser; + + addParameter(p, 'replicates', {1}); % + addParameter(p, 'noise', 'default'); % the default is 0 + addParameter(p, 'timeUnits', {'seconds'}); + addParameter(p, 'dataUnits', {'nM'}); + addParameter(p, 'doseUnits', {'nM'}); + addParameter(p, 'dataInfo', {'Artificial Data'}); + addParameter(p, 'dimensionLabels', {{'time points', 'measured species',... + 'replicates', 'doses'}}); + parse(p, varargin{:}); + p = p.Results; + for i = 1:nDatasets + currmeasuredSpecies = cellcontents(measuredSpecies, i); + + if strcmp(p.noise, 'default') + noisevec = zeros(length(currmeasuredSpecies), 1); + else + noisevec = cellcontents(p.noise, i); + end + nReplicates = cellcontents(p.replicates, i); + timeUnits = cellcontents(p.timeUnits, i); + dataUnits = cellcontents(p.dataUnits, i); + doseUnits = cellcontents(p.doseUnits, i); + dataInfo = cellcontents(p.dataInfo, i); + dimensionLabels = cellcontents(p.dimensionLabels, i); + currmobj = cellcontents(mobj, i); + currtv = cellcontents(tv, i); + currdosedNames = cellcontents(dosedNames, i); + currdosedVals = cellcontents(dosedVals, i); + curractiveNames = cellcontents(activeNames, i); + if ~length(activeValues)>1 + error('what on earth?') + end + curractiveValues = activeValues{i}; + + da = computeArtificialData(currmobj, currtv, noisevec, ... + currmeasuredSpecies, nReplicates, currdosedVals, currdosedNames, ... + curractiveNames, curractiveValues); + + if i ==1 + % make the data_info struct + di = struct('dataInfo', {dataInfo}, ... + 'timeVector', {currtv}, ... + 'timeUnits', {timeUnits},... + 'dataArray', {da},... + 'measuredNames', {currmeasuredSpecies},... + 'dataUnits', {dataUnits},... + 'dimensionLabels', {dimensionLabels}, ... + 'dosedNames', {currdosedNames},... + 'dosedVals', {currdosedVals}, ... + 'doseUnits', {doseUnits}); + else + currdi = struct('dataInfo', {dataInfo}, ... + 'timeVector', {currtv}, ... + 'timeUnits', {timeUnits},... + 'dataArray', {da},... + 'measuredNames', {currmeasuredSpecies},... + 'dataUnits', {dataUnits},... + 'dimensionLabels', {dimensionLabels}, ... + 'dosedNames', {currdosedNames},... + 'dosedVals', {currdosedVals}, ... + 'doseUnits', {doseUnits}); + di = [di; currdi]; + end + end +else + noisedefaults = zeros(length(measuredSpecies), 1); + dimensionLabels = {'time points', 'measured species', 'replicates', 'doses'}; + p = inputParser; + addParameter(p, 'replicates', 1, @isnumeric); % + addParameter(p, 'noise', noisedefaults, @isnumeric); % the default is 0 + addParameter(p, 'timeUnits', 'seconds', @ischar); + addParameter(p, 'dataUnits', 'nM'); + addParameter(p, 'doseUnits', 'nM'); + addParameter(p, 'dataInfo', 'Artificial Data'); + addParameter(p, 'dimensionLabels', dimensionLabels); + parse(p, varargin{:}); + p = p.Results; + noisevec = p.noise; + nReplicates = p.replicates; + + da = computeArtificialData(mobj, tv, noisevec, measuredSpecies, ... + nReplicates, dosedVals, dosedNames, activeNames, activeValues); + + % make the data_info struct + di = struct('dataInfo', {p.dataInfo}, ... + 'timeVector', {tv}, ... + 'timeUnits', {p.timeUnits},... + 'dataArray', {da},... + 'measuredNames', {measuredSpecies},... + 'dataUnits', {p.dataUnits},... + 'dimensionLabels', {p.dimensionLabels}, ... + 'dosedNames', {dosedNames},... + 'dosedVals', {dosedVals}, ... + 'doseUnits', {p.doseUnits}); + +end +end + +function da = computeArtificialData(mobj, tv, noisevec, measuredSpecies, ... + nReplicates, dosedVals, dosedNames, activeNames, activeValues) + +configsetObj = getconfigset(mobj, 'active'); +set(configsetObj, 'StopTime', tv(end)); + + +% initialize the data array +da = zeros(length(tv), length(measuredSpecies),... + nReplicates, size(dosedVals, 2)); + +% set parameters and species initial concentrations in the model +for i = 1:length(activeNames) + p1 = sbioselect(mobj.parameters, 'Name', activeNames{i}); + if ~isempty(p1) + set(p1, 'Value', activeValues(i)); + end +end + +for i = 1:length(activeNames) + s1 = sbioselect(mobj.species, 'Name', activeNames{i}); + if ~isempty(s1) + set(s1, 'InitialAmount', activeValues(i)) + end +end + +% set dose values, simulate model, and populate output data array. +for dID = 1:size(dosedVals, 2) + % set the dose value using the mcmc_info struct + for i = 1:length(dosedNames) + s1 = sbioselect(mobj.species, 'Name', dosedNames{i}); + if ~isempty(s1) + set(s1, 'InitialAmount', dosedVals(i, dID)) + end + end + + % simulate the model. + sd = sbiosimulate(mobj); + sd = resample(sd, tv); + for msID = 1:length(measuredSpecies) + currmeasuredSpecie = measuredSpecies{msID}; + spSD = selectbyname(sd, currmeasuredSpecie); + summed_trajectories = sum(spSD.Data, 2); + % add noise if needed. + for rID = 1:nReplicates + da(:, msID, rID, dID) = ... + summed_trajectories + ... + noisevec(msID)*randn(length(tv), 1); + end + end +end + + +end + +function currcellcontents = cellcontents(cellarray, count) +assert(iscell(cellarray)); + +if length(cellarray)>1 + currcellcontents = cellarray{count}; +else + currcellcontents = cellarray{1}; +end + +end + + + diff --git a/mcmc_simbio/src/drawCuboid.m b/mcmc_simbio/src/drawCuboid.m new file mode 100755 index 0000000..a98bfb2 --- /dev/null +++ b/mcmc_simbio/src/drawCuboid.m @@ -0,0 +1,24 @@ +function [outputArg1,outputArg2] = drawCuboid(inputArg1,inputArg2) +% Need to work on this .Useful in script analysis_vnprl_F2.m +% Detailed explanation goes here + +xc=1; yc=1; zc=1; % coordinated of the center +L=10; % cube size (length of an edge) +alpha=0.8; % transparency (max=1=opaque) + +X = [0 0 0 0 0 1; 1 0 1 1 1 1; 1 0 1 1 1 1; 0 0 0 0 0 1]; +Y = [0 0 0 0 1 0; 0 1 0 0 1 1; 0 1 1 1 1 1; 0 0 1 1 1 0]; +Z = [0 0 1 0 0 0; 0 0 1 0 0 0; 1 1 1 0 1 1; 1 1 1 0 1 1]; + +C='blue'; % unicolor + +X = L*(X-0.5) + xc; +Y = L*(Y-0.5) + yc; +Z = L*(Z-0.5) + zc; + +fill3(X,Y,Z,C,'FaceAlpha',alpha); % draw cube +axis equal + + +end + diff --git a/mcmc_simbio/src/exportmobj.m b/mcmc_simbio/src/exportmobj.m new file mode 100755 index 0000000..6b81611 --- /dev/null +++ b/mcmc_simbio/src/exportmobj.m @@ -0,0 +1,146 @@ +function [da, mi, tv] = exportmobj(mi, data_info, fitOption) +%exportmobj export simbiology model object and update the model info struct +%with the ordering indices and the exported model object. + +nTopo = length(mi); +nGeom = zeros(length(mi),1); +for i = 1:nTopo + nGeom(i) = length(mi(i).dataToMapTo); +end + +% V2 data +% for each topology geometry pair, compute the data to fit +% ASSUME that the data dimensions across geometries is the same +% only differs across topologies at most. +% Despite this, we allow for different geometries within a topology +% to point to different data info array elements, just that all of +% these elements must have the same number of timepoints, measured species, +% replicates and dosing combinations. (version 3 of this code can be even +% more general, with each topo-geom pair getting its own cell. this will be +% slower.) + +da = cell(nTopo, 1); +emo = cell(nTopo, 1); +tv = cell(nTopo, 1); +for i = 1:nTopo % each topology + % each of the nGeom(i) geometries has a data info array element it points to. + % since the dimensions of these is assumed to be equal, we just use the first + % one to set the empty array: + data_info_element = mi(i).dataToMapTo(1); + currda = data_info(data_info_element).dataArray; + % Transform Experimental - compute mean or median or nothing + currda = computeFitOption(currda, fitOption); + da{i} = currda; + tv{i} = data_info(data_info_element).timeVector; + for j = 2:nGeom(i) % each geometry + data_info_element = mi(i).dataToMapTo(j); + currda = data_info(data_info_element).dataArray; + % Transform Experimental - compute mean or median or nothing + currda = computeFitOption(currda, fitOption); + % concatenate in the 5th dimension (the geometries dimension.) + da{i} = cat(5, da{i}, currda); + end + % EXPORT MODEL object to get it ready for MCMC + % the resulting object is of class SimBiology.export.Model + % documentation: + % https://www.mathworks.com/help/simbio/ref/simbiology.export.model-class.html + % Sven Mesecke's blog post on using the exported model class for + % parameter inference applicaton. + % http://sveme.org/how-to-use-global-optimization-toolbox-algorithms-for- + % simbiology-parameter-estimation-in-parallel-part-i.html + + + mobj = mi(i).modelObj; + + enuo = mi(i).namesUnord; % estimated names unordered + + ep = sbioselect(mobj, 'Type', 'parameter', 'Name', ... + mi(i).namesUnord);% est parameters + + es = sbioselect(mobj, 'Type', 'species', 'Name', ... + mi(i).namesUnord);% est species + + + aps = [ep; es]; % active parameters and species + + % reorder the parameter and species so they are in the same order as that + % in the model. + eno = cell(length(aps), 1);% est names ordered + ds = sbioselect(mobj, 'Type', 'species', 'Name', mi(i).dosedNames); + + % bugfix -- APRIL 19 2019: need to also reorder the dose values to + % match the ordering in the model objects value info. See for example: + % + % ds + % + % SimBiology Species Array + % + % Index: Compartment: Name: InitialAmount: InitialAmountUnits: + % 1 contents DNA ptet--utr1--deGFP 0 + % 2 contents aTc 0 + % 3 contents DNA plac--utr1--tetR 0 + % + % mi(3).dosedNames + % + % ans = + % + % 31 cell array + % + % {'DNA ptet--utr1--deGFP'} + % {'DNA plac--utr1--tetR' } + % {'aTc' } + + ndoses = length(mi(i).dosedNames); + doseOrderingIx = zeros(ndoses, 1); + for q = 1:ndoses + + doseOrderingIx(q) = find(cellfun(@(x) strcmp({ds(q).Name}, x),... + mi(i).dosedNames,... + 'UniformOutput', true)); + %IE, mi(i).dosedNames(doseOrderingIx(q)) == ds(q).Name + % ie, use doseOrderingIx to transform mi(i).dosedNames ---> the + % ordering in ds(q).Name, ie, expected by the exported model + % object. + end + + + emo{i} = export(mobj, [ep; es; ds]); % exported model object, dosed species names. + SI = emo{i}.SimulationOptions; + + % each of the nGeom(i) geometries has a data info array element it points to. + % since the dimensions of these is assumed to be equal, we just use the first + % one to set the empty array: + data_info_element = mi(i).dataToMapTo(1); + SI.StopTime = data_info(data_info_element).timeVector(end); + accelerate(emo{i}); + + mi(i).emo = emo{i}; % exported model object. + orderingIx = zeros(length(aps),1); + orderingIx2 = orderingIx; + for k = 1:length(aps) + eno{k} = aps(k).Name; + for kk = 1:length(enuo) + if strcmp(eno{k}, enuo{kk} ) + orderingIx(k) = kk; % eno = enuo(orderingIx); + % the kth element of orderingIx is kk. so the kth element of + % enuo(orderingIx) is enuo(kk). But this is just eno(k). And eno + % has the property of the kth element being eno(k). (as seen + % from "if eno{k} == enuo{kk} ") + + orderingIx2(kk) = k; %i.e., enuo = eno(orderingIx2); + % the kkth element of orderingIx2 is k. so the kk th element of + % eno(orderingIx2) is eno(k). But the vector with this property is + % simply enuo. (as seen from "if eno{k} == enuo{kk} ") + end + end + end + + mi(i).orderingIx = orderingIx; % these two arrays will be VERY useful. + mi(i).orderingIx2 = orderingIx2; % this one being the second. + mi(i).namesOrd = eno; % est names ordered. + mi(i).doseReordering = doseOrderingIx; % dose names that were used to reorder the doses. + mi(i).dosedNames = mi(i).dosedNames(doseOrderingIx); + mi(i).dosedVals = mi(i).dosedVals(doseOrderingIx,:); +end +end + diff --git a/mcmc_simbio/src/gen_residuals.m b/mcmc_simbio/src/gen_residuals.m new file mode 100755 index 0000000..6bfe328 --- /dev/null +++ b/mcmc_simbio/src/gen_residuals.m @@ -0,0 +1,144 @@ +function res = gen_residuals(logp, exportedMdlObj, data_array, timevec, ... + dosedInitVals, measuredSpecies, varargin) +% generate residuals for MCMC +% dosedInitVals needs to be a nDoseCombinations x nSpeciesToDose matrix. +% the concentration of this matrix needs some work from the dosedArray struct. +% logp should be a column vector. in exportedMdlObj, we already have the things +% that can be varied to be just the parameters to be estimated and the species that can be dosed, in that order. +% measuresSpecies is a cell array of strings. +% (unlike the struct in objFun_multiDoseSpecies.m) +% data_array is a length(timevec) * nDoseCombinations by nMeasuredSPecies array. +% the order of the data is the same as the order of the dosing, and needs to be maintained carefully +% +p = inputParser; +% estimation structure is a matrix that specifies which parameters in logp +% to apply to the individual exported model objects. Ie, which parameters +% in logp get estimated for each (model, data, timevec, dose, measured +% species) tuple. +p.addParameter('multiopt_params', [], @isnumeric); +p.parse(varargin{:}) +p = p.Results; +multiparam = p.multiopt_params; + +if ~iscell(exportedMdlObj) + + meanVals = mean(data_array); + + % meanVals = mean(reshape(data_array, [size(data_array, 1) size(data_array, 3)]),1); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + %!TODO is the mean the right statistic, or is the median or max a better statistic? + relWt = wt/sum(wt); + CONC_temp = zeros(length(timevec)*size(dosedInitVals,1), length(measuredSpecies)); + for i = 1:size(dosedInitVals,1) + + sd = simulate(exportedMdlObj, [exp(logp); dosedInitVals(i,:)']); + sd = resample(sd, timevec); + + spSD = selectbyname(sd, measuredSpecies); + % !TODO :test if i can just feed in the cell of strings. + CONC_temp((i-1)*length(timevec) + 1:(i-1)*length(timevec) +... + length(timevec), :) = spSD.Data; % and then just do this. + end + ExpData = data_array; + if isequal(size(CONC_temp), size(ExpData)) + residuals = repmat(relWt, size(CONC_temp,1),1).*(CONC_temp - ExpData); + res = residuals(:); + % scale the residuals by relative weight. THis emphasizes + % the species which are low conc, + % and deemphasizes species which are high in magnitude + % to make them all equally important + else + error('txtl_toolbox:objFun_multiDoseSpecies:incompatibleArrays',... + 'The simulation and experimental data need to be the same sizes.') + end +else + % start combined optimization mode + % check that all the arrays are in the right format. + % I think using cell arrays here is probably very slow. But lets try it + % nonetheless for generality + if ~iscell(data_array) || ~iscell(timevec) || ~iscell(dosedInitVals) ... + || ~iscell(measuredSpecies) + error('txtl_toolbox:genresiduals:inputsIncompatible1',... + 'Cell array expected for data, time vector, dose values, and measured species') + end + assert(isequal(length(exportedMdlObj), length(data_array), ... + length(timevec), length(dosedInitVals), length(measuredSpecies)), ... + 'txtl_toolbox:genresiduals:inputsIncompatible2',... + 'The number of cells in the input arrays must be equal') + + nOpt = length(exportedMdlObj); +% preallocate redidual array for speed + +nres = zeros(nOpt, 1); + + + for kk = 1:nOpt + mS = measuredSpecies{kk}; + tv = timevec{kk}; + nms = length(mS); + nres(kk) = length(tv)*nms; + + end + res = zeros(sum(nres), 1); + + for kk = 1:nOpt + [~, ~, V] = find(multiparam(kk, :)); + lp = logp(V); + da = data_array{kk}; + dIV = dosedInitVals{kk}; + mS = measuredSpecies{kk}; + tv = timevec{kk}; + eMO = exportedMdlObj{kk}; + + meanVals = mean(da); + % meanVals = mean(reshape(data_array, [size(data_array, 1) size(data_array, 3)]),1); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + %!TODO is the mean the right statistic, or is the median or max a better statistic? + relWt = wt/sum(wt); + CONC_temp = zeros(length(tv)*size(dIV,1), length(mS)); + for i = 1:size(dIV,1) + + sd = simulate(eMO, [exp(lp); dIV(i,:)']); + sd = resample(sd, tv); + + spSD = selectbyname(sd, mS); + % !TODO :test if i can just feed in the cell of strings. + CONC_temp((i-1)*length(tv) + 1:(i-1)*length(tv) +length(tv), :) ... + = spSD.Data; % and then just do this. + end + ExpData = da; + if isequal(size(CONC_temp), size(ExpData)) + residuals = repmat(relWt, size(CONC_temp,1),1).*(CONC_temp - ExpData); + residx = (sum(nres(1:(kk-1)))+1):sum(nres(1:kk)); + res(residx) = residuals(:); + % scale the residuals by relative weight. THis emphasizes + % the species which are low conc, + % and deemphasizes species which are high in magnitude + % to make them all equally important + else + error('simulation and experimental data must have same sizes') + end + + end + + % I am not sure how to get away from a for loop. + % !TODO: Ask AS, RMM, or Sam about code vectorization. + % in exportedMdlObjArray, we have already set the dosing. + % All that remains to be set is the parameters. + + + + + % if i can somehow have a construct that only takes params as inputs, + % and then just runs the models and subtracts from the data, instead of + % doing the fol loop after the simulations. + % I dont think I can do that. So lets not try. zzz + + % can try interp1 or sd.resample to see which is faster. + % I think deciding which strategy is faster will require some testing. + + % for now lets just use the naive sd.resample method. + % If its abysmally slow, can try to modify this code to have interp1, + % with the measured species indices predetermined. +end + diff --git a/mcmc_simbio/src/gen_residuals2.m b/mcmc_simbio/src/gen_residuals2.m new file mode 100755 index 0000000..8607d7a --- /dev/null +++ b/mcmc_simbio/src/gen_residuals2.m @@ -0,0 +1,63 @@ +function res = gen_residuals2(logp, exportedMdlObj, data_array, timevec, ... + dosedInitVals, measuredSpecies) +% NOT COMPLETE YET +% this is different from gen_residuals in that the data_array here is +% #timepoints X #doses X #measured species. +% +% dosedInitVals needs to be a nDoseCombinations x nSpeciesToDose matrix. +% the concentration of this matrix needs some work from the dosedArray struct. +% +% logp should be a column vector. in exportedMdlObj, we already have the things +% that can be varied to be just the parameters to be estimated and the species that can be dosed, in that order. +% measuresSpecies is a cell array of strings. +% (unlike the struct in objFun_multiDoseSpecies.m) +% +meanVals = mean(mean(data_array,1),2); + +% meanVals = mean(reshape(data_array, [size(data_array, 1) size(data_array, 3)]),1); +wt = sum(meanVals)./meanVals; %hight mean = lower wt +%!TODO is the mean the right statistic, or is the median or max a better statistic? +relWt = wt/sum(wt); +CONC_temp = zeros(length(timevec)*size(dosedInitVals,1), length(measuredSpecies)); +for i = 1:size(dosedInitVals,1) + + sd = simulate(exportedMdlObj, [exp(logp); dosedInitVals(i,:)']); + sd = resample(sd, timevec); + + spSD = selectbyname(sd, measuredSpecies); + % !TODO :test if i can just feed in the cell of strings. + CONC_temp((i-1)*length(timevec) + 1:(i-1)*length(timevec) +length(timevec), :) = spSD.Data; % and then just do this. +end +ExpData = data_array; +if isequal(size(CONC_temp), size(ExpData)) + residuals = repmat(relWt, size(CONC_temp,1),1).*(CONC_temp - ExpData); + res = residuals(:); + % scale the residuals by relative weight. THis emphasizes + % the species which are low conc, + % and deemphasizes species which are high in magnitude + % to make them all equally important +else + error('txtl_toolbox:objFun_multiDoseSpecies:incompatibleArrays',... + 'The simulation and experimental data need to be the same sizes.') +end + +% I am not sure how to get away from a for loop. +% !TODO: Ask AS, RMM, or Sam about code vectorization. +% in exportedMdlObjArray, we have already set the dosing. +% All that remains to be set is the parameters. + + + + +% if i can somehow have a construct that only takes params as inputs, +% and then just runs the models and subtracts from the data, instead of +% doing the fol loop after the simulations. +% I dont think I can do that. So lets not try. zzz + +% can try interp1 or sd.resample to see which is faster. +% I think deciding which strategy is faster will require some testing. + +% for now lets just use the naive sd.resample method. +% If its abysmally slow, can try to modify this code to have interp1, +% with the measured species indices predetermined. + diff --git a/mcmc_simbio/src/gen_residuals_3.m b/mcmc_simbio/src/gen_residuals_3.m new file mode 100755 index 0000000..80aba2e --- /dev/null +++ b/mcmc_simbio/src/gen_residuals_3.m @@ -0,0 +1,178 @@ +function res = gen_residuals_3(logp, em, data_array, tv, ... + dv, ms, varargin) +% generate residuals for MCMC. +% - logp is a vector of log transformed parameter (and species) values. +% +% - em is an exported simbiology model object +% +% - da (data array) is a matlab array of numbers with dimensions of size +% #timepoints x #measured variables x #ICs (aka dose combinations) +% +% - tv is a time vector, just a vector of timepoints in seconds +% +% - dv is a matrix of dose vals of size # species to +% dose x # dose combinations. We do not need to specify the names of the +% species to dose because +% that gets done when the exported model object gets made. +% +% - ms is a cell array of subcells of strings. so for example, we have +% {{'species a'}, {'species b', 'species c'}} then the first output of the +% model is the trajectory of species a, and the second output is the sum of +% the trajectores of species b and c. These two outputs will respectively +% correspond to the first column and the second column of the data array +% (for a given dose). Note that the strings 'species x' must correspond to +% species in the model object. +% +% There is also a combined optimization mode that will exist in the future. +% I have not really completed it yet, so ignore that for now. The idea is: +% It is a way to estimate shared parameters across models when I want +% to use different data to estimate sets of parameters that overlap in +% different ways across the data. +% +% Vipul Singhal, CIT 2017 + +p = inputParser; +% estimation structure is a matrix that specifies which parameters in logp +% to apply to the individual exported model objects. Ie, which parameters +% in logp get estimated for each (model, data, timevec, dose, measured +% species) tuple. +p.addParameter('multiopt_params', [], @isnumeric); +p.parse(varargin{:}) +p = p.Results; +multiparam = p.multiopt_params; +summed_trajectories = zeros(length(tv), 1); + +if ~iscell(em) + meanVals = mean(mean(data_array, 1), 3); % a 1 by # measured variables array + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); % note that relWt is a row vector. + + CONC_temp = zeros(length(tv), length(ms), size(dv,2)); + for i = 1:size(dv,2) + sd = simulate(em, [exp(logp); dv(:,i)]); + sd = resample(sd, tv); + for j = 1:length(ms) + measuredspecies = ms{j}; + spSD = selectbyname(sd, measuredspecies); + summed_trajectories = sum(spSD.Data, 2); + CONC_temp(:, j, i) = summed_trajectories; + end + end + + ExpData = data_array; + if isequal(size(CONC_temp), size(ExpData)) % both must be #timepoints x + % # measured species x # dose combinations + relWt_tiled = repmat(relWt, size(CONC_temp,1), 1, size(CONC_temp,3)); + residuals = relWt_tiled.*(CONC_temp - ExpData); + res = residuals(:); +% scaledsimdata = relWt_tiled.*(CONC_temp); +% scaleddata = relWt_tiled.*(ExpData); +% figure +% for ccol = 1:2 +% for rrow = 1:4 +% subplot(4, 2, (rrow-1)*2+ccol) +% plot(tv, CONC_temp(:,ccol, rrow), 'r', tv, scaledsimdata(:,ccol, rrow), 'b'); +% hold on +% plot(tv, ExpData(:,ccol, rrow), ':r', tv, scaleddata(:,ccol, rrow), ':b'); +% hold on +% plot(tv, residuals(:,ccol, rrow), 'k'); +% end +% end + +% figure +% for ccol = 1:2 +% for rrow = 1:4 +% subplot(4, 2, (rrow-1)*2+ccol) +% plot(tv, scaledsimdata(:,ccol, rrow), 'b'); +% hold on +% plot(tv, scaleddata(:,ccol, rrow), ':b'); +% hold on +% plot(tv, residuals(:,ccol, rrow), 'k'); +% end +% end + + % scale the residuals by relative weight. THis emphasizes + % the species which are low conc, + % and deemphasizes species which are high in magnitude + % to make them all equally important + else + error('txtl_toolbox:objFun_multiDoseSpecies:incompatibleArrays',... + 'The simulation and experimental data need to be the same sizes.') + end +else + % start combined optimization mode % write this properly later + % check that all the arrays are in the right format. + % I think using cell arrays here is probably very slow. But lets try it + % nonetheless for generality + if ~iscell(data_array) || ~iscell(tv) || ~iscell(dv) ... + || ~iscell(ms) + error('txtl_toolbox:genresiduals:inputsIncompatible1',... + 'Cell array expected for data, time vector, dose values, and measured species') + end + assert(isequal(length(em), length(data_array), ... + length(tv), length(dv), length(ms)), ... + 'txtl_toolbox:genresiduals:inputsIncompatible2',... + 'The number of cells in the input arrays must be equal') + + nOpt = length(em); +% preallocate redidual array for speed + + nres = zeros(nOpt, 1); + + + for kk = 1:nOpt + mS = ms{kk}; + tv = tv{kk}; + nms = length(mS); + nres(kk) = length(tv)*nms; + + end + res = zeros(sum(nres), 1); + + for kk = 1:nOpt + [~, ~, V] = find(multiparam(kk, :)); + lp = logp(V); + da = data_array{kk}; + dIV = dv{kk}; + mS = ms{kk}; + tv = tv{kk}; + eMO = em{kk}; + + meanVals = mean(da); + % meanVals = mean(reshape(data_array, [size(data_array, 1) size(data_array, 3)]),1); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + %!TODO is the mean the right statistic, or is the median or max a better statistic? + relWt = wt/sum(wt); + CONC_temp = zeros(length(tv)*size(dIV,1), length(mS)); + for i = 1:size(dIV,1) + + sd = simulate(eMO, [exp(lp); dIV(i,:)']); + sd = resample(sd, tv); + + spSD = selectbyname(sd, mS); + % !TODO :test if i can just feed in the cell of strings. + CONC_temp((i-1)*length(tv) + 1:(i-1)*length(tv) +length(tv), :) ... + = spSD.Data; % and then just do this. + end + ExpData = da; + if isequal(size(CONC_temp), size(ExpData)) + residuals = repmat(relWt, size(CONC_temp,1),1).*(CONC_temp - ExpData); + residx = (sum(nres(1:(kk-1)))+1):sum(nres(1:kk)); + res(residx) = residuals(:); + % scale the residuals by relative weight. THis emphasizes + % the species which are low conc, + % and deemphasizes species which are high in magnitude + % to make them all equally important + else + error('simulation and experimental data must have same sizes') + end + + end + % can try interp1 or sd.resample to see which is faster. + % I think deciding which strategy is faster will require some testing. + + % for now lets just use the naive sd.resample method. + % If its abysmally slow, can try to modify this code to have interp1, + % with the measured species indices predetermined. +end + diff --git a/mcmc_simbio/src/gen_residuals_3_debug.m b/mcmc_simbio/src/gen_residuals_3_debug.m new file mode 100755 index 0000000..4f1e7a2 --- /dev/null +++ b/mcmc_simbio/src/gen_residuals_3_debug.m @@ -0,0 +1,179 @@ +function [res, residuals, scaledsimdata, scaleddata] ... + = gen_residuals_3_debug(logp, em, data_array, tv, ... + dv, ms, varargin) +% generate residuals for MCMC. +% - logp is a vector of log transformed parameter (and species) values. +% +% - em is an exported simbiology model object +% +% - da (data array) is a matlab array of numbers with dimensions of size +% #timepoints x #measured variables x #ICs (aka dose combinations) +% +% - tv is a time vector, just a vector of timepoints in seconds +% +% - dv is a matrix of dose vals of size # species to +% dose x # dose combinations. We do not need to specify the names of the +% species to dose because +% that gets done when the exported model object gets made. +% +% - ms is a cell array of subcells of strings. so for example, we have +% {{'species a'}, {'species b', 'species c'}} then the first output of the +% model is the trajectory of species a, and the second output is the sum of +% the trajectores of species b and c. These two outputs will respectively +% correspond to the first column and the second column of the data array +% (for a given dose). Note that the strings 'species x' must correspond to +% species in the model object. +% +% There is also a combined optimization mode that will exist in the future. +% I have not really completed it yet, so ignore that for now. The idea is: +% It is a way to estimate shared parameters across models when I want +% to use different data to estimate sets of parameters that overlap in +% different ways across the data. +% +% Vipul Singhal, CIT 2017 + +p = inputParser; +% estimation structure is a matrix that specifies which parameters in logp +% to apply to the individual exported model objects. Ie, which parameters +% in logp get estimated for each (model, data, timevec, dose, measured +% species) tuple. +p.addParameter('multiopt_params', [], @isnumeric); +p.parse(varargin{:}) +p = p.Results; +multiparam = p.multiopt_params; +summed_trajectories = zeros(length(tv), 1); + +if ~iscell(em) + meanVals = mean(mean(data_array, 1), 3); % a 1 by # measured variables array + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); % note that relWt is a row vector. + + CONC_temp = zeros(length(tv), length(ms), size(dv,2)); + for i = 1:size(dv,2) + sd = simulate(em, [exp(logp); dv(:,i)]); + sd = resample(sd, tv); + for j = 1:length(ms) + measuredspecies = ms{j}; + spSD = selectbyname(sd, measuredspecies); + summed_trajectories = sum(spSD.Data, 2); + CONC_temp(:, j, i) = summed_trajectories; + end + end + + ExpData = data_array; + if isequal(size(CONC_temp), size(ExpData)) % both must be #timepoints x + % # measured species x # dose combinations + relWt_tiled = repmat(relWt, size(CONC_temp,1), 1, size(CONC_temp,3)); + residuals = relWt_tiled.*(CONC_temp - ExpData); + res = residuals(:); + scaledsimdata = relWt_tiled.*(CONC_temp); + scaleddata = relWt_tiled.*(ExpData); +% figure +% for ccol = 1:2 +% for rrow = 1:4 +% subplot(4, 2, (rrow-1)*2+ccol) +% plot(tv, CONC_temp(:,ccol, rrow), 'r', tv, scaledsimdata(:,ccol, rrow), 'b'); +% hold on +% plot(tv, ExpData(:,ccol, rrow), ':r', tv, scaleddata(:,ccol, rrow), ':b'); +% hold on +% plot(tv, residuals(:,ccol, rrow), 'k'); +% end +% end + +% figure +% for ccol = 1:2 +% for rrow = 1:4 +% subplot(4, 2, (rrow-1)*2+ccol) +% plot(tv, scaledsimdata(:,ccol, rrow), 'b'); +% hold on +% plot(tv, scaleddata(:,ccol, rrow), ':b'); +% hold on +% plot(tv, residuals(:,ccol, rrow), 'k'); +% end +% end + + % scale the residuals by relative weight. THis emphasizes + % the species which are low conc, + % and deemphasizes species which are high in magnitude + % to make them all equally important + else + error('txtl_toolbox:objFun_multiDoseSpecies:incompatibleArrays',... + 'The simulation and experimental data need to be the same sizes.') + end +else + % start combined optimization mode % write this properly later + % check that all the arrays are in the right format. + % I think using cell arrays here is probably very slow. But lets try it + % nonetheless for generality + if ~iscell(data_array) || ~iscell(tv) || ~iscell(dv) ... + || ~iscell(ms) + error('txtl_toolbox:genresiduals:inputsIncompatible1',... + 'Cell array expected for data, time vector, dose values, and measured species') + end + assert(isequal(length(em), length(data_array), ... + length(tv), length(dv), length(ms)), ... + 'txtl_toolbox:genresiduals:inputsIncompatible2',... + 'The number of cells in the input arrays must be equal') + + nOpt = length(em); +% preallocate redidual array for speed + + nres = zeros(nOpt, 1); + + + for kk = 1:nOpt + mS = ms{kk}; + tv = tv{kk}; + nms = length(mS); + nres(kk) = length(tv)*nms; + + end + res = zeros(sum(nres), 1); + + for kk = 1:nOpt + [~, ~, V] = find(multiparam(kk, :)); + lp = logp(V); + da = data_array{kk}; + dIV = dv{kk}; + mS = ms{kk}; + tv = tv{kk}; + eMO = em{kk}; + + meanVals = mean(da); + % meanVals = mean(reshape(data_array, [size(data_array, 1) size(data_array, 3)]),1); + wt = sum(meanVals)./meanVals; %hight mean = lower wt + %!TODO is the mean the right statistic, or is the median or max a better statistic? + relWt = wt/sum(wt); + CONC_temp = zeros(length(tv)*size(dIV,1), length(mS)); + for i = 1:size(dIV,1) + + sd = simulate(eMO, [exp(lp); dIV(i,:)']); + sd = resample(sd, tv); + + spSD = selectbyname(sd, mS); + % !TODO :test if i can just feed in the cell of strings. + CONC_temp((i-1)*length(tv) + 1:(i-1)*length(tv) +length(tv), :) ... + = spSD.Data; % and then just do this. + end + ExpData = da; + if isequal(size(CONC_temp), size(ExpData)) + residuals = repmat(relWt, size(CONC_temp,1),1).*(CONC_temp - ExpData); + residx = (sum(nres(1:(kk-1)))+1):sum(nres(1:kk)); + res(residx) = residuals(:); + % scale the residuals by relative weight. THis emphasizes + % the species which are low conc, + % and deemphasizes species which are high in magnitude + % to make them all equally important + else + error('simulation and experimental data must have same sizes') + end + + end + % can try interp1 or sd.resample to see which is faster. + % I think deciding which strategy is faster will require some testing. + + % for now lets just use the naive sd.resample method. + % If its abysmally slow, can try to modify this code to have interp1, + % with the measured species indices predetermined. +end + diff --git a/mcmc_simbio/src/gen_residuals_4.m b/mcmc_simbio/src/gen_residuals_4.m new file mode 100755 index 0000000..aeb8006 --- /dev/null +++ b/mcmc_simbio/src/gen_residuals_4.m @@ -0,0 +1,82 @@ +function llike = gen_residuals_4(logp, em, data_array, tv, ... + dv, ms, logresvec, stdev) +%{ +% This code is an intermediary between existing code (gen_residuals_3) and +% the future code that will be the final version. Basically here I +% prototype the capability for the computation of the log likelihood a bit. +% In particular I try to reduce the size of the matrices that must be kept +in memory by computing the log likelihood in parts. +% +% +% - logp is a vector of log transformed parameter (and species) values. +% +% - em is an exported simbiology model object +% +% - da (data array) is a matlab array of numbers with dimensions: +% dim 1: has the length of tv +% dim 2: species (length is # of measured species) +% dim 3: replicates (#replicates) +% dim 4: dosing / ICs +% +% +% - tv is a time vector, just a vector of timepoints in seconds +% +% - dv is a matrix of dose vals of size # species to +% dose x # dose combinations. We do not need to specify the names of the +% species to dose because +% that gets done when the exported model object gets made. +% +% - ms is a cell array of subcells of strings. so for example, we have +% {{'species a'}, {'species b', 'species c'}} then the first output of the +% model is the trajectory of species a, and the second output is the sum of +% the trajectores of species b and c. These two outputs will respectively +% correspond to the first column and the second column of the data array +% (for a given dose). Note that the strings 'species x' must correspond to +% species in the model object. +% +% There is also a combined optimization mode that I will attempt to build here +% soon The idea is: +% It is a way to estimate shared parameters across models when I want +% to use different data to estimate sets of parameters that overlap in +% different ways across the data. +% +% Vipul Singhal, CIT 2017 + %} + + meanVals = mean(mean(mean(data_array, 1), 3), 4); + % a 1 by # measured variables array + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); % note that relWt is a row vector. + + CONC_temp = zeros(length(tv), length(ms), 1, size(dv,2)); + llike = 0; + for i = 1:size(dv,2) + sd = simulate(em, [exp(logp); dv(:,i)]); + sd = resample(sd, tv); + for j = 1:length(ms) + % COMPUTE THE SIMULATED TRAJECTORY + % each set of measures species to sum - can remove the loop + % if each species is individual.. in the main version have a + % different mode + measuredspecies = ms{j}; + spSD = selectbyname(sd, measuredspecies); + summed_trajectories = sum(spSD.Data, 2); + CONC_temp(:, j,1, i) = summed_trajectories; + + % COMPUTE THE RESIDUAL - can use repmat here because the + % matrices are probably not big enough to slow the code down. + % On the other hand, the for loop to do the replicates might + % actually slow the code down. + relWt_tiled = repmat(relWt(1,j), size(CONC_temp,1), 1, size(data_array,3)); + replicatedsimdata = repmat(CONC_temp(:, j,1, i), [1, 1, size(data_array, 3)]); + residuals = relWt_tiled.*(replicatedsimdata - data_array(:, j, :, i)); + res = residuals(:); + llike = llike + sum(logresvec(res, stdev)); + end + end + +end + + + + diff --git a/mcmc_simbio/src/gen_residuals_5.m b/mcmc_simbio/src/gen_residuals_5.m new file mode 100755 index 0000000..0cb1477 --- /dev/null +++ b/mcmc_simbio/src/gen_residuals_5.m @@ -0,0 +1,130 @@ +function llike = gen_residuals_5(logp, em, data_array, tv, ... + dv, ms, logresvec, stdev, parametermap) + +%{ + % Actually the simplest thing I can do rigth now is just shared CSPs. + % this pretty much follows the function log_likelihood_sharedCSP.m + % so 1 model topo. and two geometries (extracts)... or actually any number + % of geometries. and a spec for which + params are the CSPs, and which are the extract specific parameters and + extract specific species. + % + + THIS VERSION OF THE CODE IS THE FIRST CUT AT BUILDING MODELS WHERE + PARAMETERS ARE SHARED ACROSS GEOMETRIES AND TOPOLOGIES +% This version of the code is not the one where we have fully general paraneter sharing +across topologies and geometries (that comes later, and I suspect will be +slower). Here we simply have up to 2 topologies (calibration and test) and +2 geometries (before going to the full arbitrary sharing, we will +generalize this to arbitrary # of topos and geos, but still in the crossed +calib-corr method. + + +% in the more general code: em is an array of exported model objects. Here +we just have em1 and em2 for the two topologies. +% +% I will start with considering the following modes: + x0b, x2b, x0, +% +% - logp is a vector of log transformed parameter (and species) values. +% +% - em is an exported simbiology model object +% +% - da (data array) is a matlab array of numbers with dimensions: +% dim 1: has the length of tv +% dim 2: species (length is # of measured species) +% dim 3: replicates (#replicates) +% dim 4: dosing / ICs +% dim 5: extracts (geometries) +% +% +% - tv is a time vector, just a vector of timepoints in seconds +% +% - dv is a matrix of dose vals of size # species to +% dose x # dose combinations. We do not need to specify the names of the +% species to dose because +% that gets done when the exported model object gets made. +% +% - ms is a cell array of subcells of strings. so for example, we have +% {{'species a'}, {'species b', 'species c'}} then the first output of the +% model is the trajectory of species a, and the second output is the sum of +% the trajectores of species b and c. These two outputs will respectively +% correspond to the first column and the second column of the data array +% (for a given dose). Note that the strings 'species x' must correspond to +% species in the model object. +% +% There is also a combined optimization mode that I will attempt to build here +% soon The idea is: +% It is a way to estimate shared parameters across models when I want +% to use different data to estimate sets of parameters that overlap in +% different ways across the data. +% +% Vipul Singhal, CIT 2017 + %} + + + + espIX = parametermap{1}; + cspIX = parametermap{2}; + nESP = length(espIX); % the ESP indices in the model (not in logpjoint) + nCSP = length(cspIX); % the CSP indices in the model (not in logpjoint) + + + nEnv = size(data_array, 5); + meanVals = mean(mean(mean(mean(data_array, 1), 3), 4), 5); + % a 1 by # measured variables array + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); % note that relWt is a row vector. + + CONC_temp = zeros(length(tv), length(ms)); + % dont need the other dimensions! remove from gen_residuals_4 too. + + + paramvec = zeros(nESP+nCSP,1); + cspindices = (nESP*nEnv+1):length(logp); + logpcsp = logp(cspindices); + paramvec(cspIX) = logpcsp; + + + llike = 0; + for envID = 1:nEnv + % pick out the relevant parameters from the joint parameter vector + espindices = (envID-1)*nESP + (1:nESP); + logpesp = logp(espindices); + paramvec(espIX) = logpesp; + + + % set the vector of parameters and species that get estimated (ie + % non dosing values to simulate with) + + for i = 1:size(dv,2) + sd = simulate(em, [exp(paramvec); dv(:,i)]); + sd = resample(sd, tv); + for j = 1:length(ms) + % COMPUTE THE SIMULATED TRAJECTORY + % each set of measures species to sum - can remove the loop + % if each species is individual.. in the main version have a + % different mode + measuredspecies = ms{j}; + spSD = selectbyname(sd, measuredspecies); + summed_trajectories = sum(spSD.Data, 2); + CONC_temp(:, j) = summed_trajectories; + + % COMPUTE THE RESIDUAL - can use repmat here because the + % matrices are probably not big enough to slow the code down. + % On the other hand, the for loop to do the replicates might + % actually slow the code down. + relWt_tiled = repmat(relWt(1,j), size(CONC_temp,1), 1, size(data_array,3)); + replicatedsimdata = repmat(CONC_temp(:, j), [1, 1, size(data_array, 3)]); + residuals = relWt_tiled.*(replicatedsimdata - data_array(:, j, :, i,envID)); + res = residuals(:); + llike = llike + sum(logresvec(res, stdev)); + end + end + end + +end + + + + diff --git a/mcmc_simbio/src/gen_residuals_v2.m b/mcmc_simbio/src/gen_residuals_v2.m new file mode 100755 index 0000000..0f6339e --- /dev/null +++ b/mcmc_simbio/src/gen_residuals_v2.m @@ -0,0 +1,160 @@ +function llike = gen_residuals_v2(logp, estParamIx, fixedMasterVec, data_array,... + timeVec, mi, logresvec, stdev) +% This code is for computing the log likelihood with parameters spread out over +% multiple models (network topologies) - geometries. +%{ OLD DOCUMENTATION from gen_residuals_4 +% This code is an intermediary between existing code (gen_residuals_3) and +% the future code that will be the final version. Basically here I +% prototype the capability for the computation of the log likelihood a bit. +% In particular I try to reduce the size of the matrices that must be kept +% in memory by computing the log likelihood in parts. +% +% +% - logp is a vector of log transformed parameter (and species) values. +% +% - em is an exported simbiology model object +% +% - da (data array) is a matlab array of numbers with dimensions: +% dim 1: has the length of tv +% dim 2: species (length is # of measured species) +% dim 3: replicates (#replicates) +% dim 4: dosing / ICs +% +% +% - tv is a time vector, just a vector of timepoints in seconds +% +% - dv is a matrix of dose vals of size # species to +% dose x # dose combinations. We do not need to specify the names of the +% species to dose because +% that gets done when the exported model object gets made. +% +% - mspecies is a cell array of subcells of strings. so for example, we have +% {{'species a'}, {'species b', 'species c'}} then the first output of the +% model is the trajectory of species a, and the second output is the sum of +% the trajectores of species b and c. These two outputs will respectively +% correspond to the first column and the second column of the data array +% (for a given dose). Note that the strings 'species x' must correspond to +% species in the model object. +% +% There is also a combined optimization mode that I will attempt to build here +% soon The idea is: +% It is a way to estimate shared parameters across models when I want +% to use different data to estimate sets of parameters that overlap in +% different ways across the data. +% +% Vipul Singhal, CIT 2017 + %} + + % the unpacking happens in steps. (quite similar to integrableLHS_v2) + +fixedMasterVec(estParamIx) = logp; +fullMasterVec = fixedMasterVec; + + + + + + + llike = 0; + + for kk = 1:length(mi) % for each topo + if isfield(mi(kk), 'experimentWeighting') + if ~isempty(mi(kk).experimentWeighting) + % The relative importance of this topology + topoWeight = mi(kk).experimentWeighting; % a scalar number + else + topoWeight = 1; + end + else + topoWeight = 1; + end + + + pmaps = mi(kk).paramMaps; + + % ds = struct('names', {mi(kk).dosednames},... + % 'dosematrix', mi(kk).dosedvals); + + dv = mi(kk).dosedVals; % can doses be reordered in the export process? +% This is very important to check. + if isfield(mi(kk), 'doseWeighting') + % the dose weighting muse have size 1 by number of dose + % combintations. + if isequal(size(mi(kk).doseWeighting), [1 size(dv,2)]) + + % The ralative importance of this topology is given by + doseWeight = mi(kk).doseWeighting; + else + % otherwise, all the doses are equally weighted. + doseWeight = ones(1,size(dv,2)); + end + else + doseWeight = ones(1,size(dv,2)); + end + + em = mi(kk).emo; + mspecies = mi(kk).measuredSpecies; + % for each geom + for hh = 1:size(pmaps, 2) + + % pmaps is in the order defined by the unordered list of names + % in each model info. we need to reorder these indices. + pIX_tg = pmaps(mi(kk).orderingIx, hh); + % THIS REORDERING STEP IS VERY IMPORTANT. + + pvec_tg = fullMasterVec(pIX_tg); + da = data_array{kk}(:, :, :, :, hh); + tv = timeVec{kk}; + + meanVals = mean(mean(mean(da, 1), 3), 4); + % a 1 by # measured variables array + wt = sum(meanVals)./meanVals; %hight mean = lower wt + relWt = wt/sum(wt); % note that relWt is a row vector. + + CONC_temp = zeros(length(tv), length(mspecies), 1, size(dv,2)); + + for ii = 1:size(dv,2) + + % pvec_tg needs to be in the ordered state, ie, + % mi(kk).namesOrd. + + %try + sd = simulate(em, [exp(pvec_tg); dv(:,ii)]); + %catch ME + % disp(ME.identifier); + %end + + sd = resample(sd, tv); + for jj = 1:length(mspecies) + % COMPUTE THE SIMULATED TRAJECTORY + % each set of measures species to sum - can remove the loop + % if each species is individual.. in the main version have a + % different mode + measuredspecies = mspecies{jj}; + spSD = selectbyname(sd, measuredspecies); + summed_trajectories = sum(spSD.Data, 2); + CONC_temp(:, jj,1, ii) = summed_trajectories; + + % COMPUTE THE RESIDUAL - can use repmat here because the + % matrices are probably not big enough to slow the code down. + % On the other hand, the for loop to do the replicates might + % actually slow the code down. + relWt_tiled = repmat(relWt(1,jj), size(CONC_temp,1), 1, size(da,3)); + replicatedsimdata = repmat(CONC_temp(:, jj,1, ii), [1, 1, size(da, 3)]); + residuals = relWt_tiled.*(replicatedsimdata - da(:, jj, :, ii)); + + % multiply the residuals with the topology's relative + % importance, and the dose's relative importance. + res = topoWeight*doseWeight(ii)*residuals(:); + llike = llike + sum(logresvec(res, stdev)); + end + end + end + end + + +end + + + + diff --git a/mcmc_simbio/src/generateStandardPlots.m b/mcmc_simbio/src/generateStandardPlots.m new file mode 100755 index 0000000..0c7f114 --- /dev/null +++ b/mcmc_simbio/src/generateStandardPlots.m @@ -0,0 +1,55 @@ +function mcat_l10 = generateStandardPlots(datafiles, titlestr, legends, plotmode) +% datafiles need to be from the same batch, so that things like +% {'simulatedDataMatrix', 'dosedInitVals','measuredSpecies',... +% 'exportedMdlObj','tspan'}; +% are compatible + + +if strcmp(plotmode, 'txtl') + vars = {'simulatedDataMatrix', 'dosedInitVals','measuredSpecies',... + 'exportedMdlObj','tspan'}; + load(datafiles{1}, vars{:}); + mcat = catMC(datafiles); + mcat_l10 = mcat/log(10); + plotEstimTraces003(mcat,exportedMdlObj,tspan, ... + simulatedDataMatrix, dosedInitVals,... + measuredSpecies);% , 'paramID', [1 2 3] +elseif strcmp(plotmode, 'simplemodel') + + mcat = catMC(datafiles); + mcat_l10 = mcat/log(10); +end + +clear mcat + +plotChains(mcat_l10, 100, legends); +suptitle(titlestr) + +figure +[C,lags,ESS]=eacorr(mcat_l10); +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',ceil(mean(ESS))),... + 'verticalalignment','bottom','horizontalalignment','right') +suptitle(titlestr) +% +figure; +ecornerplot_vse(mcat_l10,... + 'ess', 30,'ks',true, 'color',[.6 .35 .3], ... + 'names', legends, 'fontsize', 16) +% suptitle(titlestr) + +figure; +ecornerplot_vse(mcat_l10,... + 'scatter', true,'transparency',0.01, 'color',[.6 .35 .3], ... + 'names', legends); +suptitle(titlestr); + + + + + +end + diff --git a/mcmc_simbio/src/gwmcmc/.gitattributes b/mcmc_simbio/src/gwmcmc/.gitattributes new file mode 100755 index 0000000..bdb0cab --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/mcmc_simbio/src/gwmcmc/.gitignore b/mcmc_simbio/src/gwmcmc/.gitignore new file mode 100755 index 0000000..958969c --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/.gitignore @@ -0,0 +1,94 @@ + + +repoexclude/ +demos/*.zip +demos/*/ + + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + + +# ========================= +# Operating System Files +# ========================= + +# OSX +# ========================= + +.DS_Store +.AppleDouble +.LSOverride + +# Icon must ends with two \r. +Icon + + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# +# List of files that should be excluded from the public repository. +# + +#this is for preparing the example data +prepare*.m + +#Standard exclude files for matlab: +*.asv +*.m~ +*.mex* +slprj/ + + + +#standard gitignore rules. .. Some not relevant for this particular project but excluded anyway: +#compiled +*.com +*.pyc +*.class +*.dll +*.exe +*.o +*.so + +#compressed files +*.zip +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar + +#logs & dbs +*.log +*.sql +*.sqllite + +#OS generated files +.DS_Store +.DS_Store? +*._ +.Spotlight-V100 +*.Trashes +ehthumbs.db +Thumbs.db diff --git a/mcmc_simbio/src/gwmcmc/README.md b/mcmc_simbio/src/gwmcmc/README.md new file mode 100755 index 0000000..96e0966 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/README.md @@ -0,0 +1,36 @@ + +GWMCMC +======================= + +GWMCMC is an implementation of the Goodman and Weare 2010 Affine +invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +enables bayesian inference. The problem with many traditional MCMC samplers +is that they can have slow convergence for badly scaled problems, and that +it is difficult to optimize the random walk for high-dimensional problems. +This is where the GW-algorithm really excels as it is affine invariant. It +can achieve much better convergence on badly scaled problems. It is much +simpler to get to work straight out of the box, and for that reason it +truly deserves to be called the MCMC hammer. + +![line fitting example ecornerplot](html/ex_linefit_05.png) + +Authors: [Aslak Grinsted](http://www.glaciology.net) + + +## Examples + ++ [Line fitting example](html/ex_linefit.md) ++ [Rosenbrock banana](html/ex_rosenbrockbanana.md) ++ [Be happy](html/ex_behappy.md) ++ [Fitting a trend change model](html/ex_breakfit.md) + + +## Licensing + +The majority of the code is licensed under a very permissive MIT license, but some routines and example data are licensed under other terms. See licensing details in LICENSE.txt and individual files. + + + +## Acknowledgements + +This software has been developed at [Centre for Ice and Climate](http://www.iceandclimate.nbi.ku.dk), Niels Bohr Institute, University of Copenhagen. It is partly inspired by emcee for python, but not modelled after it. diff --git a/mcmc_simbio/src/gwmcmc/animation.m b/mcmc_simbio/src/gwmcmc/animation.m new file mode 100755 index 0000000..2f7ec25 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/animation.m @@ -0,0 +1,83 @@ +n=netcdfobj('C:\Users\Aslak\HugeData\GriddedData\had4_krig_v2_0_0.nc'); + +T=permute(n.vars.temperature_anomaly.value,[2 1 3]); +x=n.vars.longitude.value; +y=n.vars.latitude.value; +[X,Y]=meshgrid(x,y); +up=5; +X=imresize(X,up,'bilinear');Y=imresize(Y,up,'bilinear'); +t=double(n.vars.time.value); +ix=tsM(2) + m=permute(m,[2 3 1]); + else + m=permute(m,[1 3 2]); + end +end + + +M=size(m,1);W=size(m,2);T=size(m,3); +N=W*T; + +lags=(0:T-1)'; +nfft = 2^nextpow2(2*T-1); +C=nan(T,M); +for mix=1:M + c=zeros(T,1); + mm=mean(m(mix,:)); %center data using ensemble average! + for wix=1:W + d=m(mix,wix,:); + d=d(:)-mm; + r=ifft( abs(fft(d,nfft)).^2); + c=c+r(1:T); + end +% C(:,mix)=c./(T-lags); %biased/unbiased +% C(:,mix)=C(:,mix)./C(1,mix); + C(:,mix)=c./c(1); +end +if isreal(m) + C=real(C); +end + +if nargout>2 + ESS=nan(1,size(C,2)); + %we use N/(1+2*sum(ACF)) (eqn 7.11 in DBDA2) + %Here, I assume that the ACF can be approximated with exp(-k/lag) + + for ii=1:size(C,2) + kix=find(C(:,ii)<=0.5,1);%we determine k at the lag where C~=0.5; + if isempty(kix), kix=2; end %use lag1 as fall-back for short chains. TODO:warn? + if (C(kix,ii)<0.05)&&(kix==2), ESS(ii)=N;continue;end %essentially no autocorrelation... + k=-log(C(kix,ii))./lags(kix); + sumACF=1/(exp(k)-1); %http://functions.wolfram.com/ElementaryFunctions/Exp/23/01/0001/ + ESS(ii)=N/(1+2*sumACF); + end +end + +if nargout==0 + plot(lags,C,'.-',lags([1 end]),[0 0],'k'); + grid on + xlabel('lags') + ylabel('autocorrelation'); + clearvars lags C ESS +end diff --git a/mcmc_simbio/src/gwmcmc/ecornerplot.m b/mcmc_simbio/src/gwmcmc/ecornerplot.m new file mode 100755 index 0000000..d907aff --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/ecornerplot.m @@ -0,0 +1,198 @@ +function H=ecornerplot(m,varargin) +%% Corner plot with allowance for effective sample size +% +% ecornerplot(m,[parameter,value]) +% +% INPUTS: +% m: a matrix of values that should be plotted in the corner plot. +% +% +% When m is a 3d matrix (ndims(m)==3), then it is assumed to have the form +% MxWxT as output from GWMCMC, where M is the number of parameters, W is +% the number of walkers, and T is the number of steps in each markov chain. +% +% +% NAMED PARAMETERS: +% range: Restrict visual limits to central [99.5] percentile. +% names: A cell of strings with labels for each parameter in m. +% ks: enable kernel smoothing density instead of histograms [false] +% support: a 2xM matrix with upper and lower limits. +% ess: effective sample size. [default: auto-determine ess using EACORR.] +% - used to adjust bandwidth estimates in kernel density estimates. +% scatter: show scatter plot instead of 2d-kernel density estimate [true if #points<2000]. +% fullmatrix: display upper corner of plotmatrix. [false] +% color: A color-theme for the plot. [.5 .5 .5]. +% grid: show grid. [false]. +% +% +% Notes: The 2d kernel density contours are plotted as the highest density +% contours at intervals of 10%:20%:90% +% +% EXAMPLE: +% mu = [1 -1 1]; C= [.9 .4 .1; .4 .3 .2; .1 .2 1]; +% m=mvnrnd(mu,C,6000); +% m(:,3)=exp(m(:,3)/2); +% ecornerplot(m,'support',[nan nan;nan nan; 0 nan]','ks',true); +% +% Aslak Grinsted 2015 + +if nargin==0 + close all + m=randn(10000,4);%m(:,2)=m(:,2)+100000; + ecornerplot(m,'ks',true,'fullmatrix',false,'grid',true); + error('test mode... ') + return +end + +p = inputParser; +p.addOptional('range',99.5,@isnumeric); +p.addOptional('names',{},@iscellstr); +p.addOptional('ks',false,@islogical); %TODO: allow definition of support? +p.addOptional('support',[]); +p.addOptional('grid',false,@islogical); +p.addOptional('scatter',nan,@islogical); +p.addOptional('fullmatrix',false,@islogical); +p.addOptional('color',[1 1 1]*.5,@(x)all(size(x)==[1 3])) +p.addOptional('ess',[]); +% p.addOptional('truth',[fa],@isnumeric); +p.parse(varargin{:}); +p=p.Results; + + +if (size(m,1)Np + error('Effective Sample Size (ess) must be smaller than number of samples') +end +if M>20 + error('Too many dimensions. You probably don''t want to make that many subplots. ') +end +if isnan(p.scatter) + p.scatter=Np<2000; +end + +p.range=prctile(m,[50+[-1 1]*p.range/2 0 100]); %first 2 +rng=p.range(4,:)-p.range(3,:); +if isempty(p.support),p.support=nan(2,M);end +ix=isnan(p.support(1,:)); p.support(1,ix)=p.range(3,ix)-rng(ix)/4; +ix=isnan(p.support(2,:)); p.support(2,ix)=p.range(4,ix)+rng(ix)/4; + + + + +for ii=length(p.names)+1:M + p.names{ii}=sprintf('m_{%.0f}',ii); +end +% for ii=size(p.truth,2)+1:M +% p.truth(ii,:)=nan; +% end +if p.grid + p.grid='on'; +else + p.grid='off'; +end + +clf +H=nan(M); +for r=1:M + for c=1:max(r,M*p.fullmatrix) + H(r,c)=subaxis(M,M,c,r,'s',0.01,'mb',0.12,'mt',0.05,'ml',0.12,'mr',0.0); + if c==r + if p.ks + [F,X,bw]=ksdensity(m(:,r),'support',p.support(:,r)); %TODO: use ESS + if p.ess0, set(gca,'Ylim',p.range(1:2,r)); end + end + if r==M, xlabel(['^{ }' p.names{c} '_{ }']);end + if (c==1)&(r>1-p.fullmatrix), ylabel(['^{ }' p.names{r} '_{ }']);end + if diff(p.range(1:2,c))>0, set(gca,'Xlim',p.range(1:2,c)'); end + end + +end +h=H(:,2:end);h(isnan(h))=[]; +set(h,'YTickLabel',[]) +h=H(1:M-1,:);h(isnan(h))=[]; +set(h,'XTickLabel',[]) +colormap(bsxfun(@minus,[1 1 1],linspace(0,.7,300)')); + + +%LINK the axes for zooming: +hlink={}; +drawnow +lh=cellfun(@(x)double(x),get(H(~isnan(H)),'Xlabel')); +set(lh,'units','normalized') +set(lh,'position',min(cell2mat(get(lh,'position')))); +hlink{end+1}=linkprop(lh,'position'); +lh=cellfun(@(x)double(x),get(H(~isnan(H)),'Ylabel')); +set(lh,'units','normalized'); +set(lh,'position',min(cell2mat(get(lh,'position')))); +hlink{end+1}=linkprop(lh,'position'); + +for ii=1:M + h=H(:,ii); h(isnan(h))=[]; + set(h,'XLimMode','manual') + hlink{end+1}=linkprop(h,'XLim'); + h=H(ii,1:ii-1); h(isnan(h))=[]; + set(h,'YLimMode','manual') + hlink{end+1}=linkprop(h,{'YLim','YTick'}); +end +setappdata(gcf,'aplotmatrix_linkprop_handles',hlink) + + +if nargout==0 + clearvars H +end diff --git a/mcmc_simbio/src/gwmcmc/ecornerplot_vse.m b/mcmc_simbio/src/gwmcmc/ecornerplot_vse.m new file mode 100755 index 0000000..cad8c8a --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/ecornerplot_vse.m @@ -0,0 +1,213 @@ +function H=ecornerplot_vse(m,varargin) +%% Corner plot with allowance for effective sample size +% +% ecornerplot(m,[parameter,value]) +% +% INPUTS: +% m: a matrix of values that should be plotted in the corner plot. +% +% +% When m is a 3d matrix (ndims(m)==3), then it is assumed to have the form +% MxWxT as output from GWMCMC, where M is the number of parameters, W is +% the number of walkers, and T is the number of steps in each markov chain. +% +% +% NAMED PARAMETERS: +% range: Restrict visual limits to central [99.5] percentile. +% names: A cell of strings with labels for each parameter in m. +% ks: enable kernel smoothing density instead of histograms [false] +% support: a 2xM matrix with upper and lower limits. +% ess: effective sample size. [default: auto-determine ess using EACORR.] +% - used to adjust bandwidth estimates in kernel density estimates. +% scatter: show scatter plot instead of 2d-kernel density estimate +% [true if #points<2000]. +% fullmatrix: display upper corner of plotmatrix. [false] +% color: A color-theme for the plot. [.5 .5 .5]. +% grid: show grid. [false]. +% +% +% Notes: The 2d kernel density contours are plotted as the highest density +% contours at intervals of 10%:20%:90% +% +% EXAMPLE: +% mu = [1 -1 1]; C= [.9 .4 .1; .4 .3 .2; .1 .2 1]; +% m=mvnrnd(mu,C,6000); +% m(:,3)=exp(m(:,3)/2); +% ecornerplot(m,'support',[nan nan;nan nan; 0 nan]','ks',true); +% +% Aslak Grinsted 2015 + +if nargin==0 + close all + m=randn(10000,4);%m(:,2)=m(:,2)+100000; + ecornerplot_vse(m,'ks',true,'fullmatrix',false,'grid',true); + error('test mode... ') + return +end + +p = inputParser; +p.addOptional('range',99.5,@isnumeric); +p.addOptional('names',{},@iscellstr); +p.addOptional('ks',false,@islogical); %TODO: allow definition of support? +p.addOptional('support',[]); +p.addOptional('grid',false,@islogical); +p.addOptional('scatter',nan,@islogical); +p.addOptional('fullmatrix',false,@islogical); +p.addOptional('color',[1 1 1]*.5,@(x)all(size(x)==[1 3])) +p.addOptional('ess',[]); +p.addOptional('transparency', 0.2, @isnumeric); +p.addOptional('fontsize', 10, @isnumeric); +p.addOptional('nbins', [], @isnumeric); +% p.addOptional('truth',[fa],@isnumeric); +p.parse(varargin{:}); +p=p.Results; + +if (size(m,1)Np + error('Effective Sample Size (ess) must be smaller than number of samples') +end +if M>25 + error('Too many dimensions. You probably don''t want to make that many subplots. ') +end +if isnan(p.scatter) + p.scatter=Np<2000; +end + +p.range=prctile(m,[50+[-1 1]*p.range/2 0 100]); %first 2 +rng=p.range(4,:)-p.range(3,:); +if isempty(p.support),p.support=nan(2,M);end +ix=isnan(p.support(1,:)); p.support(1,ix)=p.range(3,ix)-rng(ix)/4; +ix=isnan(p.support(2,:)); p.support(2,ix)=p.range(4,ix)+rng(ix)/4; + +for ii=length(p.names)+1:M + p.names{ii}=sprintf('m_{%.0f}',ii); +end +% for ii=size(p.truth,2)+1:M +% p.truth(ii,:)=nan; +% end +if p.grid + p.grid='on'; +else + p.grid='off'; +end +set(0,'Units','normalized') +figure +set(gcf,'Units', 'normalized') +set(gcf, 'Position', [0.05, 0.1, 0.9, 0.8]) +% clf +% ff = gcf; +% set(ff, 'Position', [100 100 900 600]) +H=nan(M); +for r=1:M + for c=1:max(r,M*p.fullmatrix) + H(r,c)=subaxis(M,M,c,r,'s',0.01,'mb',0.12,'mt',0.05,'ml',0.12,'mr',0.0); + if c==r + if p.ks + [F,X,bw]=ksdensity(m(:,r),'support',p.support(:,r)); %TODO: use ESS + if p.ess0, set(gca,'Ylim',p.support(1:2,r)); end + %!VSE: changed p.range to p.support + end + if r==M, xlabel(['^{ }' p.names{c} '_{ }'], 'FontSize', p.fontsize);end + if (c==1)&(r>1-p.fullmatrix), ylabel(['^{ }' p.names{r} '_{ }'], 'FontSize', p.fontsize);end + if diff(p.support(1:2,c))>0, set(gca,'Xlim',p.support(1:2,c)'); end + end + +end +h=H(:,2:end);h(isnan(h))=[]; +set(h,'YTickLabel',[]) +h=H(1:M-1,:);h(isnan(h))=[]; +set(h,'XTickLabel',[]) +colormap(bsxfun(@minus,[1 1 1],linspace(0,.7,300)')); + + +%LINK the axes for zooming: +hlink={}; +drawnow +lh=cellfun(@(x)double(x),get(H(~isnan(H)),'Xlabel')); +set(lh,'units','normalized') +set(lh,'position',min(cell2mat(get(lh,'position')))); +hlink{end+1}=linkprop(lh,'position'); +lh=cellfun(@(x)double(x),get(H(~isnan(H)),'Ylabel')); +set(lh,'units','normalized'); +set(lh,'position',min(cell2mat(get(lh,'position')))); +hlink{end+1}=linkprop(lh,'position'); + +for ii=1:M + h=H(:,ii); h(isnan(h))=[]; + set(h,'XLimMode','manual') + hlink{end+1}=linkprop(h,'XLim'); + h=H(ii,1:ii-1); h(isnan(h))=[]; + set(h,'YLimMode','manual') + hlink{end+1}=linkprop(h,{'YLim','YTick'}); +end +setappdata(gcf,'aplotmatrix_linkprop_handles',hlink) + + +if nargout==0 + clearvars H +end diff --git a/mcmc_simbio/src/gwmcmc/ex_behappy.m b/mcmc_simbio/src/gwmcmc/ex_behappy.m new file mode 100755 index 0000000..fc747a8 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/ex_behappy.m @@ -0,0 +1,33 @@ +%% Don't worry, be Happy +% +% Sampling a smiley face likelihood function. +% + +%% Smiley face equation +% Formulate a likelihood function inspired by an equation of a smiley face. +% +% Source Michael Borcherds: https://twitter.com/mike_geogebra/status/135391208703930369 + +logHappiness=@(m)1-exp(1e-4*((m(1)^4+2*m(1)^2*m(2)^2-0.3*m(1)^2*m(2)-40.75*m(1)^2+m(2)^4-m(2)^3-40.75*m(2)^2+25*m(2)+393.75)*((m(1)+3)^2+(m(2)-7)^2-1)*((m(1)-3)^2+(m(2)-7)^2-1)*(m(1)^2+(m(2)-2)^2-64))); + + +%% Draw samples from the distribution using GWMCMC +% +% Now we apply the MCMC hammer to draw samples from the logHappiness distribution. +% + +[models,logP]=gwmcmc(randn(2,100),logHappiness,100000,'ThinChain',2); +models(:,:,1:end*.2)=[]; +models=models(:,:)'; + + +plot(models(:,1),models(:,2),'yo','markerfacecolor',[1 1 0]*.8); + +axis equal off + + +title('GWMCMC says: "Don''t Worry, Be Happy!"'); + + +%% Important links +% Bobby McFerrin on youtube: https://www.youtube.com/watch?v=d-diB65scQU \ No newline at end of file diff --git a/mcmc_simbio/src/gwmcmc/ex_breakfit.m b/mcmc_simbio/src/gwmcmc/ex_breakfit.m new file mode 100755 index 0000000..1fba0f7 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/ex_breakfit.m @@ -0,0 +1,147 @@ +%% Fitting a trend-change model to a time series +% +% This code fits a trend-change model to a historical time series of sea level +% in Amsterdam with gaps. +% + +%% Input data +% +% Amsterdam sea level from this source: http://www.psmsl.org/data/longrecords/ + +Y=[1700 -152; 1701 -158; 1702 -132; 1703 -172; 1704 -135; 1705 -167; 1706 -192; 1707 -153; 1708 -149; 1709 -187; 1710 -168; 1711 -140; 1712 -129; 1713 -151; + 1714 -106; 1715 -172; 1716 -168; 1717 -164; 1718 -185; 1719 -182; 1720 -109; 1721 -146; 1722 -141; 1723 -99; 1724 -145; 1725 -166; 1726 -108; 1727 -136; + 1728 -195; 1729 -176; 1730 -148; 1731 -108; 1732 -134; 1733 -160; 1734 -165; 1735 -181; 1736 -109; 1737 -92; 1738 -152; 1739 -123; 1740 -124; 1741 -122; + 1742 -154; 1743 -144; 1744 -148; 1745 -178; 1746 -178; 1747 -142; 1748 -147; 1749 -167; 1766 -175; 1767 -111; 1768 -160; 1769 -86; 1770 -94; 1771 -87; + 1772 -142; 1773 -143; 1774 -135; 1775 -127; 1776 -150; 1777 -131; 1778 -155; 1779 -131; 1780 -130; 1781 -134; 1782 -160; 1783 -157; 1784 -173; 1785 -178; + 1786 -178; 1787 -125; 1788 -204; 1789 -161; 1790 -109; 1791 -92; 1792 -150; 1793 -154; 1794 -118; 1795 -121; 1796 -157; 1797 -134; 1798 -135; 1799 -177; + 1800 -175; 1801 -90; 1802 -159; 1803 -172; 1804 -130; 1805 -142; 1806 -106; 1807 -105; 1808 -183; 1809 -151; 1810 -128; 1811 -137; 1812 -141; 1813 -150; + 1814 -185; 1815 -144; 1816 -113; 1817 -102; 1818 -160; 1819 -158; 1820 -194; 1821 -123; 1822 -125; 1823 -198; 1824 -97; 1825 -87; 1826 -126; 1827 -97; + 1828 -124; 1829 -119; 1830 -141; 1831 -94; 1832 -141; 1833 -106; 1834 -77; 1835 -105; 1836 -96; 1837 -88; 1838 -117; 1839 -114; 1840 -111; 1841 -85; + 1842 -132; 1843 -57; 1844 -53; 1845 -90; 1846 -80; 1847 -118; 1848 -141; 1849 -101; 1850 -91; 1851 -102; 1852 -97; 1853 -113; 1854 -49; 1855 -111; + 1856 -85; 1857 -145; 1858 -137; 1859 -102; 1860 -113; 1861 -94; 1862 -125; 1863 -121; 1864 -161; 1865 -157; 1866 -93; 1867 -58; 1868 -91; 1869 -75; 1870 -129; + 1871 -141; 1874 -110; 1875 -125; 1876 -80; 1877 -43; 1878 -60; 1879 -79; 1880 -31; 1881 -64; 1882 -74; 1883 -58; 1884 -54; 1885 -75; 1886 -88; 1887 -64; 1888 -86; + 1889 -53; 1890 -84; 1891 -94; 1892 -78; 1893 -67; 1894 -92; 1895 -74; 1896 -81; 1897 -82; 1898 -32; 1899 -36; 1900 -67; 1901 -45; 1902 -62; 1903 -25; 1904 -58; 1905 -32; + 1906 -34; 1907 -75; 1908 -66; 1909 -36; 1910 -12; 1911 -24; 1912 -7; 1913 -22; 1914 0; 1915 7; 1916 -5; 1917 -37; 1918 -44; 1919 -38; 1920 14; 1921 -10; + 1922 -16; 1923 -38;1925 29]; +t=Y(:,1); +Y=Y(:,2); + + +%% Define trend change forward model: + +forwardmodel=@(t,m)(m(1)*(tm(3))).*(t-m(3))+m(4); + +%% Make an initial guess for the model parameters. +p=polyfit(t-mean(t),Y,1); +m0=[p(1) p(1) mean(t) p(2)]'; +sigma=std(Y-forwardmodel(t,m0)); +m0=[m0 ; log(sigma)]; + + + +%% Likelihood +% +% We assume the data are normally distributed around the forward model. +% + +% First we define a helper function equivalent to calling log(normpdf(x,mu,sigma)) +% but has higher precision because it avoids truncation errors associated with calling +% log(exp(xxx)). +lognormpdf=@(x,mu,sigma)-0.5*((x-mu)./sigma).^2 -log(sqrt(2*pi).*sigma); + + +logLike=@(m)sum(lognormpdf(Y,forwardmodel(t,m),exp(m(5)))); + + +%% Prior information +% +% We want to restrict the model to place the kink-point within the observed +% time interval. All other parameters have a uniform prior. +% + +logprior = @(m)(m(3)>min(t))&(m(3)-5)&&(m(1)<0.5) && (m(2)>0)&&(m(2)<10) && (m(3)>-10)&&(m(3)<1) ; + +%% Find the posterior distribution using GWMCMC +% +% Now we apply the MCMC hammer to draw samples from the posterior. +% +% + +% first we initialize the ensemble of walkers in a small gaussian ball +% around the max-likelihood estimate. +minit=bsxfun(@plus,m_maxlike,randn(3,100)*0.01); + +%% Apply the hammer: +% +% Draw samples from the posterior +% +tic +m=gwmcmc(minit,{logprior logLike},100000,'ThinChain',5,'burnin',.2); +toc + + + +%% Auto-correlation function +% + + +figure +[C,lags,ESS]=eacorr(m); +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') + +%% Corner plot of parameters +% + +figure +ecornerplot(m,'ks',true,'color',[.6 .35 .3]) + +%% Plot of posterior fit +% + +figure +m=m(:,:)'; %flatten the chain + +%plot 100 samples... +for kk=1:100 + r=ceil(rand*size(m,1)); + h=plot(x,forwardmodel(m(r,:)),'color',[.6 .35 .3].^.3); + hold on +end +h(2)=errorbar(x,y,yerr,'ks','markerfacecolor',[1 1 1]*.4,'markersize',4); + +h(4)=plot(x,forwardmodel(m_lsq),'b--','linewidth',2); +h(3)=plot(x,forwardmodel(median(m)),'color',[.6 .35 .3],'linewidth',3); +h(5)=plot(x,forwardmodel(m_true),'r','linewidth',2); + +axis tight +legend(h,'Samples from posterior','Data','GWMCMC median','LSQ fit','Truth') diff --git a/mcmc_simbio/src/gwmcmc/ex_rosenbrockbanana.m b/mcmc_simbio/src/gwmcmc/ex_rosenbrockbanana.m new file mode 100755 index 0000000..ba38a26 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/ex_rosenbrockbanana.m @@ -0,0 +1,65 @@ +%% The MCMC hammer +% +% GWMCMC is an implementation of the Goodman and Weare 2010 Affine +% invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +% enables bayesian inference. The problem with many traditional MCMC samplers +% is that they can have slow convergence for badly scaled problems, and that +% it is difficult to optimize the random walk for high-dimensional problems. +% This is where the GW-algorithm really excels as it is affine invariant. It +% can achieve much better convergence on badly scaled problems. It is much +% simpler to get to work straight out of the box, and for that reason it +% truly deserves to be called the MCMC hammer. +% +% See also: +% +% + +%% Rosenbrock: A badly scaled example +% +% A classical difficult low dimensional problem is the rosenbrock density. +% It is defined by the following log-probability function: +% + +logPfun=@(m) -(100*(m(2,:)-m(1,:).^2).^2 +(1-m(1,:)).^2)/20; + +%lets visualize it: +close all +[X,Y]=meshgrid(-4:.01:6,-1:.02:34); +Z=logPfun([X(:) Y(:)]'); Z=reshape(Z,size(X)); +contour(X,Y,exp(Z)) +colormap(parula) +title('The Rosenbrock banana') +xlim([-4 6]) +ylim([-1 34]) + +%% Apply the MCMC hammer: +% +% Now we apply the Goodman & Weare MCMC sampler and plot the results on top +% + +M=2; %number of model parameters +Nwalkers=40; %number of walkers/chains. +minit=randn(M,Nwalkers); +tic +models=gwmcmc(minit, logPfun,100000,'StepSize',30,'burnin',.2); +toc + + +%flatten the chain: analyze all the chains as one + +models=models(:,:); + +%plot the results + +hold on +plot(models(1,:),models(2,:),'k.') + +legend('Rosenbrock','GWMCMC samples','location','northwest') + + + +%% References: +% * Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. App. Math. Comp. Sci., Vol. 5, No. 1, 65�80 +% * Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +% +% -Aslak Grinsted 2015 diff --git a/mcmc_simbio/src/gwmcmc/gwmcmc.m b/mcmc_simbio/src/gwmcmc/gwmcmc.m new file mode 100755 index 0000000..64aa852 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/gwmcmc.m @@ -0,0 +1,279 @@ +function [models,logP]=gwmcmc(minit,logPfuns,mccount,varargin) +%% Cascaded affine invariant ensemble MCMC sampler. "The MCMC hammer" +% +% GWMCMC is an implementation of the Goodman and Weare 2010 Affine +% invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +% enables bayesian inference. The problem with many traditional MCMC samplers +% is that they can have slow convergence for badly scaled problems, and that +% it is difficult to optimize the random walk for high-dimensional problems. +% This is where the GW-algorithm really excels as it is affine invariant. It +% can achieve much better convergence on badly scaled problems. It is much +% simpler to get to work straight out of the box, and for that reason it +% truly deserves to be called the MCMC hammer. +% +% (This code uses a cascaded variant of the Goodman and Weare algorithm). +% +% USAGE: +% [models,logP]=gwmcmc(minit,logPfuns,mccount,[Parameter,Value,Parameter,Value]); +% +% INPUTS: +% minit: an MxW matrix of initial values for each of the walkers in the +% ensemble. (M:number of model params. W: number of walkers). W +% should be atleast 2xM. (see e.g. mvnrnd). +% logPfuns: a cell of function handles returning the log probality of a +% proposed set of model parameters. Typically this cell will +% contain two function handles: one to the logprior and another +% to the loglikelihood. E.g. {@(m)logprior(m) @(m)loglike(m)} +% mccount: What is the desired total number of monte carlo proposals. +% This is the total number, -NOT the number per chain. +% +% Named Parameter-Value pairs: +% 'StepSize': unit-less stepsize (default=2.5). +% 'ThinChain': Thin all the chains by only storing every N'th step (default=10) +% 'ProgressBar': Show a text progress bar (default=true) +% 'Parallel': Run in ensemble of walkers in parallel. (default=false) +% 'BurnIn': fraction of the chain that should be removed. (default=0) +% +% OUTPUTS: +% models: A MxWxT matrix with the thinned markov chains (with T samples +% per walker). T=~mccount/p.ThinChain/W. +% logP: A PxWxT matrix of log probabilities for each model in the +% models. here P is the number of functions in logPfuns. +% +% Note on cascaded evaluation of log probabilities: +% The logPfuns-argument can be specifed as a cell-array to allow a cascaded +% evaluation of the probabilities. The computationally cheapest function should be +% placed first in the cell (this will typically the prior). This allows the +% routine to avoid calculating the likelihood, if the proposed model can be +% rejected based on the prior alone. +% logPfuns={logprior loglike} is faster but equivalent to +% logPfuns={@(m)logprior(m)+loglike(m)} +% +% TIP: if you aim to analyze the entire set of ensemble members as a single +% sample from the distribution then you may collapse output models-matrix +% thus: models=models(:,:); This will reshape the MxWxT matrix into a +% Mx(W*T)-matrix while preserving the order. +% +% +% EXAMPLE: Here we sample a multivariate normal distribution. +% +% %define problem: +% mu = [5;-3;6]; +% C = [.5 -.4 0;-.4 .5 0; 0 0 1]; +% iC=pinv(C); +% logPfuns={@(m)-0.5*sum((m-mu)'*iC*(m-mu))} +% +% %make a set of starting points for the entire ensemble of walkers +% minit=randn(length(mu),length(mu)*2); +% +% %Apply the MCMC hammer +% [models,logP]=gwmcmc(minit,logPfuns,100000); +% models(:,:,1:floor(size(models,3)*.2))=[]; %remove 20% as burn-in +% models=models(:,:)'; %reshape matrix to collapse the ensemble member dimension +% scatter(models(:,1),models(:,2)) +% prctile(models,[5 50 95]) +% +% +% References: +% Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. App. Math. Comp. Sci., Vol. 5, No. 1, 6580 +% Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +% +% WebPage: https://github.com/grinsted/gwmcmc +% +% -Aslak Grinsted 2015 + + +persistent isoctave; +if isempty(isoctave) + isoctave = (exist ('OCTAVE_VERSION', 'builtin') > 0); +end + +if nargin<3 + error('GWMCMC:toofewinputs','GWMCMC requires atleast 3 inputs.') +end +M=size(minit,1); +if size(minit,2)==1 + minit=bsxfun(@plus,minit,randn(M,M*5)); +end + + +p=inputParser; +if isoctave + p=p.addParamValue('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p=p.addParamValue('ThinChain',10,@isnumeric); + p=p.addParamValue('ProgressBar',true,@islogical); + p=p.addParamValue('Parallel',false,@islogical); + p=p.addParamValue('BurnIn',0,@(x)(x>=0)&&(x<1)); + p=p.parse(varargin{:}); +else + p.addParameter('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p.addParameter('ThinChain',10,@isnumeric); + p.addParameter('ProgressBar',true,@islogical); + p.addParameter('Parallel',false,@islogical); + p.addParameter('BurnIn',0,@(x)(x>=0)&&(x<1)); + p.parse(varargin{:}); +end +p=p.Results; + + +Nwalkers=size(minit,2); + +if size(minit,1)*2>size(minit,2) + warning('GWMCMC:minitdimensions','Check minit dimensions.\nIt is recommended that there be atleast twice as many walkers in the ensemble as there are model dimension.') +end + +if p.ProgressBar + progress=@textprogress; +else + progress=@noaction; +end + + +Nkeep=ceil(mccount/p.ThinChain/Nwalkers); %number of samples drawn from each walker +mccount=(Nkeep-1)*p.ThinChain+1; + +models=nan(M,Nwalkers,Nkeep); %pre-allocate output matrix + +models(:,:,1)=minit; + +if ~iscell(logPfuns) + logPfuns={logPfuns}; +end + +NPfun=numel(logPfuns); + +%calculate logP state initial pos of walkers +logP=nan(NPfun,Nwalkers,Nkeep); +for wix=1:Nwalkers % walker index + for fix=1:NPfun % function index + + v=logPfuns{fix}(minit(:,wix)); + if islogical(v) %reformulate function so that false=-inf for logical constraints. + v=-1/v;logPfuns{fix}=@(m)-1/logPfuns{fix}(m); %experimental implementation of experimental feature + end + logP(fix,wix,1)=v; + + end +end + +if ~all(all(isfinite(logP(:,:,1)))) + error('Starting points for all walkers must have finite logP') +end +reject=zeros(Nwalkers,1); +curm=models(:,:,1); +curlogP=logP(:,:,1); +progress(0,0,0) +totcount=Nwalkers; +for row=1:Nkeep + for jj=1:p.ThinChain + %generate proposals for all walkers + %(done outside walker loop, in order to be compatible with parfor - some penalty for memory): + %-Note it appears to give a slight performance boost for non-parallel. + rix=mod((1:Nwalkers)+floor(rand*(Nwalkers-1)),Nwalkers)+1; %pick a random partner + zz=((p.StepSize - 1)*rand(1,Nwalkers) + 1).^2/p.StepSize; + proposedm=curm(:,rix) - bsxfun(@times,(curm(:,rix)-curm),zz); + logrand=log(rand(NPfun+1,Nwalkers)); %moved outside because rand is slow inside parfor + if p.Parallel + %parallel/non-parallel code is currently mirrored in + %order to enable experimentation with separate optimization + %techniques for each branch. Parallel is not really great yet. + %TODO: use SPMD instead of parfor. + + parfor wix=1:Nwalkers + cp=curlogP(:,wix); + lr=logrand(:,wix); + acceptfullstep=true; + proposedlogP=nan(NPfun,1); + if lr(1)<(numel(proposedm(:,wix))-1)*log(zz(wix)) + for fix=1:NPfun + proposedlogP(fix)=logPfuns{fix}(proposedm(:,wix)); %have tested workerobjwrapper but that is slower. + if lr(fix+1)>proposedlogP(fix)-cp(fix) || ~isreal(proposedlogP(fix)) || isnan( proposedlogP(fix) ) + %if ~(lr(fix+1)proposedlogP(fix)-curlogP(fix,wix) || ~isreal(proposedlogP(fix)) || isnan(proposedlogP(fix)) + %if ~(logrand(fix+1,wix)0 + crop=ceil(Nkeep*p.BurnIn); + models(:,:,1:crop)=[]; %TODO: never allocate space for them ? + logP(:,:,1:crop)=[]; +end + + +% TODO: make standard diagnostics to give warnings... +% TODO: make some diagnostic plots if nargout==0; + + + +function textprogress(pct,curm,rejectpct) +persistent lastNchar lasttime starttime +if isempty(lastNchar)||pct==0 + lasttime=cputime-10;starttime=cputime;lastNchar=0; + pct=1e-16; +end +if pct==1 + fprintf('%s',repmat(char(8),1,lastNchar));lastNchar=0; + return +end +if (cputime-lasttime>0.1) + + ETA=datestr((cputime-starttime)*(1-pct)/(pct*60*60*24),13); + progressmsg=[183-uint8((1:40)<=(pct*40)).*(183-'*') '']; + %progressmsg=['-'-uint8((1:40)<=(pct*40)).*('-'-'') '']; + %progressmsg=[uint8((1:40)<=(pct*40)).*'#' '']; + curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); + %curmtxt=mat2str(curm); + progressmsg=sprintf('\nGWMCMC %5.1f%% [%s] %s\n%3.0f%% rejected\n%s\n',pct*100,progressmsg,ETA,rejectpct*100,curmtxt); + + fprintf('%s%s',repmat(char(8),1,lastNchar),progressmsg); + drawnow;lasttime=cputime; + lastNchar=length(progressmsg); +end + +function noaction(varargin) + +% Acknowledgements: I became aware of the GW algorithm via a student report +% which was using emcee for python. Great stuff. diff --git a/mcmc_simbio/src/gwmcmc/gwmcmc_light.m b/mcmc_simbio/src/gwmcmc/gwmcmc_light.m new file mode 100755 index 0000000..ed7fd9a --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/gwmcmc_light.m @@ -0,0 +1,377 @@ +function [models,logP, rejProp]=gwmcmc_light(minit,logPfuns,mccount,varargin) +%% Cascaded affine invariant ensemble MCMC sampler. "The MCMC hammer" +% +% Originally written by Aslak Grinsted. Edited by Vipul Singhal +% This code differs from the original function gwmcmc or my other version +% gwmcmc_vse in the following ways: +% 1. It allows for the possibility of plotting real time progress in terms +% of scatterplots of the point clouds. +% 2. It does not track the non integrable points as the vse version does. +% In doing so, it should use less memory. +% +% +% GWMCMC is an implementation of the Goodman and Weare 2010 Affine +% invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +% enables bayesian inference. The problem with many traditional MCMC samplers +% is that they can have slow convergence for badly scaled problems, and that +% it is difficult to optimize the random walk for high-dimensional problems. +% This is where the GW-algorithm really excels as it is affine invariant. It +% can achieve much better convergence on badly scaled problems. It is much +% simpler to get to work straight out of the box, and for that reason it +% truly deserves to be called the MCMC hammer. +% +% (This code uses a cascaded variant of the Goodman and Weare algorithm). +% +% USAGE: +% [models,logP]=gwmcmc(minit,logPfuns,mccount,[Parameter,Value,Parameter,Value]); +% +% INPUTS: +% minit: an MxW matrix of initial values for each of the walkers in the +% ensemble. (M:number of model params. W: number of walkers). W +% should be atleast 2xM. (see e.g. mvnrnd). +% logPfuns: a cell of function handles returning the log probality of a +% proposed set of model parameters. Typically this cell will +% contain two function handles: one to the logprior and another +% to the loglikelihood. E.g. {@(m)logprior(m) @(m)loglike(m)} +% mccount: What is the desired total number of monte carlo proposals. +% This is the total number, -NOT the number per chain. +% +% Named Parameter-Value pairs: +% 'StepSize': unit-less stepsize (default=2.5). +% 'ThinChain': Thin all the chains by only storing every N'th step (default=10) +% 'ProgressBar': Show a text progress bar (default=true) +% 'Parallel': Run in ensemble of walkers in parallel. (default=false) +% 'BurnIn': fraction of the chain that should be removed. (default=0) +% +% OUTPUTS: +% models: A MxWxT matrix with the thinned markov chains (with T samples +% per walker). T=~mccount/p.ThinChain/W. +% logP: A PxWxT matrix of log probabilities for each model in the +% models. here P is the number of functions in logPfuns. +% +% Note on cascaded evaluation of log probabilities: +% The logPfuns-argument can be specifed as a cell-array to allow a cascaded +% evaluation of the probabilities. The computationally cheapest function should be +% placed first in the cell (this will typically the prior). This allows the +% routine to avoid calculating the likelihood, if the proposed model can be +% rejected based on the prior alone. +% logPfuns={logprior loglike} is faster but equivalent to +% logPfuns={@(m)logprior(m)+loglike(m)} +% +% TIP: if you aim to analyze the entire set of ensemble members as a single +% sample from the distribution then you may collapse output models-matrix +% thus: models=models(:,:); This will reshape the MxWxT matrix into a +% Mx(W*T)-matrix while preserving the order. +% +% +% EXAMPLE: Here we sample a multivariate normal distribution. +% +% %define problem: +% mu = [5;-3;6]; +% C = [.5 -.4 0;-.4 .5 0; 0 0 1]; +% iC=pinv(C); +% logPfuns={@(m)-0.5*sum((m-mu)'*iC*(m-mu))} +% +% %make a set of starting points for the entire ensemble of walkers +% minit=randn(length(mu),length(mu)*2); +% +% %Apply the MCMC hammer +% [models,logP]=gwmcmc(minit,logPfuns,100000); +% models(:,:,1:floor(size(models,3)*.2))=[]; %remove 20% as burn-in +% models=models(:,:)'; %reshape matrix to collapse the ensemble member dimension +% scatter(models(:,1),models(:,2)) +% prctile(models,[5 50 95]) +% +% +% References: +% Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. App. Math. Comp. Sci., Vol. 5, No. 1, 6580 +% Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +% +% WebPage: https://github.com/grinsted/gwmcmc +% +% -Aslak Grinsted 2015 + + +persistent isoctave; +if isempty(isoctave) + isoctave = (exist ('OCTAVE_VERSION', 'builtin') > 0); +end + +if nargin<3 + error('GWMCMC:toofewinputs','GWMCMC requires atleast 3 inputs.') +end +M=size(minit,1); +if size(minit,2)==1 + minit=bsxfun(@plus,minit,randn(M,M*5)); +end + + +p=inputParser; +if isoctave + p=p.addParamValue('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p=p.addParamValue('ThinChain',10,@isnumeric); + p=p.addParamValue('ProgressBar',true,@islogical); + p=p.addParamValue('Parallel',false,@islogical); + p=p.addParamValue('BurnIn',0,@(x)(x>=0)&&(x<1)); + p=p.parse(varargin{:}); +else + p.addParameter('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p.addParameter('ThinChain',10,@isnumeric); + p.addParameter('ProgressBar',true,@islogical); + p.addParameter('Parallel',false,@islogical); + p.addParameter('BurnIn',0,@(x)(x>=0)&&(x<1)); + p.parse(varargin{:}); +end +p=p.Results; + + + +Nwalkers=size(minit,2); % MxW, ie, W = Nwalkers +if size(minit,1)*2>size(minit,2) + warning('GWMCMC:minitdimensions','Check minit dimensions.\nIt is recommended that there be atleast twice as many walkers in the ensemble as there are model dimension.') +end +if p.ProgressBar + progress=@textprogress; +else + progress=@noaction; +end + + + +Nkeep=ceil(mccount/p.ThinChain/Nwalkers); %number of samples drawn from each walker +mccount=(Nkeep-1)*p.ThinChain+1; % !todo what is this used for. + +% models is the matrix of parameter samples that make up the posterior +% distribution. M is the number of parameters. Nkeep is the number of +% steps the full walker ensemble takes after thinning. +% The largest arrays should be of this size, and ideally you dont want to +% keep too many of these in memory too. +models=nan(M,Nwalkers,Nkeep); %pre-allocate output matrix +models(:,:,1)=minit; % set the first walker positions to be according to minit. + + +if ~iscell(logPfuns) + logPfuns={logPfuns}; +end +NPfun=numel(logPfuns); +%calculate logP state initial pos of walkers +% logP is the result of the function(s) evaluation(s) for all walkers, at all +% timesteps we choose to keep +logP=nan(NPfun,Nwalkers,Nkeep); + + +% do the evaluation once for the minit points. (for all the walkers) +for wix=1:Nwalkers % walker index + for fix=1:NPfun % function index + try + v=logPfuns{fix}(minit(:,wix)); + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + v = -Inf; + else + error('there was an unknown error'); % need this, otherwise if there is an unknown error, the catch statement does not report it + %and the code continues to execute. + end + end + if islogical(v) + + + %reformulate function so that false=-inf for logical constraints. + % what happens here is that the first time the logical function + % is called, the value is converted to a -Inf. But more than + % that, even the function is changed from something logical to + % something that returns -Inf every time the conditions are not + % met. very cool. + v=-1/v;logPfuns{fix}=@(m)-1/logPfuns{fix}(m); + %experimental implementation of experimental feature + end + logP(fix,wix,1)=v; + end +end + +% both the priors and the likelihood should be finite at the intial points. +% Ie, the prior must be met and the likelihood must not have tolerance +% errors. +% +if ~all(all(isfinite(logP(:,:,1)))) + error('Starting points for all walkers must have finite logP') +end + + +reject=zeros(Nwalkers,1); +rejProp = nan(1,Nkeep); +curm=models(:,:,1); % current model, all walkers +curlogP=logP(:,:,1); +progress(0,0,0) % show progress bar. +totcount=Nwalkers; + +% ! this line gets removed: preallocate matrix to store parameter values that could not get simulated +% non_integrable_m = nan(M, Nwalkers, Nkeep*p.ThinChain); +for row=1:Nkeep + for jj=1:p.ThinChain + %generate proposals for all walkers + %(done outside walker loop, in order to be compatible with parfor - some penalty for memory): + %-Note it appears to give a slight performance boost for non-parallel. + + rix=mod((1:Nwalkers)+floor(rand*(Nwalkers-1)),Nwalkers)+1; %pick a random partner + + zz=((p.StepSize - 1)*rand(1,Nwalkers) + 1).^2/p.StepSize; + %VSE: why -1 here? this is what makes the system fail at 1 + proposedm=curm(:,rix) - bsxfun(@times,(curm(:,rix)-curm),zz); + logrand=log(rand(NPfun+1,Nwalkers)); %moved outside because rand is slow inside parfor + % logrand is what we compare our computed log likelihood to. + + totalcount = (row-1)*p.ThinChain+jj; + + if p.Parallel + %parallel/non-parallel code is currently mirrored in + %order to enable experimentation with separate optimization + %techniques for each branch. Parallel is not really great yet. + %TODO: use SPMD instead of parfor. + + parfor wix=1:Nwalkers + cp=curlogP(:,wix); + lr=logrand(:,wix); + acceptfullstep=true; + proposedlogP=nan(NPfun,1); + + if lr(1)<(numel(proposedm(:,wix))-1)*log(zz(wix)) + % no idea why only some of the walkers are chosen to be updated. + for fix=1:NPfun + try + proposedlogP(fix)=logPfuns{fix}(proposedm(:,wix)); + %have tested workerobjwrapper but that is slower. + catch ME + if strcmp(ME.identifier, ... + 'DESuite:ODE15S:IntegrationToleranceNotMet') + % non_integrable_m(:,wix,totalcount) = proposedm(:,wix); + proposedlogP(fix) = -Inf; + else + error('there was an unknown error'); + % need this, otherwise if there is an unknown error, the catch statement does not report it + %and the code continues to execute. + + end + end + + if lr(fix+1)>proposedlogP(fix)-cp(fix) ||... + ~isreal(proposedlogP(fix)) ||... + isnan( proposedlogP(fix) ) + %if ~(lr(fix+1)proposedlogP(fix)-curlogP(fix,wix) || ~isreal(proposedlogP(fix)) || isnan(proposedlogP(fix)) + %if ~(logrand(fix+1,wix)0 + crop=ceil(Nkeep*p.BurnIn); + models(:,:,1:crop)=[]; %TODO: never allocate space for them ? + logP(:,:,1:crop)=[]; +end + + +% TODO: make standard diagnostics to give warnings... +% TODO: make some diagnostic plots if nargout==0; + + + +function textprogress(pct,curm,rejectpct) +persistent lastNchar lasttime starttime +if isempty(lastNchar)||pct==0 + lasttime=cputime-10;starttime=cputime;lastNchar=0; + pct=1e-16; +end +if pct==1 + fprintf('%s',repmat(char(8),1,lastNchar));lastNchar=0; + return +end +if (cputime-lasttime>0.1) + + ETA=datestr((cputime-starttime)*(1-pct)/(pct*60*60*24),13); + progressmsg=[183-uint8((1:40)<=(pct*40)).*(183-'*') '']; + %progressmsg=['-'-uint8((1:40)<=(pct*40)).*('-'-'') '']; + %progressmsg=[uint8((1:40)<=(pct*40)).*'#' '']; + curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); + %curmtxt=mat2str(curm); + progressmsg=sprintf('\nGWMCMC %5.1f%% [%s] %s\n%3.0f%% rejected\n%s\n',pct*100,progressmsg,ETA,rejectpct*100,curmtxt); + + fprintf('%s%s',repmat(char(8),1,lastNchar),progressmsg); + drawnow;lasttime=cputime; + lastNchar=length(progressmsg); +end + +function noaction(varargin) + +% Acknowledgements: I became aware of the GW algorithm via a student report +% which was using emcee for python. Great stuff. diff --git a/mcmc_simbio/src/gwmcmc/gwmcmc_par.m b/mcmc_simbio/src/gwmcmc/gwmcmc_par.m new file mode 100755 index 0000000..deab158 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/gwmcmc_par.m @@ -0,0 +1,282 @@ +function [models,logP]=gwmcmc_par(minit,logPfuns,mccount,varargin) +%% Cascaded affine invariant ensemble MCMC sampler. "The MCMC hammer" +% Parallelization fixed gwmcmc +% GWMCMC is an implementation of the Goodman and Weare 2010 Affine +% invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +% enables bayesian inference. The problem with many traditional MCMC samplers +% is that they can have slow convergence for badly scaled problems, and that +% it is difficult to optimize the random walk for high-dimensional problems. +% This is where the GW-algorithm really excels as it is affine invariant. It +% can achieve much better convergence on badly scaled problems. It is much +% simpler to get to work straight out of the box, and for that reason it +% truly deserves to be called the MCMC hammer. +% +% (This code uses a cascaded variant of the Goodman and Weare algorithm). +% +% USAGE: +% [models,logP]=gwmcmc(minit,logPfuns,mccount,[Parameter,Value,Parameter,Value]); +% +% INPUTS: +% minit: an MxW matrix of initial values for each of the walkers in the +% ensemble. (M:number of model params. W: number of walkers). W +% should be atleast 2xM. (see e.g. mvnrnd). +% logPfuns: a cell of function handles returning the log probality of a +% proposed set of model parameters. Typically this cell will +% contain two function handles: one to the logprior and another +% to the loglikelihood. E.g. {@(m)logprior(m) @(m)loglike(m)} +% mccount: What is the desired total number of monte carlo proposals. +% This is the total number, -NOT the number per chain. +% +% Named Parameter-Value pairs: +% 'StepSize': unit-less stepsize (default=2.5). +% 'ThinChain': Thin all the chains by only storing every N'th step (default=10) +% 'ProgressBar': Show a text progress bar (default=true) +% 'Parallel': Run in ensemble of walkers in parallel. (default=false) +% 'BurnIn': fraction of the chain that should be removed. (default=0) +% +% OUTPUTS: +% models: A MxWxT matrix with the thinned markov chains (with T samples +% per walker). T=~mccount/p.ThinChain/W. +% logP: A PxWxT matrix of log probabilities for each model in the +% models. here P is the number of functions in logPfuns. +% +% Note on cascaded evaluation of log probabilities: +% The logPfuns-argument can be specifed as a cell-array to allow a cascaded +% evaluation of the probabilities. The computationally cheapest function should be +% placed first in the cell (this will typically the prior). This allows the +% routine to avoid calculating the likelihood, if the proposed model can be +% rejected based on the prior alone. +% logPfuns={logprior loglike} is faster but equivalent to +% logPfuns={@(m)logprior(m)+loglike(m)} +% +% TIP: if you aim to analyze the entire set of ensemble members as a single +% sample from the distribution then you may collapse output models-matrix +% thus: models=models(:,:); This will reshape the MxWxT matrix into a +% Mx(W*T)-matrix while preserving the order. +% +% +% EXAMPLE: Here we sample a multivariate normal distribution. +% +% %define problem: +% mu = [5;-3;6]; +% C = [.5 -.4 0;-.4 .5 0; 0 0 1]; +% iC=pinv(C); +% logPfuns={@(m)-0.5*sum((m-mu)'*iC*(m-mu))} +% +% %make a set of starting points for the entire ensemble of walkers +% minit=randn(length(mu),length(mu)*2); +% +% %Apply the MCMC hammer +% [models,logP]=gwmcmc(minit,logPfuns,100000); +% models(:,:,1:floor(size(models,3)*.2))=[]; %remove 20% as burn-in +% models=models(:,:)'; %reshape matrix to collapse the ensemble member dimension +% scatter(models(:,1),models(:,2)) +% prctile(models,[5 50 95]) +% +% +% References: +% Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. App. Math. Comp. Sci., Vol. 5, No. 1, 6580 +% Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +% +% WebPage: https://github.com/grinsted/gwmcmc +% +% -Aslak Grinsted 2015 +% -eidts: vs 2016 + + +persistent isoctave; +if isempty(isoctave) + isoctave = (exist ('OCTAVE_VERSION', 'builtin') > 0); +end + +if nargin<3 + error('GWMCMC:toofewinputs','GWMCMC requires atleast 3 inputs.') +end +M=size(minit,1); +if size(minit,2)==1 + minit=bsxfun(@plus,minit,randn(M,M*5)); +end + + +p=inputParser; +if isoctave + p=p.addParamValue('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p=p.addParamValue('ThinChain',10,@isnumeric); + p=p.addParamValue('ProgressBar',true,@islogical); + p=p.addParamValue('Parallel',false,@islogical); + p=p.addParamValue('BurnIn',0,@(x)(x>=0)&&(x<1)); + p=p.parse(varargin{:}); +else + p.addParameter('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p.addParameter('ThinChain',10,@isnumeric); + p.addParameter('ProgressBar',true,@islogical); + p.addParameter('Parallel',false,@islogical); + p.addParameter('BurnIn',0,@(x)(x>=0)&&(x<1)); + p.parse(varargin{:}); +end +p=p.Results; + + +Nwalkers=size(minit,2); + +if size(minit,1)*2>size(minit,2) + warning('GWMCMC:minitdimensions','Check minit dimensions.\nIt is recommended that there be atleast twice as many walkers in the ensemble as there are model dimension.') +end + +if p.ProgressBar + progress=@textprogress; +else + progress=@noaction; +end + + +Nkeep=ceil(mccount/p.ThinChain/Nwalkers); %number of samples drawn from each walker +mccount=(Nkeep-1)*p.ThinChain+1; + +models=nan(M,Nwalkers,Nkeep); %pre-allocate output matrix + +models(:,:,1)=minit; + +if ~iscell(logPfuns) + logPfuns={logPfuns}; +end + +NPfun=numel(logPfuns); + +%calculate logP state initial pos of walkers +logP=nan(NPfun,Nwalkers,Nkeep); +for wix=1:Nwalkers + for fix=1:NPfun + v=logPfuns{fix}(minit(:,wix)); + if islogical(v) %reformulate function so that false=-inf for logical constraints. + v=-1/v;logPfuns{fix}=@(m)-1/logPfuns{fix}(m); %experimental implementation of experimental feature + end + logP(fix,wix,1)=v; + end +end + +if ~all(all(isfinite(logP(:,:,1)))) + error('Starting points for all walkers must have finite logP') +end + + +reject=zeros(Nwalkers,1); + + +curm=models(:,:,1); +curlogP=logP(:,:,1); +progress(0,0,0) +totcount=Nwalkers; +for row=1:Nkeep + for jj=1:p.ThinChain + %generate proposals for all walkers + %(done outside walker loop, in order to be compatible with parfor - some penalty for memory): + %-Note it appears to give a slight performance boost for non-parallel. + rix=mod((1:Nwalkers)+floor(rand*(Nwalkers-1)),Nwalkers)+1; %pick a random partner + zz=((p.StepSize - 1)*rand(1,Nwalkers) + 1).^2/p.StepSize; + proposedm=curm(:,rix) - bsxfun(@times,(curm(:,rix)-curm),zz); + logrand=log(rand(NPfun+1,Nwalkers)); %moved outside because rand is slow inside parfor + if p.Parallel + %parallel/non-parallel code is currently mirrored in + %order to enable experimentation with separate optimization + %techniques for each branch. Parallel is not really great yet. + %TODO: use SPMD instead of parfor. + + parfor wix=1:Nwalkers + cp=curlogP(:,wix); + lr=logrand(:,wix); + acceptfullstep=true; + proposedlogP=nan(NPfun,1); + if lr(1)<(numel(proposedm(:,wix))-1)*log(zz(wix)) + for fix=1:NPfun + proposedlogP(fix)=logPfuns{fix}(proposedm(:,wix)); %have tested workerobjwrapper but that is slower. + if lr(fix+1)>proposedlogP(fix)-cp(fix) || ~isreal(proposedlogP(fix)) || isnan( proposedlogP(fix) ) + %if ~(lr(fix+1)proposedlogP(fix)-curlogP(fix,wix) || ~isreal(proposedlogP(fix)) || isnan(proposedlogP(fix)) + %if ~(logrand(fix+1,wix)0 + crop=ceil(Nkeep*p.BurnIn); + models(:,:,1:crop)=[]; %TODO: never allocate space for them ? + logP(:,:,1:crop)=[]; +end + + +% TODO: make standard diagnostics to give warnings... +% TODO: make some diagnostic plots if nargout==0; + + + +function textprogress(pct,curm,rejectpct) +persistent lastNchar lasttime starttime +if isempty(lastNchar)||pct==0 + lasttime=cputime-10;starttime=cputime;lastNchar=0; + pct=1e-16; +end +if pct==1 + fprintf('%s',repmat(char(8),1,lastNchar));lastNchar=0; + return +end +if (cputime-lasttime>0.1) + + ETA=datestr((cputime-starttime)*(1-pct)/(pct*60*60*24),13); + progressmsg=[183-uint8((1:40)<=(pct*40)).*(183-'*') '']; + %progressmsg=['-'-uint8((1:40)<=(pct*40)).*('-'-'') '']; + %progressmsg=[uint8((1:40)<=(pct*40)).*'#' '']; + curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); + %curmtxt=mat2str(curm); + progressmsg=sprintf('\nGWMCMC %5.1f%% [%s] %s\n%3.0f%% rejected\n%s\n',pct*100,progressmsg,ETA,rejectpct*100,curmtxt); + + fprintf('%s%s',repmat(char(8),1,lastNchar),progressmsg); + drawnow;lasttime=cputime; + lastNchar=length(progressmsg); +end + +function noaction(varargin) + +% Acknowledgements: I became aware of the GW algorithm via a student report +% which was using emcee for python. Great stuff. diff --git a/mcmc_simbio/src/gwmcmc/gwmcmc_vse.m b/mcmc_simbio/src/gwmcmc/gwmcmc_vse.m new file mode 100755 index 0000000..72a73c0 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/gwmcmc_vse.m @@ -0,0 +1,373 @@ +function [models,logP, rejProp]=gwmcmc_vse(minit,logPfuns,mccount,varargin) +%% Cascaded affine invariant ensemble MCMC sampler. "The MCMC hammer" +% +% GWMCMC is an implementation of the Goodman and Weare 2010 Affine +% invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +% enables bayesian inference. The problem with many traditional MCMC samplers +% is that they can have slow convergence for badly scaled problems, and that +% it is difficult to optimize the random walk for high-dimensional problems. +% This is where the GW-algorithm really excels as it is affine invariant. It +% can achieve much better convergence on badly scaled problems. It is much +% simpler to get to work straight out of the box, and for that reason it +% truly deserves to be called the MCMC hammer. +% +% (This code uses a cascaded variant of the Goodman and Weare algorithm). +% +% USAGE: +% [models,logP]=gwmcmc(minit,logPfuns,mccount,[Parameter,Value,Parameter,Value]); +% +% INPUTS: +% minit: an MxW matrix of initial values for each of the walkers in the +% ensemble. (M:number of model params. W: number of walkers). W +% should be atleast 2xM. (see e.g. mvnrnd). +% logPfuns: a cell of function handles returning the log probality of a +% proposed set of model parameters. Typically this cell will +% contain two function handles: one to the logprior and another +% to the loglikelihood. E.g. {@(m)logprior(m) @(m)loglike(m)} +% mccount: What is the desired total number of monte carlo proposals. +% This is the total number, -NOT the number per chain. +% +% Named Parameter-Value pairs: +% 'StepSize': unit-less stepsize (default=2.5). +% 'ThinChain': Thin all the chains by only storing every N'th step (default=10) +% 'ProgressBar': Show a text progress bar (default=true) +% 'Parallel': Run in ensemble of walkers in parallel. (default=false) +% 'BurnIn': fraction of the chain that should be removed. (default=0) +% +% OUTPUTS: +% models: A MxWxT matrix with the thinned markov chains (with T samples +% per walker). T=~mccount/p.ThinChain/W. +% logP: A PxWxT matrix of log probabilities for each model in the +% models. here P is the number of functions in logPfuns. +% +% Note on cascaded evaluation of log probabilities: +% The logPfuns-argument can be specifed as a cell-array to allow a cascaded +% evaluation of the probabilities. The computationally cheapest function should be +% placed first in the cell (this will typically the prior). This allows the +% routine to avoid calculating the likelihood, if the proposed model can be +% rejected based on the prior alone. +% logPfuns={logprior loglike} is faster but equivalent to +% logPfuns={@(m)logprior(m)+loglike(m)} +% +% TIP: if you aim to analyze the entire set of ensemble members as a single +% sample from the distribution then you may collapse output models-matrix +% thus: models=models(:,:); This will reshape the MxWxT matrix into a +% Mx(W*T)-matrix while preserving the order. +% +% +% EXAMPLE: Here we sample a multivariate normal distribution. +% +% %define problem: +% mu = [5;-3;6]; +% C = [.5 -.4 0;-.4 .5 0; 0 0 1]; +% iC=pinv(C); +% logPfuns={@(m)-0.5*sum((m-mu)'*iC*(m-mu))} +% +% %make a set of starting points for the entire ensemble of walkers +% minit=randn(length(mu),length(mu)*2); +% +% %Apply the MCMC hammer +% [models,logP]=gwmcmc(minit,logPfuns,100000); +% models(:,:,1:floor(size(models,3)*.2))=[]; %remove 20% as burn-in +% models=models(:,:)'; %reshape matrix to collapse the ensemble member dimension +% scatter(models(:,1),models(:,2)) +% prctile(models,[5 50 95]) +% +% +% References: +% Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. +% App. Math. Comp. Sci., Vol. 5, No. 1, 6580 +% Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +% +% WebPage: https://github.com/grinsted/gwmcmc +% +% -Aslak Grinsted 2015 + + +persistent isoctave; +if isempty(isoctave) + isoctave = (exist ('OCTAVE_VERSION', 'builtin') > 0); +end + +if nargin<3 + error('GWMCMC:toofewinputs','GWMCMC requires atleast 3 inputs.') +end +M=size(minit,1); +if size(minit,2)==1 + minit=bsxfun(@plus,minit,randn(M,M*5)); +end + + +p=inputParser; +if isoctave + p=p.addParamValue('StepSize',2,@isnumeric); + %addParamValue is chose for compatibility with octave. Still Untested. + p=p.addParamValue('ThinChain',10,@isnumeric); + p=p.addParamValue('ProgressBar',true,@islogical); + p=p.addParamValue('Parallel',false,@islogical); + p=p.addParamValue('BurnIn',0,@(x)(x>=0)&&(x<1)); + p=p.parse(varargin{:}); +else + p.addParameter('StepSize',2,@isnumeric); + %addParamValue is chose for compatibility with octave. Still Untested. + p.addParameter('ThinChain',10,@isnumeric); + p.addParameter('ProgressBar',true,@islogical); + p.addParameter('Parallel',false,@islogical); + p.addParameter('BurnIn',0,@(x)(x>=0)&&(x<1)); + p.parse(varargin{:}); +end +p=p.Results; + +Nwalkers=size(minit,2); +if size(minit,1)*2>size(minit,2) + warning('GWMCMC:minitdimensions',... + ['Check minit dimensions.\nIt is recommended that there be atleast'... + ' twice as many walkers in the ensemble as there are model dimension.']) +end +if p.ProgressBar + progress=@textprogress; +else + progress=@noaction; +end + +Nkeep=ceil(mccount/p.ThinChain/Nwalkers); %number of samples drawn from each walker +mccount=(Nkeep-1)*p.ThinChain+1; +models=nan(M,Nwalkers,Nkeep); %pre-allocate output matrix +models(:,:,1)=minit; + +if ~iscell(logPfuns) + logPfuns={logPfuns}; +end +NPfun=numel(logPfuns); +%calculate logP state initial pos of walkers +% logP is the result of the function(s) evaluation(s) for all walkers, at all +% timesteps we choose to keep +logP=nan(NPfun,Nwalkers,Nkeep); + +wix = 1; +for fix=1:NPfun % function index + try + v=logPfuns{fix}(minit(:,wix)); + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + v = -Inf; % could potentially change this to something like -50, but then + % if here integration tolerances are not met, an error is + % thrown. So we NEED integration tolerances to be met + % initially. This is because of the way things are compared + % in the future iterations, and accepted and rejected. + % Should be -Inf, but I have changed it to -20. in the + % later iterations, keep it at -Inf, so that any future + % integration tol errors also get rejected. + end + end + if islogical(v) + %reformulate function so that false=-inf for logical constraints. + v=-1/v;logPfuns{fix}=@(m)-1/logPfuns{fix}(m); + %experimental implementation of experimental feature + end + logP(fix,wix,1)=v; +end + + + + +if p.Parallel + parfor wix=2:Nwalkers % walker index + for fix=1:NPfun % function index + try + logP(fix,wix,1)=logPfuns{fix}(minit(:,wix)); + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + logP(fix,wix,1) = -Inf; % could potentially change this to something like -50, but then + % if here integration tolerances are not met, an error is + % thrown. So we NEED integration tolerances to be met + % initially. This is because of the way things are compared + % in the future iterations, and accepted and rejected. + % Should be -Inf, but I have changed it to -20. in the + % later iterations, keep it at -Inf, so that any future + % integration tol errors also get rejected. + else + error('what happened?') + end + end + end + end + +else + for wix=2:Nwalkers % walker index + for fix=1:NPfun % function index + try + logP(fix,wix,1)=logPfuns{fix}(minit(:,wix)); + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + logP(fix,wix,1) = -Inf; % could potentially change this to something like -50, but then + % if here integration tolerances are not met, an error is + % thrown. So we NEED integration tolerances to be met + % initially. This is because of the way things are compared + % in the future iterations, and accepted and rejected. + % Should be -Inf, but I have changed it to -20. in the + % later iterations, keep it at -Inf, so that any future + % integration tol errors also get rejected. + else + error('what happened?') + end + end + end + end + +end + + + +if ~all(all(isfinite(logP(:,:,1)))) + error('Starting points for all walkers must have finite logP') +end +reject=zeros(Nwalkers,1); +rejProp = nan(1,Nkeep); +curm=models(:,:,1); % current model, all walkers +curlogP=logP(:,:,1); +progress(0,0,0) +totcount=Nwalkers; +% preallocate matrix to store parameter values that could not get simulated +% non_integrable_m = nan(M, Nwalkers, Nkeep*p.ThinChain); +for row=1:Nkeep + for jj=1:p.ThinChain + %generate proposals for all walkers + %(done outside walker loop, in order to be compatible with parfor - some penalty for memory): + %-Note it appears to give a slight performance boost for non-parallel. + rix=mod((1:Nwalkers)+floor(rand*(Nwalkers-1)),Nwalkers)+1; %pick a random partner + zz=((p.StepSize - 1)*rand(1,Nwalkers) + 1).^2/p.StepSize; + %VSE: whu -1 here? this is what makes the system fail at 1 + proposedm=curm(:,rix) - bsxfun(@times,(curm(:,rix)-curm),zz); + logrand=log(rand(NPfun+1,Nwalkers)); %moved outside because rand is slow inside parfor + % logrand is what we compare our computed log likelihood to. + totalcount = (row-1)*p.ThinChain+jj; + if p.Parallel + %parallel/non-parallel code is currently mirrored in + %order to enable experimentation with separate optimization + %techniques for each branch. Parallel is not really great yet. + %TODO: use SPMD instead of parfor. + + parfor wix=1:Nwalkers + cp=curlogP(:,wix); + lr=logrand(:,wix); + acceptfullstep=true; + proposedlogP=nan(NPfun,1); + + if lr(1)<(numel(proposedm(:,wix))-1)*log(zz(wix)) + for fix=1:NPfun + try + proposedlogP(fix)=logPfuns{fix}(proposedm(:,wix)); + %have tested workerobjwrapper but that is slower. + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + % non_integrable_m(:,wix,totalcount) = proposedm(:,wix); + proposedlogP(fix) = -Inf; + end + end + + if lr(fix+1)>proposedlogP(fix)-cp(fix) ||... + ~isreal(proposedlogP(fix)) || isnan( proposedlogP(fix) ) + %if ~(lr(fix+1)proposedlogP(fix)-curlogP(fix,wix)... + || ~isreal(proposedlogP(fix)) || isnan(proposedlogP(fix)) + %if ~(logrand(fix+1,wix)0 + crop=ceil(Nkeep*p.BurnIn); + models(:,:,1:crop)=[]; %TODO: never allocate space for them ? + logP(:,:,1:crop)=[]; +end + + +% TODO: make standard diagnostics to give warnings... +% TODO: make some diagnostic plots if nargout==0; + + + +function textprogress(pct,curm,rejectpct) +persistent lastNchar lasttime starttime +if isempty(lastNchar)||pct==0 + lasttime=cputime-10;starttime=cputime;lastNchar=0; + pct=1e-16; +end +if pct==1 + fprintf('%s',repmat(char(8),1,lastNchar));lastNchar=0; + return +end +if (cputime-lasttime>0.1) + + ETA=datestr((cputime-starttime)*(1-pct)/(pct*60*60*24),13); + progressmsg=[183-uint8((1:40)<=(pct*40)).*(183-'*') '']; + %progressmsg=['-'-uint8((1:40)<=(pct*40)).*('-'-'') '']; + %progressmsg=[uint8((1:40)<=(pct*40)).*'#' '']; + curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); + %curmtxt=mat2str(curm); + progressmsg=sprintf('\nGWMCMC %5.1f%% [%s] %s\n%3.0f%% rejected\n%s\n',... + pct*100,progressmsg,ETA,rejectpct*100,curmtxt); + + fprintf('%s%s',repmat(char(8),1,lastNchar),progressmsg); + drawnow;lasttime=cputime; + lastNchar=length(progressmsg); +end + +function noaction(varargin) + +% Acknowledgements: I became aware of the GW algorithm via a student report +% which was using emcee for python. Great stuff. diff --git a/mcmc_simbio/src/gwmcmc/gwmcmc_vse_deterministic.m b/mcmc_simbio/src/gwmcmc/gwmcmc_vse_deterministic.m new file mode 100755 index 0000000..129d0cd --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/gwmcmc_vse_deterministic.m @@ -0,0 +1,314 @@ +function [models,logP, non_integrable_m, rejProp]=gwmcmc_vse_deterministic(minit,logPfuns,mccount,varargin) +%% Cascaded affine invariant ensemble MCMC sampler. "The MCMC hammer" +% +% GWMCMC is an implementation of the Goodman and Weare 2010 Affine +% invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +% enables bayesian inference. The problem with many traditional MCMC samplers +% is that they can have slow convergence for badly scaled problems, and that +% it is difficult to optimize the random walk for high-dimensional problems. +% This is where the GW-algorithm really excels as it is affine invariant. It +% can achieve much better convergence on badly scaled problems. It is much +% simpler to get to work straight out of the box, and for that reason it +% truly deserves to be called the MCMC hammer. +% +% (This code uses a cascaded variant of the Goodman and Weare algorithm). +% +% USAGE: +% [models,logP]=gwmcmc(minit,logPfuns,mccount,[Parameter,Value,Parameter,Value]); +% +% INPUTS: +% minit: an MxW matrix of initial values for each of the walkers in the +% ensemble. (M:number of model params. W: number of walkers). W +% should be atleast 2xM. (see e.g. mvnrnd). +% logPfuns: a cell of function handles returning the log probality of a +% proposed set of model parameters. Typically this cell will +% contain two function handles: one to the logprior and another +% to the loglikelihood. E.g. {@(m)logprior(m) @(m)loglike(m)} +% mccount: What is the desired total number of monte carlo proposals. +% This is the total number, -NOT the number per chain. +% +% Named Parameter-Value pairs: +% 'StepSize': unit-less stepsize (default=2.5). +% 'ThinChain': Thin all the chains by only storing every N'th step (default=10) +% 'ProgressBar': Show a text progress bar (default=true) +% 'Parallel': Run in ensemble of walkers in parallel. (default=false) +% 'BurnIn': fraction of the chain that should be removed. (default=0) +% +% OUTPUTS: +% models: A MxWxT matrix with the thinned markov chains (with T samples +% per walker). T=~mccount/p.ThinChain/W. +% logP: A PxWxT matrix of log probabilities for each model in the +% models. here P is the number of functions in logPfuns. +% +% Note on cascaded evaluation of log probabilities: +% The logPfuns-argument can be specifed as a cell-array to allow a cascaded +% evaluation of the probabilities. The computationally cheapest function should be +% placed first in the cell (this will typically the prior). This allows the +% routine to avoid calculating the likelihood, if the proposed model can be +% rejected based on the prior alone. +% logPfuns={logprior loglike} is faster but equivalent to +% logPfuns={@(m)logprior(m)+loglike(m)} +% +% TIP: if you aim to analyze the entire set of ensemble members as a single +% sample from the distribution then you may collapse output models-matrix +% thus: models=models(:,:); This will reshape the MxWxT matrix into a +% Mx(W*T)-matrix while preserving the order. +% +% +% EXAMPLE: Here we sample a multivariate normal distribution. +% +% %define problem: +% mu = [5;-3;6]; +% C = [.5 -.4 0;-.4 .5 0; 0 0 1]; +% iC=pinv(C); +% logPfuns={@(m)-0.5*sum((m-mu)'*iC*(m-mu))} +% +% %make a set of starting points for the entire ensemble of walkers +% minit=randn(length(mu),length(mu)*2); +% +% %Apply the MCMC hammer +% [models,logP]=gwmcmc(minit,logPfuns,100000); +% models(:,:,1:floor(size(models,3)*.2))=[]; %remove 20% as burn-in +% models=models(:,:)'; %reshape matrix to collapse the ensemble member dimension +% scatter(models(:,1),models(:,2)) +% prctile(models,[5 50 95]) +% +% +% References: +% Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. App. Math. Comp. Sci., Vol. 5, No. 1, 6580 +% Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +% +% WebPage: https://github.com/grinsted/gwmcmc +% +% -Aslak Grinsted 2015 + + +persistent isoctave; +if isempty(isoctave) + isoctave = (exist ('OCTAVE_VERSION', 'builtin') > 0); +end + +if nargin<3 + error('GWMCMC:toofewinputs','GWMCMC requires atleast 3 inputs.') +end +M=size(minit,1); +if size(minit,2)==1 + minit=bsxfun(@plus,minit,randn(M,M*5)); +end + + +p=inputParser; +if isoctave + p=p.addParamValue('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p=p.addParamValue('ThinChain',10,@isnumeric); + p=p.addParamValue('ProgressBar',true,@islogical); + p=p.addParamValue('Parallel',false,@islogical); + p=p.addParamValue('BurnIn',0,@(x)(x>=0)&&(x<1)); + p=p.parse(varargin{:}); +else + p.addParameter('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p.addParameter('ThinChain',10,@isnumeric); + p.addParameter('ProgressBar',true,@islogical); + p.addParameter('Parallel',false,@islogical); + p.addParameter('BurnIn',0,@(x)(x>=0)&&(x<1)); + p.parse(varargin{:}); +end +p=p.Results; + +Nwalkers=size(minit,2); +if size(minit,1)*2>size(minit,2) + warning('GWMCMC:minitdimensions','Check minit dimensions.\nIt is recommended that there be atleast twice as many walkers in the ensemble as there are model dimension.') +end +if p.ProgressBar + progress=@textprogress; +else + progress=@noaction; +end + +Nkeep=ceil(mccount/p.ThinChain/Nwalkers); %number of samples drawn from each walker +mccount=(Nkeep-1)*p.ThinChain+1; +models=nan(M,Nwalkers,Nkeep); %pre-allocate output matrix +models(:,:,1)=minit; + +if ~iscell(logPfuns) + logPfuns={logPfuns}; +end +NPfun=numel(logPfuns); +%calculate logP state initial pos of walkers +% logP is the result of the function(s) evaluation(s) for all walkers, at all +% timesteps we choose to keep +logP=nan(NPfun,Nwalkers,Nkeep); + +for wix=1:Nwalkers % walker index + for fix=1:NPfun % function index + try + v=logPfuns{fix}(minit(:,wix)); + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + v = -Inf; + % could potentially change this to something like -50, but then + % if here integration tolerances are not met, an error is + % thrown. So we NEED integration tolerances to be met + % initially. This is because of the way things are compared + % in the future iterations, and accepted and rejected. + % Should be -Inf, but I have changed it to -20. in the + % later iterations, keep it at -Inf, so that any future + % integration tol errors also get rejected. + end + end + if islogical(v) + %reformulate function so that false=-inf for logical constraints. + v=-1/v;logPfuns{fix}=@(m)-1/logPfuns{fix}(m); + %experimental implementation of experimental feature + end + logP(fix,wix,1)=v; + end +end + +if ~all(all(isfinite(logP(:,:,1)))) + error('Starting points for all walkers must have finite logP') +end +reject=zeros(Nwalkers,1); +rejProp = nan(1,Nkeep); +curm=models(:,:,1); % current model, all walkers +curlogP=logP(:,:,1); +progress(0,0,0) +totcount=Nwalkers; +% preallocate matrix to store parameter values that could not get simulated +non_integrable_m = nan(M, Nwalkers, Nkeep*p.ThinChain); +for row=1:Nkeep + for jj=1:p.ThinChain + %generate proposals for all walkers + %(done outside walker loop, in order to be compatible with parfor - some penalty for memory): + %-Note it appears to give a slight performance boost for non-parallel. + rix=mod((1:Nwalkers)+floor(rand*(Nwalkers-1)),Nwalkers)+1; %pick a random partner + zz=((p.StepSize - 1)*rand(1,Nwalkers) + 1).^2/p.StepSize; + %VSE: whu -1 here? this is what makes the system fail at 1 + proposedm=curm(:,rix) - bsxfun(@times,(curm(:,rix)-curm),zz); + logrand=log(rand(NPfun+1,Nwalkers)); %moved outside because rand is slow inside parfor + % logrand is what we compare our computed log likelihood to. + totalcount = (row-1)*p.ThinChain+jj; + if p.Parallel + %parallel/non-parallel code is currently mirrored in + %order to enable experimentation with separate optimization + %techniques for each branch. Parallel is not really great yet. + %TODO: use SPMD instead of parfor. + + parfor wix=1:Nwalkers + cp=curlogP(:,wix); + lr=logrand(:,wix); + acceptfullstep=true; + proposedlogP=nan(NPfun,1); + + if lr(1)<(numel(proposedm(:,wix))-1)*log(zz(wix)) + for fix=1:NPfun + try + proposedlogP(fix)=logPfuns{fix}(proposedm(:,wix)); %have tested workerobjwrapper but that is slower. + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + non_integrable_m(:,wix,totalcount) = proposedm(:,wix); + proposedlogP(fix) = -Inf; + end + end + + if lr(fix+1)>proposedlogP(fix)-cp(fix) || ~isreal(proposedlogP(fix)) || isnan( proposedlogP(fix) ) + %if ~(lr(fix+1)proposedlogP(fix)-curlogP(fix,wix) || ~isreal(proposedlogP(fix)) || isnan(proposedlogP(fix)) + %if ~(logrand(fix+1,wix)0 + crop=ceil(Nkeep*p.BurnIn); + models(:,:,1:crop)=[]; %TODO: never allocate space for them ? + logP(:,:,1:crop)=[]; +end + + +% TODO: make standard diagnostics to give warnings... +% TODO: make some diagnostic plots if nargout==0; + + + +function textprogress(pct,curm,rejectpct) +persistent lastNchar lasttime starttime +if isempty(lastNchar)||pct==0 + lasttime=cputime-10;starttime=cputime;lastNchar=0; + pct=1e-16; +end +if pct==1 + fprintf('%s',repmat(char(8),1,lastNchar));lastNchar=0; + return +end +if (cputime-lasttime>0.1) + + ETA=datestr((cputime-starttime)*(1-pct)/(pct*60*60*24),13); + progressmsg=[183-uint8((1:40)<=(pct*40)).*(183-'*') '']; + %progressmsg=['-'-uint8((1:40)<=(pct*40)).*('-'-'') '']; + %progressmsg=[uint8((1:40)<=(pct*40)).*'#' '']; + curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); + %curmtxt=mat2str(curm); + progressmsg=sprintf('\nGWMCMC %5.1f%% [%s] %s\n%3.0f%% rejected\n%s\n',pct*100,progressmsg,ETA,rejectpct*100,curmtxt); + + fprintf('%s%s',repmat(char(8),1,lastNchar),progressmsg); + drawnow;lasttime=cputime; + lastNchar=length(progressmsg); +end + +function noaction(varargin) + +% Acknowledgements: I became aware of the GW algorithm via a student report +% which was using emcee for python. Great stuff. diff --git a/mcmc_simbio/src/gwmcmc/gwmcmc_vse_diagnosticmode.m b/mcmc_simbio/src/gwmcmc/gwmcmc_vse_diagnosticmode.m new file mode 100755 index 0000000..6c1e369 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/gwmcmc_vse_diagnosticmode.m @@ -0,0 +1,316 @@ +function [models,logP, non_integrable_m, rejProp]=gwmcmc_vse_diagnosticmode(minit,logPfuns,mccount,varargin) +%% Cascaded affine invariant ensemble MCMC sampler. "The MCMC hammer" +% % this is just a copy of the gwmcmc_vse, and contains the non integrable +% points array. Going forward, I am removing that array from the +% computation so reduce the space overhead. +% +% GWMCMC is an implementation of the Goodman and Weare 2010 Affine +% invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +% enables bayesian inference. The problem with many traditional MCMC samplers +% is that they can have slow convergence for badly scaled problems, and that +% it is difficult to optimize the random walk for high-dimensional problems. +% This is where the GW-algorithm really excels as it is affine invariant. It +% can achieve much better convergence on badly scaled problems. It is much +% simpler to get to work straight out of the box, and for that reason it +% truly deserves to be called the MCMC hammer. +% +% (This code uses a cascaded variant of the Goodman and Weare algorithm). +% +% USAGE: +% [models,logP]=gwmcmc(minit,logPfuns,mccount,[Parameter,Value,Parameter,Value]); +% +% INPUTS: +% minit: an MxW matrix of initial values for each of the walkers in the +% ensemble. (M:number of model params. W: number of walkers). W +% should be atleast 2xM. (see e.g. mvnrnd). +% logPfuns: a cell of function handles returning the log probality of a +% proposed set of model parameters. Typically this cell will +% contain two function handles: one to the logprior and another +% to the loglikelihood. E.g. {@(m)logprior(m) @(m)loglike(m)} +% mccount: What is the desired total number of monte carlo proposals. +% This is the total number, -NOT the number per chain. +% +% Named Parameter-Value pairs: +% 'StepSize': unit-less stepsize (default=2.5). +% 'ThinChain': Thin all the chains by only storing every N'th step (default=10) +% 'ProgressBar': Show a text progress bar (default=true) +% 'Parallel': Run in ensemble of walkers in parallel. (default=false) +% 'BurnIn': fraction of the chain that should be removed. (default=0) +% +% OUTPUTS: +% models: A MxWxT matrix with the thinned markov chains (with T samples +% per walker). T=~mccount/p.ThinChain/W. +% logP: A PxWxT matrix of log probabilities for each model in the +% models. here P is the number of functions in logPfuns. +% +% Note on cascaded evaluation of log probabilities: +% The logPfuns-argument can be specifed as a cell-array to allow a cascaded +% evaluation of the probabilities. The computationally cheapest function should be +% placed first in the cell (this will typically the prior). This allows the +% routine to avoid calculating the likelihood, if the proposed model can be +% rejected based on the prior alone. +% logPfuns={logprior loglike} is faster but equivalent to +% logPfuns={@(m)logprior(m)+loglike(m)} +% +% TIP: if you aim to analyze the entire set of ensemble members as a single +% sample from the distribution then you may collapse output models-matrix +% thus: models=models(:,:); This will reshape the MxWxT matrix into a +% Mx(W*T)-matrix while preserving the order. +% +% +% EXAMPLE: Here we sample a multivariate normal distribution. +% +% %define problem: +% mu = [5;-3;6]; +% C = [.5 -.4 0;-.4 .5 0; 0 0 1]; +% iC=pinv(C); +% logPfuns={@(m)-0.5*sum((m-mu)'*iC*(m-mu))} +% +% %make a set of starting points for the entire ensemble of walkers +% minit=randn(length(mu),length(mu)*2); +% +% %Apply the MCMC hammer +% [models,logP]=gwmcmc(minit,logPfuns,100000); +% models(:,:,1:floor(size(models,3)*.2))=[]; %remove 20% as burn-in +% models=models(:,:)'; %reshape matrix to collapse the ensemble member dimension +% scatter(models(:,1),models(:,2)) +% prctile(models,[5 50 95]) +% +% +% References: +% Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. App. Math. Comp. Sci., Vol. 5, No. 1, 6580 +% Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +% +% WebPage: https://github.com/grinsted/gwmcmc +% +% -Aslak Grinsted 2015 + + +persistent isoctave; +if isempty(isoctave) + isoctave = (exist ('OCTAVE_VERSION', 'builtin') > 0); +end + +if nargin<3 + error('GWMCMC:toofewinputs','GWMCMC requires atleast 3 inputs.') +end +M=size(minit,1); +if size(minit,2)==1 + minit=bsxfun(@plus,minit,randn(M,M*5)); +end + + +p=inputParser; +if isoctave + p=p.addParamValue('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p=p.addParamValue('ThinChain',10,@isnumeric); + p=p.addParamValue('ProgressBar',true,@islogical); + p=p.addParamValue('Parallel',false,@islogical); + p=p.addParamValue('BurnIn',0,@(x)(x>=0)&&(x<1)); + p=p.parse(varargin{:}); +else + p.addParameter('StepSize',2,@isnumeric); %addParamValue is chose for compatibility with octave. Still Untested. + p.addParameter('ThinChain',10,@isnumeric); + p.addParameter('ProgressBar',true,@islogical); + p.addParameter('Parallel',false,@islogical); + p.addParameter('BurnIn',0,@(x)(x>=0)&&(x<1)); + p.parse(varargin{:}); +end +p=p.Results; + +Nwalkers=size(minit,2); +if size(minit,1)*2>size(minit,2) + warning('GWMCMC:minitdimensions','Check minit dimensions.\nIt is recommended that there be atleast twice as many walkers in the ensemble as there are model dimension.') +end +if p.ProgressBar + progress=@textprogress; +else + progress=@noaction; +end + +Nkeep=ceil(mccount/p.ThinChain/Nwalkers); %number of samples drawn from each walker +mccount=(Nkeep-1)*p.ThinChain+1; +models=nan(M,Nwalkers,Nkeep); %pre-allocate output matrix +models(:,:,1)=minit; + +if ~iscell(logPfuns) + logPfuns={logPfuns}; +end +NPfun=numel(logPfuns); +%calculate logP state initial pos of walkers +% logP is the result of the function(s) evaluation(s) for all walkers, at all +% timesteps we choose to keep +logP=nan(NPfun,Nwalkers,Nkeep); + +for wix=1:Nwalkers % walker index + for fix=1:NPfun % function index + try + v=logPfuns{fix}(minit(:,wix)); + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + v = -Inf; % could potentially change this to something like -50, but then + % if here integration tolerances are not met, an error is + % thrown. So we NEED integration tolerances to be met + % initially. This is because of the way things are compared + % in the future iterations, and accepted and rejected. + % Should be -Inf, but I have changed it to -20. in the + % later iterations, keep it at -Inf, so that any future + % integration tol errors also get rejected. + end + end + if islogical(v) + %reformulate function so that false=-inf for logical constraints. + v=-1/v;logPfuns{fix}=@(m)-1/logPfuns{fix}(m); + %experimental implementation of experimental feature + end + logP(fix,wix,1)=v; + end +end + +if ~all(all(isfinite(logP(:,:,1)))) + error('Starting points for all walkers must have finite logP') +end +reject=zeros(Nwalkers,1); +rejProp = nan(1,Nkeep); +curm=models(:,:,1); % current model, all walkers +curlogP=logP(:,:,1); +progress(0,0,0) +totcount=Nwalkers; +% preallocate matrix to store parameter values that could not get simulated +non_integrable_m = nan(M, Nwalkers, Nkeep*p.ThinChain); +for row=1:Nkeep + for jj=1:p.ThinChain + %generate proposals for all walkers + %(done outside walker loop, in order to be compatible with parfor - some penalty for memory): + %-Note it appears to give a slight performance boost for non-parallel. + rix=mod((1:Nwalkers)+floor(rand*(Nwalkers-1)),Nwalkers)+1; %pick a random partner + zz=((p.StepSize - 1)*rand(1,Nwalkers) + 1).^2/p.StepSize; + %VSE: whu -1 here? this is what makes the system fail at 1 + proposedm=curm(:,rix) - bsxfun(@times,(curm(:,rix)-curm),zz); + logrand=log(rand(NPfun+1,Nwalkers)); %moved outside because rand is slow inside parfor + % logrand is what we compare our computed log likelihood to. + totalcount = (row-1)*p.ThinChain+jj; + if p.Parallel + %parallel/non-parallel code is currently mirrored in + %order to enable experimentation with separate optimization + %techniques for each branch. Parallel is not really great yet. + %TODO: use SPMD instead of parfor. + + parfor wix=1:Nwalkers + cp=curlogP(:,wix); + lr=logrand(:,wix); + acceptfullstep=true; + proposedlogP=nan(NPfun,1); + + if lr(1)<(numel(proposedm(:,wix))-1)*log(zz(wix)) + for fix=1:NPfun + try + proposedlogP(fix)=logPfuns{fix}(proposedm(:,wix)); %have tested workerobjwrapper but that is slower. + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + non_integrable_m(:,wix,totalcount) = proposedm(:,wix); + proposedlogP(fix) = -Inf; + end + end + + if lr(fix+1)>proposedlogP(fix)-cp(fix) || ~isreal(proposedlogP(fix)) || isnan( proposedlogP(fix) ) + %if ~(lr(fix+1)proposedlogP(fix)-curlogP(fix,wix) || ~isreal(proposedlogP(fix)) || isnan(proposedlogP(fix)) + %if ~(logrand(fix+1,wix)0 + crop=ceil(Nkeep*p.BurnIn); + models(:,:,1:crop)=[]; %TODO: never allocate space for them ? + logP(:,:,1:crop)=[]; +end + + +% TODO: make standard diagnostics to give warnings... +% TODO: make some diagnostic plots if nargout==0; + + + +function textprogress(pct,curm,rejectpct) +persistent lastNchar lasttime starttime +if isempty(lastNchar)||pct==0 + lasttime=cputime-10;starttime=cputime;lastNchar=0; + pct=1e-16; +end +if pct==1 + fprintf('%s',repmat(char(8),1,lastNchar));lastNchar=0; + return +end +if (cputime-lasttime>0.1) + + ETA=datestr((cputime-starttime)*(1-pct)/(pct*60*60*24),13); + progressmsg=[183-uint8((1:40)<=(pct*40)).*(183-'*') '']; + %progressmsg=['-'-uint8((1:40)<=(pct*40)).*('-'-'') '']; + %progressmsg=[uint8((1:40)<=(pct*40)).*'#' '']; + curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); + %curmtxt=mat2str(curm); + progressmsg=sprintf('\nGWMCMC %5.1f%% [%s] %s\n%3.0f%% rejected\n%s\n',pct*100,progressmsg,ETA,rejectpct*100,curmtxt); + + fprintf('%s%s',repmat(char(8),1,lastNchar),progressmsg); + drawnow;lasttime=cputime; + lastNchar=length(progressmsg); +end + +function noaction(varargin) + +% Acknowledgements: I became aware of the GW algorithm via a student report +% which was using emcee for python. Great stuff. diff --git a/mcmc_simbio/src/gwmcmc/gwmcmc_vse_origjan30_19.m b/mcmc_simbio/src/gwmcmc/gwmcmc_vse_origjan30_19.m new file mode 100755 index 0000000..8689298 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/gwmcmc_vse_origjan30_19.m @@ -0,0 +1,323 @@ +function [models,logP, rejProp]=gwmcmc_vse(minit,logPfuns,mccount,varargin) +%% Cascaded affine invariant ensemble MCMC sampler. "The MCMC hammer" +% +% GWMCMC is an implementation of the Goodman and Weare 2010 Affine +% invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling +% enables bayesian inference. The problem with many traditional MCMC samplers +% is that they can have slow convergence for badly scaled problems, and that +% it is difficult to optimize the random walk for high-dimensional problems. +% This is where the GW-algorithm really excels as it is affine invariant. It +% can achieve much better convergence on badly scaled problems. It is much +% simpler to get to work straight out of the box, and for that reason it +% truly deserves to be called the MCMC hammer. +% +% (This code uses a cascaded variant of the Goodman and Weare algorithm). +% +% USAGE: +% [models,logP]=gwmcmc(minit,logPfuns,mccount,[Parameter,Value,Parameter,Value]); +% +% INPUTS: +% minit: an MxW matrix of initial values for each of the walkers in the +% ensemble. (M:number of model params. W: number of walkers). W +% should be atleast 2xM. (see e.g. mvnrnd). +% logPfuns: a cell of function handles returning the log probality of a +% proposed set of model parameters. Typically this cell will +% contain two function handles: one to the logprior and another +% to the loglikelihood. E.g. {@(m)logprior(m) @(m)loglike(m)} +% mccount: What is the desired total number of monte carlo proposals. +% This is the total number, -NOT the number per chain. +% +% Named Parameter-Value pairs: +% 'StepSize': unit-less stepsize (default=2.5). +% 'ThinChain': Thin all the chains by only storing every N'th step (default=10) +% 'ProgressBar': Show a text progress bar (default=true) +% 'Parallel': Run in ensemble of walkers in parallel. (default=false) +% 'BurnIn': fraction of the chain that should be removed. (default=0) +% +% OUTPUTS: +% models: A MxWxT matrix with the thinned markov chains (with T samples +% per walker). T=~mccount/p.ThinChain/W. +% logP: A PxWxT matrix of log probabilities for each model in the +% models. here P is the number of functions in logPfuns. +% +% Note on cascaded evaluation of log probabilities: +% The logPfuns-argument can be specifed as a cell-array to allow a cascaded +% evaluation of the probabilities. The computationally cheapest function should be +% placed first in the cell (this will typically the prior). This allows the +% routine to avoid calculating the likelihood, if the proposed model can be +% rejected based on the prior alone. +% logPfuns={logprior loglike} is faster but equivalent to +% logPfuns={@(m)logprior(m)+loglike(m)} +% +% TIP: if you aim to analyze the entire set of ensemble members as a single +% sample from the distribution then you may collapse output models-matrix +% thus: models=models(:,:); This will reshape the MxWxT matrix into a +% Mx(W*T)-matrix while preserving the order. +% +% +% EXAMPLE: Here we sample a multivariate normal distribution. +% +% %define problem: +% mu = [5;-3;6]; +% C = [.5 -.4 0;-.4 .5 0; 0 0 1]; +% iC=pinv(C); +% logPfuns={@(m)-0.5*sum((m-mu)'*iC*(m-mu))} +% +% %make a set of starting points for the entire ensemble of walkers +% minit=randn(length(mu),length(mu)*2); +% +% %Apply the MCMC hammer +% [models,logP]=gwmcmc(minit,logPfuns,100000); +% models(:,:,1:floor(size(models,3)*.2))=[]; %remove 20% as burn-in +% models=models(:,:)'; %reshape matrix to collapse the ensemble member dimension +% scatter(models(:,1),models(:,2)) +% prctile(models,[5 50 95]) +% +% +% References: +% Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. +% App. Math. Comp. Sci., Vol. 5, No. 1, 65�80 +% Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +% +% WebPage: https://github.com/grinsted/gwmcmc +% +% -Aslak Grinsted 2015 + + +persistent isoctave; +if isempty(isoctave) + isoctave = (exist ('OCTAVE_VERSION', 'builtin') > 0); +end + +if nargin<3 + error('GWMCMC:toofewinputs','GWMCMC requires atleast 3 inputs.') +end +M=size(minit,1); +if size(minit,2)==1 + minit=bsxfun(@plus,minit,randn(M,M*5)); +end + + +p=inputParser; +if isoctave + p=p.addParamValue('StepSize',2,@isnumeric); + %addParamValue is chose for compatibility with octave. Still Untested. + p=p.addParamValue('ThinChain',10,@isnumeric); + p=p.addParamValue('ProgressBar',true,@islogical); + p=p.addParamValue('Parallel',false,@islogical); + p=p.addParamValue('BurnIn',0,@(x)(x>=0)&&(x<1)); + p=p.parse(varargin{:}); +else + p.addParameter('StepSize',2,@isnumeric); + %addParamValue is chose for compatibility with octave. Still Untested. + p.addParameter('ThinChain',10,@isnumeric); + p.addParameter('ProgressBar',true,@islogical); + p.addParameter('Parallel',false,@islogical); + p.addParameter('BurnIn',0,@(x)(x>=0)&&(x<1)); + p.parse(varargin{:}); +end +p=p.Results; + +Nwalkers=size(minit,2); +if size(minit,1)*2>size(minit,2) + warning('GWMCMC:minitdimensions',... + ['Check minit dimensions.\nIt is recommended that there be atleast'... + ' twice as many walkers in the ensemble as there are model dimension.']) +end +if p.ProgressBar + progress=@textprogress; +else + progress=@noaction; +end + +Nkeep=ceil(mccount/p.ThinChain/Nwalkers); %number of samples drawn from each walker +mccount=(Nkeep-1)*p.ThinChain+1; +models=nan(M,Nwalkers,Nkeep); %pre-allocate output matrix +models(:,:,1)=minit; + +if ~iscell(logPfuns) + logPfuns={logPfuns}; +end +NPfun=numel(logPfuns); +%calculate logP state initial pos of walkers +% logP is the result of the function(s) evaluation(s) for all walkers, at all +% timesteps we choose to keep +logP=nan(NPfun,Nwalkers,Nkeep); + +for wix=1:Nwalkers % walker index + for fix=1:NPfun % function index + try + v=logPfuns{fix}(minit(:,wix)); + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') + v = -Inf; % could potentially change this to something like -50, but then + % if here integration tolerances are not met, an error is + % thrown. So we NEED integration tolerances to be met + % initially. This is because of the way things are compared + % in the future iterations, and accepted and rejected. + % Should be -Inf, but I have changed it to -20. in the + % later iterations, keep it at -Inf, so that any future + % integration tol errors also get rejected. + end + end + if islogical(v) + %reformulate function so that false=-inf for logical constraints. + v=-1/v;logPfuns{fix}=@(m)-1/logPfuns{fix}(m); + %experimental implementation of experimental feature + end + logP(fix,wix,1)=v; + end +end + +if ~all(all(isfinite(logP(:,:,1)))) + error('Starting points for all walkers must have finite logP') +end +reject=zeros(Nwalkers,1); +rejProp = nan(1,Nkeep); +curm=models(:,:,1); % current model, all walkers +curlogP=logP(:,:,1); +progress(0,0,0) +totcount=Nwalkers; +% preallocate matrix to store parameter values that could not get simulated +% non_integrable_m = nan(M, Nwalkers, Nkeep*p.ThinChain); +for row=1:Nkeep + for jj=1:p.ThinChain + %generate proposals for all walkers + %(done outside walker loop, in order to be compatible with parfor - some penalty for memory): + %-Note it appears to give a slight performance boost for non-parallel. + rix=mod((1:Nwalkers)+floor(rand*(Nwalkers-1)),Nwalkers)+1; %pick a random partner + zz=((p.StepSize - 1)*rand(1,Nwalkers) + 1).^2/p.StepSize; + %VSE: whu -1 here? this is what makes the system fail at 1 + proposedm=curm(:,rix) - bsxfun(@times,(curm(:,rix)-curm),zz); + logrand=log(rand(NPfun+1,Nwalkers)); %moved outside because rand is slow inside parfor + % logrand is what we compare our computed log likelihood to. + totalcount = (row-1)*p.ThinChain+jj; + if p.Parallel + %parallel/non-parallel code is currently mirrored in + %order to enable experimentation with separate optimization + %techniques for each branch. Parallel is not really great yet. + %TODO: use SPMD instead of parfor. + + parfor wix=1:Nwalkers + cp=curlogP(:,wix); + lr=logrand(:,wix); + acceptfullstep=true; + proposedlogP=nan(NPfun,1); + + if lr(1)<(numel(proposedm(:,wix))-1)*log(zz(wix)) + for fix=1:NPfun + try + proposedlogP(fix)=logPfuns{fix}(proposedm(:,wix)); + %have tested workerobjwrapper but that is slower. + catch ME + if strcmp(ME.identifier, 'DESuite:ODE15S:IntegrationToleranceNotMet') +% non_integrable_m(:,wix,totalcount) = proposedm(:,wix); + proposedlogP(fix) = -Inf; + end + end + + if lr(fix+1)>proposedlogP(fix)-cp(fix) ||... + ~isreal(proposedlogP(fix)) || isnan( proposedlogP(fix) ) + %if ~(lr(fix+1)proposedlogP(fix)-curlogP(fix,wix)... + || ~isreal(proposedlogP(fix)) || isnan(proposedlogP(fix)) + %if ~(logrand(fix+1,wix)0 + crop=ceil(Nkeep*p.BurnIn); + models(:,:,1:crop)=[]; %TODO: never allocate space for them ? + logP(:,:,1:crop)=[]; +end + + +% TODO: make standard diagnostics to give warnings... +% TODO: make some diagnostic plots if nargout==0; + + + +function textprogress(pct,curm,rejectpct) +persistent lastNchar lasttime starttime +if isempty(lastNchar)||pct==0 + lasttime=cputime-10;starttime=cputime;lastNchar=0; + pct=1e-16; +end +if pct==1 + fprintf('%s',repmat(char(8),1,lastNchar));lastNchar=0; + return +end +if (cputime-lasttime>0.1) + + ETA=datestr((cputime-starttime)*(1-pct)/(pct*60*60*24),13); + progressmsg=[183-uint8((1:40)<=(pct*40)).*(183-'*') '']; + %progressmsg=['-'-uint8((1:40)<=(pct*40)).*('-'-'�') '']; + %progressmsg=[uint8((1:40)<=(pct*40)).*'#' '']; + curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); + %curmtxt=mat2str(curm); + progressmsg=sprintf('\nGWMCMC %5.1f%% [%s] %s\n%3.0f%% rejected\n%s\n',... + pct*100,progressmsg,ETA,rejectpct*100,curmtxt); + + fprintf('%s%s',repmat(char(8),1,lastNchar),progressmsg); + drawnow;lasttime=cputime; + lastNchar=length(progressmsg); +end + +function noaction(varargin) + +% Acknowledgements: I became aware of the GW algorithm via a student report +% which was using emcee for python. Great stuff. diff --git a/mcmc_simbio/src/gwmcmc/html/ex_behappy.html b/mcmc_simbio/src/gwmcmc/html/ex_behappy.html new file mode 100755 index 0000000..671580e --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/html/ex_behappy.html @@ -0,0 +1,117 @@ + + + + + Don't worry, be Happy

Don't worry, be Happy

Sampling a smiley face likelihood function.

Contents

Smiley face equation

Formulate a likelihood function inspired by an equation of a smiley face.

Source Michael Borcherds: https://twitter.com/mike_geogebra/status/135391208703930369

logHappiness=@(m)1-exp(1e-4*((m(1)^4+2*m(1)^2*m(2)^2-0.3*m(1)^2*m(2)-40.75*m(1)^2+m(2)^4-m(2)^3-40.75*m(2)^2+25*m(2)+393.75)*((m(1)+3)^2+(m(2)-7)^2-1)*((m(1)-3)^2+(m(2)-7)^2-1)*(m(1)^2+(m(2)-2)^2-64)));
+

Draw samples from the distribution using GWMCMC

Now we apply the MCMC hammer to draw samples from the logHappiness distribution.

[models,logP]=gwmcmc(randn(2,100),logHappiness,100000,'ThinChain',2);
+models(:,:,1:end*.2)=[];
+models=models(:,:)';
+
+
+plot(models(:,1),models(:,2),'yo','markerfacecolor',[1 1 0]*.8);
+
+axis equal off
+
+
+title('GWMCMC says: "Don''t Worry, Be Happy!"');
+

Important links

Bobby McFerrin on youtube: https://www.youtube.com/watch?v=d-diB65scQU

\ No newline at end of file diff --git a/mcmc_simbio/src/gwmcmc/html/ex_behappy.md b/mcmc_simbio/src/gwmcmc/html/ex_behappy.md new file mode 100755 index 0000000..c8b4421 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/html/ex_behappy.md @@ -0,0 +1,46 @@ +Don't worry, be Happy +======================================= + +Sampling a smiley face likelihood function. + + + +Smiley face equation +---------------------------------------------------------- + +Formulate a likelihood function inspired by an equation of a smiley face. + +Source Michael Borcherds: https:\#\#twitter.com\#mike_geogebra\#status\#135391208703930369 + +```matlab +logHappiness=@(m)1-exp(1e-4*((m(1)^4+2*m(1)^2*m(2)^2-0.3*m(1)^2*m(2)-40.75*m(1)^2+m(2)^4-m(2)^3-40.75*m(2)^2+25*m(2)+393.75)*((m(1)+3)^2+(m(2)-7)^2-1)*((m(1)-3)^2+(m(2)-7)^2-1)*(m(1)^2+(m(2)-2)^2-64))); +``` + + +Draw samples from the distribution using GWMCMC +---------------------------------------------------------- + +Now we apply the MCMC hammer to draw samples from the logHappiness distribution. + +```matlab +[models,logP]=gwmcmc(randn(2,100),logHappiness,100000,'ThinChain',2); +models(:,:,1:end*.2)=[]; +models=models(:,:)'; + + +plot(models(:,1),models(:,2),'yo','markerfacecolor',[1 1 0]*.8); + +axis equal off + + +title('GWMCMC says: "Don''t Worry, Be Happy!"'); +``` + +![IMAGE](ex_behappy_01.png) + + +Important links +---------------------------------------------------------- + +Bobby McFerrin on youtube: https:\#\#www.youtube.com\#watch?v=d-diB65scQU + diff --git a/mcmc_simbio/src/gwmcmc/html/ex_behappy_01.png b/mcmc_simbio/src/gwmcmc/html/ex_behappy_01.png new file mode 100755 index 0000000..bf840d4 Binary files /dev/null and b/mcmc_simbio/src/gwmcmc/html/ex_behappy_01.png differ diff --git a/mcmc_simbio/src/gwmcmc/html/ex_breakfit.html b/mcmc_simbio/src/gwmcmc/html/ex_breakfit.html new file mode 100755 index 0000000..e97688e --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/html/ex_breakfit.html @@ -0,0 +1,301 @@ + + + + + Fitting a trend-change model to a time series

Fitting a trend-change model to a time series

This code fits a trend-change model to a historical time series of sea level in Amsterdam with gaps.

Contents

Input data

Amsterdam sea level from this source: http://www.psmsl.org/data/longrecords/

Y=[1700 -152; 1701 -158; 1702 -132; 1703 -172; 1704 -135; 1705 -167; 1706 -192; 1707 -153; 1708 -149; 1709 -187; 1710 -168; 1711 -140; 1712 -129; 1713 -151;
+   1714 -106; 1715 -172; 1716 -168; 1717 -164; 1718 -185; 1719 -182; 1720 -109; 1721 -146; 1722 -141; 1723 -99; 1724 -145; 1725 -166; 1726 -108; 1727 -136;
+   1728 -195; 1729 -176; 1730 -148; 1731 -108; 1732 -134; 1733 -160; 1734 -165; 1735 -181; 1736 -109; 1737 -92; 1738 -152; 1739 -123; 1740 -124; 1741 -122;
+   1742 -154; 1743 -144; 1744 -148; 1745 -178; 1746 -178; 1747 -142; 1748 -147; 1749 -167; 1766 -175; 1767 -111; 1768 -160; 1769 -86; 1770 -94; 1771 -87;
+   1772 -142; 1773 -143; 1774 -135; 1775 -127; 1776 -150; 1777 -131; 1778 -155; 1779 -131; 1780 -130; 1781 -134; 1782 -160; 1783 -157; 1784 -173; 1785 -178;
+   1786 -178; 1787 -125; 1788 -204; 1789 -161; 1790 -109; 1791 -92; 1792 -150; 1793 -154; 1794 -118; 1795 -121; 1796 -157; 1797 -134; 1798 -135; 1799 -177;
+   1800 -175; 1801 -90; 1802 -159; 1803 -172; 1804 -130; 1805 -142; 1806 -106; 1807 -105; 1808 -183; 1809 -151; 1810 -128; 1811 -137; 1812 -141; 1813 -150;
+   1814 -185; 1815 -144; 1816 -113; 1817 -102; 1818 -160; 1819 -158; 1820 -194; 1821 -123; 1822 -125; 1823 -198; 1824 -97; 1825 -87; 1826 -126; 1827 -97;
+   1828 -124; 1829 -119; 1830 -141; 1831 -94; 1832 -141; 1833 -106; 1834 -77; 1835 -105; 1836 -96; 1837 -88; 1838 -117; 1839 -114; 1840 -111; 1841 -85;
+   1842 -132; 1843 -57; 1844 -53; 1845 -90; 1846 -80; 1847 -118; 1848 -141; 1849 -101; 1850 -91; 1851 -102; 1852 -97; 1853 -113; 1854 -49; 1855 -111;
+   1856 -85;  1857 -145; 1858 -137; 1859 -102; 1860 -113; 1861 -94; 1862 -125; 1863 -121; 1864 -161; 1865 -157; 1866 -93; 1867 -58; 1868 -91; 1869 -75; 1870 -129;
+   1871 -141; 1874 -110; 1875 -125; 1876 -80; 1877 -43; 1878 -60; 1879 -79; 1880 -31; 1881 -64; 1882 -74; 1883 -58; 1884 -54; 1885 -75; 1886 -88; 1887 -64; 1888 -86;
+   1889 -53; 1890 -84; 1891 -94; 1892 -78; 1893 -67; 1894 -92; 1895 -74; 1896 -81; 1897 -82; 1898 -32; 1899 -36; 1900 -67; 1901 -45; 1902 -62; 1903 -25; 1904 -58; 1905 -32;
+   1906 -34; 1907 -75; 1908 -66; 1909 -36; 1910 -12; 1911 -24; 1912 -7; 1913 -22; 1914 0; 1915 7; 1916 -5; 1917 -37; 1918 -44; 1919 -38; 1920 14; 1921 -10;
+   1922 -16; 1923 -38;1925 29];
+t=Y(:,1);
+Y=Y(:,2);
+

Define trend change forward model:

forwardmodel=@(t,m)(m(1)*(t<m(3))+m(2)*(t>m(3))).*(t-m(3))+m(4);
+

Make an initial guess for the model parameters.

p=polyfit(t-mean(t),Y,1);
+m0=[p(1) p(1) mean(t) p(2)]';
+sigma=std(Y-forwardmodel(t,m0));
+m0=[m0 ; log(sigma)];
+

Likelihood

We assume the data are normally distributed around the forward model.

% First we define a helper function equivalent to calling log(normpdf(x,mu,sigma))
+% but has higher precision because it avoids truncation errors associated with calling
+% log(exp(xxx)).
+lognormpdf=@(x,mu,sigma)-0.5*((x-mu)./sigma).^2  -log(sqrt(2*pi).*sigma);
+
+
+logLike=@(m)sum(lognormpdf(y,forwardmodel(t,m),m(5)));
+

Prior information

We want to restrict the model to place the kink-point within the observed time interval. All other parameters have a uniform prior.

logprior = @(m)(m(3)>min(t))&(m(3)<max(t));
+

Find the posterior distribution using GWMCMC

Now we apply the MCMC hammer to draw samples from the posterior.

% first we initialize the ensemble of walkers in a small gaussian ball
+% around the m0 estimate.
+
+ball=randn(length(m0),30)*0.1;
+ball(:,3)=ball(:,3)*200;
+mball=bsxfun(@plus,m0,ball);
+

Apply the hammer:

Draw samples from the posterior.

tic
+m=gwmcmc(mball,{logprior logL},300000,'burnin',.3,'stepsize',2);
+toc
+
Elapsed time is 25.385783 seconds.
+

Plot the auto-correlation function

And determine the effective sample size.

figure
+[C,lags,ESS]=eacorr(m);
+plot(lags,C,'.-',lags([1 end]),[0 0],'k');
+grid on
+xlabel('lags')
+ylabel('autocorrelation');
+text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right')
+title('Markov Chain Auto Correlation')
+

Corner plot of parameters

The corner plot shows a bi-modal distribution with two different places you might place the kink in the trend-change model.

figure
+ecornerplot(m,'ks',true,'color',[.6 .35 .3],'names',{'rate_1' 'rate_2' 'kink' 'k' '\sigma'})
+

Plot of posterior fit

figure
+m=m(:,:)'; %flatten the chain
+
+
+%make a 2d histogram of forwardmodel of the posterior samples
+ygrid=linspace(min(Y),max(Y),200);
+tgrid=min(t):max(t);
+Ycount=zeros(length(ygrid),length(tgrid));
+for kk=1:1000
+    r=ceil(rand*size(m,1));
+    Ymodel=forwardmodel(tgrid,m(r,:));
+    Ybin=round((Ymodel-ygrid(1))*length(ygrid)/(ygrid(end)-ygrid(1)));
+    for jj=1:length(tgrid)
+        Ycount(Ybin(jj),jj)	=Ycount(Ybin(jj),jj)+1;
+    end
+end
+Ycount(Ycount==0)=nan;
+h=imagesc(Ycount,'Xdata',tgrid,'Ydata',ygrid);
+axis xy
+
+hold on
+
+h=plot(t,Y,'ks','markersize',5);
+
+[~, mm]=kmeans(m, 2); %use Kmeans to characterize two solutions
+
+h(2)=plot(tgrid,forwardmodel(tgrid,mm(1,:)),'color',[.6 .45 .3],'linewidth',2);
+h(3)=plot(tgrid,forwardmodel(tgrid,mm(2,:)),'color',[.6 .3 .45],'linewidth',2);
+
+axis tight
+legend(h,'Data','Model A','Model B','location','best')
+
\ No newline at end of file diff --git a/mcmc_simbio/src/gwmcmc/html/ex_breakfit.md b/mcmc_simbio/src/gwmcmc/html/ex_breakfit.md new file mode 100755 index 0000000..acda5e5 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/html/ex_breakfit.md @@ -0,0 +1,180 @@ +Fitting a trend-change model to a time series +======================================= + +This code fits a trend-change model to a historical time series of sea level in Amsterdam with gaps. + + + +Input data +---------------------------------------------------------- + +Amsterdam sea level from this source: http://www.psmsl.org/data/longrecords/ + +```matlab +Y=[1700 -152; 1701 -158; 1702 -132; 1703 -172; 1704 -135; 1705 -167; 1706 -192; 1707 -153; 1708 -149; 1709 -187; 1710 -168; 1711 -140; 1712 -129; 1713 -151; + 1714 -106; 1715 -172; 1716 -168; 1717 -164; 1718 -185; 1719 -182; 1720 -109; 1721 -146; 1722 -141; 1723 -99; 1724 -145; 1725 -166; 1726 -108; 1727 -136; + 1728 -195; 1729 -176; 1730 -148; 1731 -108; 1732 -134; 1733 -160; 1734 -165; 1735 -181; 1736 -109; 1737 -92; 1738 -152; 1739 -123; 1740 -124; 1741 -122; + 1742 -154; 1743 -144; 1744 -148; 1745 -178; 1746 -178; 1747 -142; 1748 -147; 1749 -167; 1766 -175; 1767 -111; 1768 -160; 1769 -86; 1770 -94; 1771 -87; + 1772 -142; 1773 -143; 1774 -135; 1775 -127; 1776 -150; 1777 -131; 1778 -155; 1779 -131; 1780 -130; 1781 -134; 1782 -160; 1783 -157; 1784 -173; 1785 -178; + 1786 -178; 1787 -125; 1788 -204; 1789 -161; 1790 -109; 1791 -92; 1792 -150; 1793 -154; 1794 -118; 1795 -121; 1796 -157; 1797 -134; 1798 -135; 1799 -177; + 1800 -175; 1801 -90; 1802 -159; 1803 -172; 1804 -130; 1805 -142; 1806 -106; 1807 -105; 1808 -183; 1809 -151; 1810 -128; 1811 -137; 1812 -141; 1813 -150; + 1814 -185; 1815 -144; 1816 -113; 1817 -102; 1818 -160; 1819 -158; 1820 -194; 1821 -123; 1822 -125; 1823 -198; 1824 -97; 1825 -87; 1826 -126; 1827 -97; + 1828 -124; 1829 -119; 1830 -141; 1831 -94; 1832 -141; 1833 -106; 1834 -77; 1835 -105; 1836 -96; 1837 -88; 1838 -117; 1839 -114; 1840 -111; 1841 -85; + 1842 -132; 1843 -57; 1844 -53; 1845 -90; 1846 -80; 1847 -118; 1848 -141; 1849 -101; 1850 -91; 1851 -102; 1852 -97; 1853 -113; 1854 -49; 1855 -111; + 1856 -85; 1857 -145; 1858 -137; 1859 -102; 1860 -113; 1861 -94; 1862 -125; 1863 -121; 1864 -161; 1865 -157; 1866 -93; 1867 -58; 1868 -91; 1869 -75; 1870 -129; + 1871 -141; 1874 -110; 1875 -125; 1876 -80; 1877 -43; 1878 -60; 1879 -79; 1880 -31; 1881 -64; 1882 -74; 1883 -58; 1884 -54; 1885 -75; 1886 -88; 1887 -64; 1888 -86; + 1889 -53; 1890 -84; 1891 -94; 1892 -78; 1893 -67; 1894 -92; 1895 -74; 1896 -81; 1897 -82; 1898 -32; 1899 -36; 1900 -67; 1901 -45; 1902 -62; 1903 -25; 1904 -58; 1905 -32; + 1906 -34; 1907 -75; 1908 -66; 1909 -36; 1910 -12; 1911 -24; 1912 -7; 1913 -22; 1914 0; 1915 7; 1916 -5; 1917 -37; 1918 -44; 1919 -38; 1920 14; 1921 -10; + 1922 -16; 1923 -38;1925 29]; +t=Y(:,1); +Y=Y(:,2); +``` + + +Define trend change forward model: +---------------------------------------------------------- + +```matlab +forwardmodel=@(t,m)(m(1)*(tm(3))).*(t-m(3))+m(4); +``` + + +Make an initial guess for the model parameters. +---------------------------------------------------------- + +```matlab +p=polyfit(t-mean(t),Y,1); +m0=[p(1) p(1) mean(t) p(2)]'; +sigma=std(Y-forwardmodel(t,m0)); +m0=[m0 ; log(sigma)]; +``` + + +Likelihood +---------------------------------------------------------- + +We assume the data are normally distributed around the forward model. + +```matlab +% First we define a helper function equivalent to calling log(normpdf(x,mu,sigma)) +% but has higher precision because it avoids truncation errors associated with calling +% log(exp(xxx)). +lognormpdf=@(x,mu,sigma)-0.5*((x-mu)./sigma).^2 -log(sqrt(2*pi).*sigma); + + +logLike=@(m)sum(lognormpdf(y,forwardmodel(t,m),m(5))); +``` + + +Prior information +---------------------------------------------------------- + +We want to restrict the model to place the kink-point within the observed time interval. All other parameters have a uniform prior. + +```matlab +logprior = @(m)(m(3)>min(t))&(m(3) + + + Fitting a line

Fitting a line

This demo follows the linefit example of EMCEE for python. See full description here: http://dan.iel.fm/emcee/current/user/line/

Contents

Generate synthetic data

First we generate some noisy data which falls on a line. We know the true parameters of the line and the parameters of the noise added to the observations.

In this surrogate data there are two sources of uncertainty. One source with known variance (yerr), and another multiplicative uncertainty with unknown variance.

% This is the true model parameters used to generate the noise
+m_true = [-0.9594;4.294;log(0.534)]
+
+N = 50;
+x = sort(10*rand(1,N));
+yerr = 0.1+0.5*rand(1,N);
+y = m_true(1)*x+m_true(2);
+y = y + abs(exp(m_true(3))*y) .* randn(1,N);
+y = y + yerr .* randn(1,N);
+
+
+close all %close all figures
+errorbar(x,y,yerr,'ks','markerfacecolor',[1 1 1]*.4,'markersize',4);
+axis tight
+
m_true =
+      -0.9594
+        4.294
+     -0.62736
+

Least squares fit

lscov can be used to fit a straight line to the data assuming that the errors in yerr are correct. Notice how this results in very optimistic uncertainties on the slope and intercept. This is because this method only accounts for the known source of error.

[m_lsq,sigma_mlsq,MSE]=lscov([x;ones(size(x))]',y',diag(yerr.^2));
+sigma_m_lsq=sigma_mlsq/sqrt(MSE); %see help on lscov
+m_lsq
+sigma_m_lsq
+
+hold on
+plot(x,polyval(m_lsq,x),'b--','linewidth',2)
+legend('Data','LSQ fit')
+
m_lsq =
+      -1.0692
+       4.4279
+sigma_m_lsq =
+     0.011028
+     0.076933
+

Likelihood

We define a likelihood function consistent with how the data was generated, and then we use fminsearch to find the max-likelihood fit of the model to the data.

% First we define a helper function equivalent to calling log(normpdf(x,mu,sigma))
+% but has higher precision because it avoids truncation errors associated with calling
+% log(exp(xxx)).
+lognormpdf=@(x,mu,sigma)-0.5*((x-mu)./sigma).^2  -log(sqrt(2*pi).*sigma);
+
+forwardmodel=@(m)m(1)*x + m(2);
+variancemodel=@(m) yerr.^2 + (forwardmodel(m)*exp(m(3))).^2;
+
+logLike=@(m)sum(lognormpdf(y,forwardmodel(m),sqrt(variancemodel(m))));
+
+m_maxlike=fminsearch(@(m)-logLike(m),[polyfit(x,y,1) 0]');
+

Prior information

Here we formulate our prior knowledge about the model parameters. Here we use flat priors within a hard limits for each of the 3 model parameters. GWMCMC allows you to specify these kinds of priors as logical expressions.

logprior =@(m) (m(1)>-5)&&(m(1)<0.5) && (m(2)>0)&&(m(2)<10) && (m(3)>-10)&&(m(3)<1) ;
+

Find the posterior distribution using GWMCMC

Now we apply the MCMC hammer to draw samples from the posterior.

% first we initialize the ensemble of walkers in a small gaussian ball
+% around the max-likelihood estimate.
+minit=bsxfun(@plus,m_maxlike,randn(3,100)*0.01);
+

Apply the hammer:

Draw samples from the posterior

tic
+m=gwmcmc(minit,{logprior logLike},100000,'ThinChain',5,'burnin',.2);
+toc
+
Elapsed time is 6.605606 seconds.
+

Auto-correlation function

figure
+[C,lags,ESS]=eacorr(m);
+plot(lags,C,'.-',lags([1 end]),[0 0],'k');
+grid on
+xlabel('lags')
+ylabel('autocorrelation');
+text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right')
+title('Markov Chain Auto Correlation')
+

Corner plot of parameters

figure
+ecornerplot(m,'ks',true,'color',[.6 .35 .3])
+

Plot of posterior fit

figure
+m=m(:,:)'; %flatten the chain
+
+%plot 100 samples...
+for kk=1:100
+    r=ceil(rand*size(m,1));
+    h=plot(x,forwardmodel(m(r,:)),'color',[.6 .35 .3].^.3);
+    hold on
+end
+h(2)=errorbar(x,y,yerr,'ks','markerfacecolor',[1 1 1]*.4,'markersize',4);
+
+h(4)=plot(x,forwardmodel(m_lsq),'b--','linewidth',2);
+h(3)=plot(x,forwardmodel(median(m)),'color',[.6 .35 .3],'linewidth',3);
+h(5)=plot(x,forwardmodel(m_true),'r','linewidth',2);
+
+axis tight
+legend(h,'Samples from posterior','Data','GWMCMC median','LSQ fit','Truth')
+
\ No newline at end of file diff --git a/mcmc_simbio/src/gwmcmc/html/ex_linefit.md b/mcmc_simbio/src/gwmcmc/html/ex_linefit.md new file mode 100755 index 0000000..07474d3 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/html/ex_linefit.md @@ -0,0 +1,182 @@ +Fitting a line +======================================= + +This demo follows the linefit example of EMCEE for python. See full description here: http://dan.iel.fm/emcee/current/user/line/ + + + +Generate synthetic data +---------------------------------------------------------- + +First we generate some noisy data which falls on a line. We know the true parameters of the line and the parameters of the noise added to the observations. + +In this surrogate data there are two sources of uncertainty. One source with known variance (yerr), and another multiplicative uncertainty with unknown variance. + +```matlab +% This is the true model parameters used to generate the noise +m_true = [-0.9594;4.294;log(0.534)] + +N = 50; +x = sort(10*rand(1,N)); +yerr = 0.1+0.5*rand(1,N); +y = m_true(1)*x+m_true(2); +y = y + abs(exp(m_true(3))*y) .* randn(1,N); +y = y + yerr .* randn(1,N); + + +close all %close all figures +errorbar(x,y,yerr,'ks','markerfacecolor',[1 1 1]*.4,'markersize',4); +axis tight +``` + +``` +m_true = + -0.9594 + 4.294 + -0.62736 + +``` + +![IMAGE](ex_linefit_01.png) + + +Least squares fit +---------------------------------------------------------- + +lscov can be used to fit a straight line to the data assuming that the errors in yerr are correct. Notice how this results in very optimistic uncertainties on the slope and intercept. This is because this method only accounts for the known source of error. + +```matlab +[m_lsq,sigma_mlsq,MSE]=lscov([x;ones(size(x))]',y',diag(yerr.^2)); +sigma_m_lsq=sigma_mlsq/sqrt(MSE); %see help on lscov +m_lsq +sigma_m_lsq + +hold on +plot(x,polyval(m_lsq,x),'b--','linewidth',2) +legend('Data','LSQ fit') +``` + +``` +m_lsq = + -1.0376 + 4.0345 +sigma_m_lsq = + 0.0095665 + 0.058728 + +``` + +![IMAGE](ex_linefit_02.png) + + +Likelihood +---------------------------------------------------------- + +We define a likelihood function consistent with how the data was generated, and then we use fminsearch to find the max-likelihood fit of the model to the data. + +```matlab +% First we define a helper function equivalent to calling log(normpdf(x,mu,sigma)) +% but has higher precision because it avoids truncation errors associated with calling +% log(exp(xxx)). +lognormpdf=@(x,mu,sigma)-0.5*((x-mu)./sigma).^2 -log(sqrt(2*pi).*sigma); + +forwardmodel=@(m)m(1)*x + m(2); +variancemodel=@(m) yerr.^2 + (forwardmodel(m)*exp(m(3))).^2; + +logLike=@(m)sum(lognormpdf(y,forwardmodel(m),sqrt(variancemodel(m)))); + +m_maxlike=fminsearch(@(m)-logLike(m),[polyfit(x,y,1) 0]'); +``` + + +Prior information +---------------------------------------------------------- + +Here we formulate our prior knowledge about the model parameters. Here we use flat priors within a hard limits for each of the 3 model parameters. GWMCMC allows you to specify these kinds of priors as logical expressions. + +```matlab +logprior =@(m) (m(1)>-5)&&(m(1)<0.5) && (m(2)>0)&&(m(2)<10) && (m(3)>-10)&&(m(3)<1) ; +``` + + +Find the posterior distribution using GWMCMC +---------------------------------------------------------- + +Now we apply the MCMC hammer to draw samples from the posterior. + +```matlab +% first we initialize the ensemble of walkers in a small gaussian ball +% around the max-likelihood estimate. +minit=bsxfun(@plus,m_maxlike,randn(3,100)*0.01); +``` + + +Apply the hammer: +---------------------------------------------------------- + +Draw samples from the posterior + +```matlab +tic +m=gwmcmc(minit,{logprior logLike},100000,'ThinChain',5,'burnin',.2); +toc +``` + +``` +Elapsed time is 6.766257 seconds. + +``` + + +Auto-correlation function +---------------------------------------------------------- + +```matlab +figure +[C,lags,ESS]=eacorr(m); +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') +``` + +![IMAGE](ex_linefit_03.png) + + +Corner plot of parameters +---------------------------------------------------------- + +```matlab +figure +ecornerplot(m,'ks',true,'color',[.6 .35 .3]) +``` + +![IMAGE](ex_linefit_04.png) + + +Plot of posterior fit +---------------------------------------------------------- + +```matlab +figure +m=m(:,:)'; %flatten the chain + +%plot 100 samples... +for kk=1:100 + r=ceil(rand*size(m,1)); + h=plot(x,forwardmodel(m(r,:)),'color',[.6 .35 .3].^.3); + hold on +end +h(2)=errorbar(x,y,yerr,'ks','markerfacecolor',[1 1 1]*.4,'markersize',4); + +h(4)=plot(x,forwardmodel(m_lsq),'b--','linewidth',2); +h(3)=plot(x,forwardmodel(median(m)),'color',[.6 .35 .3],'linewidth',3); +h(5)=plot(x,forwardmodel(m_true),'r','linewidth',2); + +axis tight +legend(h,'Samples from posterior','Data','GWMCMC median','LSQ fit','Truth') +``` + +![IMAGE](ex_linefit_05.png) diff --git a/mcmc_simbio/src/gwmcmc/html/ex_linefit_01.png b/mcmc_simbio/src/gwmcmc/html/ex_linefit_01.png new file mode 100755 index 0000000..99d70a5 Binary files /dev/null and b/mcmc_simbio/src/gwmcmc/html/ex_linefit_01.png differ diff --git a/mcmc_simbio/src/gwmcmc/html/ex_linefit_02.png b/mcmc_simbio/src/gwmcmc/html/ex_linefit_02.png new file mode 100755 index 0000000..e988fb1 Binary files /dev/null and b/mcmc_simbio/src/gwmcmc/html/ex_linefit_02.png differ diff --git a/mcmc_simbio/src/gwmcmc/html/ex_linefit_03.png b/mcmc_simbio/src/gwmcmc/html/ex_linefit_03.png new file mode 100755 index 0000000..6c7d6e5 Binary files /dev/null and b/mcmc_simbio/src/gwmcmc/html/ex_linefit_03.png differ diff --git a/mcmc_simbio/src/gwmcmc/html/ex_linefit_04.png b/mcmc_simbio/src/gwmcmc/html/ex_linefit_04.png new file mode 100755 index 0000000..42a0628 Binary files /dev/null and b/mcmc_simbio/src/gwmcmc/html/ex_linefit_04.png differ diff --git a/mcmc_simbio/src/gwmcmc/html/ex_linefit_05.png b/mcmc_simbio/src/gwmcmc/html/ex_linefit_05.png new file mode 100755 index 0000000..97f6d91 Binary files /dev/null and b/mcmc_simbio/src/gwmcmc/html/ex_linefit_05.png differ diff --git a/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana.html b/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana.html new file mode 100755 index 0000000..93a7aab --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana.html @@ -0,0 +1,168 @@ + + + + + The MCMC hammer

The MCMC hammer

GWMCMC is an implementation of the Goodman and Weare 2010 Affine invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling enables bayesian inference. The problem with many traditional MCMC samplers is that they can have slow convergence for badly scaled problems, and that it is difficult to optimize the random walk for high-dimensional problems. This is where the GW-algorithm really excels as it is affine invariant. It can achieve much better convergence on badly scaled problems. It is much simpler to get to work straight out of the box, and for that reason it truly deserves to be called the MCMC hammer.

See also: http://astrobites.org/2012/02/20/code-you-can-use-the-mcmc-hammer/

Contents

Rosenbrock: A badly scaled example

A classical difficult low dimensional problem is the rosenbrock density. It is defined by the following log-probability function:

logPfun=@(m) -(100*(m(2,:)-m(1,:).^2).^2 +(1-m(1,:)).^2)/20;
+
+%lets visualize it:
+close all
+[X,Y]=meshgrid(-4:.01:6,-1:.02:34);
+Z=logPfun([X(:) Y(:)]'); Z=reshape(Z,size(X));
+contour(X,Y,exp(Z))
+colormap(parula)
+title('The Rosenbrock banana')
+xlim([-4 6])
+ylim([-1 34])
+

Apply the MCMC hammer:

Now we apply the Goodman & Weare MCMC sampler and plot the results on top

M=2; %number of model parameters
+Nwalkers=40; %number of walkers/chains.
+minit=randn(M,Nwalkers);
+tic
+models=gwmcmc(minit, logPfun,100000,'StepSize',30,'burnin',.2);
+toc
+
+
+%flatten the chain: analyze all the chains as one
+
+models=models(:,:);
+
+%plot the results
+
+hold on
+plot(models(1,:),models(2,:),'k.')
+
+legend('Rosenbrock','GWMCMC samples','location','northwest')
+
Elapsed time is 2.228519 seconds.
+

References:

  • Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. App. Math. Comp. Sci., Vol. 5, No. 1, 65�80
  • Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665

-Aslak Grinsted 2015

\ No newline at end of file diff --git a/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana.md b/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana.md new file mode 100755 index 0000000..8985534 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana.md @@ -0,0 +1,72 @@ +The MCMC hammer +======================================= + +GWMCMC is an implementation of the Goodman and Weare 2010 Affine invariant ensemble Markov Chain Monte Carlo (MCMC) sampler. MCMC sampling enables bayesian inference. The problem with many traditional MCMC samplers is that they can have slow convergence for badly scaled problems, and that it is difficult to optimize the random walk for high-dimensional problems. This is where the GW-algorithm really excels as it is affine invariant. It can achieve much better convergence on badly scaled problems. It is much simpler to get to work straight out of the box, and for that reason it truly deserves to be called the MCMC hammer. + +See also: http://astrobites.org/2012/02/20/code-you-can-use-the-mcmc-hammer/ + + + +Rosenbrock: A badly scaled example +---------------------------------------------------------- + +A classical difficult low dimensional problem is the rosenbrock density. It is defined by the following log-probability function: + +```matlab +logPfun=@(m) -(100*(m(2,:)-m(1,:).^2).^2 +(1-m(1,:)).^2)/20; + +%lets visualize it: +close all +[X,Y]=meshgrid(-4:.01:6,-1:.02:34); +Z=logPfun([X(:) Y(:)]'); Z=reshape(Z,size(X)); +contour(X,Y,exp(Z)) +colormap(parula) +title('The Rosenbrock banana') +xlim([-4 6]) +ylim([-1 34]) +``` + +![IMAGE](ex_rosenbrockbanana_01.png) + + +Apply the MCMC hammer: +---------------------------------------------------------- + +Now we apply the Goodman & Weare MCMC sampler and plot the results on top + +```matlab +M=2; %number of model parameters +Nwalkers=40; %number of walkers/chains. +minit=randn(M,Nwalkers); +tic +models=gwmcmc(minit, logPfun,100000,'StepSize',30,'burnin',.2); +toc + + +%flatten the chain: analyze all the chains as one + +models=models(:,:); + +%plot the results + +hold on +plot(models(1,:),models(2,:),'k.') + +legend('Rosenbrock','GWMCMC samples','location','northwest') +``` + +``` +Elapsed time is 2.202490 seconds. + +``` + +![IMAGE](ex_rosenbrockbanana_02.png) + + +References: +---------------------------------------------------------- + + + Goodman & Weare (2010), Ensemble Samplers With Affine Invariance, Comm. App. Math. Comp. Sci., Vol. 5, No. 1, 65�80 + + Foreman-Mackey, Hogg, Lang, Goodman (2013), emcee: The MCMC Hammer, arXiv:1202.3665 +-Aslak Grinsted 2015 + diff --git a/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana_01.png b/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana_01.png new file mode 100755 index 0000000..cb95885 Binary files /dev/null and b/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana_01.png differ diff --git a/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana_02.png b/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana_02.png new file mode 100755 index 0000000..fdd029e Binary files /dev/null and b/mcmc_simbio/src/gwmcmc/html/ex_rosenbrockbanana_02.png differ diff --git a/mcmc_simbio/src/gwmcmc/kde2d.m b/mcmc_simbio/src/gwmcmc/kde2d.m new file mode 100644 index 0000000..d78a9e0 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/kde2d.m @@ -0,0 +1,244 @@ +function [bandwidth,density,X,Y]=kde2d(data,n,MIN_XY,MAX_XY,EffectiveSampleSize) +%% fast and accurate state-of-the-art bivariate kernel density estimator with diagonal bandwidth matrix. +% +% The kernel is assumed to be Gaussian. The two bandwidth parameters are +% chosen optimally without ever using/assuming a parametric model for the data or any "rules of thumb". +% Unlike many other procedures, this one is immune to accuracy failures in the estimation of +% multimodal densities with widely separated modes (see examples). +% +% Usage: [bandwidth,density,X,Y]=kde2d(data,n[,MIN_XY,MAX_XY,EffectiveSampleSize]) +% +% INPUTS: data - an N by 2 array with continuous data +% n - size of the n by n grid over which the density is computed +% n has to be a power of 2, otherwise n=2^ceil(log2(n)); +% the default value is 2^8; +% MIN_XY,MAX_XY- limits of the bounding box over which the density is computed; +% the format is: +% MIN_XY=[lower_Xlim,lower_Ylim] +% MAX_XY=[upper_Xlim,upper_Ylim]. +% The dafault limits are computed as: +% MAX=max(data,[],1); MIN=min(data,[],1); Range=MAX-MIN; +% MAX_XY=MAX+Range/4; MIN_XY=MIN-Range/4; +% [EffectiveSampleSize]- allows you to choose a smaller effective sample +% size than the number of points in data. +% OUTPUT: bandwidth - a row vector with the two optimal +% bandwidths for a bivaroate Gaussian kernel; +% the format is: +% bandwidth=[bandwidth_X, bandwidth_Y]; +% density - an n by n matrix containing the density values over the n by n grid; +% density is not computed unless the function is asked for such an output; +% X,Y - the meshgrid over which the variable "density" has been computed; +% the intended usage is as follows: +% surf(X,Y,density) +% Example (simple Gaussian mixture) +% clear all +% % generate a Gaussian mixture with distant modes +% data=[randn(500,2); +% randn(500,1)+3.5, randn(500,1);]; +% % call the routine +% [bandwidth,density,X,Y]=kde2d(data); +% % plot the data and the density estimate +% contour3(X,Y,density,50), hold on +% plot(data(:,1),data(:,2),'r.','MarkerSize',5) +% +% Example (Gaussian mixture with distant modes): +% +% clear all +% % generate a Gaussian mixture with distant modes +% data=[randn(100,1), randn(100,1)/4; +% randn(100,1)+18, randn(100,1); +% randn(100,1)+15, randn(100,1)/2-18;]; +% % call the routine +% [bandwidth,density,X,Y]=kde2d(data); +% % plot the data and the density estimate +% surf(X,Y,density,'LineStyle','none'), view([0,60]) +% colormap hot, hold on, alpha(.8) +% set(gca, 'color', 'blue'); +% plot(data(:,1),data(:,2),'w.','MarkerSize',5) +% +% Example (Sinusoidal density): +% +% clear all +% X=rand(1000,1); Y=sin(X*10*pi)+randn(size(X))/3; data=[X,Y]; +% % apply routine +% [bandwidth,density,X,Y]=kde2d(data); +% % plot the data and the density estimate +% surf(X,Y,density,'LineStyle','none'), view([0,70]) +% colormap hot, hold on, alpha(.8) +% set(gca, 'color', 'blue'); +% plot(data(:,1),data(:,2),'w.','MarkerSize',5) +% +% Notes: If you have a more accurate density estimator +% (as measured by which routine attains the smallest +% L_2 distance between the estimate and the true density) or you have +% problems running this code, please email me at botev@maths.uq.edu.au +% + +% +% This version has been modified by Aslak Grinsted to allow effective +% sample size adjustment to the bandwidth calculation. +% + +%LICENSE: +% Copyright (c) 2015, Dr. Zdravko Botev +% All rights reserved. +% +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are +% met: +% +% * Redistributions of source code must retain the above copyright +% notice, this list of conditions and the following disclaimer. +% * Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in +% the documentation and/or other materials provided with the distribution +% * Neither the name of the The University of New South Wales nor the names +% of its contributors may be used to endorse or promote products derived +% from this software without specific prior written permission. +% +% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +% POSSIBILITY OF SUCH DAMAGE. + +% Reference: Z. I. Botev, J. F. Grotowski and D. P. Kroese +% "KERNEL DENSITY ESTIMATION VIA DIFFUSION" ,Submitted to the +% Annals of Statistics, 2009 +if nargin<2 + n=2^8; +end +n=2^ceil(log2(n)); % round up n to the next power of 2; +N=size(data,1); +if (nargin<3), MIN_XY=[], end +if (nargin<4), MAX_XY=[], end +if isempty(MIN_XY)||isempty(MAX_XY) + MAX=max(data,[],1); MIN=min(data,[],1); Range=MAX-MIN; + if isempty(MAX_XY),MAX_XY=MAX+Range/4; end + if isempty(MIN_XY),MIN_XY=MIN-Range/4; end +end +scaling=MAX_XY-MIN_XY; +if N<=size(data,2) + error('data has to be an N by 2 array where each row represents a two dimensional observation') +end +transformed_data=(data-repmat(MIN_XY,N,1))./repmat(scaling,N,1); +if nargin>=5 + if EffectiveSampleSize>N + error('EffectiveSampleSize>size(Data,1)') + end + N=EffectiveSampleSize; +end +%bin the data uniformly using regular grid; +initial_data=ndhist(transformed_data,n); +% discrete cosine transform of initial data +a= dct2d(initial_data); +% now compute the optimal bandwidth^2 +I=(0:n-1).^2; A2=a.^2; + +t_star=fzero( @(t)(t-evolve(t)),[0,0.1]); + +p_02=func([0,2],t_star);p_20=func([2,0],t_star); p_11=func([1,1],t_star); +t_y=(p_02^(3/4)/(4*pi*N*p_20^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3); +t_x=(p_20^(3/4)/(4*pi*N*p_02^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3); +% smooth the discrete cosine transform of initial data using t_star +a_t=exp(-(0:n-1)'.^2*pi^2*t_x/2)*exp(-(0:n-1).^2*pi^2*t_y/2).*a; +% now apply the inverse discrete cosine transform +if nargout>1 + density=idct2d(a_t)*(numel(a_t)/prod(scaling)); + [X,Y]=meshgrid(MIN_XY(1):scaling(1)/(n-1):MAX_XY(1),MIN_XY(2):scaling(2)/(n-1):MAX_XY(2)); +end +bandwidth=sqrt([t_x,t_y]).*scaling; + +%####################################### + function [out,time]=evolve(t) + Sum_func = func([0,2],t) + func([2,0],t) + 2*func([1,1],t); + time=(2*pi*N*Sum_func)^(-1/3); + out=(t-time)/time; + end +%####################################### + function out=func(s,t) + if sum(s)<=4 + Sum_func=func([s(1)+1,s(2)],t)+func([s(1),s(2)+1],t); const=(1+1/2^(sum(s)+1))/3; + time=(-2*const*K(s(1))*K(s(2))/N/Sum_func)^(1/(2+sum(s))); + out=psi(s,time); + else + out=psi(s,t); + end + + end +%####################################### + function out=psi(s,Time) + % s is a vector + w=exp(-I*pi^2*Time).*[1,.5*ones(1,length(I)-1)]; + wx=w.*(I.^s(1)); + wy=w.*(I.^s(2)); + out=(-1)^sum(s)*(wy*A2*wx')*pi^(2*sum(s)); + end +%####################################### + function out=K(s) + out=(-1)^s*prod((1:2:2*s-1))/sqrt(2*pi); + end +%####################################### + function data=dct2d(data) + % computes the 2 dimensional discrete cosine transform of data + % data is an nd cube + [nrows,ncols]= size(data); + if nrows~=ncols + error('data is not a square array!') + end + % Compute weights to multiply DFT coefficients + w = [1;2*(exp(-i*(1:nrows-1)*pi/(2*nrows))).']; + weight=w(:,ones(1,ncols)); + data=dct1d(dct1d(data)')'; + function transform1d=dct1d(x) + + % Re-order the elements of the columns of x + x = [ x(1:2:end,:); x(end:-2:2,:) ]; + + % Multiply FFT by weights: + transform1d = real(weight.* fft(x)); + end + end +%####################################### + function data = idct2d(data) + % computes the 2 dimensional inverse discrete cosine transform + [nrows,ncols]=size(data); + % Compute wieghts + w = exp(i*(0:nrows-1)*pi/(2*nrows)).'; + weights=w(:,ones(1,ncols)); + data=idct1d(idct1d(data)'); + function out=idct1d(x) + y = real(ifft(weights.*x)); + out = zeros(nrows,ncols); + out(1:2:nrows,:) = y(1:nrows/2,:); + out(2:2:nrows,:) = y(nrows:-1:nrows/2+1,:); + end + end +%####################################### + function binned_data=ndhist(data,M) + % this function computes the histogram + % of an n-dimensional data set; + % 'data' is nrows by n columns + % M is the number of bins used in each dimension + % so that 'binned_data' is a hypercube with + % size length equal to M; + [nrows,ncols]=size(data); + bins=zeros(nrows,ncols); + for i=1:ncols + [dum,bins(:,i)] = histc(data(:,i),[0:1/M:1],1); + bins(:,i) = min(bins(:,i),M); + end + % Combine the vectors of 1D bin counts into a grid of nD bin + % counts. + binned_data = accumarray(bins(all(bins>0,2),:),1/nrows,M(ones(1,ncols))); + end + + + +end diff --git a/mcmc_simbio/src/gwmcmc/parseArgs.m b/mcmc_simbio/src/gwmcmc/parseArgs.m new file mode 100644 index 0000000..f43d22b --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/parseArgs.m @@ -0,0 +1,159 @@ +function ArgStruct=parseArgs(args,ArgStruct,varargin) +% Helper function for parsing varargin. +% +% +% ArgStruct=parseArgs(varargin,ArgStruct[,FlagtypeParams[,Aliases]]) +% +% * ArgStruct is the structure full of named arguments with default values. +% * Flagtype params is params that don't require a value. (the value will be set to 1 if it is present) +% * Aliases can be used to map one argument-name to several argstruct fields +% +% +% example usage: +% -------------- +% function parseargtest(varargin) +% +% %define the acceptable named arguments and assign default values +% Args=struct('Holdaxis',0, ... +% 'SpacingVertical',0.05,'SpacingHorizontal',0.05, ... +% 'PaddingLeft',0,'PaddingRight',0,'PaddingTop',0,'PaddingBottom',0, ... +% 'MarginLeft',.1,'MarginRight',.1,'MarginTop',.1,'MarginBottom',.1, ... +% 'rows',[],'cols',[]); +% +% %The capital letters define abrreviations. +% % Eg. parseargtest('spacingvertical',0) is equivalent to parseargtest('sv',0) +% +% Args=parseArgs(varargin,Args, ... % fill the arg-struct with values entered by the user +% {'Holdaxis'}, ... %this argument has no value (flag-type) +% {'Spacing' {'sh','sv'}; 'Padding' {'pl','pr','pt','pb'}; 'Margin' {'ml','mr','mt','mb'}}); +% +% disp(Args) +% +% +% +% +% Aslak Grinsted 2004 + +% ------------------------------------------------------------------------- +% Copyright (C) 2002-2004, Aslak Grinsted +% This software may be used, copied, or redistributed as long as it is not +% sold and this copyright notice is reproduced on each copy made. This +% routine is provided as is without any express or implied warranties +% whatsoever. + +persistent matlabver + +if isempty(matlabver) + matlabver=ver('MATLAB'); + matlabver=str2double(matlabver.Version); +end + +Aliases={}; +FlagTypeParams=''; + +if (length(varargin)>0) + FlagTypeParams=lower(strvcat(varargin{1})); %#ok + if length(varargin)>1 + Aliases=varargin{2}; + end +end + + +%---------------Get "numeric" arguments +NumArgCount=1; +while (NumArgCount<=size(args,2))&&(~ischar(args{NumArgCount})) + NumArgCount=NumArgCount+1; +end +NumArgCount=NumArgCount-1; +if (NumArgCount>0) + ArgStruct.NumericArguments={args{1:NumArgCount}}; +else + ArgStruct.NumericArguments={}; +end + + +%--------------Make an accepted fieldname matrix (case insensitive) +Fnames=fieldnames(ArgStruct); +for i=1:length(Fnames) + name=lower(Fnames{i,1}); + Fnames{i,2}=name; %col2=lower + Fnames{i,3}=[name(Fnames{i,1}~=name) ' ']; %col3=abreviation letters (those that are uppercase in the ArgStruct) e.g. SpacingHoriz->sh + %the space prevents strvcat from removing empty lines + Fnames{i,4}=isempty(strmatch(Fnames{i,2},FlagTypeParams)); %Does this parameter have a value? +end +FnamesFull=strvcat(Fnames{:,2}); %#ok +FnamesAbbr=strvcat(Fnames{:,3}); %#ok + +if length(Aliases)>0 + for i=1:length(Aliases) + name=lower(Aliases{i,1}); + FieldIdx=strmatch(name,FnamesAbbr,'exact'); %try abbreviations (must be exact) + if isempty(FieldIdx) + FieldIdx=strmatch(name,FnamesFull); %&??????? exact or not? + end + Aliases{i,2}=FieldIdx; + Aliases{i,3}=[name(Aliases{i,1}~=name) ' ']; %the space prevents strvcat from removing empty lines + Aliases{i,1}=name; %dont need the name in uppercase anymore for aliases + end + %Append aliases to the end of FnamesFull and FnamesAbbr + FnamesFull=strvcat(FnamesFull,strvcat(Aliases{:,1})); %#ok + FnamesAbbr=strvcat(FnamesAbbr,strvcat(Aliases{:,3})); %#ok +end + +%--------------get parameters-------------------- +l=NumArgCount+1; +while (l<=length(args)) + a=args{l}; + if ischar(a) + paramHasValue=1; % assume that the parameter has is of type 'param',value + a=lower(a); + FieldIdx=strmatch(a,FnamesAbbr,'exact'); %try abbreviations (must be exact) + if isempty(FieldIdx) + FieldIdx=strmatch(a,FnamesFull); + end + if (length(FieldIdx)>1) %shortest fieldname should win + [mx,mxi]=max(sum(FnamesFull(FieldIdx,:)==' ',2));%#ok + FieldIdx=FieldIdx(mxi); + end + if FieldIdx>length(Fnames) %then it's an alias type. + FieldIdx=Aliases{FieldIdx-length(Fnames),2}; + end + + if isempty(FieldIdx) + error(['Unknown named parameter: ' a]) + end + for curField=FieldIdx' %if it is an alias it could be more than one. + if (Fnames{curField,4}) + if (l+1>length(args)) + error(['Expected a value for parameter: ' Fnames{curField,1}]) + end + val=args{l+1}; + else %FLAG PARAMETER + if (l=6 + ArgStruct.(Fnames{curField,1})=val; %try the line below if you get an error here + else + ArgStruct=setfield(ArgStruct,Fnames{curField,1},val); %#ok <-works in old matlab versions + end + end + l=l+1+paramHasValue; %if a wildcard matches more than one + else + error(['Expected a named parameter: ' num2str(a)]) + end +end \ No newline at end of file diff --git a/mcmc_simbio/src/gwmcmc/private/kde2d.m b/mcmc_simbio/src/gwmcmc/private/kde2d.m new file mode 100755 index 0000000..d78a9e0 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/private/kde2d.m @@ -0,0 +1,244 @@ +function [bandwidth,density,X,Y]=kde2d(data,n,MIN_XY,MAX_XY,EffectiveSampleSize) +%% fast and accurate state-of-the-art bivariate kernel density estimator with diagonal bandwidth matrix. +% +% The kernel is assumed to be Gaussian. The two bandwidth parameters are +% chosen optimally without ever using/assuming a parametric model for the data or any "rules of thumb". +% Unlike many other procedures, this one is immune to accuracy failures in the estimation of +% multimodal densities with widely separated modes (see examples). +% +% Usage: [bandwidth,density,X,Y]=kde2d(data,n[,MIN_XY,MAX_XY,EffectiveSampleSize]) +% +% INPUTS: data - an N by 2 array with continuous data +% n - size of the n by n grid over which the density is computed +% n has to be a power of 2, otherwise n=2^ceil(log2(n)); +% the default value is 2^8; +% MIN_XY,MAX_XY- limits of the bounding box over which the density is computed; +% the format is: +% MIN_XY=[lower_Xlim,lower_Ylim] +% MAX_XY=[upper_Xlim,upper_Ylim]. +% The dafault limits are computed as: +% MAX=max(data,[],1); MIN=min(data,[],1); Range=MAX-MIN; +% MAX_XY=MAX+Range/4; MIN_XY=MIN-Range/4; +% [EffectiveSampleSize]- allows you to choose a smaller effective sample +% size than the number of points in data. +% OUTPUT: bandwidth - a row vector with the two optimal +% bandwidths for a bivaroate Gaussian kernel; +% the format is: +% bandwidth=[bandwidth_X, bandwidth_Y]; +% density - an n by n matrix containing the density values over the n by n grid; +% density is not computed unless the function is asked for such an output; +% X,Y - the meshgrid over which the variable "density" has been computed; +% the intended usage is as follows: +% surf(X,Y,density) +% Example (simple Gaussian mixture) +% clear all +% % generate a Gaussian mixture with distant modes +% data=[randn(500,2); +% randn(500,1)+3.5, randn(500,1);]; +% % call the routine +% [bandwidth,density,X,Y]=kde2d(data); +% % plot the data and the density estimate +% contour3(X,Y,density,50), hold on +% plot(data(:,1),data(:,2),'r.','MarkerSize',5) +% +% Example (Gaussian mixture with distant modes): +% +% clear all +% % generate a Gaussian mixture with distant modes +% data=[randn(100,1), randn(100,1)/4; +% randn(100,1)+18, randn(100,1); +% randn(100,1)+15, randn(100,1)/2-18;]; +% % call the routine +% [bandwidth,density,X,Y]=kde2d(data); +% % plot the data and the density estimate +% surf(X,Y,density,'LineStyle','none'), view([0,60]) +% colormap hot, hold on, alpha(.8) +% set(gca, 'color', 'blue'); +% plot(data(:,1),data(:,2),'w.','MarkerSize',5) +% +% Example (Sinusoidal density): +% +% clear all +% X=rand(1000,1); Y=sin(X*10*pi)+randn(size(X))/3; data=[X,Y]; +% % apply routine +% [bandwidth,density,X,Y]=kde2d(data); +% % plot the data and the density estimate +% surf(X,Y,density,'LineStyle','none'), view([0,70]) +% colormap hot, hold on, alpha(.8) +% set(gca, 'color', 'blue'); +% plot(data(:,1),data(:,2),'w.','MarkerSize',5) +% +% Notes: If you have a more accurate density estimator +% (as measured by which routine attains the smallest +% L_2 distance between the estimate and the true density) or you have +% problems running this code, please email me at botev@maths.uq.edu.au +% + +% +% This version has been modified by Aslak Grinsted to allow effective +% sample size adjustment to the bandwidth calculation. +% + +%LICENSE: +% Copyright (c) 2015, Dr. Zdravko Botev +% All rights reserved. +% +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are +% met: +% +% * Redistributions of source code must retain the above copyright +% notice, this list of conditions and the following disclaimer. +% * Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in +% the documentation and/or other materials provided with the distribution +% * Neither the name of the The University of New South Wales nor the names +% of its contributors may be used to endorse or promote products derived +% from this software without specific prior written permission. +% +% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +% POSSIBILITY OF SUCH DAMAGE. + +% Reference: Z. I. Botev, J. F. Grotowski and D. P. Kroese +% "KERNEL DENSITY ESTIMATION VIA DIFFUSION" ,Submitted to the +% Annals of Statistics, 2009 +if nargin<2 + n=2^8; +end +n=2^ceil(log2(n)); % round up n to the next power of 2; +N=size(data,1); +if (nargin<3), MIN_XY=[], end +if (nargin<4), MAX_XY=[], end +if isempty(MIN_XY)||isempty(MAX_XY) + MAX=max(data,[],1); MIN=min(data,[],1); Range=MAX-MIN; + if isempty(MAX_XY),MAX_XY=MAX+Range/4; end + if isempty(MIN_XY),MIN_XY=MIN-Range/4; end +end +scaling=MAX_XY-MIN_XY; +if N<=size(data,2) + error('data has to be an N by 2 array where each row represents a two dimensional observation') +end +transformed_data=(data-repmat(MIN_XY,N,1))./repmat(scaling,N,1); +if nargin>=5 + if EffectiveSampleSize>N + error('EffectiveSampleSize>size(Data,1)') + end + N=EffectiveSampleSize; +end +%bin the data uniformly using regular grid; +initial_data=ndhist(transformed_data,n); +% discrete cosine transform of initial data +a= dct2d(initial_data); +% now compute the optimal bandwidth^2 +I=(0:n-1).^2; A2=a.^2; + +t_star=fzero( @(t)(t-evolve(t)),[0,0.1]); + +p_02=func([0,2],t_star);p_20=func([2,0],t_star); p_11=func([1,1],t_star); +t_y=(p_02^(3/4)/(4*pi*N*p_20^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3); +t_x=(p_20^(3/4)/(4*pi*N*p_02^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3); +% smooth the discrete cosine transform of initial data using t_star +a_t=exp(-(0:n-1)'.^2*pi^2*t_x/2)*exp(-(0:n-1).^2*pi^2*t_y/2).*a; +% now apply the inverse discrete cosine transform +if nargout>1 + density=idct2d(a_t)*(numel(a_t)/prod(scaling)); + [X,Y]=meshgrid(MIN_XY(1):scaling(1)/(n-1):MAX_XY(1),MIN_XY(2):scaling(2)/(n-1):MAX_XY(2)); +end +bandwidth=sqrt([t_x,t_y]).*scaling; + +%####################################### + function [out,time]=evolve(t) + Sum_func = func([0,2],t) + func([2,0],t) + 2*func([1,1],t); + time=(2*pi*N*Sum_func)^(-1/3); + out=(t-time)/time; + end +%####################################### + function out=func(s,t) + if sum(s)<=4 + Sum_func=func([s(1)+1,s(2)],t)+func([s(1),s(2)+1],t); const=(1+1/2^(sum(s)+1))/3; + time=(-2*const*K(s(1))*K(s(2))/N/Sum_func)^(1/(2+sum(s))); + out=psi(s,time); + else + out=psi(s,t); + end + + end +%####################################### + function out=psi(s,Time) + % s is a vector + w=exp(-I*pi^2*Time).*[1,.5*ones(1,length(I)-1)]; + wx=w.*(I.^s(1)); + wy=w.*(I.^s(2)); + out=(-1)^sum(s)*(wy*A2*wx')*pi^(2*sum(s)); + end +%####################################### + function out=K(s) + out=(-1)^s*prod((1:2:2*s-1))/sqrt(2*pi); + end +%####################################### + function data=dct2d(data) + % computes the 2 dimensional discrete cosine transform of data + % data is an nd cube + [nrows,ncols]= size(data); + if nrows~=ncols + error('data is not a square array!') + end + % Compute weights to multiply DFT coefficients + w = [1;2*(exp(-i*(1:nrows-1)*pi/(2*nrows))).']; + weight=w(:,ones(1,ncols)); + data=dct1d(dct1d(data)')'; + function transform1d=dct1d(x) + + % Re-order the elements of the columns of x + x = [ x(1:2:end,:); x(end:-2:2,:) ]; + + % Multiply FFT by weights: + transform1d = real(weight.* fft(x)); + end + end +%####################################### + function data = idct2d(data) + % computes the 2 dimensional inverse discrete cosine transform + [nrows,ncols]=size(data); + % Compute wieghts + w = exp(i*(0:nrows-1)*pi/(2*nrows)).'; + weights=w(:,ones(1,ncols)); + data=idct1d(idct1d(data)'); + function out=idct1d(x) + y = real(ifft(weights.*x)); + out = zeros(nrows,ncols); + out(1:2:nrows,:) = y(1:nrows/2,:); + out(2:2:nrows,:) = y(nrows:-1:nrows/2+1,:); + end + end +%####################################### + function binned_data=ndhist(data,M) + % this function computes the histogram + % of an n-dimensional data set; + % 'data' is nrows by n columns + % M is the number of bins used in each dimension + % so that 'binned_data' is a hypercube with + % size length equal to M; + [nrows,ncols]=size(data); + bins=zeros(nrows,ncols); + for i=1:ncols + [dum,bins(:,i)] = histc(data(:,i),[0:1/M:1],1); + bins(:,i) = min(bins(:,i),M); + end + % Combine the vectors of 1D bin counts into a grid of nD bin + % counts. + binned_data = accumarray(bins(all(bins>0,2),:),1/nrows,M(ones(1,ncols))); + end + + + +end diff --git a/mcmc_simbio/src/gwmcmc/private/mxdom2md.xsl b/mcmc_simbio/src/gwmcmc/private/mxdom2md.xsl new file mode 100755 index 0000000..944ecfe --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/private/mxdom2md.xsl @@ -0,0 +1,252 @@ + + + + + ]> + + + + + + + + + +======================================= + + + + + + + + + + + + + + + +========================================================== + + + +---------------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + + + + +** + + + + + + + + + + + +Contents +------------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +`````` + + +```matlab + +``` + + + +**** +`` +** + + + + + + + + + + + + + + + + + + + + + +```matlab + +``` + + + + + + + + + +``` + +``` + + + + + + + + +![IMAGE]() + + + + +```matlab``` + + + + + + + + + + + + + + + + + + + + + + + *\* + #\% + /\# + <\< + >\> + [\[ + ]\] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mcmc_simbio/src/gwmcmc/private/parseArgs.m b/mcmc_simbio/src/gwmcmc/private/parseArgs.m new file mode 100755 index 0000000..f43d22b --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/private/parseArgs.m @@ -0,0 +1,159 @@ +function ArgStruct=parseArgs(args,ArgStruct,varargin) +% Helper function for parsing varargin. +% +% +% ArgStruct=parseArgs(varargin,ArgStruct[,FlagtypeParams[,Aliases]]) +% +% * ArgStruct is the structure full of named arguments with default values. +% * Flagtype params is params that don't require a value. (the value will be set to 1 if it is present) +% * Aliases can be used to map one argument-name to several argstruct fields +% +% +% example usage: +% -------------- +% function parseargtest(varargin) +% +% %define the acceptable named arguments and assign default values +% Args=struct('Holdaxis',0, ... +% 'SpacingVertical',0.05,'SpacingHorizontal',0.05, ... +% 'PaddingLeft',0,'PaddingRight',0,'PaddingTop',0,'PaddingBottom',0, ... +% 'MarginLeft',.1,'MarginRight',.1,'MarginTop',.1,'MarginBottom',.1, ... +% 'rows',[],'cols',[]); +% +% %The capital letters define abrreviations. +% % Eg. parseargtest('spacingvertical',0) is equivalent to parseargtest('sv',0) +% +% Args=parseArgs(varargin,Args, ... % fill the arg-struct with values entered by the user +% {'Holdaxis'}, ... %this argument has no value (flag-type) +% {'Spacing' {'sh','sv'}; 'Padding' {'pl','pr','pt','pb'}; 'Margin' {'ml','mr','mt','mb'}}); +% +% disp(Args) +% +% +% +% +% Aslak Grinsted 2004 + +% ------------------------------------------------------------------------- +% Copyright (C) 2002-2004, Aslak Grinsted +% This software may be used, copied, or redistributed as long as it is not +% sold and this copyright notice is reproduced on each copy made. This +% routine is provided as is without any express or implied warranties +% whatsoever. + +persistent matlabver + +if isempty(matlabver) + matlabver=ver('MATLAB'); + matlabver=str2double(matlabver.Version); +end + +Aliases={}; +FlagTypeParams=''; + +if (length(varargin)>0) + FlagTypeParams=lower(strvcat(varargin{1})); %#ok + if length(varargin)>1 + Aliases=varargin{2}; + end +end + + +%---------------Get "numeric" arguments +NumArgCount=1; +while (NumArgCount<=size(args,2))&&(~ischar(args{NumArgCount})) + NumArgCount=NumArgCount+1; +end +NumArgCount=NumArgCount-1; +if (NumArgCount>0) + ArgStruct.NumericArguments={args{1:NumArgCount}}; +else + ArgStruct.NumericArguments={}; +end + + +%--------------Make an accepted fieldname matrix (case insensitive) +Fnames=fieldnames(ArgStruct); +for i=1:length(Fnames) + name=lower(Fnames{i,1}); + Fnames{i,2}=name; %col2=lower + Fnames{i,3}=[name(Fnames{i,1}~=name) ' ']; %col3=abreviation letters (those that are uppercase in the ArgStruct) e.g. SpacingHoriz->sh + %the space prevents strvcat from removing empty lines + Fnames{i,4}=isempty(strmatch(Fnames{i,2},FlagTypeParams)); %Does this parameter have a value? +end +FnamesFull=strvcat(Fnames{:,2}); %#ok +FnamesAbbr=strvcat(Fnames{:,3}); %#ok + +if length(Aliases)>0 + for i=1:length(Aliases) + name=lower(Aliases{i,1}); + FieldIdx=strmatch(name,FnamesAbbr,'exact'); %try abbreviations (must be exact) + if isempty(FieldIdx) + FieldIdx=strmatch(name,FnamesFull); %&??????? exact or not? + end + Aliases{i,2}=FieldIdx; + Aliases{i,3}=[name(Aliases{i,1}~=name) ' ']; %the space prevents strvcat from removing empty lines + Aliases{i,1}=name; %dont need the name in uppercase anymore for aliases + end + %Append aliases to the end of FnamesFull and FnamesAbbr + FnamesFull=strvcat(FnamesFull,strvcat(Aliases{:,1})); %#ok + FnamesAbbr=strvcat(FnamesAbbr,strvcat(Aliases{:,3})); %#ok +end + +%--------------get parameters-------------------- +l=NumArgCount+1; +while (l<=length(args)) + a=args{l}; + if ischar(a) + paramHasValue=1; % assume that the parameter has is of type 'param',value + a=lower(a); + FieldIdx=strmatch(a,FnamesAbbr,'exact'); %try abbreviations (must be exact) + if isempty(FieldIdx) + FieldIdx=strmatch(a,FnamesFull); + end + if (length(FieldIdx)>1) %shortest fieldname should win + [mx,mxi]=max(sum(FnamesFull(FieldIdx,:)==' ',2));%#ok + FieldIdx=FieldIdx(mxi); + end + if FieldIdx>length(Fnames) %then it's an alias type. + FieldIdx=Aliases{FieldIdx-length(Fnames),2}; + end + + if isempty(FieldIdx) + error(['Unknown named parameter: ' a]) + end + for curField=FieldIdx' %if it is an alias it could be more than one. + if (Fnames{curField,4}) + if (l+1>length(args)) + error(['Expected a value for parameter: ' Fnames{curField,1}]) + end + val=args{l+1}; + else %FLAG PARAMETER + if (l=6 + ArgStruct.(Fnames{curField,1})=val; %try the line below if you get an error here + else + ArgStruct=setfield(ArgStruct,Fnames{curField,1},val); %#ok <-works in old matlab versions + end + end + l=l+1+paramHasValue; %if a wildcard matches more than one + else + error(['Expected a named parameter: ' num2str(a)]) + end +end \ No newline at end of file diff --git a/mcmc_simbio/src/gwmcmc/private/publishexamples.m b/mcmc_simbio/src/gwmcmc/private/publishexamples.m new file mode 100755 index 0000000..ce49793 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/private/publishexamples.m @@ -0,0 +1,83 @@ +%%publish examples. +% +% This code publishes the examples to the html folder. +% +function publishexamples + + +font='Rockwell'; +set(0,'defaultUicontrolFontName',font); +set(0,'defaultUitableFontName',font); +set(0,'defaultAxesFontName',font); +set(0,'defaultTextFontName',font); +set(0,'defaultUipanelFontName',font); +set(0,'defaultFigureColor',[1 1 1]); +set(0,'defaultAxesColor',[1 1 1]*.97); +set(0,'defaultaxesxcolor',[1 1 1]*.4); +set(0,'defaultaxesycolor',[1 1 1]*.4); +set(0, 'defaulttextcolor',[1 1 1]*.4); +set(0,'defaultaxesbox','off'); +set(0,'defaultlegendbox','off'); +set(0,'defaultaxestickdir','out','defaultAxesTickDirMode', 'manual'); +set(0,'defaultfigureinverthardcopy','off'); +set(0,'defaultfigurecolormap', hslcolormap('yr',[0 .7 .9],[.98 .2])); + +% reset random number generator... +s = RandStream('mt19937ar','Seed',0); +RandStream.setGlobalStream(s); + + + +% publishfile('..\ex_linefit','html') +% publishfile('..\ex_rosenbrockbanana','html') +% publishfile('..\ex_behappy','html') +publishfile('..\ex_breakfit','html') + +% publishfile('..\ex_linefit','markdown') +% publishfile('..\ex_rosenbrockbanana','markdown') +% publishfile('..\ex_behappy','markdown') +publishfile('..\ex_breakfit','markdown') + + + + +function publishfile(fname,outputformat) + +options=[]; +options.format= 'html'; % 'html' | 'doc' | 'pdf' | 'ppt' | 'xml' | 'latex' +%options.stylesheet= 'C:\Users\Aslak\Documents\MATLAB\gwmcmc\repoexclude\robotoslab.xsl'; % '' | an XSL filename (ignored when format = 'doc', 'pdf', or 'ppt') +options.outputDir= 'html'; +options.imageFormat= 'png'; % '' (default based on format) 'bmp' | 'eps' | 'epsc' | 'jpeg' | 'meta' | 'png' | 'ps' | 'psc' | 'tiff' +options.figureSnapMethod= 'print'; % 'entireGUIWindow'| 'print' | 'getframe' | 'entireFigureWindow' +options.useNewFigure= true; % true | false +options.showCode= true; % true | false +options.evalCode= true; % true | false +options.catchError= true; % true | false +options.createThumbnail= false; % true | false +options.maxOutputLines= inf; % Inf | non-negative integer + +switch outputformat + case 'markdown',markdown=true; + otherwise, markdown=false; +end + +if markdown + privatepath=fileparts(mfilename('fullpath')); + options.stylesheet= fullfile(privatepath,'mxdom2md.xsl'); + options.format= 'latex'; +end + +[examplepath,name]=fileparts(fname); +oldpath=pwd; +try + cd(examplepath) + publish(name,options); + if markdown + target=fullfile(options.outputDir,name); + movefile([target '.tex'],[target '.md']); + end +catch ME + cd(oldpath) + rethrow(ME) +end +cd(oldpath) diff --git a/mcmc_simbio/src/gwmcmc/private/subaxis.m b/mcmc_simbio/src/gwmcmc/private/subaxis.m new file mode 100755 index 0000000..fb1476f --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/private/subaxis.m @@ -0,0 +1,106 @@ +function h=subaxis(varargin) +%SUBAXIS Create axes in tiled positions. (just like subplot) +% Usage: +% h=subaxis(rows,cols,cellno[,settings]) +% h=subaxis(rows,cols,cellx,celly[,settings]) +% h=subaxis(rows,cols,cellx,celly,spanx,spany[,settings]) +% +% SETTINGS: Spacing,SpacingHoriz,SpacingVert +% Padding,PaddingRight,PaddingLeft,PaddingTop,PaddingBottom +% Margin,MarginRight,MarginLeft,MarginTop,MarginBottom +% Holdaxis +% +% all units are relative (i.e. from 0 to 1) +% +% Abbreviations of parameters can be used.. (Eg MR instead of MarginRight) +% (holdaxis means that it wont delete any axes below.) +% +% +% Example: +% +% >> subaxis(2,1,1,'SpacingVert',0,'MR',0); +% >> imagesc(magic(3)) +% >> subaxis(2,'p',.02); +% >> imagesc(magic(4)) +% +% 2001-2014 / Aslak Grinsted (Feel free to modify this code.) + +f=gcf; + + + +UserDataArgsOK=0; +Args=get(f,'UserData'); +if isstruct(Args) + UserDataArgsOK=isfield(Args,'SpacingHorizontal')&isfield(Args,'Holdaxis')&isfield(Args,'rows')&isfield(Args,'cols'); +end +OKToStoreArgs=isempty(Args)|UserDataArgsOK; + +if isempty(Args)&&(~UserDataArgsOK) + Args=struct('Holdaxis',0, ... + 'SpacingVertical',0.05,'SpacingHorizontal',0.05, ... + 'PaddingLeft',0,'PaddingRight',0,'PaddingTop',0,'PaddingBottom',0, ... + 'MarginLeft',.1,'MarginRight',.1,'MarginTop',.1,'MarginBottom',.1, ... + 'rows',[],'cols',[]); +end +Args=parseArgs(varargin,Args,{'Holdaxis'},{'Spacing' {'sh','sv'}; 'Padding' {'pl','pr','pt','pb'}; 'Margin' {'ml','mr','mt','mb'}}); + +if (length(Args.NumericArguments)>2) + Args.rows=Args.NumericArguments{1}; + Args.cols=Args.NumericArguments{2}; +%remove these 2 numerical arguments + Args.NumericArguments={Args.NumericArguments{3:end}}; +end + +if OKToStoreArgs + set(f,'UserData',Args); +end + + +switch length(Args.NumericArguments) + case 0 + return % no arguments but rows/cols.... + case 1 + if numel(Args.NumericArguments{1}) > 1 % restore subplot(m,n,[x y]) behaviour + [x1 y1] = ind2sub([Args.cols Args.rows],Args.NumericArguments{1}(1)); % subplot and ind2sub count differently (column instead of row first) --> switch cols/rows + [x2 y2] = ind2sub([Args.cols Args.rows],Args.NumericArguments{1}(end)); + else + x1=mod((Args.NumericArguments{1}-1),Args.cols)+1; x2=x1; + y1=floor((Args.NumericArguments{1}-1)/Args.cols)+1; y2=y1; + end +% x1=mod((Args.NumericArguments{1}-1),Args.cols)+1; x2=x1; +% y1=floor((Args.NumericArguments{1}-1)/Args.cols)+1; y2=y1; + case 2 + x1=Args.NumericArguments{1};x2=x1; + y1=Args.NumericArguments{2};y2=y1; + case 4 + x1=Args.NumericArguments{1};x2=x1+Args.NumericArguments{3}-1; + y1=Args.NumericArguments{2};y2=y1+Args.NumericArguments{4}-1; + otherwise + error('subaxis argument error') +end + + +cellwidth=((1-Args.MarginLeft-Args.MarginRight)-(Args.cols-1)*Args.SpacingHorizontal)/Args.cols; +cellheight=((1-Args.MarginTop-Args.MarginBottom)-(Args.rows-1)*Args.SpacingVertical)/Args.rows; +xpos1=Args.MarginLeft+Args.PaddingLeft+cellwidth*(x1-1)+Args.SpacingHorizontal*(x1-1); +xpos2=Args.MarginLeft-Args.PaddingRight+cellwidth*x2+Args.SpacingHorizontal*(x2-1); +ypos1=Args.MarginTop+Args.PaddingTop+cellheight*(y1-1)+Args.SpacingVertical*(y1-1); +ypos2=Args.MarginTop-Args.PaddingBottom+cellheight*y2+Args.SpacingVertical*(y2-1); + +if Args.Holdaxis + h=axes('position',[xpos1 1-ypos2 xpos2-xpos1 ypos2-ypos1]); +else + h=subplot('position',[xpos1 1-ypos2 xpos2-xpos1 ypos2-ypos1]); +end + + +set(h,'box','on'); +%h=axes('position',[x1 1-y2 x2-x1 y2-y1]); +set(h,'units',get(gcf,'defaultaxesunits')); +set(h,'tag','subaxis'); + + + +if (nargout==0), clear h; end; + diff --git a/mcmc_simbio/src/gwmcmc/publishexamples.m b/mcmc_simbio/src/gwmcmc/publishexamples.m new file mode 100644 index 0000000..ce49793 --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/publishexamples.m @@ -0,0 +1,83 @@ +%%publish examples. +% +% This code publishes the examples to the html folder. +% +function publishexamples + + +font='Rockwell'; +set(0,'defaultUicontrolFontName',font); +set(0,'defaultUitableFontName',font); +set(0,'defaultAxesFontName',font); +set(0,'defaultTextFontName',font); +set(0,'defaultUipanelFontName',font); +set(0,'defaultFigureColor',[1 1 1]); +set(0,'defaultAxesColor',[1 1 1]*.97); +set(0,'defaultaxesxcolor',[1 1 1]*.4); +set(0,'defaultaxesycolor',[1 1 1]*.4); +set(0, 'defaulttextcolor',[1 1 1]*.4); +set(0,'defaultaxesbox','off'); +set(0,'defaultlegendbox','off'); +set(0,'defaultaxestickdir','out','defaultAxesTickDirMode', 'manual'); +set(0,'defaultfigureinverthardcopy','off'); +set(0,'defaultfigurecolormap', hslcolormap('yr',[0 .7 .9],[.98 .2])); + +% reset random number generator... +s = RandStream('mt19937ar','Seed',0); +RandStream.setGlobalStream(s); + + + +% publishfile('..\ex_linefit','html') +% publishfile('..\ex_rosenbrockbanana','html') +% publishfile('..\ex_behappy','html') +publishfile('..\ex_breakfit','html') + +% publishfile('..\ex_linefit','markdown') +% publishfile('..\ex_rosenbrockbanana','markdown') +% publishfile('..\ex_behappy','markdown') +publishfile('..\ex_breakfit','markdown') + + + + +function publishfile(fname,outputformat) + +options=[]; +options.format= 'html'; % 'html' | 'doc' | 'pdf' | 'ppt' | 'xml' | 'latex' +%options.stylesheet= 'C:\Users\Aslak\Documents\MATLAB\gwmcmc\repoexclude\robotoslab.xsl'; % '' | an XSL filename (ignored when format = 'doc', 'pdf', or 'ppt') +options.outputDir= 'html'; +options.imageFormat= 'png'; % '' (default based on format) 'bmp' | 'eps' | 'epsc' | 'jpeg' | 'meta' | 'png' | 'ps' | 'psc' | 'tiff' +options.figureSnapMethod= 'print'; % 'entireGUIWindow'| 'print' | 'getframe' | 'entireFigureWindow' +options.useNewFigure= true; % true | false +options.showCode= true; % true | false +options.evalCode= true; % true | false +options.catchError= true; % true | false +options.createThumbnail= false; % true | false +options.maxOutputLines= inf; % Inf | non-negative integer + +switch outputformat + case 'markdown',markdown=true; + otherwise, markdown=false; +end + +if markdown + privatepath=fileparts(mfilename('fullpath')); + options.stylesheet= fullfile(privatepath,'mxdom2md.xsl'); + options.format= 'latex'; +end + +[examplepath,name]=fileparts(fname); +oldpath=pwd; +try + cd(examplepath) + publish(name,options); + if markdown + target=fullfile(options.outputDir,name); + movefile([target '.tex'],[target '.md']); + end +catch ME + cd(oldpath) + rethrow(ME) +end +cd(oldpath) diff --git a/mcmc_simbio/src/gwmcmc/subaxis.m b/mcmc_simbio/src/gwmcmc/subaxis.m new file mode 100644 index 0000000..fb1476f --- /dev/null +++ b/mcmc_simbio/src/gwmcmc/subaxis.m @@ -0,0 +1,106 @@ +function h=subaxis(varargin) +%SUBAXIS Create axes in tiled positions. (just like subplot) +% Usage: +% h=subaxis(rows,cols,cellno[,settings]) +% h=subaxis(rows,cols,cellx,celly[,settings]) +% h=subaxis(rows,cols,cellx,celly,spanx,spany[,settings]) +% +% SETTINGS: Spacing,SpacingHoriz,SpacingVert +% Padding,PaddingRight,PaddingLeft,PaddingTop,PaddingBottom +% Margin,MarginRight,MarginLeft,MarginTop,MarginBottom +% Holdaxis +% +% all units are relative (i.e. from 0 to 1) +% +% Abbreviations of parameters can be used.. (Eg MR instead of MarginRight) +% (holdaxis means that it wont delete any axes below.) +% +% +% Example: +% +% >> subaxis(2,1,1,'SpacingVert',0,'MR',0); +% >> imagesc(magic(3)) +% >> subaxis(2,'p',.02); +% >> imagesc(magic(4)) +% +% 2001-2014 / Aslak Grinsted (Feel free to modify this code.) + +f=gcf; + + + +UserDataArgsOK=0; +Args=get(f,'UserData'); +if isstruct(Args) + UserDataArgsOK=isfield(Args,'SpacingHorizontal')&isfield(Args,'Holdaxis')&isfield(Args,'rows')&isfield(Args,'cols'); +end +OKToStoreArgs=isempty(Args)|UserDataArgsOK; + +if isempty(Args)&&(~UserDataArgsOK) + Args=struct('Holdaxis',0, ... + 'SpacingVertical',0.05,'SpacingHorizontal',0.05, ... + 'PaddingLeft',0,'PaddingRight',0,'PaddingTop',0,'PaddingBottom',0, ... + 'MarginLeft',.1,'MarginRight',.1,'MarginTop',.1,'MarginBottom',.1, ... + 'rows',[],'cols',[]); +end +Args=parseArgs(varargin,Args,{'Holdaxis'},{'Spacing' {'sh','sv'}; 'Padding' {'pl','pr','pt','pb'}; 'Margin' {'ml','mr','mt','mb'}}); + +if (length(Args.NumericArguments)>2) + Args.rows=Args.NumericArguments{1}; + Args.cols=Args.NumericArguments{2}; +%remove these 2 numerical arguments + Args.NumericArguments={Args.NumericArguments{3:end}}; +end + +if OKToStoreArgs + set(f,'UserData',Args); +end + + +switch length(Args.NumericArguments) + case 0 + return % no arguments but rows/cols.... + case 1 + if numel(Args.NumericArguments{1}) > 1 % restore subplot(m,n,[x y]) behaviour + [x1 y1] = ind2sub([Args.cols Args.rows],Args.NumericArguments{1}(1)); % subplot and ind2sub count differently (column instead of row first) --> switch cols/rows + [x2 y2] = ind2sub([Args.cols Args.rows],Args.NumericArguments{1}(end)); + else + x1=mod((Args.NumericArguments{1}-1),Args.cols)+1; x2=x1; + y1=floor((Args.NumericArguments{1}-1)/Args.cols)+1; y2=y1; + end +% x1=mod((Args.NumericArguments{1}-1),Args.cols)+1; x2=x1; +% y1=floor((Args.NumericArguments{1}-1)/Args.cols)+1; y2=y1; + case 2 + x1=Args.NumericArguments{1};x2=x1; + y1=Args.NumericArguments{2};y2=y1; + case 4 + x1=Args.NumericArguments{1};x2=x1+Args.NumericArguments{3}-1; + y1=Args.NumericArguments{2};y2=y1+Args.NumericArguments{4}-1; + otherwise + error('subaxis argument error') +end + + +cellwidth=((1-Args.MarginLeft-Args.MarginRight)-(Args.cols-1)*Args.SpacingHorizontal)/Args.cols; +cellheight=((1-Args.MarginTop-Args.MarginBottom)-(Args.rows-1)*Args.SpacingVertical)/Args.rows; +xpos1=Args.MarginLeft+Args.PaddingLeft+cellwidth*(x1-1)+Args.SpacingHorizontal*(x1-1); +xpos2=Args.MarginLeft-Args.PaddingRight+cellwidth*x2+Args.SpacingHorizontal*(x2-1); +ypos1=Args.MarginTop+Args.PaddingTop+cellheight*(y1-1)+Args.SpacingVertical*(y1-1); +ypos2=Args.MarginTop-Args.PaddingBottom+cellheight*y2+Args.SpacingVertical*(y2-1); + +if Args.Holdaxis + h=axes('position',[xpos1 1-ypos2 xpos2-xpos1 ypos2-ypos1]); +else + h=subplot('position',[xpos1 1-ypos2 xpos2-xpos1 ypos2-ypos1]); +end + + +set(h,'box','on'); +%h=axes('position',[x1 1-y2 x2-x1 y2-y1]); +set(h,'units',get(gcf,'defaultaxesunits')); +set(h,'tag','subaxis'); + + + +if (nargout==0), clear h; end; + diff --git a/mcmc_simbio/src/integrableLHS.m b/mcmc_simbio/src/integrableLHS.m new file mode 100755 index 0000000..20aa57a --- /dev/null +++ b/mcmc_simbio/src/integrableLHS.m @@ -0,0 +1,137 @@ +function int_minit = integrableLHS(eMO, nW, paramranges,... + enames, ds, varargin) +%integrableLHS generate a set of integrable latin hypercube distributed +% parameter points for simbiology models +% eMO = exported model object +% nW = number of walkers + +% OLD VERSION: +% spread = log-spread of the parameter values around logp +% logp = the parameters that set the center of the latin hypercube +% NEW VERSION: +% just specify the parameter ranges explicitly. these are log transformed. + +% enames = names of estimated parameters +% ds = dosing strategy +% optional name value pair: 'multiopt_params', mop is a matrix containing +% the indiced for the parameters to use for each sub optimization problem. +% it has rows corresponding to each sub optimization problem, and each row +% us the indices of the parameters to be estimated for that problem, +% followed by zeros to pad. + + +p = inputParser; +p.addParameter('multiopt_params', [], @isnumeric) +p.addParameter('distribution', 'LHS', @ischar) +p.addParameter('width', .001, @isnumeric) + +p.parse(varargin{:}); + +p = p.Results; + +if iscell(eMO) + % TODO: update this multiopt version. for now, we just do the single + % opt version. + mop = p.multiopt_params; + assert(~isempty(mop),... + 'Please ensure that in multi optimization mode, the estimation structure is specified') + assert(isequal(length(logp), length(estNamesFull), size(mop,2),... + 'The length of logp, full estimation names, and the # columns in estimation structure must match')); + assert(isequal(length(eMO), size(mop, 1)), ... + 'The number of sub optimization problems must be consistent in the array of model objects and the estimation structure array'); + nOpt = length(eMO); + nparam = length(logp); % logp not defined? + % for each sub problem, get indices of the integrable points + % Most of the time we seem for have 70% or more integrability. So assume we lose 30% of points per sub problem. + npts = round(nW/max([0.65^nOpt 0.1])); %we allow for up to 10X multiplication, need to rethink the method if this does not suffice + lhsamp = paramranges*(lhsdesign(npts, nparam)-0.5); + minit=bsxfun(@plus,logp,lhsamp'); + IP = cell(nOpt,1); + % number of points to generate initially should be + tic + for kk = 1:nOpt + % here we reorder the parameters for the individual optimization problem. The estNames input to the sbiointegrable function below + % should be in the order that the parameters appear in the exported model object. + [~,~,V] = find(mop(kk,:)); + en = enames(V); + % order en correctly by working through valueInfo + count = 1; + for ii = 1:length(eMO.ValueInfo) + index1 = strcmp(en, eMO.ValueInfo(ii).Name); + index2 = find(index1); + if index2~= 0 + en2{count} = en{index2}; + count = count+1; + end + end + + IP{kk} = sbiointegrable(eMO{kk}, minit, en2, ds{kk}); + numInt{kk} = sum(all(IP{kk}==1, 2)); + intIx{kk} = find(all(IP{kk}==1, 2)); + end + toc ; + + simul_int = (1:npts)'; + for kk = 1:nOpt + simul_int = intersection(intIx{kk}, simul_int); + end + + if nW >= length(simulint) + int_minit = minit(:, simul_int); + warning('Number of integrable points less than number specified. Using only integrable points.') + + else + % randomly generate nW samples from list of integrable indices + r = randperm(length(simulint), nW); + int_minit = minit(:, simul_int(r)); + end + +else + + nparam = length(enames); + npts = round(nW*2); % can tolerate up to 50% non integrability. + % Increase the factor here if you need to tolerate more. + + % generate latin hyper cube distributed points to test for + % integrability + switch p.distribution + case 'LHS' + lhsamp = lhsdesign(npts, nparam); + lhsamp = lhsamp'; % nparam by npts matrix of LHS points + + minit= ... + lhsamp.*(repmat(paramranges(:, 2), 1, npts)-repmat(paramranges(:, 1), 1, npts))+... + repmat(paramranges(:, 1), 1, npts); + + case 'gaussian' + midpt = (repmat(paramranges(:, 2), 1, npts) +... + repmat(paramranges(:, 1), 1, npts))/2; + + minit = p.width*randn(nparam,npts)-p.width/2 + midpt; + + case 'unifrand' + midpt = (repmat(paramranges(:, 2), 1, npts) +... + repmat(paramranges(:, 1), 1, npts))/2; + width = (repmat(paramranges(:, 2), 1, npts) -... + repmat(paramranges(:, 1), 1, npts)); + minit = width.*rand(nparam,npts)-width/2 + midpt; + end + + + tic + IP = sbiointegrable(eMO, minit, enames, ds); + toc ; + + numInt = sum(all(IP==1, 2)); + intIx = find(all(IP==1, 2)); + if nW >= numInt + int_minit = minit(:, intIx); + else + % randomly generate nW samples from list of integrable indices + r = randperm(numInt, nW); + int_minit = minit(:, intIx(r)); + end +end + +end + diff --git a/mcmc_simbio/src/integrableLHS_v2.m b/mcmc_simbio/src/integrableLHS_v2.m new file mode 100755 index 0000000..5ebb944 --- /dev/null +++ b/mcmc_simbio/src/integrableLHS_v2.m @@ -0,0 +1,174 @@ +function int_minit = integrableLHS_v2(mi, mai, ri, varargin) + % version 2 of the integrable LHS function. + % + % OLD HELP FILE: + %integrableLHS generate a set of integrable latin hypercube distributed + % parameter points for simbiology models + % eMO = exported model object + % ri.nW = number of walkers + + % OLD VERSION: + % spread = log-spread of the parameter values around logp + % logp = the parameters that set the center of the latin hypercube + % NEW VERSION: + % just specify the parameter ranges explicitly. these are log transformed. + + % enames = names of estimated parameters + % ds = dosing strategy + % optional name value pair: 'multiopt_params', mop is a matrix containing + % the indiced for the parameters to use for each sub optimization problem. + % it has rows corresponding to each sub optimization problem, and each row + % us the indices of the parameters to be estimated for that problem, + % followed by zeros to pad. + + p = inputParser; + p.addParameter('multiopt_params', [], @isnumeric) + p.addParameter('distribution', 'LHS', @ischar) + p.addParameter('width', .001, @isnumeric) + + p.addParameter('Parallel',true,@islogical); + p.parse(varargin{:}); + + p = p.Results; + + % compute the reduced number of parameters. + % nreduc = sum(cellfun(@numel, mi.semanticGroups)) ... + % - numel(mi.semanticGroups); + + % reducedvec -> mastervec -> -> -> distribute across all models + % and geometries and doses. if the integration passes for all cases, + % then that points is integrable. Probably need to expand the candidate + % points to be 5x the original number of walkers. + % make sure the parameter order is correct. + % + [~, rpr, ~] = reduceMasterVec(mai); + nparam = size(rpr, 1); + + + npts = round(ri.nW*3); % can tolerate up to 67% non integrability. + % Increase the factor here if you need to tolerate more. + + % Compute the parameter sharing across all topologies and geometries for + % initial walker estimation purposess. + + % generate latin hyper cube distributed points to test for + % integrability + + switch p.distribution + case 'LHS' + lhsamp = lhsdesign(npts, nparam); + lhsamp = lhsamp'; % nparam by npts matrix of LHS points + % Note that this is a npts dimensional hypercube, with sides + % from 0 to 1, excluding the edges. + + + minit= ... + lhsamp.*(repmat(rpr(:, 2), 1, npts)-... + repmat(rpr(:, 1), 1, npts))+... + repmat(rpr(:, 1), 1, npts); + + case 'gaussian' + midpt = (repmat(rpr(:, 2), 1, npts) +... + repmat(rpr(:, 1), 1, npts))/2; + + minit = p.width*randn(nparam,npts)-p.width/2 + midpt; + + case 'unifrand' + midpt = (repmat(rpr(:, 2), 1, npts) +... + repmat(rpr(:, 1), 1, npts))/2; + width = (repmat(rpr(:, 2), 1, npts) -... + repmat(rpr(:, 1), 1, npts)); + minit = width.*rand(nparam,npts)-width/2 + midpt; + end + + % rebuild the master vector + minit_justEstParams = rebuildMasterVec(minit, mai); + % only has #estparams in the columns. + % not the full master vector. + % all the values should be in log space. + + % we build the full set of npts master vectors, arranged into a matrix + % of size #full master vector elements x npts: + mv = mai.masterVector; + minit_fixedAndEstParams = repmat(mv, 1, npts); + estParamsIx = setdiff((1:length(mv))', mai.fixedParams); + minit_fixedAndEstParams(estParamsIx, :) = minit_justEstParams; + % i changed this line on 3.12.2018. not sure if this break previous + % code or fixes it. check how the previous code was working in the + % first place. yeah i think the previous code, which was only the vnprl + % and the protein with the mrna parameters fixed to 10 sets of values + % all never had semantic groups for parameters to be ESTIMATED. + + % each column of minit, when distributed across topologies and geometries + % should work for every topology geometry pair. + + IProw_old = ones(1, npts); + for i = 1:length(mi) % for each topology + + %number of params in a given topo (model) + nParam_TopoGeom = size(mi(i).paramMaps, 1); + + % define dose matrix. This is correct, can also put a {} around the dosedvals + % matrix. Cant remove the braces around the names. + ds = struct('names', {mi(i).dosedNames}, 'dosematrix', mi(i).dosedVals); + + + for j = 1:size(mi(i).paramMaps, 2) % for each geometry, do everything. + + % build the minit for this topo - geom pair + % from the master one (ie, minit_fixedAndEstParams) + pIX_TopoGeom = mi(i).paramMaps(mi(i).orderingIx, j); + minitTopoGeom = minit_fixedAndEstParams(pIX_TopoGeom, :); + + % REORDER TO MAKE THEM CORRECT WITH THE EXPORTED MODEL'S + % parameter ORDERING. + % + % ??? MAYBE NOT NEEDED. JUST REORDER AFTR THE ESTIMATION. THE + % PARAM RANGERS ARE MAYBE ALREADY ORDERED. + +% minitTopoGeom_reordered = minitTopoGeom( + + + + % now simulate this the t-g for this minit and + % for each column of minit, report if it passes. + % IP is a matrix of dimension npts x # dose combinations. + % Three possible values: + % 0 = integration tol not met + % 1 = run successfully + % 2 = unknown error. + % + tic + IP = sbiointegrable(mi(i).emo, minitTopoGeom, mi(i).namesOrd, ds, p.Parallel); + toc + IP = IP'; % make IP nDoses x npts + + + % numInt = sum(all(IP==1, 1)); + IProw_new = all(IP==1, 1); + % intIx = find(all(IP==1, 1)); + IPtemp = [IProw_old; IProw_new]; + IProw_old = all(IPtemp==1, 1); + end + % do this for each geometry and each topology. the set of points that + % pass every t-g pair are our valid starting point. could be stringent. + end + IProw = IProw_old; + numInt = sum(IProw==1); + disp([num2str(numInt) ' points out of ' num2str(size(minitTopoGeom,2)) ... + ' are integrable. Need ' num2str(ri.nW) ' walkers.']) + intIx = find(IProw==1); + if ri.nW >= numInt + % not enough integrable points + warning(['Not enough integrable points. '... + 'Reducing to maximal set of integrable points.']) + int_minit = minit_justEstParams(:, intIx); + else + % randomly generate ri.nW samples from list of integrable indices + r = randperm(numInt, ri.nW); + int_minit = minit_justEstParams(:, intIx(r)); + end + + +end + diff --git a/mcmc_simbio/src/loglike_gaussian.m b/mcmc_simbio/src/loglike_gaussian.m new file mode 100755 index 0000000..31fc448 --- /dev/null +++ b/mcmc_simbio/src/loglike_gaussian.m @@ -0,0 +1,34 @@ +function [llh] = loglike_gaussian(logp, stdev, ICarray,measuredspidx, tspan, ... + dataArray, genemodel, lognormvec) +% loglike_gaussian Gaussian log likelihood +% Compute the log likelihood of the data given the model parameters and +% the standard deviation. + +% Data is input as a array that is N x M x nIC. N is number of time points in tspan, +% M is the number of species species + +mV = mean(dataArray(:,measuredspidx,:),1); +meanVals = mean(mV,3); %meanVals is a row vec. + +wt = sum(meanVals)./meanVals; %hight mean = lower wt +relWt = wt/sum(wt); +CONC_temp = zeros(size(dataArray)); + + +nIC = size(ICarray,1); % number of different initial conditions. +% initial conditions are row vectors. Rows are different sets of initial conditions. + +for i = 1:nIC +[~,CONC_temp(:,:,i)] = genemodel(logp, ICarray(i,:), tspan); +end + +residuals = dataArray(:,measuredspidx,:) - CONC_temp(:,measuredspidx,:); +resi = bsxfun(@times, residuals, relWt); + +res = resi(:); +llh = sum(lognormvec(res, stdev)); + + + +end + diff --git a/mcmc_simbio/src/loglike_gaussian_joint.m b/mcmc_simbio/src/loglike_gaussian_joint.m new file mode 100755 index 0000000..3ac500c --- /dev/null +++ b/mcmc_simbio/src/loglike_gaussian_joint.m @@ -0,0 +1,60 @@ +function [llh] = loglike_gaussian_joint(jointlogp, stdev, ICarray,measuredspidx, tspan, ... + dataArray1,dataArray2, genemodel, lognormvec) +% +% loglike_gaussian Gaussian log likelihood +% Compute the log likelihood of the data given the model parameters and +% the standard deviation. +% +% Data is input as a array that is N x M x nIC. N is number of time points in tspan, +% M is the number of species species +% +% one param vector, used two populate two runs. two data sets. +logp1 = jointlogp([1:4 7:8]); + +mV = mean(dataArray1(:,measuredspidx,:),1); +meanVals = mean(mV,3); %meanVals is a row vec. + +wt = sum(meanVals)./meanVals; %hight mean = lower wt +relWt = wt/sum(wt); +CONC_temp = zeros(size(dataArray1)); + +nIC = size(ICarray,1); % number of different initial conditions. +% initial conditions are row vectors. Rows are different sets of initial conditions. + +for i = 1:nIC +[~,CONC_temp(:,:,i)] = genemodel(logp1, ICarray(i,:), tspan); +end + +residuals = dataArray1(:,measuredspidx,:) - CONC_temp(:,measuredspidx,:); +resi = bsxfun(@times, residuals, relWt); + +res1 = resi(:); + +logp2 = jointlogp([1:2 5:8]); +mV = mean(dataArray2(:,measuredspidx,:),1); +meanVals = mean(mV,3); %meanVals is a row vec. + +wt = sum(meanVals)./meanVals; %hight mean = lower wt +relWt = wt/sum(wt); +CONC_temp = zeros(size(dataArray2)); + + +nIC = size(ICarray,1); % number of different initial conditions. +% initial conditions are row vectors. Rows are different sets of initial conditions. + +for i = 1:nIC +[~,CONC_temp(:,:,i)] = genemodel(logp2, ICarray(i,:), tspan); +end + +residuals = dataArray2(:,measuredspidx,:) - CONC_temp(:,measuredspidx,:); +resi = bsxfun(@times, residuals, relWt); + +res2 = resi(:); + +res = [res1; res2]; +llh = sum(lognormvec(res, stdev)); + + + +end + diff --git a/mcmc_simbio/src/masterVecArray.m b/mcmc_simbio/src/masterVecArray.m new file mode 100755 index 0000000..1303a82 --- /dev/null +++ b/mcmc_simbio/src/masterVecArray.m @@ -0,0 +1,13 @@ +function [mvarray] = masterVecArray(marray, mai) +%UNTITLED2 Summary of this function goes here +% Detailed explanation goes here + +szm = size(marray); +mvarray = repmat(mai.masterVector, [1, szm(2:end)]) ; + +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +mvarray(estParamsIx, :, :) = marray; + + +end + diff --git a/mcmc_simbio/src/mcmc_3D.m b/mcmc_simbio/src/mcmc_3D.m new file mode 100755 index 0000000..d813d52 --- /dev/null +++ b/mcmc_simbio/src/mcmc_3D.m @@ -0,0 +1,22 @@ +function [fig, ax] = mcmc_3D(mcut, axL, titl) + % mcmc_3D takes an array of dimensions nPoints x 3 and generates a + % scatterplot. + % + % mcut is a nPoints x 3 matrix of points to scatterplot. + % axL must be a 1 x 3 cell array of the axis label strings + % corresponding to the 3 columns of mcus. + % titl is a title string. + % +fig = figure; + + +XX = mcut(:, 1); +YY = mcut(:, 2); +ZZ = mcut(:, 3); +scatter3(XX,YY,ZZ) +xlabel(axL{1}, 'FontSize', 20) +ylabel(axL{2}, 'FontSize', 20) +zlabel(axL{3}, 'FontSize', 20) +title(titl, 'FontSize', 20) +ax = gca; +end diff --git a/mcmc_simbio/src/mcmc_cut.m b/mcmc_simbio/src/mcmc_cut.m new file mode 100755 index 0000000..4f77463 --- /dev/null +++ b/mcmc_simbio/src/mcmc_cut.m @@ -0,0 +1,80 @@ +function outputslice = mcmc_cut(marray, pID, pRanges, varargin) +% Cut a lower dimensional slice out of a high dimensional +% parameter distribution. +% +% - marray: This function takes an array of numbers of size +% nPoints x nParam, and returns an array of size +% nPointsFewer x nParam, where nPointsFewer is the number of +% points satisfying the slicing condition described below. +% marray can also be an array of size nParam x nWalkers x nsteps, +% in which case the output is of the same dimension, or of dimension +% nParam x nWalkersSmaller, where nWalkersSmaller is the total +% number of points where the slicing condition holds. Note that the walker +% positions with respect to the steps is not preserved. +% +% - pID is a vector of parameter indices ranging from 1 to +% nParam. +% +% - pRanges is a 2 x length(pID) array of upper and lower bounds +% (first and second row resp) for parameter values corresponding +% to the parameters indexed by the array pID. +% +% SLICING CONDITION: +% This function returns the subset of points (rows) in marray +% for which the condition all(pranges(1, :) >= point(pID)) and +% all(pranges(2, :) <= point(pID)), where the vector 'point' +% is a row of the array of parameter points marray. (The Output +% 'outputslice' is a matrix of all such points.) +% +% Optional Input name-value pair +% 'marginalize' (default: false). If set to true, we remove +% the parameters with indices in the index vector pID from +% the returned array, and and in this case the output array +% OUTPUTSLICE will have dimensions +% nPointsFewer x (nParam - length(pID)). +% +p = inputParser; +p.addParameter('marginalize', false, @islogical) +p.parse(varargin{:}); +p = p.Results; +convertTo3D = false; +if ndims(marray) == 3 + convertTo3D = true; + szm = size(marray); + marray = marray(:, :)'; +end + +fun1 = @(rowvec) all(rowvec(pID) CAN JUST USE MCMC_TRAJECTORIES WITH A CUSTOM SPECIES ARGUMENT. +%mcmc_plotCustomSpecies Take an exported model, and a parameter array (2D), and plot the +%trajectories for up to the last 5 parameter points in the parameter array +% -- em: exported model object. +% -- m: parameter array, ORDERED (ie, parameters ordered by the following +% type of code: +% mvarray = masterVecArray(m, mai); +% marrayOrd = mvarray(mi.paramMaps(mi.orderingIx, 1),:,:); +% and then made 2D if needed. +% This array has dimensions: nPoints x nParam +% last 5 points get plotted. If there are less than 5 points, then +% all of them get plotted. +% -- mi: model_info struct. Must be a scalar struct. +% -- mai: master_info struct. must be a scalar struct. +% -- spl: cell array vector list of cell array vector lists of species to plot. +% The outer cell array is the number of subplots. The inner cell +% array is the list of species whose trajectories get summed in +% the plotting. This is the same specification as the +% measuredSpecies field in the model_info struct. +% + +% determine the subplot dimensions from the +nParam = size(m, 2); +[n1 n2] = twofactors(nParam); +if isprime(nParam) + n1 = ceil(nParam/5); % 5 columns + n2 = 5; +end +nPoints = size(m, 1); +if nPoints >4 + sIx = nPoints-4; + nSimCurves = 5; + +else + sIx = 1; + nSimCurves = nPoints; +end + +tv = di(mi.dataToMapTo).timeVector; +dose = mi.dosedVals; + +% simulate the model at the required points. +[da, idxnotused] = simulatecurves(em,m, nSimCurves, dose, tv, spl); + +for i = sIx:nPoints + + + + + +% plot the results + + + + +end + diff --git a/mcmc_simbio/src/mcmc_plot_txtl.m b/mcmc_simbio/src/mcmc_plot_txtl.m new file mode 100755 index 0000000..a0e65c1 --- /dev/null +++ b/mcmc_simbio/src/mcmc_plot_txtl.m @@ -0,0 +1,135 @@ +function mcmc_plot_txtl(m, p, d, varargin) +% Generate txtl_plot plot using user specified parameters, for models used +% in the mcmc_simbio toolbox (ie, those with parameters already globalized +% and bound using the Kd rules). If the parameters are not globalized, they +% *must* be specified in the p struct that is input into this function, +% along with the reaction string specifying which reaction that parameter +% is to be scoped under. +% +% This function is useful when you have results from mcmc and want to just +% plot an unexported Simbiology model object with those parameters. +% +% INPUTS: +% m: the Simbiology model object you want to simulate. This needs to have +% gone through the setup reactions phase and globalize parameters phases +% already. +% +% p: A struct specifying the parameters you want to use for the simulation. +% This has fields: +% paramNames: name of parameter +% paramVals: value of the parameter; this is not log transformed. +% reactionString: This is either 'global' for globally (model object +% level) parameters, or a string corresponding to the +% reaction that parameter belongs to. +% +% d: A struct specifying the dose to use. There are two fields: 'dosedVals' +% and 'dosedNames'. dosedVals is a column vector of values to use, and +% dosedNames is a cell array of the names of the species to be dosed. +% +% varargin: optional arguments. +% +% +% Name value pair: +% 1. 'model_info', model_info(j) (One element of model_info struct array) +% inputs the jth elements of the model_info struct array to this function. +% The model_info struct contains the +% parameters to be used with the model, These get overwritten by any +% parameters that are also specified int eh parameter struct p provided to +% this function. The model info struct must be for a single topology, i.e., +% must be a struct of length 1. For multiple topology model info struct, +% slice them as mi(j) before passing to this function. +% +% 2. 'which_geometry', g (numeric) +% If there are multiple geometries (for example, columns of paramMaps) in the model +% info struct, this one specifies which one to use to set the model +% parameters. If unspecified, then the first geometry is used in the +% model_info. +% +% 3. 'master_info', mai (struct) +% This is the master_info struct that contains the parameters used by the +% model_info struct (namesUnord is the array of names, and paramMaps is the +% map that takes the master vector to the model's parameters specified by +% the names in model_info.namesUnord +% +% Vipul Singhal, Caltech, 2018 + + +% parse optional inputs +inp = inputParser; +inp.addParameter('model_info', [], @isstruct); % +inp.addParameter('which_geometry', 1, @isnumeric); % +inp.addParameter('master_info', [], @isstruct); % +inp.parse(varargin{:}); +inp = inp.Results; + + +% set the parameters in the model object - first from the model_info, then +% from the parameters struct p. +if ~isempty(inp.model_info) && ~isempty(inp.master_info) + [m, pnotset] = set_mobj_from_model_info(m, ... + inp.model_info, ... + inp.master_info, ... + inp.which_geometry); +end + +% now set the parameters from the supplied parameter array. +for i = 1:length(p) + obj = sbioselect(m, 'name', p(i).paramNames); + if ~isempty(obj) + switch class(obj) + case 'SimBiology.Parameter' + obj.Value = exp(p(i).paramVals); + case 'SimBiology.Species' + obj.InitialAmount = exp(p(i).paramVals); + end + else + % maybe the parameter is reaction level scoped. +% rObj = []; +% if ~strcmp(p(i).reactionString, 'global') +% rObj = sbioselect(m,'Type','reaction','reaction',p(i).reactionString); +% +% % if it is a reaction, then it could be reveresible or +% % irreversible. Then we need to set the parameter within the +% % kinetic law object. I dont have time for this. +% +% +% % rObj.Value = log(p(i).paramVals); +% % !todo... +% error('todo') +% end + error('paramnotset_see_what_happened.') + % otherwise just report that it did not get set. +% paramsNotSet = [paramsNotSet; pnames(i)]; +% warning(['Object with name ' pnames{i} ' not found. Skipping setting its value.']) + end +% can also look into: setparam(m, p(i).reactionString, p(i).paramNames, p(i).paramVals); +end + +% now run the model under the specified dose and record the output. +for i = 1:length(d.dosedNames) + sp = sbioselect(m, 'Name', d.dosedNames{i}); + sp.InitialAmount = d.dosedVals(i); +end +[simData] = txtl_runsim(m,14*60*60); + + +% finally plot stuff. +txtl_plot(simData,m); + + + + +% Save then in the current directory as a low res jpg, +% displaying the directory they were saved in in the command window. +% If a file with the current name exists, then append a numeric +% to the filename. +print(['txtlplot_' datestr(now, 'yyyymmddTHHMMSS')],'-djpeg', '-r100') + +end + + + + + + + diff --git a/mcmc_simbio/src/mcmc_runsim.m b/mcmc_simbio/src/mcmc_runsim.m new file mode 100755 index 0000000..92b42ec --- /dev/null +++ b/mcmc_simbio/src/mcmc_runsim.m @@ -0,0 +1,215 @@ +function mi = mcmc_runsim(tstamp, projdir,di, mobj, mi, varargin) +% mcmc_runsim: run the mcmc estimation using the affine invariant +% ensemble sampler. +% +% INPUTS: +% +% tstamp: The time stamp string of the simulation generated by +% project_init. Format is 'yyyymmdd_HHMMSS' +% +% projdir: Directory where the generated data subdirectory +% (simdata_yyyymmdd_HHMMSS, where yyyymmdd_HHMMSS is +% the time stamp) will be created. +% +% tv: time vector in the units of seconds. +% +% da: A matlab array containing experimental data. This array +% has dimensions nTimePoints x nMS x nReplicates x nDoses +% where +% -nTimePoints: length(tv), i.e., the number of time points. +% -nMS: The number of measured species. Corresponds +% to values given in the mcmc_info and data_info +% structs. +% -nReplicates +% -nDoses: Number of dose combinations (initial conditions) +% +% mobj: Simbiology model object. +% +% mi: mcmc_info struct. Type 'help mcmc_info_dsg2014_mrna' or +% 'help mcmc_info_template' into the MATLAB command line to learn +% more. +% +% Optional name-value pair arguments: +% InitialDistribution: Initial distribution of walker points. This can be +% Latin hyprcube sampled (Value: 'LHS'), gaussian +% distributed (Value: 'gaussian') about the midpoint of +% mi.paramranges or uniformly distributed (Value: 'unifrand'). +% +% Width: Applies to the width of the gaussian or uniform random +% parameter distribution around the midpoint given by +% mi.paramranges. +% +% UserInitialize: The user provides a matrix of initial walker positions. +% When this input is specified, 'InitialDistribution' and +% 'Width' are ignored. +% +% FitOption: Allows for fitting to data in 3 modes: +% 'FitMedian': This mode computes the curvewise median (Default). +% of the data over the replicates, and fits the model +% to this. +% 'FitMean': Compute the mean of the replicates, and fit to this +% mean +% 'FitAll' Fit all the curves. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser; +p.addParameter('InitialDistribution', 'LHS', @ischar); % LHS, gaussian, unifrand +p.addParameter('Width', 0.1, @isnumeric) +p.addParameter('UserInitialize', [], @isnumeric) +p.addParameter('FitOption', 'FitMedian', @ischar); % 'FitMean', 'FitAll' +p.parse(varargin{:}); +p = p.Results; + +% Transform Experimental data to the appropriate form for fitting +da = di.dataArray; +tv = di.timeVector; +switch p.FitOption + case 'FitMedian' + % Compute the curvewise median of the data. + [ix, mdvals] = medianIndex(sum(da, 1), 3); + da = medianReplicate(da, ix); + case 'FitMean' + da = mean(da, 3); + case 'FitAll' + % do nothing +% da = da; + otherwise + error('Invalid fit option. Read the documentation for how to specify inputs.') +end + +%% EXPORT MODEL object to get it ready for MCMC +% the resulting object is of class SimBiology.export.Model +% documentation: https://www.mathworks.com/help/simbio/ref/simbiology.export.model-class.html +% Sven Mesecke's blog post on using the exported model class for parameter inference applicaton. +% http://sveme.org/how-to-use-global-optimization-toolbox-algorithms-for-simbiology-parameter-estimation-in-parallel-part-i.html + +% export and accelerate simbiology model object using estimated species +% and dosing species names + +% select the parameters and species objects using the name array +ep = sbioselect(mobj, 'Type', 'parameter', 'Name', ... + mi.namesUnord);% est parameters + +es = sbioselect(mobj, 'Type', 'species', 'Name', ... + mi.namesUnord);% est species + +aps = [ep; es]; % active parameters and species + +% reorder the parameter and species so they are in the same order as that +% in the model. +eno = cell(length(aps), 1);% est names ordered + +for i = 1:length(aps) + eno{i} = aps(i).Name; +end +% +ds = sbioselect(mobj, 'Type', 'species', 'Name', mi.dosedNames); + +emo = export(mobj, [ep; es; ds]); % exported model object, dosed species names. +SI = emo.SimulationOptions; +SI.StopTime = tv(end); +accelerate(emo); + +mi.names_ord = eno; % est names ordered. +mi.emo = emo; % exported model object. + + +%% COMPUTE INITIAL WALKER POSITIONS +ds = struct('names', {mi.dosedNames}, 'dosematrix', mi.dosedVals); +if isempty(p.UserInitialize) + minit = integrableLHS(emo, mi.nW, mi.paramRanges, eno, ... + ds, 'distribution', p.InitialDistribution, 'width', p.Width); +else + minit = p.UserInitialize; + % assume all the user defined points are integrable. +end + +%% SETUP FUNCTIONS +% setup the log prior, log likelihood function and lognormvec functions +lognormvec=@(res,sig) -(res./sig).^2 -log(sqrt(2*pi)).*sig; + +logprior = @(logp) all(mi.paramRanges(:, 1) < logp) &&... + all(logp < mi.paramRanges(:,2)); + +sigg = mi.stdev/mi.tightening; + + + +loglike = @(logp) gen_residuals_4(logp, emo, da, tv, ... + mi.dosedVals, mi.measuredSpecies, lognormvec, sigg); + + +% BURN IN: run the burn in simulation +if isempty(p.UserInitialize) + tic + [m] =gwmcmc_vse(minit,{logprior loglike},... + mi.npoints,... + 'StepSize',mi.stepsize , ... + 'ThinChain',mi.thinning,... + 'Parallel', mi.parallel); + toc + + minit = m(:,:,end); + clear m +else + disp('User initialized intitial walker positions, skipping burn in phase') +end + + +% specify where to save things +cfname = cell(mi.nIter, 1); +specificproj = [projdir '/simdata_' tstamp]; + +%% we save useful variables in a one off manner here (ie, outside the loops) +fname = ['full_variable_set_' tstamp]; % filename +save([specificproj '/' fname]); + +% run the actual simuations, saving the data every iteration +for i = 1:mi.nIter % + if ~mod(i, 3) + fprintf('Pausing for 10 minutes before starting run number %d. \n', i); + pause(6) + end + + tic + fprintf('starting mcmc %d\n', i); + [m] = gwmcmc_vse(minit,{logprior loglike},... + mi.nPoints, ... + 'StepSize',mi.stepSize , ... + 'ThinChain',mi.thinning, 'Parallel', mi.parallel); + + fprintf('ending mcmc %d\n', i); + toc + fname = ['mcmc' tstamp '_ID' num2str(i)] ; + cfname{i} = fname; + save([specificproj '/' fname], 'm'); + % the only thing that is different in each run are the above + % pause(1) + minit = m(:,:,end);% + 0.1*randn(size(m(:,:,end-1))); + + clear m + +end + +% generate log file +mcmc_log(tstamp, projdir,specificproj, mi, di) +end + diff --git a/mcmc_simbio/src/mcmc_runsim_4.m b/mcmc_simbio/src/mcmc_runsim_4.m new file mode 100755 index 0000000..e445ad5 --- /dev/null +++ b/mcmc_simbio/src/mcmc_runsim_4.m @@ -0,0 +1,208 @@ +function mcmc_runsim_4(tstamp, projdir, tv,da, mobj, mi, varargin) +% mcmc_runsim run the mcmc estimation - This version works with (the +% prototyping version) the gen_residuals_4 function. +% +% mobj is the simbiology model +% mi is the mcmc info struct created using the mcmc_info_... function. +% funcs are the various functions needed, the prior, the lognormvec. + +% !LATER check if a directory to save the simulation results exists, +% and create it if it does not. +% for now we just assume that project_init did its job right. +% +% has the following name value input pairs. +% 'distribution', 'LHS' +% 'width', 0.1 +% +% +% +% order the est names in the same order as +% run an initial pass to find a set of points where integration tolerances +% are met. This valid points will be our initial walker positions. + +p = inputParser; +p.addParameter('distribution', 'LHS', @ischar) +p.addParameter('width', 0.1, @isnumeric) +p.addParameter('userinitialize', [], @isnumeric) + +p.parse(varargin{:}); + +p = p.Results; + +%% EXPORT MODEL object to get it ready for MCMC +% the resulting object is of class SimBiology.export.Model +% documentation: https://www.mathworks.com/help/simbio/ref/simbiology.export.model-class.html +% Sven Mesecke's blog post on using the exported model class for parameter inference applicaton. +% http://sveme.org/how-to-use-global-optimization-toolbox-algorithms-for-simbiology-parameter-estimation-in-parallel-part-i.html + +% export and accelerate simbiology model object using estimated species +% and dosing species names + +% select the parameters and species objects using the name array +ep = sbioselect(mobj, 'Type', 'parameter', 'Name', ... + mi.names_unord);% est parameters + +es = sbioselect(mobj, 'Type', 'species', 'Name', ... + mi.names_unord);% est species + +aps = [ep; es]; % active parameters and species + +% reorder the parameter and species so they are in the same order as that +% in the model. +eno = cell(length(aps), 1);% est names ordered + +for i = 1:length(aps) + eno{i} = aps(i).Name; +end + +% +ds = sbioselect(mobj, 'Type', 'species', 'Name', mi.dosednames); + +emo = export(mobj, [ep; es; ds]); % exported model object, dosed species names. +SI = emo.SimulationOptions; +SI.StopTime = tv(end); +accelerate(emo); + +mi.names_ord = eno; % est names ordered. +mi.emo = emo; % exported model object. + + +ds = struct('names', {mi.dosednames}, 'dosematrix', mi.dosedvals); +if isempty(p.userinitialize) + minit = integrableLHS(em, mi.nW, mi.paramranges, eno, ... + ds, 'distribution', p.distribution, 'width', p.width); +else + minit = p.userinitialize; + % assume all the user defined points are integrable. +end + +% setup the log prior, log likelihood function and lognormvec functions +lognormvec=@(res,sig) -(res./sig).^2 -log(sqrt(2*pi)).*sig; + +logprior = @(logp) all(mi.paramranges(:, 1) < logp) &&... + all(logp < mi.paramranges(:,2)); + +sigg = mi.stdev/mi.tightening; + +loglike = @(logp) gen_residuals_4(logp, em, da, tv, ... + mi.dosedvals, mi.measuredspecies, lognormvec, sigg); + + +% run the burn in simulation +if isempty(p.userinitialize) + tic + [m] =gwmcmc_vse(minit,{logprior loglike},... + mi.npoints,... + 'StepSize',mi.stepsize , ... + 'ThinChain',mi.thinning,... + 'Parallel', mi.parallel); + toc + + minit = m(:,:,end); + clear m +else + disp('User initialized intitial walker positions, skipping burn in phase') +end + + +% specify where to save things +cfname = cell(mi.niter, 1); +specificproj = [projdir '/simdata_' tstamp]; + +%% we save useful variables in a one off manner here (ie, outside the loops) +fname = ['full_variable_set_' tstamp]; % filename +save([specificproj '/' fname]); + +% run the actual simuations, saving the data every iteration +for i = 1:mi.niter % + if ~mod(i, 3) + fprintf('Pausing for 10 minutes before starting run number %d. \n', i); + pause(600) + end + + tic + fprintf('starting mcmc %d\n', i); + [m] = gwmcmc_vse(minit,{logprior loglike},... + mi.npoints, ... + 'StepSize',mi.stepsize , ... + 'ThinChain',mi.thinning, 'Parallel', mi.parallel); + + fprintf('ending mcmc %d\n', i); + toc + fname = ['mcmc' tstamp '_ID' num2str(i)] ; + cfname{i} = fname; + save([specificproj '/' fname], 'm'); + % the only thing that is different in each run are the above + % pause(1) + minit = m(:,:,end);% + 0.1*randn(size(m(:,:,end-1))); + + clear m + +end + +% generate log file + + + +%% generate simulation log file +% do this. also, write a log file using log4m and +% fprintf. +currdir = pwd; +cd(specificproj); +fileID = fopen(['summary_' tstamp '.txt'],'w'); + +% !TODO FIX THIS. REALLY SHOULD NOT BE LIKE THIS. +% siminfo = {'MG apt and GFP', '''data_dsg2014'''}; +% fS = 'MCMC estimation for %s, using the TXTL modeling toolbox \n'; +% fprintf(fileID,fS,siminfo{1}); +% fS = 'Data from file %s \n'; +% fprintf(fileID,fS, siminfo{2}); + +fS = ['################################################ \n' ... + 'The estimated species and parameters are: \n']; +fprintf(fileID,fS); +fS = '%s in range [%0.5g %0.5g] \n'; +[nn] = length(eno); +for i = 1:nn + fprintf(fileID,fS,eno{i}, exp(mi.paramranges(i, 1)),... + exp(mi.paramranges(i, 2))); +end + +fS = ['################################################ \n' ... + 'Dosed Species are: \n']; +fprintf(fileID,fS); +fS = '%s \n'; +[nn] = length(ds.names); +for i = 1:nn + fprintf(fileID,fS,ds.names{i}); +end + +% do the measured species later: +% fS = ['################################################ '... +% '\nMeasured Species are: \n']; +% fprintf(fileID,fS); +% fS = '%s \n'; +% [nn] = length(mi.measuredspecies); +% for i = 1:nn +% fprintf(fileID,fS,mi.measuredspecies{i}); +% end + +fS = ['################################################ \n'... + 'Simulation Parameters are: \n']; +fprintf(fileID,fS); +fprintf(fileID,'path: %s \n', projdir); +fprintf(fileID,'stdev: %3.1f \n', mi.stdev); +fprintf(fileID,'number of walkers: %d \n', mi.nW); +fprintf(fileID,'step size:%4.2f \n', mi.stepsize); +fprintf(fileID,'tightening: %4.2f \n', mi.tightening); +fprintf(fileID,'number of repeats: %d \n', mi.niter); +fprintf(fileID,'thinning: %d \n', mi.thinning); +fprintf(fileID,'points per iter: %d \n', mi.npoints); + +% MAP estimates +% median +fclose(fileID); +cd(currdir) + +end + diff --git a/mcmc_simbio/src/mcmc_runsim_5.m b/mcmc_simbio/src/mcmc_runsim_5.m new file mode 100755 index 0000000..4c208f4 --- /dev/null +++ b/mcmc_simbio/src/mcmc_runsim_5.m @@ -0,0 +1,179 @@ +function mcmc_runsim_5(tstamp, projdir, tv,da, em, mi, pmap, varargin) +%mcmc_runsim run the mcmc estimation - This version works with (the +%prototyping version) the gen_residuals_5 function. +% +% em is the exported simbiology model +% mi is the mcmc info struct created using the mcmc_info_... function. +% funcs are the various functions needed, the prior, the lognormvec. + +% !LATER check if a directory to save the simulation results exists, +% and create it if it does not. +% for now we just assume that project_init did its job right. +% +% has the following name value input pairs. +% 'distribution', 'LHS' +% 'width', 0.1 +% +% +% order the est names in the same order as +% run an initial pass to find a set of points where integration tolerances +% are met. This valid points will be our initial walker positions. + +p = inputParser; +p.addParameter('distribution', 'LHS', @ischar) +p.addParameter('width', 0.1, @isnumeric) +p.addParameter('userinitialize', [], @isnumeric) + +p.parse(varargin{:}); + +p = p.Results; +eno = mi.names_ord; +ds = struct('names', {mi.dosednames}, 'dosematrix', mi.dosedvals); + +if isempty(p.userinitialize) + % need to generalize this to the multi geometry case. + minit = integrableLHS(em, mi.nW, mi.paramranges, eno, ... + ds, 'distribution', p.distribution, 'width', p.width); +else + minit = p.userinitialize; + % assume all the user defined points are integrable. +end + +% setup the log prior, log likelihood function and lognormvec functions +lognormvec=@(res,sig) -(res./sig).^2 -log(sqrt(2*pi)).*sig; + +espix = pmap{1}; +cspix = pmap{2}; +nExt = size(da, 5); + + +% nparam = nExt*length(espix) + length(cspix); +paramranges = mi.paramranges; + +priorboundz = [repmat(paramranges(espix,:), length(espix),1) ; paramranges(cspix,:)]; + + +logprior = @(logp) all(priorboundz(:, 1) < logp) &&... + all(logp < priorboundz(:,2)); + +sigg = mi.stdev/mi.tightening; + +loglike = @(logp) gen_residuals_5(logp, em, da, tv, ... + mi.dosedvals, mi.measuredspecies, lognormvec, sigg, pmap ); + + +% run the burn in simulation +if isempty(p.userinitialize) + tic + [m] =gwmcmc_vse(minit,{logprior loglike},... + mi.npoints,... + 'StepSize',mi.stepsize , ... + 'ThinChain',mi.thinning,... + 'Parallel', mi.parallel); + toc + + minit = m(:,:,end); + clear m +else + disp('User initialized intitial walker positions, skipping burn in phase') +end + + + % run the actual simuations, saving the data every iteration + cfname = cell(mi.niter, 1); + specificproj = [projdir '/simdata_' tstamp]; + for i = 1:mi.niter % + pause(10) + tic + disp(sprintf('starting mcmc %d\n', i)); + [m] = gwmcmc_vse(minit,{logprior loglike},... + mi.npoints, ... + 'StepSize',mi.stepsize , ... + 'ThinChain',mi.thinning, 'Parallel', mi.parallel); + + disp(sprintf('ending mcmc %d\n', i)); + toc + fname = ['mcmc' tstamp '_ID' num2str(i)] ; + cfname{i} = fname; + save([specificproj '/' fname], 'm'); + % the only thing that is different in each run are the above +% pause(1) + minit = m(:,:,end);% + 0.1*randn(size(m(:,:,end-1))); + + clear m + + end + +% generate log file + + +%% we save all the other things here (ie, outside the loops +fname = ['full_variable_set_' tstamp]; % filename +save([specificproj '/' fname]); + + + +%% generate simulation log file + % do this. also, write a log file using log4m and +% fprintf. +currdir = pwd; +cd(specificproj); +fileID = fopen(['summary_' tstamp '.txt'],'w'); + +% !TODO FIX THIS. REALLY SHOULD NOT BE LIKE THIS. +% siminfo = {'MG apt and GFP', '''data_dsg2014'''}; +% fS = 'MCMC estimation for %s, using the TXTL modeling toolbox \n'; +% fprintf(fileID,fS,siminfo{1}); +% fS = 'Data from file %s \n'; +% fprintf(fileID,fS, siminfo{2}); + + +% !TODO : THIS IS NOT RIGHT. +fS = ['################################################ \n' ... +'The estimated species and parameters are: \n']; +fprintf(fileID,fS); +fS = '%s in range [%0.5g %0.5g] \n'; +[nn] = length(eno); +for i = 1:nn + fprintf(fileID,fS,eno{i}, exp(mi.paramranges(i, 1)),... + exp(mi.paramranges(i, 2))); +end + +fS = ['################################################ \n' ... + 'Dosed Species are: \n']; +fprintf(fileID,fS); +fS = '%s \n'; +[nn] = length(ds.names); +for i = 1:nn + fprintf(fileID,fS,ds.names{i}); +end + +% do the measured species later: +% fS = ['################################################ '... +% '\nMeasured Species are: \n']; +% fprintf(fileID,fS); +% fS = '%s \n'; +% [nn] = length(mi.measuredspecies); +% for i = 1:nn +% fprintf(fileID,fS,mi.measuredspecies{i}); +% end + +fS = ['################################################ \n'... + 'Simulation Parameters are: \n']; +fprintf(fileID,fS); +fprintf(fileID,'path: %s \n', projdir); +fprintf(fileID,'stdev: %3.1f \n', mi.stdev); +fprintf(fileID,'number of walkers: %d \n', mi.nW); +fprintf(fileID,'step size:%4.2f \n', mi.stepsize); +fprintf(fileID,'tightening: %4.2f \n', mi.tightening); +fprintf(fileID,'number of repeats: %d \n', mi.niter); +fprintf(fileID,'thinning: %d \n', mi.thinning); +fprintf(fileID,'points per iter: %d \n', mi.npoints); + +% MAP estimates +% median +fclose(fileID); +cd(currdir) + +end + diff --git a/mcmc_simbio/src/mcmc_runsim_OLD.m b/mcmc_simbio/src/mcmc_runsim_OLD.m new file mode 100755 index 0000000..8619daf --- /dev/null +++ b/mcmc_simbio/src/mcmc_runsim_OLD.m @@ -0,0 +1,135 @@ +function mcmc_runsim(tstamp, projdir, tv,da, em, mi) +%mcmc_runsim run the mcmc estimation +% em is the exported simbiology model +% mi is the mcmc info struct created using the mcmc_info_... function. +% funcs are the various functions needed, the prior, the lognormvec. + +% !LATER check if a directory to save the simulation results exists, and create it +% if it does not. +% for now we just assume that project_init did its job right. + + +% order the est names in the same order as +% run an initial pass to find a set of points where integration tolerances +% are met. This valid points will be our initial walker positions. +eno = mi.names_ord; +ds = struct('names', {mi.dosednames}, 'dosematrix', mi.dosedvals); +minit = integrableLHS(em, mi.nW, mi.paramranges, eno, ... + ds); + +% setup the log prior, log likelihood function and lognormvec functions +lognormvec=@(res,sig) -(res./sig).^2 -log(sqrt(2*pi)).*sig; + +logprior = @(logp) all(mi.paramranges(:, 1) < logp) &&... + all(logp < mi.paramranges(:,2)); + +sigg = mi.stdev/mi.tightening; + +% in the future, change this to use input supplied functions in place of +% lognormvec and gen_residuals_3. +loglike = @(logp) sum(lognormvec(gen_residuals_3(logp, em, da, tv, ... + mi.dosedvals, mi.measuredspecies),sigg)); + +% run the burn in simulation + + tic + [m] =gwmcmc_vse(minit,{logprior loglike},... + mi.npoints,... + 'StepSize',mi.stepsize , ... + 'ThinChain',mi.thinning,... + 'Parallel', mi.parallel); + toc + +% pause(10) + + minit = m(:,:,end); + clear m + % run the actual simuations, saving the data every iteration + cfname = cell(mi.niter, 1); + specificproj = [projdir '/simdata_' tstamp]; + for i = 1:mi.niter % + tic + disp(sprintf('starting mcmc %d\n', i)); + [m, ~, ~, ~] = gwmcmc_vse(minit,{logprior loglike},... + mi.npoints, ... + 'StepSize',mi.stepsize , ... + 'ThinChain',mi.thinning, 'Parallel', mi.parallel); + + disp(sprintf('ending mcmc %d\n', i)); + toc + fname = ['mcmc' tstamp '_ID' num2str(i)] ; + cfname{i} = fname; + save([specificproj '/' fname], 'm'); + % the only thing that is different in each run are the above +% pause(1) + minit = m(:,:,end);% + 0.1*randn(size(m(:,:,end-1))); + + clear m + end + +% generate log file + + +%% we save all the other things here (ie, outside the loops +fname = ['full_variable_set_' tstamp]; % filename +save([specificproj '/' fname]); + + + +%% generate simulation log file + % do this. also, write a log file using log4m and +% fprintf. +currdir = pwd; +cd(specificproj); +fileID = fopen(['summary_' tstamp '.txt'],'w'); + +siminfo = {'MG apt and GFP', '''data_dsg2014'''}; +fS = 'MCMC estimation for %s, using the TXTL modeling toolbox \n'; +fprintf(fileID,fS,siminfo{1}); +fS = 'Data from file %s \n'; +fprintf(fileID,fS, siminfo{2}); + +fS = '################################################ \nThe estimated species and parameters are: \n'; +fprintf(fileID,fS); +fS = '%s in range [%0.5g %0.5g] \n'; +[nn] = length(eno); +for i = 1:nn + fprintf(fileID,fS,eno{i}, exp(mi.paramranges(i, 1)),... + exp(mi.paramranges(i, 2))); +end + +fS = '################################################ \nDosed Species are: \n'; +fprintf(fileID,fS); +fS = '%s \n'; +[nn] = length(ds.names); +for i = 1:nn + fprintf(fileID,fS,ds.names{i}); +end + +% do the measured species later: +% fS = '################################################ \nMeasured Species are: \n'; +% fprintf(fileID,fS); +% fS = '%s \n'; +% [nn] = length(mi.measuredspecies); +% for i = 1:nn +% fprintf(fileID,fS,mi.measuredspecies{i}); +% end + +fS = '################################################ \nSimulation Parameters are: \n'; +fprintf(fileID,fS); +fprintf(fileID,'path: %s \n', projdir); +fprintf(fileID,'stdev: %3.1f \n', mi.stdev); +fprintf(fileID,'number of walkers: %d \n', mi.nW); +fprintf(fileID,'step size:%4.2f \n', mi.stepsize); +fprintf(fileID,'tightening: %4.2f \n', mi.tightening); +fprintf(fileID,'number of repeats: %d \n', mi.niter); +fprintf(fileID,'thinning: %d \n', mi.thinning); +fprintf(fileID,'points per iter: %d \n', mi.npoints); + +% MAP estimates +% median +fclose(fileID); +cd(currdir) + +end + diff --git a/mcmc_simbio/src/mcmc_runsim_v2.m b/mcmc_simbio/src/mcmc_runsim_v2.m new file mode 100644 index 0000000..ec97a06 --- /dev/null +++ b/mcmc_simbio/src/mcmc_runsim_v2.m @@ -0,0 +1,366 @@ +function mi = mcmc_runsim_v2(tstamp, projdir, data_info, mcmc_info, varargin) +% version 2 of the runsim file. +% This version is for the multi modal version of the mcmc problem. +% +% +% mcmc_runsim: run the mcmc estimation using the affine invariant +% ensemble sampler. +% +% INPUTS: +% +% tstamp: The time stamp string of the simulation generated by +% project_init. Format is 'yyyymmdd_HHMMSS' +% +% projdir: Directory where the generated data subdirectory +% (simdata_yyyymmdd_HHMMSS, where yyyymmdd_HHMMSS is +% the time stamp) will be created. +% +% tv: time vector in the units of seconds. +% +% da: A matlab array containing experimental data. This array +% has dimensions nTimePoints x nMS x nReplicates x nDoses +% where +% -nTimePoints: length(tv), i.e., the number of time points. +% -nMS: The number of measured species. Corresponds +% to values given in the mcmc_info and data_info +% structs. +% -nReplicates +% -nDoses: Number of dose combinations (initial conditions) +% +% mobj: Simbiology model object. +% +% mi: mcmc_info struct. Type 'help mcmc_info_dsg2014_mrna' or +% 'help mcmc_info_template' into the MATLAB command line to learn +% more. +% +% Optional name-value pair arguments: +% InitialDistribution: Initial distribution of walker points. This can be +% Latin hyprcube sampled (Value: 'LHS'), gaussian +% distributed (Value: 'gaussian') about the midpoint of +% mi.paramranges or uniformly distributed (Value: 'unifrand'). +% +% Width: Applies to the width of the gaussian or uniform random +% parameter distribution around the midpoint given by +% mi.paramranges. +% +% UserInitialize: The user provides a matrix of initial walker positions. +% When this input is specified, 'InitialDistribution' and +% 'Width' are ignored. +% +% FitOption: Allows for fitting to data in 3 modes: +% 'FitMedian': This mode computes the curvewise median (Default). +% of the data over the replicates, and fits the model +% to this. +% 'FitMean': Compute the mean of the replicates, and fit to this +% mean +% 'FitAll' Fit all the curves. + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +p = inputParser; +p.addParameter('InitialDistribution', 'LHS', @ischar); % LHS, gaussian, unifrand +p.addParameter('Width', 0.1, @isnumeric) +p.addParameter('UserInitialize', [], @isnumeric) +p.addParameter('FitOption', 'FitMedian', @ischar); % 'FitMean', 'FitAll' +p.addParameter('pausemode', false, @islogical) +p.addParameter('DoseNormalization', false, @islogical) +p.addParameter('stepLadder', []); % A vector of multipliers for the +% step size. +% stepLadder: first half of the nIter get divided into sets of iterations +% with +% if stepLadder is specified, the multiplier is automatically set to 1. +p.addParameter('literalStepLadder', true) +p.addParameter('multiplier', 1, @isnumeric); % every 10 iterations, +% the stepsize is multiplied by this number. Set it to something like 2 or 4 +% in the hope that the walkers +% will be able to explore more of the space during this iteration. +p.addParameter('prevtstamp', [], @ischar); +p.parse(varargin{:}); +p = p.Results; + + + + +% get the three objects. +ri = mcmc_info.runsim_info; +mi = mcmc_info.model_info; +mai = mcmc_info.master_info; + + + + +[da, mi, tv] = exportmobj(mi, data_info, p.FitOption); +di = data_info; +% +% nTopo = length(mi); +% nGeom = zeros(length(mi),1); +% for i = 1:nTopo +% nGeom(i) = length(mi(i).dataToMapTo); +% end +% +% % V2 data +% % for each topology geometry pair, compute the data to fit +% % ASSUME that the data dimensions across geometries is the same +% % only differs across topologies at most. +% % Despite this, we allow for different geometries within a topology +% % to point to different data info array elements, just that all of +% % these elements must have the same number of timepoints, measured species, +% % replicates and dosing combinations. (version 3 of this code can be even +% % more general, with each topo-geom pair getting its own cell. this will be +% % slower.) +% +% da = cell(nTopo, 1); +% +% for i = 1:nTopo % each topology +% % each of the nGeom(i) geometries has a data info array element it points to. +% % since the dimensions of these is assumed to be equal, we just use the first +% % one to set the empty array: +% data_info_element = mi(i).dataToMapTo(1); +% currda = data_info(data_info_element).dataArray; +% % Transform Experimental - compute mean or median or nothing +% currda = computeFitOption(currda, p.FitOption); +% da{i} = currda; +% tv{i} = data_info(data_info_element).timeVector; +% for j = 2:nGeom(i) % each geometry +% data_info_element = mi(i).dataToMapTo(j); +% currda = data_info(data_info_element).dataArray; +% % Transform Experimental - compute mean or median or nothing +% currda = computeFitOption(currda, p.FitOption); +% % concatenate in the 5th dimension (the geometries dimension.) +% da{i} = cat(5, da{i}, currda); +% end +% % EXPORT MODEL object to get it ready for MCMC +% % the resulting object is of class SimBiology.export.Model +% % documentation: +% % https://www.mathworks.com/help/simbio/ref/simbiology.export.model-class.html +% % Sven Mesecke's blog post on using the exported model class for +% % parameter inference applicaton. +% % http://sveme.org/how-to-use-global-optimization-toolbox-algorithms-for- +% % simbiology-parameter-estimation-in-parallel-part-i.html +% +% mobj = mi(i).modelObj; +% +% enuo = mi(i).namesUnord;% estimated names unordered +% +% ep = sbioselect(mobj, 'Type', 'parameter', 'Name', ... +% mi(i).namesUnord);% est parameters +% +% es = sbioselect(mobj, 'Type', 'species', 'Name', ... +% mi(i).namesUnord);% est species +% +% aps = [ep; es]; % active parameters and species +% +% % reorder the parameter and species so they are in the same order as that +% % in the model. +% eno = cell(length(aps), 1);% est names ordered +% ds = sbioselect(mobj, 'Type', 'species', 'Name', mi(i).dosedNames); +% emo{i} = export(mobj, [ep; es; ds]); % exported model object, dosed species names. +% SI = emo{i}.SimulationOptions; +% +% % each of the nGeom(i) geometries has a data info array element it points to. +% % since the dimensions of these is assumed to be equal, we just use the first +% % one to set the empty array: +% data_info_element = mi(i).dataToMapTo(1); +% SI.StopTime = data_info(data_info_element).timeVector(end); +% accelerate(emo{i}); +% +% mi(i).emo = emo{i}; % exported model object. +% orderingIx = zeros(length(aps),1); +% orderingIx2 = orderingIx; +% for k = 1:length(aps) +% eno{k} = aps(k).Name; +% for kk = 1:length(enuo) +% if strcmp(eno{k}, enuo{kk} ) +% orderingIx(k) = kk; % eno = enuo(orderingIx); +% % the kth element of orderingIx is kk. so the kth element of +% % enuo(orderingIx) is enuo(kk). But this is just eno(k). And eno +% % has the property of the kth element being eno(k). (as seen +% % from "if eno{k} == enuo{kk} ") +% +% orderingIx2(kk) = k; %i.e., enuo = eno(orderingIx2); +% % the kkth element of orderingIx2 is k. so the kk th element of +% % eno(orderingIx2) is eno(k). But the vector with this property is +% % simply enuo. (as seen from "if eno{k} == enuo{kk} ") +% end +% end +% end +% +% mi(i).orderingIx = orderingIx; % these two arrays will be VERY useful. +% mi(i).orderingIx2 = orderingIx2; % this one being the second. +% mi(i).namesOrd = eno; % est names ordered. +% end + +% V2 model export - export with all parameters, and set fixed and estimated +% parameters per iteration of mcmc. One exported model for each topology +% make sure the reordering of the parameters when exporting is carefully +% taken care of. + +%% COMPUTE INITIAL WALKER POSITIONS +% a very cool idea: if a parameter with the same semantic meaning +% appears as individual parameters across different topologies and +% geometries, then we expect that generally the final estimated values +% should be close between the different verions of the parameter +% (the number of RNAP in extract 1, extract 2 and so on should be similar +% to an order of magnitude, even if they are differet.) +% To be clear, this is not saying that parameters that get shared across +% topologies and geometries need to be close. Those are EQUAL BY DEFINITION. +% All it is saying is that within a master vector if a parameter is semantically +% similar to another, they should have the same STARTING values. + +if isempty(p.UserInitialize) + minit = integrableLHS_v2(mi, mai, ri, ... + 'distribution', p.InitialDistribution, ... + 'width', p.Width, 'Parallel', ri.parallel); + +else + minit = p.UserInitialize; + % assume all the user defined points are integrable. +end + +%% SETUP FUNCTIONS +% setup the log prior, log likelihood function and lognormvec functions +lognormvec=@(res,sig) -(res./sig).^2 -log(sqrt(2*pi)).*sig; + +logprior = @(logp) all(mai.paramRanges(:, 1) < logp) &&... + all(logp < mai.paramRanges(:,2)); + +sigg = ri.stdev/ri.tightening; + + +% need to transform the data array to summary stats before +% sending it into the gen residuals function. +mv = mai.masterVector; +estParamIx = setdiff((1:length(mv))', mai.fixedParams); + +loglike = @(logp) gen_residuals_v2(logp, estParamIx, ... + mv, da,... + tv, mi, lognormvec, sigg); + +% BURN IN: run the burn in simulation +if isempty(p.UserInitialize) + if ~isempty(p.stepLadder) + disp('Step size ladder being used, skipping burn in phase') + p.stepLadder + m_burnin = minit; + else + tic + [m_burnin] =gwmcmc_vse(minit,{logprior loglike},... + ri.nPoints,... + 'StepSize',ri.stepSize , ... + 'ThinChain',ri.thinning,... + 'Parallel', ri.parallel); + toc + end + minit = m_burnin(:,:,end); +else + disp('User initialized intitial walker positions, skipping burn in phase') +end + +% specify where to save things +cfname = cell(ri.nIter, 1); +specificproj = [projdir '/simdata_' tstamp]; + +%% we save useful variables in a one off manner here (ie, outside the loops) +fname = ['full_variable_set_' tstamp]; % filename +save([specificproj '/' fname]); + +% run the actual simuations, saving the data every iteration +stepMultipliers = ones(1, ri.nIter); +if ~isempty(p.stepLadder) + if p.literalStepLadder + stepMultipliers = p.stepLadder; + else + numItersPerStep = round(ri.nIter/(2*length(p.stepLadder))); + for ii = 1:length(p.stepLadder) + ixToSet = (((ii-1)*numItersPerStep)+1):(ii*numItersPerStep); + stepMultipliers(ixToSet) = p.stepLadder(ii); + end + end + +end + + +for i = 1:ri.nIter % + disp(['Iteration number ' num2str(i) '.']); + if p.pausemode + if ~mod(i, 2) + fprintf('Pausing for 5 minutes to cool the CPU before starting run number %d. \n', i); + pause(300) + end + end + if isempty(p.stepLadder) && (i == 5 || ~mod(i, 5)) + ssize = p.multiplier*ri.stepSize; + fprintf('Mixup round! The step size for this iteration is set to \n %d * %d = %d.\n',... + p.multiplier, ri.stepSize, ssize); + else + ssize = ri.stepSize; + end + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% refresh parallel pool to free memory on windows... (sigh)### + +% +% currpool = gcp('nocreate'); +% if (~mod(i, 5)) +% if ~isempty(currpool) +% nWorker = currpool.NumWorkers; +% delete(gcp('nocreate')) +% parpool(nWorker) +% end +% end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + + + tic + fprintf('starting mcmc %d\n', i); + fprintf('current step size: %d\n', ssize*stepMultipliers(i)); + [m] = gwmcmc_vse(minit,{logprior loglike},... + ri.nPoints, ... + 'StepSize',ssize*stepMultipliers(i) , ... + 'ThinChain',ri.thinning, 'Parallel', ri.parallel); + fprintf('ending mcmc %d\n', i); + toc + fname = ['mcmc' tstamp '_ID' num2str(i)] ; + cfname{i} = fname; + save([specificproj '/' fname], 'm'); + % the only thing that is different in each run are the above + % pause(1) + minit = m(:,:,end);% + 0.1*randn(size(m(:,:,end-1))); + clear m +end + +% generate log file +if isempty(p.UserInitialize) + initialization_used = p.InitialDistribution; +else + initialization_used = 'User_initialized'; +end + +mcmc_log_v2(tstamp,projdir, specificproj, mcmc_info, data_info,... + initialization_used, ssize*stepMultipliers, p.prevtstamp); +end + + + diff --git a/mcmc_simbio/src/mcmc_traj_CustomSpecies.m b/mcmc_simbio/src/mcmc_traj_CustomSpecies.m new file mode 100755 index 0000000..dbc33e8 --- /dev/null +++ b/mcmc_simbio/src/mcmc_traj_CustomSpecies.m @@ -0,0 +1,924 @@ +function fighandle = mcmc_traj_CustomSpecies(em, mi, marray, titl, lgds, varargin) +% +% Plot the data time course trajectories and simulated model trajectories +% for each dose and measured species. The doses are arranged in rows of a +% subplot, or all collapsed into a single row. Each measured species has its +% own figure. +% +% Subplot arrangement: +% - Subplot Column: The column corresponds to a measured species. If there +% are multiple measured species, then multiple figures are generated. +% If the separateExpSim optional input parameter's value is set to +% true, then there are two columns, the first one corresponding the +% experimental data and the second corresponding to the simulated data. +% - Subplot Rows: Default is to use one row for each dose. But if the +% collateDoses input parameter is set to true, then all the doses +% get plotted on a single row. +% +% The experimental data and the simulation may be plotted in a few different +% ways: Mean + standard deviation, (curvewise) median + rest of the curves, +% just the curves, just the mean, just the median. +% The default is to use the median for the experimental data, and the mean +% + standard deviation for the simulated curves. +% The standard deviation is plotted as a shaded region. When the individual +% curves are plotted, they are plotted as thin lines: solid for experimental +% data and dotted for simulations. +% +% INPUTS +% em: The exported simbiology model object that is to be simulated. +% This is created when the mcmc_runsim is run, and the parameters, species an +% doses that can be set are predefined. +% +% data_info: This is the data info struct that contains the data and the +% related information. +% +% mcmc_info: This is the mcmc info struct that contains info on the mcmc +% run (including which species are dosed, measured etc.) +% +% marray: A numerical array of dimensions nParam x nWalkers x nSamp +% or nPoints x nParam. +% +% OPTIONAL NAME VALUE PAIRS +% collateDoses: Default is false. If true, all the doses get plotted on the +% same row of the subplots. +% +% separateExpSim: Default is false. If true, the experimental data and the +% simulation graphs are each given their own column. +% +% ExpMode: How to plot the experimental data. Can be 'mean', 'median' +% 'meanstd','medianstd', 'mediancurves', 'meancurves', 'curves' or 'none'. +% Default is 'median'. +% +% SimMode: How to plot the simulated data. Can be 'mean', 'median' +% 'meanstd','medianstd', 'mediancurves', 'meancurves', 'curves' or 'none'. +% Default is 'median'. +% If both the Exp and Sim Mode are none, or if the separateExpSim is set to +% true, and either mode are none, then an error is thrown. +% +% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % +% How to specify TITLES and LEGENDS. +% Titles and Legends depend on the combination of CollatedDoses and separateExpSim +% +% CollatedDoses 1; separateExpSim 1 +% The subplots within each species' figure are arranged as 1 x 2. +% +% Title: This should we a cell array of strings of size 1 x 2 x nMS, where nMS is the +% number of measured species. The first column corresponds to the experimental +% data, and the second to the simulated data. Each string should specify the +% measures species that is being displayed in the plot, and whether it is +% experimental or simulated data. Furthermore, You should also specify +% what kind of statistic is being shown: mean or median with standard +% deviation or just sample curves etc. +% Legends: This should be a cell array of strings of dimension 1 x nICs or +% 2 x nICs (the two rows corresponding to experimental data column, +% and simulated data column respectively). If either ExpMode or SimMode are +% 'none', then the dimension must be 1 x nICs. If the dimension is 1 x nICs, +% and both ExpMode and SimMode are specified, then the same legend is used for +% both. +% +% CollatedDoses 1; separateExpSim 0 +% Here the subplots are arranged as 1 by 1 for each species. +% +% Title: This should be a cell array of strings of size 1 x nMS, where nMS is the +% number of measured species. Each string corresponds to one measured species. +% You should also probably use this place to specify what the statistics being +% plotted are: (mean median or none) with (std, curves or none) for both +% experimental data and simulated data. +% +% Legends: This should be a cell array of strings of dimension 1 x (nICs + 1) +% The strings should describe the curves corresponding to Dose 1 of +% experimental data, Dose 1 of simulated data, Doses 2 to last of +% experimental data. For the simulated data doses 2 to last, the fact that +% the same colors are used for the same dose for both the simulated and +% experimental data should be used to interpret the simulated data curves. +% If either ExpMode or SimMode are 'none', then the dimension must +% be 1 x nICs. The same legend sting array is used for every measured +% species. +% +% CollatedDoses 0; separateExpSim 1 +% Here the number of subplots is nICs x 2 per figure, and there is one +% figure for each species. +% +% Title: This should be a cell array of size nICs x 2 x nMS, where nMS +% is the number of measured species. +% Legends: No legend array is needed. +% +% CollatedDoses 0; separateExpSim 0 +% Number of subplots: nICs x 1 per figure, and there is one figure for +% each species. +% +% Title: This should be a cell array of size nICs x 1 x nMS, where nMS +% is the number of measured species. +% Legends: No legend array is needed. In the first dose, the experimental +% data and simulated data plots are labeled as 'exp' and 'sim' +% respectively. +% +% +% +% +% +% +% If SimMode of ExpMode are 'curves', then the curves are used in the legend. +% If Either of them are none, then no legend is used. +% +% TITLES: +% +% +% +% If either the ExpMode or the SimMode are 'curves', then the +% + +% Specify the title and legend inputs as follows: +% For +% The legend that gets specified, if one is to be specified +% (see 'Conditions under which legends are included in the plots'), +% for both ExpMode and SimMode is as follows: +% 'mean', 'median': Specify legend for the mean or median curves. +% + +% +% If collateDoses is true, then the legends are the doses, otherwise the +% titles have the dose information, and the legends depend on the summary +% and spread statistics displayed in each subplot. +% +% The plot titles are taken from the data info struct's measuredNames field. +% If that field is empty, then the measured species field of the mcmc info +% struct is used. Dosing information is taken from the dosedNames and the +% dosedVals fields of the data info struct, and if these are not populated, +% then it is taken from the dosedNames and dosedVals fields of the mcmc_info +% struct. +% +% When the collateDoses option is false, i.e., each dose is +% is plotted in a separate row, then the dose values are also used in the +% title string. If collateDoses is true, then the dose info is used to produce +% the legend strings. Depending on the values of the options ExpSummary, ExpSpread, +% SimSummary, and SimSpread, we also include legends for the corresponding lines +% (if there are any) for the first dose. +% +% +% +% -------------------------------------------------------------------------- + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +%% precompute a bunch of things to set the defaults for this function +% Number of simulation curves to plot + +p = inputParser; +p.addParameter('nSimCurves', 50, @isnumeric); +p.addParameter('collateDoses', false, @islogical); +p.addParameter('separateExpSim', false, @islogical); +p.addParameter('just_data_info', false, @islogical); +p.addParameter('subplot_arrangement', [], @isnumeric); % [nrows ncols]. Must have nrows*ncols = ndoses. only gets used if collate doses is false +% Modes for the next two inputs: 'mean', 'median' 'meanstd', 'medianstd' +% 'mediancurves', 'curves' +p.addParameter('ExpMode', 'median', @ischar); +p.addParameter('SimMode', 'meanstd', @ischar); +p.addParameter('title', {}, @iscell); +p.addParameter('legends', {}, @iscell); +p.addParameter('savematlabfig', false, @islogical); % if this is true, then projdir and tstamp must be specified. +p.addParameter('savejpeg', false, @islogical); % if this is true, then projdir and tstamp must be specified. +p.addParameter('projdir', [], @ischar); +p.addParameter('tstamp', [], @ischar); +p.addParameter('extrafignamestring', [], @ischar); +p.parse(varargin{:}) +p = p.Results; + +if p.separateExpSim && (p.ExpMode == 'none' || p.SimMode == 'none') + error(['Cant have unspecified Experimental data or Simulation Data '... + 'if the separateExpSim is set to true']) +end + +if p.just_data_info + % just plot the data in data info + % One plot per measured species in each data info. All doses collated + % in the same plot. + fighandle = cell(length(di), 1); + + for dID = 1:length(di) + currdi = di(dID); + [expsummst, expspreadst] = computeDataStats(currdi.dataArray, p.ExpMode); + % dimensionLabels = currdi.dimensionLabels; + % expmax = computeMaxes(expsummst, expspreadst, p.ExpMode, dimensionLabels); + dNames = currdi.dosedNames; + dVals = currdi.dosedVals; + [ndNames, nICs] = size(dVals); + assert(length(dNames) == ndNames); + linehandle = zeros(nICs, 1); + % ptchhandle = zeros(nICs, 1); + nMS = length(currdi.measuredNames); + + tv = currdi.timeVector; + timeUnits = currdi.timeUnits; + tv = converttosec(tv, timeUnits); + colorz = parula(nICs+2); + for msnum = 1:nMS + fighandle{dID}(msnum) = figure; + ax = gca; + legendentry = cell(ndNames, 1); + for i=1:nICs + [ax, linehandle(i)] = ... + plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + legendentry{i} = []; + + for dnID = 1:ndNames-1 + legendentry{i} = [legendentry{i} dNames{dnID} ' = ' num2str(dVals(dnID, i)) ', ']; + end + + legendentry{i} = [legendentry{i} dNames{ndNames} ' = ' num2str(dVals(ndNames,i ))]; + end + legend(linehandle, legendentry); + title(currdi.measuredNames{msnum}{1:end}) + + end + + + end + + +else + + % Compute the y axis limits for each measured species. All the y axis for a + % given measured species are set to the max y axis limits. + + %% set the number of curves to simulate + % number of walkers is the second dimension of the 3D version of the + % paraemter array OR if the parameter array is 2D, it is taken from the + % mi array. + if ndims(marray) == 3 + % compute the number of walkers + nWalkers = size(marray, 2); + m = marray(:,:)'; % the parameter array is now #points x #params + elseif ismatrix(marray) + % nWalkers = mi.nW; + m = marray; % assume that the 2 dims are correct - npoints x nparams + end + + % Number of curves to simulate is the minimum of the specified number and the + % number of available walkers. + % if p.nSimCurves > nWalkers + % p.nSimCurves = nWalkers; + % end + + if p.nSimCurves > size(m, 1) + p.nSimCurves = size(m, 1); + end + + %% initialize things + [nDSP, nICs] = size(mi.dosedVals); % number of dosed species, + % and number of dose combinations + + dn = mi.dosedNames; %cell array + dose = mi.dosedVals'; + % recall from the data_info documentation: + % 'dosedVals': A matrix of dose values of size + % # of dosed species by # of dose combinations + % thus dose has dimensions #combos x #species + + % convert time vector to seconds. + tv = di.timeVector; + timeUnits = di.timeUnits; + tv = converttosec(tv, timeUnits); + + nts = length(tv); + nMS = length(mi.measuredSpecies); + + % initialize arrays (nominal array is: + % timepoints x measured outputs x nSimCurves x doses ) + da = zeros(nts, nMS, p.nSimCurves, nICs); + ms = mi.measuredSpecies; + dv = mi.dosedVals; + %% + % figure out how to incorporate Extract differences too. + % !TODO + + %% Simulate the model for the given parameters. + % set parameters in the model + % for each dose simulate the model + % simulate the model + + [da, idxnotused] = simulatecurves(em,m, p.nSimCurves, dose, tv, ms); + % compute the simulation maxes, with the non - integrable points removed. + pointstouse = setdiff(1:(p.nSimCurves),idxnotused); + if isempty(pointstouse) + error('none of the points are integrable. Something has gone wrong...') + end + %% Compute relevant statistics depending on what is specified in the inputs. + % for the experimental data. + [expsummst, expspreadst] = computeDataStats(di.dataArray, p.ExpMode); + [simsummst, simspreadst] = computeDataStats(da, p.SimMode); + + dimensionLabels = {'time points', 'measured species', 'replicates', 'doses'}; + expmax = computeMaxes(expsummst, expspreadst, p.ExpMode, dimensionLabels); + simmax = computeMaxes(simsummst, simspreadst, p.SimMode, dimensionLabels); + colorz = parula(nICs+2); + colorz2 = summer(nICs+2); + colorz3 = winter(nICs+2); + fighandle = zeros(nMS, 1); + % titl = p.title; + % legs = p.legends; + + for msnum = 1:nMS + fighandle(msnum) = figure; + ax = gca; + if p.collateDoses + if p.separateExpSim + % SEPARATEEXPSIM 1 , COLLATEDOSES 1 + ax = subplot(1, 2, 1); % get axis + linehandle = zeros(nICs, 1); + ptchhandle = zeros(nICs, 1); + for i=1:nICs + [ax, linehandle(i)] = ... + plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); + end + + legends([linehandle], legs(1,:)); + title(titl{1, 1, msnum}); + % !! p.legends must be a cell array of size 2 x nICs + % p.title must be a 2 x nMS cell array containing titles + % specifying experiment and simulation for a given measures species. + % can talk about what the summary and spread statistic refer to. + ax = subplot(1, 2, 2); + for i=1:nICs + [ax, linehandle] = ... + plotintoaxis(ax, p.SimMode,... + tv, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '--',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', ':',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + end + % legends([linehandle(1); ptchhandle(1); linehandle(2:end)], + % legs(2,:)); + legends([linehandle], legs(2,:)); + title(titl{1, 2, msnum}) + + else + % SEPARATEEXPSIM 0 , COLLATEDOSES 1 + + linehandle = zeros(nICs, 1); + ptchhandle = zeros(nICs, 1); + + linehandle2 = zeros(nICs, 1); + ptchhandle2 = zeros(nICs, 1); + + for i=1:nICs + [ax, linehandle] = ... + plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + end + + for i=1:nICs + [ax, linehandle2] = ... + plotintoaxis(ax, p.SimMode,... + tv, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz2(i, :),... + 'LineStyle', '-.',... + 'LineWidth', 1,... + 'SpreadColor', colorz2(i, :),... + 'SpreadLineStyle', ':',... + 'SpreadLineWidth', 0.25,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle2 + end + title(titl{msnum}); + % !! p.legends must be a legend array saying exp dose 1, + % sim dose 1, exp dose 2 to end. + legends([linehandle(1); linehandle2(1); linehandle(2:end)],... + p.legends); + end + else + if ~isempty(p.subplot_arrangement) + assert(numel(p.subplot_arrangement) == 2); + assert(prod(p.subplot_arrangement) == nICs); + pCell = num2cell(p.subplot_arrangement); + [nrows, ncols] = pCell{:}; + + + linehandle = zeros(nrows, ncols); + ptchhandle = zeros(nrows, ncols); + + linehandle2 = zeros(nrows, ncols); + ptchhandle2 = zeros(nrows, ncols); + + for i = 1:nICs + rowIX = floor((i-1)/ncols)+1; + colIX = i-floor((i-1)/ncols)*ncols; + + if p.separateExpSim + warning('Both subplot arrangement and separate experiment and sim are specified.\n Not going to do anything') + % future version : just make two figures. + + % SEPARATEEXPSIM 1 , COLLATEDOSES 0, + % subplot_arrangement specified. +% +% ind = (i-1)*2+1; +% ax = subplot(nICs, 2, ind); % exp data plot. +% [ax, linehandle] = ... +% plotintoaxis(ax, p.ExpMode,... +% tv, expsummst, expspreadst, ... +% i, msnum, ... +% 'LineColor', colorz(i, :),... +% 'LineStyle', '-',... +% 'LineWidth', 2,... +% 'SpreadColor', colorz(i, :),... +% 'SpreadLineStyle', '--',... +% 'SpreadLineWidth', 0.5,... +% 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle +% % set title +% title(titl{i, 1, msnum}); +% ind = (i-1)*2+2; +% ax = subplot(nICs, 2, ind); % simulated data plot +% [ax, linehandle] = ... +% plotintoaxis(ax, p.SimMode,... +% tv, simsummst, simspreadst, ... +% i, msnum, ... +% 'LineColor', colorz(i, :),... +% 'LineStyle', '-.',... +% 'LineWidth', 2,... +% 'SpreadColor', colorz(i, :),... +% 'SpreadLineStyle', ':',... +% 'SpreadLineWidth', 0.5,... +% 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle +% % set title +% title(titl{i, 2, msnum}); +% % in this case, the title has to be a cell array +% % of dimensions nICs x 2 x nMS + else + % % SEPARATEEXPSIM 0 , COLLATEDOSES 0 + + + ax = subplot(nrows, ncols, i); % start plotting row first. ugh. why matlab, why? + [ax, linehandle(rowIX, colIX)] = plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , , ptchhandle(i) + hold on + [ax, linehandle2(rowIX, colIX)] = ... + plotintoaxis(ax, p.SimMode,... + tv, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz2(i, :),... + 'LineStyle', '-.',... + 'LineWidth', 1,... + 'SpreadColor', colorz2(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.25,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) ,, ptchhandle2(i) + hold on + % set titles + title(titl{i, 1, msnum}); + % in this case, the p.title has to be a cell array + % of dimensions + % nICs x 1 x nMS + % set legends only for the top subplot. + % and distinguish the experimental and simulated data. + + if i == 1 + legend([linehandle(1); linehandle2(1)],... + {'exp', 'sim'}, 'Location', 'SouthEast') + end + end + end + + else + for i = 1:nICs + if p.separateExpSim + + % SEPARATEEXPSIM 1 , COLLATEDOSES 0 + + ind = (i-1)*2+1; + ax = subplot(nICs, 2, ind); % exp data plot. + [ax, linehandle] = ... + plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + % set title + title(titl{i, 1, msnum}); + ind = (i-1)*2+2; + ax = subplot(nICs, 2, ind); % simulated data plot + [ax, linehandle] = ... + plotintoaxis(ax, p.SimMode,... + tv, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-.',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', ':',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + % set title + title(titl{i, 2, msnum}); + % in this case, the title has to be a cell array + % of dimensions nICs x 2 x nMS + else + % % SEPARATEEXPSIM 0 , COLLATEDOSES 0 + + linehandle = zeros(nICs, 1); + ptchhandle = zeros(nICs, 1); + + linehandle2 = zeros(nICs, 1); + ptchhandle2 = zeros(nICs, 1); + + ax = subplot(nICs, 1, i); + [ax, linehandle(i)] = plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , , ptchhandle(i) + hold on + [ax, linehandle2(i)] = ... + plotintoaxis(ax, p.SimMode,... + tv, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz2(i, :),... + 'LineStyle', '-.',... + 'LineWidth', 1,... + 'SpreadColor', colorz2(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.25,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) ,, ptchhandle2(i) + hold on + % set titles + title(titl{i, 1, msnum}); + % in this case, the p.title has to be a cell array + % of dimensions + % nICs x 1 x nMS + % set legends only for the top subplot. + % and distinguish the experimental and simulated data. + + if i == 1 + legend([linehandle(1); linehandle2(1)],... + {'exp', 'sim'}) + end + end + end + + end + + + end + + % save figure here + if p.savematlabfig + if isempty(p.projdir) || isempty(p.tstamp) + warning('timestamp and project directory not specified. Nothing will be saved.') + else + specificproj = [p.projdir '/simdata_' p.tstamp]; + saveas(gcf, [specificproj '/traj' p.tstamp num2str(msnum) p.extrafignamestring]); + + end + end + + if p.savejpeg + if isempty(p.projdir) || isempty(p.tstamp) + warning('timestamp and project directory not specified. Nothing will be saved.') + else + specificproj = [p.projdir '/simdata_' p.tstamp]; + print(gcf, '-djpeg', '-r200', [specificproj '/traj' p.tstamp num2str(msnum) p.extrafignamestring]) + end + end + end +end + + + +end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function tv = converttosec(tv, timeUnits) +% convert weeks, days, hours, or minutes to seconds. +switch timeUnits + case 'weeks' + tv = tv*7*24*3600; + case 'days' + tv = tv*24*3600; + case 'hours' + tv = tv*3600; + case 'minutes' + tv = tv*60; + case 'seconds' + tv = tv; +end +end + +function [timeDim, measuredDim, doseDim, replicateDim] =... + dimensionLabelMaps(dimensionLabels) + +% dimension lebels have to be the strings +% 'replicates', 'time points', 'measured species', 'doses'. +replicateDim = strcmp(dimensionLabels, 'replicates'); +replicateDim = find(replicateDim); +if isempty(replicateDim) + error('There is no ''replicates'' entry in the dimension labels array.') +end +timeDim = strcmp(dimensionLabels, 'time points'); +timeDim = find(timeDim); +if isempty(timeDim) + error('There is no ''time points'' entry in the dimension labels array.') +end +measuredDim = strcmp(dimensionLabels, 'measured species'); +measuredDim = find(measuredDim); +if isempty(measuredDim) + error('There is no ''measured species'' entry in the dimension labels array.') +end +doseDim = strcmp(dimensionLabels, 'doses'); +doseDim = find(doseDim); +if isempty(doseDim) + error('There is no ''doses'' entry in the dimension labels array.') +end + +end + + +function datamax = computeMaxes(summst, spreadst, dispmode, dimensionLabels) +[tD, mD, dD, rD] = dimensionLabelMaps(dimensionLabels); + +switch dispmode + case 'mean' + % summst must be a time x measured species x 1 x doses array. + datamax = max(max(summst, [],1), [], 4); % max over time and doses. + case 'median' + % summst must be a time x measured species x 1 x doses array. + datamax = max(max(summst, [],1), [], 4); + case 'meanstd' + % summst must be a time x measured species x 1 x doses array. + % spreadst must be a time x measured species x 1 x doses array. + summ_spread_st = summst + spreadst; + datamax = max(max(summ_spread_st, [],1), [], 4); + case 'meancurves' + datamax = max(max(max(spreadst, [],1), [], 4), [], 3); + case 'medianstd' + % summst must be a time x measured species x 1 x doses array. + % spreadst must be a time x measured species x 1 x doses array. + summ_spread_st = summst + spreadst; + datamax = max(max(summ_spread_st, [],1), [], 4); + case 'mediancurves' + datamax = max(max(max(cat(3,spreadst, summst), [],1), [], 4), [], 3); + case 'curves' + datamax = max(max(max(spreadst, [],1), [], 4), [], 3); + otherwise + error(['Invalid data display mode. Must be one of: ''mean'','... + ' ''median'' , ''meanstd'',''medianstd'', ''mediancurves'', ''curves''.']) +end +end + + +%!! +function [summst, spreadst] = computeDataStats(dataArray, dispmode) +% da: data array +% datasummary: mean, median or none +% dataspread: curves, std or none. +% rD: replicates dimension + +switch dispmode + case 'mean' + summst = mean(dataArray, 3); + case 'median' + % sum over the time dimension + % tD MUST be 1 for this to work.. I tried being fully general, + % but what is the point? It's unnecessarily difficult. + % compute the indexes of the median (in terms of sum / integral) + % curves over the replicates + [ix, mdvals] = medianIndex(sum(dataArray, 1), 3); + % again, rD MUST be 3. + summst = medianReplicate(dataArray, ix); + % spreadstatistic is the empty vector + spreadst = []; + case 'meanstd' + summst = mean(dataArray, 3); + spreadst = std(dataArray, 0, 3); + case 'meancurves' + summst = mean(dataArray, 3); + spreadst = dataArray; + case 'medianstd' + [ix, mdvals] = medianIndex(sum(dataArray, 1), 3); + summst = medianReplicate(dataArray, ix); + spreadst = std(dataArray, 0, 3); + case 'mediancurves' + [ix, mdvals] = medianIndex(sum(dataArray, 1), 3); + summst = medianReplicate(dataArray, ix); + spreadst = allButMedianCurve(dataArray, ix); + case 'curves' + summst = []; + spreadst = dataArray; + + otherwise + error(['Invalid data display mode. Must be one of: ''mean'','... + ' ''median'' , ''meanstd'',''medianstd'', ''meancurves'','... + ' ''mediancurves'', ''curves''.']) +end +end + + + +%!! + +function nonMedianCurves = allButMedianCurve(dataArray, ix) +% data array must be time x measuredspecies x replicates x doses + +% Get the median curves. Can this be done via pure vector indexing? +% !UNIMPORTANT but could be fun to think about sometime. +nonMedianCurves = zeros(size(dataArray, 1), size(dataArray, 2), ... + size(dataArray, 3)-1, size(dataArray, 4)); +ixx = 1:size(dataArray, 3); +for i = 1:size(dataArray, 2) + for j = 1:size(dataArray, 4) + ixxx = setdiff(ixx , ix(1,i, 1,j)); % remove median curve index + for k = 1:size(nonMedianCurves, 3) + nonMedianCurves(:,i,k,j) = dataArray(:, i, ixxx(k), j); + end + end +end +end + + +function [title, legend] = titlelegend(p, di, mi) +end + +function [ax, varargout] = plotintoaxis(ax, mode, tv,... + summst, spreadst, dosei, msi, varargin) +% plot a single summary statistic and spread statistic on a given axis +% optional name value pair arguments have names: +% +% 'LineColor' +% 'LineStyle' +% 'LineWidth' +% 'SpreadColor' +% 'SpreadLineStyle' +% 'SpreadLineWidth' +% 'FaceAlpha' +% +p = inputParser; +p.addParameter('LineColor', parula(1), @isnumeric); +p.addParameter('LineStyle','-' , @ischar); +p.addParameter('LineWidth', 2, @isnumeric); +p.addParameter('SpreadColor', summer(1), @isnumeric); +p.addParameter('SpreadLineStyle', ':', @ischar); % gets used if the spread is curves. +p.addParameter('SpreadLineWidth', 2, @isnumeric); + +% gets used if the spread is standard deviation +p.addParameter('FaceAlpha', 0.25, @isnumeric); + +% shading. +p.parse(varargin{:}) +p = p.Results; + +% make the axes to be plotted on current, and bring the relevant figure into focus +axes(ax); + +if strcmp(mode, 'meanstd') || strcmp(mode, 'medianstd') + % plot summary and std as the spread. + [linehandle, ptchhandle] =... + boundedline(tv, summst(:,msi,1, dosei),... + spreadst(:,msi,1, dosei)); + set(ptchhandle, ... + 'FaceColor', p.SpreadColor,... + 'FaceAlpha', p.FaceAlpha); + set(linehandle, ... + 'Color', p.LineColor,... + 'LineStyle', p.LineStyle,... + 'LineWidth', p.LineWidth); + hold on + outstuff = {linehandle, ptchhandle}; + +elseif strcmp(mode, 'mean') || strcmp(mode, 'median') + % plot only the mean or median (no spread) + [linehandle] = plot(tv, summst(:,msi,1, dosei)); + set(linehandle, ... + 'Color', p.LineColor,... + 'LineStyle', p.LineStyle,... + 'LineWidth', p.LineWidth); + hold on + outstuff = {linehandle}; + +elseif strcmp(mode, 'mediancurves') || strcmp(mode, 'meancurves') + + [linehandle] = plot(tv, ... + summst(:,msi,1, dosei)); + set(linehandle, ... + 'Color', p.LineColor,... + 'LineStyle', p.LineStyle,... + 'LineWidth', p.LineWidth); + hold on + + spreadhandles = zeros(size(spreadst, 3), 1); + for j = 1:size(spreadst, 3) % number of replicates + spreadhandles(j) = plot(tv, spreadst(:,msi,j, dosei)); + set(spreadhandles(j),... + 'Color', p.SpreadColor,... + 'LineStyle', p.SpreadLineStyle,... + 'LineWidth', p.SpreadLineWidth); + hold on + end + outstuff = {linehandle, spreadhandles}; + +elseif strcmp(mode, 'curves') + spreadhandles = zeros(size(spreadst, 3),1); + for j = 1:size(spreadst, 3) + spreadhandles(j) = plot(tv, ... + spreadst(:,msi,j, dosei)); + set(spreadhandles(j),... + 'Color', p.SpreadColor,... + 'LineStyle', p.SpreadLineStyle,... + 'LineWidth', p.SpreadLineWidth); + hold on + end + outstuff = {spreadhandles(1)}; +else + warning(['No valid exp data plotting format'... + ' specified. No experimental data will be plotted.']) +end +hold on + +% process variable outputs +nout = nargout-1; +varargout(1:nout) = outstuff(1:nout); + + + +end + + + + + + + + + + + + + diff --git a/mcmc_simbio/src/mcmc_trajectories.m b/mcmc_simbio/src/mcmc_trajectories.m new file mode 100755 index 0000000..5092b9c --- /dev/null +++ b/mcmc_simbio/src/mcmc_trajectories.m @@ -0,0 +1,920 @@ +function [fighandle, varargout] = mcmc_trajectories(em, di, mi, marray,... + titl, lgds, varargin) +% +% Plot the data time course trajectories and simulated model trajectories +% for each dose and measured species. The doses are arranged in rows of a +% subplot, or all collapsed into a single row. Each measured species has its +% own figure. +% +% Subplot arrangement: +% - Subplot Column: The column corresponds to a measured species. If there +% are multiple measured species, then multiple figures are generated. +% If the separateExpSim optional input parameter's value is set to +% true, then there are two columns, the first one corresponding the +% experimental data and the second corresponding to the simulated data. +% - Subplot Rows: Default is to use one row for each dose. But if the +% collateDoses input parameter is set to true, then all the doses +% get plotted on a single row. +% +% The experimental data and the simulation may be plotted in a few different +% ways: Mean + standard deviation, (curvewise) median + rest of the curves, +% just the curves, just the mean, just the median. +% The default is to use the median for the experimental data, and the mean +% + standard deviation for the simulated curves. +% The standard deviation is plotted as a shaded region. When the individual +% curves are plotted, they are plotted as thin lines: solid for experimental +% data and dotted for simulations. +% +% OUTPUTS: fighandle and tw optional outputs: +% varargout{1} = data array of dimensions nTimepoints x nMeasuredSpecies x +% nSimCurves x nDoseCombinations +% varargout{2} = idxnotused. This is the set of indices of the third +% (nSimCurves) dimension that have at least one dose that led to an error +% during the simulation. The corresponding vector in the da array will have +% all NaNs. +% +% INPUTS +% em: The exported simbiology model object that is to be simulated. +% This is created when the mcmc_runsim is run, and the parameters, species an +% doses that can be set are predefined. +% +% data_info: This is the data info struct that contains the data and the +% related information. +% +% mcmc_info: This is the mcmc info struct that contains info on the mcmc +% run (including which species are dosed, measured etc.) +% +% marray: A numerical array of dimensions nParam x nWalkers x nSamp +% or nPoints x nParam. +% +% OPTIONAL NAME VALUE PAIRS +% collateDoses: Default is false. If true, all the doses get plotted on the +% same row of the subplots. +% +% separateExpSim: Default is false. If true, the experimental data and the +% simulation graphs are each given their own column. +% +% ExpMode: How to plot the experimental data. Can be 'mean', 'median' +% 'meanstd','medianstd', 'mediancurves', 'meancurves', 'curves' or 'none'. +% Default is 'median'. +% +% SimMode: How to plot the simulated data. Can be 'mean', 'median' +% 'meanstd','medianstd', 'mediancurves', 'meancurves', 'curves' or 'none'. +% Default is 'median'. +% If both the Exp and Sim Mode are none, or if the separateExpSim is set to +% true, and either mode are none, then an error is thrown. +% +% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % +% How to specify TITLES and LEGENDS. +% Titles and Legends depend on the combination of CollatedDoses and separateExpSim +% +% CollatedDoses 1; separateExpSim 1 +% The subplots within each species' figure are arranged as 1 x 2. +% +% Title: This should we a cell array of strings of size 1 x 2 x nMS, where nMS is the +% number of measured species. The first column corresponds to the experimental +% data, and the second to the simulated data. Each string should specify the +% measures species that is being displayed in the plot, and whether it is +% experimental or simulated data. Furthermore, You should also specify +% what kind of statistic is being shown: mean or median with standard +% deviation or just sample curves etc. +% Legends: This should be a cell array of strings of dimension 1 x nICs or +% 2 x nICs (the two rows corresponding to experimental data column, +% and simulated data column respectively). If either ExpMode or SimMode are +% 'none', then the dimension must be 1 x nICs. If the dimension is 1 x nICs, +% and both ExpMode and SimMode are specified, then the same legend is used for +% both. +% +% CollatedDoses 1; separateExpSim 0 +% Here the subplots are arranged as 1 by 1 for each species. +% +% Title: This should be a cell array of strings of size 1 x nMS, where nMS is the +% number of measured species. Each string corresponds to one measured species. +% You should also probably use this place to specify what the statistics being +% plotted are: (mean median or none) with (std, curves or none) for both +% experimental data and simulated data. +% +% Legends: This should be a cell array of strings of dimension 1 x (nICs + 1) +% The strings should describe the curves corresponding to Dose 1 of +% experimental data, Dose 1 of simulated data, Doses 2 to last of +% experimental data. For the simulated data doses 2 to last, the fact that +% the same colors are used for the same dose for both the simulated and +% experimental data should be used to interpret the simulated data curves. +% If either ExpMode or SimMode are 'none', then the dimension must +% be 1 x nICs. The same legend sting array is used for every measured +% species. +% +% CollatedDoses 0; separateExpSim 1 +% Here the number of subplots is nICs x 2 per figure, and there is one +% figure for each species. +% +% Title: This should be a cell array of size nICs x 2 x nMS, where nMS +% is the number of measured species. +% Legends: No legend array is needed. +% +% CollatedDoses 0; separateExpSim 0 +% Number of subplots: nICs x 1 per figure, and there is one figure for +% each species. +% +% Title: This should be a cell array of size nICs x 1 x nMS, where nMS +% is the number of measured species. +% Legends: No legend array is needed. In the first dose, the experimental +% data and simulated data plots are labeled as 'exp' and 'sim' +% respectively. +% +% +% +% +% +% +% If SimMode of ExpMode are 'curves', then the curves are used in the legend. +% If Either of them are none, then no legend is used. +% +% TITLES: +% +% +% +% If either the ExpMode or the SimMode are 'curves', then the +% + +% Specify the title and legend inputs as follows: +% For +% The legend that gets specified, if one is to be specified +% (see 'Conditions under which legends are included in the plots'), +% for both ExpMode and SimMode is as follows: +% 'mean', 'median': Specify legend for the mean or median curves. +% + +% +% If collateDoses is true, then the legends are the doses, otherwise the +% titles have the dose information, and the legends depend on the summary +% and spread statistics displayed in each subplot. +% +% The plot titles are taken from the data info struct's measuredNames field. +% If that field is empty, then the measured species field of the mcmc info +% struct is used. Dosing information is taken from the dosedNames and the +% dosedVals fields of the data info struct, and if these are not populated, +% then it is taken from the dosedNames and dosedVals fields of the mcmc_info +% struct. +% +% When the collateDoses option is false, i.e., each dose is +% is plotted in a separate row, then the dose values are also used in the +% title string. If collateDoses is true, then the dose info is used to produce +% the legend strings. Depending on the values of the options ExpSummary, ExpSpread, +% SimSummary, and SimSpread, we also include legends for the corresponding lines +% (if there are any) for the first dose. +% +% +% +% -------------------------------------------------------------------------- + +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +%% precompute a bunch of things to set the defaults for this function +% Number of simulation curves to plot + +p = inputParser; +p.addParameter('nSimCurves', 50, @isnumeric); +p.addParameter('collateDoses', false, @islogical); +p.addParameter('separateExpSim', false, @islogical); +p.addParameter('just_data_info', false, @islogical); +p.addParameter('subplot_arrangement', [], @isnumeric); % [nrows ncols]. +% Must have nrows*ncols = ndoses. only gets used if collate doses is false +% Modes for the next two inputs: 'mean', 'median' 'meanstd', 'medianstd' +% 'mediancurves', 'curves' +p.addParameter('ExpMode', 'median', @ischar); +p.addParameter('SimMode', 'meanstd', @ischar); +p.addParameter('title', {}, @iscell); +p.addParameter('legends', {}, @iscell); +p.addParameter('savematlabfig', false, @islogical); +% if this is true, then projdir and tstamp must be specified. +p.addParameter('savejpeg', false, @islogical); +% if this is true, then projdir and tstamp must be specified. +p.addParameter('projdir', [], @ischar); +p.addParameter('tstamp', [], @ischar); +p.addParameter('extrafignamestring', [], @ischar); +p.parse(varargin{:}) +p = p.Results; + +% get the screen size for plotting. +set(0,'Units','normalized') + + +if p.separateExpSim && (strcmp(p.ExpMode,'none') || strcmp(p.SimMode, 'none')) + error(['Cant have unspecified Experimental data or Simulation Data '... + 'if the separateExpSim is set to true']) +end + +if p.just_data_info + % just plot the data in data info + % One plot per measured species in each data info. All doses collated + % in the same plot. + fighandle = cell(length(di), 1); + + for dID = 1:length(di) + currdi = di(dID); + [expsummst, expspreadst] = computeDataStats(currdi.dataArray, p.ExpMode); + % dimensionLabels = currdi.dimensionLabels; + % expmax = computeMaxes(expsummst, ... + % expspreadst, p.ExpMode, dimensionLabels); + dNames = currdi.dosedNames; + dVals = currdi.dosedVals; + [ndNames, nICs] = size(dVals); + assert(length(dNames) == ndNames); + linehandle = zeros(nICs, 1); + % ptchhandle = zeros(nICs, 1); + nMS = length(currdi.measuredNames); + + tv = currdi.timeVector; + timeUnits = currdi.timeUnits; + tv = converttosec(tv, timeUnits); + colorz = parula(nICs+2); + for msnum = 1:nMS + fighandle{dID}(msnum) = figure; + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.5, 0.8]) + ax = gca; + legendentry = cell(ndNames, 1); + for i=1:nICs + [ax, linehandle(i)] = ... + plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + legendentry{i} = []; + + for dnID = 1:ndNames-1 + legendentry{i} = ... + [legendentry{i} dNames{dnID} ' = ' num2str(dVals(dnID, i)) ', ']; + end + + legendentry{i} = ... + [legendentry{i} dNames{ndNames} ' = ' num2str(dVals(ndNames,i ))]; + end + legend(linehandle, legendentry); + %title(currdi.measuredNames{msnum}{1:end}) % what was I thinking here? + title(currdi.measuredNames{msnum}) + end + + + end + + +else + + % Compute the y axis limits for each measured species. All the y axis for a + % given measured species are set to the max y axis limits. + + %% set the number of curves to simulate + % number of walkers is the second dimension of the 3D version of the + % paraemter array OR if the parameter array is 2D, it is taken from the + % mi array. + if ndims(marray) == 3 + % compute the number of walkers + nWalkers = size(marray, 2); + m = marray(:,:)'; % the parameter array is now #points x #params + elseif ismatrix(marray) + % nWalkers = mi.nW; + m = marray; % assume that the 2 dims are correct - npoints x nparams + end + + % Number of curves to simulate is the minimum of the specified number and the + % number of available walkers. + % if p.nSimCurves > nWalkers + % p.nSimCurves = nWalkers; + % end + + if p.nSimCurves > size(m, 1) + p.nSimCurves = size(m, 1); + end + + %% initialize things + [nDSP, nICs] = size(mi.dosedVals); % number of dosed species, + % and number of dose combinations + + dn = mi.dosedNames; %cell array + dose = mi.dosedVals'; + % recall from the data_info documentation: + % 'dosedVals': A matrix of dose values of size + % # of dosed species by # of dose combinations + % thus dose has dimensions #combos x #species + + % convert time vector to seconds. + tv = di.timeVector; + timeUnits = di.timeUnits; + tv = converttosec(tv, timeUnits); + + nts = length(tv); + nMS = length(mi.measuredSpecies); + + % initialize arrays (nominal array is: + % timepoints x measured outputs x nSimCurves x doses ) + da = zeros(nts, nMS, p.nSimCurves, nICs); + ms = mi.measuredSpecies; + dv = mi.dosedVals; + %% + % figure out how to incorporate Extract differences too. + % !TODO + + %% Simulate the model for the given parameters. + % set parameters in the model + % for each dose simulate the model + % simulate the model + + [da, idxnotused] = simulatecurves(em,m, p.nSimCurves, dose, tv, ms); + % compute the simulation maxes, with the non - integrable points removed. + pointstouse = setdiff(1:(p.nSimCurves),idxnotused); + if isempty(pointstouse) + error('none of the points are integrable. Something has gone wrong...') + end + %% Compute relevant statistics depending on what is specified in the inputs. + % for the experimental data. + [expsummst, expspreadst] = computeDataStats(di.dataArray, p.ExpMode); + [simsummst, simspreadst] = computeDataStats(da(:,:,pointstouse, :), p.SimMode); + + dimensionLabels = {'time points', 'measured species', 'replicates', 'doses'}; + expmax = computeMaxes(expsummst, expspreadst, p.ExpMode, dimensionLabels); + simmax = computeMaxes(simsummst, simspreadst, p.SimMode, dimensionLabels); + expsimmax = max(expmax, simmax); %% + colorz = parula(nICs+2); + colorz2 = summer(nICs+2); + colorz3 = winter(nICs+2); + fighandle = zeros(nMS, 1); + % titl = p.title; + % legs = p.legends; + + + + + for msnum = 1:nMS + fighandle(msnum) = figure; + set(gcf,'Units', 'normalized') + set(gcf, 'Position', [0.05, 0.1, 0.5, 0.8]) + ax = gca; + if p.collateDoses + if p.separateExpSim + % SEPARATEEXPSIM 1 , COLLATEDOSES 1 + ax = subplot(1, 2, 1); % get axis + linehandle = zeros(nICs, 1); + ptchhandle = zeros(nICs, 1); + for i=1:nICs + [ax, linehandle(i)] = ... + plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); + end + +% legends([linehandle], legs(1,:)); + title(titl{1, 1, msnum}); + % !! p.legends must be a cell array of size 2 x nICs + % p.title must be a 2 x nMS cell array containing titles + % specifying experiment and simulation for a given measures species. + % can talk about what the summary and spread statistic refer to. + ax = subplot(1, 2, 2); + for i=1:nICs + [ax, linehandle] = ... + plotintoaxis(ax, p.SimMode,... + tv, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '--',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', ':',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + end + % legends([linehandle(1); ptchhandle(1); linehandle(2:end)], + % legs(2,:)); +% legends([linehandle], legs(2,:)); + title(titl{1, 2, msnum}) + + else + % SEPARATEEXPSIM 0 , COLLATEDOSES 1 + + linehandle = zeros(nICs, 1); + ptchhandle = zeros(nICs, 1); + + linehandle2 = zeros(nICs, 1); + ptchhandle2 = zeros(nICs, 1); + % plot experimental data + for i=1:nICs + [ax, linehandle] = ... + plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + end + % plot simulation data + for i=1:nICs + [ax, linehandle2] = ... + plotintoaxis(ax, p.SimMode,... + tv, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz2(i, :),... + 'LineStyle', '-.',... + 'LineWidth', 1,... + 'SpreadColor', colorz2(i, :),... + 'SpreadLineStyle', ':',... + 'SpreadLineWidth', 0.25,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle2 + end + title(titl{msnum}); + % !! p.legends must be a legend array saying exp dose 1, + % sim dose 1, exp dose 2 to end. + legends([linehandle(1); linehandle2(1); linehandle(2:end)],... + p.legends); + end + else + if ~isempty(p.subplot_arrangement) + assert(numel(p.subplot_arrangement) == 2); + assert(prod(p.subplot_arrangement) == nICs); + pCell = num2cell(p.subplot_arrangement); + [nrows, ncols] = pCell{:}; + + + linehandle = zeros(nrows, ncols); + ptchhandle = zeros(nrows, ncols); + + linehandle2 = zeros(nrows, ncols); + ptchhandle2 = zeros(nrows, ncols); + + for i = 1:nICs + rowIX = floor((i-1)/ncols)+1; + colIX = i-floor((i-1)/ncols)*ncols; + + if p.separateExpSim + warning(['Both subplot arrangement and separate experiment and sim are specified.\n ' ... + 'Not going to do anything']) + % future version : just make two figures. + + % SEPARATEEXPSIM 1 , COLLATEDOSES 0, + % subplot_arrangement specified. +% +% ind = (i-1)*2+1; +% ax = subplot(nICs, 2, ind); % exp data plot. +% [ax, linehandle] = ... +% plotintoaxis(ax, p.ExpMode,... +% tv, expsummst, expspreadst, ... +% i, msnum, ... +% 'LineColor', colorz(i, :),... +% 'LineStyle', '-',... +% 'LineWidth', 2,... +% 'SpreadColor', colorz(i, :),... +% 'SpreadLineStyle', '--',... +% 'SpreadLineWidth', 0.5,... +% 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle +% % set title +% title(titl{i, 1, msnum}); +% ind = (i-1)*2+2; +% ax = subplot(nICs, 2, ind); % simulated data plot +% [ax, linehandle] = ... +% plotintoaxis(ax, p.SimMode,... +% tv, simsummst, simspreadst, ... +% i, msnum, ... +% 'LineColor', colorz(i, :),... +% 'LineStyle', '-.',... +% 'LineWidth', 2,... +% 'SpreadColor', colorz(i, :),... +% 'SpreadLineStyle', ':',... +% 'SpreadLineWidth', 0.5,... +% 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle +% % set title +% title(titl{i, 2, msnum}); +% % in this case, the title has to be a cell array +% % of dimensions nICs x 2 x nMS + else + % % SEPARATEEXPSIM 0 , COLLATEDOSES 0 + + + ax = subplot(nrows, ncols, i); % start plotting row first. ugh. why matlab, why? + [ax, linehandle(rowIX, colIX)] = plotintoaxis(ax, p.ExpMode,... + tv, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , , ptchhandle(i) + hold on + [ax, linehandle2(rowIX, colIX)] = ... + plotintoaxis(ax, p.SimMode,... + tv, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz2(i, :),... + 'LineStyle', '-.',... + 'LineWidth', 1,... + 'SpreadColor', colorz2(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.25,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) ,, ptchhandle2(i) + hold on + % set titles + title(titl{i, 1, msnum}); + % in this case, the p.title has to be a cell array + % of dimensions + % nICs x 1 x nMS + % set legends only for the top subplot. + % and distinguish the experimental and simulated data. + + if i == 1 + legend([linehandle(1); linehandle2(1)],... + {'exp', 'sim'}, 'Location', 'SouthEast') + end + end + end + + else + for i = 1:nICs + if p.separateExpSim + + % SEPARATEEXPSIM 1 , COLLATEDOSES 0 + + ind = (i-1)*2+1; + ax = subplot(nICs, 2, ind); % exp data plot. + [ax, linehandle] = ... + plotintoaxis(ax, p.ExpMode,... + tv/60, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + ax.YLim = [0 expsimmax(msnum)]; + % set title + title(titl{i, 1, msnum}); + ind = (i-1)*2+2; + ax = subplot(nICs, 2, ind); % simulated data plot + [ax, linehandle] = ... + plotintoaxis(ax, p.SimMode,... + tv/60, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-.',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', ':',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , ptchhandle + ax.YLim = [0 expsimmax(msnum)]; + % set title + title(titl{i, 2, msnum}); + % in this case, the title has to be a cell array + % of dimensions nICs x 2 x nMS + else + % % SEPARATEEXPSIM 0 , COLLATEDOSES 0 + + linehandle = zeros(nICs, 1); + ptchhandle = zeros(nICs, 1); + + linehandle2 = zeros(nICs, 1); + ptchhandle2 = zeros(nICs, 1); + + ax = subplot(nICs, 1, i); + [ax, linehandle(i)] = plotintoaxis(ax, p.ExpMode,... + tv/60, expsummst, expspreadst, ... + i, msnum, ... + 'LineColor', colorz(i, :),... + 'LineStyle', '-',... + 'LineWidth', 2,... + 'SpreadColor', colorz(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.5,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) , , ptchhandle(i) + hold on + [ax, linehandle2(i)] = ... + plotintoaxis(ax, p.SimMode,... + tv/60, simsummst, simspreadst, ... + i, msnum, ... + 'LineColor', colorz2(i, :),... + 'LineStyle', '-.',... + 'LineWidth', 1,... + 'SpreadColor', colorz2(i, :),... + 'SpreadLineStyle', '--',... + 'SpreadLineWidth', 0.25,... + 'FaceAlpha', 0.25); % removed out arg: (doesnt work yet) ,, ptchhandle2(i) + ax.YLim = [0 expsimmax(msnum)]; + hold on + % set titles + title(titl{i, 1, msnum}); + % in this case, the p.title has to be a cell array + % of dimensions + % nICs x 1 x nMS + % set legends only for the top subplot. + % and distinguish the experimental and simulated data. + + if i == 1 + legend([linehandle(1); linehandle2(1)],... + {'exp', 'sim'}) + end + end + end + + end + + + end + + % save figure here + if p.savematlabfig + if isempty(p.projdir) || isempty(p.tstamp) + warning('timestamp and project directory not specified. Nothing will be saved.') + else + specificproj = [p.projdir '/simdata_' p.tstamp]; + saveas(gcf, [specificproj '/traj' p.tstamp num2str(msnum) p.extrafignamestring]); + + end + end + + if p.savejpeg + if isempty(p.projdir) || isempty(p.tstamp) + warning('timestamp and project directory not specified. Nothing will be saved.') + else + specificproj = [p.projdir '/simdata_' p.tstamp]; + print(gcf, '-djpeg', '-r200', [specificproj '/traj' p.tstamp num2str(msnum) p.extrafignamestring]) + end + end + end +end + +if nargout == 2 + varargout{1} = da; +elseif nargout == 3 + varargout{1} = da; + varargout{2} = idxnotused; +end + + + + + +end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function tv = converttosec(tv, timeUnits) +% convert weeks, days, hours, or minutes to seconds. +switch timeUnits + case 'weeks' + tv = tv*7*24*3600; + case 'days' + tv = tv*24*3600; + case 'hours' + tv = tv*3600; + case 'minutes' + tv = tv*60; + case 'seconds' + tv = tv; +end +end + +function [timeDim, measuredDim, doseDim, replicateDim] =... + dimensionLabelMaps(dimensionLabels) + +% dimension lebels have to be the strings +% 'replicates', 'time points', 'measured species', 'doses'. +replicateDim = strcmp(dimensionLabels, 'replicates'); +replicateDim = find(replicateDim); +if isempty(replicateDim) + error('There is no ''replicates'' entry in the dimension labels array.') +end +timeDim = strcmp(dimensionLabels, 'time points'); +timeDim = find(timeDim); +if isempty(timeDim) + error('There is no ''time points'' entry in the dimension labels array.') +end +measuredDim = strcmp(dimensionLabels, 'measured species'); +measuredDim = find(measuredDim); +if isempty(measuredDim) + error('There is no ''measured species'' entry in the dimension labels array.') +end +doseDim = strcmp(dimensionLabels, 'doses'); +doseDim = find(doseDim); +if isempty(doseDim) + error('There is no ''doses'' entry in the dimension labels array.') +end + +end + +function datamax = computeMaxes(summst, spreadst, dispmode, dimensionLabels) +[tD, mD, dD, rD] = dimensionLabelMaps(dimensionLabels); + +switch dispmode + case 'mean' + % summst must be a time x measured species x 1 x doses array. + datamax = max(max(summst, [],1), [], 4); % max over time and doses. + case 'median' + % summst must be a time x measured species x 1 x doses array. + datamax = max(max(summst, [],1), [], 4); + case 'meanstd' + % summst must be a time x measured species x 1 x doses array. + % spreadst must be a time x measured species x 1 x doses array. + summ_spread_st = summst + spreadst; + datamax = max(max(summ_spread_st, [],1), [], 4); + case 'meancurves' + datamax = max(max(max(spreadst, [],1), [], 4), [], 3); + case 'medianstd' + % summst must be a time x measured species x 1 x doses array. + % spreadst must be a time x measured species x 1 x doses array. + summ_spread_st = summst + spreadst; + datamax = max(max(summ_spread_st, [],1), [], 4); + case 'mediancurves' + datamax = max(max(max(cat(3,spreadst, summst), [],1), [], 4), [], 3); + case 'curves' + datamax = max(max(max(spreadst, [],1), [], 4), [], 3); + otherwise + error(['Invalid data display mode. Must be one of: ''mean'','... + ' ''median'' , ''meanstd'',''medianstd'', ''mediancurves'', ''curves''.']) +end +end + + +%!! + + + + +%!! + +function nonMedianCurves = allButMedianCurve(dataArray, ix) +% data array must be time x measuredspecies x replicates x doses + +% Get the median curves. Can this be done via pure vector indexing? +% !UNIMPORTANT but could be fun to think about sometime. +nonMedianCurves = zeros(size(dataArray, 1), size(dataArray, 2), ... + size(dataArray, 3)-1, size(dataArray, 4)); +ixx = 1:size(dataArray, 3); +for i = 1:size(dataArray, 2) + for j = 1:size(dataArray, 4) + ixxx = setdiff(ixx , ix(1,i, 1,j)); % remove median curve index + for k = 1:size(nonMedianCurves, 3) + nonMedianCurves(:,i,k,j) = dataArray(:, i, ixxx(k), j); + end + end +end +end + + +function [title, legend] = titlelegend(p, di, mi) +end + +function [ax, varargout] = plotintoaxis(ax, mode, tv,... + summst, spreadst, dosei, msi, varargin) +% plot a single summary statistic and spread statistic on a given axis +% optional name value pair arguments have names: +% +% 'LineColor' +% 'LineStyle' +% 'LineWidth' +% 'SpreadColor' +% 'SpreadLineStyle' +% 'SpreadLineWidth' +% 'FaceAlpha' +% +p = inputParser; +p.addParameter('LineColor', parula(1), @isnumeric); +p.addParameter('LineStyle','-' , @ischar); +p.addParameter('LineWidth', 2, @isnumeric); +p.addParameter('SpreadColor', summer(1), @isnumeric); +p.addParameter('SpreadLineStyle', ':', @ischar); % gets used if the spread is curves. +p.addParameter('SpreadLineWidth', 2, @isnumeric); + +% gets used if the spread is standard deviation +p.addParameter('FaceAlpha', 0.25, @isnumeric); + +% shading. +p.parse(varargin{:}) +p = p.Results; + +% make the axes to be plotted on current, and bring the relevant figure into focus +axes(ax); + +if strcmp(mode, 'meanstd') || strcmp(mode, 'medianstd') + % plot summary and std as the spread. + [linehandle, ptchhandle] =... + boundedline(tv, summst(:,msi,1, dosei),... + spreadst(:,msi,1, dosei)); + set(ptchhandle, ... + 'FaceColor', p.SpreadColor,... + 'FaceAlpha', p.FaceAlpha); + set(linehandle, ... + 'Color', p.LineColor,... + 'LineStyle', p.LineStyle,... + 'LineWidth', p.LineWidth); + hold on + outstuff = {linehandle, ptchhandle}; + +elseif strcmp(mode, 'mean') || strcmp(mode, 'median') + % plot only the mean or median (no spread) + [linehandle] = plot(tv, summst(:,msi,1, dosei)); + set(linehandle, ... + 'Color', p.LineColor,... + 'LineStyle', p.LineStyle,... + 'LineWidth', p.LineWidth); + hold on + outstuff = {linehandle}; + +elseif strcmp(mode, 'mediancurves') || strcmp(mode, 'meancurves') + + [linehandle] = plot(tv, ... + summst(:,msi,1, dosei)); + set(linehandle, ... + 'Color', p.LineColor,... + 'LineStyle', p.LineStyle,... + 'LineWidth', p.LineWidth); + hold on + + spreadhandles = zeros(size(spreadst, 3), 1); + for j = 1:size(spreadst, 3) % number of replicates + spreadhandles(j) = plot(tv, spreadst(:,msi,j, dosei)); + set(spreadhandles(j),... + 'Color', p.SpreadColor,... + 'LineStyle', p.SpreadLineStyle,... + 'LineWidth', p.SpreadLineWidth); + hold on + end + outstuff = {linehandle, spreadhandles}; + +elseif strcmp(mode, 'curves') + spreadhandles = zeros(size(spreadst, 3),1); + for j = 1:size(spreadst, 3) + spreadhandles(j) = plot(tv, ... + spreadst(:,msi,j, dosei)); + set(spreadhandles(j),... + 'Color', p.SpreadColor,... + 'LineStyle', p.SpreadLineStyle,... + 'LineWidth', p.SpreadLineWidth); + hold on + end + outstuff = {spreadhandles(1)}; +else + warning(['No valid exp data plotting format'... + ' specified. No experimental data will be plotted.']) +end +hold on + +% process variable outputs +nout = nargout-1; +varargout(1:nout) = outstuff(1:nout); + + + +end + + + + + + + + + + + + + diff --git a/mcmc_simbio/src/medianIndex.m b/mcmc_simbio/src/medianIndex.m new file mode 100755 index 0000000..8cadb6a --- /dev/null +++ b/mcmc_simbio/src/medianIndex.m @@ -0,0 +1,163 @@ +function [ix, medianvals] = medianIndex(inputarray, dim) + % compute the index of the median element of an + % array along a specified dimension. If there is an + % even number of elements, then pick the bigger of the middle + % two elements. + % ix is an array of the same size as 'inputarray', but with a width + % of 1 on dimension number dim. The elements of ix give the element + % along 'dim' in the array 'inputarray' that is either the median + % element along that dimension, or if there are an even number of + % element in that dimension, then is the closest overestimate of + % the median. The output medianvals is an array of the values in + % inputarray that ix points to. + % + % (c) Vipul Singhal + + % EXAMPLE: inputarray is, for eg, 1-2-1-4 ---> 1-4-1-2 when dim = 3. + % time - ms - replicates - doses ---> replicates - doses - time - ms + shiftedarray = shiftdim(inputarray, dim-1); + + + % if all the leading dimensions to be shifted are singletons, then they + % will be lost when shiftdim works: ie, if dim = 3, so the shifting is + % to be by 2 dimensions, then the result of shifting is: + % 1-2-3-4 ---> 3-4-1-2 (stays 4D array!) + % 1-1-3-4 ---> 3-4 (becomes 2D array!) + % + % Also, note that + % rr = rand(2, 1, 3, 4); + % size(shiftdim(rr, 2)) + % + % ans = + % + % 3 4 2 + % + % ie, basically matlab will just not report trailing singletons, and + % therein lies the problem. + % + % + % so later when we do the shift back, have to do it as follows: + % + % First pad on the left with singletons equal to the number removed: + % + % [1-2-3-4 --->] 3-4-1-2 --(pad with 0)--> 3-4-1-2, then rotate by + % ndims - ((ndims - dim +1) - 0) == 2, ---> 1-2-3-4. [ORIGINAL] + % + % + % + % [1-1-3-4 --->] 3-4 --(pad with 2 singletons)--> 1-1-3-4, then rotate + % by ndims - ((ndims - dim +1) - 2) == 4, ---> 1-1-3-4 [ORIGINAL] + % + % + % + % [2-1-3-4 --->] 3-4-2 --(pad with one singleton)--> 1-3-4-2 + % then rotate by ndims -((ndims - dim +1) - 1) == 3, ---> 2-1-3-4 [ORIGINAL] + % + % Then do the rotation in the same direction as the original, but + % ndims - dim +1 + % + + %{ OLD: + % This can be undone by first rotating the + % remaining dimensions back, and then adding singletons on the right. + % if ndims(shiftedarray) < ndims(inputarray) + % dimsToRightPad = ndims(inputarray) - ndims(shiftedarray); + % end + % otherwise: + % undo using shiftdim(shiftedarray, ndims(array) - dim +1) + % actually instead of circularly shifting, can just do : + % shiftdim(I5, -dim+1) to undo it!!!! <--- NOPE. + % From the documentation: "When N is negative, shiftdim + % shifts the dimensions to the right and pads with singletons." + %} + + % EXAMPLE (cont): srted is 1-4-1-2, and in this case the same as + % shiftedarray, since dimension 1 has length 1, so there is nothing to + % sort. I is a array of ones of the saem size. + [srted, I] = sort(shiftedarray, 1); + + %index of the element in srted that is the closest + % overestimate of the median + % also indices the first dimension of I + + II = ceil((size(I, 1)+1)/2); + + % Reshape I into a matrix + III = I(:,:); + srted3 = srted(:,:); + % index using II (ie, find the closest-to-middle element) + I4 = III(II,:); + srted4 = srted3(II, :); + % Now reshape back using the original dimensions + + szmat = size(I); + I5 = reshape(I4, [1, szmat(2:end)]); + srted5 = reshape(srted4, [1, szmat(2:end)]); + % shift back to the original dimensions + % there are 2 cases here: + % if the original count of the dimension sizes was + % 1-1-nRep-nDoses, then the shiftdim above resulted in a 2D matrix + % + + singletonsToPad = ndims(inputarray) - ndims(shiftedarray); + padded_srted5 = shiftdim(srted5, -singletonsToPad); + padded_I5 = shiftdim(I5, -singletonsToPad); + + % dimsToRotateBy = ndims -((ndims - dim +1) - singletonsToPad) + % = dim -1 + singletonsToPad + dimsToRotateBy = dim - 1 + singletonsToPad; + ix = shiftdim(padded_I5,dimsToRotateBy); + medianvals = shiftdim(padded_srted5,dimsToRotateBy); + + + + +% coding notes: + % first bring the dimension along which the median is to + % be found to the first dimension. + %%%% + % dim is 3 + % 4 total # of dims. + % 1 2 3 5 (sumovertime, ms, rep, dose) + % > shiftdim by dim - 1 + % shifted has size: 3 5 1 2 (rep, dose, sumovertime, ms) + % ie, 3 element columns, and 5 columns per pane, 1 pane per set1, + % 2 set1's. + %%%% + + + % then sort along this dimension, and subsequently pick + % out the (possibly closest overestimate of the) median value. + + %%%% + % sort + % pick out median indices + + % Ix has size 1 5 1 2 and points to elements of shifted + % shifted(Ix) is a 1 5 1 2 array of the median elements. + % more than that, Ix is what we want. + % in fact, unshifting Ix as follows: + % shiftdim(Ix, numel(size(array)) - dim + 1) brings Ix to + % 1 2 1 5 <---- Ix2 + % Now use Ix2 to index the full array back in the calling function + % array2(:, Ix(1,:,:,:)) maybe? I have no idea. Try it out I guess. + % no i dont think this works. + + + + + % % bring dim to be the first dimension + % shftsrted = shiftdim(srted, dim-1); + % medianarray = shftsrted(ceil((size(I, dim)+1)/2), ) + + + + %%%% + + + + + + + + end diff --git a/mcmc_simbio/src/medianReplicate.m b/mcmc_simbio/src/medianReplicate.m new file mode 100755 index 0000000..fdb1393 --- /dev/null +++ b/mcmc_simbio/src/medianReplicate.m @@ -0,0 +1,29 @@ +function medianCurves = medianReplicate(dataArray, ix) + % Pick out the median replicate from data array, the replicate to be picked + % out specified by the index array ix. + % + % This function takes two inputs: dataArray and ix. dataArray is an array + % containing data that has dimensions time x measured species x replicates + % x doses. ix is an array of dimensions 1 x nMS x 1 x nDoses OR + % nTimePoints x nMS x 1 x nDoses. If it is the latter, only the element + % corresponding to the first time point is used. + % I.e., for the ith measures species, and the jth dose, the index of the + % replicate within dataArray that is used comes from ix(1,i, 1,j), so that + % if ix(2:end,i, 1,j) exist, they are not used in any way. The function that + % creates the ix array is medianindex, and this function is used, for example + % the computeDataStats function above, or in mcmc_runsim.m. + + + % data array must be time x measuredspecies x replicates x doses + + % Get the median curves. Can this be done via pure vector indexing? + % !UNIMPORTANT but could be fun to think about sometime. + medianCurves = zeros(size(dataArray, 1), size(dataArray, 2), ... + 1, size(dataArray, 4)); + + for i = 1:size(dataArray, 2) + for j = 1:size(dataArray, 4) + medianCurves(:,i,1,j) = dataArray(:, i, ix(1,i, 1,j), j); + end + end +end \ No newline at end of file diff --git a/mcmc_simbio/src/plotChains.m b/mcmc_simbio/src/plotChains.m new file mode 100755 index 0000000..7ceb96a --- /dev/null +++ b/mcmc_simbio/src/plotChains.m @@ -0,0 +1,55 @@ +function plotChains(m, nW, legends, varargin) +% Plot markov chain trajectories. +% m is a nParam x nWalkers x numSamples +% nW is the number of walkers to plot. +% legs is legends +p = inputParser; +p.addParameter('Visible', 'on', @ischar) +p.parse(varargin{:}); +p=p.Results; + +[nParam, nWalkers, nSamples] = size(m); +[n1 n2] = twofactors(nParam); + +if isprime(nParam) + if nParam<12 + n1 = ceil(nParam/3); % 5 columns + n2 = 3; + elseif nParam < 20 + n1 = ceil(nParam/4); % 5 columns + n2 = 4; + else + n1 = ceil(nParam/5); % 5 columns + n2 = 5; + end + +end + +wix = unique(ceil(rand(nW, 1)*nWalkers)); +m = m(:,wix, :); +figure('Visible', p.Visible) +set(0,'Units','normalized') + +set(gcf,'Units', 'normalized') +set(gcf, 'Position', [0.05, 0.1, 0.9, 0.85]) +for i = 1:nParam + subplot(n1, n2, i) + + for j = 1:length(wix) + plot1 = plot(1:nSamples, squeeze(m(i, j, :)),... + 'LineWidth', 0.1,... + 'color', [0.2 0.7 0.1].^2); + plot1.Color(4) = 0.015; + hold on + end + title(legends{i}, 'fontsize', 14); + xlabel('Iteration', 'fontsize', 16); + ylabel('log-value', 'fontsize', 16); + ax = gca; + ax.FontSize = 14; + + +end + +end + diff --git a/mcmc_simbio/src/plotEstimTraces.m b/mcmc_simbio/src/plotEstimTraces.m new file mode 100755 index 0000000..873e885 --- /dev/null +++ b/mcmc_simbio/src/plotEstimTraces.m @@ -0,0 +1,139 @@ +function [f, meanconc, stdconc ] = plotEstimTraces(m,em,ts, datmat, ds, ms, varargin) +%plotEstimTraces Plot estimated trace mean and standard deviation for +%txtl data +% m is the MCMC data, either in 3D or 2D +% ts = tspan +% datmat = data matrix +% em = exported model object +% ds = dosing strat +% ms = measured species + + + +p = inputParser; +p.addParameter('title',[] ,@ischar) +p.addParameter('nplot',150,@isnumeric); +p.addParameter('colorseq', [7, 4, 6, 1, 8, 9, 10], @isnumeric); % meangirls (RNA), rainforest (GFP), swamplands (CFP), bog (YFP), ... +p.addParameter('Visible', 'on', @ischar) +p.parse(varargin{:}); +p=p.Results; + + +if ndims(m) == 3 + m = m(:,:)'; +end + +idx = randperm(size(m, 1), p.nplot); + + + +% construct measured names array +nMS = length(ms); +mn = cell(nMS, 1); % names of measured species +for i = 1:nMS + mn{i} = ms(i).objectName; +end + +% extract dose matrix and dose names from dosing strat +nICs = length(ds(1).concentrations); +nDSP = length(ds); +dn = cell(length(ds)); +for i = 1:length(ds) + dn{i} = ds(i).species; +end +dose = zeros(nICs , nDSP); +for j = 1:nICs + for i = 1:nDSP + dose(j,i) = ds(i).concentrations(j); + end +end +nts = length(ts); +% Compute sample trajectories, max values for axis limits, means, standard deviations +meanconc = zeros(nts, nMS, nICs); +stdconc = zeros(nts, nMS, nICs); +samp = zeros(nts, nMS, p.nplot, nICs); + +idxnotused = zeros(p.nplot, nICs); +for i = 1:nICs + for kk=1:p.nplot + try + sd = simulate(em, [exp(m(idx(kk),:)'); dose(i,:)']); + sd = resample(sd, ts); + spSD = selectbyname(sd, mn); + % output the relevant data to the samples + samp(:,:,kk, i) = spSD.Data; + catch + idx(kk) + idxnotused(kk, i) = idx(kk); + end + end + % compute mean and std over the p.nplot dimension, for each timepoint, IC and + % each species + kknotused = find(idxnotused(:,i)); + for j = 1:nMS + meanconc(:,j, i) = mean(samp(:,j,setdiff(1:(p.nplot), kknotused), i), 3); + stdconc(:, j, i) = std(samp(:,j,setdiff(1:(p.nplot), kknotused), i),0, 3); + end +end + +%% + +% +cc = colorschemes; +f = figure('Visible', p.Visible); +% ss = get(0, 'screensize'); +% set(gcf, 'Position', [50 100 ss(3)/1.1 ss(4)/1.3]); +% Compute species maxes for plotting +mxtemp = max(max(meanconc + stdconc, [], 1), [],3); +mxtemp = max(mxtemp, max(datmat)); % dm is the data matrix, DIM1:time, DIM2:measured species +maxsp = mxtemp'; + +h = zeros(nICs, nMS); +ptch = zeros(nICs, nMS); +d = zeros(nICs, nMS); + +csq = p.colorseq; + +for i = 1:nICs + for j = 1:nMS + subplot(nICs, nMS,nMS*(i-1)+j); + [h(i, j), ptch(i, j)] = boundedline(ts/3600, meanconc(:,j, i), stdconc(:, j, i)); + set(ptch(i, j), 'FaceColor', cc{2,csq(j)}(1,:), 'FaceAlpha', 0.5); + set(h(i, j), 'Color', cc{2,csq(j)}(2,:), 'LineStyle', '--'); + hold on + set(h(i, j), 'LineWidth', 2) + d(i, j)=plot(ts/3600,datmat((i-1)*nts + 1 : (i)*nts,j),'color',cc{2,csq(j)}(3,:) ,'linewidth',2); + hold on + set(gca, 'Ylim', [0, round(maxsp(j)*1.1, -(order(maxsp(j)*1.1)-2))]) + xlabel('time/h') + ylabel('conc/nM') + + title(sprintf('%s conc, dosed %s = %0.2g nM', mn{j}, dn{1}, dose(i,1))) + % right now I can only support a single species dose. Need to come up + % with an elegant way of putting all the dosing information in the + % title or in floating text. + + if i ==1 && j ==1 + ax = gca; + end + + end +end +if ~isempty(p.title) +suptitle(p.title) +end + +handles = [h(1, :), d(1,:)]; +lg1 = cell(1, nMS); +lg2 = cell(1, nMS); +for i = 1:nMS + lg1{i} = [mn{i} ' sample mean']; + lg2{i} = [mn{i} ' exp data']; +end + +legstr = [lg1, lg2]; + legend(ax, handles,legstr, 'Location', 'NorthWest'); + +end + + diff --git a/mcmc_simbio/src/plotEstimTraces003.m b/mcmc_simbio/src/plotEstimTraces003.m new file mode 100755 index 0000000..b46ef0d --- /dev/null +++ b/mcmc_simbio/src/plotEstimTraces003.m @@ -0,0 +1,174 @@ +function [ output_args ] = plotEstimTraces003(m,exportedMdlObj,tspan, ... + simulatedDataMatrix, dosedInitVals,... + measuredSpecies, varargin) +%plotEstimTraces003 Plot estimated trace mean and standard deviation for +%txtl data +% + +p = inputParser; +p.addParameter('paramID',[10 12 13],@isnumeric); +p.addParameter('titlestr',[] ,@ischar) +p.parse(varargin{:}); +p=p.Results; + +colIdx = p.paramID; +if ndims(m) == 3 + m = m(:,:)'; +end + +I = sampleIntersections(m, colIdx, 'mass', 0.4); + +numPostPlots = min([250, length(I)]); %plot numPostPlots samples... +if numPostPlots== 0 + error('No parameter points meet specified search criteria') +elseif numPostPlots<30 + warning(['Only using ' num2str(numPostPlots) 'parameter points. Expand Search parameters']) +end + +r = ceil(rand(numPostPlots,1)*size(I,1)); +% I = (1:size(msimple,1))'; +idx = I(r); +conc = simulatedDataMatrix; +nICs = size(dosedInitVals,1); +if length(measuredSpecies)==2 +[measuredNames{1}, measuredNames{2}] = deal(measuredSpecies.objectName); +elseif length(measuredSpecies)==1 + [measuredNames{1}] = deal(measuredSpecies.objectName); +end + + + +% Compute sample trajectories, max values for axis limits, means, standard deviations +meanGFP = zeros(length(tspan), nICs); +meanRNA = zeros(length(tspan), nICs); +stdevGFP = zeros(length(tspan), nICs); +stdevRNA = zeros(length(tspan), nICs); +GFPsampleTraj = zeros(length(tspan), nICs, numPostPlots); +RNAsampleTraj = zeros(length(tspan), nICs, numPostPlots); + +idxnotused = []; +kknotused = []; +for i = 1:nICs + for kk=1:numPostPlots + try + sd = simulate(exportedMdlObj, [exp(m(idx(kk),:)'); dosedInitVals(i,:)']); + sd = resample(sd, tspan); + spSD = selectbyname(sd, measuredNames); + [RNAsampleTraj(:,i, kk), GFPsampleTraj(:,i,kk)] = deal(spSD.Data(:,1), spSD.Data(:,2)); + catch + idx(kk) + idxnotused = [idxnotused; idx(kk)]; + kknotused = [kknotused;kk]; + + end + end + % compute mean and std + + meanGFP(:,i)=mean(GFPsampleTraj(:,i,setdiff(1:numPostPlots, kknotused)),3); + meanRNA(:,i)=mean(RNAsampleTraj(:,i,setdiff(1:numPostPlots, kknotused)),3); + stdevGFP(:,i)=std(GFPsampleTraj(:,i,setdiff(1:numPostPlots, kknotused)),0,3); + stdevRNA(:,i)=std(RNAsampleTraj(:,i,setdiff(1:numPostPlots, kknotused)),0,3); +end + +%% + +% +cc = colorschemes; +figure +ss = get(0, 'screensize'); +set(gcf, 'Position', [50 100 ss(3)/1.1 ss(4)/1.3]); +% + maxRNA = max(max(max(meanRNA+stdevRNA)), max(conc(:,1))); + maxGFP = max(max(max(meanGFP+stdevGFP)), max(conc(:,2))); + +for i = 1:nICs + + % RNA + subplot(nICs, 2,2*(i-1)+1); + [h(1), ptch(1)] = boundedline(tspan/3600, meanRNA(:,i), stdevRNA(:,i)); + set(ptch(1), 'FaceColor', cc{2,7}(1,:), 'FaceAlpha', 0.5); + set(h(1), 'Color', cc{2,7}(2,:), 'LineStyle', '--'); + hold on + set(h(1), 'LineWidth', 2) + h(2)=plot(tspan/3600,conc((i-1)*161 + 1 : (i)*161,1),'color',cc{2,7}(3,:) ,'linewidth',2); + hold on + set(gca, 'Ylim', [0, round(maxRNA+5, -1)]) + xlabel('time/h') + ylabel('conc/nM') + title(sprintf('%s conc, DNA=%0.2g nM', 'RNA', dosedInitVals(i,:)')) + + % GFP + subplot(nICs, 2,2*(i-1)+2); + [h(3), ptch(2)] = boundedline(tspan/3600, meanGFP(:,i), stdevGFP(:,i)); + set(ptch(2), 'FaceColor', cc{2,9}(3,:), 'FaceAlpha', 0.5); + set(h(3), 'Color', cc{2,9}(2,:), 'LineStyle', '--'); + hold on + set(h(3), 'LineWidth', 2) + h(4)=plot(tspan/3600,conc((i-1)*161 + 1 : (i)*161,2),'color',cc{2,9}(1,:) ,'linewidth',2); + hold on + set(gca, 'Ylim', [0, round(maxGFP+10, -1)]) + xlabel('time/h') + ylabel('conc/nM') + title(sprintf('%s conc, DNA=%0.2g nM', 'GFP', dosedInitVals(i,:)')) + + + ax = gca; +end +if ~isempty(p.titlestr) +suptitle(p.titlestr) +end + legend(ax, [h(1), h(2), h(3), h(4)],{'RNA sample mean','RNA Truth',... + 'GFP sample mean',... + 'GFP Truth'}) + + %% Plot the true traces, estimated means and shade the standard deviations. + figure +ss = get(0, 'screensize'); +set(gcf, 'Position', [50 100 ss(3)/1.1 ss(4)/1.3]); +% + maxRNA = max(max(max(meanRNA+stdevRNA)), max(conc(:,1))); + maxGFP = max(max(max(meanGFP+stdevGFP)), max(conc(:,2))); + +for i = 1:nICs + + % RNA + subplot(nICs, 2,2*(i-1)+1); + [h(1), ptch(1)] = boundedline(tspan/3600, meanRNA(:,i), stdevRNA(:,i)); + set(ptch(1), 'FaceColor', cc{2,7}(1,:), 'FaceAlpha', 0.5); + set(h(1), 'Color', cc{2,7}(2,:), 'LineStyle', '--'); + hold on + set(h(1), 'LineWidth', 2) + h(2)=plot(tspan/3600,conc((i-1)*161 + 1 : (i)*161,1),'color',cc{2,7}(3,:) ,'linewidth',2); + hold on + set(gca, 'Ylim', [0, round(maxRNA+5, -1)]) + xlabel('time/h') + ylabel('conc/nM') + title(sprintf('%s conc, DNA=%0.2g nM', 'RNA', dosedInitVals(i,:)')) + + % GFP + subplot(nICs, 2,2*(i-1)+2); + [h(3), ptch(2)] = boundedline(tspan/3600, meanGFP(:,i), stdevGFP(:,i)); + set(ptch(2), 'FaceColor', cc{2,9}(3,:), 'FaceAlpha', 0.5); + set(h(3), 'Color', cc{2,9}(2,:), 'LineStyle', '--'); + hold on + set(h(3), 'LineWidth', 2) + h(4)=plot(tspan/3600,conc((i-1)*161 + 1 : (i)*161,2),'color',cc{2,9}(1,:) ,'linewidth',2); + hold on + set(gca, 'Ylim', [0, round(maxGFP+10, -1)]) + xlabel('time/h') + ylabel('conc/nM') + title(sprintf('%s conc, DNA=%0.2g nM', 'GFP', dosedInitVals(i,:)')) + + + ax = gca; +end + +if ~isempty(p.titlestr) +suptitle(p.titlestr) +end + legend(ax, [h(1), h(2), h(3), h(4)],{'RNA sample mean','RNA Truth',... + 'GFP sample mean',... + 'GFP Truth'}) + +end + diff --git a/mcmc_simbio/src/plotEstimTraces008.m b/mcmc_simbio/src/plotEstimTraces008.m new file mode 100755 index 0000000..5fb2d07 --- /dev/null +++ b/mcmc_simbio/src/plotEstimTraces008.m @@ -0,0 +1,183 @@ +function plotEstimTraces008(m, genemodel, ICarray, tspan,... + spconc1, spconc2, varargin) +%plotEstimTraces008 Sample from the posterior distributions, and generate +%time traces, means, standard deviations. +% Optional Capability: if true parameters are provided, plot the true data too. +% +% +% +% +% +nSp = 3; +if ndims(m) == 3 + m = m(:,:)'; +end + +p = inputParser; +p.addParameter('mode','samplesonly',@ischar); % 'samplesonly', 'trueparams' +p.addParameter('sampling', 'all', @ischar) % 'all', 'MAPint, 'percentiles' +p.addParameter('paramID',[10 12 13],@isnumeric); +p.addParameter('titlestr',[] ,@ischar) +p.addParameter('ncurves',200 ,@isnumeric) +p.parse(varargin{:}); +p=p.Results; + +ncurves = p.ncurves; + +if strcmp(p.sampling, 'all') + idx = ceil(rand(ncurves, 1)*size(m,1)); +elseif strcmp(p.sampling, 'percentiles') + %!TODO, percentiles +elseif strcmp(p.sampling, 'MAPint') + %!TODO: MAP intervals, some mass around +end + +nICs = size(ICarray,1); +% compute the mean and the axis limits + +estimconc1 = zeros(length(tspan),nSp, nICs , ncurves); +estimconc2 = zeros(length(tspan),nSp, nICs , ncurves); +maxRNA_sd = 0; +maxGFP_sd = 0; +for i = 1:nICs + for kk=1:ncurves + sp0 = ICarray(i,:); + [~,estimconc1(:,:, i, kk)] = genemodel(m(idx(kk),[1:4 7 8]), sp0, tspan); + [~,estimconc2(:,:, i, kk)] = genemodel(m(idx(kk),[1:2 5:8]), sp0, tspan); + end + % compute mean and std + mean1 = mean(estimconc1, 4); % mean in dim 4 + mean2 = mean(estimconc2, 4); + std1 = std(estimconc1, 0, 4); % SD in dim 4 + std2 = std(estimconc2, 0, 4); + maxRNA_sd = max([maxRNA_sd, max(mean1(:,2, i)+std1(:,2, i)), max(mean2(:,2,i)+std2(:,2,i))]); + maxGFP_sd = max([maxGFP_sd, max(mean1(:,3,i)+std1(:,3,i)), max(mean2(:,3,i)+std2(:,3,i))]); +end + +maxRNA_curves = max(max(max(max([estimconc1(:,2,:,:), estimconc2(:,2,:,:)])))); +maxGFP_curves = max(max(max(max([estimconc1(:,3,:,:), estimconc2(:,3,:,:)])))); + +cc = colorschemes; +% figure +% ss = get(0, 'screensize'); +% set(gcf, 'Position', [50 100 ss(3)/1.1 ss(4)/1.3]); +% % plot the mean and individual curves +% for i = 1:nICs +% for kk=1:ncurves +% subplot(nICs, 4,4*(i-1)+1); +% h(1)=plot(tspan,estimconc1(:,2,i,kk),'color',[.6 .35 .3].^.2); +% hold on +% subplot(nICs, 4,4*(i-1)+2); +% h(2)=plot(tspan,estimconc1(:,3,i,kk),'color',[.2 .75 .2].^.2); +% hold on +% subplot(nICs, 4,4*(i-1)+3); +% h(3)=plot(tspan,estimconc2(:,2,i,kk),'color',[.6 .35 .3].^.2); +% hold on +% subplot(nICs, 4,4*(i-1)+4); +% h(4)=plot(tspan,estimconc2(:,3,i,kk),'color',[.2 .75 .2].^.2); +% hold on +% end +% subplot(nICs, 4,4*(i-1)+1); +% h(5)=plot(tspan,spconc1(:,2,i),'r','linewidth',2); +% h(9) = plot(tspan,mean1(:,2,i),'color',[.6 .35 .3],'linewidth',2, 'LineStyle',':'); +% title(sprintf('%s, E%d, DNA = %0.2g', 'RNA', 1, ICarray(i,1))) +% set(gca, 'Ylim', [0, round(maxRNA_curves+5)]) +% hold on +% subplot(nICs, 4,4*(i-1)+2); +% h(6)=plot(tspan,spconc1(:,3,i),'g','linewidth',2); +% h(10) = plot(tspan,mean1(:,3,i),'color',[.2 .75 .2],'linewidth',2, 'LineStyle',':'); +% title(sprintf('%s, E%d, DNA = %0.2g', 'GFP', 1, ICarray(i,1))) +% set(gca, 'Ylim', [0, round(maxGFP_curves+5)]) +% hold on +% subplot(nICs, 4,4*(i-1)+3); +% h(7)=plot(tspan,spconc2(:,2,i),'r','linewidth',2); +% h(11) = plot(tspan,mean2(:,2,i),'color',[.6 .35 .3],'linewidth',2, 'LineStyle',':'); +% title(sprintf('%s, E%d, DNA = %0.2g', 'RNA', 2, ICarray(i,1))) +% set(gca, 'Ylim', [0, round(maxRNA_curves+5)]) +% hold on +% subplot(nICs, 4,4*(i-1)+4); +% h(8)=plot(tspan,spconc2(:,3,i),'g','linewidth',2); +% h(12) = plot(tspan,mean2(:,3,i),'color',[.2 .75 .2],'linewidth',2, 'LineStyle',':'); +% title(sprintf('%s, E%d, DNA = %0.2g', 'DNA', 2, ICarray(i,1))) +% set(gca, 'Ylim', [0, round(maxGFP_curves+5)]) +% hold on +% end +% +% axis tight +% legend([h(1), h(2), h(5), h(6), h(9), h(10)],'RNA Samples','GFP Samples',... +% 'RNA True', 'GFP True', 'RNA mean', 'GFP mean') +% suplabel('Plots using parameter estimates' ,'t'); + +% plot the mean and standard deviation +figure +ss = get(0, 'screensize'); +set(gcf, 'Position', [50 100 ss(3)/1.8 ss(4)/1.8]); +for i = 1:nICs + % compute mean and std + + subplot(nICs, 4,4*(i-1)+1); + h(5)=plot(tspan,spconc1(:,2,i),'color',cc{2,7}(2,:) ,'linewidth',2); + hold on + [h(1), ptch(1)] = boundedline(tspan, mean1(:,2,i), std1(:,2,i)); + set(ptch(1), 'FaceColor', cc{2,7}(1,:), 'FaceAlpha', 0.5); + set(h(1), 'Color', cc{2,7}(2,:).^2, 'LineStyle', '--'); + hold on + set(h(1), 'LineWidth', 2) + + set(gca, 'Ylim', [0, round(maxRNA_sd+5)]) + title(sprintf('%s, E%d, DNA = %0.2g', 'RNA', 1, ICarray(i,1)), 'FontSize', 16) + + subplot(nICs, 4,4*(i-1)+2); + h(6)=plot(tspan,spconc1(:,3,i),'color',cc{2,9}(2,:),'linewidth',2); + title(sprintf('%s, E%d, DNA = %0.2g', 'GFP', 1, ICarray(i,1)), 'FontSize', 16) + hold on + [h(2), ptch(2)] = boundedline(tspan, mean1(:,3,i), std1(:,3,i)); + set(ptch(2), 'FaceColor', cc{2,9}(3,:), 'FaceAlpha', 0.5); + set(h(2), 'Color', cc{2,9}(2,:).^2, 'LineStyle', '--'); + hold on + set(h(2), 'LineWidth', 2) + + set(gca, 'Ylim', [0, round(maxGFP_sd+5)]) + + subplot(nICs, 4,4*(i-1)+3); + h(7)=plot(tspan,spconc2(:,2,i),'color',cc{2,7}(2,:) ,'linewidth',2); + title(sprintf('%s, E%d, DNA = %0.2g', 'RNA', 2, ICarray(i,1)), 'FontSize', 16) + hold on + [h(3),ptch(3)] = boundedline(tspan, mean2(:,2,i), std2(:,2,i)); + set(ptch(3), 'FaceColor', cc{2,7}(1,:), 'FaceAlpha', 0.5); + set(h(3), 'Color', cc{2,7}(2,:).^2, 'LineStyle', '--'); + hold on + set(h(3), 'LineWidth', 2) + + set(gca, 'Ylim', [0, round(maxRNA_sd+5)]) + + + subplot(nICs, 4,4*(i-1)+4); + h(8)=plot(tspan,spconc2(:,3,i),'color',cc{2,9}(2,:),'linewidth',2); + title(sprintf('%s, E%d, DNA = %0.2g', 'GFP', 2, ICarray(i,1)), 'FontSize', 16) + hold on + [h(4), ptch(4)] = boundedline(tspan, mean2(:,3,i), std2(:,3,i)); + set(ptch(4), 'FaceColor', cc{2,9}(3,:), 'FaceAlpha', 0.5); + set(h(4), 'Color', cc{2,9}(2,:).^2, 'LineStyle', '--'); + hold on + set(h(4), 'LineWidth', 2) + + set(gca, 'Ylim', [0, round(maxGFP_sd+5)]) + if i ==1 + ax = gca; + end +end + +% +% axis tight +% suplabel('Plots using parameter estimates' ,'t'); + [ax1,h1] =suplabel('time, arbitrary units' ); + [ax2,h2] =suplabel('concentration, arbitrary units' ,'y'); + set(h1,'FontSize',20) + set(h2,'FontSize',20) + legend(ax, [h(3), h(4), h(7), h(8)],{'RNA mean','GFP mean',... + 'RNA True', 'GFP True'}, 'FontSize', 12, 'Location', 'NorthEast') + + + +end diff --git a/mcmc_simbio/src/plotEstimTraces009s0s1s2.m b/mcmc_simbio/src/plotEstimTraces009s0s1s2.m new file mode 100755 index 0000000..6721ef2 --- /dev/null +++ b/mcmc_simbio/src/plotEstimTraces009s0s1s2.m @@ -0,0 +1,12 @@ +function [ output_args ] = plotEstimTraces009s0s1s2(m, S, varargin) +%plotEstimTraces008 Sample from the posterior distributions, and generate +%time traces, means, standard deviations. +% Optional Capability: if true parameters are provided, plot the true data too. +% +% +% +% +% + + +end diff --git a/mcmc_simbio/src/plotEstimTraces_singleplot.m b/mcmc_simbio/src/plotEstimTraces_singleplot.m new file mode 100755 index 0000000..7be15c3 --- /dev/null +++ b/mcmc_simbio/src/plotEstimTraces_singleplot.m @@ -0,0 +1,140 @@ +function [f, meanconc, stdconc ] = plotEstimTraces_singleplot(m,em,ts, datmat, ds, ms, varargin) +%plotEstimTraces Plot estimated trace mean and standard deviation for +%txtl data +% m is the MCMC data, either in 3D or 2D +% ts = tspan +% datmat = data matrix +% em = exported model object +% ds = dosing strat +% ms = measured species + + + +p = inputParser; +p.addParameter('title',[] ,@ischar) +p.addParameter('nplot',150,@isnumeric); +p.addParameter('colorseq', [7, 4, 6, 1, 8, 9, 10], @isnumeric); % meangirls (RNA), rainforest (GFP), swamplands (CFP), bog (YFP), ... +p.addParameter('Visible', 'on', @ischar) +p.parse(varargin{:}); +p=p.Results; + + +if ndims(m) == 3 + m = m(:,:)'; +end + +idx = randperm(size(m, 1), p.nplot); + + + +% construct measured names array +nMS = length(ms); +mn = cell(nMS, 1); % names of measured species +for i = 1:nMS + mn{i} = ms(i).objectName; +end + +% extract dose matrix and dose names from dosing strat +nICs = length(ds(1).concentrations); +nDSP = length(ds); +dn = cell(length(ds)); +for i = 1:length(ds) + dn{i} = ds(i).species; +end +dose = zeros(nICs , nDSP); +for j = 1:nICs + for i = 1:nDSP + dose(j,i) = ds(i).concentrations(j); + end +end +nts = length(ts); +% Compute sample trajectories, max values for axis limits, means, standard deviations +meanconc = zeros(nts, nMS, nICs); +stdconc = zeros(nts, nMS, nICs); +samp = zeros(nts, nMS, p.nplot, nICs); + +idxnotused = zeros(p.nplot, nICs); +for i = 1:nICs + for kk=1:p.nplot + try + sd = simulate(em, [exp(m(idx(kk),:)'); dose(i,:)']); + sd = resample(sd, ts); + spSD = selectbyname(sd, mn); + % output the relevant data to the samples + samp(:,:,kk, i) = spSD.Data; + catch + idx(kk) + idxnotused(kk, i) = idx(kk); + end + end + % compute mean and std over the p.nplot dimension, for each timepoint, IC and + % each species + kknotused = find(idxnotused(:,i)); + for j = 1:nMS + meanconc(:,j, i) = mean(samp(:,j,setdiff(1:(p.nplot), kknotused), i), 3); + stdconc(:, j, i) = std(samp(:,j,setdiff(1:(p.nplot), kknotused), i),0, 3); + end +end + +%% + +% +cc = colorschemes; +f = figure('Visible', p.Visible); +% ss = get(0, 'screensize'); +% set(gcf, 'Position', [50 100 ss(3)/1.1 ss(4)/1.3]); +% Compute species maxes for plotting +mxtemp = max(max(meanconc + stdconc, [], 1), [],3); +mxtemp = max(mxtemp, max(datmat)); % dm is the data matrix, DIM1:time, DIM2:measured species +maxsp = mxtemp'; + +h = zeros(nICs, nMS); +ptch = zeros(nICs, nMS); +d = zeros(nICs, nMS); + +csq = p.colorseq; + + +for j = 1:nMS + for i = 1:nICs + subplot(1, nMS,j); + [h(i, j), ptch(i, j)] = boundedline(ts/3600, meanconc(:,j, i), stdconc(:, j, i)); + set(ptch(i, j), 'FaceColor', i*(1/nICs)*cc{2,csq(j)}(1,:), 'FaceAlpha', 0.5); + set(h(i, j), 'Color', i*(1/nICs)*cc{2,csq(j)}(2,:), 'LineStyle', '--'); + hold on + set(h(i, j), 'LineWidth', 2) + d(i, j)=plot(ts/3600,datmat((i-1)*nts + 1 : (i)*nts,j),'color',i*(1/nICs)*cc{2,csq(j)}(3,:) ,'linewidth',2); + hold on + set(gca, 'Ylim', [0, round(maxsp(j)*1.1, -(order(maxsp(j)*1.1)-2))]) + xlabel('time/h') + ylabel('conc/nM') + + title(sprintf('%s conc, dosed %s = %0.2g nM', mn{j}, dn{1}, dose(i,1))) + % right now I can only support a single species dose. Need to come up + % with an elegant way of putting all the dosing information in the + % title or in floating text. + + if i ==1 && j ==1 + ax = gca; + end + + end +end +if ~isempty(p.title) +suptitle(p.title) +end + +handles = [h(1, :), d(1,:)]; +lg1 = cell(1, nMS); +lg2 = cell(1, nMS); +for i = 1:nMS + lg1{i} = [mn{i} ' sample mean']; + lg2{i} = [mn{i} ' exp data']; +end + +legstr = [lg1, lg2]; + legend(ax, handles,legstr, 'Location', 'NorthWest'); + +end + + diff --git a/mcmc_simbio/src/plotEstimTraces_ver201711.m b/mcmc_simbio/src/plotEstimTraces_ver201711.m new file mode 100755 index 0000000..0fea061 --- /dev/null +++ b/mcmc_simbio/src/plotEstimTraces_ver201711.m @@ -0,0 +1,159 @@ +function [f, meanconc, stdconc , idxnotused] = ... + plotEstimTraces_ver201711(m,em,ts, datmat, ds, ms, varargin) +%plotEstimTraces_ver201711 based on the function plotEstimTraces, except +%measured species is as used in the mcmc toolbox. Ie, ms is a cell array of +%cell arrays. +% +% m is the MCMC data, either in 3D or 2D +% ts = tspan +% datmat = data matrix +% em = exported model object +% ds = dosing strat +% ms = measured species + + + +p = inputParser; +p.addParameter('title',[] ,@ischar) +p.addParameter('nplot',150,@isnumeric); +p.addParameter('colorseq', [7, 4, 6, 1, 8, 9, 10],... + @isnumeric);... + % colorscheme: meangirls (RNA), rainforest (GFP), swamplands (CFP), +% bog (YFP), ... +p.addParameter('Visible', 'on', @ischar) +p.parse(varargin{:}); +p=p.Results; + + +if ndims(m) == 3 + m = m(:,:)'; +end + +idx = randperm(size(m, 1), p.nplot); + + +% extract dose matrix and dose names from dosing strat +nICs = length(ds(1).concentrations); +nDSP = length(ds); +dn = cell(length(ds)); +for i = 1:length(ds) + dn{i} = ds(i).species; +end +dose = zeros(nICs , nDSP); +for j = 1:nICs + for i = 1:nDSP + dose(j,i) = ds(i).concentrations(j); + end +end + +nts = length(ts); +nMS = length(ms); +% Compute sample trajectories, max values for axis limits, means, +% standard deviations +meanconc = zeros(nts, nMS, nICs); +stdconc = zeros(nts, nMS, nICs); +samp = zeros(nts, nMS, p.nplot, nICs); + +idxnotused = zeros(p.nplot, nICs); +for i = 1:nICs + for kk=1:p.nplot + try + sd = simulate(em, [exp(m(idx(kk),:)'); dose(i,:)']); + sd = resample(sd, ts); + + % since measured species is a cell array of cell arrays of strings, + % we need to loop over the outer cell, summing the values of the + % species in the inner cell. + for ss = 1:nMS + [~, XX] = selectbyname(sd, ms{ss}); + X = sum(XX, 2); + % output the relevant data to the samples + samp(:,ss,kk, i) = X; + + end + + + + + + catch ME + ME.message + idx(kk); + idxnotused(kk, i) = idx(kk); + end + end + % compute mean and std over the p.nplot dimension, + % for each timepoint, IC and + % each species + kknotused = find(idxnotused(:,i)); + for j = 1:nMS + meanconc(:,j, i) = ... + mean(samp(:,j,setdiff(1:(p.nplot),kknotused), i), 3); + stdconc(:, j, i) = ... + std(samp(:,j,setdiff(1:(p.nplot), kknotused), i),0, 3); + end +end + +%% + +% + +cc = colorschemes; +f = figure('Visible', p.Visible); +% ss = get(0, 'screensize'); +% set(gcf, 'Position', [50 100 ss(3)/1.1 ss(4)/1.3]); +% Compute species maxes for plotting +mxtemp = max(max(meanconc + stdconc, [], 1), [],3); +mxtemp = max(mxtemp, max(datmat)); % dm is the data matrix, +% DIM1:time, DIM2:measured species +maxsp = mxtemp'; + +h = zeros(nICs, nMS); +ptch = zeros(nICs, nMS); +d = zeros(nICs, nMS); + +csq = p.colorseq; + +for i = 1:nICs + for j = 1:nMS + subplot(nICs, nMS,nMS*(i-1)+j); + [h(i, j), ptch(i, j)] = boundedline(ts/3600, meanconc(:,j, i),... + stdconc(:, j, i)); + set(ptch(i, j), 'FaceColor', cc{2,csq(j)}(1,:), 'FaceAlpha', 0.5); + set(h(i, j), 'Color', cc{2,csq(j)}(2,:), 'LineStyle', '--'); + hold on + set(h(i, j), 'LineWidth', 2) + d(i, j)=plot(ts/3600,datmat((i-1)*nts + 1 : (i)*nts,j),... + 'color',cc{2,csq(j)}(3,:) ,'linewidth',2); + hold on + set(gca, 'Ylim', [0, round(maxsp(j)*1.1, -(order(maxsp(j)*1.1)-2))]) + xlabel('time/h') + ylabel('conc/nM') + +% title(sprintf('%s conc, dosed %s = %0.2g nM', mn{j}, dn{1}, dose(i,1))) + % right now I can only support a single species dose. Need to come up + % with an elegant way of putting all the dosing information in the + % title or in floating text. + if i ==1 && j ==1 + ax = gca; + end + end +end +% if ~isempty(p.title) +% suptitle(p.title) +% end + +% handles = [h(1, :), d(1,:)]; +% lg1 = cell(1, nMS); +% lg2 = cell(1, nMS); +% for i = 1:nMS +% lg1{i} = [mn{i} ' sample mean']; +% lg2{i} = [mn{i} ' exp data']; +% end + +% legstr = [lg1, lg2]; +% legend(ax, handles,legstr, 'Location', 'NorthWest'); + +end + + diff --git a/mcmc_simbio/src/plotEstimTraces_ver201801.m b/mcmc_simbio/src/plotEstimTraces_ver201801.m new file mode 100755 index 0000000..e745aea --- /dev/null +++ b/mcmc_simbio/src/plotEstimTraces_ver201801.m @@ -0,0 +1,174 @@ +function [f, meanconc, stdconc , idxnotused] = ... + plotEstimTraces_ver201801(m,em,ts, datmat, ds, ms, varargin) +%plotEstimTraces_ver201711 based on the function plotEstimTraces, except +%measured species is as used in the mcmc toolbox. Ie, ms is a cell array of +%cell arrays. +% +% m is the MCMC data, either in 3D or 2D +% ts = tspan +% datmat = data matrix of dimensions time by ms by replicates by doses +% em = exported model object +% ds = dosing strat. +% ms = measured species + +p = inputParser; +p.addParameter('title',[] ,@ischar) +p.addParameter('nplot',150,@isnumeric); +p.addParameter('colorseq', [7, 4, 6, 1, 8, 9, 10],... + @isnumeric);... + % colorscheme: meangirls (RNA), rainforest (GFP), swamplands (CFP), +% bog (YFP), ... +p.addParameter('Visible', 'on', @ischar) +p.parse(varargin{:}); +p=p.Results; + + +if ndims(m) == 3 + m = m(:,:)'; +end + +idx = randperm(size(m, 1), p.nplot); + + +% extract dose matrix and dose names from dosing strat +nICs = length(ds(1).concentrations); +nDSP = length(ds); % number of dosed species per combination +dn = cell(length(ds)); % dose names (ie the species that get dosed. +for i = 1:length(ds) + dn{i} = ds(i).species; +end +dose = zeros(nICs , nDSP); % # of dose combos x number of species per combo +for j = 1:nICs + for i = 1:nDSP + dose(j,i) = ds(i).concentrations(j); + end +end + +nts = length(ts); % number of timepoints +nMS = length(ms); % number of measured species. +% Compute sample trajectories, max values for axis limits, means, +% standard deviations +meanconc = zeros(nts, nMS, nICs); +stdconc = zeros(nts, nMS, nICs); +samp = zeros(nts, nMS, p.nplot, nICs); + +idxnotused = zeros(p.nplot, nICs); +for i = 1:nICs + for kk=1:p.nplot + try + sd = simulate(em, [exp(m(idx(kk),:)'); dose(i,:)']); + sd = resample(sd, ts); + % since measured species is a cell array of cell arrays of strings, + % we need to loop over the outer cell, summing the values of the + % species in the inner cell. + for ss = 1:nMS + [~, XX] = selectbyname(sd, ms{ss}); + X = sum(XX, 2); + % output the relevant data to the samples + samp(:,ss,kk, i) = X; + end + catch ME + ME.message + idx(kk); + idxnotused(kk, i) = idx(kk); + end + end + % compute mean and std over the p.nplot dimension, + % for each timepoint, IC and + % each species + kknotused = find(idxnotused(:,i)); + for j = 1:nMS + meanconc(:,j, i) = ... + mean(samp(:,j,setdiff(1:(p.nplot),kknotused), i), 3); + stdconc(:, j, i) = ... + std(samp(:,j,setdiff(1:(p.nplot), kknotused), i),0, 3); + end +end + +%% + +% + +cc = colorschemes; +f = figure('Visible', p.Visible); +% ss = get(0, 'screensize'); +% set(gcf, 'Position', [50 100 ss(3)/1.1 ss(4)/1.3]); +% Compute species maxes for plotting +mxtemp = max(max(meanconc + stdconc, [], 1), [],3); +mxtemp = max(mxtemp, max(max(max(datmat, [], 1), [], 3),[],4)); % dm is the data matrix, +% DIM1:time, DIM2:measured species +maxsp = squeeze(mxtemp)'; + +h = zeros(nICs, nMS); +ptch = zeros(nICs, nMS); +d = zeros(nICs, nMS); +hdata= zeros(nICs, nMS); +ptchdata = zeros(nICs, nMS); +csq = p.colorseq; + +if size(datmat, 3)>1 + hasreplicates = true; +else + hasreplicates = false; + +end + +for i = 1:nICs + for j = 1:nMS + subplot(nICs, nMS,nMS*(i-1)+j); + [h(i, j), ptch(i, j)] = boundedline(ts/3600, meanconc(:,j, i),... + stdconc(:, j, i)); + set(ptch(i, j), 'FaceColor', cc{2,csq(j)}(1,:), 'FaceAlpha', 0.5); + set(h(i, j), 'Color', cc{2,csq(j)}(2,:), 'LineStyle', '--'); + hold on + set(h(i, j), 'LineWidth', 1) + +% the data can have replicates, and therefore have a mean and a +% standard deviation. + + if hasreplicates + % compute standard deviation of the data and plot the shaded region + [hdata(i, j), ptchdata(i, j)] = boundedline(... + ts/3600, mean(datmat(:,j, :, i), 3),... + std(datmat(:,j, :, i),0, 3)); + set(ptchdata(i, j), 'FaceColor', cc{2,csq(j)}(4,:), 'FaceAlpha', 0.5); + set(hdata(i, j), 'Color', cc{2,csq(j)}(3,:), 'LineStyle', '-'); + hold on + set(hdata(i, j), 'LineWidth', 2) + else + d(i, j)=plot(ts/3600,mean(datmat(:,j, :, i), 3),... + 'color',cc{2,csq(j)}(3,:) ,'linewidth',2); + end + + hold on + set(gca, 'Ylim', [0, round(maxsp(j)*1.1, -(order(maxsp(j)*1.1)-2))]) + xlabel('time/h', 'FontSize', 14) + ylabel('conc/nM', 'FontSize', 14) + +% title(sprintf('%s conc, dosed %s = %0.2g nM', mn{j}, dn{1}, dose(i,1))) + % right now I can only support a single species dose. Need to come up + % with an elegant way of putting all the dosing information in the + % title or in floating text. + if i ==1 && j ==1 + ax = gca; + end + end +end +if ~isempty(p.title) +suptitle(p.title) +end + +% handles = [h(1, :), d(1,:)]; +% lg1 = cell(1, nMS); +% lg2 = cell(1, nMS); +% for i = 1:nMS +% lg1{i} = [mn{i} ' sample mean']; +% lg2{i} = [mn{i} ' exp data']; +% end + +% legstr = [lg1, lg2]; +% legend(ax, handles,legstr, 'Location', 'NorthWest'); + +end + + diff --git a/mcmc_simbio/src/plotOrigTraces008.m b/mcmc_simbio/src/plotOrigTraces008.m new file mode 100755 index 0000000..32dbb96 --- /dev/null +++ b/mcmc_simbio/src/plotOrigTraces008.m @@ -0,0 +1,190 @@ +function plotOrigTraces008(m, genemodel, ICarray, tspan,... + spconc1, spconc2, varargin) +%plotEstimTraces008 Sample from the posterior distributions, and generate +%time traces, means, standard deviations. +% Optional Capability: if true parameters are provided, plot the true data too. +% +% +% +% +% +nSp = 3; +if ndims(m) == 3 + m = m(:,:)'; +end + +p = inputParser; +p.addParameter('mode','samplesonly',@ischar); % 'samplesonly', 'trueparams' +p.addParameter('sampling', 'all', @ischar) % 'all', 'MAPint, 'percentiles' +p.addParameter('paramID',[10 12 13],@isnumeric); +p.addParameter('titlestr',[] ,@ischar) +p.addParameter('ncurves',200 ,@isnumeric) +p.parse(varargin{:}); +p=p.Results; + +ncurves = p.ncurves; + +if strcmp(p.sampling, 'all') + idx = ceil(rand(ncurves, 1)*size(m,1)); +elseif strcmp(p.sampling, 'percentiles') + %!TODO, percentiles +elseif strcmp(p.sampling, 'MAPint') + %!TODO: MAP intervals, some mass around +end + +nICs = size(ICarray,1); +% compute the mean and the axis limits + +estimconc1 = zeros(length(tspan),nSp, nICs , ncurves); +estimconc2 = zeros(length(tspan),nSp, nICs , ncurves); +maxRNA_sd = 0; +maxGFP_sd = 0; +for i = 1:nICs + for kk=1:ncurves + sp0 = ICarray(i,:); + [~,estimconc1(:,:, i, kk)] = genemodel(m(idx(kk),[1:4 7 8]), sp0, tspan); + [~,estimconc2(:,:, i, kk)] = genemodel(m(idx(kk),[1:2 5:8]), sp0, tspan); + end + % compute mean and std + mean1 = mean(estimconc1, 4); % mean in dim 4 + mean2 = mean(estimconc2, 4); + std1 = std(estimconc1, 0, 4); % SD in dim 4 + std2 = std(estimconc2, 0, 4); + maxRNA_sd = max([maxRNA_sd, max(mean1(:,2, i)+std1(:,2, i)), max(mean2(:,2,i)+std2(:,2,i))]); + maxGFP_sd = max([maxGFP_sd, max(mean1(:,3,i)+std1(:,3,i)), max(mean2(:,3,i)+std2(:,3,i))]); +end + +maxRNA_curves = max(max(max(max([estimconc1(:,2,:,:), estimconc2(:,2,:,:)])))); +maxGFP_curves = max(max(max(max([estimconc1(:,3,:,:), estimconc2(:,3,:,:)])))); + +cc = colorschemes; +% figure +% ss = get(0, 'screensize'); +% set(gcf, 'Position', [50 100 ss(3)/1.1 ss(4)/1.3]); +% plot the mean and individual curves +% for i = 1:nICs +% for kk=1:ncurves +% subplot(nICs, 4,4*(i-1)+1); +% h(1)=plot(tspan,estimconc1(:,2,i,kk),'color',[.6 .35 .3].^.2); +% hold on +% subplot(nICs, 4,4*(i-1)+2); +% h(2)=plot(tspan,estimconc1(:,3,i,kk),'color',[.2 .75 .2].^.2); +% hold on +% subplot(nICs, 4,4*(i-1)+3); +% h(3)=plot(tspan,estimconc2(:,2,i,kk),'color',[.6 .35 .3].^.2); +% hold on +% subplot(nICs, 4,4*(i-1)+4); +% h(4)=plot(tspan,estimconc2(:,3,i,kk),'color',[.2 .75 .2].^.2); +% hold on +% end +% subplot(nICs, 4,4*(i-1)+1); +% h(5)=plot(tspan,spconc1(:,2,i),'r','linewidth',2); +% h(9) = plot(tspan,mean1(:,2,i),'color',[.6 .35 .3],'linewidth',2, 'LineStyle',':'); +% title(sprintf('%s, E%d, DNA = %0.2g', 'RNA', 1, ICarray(i,1))) +% set(gca, 'Ylim', [0, round(maxRNA_curves+5)]) +% hold on +% subplot(nICs, 4,4*(i-1)+2); +% h(6)=plot(tspan,spconc1(:,3,i),'g','linewidth',2); +% h(10) = plot(tspan,mean1(:,3,i),'color',[.2 .75 .2],'linewidth',2, 'LineStyle',':'); +% title(sprintf('%s, E%d, DNA = %0.2g', 'GFP', 1, ICarray(i,1))) +% set(gca, 'Ylim', [0, round(maxGFP_curves+5)]) +% hold on +% subplot(nICs, 4,4*(i-1)+3); +% h(7)=plot(tspan,spconc2(:,2,i),'r','linewidth',2); +% h(11) = plot(tspan,mean2(:,2,i),'color',[.6 .35 .3],'linewidth',2, 'LineStyle',':'); +% title(sprintf('%s, E%d, DNA = %0.2g', 'RNA', 2, ICarray(i,1))) +% set(gca, 'Ylim', [0, round(maxRNA_curves+5)]) +% hold on +% subplot(nICs, 4,4*(i-1)+4); +% h(8)=plot(tspan,spconc2(:,3,i),'g','linewidth',2); +% h(12) = plot(tspan,mean2(:,3,i),'color',[.2 .75 .2],'linewidth',2, 'LineStyle',':'); +% title(sprintf('%s, E%d, DNA = %0.2g', 'DNA', 2, ICarray(i,1))) +% set(gca, 'Ylim', [0, round(maxGFP_curves+5)]) +% hold on +% end +% +% axis tight +% legend([h(1), h(2), h(5), h(6), h(9), h(10)],'RNA Samples','GFP Samples',... +% 'RNA True', 'GFP True', 'RNA mean', 'GFP mean') +% suplabel('Plots using parameter estimates' ,'t'); + +% plot the mean and standard deviation +figure +ss = get(0, 'screensize'); +set(gcf, 'Position', [50 100 ss(3)/1.8 ss(4)/1.8]); +for i = 1:nICs + % compute mean and std + + subplot(nICs, 4,4*(i-1)+1); + h(5)=plot(tspan,spconc1(:,2,i),'color',cc{2,7}(2,:) ,'linewidth',2); + hold on +% [h(1), ptch(1)] = boundedline(tspan, mean1(:,2,i), std1(:,2,i)); +% set(ptch(1), 'FaceColor', cc{2,7}(1,:), 'FaceAlpha', 0.5); +% set(h(1), 'Color', cc{2,7}(2,:), 'LineStyle', '--'); +% hold on +% set(h(1), 'LineWidth', 2) + + set(gca, 'Ylim', [0, round(maxRNA_sd+5)]) + title(sprintf('%s, E%d, DNA = %0.2g', 'RNA', 1, ICarray(i,1)), 'FontSize', 16) + + subplot(nICs, 4,4*(i-1)+2); + h(6)=plot(tspan,spconc1(:,3,i),'color',cc{2,9}(2,:),'linewidth',2); + title(sprintf('%s, E%d, DNA = %0.2g', 'GFP', 1, ICarray(i,1)), 'FontSize', 16) + hold on +% [h(2), ptch(2)] = boundedline(tspan, mean1(:,3,i), std1(:,3,i)); +% set(ptch(2), 'FaceColor', cc{2,9}(3,:), 'FaceAlpha', 0.5); +% set(h(2), 'Color', cc{2,9}(2,:), 'LineStyle', '--'); +% hold on +% set(h(2), 'LineWidth', 2) + + set(gca, 'Ylim', [0, round(maxGFP_sd+5)]) + + subplot(nICs, 4,4*(i-1)+3); +% if i ==1 +% h(1)=plot(tspan,spconc2(:,2,i),'color',cc{2,7}(2,:) ,'linewidth',2); +% else + h(7)=plot(tspan,spconc2(:,2,i),'color',cc{2,7}(2,:) ,'linewidth',2); +% end + title(sprintf('%s, E%d, DNA = %0.2g', 'RNA', 2, ICarray(i,1)), 'FontSize', 16) + hold on +% [h(3),ptch(3)] = boundedline(tspan, mean2(:,2,i), std2(:,2,i)); +% set(ptch(3), 'FaceColor', cc{2,7}(1,:), 'FaceAlpha', 0.5); +% set(h(3), 'Color', cc{2,7}(2,:), 'LineStyle', '--'); +% hold on +% set(h(3), 'LineWidth', 2) + + set(gca, 'Ylim', [0, round(maxRNA_sd+5)]) + + + subplot(nICs, 4,4*(i-1)+4); +% if i ==1 +% h(2)=plot(tspan,spconc2(:,3,i),'color',cc{2,9}(2,:),'linewidth',2); +% else + h(8)=plot(tspan,spconc2(:,3,i),'color',cc{2,9}(2,:),'linewidth',2); +% end + title(sprintf('%s, E%d, DNA = %0.2g', 'GFP', 2, ICarray(i,1)), 'FontSize', 16) + hold on +% [h(4), ptch(4)] = boundedline(tspan, mean2(:,3,i), std2(:,3,i)); +% set(ptch(4), 'FaceColor', cc{2,9}(3,:), 'FaceAlpha', 0.5); +% set(h(4), 'Color', cc{2,9}(2,:), 'LineStyle', '--'); +% hold on +% set(h(4), 'LineWidth', 2) + + set(gca, 'Ylim', [0, round(maxGFP_sd+5)]) + if i ==1 + ax = gca; + end +end + +% +% axis tight +% suplabel('Plots using parameter estimates' ,'t'); + [ax1,h1] = suplabel('time, arbitrary units' ); + [ax2,h2] = suplabel('concentration, arbitrary units' ,'y'); + set(h1,'FontSize',20) + set(h2,'FontSize',20) + legend(ax, [h(7), h(8)],{'RNA True', 'GFP True'}, 'FontSize', 14, 'Location', 'NorthEast') + + + +end diff --git a/mcmc_simbio/src/project_init.m b/mcmc_simbio/src/project_init.m new file mode 100755 index 0000000..adb37ff --- /dev/null +++ b/mcmc_simbio/src/project_init.m @@ -0,0 +1,125 @@ +function [tstamp, specificprojdir, st] = project_init(varargin) +% this function is to be called at the beginning of the project script stored in the projects +% directory of the MCMC toolbox. +% The script calling this should be a project file (.m) that sets up the data, models, +% MCMC simulation, runs it, and optionally plots the results. +% The main function of this file is that every time a given project is run, a directory +% created (using a timestamp) where the results of that run are stored. +% +% This function can be run without any arguments, in which case it will check if a directory +% with the same name as the project that calls it exists in the projects folder. If it does, +% then all the simulation data is stored in timestamped subdirectories within this directory, +% and this directory is what gets checked first for the various things like models, +% experimental data, est_info structs, model_map structs, etc. If any of these things are +% not present in this directory, then the models or data directories in the main directory +% are checked. If those directories also do not contain the files required, an error is thrown. +% If the directory does not exist, then a directory with the same name as the project file +% gets created, and all the models/ data etc are looked for in the main directories. This +% directory will be where the simulation data will be stored. +% +% on the other hand, if a string argument is supplied, then the above applied, but instead of +% the project name, we use this string as the name. +% +% the output of this function is a string that specifies the timestamp for the purposes of +% identifying the directory created. + + + +% get the name of the (project) file calling this function, and its path. +st = dbstack(1,'-completenames'); +if ispc + + fp = st(1).file; + slashes = regexp(fp, '\'); + projdir = fp(1:slashes(end)-1); % full path to the directory containing the + % function\script that called this function, without the final slash ...\dirname + projname = st(1).name; % name of the function \ script that called this function + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + + % get the optional input (the name of the directory where things will be stored) + p = inputParser; + addParameter(p, 'proj', projname, @ischar); % + addParameter(p, 'saveStr', tstamp, @ischar); % + p.parse(varargin{:}); + p=p.Results; + specificprojdir = [projdir '\' p.proj]; + % display some output text + disp(sprintf('############################################ \n')) + disp(sprintf('File and directory info:\n')) + disp(sprintf('Project name: \n ''%s'' \n', projname)) + disp(sprintf('Directory where the project file is stored: \n ''%s'' \n', projdir)) + disp(sprintf('Directory where data will be stored: \n ''%s'' \n', specificprojdir)) + disp(sprintf('Timestamp for this run (yyyymmdd_HHMMSS): \n ''%s'' \n', tstamp)) + + % check if the project directory already exists, and create it if it doesnt. + if exist( specificprojdir ,'dir') + disp(sprintf(['Project directory already exists, using this to store data\n' ... + ' (in a subdirectory named ''%s''). \n'], ['simdata_' p.saveStr])); + + addpath(specificprojdir); + addpath(genpath(specificprojdir)); + rmpath(genpath(specificprojdir)); + mkdir([specificprojdir '\simdata_' p.saveStr]); + addpath([specificprojdir '\simdata_' p.saveStr]); + else + mkdir(specificprojdir); + mkdir([specificprojdir '\simdata_' p.saveStr]); + addpath([specificprojdir '\simdata_' p.saveStr]); + disp(sprintf(['Project directory does not exist. Creating it,' ... + ' and using this to store data\n' ... + ' (in a subdirectory named ''%s''). \n'], ['simdata_' p.saveStr])); + + end + disp(sprintf('############################################ \n')) + + +else + + fp = st(1).file; + slashes = regexp(fp, '/'); + projdir = fp(1:slashes(end)-1); % full path to the directory containing the + % function/script that called this function, without the final slash .../dirname + projname = st(1).name; % name of the function / script that called this function + tstamp = datestr(now, 'yyyymmdd_HHMMSS'); + + % get the optional input (the name of the directory where things will be stored) + p = inputParser; + addParameter(p, 'proj', projname, @ischar); % + addParameter(p, 'saveStr', tstamp, @ischar); % + p.parse(varargin{:}); + p=p.Results; + specificprojdir = [projdir '/' p.proj]; + % display some output text + disp(sprintf('############################################ \n')) + disp(sprintf('File and directory info:\n')) + disp(sprintf('Project name: \n ''%s'' \n', projname)) + disp(sprintf('Directory where the project file is stored: \n ''%s'' \n', projdir)) + disp(sprintf('Directory where data will be stored: \n ''%s'' \n', specificprojdir)) + disp(sprintf('Timestamp for this run (yyyymmdd_HHMMSS): \n ''%s'' \n', tstamp)) + + % check if the project directory already exists, and create it if it doesnt. + if exist( specificprojdir ,'dir') + disp(sprintf(['Project directory already exists, using this to store data\n' ... + ' (in a subdirectory named ''%s''). \n'], ['simdata_' p.saveStr])); + + addpath(specificprojdir); + addpath(genpath(specificprojdir)); + rmpath(genpath(specificprojdir)); + mkdir([specificprojdir '/simdata_' p.saveStr]); + addpath([specificprojdir '/simdata_' p.saveStr]); + else + mkdir(specificprojdir); + mkdir([specificprojdir '/simdata_' p.saveStr]); + addpath([specificprojdir '/simdata_' p.saveStr]); + disp(sprintf(['Project directory does not exist. Creating it,' ... + ' and using this to store data\n' ... + ' (in a subdirectory named ''%s''). \n'], ['simdata_' p.saveStr])); + + end + disp(sprintf('############################################ \n')) + + +end + +end + diff --git a/mcmc_simbio/src/rebuildMasterVec.m b/mcmc_simbio/src/rebuildMasterVec.m new file mode 100755 index 0000000..32e52da --- /dev/null +++ b/mcmc_simbio/src/rebuildMasterVec.m @@ -0,0 +1,37 @@ +function [mv] = rebuildMasterVec(rmv, mai) + % rmv = reduced master vector or array of vectors + % mai: master_info struct + % mv = rebuilt master vector. + + % sg = cell array of semantic group vectors + sg = mai.semanticGroups; + mv = zeros(size(mai.paramRanges, 1), size(rmv, 2)); + % size(rmv, 2) should be 1 right? No! This can also be + % of lenght number of walkers! so for example, minit can be + % fed into this function, as done by the integrableLHS_v2.m + + for i = 1:length(sg) + % build the matrix of semanticGroup normalizations + % This is very interesting! can write a paper about this. + % data initialization structure. + % This is a cool bit of code! Very non intuitive why I am doing + % this here. Worth explaining somewhere for future reference.... + % but am I going to? + % + % + % +% y = datasample(s,1:2,2,'Replace',false) + % + multfact = ones(numel(sg{i}), size(rmv, 2)); + for k = 1:size(rmv, 2) + y = datasample(1:numel(sg{i}),numel(sg{i}),'Replace',false); + for j = 1:length(y) + % work on the y(j)th index + multfact(y(j), k) = (-0.25 + 0.5*rand(1) + 0.74)^(y(j)-1); + + end + end + + mv(sg{i}, :) = multfact.*repmat(rmv(i, :), numel(sg{i}), 1); + end +end diff --git a/mcmc_simbio/src/reduceMasterVec.m b/mcmc_simbio/src/reduceMasterVec.m new file mode 100755 index 0000000..9726da5 --- /dev/null +++ b/mcmc_simbio/src/reduceMasterVec.m @@ -0,0 +1,34 @@ +function [rmv, rpr, sgnames] = reduceMasterVec(master_info) + % in mcmc_info = mcmc_info_constgfp3ii(modelObj), we have the note: + % semanticGroups = {1, [2 4] [3 5]}; % cant do this, then the points never +% get differentiated at all. need some jitter. think about this actually. +% +% return to that and try some things out. % working on this +% nov 2018 +% Copyright, Vipul Singhal + mv = master_info.masterVector; + estParamsIx = setdiff((1:length(mv))', master_info.fixedParams); + logp = mv(estParamsIx); + % reduce the logp (take only the first element for each group) + % nreduc = sum(cellfun(@numel, master_info.semanticGroups)) ... + % - numel(master_info.semanticGroups); + % reducedLength = length(logp) - nreduc; + reducedLength = length(master_info.semanticGroups); + % reduced master vector (actually the to-be-estimated part of it) + rmv = zeros(reducedLength, 1); + % reduced parameter ranges + pr = master_info.paramRanges; + rpr = zeros(reducedLength, 2); + sgnames = cell(reducedLength, 1); % list of names for the sematic groups + mastnames = master_info.estNames; + for i = 1:reducedLength + sgi = master_info.semanticGroups{i}; % ith sematic group + rmv(i) = logp(sgi(1)); + rpr(i, :) = [max(pr(sgi, 1)) min(pr(sgi, 2))]; + sgnames{i} = mastnames{sgi(1)}; % the first name in the group + end + +end + + + diff --git a/mcmc_simbio/src/sampleIntersections.m b/mcmc_simbio/src/sampleIntersections.m new file mode 100755 index 0000000..7e8e53f --- /dev/null +++ b/mcmc_simbio/src/sampleIntersections.m @@ -0,0 +1,43 @@ +function [Ikeep, bds, mx, mp] = sampleIntersections(m, colIdx, varargin) +%sampleIntersections Indices of the MCMC samples to use for plotting +% generate sample intersections using either custom bounds, percentile +% bounds, or MAP estimate mass bounds +% m is numSamples x numParameters matrix +% colIdx is the indices of the parameters to to use + +p = inputParser; +p.addParameter('mode','MAPmass',@ischar); % other modes: percentile, custom +p.addParameter('npoints',100,@isnumeric); +p.addParameter('bw',[],@isnumeric); +p.addParameter('mass',0.2,@isnumeric); + +p.parse(varargin{:}); +p=p.Results; + +if strcmp(p.mode, 'MAPmass') + bds = zeros(2, length(colIdx)); + mx = zeros(1, length(colIdx)); + mp = zeros(1, length(colIdx)); + Ikeep = (1:size(m, 1))'; + for i = 1:length(colIdx) + if isempty(p.bw) + [bds(:,i), mx(i), mp(i) ] = MPinterval(m(:,colIdx(i)), 'npoints', p.npoints,... + 'mass', p.mass); + else + [bds(:,i), mx(i), mp(i) ] = MPinterval(m(:,colIdx(i)), 'npoints', p.npoints,... + 'mass', p.mass, 'bw', p.bw); + BW(i) = p.bw; + end + + + Inew = find(m(:,colIdx(i))>bds(1,i) & m(:,colIdx(i))= 2 +clc +test016_ADMMvivo_Apr20 +whos +LAMBDA +XF +F_VAL +FVAL +plot(1:nITER, LAMBDA) +plot(1:3, LAMBDA) +plot(1:3, FVAL) +figure; plot(1:3, FVAL) +figure; plot(1:3, XF) +figure; plot(1:3, F_ERR) +help norm +nITER = 3 +help legend +FVALS +FVAL +test016_ADMMvivo_Apr20 +whos +test016_ADMMvivo_Apr20 +THETA = nITER +nITER = 4 +for r = [1 100 1000] +r +end +close all +a = cell(2) +a{1, 1} = 'hello' +a(2,2) = 1 +test016_ADMMvivo_Apr20 +close all +beep +beep ; beep ; beep; +beep +pause(1) +beep +pause(1) +beep +pause(1) +beep +clc +test016_ADMMvivo_Apr20 +%-- 4/21/16, 6:03 PM --% +test016_ADMMvivo_Apr20 +%-- 4/21/16, 9:32 PM --% +load allDATA_APR2016 +whos +figure +subplot(4,1,1) +p1 = plot(1:nITER, LAMBDA); +title(['lambda, rho = ' num2str(rho)]) +legend(p1, {'L1', 'L2', 'L3', 'L4'}) +subplot(4,1,2) +p2 = plot(1:nITER, XF); +title(['parameters, rho = ' num2str(rho)]) +legend(p2, {'g11', 'g12', 'g21', 'g22', 't11', 't12', 't21', 't22'}) +subplot(4,1,3) +p3= plot(1:nITER, FVAL); +title(['fvals, rho = ' num2str(rho)]) +legend(p3, {'11', '12', '21', '22'}) +subplot(4,1,4) +p4= plot(1:nITER, F_ERR); +title(['f_error, rho = ' num2str(rho)]) +figure +p5= plot(1:nITER, THETA); +title(['Theta, rho = ' num2str(rho)]) +legend(p5, {'g11', 'g12', 'g21', 'g22', 't11', 't12', 't21', 't22'}) +disp(['ITERATION ' num2str(count) 'Just Ended']) +whos +nITER +count +c2LAMBDA +size(THETA) +(THETA(end,:)) +load allDATA_APR2016_mini +THETA +cTHETA +test016_ADMMvivo_Apr20 +whos +THETA +THETA(end,:) +help legend +p3 +p3(1) +figure +subplot(4,1,1) +p1 = plot(1:nITER, LAMBDA); +title(['lambda, rho = ' num2str(rho)]) +legend(p1', {'L1', 'L2', 'L3', 'L4'}) +subplot(4,1,2) +p2 = plot(1:nITER, XF); +title(['parameters, rho = ' num2str(rho)]) +legend(p2', {'g11', 'g12', 'g21', 'g22', 't11', 't12', 't21', 't22'}) +subplot(4,1,3) +p3= plot(1:nITER, FVAL); +title(['fvals, rho = ' num2str(rho)]) +legend(p3', {'11', '12', '21', '22'}) +subplot(4,1,4) +p4= plot(1:nITER, F_ERR); +title(['f_error, rho = ' num2str(rho)]) +figure +p5= plot(1:nITER, THETA); +title(['Theta, rho = ' num2str(rho)]) +legend(p5', {'g11', 'g12', 'g21', 'g22', 't11', 't12', 't21', 't22'}) +disp(['ITERATION ' num2str(count) 'Just Ended']) +THETA(end,:) +close all +THETA(end,:) +LAMBDA(end,:) +test016_ADMMvivo_Apr20 +load allDATA_APR2016_apr21 +load allDATA_APR2016 +THETA(end,:) +THETA(end,:)' +test016_ADMMvivo_Apr20 +close close all +close all +THETA(end, :) +test016_ADMMvivo_Apr20 +%-- 4/23/16, 9:58 AM --% +test016_ADMMvivo_Apr20 +c2THETA +c2THETA{4} +test016_ADMMvivo_Apr20 +THETA +XF +test016_ADMMvivo_Apr20 +ysim.data +d11 +norm(ysim.data - d11, 2) +1e-7*0.5*norm(ysim.data - d11, 2)^2 +test016_ADMMvivo_Apr20 +m1 +m1.parameters +load test008ME_042815_175027_DATA +whos +fitparam +fitparam{2,1} +fitparam{2,1}([1,6],[1,11]) +fitparam{2,2}([1,6],[1,11]) +test016_ADMMvivo_Apr20 +clear all +whos +close all +whos +test016_ADMMvivo_Apr20 +edit test016_ADMMvivo_Apr20 +whos +%-- 4/24/16, 9:33 AM --% +ls +load allDATA_APR2016_apr22_0. +whos +plotall +simbiology +help lsqnonlin +Inf +help optimoptions +op = optimoptions('lsqnonlin') +op.Algorithm +op = optimoptions('lsqnonlin'help surf) +help surf +p = surf([1 10 100], [3, 30 300], [1 10 100]'*[3, 30 300]) +p = surf([1 10 100], [3, 30 300], [1 10 100]'*log([3, 30 300])) +close all +p = surf([1 10 100], [3, 30 300], [1 10 100]'*log([3, 30 300])) +set(p) +set(p,'XScale','log'); +clear all +load('mobj_IFFL_aTc_inflow_Feb15_estimated2_initialAtcparameter.mat'); +whos +main_CostFcnPlots +length(0.0:0.02:2) +length(0.0:0.02:2)^2 +length(0.0:0.02:0.2)^2 +main_CostFcnPlots +10201*19.618386/121 +10201*19.618386/121/60 +length(0.0:0.05:5)^2 +main_CostFcnPlots +edit transform +whos +save('visualizeCostfcn_4_24_2016') +close all +load('visualizeCostfcn_4_24_2016') +main_CostFcnPlots +toc +main_CostFcnPlots +%-- 4/29/16, 8:16 AM --% +ls +cvx_setup +%-- 6/1/16, 3:15 AM --% +help eig +A = [0 0 0; 0 0 -1/2; 0 -1/2 0] +[V,D] = eig(A) +%-- 7/8/16, 12:58 PM --% +addpath(genpath(pwd)) +edit ADMM_Apr20 +%-- 7/9/16, 6:23 AM --% +ls +Test004_allTraining_combined +Test004_ptet_expression +whos +clear all +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S1/s1_pre_estParams_2015January05_125022.mat') +whos +Test004_ptet_expression +Mobj_s1 +Mobj_s1.Events +Mobj_s1.Parameters +m = Mobj_s1; +titl = ''; +titl +isempty(titl) +help axes +help axis +Test004_s2_plac_expression +Test004_ptet_expression +Test004_s3s4_combined +xaxisticks{j} +xaxisticks{j} = [2^10^-6 2*10^-4 2*10^-2 2] +close all +Test004_s5_plasActivation +%-- 7/15/16, 4:16 AM --% +help scatter +IPTGexperimentaldata +close all +clear all +close all +placgroupeddata +who +whos +gd(1:100) +gd(1:100,1:4) +ls +txtl_init +whos +clear all +ls +edit placMobj.m +placMobj +whos +simbiology(Mobj) +whos +%-- 7/21/16, 7:58 AM --% +ls +txtl_init +placparameterestimation +clc +clear all +close all +%-- 7/23/16, 5:23 AM --% +txtl_init +%-- 7/23/16, 8:54 AM --% +edittxtl_init +edit txtl_init +txtl_init +vs_HandFit +LacIsolo +handfitting +%-- 7/26/16, 7:28 AM --% +ls +l +ls +edit handfitting +handfittingdata +whos +handfitting +txtl_init +handfitting +handfittingdataLacI +clear all +handfittingdataLacI +handfittingLacI +lacI1 +size(lacI1) +size(lacI2) +size(lacI3) +dose = nan(160,5); +dose(1,1) = 0.1; +dose(1,2) = 0.2; +dose(1,3) = 0.4; +dose(1,4) = 0.8; +dose(1,5) = 1.5; +dose = reshape(dose, 160*5, 1); +dose(1:200) +size(dose) +lacI_gd +timeI +lacI_gd +clc +gd_lacI1 +trellis(gd_lacI1) +sbiotrellis(gd_lacI1) +sbiotrellis(gd_lacI1, 'ID', 'time', 'GFP1') +lacI_gd +close all +%-- 7/30/16, 7:00 AM --% +vs_K_calibration_e35_July2016 +distinguishable_colors +HELP distinguishable_colors +help distinguishable_colors +p(1) +get(gcf) +set(gcf) +%-- 7/31/16, 5:09 AM --% +help print +vs_Mg_calibration_e35_July2016 +clear all +vs_Mg_calibration_e35_July2016 +%-- 8/6/16, 4:48 AM --% +vs_Mg_calibration_e35_July2016 +vs_K_calibration_e35_July2016_2 +vs_K_calibration_e35_July2016 +%-- 8/7/16, 1:32 PM --% +vs_K_calibration_e35_July2016_2 +close all +clear all +vs_K_calibration_e35_July2016_2 +%-- 8/7/16, 10:10 PM --% +ls +edit lacI_gd +%-- 8/7/16, 10:30 PM --% +txtl_init +lacI_gd +edit vs_CreateModelObject +edit vs_CreateModelObjectBS.m +ls +edit handfittingLacI +handfittingLacI +Mobj +who +simbiology(Mobj) +gd_lacImean +ls +edit vs_LacRules.m +vs_LacRules +clear all +vs_LacRules +simbiology(Mobj) +lacI_gd +Mobj +Mobj.parameters +Mobj.reactions +%-- 8/8/16, 3:01 AM --% +txtl_init +Plot_lacI_repression_Fits +Mobj +Mobj.parameters +vs_LacRules +Simbiology(Mobj) +simbiology(Mobj) +lacI_gd +Mobj.parameters +close all +Plot_lacI_repression_Fits +myGFPdata{1}.data +Plot_lacI_repression_Fits +vs_BSsimulation +clear all +vs_BSsimulation +BistableSwitchGrid +ParaChangeRepInd +vs_HandFit +Plot_lacI_repression_Fits +Mobj.parameters +Mobj.rules +Plot_lacI_repression_Fits +%-- 8/8/16, 7:21 AM --% +txtl_init +geneexpr +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/ModelBasedCalibrations/MatlabFiles') +MBC_test1 +DNAobj = sbioselect(Mobj2, 'Name', 'DNA p70--rbs--deGFP'); +DNAobj +DNAobj.InitialAmount +DNAobj.InitialAmount = 2 +[t,x] = txtl_runsim(Mobj2,8*60*60); +t +x +size(x) +[sd] = txtl_runsim(Mobj2,8*60*60); +sd +sd.Names +get(sd) +get(sd, 'DataNames') +ls +edit make_gd.m +selectbyname(sd, 'RNA rbs--deGFP'); +a = selectbyname(sd, 'RNA rbs--deGFP'); +a +a.data +MBC_test1 +whos +MBC_test1 +whos +tvec +(0:6:480)'; +(0:6:480)' +MBC_test1 +gd +close all +MBC_test1 +gd +Mobj2.species +MBC_test1 +sd1 +sd1.data +clc +temp +temp.data +MBC_test1 +temp.data +MBC_test1 +gd +help sbiosimulate +MBC_test1 +gd +MBC_test1 +close all +MBC_test1 +gd +clear all +close all +MBC_test1 +gd +MBC_test1 +gd +Mobj1.species +MBC_test1 +gd +MBC_test1 +whos +Mobj2.reactions +Mobj2.reactions(5) +get(Mobj2.reactions(5)) +get(Mobj2.reactions(5).KineticLaw) +get(Mobj2.reactions(5).KineticLaw.Parameters) +get(Mobj2.reactions(5).KineticLaw.Parameters(1)) +get(Mobj2.reactions(5).KineticLaw.Parameters(2)) +get(Mobj2.reactions(4).KineticLaw.Parameters(2)) +addpath('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools') +whos +ls +load('Workspace_test005_IFFL_aTc_inflow_Feb15_estimated_2.mat') +whos +clear all +load('Workspace_test005_IFFL_aTc_inflow_Feb15_estimated_2.mat') +whos +mobj +mobj.events +clear all +load('vitro_Mobj_may5_addedClpXRxn.mat') +whos +getparam(mobj) +help getparam +edit getparam +[p, pt] = getparam(mobj); +p +p(:,1:2) +p(:,1:3) +edit setparam +edit updateparam +pt +p = getparam(mobj) +clear all +close all +p = getparam(Mobj2); +p +p(1,1) +p{1,1} +Mobj2.reactions +p = getparam(Mobj2); +p(:,1:3) +who +load('vitro_Mobj_may5_addedClpXRxn.mat') +who +p_ref = getparam(mobj); +p_ref(:,1:3) +pNew={'TXTL_RNAP_S70_F', 10; +'TXTL_RNAP_S70_R' , 0.1; +'TXTL_UTR_RBS_F', 0.23; +'TXTL_UTR_RBS_R' , 104; +'TXTL_P70_RNAPbound_F' , 0.06; +'TXTL_P70_RNAPbound_R' , 725.07; +'TXTL_AA_F' , 9.0550; +'TXTL_AA_R', 325046; +'AGTPdegrate' , 2.4000e-04} +for i = 1:size(pNew, 1) +p1 = sbioselect(Mobj2.parameters, 'Name', pNew{i,1}); +set(p1, 'Value', pNew{i,2}); +end +p = getparam(Mobj2); +p +p(:,1:3) +help sbioselect +pNew={'TXTL_RNAP_S70_F', 10; +'TXTL_RNAP_S70_R' , 0.1; +'TXTL_UTR_RBS_F', 0.23; +'TXTL_UTR_RBS_R' , 104; +'TXTL_P70_RNAPbound_F' , 0.06; +'TXTL_P70_RNAPbound_R' , 725.07; +'TXTL_AA_F' , 9.0550; +'TXTL_AA_R', 325046; +'AGTPdegrate' , 1.4650e-04} +for i = 1:size(pNew, 1) +p1 = sbioselect(Mobj2, 'Type', 'parameters', 'Name', pNew{i,1}); +set(p1, 'Value', pNew{i,2}); +end +p = getparam(Mobj2); +p(:,1:3) +p(:,[1 3]) +p(:,[3]) +MBC_test1 +p = getparam(Mobj1); +p(:,1:3) +MBC_test1 +help addrule +ruleExpr = ['TotalRNA = [RNA rbs--deGFP]+[Ribo:RNA rbs--deGFP]' ... +'[AA:AGTP:Ribo:RNA rbs--deGFP] + [RNA rbs--deGFP:RNase]'... +'+ [AA:AGTP:Ribo:RNA rbs--deGFP:RNase] + [Ribo:RNA rbs--deGFP:RNase]'] +ruleExpr = ['TotalRNA = [RNA rbs--deGFP] + [Ribo:RNA rbs--deGFP] + ' ... +'[AA:AGTP:Ribo:RNA rbs--deGFP] + [RNA rbs--deGFP:RNase]'... +' + [AA:AGTP:Ribo:RNA rbs--deGFP:RNase] + [Ribo:RNA rbs--deGFP:RNase]'] +MBC_test1 +help txtl_addspecies +MBC_test1 +%-- 8/10/16, 2:27 AM --% +addpath(genpath('pwd')) +txtl_init +MBC_test2 +MBC_test2 +gd(ID==1) +gd +gd(gd.ID==1) +gd(gd.ID==1,:) +edit createKdRules +edit createKdrules +edit createKdRules +Mobj2.reactions +clear all +MBC_test2 +Mobj2.parameters +MBC_test2 +finalEstimate +fval +startPointMatrix +format long +startPointMatrix +format short g +startPointMatrix +finalEstimate +Mobj2.parameters +sbioselect(Mobj2, 'TXTL_RBS_Ribo_deGFP_Kd') +p1 = sbioselect(Mobj2, 'TXTL_RBS_Ribo_deGFP_Kd') +p1 = sbioselect(Mobj2,'Name', 'TXTL_RBS_Ribo_deGFP_Kd') +set(p1) +set(p1, 'Value', 2) +p1 = sbioselect(Mobj2,'Name', 'TXTL_RBS_Ribo_deGFP_Kd') +dnaConcIDToUse = 5 +GFP1 +gd5_1 +close all +MBC_test2 +finalEstimate +725.07/0.06 +104/0.23 +help print +print('extractx', '-djpg', '-r300') +print('extractx', '-djpeg', '-r300') +datestr +datestr(now) +MBC_test2 +finalEstimate +MBC_test2 +finalEstimate +MBC_test2 +finalEstimate +%-- 8/12/16, 1:25 AM --% +grabcode('http://web.stanford.edu/~boyd/papers/admm/basis_pursuit/basis_pursuit.html') +measuredVars = struct('colNames', 'objectNames', 'Type') +help struct +measuredVars = struct('cols', {'RNA', 'GFP'}, ... +'objectName',{'TotalRNA', 'protein deGFP*'}, ... +'type', {'species', 'species'}) +measuredVars.objectName +length(measuredVars.objectName) +a = (measuredVars.objectName) +[a, b] = deal(measuredVars.objectName) +[a, b] = size(measuredVars) +help accelerate +modelObj = sbmlimport('lotka'); +em = export(modelObj) +accelerate(em); +em.isAccelerated +mex -setup +accelerate(em); +mex -setup +accelerate(em); +em.isAccelerated +speciesGroups = struct('groupedSpecies', {'TotalRNA'},... +'speciesToGroup', {{'[RNA rbs--deGFP]', '[Ribo:RNA rbs--deGFP]',... +'[AA:AGTP:Ribo:RNA rbs--deGFP]', '[RNA rbs--deGFP:RNase]',... +'[AA:AGTP:Ribo:RNA rbs--deGFP:RNase]', '[Ribo:RNA rbs--deGFP:RNase]'}}) +speciesGroups = struct('groupedSpecies', {'TotalRNA','TotalProt'},... +'speciesToGroup', {{'[RNA rbs--deGFP]', '[Ribo:RNA rbs--deGFP]',... +'[AA:AGTP:Ribo:RNA rbs--deGFP]', '[RNA rbs--deGFP:RNase]',... +'[AA:AGTP:Ribo:RNA rbs--deGFP:RNase]', '[Ribo:RNA rbs--deGFP:RNase]'}, {'hello'}}) +specieGroups.groupedSpecies +speciesGroups.groupedSpecies +length(speciesGroups.groupedSpecies) +length(speciesGroups) +length(speciesGroups.SpeciesToGroup{1}) +(speciesGroups.SpeciesToGroup +speciesGroups.SpeciesToGroup +speciesGroups.speciesToGroup +speciesGroups.speciesToGroup(1) +speciesGroups(1).speciesToGroup +length(speciesGroups(1).speciesToGroup) +a = 1 +for i = 1:length(a)-1 +a +end +for i = 1:length(a) +a +end +speciesGroups(1).speciesToGroup +speciesGroups(1).speciesToGroup{1} +class(speciesGroups(1).speciesToGroup{1}) +expr +globalKdRules +globalKdRules(1) +globalKdRules(1).rxStr +class(globalKdRules(1).rxStr) +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/ModelBasedCalibrations/NonlinearMBC/Code_NonlinearMBC') +addpath('/Users/vipulsinghal/Dropbox/Documents/toolbox/txtl-code-166-trunk') +%-- 8/17/16, 3:27 AM --% +-nodesktop +-desktop +clc +help sbiosimulate +dosingStrat = struct('species', {'DNA p70--rbs--deGFP'},... +'concentrations', {[1 2 4 8 16]}); +dosingStrat(1).concentrations +length(dosingStrat(1).concentrations) +help sbioselect +help simdata/resample +help iscol +help isrow +magic(2) +reshape(magic(2)) +reshape(magic(2), 4, 1) +reshape(magic(4), 8, 2) +magic(4) +reshape(magic(4), 16, 1) +reshape(magic(4), 1, 16) +help reshape +help selectbyname +randn(10, 1) +help randn +help trunc +help min +min([zeros(1, 10); randn(1,10)]) +max([zeros(1, 10); randn(1,10)]) +max([zeros(1, 10); randn(1,10)]', 1) +max([zeros(1, 10); randn(1,10)]', [],1) +max([zeros(1, 10)', randn(1,10)'], [],1) +max([zeros(1, 10)', randn(1,10)'], [],2) +max([zeros(10, 1), randn(10,1)], [],2) +max([zeros(10, 1), randn(10,1)]) +max([zeros(10, 1), randn(10,1)], [],1) +max([zeros(10, 1), randn(10,1)], [],2) +help SimBiology.Export.Model +txtl_init +ls +clc +MBC_test2 +clear all +clc +clear all +MBC_test2 +exportedMdlObj +get(exportedMdlObj) +get(exportedMdlObj.SimulationOptions) +8*3600 +get(exportedMdlObj.ValueInfo) +get(exportedMdlObj(1).ValueInfo) +get(exportedMdlObj.ValueInfo(1)) +get(exportedMdlObj.ValueInfo(2)) +get(exportedMdlObj.DependentFiles) +a = get(exportedMdlObj.DependentFiles) +a = get(exportedMdlObj.DependentFiles{1}) +a = get(exportedMdlObj.DependentFiles(1)) +a = get(exportedMdlObj.DependentFiles{1}{1}) +exportedMdlObj.DependentFiles +exportedMdlObj.DependentFiles{1} +sI = get(exportedMdlObj.SimulationOptions) +get(exportedMdlObj) +help error +defaultMode = struct('simMode', {'default'}, 'paramsToEst', {}) +defaultMode = struct('simMode', {'default'}, 'paramsToEst', {''}) +whos +who +exportedMdlObj +get(exportedMdlObj) +set(exportedMdlObj) +sbioselect(exportedMdlObj, 'Type', 'species', 'Name', 'protein deGFP*') +help Simbiology.export +getIndex(exportedMdlObj) +getIndex(exportedMdlObj, 'protein deGFP*') +measuredSpecies = struct('cols', {'RNA', 'GFP'}, ... +'objectName',{'TotalRNA', 'protein deGFP*'}, ... +'type', {'species', 'species'}) +struct2cell(measuredSpecies) +a = struct2cell(measuredSpecies) +a(1,1,:) +b = a(1,1,:) +b = deal(a(1,1,:)) +[b1 , b2] = deal(a(1,1,:)) +dosingStrat = struct('species', {'DNA p70--rbs--deGFP'},... +'concentrations', {[1 2 4 8 16]}); +dosedNames = {}; +for i = 1:length(dosingStrat) +dosedNames = [dosedNames {dosingStrat(i).species}] +end +estNames = {'TXTL_RBS_Ribo_deGFP_Kd', 'TXTL_P70_RNAPbound_deGFP_Kd' }; +estParameters = sbioselect(Mobj2, 'Type', 'parameter', 'Name', estNames); +estSpecies = sbioselect(Mobj2, 'Type', 'species', 'Name', estNames); +dosedSpecies = {}; +for i = 1:length(dosingStrat) +dosedSPecies = [dosedSpecies {dosingStrat(i).species}] +end +estNames = {'TXTL_RBS_Ribo_deGFP_Kd', 'TXTL_P70_RNAPbound_deGFP_Kd' }; +estParameters = sbioselect(Mobj2, 'Type', 'parameter', 'Name', estNames); +estSpecies = sbioselect(Mobj2, 'Type', 'species', 'Name', estNames); +dosedNames = {}; +for i = 1:length(dosingStrat) +dosedNames = [dosedNames {dosingStrat(i).species}] +end +dosedSpecies = sbioselect(Mobj2, 'Type', 'species', 'Name', dosedNames); +[estParameters; estSpecies; dosedSpecies] +a = [estParameters; estSpecies; dosedSpecies] +a(1) +a(2) +a(3) +estParameters +estNames = {'TXTL_RBS_Ribo_deGFP_Kd'; 'TXTL_P70_RNAPbound_deGFP_Kd' }; +estParameters = sbioselect(Mobj2, 'Type', 'parameter', 'Name', estNames); +estSpecies = sbioselect(Mobj2, 'Type', 'species', 'Name', estNames); +dosedNames = {}; +for i = 1:length(dosingStrat) +dosedNames = [dosedNames; {dosingStrat(i).species}] +end +dosedSpecies = sbioselect(Mobj2, 'Type', 'species', 'Name', dosedNames); +a = [estParameters; estSpecies; dosedSpecies] +clear all +close all +clc +MBC_test2 +exportedMdlObj +get(exportedMdlObj) +VI = get(exportedMdlObj) +VI = (exportedMdlObj.ValueInfo) +getIndex(exportedMdlObj, 'DNA p70--rbs--deGFP') +VI(getIndex(exportedMdlObj, 'DNA p70--rbs--deGFP')) +gfp = VI(getIndex(exportedMdlObj, 'DNA p70--rbs--deGFP')) +gfp.InitialValue +gfp.InitialValue = 1 +VI(getIndex(exportedMdlObj, 'DNA p70--rbs--deGFP')) +get(exportedMdlObj) +exportedMdlObj.SimulationOptions +SI = exportedMdlObj.SimulationOptions +SI.StopTime +exportedMdlObj.InitialValues +format long +exportedMdlObj.InitialValues +gd_1 +gd_1.GFP1(gd_1.ID==1) +a = {ones(4,1), 2*ones(4,1);3*ones(5,1), 4*ones(5,1)} +a{:} +vertcat(a{:}) +mean(magic(3)) +mean(magic(3),1) +mean(magic(3),2) +meanVals = [1 5 10] +relativeWt = 1./(meanVals/sum(meanVals)) +relativeWt.*meanVals +sum(meanVals)/meanVals +sum(meanVals)./meanVals +a = sum(meanVals)./meanVals +a/sum(a) +function_design_script +repmat(1:nDoseCombinations, length(tvec), 1) +numel(repmat(1:nDoseCombinations, length(tvec), 1)) +prod(length(tvec), nDoseCombinations) +ID = reshape(repmat(1:nDoseCombinations, length(tvec), 1) , ... +prod([length(tvec), nDoseCombinations]), 1); +ID +function_design_script +DOSE1 +CONC +function_design_script +measuredSpecies(i).cols +GFP +RNA +help groupedData +function_design_script +length(gdi.TIME) +measuredSpecies(i).cols +function_design_script +gd +gd.RNA +function_design_script +dosedInitVals +function_design_script +finalEstimate +format short g +finalEstimate +m1.reactions +m1.reactions(12) +m1.reactions(12).getparameters +get(m1.reactions(12)) +get(m1.reactions(12).KineticLaw) +get(m1.reactions(12).KineticLaw.Parameters) +m1.Species +sbioselect(m1, 'Name', 'RNAP') +sbioselect(m1, 'Type', 'Species', 'Name', 'RNAP') +rnap = sbioselect(m1, 'Type', 'Species', 'Name', 'RNAP') +rnap.InitialAmount +rnap.InitialAmount = 20 +nlMBC_T2 +finalEstimate +scatter(finalEstimate) +help scatter +scatter(finalEstimate(:,1), finalEstimate(:,2)) +sc = scatter(finalEstimate(:,1), finalEstimate(:,2)) +set(sc) +ca = gca +set(ca, 'XScale', 'log', 'YScale', 'Log') +nlMBC_T2 +finalEstimate +startPointMatrix +startPointMatrix{1} +figure; sc2 = scatter(startPointMatrix{1}finalEstimate(:,1), startPointMatrix{1}(:,2)); set(gca, 'XScale', 'log', 'YScale', 'Log'); +figure; sc2 = scatter(startPointMatrix{1}(:,1), startPointMatrix{1}(:,2)); set(gca, 'XScale', 'log', 'YScale', 'Log'); +startPointMatrix{:} +vertcat(startPointMatrix{:}) +vertcat(startPointMatrix{:})(:,1) +vertcat(startPointMatrix{:}(:,1)) +spm = vertcat(startPointMatrix{:}); +spm(:,1) +spm = vertcat(startPointMatrix{:});spm = vertcat(startPointMatrix{:}); +figure; sc2 = scatter(spm(:,1), spm{1}(:,2)); set(gca, 'XScale', 'log', 'YScale', 'Log'); +figure; sc2 = scatter(spm(:,1), spm(:,2)); set(gca, 'XScale', 'log', 'YScale', 'Log'); +help axis +close all +help tight_subplot +help smplot +%-- 8/18/16, 8:03 AM --% +clc +help smplot +smplot(3,4,1,'right',0.2,'bottom',0.5) +smplot(3,4,12,'right',0.2,'bottom',0.5) +for k = 1:21 +smplot(7,3,k) +imagesc(peaks(300)) +axis off +end +% Create some example data: +[X,Y,Z] = peaks(300); +xv=[-66,-104,-151,-193,-133,-125,-75,-6,133,234,196,204,132,117]/100; +yv=[276,220,89,-38,-134,-222,-268,-280,-259,-213,-104,66,162,252]/100; +in = inpolygon(X,Y,xv,yv); +Z(~in) = NaN; +% Plot 24 datasets: +for k = 1:24 +smplot(6,4,k,'right',0.1) +pcolor(X,Y,Z+3*randn(1)+3*sin(k/4)) +shading flat +caxis([-12 12]) +axis off +end +cb = colorbar('east'); +set(cb,'Position',[0.92 0.1 0.04 0.8]) +close all +% Create some example data: +[X,Y,Z] = peaks(300); +xv=[-66,-104,-151,-193,-133,-125,-75,-6,133,234,196,204,132,117]/100; +yv=[276,220,89,-38,-134,-222,-268,-280,-259,-213,-104,66,162,252]/100; +in = inpolygon(X,Y,xv,yv); +Z(~in) = NaN; +% Plot 24 datasets: +for k = 1:24 +smplot(6,4,k,'right',0.1) +pcolor(X,Y,Z+3*randn(1)+3*sin(k/4)) +shading flat +caxis([-12 12]) +axis off +end +cb = colorbar('east'); +set(cb,'Position',[0.92 0.1 0.04 0.8]) +close all +for k = 1:12 +smplot(3,4,k,'axis','on') +plot(rand(6,2),'p'); +axis tight +end +help subaxis +subaxis(2,1,1,'SpacingVert',0,'MR',0); +imagesc(magic(3)) +close all +subaxis(2,1,1,'SpacingVert',0,'MR',0); +imagesc(magic(3)) +close all +subaxis(2,'p',.02); +subaxis(2,1,1,'SpacingVert',0,'MR',0); +imagesc(magic(3)) +subaxis(2,'p',.02); +imagesc(magic(4)) +edit subaxis +help tightplot +help tightPlot +help tightPlots +edit tightPlots +addpath(genpath(pwd)) +help tightPlots +nlMBC_T2 +clear all +nlMBC_T2 +who +help save +save('first_run') +fval{1} +fval{end} +help subtightplot +figure; +subtightplot(2,2,1, 0.3, 0.1, 0.1) +subtightplot(2,2,2, 0.3, 0.01, 0.01) +subtightplot(2,2,2, 0.1, 0.01, 0.01) +subtightplot(2,2,2, 0.01, 0.01, 0.01) +subtightplot(2,2,1, 0.01, 0.01, 0.01) +subtightplot(2,2,1, 0.07, 0.01, 0.01) +subtightplot(2,2,2, 0.07, 0.01, 0.01) +subtightplot(2,2,2, 0.05, 0.05, 0.05) +subtightplot(2,2,3, 0.05, 0.05, 0.05) +subtightplot(2,2,4, 0.05, 0.05, 0.05) +subtightplot(2,2,4, 0.04, 0.04, 0.04) +edit testScript +close all +ff +get(ff) +set(ff) +close all +help subtightplot +close all +testScript +edit subtightplot +help ind2sub +testScript +help subplot +help legend +help xlabel +ff +ff.CurrentAxes +ff.Children +ff.Children(1) +ff.Children(2) +help suplabel +edit suplabel +[ax4,h3]=suplabel('super Title' ,'t'); +testScript +close all +testScript +nR = 5 +c = 7 +mod(c, nR) +testScript +%-- 8/19/16, 10:38 AM --% +help deal +axBuf=.02; +[leftBuff, rightBuff, topBuff, BotBuff] = deal(axBuf); +leftBuff +help inputParser +help isstring +ischar +help ischar +a = [1 2 3 4] +[p q r s] = deal(a) +[p q r s] = deal(a(:)) +a = {1 2 3 4} +[p q r s] = deal(a{:}) +class(p) +help mfilename +help isstr +testScript +help ylabel +ylabel(ax4, 'This YLabel') +testScript +suplabel_vs +testScript +suplabel_vs +testScript +help smallplots +edit suplabel_vs +%-- 8/23/16, 3:56 AM --% +help iscell +help addParameter +struct('legends', {''}, 'position', [0.87,0.85,0.05,0.1])struct('legends', {''}, 'position', {[0.87,0.85,0.05,0.1]}) +struct('legends', {''}, 'position', [0.87,0.85,0.05,0.1])*struct('legends', {''}, 'position', {[0.87,0.85,0.05,0.1]}) +struct('legends', {''}, 'position', {[0.87,0.85,0.05,0.1]}) +struct('legends', {{}}, 'position', {[0.87,0.85,0.05,0.1]}) +a = struct('legends', {{}}, 'position', {[0.87,0.85,0.05,0.1]}) +a.legends +isempty(a.legends) +isempty({''}) +isempty({}) +isempty({{}}) +help index +help indices +help findindex +help ind2sub +[h,v] = ind2sub([5,7], 12) +[r,c] = ind2sub([5,7], 12) +% i see, it counts downwards +[col, row] = ind2sub([7,5], 12) +%-- 9/4/16, 11:28 AM --% +mcmc_example1 +%-- 9/4/16, 11:33 AM --% +% METROPOLIS SAMPLING EXAMPLE +randn('seed',12345); +% DEFINE THE TARGET DISTRIBUTION +p = inline('(1 + x.^2).^-1','x') +% SOME CONSTANTS +nSamples = 5000; +burnIn = 500; +nDisplay = 30; +sigma = 1; +minn = -20; maxx = 20; +xx = 3*minn:.1:3*maxx; +target = p(xx) +plot(target) +plot(xx,target) +%-- 9/4/16, 11:41 AM --% +p = @(x)((1 + x.^2).^-1) +p(3) +randn('seed',12345); +randn('seed',12345) +nSamples = 5000; +burnIn = 500; +nDisplay = 30; +sigma = 1; +minn = -20; maxx = 20; +xx = 3*minn:.1:3*maxx; +target = p(xx) +pauseDur = .8; +x = zeros(1 ,nSamples); +x(1) = randn; +t = 1; +mcmc_example1 +a = +a = normrnd(2,1) +%-- 9/7/16, 6:08 AM --% +magic(4) +%-- 9/7/16, 6:20 AM --% +help toolbox_path_cache +%-- 9/7/16, 6:29 AM --% +ls +cd toolbox +%-- 9/7/16, 6:31 AM --% +ls +cd toolbox +ls +cd txtl-code-166-trunk +ls +txtl_init +geneexpr +dir examples +negautoreg +simbiology +clc +randn('seed',12345); +p = @(x)((1 + x.^2).^-1) +mcmc_example1 +test_001_ODE23 +help ode23 +help ode15s +help sprintf +%-- 9/7/16, 10:19 AM --% +clc +%-- 9/7/16, 10:46 AM --% +1 + 1 +%-- 9/7/16, 11:11 AM --% +filebrowser +%-- 9/7/16, 1:43 PM --% +filebrowser +%-- 9/7/16, 1:44 PM --% +untitled +edit ex_linefit.m +ex_linefit +ex_behappy +edit ex_behappy.m +%-- 9/8/16, 5:21 AM --% +help polyfit +help log +log([1, 2, 3]) +ex_linefit +help fminsearch +polyfit(x,y,1) +[polyfit(x,y,1) 0]' +10*rand(length(tspan),1) +close all +tic +a_m = 40; +a_p = 100; +K_m = 30; +K_p = 20; +d_m = 0.1; +dil = 0.5; +p = [a_m, a_p, K_m, K_p, d_m, dil]; +tspan = [0:1:20]; +DNAconc = [1 16 128]; +sconc = cell(length(DNAconc),1); +figure +for i = 1:length(DNAconc) +sp0 = [DNAconc(i) 0 0]; +[t,sconc{i}] = ode15s(@(t,sp) constitutive_gfp(t,sp,p), tspan, sp0); +noise_gfp = 10*rand(length(tspan),1); +noise_rna = 15*rand(length(tspan),1); +sconc{i}(:,2) = sconc{i}(:,2) + noise_rna; +sconc{i}(:,3) = sconc{i}(:,3) + noise_gfp; +subplot(length(DNAconc),1,i) +plot(tspan,sconc{i}(:,2),'-',t,sconc{i}(:,3),'-.') +title(sprintf('Initial DNA concentration %s units', num2str(DNAconc(i)))) +legend({'mRNA', 'GFP'}) +xlabel('time/arbitrary units') +ylabel('AFU') +end +genemodel = @(p, sp0) ode15s(@(t,sp) constitutive_gfp(t,sp,p), tspan, sp0); +gene +genemodel +p +genemodel(p,sp0) +sp0 +conc = genemodel(p,sp0) +conc.extdata +conc.x +tspan +conc.y +conc.stats +conc.idata +[t, conc] = genemodel(p,sp0) +figure; plot(t,conc) +help rand +help randn +m = magic(4) +a = m(:) +1>2 || 3>2 +[1>2 || 3>2; +4 = 3 || 2<6] +[1>2 || 3>2; +4 == 3 || 2<6] +[1>2 || 3>2 ... +&& 4==3 || 2<6] +[1>2 || 3>2 ... +&& 4==3 || 2>6] +exp(2) +a = [-3; 2; 4] +a>-6 +istrue(a>-6) +all(a>-6) +e^-12 +exp(-12_ +exp(-12) +exp(-18) +exp(-20) +help bsxfun +help lhs +help lhsample +help lhsdesign +X = lhsdesign(4, 3) +X = lhsdesign(4, 9) +a_m = 40; +a_p = 100; +K_m = 30; +K_p = 20; +d_m = 0.1; +dil = 0.5; +logp = log([a_m, a_p, K_m, K_p, d_m, dil]) +edit constitutive_gfp.m +clear all +test_002_ODE23_test +minit +size(minit) +test_002_ODE23_test +clear all +close all +clc +test_002_ODE23_test +help rand +test_002_ODE23_test +help suplabel +whos +help save +save('t002_8Sep2016_1545') +help gwmcmc +test_002_ODE23_test +a = 1 +test_002_ODE23_test +whos +save('t002_big_sim_sep8_2016') +close all +test_002_ODE23_test +exp(-12) +exp(12) +exp(6) +exp(-6) +nparam +lhsamp = 24*(lhsdesign(nW, nparam)-0.5); +size(lhsamp) +lhsamp +exp(lhsamp) +format short g +exp(lhsamp) +help gwmcmc +test_002_ODE23_test +%-- 9/9/16, 10:03 PM --% +size(m) +save('giiiid 5mil lhs') +close all +clear all +load('giiiid 5mil lhs') +%-- 9/16/16, 5:04 AM --% +ls +load test003_sep15_simresults4param +whos +estParameters +ls +edit testScript.m +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/Advanced Matlab Tools/mcmc_grinsted-gwmcmc-2c86b0e') +testScript +clear all +load test003_sep14_simresults3param +estParameters +testScript +load test003_sep15_simresults4param +testScript +%-- 9/17/16, 12:45 PM --% +load NESSA_test003_6param_sep15_1 +whos +estNames +testScript +clc +testScript +addpath('/Users/vipulsinghal/Dropbox/Documents/MATLAB') +testScript +exp([-6 0 -5.33 2.6]) +113414/3600 +%-- 9/19/16, 7:33 AM --% +close all +clear all +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/Advanced Matlab Tools/mcmc_grinsted-gwmcmc-2c86b0e') +addpath('/Users/vipulsinghal/Dropbox/Documents/vipul_repo/MBC/Code_NonlinearMBC') +currdir = pwd; +txtldir = '/Users/vipulsinghal/Dropbox/Documents/toolbox/txtl-code-166-trunk'; +cd(txtldir) +txtl_init % txtl toolbox subdirectories path initialization +cd(currdir) +help meshgrid +meshgrid(1:5,6:10) +reshape(meshgrid(1:5,6:10),25,1) +reshape(meshgrid(1:5,6:10),25,1)' +xcol1 = reshape(meshgrid(1:6,6:11),36,1)' +length(xcol) +length(ycol) +close all +concat_arrays +help axis +whos +concat_arrays +scplot = scatter(m(:,c),m(:,r),'.') +concat_arrays +p.range +help prctile +help position +help clf +help gcf +concat_arrays +set(ff, 'Position', [100 100 900 800]) +set(gcf, 'Position', [100 100 900 800]) +set(gcf, 'Position', [200 100 900 800]) +set(gcf, 'Position', [50 100 900 800]) +set(gcf, 'Position', [50 200 400 400]) +set(gcf, 'Position', [50 400 400 400]) +get(0) +get(0, 'ScreenSize') +xs = 500; ys = 600; set(gcf, 'Position', [50 850-ys xs ys]) +xs = 500; ys = 900; set(gcf, 'Position', [50 850-ys xs ys]) +xs = 500; ys = 1400; set(gcf, 'Position', [50 850-ys xs ys]) +xs = 500; ys = 1800; set(gcf, 'Position', [50 850-ys xs ys]) +help print +%-- 9/19/16, 5:19 PM --% +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/Advanced Matlab Tools/mcmc_grinsted-gwmcmc-2c86b0e') +addpath('/Users/vipulsinghal/Dropbox/Documents/vipul_repo/MBC/Code_NonlinearMBC') +currdir = pwd; +txtldir = '/Users/vipulsinghal/Dropbox/Documents/toolbox/txtl-code-166-trunk'; +cd(txtldir) +txtl_init % txtl toolbox subdirectories path initialization +cd(currdir) +concat_arrays +%-- 9/20/16, 2:33 PM --% +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/Advanced Matlab Tools/mcmc_grinsted-gwmcmc-2c86b0e') +addpath('/Users/vipulsinghal/Dropbox/Documents/vipul_repo/MBC/Code_NonlinearMBC') +load test002_lhInitialpts_5million_sep8_2016 +%-- 9/21/16, 2:04 AM --% +load test004_sep19_2016_E1 +whos +m1 = m; +load test004_sep19_2016_E2 +m2 = m; +size(m) +close all +exp([3.6 3.8 3.9 0.9 -1.2 -0.9]) +exp([3.9 3.6 1.2 5 -1.2 -0.6]) +load test004_sep20_2016_E1_linp +whos +linp +m1 = m; +%-- 9/21/16, 5:37 AM --% +m1 +clc +whos +save('this_is_m1', 'm1') +m1 +clear all +load this_is_m1 +m1 +load this_is_m1 +m1 +m1.reactions +m1.reactions(3) +m1.reactions(3).KineticLaw +m1.reactions(3).KineticLaw.getparameters +m1.reactions(4).KineticLaw.getparameters +m1.reactions(5).KineticLaw.getparameters +%-- 9/28/16, 7:02 AM --% +help subplot +%-- 9/28/16, 11:52 AM --% +process_test_005_sep26_MBP +logp2 +%-- 9/30/16, 9:39 AM --% +exp([11.5 +-9.61 +3.23 +-2.5 +-7.51 +-9.89 +2.11 +-0.549 +2.66 +9.77 +-14 +-0.732 +7.38 +-6.47 +14.6]) +format short g +14.6]) +exp([11.5 +-9.61 +3.23 +-2.5 +-7.51 +-9.89 +2.11 +-0.549 +2.66 +9.77 +-14 +-0.732 +7.38 +-6.47 +14.6]) +%-- 10/2/16, 3:01 AM --% +edit poolStartup.m +test003_sep30_3 +minit +size(minit) +whos +load('test003_sep30_2', 'm') +size(m) +load('test003_sep30', 'm') +size(m) +load('test003_sep30_2', 'm') % size(m) is 15 x 1600 x 14 +minit = m(:,1:4:1600,end); +size(minit) +test003_sep30_3 +whos +load('test003_sep30_3', 'm') +whos +test003_sep30_3 +process_test003_30_3 +size(m1) +size(m2) +size(m3) +load('test004_sep30_E1_5_MBP.mat', 'm', 'logp') +logp +log p +logp +exp(1.1) +exp(5.25) +test007_plot_posterior_simpleE1_oct2 +clear all +load('test003_sep30.mat') +m0 = m(:,:)'; +whos +tspan +size(tspan) +size(tspan,1)*5 +clear all +close all +test007_plot_posterior_simpleE1_oct2 +whos +test007_plot_posterior_simpleE1_oct2 +measuredSpecies +measuredSpecies(2) +test007_plot_posterior_simpleE1_oct2 +h +test007_plot_posterior_simpleE1_oct2 +size(conc) +test007_plot_posterior_simpleE1_oct2 +r +mtxtl(r,:) +help hist +help histogram +mm = mtxtl(r,:); +histogram(mtxtl(:,10)) +close all +histogram(mtxtl(:,10)) +I = find(-1.5bds(1,colIdx(i)) +[Ikeep, bds, mx, mp] = sampleIntersections(m(:,:)', [10 11 12]); +size(Ikeep) +Ikeep +plot(Ikeep) +bds +mx +mp +length(size(m)) +help ndim +ndim(m) +ndims(m) +[Ikeep] = sampleIntersections(m(:,:)', [10 11 12]); +Ikeep +colorschemes +colorschemes('plot') +tspan +length(tspan) +clear all +close all +clc +process_test003_oct12_withFunctions +whos +process_test003_oct12_withFunctions +rejProp +plotChains(m) +help plotchains +edit plotChains +plotChains(m, 100, legs) +legends = { 'k_{term}' +'RNAd_{cat}' +'RBS_{Kd}' +'prom_{Kd}' +'s70_{Kd}' +'NTP_{Kd1}' +'NTP_{Kd2}' +'AA_{Kd}' +'RNAd_{Kd}' +'k_{emrna}' +'k_{eprot}' +'RNAP' +'s70' +'Ribo' +'RNase'}; +plotChains(m, 100, legends) +process_test003_oct12_withFunctions +whos +rejProp +plot(rejProp) +gcf +figure; plot(rejProp) +close all +clear all +lead test003_oct11_ss_0p011 +load test003_oct11_ss_0p011 +whos +loglike +clc +process_test003_oct12_withFunctions +p.mass +help addOptional +process_test003_oct12_withFunctions +help break +process_test003_oct12_withFunctions +close all +clear all +help MPestimate +ls +help MPinterval +edit MPinterval +edit test008_oct11_tightLikelihood.m +edit test009s0s1 +test009s0s1 +clear all +close all +clc +whos +test009s0s1 +log([1e-4 1e4]) +exp([-8 8]) +format short g +exp([-8 8]) +exp([-7 7]) +test008_oct11_tightLikelihood +m +whos +clear all +close all +clc +load test008_oct14_burnin_smallerlims +whos +logpjoint +logpjoint/log(10) +I = sampleIntersections(mcat_l10, 1:8, 'mass', 0.02, 'npoints', 500); +mean(mcat_l10(I, :)) +I = sampleIntersections(mcat_l10(:,:)', 1:8, 'mass', 0.02, 'npoints', 500); +mm = (mcat_l10(:, :)'); +mean(mm(I, :)) +mcat_l10 +mm = (mcat_l10(:, :)'); +I = sampleIntersections(mm, 1:8, 'mass', 0.02, 'npoints', 500); +I(1:10) +size(I) +I = sampleIntersections(mm, 1:8, 'mass', 0.2, 'npoints', 500); +I +size(mm) +I = sampleIntersections(mm, 1:8, 'mass', 0.2, 'npoints', 50); +I +I = sampleIntersections(mm, 1:8, 'mass', 0.5, 'npoints', 50); +I +size(I) +I = sampleIntersections(mm, 1:8, 'mass', 0.5, 'npoints', 500); +size(I) +mean(mm(I, :)) +logpjoint/log(10) +I = sampleIntersections(mm, 1:8, 'mass', 0.5, 'npoints', 100); +I = sampleIntersections(mm, 1:8, 'mass', 0.5, 'npoints', 100); mean(mm(I, :)) +I = sampleIntersections(mm, 1:8, 'mass', 0.2, 'npoints', 100); mean(mm(I, :)) +I = sampleIntersections(mm, 1:8, 'mass', 0.9, 'npoints', 100); mean(mm(I, :)) +I = sampleIntersections(mm, 1:8, 'mass', 0.99, 'npoints', 100); mean(mm(I, :)) +logpjoint/log(10) +mean(mm) +median(mm) +exp(logpjoint(3:6)) +I = sampleIntersections(mm, 1:8, 'mass', 0.5, 'npoints', 100); mean(mm(I, :)) +clc +estparams +logpjoint +100*(logpjoint-estparams)./logpjoint +(logpjoint-estparams)./logpjoint +round(100*(logpjoint-estparams)./logpjoint) +exp(estparams) +exp(estparams)' +exp(median(msimple))' +test009s0s1 +%-- 10/16/16, 1:53 PM --% +test008_oct11_tightLikelihood +43000/3600 +test003_oct11_tightLikelihood +m1 +m1.parameters +exp(8) +exp(9) +exp(-9) +exp(-8) +exp(8) +test003_oct11_tightLikelihood +18*rand(1)+lb/(ub-lb) +18*rand(10)+lb/(ub-lb) +lb +lb/(ub-lb) +rsamp = (ub-lb)*rand(nparam, 5) +lb +hist(rsamp()) +hist(rsamp(:)) +figure; hist(rsamp(:)) +rsamp = (ub-lb)*rand(nparam, nW) +lb; +figure; hist(rsamp(:)) +figure; hist(rsamp(:), 100) +rsamp = (ub-lb)*rand(nparam, nW*3) +lb; +figure; hist(rsamp(:), 100) +test003_oct11_tightLikelihood +rsamp +clear all +clc +close all +test003_oct11_tightLikelihood +logprior(rsamp) +logprior(rsamp(:,1)) +for i = 1:nW +end +check = 1 +for i = 1:nW +check = logprior(rsamp(:,i))*check; +end +check +test003_oct11_tightLikelihood +logP(:,:,1) +test003_oct11_tightLikelihood +%-- 10/17/16, 12:27 PM --% +randn(1) +estparams' +logpjoint' +exp(estparams') +clear all +load test009s0s1_oct15_burnin_smallerlims +whos +legs +legends +size(m) +legends{1:2, 5:6} +legends{[1:2, 5:6]} +legends{[1:2, 5:6]}' +legends([1:2, 5:6])' +edit plotChains +datafiles = {'test009s0s1_oct15_burnin_smallerlims' +'test009s0s1_oct15_1_MBP_smallerlims' +'test009s0s1_oct15_2_MBP_smallerlims' +'test009s0s1_oct15_3_MBP_smallerlims' +'test009s0s1_oct15_4_MBP_smallerlims' +'test009s0s1_oct15_5_MBP_smallerlims'}; +legends = {'a_m' 'a_p' 'K_m_2' 'K_p_2'}; +mcat = catMC(datafiles); +plotChains(mcat, 200, legends ); +test009s2 +a_m_est = partmedian(1) +a_p_est = partmedian(2) +d_m_est = partmedian(3) +d_p_est = partmedian(4) +K_m_est_e1 = exp(estparams(3)) +K_p_est_e1 = exp(estparams(4)) +K_m_est_e2 = exp(estparams(5)) +K_p_est_e2 = exp(estparams(6)) +K_m_est_e1 = exp(estparams(3)) +K_p_est_e1 = exp(estparams(4)) +test009s2 +clear all +load test008_oct14_2_MBP_smallerlims +tspan +load test009s0s1_oct15_2_MBP_smallerlims +tspan +test009s2 +clc +maxRNA = max(max(spconc_e2data(:,2,:))) +get(f) +get(f, 'Children') +aaa = get(f, 'Children') +aaa(1) +class(aaa(1) +class(aaa(1)) +class(aaa(2)) +help isaxis +class(aaa(2)) +aaa = get(f, 'Children') +help isa +isa(aaa(2), 'matlab.graphics.axis.Axes') +aaa(2) +get(aaa(2)) +maxGFP = max(max(spconc_e2data(:,3,:))) +test009s2 +close all +whos +test009s2 +cc +test009s2 +close all +clear all +close all +clear all +load('test008_oct14_10_MBP_smallerlims_ssp5') +whos +format short g +ans +process_test008_withFunctions +test009s2 +whos +test009s2 +close all +clc +ex_rosenbrockbanana +test003_oct11_tightLikelihood +eig([1 -1; -1 1]) +%-- 10/19/16, 7:23 PM --% +HW3q5i +cvx_setup +HW3q5i +help NARGINCHK +HW3q5i +help nargchk +HW3q5i +warning('off','all') +HW3q5i +X +X(:,1:2) +help iszero +help isnan +sum(X(:,2) == 0) +HW3q5i +help norm +HW3q5i +(A*A') +(A*A')\y +A'*(A*A')\y +A'*((A*A')\y) +HW3q5i +imagesc(success) +success(1:5,1:5) +size(success) +clear all +cvx_quiet true +help cvx_quiet +cvx_quiet +cvx_quiet(TRUE) +cvx_quiet(true) +cvx_quiet +HW3q5i +cvx_quiet +cvx_quiet(true) +HW3q5i +x +sum(x) +(x(1)+3)^2 + (x(2)^2+1) + exp(x(3)/10) + 20*x(4)+2 +y = x + [-3 +1 1 1] +y = x + [-3 +1 1 1]' +y = x +x = y + [-3 +1 1 1]' +(x(1)+3)^2 + (x(2)^2+1) + exp(x(3)/10) + 20*x(4)+2 +help surf +help imagesc +success +save('cvx_hw3_q5') +%-- 10/20/16, 8:11 AM --% +test003_oct11_tightLikelihood +clc +size(simulatedDataMatrix) +nt = length(tspan); +for i = 1:5 +subplot(5, 2, (i-1)*2+1) +plot(tspan, simulatedDataMatrix((i-1)*nt+1:(i-1)*nt, 1)) +hold on +title('mrna') +subplot(5, 2, (i-1)*2+2) +plot(tspan, simulatedDataMatrix((i-1)*nt+1:(i-1)*nt, 2)) +hold on +title('gfp') +end +nt = length(tspan); +for i = 1:5 +subplot(5, 2, (i-1)*2+1) +plot(tspan, simulatedDataMatrix((i-1)*nt+1:(i)*nt, 1)) +hold on +title('mrna') +subplot(5, 2, (i-1)*2+2) +plot(tspan, simulatedDataMatrix((i-1)*nt+1:(i)*nt, 2)) +hold on +title('gfp') +end +estParameters +estSpecies +dosedNames +dosedSpecies +exportedMdlObj +[tt, cc] = simulate(exportedMdlObj); +size(tt) +size(cc) +[sdsd] = simulate(exportedMdlObj); +sdsd +get(sdsd) +get(sdsd, DataInfo) +get(sdsd, 'DataInfo') +get(sdsd, 'DataNames') +selectbyname(sdsd, 'protein deGFP*') +GFPdata = selectbyname(sdsd, 'protein deGFP*') +figure; plot(sdsd.time, GFPdata.Data) +doc selectbyname +sbioplot(sdsd) +test003_oct11_tightLikelihood +edit gwmcmc_vse.m +i +figure; plot(spSd.time, spSD.data) +spSD +get(spSD) +figure; plot(spSd.Time, spSD.Data) +figure; plot(spSD.Time, spSD.Data) +figure; plot(spSD.Time, spSD(2).Data) +figure; plot(spSD.Time, spSD.Data(:,2)) +figure; plot(spSD.Time, spSD.DataNames(:,2)) +figure; plot(spSD.Time, spSD.DataNames{2}) +spSD.DataNames{2} +spSD.DataNames{1} +figure; plot(spSD.Time, spSD(2).Data) +figure; plot(spSD.Time, spSD.Data) +test003_oct11_tightLikelihood +logPfuns{fix} +minit(:,wix) +logPfuns{fix}(minit(:,wix)) +size(CONC_temp,1) +exportedMdlObj +get(exportedMdlObj) +get(exportedMdlObj, 'ValueInfo') +vi = get(exportedMdlObj, 'ValueInfo') +vi.Name +vi.Name' +spSD.Data +clc +spSD +spSD.Names +spSD.Name +get(spSD) +get(sd) +get(sd, 'DataNames') +get(sd.Data ) +figure; plot(timevec, selectbyname(sd, 'AGTP')) +agtp = selectbyname(sd, 'AGTP') +figure; plot(timevec, agtp.data) +logprior(logp) +logp +hist(randn(100,1)) +close all +hist(randn(100,1)) +hist(randn(1500,1)) +hist(randn(15000,1)) +hist(randn(150000,1)) +hist(0.5randn(150000,1)) +hist(0.5*randn(150000,1)) +hist(2*randn(150000,1)) +hist(1.5*randn(150000,1)) +lb =logp-9; +ub =logp+9; +nW = 400; %number of walkers +sd = 1; +rnsamp = sd*randn(nparam,nW); +mdpts = (lb+ub)/2; +minit=bsxfun(@plus,mdpts,rnsamp); +logprior(minit(:,1)) +for i = 1:400 +lpr(i) = logprior(minit(:,i)); +end +all(lpr) +minit=bsxfun(@plus,mdpts,rnsamp); +for i = 1:400 +lpr(i) = logprior(minit(:,i)); +end +all(lpr) +minit(:,1:10) +[minit(:,1:10), logp] +test003_oct11_tightLikelihood +help lhsample +help lhdesign +exp(-15) +exp(15) +exp(12) +exp(-12) +test003_oct20_LHS_truecentered +clear all +close all +clc +test003_oct20_LHS_truecentered +lhsamp(1:10, :) +figure; scatter(lhsamp(:, 1:2)) +figure; scatter(lhsamp(:, 1),lhsamp(:, 1)) +figure; scatter(lhsamp(:, 1),lhsamp(:, 2)) +figure; scatter3(lhsamp(:, 1),lhsamp(:, 2), lhsamp(:, 3)) +whos +size(nim) +numel(nim == 0) +numel(nim) +numel(m) +load test003_oct20_stp2p5_tght1_LHStruecenter_burnin +numel(m) +size(m) +whos +80*662 +800*662 +800*662/1.1 +nim(1:10,1:10,1:10) +(nim == 0) +-Inf <-Inf +%-- 10/23/16, 6:20 AM --% +test003_oct11_tightLikelihood +clear all +close all +clc +test003_oct11_tightLikelihood +logP(:,:,1) +test003_oct11_tightLikelihood +logP(:,:,1) +test003_oct11_tightLikelihood +5e5/40/800 +ceil(5e5/40/800) +15*40+1 +15*40+1*1.1 +15*40+1 +(15*40+1)*1.1 +16*40 +ceil(3e5/40/800) +(3e5/40/800) +9*40+1 +ans*1.1 +test003_oct11_tightLikelihood +%-- 10/27/16, 6:46 PM --% +edit gwmcmc.m +test003_oct11_tightLikelihood +whos +exportedMdlObj +get(exportedMdlObj) +get(exportedMdlObj.SimulationOptions) +get(exportedMdlObj.SimulationOptions.AbsoluteTolerance) +get(exportedMdlObj.SimulationOptions) +get(exportedMdlObj.SimulationOptions, 'AbsoluteTolerance') +set(exportedMdlObj.SimulationOptions, 'AbsoluteTolerance') +set(exportedMdlObj.SimulationOptions, 'AbsoluteTolerance', 1e-8) +get(exportedMdlObj.SimulationOptions, 'AbsoluteTolerance') +IP = [1 0 1 1; 0 1 1 1; 1 1 1 1] +all(IP) +all(IP') +all(IP')' +find(all(IP')') +find(all(IP'==1)') +all(IP'==1)' +IP = [1 0 1 1; 1 1 1 2; 1 1 1 1] +all(IP'==1)' +all(IP')' +help surf +edit gwmcmc_vse +close all +logp = log([0.05, 0.003, 452, 12000,0.01, 120000, 120000, 36000, 200, 1.5, ... +4, 100, 35, 50 100]'); +4, 100, 35, 50 100]') +logp = log([0.05, 0.003, 452, 12000,0.01, 120000, 120000, 36000, 200, 1.5, ... +4, 100, 35, 50 100]'); +logp = log([0.05, 0.003, 452, 12000,0.01, 120000, 120000, 36000, 200, 1.5, ... +4, 100, 35, 50 100]'); +logp = log([0.05, 0.003, 452, 12000,0.01, 120000, 120000, 36000, 200, 1.5, ... +4, 100, 35, 50 100]') +ls +help MPinterval +size(mcat) +[bds, mx, mp ] = MPinterval(mcat(:,:)'); +size(mcat) +[bds, mx, mp ] = MPinterval(mcat(:,:)'); +[F,XI,BW]=ksdensity(vec, 'npoints', p.npoints); +help catMC +edit catMC +MAPx +[MAPx' logp] +%-- 10/29/16, 4:56 AM --% +9000/3600 +m1 +set(m1.species +set(m1.species) +m1.species +sbioselect(m1, 'DNA p70--rbs--deGFP') +sbioselect(m1, 'Name', 'DNA p70--rbs--deGFP') +whos +MAPx' +m1.parametres +m1.Parameters +edit setparam +m1.parameters +MAPx +test010a_oct27 +m1.species +test010a_oct27 +exp(3.8) +exp(600) +log(600) +test010a_oct27 +m1.species +m1.rules +clc +clear all +close all +test010a_oct27 +%-- 10/31/16, 4:45 PM --% +exportedMdlObj +get(exportedMdlObj) +get(exportedMdlObj.ValueInfo) +(exportedMdlObj.ValueInfo) +(exportedMdlObj.ValueInfo(1)) +(exportedMdlObj.ValueInfo(2)) +(exportedMdlObj.ValueInfo(3)) +(exportedMdlObj.ValueInfo(4)) +100000/40/800 +%-- 11/7/16, 1:46 PM --% +legends={'k_{term}','RNAd_{cat}','RBS_{Kd}','prom_{Kd}','s70_{Kd}',... +'NTP_{Kd1}','NTP_{Kd2}','AA_{Kd}','RNAd_{Kd}','k_{emrna}','k_{eprot}',... +'RNAP','s70','Ribo','RNase'}' +[legends MAPx' logp] +[legends {MAPx'} {logp}] +[legends {MAPx'(:)} {logp(:)}] +[legends {MAPxMAPx'(:)} {logp(:)}] +MAPx +logp' +legends' +3e5/8000 +3e5/4000 +3e5/8000 +4e5/8000 +measuredSpecies = struct('cols', {'RNA', 'GFP'}, ... +'objectName',{'TotalRNA', 'protein deGFP*'}, ... +'type', {'species', 'species'}) ; +mn = cell(2,1) +mn = cell(1, 2) +cat(1, measuredSpecies(:).objectName) +measuredSpecies(1).objectName) +measuredSpecies(1).objectName +deal(measuredSpecies(:).objectName) +deal(measuredSpecies.objectName) +mn{:} = deal(measuredSpecies.objectName) +mn = deal(measuredSpecies.objectName) +[a,b] = deal(measuredSpecies.objectName) +formatSpec = string('%s : %.3f'); +A = {'RNA', 'DNA'}; +B = [100 5]; +str = compose(formatSpec,A, B) +formatSpec = string('%s : %.3f') +help string +openExample('matlab/FormatNumbersIntoStringsExample') +help compose +help savefig +help print +fig = figure +print(fig, 'abcd', '-djpeg') +help print +print( 'abcd', '-djpeg') +print(fig, 'abcd2', '-djpeg') +%-- 11/13/16, 1:22 PM --% +help assert +help isequal +help assert +help error +aa = [1:11]; +estPS = [1 3 0 0; 1 3 5 7; 1 0 0 0]; +aa(estPS(1,:)) +estPS = [1 3 0 0; 1 3 5 7; 1 0 0 0]; +find(estPS(1m:)) +find(estPS(1:)) +find(estPS(1,:)) +[I, J] = find(estPS(1,:)) +help find +[I, J, V] = find(estPS(1,:)) +rr = [10 12 14 16 18 24 28] +dd = [10 12 14 16 18 24 28] +pp = [11 15 16 19 22 34 40] +pp./(pi*(dd/2).^2) +plot(0.1401 0.1326 0.1039 0.0945 0.0865 0.0752 0.0650) +plot([0.1401 0.1326 0.1039 0.0945 0.0865 0.0752 0.0650]) +plot([1.091*(2.95+pp)./(pi*(dd/2).^2)) +plot([1.091*(2.95+pp)./(pi*(dd/2).^2)]) +figure; plot([1.091*(2.95+pp)./(pi*(dd/2).^2)]) +[1.091*(2.95+pp)./(pi*(dd/2).^2)] +figure; subplot(2,1,1); plot((pi*(dd/2).^2), 1.091*(2.95+pp)] +figure; subplot(2,1,1); plot((pi*(dd/2).^2), 1.091*(2.95+pp)) +figure; subplot(2,1,1); plot((pi*(dd/2).^2), 1.091*(2.95+pp), '*') +figure; subplot(2,1,1); plot((pi*(dd/2).^2), 1.091*(2.95+pp), '*-') +figure; subplot(2,1,1); plot((pi*(dd/2).^2), 1.091*(2.95+pp), '*-'); axes([0 700 0 60]) +figure; subplot(2,1,1); plot((pi*(dd/2).^2), 1.091*(2.95+pp), '*-'); axis([0 700 0 60]) +subplot(2,1,2); plot([1.091*(2.95+pp)./(pi*(dd/2).^2)]) +nres = [122 345 800] +nres = [122 345 800 1345 1900 3000] +clc +sum(nres(1:(1-1)) +sum(nres(1:(1-1))) +sum(nres(1:(2-1))) +sum(nres(1:(3-1))) +close all +m1 +m1.parameters +0.65^3 +0.65^2 +800/0.4225 +round(800/0.4225) +en +integrable +exportedMdlObj +test013_server +test012_server_test_onMBP +exportedMdlObj +sbioselect(exportedMdlObj, 'Type', 'Parameter', 'Name', estNames) +exportedMdlObj.ValueInfo +exportedMdlObj.ValueInfo(1).Name +C = {'efwef', 'fve', 'wefbeabla', 'dfblarergsx', 'bla'} +IndexC = strfind(C, 'bla'); +Index = find(not(cellfun('isempty', IndexC))) +IndexC +IndexC = strcmp(C, 'bla'); +IndexC = strcmp(C, 'bla') +Index = find(not(cellfun('isempty', IndexC))) +Index = find( IndexC) +%-- 11/15/16, 4:56 AM --% +dirToSaveIn +close all +10^5 +180*60 +%-- 12/8/16, 11:31 PM --% +help dataset +help subplot +dec6data +dec6data{2,1} +dec6data{2,1}{1} +12*60 +help legend +dset +dset{2,1} +dset{2,1}{1} +dec6data +j = 1 +dec6data{3, 2*(j-1)+1} +dec6data{2, 2*(j-1)+1} +dset +dset{2,1} +dset{2,1}{2} +dset{2,1}{3} +Ext +i +Ext{1} +clear all +close all +clc +ax +gca +h +close all +clear all +clc +colorschemes +edit colorschemes +colorschemes('plot') +help suplabel +colorschemes('plot') +test009s2 +plot_dec6_2016 +dec6data{2, 2*3+1} +dec6data +for i = [1 3 4] +i +end +dec6data +help suplabel +close all +[ymin, ymax]/1517 +[ymin, ymax] +%-- 12/15/16, 5:34 AM --% +mainSSA +%-- 12/16/16, 12:04 PM --% +addpath('/Users/vipulsinghal/Dropbox/Documents/MATLAB/mcmc_grinsted-gwmcmc-2c86b0e') +addpath(genpath(pwd)) +%-- 1/14/17, 9:46 AM --% +load('020615_Data.mat', 'endMatrixGFP_TxBCD13_vitro') +addpath(genpath(pwd)) +load('020615_Data.mat', 'endMatrixGFP_TxBCD13_vitro') +load('020615_Data.mat') +whos +peaks(squeeze(endMatrixGFP_404p_vitro(2,:,:,:)), false, 4) +warning('off','all') +whos +peaks(squeeze(endMatrixGFP_TxBCD13_vitro(2,:,:,:)), false, 4) +test010_fitwholeTLpanel +sgolayfit +help sgolayfilt +help sbiotrellis +trell = sbiotrellis(gd, 'ID', 't', 'GFP') +(0:6:720)'/60 +test010_fitwholeTLpanel +edit smallplots +test010_fitwholeTLpanel +size(panel) +test010_fitwholeTLpanel +gLi +gLI +test010_fitwholeTLpanel +isempty(iLI) +iLI +whos +test010_fitwholeTLpanel +isempty(iLI) +exists(gLI.title) +exist(gLI.title) +help exist +isempty(gLI.title) +help isempty +what(iLI) +help what +test010_fitwholeTLpanel +close all +test010_fitwholeTLpanel +gca +help round +help ceil +order(16) +order(160) +13/(10^order(13)) +ceil(13/(10^order(13))) +%-- 1/15/17, 9:46 PM --% +ceil(13/(10^order(13)))*(10^order(13)) +test010_fitwholeTLpanel +%-- 1/15/17, 9:49 PM --% +addpath(genpath(pwd)) +test010_fitwholeTLpanel +maxdata +test010_fitwholeTLpanel +close all +test010_fitwholeTLpanel +smallplots +test010_fitwholeTLpanel +gca +test010_fitwholeTLpanel +%-- 2/13/17, 4:58 PM --% +whos +dec6data +dec6data{2,1} +dec7data{2,1} +dset +dset{2,1} +dset{2,1}{1,1} +d7 +d7{2,2} +d7{2,1} +d7{2,1}{1} +d7{2,2}{1} +d7{2,2}[dset, dec6data, dec7data] = Data_Dec6_7_2016_legendredefined +[dset, dec6data, dec7data] = Data_Dec6_7_2016_legendredefined +dec7data{3,1} +d7{2,1}{4} +d7{3,1}{4} +d7 +ds +ds{2,1} +ds{2,1}{1,1} +ds{2,1}{1,2} +ds{2,1}{1,3} +help reshape +size(d7{2,1}{1,4}) +test014_GFP_mga_full +whos +m1 +m1.parameters +m1 +m1.rules +edit txtl_translation +%-- 3/8/17, 7:27 AM --% +run('/Users/vipulsinghal/Dropbox/Documents/vipul_repo/MCMC/Code_MCMC/examples/test005_oct2_many_walkers.m') +txtl_init +edit geneexpr +geneexpr +%-- 3/9/17, 6:53 AM --% +txtl_init +geneexpr +Mobj.parameters +Mobj.reactions +Mobj.reactions(18) +get(Mobj.reactions(18)) +set(Mobj.reactions(18)) +KL_rnase = get(Mobj.reactions(18), 'KineticLaw') +get(KL_rnase) +get(KL_rnase, 'Parameters') +%-- 3/15/17, 7:04 AM --% +test012_AWS_030917 +mcmc_init +test012_AWS_030917 +slashes +mcmc_init +slashes +[tmg, ymg, metamg] = load_ACSDSG2014('MGapt'); % y is ntimepoints x ndoses +[tgfp, ygfp, metagfp] = load_ACSDSG2014('deGFP'); +metamg +size(ymg +size(ymg) +size(ygfp) +metagfp +plot(tmg, ymg) +p = plot(tmg, ymg); legends('0.5','2', '5', '20') +p = plot(tmg, ymg); legend('0.5','2', '5', '20') +p = plot(tgfp, ygfp); legend('0.5','2', '5', '20') +p = plot(tgfp, ygfp(:,[2 4 5 6])); legend('0.5','2', '5', '20') +p = plot(tgfp, ygfp); legend('0.5','2', '5', '20') +size(ygfp) +length(tspan) +fig; plot(tspan, resahpe(dataspec(1:404), 101, 4)) +figure; plot(tspan, resahpe(dataspec(1:404), 101, 4)) +figure; plot(tspan, reshape(dataspec(1:404), 101, 4)) +figure; plot(tspan, reshape(dataspec(404+ 1:808), 101, 4)) +figure; p3 = plot(tspan, reshape(dataspec(404+ 1:808), 101, 4)); legend('0.5','2', '5', '20') +figure; p3 = plot(tspan, reshape(dataspec(1:404), 101, 4)); legend('0.5','2', '5', '20') +m1 +m1.parameters +a + 1 +close all +%-- 5/6/17, 6:50 AM --% +test014_GFP_mga_full +minit = integrableLHS(exportedMdlObj, nW, spread, logp,... +estNames_ordered, dosingStrat); +%-- 12/19/17, 6:44 AM --% +ver +help addpoints +help animatedline +%-- 12/20/17, 10:50 PM --% +x = 2 +y = 4 +x+y +%-- 12/20/17, 10:54 PM --% +ttl_init +txtl_init +geneexpr +mcmc_init +edit proj_acs_dsg2014 +edit gwmcmc_vse.m +help textprogress +help noaction +log(rand(3, 10)) +log(rand(3, 100)) +((3-1)*rand(1, Nwalkers) + 1).^2/3 +((3-1)*rand(1, 10) + 1).^2/3 +hist(((3-1)*rand(1, 10) + 1).^2/3) +hist(((3-1)*rand(1, 10000) + 1).^2/3) +ss = 10 +hist(((ss-1)*rand(1, 10000) + 1).^2/ss) +close all; figure; hist(((ss-1)*rand(1, 10000) + 1).^2/ss) +for ss = 1:15 +subplot(15, 1, ss); hist(((ss-1)*rand(1, 10000) + 1).^2/ss); +end +close all +figure +for ss = 1:15 +subplot(15, 1, ss); hist(((ss-1)*rand(1, 10000) + 1).^2/ss); +axis([0 10 0 15]) +end +log(((ss-1)*rand(1, 10) + 1).^2/ss) +log(((ss-1)*rand(1, 100) + 1).^2/ss) +log(rand(1)) < 10*log(((ss-1)*rand(1, 100) + 1).^2/ss) +ss = 100 +log(rand(1)) < 10*log(((ss-1)*rand(1, 100) + 1).^2/ss) +ss = 1 +log(rand(1)) < 10*log(((ss-1)*rand(1, 100) + 1).^2/ss) +ss = 0.1 +log(rand(1)) < 10*log(((ss-1)*rand(1, 100) + 1).^2/ss) +ss = 2 +log(rand(1)) < 10*log(((ss-1)*rand(1, 100) + 1).^2/ss) +sbioselect(m1, 'P') +help sbioselect +sbioselect(m1, 'name', 'P') +clc +help sbiosimulate +help inputparser +help time +help struct +edit mcmc_runsim.m +help varargout +edit gen_residuals_3 +load mcmc20171128_130412_ID10 +addpath(genpath(pwd)) +load mcmc20171128_130412_ID10 +ls +who +da +whos +edit data_dsg2014 +50/50000 +50/50000*100 +50/50000*50000 +50000/(50/50000) +%-- 1/14/18, 7:54 AM --% +help randn +help chol +path +txtl_init +data_init +path +mcmc_init +proj_enzymatic_model +help addparameter +proj_enzymatic_model +p +p.Results +proj_enzymatic_model +cloe all +close all +clear all +proj_enzymatic_model +p +proj_enzymatic_model +emo +get(emo) +get(emo, 'ValueInfo') +vii = get(emo, 'ValueInfo') +vii(:) +vii(1) +vii(2) +vii(3) +vii(4) +edit model_dsg2014 +edit mcmc_info_dsg2014 +proj_enzymatic_model +emo +emo.ValueInfo +i = 1:5 emo.ValueInfo(i).Name end +for i = 1:5 ; emo.ValueInfo(i).Name end +for i = 1:5 ; emo.ValueInfo(i).Name; end +for i = 1:5 ; emo.ValueInfo(i).Name end +for i = 1:5 ; emo.ValueInfo(i).Name +end +help simulate +em.SimulationOptions +em.SimulationOptions.StopTime +proj_enzymatic_model +size(da) +proj_enzymatic_model +size(da) +proj_enzymatic_model +size(da) +proj_enzymatic_model +p.replicates +help inputParser +proj_enzymatic_model +help isinteger +proj_enzymatic_model +isinteger(3) +help isinteger +int8(3) +proj_enzymatic_model +size(da) +close all +help repmat +edit catMC +help std +cc = colorschemes +cc{1} +cc{2,1} +proj_enzymatic_model +help max +proj_enzymatic_model +squeeze(mxtemp) +squeeze(max(max(datmat, [], 1), [], 3)) +squeeze(max(max(max(datmat, [], 1), [], 3),[],4)) +proj_enzymatic_model +beep +gong +ring +rng +help beep +help sound +figure; plot(tv, da(:,1,1,1)) +size(da) +geomean([0.005 50 +0.005 50 +0.05 50 +5 500], 2) +close all +edit integrable LHS +geomean([[0.0005 .05 +0.005 .5 +.4 40 +1 100]) +geomean([0.0005 .05 +0.005 .5 +.4 40 +1 100]) +geomean([0.0005 .05 +0.005 .5 +.4 40 +1 100], 2) +proj_enzymatic_model +loglike(minit) +logP(:,:,1) +logPfuns{2} +logPfuns{2}(minit(:, 1) +logPfuns{2}(minit(:, 1)) +proj_enzymatic_model +loglike(minit(:,1)) +proj_enzymatic_model +logP(:,:,1) +proj_enzymatic_model +logP(:,:,1) +logPfuns{1} +get(logPfuns{1}) +set(logPfuns{1}) +logprior = @(logp) all(mi.paramranges(:, 1) < logp) &&... +all(logp < mi.paramranges(:,2)); +logprior(minit(:,1)) +proj_enzymatic_model +logprior(minit(:,1)) +mi.paramranges(:, 1) +minit(:,1) +help randn +minit +exp(minit) +exp(mi.paramranges) +geomean(mi.paramranges, 2) +geomean(exp(mi.paramranges), 2) +geomean(exp(mi.paramranges), 2).^2 +proj_enzymatic_model +nOpt +proj_enzymatic_model +model_enzymatic +proj_enzymatic_model +((2 - 1)*rand(1,10) + 1).^2/2 +((ssz - 1)*rand(40,1) + 1).^2/ssz +ssz = 3; ((ssz - 1)*rand(40,1) + 1).^2/ssz +ssz = 3; hist(((ssz - 1)*rand(40,1) + 1).^2/ssz) +close all; ssz = 3; hist(((ssz - 1)*rand(40,1) + 1).^2/ssz) +close all; ssz = 3; hist(((ssz - 1)*rand(4000,1) + 1).^2/ssz) +close all; ssz = 3; hist(((ssz - 1)*rand(400000,1) + 1).^2/ssz) +help hist +close all; ssz = 3; hist(((ssz - 1)*rand(400000,1) + 1).^2/ssz); set(gca,'xscale','log') +close all; ssz = 3; hist(((ssz - 1)*rand(4000000,1) + 1).^2/ssz); +close all; ssz = 2; hist(((ssz - 1)*rand(4000000,1) + 1).^2/ssz); +proj_enzymatic_model +close all; ssz = 1.5; hist(((ssz - 1)*rand(4000000,1) + 1).^2/ssz); +proj_enzymatic_model +help scatter3 +figure; scatter3(mstacked(:,1), mstacked(:,3), mstacked(:,4)) +figure; scatter3(mstacked(:,1), mstacked(:,2), mstacked(:,3)) +path +whos +clear all +proj_enzymatic_model +tstamp +[mcmc' prevtstamp '_ID' finalsimID] +['mcmc' prevtstamp '_ID' finalsimID] +['mcmc' prevtstamp '_ID' finalsimID '.mat'] +help exist +exist(['mcmc' prevtstamp '_ID' finalsimID '.mat']) +exist([pwd 'mcmc_simbio/projects/proj_enzymatic_model/simdata_' prevtstamp '/mcmc' prevtstamp '_ID' finalsimID '.mat']) +exist([pwd '/mcmc_simbio/projects/proj_enzymatic_model/simdata_' prevtstamp '/mcmc' prevtstamp '_ID' finalsimID '.mat']) +proj_enzymatic_model +loglike = @(logp) gen_residuals_4(logp, em, da, tv, ... +mi.dosedvals, mi.measuredspecies, lognormvec, sigg); +loglike(minit(:,1) +loglike(minit(:,1)) +proj_enzymatic_model +close all +help cat +proj_enzymatic_model +figure; scatter3(mstacked(:,1), mstacked(:,3), mstacked(:,4)) +figure; scatter3(mstacked(1:10:end,1), mstacked(1:10:end,3), mstacked(1:10:end,4)) +close all +edit rawdata_ACSDSG2014 +edit plotcustomspecies +edit plotcustomspecies2 +help legends +dv +m.species +help setparam +edit setparam +m.Parameters +m.Parameters.name +m.Parameters.Name +m.Parameters(1).Name +for i = 1:33 names{i} = m.Parameters(1).Name; end +names +for i = 1:33 names{i} = m.Parameters(i).Name; end +names' +names = cell(33, 1) +for i = 1:33 names{i} = m.Parameters(i).Name; end +names +names{1} +vals = zeros(33, 1) +for i = 1:33 vals(i) = m.Parameters(i).Value; end +vals +format short g +vals +repmat('global', 19, 1) +help repmat +repmat({'global'}, 19, 1) +clc +close all +gcf +ff = gcf +class(ff) +help figure +gcf +m +m.Parameters +[pstrs pvals] +{pstrs pvals} +struct('names', pstrs, 'vals', pvals) +pstruct = struct('names', pstrs, 'vals', pvals) +pstruct +pstruct(1) +getparam(m) +close all +m.species +close +close all +m.rules +for i = 1:33 names{i} = m.Parameters(i).Name; end +names +m.Parameters +close all +pcells(:,1) +help cell2mat +cell2mat(pcells(:,2)) +close all +proj_acs_dsg2014 +loglike(minit(:, 1)) +for i = 1:100 loglike(minit(:, i)) end +for i = 1:100 loglike(minit(:, i)) +end +for i = 1:100 logprior(minit(:, i)) +end +minit +m.Events +mcmc_info_dsg2014_version2 +edit mcmc_info_dsg2014_version2.m +proj_acs_dsg2014 +for i = 1:100 loglike(minit(:, i)) +end +minit +for i = 1:100 logprior(minit(:, i)) +end +measuredspecies +measuredspecies' +size(data_array) +proj_acs_dsg2014 +path +mi.nIter +mi.niter +mi.names_ord +proj_acs_dsg2014 +close all +pcells = [{'TX_elong_glob', 1 } +{'TL_elong_glob' 40} +{'AGTPdeg_time' 7200 } +{'AGTPdeg_rate' 0.0002 } +{'TXTL_PROT_deGFP_MATURATION' 0.0023105 } +{'TXTL_UTR_UTR1_Kd' 40 } +{'TXTL_UTR_UTR1_F' 0.62 } +{'TXTL_P70_RNAPbound_Kd' 20 } +{'TXTL_P70_RNAPbound_F' 20 } +{'TXTL_RNAPBOUND_TERMINATION_RATE' 0.05} +{'TXTL_NTP_RNAP_1_Kd' 2 } +{'TXTL_NTP_RNAP_1_F' 10 } +{'TXTL_NTP_RNAP_2_Kd' 10 } +{'TXTL_NTP_RNAP_2_F' 1 } +{'TL_AA_Kd' 0.1 } +{'TL_AA_F' 10 } +{'TL_AGTP_Kd' 1 } +{'TL_AGTP_F' 10 } +{'TXTL_RIBOBOUND_TERMINATION_RATE' 10} +{'TXTL_RNAdeg_Kd' 1000/.52 } +{'TXTL_RNAdeg_F' 0.001/.4 }]; +estNames_ver2 = [pcells(:,1) +{'RNAP' +'Ribo' +'RNase'}]; +estVals_ver2 = [cell2mat(pcells(:,2)) +50 +50 +50]; +estVals_ver2 +size([1/2 200 +40/5 4000 +7200/4 7200*3 +0.0002/10 0.0002*10 +0.0023105/2 0.0023105*2 +40/500 40*500 +0.62/50 0.62*5 +20/1000 20*1000 +0.01 10 +0.05/10 5 +2/100 2*100 +10/1000 10 +2/100 2*100 +10/1000 10 +0.01/10 1000 +10/100 10 +1/1000 1000 +0.01 10 +0.01 10 +0.001 1000 +0.0025/50 0.0025*50 +5 5000 +5 5000 +5 5000]) +{'TX_elong_glob', 1 } +{'TL_elong_glob' 40} +{'AGTPdeg_time' 7200 } +{'AGTPdeg_rate' 0.0002 } +{'TXTL_PROT_deGFP_MATURATION' 0.0023105 } +{'TXTL_UTR_UTR1_Kd' 40 } +{'TXTL_UTR_UTR1_F' 0.62 } +{'TXTL_P70_RNAPbound_Kd' 20 } +{'TXTL_P70_RNAPbound_F' 20 } +{'TXTL_RNAPBOUND_TERMINATION_RATE' 0.05} +{'TXTL_NTP_RNAP_1_Kd' 2 } +{'TXTL_NTP_RNAP_1_F' 10 } +{'TXTL_NTP_RNAP_2_Kd' 10 } +{'TXTL_NTP_RNAP_2_F' 1 } +{'TL_AA_Kd' 0.1 } +{'TL_AA_F' 10 } +{'TL_AGTP_Kd' 1 } +{'TL_AGTP_F' 10 } +{'TXTL_RIBOBOUND_TERMINATION_RATE' 10} +{'TXTL_RNAdeg_Kd' 1000/.52 } +{'TXTL_RNAdeg_F' 0.001/.4 } +size([{'TX_elong_glob', 1 } +{'TL_elong_glob' 40} +{'AGTPdeg_time' 7200 } +{'AGTPdeg_rate' 0.0002 } +{'TXTL_PROT_deGFP_MATURATION' 0.0023105 } +{'TXTL_UTR_UTR1_Kd' 40 } +{'TXTL_UTR_UTR1_F' 0.62 } +{'TXTL_P70_RNAPbound_Kd' 20 } +{'TXTL_P70_RNAPbound_F' 20 } +{'TXTL_RNAPBOUND_TERMINATION_RATE' 0.05} +{'TXTL_NTP_RNAP_1_Kd' 2 } +{'TXTL_NTP_RNAP_1_F' 10 } +{'TXTL_NTP_RNAP_2_Kd' 10 } +{'TXTL_NTP_RNAP_2_F' 1 } +{'TL_AA_Kd' 0.1 } +{'TL_AA_F' 10 } +{'TL_AGTP_Kd' 1 } +{'TL_AGTP_F' 10 } +{'TXTL_RIBOBOUND_TERMINATION_RATE' 10} +{'TXTL_RNAdeg_Kd' 1000/.52 } +{'TXTL_RNAdeg_F' 0.001/.4 }]) +proj_acs_dsg2014 +estVals_ver2/10 estVals_ver2*10] +[estVals_ver2/10 estVals_ver2*10] +a=[1/2 200 +40/5 4000 +7200/4 7200*3 +0.0002/10 0.0002*10 +0.0023105/2 0.0023105*2 +40/500 40*500 +0.62/50 0.62*5 +20/1000 20*1000 +0.01 10 +0.05/10 5 +2/100 2*100 +10/1000 10 +2/100 2*100 +10/1000 10 +0.01/10 1000 +10/100 10 +1/1000 1000 +0.01 10 +0.01 10 +0.001 1000 +0.0025/50 0.0025*50 +5 5000 +5 5000 +5 5000] +b = [estVals_ver2/10 estVals_ver2*10] +a(:,1)log(100) +all(all(abs(0.5*randn(20))>log(100))) +all(all(abs(0.5*randn(2000))>log(100))) +mi +proj_acs_dsg2014_mrna +m.reactions +m.rules +proj_acs_dsg2014_mrna +cc = colorschemes +hex2rgb(hexColorCell{i}) +help hex2rgb +cc = colorschemes +hex2rgb(hexColorCell{i}) +path +edit data_init +data_init +proj_acs_dsg2014_mrna +pwd +cd .. +cd +pwd +proj_acs_dsg2014_mrna +size(mcat) +close all +clear all +%-- 1/18/18, 4:28 PM --% +txtl_init +mcmc_init +data_init +proj_acs_dsg2014_mrna +logPfuns{fix}(minit(:,wix)) +logP(:,:,1) +proj_acs_dsg2014_mrna +load([pwd '/mcmc_simbio/projects/proj_acs_dsg2014_mrna/simdata_' prevtstamp '/mcmc' prevtstamp '_ID' finalsimID '.mat'], 'm'); +minit = m(:,:,end); +minit = 0.9*minit+0.0001*rand(size(minit)); +for i = 1:size(minit, 2) +lprior(i) = logprior(minit(:,i)); +end +~all(isfinite(lprior)) +prevtstamp = '20180117_193328'; +finalsimID = '3'; +load([pwd '/mcmc_simbio/projects/proj_acs_dsg2014_mrna/simdata_' prevtstamp '/mcmc' prevtstamp '_ID' finalsimID '.mat'], 'm'); +minit = m(:,:,end); +minit = 0.95*minit+0.0001*rand(size(minit)); +logprior = @(logp) all(mi.paramranges(:, 1) < logp) &&... +all(logp < mi.paramranges(:,2)); +lprior = zeros(1, size(minit, 2)); +for i = 1:size(minit, 2) +lprior(i) = logprior(minit(:,i)); +end +if ~all(isfinite(lprior)) +error('Starting points for all walkers must have finite logP') +end +prevtstamp = '20180117_193328'; +finalsimID = '3'; +load([pwd '/mcmc_simbio/projects/proj_acs_dsg2014_mrna/simdata_' prevtstamp '/mcmc' prevtstamp '_ID' finalsimID '.mat'], 'm'); +minit = m(:,:,end); +minit = 0.97*minit+0.0001*rand(size(minit)); +logprior = @(logp) all(mi.paramranges(:, 1) < logp) &&... +all(logp < mi.paramranges(:,2)); +lprior = zeros(1, size(minit, 2)); +for i = 1:size(minit, 2) +lprior(i) = logprior(minit(:,i)); +end +if ~all(isfinite(lprior)) +error('Starting points for all walkers must have finite logP') +end +prevtstamp = '20180117_193328'; +finalsimID = '3'; +load([pwd '/mcmc_simbio/projects/proj_acs_dsg2014_mrna/simdata_' prevtstamp '/mcmc' prevtstamp '_ID' finalsimID '.mat'], 'm'); +minit = m(:,:,end); +minit = 0.98*minit+0.0001*rand(size(minit)); +logprior = @(logp) all(mi.paramranges(:, 1) < logp) &&... +all(logp < mi.paramranges(:,2)); +lprior = zeros(1, size(minit, 2)); +for i = 1:size(minit, 2) +lprior(i) = logprior(minit(:,i)); +end +if ~all(isfinite(lprior)) +error('Starting points for all walkers must have finite logP') +end +~all(isfinite(lprior)) +prevtstamp = '20180117_193328'; +finalsimID = '3'; +load([pwd '/mcmc_simbio/projects/proj_acs_dsg2014_mrna/simdata_' prevtstamp '/mcmc' prevtstamp '_ID' finalsimID '.mat'], 'm'); +minit = m(:,:,end); +minit = 0.98*minit+0.0001*rand(size(minit)); +logprior = @(logp) all(mi.paramranges(:, 1) < logp) &&... +all(logp < mi.paramranges(:,2)); +lprior = zeros(1, size(minit, 2)); +for i = 1:size(minit, 2) +lprior(i) = logprior(minit(:,i)); +end +if ~all(isfinite(lprior)) +error('Starting points for all walkers must have finite logP') +end +prevtstamp = '20180117_193328'; +finalsimID = '3'; +load([pwd '/mcmc_simbio/projects/proj_acs_dsg2014_mrna/simdata_' prevtstamp '/mcmc' prevtstamp '_ID' finalsimID '.mat'], 'm'); +minit = m(:,:,end); +minit = 0.99*minit+0.0001*rand(size(minit)); +logprior = @(logp) all(mi.paramranges(:, 1) < logp) &&... +all(logp < mi.paramranges(:,2)); +lprior = zeros(1, size(minit, 2)); +for i = 1:size(minit, 2) +lprior(i) = logprior(minit(:,i)); +end +if ~all(isfinite(lprior)) +error('Starting points for all walkers must have finite logP') +end +proj_acs_dsg2014_mrna +help all +proj_acs_dsg2014_mrna +%-- 1/18/18, 5:22 PM --% +txtl_init +mcmc_init +edit gwmcmc_vse.m +proj_acs_dsg2014_mrna +save('mcmc20180118_012422_final') +%-- 1/19/18, 4:30 AM --% +whos +txtl_init +mcmc_init +whos +data_init +edit data_init +mi.names_ord +m +whos +mobj.parameters +getparam(mobj) +edit txtl_mrna_degradation.m +getparam(mobj) +mobj.rules +mobj.Parameters +mi.names_ord +close all +proj_protein_model +emo +get(emo) +get(emo, 'ValueInfo') +vi = get(emo, 'ValueInfo') +vi(:).Name +sd +get(sd) +get(sd, 'DataNames') +proj_protein_model +logP(:,:,1) +logPfuns{fix} +logPfuns{fix}(minit(:,1)) +proj_protein_model +logP(:,:,1) +logPfuns{fix}(minit(:,1)) +paramvec(espIX) = logpesp +proj_protein_model +logP(:,:,1) +logPfuns{fix}(minit(:,1)) +proj_protein_model +logPfuns{fix}(minit(:,1)) +logP(:,:,1) +logPfuns{fix}(minit(:,1)) +proj_protein_model +boundz +proj_protein_model +tstamp +proj_protein_model +rand(3) +rand(3)-0.5 +proj_protein_model +boundz +log([20 10 40 20 100]) +help scatter3 +data_init +dosingStrat +proj_acs_dsg2014_mrna +%-- 1/19/18, 6:30 PM --% +txlt_init +txtl_init +mcmc_init +proj_protein_model +close all +clc +clear all +proj_acs_dsg2014_mrna +m +mobj +mobj.Parameters +exp([0,4]) +exp(6.6) +exp(9.6) +format short g +exp(9.6) +proj_acs_dsg2014_mrna +path +islogical(v) +v=logPfuns{fix}(minit(:,wix)) +edit mcmc_runsim_4.m +mi +size(minit) +mi.names_ord +proj_acs_dsg2014_mrna +whos +close all +tstamp +mod(4,3) +mod(6,3) +mod(i, 3) == 0 +if ~mod(4,3) +'hello' +end +if ~mod(6,3) +'hello' +end +~mod(6,3) +i = 4 +if ~mod(i, 3) +pause(600) +disp('Pausing for 10 minutes before starting run number %d. \n', i) +end +i = 9 +if ~mod(i, 3) +pause(1) +disp('Pausing for 10 minutes before starting run number %d. \n', i) +end +if ~mod(i, 3) +pause(1) +disp(sprintf('Pausing for 10 minutes before starting run number %d. \n', i)) +end +mi.nW +proj_acs_dsg2014_mrna +clear all +close all +clc +help fprintf +if ~mod(i, 3) +pause(600) +fprintf('Pausing for 10 minutes before starting run number %d. \n', i); +end +i = 3 +if ~mod(i, 3) +pause(6) +fprintf('Pausing for 10 minutes before starting run number %d. \n', i); +end +mcmc_runsim_4 +proj_acs_dsg2014_mrna +data_init +%-- 1/22/18, 11:13 AM --% +txtl_init +mcmc_init +data_init +proj_acs_dsg2014_protein +mi.names_ord +proj_acs_dsg2014_protein +mi +edit setparam +isempty({}) +close all +extractCrashLogs +help extractCrashLogs +extractCrashLogs(100, '/Users/vipulsinghal') +clc +dir components +edit txtl_protein_sigma28.m +edit txtl_tutorial +%-- 1/23/18, 8:15 AM --% +m1 = sbiomodel('simpleModel'); +m1 +r1 = addreaction(m1,'A -> B'); +m1 +m1.Species +r1 = addreaction(m1,'A + B <-> C'); +r1 +m1.Species +m1 +m1.Reactions +m1.reactions(1) +m1.reactions(2) +get(m1.reactions(2)) +m1.reactions(2).reaction +m1.reactions(2).reversible +get(m1.species(1)) +m1.species(1).InitialAmount +m1.species(1).InitialAmount = 10 +get(m1.species(1)) +set(m1.species(1), 'InitialAmount', 20) +get(m1) +kineticLaw = addkineticlaw(r1,'MassAction'); +get(m1.reactions(2)) +kineticLaw = addkineticlaw(m1.reactions(2),'MassAction'); +kineticLaw = addkineticlaw(m1.reactions(1),'MassAction'); +addkineticlaw(m1.reactions(1),'MassAction'); +get(m1.reactions(1)) +myKLobj = get(m1.reactions(1), 'KineticLaw') +get(myKLobj) +get(m1.reactions(1).KineticLaw) +p1 = addparameter(myKLobj,'k',0.5); +myKLobj.ParameterVariableNames = 'k'; +get(m1.reactions(1).KineticLaw) +m1.reactions(1).KineticLaw.Parameters +get(m1.reactions(1).KineticLaw.Parameters) +set(m1.reactions(1).KineticLaw.Parameters) +set(m1.reactions(1).KineticLaw.Parameters, 'Notes', 'Just trying to explain stuff to Gloria') +get(m1.reactions(1).KineticLaw.Parameters) +get(m1.reactions(2).KineticLaw.Parameters) +get(m1.reactions(2).KineticLaw(1).Parameters) +get(m1.reactions(2).KineticLaw) +help addparameter +edit txtl_reaction +edit txtl_addreaction +txtl_init +edit txtl_addreaction +p1 = addparameter(m1.reactions(2).KineticLaw.Parameters,'kf',10); +p1 = addparameter(m1.reactions(2).KineticLaw,'kf',10); +get(m1.reactions(2).KineticLaw) +p1 = addparameter(m1.reactions(2).KineticLaw,'kr',2); +get(m1.reactions(2).KineticLaw) +clc +clear all +close all +%-- 1/24/18, 6:38 AM --% +fprintf(['This is a simple constitutive gene expression model \n'... +'built using the TXTL modeling toolbox. It models DNA binding \n'... +'to RNAP and nucleotides, followed by transcription. The resulting\n'... +'mRNA can degrade and participate in translation. The former is \n'... +'modeled as a enzymatic reaction involving every complex containing \n'... +'mRNA. The latter involves binging to Ribosomes, followed by amino acids \n'... +'and ATP, and finally elongation and termination resulting in protein.']) +%-- 1/25/18, 5:12 AM --% +mm = sbiomodel +help sbiomodel +mm = sbiomodel('test') +set(mm) +getconfigset(mm) +%-- 1/27/18, 9:38 AM --% +mm = cat(3, magic(3), 2*magic(3), 3*magic(3)) +mm(:,:) +mm(:,1:5) +mm(:,1:5)' +help isnumeric +single(2) +single(2^31 +single(2^31) +single(2^32) +single(2^33) +single(2^64) +single(2^126) +single(2^127) +single(2^128) +double(2^128) +double(2^255) +double(2^256) +double(2^257) +double(2^258) +double(2^30000) +double(2^3000) +double(2^1000) +double(2^1500) +double(2^1024) +double(2^1023) +double(log(2^1023)) +double(log(2^4000)) +log(2^4000) +(2^4000) +(2^1100 +(2^1100) +10^300 +10^305 +10^3010 +10^1010 +10^310 +help isequal +help cat +m = cat(3, [magic(4), magic(4)], 2*[magic(4), magic(4)], 3*[magic(4), magic(4)]) +m2 = cat(3, [5*magic(4)], 5*2*[magic(4)], 5*3*[magic(4)]) +cat(2, m(:,:)', m2(:,:)') +cat(1, m(:,:)', m2(:,:)') +help reshape +cat(2, m(:,:), m2(:,:)) +floor(36/8) +m3 = cat(2, m(:,:), m2(:,:)) +reshape(m3(:, 1:(floor(size(m3, 3)/size(m, 2)))), size(m, 1), size(m, 2), floor(size(m3, 3)/size(m, 2))) +reshape(m3(:, 1:(floor(size(m3, 2)/size(m, 2)))), size(m, 1), size(m, 2), floor(size(m3, 2)/size(m, 2))) +reshape(m3(:, 1:(size(m, 2)*floor(size(m3, 2)/size(m, 2)))), size(m, 1), size(m, 2), floor(size(m3, 2)/size(m, 2))) +m +m2 +m2(:,:) +nw = size(m, 2) +np = size(m, 1) +ntemp = size(m2(:,:), 2) +nplanes = floor(ntemp/nw) +m2t = m2(:,:) +m2t = m2(:,1:nplanes*nw); reshape(m2t, nparam, nw, nplanes) +m2t = m2(:,1:nplanes*nw); reshape(m2t, n, nw, nplanes) +m2t = m2(:,1:nplanes*nw); reshape(m2t, np, nw, nplanes) +m2t +num2str +help num2str +num2str(1:10) +size(num2str(1:10)) +size(num2str(1:2)) +size(num2str(1:3)) +150000000 +150000000/12000 +32/12500 +30.48*0.0026 +a = {{'1'}} +b = {'2'} +{c} = b +c = {b} +1:10 +cellstr( num2str(1:10)) +a = {{'1', '2', '3'}, {'1', '2', '3'}} +a{:} +iscell(a) +iscell(a{1}) +iscell(a{2}) +iscell(a{:}) +help cellfun +cellfun(@iscell, a) +a +b = {1:3 1:3} +cellfun(@iscell, b) +all(cellfun(@iscell, a)) +help arrayfun +arrayfun(@num2str, 1:10) +b = arrayfun(@num2str, 1:10) +b = arrayfun(@num2str, 1:9) +b = arrayfun(@num2str, 1:9, 'UniformOutput', false) +b = arrayfun(@num2str, 1:15, 'UniformOutput', false) +anonf = @(numarray) arrayfun(@num2str,numarray, 'UniformOutput', false) +anonf(1:8) +anonf(1:10) +simID = {{1:10}, {2:20}} +convertedsID = cellfun(anonf, simID) +simID = {1:10, 2:20} +convertedsID = cellfun(anonf, simID) +anonf = @(numarray) arrayfun(@num2str,numarray, 'UniformOutput', false) +help cellfun +convertedsID = cellfun(anonf, simID, 'UniformOutput', false) +convertedsID{1} +convertedsID{1}{1} +class(convertedsID{1}{1}) +simID = {1:10, 2:11} +convertedsID = cellfun(anonf, simID, 'UniformOutput', false) +convertedsID = cellfun(anonf, simID, 'UniformOutput', true) +convertedsID = cellfun(anonf, simID, 'UniformOutput', false) +convertedsID = cellfun(@(numarray) arrayfun(@num2str,numarray, 'UniformOutput', false), simID, 'UniformOutput', false) +all +help all +help find +help arrayfun +setdiff([1 2 4 5 6], [1 5 6]) +help islogical +mcmc_init +txtl_init +mcmc_init +help ecornerplot_vse +help ndims +edit ndims +help eacorr +help plotChains +edit plotChains.m +twofactors(7) +twofactors(34) +[a b] = twofactors(34) +[a b] = twofactors(36) +[a b] = twofactors(64) +[a b] = twofactors(99) +[a b] = twofactors(4523) +[a b] = twofactors(4524) +[a b] = twofactors(4525) +[a b] = twofactors(4526) +[a b] = twofactors(4527) +[a b] = twofactors(4528) +[a b] = twofactors(4529) +[a b] = twofactors(4530) +for i = 1:100; [a b] = twofactors(4530); a +end +for i = 1:100; [a b] = twofactors(i); a +end +for i = 1:100; [a b] = twofactors(i); c(i) = a; end +clear c +for i = 1:100; [a b] = twofactors(i); c(i) = a; end +end +c +hel stem +help stem +stem(1:100, c) +for i = 1:10000; [a b] = twofactors(i); c(i) = a; end +stem(1:10000, c) +for i = 1:1000; [a b] = twofactors(i); c(i) = a; end stem(1:1000, c) +for i = 1:1000; [a b] = twofactors(i); c(i) = a; end; stem(1:1000, c) +clear c +for i = 1:1000; [a b] = twofactors(i); c(i) = a; end; stem(1:1000, c) +help ecornerplot_vse +ecornerplot_vse +edit ecornerplot_vse +help legend +help legends +help median +help sort +help iseven +help isodd +help odd +curvewiseMedian([sin((1:20)'), 2*sin((1:20)') 3*sin((1:20)') 4*sin((1:20)')]) +3*sin((1:20)') +curvewiseMedian([sin((1:20)'), 2*sin((1:20)') 3*sin((1:20)') 4*sin((1:20)')]) - 3*sin((1:20)') +curvewiseMedian([sin((1:20)'),1.5*sin((1:20)') 2*sin((1:20)') 3*sin((1:20)') 4*sin((1:20)')]) - 3*sin((1:20)') +curvewiseMedian([sin((1:20)'),1.5*sin((1:20)') 2*sin((1:20)') 3*sin((1:20)') 4*sin((1:20)')]) - 2*sin((1:20)') +find({'a', 'b', 'c'}, 'b') +strfind({'a', 'b', 'c'}, 'b') +strcmp({'a', 'b', 'c'}, 'b') +help strcmp +strcmp({'a', 'b', 'c'}, 'b') +find(strcmp({'a', 'b', 'c'}, 'b')) +help std +strcmp({'a', 'b', 'c'}, 'b') +help max +%-- 2/7/18, 7:50 AM --% +help displaymode +help median +help sort +txtl_init +mcmc_init +curvewiseMedian([sin((1:20)'),1.5*sin((1:20)') 2*sin((1:20)') 3*sin((1:20)') 4*sin((1:20)')]) - 2*sin((1:20)') +curvewiseMedian([1.5*sin((1:20)') 2*sin((1:20)') 3*sin((1:20)')]) - 2*sin((1:20)') +curvewiseMedian([1.5*sin((1:20)') 2*sin((1:20)') 3*sin((1:20)')]) +mm = [magic(4); 2*magic(4)] +max(mm) +mm = [[magic(4) ones(4)]; [2*magic(4) 2*ones(4)]] +max(mm) +median(max(mm)) +curvewiseMedian(mm) +help reshape +help permute +rand([2 1 3 5 2] +rand([2 1 3 5 2]) +rand([2 1 3 5]) +rand([2 3 5]) +clc +rand([2 3 5]) +aa = rand([2 3 5]) +aa(:,2,:) +bb= shiftdim(aa, 1) +aa +bb(:,:) +bb +cc = bb(:,:) +cc(2,:) +sort(cc) +aa +cat(4, aa, 2*aa) +dd = cat(4, aa, 2*aa); +size(dd) +mm +cat(3, mm, 2*mm) +ee = cat(3, mm, 2*mm) +ee(:,:,[1 1 2 2 1 2 1 1]) +ff = ee(1:4,1:4, :) +ff(:,[1 2], [1]) +ff(:,[1 2], [1 2]) +ff(:,[1 2], [1 2 2]) +ff(:,[1 2 3 4], [1 2]) +gg = [1 2 1 1] +help reshape +whos +cc +bb +aa +cc +dd +dd(:,:) +dd = cat(4, bb, 2*bb) +dd(:,:) +reshape(dd(:,:), size(dd)) +dd +dd - reshape(dd(:,:), size(dd)) +help medianIndex +dd +aa +ix = medianIndex(aa, 3) +ix = medianIndex(aa, 2) +aa +size(ix) +size(aa) +ix = medianIndex(aa, 1) +aa(ix) +aa +[ix,md] = medianIndex(aa, 1) +aa +[ix,md] = medianIndex(aa, 2) +aa +[ix,md] = medianIndex(aa, 3) +aa +[ix,md] = medianIndex(aa, 3) +%-- 2/8/18, 3:35 AM --% +help std +aa = rand([2 3 5]) +bb= shiftdim(aa, 1) +cc = bb(:,:) +dd = cat(4, aa, 2*aa); +ee = cat(3, mm, 2*mm) +ff = ee(1:4,1:4, :) +gg = [1 2 1 1] +mm = [[magic(4) ones(4)]; [2*magic(4) 2*ones(4)]] +ee = cat(3, mm, 2*mm) +ff = ee(1:4,1:4, :) +gg = [1 2 1 1] +help meshgrid +[x,y,z] = meshgrid(-2:.2:2, -2:.25:2, -2:.16:2); +v = x .* exp(-x.^2 - y.^2 - z.^2); +slice(x,y,z,v,[-1.2 .8 2],2,[-2 -.2]) +ndgrid(-2:.2:2, -2:.25:2, -2:.16:2); +ndgrid(-2:.2:2, -2:.25:2, -2:.16:2) +ndgrid(-0.5:.2:0.5, -0.5:.25:0.5, -0.5:.16:0.5) +[~, ~, ixprime, ~] = ndgrid(ones(10,1), [1 1], [1 2 3], [1 1 1 1]); +ixprime +txtl_init +mcmc_init +[ix,md] = medianIndex(aa, 2) +setdiff([1 2 3 4], [2 3]) +setdiff([1 2 3 4; 5 6 7 8], [2 3; 6 8]) +help figure +help root +help gcf +help gca +true | false +true || false +help OR +help LineStyle +help plot +help parula +autmn +autumn +%-- 2/9/18, 8:59 AM --% +help gca +p1 = plot(1:10) +p2 = plot(2:20) +p1 +p1 = plot(1:10);hold on +p2 = plot(2:20) +[p1;[];p2] +pp = [p1;[];p2] +pp(1) +pp(3:end) +[pp(3:end);pp] +[pp pp] +reshape([pp pp], 4, 1) +help legends +help legend +a +a = 1 +a = 2*a +a = a +help fprintf +fprintf('%g\t', [2 3 4 5]) +a = struct('hello', {{'cc', 'dd'}}) +a.hello +a.hello(1) +a.hello = a.hello(1) +a.hello +datadescription = ... +{['Data from Figure 1 of the 2014 ACS Synthetic Biology paper titled: \n'... +'Gene Circuit Performance Characterization and Resource Usage in a \n'... +'Cell-Free “Breadboard” by Siegal-Gaskins et al. This data involves a \n'... +'measurement of malachite green aptamer and green fluorescent protein \n'... +'over a period of 800 minutes in the TX-TL cell free expression system. \n'... +'The DNA initial conditions used are 0.5nM, 2nM, 5nM, and 20nM.' ]} +di = struct('dataInfo', {datadescription}) +di.dataInfo = {['Modified to only have mRNA data. \n',... +di.dataInfo{1}]}; +di.dataInfo +di.dataInfo{1} +fprintf(di.dataInfo{1}) +whos +txtl_init +mcmc_init +m = model_dsg2014 +m.Parameters +m.Rules +m.Events +txtl_init +txtl_tutorial +%-- 2/15/18, 8:09 AM --% +txtl_init +edit txtl_tutorial +sum([10/3 4.41666]) +sum([10/3 4.41666])/10.5 +ls +edit TXTL_workshop_scripts +help varargin +%-- 2/15/18, 3:22 PM --% +help strut +s = struct('type',{'big','little'},'color','red','x',{3 4}) +s(1) +txtl_init +geneexpr +whos +Mobj.parameters +help globalize_params +globalize_params(Mobj) +Mobj.Parameters +[1 2 5 0 0 1 30 0 3 0 0 0 3 0 0 ] +find(ans) +~find(ans) +help cellfun +cellfun(numel, {[1 3 5], [4 7]}) +help numel +cellfun(@numel, {[1 3 5], [4 7]}) +sum(cellfun(@numel, {[1 3 5], [4 7]})) +numel({[1 3 5], [4 7]}) +mcmc_init +edit proj_acs_dsg2014_mrna.m +proj_acs_dsg2014_mrna +cellfun(@iscell, simID) +proj_acs_dsg2014_mrna +ix +size(dataArray, 4) +proj_acs_dsg2014_mrna +size(inputarray) +(inputarray) +shiftedarray +help sort +help shiftdim +shiftdim(shiftedarray, ndims(inputarray) - dim +1) +ndims(inputarray) - dim +1 +a = rand(1, 4, 2) +a(:,:) +a = rand(1, 4, 1,2) +a(:,:) +a = rand(1, 2, 3,2) +[b,c]=medianIndex(a,3) +shiftedarray +[b,c]=medianIndex(a,3) +shiftedarray +srted +I +II +III +srted3 +reshape(I4, [1, szmat(2:end)]) +I5 +ix +medianvals +a = rand(1, 1, 1,5) +[b,c]=medianIndex(a,3) +ix +a = rand(1, 1, 3,5) +[b,c]=medianIndex(a,3) +medianIndex +a = rand(1, 1, 3,5) +[b,c]=medianIndex(a,3) +a = rand(1, 1, 3,5); +[b,c]=medianIndex(a,3); +a +b +c +proj_acs_dsg2014_mrna +em +proj_acs_dsg2014_mrna +aps +get(aps) +aps(1) +aps(2) +aps(15) +help max +help sgn +help sgnm +a +a = zeros(4) +a(1,:) = 1 +help num2cell +num2str +help num2str +arrayfun(@num2str, 1:10) +arrayfun(@num2str, 1:10, 'UniformOutput', false) +arrayfun(@num2str, 1:9, 'UniformOutput', false) +help arrayfun +arrayfun(@num2str, 1:9, 'UniformOutput', true) +struct('names', {mi(i).dosednames}, 'dosematrix', mi(i).dosedvals);arrayfun(@num2str, 1:9, 'UniformOutput', false) +dosedVals = [0.5 2 5 20] +dosedNames = {'DNA p70--utr1--deGFP'} +struct('names', {dosednames}, 'dosematrix', dosedvals) +struct('names', {dosedNames}, 'dosematrix', dosedVals) +struct('names', {{dosedNames}}, 'dosematrix', {dosedVals}) +struct('names', {dosedNames}, 'dosematrix', {dosedVals}) +struct('names', dosedNames, 'dosematrix', {dosedVals}) +struct('names', dosedNames, 'dosematrix', dosedVals) +dosedVals = [0.5 2 5 20; 3 6 7 2] +dosedNames = {'DNA p70--utr1--deGFP'; 'str2'} +struct('names', dosedNames, 'dosematrix', dosedVals) +ans(1).dosematrix +struct('names', dosedNames, 'dosematrix', dosedVals) +a = struct('names', dosedNames, 'dosematrix', dosedVals) +a.names +a.dosematrix +a = struct('names', {dosedNames}, 'dosematrix', dosedVals) +a.dosematrix +a = struct('names', {dosedNames}, 'dosematrix', {dosedVals}) +a.dosematrix +help all +proj_acs_dsg2014_mrna +logPfuns{fix} +logPfuns{1} +logPfuns{2} +proj_acs_dsg2014_mrna +di.dataInfo +proj_acs_dsg2014_mrna +di.dataInfo +fprintf(di.dataInfo) +fsprintf(di.dataInfo) +sprintf(di.dataInfo) +help fprintf +fsprintf(di.dataInfo{1}) +fprintf(di.dataInfo{1}) +proj_acs_dsg2014_mrna +clc +marray +mi +proj_acs_dsg2014_mrna +size marray +mtemp +marray +clc +mobj +di +mi +size(marray) +mcmc_trajectories(mobj, di, mi, marray) +mi +get(mi.emo) +get(mi.emo.SimulationOptions) +48000/3600 +tv +di +di.timeVector +mcmc_trajectories(mobj, di, mi, marray) +get(mi.emo) +(mi.emo) +get(em.SimulationOptions) +mcmc_trajectories(mobj, di, mi, marray) +get(em.SimulationOptions) +SI = get(em, 'SimulationOptions') +mcmc_trajectories(mobj, di, mi, marray) +mcmc_trajectories(mi.emo, di, mi, marray) +close all +mcmc_trajectories(mi.emo, di, mi, marray) +titls +titls = {'dna 0.5'; 'dna 2';'dna 5';'dna 20'}; +lgds = {}; +mcmc_trajectories(mi.emo, di, mi, marray, titls, lgds) +titls +mcmc_trajectories +mcmc_trajectories(mi.emo, di, mi, marray, titls, lgds) +mcmc_trajectories +mcmc_trajectories(mi.emo, di, mi, marray, titls, lgds) +help legend +mcmc_trajectories(mi.emo, di, mi, marray, titls, lgds) +sum(indices) +clc +double2logical +logical(indices) +marray(logical(indices), :); +marray(logical(indices), :) +clear all +clc +close all +schemer_import +%-- 2/19/18, 6:27 AM --% +schemer_import +txtl_init +mcmc_init +edit proj_acs_dsg2014_protein.m +proj_acs_dsg2014_protein +eno{k} == enuo{kk} +enuo{kk} +eno{k} +class(eno{k}) +strcmp(eno{k}, enuo{kk} ) +proj_acs_dsg2014_protein +master_info.semanticGroups{i} +sgi(1) +help str2num +proj_acs_dsg2014_protein +master_info.fixedParams +proj_acs_dsg2014_protein +mv +proj_acs_dsg2014_protein +mi(i).namesOrd +proj_acs_dsg2014_protein +mi(i).namesOrd +proj_acs_dsg2014_protein +edit gen_residuals_v2.m +length(mi) +mi(i).paramMaps +proj_acs_dsg2014_protein +(ME.identifier +(ME.identifier) +ME +ME.stack +ME.stack(1) +ME.stack(5) +ME.stack(:) +ME(1).stack +ME +proj_acs_dsg2014_protein +mspecies +mspecies{1} +em +get(em) +proj_acs_dsg2014_protein +logPfuns{fix}(minit(:,wix)) +logPfuns{fix} +-1/logPfuns{fix} +logPfuns{fix} +ME +ME.stack(1) +proj_acs_dsg2014_protein +logPfuns{fix}(minit(:,wix)) +fix +whos +kk +length(mi) +size(pmaps, 2) +size(data_array) +size(data_array{kk}) +proj_acs_dsg2014_protein +size(data_array{kk}) +logP(:,:,1) +proj_acs_dsg2014_protein +logPfuns{fix}(proposedm(:,wix)) +proposedm(:,wix) +logP +logP(1,:,1) +minit +proj_acs_dsg2014_protein +minitmi(i).namesOrd = eno +eno{1} +eno +mi +mi(1).paramMaps +mai +mai.masterNames +mai.masterVector +size(mai.masterVector) +mai.masterVector(mi.paramMaps(:,1)) +proj_acs_dsg2014_protein +logP(:,:,1) +logP(1,:,1) +proj_acs_dsg2014_protein +ME +minit +wix +v=logPfuns{fix}(minit(:,wix+1)) +tic v=logPfuns{fix}(minit(:,wix+1)) toc +tic; v=logPfuns{fix}(minit(:,wix+1)); toc +tic; v=logPfuns{fix}(minit(:,wix+2)); toc +for iii = 1:20 +tic; v=logPfuns{fix}(minit(:,wix+iii)); toc +end +clc +proj_acs_dsg2014_protein +minit_justEstParams +estParamsIx +mi(i).paramMaps(:,1) +mi(i).paramMaps(mi(i).orderingIx, 1) +proj_acs_dsg2014_protein +size(marray) +projdir +help repmat +schemer_import +size(mvarray(estParamsIx, :) ) +size(marrayOrd) +clc +close all +tstamp +mi.namesOrd +close all +help proj_acs_dsg2014_mrna +edit proj_acs_dsg2014_mrna +schemer_import +proj_acs_dsg2014_protein +magic(2)' +magic(2) +mmm = [magic(2);2*magic(2)] +mmm' +flipud(mmm') +size(outputsliceold(:,(end-npoints+1):end)) +clc +clear all +close all +proj_acs_dsg2014_protein +tstamp +clear all; load(['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/'... +'mcmc_simbio/projects/proj_acs_dsg2014_mrna/simdata_20180121_131114/full_variable_set_20180121_131114.mat']) +whos +em +eno +mi +mi.names_unord +mi.names_ord +cellfun(@strcmp, mi.names_ord, mi.names_unord) +proj_acs_dsg2014_protein +mi(i).dataToMapTo(j) +eno +enuo +orderingIx +orderingIx2 +cellfun(@strcmp, enuo(orderingIX), eno) +cellfun(@strcmp, enuo(orderingIx), eno) +mi(1).paramMaps(:,1) +mi(1).paramMaps(orderingIx,1) +mi +mi.paramMaps +mi.paramMaps(mi.orderingIx, :) +proj_acs_dsg2014_protein +clear all +size(marray) +clear all; load(['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/'... +'mcmc_simbio/projects/proj_acs_dsg2014_mrna/simdata_20180121_131114/full_variable_set_20180121_131114.mat'])whos +whos +mi +get(em) +[exp(m(end - kk,:)'); dose(i,:)'] +ms{ss} +ME.message +help selectbyname +clc +proj_acs_dsg2014_protein +clear all +close all +clc +proj_acs_dsg2014_protein +marray = mcmc_get_walkers({'20180121_131114'}, {5}, ... +['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/'... +'mcmc_simbio/projects/proj_acs_dsg2014_mrna']); +nPrevPoints = 5; +minit = marray(:, ((end-nPrevPoints+1) : end), end); +minit] +minit +marray_cut(:,:,end) +proj_acs_dsg2014_protein +marray_cut(:,:,end) +marray_cut(:,:,end)' +proj_acs_dsg2014_protein +tstamp +whos +exp(10) +exp(8) +exp(9) +tstamp +proj_acs_dsg2014_protein +close all +clear all +clc +%-- 2/22/18, 2:32 AM --% +txtl_init +mcmc_init +proj_acs_dsg2014_protein +edit mcmc_trajectories.m +size(spreadst, 3) +squeeze(spreadst(:,1,:,2)) +format short g +squeeze(spreadst(:,1,1:10,2)) +squeeze(simspreadst(:,1,1:10,3)) +m(end-3:end,:) +figure; hist(m(end-50:end,:)) +help hist +figure; hist(m(end-1000:end,1)) +figure; hist(m(end-1000:end,1),50) +figure; hist(m(end-1000:end,2),50) +figure; hist(m(end-1000:end,3),50) +mi +close all +mi.namesUnord(mi.orderingIx) +figure; hist(m(end-1000:end,5),50) +figure; hist(m(end-50:end,5),50) +figure; hist(m(end-50:end,5),50); pause(3); close +figure; hist(m(end-50:end,5),50); pause(6); close +figure; hist(m(end-50:end,6),50); pause(2); close +figure; hist(m(end-50:end,7),50); pause(2); close +figure; hist(m(end-50:end,24),50); pause(2); close +m(end-50:end,2) +[xx, yy] = sort(m(end-500:end,2)) +[xx, yy] = sort(m(121,2)) +[xx, yy, zz] = sort(m(end-500:end,2)) +help sort +m(121,2) +m(386,2) +m(end-121,2) +m(end-500+121,2) +m(end-500+121+1,2) +m(end-500+121-1,2) +m(end-50:end,2) +em +ms +ms{1} +idxnotused +size(da) +da(:,1,1:10,4) +clc +squeeze(da(:,1,1:10,4)) +squeeze(da(:,1,1:5,4)) +get(em, 'ValueInfo') +em.ValueInfo +vii = em.ValueInfo; +for ii = 1:25 +vin{ii} = vii.Name; +end +vin +edit mcmc_runsim_v2.m +mi,em +mi.em +mi.emo +for ii = 1:25 +vii = mi.emo.ValueInfo; +vin{ii} = vii.Name; +end +vin +mi(i).emo +for ii = 1:25 +vii = mi.emo.ValueInfo; +vin{ii} = vii.Name; +end +vin +mi(i).namesUnord +ep +es +aps +get(aps) +get(aps(22)) +emo +emo{1} +for ii = 1:25 +vii = mi.emo.ValueInfo; +vin{ii} = vii.Name; +end +for ii = 1:25 +vii = emo{1}.ValueInfo; +vin{ii} = vii.Name; +end +vin +mobj +mobj.parameters +[ep; es; ds](1) +epep = [ep; es; ds] +epep(1) +epep(2) +epep(3) +epep(4) +epep(5) +emo{i} +emo{i}.ValueInfo +emo{i}.ValueInfo(1).Name +emo{i}.ValueInfo(2).Name +emo{i}.ValueInfo(3).Name +for ii = 1:25 +vii = emo{1}.ValueInfo(ii); +vin{ii} = vii.Name; +end +vin +em.ValueInfo(1).Name +em.ValueInfo(4).Name +em.ValueInfo(7).Name +sd +get(sd) +get(sd.DataNames) +(sd.DataNames) +(sd.Data) +help sbiotrellis +sbiotrellis(sd) +sbioplot(sd) +marrayOrd +size(marrayOrd) +marrayOrd(:,end-2:end, end) +mi.namesOrd +[mi.namesOrd, marrayOrd(:,end-2:end, end)] +{mi.namesOrd, marrayOrd(:,end-2:end, end)} +marrayOrd(:,end-4:end, end) +marrayOrd(:,end, end) +exp(4.5145) +help num2cell +num2cell(marrayOrd(:,end, end)) +[num2cell(marrayOrd(:,end, end)) mi.namesOrd] +aaa = [num2cell(marrayOrd(:,end, end)) mi.namesOrd] +aaa(:,1) +cell2mat(aaa(:,1)) +m +size(m) +ME +[exp(m(end - kk+1,:)'); dose(i,:)'] +close all +cell2mat(aaa(:,1))' +[exp(m(end - kk+1,:)'); dose(i,:)'] +di +mi +ehos +whos +ms +mi.measuredSpecies +[exp(m(end - kk+1,:)'); dose(i,:)']mi.measuredSpecies +[exp(m(end - kk+1,:)'); dose(i,:)'] +ME +[exp(m(end - kk+1,:)'); dose(i,:)'] +size([exp(m(end - kk+1,:)'); dose(i,:)']) +tv +help sbioplot +geneexpr +mobj +whos +Mobj +mobj +mobj.reactions +marrayOrd(:,end, end) +aaa = [num2cell(marrayOrd(:,end, end)) mi.namesOrd] +aaa = [num2cell(marrayOrd(:,end, end)) num2cell(marrayOrd(:,end, end)) mi.namesOrd] +edit data_dsg2014.m +data_VNPRL2011 +di +whos +clear all +di = data_VNPRL2011; +di +di(1) +di(2) +di(2).timeVector +plot(di(2).timeVector, squeeze(di(2).dataArray)) +daa = squeeze(di(2).dataArray) +di = data_VNPRL2011; +daa = squeeze(di(2).dataArray) +plot(di(2).timeVector, squeeze(di(2).dataArray)) +di = data_VNPRL2011; +plot(di(2).timeVector, squeeze(di(2).dataArray)) +plot(di(1).timeVector, squeeze(di(1).dataArray)) +daa = squeeze(di(1).dataArray) +clc +daa = squeeze(di(1).dataArray) +di = data_VNPRL2011; +daa = squeeze(di(1).dataArray) +squeeze(daa(:,1,:)) +plot(di(1).timeVector, squeeze(daa(:,1,:))) +plot(di(1).timeVector, squeeze(daa(:,2,:))) +figure; subplot(2, 1, 1); plot(di(1).timeVector, squeeze(daa(:,2,:))); +figure; subplot(2, 1, 2); plot(di(1).timeVector, squeeze(daa(:,1,:))); +subplot(2, 1, 2); plot(di(1).timeVector, squeeze(daa(:,2,:))); +close all; subplot(2, 1, 2); plot(di(1).timeVector, squeeze(daa(:,2,:))); +subplot(2, 1, 1); plot(di(1).timeVector, squeeze(daa(:,1,:))); +help diff +figure; plot(di(1).timeVector, diff(squeeze(daa(:,2,:)))); +figure; plot(di(1).timeVector(1:end-1), diff(squeeze(daa(:,2,:)))); +help interp1 +di = data_VNPRL2011; +daa = squeeze(di(1).dataArray) +figure; plot(di(1).timeVector(1:end-1), diff(squeeze(daa(:,2,:)))); +figure; plot(di(1).timeVector(1:end-1)/3600, diff(squeeze(daa(:,2,:)))); +close all; subplot(2, 1, 2); plot(di(1).timeVector/3600, squeeze(daa(:,2,:))); +subplot(2, 1, 1); plot(di(1).timeVector/3600, squeeze(daa(:,1,:))); +figure; plot(di(1).timeVector(1:end-1)/3600, diff(squeeze(daa(:,2,:)))); +di = data_VNPRL2011; +di +proj_VNPRL +subplot(2, 1, 2); plot(di(1).timeVector, squeeze(daa(:,2,:))); +close all; subplot(2, 1, 2); plot(di(1).timeVector, squeeze(daa(:,2,:))); +subplot(2, 1, 1); plot(di(1).timeVector, squeeze(daa(:,1,:))); +help diff +figure; plot(di(1).timeVector, diff(squeeze(daa(:,2,:)))); +figure; plot(di(1).timeVector(1:end-1), diff(squeeze(daa(:,2,:)))); +help interp1 +di = data_VNPRL2011; +daa = squeeze(di(1).dataArray) +figure; plot(di(1).timeVector(1:end-1), diff(squeeze(daa(:,2,:)))); +figure; plot(di(1).timeVector(1:end-1)/3600, diff(squeeze(daa(:,2,:)))); +close all; subplot(2, 1, 2); plot(di(1).timeVector/3600, squeeze(daa(:,2,:))); +subplot(2, 1, 1); plot(di(1).timeVector/3600, squeeze(daa(:,1,:))); +figure; plot(di(1).timeVector(1:end-1)/3600, diff(squeeze(daa(:,2,:)))); +proj_VNPRL +size(di(1).timeVector(1:end-10)/3600) +proj_VNPRL +close all +log(0.1) +log(10) +log(0.5) +3600*5 +activeNames +activeNames(:,3) +cell2mat(activeNames(:,3)) +mi = mcmc_info_vnprl2011_mrna +help struct +mi = mcmc_info_vnprl2011_mrna +model_info = struct(... +'circuitInfo',{circuitInfo1, circuitInfo2},... +'modelObj', {modelObj, modelObj}) +whos +mcmc_info = mcmc_info_vnprl2011(mobj) +mcmc_info = mcmc_info_vnprl2011_mrna(mobj) +mcmc_info.model_info +mcmc_info.model_info(1) +mcmc_info.model_info(2) +mcmc_info = mcmc_info_vnprl2011_mrna(mobj) +mcmc_info.model_info(1) +mcmc_info.model_info(2) +close all +%-- 2/26/18, 9:11 AM --% +tv1<10*3600 +tv1(tv1<10*3600) +proj_VNPRL_mrna +currda +close all +format short g +currda +sum(da, 1) +[ix, mdvals] = medianIndex(sum(da, 1), 3) +inputarray +inputarrayshiftdim(inputarray, dim-1) +shiftdim(inputarray, dim-1) +srted +I +size(I, 1)+1) +size(I, 1)+1 +II +III +help shiftdim +size(inputarray) +size(shiftedarray) +proj_VNPRL_mrna +I +srtd +srted +inputarray +srted5 +I5 +help shiftdim +ia = inputarray(:, 1, :, :); +shiftdim(ia, 2) +size(ans) +inputarray = inputarray(:, 1, :, :); +shiftedarray = shiftdim(inputarray, dim-1); +[srted, I] = sort(shiftedarray, 1); +II = ceil((size(I, 1)+1)/2); +III = I(:,:); +srted3 = srted(:,:); +% index using II (ie, find the closest-to-middle element) +I4 = III(II,:); +srted4 = srted3(II, :); +% Now reshape back using the original dimensions +szmat = size(I); +I5 = reshape(I4, [1, szmat(2:end)]); +srted5 = reshape(srted4, [1, szmat(2:end)]); +% shift back to the original dimensions +ix = shiftdim(I5, -dim+1);%ndims(inputarray) - dim +1 +medianvals = shiftdim(srted5, -dim+1); +ix +srted5 +size(srted5) +rr = rand(2, 1, 3, 4); +size(shiftdim(rr, 2)) +proj_VNPRL_mrna +ix +medianvals +proj_VNPRL_mrna +mobj +mobj.species +sbioselect(mobj, 'Type', 'species', 'Name', ... +mi.namesUnord) +es = sbioselect(mobj, 'Type', 'species', 'Name', ... +mi.namesUnord); +queryargs{:} +s = SimBiology.internal.makeFindString(opts, queryargs{:}) +es = sbioselect(mobj, 'Type', 'species', 'Name', ... +mi(i).namesUnord) +proj_VNPRL_mrna +da +ix +ix(1,i, 1,j) +ix +size(dataArray, 4) +size(dataArray, 2) +size(dataArray) +dataArray(:, i, ix(1,i, 1,j), j) +medianCurves(:,i,1,j) = dataArray(:, i, ix(1,i, 1,j), j) +proj_VNPRL_mrna +size(dataArray, 4) +size(dataArray, 2) +ix +proj_VNPRL_mrna +size(da) +size(shiftdim(inputarray, dim-1)) +szmat(2:end) +size(padded_I5) +padded_I5 +padded_srted5 +proj_VNPRL_mrna +mi(i).emo +i +minitTopoGeom +mi(i).namesOrd +proj_VNPRL_mrna +mi(kk).paramMaps +mi(kk).dosedVals +mi(kk).emo +get(mi(kk).emo) +mi(kk).measuredSpecies +proj_VNPRL_mrna +close all +mami(1).orderingIx +mai(1).orderingIx +mi(1).orderingIx +mi(1).emo +get(mi(1).emo, 'ValueInfo') +vii = get(mi(1).emo, 'ValueInfo') +vii(:) +vii(1).Name +for i = 1:16; vii(i ).Name end +for i = 1:16; vii(i ).Name +end +size(marrayOrd) +mi(2).orderingIx +paramMaps(mi(2).orderingIx, 1) +mi(2).paramMaps(mi(2).orderingIx, 1) +di(3) +mi(2) +%-- 2/26/18, 4:26 PM --% +txtl_init +mcmc_init +proj_VNPRL_mrna +%-- 2/27/18, 5:49 AM --% +txlt_init +txtl_init +mcmc_init +close all +ecornerplot_vse(marray,'scatter', p.scatter,... +'ks', p.ks,... +'names', legendz,... +'grid', p.grid,... +'color', p.color,... +'fullmatrix', p.fullmatrix,... +'ks', p.ks,... +'support', p.support, ... +'transparency', p.transparency); +close all +ecornerplot_vse(marray,'scatter', p.scatter,... +'ks', p.ks,... +'names', legendz,... +'grid', p.grid,... +'color', p.color,... +'fullmatrix', p.fullmatrix,... +'ks', p.ks,... +'support', p.support, ... +'transparency', p.transparency); +close all +tstamp +paramRanges +estParams +exp(8.9) +exp(8.9)/3600 +size(marrayOrd) +%-- 3/9/18, 11:43 PM --% +txtl_init +mcmc_init +help struct +help assert +help struct +s1 = struct('a', 2, 'b', {{3 4 6}}) +s2 = struct('a', 7, 'b', {{5 4 6}}) +s3 = [s1, s2] +clc +s1 +clc +measuredSpecies{msID} +da_extract1 +close all +clc +proj_protein_constgfp3i +close all +proj_protein_constgfp3i +tstamp2 +tstamp2 = '20180311_224651' +projdir +proj_protein_constgfp3i +projdir +tstamp2 +20180311_224651 +tstamp2 = '20180311_224651' +help save +clc +help save +close all +rng +rng.state +rng.State +help rng +rand +rand*10000 +randstream +RandStream +now +help now +datestr(now) +datestr(now, 'yyyymmddHHmmss') +datestr(now, 'yyyymmddHHMMSS') +datestr(now, 'yyyymmdd_HHMMSS') +help saveas +help print +projdir +close all +proj_protein_constgfp3i +%-- 3/12/18, 4:19 PM --% +txtl_init +mcmc_init +proj_protein_constgfp3i +close all +edit mcmc_info_constgfp3ii.m +proj_protein_constgfp3ii +ME +ME.stack +ME.stack(:) +ME(1).stack +ME(1).stack(1) +ME(1).stack(2) +edit mcmc_runsim_v2 +proj_protein_constgfp3ii +mai.estNames +close all +fhandle +close all +proj_protein_constgfp3iii +close all +clear all +clcl +clc +proj_protein_constgfp3iv +close all +clc +proj_protein_constgfp3ii +close all +mi(1).orderingIx +mi +mi(1).paramMaps +mi(1).paramMaps(mi(1).orderingIx, 2) +mi(1).paramMaps(mi(1).orderingIx, 1) +clc +close all +size(mvarray) +em +mi.namesOrd +mi.namesUnord +get(em) +get(em, 'ValueInfo') +gg = get(em, 'ValueInfo') +gg(1) +gg(2) +gg(3) +gg(4) +ms +ms{1} +[da, idxnotused] = simulatecurves(em,m, p.nSimCurves, dose, tv, ms); +marray(:,end-10:end, end) +proj_protein_constgfp3ii +proj_protein_constgfp3iii +close all +tstamp1 +tstamp2 +proj_protein_constgfp3iii +proj_protein_constgfp3iv +exp(-2) +exp(10) +exp(5) +exp(8) +exp(-5) +exp(-7) +exp(7) +exp(-2) +exp(-4) +exp(-3) +exp(5) +exp(6) +proj_protein_constgfp3iv +close all +exp(-.3) +size(marrayOrd) +size(marrayOrd(:,end-5:end,end)) +(marrayOrd(:,end-5:end,end)) +(marrayOrd(3,:,end))' +hist(marrayOrd(3,:,end))' +help hist +histogram(marrayOrd(3,:,end))' +figure histogram(marrayOrd(3,:,end))' +figure; histogram(marrayOrd(3,:,end))' +figure; histogram(marrayOrd(3,:,end), 100)' +exp(marrayOrd(3,:,end))' +histogram(exp(marrayOrd(3,:,end))', 50) +histogram(exp(marrayOrd(3,:,end))', 500) +format short g +exp(marrayOrd(3,:,end))' +marray = mcmc_get_walkers({tstamptouse}, {1}, projdir); +size(marray) +size(marray(3,:,:)) +histogram(marray(3,:,:), 100) +histogram(marray(3,:,1), 100) +close all +histogram(marray(3,:,1), 100) +figure; for i = 1:8 +subplot(4, 2, i); histogram(marray(3,:,i), 100); +end +figure; for i = 1:16 +subplot(4, 4, i); histogram(marray(3,:,4*i), 100); +end +marray = mcmc_get_walkers({tstamptouse}, {1:8}, projdir); +figure; for i = 1:36 +subplot(6, 6, i); histogram(marray(3,:,20*i), 100); +end +edit mcmc_runsim_v2 +%-- 3/16/18, 4:28 AM --% +edit mcmc_trajectories.m +log([100;6000;0.012;200;400;200;400;100]) +log([100;6000;0.012;200;400;200;400;100])-3 +log([100;6000;0.012;200;400;200;400;100])+3 +[log([100;6000;0.012;200;400;200;400;100])-3 log([100;6000;0.012;200;400;200;400;100])+3] +clc +whos +clear all +close all +clc +whos +di +help DSP) +help DSP +help legends +explore_constgfp3tetR1 +di(1) +di(2) +di(2).dosedNames +explore_constgfp3tetR1 +size(expsummst) +squeeze(expsummst) +aaa = squeeze(expsummst) +unique(aaa(end,:)) +close all +clear all +explore_constgfp3tetR1 +currmeasuredSpecies +currmeasuredSpecies{1} +explore_constgfp3tetR1 +aaa = squeeze(da) +aaa = squeeze(da(end,:,:,:)) +explore_constgfp3tetR1 +mobj +mobj.species +mobj.Parameters +explore_constgfp3tetR1 +ckc +clc +ln(2) +log(2) +edit explore_constgfp5tetR2.m +explore_constgfp5tetR2 +{mi(1).measuredSpecies +} +mi(1).measuredSpecies +mi(1).measuredSpecies{1}] +mi(1).measuredSpecies{1} +mi(2).measuredSpecies{1} +mi(2).measuredSpecies{2} +edit proj_tetR1i.m +explore_constgfp3tetR1 +edit explore_constgfp3tetR1 +close all +edit mcmc_info_tetR_1i.m +close all +%-- 3/19/18, 1:11 AM --% +txtl_init +mcmc_init +edit proj_tetR1i.m +proj_tetR1i +mi2(1).paramMaps(mi2(1).orderingIx, 2) +mi2(1).paramMaps(mi2(1).orderingIx, 1) +proj_tetR1i +mi1.namesUnord +close all +exp([-3.75 4.4]) +exp([-4.46 4.4]) +edit proj_tetR1ii.m +proj_tetR1ii +whos +masterVector' +masterVector([2 4 6 8 9 11])' +masterVector([2 4 6 8 10 12])' +close all +mai.estNames +help scatter3 +close all +proj_tetR1ii +close all +size(mstacked) +close all +proj_tetR1i +close all +edit proj_tetR2i.m +proj_tetR2i +%-- 3/20/18, 6:38 AM --% +txtl_init +mcmc_init +proj_tetR2i +edit proj_tetR2ii.m +proj_tetR2ii +close all +edit mcmc_runsim_v2.m +proj_tetR2ii +mcmc_info_tetR_2ii +proj_tetR2ii +%-- 3/21/18, 2:00 AM --% +txtl_init +mcmc_init +proj_tetR2ii +whos +tstamp +clear all +close all +clc +proj_tetR2ii +tstamp +proj_tetR2ii +tstamp +proj_tetR2ii +close all +clear all +clc +proj_tetR2ii +close all +clc +clear all +proj_protein_constgfp5ii +tstamp +cloe all +close all +clear all +clc +proj_protein_constgfp5ii +tstamp +proj_protein_constgfp5ii +tstamp +proj_protein_constgfp5ii +edit mcmc_runsim_v2.m +proj_protein_constgfp5ii +close all +proj_protein_constgfp5ii +tstamp +proj_protein_constgfp5ii +tstamp +closr all +close all +%-- 3/23/18, 4:35 AM --% +txtl_init +mcmc_init +20180322_115822 +proj_protein_constgfp5ii +tstamp +proj_protein_constgfp5ii +close all; proj_protein_constgfp5ii +tstamp +proj_protein_constgfp5ii +close all +proj_tetR2i +tstamp1 +tstamp2 +proj_tetR2i +clc +close all +clear all +%-- 4/2/18, 1:52 AM --% +proj_protein_constgfp3ii +close all +clear all +clc +proj_protein_constgfp3ii_linux +whos +projdir +clear all +load full_variable_set_20180401_151138 +whos +tstamp +da +mcmc_info +specificproj +close all +clear all +load(['full_variable_set_' ts1]); +load(['full_variable_set_20180401_151716' ]); +path +clc +clear all +close all +load([specificprojdir '/full_variable_set_' ts1], 'mcmc_info', 'mi'); +whos +mi +load([specificprojdir '/full_variable_set_' ts1]) +whos +data_info +explore_corr_gfp3ii_w_and_wo_cov +size(marray) +clc +clear all +explore_corr_gfp3ii_w_and_wo_cov +close all +clear all +clc +explore_corr_gfp3ii_w_and_wo_cov +help addOptional +mi = proj_protein_constgfp3ii_linux([], 'stepSize', 1.05, 'nW', 40, 'nPoints', 4e2, 'thinning', 2, 'nIter', 2, 'parallel', false, 'multiplier', 2) +explore_corr_gfp3ii_w_and_wo_cov +%-- 4/3/18, 2:37 PM --% +help lead +help load +explore_corr_gfp3ii_w_and_wo_cov +%-- 4/4/18, 5:45 AM --% +explore_corr_gfp3ii_w_and_wo_cov +whos +data_info +data_info(1) +close all +help scatter +scatter3 +help scatter3 +XXred +help line +[XX1;XX2] +help scatter3 +save('covE1_offthemanifold') +mcmc_info +mcmc_info.runsim_info +mcmc_info.model_info +mcmc_info.master_info +close all +explore_corr_gfp3ii_w_and_wo_cov +whos +%-- 4/5/18, 7:46 AM --% +CaptureFigVid_Example +explore_corr_gfp3ii_w_and_wo_cov +mai.estNames +help surf +ssurrff +ssurrff.FaceAlpha +ssurrff.FaceAlpha = 0.2 +caxis +colormap +vq +xq +yq +help axis +axis +s2 +set(s2) +set(s2, 'LineStyle', 'none') +s2 +s2.EdgeColor = [0.5 0 0] +set(s2, 'LineStyle', ':') +s2.EdgeColor = [0.5 0.5 0.5] +set(s2, 'LineStyle', '--') +set(s2, 'LineStyle', '-') +help daspect +addpath('/Users/vipulsinghal/Dropbox/Documents/MATLAB/CaptureFigVid/CaptureFigVid') +30:0:30 +290:10:200 +290:-10:200 +explore_corr_gfp3ii_w_and_wo_cov +length([30*ones(1,6),30:-3:18 18:3:57]) +explore_corr_gfp3ii_w_and_wo_cov +[30*ones(1,6),30:-6:18 18:6:90] +[30*ones(1,6),30:6:72 72:-6:18 +] +tstouse +fhandle +get(fhandle) +cc2 = get(fhandle, 'Children') +cc2(1) +cc2(1).title +cc2(1).Title +class(cc2) +class(cc2(1)) +class(cc2(2)) +class(cc2(3)) +class(cc2(4)) +help plot +di(2) +help paramid +size(da) +cc1 +explore_corr_gfp3ii_w_and_wo_cov +pp +alpha(pp, 0.1) +close all +cc1 +clc +explore_corr_gfp3ii_w_and_wo_cov +tstouse +explore_corr_gfp3ii_w_and_wo_cov +whos +axis +gca +help axis +explore_corr_gfp3ii_w_and_wo_cov +help axis +explore_corr_gfp3ii_w_and_wo_cov +cc(3) +cc2 +cc2(3) +explore_corr_gfp3ii_w_and_wo_cov +close all +geneexpr +edit txtl_enzyme_resource_degradation.m +%-- 4/12/18, 7:24 AM --% +txtl_init +geneexpr +mobj +Mobj +mobj.reactions +Mobj.Reactions +edit txtl_protein_degradation.m +negautoreg +tube.Parameters +sbioselect(tube, 'Name', 'TX_elong_glob') +sbioselect(tube, 'Name', 'TX_elong_glob', 'Type', 'Parameter') +negautoreg +tube +tube.Parameters +tube.Userdata.ReactionConfig.Transcription_Rate +addparameter(tube, 'TX_elong_glob',tube.Userdata.ReactionConfig.Transcription_Rate); +negautoreg +Mobj +Mobj.reactions +geneexpr +Mobj.reactions +edit txtl_add_dna +edit data_info_struct.m +data_info_struct +class(tidyCSV) +class(tidyData) +size(tidyData) +(tidyData(1:20, :)) +time +time/3600 +times{1}/3600 +times{1} +times{1}==0 +time +geneexpr +modelObj +modelObj.UserData +geneexpr +modelObj.UserData +help isfield +geneexpr +edit txtl_add_dna +geneexpr +rna +get(rna) +edit geneexpr +geneexpr +Mobj +Mobj.reactions +edit geneexpr +Mobj.UserData +Mobj.UsetData.energymode = 'regeneration' +Mobj.UserData.energymode = 'regeneration' +Mobj.UserData +geneexpr_test_regen_mode +isfield(tube.UserData, 'energymode') +strcmp(tube.UserData.energymode, 'regeneration') +geneexpr_test_regen_mode +Mobj.parameters +geneexpr_test_regen_mode +get(Mobj.Parameters +get(Mobj.Parameters) +sbioselect(Mobj.Parameters) +geneexpr_test_regen_mode +Mobj.Parameters +geneexpr_test_regen_mode +data_info_struct +whos +clear all +data_info_struct +whos +data_info +dataInfo +di +di{1} +help struct +clear di +di +di(1) +aaa = struct([]) +aaa = struct(1:4) +clear di +di +di(1) +di(1).dosedNames +di(1).dosedVals +doseInfos +unique(tidyData(:,{'data_info_element'})) +(tidyData(:,{'data_info_element'})) +doseInfos = unique(tidyData(:,{'data_info_element'})) +doseInfos = table2array(doseInfos)' +size(di(1).dataArray) +help height +di(1).dosedNames +di(1).dosedVals +(di(1).dataArray(:,1,1,1) +(di(1).dataArray(:,1,1,1)) +di(1).dataArray(1:10,:,1,1) +di(1).dataArray(1:20,:,1,1) +di(1).dataArray(1:20,:,1:2,1) +di(1).dataArray(1:20,:,1,1:3) +di(2).dataArray(1:20,:,1,1:3) +di(3).dataArray(1:20,:,1,1:3) +di(3).dataArray(1:20,:,1,3:5) +di(3).dataArray(1:20,:,1,6:7) +di(2).measuredNames +clc +txtl_init +geneexpr_test_regen_mode +mobj +Mobj +Mobj.parameters +Mobj.rules +Mobj.events +%-- 4/19/18, 1:43 PM --% +txtl_init +edit txtl_enzyme_resource_degradation.m +edit txtl_reaction_config.m +activeNames1 = {... +'TX_elong_glob' 1 [0.5 10] +'AGTPdeg_time' 10800 [1800 18000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-1] +'TXTL_P70_RNAPbound_Kd' 12 [0.1 1000] +'TXTL_P70_RNAPbound_F' 17 [0.1 100] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.07 [1e-4 10] +'TXTL_NTP_RNAP_1_Kd' 2 [0.1 1000] +'TXTL_NTP_RNAP_1_F' 10 [0.1 100] +'TXTL_NTP_RNAP_2_Kd' 10 [0.1 1000] +'TXTL_NTP_RNAP_2_F' 1 [0.1 100] +'TXTL_RNAdeg_Kd' 2000 [1 5000] +'TXTL_RNAdeg_F' 1 [0.1 1000] +'TXTL_RNAdeg_kc' 0.001 [1e-4 1] +'RNAP' 30 [5 500] +'RNase' 200 [10 1000]}; +activeNames1(:,1) +exp([5 9 +-4 0 +-2 10 +-1 3 +-2 10 +-3 10 +2 7 +-3 4 +-1.2 -0.8 +5 8]) +format short g +exp([5 9 +-4 0 +-2 10 +-1 3 +-2 10 +-3 10 +2 7 +-3 4 +-1.2 -0.8 +5 8]) +Mobj.reactions +edit txtl_transcription +Mobj.reactions +Mobj +Mobj.Parameters +globalize_params(Mobj) +mmob = globalize_params(Mobj) +mmob.Parameters +Mobj.species +help globalize_params +edit globalize_params +edit txtl_transcription +edit txtl_reaction_config.m +mmob = globalize_params(Mobj) +mmob.Parameters +activeNames2 = {... +'TX_elong_glob' 10.5 [0.5 30] +'AGTPdeg_time' 7200 [1800 18000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] +'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 100] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] +'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] +'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] +'TXTL_RNAdeg_Kd' 2000 [100 10000] +'TXTL_RNAdeg_F' 0.01 [0.1 1000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] +'RNAP' 100 [5 500] +'RNase' 100 [10 1000] +'TL_elong_glob' 20 [4 200] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] +'TXTL_UTR_UTR1_Kd' 20 [1 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] +'TL_AA_Kd' 100000 [10 1e8] +'TL_AA_F' 0.001 [1e-5 1] +'TL_AGTP_Kd' 100000 [1e2 1e8] +'TL_AGTP_F' 1e-5 [1e-7 1] +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] +'Ribo' 30 [5 1000]}; +size(activeNames2) +[{1:26}' activeNames2] +{1:26}' +[(1:26)' activeNames2] +(1:26)' +activeNames2 +help array2cell +help mat2cell +[mat2cell((1:26)') activeNames2] +[mat2cell((1:26)', 26, 1) activeNames2] +[num2cell((1:26)') activeNames2] +estParams = activeNames2([1 2 5:17 19:26 ]',1); +estParams +edit proj_acs_dsg2014_regen_A.m +edit model_dsg2014 +mm = model_dsg2014_regen +mm +mm.events +mm.params +mm.Parameters +proj_acs_dsg2014_regen_A +[mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_A(... +'stepSize', 1.5, 'nW', 40, 'nPoints', 2e3, 'thinning', 3,... +'nIter', 3, 'parallel', false, 'multiplier', 2, 'stdev', 5); +[mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_A(... +'stepSize', 1.5, 'nW', 40, 'nPoints', 2e3, 'thinning', 3,... +'nIter', 3, 'parallel', false, 'multiplier', 2, 'stdev', 5); +[mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_A(... +'stepSize', 1.5, 'nW', 50, 'nPoints', 2e3, 'thinning', 3,... +'nIter', 3, 'parallel', false, 'multiplier', 2, 'stdev', 5); +edit txtl_reaction_config.m +di = data_dsg2014_full +di(1) +di(2) +di(3) +mobj = model_dsg2014_regen; +%% setup the mcmc_info struct +mcmc_info = mcmc_info_dsg2014_regen_A(mobj); +mcmc_info.model_info +mcmc_info.model_info(1) +mcmc_info = mcmc_info_dsg2014_regen_A(mobj); +mcmc_info.model_info(1) +mcmc_info.model_info(2) +di +di(1) +[mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_A(... +'stepSize', 1.10, 'nW', 42, 'nPoints', 6e2, 'thinning', 3,... +'nIter', 2, 'parallel', false, 'multiplier', 2, 'stdev', 1); +[mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_A(... +'stepSize', 1.10, 'nW', 120, 'nPoints', 4e3, 'thinning', 3,... +'nIter', 2, 'parallel', true, 'multiplier', 2, 'stdev', 1); +close all +clear all +clc +% add source code directory +addpath('/Users/vipulsinghal/Dropbox/Documents/vipul_repo/MCMC/Code_MCMC/src') +close all +clear all +clc +% add source code directory +addpath('/Users/vipulsinghal/Dropbox/Documents/vipul_repo/MCMC/Code_MCMC/src') +parallalflag = true; +nsteps = 2e5; +nW = 600; +stepsz = 3; +lb =-8; ub = 8; +% add source code directory +addpath('/Users/vipulsinghal/Dropbox/Documents/vipul_repo/MCMC/Code_MCMC/src') +parallalflag = true; +nsteps = 2e5; +nW = 600; +stepsz = 3; +lb =-8; ub = 8; +eval(['load(''t015_calib_' datestring '_5_MBP'', ''m'');']) +mstacked = m(:,:)'; +medn = median(mstacked); +kc_calib = medn(5) %use medians +P_calib = medn(6) %use medians +addpath(genpath(pwd)) +t015_calib_20171023_015326_5_MBP.mat +load('t015_calib_20171023_015326_5_MBP.mat') +whos +mstacked = m(:,:)'; +medn = median(mstacked); +kc_calib = medn(5) %use medians +P_calib = medn(6) %use medians +exp([kc_calib P_calib]) +load('t015_calib_20171023_043408_5_MBP') +mstacked = m(:,:)'; +medn = median(mstacked); +kc_calib = medn(5) %use medians +P_calib = medn(6) %use medians +exp([kc_calib P_calib]) +mstacked = m(:,:)'; +medn = median(mstacked); +kc_calib = medn(5) %use medians +P_calib = medn(6) %use medians +exp(medn) +load('t015_calib_20171023_015326_5_MBP.mat') +mstacked = m(:,:)'; +medn = median(mstacked); +kc_calib = medn(5) %use medians +P_calib = medn(6) %use medians +exp(medn) +load('t015_calib_20171023_151627_5_MBP') +mstacked = m(:,:)'; +medn = median(mstacked); +kc_calib = medn(5) %use medians +P_calib = medn(6) %use medians +exp(medn) +clear all +load 't015_corr1_20171023_151627_17_MBP' +whos +loglike_corr1 +kc_calib +P_calib +datestring +eval(['load(''t015_calib_' datestring '_5_MBP'', ''m'');']) +mstacked = m(:,:)'; +medn = median(mstacked); +kc_calib = medn(5) %use medians +P_calib = medn(6) %use medians +exp(medn) +nEnv +help find +find(mstacked(:, 5)>kc_calib3-0.01) && find(mstacked(:, 5)P_calib3-0.01) && find(mstacked(:, 6)kc_calib3-0.01) +[i, x] = find(mstacked(:, 5)>kc_calib3-0.01) +[i2, x2] = find(mstacked(:, 5)kc_calib3-0.01); +size(i) +size(x1) +help size +help find +help setdiff +intersect(find(mstacked(:, 5)>kc_calib3-0.01), find(mstacked(:, 5)P_calib3-0.01), find(mstacked(:, 6)kc_calib3-0.01), find(mstacked(:, 5)P_calib3-0.01), find(mstacked(:, 6)kc_calib3-0.01), find(mstacked(:, 5)0 +set(gca,'Ylim',p.support(1:2,r)) +diff(p.support(1:2,r))>0 +help diff +mai.estNames +mai.paramRanges +exp(9.78) +close all +clc +clear all +size(marray) +help isprime +ndims(marray_initial) +clc +pnamelist' +[(1:23)' pnamelist'] +(1:23)' +mat2cell((1:23)') +num2cell((1:23)') +[num2cell((1:23)') pnamelist'] +[13 1 3 4 6 7 8 9 5 23 15 16 17 18 19 20 21 22 14 10 11 12 2] +reordering = [13 1 3 4 6 7 8 9 5 23 15 16 17 18 19 20 21 22 14 10 11 12 2]; +pnamelist(reordering)' +pnamelist +size(pIXtoPlot, 1) +pIXtoPlot{ii} +pIXtoPlot{2} +explore_acsdsg2014_regen_A +size(marray_end(pIXtoPlot{ii}, :, :)) +(marray_end(pIXtoPlot{ii}, :, end)) +explore_acsdsg2014_regen_A +ss = get(0, 'screensize'); +figure +set(gcf, 'Position', [50 50 ss(3)/1.1 ss(4)/1.2]); +ss = get(0, 'screensize'); +figure +set(gcf, 'Position', [50 50 ss(3)/1.1 ss(4)/1.1]); +set(gcf, 'Position', [50 50 ss(3)/1.1 ss(4)/1.05]); +set(gcf, 'Position', [50 50 ss(3)/1.1 ss(4)/1.2]); +set(gcf, 'Position', [50 50 ss(3)/1.1 ss(4)/1.1]); +set(gcf, 'Position', [50 50 ss(3)/1.1 ss(4)/1.15]); +set(gcf, 'Position', [50 50 ss(3)/1.05 ss(4)/1.15]); +set(gcf, 'Position', [ss(3)*(1-1/1.05) ss(4)*(1-1/1.15) ss(3)/1.05 ss(4)/1.15]); +close al +close all +whos +help clf +close all +ss = get(0, 'screensize'); +figure +set(gcf, 'Position', [ss(3)*(1-1/1.05) ss(4)*(1-1/1.15) ss(3)/1.05 ss(4)/1.15]); +['/Users/vipulsinghal/Dropbox/Documents/toolbox/'... +'txtlsim_vsfork2017/mcmc_simbio/projects/'... +'proj_acs_dsg2014_regen_A/simdata_' tstouse_cell{1}] +MAI +mai +mi +mi(2) +mi(1) +size(mvarray) +marrayOrd +size(marrayOrd) +mi +mi(1) +mi(1).dosedVals +num2str(mi(1).dosedVals) +num2str(mi(1).dosedVals(1)) +dn +j +size(mi(1).dosedVals, 1) +dv +newcell +dn{1} +[dn{1} ' = ' num2str(dv(1, i))] +newcell +clear newcell +size(mi(1).dosedVals, 2) +titlz +clc +close all +edit mcmc_runsim +edit mcmc_runsim_v2.m +dosedNames1 = {'RNA utr1--deGFP'}; +dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +dosedNames2 = {'DNA p70--utr1--deGFP'}; +dosedVals2 = [0.5 2 5 20]; +doseWeights1 = sqrt(dosedVals1(end)/dosedVals1).*dosedVals1 +%% next we define the dosing strategy. +dosedNames1 = {'RNA utr1--deGFP'}; +dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +dosedNames2 = {'DNA p70--utr1--deGFP'}; +dosedVals2 = [0.5 2 5 20]; +doseWeights1 = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1 +doseWeights1/sum(doseWeights1) +dosedVals1/sum(dosedVals1) +plot(1:9, doseWeights1/sum(doseWeights1), 'b', 1:9, dosedVals1/sum(dosedVals1), 'r') +figure; plot(1:9, doseWeights1/sum(doseWeights1), 'b', 1:9, dosedVals1/sum(dosedVals1), 'r') +dosedNames1 = {'RNA utr1--deGFP'}; +dosedVals1 = [37.5 75 150 200 600 700 800 900 1000]; +dtempvec = sqrt(dosedVals1(end)*(ones(size(dosedVals1))./dosedVals1)).*dosedVals1; +doseWeights1 = dtempvec/(sum(dtempvec)); +dosedNames2 = {'DNA p70--utr1--deGFP'}; +dosedVals2 = [0.5 2 5 20]; +dtempvec = sqrt(dosedVals2(end)*(ones(size(dosedVals2))./dosedVals2)).*dosedVals2; +doseWeights2 = dtempvec/(sum(dtempvec)); +doseWeights2 +dosedVals2/sum(dosedVals2) +help isfield +s = struct('one',1,'two',2); +fields = isfield(s,{'two','pi','One',3.14}) +A = magic(3) +B = ones(3) +isequal(size(A), size(B)) +isequal(size(A), [3 size(B,2)]) +[mi,mai, ri, tstamp, projdir, di] = proj_acs_dsg2014_regen_A; +edit plotCustomSpecies2.m +%-- 4/28/18, 6:43 AM --% +ixexp4 +ixexp4{1} +ixexp4{2} +ixexp4{2}' +ixexp4{1}' +ixexp4{3} +ixexp4{3}' +dMGA +ixexp4 +la4 +la4.text +la4.text{1} +t +t/3600 +ixexp4 +dG(ixexp4{1}) +dG(:,ixexp4{1}) +plot(dG(:,ixexp4{1})) +close all +plot(dG(:,ixexp4{1})) +plot(t,dG(:,ixexp4{1})) +plot(t/3600,dG(:,ixexp4{1})) +help permute +s = struct('a', {1 2}, 'b', 3) +a(1) +s(1) +s(2) +s = struct('a', {1 2}, 'b', {3}) +s(2) +a(1) +s(1) +ymg +max(ymg) +max(ygfp) +format short g max(ygfp) +format short g; max(ygfp) +ixexp4{1} +ixexp4{1}(4) +deGFP_vs_20nM_max = max(dG(:,ixexp4{1}(4))) +di +close all; plot(di(1).timeVector, di(1).dataArray(:,1,1,1)) +close all; plot(di(1).timeVector, di(1).dataArray(:,1,1,6)) +close all; plot(di(3).timeVector, di(3).dataArray(:,1,1,6)) +close all; plot(di(3).timeVector, di(3).dataArray(:,2,1,6)) +cc = cmucolors +cc = cmucolors('list') +%-- 5/15/18, 5:27 AM --% +DG +dG +clc +size(dG) +t +t/3600 +t/3600<=1.6 +t(t/3600<=1.6) +t(t/3600<=1.61) +t(t/3600<=1.61)/3600 +t(t/3600<=1.6)/3600 +help order +order(14) +14/10^1 +ceil(1.4) +ceil(2*1.4) +ceil(2*1.4)/2 +plot_data_20170616 +Ch3_1b +help catMC +edit catMC +%-- 5/17/18, 1:34 PM --% +txtl_init +mcmc_init +da(:,1,i,1)... ++randn(length(data_info_corr1.timeVector), 1)*50 +day(:,1,i,1)... ++randn(length(data_info_corr1.timeVector), 1)*50 +clc +size(marray_corr1) +tstamp_corr +ri_corr1.nIter +mi +mi2_corr1 +ri_corr1 +mai_corr1 +data_info_corr1 +size(marray_corr1) +mtemp = mcmc_get_walkers({tstamp_corr}, {1:ri_corr1.nIter}, projdir_corr1); +size(mtemp) +mai_corr1 +edit mcmc_trajectories.m +c +c('list') +help max +[expsummst(:,1,1,1)+randn(length(tv), 1)*50, zeros(length(tv))] +size([expsummst(:,1,1,1)+randn(length(tv), 1)*50, zeros(length(tv))]) +size(max([expsummst(:,1,1,1)+randn(length(tv), 1)*50, zeros(length(tv),1)]) +size(max([expsummst(:,1,1,1)+randn(length(tv), 1)*50, zeros(length(tv),1)]))size +size(max([expsummst(:,1,1,1) + randn(length(tv), 1)*50, zeros(length(tv),1)]))*size +size(max([expsummst(:,1,1,1)+randn(length(tv), 1)*50, zeros(length(tv),1)]) +size([expsummst(:,1,1,1)+randn(length(tv), 1)*50, zeros(length(tv),1)]) +c('wild strawberry') +help legends +get(gca) +get(gca, 'YAxis') +gca.YAxis.FontSize +gca +get(gca) +set(gca, 'YAxis') +set(gca, 'YAxis', 'FontSize', 14) +clear gca +di +clc +expsummst +marrayOrd_stacked(paramid2,:) +cpol1 +log(cpol1) +log(rkcp1) +mcmc_info_corr2 +clear all +clc +ch3_f6 +close all +break +clear all +return +help axes +ch3_f6 +close all +clear all +clc +ch3_f6 +close all +ch3_f6 +close all +clc +clear all +ch3_f6 +close all +explore_corr_tetRi_w_and_wo_cov_stage2 +whos +mi2_corr1.dosedVals +ch3f6b +close all +data_info +data_info_corr1 +ch3_f6c +close all +clear all +clc +ch3f6b +explore_corr_tetRi_w_and_wo_cov_stage2 +size(marray_corr1) +size(mvarray_corr1) +ch3f6b +cloear all +clear all +clc +ch3f6b +close all +ch3f6b +mi +paramid_calib +varargin{:} +varargin{:}{1} +varargin{:} +[da, idxnotused] = simulatecurves(mi(1).emo,... +marrayOrd_stacked(paramid_calib,:), ... +length(paramid_calib),... +mi(1).dosedVals',... +data_info.timeVector,... +mi(1).measuredSpecies); +data_info.timeVector +data_info +mi(1).paramMaps(mi(1).orderingIx, 2) +mi(1).paramMaps(mi(1).orderingIx, :) +mai +pwd +[projdir_corr1 '/simdata_' tstamp_corr] +ch3_f6 +close all +ch3_f6 +close all +%-- 5/25/18, 12:27 PM --% +simbiology +edit txtl_prom_ptet.m +geneexpr +%-- 7/24/18, 7:18 PM --% +geneexpr_test_regen_mode +negautoreg +incoherent_ff_loop +%-- 7/27/18, 8:16 AM --% +path +%-- 7/28/18, 5:45 PM --% +txtl_init +mcmc_init +edit proj_protein_constgfp3i.m +edit txtl_tutorial.m +%-- 7/30/18, 12:40 PM --% +help mcmc_info +clc +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +clc +help mcmc_info +clc +help mcmc_info +edit mcmc_info_constgfp3ii.m +edit mcmc_info_constgfp3i.m +{'kfdG' +'krdG' +'kfdT' +'krdT' +'kfdimTet' +'krdimTet' +'kfseqTet' +'krseqTet' +'kcp' +'pol'} +'pol'}' +{'kfdG' +'krdG' +'kfdT' +'krdT' +'kfdimTet' +'krdimTet' +'kfseqTet' +'krseqTet' +'kcp' +'pol'}' +aaa = [{'kfdG'} {'krdG'} {'kfdT'} {'krdT'} {'kfdimTet'} {'krdimTet'} {'kfseqTet'} {'krseqTet'} {'kcp'} {'pol'}] +aaa([2 4 6 8 9 10]) +proj_mcmc_tutorial +close all +clear all +clc +%-- 8/2/18, 6:16 PM --% +txtl_init +mcmc_init +proj_mcmc_tutorial +edit proj_protein_constgfp3i.m +proj_protein_constgfp3i +size(logP) +help shiftdim +shiftdim(logP, 1) +logPfuns +logPfuns{1} +logPfuns{2} +shiftdim(logP, 1) +all(all(isfinite(logP(:,:,1)))) +p.ThinChain +logrand(fix+1,wix)>proposedlogP(fix)-curlogP(fix,wix) +~isreal(proposedlogP(fix)) +isnan(proposedlogP(fix)) +row +logP(:,:,row) +models(:,:,row) +proposedlogP(fix) +help logrand +logrand +proposedm(:,wix) +logPfuns{fix}(proposedm(:,wix)) +proj_protein_constgfp3i +mcmc_info_constgfp3i +proj_protein_constgfp3i +proj_mcmc_tutorial +close all +clear all +clcl +clc +proj_mcmc_tutorial +proj_mcmc_tutorial_II +mi +mi.orderingIx +mi.orderingIx2 +proj_mcmc_tutorial_II +clear all +close all +clc +proj_mcmc_tutorial_II +close all +proj_mcmc_tutorial_III +mi +mi(1) +mi1 +mi1(1) +mi1(2) +mi = mi1 +proj_mcmc_tutorial_III +close +close all +clear all +clc +proj_mcmc_tutorial_III +projdir +proj_mcmc_tutorial_III +%-- 8/3/18, 3:16 PM --% +txtl_init +mcmc_init +proj_mcmc_tutorial_III +clc +close all +clear all +clc +proj_mcmc_tutorial_III +%-- 8/6/18, 6:22 PM --% +ls +test015_estimation +st +test015_estimation +help dbstack +test015_estimation +%-- 8/9/18, 10:47 PM --% +test015_Corr_withoutCSPfixing +close all +clear all +clc +test015_Corr_withoutCSPfixing +close all +alpha +cc +mstacked(cc, :) +test_Corr_alt +mstacked +size(mstacked) +hist(mstacked(:, 1)) +figure; hist(mstacked(:, 1)) +help hist +figure; hist(mstacked(:, 1), 20) +figure; hist(mstacked(:, 2), 20) +figure; hist(mstacked(:, 3), 20) +test_Corr_alt +randperm(100, 1) +test_Corr_alt +rng(42) +medians_converged_calib = mstacked(randperm(size(mstacked, 1), 1), : ) +rng(42) +randperm(size(mstacked, 1), 1) +rng(42) +randperm(size(mstacked, 1), 1) +test_Corr_alt +size(medians_converged_calib = mstacked(randperm(size(mstacked, 500), 1), : )) +size(mstacked(randperm(size(mstacked, 500), 1), : )) +size(mstacked(randperm(size(mstacked, 1), 500), : )) +test_Corr_alt +medians_converged_calib2 +exp([1.1813 0.1407]) +exp([1.2737 0.2829]) +valid_indices +test_Corr_alt +whos +RR11 +RR12 +normreduced_cspfix +alpha_cspfix +normorig +help min +test015_estimation_v1 +['save(''t015_calib_' datestring '_' num2str(i) ''');'] +calib_point +size(minit) +clc +corr_SD +corr_SD2 = corrSD(round(end/2):end) +corr_SD2 = corr_SD(round(end/2):end)corr_SD2 = corr_SD(round(end/2):end) +corr_SD2 = corr_SD(round(end/2):end) +clc +test015_estimation_v1 +help round +size(mcat(:,:,round(end/1.5):end)) +size(mcat(:,:,:)) +corr_SD(round(end/2):end) +clc +help format +Htrans'*S +Htrans(:,1)' +Htrans(:,1)'*S +null(S') +Htrans +Sr*Srinv +Ms +Ms.' +x(1) +close all +help deal +[A, B, C, D, E, F, G, J, K, L, X]' +Sr +%-- 8/20/18, 6:31 PM --% +txtl_init +mcmc_init +edit proj_mcmc_tutorial_II.m +[pwd '/mcmc_simbio/projects/proj_mcmc_tutorial_II/simdata_20180802_221756/full_variable_set_20180802_221756.mat'] +whos +specificproj +tstamp +mi +di = data_info +close al +close all +edit mcmc_info +test_Corr +meanvals_corrstep2(:, msid, i, 1) +correction_data(1:13,msid, i, envrefID) +correction_data(1:13,msid, i, envrefID)*1000 +test_Corr +%-- 10/20/18, 3:28 PM --% +txtl_init +mcmc_init +dir('/mcmc_simbio) +dir('/mcmc_simbio') +dir /mcmc_simbio +ls +dir mcmc_simbio/ +dir mcmc_simbio/exp_data/ +edit data_dsg2014.m +dir mcmc_simbio/src/ +edit data_artificial_v2.m +dir mcmc_simbio/ +dir mcmc_simbio/models_and_supporting_files/ +edit mcmc_info_constgfp3ii +proj_tierra2018_calibration +edit data_info.m +proj_tierra2018_calibration +help permute +shiftdim +help shiftdim +proj_tierra2018_calibration +data_info +di +di(3) +proj_tierra2018_calibration +di(3) +proj_tierra2018_calibration +help deal +proj_tierra2018_calibration +di +di(3) +di(3).dataArray +proj_tierra2018_calibration +edit data_artificial_v2.m +currdi.measuredNames{msnum}{1:end} +currdi.measuredNames +currdi.measuredNames{msnum} +class(currdi.measuredNames{msnum}) +proj_tierra2018_calibration +%-- 11/3/18, 12:58 PM --% +txtl_init +mcmc_init +close all +projdir +proj_tierra2018_calibration +close all +clear all +clc +proj_tierra2018_calibration +ls +who +mi +size(marray) +close all +%-- 11/4/18, 10:28 AM --% +txtl_init +mcmc_init +proj_tierra2018_calibration +%-- 11/4/18, 1:20 PM --% +txtl_init +mcmc_init +edit mcmc_runsim_v2.m +proj_tierra2018_calibration +%-- 12/13/18, 5:38 PM --% +txtl_init +geneexpr +%-- 12/13/18, 5:46 PM --% +appdesigner +license +license('inuse') +vet +ver +%-- 12/16/18, 5:47 AM --% +txtl_init +geneexpr +%-- 12/17/18, 9:57 AM --% +appdesigner +%-- 1/18/19, 10:27 PM --% +MERFISHAnalysisPath +merfish_startup +pwd +ls +edit startup +dir startup +edit('startup/merfish_startup.m') +ls +pwd '/startup/merfish_startup' +pwd /startup/merfish_startup +pwd /startup/merfish_startup.m +addpath([pwd '/startup/']) +merfish_startup +restoredefaultpath +addpath('/Users/vipulsinghal/Dropbox/Documents/MATLAB'); % MATLAB directory +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/bioinformatics/MERFISH/MERFISH_analysis/startup'); % Location of any startup script +pwd +library_design_example +%-- 1/23/19, 7:30 AM --% +library_design_example +ver +help fastaread +library_design_example +rRNAtRNAPath +restoredefaultpath +path +library_design_example +restoredefaultpath +library_design_example +rRNAtRNAPath +fastaread(rRNAtRNAPath) +strread(filename,'%s','delimiter','\n'); +library_design_example +fastaread(rRNAtRNAPath) +library_design_example +LoadCodebook(codebookPath) +library_design_example +LoadCodebook(codebookPath) +nargin +exist(codebookPath) +LoadCodebook(codebookPath) +library_design_example +delete(p) +gcp(p) +clear all +clc +close all +restoredefaultpath +library_design_example +beep() +numProbesPerGene +finalIds +~exist(oligosPath) +tRegion +library_design_example +finalIds +readouts(barcodes(i,:)==1) +readouts(barcodes(i,:)==1)(1) +readouts(barcodes(i,:)==1){1} +aaa = readouts(barcodes(i,:)==1) +aaa +aaa(1) +possibleReadouts +possibleReadouts(1) +targetRegions +targetRegions(1) +targetRegions(2) +targetRegions(3) +targetRegions(4) +targetRegions(5) +finalTargetRegions +ismember({targetRegions.id}, finalIds) +finalIds +targetRegions.id +{targetRegions.id} +finalIds +targetRegions.id +trRegionsPath +{targetRegions.id} +finalIds +finalIds(11:end) +{targetRegions.id} +finalIds(11:end)' +{targetRegions.id}' +whos +ids +TargetRegions.Load(trRegionsPath) +ismember({targetRegions.id}, finalIds) +{targetRegions.id}' +finalIds(11:end)' +TRDesigner +library_design_example +obj.transcriptome +obj.transcriptome.GetInternalInds +parameters +obj.transcriptome.GetInternalInds('parameters', parameters) +library_design_example +idsByName +idsByName{1} +idsByName{1}' +idsByName{2}' +idsByName{3}' +idsByName{4}' +names +i +idsByName{i} +transcriptome.Slice('geneID', idsByName{i}) +localTranscriptome = transcriptome.Slice('geneID', idsByName{i} +localTranscriptome = transcriptome.Slice('geneID', idsByName{i}) +obj.GetInternalInds('geneID', parameters.geneID) +inds +obj.ids +obj.ids(inds) +obj.geneNames(inds) +obj.geneNames +obj.intSequences +obj.intSequences(inds) +obj.intSequences(inds){1} +obj.intSequences{inds} +obj.intSequences(inds) +obj.intSequences +obj.abundance(inds) +transcriptome +localTranscriptome = transcriptome.Slice('geneID', idsByName{i}) +obj.ids(inds) +obj.ids(inds)' +isoSpecificityTables +SetParallel(obj, parameters.parallel) +nargin +class(nargin) +class(targetSequences) +targetSequences.intSequences +targetSequences.intSequences{1} +p +ppool +obj +set(obj) +properties(obj) +obj.data +obj.hashBase +library_design_example +isoSpecificityTables +isoSpecificityTables(1) +isoSpecificityTables(2) +isoSpecificityTables(2).data +transcriptome.data +transcriptome.numGenes +transcriptome +transcriptome.geneNames +transcriptome.ids +transcriptome.GetAbundanceByID(ids) +transcriptome.GetAbundanceByID(transcriptome.ids) +obj.id2Ind +library_design_example +help writetable +table +help table +finalIds +targetRegions.id +{targetRegions.id} +slicedTranscriptome +library_design_example +GC(1, 1) +GC{1, 1} +penalties(1, 1, 1) +penalties{1, 1, 1} +library_design_example +targetRegions = trDesigner.DesignTargetRegions(... +'regionLength', 25, ... +'GC', [20 75]/100, ... +'Tm', [58 80], ... +'isoSpecificity', [0.4 1], ... +'specificity', [0.4 1], ... +'OTTables', {'rRNA', [0, 0]}); +% NOTE: The ranges above were determined empirically to strike +% the proper balance between stringency (narrow ranges) and +% sufficient probe numbers to target the desired genes. We +% recommend scanning many different ranges to identify the +% optimal for each application. +display(['... completed: ' datestr(now)]); +% Save target regions +targetRegions.Save(trRegionsPath); +library_design_example +oligosPath +library_design_example +tr_ids = {targetRegions.ids}'; +tr_ids = {targetRegions.id}'; +tr_ids(1:10) +tr_ids(1:30) +length(tr_ids) +length(finalIds) +length(goodIDs) +length(ids) +length({targetRegions.id}) +find(ismember({targetRegions.id}, finalIds)) +finalIds +library_design_example +%-- 1/23/19, 6:16 PM --% +library_design_example +length({targetRegions.id}) +transcriptome +finalIds +finalIds' +{targetRegions.geneName} +{targetRegions.geneName}' +[{targetRegions.geneName}' {targetRegions.id}'] +finalIds +[{codebook.name}' {codebook.id}' ] +library_design_example +%-- 1/23/19, 6:52 PM --% +library_design_example +path +%-- 1/24/19, 9:56 AM --% +library_design_example +rRNAtRNA +rRNAtRNA(1) +rRNAtRNA(400) +rRNAtRNA(401) +rRNAtRNA(401isoSpecificityTablePath) +isoSpecificityTablePath +goodIDs +transcriptome.ids' +transcriptome.name +transcriptome.names +transcriptome.Names +targetRegions +targetRegions.id +library_design_example +whos +clear all +close all +clc +txtl_som +txtl_sim +txtl_init +ls +pwd +ls +dir mcmc_simbio/ +dir mcmc_simbio/projects/ +mcmc_init +edit proj_VNPRL.m +edit proj_VNPRL_mrna.m +proj_VNPRL +mobj +edit sbiomodel +clc +mcmc_info_vnprl2011_mrna(mobj) +clc +mcmc_info_vnprl2011_mrna(mobj) +ans +aa = ans +aa +aa(1) +aa.runsim_info +aa.model_info +aa.model_info.circuitInfo +%-- 1/30/19, 8:50 PM --% +txtl_init +mcmc_init +edit proj_acs_dsg2014_regen_A.m +edit gwmcmc_vse.m +edit gen_residuals_v2.m +edit mcmc_runsim_v2.m +edit gwmcmc_vse_origjan30_19.m +a = false +a +-1/a +a = true +-1/a +lhsdesign(10, 4) +scatter(lhsdesign(10, 4)) +help scatter +lhsdesign(10, 2) +lll = lhsdesign(10, 2) +scatter(lll(:,1), lll(:,2)) +help scatter +ll = lhsdesign(10, 3) +ll = lhsdesign(100,3); scatter3(ll(:,1), ll(:,2), ll((L,3)) +ll = lhsdesign(100,3); scatter3(ll(:,1), ll(:,2), ll((:,3)) +ll = lhsdesign(100,3); scatter3(ll(:,1), ll(:,2), ll(:,3)) +ll = lhsdesign(10,3); scatter3(ll(:,1), ll(:,2), ll(:,3)) +ll = lhsdesign(10,2); scatter(ll(:,1), ll(:,2)) +help lhsdesign +figure +x = lhsdesign(100,2); +subplot(2,2,1); plot(x(:,1), x(:,2), 'o'); +subplot(2,2,2); hist(x(:,2)); +subplot(2,2,3); hist(x(:,1)); +figure; x=rand(100,2) +subplot(2,2,1); plot(x(:,1), x(:,2), 'o'); +subplot(2,2,2); hist(x(:,2)); +subplot(2,2,3); hist(x(:,1)); +%-- 1/31/19, 7:07 PM --% +txtl_init +mcmc_init +path +clc +%-- 1/31/19, 8:10 PM --% +txtl_init +mcmc_init +edit proj_acs_dsg2014_regen_A.m +edit gwmcmc_vse.m +-Inf >-Inf +-Inf >-Inf-1 +log(rand(3,6)) +eps +figure; hist(log(rand(1, 1000))) +figure; hist(log(rand(1, 1000000000))) +figure; hist(log(rand(1, 10000000))) +figure; hist(log(rand(1, 10000000)), 100) +figure; hist(log(rand(1, 100000000)), 100) +edit mcmc_runsim_v2.m +edit proj_mcmc_tutorial_II.m +proj_mcmc_tutorial_II +logP(2,:,1) +format short g; logP(2,:,1) +format short g; logP(2,1,1) +format short +format short g; logP(2,1,1) +format short g; logP(2,1,1)/2e6 +edit gen_residuals_v2.m +logPfuns{2}(minit(:,1)) +res +stdev +logresvec(res, stdev) +stdev = 2e6 +logresvec(res, stdev) +logresvec +stdev = 2e6 +res +res/stdev +logresvec +(res/stdev).^2 +(res/stdev).^2-log(sqrt(2*pi)).*stdev +-log(sqrt(2*pi)).*stdev +stdev = 10 +(res/stdev).^2-log(sqrt(2*pi)).*stdev +stdev = 1 +(res/stdev).^2-log(sqrt(2*pi)).*stdev +-log(sqrt(2*pi)).*stdev +(res/stdev).^2 +stdev = 10000 +%-- 2/1/19, 3:56 PM --% +txtl_init +mcmc_init +tstamp +data_info +ri +projdir +[pwd '/mcmc_simbio/projects/proj_mcmc_tutorial_II'] +prevtstamp = '20190131_181526' +ri.nW +size(marray_cut, 2) +size(marray_cut) +size(marray_cut,3) +ceil(size(marray_cut,3)/2) +linspace(1, size(marray_cut,3)) +linspace(1, size(marray_cut,3), 4) +linspace(1, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2))) +ceil(linspace(1, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) +ceil(linspace(1, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2))+1)) +(linspace(1, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2))+1)) +ceil(linspace(1, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2))+1)) +ceil(linspace(1, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) +ceil(linspace(ceil(size(marray_cut,3))/2, size(marray_cut,3), ceil(ri.nW/size(marray_cut, 2)))) +pID = 1:length(mai.estNames); +marray_cut = mcmc_cut(marray, pID, flipud((mai.paramRanges)')); +marray_cut +minit +hist(minit91,:)) +hist(minit(1,:)) +figure; hist(minit(1,:)) +figure; hist(minit(2,:)) +pID +(mai.paramRanges) +(mai.paramRanges)' +size(marray) +flipud((mai.paramRanges)') +%-- 2/2/19, 1:11 PM --% +txtl_init; mcmc_init; +edit proj_acs +edit proj_acs_dsg2014_regen_A.m +edit proj_mcmc_tutorial_III.m +edit proj_mcmc_tutorial_II.m +size(marray) +size(marray2) +size(marray1) +help cat +help load +load([pwd '/mcmc_simbio/projects/proj_mcmc_tutorial_II/'... +'simdata_' tstamptouse '/full_variable_set_' tstamptouse], 'mi') +load([pwd '/mcmc_simbio/projects/proj_mcmc_tutorial_III/'... +'simdata_' tstamptouse '/full_variable_set_' tstamptouse], 'mi') +mi +clc +clear all +txtl_init +mcmc_init +di +sum(sum(squeeze(di(1).dataArray))) +sum(sum(sum(squeeze(di(1).dataArray)))) +sum(sum(sum(squeeze(di(1).dataArray))))+sum(sum(sum(squeeze(di(2).dataArray)))) +sum(sum(sum(squeeze(di(1).dataArray)))) +sum(sum(sum(squeeze(di(2).dataArray)))) +di(2) +di(3) +sum(sum(sum(squeeze(di(3).dataArray)))) +sum(sum(sum(squeeze(di(1).dataArray)))) +help setparam +%-- 2/3/19, 3:38 PM --% +txtl_init +mcmc_init +edit proj_VNPRL_mrna.m +pwd +activeNames1 = {... +'TXTL_RNAdeg_Kd' 2000 [100 10000] +'TXTL_RNAdeg_F' 0.02 [0.01 100] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] +'RNase' 100 [10 1000]}; +activeNames2 = {... +'TX_elong_glob' 10.5 [0.5 100] +'AGTPdeg_time' 7200 [1800 42000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] +'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 100] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] +'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] +'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] +'TXTL_RNAdeg_Kd' 2000 [100 10000] +'TXTL_RNAdeg_F' 0.01 [0.1 1000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] +'RNAP' 100 [5 500] +'RNase' 100 [10 1000] +'TL_elong_glob' 20 [4 200] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] +'TL_AA_Kd' 100000 [10 1e8] +'TL_AA_F' 0.001 [1e-5 20] +'TL_AGTP_Kd' 100000 [1e2 1e8] +'TL_AGTP_F' 1e-5 [1e-7 1] +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] +'Ribo' 30 [5 1000]}; +estParamsIX = [1 2 5:17 19:26 ]'; +estParams = activeNames2(estParamsIX,1); +estParams +proj_mcmc_tutorial_III +edit proj_mcmc_tutorial_III +help isvector +num2str(1.6505e+04) +num2str(1.6505e+04/10000) +regexp(num2str(1.6505e+04/10000), '.') +regexp(num2str(1.6505e+04/10000), '\.') +regexp(num2str(1.6505e+04), '\.') +tsig = 1.6505e+04 +tladder = tsig*[0.1 0.001, 0.00001] +regexp(num2str(tladder), '\.') +num2str(tladder) +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 100, 'nPoints', 100*10, 'thinning', 2, 'nIter', 2, 'parallel', false, 'poolsize', 2, 'temperature_ladder', false) +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 100, 'nPoints', 100*10, 'thinning', 2, 'nIter', 2, 'parallel', false, 'poolsize', 2, 'temperatureLadder', false) +mexmex -setup -v +mexext -setup -v +mex -setup -v +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 100, 'nPoints', 100*10, 'thinning', 2, 'nIter', 2, 'parallel', false, 'poolsize', 2, 'temperatureLadder', false) +whos +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 100, 'nPoints', 100*10, 'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 100, 'nPoints', 100*10, 'thinning', 1, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +specificproj +edit project_init +help addOptional +tstamp_appended +tstamp_appended = 'asdfad' +project_init('proj', tstamp_appended) +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 60, 'nPoints', 100*2, 'thinning', 1, 'nIter', 1, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 50, 'nPoints', 100*2, 'thinning', 1, 'nIter', 1, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +specificproj +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 50, 'nPoints', 100*2, 'thinning', 1, 'nIter', 1, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +proj_acs_dsg2014_regen_A +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 50, 'nPoints', 100*2, 'thinning', 1, 'nIter', 1, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +data_info +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 50, 'nPoints', 100*2, 'thinning', 1, 'nIter', 1, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +tstamptouse = tstamp_appended; +marray = mcmc_get_walkers({tstamptouse}, {1:ri.nIter}, projdir); +mcmc_plot(marray([1 2 4], :,:), mai.estNames([1 2 4]),... +'savematlabfig', false, 'savejpeg', true,... +'projdir', projdir, 'tstamp', tstamptouse); +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 50, 'nPoints', 100*2, 'thinning', 1, 'nIter', 1, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +prevtstamp +percentLadder +ll +specificprojdir +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 50, 'nPoints', 100*2, 'thinning', 1, 'nIter', 1, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +4*3200*100 +16*3200 +copy paste into the terminal if using matlab with no display. +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +proj_acs_dsg2014_regen_A('stepSize', 1.3, 'nW', 1000, 'nPoints', 100*1000,... +'thinning', 2, 'nIter', 2, 'parallel', true, 'poolsize', 4, 'temperatureLadder', true) +dbstack +%-- 2/4/19, 12:30 AM --% +txtl_init +mcmc_init +di = data_dsg2014_full; +di +di(1) +di(3) +sum(sum(sum(di(3).dataArray))) +sum(sum(sum(di(1).dataArray))) +sum(sum(sum(di(1).dataArray)))/sum(sum(sum(di(3).dataArray))) +sum(sum(sum(di(3).dataArray)))/sum(sum(sum(di(1).dataArray))) +0.1/sum(sum(sum(di(3).dataArray)))/sum(sum(sum(di(1).dataArray))) +0.1/(sum(sum(sum(di(3).dataArray)))/sum(sum(sum(di(1).dataArray)))) +sum(sum(sum(di(1).dataArray)))+sum(sum(sum(di(3).dataArray))) +(sum(sum(sum(di(1).dataArray)))+sum(sum(sum(di(3).dataArray))))/100 +(0.1*sum(sum(sum(di(1).dataArray)))+sum(sum(sum(di(3).dataArray)))) +(0.1*sum(sum(sum(di(1).dataArray)))+sum(sum(sum(di(3).dataArray))))/10 +(0.1*sum(sum(sum(di(1).dataArray)))+sum(sum(sum(di(3).dataArray))))/1000 +(0.1*sum(sum(sum(di(1).dataArray)))+sum(sum(sum(di(3).dataArray))))/100000 +(0.1*sum(sum(sum(di(1).dataArray)))+sum(sum(sum(di(3).dataArray))))/1000 +%-- 2/4/19, 2:39 PM --% +txtl_init;mcmc_init +size(marray) +clear all +load([projdir... +'simdata_' tstamptouse1 '/full_variable_set_' tstamptouse1]) +tstamptouse1 = '10pct_20190203_173126'; +tstamptouse2 = 'pt1pct_20190203_173126'; +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_A']; +load([projdir... +'simdata_' tstamptouse1 '/full_variable_set_' tstamptouse1]) +whos +da +estParamIx +mi +mai +mcmc_info.model_info +ri +cfname +specificproj +who +loglike +mv +sigg +mai.estNames +parnames +size(mfinal) +mai.paramRanges(1:10,:) +linspace(1, 2, 4) +linspace(2,1, 4) +help isbool +help isboolean +help boolean +help isboolean +help islogical +help isnumeric +help isvector +myfun = @(x) isnumeric(x) && isvector(x) +myfun(linspace(2, 1, 4)) +close all +5/4 +round(5/4) +round(57/4) +round(7/4) +sprintf('step size ladder was: %d', [1 2 3]) +sprintf(['step size ladder was:' num2str([1 2 3])]) +sprintf(['step size ladder was: ' num2str([1 2 3])]) +linspace(2, 1, 5) +linspace(2, 1, 5)*1.2 +linspace(3, 1, 5)*1.2 +proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 200, 'nPoints', ... +200*20, 'thinning', 1, 'nIter', 4, 'parallel', true, ... +'poolsize', 3, 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +'stepLadder', linspace(2, 1, 2)) +proj_acs_dsg2014_regen_A('stepSize', 1.2, 'nW', 100, 'nPoints', ... +100*5, 'thinning', 1, 'nIter', 4, 'parallel', true, ... +'poolsize', 4, 'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +'stepLadder', linspace(2, 1, 2)) +proj_acs_dsg2014_regen_A('stepSize', 1.2,... +'nW', 50,... +'nPoints', 10*3,... +'thinning', 1,... +'nIter', 4,... +'parallel', true, ... +'poolsize', 4,... +'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +'stepLadder', linspace(2, 1, 2)) +prevtstamp +proj_acs_dsg2014_regen_A +>> proj_acs_dsg2014_regen_A('stepSize', 1.2,... +'nW', 50,... +'nPoints', 10*3,... +'thinning', 1,... +'nIter', 4,... +'parallel', true, ... +'poolsize', 4,... +'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +proj_acs_dsg2014_regen_A('stepSize', 1.2,... +'nW', 50,... +'nPoints', 10*3,... +'thinning', 1,... +'nIter', 4,... +'parallel', true, ... +'poolsize', 4,... +'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +'stepLadder', linspace(2, 1, 2)) +SS.mcmc_info.runsim_info.nIter +proj_acs_dsg2014_regen_A('stepSize', 1.2,... +'nW', 50,... +'nPoints', 50*6,... +'thinning', 2,... +'nIter', 4,... +'parallel', true, ... +'poolsize', 4,... +'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +'stepLadder', linspace(2, 1, 2)) +2>=1 +proj_acs_dsg2014_regen_A('stepSize', 1.2,... +'nW', 50,... +'nPoints', 50*3,... +'thinning', 1,... +'nIter', 4,... +'parallel', true, ... +'poolsize', 4,... +'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +'stepLadder', linspace(2, 1, 2)) +edit mcmc_info_dsg2014_regen_B.m +linspace(2, 1, 5) +linspace(2, 1, 4) +activeNames2 = {... +'TX_elong_glob' 10.5 [0.5 100] +'AGTPdeg_time' 7200 [1800 42000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] +'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 100] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] +'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] +'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] +'TXTL_RNAdeg_Kd' 2000 [100 10000] +'TXTL_RNAdeg_F' 0.01 [0.1 1000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] +'RNAP' 100 [5 500] +'RNase' 100 [10 1000] +'TL_elong_glob' 20 [4 200] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] +'TL_AA_Kd' 100000 [10 1e8] +'TL_AA_F' 0.001 [1e-5 20] +'TL_AGTP_Kd' 100000 [1e2 1e8] +'TL_AGTP_F' 1e-5 [1e-7 1] +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] +'Ribo' 30 [5 1000]}; +estParamsIX = [1 2 5:17 19:26 ]'; +estParams = activeNames2(estParamsIX,1) +activeNames2 = {... +'TX_elong_glob' 10.5 [0.5 100] %1 +'AGTPdeg_time' 7200 [1800 42000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 100] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] %7 +'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] +'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] %10 +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] +'TXTL_RNAdeg_Kd' 2000 [100 10000] +'TXTL_RNAdeg_F' 0.01 [0.1 1000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] %14 +'RNAP' 100 [5 500] +'RNase' 100 [10 1000] +'TL_elong_glob' 20 [4 200] %17 +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] %20 +'TL_AA_Kd' 100000 [10 1e8] +'TL_AA_F' 0.001 [1e-5 20] +'TL_AGTP_Kd' 100000 [1e2 1e8] %23 +'TL_AGTP_F' 1e-5 [1e-7 1] +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] +'Ribo' 30 [5 1000]} +activeNames2 = {... +'TX_elong_glob' 10.5 [0.5 100] %1 +'AGTPdeg_time' 7200 [1800 42000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 100] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] %7 +'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] +'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] %10 +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] +'TXTL_RNAdeg_Kd' 2000 [100 10000] +'TXTL_RNAdeg_F' 0.01 [0.1 1000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] %14 +'RNAP' 100 [5 500] +'RNase' 100 [10 1000] +'TL_elong_glob' 20 [4 200] %17 +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] %20 +'TL_AA_Kd' 100000 [10 1e8] +'TL_AA_F' 0.001 [1e-5 20] +'TL_AGTP_Kd' 100000 [1e2 1e8] %23 +'TL_AGTP_F' 1e-5 [1e-7 1] +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] +'Ribo' 30 [5 1000]}; +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 5 7 8 10 12 14 15 16 17 18 19 21 23 25 26]'; +estParams = activeNames2(estParamsIX,1) +17+7 +length(activeNames2) +setdiff(1:26, estParamsIX) +activeNames2(setdiff(1:26, estParamsIX)) +activeNames2(setdiff(1:26, estParamsIX))' +estParamsIX = [1 2 5 7 8 10 12 14 15 16 17 19 21 23 25 26] +activeNames2(setdiff(1:26, estParamsIX))' +activeNames2(setdiff(1:26, estParamsIX),:)' +activeNames2(setdiff(1:26, estParamsIX),:) +whos +estParamIx +clear all +estParamsIX = [1 2 5 7 8 10 12 14 15 16 17 19 21 23 25 26]'; +% Skipping the following: +% activeNames2(setdiff(1:26, estParamsIX),:) +% +% ans = +% +% 10×3 cell array +% +% {'AGTPdeg_rate' } {[2.0000e-04]} {1×2 double} +% {'AGTPreg_ON' } {[ 0.0200]} {1×2 double} +% {'TXTL_P70_RNAPbo…'} {[ 20]} {1×2 double} +% {'TXTL_NTP_RNAP_1_F'} {[1.0000e-04]} {1×2 double} +% {'TXTL_NTP_RNAP_2_F'} {[1.0000e-05]} {1×2 double} +% {'TXTL_RNAdeg_F' } {[ 0.0100]} {1×2 double} +% {'TXTL_PROT_deGFP…'} {[ 0.0023]} {1×2 double} +% {'TXTL_UTR_UTR1_F' } {[ 0.2000]} {1×2 double} +% {'TL_AA_F' } {[1.0000e-03]} {1×2 double} +% {'TL_AGTP_F' } {[1.0000e-05]} {1×2 double} +estParams = activeNames2(estParamsIX,1); +fixedParamsIX = setdiff((1:26)', estParamsIX); +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = zeros(length(activeNames2), 1); +activeNames2 = {... +'TX_elong_glob' 10.5 [0.5 100] %1 +'AGTPdeg_time' 7200 [1800 42000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 100] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] %7 +'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] +'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] %10 +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] +'TXTL_RNAdeg_Kd' 2000 [100 10000] +'TXTL_RNAdeg_F' 0.01 [0.1 1000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] %14 +'RNAP' 100 [5 500] +'RNase' 100 [10 1000] +'TL_elong_glob' 20 [4 200] %17 +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] %20 +'TL_AA_Kd' 100000 [10 1e8] +'TL_AA_F' 0.001 [1e-5 20] +'TL_AGTP_Kd' 100000 [1e2 1e8] %23 +'TL_AGTP_F' 1e-5 [1e-7 1] +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] +'Ribo' 30 [5 1000]}; +estParamsIX = [1 2 5 7 8 10 12 14 15 16 17 19 21 23 25 26]'; +% Skipping the following: +% activeNames2(setdiff(1:26, estParamsIX),:) +% +% ans = +% +% 10×3 cell array +% +% {'AGTPdeg_rate' } {[2.0000e-04]} {1×2 double} +% {'AGTPreg_ON' } {[ 0.0200]} {1×2 double} +% {'TXTL_P70_RNAPbo…'} {[ 20]} {1×2 double} +% {'TXTL_NTP_RNAP_1_F'} {[1.0000e-04]} {1×2 double} +% {'TXTL_NTP_RNAP_2_F'} {[1.0000e-05]} {1×2 double} +% {'TXTL_RNAdeg_F' } {[ 0.0100]} {1×2 double} +% {'TXTL_PROT_deGFP…'} {[ 0.0023]} {1×2 double} +% {'TXTL_UTR_UTR1_F' } {[ 0.2000]} {1×2 double} +% {'TL_AA_F' } {[1.0000e-03]} {1×2 double} +% {'TL_AGTP_F' } {[1.0000e-05]} {1×2 double} +estParams = activeNames2(estParamsIX,1); +fixedParamsIX = setdiff((1:26)', estParamsIX); +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = zeros(length(activeNames2), 1); % log transformed. +paramMap1 = [12 13 14 16]'; +paramMap2 = (1:length(masterVector))'; +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames2(estParamsIX,3))); +activeNames2(paramMap1, :) +activeNames2(paramMap2, :) +proj_acs_dsg2014_regen_C('stepSize', 1.2,... +'nW', 50,... +'nPoints', 10*50,... +'thinning', 1,... +'nIter', 4,... +'parallel', true, ... +'poolsize', 4,... +'temperatureLadder', [0.5, 0.005 0.05 0.0005],... +'stepLadder', linspace(2, 1, 2)) +edit eacorr +%-- 2/5/19, 1:42 PM --% +10880*2 +[0.5, 0.005, 0.05 0.0005, 0.005, 0.00005] * 21760 +format short g +[0.5, 0.005, 0.05 0.0005, 0.005, 0.00005] * 21760 +([0.5, 0.005, 0.05 0.0005, 0.005, 0.00005] * 21760)' +edit project_init +txtl_init; mcmc_init +edit project_init +size(marray) +marray1 = mcmc_get_walkers({ts11}, {1:10}, projdir); +size(marray) +marray1 = mcmc_get_walkers({ts11, ts12}, {1:10, 1:10}, projdir); +size(marray) +marray1 = mcmc_get_walkers({ts11, ts12}, {1:10, 1:10}, projdir); +convertedsID +convertedsID{1} +whos +marray1 = mcmc_get_walkers({ts11, ts12}, {1:10, 1:10}, projdir); +tstamp{i} +simID{i} +marray1 = mcmc_get_walkers({ts11, ts12}, {1:10, 1:10}, projdir); +size(marray1) +clc +whos +data_info +mi(2) +mi(1) +mi(1).dosedVals +mat2cell(mi(1).dosedVals) +help mat2cell +mi(1).dosedVals +length(mi(1).dosedVals) +mat2cell(mi(1).dosedVals, 1, 9) +help arrayfun +A = arrayfun(@num2str, mi(1).doseVals) +A = arrayfun(@num2str, mi(1).dosedVals) +A = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false) +mi(2) +clc +close +close all +size(marray2) +close all +size(mvarray) +help quantile +%-- 2/6/19, 5:49 AM --% +txtl_init +mcmc_init +isvector(1) +isvector(magic(2)) +size(marray) +close +close all +di = data_dsg2014_full +di(3) +%-- 2/7/19, 2:35 PM --% +userpath +%-- 2/7/19, 4:23 PM --% +path +mobj = model_dsg2014_regen +mobj +mobj.reactions +di +data_info +clear all +log([30 100 18000 42000]) +pwd +projdir +cell2mat(aaa(:,1)) +cell2mat(aaa(:,1))' +di +mi(1) +mi(1).dataToMapTo +mi(1).measuredSpecies +mi(1).measuredSpecies{:} +mi(1).emo +get(mi(1).emo) +get(mi(1).emo, 'ValueInfo') +vi = get(mi(1).emo, 'ValueInfo') +vi(1) +di((mi(1).dataToMapTo)).timeVector +mi(1) +[da, idxnotused] = simulatecurves(em,m, p.nSimCurves, dose, tv, ms); +sd = simulate(em, [exp(m(end - kk+1,:)'); dose(i,:)']); +[exp(m(end - kk+1,:)'); dose(i,:)'] +em +vi = get(mi(1).emo, 'ValueInfo') +vi = get(em, 'ValueInfo') +vi +vi(:) +vi(1) +mi(1) +mi(1).paramMaps +mai +mai.estNames +mai.estNames(mi(1).paramMaps) +mai +mai.fixedParams +mi(2).namesUnord +mi(2).namesUnord(mi(1).paramMaps) +size(aaa) +activeNames2 = {... +'TX_elong_glob' 10.5 [0.5 100] +'AGTPdeg_time' 7200 [1800 42000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] +'TXTL_P70_RNAPbound_Kd' 20 [10 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 100] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 10] +'TXTL_NTP_RNAP_1_Kd' 100000 [10 1e8] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-7 10] +'TXTL_NTP_RNAP_2_Kd' 1e6 [10 1e8] +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-7 10] +'TXTL_RNAdeg_Kd' 2000 [100 10000] +'TXTL_RNAdeg_F' 0.01 [0.1 1000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] +'RNAP' 100 [5 500] +'RNase' 100 [10 1000] +'TL_elong_glob' 20 [4 200] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 10] +'TL_AA_Kd' 100000 [10 1e8] +'TL_AA_F' 0.001 [1e-5 20] +'TL_AGTP_Kd' 100000 [1e2 1e8] +'TL_AGTP_F' 1e-5 [1e-7 1] +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 2000] +'Ribo' 30 [5 1000]}; +size(activeNames2) +vi = get(mi(1).emo, 'ValueInfo') +vi(1) +vi(2) +vi(3) +vi(4) +titls +close all +clc +close all +mi(1).emo +mobj +mobj.species +edit mcmc_runsim_v2.m +mobj.species +close all +mobj.reactinos +mobj.Reactions +mobj.species +simulatecurves(... +mi(1).emo,... +log(cell2mat(activeNames1(:,2))'),... +1,... +di(mi(1).dataToMapTo).dosedVals', ... +di((mi(1).dataToMapTo)).timeVector, ... +mi(1).measuredSpecies) +mi(1).measuredSpecies +mi(1).measuredSpecies{1} +simulatecurves(... +mi(1).emo,... +log(cell2mat(activeNames1(:,2))'),... +1,... +di(mi(1).dataToMapTo).dosedVals', ... +di((mi(1).dataToMapTo)).timeVector, ... +{mi(1).measuredSpecies{1}(1:5}) +simulatecurves(... +mi(1).emo,... +log(cell2mat(activeNames1(:,2))'),... +1,... +di(mi(1).dataToMapTo).dosedVals', ... +di((mi(1).dataToMapTo)).timeVector, ... +{mi(1).measuredSpecies{1}(1:5)}) +{mi(1).measuredSpecies{1}(1:2)}) +emodebugda = simulatecurves(... +mi(1).emo,... +log(cell2mat(activeNames1(:,2))'),... +1,... +di(mi(1).dataToMapTo).dosedVals', ... +di((mi(1).dataToMapTo)).timeVector, ... +{mi(1).measuredSpecies{1}(1:2)}); +emp +emo +mi(1).emo +get(mi(1).emo) +simulate(mi(1).emo) +debugsd = simulate(mi(1).emo) +debugsd +debugsd.DataNames +size(debugsd.Data) +size(debugsd.Time) +debugsd.DataNames +debugsd.DataNames(1) +proj_acs_dsg2014_regen_A('stepSize', 1.2,... +'nW', 50,... +'nPoints', 10*50,... +'thinning', 1,... +'nIter', 2,... +'parallel', false, ... +'poolsize', 2,... +'temperatureLadder', [0.01],... +'stepLadder', [1]) +%-- 2/8/19, 11:19 AM --% +figure +[C,lags,ESS]=eacorr(marray(:, :, :)); +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') +size(marra) +size(marray) +figure +[C,lags,ESS]=eacorr(marray(:, :, 10000:end)); +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') +titls_array = cell(length(titls), 1, length(mi(2).measuredSpeciesIndex)); +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = titls(j); +end +end +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.8, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls', {},... +'SimMode', 'meanstd');%, 'savematlabfig', false, 'savejpeg', false +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd'); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 1, length(mi(2).measuredSpeciesIndex)); +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = titls(j); +end +end +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.8, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls', {},... +'SimMode', 'meanstd');%, 'savematlabfig', false, 'savejpeg', false +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd'); +figure +[C,lags,ESS]=eacorr(marray(:, :,4000:end));%10000:end +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') +close all +clc +log([100]) +log([200]) +log([300]) +log([10]) +log(10) +log(100)-log(10) +log(1e6) +exp activeNames2 = {... % changes made to ranges on feb 8, 2019. originals in regen_A file. +'TX_elong_glob' 10.5 [0.5 300] % +'AGTPdeg_time' 7200 [1800 42000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] % +'TXTL_P70_RNAPbound_Kd' 20 [0.1 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 300] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] % +'TXTL_NTP_RNAP_1_Kd' 100000 [1 1e6] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-5 100] +'TXTL_NTP_RNAP_2_Kd' 1e6 [0.1 1e7] +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-6 1000] % +'TXTL_RNAdeg_Kd' 2000 [100 1e5] +'TXTL_RNAdeg_F' 0.01 [0.01 10000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] % +'RNAP' 100 [5 5000] +'RNase' 100 [1 10000] +'TL_elong_glob' 20 [0.1 500] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] % +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 100] +'TL_AA_Kd' 100000 [.1 1e6] +'TL_AA_F' 0.001 [1e-5 20] % +'TL_AGTP_Kd' 100000 [.1 1e7] +'TL_AGTP_F' 1e-5 [1e-5 100] % +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 20000] +'Ribo' 30 [10 10000]}; +activeNames2 = {... % changes made to ranges on feb 8, 2019. originals in regen_A file. +'TX_elong_glob' 10.5 [0.5 300] % +'AGTPdeg_time' 7200 [1800 42000] +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] +'AGTPreg_ON' 0.02 [0.005 0.2] % +'TXTL_P70_RNAPbound_Kd' 20 [0.1 1e6] +'TXTL_P70_RNAPbound_F' 20 [1e-5 300] +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] % +'TXTL_NTP_RNAP_1_Kd' 100000 [1 1e6] +'TXTL_NTP_RNAP_1_F' 0.0001 [1e-5 100] +'TXTL_NTP_RNAP_2_Kd' 1e6 [0.1 1e7] +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-6 1000] % +'TXTL_RNAdeg_Kd' 2000 [100 1e5] +'TXTL_RNAdeg_F' 0.01 [0.01 10000] +'TXTL_RNAdeg_kc' 0.0028 [1e-4 1] % +'RNAP' 100 [5 5000] +'RNase' 100 [1 10000] +'TL_elong_glob' 20 [0.1 500] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] % +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' 0.2 [1e-5 100] +'TL_AA_Kd' 100000 [.1 1e6] +'TL_AA_F' 0.001 [1e-5 20] % +'TL_AGTP_Kd' 100000 [.1 1e7] +'TL_AGTP_F' 1e-5 [1e-5 100] % +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 20000] +'Ribo' 30 [10 10000]}; +activeNames2 +exp(9.42) +exp(9.42)/3600 +close all +6+1:6 +close all +exp(5.4) +log(20) +exp(1.5) +exp(-8.4) +exp(-5.5) +format short g; exp(9.57) +format short g; exp(9.57)/3600 +exp(-0.3) +estParamsIX = [1 5 7 8 10 11 12 15 16 17 19 21 23 25 26]' +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' 10.5 [0.5 300] % 1 +'AGTPdeg_time' exp(9.57) [1800 42000] % set to exp(9.57) +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] % set from before +'AGTPreg_ON' 0.02 [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' 200 [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] % 7 +'TXTL_NTP_RNAP_1_Kd' 100000 [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' 1e6 [0.1 1e7] +'TXTL_NTP_RNAP_2_F' 1e-5 [1e-6 1000] %11 +'TXTL_RNAdeg_Kd' 2000 [100 1e5] +'TXTL_RNAdeg_F' 1 [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-5.4) [1e-4 1] %set to exp(-5.4) +'RNAP' 100 [5 5000] % 15 +'RNase' 100 [1 10000] +'TL_elong_glob' 20 [0.1 500] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' 100000 [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' 100000 [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 20000] +'Ribo' 30 [10 10000]}; %26 +estParams = activeNames2(estParamsIX,1) +fixedParamsIX = setdiff((1:26)', estParamsIX); +estParams = activeNames2(fixedParamsIX,1) +estParams = activeNames2(fixedParamsIX,2) +estParams = activeNames2(fixedParamsIX,[1:2]) +estParams = activeNames2(estParamsIX,[1:3]) +cell2mat(activeNames2(estParamsIX,[3]) ) +activeNames2(fixedParamsIX,[1:2]) +log(cell2mat(activeNames2(fixedParamsIX,[2]))) +estParamsIX = [1 5 7 8 10 12 15 16 17 19 21 23 25 26]'; +estParams = activeNames2(estParamsIX,1); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:26)', estParamsIX); +log(cell2mat(activeNames2(fixedParamsIX,[2]))) +activeNames2(fixedParamsIX,[1:2]) +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' 10.5 [0.5 300] % 1 +'AGTPdeg_time' exp(9.57) [1800 42000] % set to exp(9.57) +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] % set from before +'AGTPreg_ON' 0.02 [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' 200 [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] % 7 +'TXTL_NTP_RNAP_1_Kd' 100000 [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' 1e6 [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' 2000 [100 1e5] +'TXTL_RNAdeg_F' 1 [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-5.4) [1e-4 1] %set to exp(-5.4) +'RNAP' 100 [5 5000] % 15 +'RNase' 100 [1 10000] +'TL_elong_glob' 20 [0.1 500] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' 100000 [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' 100000 [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 20000] +'Ribo' 30 [10 10000]}; %26 +estParamsIX = [1 5 7 8 10 12 15 16 17 19 21 23 25 26]'; +estParams = activeNames2(estParamsIX,1); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:26)', estParamsIX); +log(cell2mat(activeNames2(fixedParamsIX,[2]))) +activeNames2(fixedParamsIX,[1:2]) +estParams = activeNames2(estParamsIX,[1:3]) +log(cell2mat(activeNames2(fixedParamsIX,[2]))) +activeNames2(fixedParamsIX,[1:2]) +estParams = activeNames2(estParamsIX,[1:3])activeNames2(estParamsIX,[1 +estParams = activeNames2(estParamsIX,[1:3])*activeNames2(estParamsIX,[1]) +activeNames2(estParamsIX,[1] +activeNames2(estParamsIX,[1]) +close all +clear all +clc +activeNames2(estParamsIX,[1]) +figure +[C,lags,ESS]=eacorr(marray(:, :,:));%10000:end +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') +% +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 1, length(mi(2).measuredSpeciesIndex)); +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = titls(j); +end +end +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.8, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls', {},... +'SimMode', 'meanstd');%, 'savematlabfig', false, 'savejpeg', false +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd'); +%-- 2/8/19, 8:56 PM --% +1.05*[6 3 2 1.7 1.4 1.2 1.1 1 0.75 0.5] +close all +clear all +clc +close all +mi(1).paramMaps +activeNames2(mi(1).paramMaps,:) +activeNames2(mi(1).paramMaps,2) +cell2mat(activeNames2(mi(1).paramMaps,2)) +exp([2 4.5; 9.2 10.2; 5 10; 0 4, -5 2.5; 10 14; -6 2; 2.5 5.5]) +exp([2 4.5; 9.2 10.2; 5 10; 0 4; -5 2.5; 10 14; -6 2; 2.5 5.5]) +format short g +exp([2 4.5; 9.2 10.2; 5 10; 0 4; -5 2.5; 10 14; -6 2; 2.5 5.5]) +close all +marrayOrd +mi(2).paramMaps(mi(2).orderingIx) +marrayOrd(:,1:10,1) +mai.masterVector +cell2mat(activeNames2(:,2)) +log(cell2mat(activeNames2(:,2))) +mai +masterVector = log(cell2mat(activeNames2(:,2))) +mai.masterVector = log(cell2mat(activeNames2(:,2))); +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.8, 1]); +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +marrayOrd(:,1:5,1) +mi(2).namesUnord +mi(2).namesUnord(mi(2).paramMaps(mi(2).orderingIx)) +marrayOrd(:,1:5,1) +%-- 2/9/19, 8:19 AM --% +edit gwmcmc_vse.m +isoctave +(exist ('OCTAVE_VERSION', 'builtin') > 0) +(exist ('OCTAVE_VERSION', 'builtin') +(exist ('OCTAVE_VERSION', 'builtin')) +(exist ('OCTAVE_VERSION')) +help persistent +edit mcmc_runsim_v2.m +proj_acs_dsg2014_regen_A('stepSize', 1.2,... +'nW', 50,... +'nPoints', 10*50,... +'thinning', 1,... +'nIter', 2,... +'parallel', false, ... +'poolsize', 2,... +'temperatureLadder', [0.01],... +'stepLadder', [1]) +vii = get(emo{i}, "ValueInfo') +vii = get(emo{i}, 'ValueInfo') +vii(1) +vii(2) +enuo(orderingIx) +eno(orderingIx2) +emo +emo{2} +emo{2}.ValueInfo +emo{2}.ValueInfo(1) +emo{2}.ValueInfo(2) +emo{2}.ValueInfo(3) +emo{2}.ValueInfo(6) +emo{2}.ValueInfo(18:21) +emo{2}.ValueInfo(18) +mi +mi(2) +mai +mi(2) +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls', {},... +'SimMode', 'curves');%, 'savematlabfig', false, 'savejpeg', false +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'curves'); +exp(9.57) +mvarray(:,1:6,end) +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' 10.5 [0.5 300] % 1 +'AGTPdeg_time' exp(9.57) [1800 42000] % set to exp(9.57) +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] % set from before +'AGTPreg_ON' 0.02 [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' 200 [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] % 7 +'TXTL_NTP_RNAP_1_Kd' 100000 [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' 1e6 [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' 2000 [100 1e5] +'TXTL_RNAdeg_F' 1 [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-5.4) [1e-4 1] %set to exp(-5.4) +'RNAP' 100 [5 5000] % 15 +'RNase' 100 [1 10000] +'TL_elong_glob' 20 [0.1 500] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' 100000 [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' 100000 [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 20000] +'Ribo' 30 [10 10000]}; %26 +log(cell2mat(activeNames2(:, 2))) +[mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2)))] +flagz = ones(26, 1)l +flagz = ones(26, 1); +flags([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +[mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] +flagz([1 5 7 8 10 12 15 16 17 19 21 23 25 26]) = 0; +[mvarray(:,1:6,end) log(cell2mat(activeNames2(:, 2))) flagz] +flags +clear flags +close all +(mi(1).orderingIx) +mi(1).paramMaps +mi(1).paramMaps(mi(2).orderingIx) +mi(1).paramMaps(mi(1).orderingIx) +log(cell2mat(activeNames2(:, 2))) +[log(cell2mat(activeNames2(:, 2))) (cell2mat(activeNames2(:, 2)))] +format short g +[log(cell2mat(activeNames2(:, 2))) (cell2mat(activeNames2(:, 2)))] +exp(5.8) +clear all +close all +di +sum(sum(sum(di(1).dataArray))) +sum(sum(sum(di(2).dataArray))) +sum(sum(sum(di(3).dataArray))) +di(1) +di(3) +sum(sum(sum(di(1).dataArray)))/sum(sum(sum(di(3).dataArray))) +clear all +close all +clear all +clc +mai.masterVector +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +mai.masterVector +mcmc_info = mcmc_info_dsg2014_regen_A(mobj); +mai = mcmc_info.master_info; +mai.masterVector +mvarray(:,1:3,end) +mvarray(:,1:3:end,end) +mvarray(:,1:30:end,end) +mvarray(:,1:50:end,end) +close all +mvarray(:,1:2mend) +mvarray(:,1:2,end) +paramsToTest(:,34) +activeNames2(:,1) +exp(7.5) +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. +'AGTPdeg_rate' exp(-9.5172) [1e-5 1e-2] % set from before +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [1e-4 100] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] %set to exp(-5.4) +'RNAP' exp(1.4419) [5 5000] % 15 +'RNase' exp(6.4899) [1 10000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.05 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 20000] +'Ribo' exp(7.3081) [10 10000]}; %26 +estParamsIX = [1 5 7 15 17 19 25 26]' +activeNames2(estParamsIX, 1) +activeNames2(estParamsIX, 2) +cell2mat(activeNames2(estParamsIX, 2)) +cell2mat(activeNames2(:, 2)) +[cell2mat(activeNames2(:, 2)) cell2mat(activeNames2(:, 3))] +estParamsIX = [1 5 7 12 14 15 16 17 19 25 26]'; +activeNames2(estParamsIX, 1) +estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]' +activeNames2(estParamsIX, 1) +aaa = [ {'TX_elong_glob' } +{'AGTPdeg_time' } +{'AGTPdeg_rate' } +{'TXTL_P70_RNAPbound_Kd' } +{'TXTL_RNAPBOUND_TERMINATION_RATE'} +{'TXTL_RNAdeg_Kd' } +{'TXTL_RNAdeg_kc' } +{'RNase' } +{'RNAP' } +{'TL_elong_glob' } +{'TXTL_UTR_UTR1_Kd' } +{'TXTL_RIBOBOUND_TERMINATION_RATE'} +{'Ribo' } +] +[activeNames2(estParamsIX, 1) aaa] +%-- 2/10/19, 1:36 PM --% +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 1, length(mi(1).measuredSpeciesIndex)); +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = [titls(j) ' Experiment']; +titls_array(j, 2, i) = [titls(j) ' Fits']; +end +end +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true); +{[titls{j} ' Experiment']} +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 1, length(mi(1).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true); +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true); +ax +ax.Ylim = [0 expsimmax] +ax.YLim = [0 expsimmax] +expsimmax +ax.YLim = [0 expsimmax(msnum)] +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true); +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false); +mcmc_plot(marray(:, 1:10:end,1:50:end), parnames(:)); +close all +clear all +close all +mcmc_plot(marray(:, 1:2:end,1500:10:end), parnames(:)); +analysis_regen_E +help figure +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'RNAspike'); +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'MGa_deGFP'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'RNAspike'); +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'MGa_deGFP'); +close all +figure +[C,lags,ESS]=eacorr(marray(:, :,2500:end));%10000:end +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') +mcmc_plot(marray(:, 1:30:end,1:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +mcmc_plot(marray(:, 1:30:end,1:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +mcmc_plot(marray(:, 1:2:end,2500:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:10:end,2500:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:5:end,2500:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +close all +mcmc_plot(marray(:, 1:3:end,2500:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:3:end,1:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +mcmc_plot(marray(:, 1:6:end,2500:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:6:end,1:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +mcmc_plot(marray(:, 1:6:end,2500:10:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:10:end,1:20:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +close all +% Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:6:end,92*50:30:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:6:end,3600:30:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'SemiBurnedIn'); +mcmc_plot(marray(:, 1:10:end,1:30:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +figure +[C,lags,ESS]=eacorr(marray(:, :,92*50:end));%10000:end +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') +mcmc_plot(marray(:, 1:5:end,92*50:30:end), parnames(:),... +'savematlabfig', true, 'savejpeg', true,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +%-- 2/11/19, 10:02 AM --% +help savefig +savejpg +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +mcmc_plot(marray(:, 1:6:end,4000:10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:10:end,1:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +figure +[C,lags,ESS]=eacorr(marray(:, :,4000:end));%10000:end +plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +grid on +xlabel('lags') +ylabel('autocorrelation'); +text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +title('Markov Chain Auto Correlation') +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'RNAspike'); +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'MGa_deGFP'); +close all +edit analysis_regen_F +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_F']; +addpath(projdir) +jpgsave = false; +figsave = false; +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_F(mobj); +di = data_dsg2014_full; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse +case 1 +ts1 = '20190210_184039_1_195'; +ts2 = '20190210_184039_2_20'; +tstamp = {ts1 ts2}; +nIterID = {1:10 1:4}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +mai +mai.estNames +close all +%-- 2/11/19, 8:06 PM --% +log([0.1 1e6]) +log([0.1 500]) +log([1e-6 1e-2]) +log([0.005 0.2]) +log([0.0002 0.02]) +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] +'AGTPdeg_rate' exp(-9.5172) [1e-6 1e-1] +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % +'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] % +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 10000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0001 0.2] %18 +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] % +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] +'Ribo' exp(7.3081) [1 10000]}; %26 +estParamsIX = [1 2 3 4 5 7 12 14 15 16 17 18 19 25 26]'; +estParams = activeNames2(estParamsIX,1) +estParamsIX = [1 2 3 4 5 7 8 10 12 14 15 16 17 18 19 21 23 25 26]'; +estParams = activeNames2(estParamsIX,1) +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] +'AGTPdeg_rate' exp(-9.5172) [1e-6 1e-1] +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % +'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] % +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 10000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0001 0.2] %18 +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] % +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] +'Ribo' exp(7.3081) [1 10000]}; %26 +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 4 5 7 12 14 15 16 17 18 19 25 26]'; +estParams = activeNames2(estParamsIX,1) +%-- 2/11/19, 9:19 PM --% +% In this file we try to find a set of parameter values that allow the +% model from model_dsg2014_regen to fit the data from data_dsg2014_full. +% Vipul Singhal, 2019 +% simulate txtl model with custom parameter values, and look at the species +% plots as specified by mcmc_info object. +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_acs_dsg2014_regen_G']; +addpath(projdir) +% Load model, mcmc_info, and data_info. +mobj = model_dsg2014_regen; +mcmc_info = mcmc_info_dsg2014_regen_G(mobj); +di = data_dsg2014_full; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 1; +plotflag = true; +switch tsIDtouse +case 1 +ts1temp = '20190209_191801_1_127'; +ts2temp = '20190210_030032_1_127'; +ts3temp = '20190210_123436_1_32'; +nIterID = {1:20 1:29 1:80}; +tstamp = {ts1temp ts2temp ts3temp}; +load([projdir '/simdata_' ts1temp '/full_variable_set_' ts1temp '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:, :, 1:end); +parnames = ... +[{'TX_{cat}' } +{'pol_{Kd}' } +{'pol' } +{'TL_{cat}' } +{'Ribo_{Kd}' } +{'Ribo' }]; +% +close all +%-- 2/12/19, 8:27 AM --% +mcmc_plot(marray(:, 1:50:end,5000:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:50:end,1:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'WithTransient'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +mcmc_plot(marray(:, 1:10:end,5000:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:10:end,1:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'WithTransient'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +mcmc_plot(marray(:, 1:10:end,7000:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:10:end,1:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'WithTransient'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +mcmc_plot(marray(:, 1:10:end,8000:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:10:end,1:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'WithTransient'); +mcmc_plot(marray(:, 1:end,8000:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts4, 'extrafignamestring', 'BurnedInAllWalkers'); +%-- 2/12/19, 9:17 AM --% +mai.paramRanges +exp(0.6) +exp([0.9 1.55]) +exp([3.45 4.14 4.77]) +log([1 100000]) +log([1 10000]) +%-- 2/12/19, 7:35 PM --% +close all +%-- 2/12/19, 7:53 PM --% +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/bioinformatics/GIS_Project_Bigfish/MERFISH_analysis-master/example_scripts') +addpath('/Users/vipulsinghal/Dropbox/Documents/a_Research/bioinformatics/GIS_Project_Bigfish/MERFISH_analysis-master/startup') +run('/Users/vipulsinghal/Dropbox/Documents/a_Research/bioinformatics/GIS_Project_Bigfish/All_RNAseq_datasets/codebooks/Vipul debug files 230119_small_file_size copy/library_design_example2.m') +MERFISHAnalysisPath = ... +'/Users/vipulsinghal/Dropbox/Documents/a_Research/bioinformatics/MERFISH/MERFISH_analysis' +addpath(genpath(... +'/Users/vipulsinghal/Dropbox/Documents/a_Research/bioinformatics/MERFISH/MERFISH_analysis/matlab-storm-master')) +library_design_example_debug_feb13v2 +clear all +clc +close all +startup +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] +'AGTPdeg_rate' exp(-9.5172) [1e-6 1e-1] +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % +'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] % +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 10000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0001 0.2] %18 +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] % +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] +'Ribo' exp(7.3081) [1 10000]}; %26 +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 4 5 7 8 10 12 14 15 16 17 18 19 21 23 25 26]'; +estParams = activeNames2(estParamsIX,1) +parnames = ... +[{'TX_{cat}' } +{'\tau_{atp}' } +{'\delta_{atp}' } +{'\alpha_{atp}' } +{'pol_{Kd}' } +{'pol_{term}' } +{'n_{Kd1}' } +{'n_{Kd2}' } +{'RNAse_{Kd}' } +{'RNAse_{cat}' } +{'pol' } +{'RNase' } +{'TL_{cat}' } +{'GFP_{mat}' } +{'Ribo_{Kd}' } +{'aa_{Kd}' } +{'TL_n_{Kd}' } +{'Ribo_{term}' } +{'Ribo' }] +[parnames estParams] +close all +mcmc_plot(marray(:, 1:10:end,(end-200):10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +mcmc_plot(marray(:, 1:end,(end-200):10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +clear all +close all +who +pack +%-- 2/14/19, 8:51 AM --% +analysis_regen_H +mcmc_plot(marray(:, 1:30:end,(end-3000):10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts2, 'extrafignamestring', 'last300'); +mcmc_plot(marray(:, 1:end,(end-3000):10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts2, 'extrafignamestring', 'last300'); +clear all +pack +%-- 2/17/19, 1:34 PM --% +analysis_regen_H +edit activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] +'AGTPdeg_rate' exp(-9.5172) [1e-6 1e-1] +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % +'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] % +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 10000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0001 0.2] %18 +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] % +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] +'Ribo' exp(7.3081) [1 10000]}; %26 +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 4 5 7 12 14 15 16 17 18 19 25 26]'; +estParams = activeNames2(estParamsIX,1) +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] +'AGTPdeg_rate' exp(-9.5172) [1e-6 1e-1] +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % +'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] % +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 10000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0001 0.2] %18 +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] % +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] +'Ribo' exp(7.3081) [1 10000]}; %26 +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 4 5 7 12 14 15 16 17 18 19 25 26]'; +estParams = activeNames2(estParamsIX,1) +activeNames2(:, 2) +cell2mat(activeNames2(:, 2)) +log(cell2mat(activeNames2(:, 2))) +help round +round(log(cell2mat(activeNames2(:, 2))),1) +format short g +round(log(cell2mat(activeNames2(:, 2))),1) +mat2cell(round(log(cell2mat(activeNames2(:, 2))),1)) +mat2cell(round(log(cell2mat(activeNames2(:, 2))),1), 26, 1) +help mat2cell +mat2cell(round(log(cell2mat(activeNames2(:, 2))),1), ones(26,1), 1) +[activenames2(:,1) mat2cell(round(log(cell2mat(activeNames2(:, 2))),1), ones(26,1), 1)] +[activeNames2(:,1) mat2cell(round(log(cell2mat(activeNames2(:, 2))),1), ones(26,1), 1)] +[activeNames2(:,1) mat2cell(round(log(cell2mat(activeNames2(:, 2))),1), ones(26,1), 1) mat2cell(round(log(cell2mat(activeNames2(:, 3))),1), ones(26,1), 2)] +[mat2cell(round(log(cell2mat(activeNames2(:, 3))),1), ones(26,1), 2)] +[mat2cell(round(log(cell2mat(activeNames2(:, 3))),1), ones(26,1), 1)] +[mat2cell(round(log(cell2mat(activeNames2(:, 3))),1), ones(26,1), [1 1])] +[activeNames2(:,1) mat2cell(round(log(cell2mat(activeNames2(:, 2))),1), ones(26,1), 1) mat2cell(round(log(cell2mat(activeNames2(:, 3))),1), ones(26,1), [1 1])] +log(200) +log(220) +log(230) +edit analysis_regen_H.m +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] +'AGTPdeg_rate' exp(-9.5172) [1e-6 1e-1] +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 100] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e5] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % +'TXTL_RNAdeg_kc' exp(-4.4) [1e-4 1] % +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 10000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0001 0.2] %18 +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.5 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] % +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 200] +'Ribo' exp(7.3081) [1 10000]}; %26 +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 4 5 7 12 14 15 16 17 18 19 25 26]'; +estParams = activeNames2(estParamsIX,1) +analysis_regen_I +ceil(size(mvarray, 3) * [.9, 1]) +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [0.8 0.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'RNAspike'); +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'MGa_deGFP'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +% mcmc_plot(marray(:, 1:end,5000:5:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedInAllWalkers'); +% +% mcmc_plot(marray(:, 1:20:end,5000:10:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:end,(end-2000):20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'last100'); +mcmc_plot(marray(:, 1:20:end,1:10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1, 'extrafignamestring', 'WithTransient'); +close all +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. +'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % set from before +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 1e7] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 1000] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] %set to exp(-5.4) +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 10000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.05 1e7] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] +'Ribo' exp(7.3081) [10 10000]}; %26 +% +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; +estParams = activeNames2(estParamsIX,1) +activeNames2(:,1) +log(5) +log(2.3^2) +log(2.6^2) +log(2.7^2) +exp(1) +log(2.713^2) +(2.713^2) +10 +log([0.5 300]) +log(1e-5) +log([1e-5 10]) +exp([0.1 5000]_ +exp([0.1 5000]) +log([0.1 5000]) +1200*10 +analysis_vnprl_F2 +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'RNAspike'); +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'MGa_deGFP'); +%-- 2/18/19, 10:53 AM --% +analysis_vnprl_F2 +close all +edit data_dsg2014_full.m +analysis_vnprl_F2 +size(marray(:, 1:50:end,1:10:end)) +120000/9600/10 +120000/9600/10*25 +%-- 2/19/19, 4:34 PM --% +analysis_vnprl_F2 +%-- 2/20/19, 1:52 AM --% +analysis_vnprl_F2 +mcmc_plot(marray(:, 1:5:end,(end-2000):10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +% mcmc_plot(marray(:, 1:end,8000:20:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray(:, 1:end,(end-2000):20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray(:, 1:end,(end-2000):40:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'RNAspike'); +marrayOrd = mvarray(mi(2).paramMaps(mi(2).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(2).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(2).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(2).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(2).emo, data_info(mi(2).dataToMapTo), mi(2), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'MGa_deGFP'); +%-- 2/20/19, 10:22 AM --% +analysis_vnprl_F2 +%-- 2/20/19, 6:03 PM --% +analysis_vnprl_F2 +close all +%-- 2/22/19, 12:17 PM --% +analysis_vnprl_F2 +%-- 2/22/19, 4:16 PM --% +mcmc_plot(marray(:, 1:40:end,1:20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTransient'); +mcmc_plot(marray(:, 1:end,(end-7000):20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S1/S1data.mat'); +whos +clear all +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S1/S1data.mat'); +whos +dose +t_est +t_ori +m +m.Reactions +Set1Data +format short g +Set1Data +edit IFFL_DATA_plot_multiple_2.m +IFFL_DATA_plot_multiple_2 +addpath(genpath('/Users/vipulsinghal/Dropbox/Documents/MATLAB')) +IFFL_DATA_plot_multiple_2 +edit IFFL_DATA_plot_multiple_2 +whos +clear all +%-- 2/23/19, 1:55 PM --% +editTest004_useTestForTraining +edit Test004_useTestForTraining +grpData_test +% IFFL data arranged in structures for plot_multiple.m +% this version differs from the first one in that the data is plotted in a +% 5 by 2 array, where the experimental and simulation data is plotted side +% by side +%% Step 1: Build time vectors and data matrices +tv = 60*(0:8:(8*60))'; +dmo = zeros(length(tv), 35);% data matrix of trajectories generated using original parameters +dme = zeros(length(tv), 35);% data matrix of trajectories generated using estimated parameters +dmexp = zeros(length(tv), 3*35);% data matrix of experimental data in triplicate +% load 'x_ori', 't_ori', 'x_est', 't_est', 'm', 'Set1Data' +% These variables have the following forms +% x_ori, t_ori, and x_est, t_est are cell arrays, and Set1Data is a 3D +% array of num time points x 4 x 7, where the first column is time, and +% columns 2:4 are the triplicate repeats. +% construct the various data matrices +% load S1 data +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S1/S1data.mat'); +% The data is in a 7 element cell array. But first we need to extract the +% GFP data +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +%trajectories generated using estimated parameters +[T, it_ori, ~] = unique(t_ori{i}); +gfpdata = interp1(T, x_ori{i}(it_ori,iGFP)/1000,tv); +dmo(:, i)= gfpdata; +%trajectories generated using estimated parameters +[T, it_est, ~] = unique(t_est{i}); +gfpdata = interp1(T, x_est{i}(it_est,iGFP)/1000,tv); +dme(:, i)= gfpdata; +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set1Data(:,1,i)); +dmexp(:,3*(i-1)+(1:3))= interp1(T, Set1Data(it_exp,2:4,i),tv); +end +% load S2 data +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S2/S2data.mat'); +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +offset = 7; +%trajectories generated using estimated parameters +[T, it_ori, ~] = unique(t_ori{i}); +gfpdata = interp1(T, x_ori{i}(it_ori,iGFP)/1000,tv); +dmo(:, offset+i)= gfpdata; +%trajectories generated using estimated parameters +[T, it_est, ~] = unique(t_est{i}); +gfpdata = interp1(T, x_est{i}(it_est,iGFP)/1000,tv); +dme(:, offset+i)= gfpdata; +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set2Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set2Data(it_exp,2:4,i),tv); +end +% load S3 and S4 data +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S3/S3S4data.mat'); +iGFP = findspecies(m, 'protein deGFP*'); +t_ori = T_ORI{1}; % first element is S3 +x_ori = X_ORI{1}; +t_est = T_EST{1}; +x_est = X_EST{1}; +for i = 1:7 +offset = 14; +%trajectories generated using estimated parameters +[T, it_ori, ~] = unique(t_ori{i}); +gfpdata = interp1(T, x_ori{i}(it_ori,iGFP)/1000,tv); +dmo(:, offset+i)= gfpdata; +%trajectories generated using estimated parameters +[T, it_est, ~] = unique(t_est{i}); +gfpdata = interp1(T, x_est{i}(it_est,iGFP)/1000,tv); +dme(:, offset+i)= gfpdata; +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set3Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set3Data(it_exp,2:4,i),tv); +end +t_ori = T_ORI{2}; % second element is S4 +x_ori = X_ORI{2}; +t_est = T_EST{2}; +x_est = X_EST{2}; +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +offset = 21; +%trajectories generated using estimated parameters +[T, it_ori, ~] = unique(t_ori{i}); +gfpdata = interp1(T, x_ori{i}(it_ori,iGFP)/1000,tv); +dmo(:, offset+i)= gfpdata; +%trajectories generated using estimated parameters +[T, it_est, ~] = unique(t_est{i}); +gfpdata = interp1(T, x_est{i}(it_est,iGFP)/1000,tv); +dme(:, offset+i)= gfpdata; +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(transformedSet4data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, transformedSet4data(it_exp,2:4,i),tv); +end +% load S5 data +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S5/S5data.mat'); +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +offset = 28; +%trajectories generated using estimated parameters +[T, it_ori, ~] = unique(t_ori{i}); +gfpdata = interp1(T, x_ori{i}(it_ori,iGFP)/1000,tv); +dmo(:, offset+i)= gfpdata; +%trajectories generated using estimated parameters +[T, it_est, ~] = unique(t_est{i}); +gfpdata = interp1(T, x_est{i}(it_est,iGFP)/1000,tv); +dme(:, offset+i)= gfpdata; +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set5Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set5Data(it_exp,2:4,i),tv); +end +dmexp +ixexp +% from original parameters +ixo = {[], [1 2 3 4 5 6 7]'; +[], 14+[1 2 3 4 5 6 7]'; +[], 21+[1 2 3 4 5 6 7]'; +[], 7+[1 2 3 4 5 6 7]'; +[], 28+[1 2 3 4 5 6 7]'}; +% from estimated parameters +ixe = {[], [1 2 3 4 5 6 7]'; +[], 14+[1 2 3 4 5 6 7]'; +[], 21+[1 2 3 4 5 6 7]'; +[], 7+[1 2 3 4 5 6 7]'; +[], 28+[1 2 3 4 5 6 7]'}; +% experimental data +ixexp = {[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +14*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +21*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +7*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +28*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []}; +%% Step 3: build title arrays +textarray = {'pTet constitutive data', 'pTet constitutive fit'; +'TetR repression data','TetR repression fit'; +'aTc induction data','aTc induction fit'; +'pLac constitutive data','pLac constitutive fit'; +'3oc12 AHL induction data','3oc12 AHL induction fit'}; +ta = struct('text', {textarray},... +'fontsize', 16); +%% Step 4: Build legend arrays +textarray = {{'4nM', '2nM', '1nM', '0.5nM', '0.25nM', '0.125nM', '0nM'}; +{'2nM', '0.2nM', '0.02nM', '0.002nM', '0.0002nM', '0.00002nM', '0 nM'}; +{'10000nM', '1000nM', '100nM', '10nM', '1nM', '0.1nM', '0 nM'}; +{'4nM', '2nM', '1nM', '0.5nM', '0.25nM', '0.125nM', '0nM'}; +{'10000nM', '1000nM', '100nM', '10nM', '1nM', '0.1nM', '0 nM'}}; +la = struct('text', {textarray},... +'fontsize', 9, ... +'location', 'NorthWest'); +%% Step 5: Build ylabels +textarray = {'GFP, uM','GFP, uM'; +'GFP, uM','GFP, uM'; +'GFP, uM','GFP, uM'; +'GFP, uM','GFP, uM'; +'GFP, uM','GFP, uM'}; +yl = struct('text', {textarray},... +'fontsize', 12,... +'axislimit', 'rowmax');% 'individual', 'rowmax', or a scalar input of type double +%% Step 5: Build xlabels +textarray = {'time, hours','time, hours'; +'time, hours','time, hours'; +'time, hours','time, hours'; +'time, hours','time, hours'; +'time, hours','time, hours'}; +xl = struct('text', {textarray},... +'fontsize', 12, ... +'axislimit', 8); +ixexp +ixexp{1} +ixexp{5,1} +%-- 2/23/19, 4:35 PM --% +whos +dir examples +edit induction.m +mobj = model_txtl_ptetdeGFP_pLactetR_aTc +mobj.reactions +edit txtl_prom_plas +edit txtl_protein_lasR.m +edit txtl_prom_plas +edit txtl_prom_plac +mLasR = model_txtl_pLacLasR_pLasdeGFP +tube +tube.Reactions +tube.parameters +tube.Userdata.ReactionConfig.Transcription_Rate/RNAlength +txparamname +addparameter(tube, txparamname,tube.Userdata.ReactionConfig.Transcription_Rate/RNAlength); +mLasR = model_txtl_pLacLasR_pLasdeGFP +dbstack +tube +tube.parameters +mLasR = model_txtl_pLacLasR_pLasdeGFP +dbstack +tube.parameters +sbioselect(mLasR, 'TX_transcription_utr1_deGFP') +sbioselect(tube, 'TX_transcription_utr1_deGFP') +sbioselect(tube, 'Type', 'Parameter', 'Name', 'TX_transcription_utr1_deGFP') +isempty(sbioselect(tube, 'Type', 'Parameter', 'Name', 'TX_transcription_utr1_deGFP')) +mLasR = model_txtl_pLacLasR_pLasdeGFP +mLasR +mLasR = model_txtl_pLacLasR_pLasdeGFP +mobj +mobj.rules +mLasR = model_txtl_pLacLasR_pLasdeGFP +tube.Rules +isempty(sbioselect(tube,'Type','Rule', 'Rule', ruleStr)) +ruleStr +mLasR = model_txtl_pLacLasR_pLasdeGFP +mLasR.reactions +mtet = model_txtl_ptetdeGFP_pLactetR_aTc +mtet.reactions +mlac = model_txtl_pLacdeGFP +mlac.reactions +analysis_vnprl_F2 +close +whos +clear mvarray +clear marray +clear marray_full +clear marrayOrd +whos +clear all +pwd +clear all +dataPath = [pwd '/mcmc_simbio/exp_data/Zach_IFFL_raw']; +%% Step 1: Build time vectors and data matrices +tv = 60*(0:8:(8*60))'; +dmexp = zeros(length(tv), 3*35);% data matrix of experimental data in triplicate +% load S1 data +load([dataPath '/S1/S1data.mat']); +whos +clear all +addpath(genpath('/Users/vipulsinghal/Dropbox/Documents/MATLAB')) +tv = 60*(0:8:(8*60))'; +dmexp = zeros(length(tv), 3*35);% data matrix of experimental data in triplicate +% load S1 data +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S1/S1data.mat', 'Set1Data'); +whos +load([dataPath '/S3/S3S4data.mat'], {'Set3Data', 'transformedSet4data'}); +dataPath = [pwd '/mcmc_simbio/exp_data/Zach_IFFL_raw']; +load([dataPath '/S3/S3S4data.mat'], {'Set3Data', 'transformedSet4data'}); +load([dataPath '/S3/S3S4data.mat'], 'Set3Data', 'transformedSet4data'); +ixexp = {[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +14*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +21*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +7*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +28*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []}; +ixexp +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +dataPath = [pwd '/mcmc_simbio/exp_data/Zach_IFFL_raw']; +%% Step 1: Build time vectors and data matrices +tv = 60*(0:8:(8*60))'; +dmexp = zeros(length(tv), 3*35);% data matrix of experimental data in triplicate +% load S1 data +load([dataPath '/S1/S1data.mat'], 'Set1Data'); +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set1Data(:,1,i)); +dmexp(:,3*(i-1)+(1:3))= interp1(T, Set1Data(it_exp,2:4,i),tv); +end +% load S2 data +load([dataPath '/S2/S1data.mat'], 'Set2Data'); +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +offset = 7; +[T, it_exp, ~] = unique(Set2Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set2Data(it_exp,2:4,i),tv); +end +% load S3 and S4 data +load([dataPath '/S3/S3S4data.mat'], 'Set3Data', 'transformedSet4data'); +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +offset = 14; +[T, it_exp, ~] = unique(Set3Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set3Data(it_exp,2:4,i),tv); +end +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +offset = 21; +[T, it_exp, ~] = unique(transformedSet4data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, transformedSet4data(it_exp,2:4,i),tv); +end +% load S5 data +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S5/S5data.mat'); +load([dataPath '/S5/S5data.mat'], 'Set5Data'); +iGFP = findspecies(m, 'protein deGFP*'); +for i = 1:7 +offset = 28; +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set5Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set5Data(it_exp,2:4,i),tv); +end +%% Step 2: build index arrays +% experimental data +ixexp = {[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; ... % 7 conditions for the ptet constitutive. 3 repeats each. +7*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +14*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; ... % 7 conditions too... and so on. +21*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +28*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []}; +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +dataPath = [pwd '/mcmc_simbio/exp_data/Zach_IFFL_raw']; +%% Step 1: Build time vectors and data matrices +tv = 60*(0:8:(8*60))'; +dmexp = zeros(length(tv), 3*35);% data matrix of experimental data in triplicate +% load S1 data +load([dataPath '/S1/S1data.mat'], 'Set1Data'); +for i = 1:7 +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set1Data(:,1,i)); +dmexp(:,3*(i-1)+(1:3))= interp1(T, Set1Data(it_exp,2:4,i),tv); +end +% load S2 data +load([dataPath '/S2/S1data.mat'], 'Set2Data'); +for i = 1:7 +offset = 7; +[T, it_exp, ~] = unique(Set2Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set2Data(it_exp,2:4,i),tv); +end +% load S3 and S4 data +load([dataPath '/S3/S3S4data.mat'], 'Set3Data', 'transformedSet4data'); +for i = 1:7 +offset = 14; +[T, it_exp, ~] = unique(Set3Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set3Data(it_exp,2:4,i),tv); +end +for i = 1:7 +offset = 21; +[T, it_exp, ~] = unique(transformedSet4data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, transformedSet4data(it_exp,2:4,i),tv); +end +% load S5 data +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S5/S5data.mat'); +load([dataPath '/S5/S5data.mat'], 'Set5Data'); +for i = 1:7 +offset = 28; +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set5Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set5Data(it_exp,2:4,i),tv); +end +%% Step 2: build index arrays +% experimental data +ixexp = {[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; ... % 7 conditions for the ptet constitutive. 3 repeats each. +7*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +14*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; ... % 7 conditions too... and so on. +21*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +28*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []}; +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +dataPath = [pwd '/mcmc_simbio/exp_data/Zach_IFFL_raw']; +%% Step 1: Build time vectors and data matrices +tv = 60*(0:8:(8*60))'; +dmexp = zeros(length(tv), 3*35);% data matrix of experimental data in triplicate +% load S1 data +load([dataPath '/S1/S1data.mat'], 'Set1Data'); +for i = 1:7 +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set1Data(:,1,i)); +dmexp(:,3*(i-1)+(1:3))= interp1(T, Set1Data(it_exp,2:4,i),tv); +end +% load S2 data +load([dataPath '/S2/S2data.mat'], 'Set2Data'); +for i = 1:7 +offset = 7; +[T, it_exp, ~] = unique(Set2Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set2Data(it_exp,2:4,i),tv); +end +% load S3 and S4 data +load([dataPath '/S3/S3S4data.mat'], 'Set3Data', 'transformedSet4data'); +for i = 1:7 +offset = 14; +[T, it_exp, ~] = unique(Set3Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set3Data(it_exp,2:4,i),tv); +end +for i = 1:7 +offset = 21; +[T, it_exp, ~] = unique(transformedSet4data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, transformedSet4data(it_exp,2:4,i),tv); +end +% load S5 data +load('/Users/vipulsinghal/Dropbox/110114/Vipul_computational/Computational Tools/S5/S5data.mat'); +load([dataPath '/S5/S5data.mat'], 'Set5Data'); +for i = 1:7 +offset = 28; +% trajectories of original data in triplicate +[T, it_exp, ~] = unique(Set5Data(:,1,i)); +dmexp(:,3*(offset+(i-1))+(1:3))= interp1(T, Set5Data(it_exp,2:4,i),tv); +end +%% Step 2: build index arrays +% experimental data +ixexp = {[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; ... % 7 conditions for the ptet constitutive. 3 repeats each. +7*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +14*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; ... % 7 conditions too... and so on. +21*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []; +28*3+[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21], []}; +size(dmexp) +T +tv +[T tv] +size(T) +size(tv) +8*60*60 +transformedSet4data(:,1,1) +transformedSet4data(:,1,2) +help unique +ixexp +da1 = zeros(length(tv), 1, 3, 7); +for rep = 1:3 +for doseid = 1:7 +da1(:, 1, i, j) = ixexp{1,1}(j, i); +end +end +da1 = zeros(length(tv), 1, 3, 7); +for rep = 1:3 +for doseid = 1:7 +da1(:, 1, rep, doseid) = ixexp{1,1}(doseid, rep); +end +end +da1 +da1 = zeros(length(tv), 1, 3, 7); +for rep = 1:3 +for doseid = 1:7 +da1(:, 1, rep, doseid) = dmexp(:, ixexp{1,1}(doseid, rep)); +end +end +da1 +da = cell(5, 1); +for i = 1:5 +da{i} = zeros(length(tv), 1, 3, 7); +for rep = 1:3 +for doseid = 1:7 +da{i}(:, 1, rep, doseid) = 1000*dmexp(:, ixexp{i,1}(doseid, rep)); +end +end +end +da +plot(da{3}(:, 1, 1, 1)) +plot(tv, da{3}(:, 1, 1, 1)) +figure; plot(tv, da{3}(:, 1, 1, 1)) +figure; plot(tv/3600, da{3}(:, 1, 1, 1)) +figure; plot(tv/3600, da{2}(:, 1, 1, 1)) +figure; plot(tv/3600, da{1}(:, 1, 1, 1)) +figure; plot(tv/3600, da{3}(:, 1, 1, 6)) +figure; plot(tv/3600, da{3}(:, 1, 1, 7)) +figure; plot(tv/3600, da{5}(:, 1, 1, 7)) +figure; plot(tv/3600, da{5}(:, 1, 1, 2)) +close all +di1 = struct('dataInfo', datadescription(1), ... +'timeVector', {tv}, ... +'timeUnits', {'seconds'},... +'dataArray', da(1),... +'measuredNames', {mn},... +'dataUnits', {{'nM'}},... +'dimensionLabels', {dimlabels}, ... +'dosedNames', {dosedNames1},... +'dosedVals', {dv1}, ... +'doseUnits', 'nM'); +di2 = struct('dataInfo', datadescription(2), ... +'timeVector', {tv}, ... +'timeUnits', {'seconds'},... +'dataArray', da(2),... +'measuredNames', {mn},... +'dataUnits', {{'nM'}},... +'dimensionLabels', {dimlabels}, ... +'dosedNames', {dosedNames2},... +'dosedVals', {dv2}, ... +'doseUnits', 'nM'); +di3 = struct('dataInfo', datadescription(3), ... +'timeVector', {tv}, ... +'timeUnits', {'seconds'},... +'dataArray', da(3),... +'measuredNames', {mn},... +'dataUnits', {{'nM'}},... +'dimensionLabels', {dimlabels}, ... +'dosedNames', {dosedNames3},... +'dosedVals', {dv3}, ... +'doseUnits', 'nM'); +di4 = struct('dataInfo', datadescription(4), ... +'timeVector', {tv}, ... +'timeUnits', {'seconds'},... +'dataArray', da(4),... +'measuredNames', {mn},... +'dataUnits', {{'nM'}},... +'dimensionLabels', {dimlabels}, ... +'dosedNames', {dosedNames4},... +'dosedVals', {dv4}, ... +'doseUnits', 'nM'); +di5 = struct('dataInfo', datadescription(5), ... +'timeVector', {tv}, ... +'timeUnits', {'seconds'},... +'dataArray', da(5),... +'measuredNames', {mn},... +'dataUnits', {{'nM'}},... +'dimensionLabels', {dimlabels}, ... +'dosedNames', {dosedNames5},... +'dosedVals', {dv5}, ... +'doseUnits', 'nM'); +di6 = struct('dataInfo', datadescription(6), ... +'timeVector', {tv}, ... +'timeUnits', {'seconds'},... +'dataArray', da(6),... +'measuredNames', {mn},... +'dataUnits', {{'nM'}},... +'dimensionLabels', {dimlabels}, ... +'dosedNames', {dosedNames6},... +'dosedVals', {dv6}, ... +'doseUnits', 'nM'); +di7 = struct('dataInfo', datadescription(7), ... +'timeVector', {tv}, ... +'timeUnits', {'seconds'},... +'dataArray', da(7),... +'measuredNames', {mn},... +'dataUnits', {{'nM'}},... +'dimensionLabels', {dimlabels}, ... +'dosedNames', {dosedNames7},... +'dosedVals', {dv7}, ... +'doseUnits', 'nM'); +di = [di1, di2, di3, di4, di5, di6, di7]; +di +clc +di +mcmc_trajectories +help mcmc_trajectories +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); +dosedNames2 +di = data_ZSIFFL; mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); +currdi.measuredNames +currdi.measuredNames{msnum} +hello = {'a', 's', 'r'} +figure; plot(sin(1:100)); title(hello{1:3}) +di = data_ZSIFFL; mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); +title(currdi.measuredNames{msnum}{1:end}) +close all +clear all +clc +analysis_vnprl_F2 +clc +clear all +clc +di = data_ZSIFFL; mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); +close all +edit gftuple +ver +%-- 3/12/19, 1:52 PM --% +uiopen('/Volumes/DRBANNER/pisces/Yanxia/080317MouseLiverAdult/transcriptomeObj/headerType.matb',1) +load /Volumes/DRBANNER/pisces/Yanxia/080317MouseLiverAdult/transcriptomeObj/headerType.matb +load('/Volumes/DRBANNER/pisces/Yanxia/080317MouseLiverAdult/transcriptomeObj/headerType.matb') +load('/Volumes/DRBANNER/pisces/Yanxia/080317MouseLiverAdult/transcriptomeObj/id2Ind.matb') +txtl_init +mcmc_init +edit proj_tierra2018_calibration.m +edit proj_tierra2018_calibration_B.m +edit proj_acs_dsg2014_regen_F1.m +edit mcmc_info_constgfp3ii.m +edit data_dsg2014.m +[a, b, c] = import_ptetconstitutive; +a +b +c +b +c +a +a/60 +a(1:13)/60 +a(1:13)/3600 +[tptet , data_ptet, dvptet] = import_ptetconstitutive; +[ttetR , data_tetR, dvtetR] = import_ptetconstitutive; +% data_array is nT x nMS x nIC x nEnv. +% need to separate out the Envs in the different data info entries. +% need to have data array be time by ms by reps by doses. +da1temp = data_ptet(1:13, :, :, 1); +da1 = permute(da1temp, [1, 2, 4, 3]); +da2temp = data_ptet(1:13, :, :, 2); +da2 = permute(da2temp, [1, 2, 4, 3]); +da3temp = data_ptet(1:13, :, :, 3); +da3 = permute(da3temp, [1, 2, 4, 3]); +da4temp = data_tetR(1:13, :, :, 1); +da4 = permute(da4temp, [1, 2, 4, 3]); +da5temp = data_tetR(1:13, :, :, 2); +da5 = permute(da5temp, [1, 2, 4, 3]); +da6temp = data_tetR(1:13, :, :, 3); +da6 = permute(da6temp, [1, 2, 4, 3]); +dvtetR +[tptet , data_ptet, dvptet] = import_ptetconstitutive; +[ttetR , data_tetR, dvtetR] = import_tetR_repression; +% data_array is nT x nMS x nIC x nEnv. +% need to separate out the Envs in the different data info entries. +% need to have data array be time by ms by reps by doses. +da1temp = data_ptet(1:13, :, :, 1); +da1 = permute(da1temp, [1, 2, 4, 3]); +da2temp = data_ptet(1:13, :, :, 2); +da2 = permute(da2temp, [1, 2, 4, 3]); +da3temp = data_ptet(1:13, :, :, 3); +da3 = permute(da3temp, [1, 2, 4, 3]); +da4temp = data_tetR(1:13, :, :, 1); +da4 = permute(da4temp, [1, 2, 4, 3]); +da5temp = data_tetR(1:13, :, :, 2); +da5 = permute(da5temp, [1, 2, 4, 3]); +da6temp = data_tetR(1:13, :, :, 3); +da6 = permute(da6temp, [1, 2, 4, 3]); +dvtetR +ttetR +ttetR(1:13)/3600 +di = data_test015; +di +di(3) +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); +mcmc_trajectories([], di(2), [], [], [], [], 'just_data_info', true); +mcmc_trajectories([], di(3), [], [], [], [], 'just_data_info', true); +mcmc_trajectories([], di(4), [], [], [], [], 'just_data_info', true); +mcmc_trajectories([], di(6), [], [], [], [], 'just_data_info', true); +currdi.measuredNames{msnum}{1:end} +msnum +mcmc_trajectories([], di(6), [], [], [], [], 'just_data_info', true); +di(2) +di(4) +di(4).dosedVals +proj_test015 +edit analysis_regen_F1.m +close all +analysis_test015calib +proj_test015 +analysis_test015calib +close all +analysis_test015calib +mi +length(mi(1).measuredSpeciesIndex) +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'RNAspike'); +mi(1).dataToMapTo +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', true,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', ts1,... +'extrafignamestring', 'RNAspike'); +close all +clc +marray(:, 600,end) +marray(:, end,end) +{'kfdG' +'krdG' +'kcp1' +'kcp2' +'pol1' +'pol2'}; +[{'kfdG' +'krdG' +'kcp1' +'kcp2' +'pol1' +'pol2'}, marray(:, end,end)] +'pol2'}, mat2cell(marray(:, end,end))] +[{'kfdG' +'krdG' +'kcp1' +'kcp2' +'pol1' +'pol2'}, mat2cell(marray(:, end,end))] +help mat2cell +[{'kfdG' +'krdG' +'kcp1' +'kcp2' +'pol1' +'pol2'}, mat2cell(marray(:, end,end), ones(6,1), 1)] +[parnames, mat2cell(marray(:, end,end), ones(6,1), 1)] +dir mcmc_simbio/models_and_supporting_files/ +edit model_tetR_repression1.m +dir mcmc_simbio/models_and_supporting_files/ +edit mcmc_info_tetR_1i +% +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(2)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +mi(1).orderingIx +mi(1) +mi(1).paramMaps +mi(1).paramMaps(mi(1).orderingIx) +close all +clc +di +di(4) +di(4).dosedNames +di(4).dosedVals +[parnames, mat2cell(marray(:, end,end), ones(6,1), 1)] +[parnames, mat2cell(marray(:, [1 30 200 500 1100],end), ones(6,1), [1 1 1 1 1])] +[parnames, mat2cell(marray(:, [1 30 200 500 700 900 1100],end), ones(6,1), [1 1 1 1 1 1 1 1])] +[parnames, mat2cell(marray(:, [1 30 200 350 500 700 900 1100],end), ones(6,1), [1 1 1 1 1 1 1 1])] +[parnames, mat2cell(marray(:, [1:12:240],end), ones(6,1), ones(1,20))] +[parnames, mat2cell(marray(:, [14],end), ones(6,1), ones(1,1))] +[1:12:240] +aaa = [1:12:240] +aaa(14) +[parnames, mat2cell(marray(:, [157],end), ones(6,1), ones(1,1))] +proj_test_15_corr1 +proj_test015_corr1 +di(4).dosedNames +flipud([ 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 +0 0.2500 0.5000 0.7500 1.0000 2.0000 5.0000 10.0000]) +proj_test015_corr1 +close all +pwd +mai +mvarray = masterVecArray(marray, mai) +mai.masterVector +mvarray(:,end-3:end,end +mvarray(:,end-3:end,end) +close all +clc +mai.fixedParams +mai.masterVector +kcp1 = exp( 5.9874); +pol1 = exp(-11.3549); +espvec = [ 5.9874; -11.3549] +% next we simulate the results with the estimated test CSP params and +% the non CSP fixing ESPs above. +% create a master info +szm = size(marray); +mvarray = repmat(mai.masterVector, [1, szm(2:end)]) ; +eparray = repmat(espvec, [1, szm(2:end)]) ; +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +mvarray(estParamsIx, :, :) = marray; +mvarray(mai.fixedParams, :, :) = eparray; +mvarray(:,1:3,1:4) +mi(1).dosedVals +titls +titls_array +mobj +mobj.reactions +help sbiosimulate +[T,X,NAMES] = sbiosimulate(mobj) +[T,X,NAMES] = sbiosimulate(mobj)cs = getconfigset(m, 'active'); +set(cs, 'StopTime', 60); +cs = getconfigset(m, 'active'); +set(cs, 'StopTime', 60); +m = mobj +cs = getconfigset(m, 'active'); +set(cs, 'StopTime', 60); +cs = getconfigset(m, 'active'); +set(cs, 'StopTime', 3660); +[T,X,NAMES] = sbiosimulate(mobj) +mobj.Parameters +mobj.species +mi(1).emo +data_info(mi(1).dataToMapTo(1)) +mi +mi.dosedNames +data_info(mi(1).dataToMapTo(1)).dosedVals +mi.namesOrd +mi.namesUnord +mobj.species +size(marrayOrd) +(marrayOrd(:,2,2)) +mi(1).paramMaps(mi(1).orderingIx,1 +mi(1).paramMaps(mi(1).orderingIx,1) +set(mi(1).emo) +get(mi(1).emo) +get(mi(1).emo, 'ValueInfo') +vi=get(mi(1).emo, 'ValueInfo') +vi(:) +vi(1) +for i = 1:12 +vi(i) +end +mi.namesOrd +vi +vi(8) +vi(9) +vi(10) +vi(10).InitialValue = 100 +vi(11).InitialValue = 2 +vi(12).InitialValue = 20 +[T,X,NAMES] = sbiosimulate(mobj) +[T,X,NAMES] = sbiosimulate(m) +sd = simulate(mi(1).emo) +sd.data +sd.DataNames +mobj = model_tetR_repression1 +[T,X,NAMES] = sbiosimulate(mobj) +mobj.Species +mobj.Species(7) +mobj.Species(1).InitialAmount = 0.1 +[T,X,NAMES] = sbiosimulate(mobj) +mobj.Species(1).InitialAmount = 0 +[T,X,NAMES] = sbiosimulate(mobj) +figure +plot(T, X(:,7)) +hold on +mobj.Species(1).InitialAmount = 0.1 +[T1,X1,NAMES] = sbiosimulate(mobj); +mobj.Species(1).InitialAmount = 2 +[T2,X2,NAMES] = sbiosimulate(mobj); +plot(T1, X1(:,7), 'r') +plot(T2, X2(:,7), 'g') +mobj.Species(1).InitialAmount = 20 +plot(T3, X3(:,7), 'g:') +[T3,X3,NAMES] = sbiosimulate(mobj); +plot(T3, X3(:,7), 'g:') +mobj.Parameters +mobj.Parameters.Value +mobj.Parameters(1).Value +log([1 6 .012 1 6 2 4 2 4 100]) +exp(-12) +exp(5) +exp(-8) +marrayOrd(:,1,1) +marrayOrd(:,1,end) +analysis_test015corr1_Ffix +em +m +size(m) +p.nSimCurves +dose +tv +ms +ms{1} +[exp(m(end - kk+1,:)'); dose(i,:)'] +em.ValueInfo +em.ValueInfo(11) +em.ValueInfo(12) +em.ValueInfo(10) +ms{ss} +XX +analysis_test015corr1_Ffix +da +da(:,:,1:3,:) +da(:,:,1,:) +da(:,:,1,:)*1000 +[exp(m(end - kk+1,:)'); dose(i,:)'] +sbioplot(sd) +edit proj_test015.m +da1temp = data_ptet(1:13, :, :, 1); +da1 = permute(da1temp, [1, 2, 4, 3]); +da2temp = data_ptet(1:13, :, :, 2); +da2 = permute(da2temp, [1, 2, 4, 3]); +da3temp = data_ptet(1:13, :, :, 3); +da3 = permute(da3temp, [1, 2, 4, 3]); +da4temp = data_tetR(1:13, :, :, 1); +da4 = permute(da4temp, [1, 2, 4, 3]); +da5temp = data_tetR(1:13, :, :, 2); +da5 = permute(da5temp, [1, 2, 4, 3]); +da6temp = data_tetR(1:13, :, :, 3); +da6 = permute(da6temp, [1, 2, 4, 3]); +da1 +di = data_test015 +mcmc_trajectories([], di, [], [], [], [], 'just_data_info', true); +mcmc_trajectories([], di(2), [], [], [], [], 'just_data_info', true); +close all +edit analysis_test015calib.m +analysis_test015calib +[parnames, mat2cell(marray(:, [1:12:240],end), ones(6,1), ones(1,20))] +[parnames, mat2cell(marray(:, [25],end), ones(6,1), ones(1,1))] +edit proj_test015_corr1.m +close all +proj_test015_corr1_Ffix +mi.namesOrd +mi +mai +clc +clear all +close all +mcmc_plot(marray(:, 1:end,(end-2000):100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E2'); +mai.fixedParams +mai +mai.masterVector +mai.estNames +log(2) +mi(1).dataToMapTo(1) +edit analysis_test015corr1_Ffix.m +close all +[parnames, mat2cell(marray(:, [1:12:12*40],end), ones(6,1), ones(1,40))] +[parnames, mat2cell(marray(:, [1:12:12*40],end), ones(6,1), ones(1,41))] +[parnames, mat2cell(marray(:, [1:12:12*40],end), ones(4,1), ones(1,41))] +[1:12:12*40] +[parnames, mat2cell(marray(:, [1:12:12*40],end), ones(4,1), ones(1,40))] +size(marray) +parnames +[parnames([2 4 5 7]), mat2cell(marray(:, [1:12:12*40],end), ones(4,1), ones(1,40))] +mcmc_plot(marray([1 2 3 5], 1:end,(end-2000):100:end), parnames([1 2 3 5]),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E1'); +% mcmc_plot(marray([1 2 4 6], 1:10:end,1:100:end), parnames([1 2 4 6]),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithTr_E2'); +mcmc_plot(marray([1 2 4 6], 1:end,(end-2000):100:end), parnames([1 2 4 6]),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E2'); +mcmc_plot(marray(:, 1:10:end,1:100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +edit proj_test015.m +mstack = marray(:, :) +mstack = marray(:, :)'; +size(mstack) +ixs = find(mstack(:, 1)>-4.6 & mstack(:, 1)<-4) +ixs = find(mstack(:, 1)>-4.6 & mstack(:, 1)<-4); +size(ixs) +marray_red = marray(:, :,1:100:end); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 1)>-4.6 & mstack(:, 1)<-4); +size(ixs) +mcmc_plot(mstack, parnames(:)) +mcmc_plot(mstack(ixs,:), parnames(:)) +mstack = marray(:, :)'; +size(mstack) +ixs = find(mstack(:, 1)>-4.6 & mstack(:, 1)<-4) +ixs = find(mstack(:, 1)>-4.6 & mstack(:, 1)<-4); +size(ixs) +marray_red = marray(:, :,1:100:end); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 1)>-4.6 & mstack(:, 1)<-4); +size(ixs) +mcmc_plot(mstack, parnames(:)) +mcmc_plot(mstack(ixs,:), parnames(:))sdfwer2 +close +size(marray) +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,2),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(2)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +size(marray) +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +%% +% close +% marray_red = marray(:, :,(end-16000:50:end)); +% mstack = marray_red(:, :)'; +% ixs = find(mstack(:, 1)>-4.7 & mstack(:, 1)<-3.45); +% mcmc_plot(mstack(ixs,:), parnames(:)) +%% +mcmc_plot(marray(:, 1:10:end,1:100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +mcmc_plot(marray(:, 1:10:end,(end-8000):100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:10:end,(end-12000):100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-6000):100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-10000):500:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +edit analysis_test015calib.m +analysis_test015calib +mcmc_plot(marray(:, 1:end,(end-5000):500:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +analysis_test015calib +size(marray) +analysis_test015calib +size(marray) +mcmc_plot(marray(:, 1:end,(end-16000):1000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +%% +close +marray_red = marray(:, :,(end-8000:250:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 1)>-4.7 & mstack(:, 1)<-3.5); +mcmc_plot(mstack(ixs,:), parnames(:)) +%% +% mcmc_plot(marray(:, 1:end,1:500:end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', jpgsave,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +mcmc_plot(marray(:, 1:end,(end-16000):500:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +analysis_test015calib +mcmc_plot(marray(:, 1:10:end,1:1000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +mcmc_plot(marray(:, 1:4:end,1:250:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +close all +analysis_test015calib +mcmc_plot(marray(:, 1:end,(end-20000):1000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-20000):500:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-10000):300:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-5000):250:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-7500):250:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-7500):1000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-1200):2000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-12000):2000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,(end-20000):2000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +%% +% close +% marray_red = marray(:, :,(end-18000:1000:end)); +% mstack = marray_red(:, :)'; +% ixs = find(mstack(:, 1)>-4.7 & mstack(:, 1)<-3.5); +% mcmc_plot(mstack(ixs,:), parnames(:)) +%% +mcmc_plot(marray(:, 1:end,1:2000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +mcmc_plot(marray(:, 1:end,(end-10000):1000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +mcmc_plot(marray(:, 1:end,1:4000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +marray_red = marray(:, :,(end-10000:1000:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-3.5 & mstack(:, 4)<-2.5 &... +mstack(:, 6)>2.5 & mstack(:, 6)<3); +mcmc_plot(mstack(ixs,:), parnames(:)) +close +marray_red = marray(:, :,(end-10000:200:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-3.5 & mstack(:, 4)<-2.5 &... +mstack(:, 6)>2.5 & mstack(:, 6)<3); +mcmc_plot(mstack(ixs,:), parnames(:)) +marray_red = marray(:, :,(end-10000:200:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-3.1 & mstack(:, 4)<-2.8 &... +mstack(:, 6)>2.5 & mstack(:, 6)<2.8); +mcmc_plot(mstack(ixs,:), parnames(:)) +marray_red = marray(:, :,(end-10000:200:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-3.14 & mstack(:, 4)<-3 &... +mstack(:, 6)>2.64 & mstack(:, 6)<2.7); +mcmc_plot(mstack(ixs,:), parnames(:)) +marray_red = marray(:, :,(end-10000:200:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-2.93 & mstack(:, 4)<-2.8 &... +mstack(:, 6)>2.62 & mstack(:, 6)<2.66); +mcmc_plot(mstack(ixs,:), parnames(:)) +close all +clear all +clc +analysis_test015corr1_Ffix +% figure +% % The ESPs we use are +kcp1 = -3.7404; +pol1 =4.0991; +% +espvec = [ kcp1; pol1]; +fixparamvec = [log(2); espvec]; +% +% % next we simulate the results with the estimated test CSP params and +% % the non CSP fixing ESPs above. +% +% % create a master info +% +szm = size(marray); +mvarray_corr21 = repmat(mai.masterVector, [1, szm(2:end)]) ; +fixarray = repmat(fixparamvec, [1, szm(2:end)]) ; +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +mvarray_corr21(estParamsIx, :, :) = marray; +mvarray_corr21(mai.fixedParams, :, :) = fixarray; +samplePoints = ceil(size(mvarray_corr21, 3) * [.9, 1]); +% +marrayOrd = mvarray_corr21(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'GFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(4), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +% % The ESPs we use are +kcp1 = 0.59; +pol1 =0.369; +% +espvec = [ kcp1; pol1]; +fixparamvec = [log(2); espvec]; +% +% % next we simulate the results with the estimated test CSP params and +% % the non CSP fixing ESPs above. +% +% % create a master info +% +szm = size(marray); +mvarray_corr21 = repmat(mai.masterVector, [1, szm(2:end)]) ; +fixarray = repmat(fixparamvec, [1, szm(2:end)]) ; +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +mvarray_corr21(estParamsIx, :, :) = marray; +mvarray_corr21(mai.fixedParams, :, :) = fixarray; +samplePoints = ceil(size(mvarray_corr21, 3) * [.9, 1]); +% +marrayOrd = mvarray_corr21(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'GFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(4), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +% figure +% % The ESPs we use are +kcp1 = 9.8; +pol1 =0.369; +% +espvec = [ kcp1; pol1]; +fixparamvec = [log(2); espvec]; +% +% % next we simulate the results with the estimated test CSP params and +% % the non CSP fixing ESPs above. +% +% % create a master info +% +szm = size(marray); +mvarray_corr21 = repmat(mai.masterVector, [1, szm(2:end)]) ; +fixarray = repmat(fixparamvec, [1, szm(2:end)]) ; +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +mvarray_corr21(estParamsIx, :, :) = marray; +mvarray_corr21(mai.fixedParams, :, :) = fixarray; +samplePoints = ceil(size(mvarray_corr21, 3) * [.9, 1]); +% +marrayOrd = mvarray_corr21(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'GFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(4), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +% figure +% % The ESPs we use are +kcp1 = -3.7404; +pol1 =3.0991; +% +espvec = [ kcp1; pol1]; +fixparamvec = [log(2); espvec]; +% +% % next we simulate the results with the estimated test CSP params and +% % the non CSP fixing ESPs above. +% +% % create a master info +% +szm = size(marray); +mvarray_corr21 = repmat(mai.masterVector, [1, szm(2:end)]) ; +fixarray = repmat(fixparamvec, [1, szm(2:end)]) ; +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +mvarray_corr21(estParamsIx, :, :) = marray; +mvarray_corr21(mai.fixedParams, :, :) = fixarray; +samplePoints = ceil(size(mvarray_corr21, 3) * [.9, 1]); +% +marrayOrd = mvarray_corr21(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'GFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(4), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +close all +clear all +clc +analysis_test015calib_kdfgfix +analysis_test015calib +size(marray) +mcmc_plot(marray(:, 1:end,(end-20000):300:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +marray_red = marray(:, :,((end-20000):100:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-2.89 & mstack(:, 4)<-2.85 &... +mstack(:, 6)>2.63 & mstack(:, 6)<2.65); +mcmc_plot(mstack(ixs,:), parnames(:)) +marray_red = marray(:, :,((end-20000):end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-2.89 & mstack(:, 4)<-2.85 &... +mstack(:, 6)>2.63 & mstack(:, 6)<2.65); +mcmc_plot(mstack(ixs,:), parnames(:)) +analysis_test015corr1_Ffix2 +edit analysis_test015corr1.m +edit analysis_test015corr1_Ffix.m +analysis_test015corr1_Ffix +size(marray) +mcmc_plot(marray(:, 1:end,(end-3000):50:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'WithoutTr_E2'); +%-- 3/18/19, 1:56 PM --% +analysis_test015calib +mcmc_plot(marray(:, 1:end,(end-15000):500:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +marray_red = marray(:, :,((end-14000):10:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-2.89 & mstack(:, 4)<-2.85 &... +mstack(:, 6)>2.63 & mstack(:, 6)<2.65); +mcmc_plot(mstack(ixs,:), parnames(:)) +analysis_test015calib +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,2),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(2)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +analysis_test015calib +ixs +length(ixs) +help save +ESP2_tilda = mstack(ixs,:); +save('ESP2 points', 'ESP2_tilda') +ESP2_tilda +figure; subplot(2,2,1); hist(ESP2_tilda(:,1)) +help hist +marray_red = marray(:, :,((end-2600):200:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-2.90 & mstack(:, 4)<-2.84 &... +mstack(:, 6)>2.61 & mstack(:, 6)<2.67); +mcmc_plot(mstack(ixs,:), parnames(:)) +ESP2_tilda = mstack(ixs,:); +save('ESP2 points', 'ESP2_tilda') +figure; subplot(2,2,1); hist(ESP2_tilda(:,1)) +figure; subplot(2,2,2); hist(ESP2_tilda(:,2)) +subplot(2,2,2); hist(ESP2_tilda(:,2)) +subplot(2,2,3); hist(ESP2_tilda(:,3)) +subplot(2,2,1); hist(ESP2_tilda(:,1)) +subplot(2,2,4); hist(ESP2_tilda(:,4) +subplot(2,2,4); hist(ESP2_tilda(:,4)) +subplot(2,2,4); hist(ESP2_tilda(:,5)) +analysis_test015corr1_Ffix +size(ESP2_tilda) +help randperm +randperm(length(ESP2_tilda), 20) +analysis_test015corr1_Ffix +size(marray_thin) +curr_calib = ESP2_tilda(ix_to_use(i), :); +% find the elements of mstacked that are within the set +kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon]; +kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon]; +ixs = find(mstacked(:, 1)>-kf_range(1) & mstacked(:, 1)<-kf_range(2) &... +mstacked(:, 2)>kr_range(1) & mstacked(:, 2)-kf_range(1) & mstacked(:, 1)<-kf_range(2) &... +mstacked(:, 2)>kr_range(1) & mstacked(:, 2)-kf_range(1) & mstacked(:, 1)<-kf_range(2) &... +mstacked(:, 2)>kr_range(1) & mstacked(:, 2)kf_range(1) +ixs(2) +isempty(ixs(2)) +isempty(ixs{2}) +length(ixs{2}) +length(ixs{3}) +mi(1).paramMaps(mi(1).orderingIx,1) +for i = 1:length(ix_to_use) +curr_calib = ESP2_tilda(ix_to_use(i), :); +% find the elements of mstacked that are within the set +kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon]; +kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon]; +ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)-2.88 & ESP2_tilda(:, 4)<-2.86 &... +ESP2_tilda(:, 6)>2.63 & ESP2_tilda(:, 6)<2.65); +ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +ESP2_tilda2 +size(ESP2_tilda2) +analysis_test015calib +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,2),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(2)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +mi(1).paramMaps +mi(1).paramMaps(mi(1).orderingIx,2) +mi(1).paramMaps(mi(1).orderingIx) +mi(1).paramMaps(mi(1).orderingIx,:) +edit proj_test015_corr1_Ffix3.m +mcmc_plot(marray(:, 1:end,(end-8000):1000:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +close +marray_red = marray(:, :,((end-8000):200:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-0.2447-0.1 & mstack(:, 4)<-0.2447+0.1 &... +mstack(:, 6)>0.5928-0.1 & mstack(:, 6)<0.5928+0.1); +mcmc_plot(mstack(ixs,:), parnames(:)) +ESP2_tilda_ii = mstack(ixs,:); +ESP2_tilda_ii +marray_red = marray(:, :,((end-8000):1:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-0.2447-0.1 & mstack(:, 4)<-0.2447+0.1 &... +mstack(:, 6)>0.5928-0.1 & mstack(:, 6)<0.5928+0.1); +mcmc_plot(mstack(ixs,:), parnames(:)) +ESP2_tilda_ii = mstack(ixs,:); +epsi = 0.02 +marray_red = marray(:, :,((end-8000):1:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-0.2447-epsi & mstack(:, 4)<-0.2447+epsi &... +mstack(:, 6)>0.5928-epsi & mstack(:, 6)<0.5928+epsi); +mcmc_plot(mstack(ixs,:), parnames(:)) +ESP2_tilda_ii = mstack(ixs,:); +close +close +epsi = 0.02 +marray_red = marray(:, :,((end-12000):1:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-0.2447-epsi & mstack(:, 4)<-0.2447+epsi &... +mstack(:, 6)>0.5928-epsi & mstack(:, 6)<0.5928+epsi); +mcmc_plot(mstack(ixs,:), parnames(:)) +ESP2_tilda_ii = mstack(ixs,:); +close +epsi = 0.02 +kcp2val = 0.7937 +pol2val = -0.5113 +marray_red = marray(:, :,((end-12000):1:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>kcp2val-epsi & mstack(:, 4)pol2val-epsi & mstack(:, 6)-2.88 & ESP2_tilda(:, 4)<-2.86 &... +ESP2_tilda(:, 6)>2.63 & ESP2_tilda(:, 6)<2.66); +ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +ix_to_use = randperm(length(ESP2_tilda2), 60); +% test params: +marray_thin = marray(:, :,1:200:end); +mstacked = marray_thin(:,:)'; +epsilon = 1; +ixs = cell(length(ix_to_use),1); +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +for i = 1:length(ix_to_use) +curr_calib = ESP2_tilda(ix_to_use(i), :) +% find the elements of mstacked that are within the set +kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon] +kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon] +ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)-2.90 & ESP2_tilda(:, 4)<-2.84 &... +ESP2_tilda(:, 6)>2.61 & ESP2_tilda(:, 6)<2.68); +length(ESP2_tilda2) +ixs_calib = find(ESP2_tilda(:, 4)>-2.92 & ESP2_tilda(:, 4)<-2.82 &... +ESP2_tilda(:, 6)>2.59 & ESP2_tilda(:, 6)<2.70); +length(ESP2_tilda2) +clc +load('ESP2 points', 'ESP2_tilda') +% now for 20 points in ESP2_tilda, get the CSP and ESP1, and for those +% CSPs, get the corresponding subset of test csps. +% +% then generate 20 plots of the trajectories from these 20 points. And see +% which fit the data. +ixs_calib = find(ESP2_tilda(:, 4)>-2.92 & ESP2_tilda(:, 4)<-2.82 &... +ESP2_tilda(:, 6)>2.59 & ESP2_tilda(:, 6)<2.70); +length(ESP2_tilda2) +ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +ix_to_use = randperm(length(ESP2_tilda2), 100); +% test params: +marray_thin = marray(:, :,1:200:end); +mstacked = marray_thin(:,:)'; +epsilon = .1; +ixs = cell(length(ix_to_use),1); +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +for i = 1:length(ix_to_use) +curr_calib = ESP2_tilda(ix_to_use(i), :) +% find the elements of mstacked that are within the set +kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon] +kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon] +ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)-3.02 & ESP2_tilda(:, 4)<-2.72 &... +ESP2_tilda(:, 6)>2.49 & ESP2_tilda(:, 6)<2.80); +length(ESP2_tilda2) +ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +ix_to_use = randperm(length(ESP2_tilda2), 100); +% test params: +marray_thin = marray(:, :,1:200:end); +mstacked = marray_thin(:,:)'; +epsilon = .99; +ixs = cell(length(ix_to_use),1); +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +for i = 1:length(ix_to_use) +curr_calib = ESP2_tilda(ix_to_use(i), :); +% find the elements of mstacked that are within the set +kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon]; +kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon]; +ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)rkcp2-epsi_calib & ESP2_tilda(:, 4)cpol2-epsi_calib & ESP2_tilda(:, 6)rkcp2-epsi_calib & ESP2_tilda(:, 4)cpol2-epsi_calib & ESP2_tilda(:, 6)rkcp2-epsi_calib & ESP2_tilda(:, 4)cpol2-epsi_calib & ESP2_tilda(:, 6)rkcp2-epsi_calib & ESP2_tilda(:, 4)cpol2-epsi_calib & ESP2_tilda(:, 6)rkcp2-epsi_calib & ESP2_tilda(:, 4)cpol2-epsi_calib & ESP2_tilda(:, 6)(rkcp2-epsi_calib) & ESP2_tilda(:, 4)<(rkcp2+epsi_calib) &... +ESP2_tilda(:, 6)>(cpol2-epsi_calib) & ESP2_tilda(:, 6)<(cpol2+epsi_calib)) +ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +length(ESP2_tilda2) +epsi_calib = 0.01 +ixs_calib = find(ESP2_tilda(:, 4)>(rkcp2-epsi_calib) & ESP2_tilda(:, 4)<(rkcp2+epsi_calib) &... +ESP2_tilda(:, 6)>(cpol2-epsi_calib) & ESP2_tilda(:, 6)<(cpol2+epsi_calib)) +ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +length(ESP2_tilda2) +% ix_to_use = randperm(length(ESP2_tilda2), 20); +ix_to_use = 1:length(ESP2_tilda2); +% test params: +marray_thin = marray(:, :,1:20:end); +mstacked = marray_thin(:,:)'; +epsilon = .3; +ixs = cell(length(ix_to_use),1); +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +count = 0; +for i = 1:length(ix_to_use) +curr_calib = ESP2_tilda(ix_to_use(i), :); +% find the elements of mstacked that are within the set +kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon]; +kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon]; +ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)-3.02 & ESP2_tilda(:, 4)<-2.72 &... +% ESP2_tilda(:, 6)>2.49 & ESP2_tilda(:, 6)<2.80); +% length(ESP2_tilda2) +% ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +epsi_calib = 0.01 +ixs_calib = find(ESP2_tilda(:, 4)>(rkcp2-epsi_calib) & ESP2_tilda(:, 4)<(rkcp2+epsi_calib) &... +ESP2_tilda(:, 6)>(cpol2-epsi_calib) & ESP2_tilda(:, 6)<(cpol2+epsi_calib)) +ESP2_tilda2 = ESP2_tilda(ixs_calib,:); +length(ESP2_tilda2) +% ix_to_use = randperm(length(ESP2_tilda2), 20); +ix_to_use = 1:length(ESP2_tilda2); +% test params: +marray_thin = marray(:, :,1:20:end); +mstacked = marray_thin(:,:)'; +epsilon = .3; +ixs = cell(length(ix_to_use),1); +estParamsIx = setdiff((1:length(mai.masterVector))', mai.fixedParams); +count = 0; +for i = 1:length(ix_to_use) +curr_calib = ESP2_tilda(ix_to_use(i), :); +% find the elements of mstacked that are within the set +kf_range = [curr_calib(1)-epsilon curr_calib(1)+epsilon]; +kr_range = [curr_calib(2)-epsilon curr_calib(2)+epsilon]; +ixs{i} = find(mstacked(:, 1)>kf_range(1) & mstacked(:, 1)kr_range(1) & mstacked(:, 2)-2.89 & mstack(:, 4)<-2.85 &... +% mstack(:, 6)>2.63 & mstack(:, 6)<2.65); +% mcmc_plot(mstack(ixs,:), parnames(:)) +% +mcmc_plot(marray(:, 1:10:end,1:50:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +%% +% close +% marray_red = marray(:, :,((end-2600):10:end)); +% mstack = marray_red(:, :)'; +% ixs = find(mstack(:, 4)>-2.89 & mstack(:, 4)<-2.85 &... +% mstack(:, 6)>2.63 & mstack(:, 6)<2.65); +% mcmc_plot(mstack(ixs,:), parnames(:)) +% +mcmc_plot(marray(:, 1:10:end,1:200:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +analysis_test015calib +mcmc_plot(marray(:, 1:end,1:100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +analysis_test015calib +marray_red = marray(:, :,((end-2600):200:end)); +mstack = marray_red(:, :)'; +ixs = find(mstack(:, 4)>-3.1 & mstack(:, 4)<-2.8 &... +mstack(:, 6)>2.6 & mstack(:, 6)<2.8); +mcmc_plot(mstack(ixs,:), parnames(:)) +ESP2_tilda = mstack(ixs,:); +close all +% Plot trace and corner (posterior distribution) plots +% mcmc_plot(marray(:, 1:3:end,1:50:end), parnames(:)); +%% +% close +% marray_red = marray(:, :,((end-2600):10:end)); +% mstack = marray_red(:, :)'; +% ixs = find(mstack(:, 4)>-2.89 & mstack(:, 4)<-2.85 &... +% mstack(:, 6)>2.63 & mstack(:, 6)<2.65); +% mcmc_plot(mstack(ixs,:), parnames(:)) +% +mcmc_plot(marray(:, 1:end,1:5:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithTr'); +analysis_test015calib +mai +mai.estNames +analysis_test015corr1_Ffix3 +mai +mai.masterVector +mai.masterVector(mai.fixedParams) +analysis_test015corr1_Ffix3 +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'GFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{1,j} 'nM initial tetR DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +close all +clc +clear all +analysis_test015calib +epsi = 0.2; +analysis_test015corr1_Ffix3 +size(ESP2_tilda,1) +close all +clear all +clc +analysis_test015calib +close all +analysis_test015calib +size(ESP2_tilda) +hist(ESP2_tilda(:,3)) +hist(ESP2_tilda(:,3), 100) +figure; subplot(3,2,1); hist(ESP2_tilda(:,1), 100); subplot(3,2,2); hist(ESP2_tilda(:,2), 100); subplot(3,2,3); hist(ESP2_tilda(:,3), 100); ... +subplot(3,2,4); hist(ESP2_tilda(:,4), 100); subplot(3,2,5); hist(ESP2_tilda(:,5), 100); subplot(3,2,6); hist(ESP2_tilda(:,6), 100); +figure; +subplot(3,2,1); hist(ESP2_tilda(:,1), 100); title('kfdg') +subplot(3,2,2); hist(ESP2_tilda(:,2), 100); title('krdg') +subplot(3,2,3); hist(ESP2_tilda(:,3), 100); title('kcp1') +subplot(3,2,4); hist(ESP2_tilda(:,4), 100); title('kcp2') +subplot(3,2,5); hist(ESP2_tilda(:,5), 100); title('pol1') +subplot(3,2,6); hist(ESP2_tilda(:,6), 100); title('pol2') +close all +clear all +load('ESP2 points_pts1_ts20', 'ESP2_tilda') +size(ESP2_tilda) +analysis_test015corr1_Ffix3 +analysis_test015calib +clear all +clc +close all +analysis_test015calib +close all +analysis_test015calib +edit proj_test015.m +proj_test015 +model info +model_info +model_info.namesUnord +model_info.paramMaps +master_info.masterVector +master_info +master_info.estNames +mcmc_info +mcmc_info.runsim_info +mcmc_info.model_info +mcmc_info.model_info.namesUnord +mcmc_info.model_info.paramMaps +mi +mi.namesOrd +mi.orderingIx +mi.orderingIx2 +dbstack +mi.emp +mi.emo +get(mi.emo, 'ValueInfo') +vi = get(mi.emo, 'ValueInfo') +vi(1) +vi(2) +vi(3) +vi(4) +vi(5) +mvarray = masterVecArray(marray, mai); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +% +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,1),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'RNA'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial RNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(1)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E1'); +marrayOrd = mvarray(mi(1).paramMaps(mi(1).orderingIx,2),:,samplePoints); +titls = arrayfun(@num2str, mi(1).dosedVals, 'UniformOutput', false); +titls_array = cell(length(titls), 2, length(mi(1).measuredSpeciesIndex)); +ms = {'MG aptamer', 'deGFP'}; +for i = 1:length(mi(1).measuredSpeciesIndex) +for j = 1:length(titls) +titls_array(j, 1, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, Exp data']}; +titls_array(j, 2, i) = {[ms{i} ', ' titls{j} 'nM initial DNA, MCMC samples']}; +end +end +mcmc_trajectories(mi(1).emo, data_info(mi(1).dataToMapTo(2)), mi(1), marrayOrd,... +titls_array, {},... +'SimMode', 'meanstd', 'separateExpSim', false,... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'E2'); +close all +clear all +clc +clear non_empty +clear ixs +load('CSP_fixed_pts_ts20', 'CSP_fixed_pts') +whos +size(CSP_fixed_pts) +non_empty +close all +clear all +clc +size(marray) +analysis_test015calib_E1E2same +mcmc_plot(marray(:, 1:10:end,1:10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +edit proj_test015.m +analysis_test015calib +edit analysis_test015calib +analysis_test015corr1_Ffix3 +close all +clear all +analysis_test015corr1_Ffix3 +size(CSP_fixed_pts2) +size(CSP_fixed_pts) +size(CSP_fixed_pts2(1:20,:) +size(CSP_fixed_pts2(1:20,:)) +(CSP_fixed_pts2(1:20,:)) +load('CSP_fixed_pts_ts20', 'CSP_fixed_pts') +figure; +subplot(3,2,1); hist(CSP_fixed_pts(:,1), 100); title('kfdg') +subplot(3,2,2); hist(CSP_fixed_pts(:,2), 100); title('krdg') +subplot(3,2,3); hist(CSP_fixed_pts(:,3), 100); title('kcp1') +subplot(3,2,4); hist(CSP_fixed_pts(:,4), 100); title('kcp2') +subplot(3,2,5); hist(CSP_fixed_pts(:,5), 100); title('pol1') +subplot(3,2,6); hist(CSP_fixed_pts(:,6), 100); title('pol2') +(CSP_fixed_pts2(1:80,:)) +size(CSP_fixed_pts) +ixs_calib +CSP_fixed_pts(1:20,:) +CSP_fixed_pts(1:10000:end,:) +CSP_fixed_pts(1:5000:end,:) +load('CSP_fixed_pts_ts20', 'CSP_fixed_pts') +figure; +subplot(3,2,1); hist(CSP_fixed_pts(1:3000:end,1), 100); title('kfdg') +subplot(3,2,2); hist(CSP_fixed_pts(1:3000:end,2), 100); title('krdg') +subplot(3,2,3); hist(CSP_fixed_pts(1:3000:end,3), 100); title('kcp1') +subplot(3,2,4); hist(CSP_fixed_pts(1:3000:end,4), 100); title('kcp2') +subplot(3,2,5); hist(CSP_fixed_pts(1:3000:end,5), 100); title('pol1') +subplot(3,2,6); hist(CSP_fixed_pts(1:3000:end,6), 100); title('pol2') +load('CSP_fixed_pts_ts20', 'CSP_fixed_pts') +figure; +subplot(3,2,1); hist(CSP_fixed_pts(1:1000:end,1), 30); title('kfdg') +subplot(3,2,2); hist(CSP_fixed_pts(1:1000:end,2), 30); title('krdg') +subplot(3,2,3); hist(CSP_fixed_pts(1:1000:end,3), 30); title('kcp1') +subplot(3,2,4); hist(CSP_fixed_pts(1:1000:end,4), 30); title('kcp2') +subplot(3,2,5); hist(CSP_fixed_pts(1:1000:end,5), 30); title('pol1') +subplot(3,2,6); hist(CSP_fixed_pts(1:1000:end,6), 30); title('pol2') +ixs(non_empty){1}(1:10,:) +non_empty +ixs{1}(1:10,:) +ixs{2}(1:10,:) +ixs{2}(1:10,:size(CSP_fixed_pts,1)) +size(CSP_fixed_pts,1) +ixs_calib = 1:5000:size(CSP_fixed_pts,1); +ixs_calib +clc +clear non_empty +clear ixs +load('CSP_fixed_pts_ts20', 'CSP_fixed_pts') +close all +epsi_calib = 0.06; +ixs_calib = 1:5000:size(CSP_fixed_pts,1); +%find(ESP2_tilda(:, 4)>(rkcp2-epsi_calib) & ESP2_tilda(:, 4)<(rkcp2+epsi_calib) &... +% ESP2_tilda(:, 6)>(cpol2-epsi_calib) & ESP2_tilda(:, 6)<(cpol2+epsi_calib)) +CSP_fixed_pts2 = CSP_fixed_pts(ixs_calib,:); +length(CSP_fixed_pts2) +ix_to_use = randperm(length(CSP_fixed_pts2), 5) +clc +clear non_empty +clear ixs +load('CSP_fixed_pts_ts20', 'CSP_fixed_pts') +close all +epsi_calib = 0.06; +% CSP_fixed_pts = CSP_fixed_pts(1:2000:end,:); +ixs_calib = 1:size(CSP_fixed_pts,1); +%find(ESP2_tilda(:, 4)>(rkcp2-epsi_calib) & ESP2_tilda(:, 4)<(rkcp2+epsi_calib) &... +% ESP2_tilda(:, 6)>(cpol2-epsi_calib) & ESP2_tilda(:, 6)<(cpol2+epsi_calib)) +CSP_fixed_pts2 = CSP_fixed_pts(ixs_calib,:); +length(CSP_fixed_pts2) +ix_to_use = randperm(length(CSP_fixed_pts2), 10) +CSP_fixed_pts2(ix_to_use,:) +rkcp2 +cpol2 +CSP_fixed_pts2(ix_to_use,:) +ixs_calib +length(ixs_calib) +kf_range +kr_range +jpgsave = false; +size(marray) +size(mstacked) +marray_thin = marray(:, 1:end,1:400:end); +mstacked = marray_thin(:,:)'; +size(mstacked) +marray_thin = marray(:, 1:end,1:800:end); +mstacked = marray_thin(:,:)'; +size(mstacked) +mcmc_plot(marray(:, 1:end,(end-1000):20:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'all_WithoutTr'); +edit proj_test015_E1E2same.m +proj_test015_E1E2same +data_info +data_info(3) +proj_test015_E1E2same +da{1}(:,1,1,1,1) +da{1}(:,1,1,1,2) +analysis_test015calib_E1E2same +close all +%-- 3/25/19, 9:03 PM --% +dir mcmc_simbio/projects/ +%-- 3/28/19, 4:33 PM --% +sal = 5450 +bon = 8320 +bon/sal = +bon/sal +107/365 +prorate = 107/365 +rawmonth = bon/sal +rawmonth / prorate +%-- 4/4/19, 8:21 PM --% +m = model_txtl_pLacdeGFP +m.reactions +mtet = model_txtl_ptetdeGFP_pLactetR_aTc +mtet.reac +mtet.r +mtet.re +di = data_ZSIFFL; +mcmc_trajectories([], di(1), [], [], [], [], 'just_data_info', true) +mcmc_trajectories([], di(1:5), [], [], [], [], 'just_data_info', true) +close all +dir mcmc_simbio/projects/ +help dir +dir mcmc_simbio/projects/*.m +edit proj_VNPRL_mrna +edit proj_acs_dsg2014_regen_F1 +edit proj_test015_E1E2same +dir mcmc_simbio/models_and_supporting_files/*.m +dir mcmc_simbio/models_and_supporting_files/mcmc*.m +edit mcmc_info_vnprl_F2.m +dir mcmc_simbio/models_and_supporting_files/model* +edit mcmc_info_dsg2014_regen_F1.m +%-- 4/5/19, 2:23 PM --% +geneexpr +m +mobj +Mobj +Mobj.reaction +mplac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mplac.Reactions +mlas +mlas.reac +mtet.Reactions +%-- 4/9/19, 1:34 PM --% +mplac = model_txtl_pLacdeGFP +mplac +mplac.Reactions +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlas.Reactions +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mtet.reac +mlas = model_txtl_pLacLasR_pLasdeGFP; +tube +tube.Reactions +tube.Species +tube.reac +tube.spe +tube.reac +mlas = model_txtl_pLacLasR_pLasdeGFP; +tube.reac +tube.Species +mlas = model_txtl_pLacLasR_pLasdeGFP; +mlas.reac +mplac = model_txtl_pLacdeGFP; +mlas = model_txtl_pLacLasR_pLasdeGFP; +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mplac.reac +mplas/reac +mlas.reac +mtet.reac +mlac.param +mplac.Parameters +mlas.param +mlas.rules +mlas.eve +mtet.par +mtet.para +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +R +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +m +parnames +r +m.reactions +rx +edit txtl_protein_tetR.m +edit txtl_prom_ptet.m +rx +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +rx +edit txtl_protein_tetR.m +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +paramObj +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +regexp(protein.Name,'(^protein )') +protein.Name +regx = regexp(protein.Name,'(^protein )') +regx = regexp(protein.Name,'^protein ') +regx = regexp(protein.Name,'^protein ', 'split') +help regexp +regx = regexp(protein.Name,'^protein ', 'end') +protein.Name(regx+1:end) +edit txtl_transcription +edit txtl_enzyme_resource_degradation.m +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mtet.param +edit txtl_enzyme_resource_degradation.m +edit model_txtl_ptetdeGFP_pLactetR_aTc +model_txtl_ptetdeGFP_pLactetR_aTc +dir mcmc_simbio/exp_data/ +edit data_ZSIFFL +model_txtl_ptetdeGFP_pLactetR_aTc +mtet = model_txtl_ptetdeGFP_pLactetR_aTc +edit model_txtl_ptetdeGFP_pLactetR_aTc +mtet = model_txtl_ptetdeGFP_pLactetR_aTc +mtet.Parameters +mtet.even +mtet.rule +edit analysis_vnprl_F2.m +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. +'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % set from before +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 1e7] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 1000] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] %set to exp(-5.4) +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 100000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.005 1e7] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] +'Ribo' exp(7.3081) [1 10000]}; %26 +% +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; +estParams = activeNames2(estParamsIX,1); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:26)', estParamsIX); +activeNames2(estParamsIX,:) +activeNames2(fixedParamsIX, :) +log(activeNames2(estParamsIX,2)) +log(cell2mat(activeNames2(estParamsIX,2))) +help mat2cell +help num2cell +estARRAY = [activeNames2(estParamsIX,[1 2]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] +estARRAY = [activeNames2(estParamsIX,[1 2]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] +fixARRAY = [activeNames2(fixedParamsIX,[1 2]) num2cell(log(cell2mat(activeNames2(fixedParamsIX,2))))] +estARRAY = [activeNames2(estParamsIX,[1]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] +fixARRAY = [activeNames2(fixedParamsIX,[1]) num2cell(log(cell2mat(activeNames2(fixedParamsIX,2))))] +mtet = model_txtl_ptetdeGFP_pLactetR_aTc +mtet.Parameters +estARRAY = [activeNames2(estParamsIX,[1]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] +fixARRAY = [activeNames2(fixedParamsIX,[1]) num2cell(log(cell2mat(activeNames2(fixedParamsIX,2))))] +clear all +clc +%-- 4/13/19, 4:51 PM --% +exp(2.6) +exp(3.5) +EXP(8.8) +exp(8.8) +exp(5) +size(marray) +size(masterVecArray) +size(mvarray) +size(marrayOrd) +size(marray) +mcmc_plot(marray(:, 1:end,18000:100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray(:, 1:end,10000:400:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray(1:6, 1:end,10000:400:end), parnames(1:6),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray(7:end, 1:end,10000:400:end), parnames(7:end),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +close all +mcmc_plot(marray(1:6, 1:end,10000:100:end), parnames(1:6),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray(7:end, 1:end,10000:100:end), parnames(7:end),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +[exp(5) exp(20)] +format short g +[exp(5) exp(20)] +%-- 4/14/19, 10:11 AM --% +mcmc_plot(marray(1:6, 1:end,10000:100:end), parnames(1:6),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray(7:end, 1:end,10000:100:end), parnames(7:end),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray(:, 1:end,10000:400:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +dir mcmc_simbio/ +dir mcmc_simbio/src +edit mcmc_cut +mai.paramRanges +mai +mai.estNames +mai +mai.paramRanges([7,9], :) +parRanges = mai.paramRanges +parRanges([7,9], :) = [-2.5, 1.9;3.5, 10.75] +parRanges([7,9], :) = [-2.5, 1.9;3.5, 10.75] +marray_cut = mcmc_cut(marray, [7, 9], flipud((parRanges)')); +mcmc_plot(marray_cut(:, 1:end,(end-18000):100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +whos +parRanges = mai.paramRanges; +parRanges([7,9], :) = [-2.5, 1.9;3.5, 10.75] +marray_cut = mcmc_cut(marray, [7, 9], flipud((parRanges)')); +marray_cut = mcmc_cut(marray, [7, 9], flipud((parRanges)')); +flipud((parRanges)') +flipud((pRanges)')flipud((parRanges)') +flipud((pRanges)')) +flipud((pRanges)') +parRanges = mai.paramRanges +mai +parRanges = mai.paramRanges +marray_cut = mcmc_cut(marray, [7, 9], flipud((parRanges)')) +edit rowvec +help rowvec +parRanges = mai.paramRanges; +parRanges([7,9], :) = [-2.5, 1.9;3.5, 10.75] +marray_cut = mcmc_cut(marray, [7, 9], flipud((parRanges([7 9]))')); +mcmc_plot(marray_cut(:, 1:end,(end-18000):100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +parRanges +marray_cut = mcmc_cut(marray, [7, 9], flipud((parRanges([7 9], :))')); +size(marray_cut) +mcmc_plot(marray_cut(:, 1:end,(end-10000):100:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +parRanges = mai.paramRanges; +parRanges([7,9], :) = [-1.863, 1.9;3.5, 10.75] +marray_cut = mcmc_cut(marray, [7, 9], flipud((parRanges([7 9], :))')); +mcmc_plot(marray_cut(:, 1:end,(end-10000):500:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray_cut(1:6, 1:end,10000:100:end), parnames(1:6),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray_cut(7:end, 1:end,10000:100:end), parnames(7:end),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedInAllWalkers'); +mcmc_plot(marray_cut(:, 1:end,10000:500:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +parRanges([7,9], :) = [-0.2966 0.1031; 8.298 8.738]; +marray_cut = mcmc_cut(marray, [7,9], flipud((parRanges([7 9], :))')); +mcmc_plot(marray_cut(:, 1:end,10000:10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +size(marray_cut) +mcmc_plot(marray_cut(:, 1:end,1:10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray_cut(:, 1:end,ceil(end/3):10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +parRanges([6,9], :) = [15.59 15.73 ; 8.385 8.622]; +marray_cut = mcmc_cut(marray, [6,9], flipud((parRanges([6 9], :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/3):5:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +close a +close +parRanges([6,7, 9], :) = [15.59 15.73 ; +-0.2966 0.1031; +8.385 8.622]; +marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/3):5:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +parRanges([6,7, 9], :) = [15.65 15.73 ; +-0.039 0.02126; +8.386 8.461 ]; +marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +parRanges([6,7, 9], :) = [15.59 15.73 ; +-0.2966 0.1031; +8.385 8.622]; +marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +mcmc_3D(marray_cut([6 7 9], 1:end,ceil(end/4):end), parnames([6 7 9]), 'RNA deg covariation') +size(marray_cut) +size(marray_cut([6 7 9], 1:end,ceil(end/4):end)) +mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') +help meshgrid +meshkdcat = meshgrid(linspace([15.65 15.73]), linspace([-0.039 0.02126])) +meshkdcat = meshgrid(linspace([15.65 15.73], 10), linspace([-0.039 0.02126],10)) +help linspace +meshkdcat = meshgrid(linspace(15.65 15.73, 10), linspace(-0.039 0.02126,10)) +meshkdcat = meshgrid(linspace(15.65, 15.73, 10), linspace(-0.039, 0.02126,10)) +meshcatase = meshgrid(linspace(-0.039, 0.02126,10), linspace(8.386, 8.461, 10), ) +meshcatase = meshgrid(linspace(-0.039, 0.02126,10), linspace(8.386, 8.461, 10) ) +meshKdase= meshgrid(linspace(15.65, 15.73, 10), linspace(8.386, 8.461, 10) ) +help fill3 +help mesh +close all +parRanges([6,7, 9], :) = [15.59 15.73 ; +-0.2966 0.1031; +8.385 8.622]; +marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +parRanges(paramIndices, :) = [... +2.3 2.95; %1 +8.6 8.95; %2 +-10.1 -9.7; %3 +13.5 14.5; %4 +-1 5 ; %5 +15.59 15.73; %6 +-0.2966 0.1031; %7 +1 1.8; %8 +8.385 8.622;%9 +3.18 3.69; % 10 -- TLcat +-3 13.5;%RiboKd +2.2 2.6;% Ribo term +3 4 ];% Ribo +marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +close all +paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +parRanges(paramIndices, :) = [... +2.3 2.95; %1 +8.6 8.95; %2 +-10.1 -9.7; %3 +13 15; %4 +-1 5 ; %5 +15.59 15.73; %6 +-0.2966 0.1031; %7 +0.7 2.2; %8 +8.385 8.622;%9 +3.18 3.69; % 10 -- TLcat +-3 13.5;%RiboKd +2 3;% Ribo term +3 4.6 ];% Ribo +marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +parRanges([7,9], :) = [-0.2966 0.1031; 8.298 8.738]; +marray_cut = mcmc_cut(marray, [7,9], flipud((parRanges([7 9], :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/3):10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') +oCandidateParams = marray_cut(:,:,end) +oCandidateParams = marray_cut(:,1:10:end,end) +oCandidateParams = marray_cut(:,1:100:end,end) +oCandidateParams = marray_cut(:,1:80:end,end) +parnames +parnames([6 7 9]) +mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') +parnames +mtet = model_txtl_ptetdeGFP_pLactetR_aTc +mtet.Parameters +mtet.Species +exp(8.5) +exp(3.75) +exp(1.4419) +EstimatedParams =[... +1.7214 2.2150 1.9129 2.8813 1.9206 1.8227 1.7988 1.9129 2.8933 1.9129 1.9129 2.9532 1.2016 2.4114 1.2010 +7.5328 8.8082 8.7341 8.9006 8.6899 8.6647 8.7718 8.7341 8.7898 8.7341 8.7341 8.8455 7.5343 8.8161 7.5873 +-14.8727 -9.8416 -9.7383 -9.9196 -9.8184 -9.9059 -9.7755 -9.7383 -9.9750 -9.7383 -9.7383 -9.9564 -12.2002 -10.0040 -12.2410 +0.2732 13.3223 1.9202 14.1785 -4.0507 3.1690 -0.9288 1.9202 14.0184 1.9202 1.9202 14.0528 -2.0771 13.6801 -2.1193 +1.8090 4.1443 4.2077 2.8498 -0.2423 3.6222 6.1661 4.2077 2.6321 4.2077 4.2077 6.8439 1.8918 -0.0937 0.8244 +15.8692 15.6993 15.7065 15.8548 15.9099 15.8929 15.8031 15.7065 15.6317 15.7065 15.7065 15.7650 15.3658 15.9196 15.8506 +0.0064 -0.2471 0.0346 -0.1201 0.0127 -0.0695 -0.0200 0.0346 0.0695 0.0346 0.0346 0.0223 -0.1934 0.0113 -0.1089 +2.2668 1.8478 2.0623 1.2667 2.0964 2.1888 2.1649 2.0623 1.2365 2.0623 2.0623 1.1738 5.6302 1.6939 5.3141 +8.6165 8.6996 8.4251 8.7288 8.6508 8.7161 8.5770 8.4251 8.3158 8.4251 8.4251 8.4971 8.3127 8.6617 8.7136 +4.0941 4.6648 3.1164 3.8744 3.5745 3.0612 3.5962 3.1164 3.4550 3.1164 3.1164 3.3135 3.8037 3.4360 3.5834 +12.6096 14.2733 4.2841 8.2831 16.0856 -4.8711 12.7940 4.2841 2.0779 4.2841 4.2841 6.1993 12.4489 1.8138 4.6891 +2.7504 6.1502 2.9274 2.0641 2.2956 6.4824 3.5291 2.9274 2.2867 2.9274 2.9274 2.3566 6.5085 2.3352 5.7604 +3.6967 2.6849 4.9000 7.7984 7.5775 3.6345 3.4997 4.9000 9.1144 4.9000 4.9000 9.1339 3.1382 6.7332 3.2369]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesInMasterVector = [1 3 5 7 23 15 30 31 32 2 6 28 33]; +masterVector = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] +'TXTL_UTR_UTR1_Kd' , exp(-0.2), [exp(-2) exp(2)] +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(0) exp(5)] %10 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] +'TL_AA_Kd' , exp(6.6), [exp(0) exp(5)] %13 +'TL_AGTP_Kd' , exp(14.5), [exp(0) exp(5)] +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] +'TXTL_PLAC_RNAPbound_Kd' , exp(2.6), [exp(5) exp(17)] +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 +'TXTL_RNAdeg_F' , exp(0), [exp(0) exp(5)] +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] +'RNAP' , exp(1.4419), [exp(-1) exp(4)] % 31 +'RNase' , exp(8.5), [exp(5) exp(10)] +'Ribo' , exp(3.75), [exp(1) exp(6)] }; %33 +% Set the master vector values. +masterVector(indicesInMasterVector, 2) = exp(paramVecToUse) +% Set the master vector values. +masterVector(indicesInMasterVector, 2) = num2cell(exp(paramVecToUse)) +cell2num(masterVector(indicesInMasterVector, 2)) +cell2mat(masterVector(indicesInMasterVector, 2)) +log(cell2mat(masterVector(indicesInMasterVector, 2))) +masterVector(indicesInMasterVector, 1) +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +6 'TXTL_UTR_UTR1_Kd' , exp( -0.2000) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; +cell2mat(preFixedParams(:,1)) +masterVector(cell2mat(preFixedParams(:,1)),:) +masterVector = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] +'TXTL_UTR_UTR1_Kd' , exp(-0.2), [exp(-2) exp(2)] +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(0) exp(5)] %10 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] +'TL_AA_Kd' , exp(6.6), [exp(0) exp(5)] %13 +'TL_AGTP_Kd' , exp(14.5), [exp(0) exp(5)] +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] +'TXTL_PLAC_RNAPbound_Kd' , exp(2.6), [exp(5) exp(17)] +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 +'TXTL_RNAdeg_F' , exp(0), [exp(0) exp(5)] +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] +'RNAP' , exp(1.4419), [exp(-1) exp(4)] % 31 +'RNase' , exp(8.5), [exp(5) exp(10)] +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; +% Set the master vector values that are set from the values estimated in "vnprl_F2" +masterVector(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +6 'TXTL_UTR_UTR1_Kd' , exp( -0.2000) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; +masterVector(cell2mat(preFixedParams(:,1)),:) +indicesMasterVectorEstimated = [1 3 5 7 23 15 30 31 32 2 6 28 33]; +masterVector = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] +'TXTL_UTR_UTR1_Kd' , exp(-0.2), [exp(-2) exp(2)] +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(0) exp(5)] %10 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] +'TL_AA_Kd' , exp(6.6), [exp(0) exp(5)] %13 +'TL_AGTP_Kd' , exp(14.5), [exp(0) exp(5)] +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] +'TXTL_PLAC_RNAPbound_Kd' , exp(2.6), [exp(5) exp(17)] +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 +'TXTL_RNAdeg_F' , exp(0), [exp(0) exp(5)] +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] +'RNAP' , exp(1.4419), [exp(-1) exp(4)] % 31 +'RNase' , exp(8.5), [exp(5) exp(10)] +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; +% Set the master vector values that are set from the values estimated in "vnprl_F2" +masterVector(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +6 'TXTL_UTR_UTR1_Kd' , exp( -0.2000) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; +masterVector(cell2mat(preFixedParams(:,1)),:) +masterVector(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3) +masterVector(cell2mat(preFixedParams(:,1)),:) +masterVector(cell2mat(preFixedParams(:,1)),3) +masterVector{cell2mat(preFixedParams(:,1)),3} +cell2mat(masterVector(cell2mat(preFixedParams(:,1)),3)) +[cell2mat(masterVector(cell2mat(preFixedParams(:,1)),2)) cell2mat(masterVector(cell2mat(preFixedParams(:,1)),3))] +format short g; [cell2mat(masterVector(cell2mat(preFixedParams(:,1)),2)) cell2mat(masterVector(cell2mat(preFixedParams(:,1)),3))] +format short g; aa = [cell2mat(masterVector(cell2mat(preFixedParams(:,1)),2)) cell2mat(masterVector(cell2mat(preFixedParams(:,1)),3))] +aa(:,1)aa(:,2) +[-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2)] +%-- 4/15/19, 8:40 PM --% +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 7 +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +EstimatedParams =[... +1.7214 2.2150 1.9129 2.8813 1.9206 1.8227 1.7988 1.9129 2.8933 1.9129 1.9129 2.9532 1.2016 2.4114 1.2010 +7.5328 8.8082 8.7341 8.9006 8.6899 8.6647 8.7718 8.7341 8.7898 8.7341 8.7341 8.8455 7.5343 8.8161 7.5873 +-14.8727 -9.8416 -9.7383 -9.9196 -9.8184 -9.9059 -9.7755 -9.7383 -9.9750 -9.7383 -9.7383 -9.9564 -12.2002 -10.0040 -12.2410 +0.2732 13.3223 1.9202 14.1785 -4.0507 3.1690 -0.9288 1.9202 14.0184 1.9202 1.9202 14.0528 -2.0771 13.6801 -2.1193 +1.8090 4.1443 4.2077 2.8498 -0.2423 3.6222 6.1661 4.2077 2.6321 4.2077 4.2077 6.8439 1.8918 -0.0937 0.8244 +15.8692 15.6993 15.7065 15.8548 15.9099 15.8929 15.8031 15.7065 15.6317 15.7065 15.7065 15.7650 15.3658 15.9196 15.8506 +0.0064 -0.2471 0.0346 -0.1201 0.0127 -0.0695 -0.0200 0.0346 0.0695 0.0346 0.0346 0.0223 -0.1934 0.0113 -0.1089 +2.2668 1.8478 2.0623 1.2667 2.0964 2.1888 2.1649 2.0623 1.2365 2.0623 2.0623 1.1738 5.6302 1.6939 5.3141 +8.6165 8.6996 8.4251 8.7288 8.6508 8.7161 8.5770 8.4251 8.3158 8.4251 8.4251 8.4971 8.3127 8.6617 8.7136 +4.0941 4.6648 3.1164 3.8744 3.5745 3.0612 3.5962 3.1164 3.4550 3.1164 3.1164 3.3135 3.8037 3.4360 3.5834 +12.6096 14.2733 4.2841 8.2831 16.0856 -4.8711 12.7940 4.2841 2.0779 4.2841 4.2841 6.1993 12.4489 1.8138 4.6891 +2.7504 6.1502 2.9274 2.0641 2.2956 6.4824 3.5291 2.9274 2.2867 2.9274 2.9274 2.3566 6.5085 2.3352 5.7604 +3.6967 2.6849 4.9000 7.7984 7.5775 3.6345 3.4997 4.9000 9.1144 4.9000 4.9000 9.1339 3.1382 6.7332 3.2369]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 7 23 15 30 31 32 2 6 28 33]; +masterVector = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] +'TXTL_UTR_UTR1_Kd' , exp(-0.2), [exp(-2) exp(2)] +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(0) exp(5)] %10 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] +'TL_AA_Kd' , exp(6.6), [exp(0) exp(5)] %13 +'TL_AGTP_Kd' , exp(14.5), [exp(0) exp(5)] +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] +'TXTL_PLAC_RNAPbound_Kd' , exp(2.6), [exp(5) exp(17)] +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 +'TXTL_RNAdeg_F' , exp(0), [exp(0) exp(5)] +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] +'RNAP' , exp(1.4419), [exp(-1) exp(4)] % 31 +'RNase' , exp(8.5), [exp(5) exp(10)] +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; +% Set the master vector values that are set from the values estimated in "vnprl_F2" +masterVector(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +6 'TXTL_UTR_UTR1_Kd' , exp( -0.2000) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; +masterVector(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; aa = [cell2mat(masterVector(cell2mat(preFixedParams(:,1)),2)) cell2mat(masterVector(cell2mat(preFixedParams(:,1)),3))] +[-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2)] +[-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))'] +aa +num2cell(aa) +[num2cell(aa) (masterVector(cell2mat(preFixedParams(:,1)),1))] +[num2cell(aa) (masterVector(cell2mat(preFixedParams(:,1)),1)) num2cell(preFixedParams(:,1))] +num2cell(preFixedParams(:,1)) +(preFixedParams(:,1)) +[num2cell(aa) (masterVector(cell2mat(preFixedParams(:,1)),1)) preFixedParams(:,1)] +[num2cell(aa) (masterVector(cell2mat(preFixedParams(:,1)),1)) preFixedParams(:,1) [-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))']] +[num2cell(aa) (masterVector(cell2mat(preFixedParams(:,1)),1)) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))'])] +[num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))] +[num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))]sfawfaefaw +aa = [cell2mat(leg(masterVector(cell2mat(preFixedParams(:,1)),2))) cell2mat(log(masterVector(cell2mat(preFixedParams(:,1)),3)))] +aa = [cell2mat(log(masterVector(cell2mat(preFixedParams(:,1)),2))) cell2mat(log(masterVector(cell2mat(preFixedParams(:,1)),3)))] +aa = [log(cell2mat(masterVector(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(masterVector(cell2mat(preFixedParams(:,1)),3)))] +[num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))] +cell2table +cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))]) +ans.Properties +cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))], 'w) +help cell2table +cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))], 'VariableNames', {'logval', 'log lb', 'log ub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))], 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +masterVector = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] +'TXTL_UTR_UTR1_Kd' , exp(-0.2), [exp(-2) exp(2)] +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] +'TL_AA_Kd' , exp(6.6), [exp(0) exp(5)] %13 +'TL_AGTP_Kd' , exp(14.5), [exp(0) exp(5)] +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] +'TXTL_PLAC_RNAPbound_Kd' , exp(2.6), [exp(5) exp(17)] +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 +'TXTL_RNAdeg_F' , exp(0), [exp(0) exp(5)] +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] +'RNAP' , exp(1.4419), [exp(-1) exp(4)] % 31 +'RNase' , exp(8.5), [exp(5) exp(10)] +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; +% Set the master vector values that are set from the values estimated in "vnprl_F2" +masterVector(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +6 'TXTL_UTR_UTR1_Kd' , exp( -0.2000) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; +masterVector(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; aa = [log(cell2mat(masterVector(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(masterVector(cell2mat(preFixedParams(:,1)),3)))] +cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +masterVector = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] +'TXTL_UTR_UTR1_Kd' , exp(-0.2), [exp(-2) exp(2)] +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] +'TXTL_PLAC_RNAPbound_Kd' , exp(2.6), [exp(5) exp(17)] +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] +'RNAP' , exp(1.4419), [exp(-1) exp(4)] % 31 +'RNase' , exp(8.5), [exp(5) exp(10)] +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; +% Set the master vector values that are set from the values estimated in "vnprl_F2" +masterVector(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +6 'TXTL_UTR_UTR1_Kd' , exp( -0.2000) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +masterVector(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; aa = [log(cell2mat(masterVector(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(masterVector(cell2mat(preFixedParams(:,1)),3)))] +cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +ans.ubdiff ./ ans.lbdiff +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (masterVector(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +edit mcmc_info_vnprl_F2.m +dir mcmc_simbio/projects/ +edit proj_ZSIFFL_mtet.m +mtet = model_txtl_ptetdeGFP_pLactetR_aTc +mtet.Species +paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +parRanges(paramIndices, :) = [... +2.3 2.95; %1 +8.6 8.95; %2 +-10.1 -9.7; %3 +13 15; %4 +-1 5 ; %5 +15.59 15.73; %6 +-0.2966 0.1031; %7 +0.7 2.2; %8 pol +8.385 8.622;%9 RNase +3.18 3.69; % 10 -- TLcat +-3 13.5;%RiboKd +2 3;% Ribo term +3 4.6 ];% Ribo +marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +CandidateParams = marray_cut(:,:,end) +activeNames1 = {... +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-7 10] +'RNase' exp(6.4899) [1 100000]}; +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. +'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % set from before +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 1e7] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 1000] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] %set to exp(-5.4) +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 100000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.005 1e7] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] +'Ribo' exp(7.3081) [1 10000]}; %26 +% +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; +estParams = activeNames2(estParamsIX,1) +CandidateParams(:,1:100:end,:) +%-- 4/17/19, 9:17 PM --% +activeNames1 = {... +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-7 10] +'RNase' exp(6.4899) [1 100000]}; +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. +'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % set from before +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 1e7] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 1000] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] %set to exp(-5.4) +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 100000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.005 1e7] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] +'Ribo' exp(7.3081) [1 10000]}; %26 +% +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; +estParams = activeNames2(estParamsIX,1); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:26)', estParamsIX); +estARRAY = [activeNames2(estParamsIX,[1]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] +fixARRAY = [activeNames2(fixedParamsIX,[1]) num2cell(log(cell2mat(activeNames2(fixedParamsIX,2))))] +clear all +parRanges = mai.paramRanges; +paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +parRanges(paramIndices, :) = [... +2.3 2.95; %1 +8.6 8.95; %2 +-10.1 -9.7; %3 +13 15; %4 +-1 5 ; %5 +15.59 15.73; %6 +-0.2966 0.1031; %7 +0.7 2.2; %8 pol +8.385 8.622;%9 RNase +3.18 3.69; % 10 -- TLcat +-3 13.5;%RiboKd +2 3;% Ribo term +3 4.6 ];% Ribo +marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +CandidateParams = marray_cut(:,1:100:end,end) +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 7 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 % fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] % from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] % from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7% TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] % fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] % fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10% fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] % TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] % TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13% fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] % fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] % from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] % TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] % TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19% TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] % fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] % from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22% fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] % from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] % fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25% fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] % fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] % fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28% from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] % fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] % from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] % 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] % from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33% from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; % fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +activeNames(indicesMasterVectorEstimated, 2) +log(cell2mat(activeNames(indicesMasterVectorEstimated, 2) )) +%-- 4/17/19, 10:22 PM --% +activeNames1 = {... +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-7 10] +'RNase' exp(6.4899) [1 100000]}; +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. +'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % set from before +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 1e7] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 1000] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] %set to exp(-5.4) +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 100000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.005 1e7] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] +'Ribo' exp(7.3081) [1 10000]}; %26 +% +% {'AGTPreg_ON' } +% {'TXTL_P70_RNAPbound_F' } +% {'TXTL_NTP_RNAP_1_Kd' } +% {'TXTL_NTP_RNAP_1_F' } +% {'TXTL_NTP_RNAP_2_Kd' } +% {'TXTL_NTP_RNAP_2_F' } +% {'TXTL_RNAdeg_F' } +% {'TXTL_UTR_UTR1_F' } +% {'TL_AA_Kd' } +% {'TL_AA_F' } +% {'TL_AGTP_Kd' } +% {'TL_AGTP_F' } +% {'TXTL_PROT_deGFP_MATURATION' } +% are fixed at the values above. +% 3. regen_F: +% estimate all 13 remaining params: +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +%% +% Names of parameters and species to actually estimate. +estParamsIX = [1 2 3 5 7 12 14 15 16 17 19 25 26]'; +estParams = activeNames2(estParamsIX,1); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:26)', estParamsIX); +estARRAY = [activeNames2(estParamsIX,[1]) num2cell(log(cell2mat(activeNames2(estParamsIX,2))))] +fixARRAY = [activeNames2(fixedParamsIX,[1]) num2cell(log(cell2mat(activeNames2(fixedParamsIX,2))))] +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 % fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] % from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] % from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7% TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] % fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] % fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10% fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] % TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] % TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13% fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] % fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] % from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] % TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] % TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19% TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] % fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] % from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22% fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] % from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] % fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25% fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] % fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] % fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28% from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] % fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] % from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] % 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] % from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33% from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; % fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +estParamsIX = [7, 11, 12, 16:19]'; +estParams = activeNames(estParamsIX,1); +estParams +mtet = model_txtl_ptetdeGFP_pLactetR_aTc +mtet.Species +mtet.param +edit mcmc_info_constgfp3tetR1.m +mtet.name +di = data_ZSIFFL +di +di(1) +di(3) +di(4) +mi = mcmc_info_ZSIFFL_mtet_phase1 +mi = mcmc_info_ZSIFFL_mtet_phase1(mtet) +[mi, ac] = mcmc_info_ZSIFFL_mtet_phase1(mtet) +proj_ZSIFFL_mtet +ii +proj_ZSIFFL_mtet +pIX_TopoGeom = mi(i).paramMaps(mi(i).orderingIx, j) +mi(i).paramMaps +mi(i).orderingIx +length(mi(i).orderingIx) +length(mi(i).paramMaps) +proj_ZSIFFL_mtet +errmsg2 +m.ValueInfo(i) +m.ValueInfo(i+1) +m.ValueInfo(36).Name) +m.ValueInfo(36).Name +m.ValueInfo(34).Name +m.ValueInfo(36).Name +m.ValueInfo(35).Name +m.ValueInfo(37).Name +pn +m +m.ValueInfo +for i = 1:37 +modelValues{i} = m.ValueInfo.Name; +end +modelValues +for i = 1:37 +modelValues{i} = m.ValueInfo(i).Name; +end +modelValues' +proj_ZSIFFL_mtet +mi(1).dosedNames +mi(3).dosedNames +mi(2).dosedNames +ds +mi(2).dosedNames +ds +mi(3).dosedNames +length(mi(i).dosedNames) +mi(i).dosedNames +mi(i).dosedNames{1} +sbioselect(mobj, 'Type', 'species', 'Name',mi(i).dosedNames{1}) +sbioselect(mobj, 'Type', 'species', 'Name',mi(i).dosedNames) +ds.Name +ds(1).Name +ds(1).Name == mi(i).dosedNames +cellfun(strcmp, {ds(1).Name}, mi)(i).dosedNames +cellfun(strcmp, {ds(1).Name}, mi(i).dosedNames) +cellfun(strcmp, {ds(1).Name}, mi(i).dosedNames, 'UniformOutput', true) +help cellfun +cellfun(@strcmp, {ds(1).Name}, mi(i).dosedNames, 'UniformOutput', true) +cellfun(@(x) strcmp({ds(1).Name}, x), mi(i).dosedNames, 'UniformOutput', true) +cellfun(@(x) strcmp({ds(2).Name}, x), mi(i).dosedNames, 'UniformOutput', true) +find(cellfun(@(x) strcmp({ds(2).Name}, x), mi(i).dosedNames, 'UniformOutput', true)) +mi(i).dosedNames(doseOrderingIx) +mi +mi.model_info +mi.model_info(3) +proj_ZSIFFL_mtet +mi(i).dosedNames(doseOrderingIx) +mi(i).dosedVals(doseOrderingIx,:) +edit data_ZSIFFL +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 % fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 % fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 % fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19% TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22% fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25% fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 % from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% +% Names of parameters and species to actually estimate. +% As mentioned above, I have planned this out in the file +% ZachIFFL_estimation_strategy.txt +% 'TX_elong_glob' , 'fix' +% 'TL_elong_glob' , 'fix' +% 'AGTPdeg_time' , 'fix' +% 'AGTPreg_ON' , 'fix' +% 'AGTPdeg_rate' , 'fix' +% 'TXTL_PROT_deGFP_MATURATION' , 'fix' +% 'TXTL_UTR_UTR1_Kd' , 'fix' +% 'TXTL_PTET_RNAPbound_Kd' , 'est' +% 'TXTL_PTET_RNAPbound_F' , 'fix' +% 'TXTL_NTP_RNAP_1_Kd' , 'fix' +% 'TXTL_NTP_RNAP_2_Kd' , 'fix' +% 'TXTL_PTET_sequestration_Kd' , 'est' +% 'TXTL_PTET_sequestration_F' , 'est' +% 'TL_AA_Kd' , 'fix' +% 'TL_AGTP_Kd' , 'fix' +% 'TXTL_RNAdeg_Kd' , 'fix' +% 'TXTL_INDUCER_TETR_ATC_Kd' , 'est' +% 'TXTL_INDUCER_TETR_ATC_F' , 'est' +% 'TXTL_DIMER_tetR_Kd' , 'est' +% 'TXTL_DIMER_tetR_F' , 'est' +% 'TXTL_UTR_UTR1_F' , 'fix' +% 'TXTL_PLAC_RNAPbound_Kd' , 'fix' +% 'TXTL_PLAC_RNAPbound_F' , 'fix' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , 'fix' +% 'TXTL_NTP_RNAP_1_F' , 'fix' +% 'TXTL_NTP_RNAP_2_F' , 'fix' +% 'TL_AA_F' , 'fix' +% 'TL_AGTP_F' , 'fix' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , 'fix' +% 'TXTL_RNAdeg_F' , 'fix' +% 'TXTL_RNAdeg_kc' , 'fix' +% Thus, the 7 estimated parameters are: +% 'TXTL_PTET_RNAPbound_Kd' , 'est' +% 'TXTL_PTET_sequestration_Kd' , 'est' +% 'TXTL_PTET_sequestration_F' , 'est' +% 'TXTL_INDUCER_TETR_ATC_Kd' , 'est' +% 'TXTL_INDUCER_TETR_ATC_F' , 'est' +% 'TXTL_DIMER_tetR_Kd' , 'est' +% 'TXTL_DIMER_tetR_F' , 'est' +estParamsIX = [7, 11, 12, 16:19]'; +estParams = activeNames(estParamsIX,1) +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 % fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 % fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 % fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19% TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22% fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25% fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 % from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +% Thus, the 10 estimated parameters are: +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +estParamsIX = [7, 11, 12, 16:19]'; +estParams = activeNames(estParamsIX,1) +mlac = model_txtl_pLacdeGFP.m +mlac = model_txtl_pLacdeGFP +mlac.Parameters +mlac.Spe +proj_ZSIFFL_mtet_phase2 +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +edit proj_ZSIFFL_mtet.m +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +% !! NEED TO CHECK IF AT THE PICKED POINT THE TRAJECTORIES LOOK OK. +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 % fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 % fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 % fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19% TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22% fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25% fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 % from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% +% Names of parameters and species to actually estimate. +% As mentioned above, I have planned this out in the file +% ZachIFFL_estimation_strategy.txt +% 'TX_elong_glob' , 'fix' +% 'TL_elong_glob' , 'fix' +% 'AGTPdeg_time' , 'fix' +% 'AGTPreg_ON' , 'fix' +% 'AGTPdeg_rate' , 'fix' +% 'TXTL_PROT_deGFP_MATURATION' , 'fix' +% 'TXTL_UTR_UTR1_Kd' , 'fix' +% 'TXTL_PTET_RNAPbound_Kd' , 'est' +% 'TXTL_PTET_RNAPbound_F' , 'fix' +% 'TXTL_NTP_RNAP_1_Kd' , 'fix' +% 'TXTL_NTP_RNAP_2_Kd' , 'fix' +% 'TXTL_PTET_sequestration_Kd' , 'est' +% 'TXTL_PTET_sequestration_F' , 'est' +% 'TL_AA_Kd' , 'fix' +% 'TL_AGTP_Kd' , 'fix' +% 'TXTL_RNAdeg_Kd' , 'fix' +% 'TXTL_INDUCER_TETR_ATC_Kd' , 'est' +% 'TXTL_INDUCER_TETR_ATC_F' , 'est' +% 'TXTL_DIMER_tetR_Kd' , 'est' +% 'TXTL_DIMER_tetR_F' , 'est' +% 'TXTL_UTR_UTR1_F' , 'fix' +% 'TXTL_PLAC_RNAPbound_Kd' , 'fix' +% 'TXTL_PLAC_RNAPbound_F' , 'fix' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , 'fix' +% 'TXTL_NTP_RNAP_1_F' , 'fix' +% 'TXTL_NTP_RNAP_2_F' , 'fix' +% 'TL_AA_F' , 'fix' +% 'TL_AGTP_F' , 'fix' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , 'fix' +% 'TXTL_RNAdeg_F' , 'fix' +% 'TXTL_RNAdeg_kc' , 'fix' +% Thus, the 7 estimated parameters are: +% 'TXTL_PTET_RNAPbound_Kd' , 'est' +% 'TXTL_PTET_sequestration_Kd' , 'est' +% 'TXTL_PTET_sequestration_F' , 'est' +% 'TXTL_INDUCER_TETR_ATC_Kd' , 'est' +% 'TXTL_INDUCER_TETR_ATC_F' , 'est' +% 'TXTL_DIMER_tetR_Kd' , 'est' +% 'TXTL_DIMER_tetR_F' , 'est' +estParamsIX = [7, 11, 12, 16:19]'; +estParams = activeNames(estParamsIX,1) +clc +clear all +mcmc_plot(marray(:, 1:end,1:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +close al +close all +%-- 4/23/19, 5:35 AM --% +whos +data_info +mi +mi(3).dataToMapTo +mi(2).dataToMapTo +mi(1).dataToMapTo +data_info(mi(1).dataToMapTo) +data_info(mi(1).dataToMapTo).measuredNames +data_info(mi(1).dataToMapTo).measuredNames{1} +data_info(mi(1).dataToMapTo).measuredNames{1}{1} +data_info(mi(2).dataToMapTo).measuredNames{1}{1} +data_info(mi(3).dataToMapTo).measuredNames{1}{1} +edit mcmc_info_vnprl_F2.m +edit proj_vnprl_F2.m +edit proj_vnprl.m +ddii = data_VNPRL2011; +ddii.measuredNames +data_info.measuredNames +edit data_ZSIFFL.m +data_info.dosedNames +data_info(1).dosedNames +data_info(1).dosedNames{1} +mi +mi(3) +data_info(mi(3).dataToMapTo).measuredNames +data_info(mi(3).dataToMapTo).measuredNames{1} +help isstr +exp(-25) +parRanges([1], :) = [-1.16, -0.92 ] +marray_cut = mcmc_cut(marray, [1], flipud((parRanges([1], :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut([1], 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames([1]), 'RNA deg covariation') +parRanges([1], :) = [-1.16, -0.92 ] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), [1], flipud((parRanges([1], :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut([1], 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames([1]), 'RNA deg covariation') +parIDs = [1 2 3]; +parRanges(parIDs, :) = [-1.16, -0.92 ; +-4 -0.5; +-8.5 -15] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +clc +parIDs = [1 2 3]; +parRanges(parIDs, :) = [-1.16, -0.92 ; +-4 -0.5; +-8.5 -15] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +parRanges +parIDs = [1 2 3]; +parRanges(parIDs, :) = [-1.16, -0.92 ; +-4 -0.5; +-15 -8.5] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +mcut(:,:)' +size(mcut) +close all +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-5) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +% Thus, the 10 estimated parameters are: +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +estParamsIX = [1 2 3 7 11 16 21 31 32 33]'; +estParams = activeNames(estParamsIX,1) +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-5) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +% Thus, the 10 estimated parameters are: +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +estParamsIX = [1 2 3 7 11 16 21 31 32 33]'; +estParams = activeNames(estParamsIX,1) +proj_ZSIFFL_mtet_phase2 +%-- 4/28/19, 5:08 AM --% +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-5) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +% Thus, the 10 estimated parameters are: +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +estParamsIX = [1 2 3 7 11 16 21 31 32 33]'; +estParams = activeNames(estParamsIX,1) +[... +{'tx_{cat}'} +{'tl_cat'} +{'tau'} +{'pol_{Kd,tet}'} +{'rep_{Kd}'} +{'ATC_{Kd}' } +{'pol_{Kd,lac}' } +{'pol'} +{'RNase'} +{'Ribo'}] +parnames = ... +[... +{'tx_{cat}'} +{'tl_cat'} +{'tau'} +{'pol_{Kd,tet}'} +{'rep_{Kd}'} +{'ATC_{Kd}' } +{'pol_{Kd,lac}' } +{'pol'} +{'RNase'} +{'Ribo'}]; +[estParams parnames] +clear all +clear all +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet']; +addpath(projdir) +jpgsave = true; +figsave = false; +% Load model, mcmc_info, and data_info. +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mcmc_info = mcmc_info_ZSIFFL_mtet_phase1(mtet); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 3; +plotflag = true; +switch tsIDtouse +case 1 +ts1 = '20190420_045130_1_92790'; +ts2 = '20190420_070950_1_30930'; +tstamp = {ts1 ts2}; +nIterID = {1:2, 1}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +case 2 +ts1 = '20190420_045130_1_92790'; +ts2 = '20190420_071438_1_30930'; +ts3 = '20190420_071438_2_15465'; +ts4 = '20190420_155505_1_7732'; +ts5 = '20190420_155505_2_3093'; +ts6 = '20190420_155505_3_1546'; +ts7 = '20190420_155505_4_773'; +ts8 = '20190420_155505_5_309'; +ts9 = '20190420_155505_6_155'; +ts10 = '20190420_155505_7_77'; +ts11 = '20190420_155505_8_31'; +% +% tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; +% nIterID = {1:2, 1:10 1:8 1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; +tstamp = {ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; +nIterID = {1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +% conclusions from case 2: +% [{'pol_{Kd, tet}' } OK +% {'rep_{Kd}'} expand lower bound from ~3 to maybe -5? +% {'rep_F' } OK +% {'ATC_{Kd}' } expand upper bound from 18 to 25? +% {'ATC_F' } OK +% {'dim_{Kd}' } expand lower bound from 7 to -3 +% {'dim_F' } +case 3 +ts1 = '20190421_155749_1_773'; +ts2 = '20190421_155749_2_309'; +ts3 = '20190422_142534_1_773'; +ts4 = '20190422_214228_1_773'; +ts5 = '20190424_104801_1_773'; +tstamp = {ts1 ts2 ts3 ts4 ts5}; +nIterID = {1:10 1:2 1:4 1:7 1:14}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts5; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... +[ {'rep_{Kd}'} +{'ATC_{Kd}' } +{'dim_{Kd}' } ]; +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% +%% +if plotflag +% close all +% Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:end,(end - 70):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +%% +% {'rep_{Kd}'} -1.16, -0.92 +% +parIDs = [1 2 3]; +parRanges(parIDs, :) = [-1.16, -0.92 ; +-4 -0.5; +-15 -8.5] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') +% +% paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +% parRanges(paramIndices, :) = [... +% 2.3 2.95; %1 +% 8.6 8.95; %2 +% -10.1 -9.7; %3 +% 13 15; %4 +% -1 5 ; %5 +% 15.59 15.73; %6 +% -0.2966 0.1031; %7 +% 0.7 2.2; %8 pol +% 8.385 8.622;%9 RNase +% 3.18 3.69; % 10 -- TLcat +% -3 13.5;%RiboKd +% 2 3;% Ribo term +% 3 4.6 ];% Ribo +% marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% +% CandidateParams = marray_cut(:,1:100:end,end) +% figure +% [C,lags,ESS]=eacorr(marray(:, :,1:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% +%% Plot trajectories. +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +clear marray +for miID = 1:length(mi) +currmi = mi(miID); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); +dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); +% titles array: # dose combs x (exp, sim) ==2 x # measured species. +nms = length(currmi.measuredSpeciesIndex); +ndc = size(currmi.dosedVals,2); %# dose combinations +titls_array = cell(ndc, 2, nms); +currdi = data_info(currmi.dataToMapTo); +dn = currdi.dosedNames; %usually the last one will be the thing that is changing... +% can generalize to use all dose info if it becomes needed. +for msID = 1:nms +% for each measured species (ms), plot the trajectories over +% all the doses, for both experiment and simulation +if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) +if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; +else +error('what is your data type?') +end +elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}; +else +error('what is your data type?') +end +for dcID = 1:ndc +dosestr = []; +for dnID = 1:length(dn) +dosestr = [dosestr ' ' dn{dnID} num2str(currmi.dosedVals(ndID, dcID))]; +end +% dose combination by (exp, sim) by measured species ID +titls_array{dcID, 1, msID} = ['Exp ' ms ' ' dosestr]; +titls_array{dcID, 2, msID} = ['Sim ' ms ' ' dosestr]; +end +end +end +clear all +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet']; +addpath(projdir) +jpgsave = true; +figsave = false; +% Load model, mcmc_info, and data_info. +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mcmc_info = mcmc_info_ZSIFFL_mtet_phase1(mtet); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 3; +plotflag = true; +switch tsIDtouse +case 1 +ts1 = '20190420_045130_1_92790'; +ts2 = '20190420_070950_1_30930'; +tstamp = {ts1 ts2}; +nIterID = {1:2, 1}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +case 2 +ts1 = '20190420_045130_1_92790'; +ts2 = '20190420_071438_1_30930'; +ts3 = '20190420_071438_2_15465'; +ts4 = '20190420_155505_1_7732'; +ts5 = '20190420_155505_2_3093'; +ts6 = '20190420_155505_3_1546'; +ts7 = '20190420_155505_4_773'; +ts8 = '20190420_155505_5_309'; +ts9 = '20190420_155505_6_155'; +ts10 = '20190420_155505_7_77'; +ts11 = '20190420_155505_8_31'; +% +% tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; +% nIterID = {1:2, 1:10 1:8 1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; +tstamp = {ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; +nIterID = {1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +% conclusions from case 2: +% [{'pol_{Kd, tet}' } OK +% {'rep_{Kd}'} expand lower bound from ~3 to maybe -5? +% {'rep_F' } OK +% {'ATC_{Kd}' } expand upper bound from 18 to 25? +% {'ATC_F' } OK +% {'dim_{Kd}' } expand lower bound from 7 to -3 +% {'dim_F' } +case 3 +ts1 = '20190421_155749_1_773'; +ts2 = '20190421_155749_2_309'; +ts3 = '20190422_142534_1_773'; +ts4 = '20190422_214228_1_773'; +ts5 = '20190424_104801_1_773'; +tstamp = {ts1 ts2 ts3 ts4 ts5}; +nIterID = {1:10 1:2 1:4 1:7 1:14}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts5; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... +[ {'rep_{Kd}'} +{'ATC_{Kd}' } +{'dim_{Kd}' } ]; +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% +%% +if plotflag +% close all +% Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:end,(end - 70):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +%% +% {'rep_{Kd}'} -1.16, -0.92 +% +parIDs = [1 2 3]; +parRanges(parIDs, :) = [-1.16, -0.92 ; +-4 -0.5; +-15 -8.5] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') +% +% paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +% parRanges(paramIndices, :) = [... +% 2.3 2.95; %1 +% 8.6 8.95; %2 +% -10.1 -9.7; %3 +% 13 15; %4 +% -1 5 ; %5 +% 15.59 15.73; %6 +% -0.2966 0.1031; %7 +% 0.7 2.2; %8 pol +% 8.385 8.622;%9 RNase +% 3.18 3.69; % 10 -- TLcat +% -3 13.5;%RiboKd +% 2 3;% Ribo term +% 3 4.6 ];% Ribo +% marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% +% CandidateParams = marray_cut(:,1:100:end,end) +% figure +% [C,lags,ESS]=eacorr(marray(:, :,1:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% +%% Plot trajectories. +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +clear marray +for miID = 1:length(mi) +currmi = mi(miID); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); +dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); +% titles array: # dose combs x (exp, sim) ==2 x # measured species. +nms = length(currmi.measuredSpeciesIndex); +ndc = size(currmi.dosedVals,2); %# dose combinations +titls_array = cell(ndc, 2, nms); +currdi = data_info(currmi.dataToMapTo); +dn = currdi.dosedNames; %usually the last one will be the thing that is changing... +% can generalize to use all dose info if it becomes needed. +for msID = 1:nms +% for each measured species (ms), plot the trajectories over +% all the doses, for both experiment and simulation +if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) +if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; +else +error('what is your data type?') +end +elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}; +else +error('what is your data type?') +end +for dcID = 1:ndc +dosestr = []; +for dnID = 1:length(dn) +dosestr = [dosestr ' ' dn{dnID} num2str(currmi.dosedVals(ndID, dcID))]; +end +% dose combination by (exp, sim) by measured species ID +titls_array{dcID, 1, msID} = ['Exp ' ms ' ' dosestr]; +titls_array{dcID, 2, msID} = ['Sim ' ms ' ' dosestr]; +end +end +end +end +end +clear all +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet']; +addpath(projdir) +jpgsave = true; +figsave = false; +% Load model, mcmc_info, and data_info. +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mcmc_info = mcmc_info_ZSIFFL_mtet_phase1(mtet); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 3; +plotflag = true; +switch tsIDtouse +case 1 +ts1 = '20190420_045130_1_92790'; +ts2 = '20190420_070950_1_30930'; +tstamp = {ts1 ts2}; +nIterID = {1:2, 1}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +case 2 +ts1 = '20190420_045130_1_92790'; +ts2 = '20190420_071438_1_30930'; +ts3 = '20190420_071438_2_15465'; +ts4 = '20190420_155505_1_7732'; +ts5 = '20190420_155505_2_3093'; +ts6 = '20190420_155505_3_1546'; +ts7 = '20190420_155505_4_773'; +ts8 = '20190420_155505_5_309'; +ts9 = '20190420_155505_6_155'; +ts10 = '20190420_155505_7_77'; +ts11 = '20190420_155505_8_31'; +% +% tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; +% nIterID = {1:2, 1:10 1:8 1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; +tstamp = {ts4 ts5 ts6 ts7 ts8 ts9 ts10 ts11}; +nIterID = {1:5 1:5 1:5 1:5 1:5, 1:5 1:5 1:5}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +% conclusions from case 2: +% [{'pol_{Kd, tet}' } OK +% {'rep_{Kd}'} expand lower bound from ~3 to maybe -5? +% {'rep_F' } OK +% {'ATC_{Kd}' } expand upper bound from 18 to 25? +% {'ATC_F' } OK +% {'dim_{Kd}' } expand lower bound from 7 to -3 +% {'dim_F' } +case 3 +ts1 = '20190421_155749_1_773'; +ts2 = '20190421_155749_2_309'; +ts3 = '20190422_142534_1_773'; +ts4 = '20190422_214228_1_773'; +ts5 = '20190424_104801_1_773'; +tstamp = {ts1 ts2 ts3 ts4 ts5}; +nIterID = {1:10 1:2 1:4 1:7 1:14}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts5; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... +[ {'rep_{Kd}'} +{'ATC_{Kd}' } +{'dim_{Kd}' } ]; +% +% {'TX_elong_glob' } +% {'AGTPdeg_time' } +% {'AGTPdeg_rate' } +% {'TXTL_P70_RNAPbound_Kd' } +% {'TXTL_RNAPBOUND_TERMINATION_RATE'} +% {'TXTL_RNAdeg_Kd' } +% {'TXTL_RNAdeg_kc' } +% {'RNAP' } +% {'RNase' } +% {'TL_elong_glob' } +% {'TXTL_UTR_UTR1_Kd' } +% {'TXTL_RIBOBOUND_TERMINATION_RATE'} +% {'Ribo' } +% +%% +if plotflag +% close all +% Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:end,(end - 70):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +%% +% {'rep_{Kd}'} -1.16, -0.92 +% +parIDs = [1 2 3]; +parRanges(parIDs, :) = [-1.16, -0.92 ; +-4 -0.5; +-15 -8.5] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 70):end), parIDs, flipud((parRanges(parIDs, :))')); +mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +% We can literally pick any point in this cartesian product. +% parRanges(parIDs, :) = [-1.16, -0.92 ; +% -4 -0.5; +% -15 -8.5] +% parRanges([1, 2, 3], :) = [15.59 15.73 ; +% -0.2966 0.1031; +% 8.385 8.622]; +% marray_cut = mcmc_cut(marray, [6,7,9], flipud((parRanges([6 7 9], :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% mcut = marray_cut([6 7 9], 1:end,ceil(end/4):end); +% mcmc_3D(mcut(:,:)', parnames([6 7 9]), 'RNA deg covariation') +% +% paramIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +% parRanges(paramIndices, :) = [... +% 2.3 2.95; %1 +% 8.6 8.95; %2 +% -10.1 -9.7; %3 +% 13 15; %4 +% -1 5 ; %5 +% 15.59 15.73; %6 +% -0.2966 0.1031; %7 +% 0.7 2.2; %8 pol +% 8.385 8.622;%9 RNase +% 3.18 3.69; % 10 -- TLcat +% -3 13.5;%RiboKd +% 2 3;% Ribo term +% 3 4.6 ];% Ribo +% marray_cut = mcmc_cut(marray, paramIndices, flipud((parRanges(paramIndices, :))')); +% +% mcmc_plot(marray_cut(:, 1:end,ceil(end/4):end), parnames(:),... +% 'savematlabfig', figsave, 'savejpeg', false,... +% 'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +% +% CandidateParams = marray_cut(:,1:100:end,end) +% figure +% [C,lags,ESS]=eacorr(marray(:, :,1:end));%10000:end +% plot(lags,C,'.-',lags([1 end]),[0 0],'k'); +% grid on +% xlabel('lags') +% ylabel('autocorrelation'); +% text(lags(end),0,sprintf('Effective Sample Size (ESS): %.0f_ ',... +% ceil(mean(ESS))),'verticalalignment','bottom','horizontalalignment','right') +% title('Markov Chain Auto Correlation') +% +%% Plot trajectories. +% rebuild the master vector array, either via mcmc_cut or just using +% all estimated points. +% mvarray = masterVecArray(marray_cut, mai); +mvarray = masterVecArray(marray, mai); +clear marray +for miID = 1:length(mi) +currmi = mi(miID); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); +dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); +% titles array: # dose combs x (exp, sim) ==2 x # measured species. +nms = length(currmi.measuredSpeciesIndex); +ndc = size(currmi.dosedVals,2); %# dose combinations +titls_array = cell(ndc, 2, nms); +currdi = data_info(currmi.dataToMapTo); +dn = currdi.dosedNames; %usually the last one will be the thing that is changing... +% can generalize to use all dose info if it becomes needed. +for msID = 1:nms +% for each measured species (ms), plot the trajectories over +% all the doses, for both experiment and simulation +if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) +if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; +else +error('what is your data type?') +end +elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}; +else +error('what is your data type?') +end +for dcID = 1:ndc +dosestr = []; +for dnID = 1:length(dn) +dosestr = [dosestr ' ' dn{dnID} num2str(currmi.dosedVals(dnID, dcID))]; +end +% dose combination by (exp, sim) by measured species ID +titls_array{dcID, 1, msID} = ['Exp ' ms ' ' dosestr]; +titls_array{dcID, 2, msID} = ['Sim ' ms ' ' dosestr]; +end +end +end +end +titls_array +currmi.dosedVals +ndc +dn +currdi +analysis_ZSIFFL_mtet_phase1_b +titls_array +for miID = 1:length(mi) +currmi = mi(miID); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); +dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); +% titles array: # dose combs x (exp, sim) ==2 x # measured species. +nms = length(currmi.measuredSpeciesIndex); +ndc = size(currmi.dosedVals,2); %# dose combinations +titls_array = cell(ndc, 2, nms); +currdi = data_info(currmi.dataToMapTo); +dn = currdi.dosedNames; %usually the last one will be the thing that is changing... +% can generalize to use all dose info if it becomes needed. +for msID = 1:nms +% for each measured species (ms), plot the trajectories over +% all the doses, for both experiment and simulation +if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) +if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; +else +error('what is your data type?') +end +elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}; +else +error('what is your data type?') +end +for dcID = 1:ndc +dosestr = []; +for dnID = 1:length(dn) +dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; +end +% dose combination by (exp, sim) by measured species ID +titls_array{dcID, 1, msID} = ['Exp ' ms ' ' dosestr]; +titls_array{dcID, 2, msID} = ['Sim ' ms ' ' dosestr]; +end +end +titls_array +end +for miID = 1:length(mi) +currmi = mi(miID); +samplePoints = ceil(size(mvarray, 3) * [.9, 1]); +marrayOrd = mvarray(currmi.paramMaps(currmi.orderingIx),:,samplePoints); +dvStr = arrayfun(@num2str, currmi.dosedVals, 'UniformOutput', false); +% titles array: # dose combs x (exp, sim) ==2 x # measured species. +nms = length(currmi.measuredSpeciesIndex); +ndc = size(currmi.dosedVals,2); %# dose combinations +titls_array = cell(ndc, 2, nms); +currdi = data_info(currmi.dataToMapTo); +dn = currdi.dosedNames; %usually the last one will be the thing that is changing... +% can generalize to use all dose info if it becomes needed. +for msID = 1:nms +% for each measured species (ms), plot the trajectories over +% all the doses, for both experiment and simulation +if iscell(data_info(currmi.dataToMapTo).measuredNames{msID}) +if ischar( data_info(currmi.dataToMapTo).measuredNames{msID}{1}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}{1}; +else +error('what is your data type?') +end +elseif ischar( data_info(currmi.dataToMapTo).measuredNames{msID}) +ms = data_info(currmi.dataToMapTo).measuredNames{msID}; +else +error('what is your data type?') +end +for dcID = 1:ndc +dosestr = []; +for dnID = 1:length(dn) +dosestr = [dosestr ' ' dn{dnID} ' ' num2str(currdi.dosedVals(dnID, dcID))]; +end +% dose combination by (exp, sim) by measured species ID +titls_array{dcID, 1, msID} = ['Exp ' ms dosestr]; +titls_array{dcID, 2, msID} = ['Sim ' ms dosestr]; +end +end +titls_array +end +regexp(projdir, '/') +sls = regexp(projdir, '/'); +sls(end) +projdir(sls(end)+1 : end) +sls = regexp(projdir, '/', 'split'); +sls +analysis_ZSIFFL_mtet_phase1_b +close all +clear all +analysis_ZSIFFL_mtet_phase2 +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +whos +mtet +mtet.reactions +mtet.Parameters +analysis_ZSIFFL_mtet_phase2 +close all +clear all +analysis_ZSIFFL_mtet_phase1_b +analysis_ZSIFFL_mtet_phase2 +close all +clear all +clc +analysis_ZSIFFL_mtet_phase2 +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-5) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +% Thus, the 10 estimated parameters are: +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +estParamsIX = [1 2 3 7 11 16 21 31 32 33]'; +estParams = activeNames(estParamsIX,1); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +activeNames +edit mcmc_info_ZSIFFL_mtet_phase2.m +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-5) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames +activeNames(:,3) +cell2mat(activeNames(:,3)) +activeNames(cell2mat(mtet_phase1_params(:,1)),3) +mtet_phase1_params(:,4) +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4) +cell2mat(activeNames(:,3)) +edit proj_ZSIFFL_mtet_phase2.m +%-- 4/29/19, 7:16 AM --% +analysis_ZSIFFL_mtet_phase2 +6exit +close all +%-- 4/29/19, 12:43 PM --% +txtl_init +mcmc_init +close all +analysis_ZSIFFL_mtet_phase2 +addpath(genpath(pwd)) +close all +analysis_ZSIFFL_mtet_phase2 +clc +close all +%-- 4/29/19, 5:44 PM --% +analysis_ZSIFFL_mtet_phase2 +mcmc_plot(marray(:, 1:10:end,1:3:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +analysis_ZSIFFL_mtet_phase2 +mcmc_plot(mvarray(:, 1:10:end,1:3:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', ' +close all +clc +mcmc_plot(marray(:, 1:end,1:5:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +% clear all +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet_phase2']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_mtet_phase2(mtet, mlac); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 2; +plotflag = true; +switch tsIDtouse +case 1 +ts1 = '20190427_170334_1_2058'; +ts2 = '20190427_170334_2_1029'; +tstamp = {ts1 ts2}; +nIterID = {1:10 1:3}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +case 2 +ts1 = '20190428_142033_1_2058'; +ts2 = '20190428_142033_2_1029'; +ts3 = '20190429_083138_1_1029'; +tstamp = {ts1 ts2 ts3}; +nIterID = {1:10 1:2 1:3}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts3; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... +[... +{'tx_{cat}'} +{'tl_cat'} +{'tau'} +{'pol_{Kd,tet}'} +{'rep_{Kd}'} +{'ATC_{Kd}' } +{'pol_{Kd,lac}' } +{'pol'} +{'RNase'} +{'Ribo'}]; +% +% {'TX_elong_glob' } +% {'TL_elong_glob' } +% {'AGTPdeg_time' } +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_PLAC_RNAPbound_Kd' } +% {'RNAP' } +% {'RNase' } +% {'Ribo' } +% +% +% if plotflag +% close all +% Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:end,1:5:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +mm = model_txtl_pLacLasR_pLasdeGFP +mm.para +mm.react +mm.rul +edit proj_ZSIFFL_mtet_phase2.m +edit proj_ZSIFFL_training.m +% clear all +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet_phase2']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_mtet_phase2(mtet, mlac); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 2; +plotflag = true; +switch tsIDtouse +case 1 +ts1 = '20190427_170334_1_2058'; +ts2 = '20190427_170334_2_1029'; +tstamp = {ts1 ts2}; +nIterID = {1:10 1:3}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +case 2 +ts1 = '20190428_142033_1_2058'; +ts2 = '20190428_142033_2_1029'; +ts3 = '20190429_083138_1_1029'; +ts4 = '20190429_200219_1_1029' +tstamp = {ts1 ts2 ts3}; +nIterID = {1:10 1:2 1:4 1:2}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts4; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... +[... +{'tx_{cat}'} +{'tl_cat'} +{'tau'} +{'pol_{Kd,tet}'} +{'rep_{Kd}'} +{'ATC_{Kd}' } +{'pol_{Kd,lac}' } +{'pol'} +{'RNase'} +{'Ribo'}]; +% +% {'TX_elong_glob' } +% {'TL_elong_glob' } +% {'AGTPdeg_time' } +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_PLAC_RNAPbound_Kd' } +% {'RNAP' } +% {'RNase' } +% {'Ribo' } +% +% +% if plotflag +% close all +% Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:end,(end-6):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +% clear all +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet_phase2']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_mtet_phase2(mtet, mlac); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 2; +plotflag = true; +switch tsIDtouse +case 1 +ts1 = '20190427_170334_1_2058'; +ts2 = '20190427_170334_2_1029'; +tstamp = {ts1 ts2}; +nIterID = {1:10 1:3}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +case 2 +ts1 = '20190428_142033_1_2058'; +ts2 = '20190428_142033_2_1029'; +ts3 = '20190429_083138_1_1029'; +ts4 = '20190429_200219_1_1029' +tstamp = {ts1 ts2 ts3}; +nIterID = {1:10 1:2 1:4 1:2}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts4; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... +[... +{'tx_{cat}'} +{'tl_cat'} +{'tau'} +{'pol_{Kd,tet}'} +{'rep_{Kd}'} +{'ATC_{Kd}' } +{'pol_{Kd,lac}' } +{'pol'} +{'RNase'} +{'Ribo'}]; +% +% {'TX_elong_glob' } +% {'TL_elong_glob' } +% {'AGTPdeg_time' } +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_PLAC_RNAPbound_Kd' } +% {'RNAP' } +% {'RNase' } +% {'Ribo' } +% +% +% if plotflag +% close all +% Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:end,(end-6):5:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +edit analysis_ZSIFFL_mtet_phase2.m +close all +edit mcmc_info_ZSIFFL_mtet_phase2.m +%-- 4/30/19, 10:14 PM --% +edit mcmc_info_ZSIFFL_training_full.m +edit analysis_ZSIFFL_mtet_phase2.m +% clear all +% Set working directory to the txtlsim toolbox directory. +projdir = [pwd '/mcmc_simbio/projects/proj_ZSIFFL_mtet_phase2']; +addpath(projdir) +sls = regexp(projdir, '/', 'split'); +extrastring = sls{end}; +jpgsave = true; +figsave = false; +% Load model, mcmc_info, and data_info. +% construct simbiology model object(s) +mtet = model_txtl_ptetdeGFP_pLactetR_aTc; +mlac = model_txtl_pLacdeGFP; +% setup the mcmc_info struct +mcmc_info = mcmc_info_ZSIFFL_mtet_phase2(mtet, mlac); +di = data_ZSIFFL; +mi = mcmc_info.model_info; +ri = mcmc_info.runsim_info; +mai = mcmc_info.master_info; +% plot data from existing simulations. +tsIDtouse = 2; +plotflag = true; +switch tsIDtouse +case 1 +ts1 = '20190427_170334_1_2058'; +ts2 = '20190427_170334_2_1029'; +tstamp = {ts1 ts2}; +nIterID = {1:10 1:3}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +case 2 +ts1 = '20190428_142033_1_2058'; +ts2 = '20190428_142033_2_1029'; +ts3 = '20190429_083138_1_1029'; +ts4 = '20190429_200219_1_1029'; +ts5='20190429_200219_2_412'; +ts6='20190430_141254_1_412'; +ts7='20190430_141254_2_206'; +tstamp = {ts1 ts2 ts3 ts4 ts5 ts6 ts7}; +nIterID = {1:10 1:2 1:4 1:5 1:3 1:5 1:4}; +load([projdir '/simdata_' ts1 '/full_variable_set_' ts1 '.mat'], ... +'mi',... +'mcmc_info', 'data_info', 'mai', 'ri'); +end +tsToSave = ts7; +mai.masterVector +marray_full = mcmc_get_walkers(tstamp,nIterID, projdir); +marray = marray_full(:,:,1:end); +clear marray_full +parnames = ... +[... +{'tx_{cat}'} +{'tl_cat'} +{'tau'} +{'pol_{Kd,tet}'} +{'rep_{Kd}'} +{'ATC_{Kd}' } +{'pol_{Kd,lac}' } +{'pol'} +{'RNase'} +{'Ribo'}]; +% +% {'TX_elong_glob' } +% {'TL_elong_glob' } +% {'AGTPdeg_time' } +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_PLAC_RNAPbound_Kd' } +% {'RNAP' } +% {'RNase' } +% {'Ribo' } +% +% +% if plotflag +% close all +% Plot trace and corner (posterior distribution) plots +mcmc_plot(marray(:, 1:5:end,(end-40):end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +close all +analysis_ZSIFFL_mtet_phase2 +edit mcmc_info_ZSIFFL_mtet_phase2.m +exp([8 11])/3600 +exp([9 11])/3600 +exp([9 10.05 11])/3600 +exp(3.7) +exp(5.9) +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-6.07), [exp(-20) exp(10)] %36 +'TXTL_INDUCER_LASR_AHL_F' , exp(-6.07), [exp(-6) exp(6)] %37 +'TXTL_PLAS_RNAPbound_Kd' , exp(-6.07), [exp(-20) exp(10)]%38 +'TXTL_PLAS_RNAPbound_F' , exp(-6.07), [exp(-6) exp(-6)]%39 +'TXTL_PLAS_TFBIND_Kd' , exp(-6.07), [exp(-20) exp(10)]%40 +'TXTL_PLAS_TFRNAPbound_Kd' , exp(-6.07), [exp(-20) exp(10)]%41 +'TXTL_PLAS_TFRNAPbound_F' , exp(-6.07), [exp(-6) exp(-6)]%42 +'TXTL_PLAS_TFBIND_F' , exp(-6.07), [exp(-6) exp(-6)]}%43 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 31 33 36:43]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:) +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-6.07), [exp(-20) exp(10)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(-6.07), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(-6.07), [exp(-20) exp(10)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(-6.07), [exp(-6) exp(-6)]%39-1 +'TXTL_PLAS_TFBIND_Kd' , exp(-6.07), [exp(-20) exp(10)]%40-1 +'TXTL_PLAS_TFRNAPbound_Kd' , exp(-6.07), [exp(-20) exp(10)]%41-1 +'TXTL_PLAS_TFRNAPbound_F' , exp(-6.07), [exp(-6) exp(-6)]%42-1 +'TXTL_PLAS_TFBIND_F' , exp(-6.07), [exp(-6) exp(-6)]}%43-1 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 31 33 35:42]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:) +mm +model_txtl_pLacLasR_pLasdeGFP +mm = model_txtl_pLacLasR_pLasdeGFP +mm.parame +dii = data_ZSIFFL +dii(5) +dii(5).dosedNames +dii(5).dosedVals +mm.spe +edit proj_ZSIFFL_training.m +proj_ZSIFFL_mtet_phase2 +edit proj_ZSIFFL_mtet_phase2 +proj_ZSIFFL_training +logP(:,:,1 +logP(:,:,1) +minit(:,wix) +logPfuns{1} +logPfuns +logPfuns{2} +dbstack +mai +mi +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(-6)]%39-1 +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 +'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(-6)]%42-1 +'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(-6)]}%43-1 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 31 33 35:42]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. +% paramMap is a matrix mapping the parameters in the master vector to the +% (unordered) list of parameters in the model. (obvioulsy within the code +% these parameters get ordered before they are used in the exported model) +% More precisely, Let pp = paramMap(:, 1); then masterVector(pp) is the list +% of parameters for the first geometry within that topology, as specified by +% namesUnord. Note that namesUnord is just all the active parameters in +% the model, not just the estimated ones. +% One such matrix exists for each topology. It has dimnesions +% length(model_info(i).namesUnord) x number of geometries associated with that topo. +paramMap_ptet = [1:10 13:15 20 23:34]'; +paramMap_tetR = [1:15 18:34]'; +paramMap_aTc = (1:34)'; +paramMap_plac = [1:6 9 10 13:15 20:34]'; +paramMap_plas = [1:6 9 10 13:15 20:42]'; +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +% 'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +% 'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +% 'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +% 'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +% 'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +% 'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +% 'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +% 'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +% 'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +% 'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +% 'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% parameter ranges (for the to-be-estimated parameters in the master +% vector) +paramRanges = log(cell2mat(activeNames(estParamsIX,3))) +minit(:,wix) +proj_ZSIFFL_training +%-- 5/1/19, 7:06 PM --% +analysis_ZSIFFL_mtet_phase2 +mcmc_plot(marray(:, 1:end,(end-120):5:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllWalkers'); +% +%-- 5/2/19, 8:14 PM --% +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 +'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 +'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]}%43-1 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 31 33 35:42]'; +estParams = activeNames(estParamsIX,1) +activeNames(estParamsIX,:) +mlas +mlas.spe +close all +proj_ZSIFFL_training +proj_ZSIFFL_training('parallel', true, 'stepLadder', [1]) +mmm = model_txtl_pLacLasR_pLasdeGFP +mmm +sd = txtl_runsim(mmm) +help txtl_runsim +edit txtl_runsim +help txtl_runsim +mmm.getconfigset +edit mcmc_info_ZSIFFL_mtet_phase2.m +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(18)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(15)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(12)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(12)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +% Thus, the 10 estimated parameters are: +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +estParamsIX = [1 2 3 7 11 16 21 31 32 33]'; +estParams = activeNames(estParamsIX,1); +activeNames +edit mcmc_info_ZSIFFL_training_full.m +clc +size(marray) +marray(:,1:2,end) +size(marray_cut) +mai +help arrayfun +help randn +cell2mat(marray_gauss) +mmm +mmm.rea +mmm.Reactions(28) +get(mmm.Reactions(28).KineticLaw) +close all +mvarray(:,1:5,samplePoints) +mvarray(:,1:5,end) +[(1:42)' mvarray(:,1:5,end)] +%-- 5/6/19, 5:31 PM --% +mai +mai.masterVector +% !! todo -- set the parameters estimated from phase 1. then this will be +% ready to run. +% Phase 2 of the estimation procedure of the tetR system parameters from +% Zach's tetR data. +% +% The topologies involved in this estimataion probem are: +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +forwardoffset = 4 +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]}%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% finally, we set some parameters to try to raise the ceiling of the gene expression. +% this is to make the values match for the 3OC12HSL training data. +explore_params = ... +{... +23 , 'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8+forwardoffset), [exp(-3) exp(10)] +28 , 'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3 +forwardoffset), [exp(0) exp(10)] +1 , 'TX_elong_glob' , exp(2.6 +forwardoffset), [exp(0) exp(5 +forwardoffset)] +2 , 'TL_elong_glob' , exp(3.5 +forwardoffset), [exp(0) exp(6 +forwardoffset)]}; +activeNames(cell2mat(explore_params(:,1)),3) = explore_params(:,4); +%% +estParamsIX = [7 21 31 33 35:42]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))) +clear all +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]}%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +, exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 +, exp(1.3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 plas-pol_{tf, Kd} < +, exp(1.3), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +, exp(1.3), [exp(-6) exp(6)] +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1) +%-- 5/7/19, 2:22 PM --% +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1) +activeNames(estParamsIX,:) +activeNames(estParamsIX,3) +cell2mat(activeNames(estParamsIX,3)) +log(cell2mat(activeNames(estParamsIX,3))) +cell2mat(activeNames(estParamsIX,2)) +log(cell2mat(activeNames(estParamsIX,2))) +[log(cell2mat(activeNames(estParamsIX,2))) log(cell2mat(activeNames(estParamsIX,3)))] +exp(10)/3600 +edit manual_txtlsim_parameters.m +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' 50 [0.5 300] % 1 +'AGTPdeg_time' exp(9.57) [1800 42000] % set to exp(9.57) +'AGTPdeg_rate' 0.0002 [1e-5 1e-2] % set from before +'AGTPreg_ON' 0.02 [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' 600 [0.1 1e6] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' 0.15 [1e-4 100] % 7 +'TXTL_NTP_RNAP_1_Kd' 100000 [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' 1e6 [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' 2000 [100 1e5] +'TXTL_RNAdeg_F' 1 [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-5.4) [1e-4 1] %set to exp(-5.4) +'RNAP' 100 [5 5000] % 15 +'RNase' 100 [1 10000] +'TL_elong_glob' 20 [0.1 500] +'TXTL_PROT_deGFP_MATURATION' 0.0023 [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' 20 [0.05 1e5] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' 10 [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' 10 [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' 40 [0.1 20000] +'Ribo' 30 [10 10000]}; +log(cell2mat(activeNames2(:,2)) +log(cell2mat(activeNames2(:,2))) +edit analysis_ZSIFFL_mtet_phase2.m +edit proj_ZSIFFL_training.m +%-- 5/8/19, 6:06 PM --% +10*60+23 +(10*60+23)/48*100 +((10*60+23)/48*100)/60 +((((10*60+23)/48*100)/60)*20*3)/60 +%-- 5/9/19, 3:55 PM --% +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:) +estParams +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1) +activeNames(estParamsIX,:) +log(cell2mat(activeNames(estParamsIX,2))) +exp(5.9) +exp(4.4) +close all +% plac - UTR1 - tetR, ptet - UTR1 - deGFP, aTc; This has three +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [1 2 3 7 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:) +activeNames(estParamsIX,1) +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [1 2 7 11 16 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1) +edit proj_ZSIFFL_trainingB.m +log(cell2mat(activeNames(estParamsIX,3))) +mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14, 2)) +mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2)) +[cell2mat(activeNames(estParamsIX,1))) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +[(activeNames(estParamsIX,1))) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +[activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +%-- 5/10/19, 10:43 AM --% +edit analysis_vnprl_F2.m +%-- 5/10/19, 6:00 PM --% +close all +clear all +close all +%-- 5/11/19, 12:36 PM --% +edit analysis_ZSIFFL_training_fullC.m +parIDs = [4 5 11]; +parRanges(parIDs, :) = [-1 0 ; +-4 0; +11 15] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +mcmc_plot(marray_cut, parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +mcut0 = marray_cut(parIDs, :,:); +mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +[activeNames(estParamsIX,1) mat2cell(log(cell2mat(activeNames(estParamsIX,3))), ones(14,1), ones(1, 2))] +size(marray_cut) +parRanges(parIDs, :) = [-1 0 ; +-2.5 -1.5; +11.5 14.5] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +size(marray_cut) +parRanges(parIDs, :) = [-1 0 ; +-3 -1; +11.5 14.5] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +size(marray_cut) +%-- 5/11/19, 1:56 PM --% +edit proj_ZSIFFL_trainingC.m +parIDs = [4 5 11]; +% parRanges(parIDs, :) = [-1 0 ; +% -4 0; +% 11 15] +parRanges(parIDs, :) = [-1 0 ; +-3 -1; +11.5 14.5] +marray_cut = mcmc_cut(marray(:, 1:end,(end - 40):end), parIDs, flipud((parRanges(parIDs, :))')); +mcut0 = marray_cut(parIDs, :,:); +mcmc_3D(mcut0(:,:)', parnames(parIDs), '3 params'); +mcmc_plot(marray_cut, parnames(:),... +'savematlabfig', figsave, 'savejpeg', false,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'BurnedIn'); +mcut = marray_cut(parIDs, 1:end,ceil(end/4):end); +mcmc_3D(mcut(:,:)', parnames(parIDs), '3 params') +CLOSE ALL +close all +edit model_txtl_ptetdeGFP_pLactetR_aTc.m +edit analysis_ZSIFFL_training_fullE.m +mcmc_plot(marray(:, 1:end,1:4:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave,... +'extrafignamestring', 'Without_transient'); +% % % % %% +% +mcmc_plot(marray(:, 1:end,(end - 20):4:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'Burned_in'); +% % % % % +%-- 5/19/19, 3:57 PM --% +mm = model_dsg2014_regen +mm.rea +mm.param +edit mcmc_info_vnprl_F2.m +activeNames2 = {... % changes made to ranges on feb 8, 2019. setting parameters based on +...% posterior plots. +'TX_elong_glob' exp(4.9354) [0.5 300] % 1 +'AGTPdeg_time' exp(9.17) [1800 42000] % DO NOT FIX THIS. +'AGTPdeg_rate' exp(-9.5172) [1e-7 1e-2] % set from before +'AGTPreg_ON' exp(-3.912) [0.005 0.2] %4 % set from before +'TXTL_P70_RNAPbound_Kd' exp(9.514) [0.01 1e7] % +'TXTL_P70_RNAPbound_F' exp(1.5) [1e-5 300] % set to exp(1.5) +'TXTL_RNAPBOUND_TERMINATION_RATE' exp(3.3005) [0.1 1000] % 7 +'TXTL_NTP_RNAP_1_Kd' exp(2.9459) [1 1e6] +'TXTL_NTP_RNAP_1_F' exp(0) [1e-5 100] % set to 1 +'TXTL_NTP_RNAP_2_Kd' exp(13.997) [0.1 1e7] +'TXTL_NTP_RNAP_2_F' exp(0) [1e-6 1000] %11 % set to 1 +'TXTL_RNAdeg_Kd' exp(9.237) [100 1e7] +'TXTL_RNAdeg_F' exp(0) [0.01 10000] % set to 1 (1 is right in the middle of the broad posterior density, and so not entirely arbitrary. ) +'TXTL_RNAdeg_kc' exp(-4.4) [1e-5 10] %set to exp(-5.4) +'RNAP' exp(1.4419) [0.1 5000] % 15 +'RNase' exp(6.4899) [1 100000] +'TL_elong_glob' exp(0.5219) [0.1 500] +'TXTL_PROT_deGFP_MATURATION' exp(-6.0748) [0.0002 0.02] %18 % set from before +'TXTL_UTR_UTR1_Kd' exp(11.189) [0.005 1e7] +'TXTL_UTR_UTR1_F' exp(-0.2) [1e-5 100] % set to exp(-0.2) +'TL_AA_Kd' exp(6.5566) [.1 1e6] % 21 +'TL_AA_F' exp(-0.3) [1e-5 20] % set to exp(-0.3) +'TL_AGTP_Kd' exp(14.509) [.1 1e7] % 23 +'TL_AGTP_F' exp(-1.2) [1e-5 100] %set to exp(-1.2) +'TXTL_RIBOBOUND_TERMINATION_RATE' exp(5.398) [0.1 1000] +'Ribo' exp(7.3081) [1 10000]}; %26 +activeNames2(:,2) +cell2num(activeNames2(:,2)) +cell2mat(activeNames2(:,2)) +log(cell2mat(activeNames2(:,2))) +num2cell(log(cell2mat(activeNames2(:,2)))) +[activeNames2(:,1) num2cell(log(cell2mat(activeNames2(:,2)))) num2cell(log(cell2mat(activeNames2(:,3)))) +] +lasmodel = model_txtl_pLacLasR_pLasdeGFP +lasmodel.reactio +lacmodel = model_txtl_pLacdeGFP +lacmodel.reac +tetmodel = model_txtl_ptetdeGFP_pLactetR_aTc +tetmodel.reac +lasmodel = model_txtl_pLacLasR_pLasdeGFP +lasmodel.Reactions +lasmodel.param +lasmodel.Parameters(35) +get(lasmodel.Parameters(35)) +lasmodel.Reactions +lasmodel.Reactions(1) +get(lasmodel.Reactions(1)) +get(lasmodel.Reactions(28)) +get(lasmodel.Reactions(29)) +get(lasmodel.Reactions(30)) +get(lasmodel.Reactions(31)) +edit mcmc_info_ZSIFFL_mtet_phase1.m +edit mcmc_info_ZSIFFL_mtet_phase1_b.m +edit mcmc_info_ZSIFFL_mtet_phase2.m +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +% !! NEED TO CHECK IF AT THE PICKED POINT THE TRAJECTORIES LOOK OK. +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 % fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 % fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 % fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19% TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22% fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25% fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 % from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% +% Names of parameters and species to actually estimate. +% As mentioned above, I have planned this out in the file +% ZachIFFL_estimation_strategy.txt +% 'TX_elong_glob' , 'fix' +% 'TL_elong_glob' , 'fix' +% 'AGTPdeg_time' , 'fix' +% 'AGTPreg_ON' , 'fix' +% 'AGTPdeg_rate' , 'fix' +% 'TXTL_PROT_deGFP_MATURATION' , 'fix' +% 'TXTL_UTR_UTR1_Kd' , 'fix' +% 'TXTL_PTET_RNAPbound_Kd' , 'est' +% 'TXTL_PTET_RNAPbound_F' , 'fix' +% 'TXTL_NTP_RNAP_1_Kd' , 'fix' +% 'TXTL_NTP_RNAP_2_Kd' , 'fix' +% 'TXTL_PTET_sequestration_Kd' , 'est' +% 'TXTL_PTET_sequestration_F' , 'est' +% 'TL_AA_Kd' , 'fix' +% 'TL_AGTP_Kd' , 'fix' +% 'TXTL_RNAdeg_Kd' , 'fix' +% 'TXTL_INDUCER_TETR_ATC_Kd' , 'est' +% 'TXTL_INDUCER_TETR_ATC_F' , 'est' +% 'TXTL_DIMER_tetR_Kd' , 'est' +% 'TXTL_DIMER_tetR_F' , 'est' +% 'TXTL_UTR_UTR1_F' , 'fix' +% 'TXTL_PLAC_RNAPbound_Kd' , 'fix' +% 'TXTL_PLAC_RNAPbound_F' , 'fix' +% 'TXTL_RNAPBOUND_TERMINATION_RATE' , 'fix' +% 'TXTL_NTP_RNAP_1_F' , 'fix' +% 'TXTL_NTP_RNAP_2_F' , 'fix' +% 'TL_AA_F' , 'fix' +% 'TL_AGTP_F' , 'fix' +% 'TXTL_RIBOBOUND_TERMINATION_RATE' , 'fix' +% 'TXTL_RNAdeg_F' , 'fix' +% 'TXTL_RNAdeg_kc' , 'fix' +% Thus, the 7 estimated parameters are: +% 'TXTL_PTET_RNAPbound_Kd' , 'est' +% 'TXTL_PTET_sequestration_Kd' , 'est' +% 'TXTL_PTET_sequestration_F' , 'est' +% 'TXTL_INDUCER_TETR_ATC_Kd' , 'est' +% 'TXTL_INDUCER_TETR_ATC_F' , 'est' +% 'TXTL_DIMER_tetR_Kd' , 'est' +% 'TXTL_DIMER_tetR_F' , 'est' +estParamsIX = [7, 11, 12, 16:19]'; +estParams = activeNames(estParamsIX,1) +cell2mat(activeNames(estParamsIX,3)) +log(cell2mat(activeNames(estParamsIX,3))) +num2cell(log(cell2mat(activeNames(estParamsIX,3)))) +[estParams num2cell(log(cell2mat(activeNames(estParamsIX,3))))] +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(18)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(15)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(12)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(12)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] }; %34 fixed in mcmc_info_vnprl_F2 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +format short g; +aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +% Thus, the 10 estimated parameters are: +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +estParamsIX = [1 2 3 7 11 16 21 31 32 33]'; +estParams = activeNames(estParamsIX,1); +[estParams num2cell(log(cell2mat(activeNames(estParamsIX,3))))] +analysis_ZSIFFL_mtet_phase2 +edit analysis_ZSIFFL_mtet_phase2 +clear all +close all +mcmc_plot(marray(:, 1:end,(end-(100)):10:end), parnames(:),... +'savematlabfig', figsave, 'savejpeg', jpgsave,... +'projdir', projdir, 'tstamp', tsToSave, 'extrafignamestring', 'AllW_last150_thin10'); +edit analysis_ZSIFFL_mtet_phase2.m +edit mcmc_info_ZSIFFL_training_full.m +edit analysis_ZSIFFL_training_full +edit analysis_ZSIFFL_training_fullB.m +edit analysis_ZSIFFL_training_fullC.m +edit analysis_ZSIFFL_training_fullD.m +edit analysis_ZSIFFL_training_fullE.m +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(-5) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:) +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1) +% topologies, the constitutive expression geometry, the repression +% geometry, and the aTc induction geometry. +% +% A lot of the core parameters are set from those estimated from the +% constitutive expression fits to the data in the VNPRL2011 and ACS 2014 papers. +% +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(7)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(7)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(5) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [1 2 7 11 16 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1) +% In phase 1, we estimated 7 parameters: +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); +estParamsIX = [1 2 7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1) +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1) +%-- 5/24/19, 10:32 AM --% +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(6)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(5)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(-2), [exp(-20) exp(20)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 +'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 +'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]}%43-1 +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 31 33 35:42]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:) +% {'TXTL_PTET_RNAPbound_Kd' } +% {'TXTL_PTET_sequestration_Kd'} +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_Kd' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% In this phase, we will fix the values of +% {'TXTL_PTET_sequestration_F' } +% {'TXTL_INDUCER_TETR_ATC_F' } +% {'TXTL_DIMER_tetR_Kd' } +% {'TXTL_DIMER_tetR_F' } +% +% and estimate: +% +% 'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 % from est params above +% 'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2% from est params above +% 'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 % from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 % TO BE ESTIMATED HERE +% 'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +% 'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 % TO BE ESTIMATED HERE +% 'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +% 'RNAP' , exp(1.4419), [exp(-1) exp(4)] %31 31% from est params above +% 'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +% 'Ribo' , exp(3.75), [exp(1) exp(6)] %33 % from est params above +% +% and we also include the pLac data into the estimation problem, since the +% plac part is involved. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +ptetinfo = ['This is the ptet constitutive expression circuit. \n ']; +tetrinfo = ['This is the tetR repressing ptet circuit. \n ']; +atcinfo = ['This is the aTc inducing (derepressing) the tetR ptet repression circuit. \n ']; +placinfo = ['This is the plac constitutive expression circuit. \n ']; +plasinfo = ['This is the plas - 3OC12HSL induction circuit. \n ']; +% activeNames has the mRNA parameters and the protein parameters. +% first half (up to RNase) are TX and the rest are TL. +% TX params are fixed from previous sims. +% +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged to that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimaed parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +% Here for example we have for the mrna deg sim we only care about +% setting the rna deg parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. Need to document this before I forget. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(-3) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(-20) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(1.3), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(-5) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(-2), [exp(-20) exp(20)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(2), [exp(-20) exp(20)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(1.3), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(1.3), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(0) exp(5)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(0) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(-1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(12)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(17)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(16.57) ,[exp(0) exp(22)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(5)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +estParamsIX = [7 21 23 28 31 33 35 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:) +edit mcmc_info_vnprl_F2.m +close all +%-- 6/6/19, 3:37 PM --% +edit txtl_prom_plas_ptet.m +edit txtl_prom_ptet.m +edit txtl_prom_plas.m +%-- 6/7/19, 7:20 PM --% +edit model_txtl_pLacLasR_pLasdeGFP.m +edit model_txtl_ptetdeGFP_pLactetR_aTc.m +mIFFL = model_txtl_lastetIFFL +mIFFL +mIFFL.Reactions +mIFFL = model_txtl_lastetIFFL +mIFFL.Reactions +edit manual_txtlsim_parameters.m +edit analysis_regen_C1.m +mIFFL.Parameters +mIFFL = model_txtl_lastetIFFL +mIFFL.Parameters +mIFFL = model_txtl_lastetIFFL +mIFFL.Parameters +mIFFL.Reactions +mIFFL.rules +mIFFL.Events +edit proj_ZSIFFL_trainingE.m +edit ZachIFFL_testdata.m +grpData_test +clc +unique(grpData_test.ID) +find(grpData_test.ID, unique(grpData_test.ID)) +find(grpData_test.ID == unique(grpData_test.ID)) +grpData_test(1:81:35*81,:) +grpData_test(1+1:81:35*81,:) +grpData_test(81:81:35*81,:) +grpData_test(1:81:35*81,:) +grpData_test{1:81,:) +grpData_test(1:81,:) +grpData_test(1:81,2) +grpData_test(1:81,3) +grpData_test(1:10,,) +grpData_test(1:10,) +grpData_test(1:10,:) +grpData_test.GFP(1:10) +i = 2 +doseid = 3 +((i-1)*(81*7)+((doseid-1)*81)+1:81) +((i-1)*(81*7)+((doseid-1)*81)+(1:81)) +for i = 1:2 +for doseid = 1:7 +tst{i, doseid} = ((i-1)*(81*7)+((doseid-1)*81)+1:81); +end +end +tst +for i = 1:2 +for doseid = 1:7 +tst{i, doseid} = ((i-1)*(81*7)+((doseid-1)*81)+(1:81)); +end +end +tst +tst{1 +tst{1} +tst{1,1} +tst{1,2} +tst{1,3} +tst{1,4} +tst{1,5} +tst{1,6} +tst{1,7} +tst{2,7} +tst{2,1} +grpData_test(1:81,:) +da +plot(da{:,1,1,1}) +di +clc +di{1} +si +di +di{1} +da1 = squeeze(di{1}.dataArray); +dim(da1) +size(da1) +plot(0:360:28800, da1) +plot(0:360/3600:28800/3600, da1) +figure; for i = 1:5; subplot(5, 1, i); plot(0:360/3600:28800/3600, squeeze(di{i}.dataArray)) end +figure; for i = 1:5; subplot(5, 1, i); plot(0:360/3600:28800/3600, squeeze(di{i}.dataArray)); end +di +di(1) +di +di = ZachIFFL_testdata +close all +di(1) +di(2) +di(3) +di(4) +di = ZachIFFL_testdata +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. +masterVector +activeNames +[activeNames(:,1) num2cell(log(cell2mat(activeNames(:, 2))))] +activeNames(estParamsIX,:) +exp(6)*100 +log(exp(6)*100) +mIFFL.reaction +mIFFL.riles +mIFFL.rul +mIFFL.Reactions(79) +get(mIFFL.Reactions(79)) +get(mIFFL.Reactions(65)) +proj_ZSIFFL_predictionA +size(mvarray) +mai +mai.fixedParams +mi +mi(1) +load(['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/mcmc_simbio/projects/proj_ZSIFFL_predictionA'... +'/simdata_20190613_105424_1_327/full_variable_set_20190613_105424_1_327.mat']) +clear all +load(['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/mcmc_simbio/projects/proj_ZSIFFL_predictionA'... +'/simdata_20190613_105424_1_327/full_variable_set_20190613_105424_1_327.mat'] +load(['/Users/vipulsinghal/Dropbox/Documents/toolbox/txtlsim_vsfork2017/mcmc_simbio/projects/proj_ZSIFFL_predictionA'... +'/simdata_20190613_105424_1_327/full_variable_set_20190613_105424_1_327.mat']) +whos +mi +mi(1) +close all +clc +mIFFL.reac +mIFFL.param +mIFFL.rules +mi +mi(1).emo +get(mi(1).emo) +aa = get(mi(1).emo) +aa.ValueInfo +aa.ValueInfo(:) +for i = 1:47; aa.ValueInfo(i) end +for i = 1:47; aa.ValueInfo(i); end +for i = 1:47; currvi{i} = aa.ValueInfo(i); end +currvi +for i = 1:47; currvi2(i) = aa.ValueInfo(i); end +currvi2 +currvi2(1) +for i = 1:47; currvi2(i) +end +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +oc12info = ['This is the 3OC12 perturbation in the IFFL. \n ']; +lasrinfo = ['This is the pLac-lasR DNA perturbation in the IFFL. \n ']; +atcinfo = ['This is the aTc perturbation in the IFFL. \n ']; +tetrinfo = ['This is the pLas-tetR DNA perturbation in the IFFL. \n ']; +gfpinfo = ['This is the pLas-tetO-deGFP DNA perturbation in the IFFL. \n ']; +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged so that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimated parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); +% add the combinatorial activator knockoff parameter +% 'TXTL_PLAS_TFBIND_Kd', exp(6) +% 'TXTL_PLAS_TFBIND_F', exp(0) % % +multiplier = 100; +plasTFbind_KD = exp(6); +activeNames = [activeNames; +{'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_Kd', 1/(plasTFbind_KD*multiplier) , [exp(-20) exp(20)] +'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F', (plasTFbind_KD*multiplier), [exp(-20) exp(20)]}]; +% reverse rate = 1 +% forward rate / reverse rate = exp(6)*100/exp(0) ~= exp(10.5) = 1/kD => KD +% = exp(-10.6) +% forward rate = exp(10.5) +% +estParamsIX = [7 21 23 28 31 33 37 39 40]'; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); +% for troubleshooting / visualizing the fixed params: +% log(cell2mat(activeNames2(fixedParamsIX,[2]))) +% activeNames2(fixedParamsIX,[1:2]) +% since activeNames2 is a superset of activeNames1, we can just use +% activeNames2 as the master vector. +masterVector = log(cell2mat(activeNames(:,2))); % log transformed. +[activeNames(:,1) num2cell(log(cell2mat(activeNames(:, 2))))] +mai +mai.mast +mai.masterVector +mi(1) +edit mcmc_runsim +edit mcmc_runsim_v2.m +edit proj_ZSIFFL_predictionA +proj_ZSIFFL_predictionA('nW', 20, 'nPoints', 100, 'nIter', 1, 'parallel', false, 'multiplier', 1, 'thinning', 1) +ep +es +enuo +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +% 'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +% 'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +activeNames +% +% There is only one topology in this example: the IFFL. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +oc12info = ['This is the 3OC12 perturbation in the IFFL. \n ']; +lasrinfo = ['This is the pLac-lasR DNA perturbation in the IFFL. \n ']; +atcinfo = ['This is the aTc perturbation in the IFFL. \n ']; +tetrinfo = ['This is the pLas-tetR DNA perturbation in the IFFL. \n ']; +gfpinfo = ['This is the pLas-tetO-deGFP DNA perturbation in the IFFL. \n ']; +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged so that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimated parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); +% add the combinatorial activator knockoff parameter +% 'TXTL_PLAS_TFBIND_Kd', exp(6) +% 'TXTL_PLAS_TFBIND_F', exp(0) % % +multiplier = 100; +plasTFbind_KD = exp(6); +activeNames = [activeNames; +{'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_Kd', 1/(plasTFbind_KD*multiplier) , [exp(-20) exp(20)] +'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F', (plasTFbind_KD*multiplier), [exp(-20) exp(20)]}]; +activeNames +activeNames = activeNames(setdiff(1:44, [7, 8]), :); +activeNames +% +% There is only one topology in this example: the IFFL. +% +% +% mcmc_info has the following substructures: +% +% runsim_info: information on the mcmc algorithm parameters +% model_info: array of models, and associated properties like parameters, +% and the matrices of indices from the master vector +% to the model parameters. +% master_info: contains the master vector, and a spec for which parameters +% get estimated. +% +% Copyright (c) 2018, Vipul Singhal, Caltech +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. +% Some human readable descriptive text. +oc12info = ['This is the 3OC12 perturbation in the IFFL. \n ']; +lasrinfo = ['This is the pLac-lasR DNA perturbation in the IFFL. \n ']; +atcinfo = ['This is the aTc perturbation in the IFFL. \n ']; +tetrinfo = ['This is the pLas-tetR DNA perturbation in the IFFL. \n ']; +gfpinfo = ['This is the pLas-tetO-deGFP DNA perturbation in the IFFL. \n ']; +% ordering requirements: +% ensure that the following two orderings match up: +% activeNames(orderingIX) == masterVector(paramMaps(orderingIX)) +% +% ie, activeNames == masterVector(paramMaps) +% +% This gets satisfied when two conditions hold: +% +% The fixed parameters in the master vector must be arranged so that +% for every paramMap and every corresponding activeNames list, the +% fixed params subset of the elements gets mapped correctly. +% +% for the estimated parameters, again, the estimated parameters need to +% populate the master vector in a way such that the condition +% activeNames == masterVector(paramMaps) holds for all the activeNames +% arrays (each topology will have one), and for each paramMap column +% (geometry) for each topology. +% +% +% of course, the masterVector is built as follows: +% masterVector(estparamIX) == logp +% masterVector(fixedParams) == [marray(:, end-2); marray(:, end-1); marray(:, end);] +% +% So this is all a bit complicated... +% Basically we need to make sure that after we build master vector from +% the fixed parameters (from the previous simulations), when we access +% them using paramMaps, we get the ones corresponding to the names in +% activeNames. +% names of the parameters and species to set allow for setting in the +% exported model. These are both the set parameters and the to estimate +% parameters. +%% +% SEE FILE ZachIFFL_estimation_strategy.txt for the overall strategy. +% first we set up the master vector +% +% then we will set the parameters to fix, and the remaining ones to +% estimate. +% +% Then we will define paramMaps that will be used to distribute the +% master vector among the different topologies. +% parameters of the master vector we fix and estimate +% The following params are the ones estimaed from the last set of +% restrictions in the file analysis_vnprl_F2.m +% parnames = +% +% 13×1 cell array +% +% {'TX_{cat}' } 1 +% {'\tau_{atp}' } 3 +% {'\delta_{atp}'} 5 +% {'pol_{Kd}' } 21 % plac Kd NOT PTET Kd, the Ptet KD gets estimated. +% {'pol_{term}' } 23 +% {'RNAse_{Kd}' } 15 +% {'RNAse_{cat}' } 30 +% {'pol' } 31 +% {'RNase' } 32 +% {'TL_{cat}' } 2 +% {'Ribo_{Kd}' } 6 +% {'Ribo_{term}' } 28 +% {'Ribo' } 33 +% The following were parameters esitmated in vnprl_F2, and were extracted +% carefully from the accompanying analysis script. see the code there to +% understand how they were picked. +EstimatedParams =[... +2.5234 2.4464 2.6231 2.5976 2.4650 2.4277 2.4806 2.6010 2.4301 2.5499 2.6991 2.4356 +8.8054 8.9024 8.8097 8.8014 8.8483 8.8642 8.8394 8.8427 8.8616 8.7634 8.8621 8.7910 +-10.0179 -9.7873 -9.9376 -10.0048 -9.9056 -9.8889 -9.9100 -9.9631 -9.9827 -10.0348 -9.8702 -9.9538 +13.7327 13.6474 13.8789 13.9325 13.7827 13.7665 13.7762 13.8681 13.8867 13.7211 14.0961 13.8706 +2.8000 4.3598 0.0020 2.8127 3.5490 4.4005 4.1178 3.1338 0.3334 2.7831 1.8745 1.7856 +15.6977 15.6349 15.7098 15.6858 15.6061 15.6339 15.7103 15.6193 15.6295 15.7294 15.6074 15.5958 +0.0535 -0.2251 -0.1516 -0.0709 -0.2109 -0.1276 -0.0340 -0.1752 -0.0117 0.0436 -0.2481 -0.1603 +1.5652 1.6167 1.4897 1.5206 1.6080 1.6259 1.6008 1.5196 1.7133 1.5597 1.4531 1.7096 +8.3976 8.6141 8.6149 8.5123 8.5710 8.5146 8.4985 8.5494 8.3963 8.4382 8.6104 8.5097 +3.6442 3.2731 3.2538 3.3828 3.2633 3.2936 3.2387 3.4129 3.4920 3.3685 3.5169 3.3055 +8.2565 0.0542 4.5196 -2.2731 -1.6399 -1.7370 -2.9377 0.6546 -1.7598 3.9814 6.7136 -0.3827 +2.5533 2.8328 2.8292 2.7929 2.9282 2.8804 2.9859 2.9519 2.8087 2.7650 2.7130 2.9940 +3.9583 4.1863 4.1261 4.0012 4.1922 3.9954 4.0318 3.7330 3.8616 4.1038 3.8526 3.8081]; +ParamColumnToUse = 2; +paramVecToUse = EstimatedParams(:, ParamColumnToUse); +indicesMasterVectorEstimated = [1 3 5 21 23 15 30 31 32 2 6 28 33]; +activeNames = {... % param name, nominal value, rage of parameters for uniform prior, +'TX_elong_glob' , exp(2.6), [exp(0) exp(5)] %1 from est params above +'TL_elong_glob' , exp(3.5), [exp(0) exp(6)] %2 from est params above +'AGTPdeg_time' , exp(8.8), [exp(6) exp(11)] %3 from est params above +'AGTPreg_ON' , exp(-3.9), [exp(-6) exp(-1)] %4 fixed in mcmc_info_vnprl_F2 +'AGTPdeg_rate' , exp(-9.9), [exp(-13) exp(-7)] %5 from est params above +'TXTL_UTR_UTR1_Kd' , exp(11), [exp(-3) exp(15)] %6 from est params above +'TXTL_PTET_RNAPbound_Kd' , exp(14), [exp(0) exp(17)] %7 TO BE ESTIMATED HERE +'TXTL_PTET_RNAPbound_F' , exp(1.5), [exp(0) exp(4)] %8 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_1_Kd' , exp(2.9), [exp(0) exp(5)] %9 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_Kd' , exp(14), [exp(10) exp(20)] %10 fixed in mcmc_info_vnprl_F2 +'TXTL_PTET_sequestration_Kd' , exp(12), [exp(3) exp(15)] %11 TO BE ESTIMATED HERE +'TXTL_PTET_sequestration_F' , exp(1.5), [exp(-2) exp(5)] %12 TO BE ESTIMATED HERE +'TL_AA_Kd' , exp(6.6), [exp(3) exp(10)] %13 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_Kd' , exp(14.5), [exp(10) exp(18)] %14 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_Kd' , exp(15.2), [exp(7) exp(17)] %15 from est params above +'TXTL_INDUCER_TETR_ATC_Kd' , exp(13), [exp(0) exp(18)] %16 TO BE ESTIMATED HERE +'TXTL_INDUCER_TETR_ATC_F' , exp(2.6), [exp(-2) exp(5)] %17 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_Kd' , exp(13), [exp(7) exp(17)] %18 TO BE ESTIMATED HERE +'TXTL_DIMER_tetR_F' , exp(2.6), [exp(-2) exp(5)] %19 TO BE ESTIMATED HERE +'TXTL_UTR_UTR1_F' , exp(-.2), [exp(-4) exp(2)] %20 fixed in mcmc_info_vnprl_F2 +'TXTL_PLAC_RNAPbound_Kd' , exp(13.8), [exp(5) exp(17)] %21 from est params above +'TXTL_PLAC_RNAPbound_F' , exp(2.6), [exp(-2) exp(5)] %22 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAPBOUND_TERMINATION_RATE' , exp(1.8), [exp(0) exp(12)] %23 from est params above +'TXTL_NTP_RNAP_1_F' , exp(0), [exp(-2) exp(3)] %24 fixed in mcmc_info_vnprl_F2 +'TXTL_NTP_RNAP_2_F' , exp(0), [exp(-2) exp(3)] %25 fixed in mcmc_info_vnprl_F2 +'TL_AA_F' , exp(-0.3), [exp(-3) exp(3)] %26 fixed in mcmc_info_vnprl_F2 +'TL_AGTP_F' , exp(-1.2), [exp(-4) exp(2)] %27 fixed in mcmc_info_vnprl_F2 +'TXTL_RIBOBOUND_TERMINATION_RATE' , exp(2.3), [exp(0) exp(12)] %28 from est params above +'TXTL_RNAdeg_F' , exp(0), [exp(-3) exp(3)] %29 fixed in mcmc_info_vnprl_F2 +'TXTL_RNAdeg_kc' , exp(-0.45), [exp(-5) exp(3)] %30 from est params above +'RNAP' , exp(1.4419), [exp(-1) exp(8)] %31 31% from est params above +'RNase' , exp(8.5), [exp(5) exp(10)] %32 from est params above +'Ribo' , exp(3.75), [exp(1) exp(6)] %33 from est params above +'TXTL_PROT_deGFP_MATURATION' , exp(-6.07), [exp(-9) exp(-3)] %34 fixed in mcmc_info_vnprl_F2 +'TXTL_INDUCER_LASR_AHL_Kd' , exp(-2), [exp(5) exp(20)] %36-1 +'TXTL_INDUCER_LASR_AHL_F' , exp(0), [exp(-6) exp(6)] %37-1 +'TXTL_PLAS_RNAPbound_Kd' , exp(30), [exp(25) exp(40)]%38-1 +'TXTL_PLAS_RNAPbound_F' , exp(3), [exp(-6) exp(6)]%39-1 pol_{F,las} +'TXTL_PLAS_TFBIND_Kd' , exp(5), [exp(0) exp(10)]%40-1 plas_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_Kd' , exp(8), [exp(0) exp(15)]%41-1 plas-pol_{tf, Kd} < +'TXTL_PLAS_TFRNAPbound_F' , exp(0), [exp(-6) exp(6)]%42-1 plas-pol_{tf, F} +'TXTL_PLAS_TFBIND_F' , exp(0), [exp(-6) exp(6)]};%43-1 plas_{tf, F} +% Set the master vector values that are set from the values estimated in "vnprl_F2" +activeNames(indicesMasterVectorEstimated, 2) = num2cell(exp(paramVecToUse)); +% Set the master vector values that were already fixed in "vnprl_F2" +preFixedParams = {... +4 'AGTPreg_ON' , exp( -3.9120) +34 'TXTL_PROT_deGFP_MATURATION' , exp( -6.0748) +8 'TXTL_PTET_RNAPbound_F' , exp( 1.5000) +9 'TXTL_NTP_RNAP_1_Kd' , exp( 2.9459) +10 'TXTL_NTP_RNAP_2_Kd' , exp( 13.9970) +13 'TL_AA_Kd' , exp( 6.5566) +14 'TL_AGTP_Kd' , exp( 14.5090) +20 'TXTL_UTR_UTR1_F' , exp( -0.2000) +22 'TXTL_PLAC_RNAPbound_F' , exp( 1.5000) +24 'TXTL_NTP_RNAP_1_F' , exp( 0) +25 'TXTL_NTP_RNAP_2_F' , exp( 0) +26 'TL_AA_F' , exp( -0.3000) +27 'TL_AGTP_F' , exp( -1.2000) +29 'TXTL_RNAdeg_F' , exp( 0)}; % checked and verified. +% set the prefixed params elements in master vector to the values in +% prefixed params. +% +activeNames(cell2mat(preFixedParams(:,1)),2) = preFixedParams(:,3); +% format short g; +% aa = [log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),2))) log(cell2mat(activeNames(cell2mat(preFixedParams(:,1)),3)))] +% +% pdiagnostic = cell2table([num2cell(aa) preFixedParams(:,1) num2cell([-aa(:,1)+aa(:,3) ... +% aa(:,1)-aa(:,2) (1:length(aa))']) (activeNames(cell2mat(preFixedParams(:,1)),1))],... +% 'VariableNames', {'logval', 'loglb', 'logub', 'mvix', 'ubdiff', 'lbdiff', 'ix', 'name'}) +% pdiagnostic.lbdiff./pdiagnostic.ubdiff +% pdiagnostic = +% +% 14×8 table +% +% logval loglb logub mvix ubdiff lbdiff ix name +% _______ _____ _____ ____ ______ ______ __ ____________________________ +% +% -3.912 -6 -1 4 2.912 2.088 1 'AGTPreg_ON' +% -6.0748 -9 -3 34 3.0748 2.9252 2 'TXTL_PROT_deGFP_MATURATION' +% 1.5 0 4 8 2.5 1.5 3 'TXTL_PTET_RNAPbound_F' +% 2.9459 0 5 9 2.0541 2.9459 4 'TXTL_NTP_RNAP_1_Kd' +% 13.997 10 20 10 6.003 3.997 5 'TXTL_NTP_RNAP_2_Kd' +% 6.5566 3 10 13 3.4434 3.5566 6 'TL_AA_Kd' +% 14.509 10 18 14 3.491 4.509 7 'TL_AGTP_Kd' +% -0.2 -4 2 20 2.2 3.8 8 'TXTL_UTR_UTR1_F' +% 1.5 -2 5 22 3.5 3.5 9 'TXTL_PLAC_RNAPbound_F' +% 0 -2 3 24 3 2 10 'TXTL_NTP_RNAP_1_F' +% 0 -2 3 25 3 2 11 'TXTL_NTP_RNAP_2_F' +% -0.3 -3 3 26 3.3 2.7 12 'TL_AA_F' +% -1.2 -4 2 27 3.2 2.8 13 'TL_AGTP_F' +% 0 -3 3 29 3 3 14 'TXTL_RNAdeg_F' +%% Next set the parameters estimated in mcmc_info_ZSIFFL_mtet_phase1.m +% +% The values estimated are: +mtet_phase1_params = ... +{... +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(14) , [exp(0) exp(17)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-1) , [exp(-10) exp(5)] +12 , 'TXTL_PTET_sequestration_F' , exp(1.314) , [exp(-2) exp(5)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) , [exp(-15) exp(5)] +17 , 'TXTL_INDUCER_TETR_ATC_F' , exp(1.577) , [exp(-2) exp(5)] +18 , 'TXTL_DIMER_tetR_Kd' , exp(-10) , [exp(-20) exp(-7)] +19 , 'TXTL_DIMER_tetR_F' , exp(1.447) , [exp(-2) exp(5)]... +}; +activeNames(cell2mat(mtet_phase1_params(:,1)),2) = mtet_phase1_params(:,3); +activeNames(cell2mat(mtet_phase1_params(:,1)),3) = mtet_phase1_params(:,4); +%% next we set the parameters estimated from mcmc_info_ZSIFFL_mtet_phase2.m +% The values estimated are: +mtet_phase2_params = ... +{... +1 , 'TX_elong_glob' , exp(2.3) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.7) ,[exp(1) exp(6)] %2 from est params above +3 , 'AGTPdeg_time' , exp(10.05) ,[exp(8) exp(12)] %3 from est params above +31 , 'RNAP' , exp(5.9) ,[exp(1) exp(15)] %31 31% from est params above +32 , 'RNase' , exp(9.2) ,[exp(7) exp(11)] %32 from est params above +33 , 'Ribo' , exp(5.9) ,[exp(1) exp(15)] %33 from est params above +21 , 'TXTL_PLAC_RNAPbound_Kd' , exp(10.5) ,[exp(5) exp(25)] %21 from est params above +7 , 'TXTL_PTET_RNAPbound_Kd' , exp(17) ,[exp(15) exp(25)] +11 , 'TXTL_PTET_sequestration_Kd' , exp(-2.7) ,[exp(-10) exp(10)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-6) ,[exp(-15) exp(15)]... +}; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% we also set the forward rate parameters, since those should not matter much, and any value around 1 is good +% the F rate parameters just set the timescale. +mtet_phase2_params = ... +{... +36 , 'TXTL_INDUCER_LASR_AHL_F' , exp(0) , [exp(-3) exp(5)] +38 , 'TXTL_PLAS_RNAPbound_F' , exp(0) , [exp(-3) exp(5)] +41 , 'TXTL_PLAS_TFRNAPbound_F' , exp(0) , [exp(-3) exp(5)] +42 , 'TXTL_PLAS_TFBIND_F' , exp(0) , [exp(-3) exp(5)] }; +activeNames(cell2mat(mtet_phase2_params(:,1)),2) = mtet_phase2_params(:,3); +activeNames(cell2mat(mtet_phase2_params(:,1)),3) = mtet_phase2_params(:,4); +%% +training_fullC_params = ... +{... +11 , 'TXTL_PTET_sequestration_Kd' , exp(-0.5) ,[exp(-2) exp(1)] +16 , 'TXTL_INDUCER_TETR_ATC_Kd' , exp(-2) ,[exp(-10) exp(5)] +35 , 'TXTL_INDUCER_LASR_AHL_Kd' , exp(13), [exp(5) exp(15)] ... +}; +activeNames(cell2mat(training_fullC_params(:,1)),2) = training_fullC_params(:,3); +activeNames(cell2mat(training_fullC_params(:,1)),3) = training_fullC_params(:,4); +training_fullD_params = ... +{... +1 , 'TX_elong_glob' , exp(3.121) ,[exp(1) exp(6)] %1 from est params above +2 , 'TL_elong_glob' , exp(3.436) ,[exp(1) exp(6)] %2 from est params above +}; +activeNames(cell2mat(training_fullD_params(:,1)),2) = training_fullD_params(:,3); +activeNames(cell2mat(training_fullD_params(:,1)),3) = training_fullD_params(:,4); +% add the combinatorial activator knockoff parameter +% 'TXTL_PLAS_TFBIND_Kd', exp(6) +% 'TXTL_PLAS_TFBIND_F', exp(0) % % +multiplier = 100; +plasTFbind_KD = exp(6); +activeNames = [activeNames; +{'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_Kd', 1/(plasTFbind_KD*multiplier) , [exp(-20) exp(20)] +'TXTL_COMBINATORIAL_ACTIVATOR_KNOCKOFF_F', (plasTFbind_KD*multiplier), [exp(-20) exp(20)]}]; +% reverse rate = 1 +% forward rate / reverse rate = exp(6)*100/exp(0) ~= exp(10.5) = 1/kD => KD +% = exp(-10.6) +% forward rate = exp(10.5) +% +%% Next, remove the ptet rnap binding and the forward rate reacton parameters. +% these parameters are not present in the model +activeNames = activeNames(setdiff(1:44, [7, 8]), :); +%% +estParamsIX = [21 23 28 31 33 37 39 40]'-2; +estParams = activeNames(estParamsIX,1); +activeNames(estParamsIX,:); +% skipping AGTPdeg_rate, AGTPreg_ON, TXTL_PROT_deGFP_MATURATION +% fixedParams vector +fixedParamsIX = setdiff((1:size(activeNames, 1))', estParamsIX); +fixedParamsIX +estParamIx +estParamsIx +estParamsIX +proj_ZSIFFL_predictionA('nW', 18, 'nPoints', 50, 'nIter', 1, 'parallel', false, 'multiplier', 1, 'thinning', 1) +close all +edit exportmobj.m +mi(1) +mi(1).doseReordering +mi(1).dosedNames +currdi +currdi.timeVec +currdi.timeVector +size(marrayOrd) +size(dose) +clc +close all +mIFFL +mIFFL.spec +%-- 6/25/19, 2:35 PM --% +edit schemer_import +addpath('/Users/vipulsinghal/Dropbox/Documents/MATLAB/scottclowe-matlab-schemer-f8115af') +edit schemer_import +schemer_import +%-- 6/25/19, 2:51 PM --% +ls +edit FishWatcherV3c.mlapp +edit AmatPipeline_ver9_filterNdecode.m +edit AmatPipeline_ver9_registration.m +edit LoadAmatPipeline_ver6.m +edit NormalizeMERFISHData2.m +edit NormalizeMERFISHData3.m +edit NormalizeMERFISHData4.m +edit OneCellApplyFilters2p.m +edit OneCellCorrectDrift2_v23_t.m +edit OneCellCorrectDrift2_v3p2.m +schemer_import +addpath('/Users/vipulsinghal/Dropbox/Documents/MATLAB/scottclowe-matlab-schemer-f8115af') +schemer_import +%-- 6/29/19, 12:44 PM --% +dir mcmc_simbio/projects/ +edit IFFL_predictionA.m +txtl_init +mcmc_init +edit IFFL_predictionA.m +edit proj_ZSIFFL_predictionA.m +da +ms +ms{1} +whos +mIFFL.reactinos +mIFFL.Reactions +currmi +di +currdi +da +help factors +help twofactors +tfac +mIFFL +mIFFL.species +close all +clear all +clc +IFFL_predictionA +meantraj = mean(currda(:, speciesGrp, :, dID), 3); +size(meantraj) +currda +size(currda) +da +mIFFL.spe +mi +mi.emo +mi(4).emo +get(mi(4).emo) +get(mi(4).emo, 'ValueInfo') +vi = get(mi(4).emo, 'ValueInfo') +vi(:) +vi(1) +vi(47) +vi(46) +vi(45) +vi(44) +get(mi(4).emo, 'ValueInfo') +get(mi(4).emo) +get(mi(4).emo, 'InitialVlaues') +get(mi(4).emo, 'InitialValues') +format short g; get(mi(4).emo, 'InitialValues') +get(mi(4).emo) +for i = 1:47 +names{i} = vi(i).Name; +end +names +names' +[names', mat2cell(get(mi(4).emo, 'InitialValues'))] +help num2cell +[names', num2cell(get(mi(4).emo, 'InitialValues'))] +dose +currmi +mi \ No newline at end of file diff --git a/mcmc_simbio/unused_drafts/dsg2014_d1.m b/mcmc_simbio/unused_drafts/dsg2014_d1.m new file mode 100755 index 0000000..bed3b56 --- /dev/null +++ b/mcmc_simbio/unused_drafts/dsg2014_d1.m @@ -0,0 +1,21 @@ +function gd = dsg2014_d1 +% dsg2014_d1 Dan / Zoltan's ACS paper data. +% This file calls another file containing the raw data, and then organizes +% that into a groupedData format. + +[t, y, meta] = load_ACSDSG2014('RNAdeg'); +Time = repmat(t*60, 9, 1); +RNA = reshape(y, numel(y), 1); +dosematrix = [[37.5, 75, 150, 200, 600, 700, 800, 900, 1000]; + zeros(length(t)-1, size(y, 2))]; + +Dose = reshape(dosematrix, numel(dosematrix), 1); +clear dosematrix +idmat = mtimes((1:9)', ones(1, length(t))); +ID = reshape(idmat', numel(idmat), 1); + +dttable = table(ID, Time, RNA, Dose); +gd = groupedData(dttable); + +end + diff --git a/mcmc_simbio/unused_drafts/zsIFFL_species b/mcmc_simbio/unused_drafts/zsIFFL_species new file mode 100755 index 0000000..386c5c1 --- /dev/null +++ b/mcmc_simbio/unused_drafts/zsIFFL_species @@ -0,0 +1,113 @@ + + +% misc. species +'RNAP' +'Ribo' +'RecBCD' +'RNase' +'AGTP' +'CUTP' +'AA' +'AGMP' +'CUMP' +'OC12HSL' +'aTc' + + + +'DNA plac--utr1--lasR' +'RNAP:DNA plac--utr1--lasR' +'AGTP:RNAP:DNA plac--utr1--lasR' +'CUTP:RNAP:DNA plac--utr1--lasR' +'CUTP:AGTP:RNAP:DNA plac--utr1--lasR' +'term_RNAP:DNA plac--utr1--lasR' + + +'RNA utr1--lasR' +'Ribo:RNA utr1--lasR' +'AA:Ribo:RNA utr1--lasR' +'AA:AGTP:Ribo:RNA utr1--lasR' +'term_Ribo:RNA utr1--lasR' + + +'RNA utr1--lasR:RNase' +'Ribo:RNA utr1--lasR:RNase' +'AA:AGTP:Ribo:RNA utr1--lasR:RNase' +'term_Ribo:RNA utr1--lasR:RNase' +'AA:Ribo:RNA utr1--lasR:RNase' + +'protein lasR' +'OC12HSL:protein lasR' + + + +'DNA plas--utr1--tetR' +'RNAP:DNA plas--utr1--tetR' +'AGTP:RNAP:DNA plas--utr1--tetR' +'CUTP:RNAP:DNA plas--utr1--tetR' +'CUTP:AGTP:RNAP:DNA plas--utr1--tetR' +'term_RNAP:DNA plas--utr1--tetR' + + +'DNA plas--utr1--tetR:OC12HSL:protein lasR' +'RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +'AGTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +'CUTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +'CUTP:AGTP:RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' +'term_RNAP:DNA plas--utr1--tetR:OC12HSL:protein lasR' + + +'RNA utr1--tetR' +'Ribo:RNA utr1--tetR' +'AA:Ribo:RNA utr1--tetR' +'AA:AGTP:Ribo:RNA utr1--tetR' +'term_Ribo:RNA utr1--tetR' + +'RNA utr1--tetR:RNase' +'Ribo:RNA utr1--tetR:RNase' +'AA:Ribo:RNA utr1--tetR:RNase' +'AA:AGTP:Ribo:RNA utr1--tetR:RNase' +'term_Ribo:RNA utr1--tetR:RNase' + +'protein tetR' +'protein tetRdimer' +'2 aTc:protein tetRdimer' + + +%% deGFP combinatorial promoter tx species. might have an error. +'DNA plas_ptet--utr1--deGFP' +'RNAP:DNA plas_ptet--utr1--deGFP' +---- +does this dna not bind agtp cutp without activation? maybe thats ok? +---- + +'DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +'AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +'CUTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +'CUTP:AGTP:RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' +'term_RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR' + +'DNA plas_ptet--utr1--deGFP:protein tetRdimer' +'DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer' +'RNAP:DNA plas_ptet--utr1--deGFP:OC12HSL:protein lasR:protein tetRdimer' + + +'RNA utr1--deGFP' +'Ribo:RNA utr1--deGFP' +'AA:Ribo:RNA utr1--deGFP' +'AA:AGTP:Ribo:RNA utr1--deGFP' +'term_Ribo:RNA utr1--deGFP' + + +'RNA utr1--deGFP:RNase' +'Ribo:RNA utr1--deGFP:RNase' +'AA:Ribo:RNA utr1--deGFP:RNase' +'AA:AGTP:Ribo:RNA utr1--deGFP:RNase' +'term_Ribo:RNA utr1--deGFP:RNase' + +'protein deGFP' +'protein deGFP*' + +-------- + diff --git a/models/fbs/README b/models/fbs/README old mode 100644 new mode 100755 diff --git a/models/fbs/genereg_params.m b/models/fbs/genereg_params.m old mode 100644 new mode 100755 diff --git a/models/fbs/genswitch.py b/models/fbs/genswitch.py old mode 100644 new mode 100755 diff --git a/models/fbs/repressilator.m b/models/fbs/repressilator.m old mode 100644 new mode 100755 diff --git a/models/fbs/repressilator_plot.m b/models/fbs/repressilator_plot.m old mode 100644 new mode 100755 diff --git a/modules/paramest/paramestCostFcn.m b/modules/paramest/paramestCostFcn.m deleted file mode 100644 index 0990a5d..0000000 --- a/modules/paramest/paramestCostFcn.m +++ /dev/null @@ -1,112 +0,0 @@ -% Written by Zoltan A Tuza, Mar 2013 -% Copyright (c) 2012 by California Institute of Technology -% All rights reserved. -% -% Redistribution and use in source and binary forms, with or without -% modification, are permitted provided that the following conditions are -% met: -% -% 1. Redistributions of source code must retain the above copyright -% notice, this list of conditions and the following disclaimer. -% -% 2. Redistributions in binary form must reproduce the above copyright -% notice, this list of conditions and the following disclaimer in the -% documentation and/or other materials provided with the distribution. -% -% 3. The name of the author may not be used to endorse or promote products -% derived from this software without specific prior written permission. -% -% THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -% IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -% DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -% INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -% STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -% IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -% POSSIBILITY OF SUCH DAMAGE. - - -function cost = paramestCostFcn(p_act,data) - -% sampling time points -tspan = data.xdata; -% mapping external parameters -pVector = data.p0; - -% deciding initial values are estimated or not -if size(data.x0_mapping,1) == 0 - pVector(data.p_mapping) = p_act; -else - pVector(data.p_mapping) = p_act(1:size(data.p_mapping,1)); - - % updating initial values with current estimate - cases = size(data.x0,2); - startId = size(data.p_mapping,1); - initParams = size(data.x0_mapping,1); - for k=1:cases - data.x0(data.x0_mapping,k) = p_act(startId+k:(startId+k)+initParams-1); - end - -end - -% evaluate parameters dependencies -if ~isempty(data.p_dependecies) - cellfun(@(x) evalc(strrep(x,'p','pVector')),data.p_dependecies,'UniformOutput',false); -end - -simTime =[]; -%% start of simulations -try - % run simulations with different initial values - for k=1:size(data.x0,2) - tic - [t(:,k),y{k}] = ode15s(@(t,x)data.modelFcn(t,x,pVector),tspan,data.x0(:,k)); - simTime(k) = toc; - - if sum(y{k}(:,data.outputCheck)) == 0 - - cost = Inf; - disp(sprintf('cost:%f\n',cost)); - return; - - end - end - -%% calculate cost - cost = 0; - - - for k=1:size(data.x0,2) - cost = cost + sum((data.ydata(:,k)-sum(y{k}(:,data.targetSpecies),2)*data.speciesScaleFactor).^2); - end - - - -catch err - cost = Inf; - err.message -end - -str1 = sprintf('costV:%6.2G\t',cost); -str2 = strtrim(sprintf('p:%f ',p_act)); -str3 = sprintf('%6.2f sec',sum(simTime)); -disp([str1 ' ' str2 ' ' str3]); - -if data.debugMode ==1 && cost < Inf - - figure(1); - hold on - for k=1:size(data.x0,2) - plot(data.xdata/60,[data.ydata(:,k) sum(y{k}(:,data.targetSpecies),2)*data.speciesScaleFactor]) - end - hold off - title(sprintf('current cost value:%f',cost)) - disp('push any key to continue') - pause - close all - - -end \ No newline at end of file diff --git a/modules/paramest/parameter_estimation_patternsearch.m b/modules/paramest/parameter_estimation_patternsearch.m deleted file mode 100644 index 3145b4e..0000000 --- a/modules/paramest/parameter_estimation_patternsearch.m +++ /dev/null @@ -1,112 +0,0 @@ -%% load datasets -% -% e15_pr_gfp_mg_0821 = wholeExpfileReader('ACS_paper_data/e15_pr_gfp_pr_gfp_mg_grad_0821_data.csv',';',2); -% e15_pr_gfp_mg_0821 = processMGData(e15_pr_gfp_mg_0821); -% e15_pr_gfp_mg_0821.valveNames = {'pos cont','neg cont','pr-gfp 1nM','pr-gfp 2nM','pr-gfp 3nM','pr-gfp 5nM','pr-gfp 10nM','pr-gfp 15nM'... -% 'pr-gfp-s15-mg 1nm','pr-gfp-s15-mg 2nM','pr-gfp-s15-mg 3nM','pr-gfp-s15-mg 5nM','pr-gfp-s15-mg 10nM','pr-gfp-s15-mg 15nM'}; -% - -data.xdata = 1:281; %e15_pr_gfp_mg_0821.t_vec; -data.ydata = rand(1,281)*50+10; %e15_pr_gfp_mg_0821.noBg(:,3:8,2)./2683.9; - -%% initial values and parameters - -geneexpr -close all; - dataOut = parseGetEqOutput(Mobj); - -data.x0 = dataOut.initialValues; -data.p0 = dataOut.parameters; - -data.modelFcn = str2func(dataOut.modelFcn); -data.costFcn = @paramestCostFcn; - -% building initial cases -% -% select a species (e.g. DNA or induder, which are subject to variations in the experiments) -speciesInd = findStringInAList(dataOut.speciesNames,'[DNA p70--rbs--deGFP]'); -% specify the initial values for the selected species -speciesInitialValues = [1 2 3 4]; % 1-4nM -% transform x0 vector to the right format (each column -> one different initial values vector) -data.x0 = repmat(data.x0,1,size(speciesInitialValues,2)); -data.x0(speciesInd,:) = speciesInitialValues; - -% which species are subject to initial value estimation -%data.x0_mapping = speciesInd; -data.x0_mapping = []; -% adjusting parameter vector size based on the initial values -if ~isempty(data.x0_mapping) - data.p0 = [data.p0; data.x0(speciesInd,:)']; -end - -% select parameters for estimation, list is given by parseGetEqOutput (parameterNames field) -ParametersToEstimate = {'TXTL_TL_rate',... - 'TXTL_UTR_RBS_F',... - 'TXTL_transcription_rate1' - }; - -pSelect = cellfun(@(x) findStringInAList(dataOut.parameterNames,x),ParametersToEstimate); - -% selecting parameters of interest -data.p_mapping = pSelect; - -gfp = findStringInAList(dataOut.speciesNames,'[protein deGFP*]'); - -% cost function target species -data.targetSpecies = gfp; -% conversion btw nM vs uM -data.speciesScaleFactor = 0.001; -% ploting simulation results with the origianl data in each step -data.debugMode =0; -% output check -data.outputCheck = gfp; - -% parameter perturbation -% select parameters to perturb: -parametersToPerturb = data.p_mapping; -data.parameterPerturbNum = 10; -% perturbation range in percentage -data.parameterPerturbRange = 0.5; -% give the indexes of parameters are subject to parameter estimation - -data.parameterPerturbList = find(ismember(data.p_mapping,parametersToPerturb) == 1); -data.notParameterPerturbList = find(ismember(data.p_mapping,parametersToPerturb) == 0); - -% parameter dependency rules -ntp_consumption_rate = findStringInAList(dataOut.parameterNames,'TXTL_NTP_consumption'); -aa_consumption_rate = findStringInAList(dataOut.parameterNames,'TXTL_TL_AA_consumption'); -K_tx = findStringInAList(dataOut.parameterNames,'TXTL_transcription_rate1'); -K_tl = findStringInAList(dataOut.parameterNames,'TXTL_TL_rate'); -data.p_dependecies{1} = sprintf('p(%d)=9*p(%d)',ntp_consumption_rate,K_tx); -data.p_dependecies{2} = sprintf('p(%d)=2*p(%d)',aa_consumption_rate,K_tl); - -options = psoptimset('TolMesh',1e-8,'MaxIter',2000); - -% parameters subject to parameter estimation -pVec = data.p0(data.p_mapping); - -% default generate lower and upper bounds -default_lb = 0; -default_ub = 100; - -LB = repmat(default_lb,size(pVec),1); -UB = repmat(default_ub,size(pVec),1); - -% handle perturbed initial parameter cases -% Latin Hypercube sampling from a uniform distribution -p0Array = zeros(size(data.parameterPerturbList,2)+size(data.notParameterPerturbList,2),data.parameterPerturbNum); -p0Array(data.parameterPerturbList,:) = lhsu(pVec(data.parameterPerturbList)-data.parameterPerturbRange.*pVec(data.parameterPerturbList),(1+data.parameterPerturbRange).*pVec(data.parameterPerturbList),data.parameterPerturbNum)'; -p0Array(data.notParameterPerturbList,:) = repmat(pVec(data.notParameterPerturbList),1,data.parameterPerturbNum); - - -for k = 1:data.parameterPerturbNum - -[x(:,k),fval(k),exitflag(k),output(k)] = ... - patternsearch(@(y)data.costFcn(y,data),p0Array(:,k),[],[],[],[],LB,UB,[],options); -end - - - - - - diff --git a/startup.m b/startup.m new file mode 100755 index 0000000..af03c6d --- /dev/null +++ b/startup.m @@ -0,0 +1,3 @@ +% startup.m +txtl_init +mcmc_init diff --git a/sysID/MCMC_example.m b/sysID/MCMC_example.m deleted file mode 100644 index 042ffd1..0000000 --- a/sysID/MCMC_example.m +++ /dev/null @@ -1,5 +0,0 @@ -% MCMC Parameter Estimation example using the TXTL toolbox -% This file demonstrates how to use the Goodman and Weare MCMC algorithm -% for performing Bayesian Parameter inference. - -% \ No newline at end of file diff --git a/tests/RNAdegradation_test.m b/tests/RNAdegradation_test.m deleted file mode 100644 index ac60de8..0000000 --- a/tests/RNAdegradation_test.m +++ /dev/null @@ -1,47 +0,0 @@ -% Accessing individual parameters: Mobj.UserData.ReactionConfig.RNase_F for example. -% Accessing initial concentrations. Mobj.species(2).initialAmount (for the -% second species. can use findspecies to get tthe index). - -% We do a parameter study of the RNA degradation. - -% Nominal Parameters -close all; clear all; clc -tube1 = txtl_extract('E30VNPRL'); -tube2 = txtl_buffer('E30VNPRL'); -tube3 = txtl_newtube('gene_expression'); -dna_deGFP = txtl_add_dna(tube3, 'p70(50)', 'rbs(20)', 'deGFP(1000)', 0, 'plasmid'); - -Mobj = txtl_combine([tube1, tube2, tube3]); -txtl_addspecies(Mobj, 'RNA rbs--deGFP', 200); - - - -[simData] = txtl_runsim(Mobj,14*60*60); -t_ode = simData.Time; -x_ode = simData.Data; -RNA1 = findspecies(Mobj, 'RNA rbs--deGFP'); -RNA2 = findspecies(Mobj, 'Ribo:RNA rbs--deGFP'); -RNA3 = findspecies(Mobj, 'AA:AGTP:Ribo:RNA rbs--deGFP') ; -RNA4 = findspecies(Mobj, 'RNA rbs--deGFP:RNase') ; -RNA5 = findspecies(Mobj, 'AA:AGTP:Ribo:RNA rbs--deGFP:RNase') ; -RNA6 = findspecies(Mobj, 'Ribo:RNA rbs--deGFP:RNase') ; - -figure -subplot(2,1,1) -semilogy(t_ode/60, x_ode(:,RNA1)+x_ode(:,RNA2)+x_ode(:,RNA3)+x_ode(:,RNA4)+x_ode(:,RNA5)+x_ode(:,RNA6)) -axis([0.01 240 0.01 300]) -title('logy, RNA degradation, initial RNA conc = 200nM') - -subplot(2,1,2) -plot(t_ode/60, x_ode(:,RNA1)+x_ode(:,RNA2)+x_ode(:,RNA3)+x_ode(:,RNA4)+x_ode(:,RNA5)+x_ode(:,RNA6)) -axis([0 240 0.01 300]) -title('RNA degradation, initial RNA conc = 200nM') - -% The graph has an initial half life of 15 min, about what we want, and this half life stays at this value. -% This is pretty good. What we would like is to get the number closer to -% 12 min. -% Lets see what happens when we change initial RNase conc, the k_deg, and the -% k_on and k_off. - -% Actually lets do this later. For now, this is good enough. We can try to get it close to 12 nM in the next iteration. - diff --git a/tests/atp_test.m b/tests/atp_test.m deleted file mode 100644 index ce11144..0000000 --- a/tests/atp_test.m +++ /dev/null @@ -1,30 +0,0 @@ -% ATP degradation work - -close all; clear all; clc -tube1 = txtl_extract('E30'); -tube2 = txtl_buffer('E30'); -tube3 = txtl_newtube('gene_expression'); -dna_deGFP = txtl_add_dna(tube3, 'p70(50)', 'rbs(20)', 'deGFP(1000)', 0, 'plasmid'); - -Mobj = txtl_combine([tube1, tube2, tube3]); - - - - -[simData] = txtl_runsim(Mobj,14*60*60); -t_ode = simData.Time; -x_ode = simData.Data; -ATP1 = findspecies(Mobj, 'ATP'); -ATP2 = findspecies(Mobj, 'AA:ATP:Ribo:RNA rbs--deGFP:RNase'); -ATP3 = findspecies(Mobj, 'AA:ATP:Ribo:RNA rbs--deGFP'); - -figure -subplot(2,1,1) -semilogy(t_ode/60, x_ode(:,ATP1)+x_ode(:,RNA2)+x_ode(:,RNA3)+x_ode(:,RNA4)+x_ode(:,RNA5)+x_ode(:,RNA6)) -axis([0 240 0.01 300]) -title('logy, RNA degradation, initial RNA conc = 200nM') - -subplot(2,1,2) -plot(t_ode/60, x_ode(:,ATP1)+x_ode(:,RNA2)+x_ode(:,RNA3)+x_ode(:,RNA4)+x_ode(:,RNA5)+x_ode(:,RNA6)) -axis([0 240 0.01 300]) -title('RNA degradation, initial RNA conc = 200nM') \ No newline at end of file diff --git a/tests/geneexpr_DNAsweep.m b/tests/geneexpr_DNAsweep.m deleted file mode 100644 index e45f278..0000000 --- a/tests/geneexpr_DNAsweep.m +++ /dev/null @@ -1,52 +0,0 @@ -close all; clear all - -% 30 nM initial DNA conc, match figure 1c in PRL paper. -tube1 = txtl_extract('E31VNPRL'); -tube2 = txtl_buffer('E31VNPRL'); -tube3 = txtl_newtube('gene_expression'); -dna_deGFP = txtl_add_dna(tube3,'p70(50)', 'rbs(20)', 'deGFP(1000)', 30, 'plasmid'); -Mobj = txtl_combine([tube1, tube2, tube3]); -[simData] = txtl_runsim(Mobj,14*60*60); -txtl_plot(simData,Mobj); -t_ode = simData.Time; - x_ode = simData.Data; -RNA1 = findspecies(Mobj, 'RNA rbs--deGFP'); -RNA2 = findspecies(Mobj, 'Ribo:RNA rbs--deGFP'); -RNA3 = findspecies(Mobj, 'AA:AGTP:Ribo:RNA rbs--deGFP') ; -RNA4 = findspecies(Mobj, 'RNA rbs--deGFP:RNase') ; -RNA5 = findspecies(Mobj, 'AA:AGTP:Ribo:RNA rbs--deGFP:RNase') ; -RNA6 = findspecies(Mobj, 'Ribo:RNA rbs--deGFP:RNase') ; -figure -plot(t_ode/60, x_ode(:,RNA1)+x_ode(:,RNA2)+x_ode(:,RNA3)+x_ode(:,RNA4)+x_ode(:,RNA5)+x_ode(:,RNA6)) -title('RNA levels, initial DNA conc = 30nM') - -count = 0; Mobj = cell(6,1); simData = cell(6,1); t_ode = cell(6,1); x_ode = cell(6,1); -for DNAinitial = [0.5 5 10 20 30 40] - count = count+1; - tube1 = txtl_extract('E31VNPRL'); - tube2 = txtl_buffer('E31VNPRL'); - tube3 = txtl_newtube('gene_expression'); - dna_deGFP = txtl_add_dna(tube3, 'p70(50)', 'rbs(20)', 'deGFP(1000)', DNAinitial, 'plasmid'); - Mobj{count} = txtl_combine([tube1, tube2, tube3]); - [simData{count}] = txtl_runsim(Mobj{count},8*60*60); - t_ode{count} = simData{count}.Time; - x_ode{count} = simData{count}.Data; -end -figure -colororder = lines; -for i = 1:6 - iGFP = findspecies(Mobj{i}, 'protein deGFP*'); - h(i) = plot(t_ode{i}/60, x_ode{i}(:,iGFP)); - hold on - set(h(i), 'Color', colororder(i,:), 'LineWidth', 1.5); - hold on -end - axis([0 55 0 1350]) - legend(h, {'0.5 nM', '5 nM', '10 nM', '20 nM', '30 nM', '40 nM'}, 'Location', 'NorthEastOutside') - title('deGFP expression as a function of initial DNA conc'); -xlabel('time, min') -ylabel('protein conc nM') -% Automatically use matlab mode in emacs (keep at end of file) -% Local variables: -% mode: matlab -% End: diff --git a/tests/test_basic_examples.m b/tests/test_basic_examples.m old mode 100644 new mode 100755 diff --git a/txtl_de_init.m b/txtl_de_init.m new file mode 100755 index 0000000..de9f5bd --- /dev/null +++ b/txtl_de_init.m @@ -0,0 +1,15 @@ +function txtldir = txtl_de_init +fp = mfilename('fullpath'); +slashes = regexp(fp, '/'); +filedir = fp(1:slashes(end)-1); +rmpath(filedir); +rmpath([filedir '/auxiliary']) +rmpath([filedir '/components']) +rmpath([filedir '/config']) +rmpath([filedir '/core']) +rmpath([filedir '/examples']) +rmpath([filedir '/examples/CompanionFiles']) +rmpath([filedir '/tests']) +rmpath([filedir '/data']) +txtldir = filedir; +end diff --git a/txtl_init.m b/txtl_init.m old mode 100644 new mode 100755 index 740b008..549f4a1 --- a/txtl_init.m +++ b/txtl_init.m @@ -1,9 +1,39 @@ -addpath([pwd '/auxiliary']) -addpath([pwd '/components']) -addpath([pwd '/config']) -addpath([pwd '/core']) -addpath([pwd '/examples']) -addpath([pwd '/examples/CompanionFiles']) -addpath([pwd '/modules/paramest']) -addpath([pwd '/tests']) -addpath([pwd '/data']) \ No newline at end of file +function txtldir = txtl_init +if ispc + + fp = mfilename('fullpath'); + slashes = regexp(fp, '\'); + filedir = fp(1:slashes(end)-1); + addpath(filedir); + addpath(genpath([filedir '\auxiliary'])) + addpath([filedir '\components']) + addpath([filedir '\config']) + addpath([filedir '\core']) + addpath([filedir '\examples']) + addpath([filedir '\examples\CompanionFiles']) + addpath([filedir '\tests']) + addpath([filedir '\data']) + addpath([filedir '\mcmc_simbio']) + addpath([filedir '\generate_paper_figs']) + + txtldir = filedir; +else + + fp = mfilename('fullpath'); + slashes = regexp(fp, '/'); + filedir = fp(1:slashes(end)-1); + addpath(filedir); + addpath(genpath([filedir '/auxiliary'])) + addpath([filedir '/components']) + addpath([filedir '/config']) + addpath([filedir '/core']) + addpath([filedir '/examples']) + addpath([filedir '/examples/CompanionFiles']) + addpath([filedir '/tests']) + addpath([filedir '/data']) + addpath([filedir '/mcmc_simbio']) + addpath([filedir '/generate_paper_figs']) + + txtldir = filedir; +end +end diff --git a/txtl_tutorial.m b/txtl_tutorial.m old mode 100644 new mode 100755 index 7d70410..bfff24a --- a/txtl_tutorial.m +++ b/txtl_tutorial.m @@ -1,8 +1,9 @@ %% TXTL Tutorial % txtl_tutorial.m - basic usage of the TXTL modeling toolbox +% % Vipul Singhal, 28 July 2017 % -% This file contains a simple tutorial of the TXTL modeling toolbox. You +% This file contains a tutorial of the TXTL modeling toolbox. You % will learn about setting up a negative autoregulation circuit, simulating it, % plotting the results, creating variations of the circuit, and % understanding the object structure of the models. @@ -33,7 +34,7 @@ Mobj = txtl_combine([tube1, tube2, tube3]); % Run a simulaton -% +% % At this point, the entire experiment is set up and loaded into 'Mobj'. % So now we just use standard Simbiology and MATLAB commands to run % and plot our results! diff --git a/unused/ProteinDegradationTest.m b/unused/ProteinDegradationTest.m old mode 100644 new mode 100755 diff --git a/unused/gamS_plot.m b/unused/gamS_plot.m old mode 100644 new mode 100755 diff --git a/unused/iffloop.m b/unused/iffloop.m old mode 100644 new mode 100755 diff --git a/unused/par_test_prime.m b/unused/par_test_prime.m new file mode 100755 index 0000000..f38bee4 --- /dev/null +++ b/unused/par_test_prime.m @@ -0,0 +1,31 @@ +delete(gcp('nocreate')) +parpool(48) +primeNumbers = primes(uint64(2^23)); +compositeNumbers = primeNumbers.*primeNumbers(randperm(numel(primeNumbers))); +factors = zeros(numel(primeNumbers),2); +numWorkers = [12 18 24 32 36 46 47 48]; +tLocal = zeros(size(numWorkers)); +for w = 1:numel(numWorkers) + tic; + parfor (idx = 1:numel(compositeNumbers), numWorkers(w)) + factors(idx,:) = factor(compositeNumbers(idx)); + end + tLocal(w) = toc; +end +numWorkers2 = [numWorkers] +tLocal2 = [tLocal] +f = figure; +speedup = tLocal2(1)./tLocal2; +plot(numWorkers2, speedup); +title('Speedup with the number of workers'); +xlabel('Number of workers'); +xticks(numWorkers2); +ylabel('Speedup'); +%% +f = figure; + +plot(numWorkers2, tLocal2); +title('time taken vs the number of workers'); +xlabel('Number of workers'); +xticks(numWorkers2); +ylabel('Time Taken'); \ No newline at end of file diff --git a/unused/paramest_lacoperon.m b/unused/paramest_lacoperon.m old mode 100644 new mode 100755 diff --git a/unused/protsynt81bis.m b/unused/protsynt81bis.m old mode 100644 new mode 100755 diff --git a/unused/protsynt_plot.m b/unused/protsynt_plot.m old mode 100644 new mode 100755 diff --git a/unused/sbio_genereg.m b/unused/sbio_genereg.m old mode 100644 new mode 100755 diff --git a/unused/tmpscript.m b/unused/tmpscript.m new file mode 100755 index 0000000..199b997 --- /dev/null +++ b/unused/tmpscript.m @@ -0,0 +1,13 @@ +for i = 18:length(activeNames2(:,3)) + % 7, 12, 15, 16, 17, 19, + + + + + +if (activeNames2{i, 3}(1)>activeNamesF3{i, 3}(1)) +error(['lower limit fail at ' num2str(i)]) +elseif activeNames2{i, 3}(2)