Repository navigation
Expand file tree
/
Copy pathexample_00_AllManuscriptExamples.m
More file actions
165 lines (137 loc) · 6.18 KB
/
Copy pathexample_00_AllManuscriptExamples.m
File metadata and controls
165 lines (137 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
% Install all SSIT tools and packages
% install
% Load STL1_4state model (see SI for manual creation)
STL1_4state = SSIT('STL1_4state');
% Solve ODEs:
STL1_4state = STL1_4state.solve(solver='ODE');
% Plot ODE solutions for mRNA:
STL1_4state.plotODE(speciesNames={'mRNA'}, timeVec=STL1_4state.tSpan, ...
lineProps={'linewidth',4}, TitleFontSize=26, Title='4-state STL1 (mRNA)', ...
AxisLabelSize=20, TickLabelSize=20, LegendFontSize=20, LegendLocation='east',...
Colors=[0.23,0.67,0.20], XLabel='Time', YLabel='Molecule Count')
% Plot ODE solutions for the four gene states:
STL1_4state.plotODE(speciesNames=STL1_4state.species(1:4), ...
Title='4-state STL1 (gene states)', YLabel='Molecule Count')
%%
% Set the number of simulations performed per experiment:
STL1_4state.ssaOptions.nSims=100;
% Use a negative initial time to allow model to equilibrate to an initial
% steady state prior to starting the subsequent simulation (burn-in):
STL1_4state.tSpan = [-100,STL1_4state.tSpan];
% Set the initial time:
STL1_4state.initialTime = -100;
% Run SSA:
STL1_4state = STL1_4state.solve(solver='SSA');
%%
% Set FSP 1-norm error tolerance:
STL1_4state.fspOptions.fspTol = 1e-4;
% Guess initial bounds on FSP StateSpace:
STL1_4state.fspOptions.bounds = [0;0;0;0;0;1;1;1;1;200];
% Approximate the steady state for the initial distribution:
STL1_4state.fspOptions.initApproxSS = true;
STL1_4state.tSpan = [0:5:60];
STL1_4state.initialTime = 0;
% Solve Model:
STL1_4state = STL1_4state.solve(solver='FSP');
%%
% Solve for time for mRNA to reach 100:
STL1_4state.fspOptions.escapeSinks.f = {'mRNA'};
STL1_4state.fspOptions.escapeSinks.b = 100;
STL1_4state = STL1_4state.solve(solver='FSP');
%%
% Solve the sensitivity problem:
STL1_4state = STL1_4state.solve(solver='fspSens');
%%
% Specify time points and numbers of cells for experiments
STL1_4state.tSpan = [0,1,2,4,6,8,10:5:55];
cellCounts = 1000*ones(1,16);
% Compute FIMs using FSP sensitivity results (for all parameters)
fims_full = STL1_4state.computeFIM(scale='log',observed='mRNA'); % full FIM
% Compute FIMs using FSP sensitivity results (Hog1 parameters fixed)
fims_free = STL1_4state.computeFIM(scale='log',observed='mRNA',...
freePars=(1:13)); % FIM sub matrix
% Evaluate the provided experiment design (in "cellCounts")
% to get the FIM:
[fimTotal_full,mleCovEstimate_full,fimMetrics_full] = ...
STL1_4state.evaluateExperiment(fims_full,cellCounts)
[fimTotal_free,mleCovEstimate_free,fimMetrics_free] = ...
STL1_4state.evaluateExperiment(fims_free,cellCounts)
%%
% Experiment Design: Find the FIM-based designs for total of 16k cells
% Compute the optimal number of cells from the FIM results using different
% design criteria:
nTotal = 16000;
nC_Dcov = STL1_4state.optimizeCellCounts(fims_full,nTotal,'D-cov');
nC_Trace = STL1_4state.optimizeCellCounts(fims_full,nTotal,'Trace');
nC_Dopt8 = STL1_4state.optimizeCellCounts(fims_full,nTotal,'D-opt-sub[1:8]');
nC_Dopt13 = STL1_4state.optimizeCellCounts(fims_full,nTotal,'D-opt-sub[9:13]');
nC_Dopt18 = STL1_4state.optimizeCellCounts(fims_full,nTotal,'D-opt-sub[14:18]');
%%
STL1_4state = STL1_4state.loadData('data/filtered_data_2M_NaCl_Step.csv',...
{'mRNA','RNA_STL1_total_TS3Full'},...
{'Replica',1;'Condition','0.2M_NaCl_Step'});
%%
% An example of fitting model parameters to loaded data using maximum likelihood
% estimation (MLE) is shown below.
% Set fitOptions, with the maximum allowable number of iterations to fit:
fitOptions = optimset('Display','iter','MaxIter',2000);
% Specify parameters to fit (all but Hog1 input parameters, which are fixed):
STL1_4state.fittingOptions.modelVarsToFit = 1:13;
% Search to Find the MLE:
STL1_4state = STL1_4state.maximizeLikelihood(fitOptions=fitOptions);
%%
% Specify Prior as log-normal distribution with wide uncertainty.
mu_log10 = [0.5,2,5,3.5,-0.4,1,0.2,0.4,-0.5,-1.3,-0.1,2,0.5]; % Prior log-mean
sig_log10 = 2*ones(1,13); % Prior log-standard deviation
% Log Prior (neglecting the normalization constant):
STL1_4state.fittingOptions.logPrior = ...
@(x)-sum((log10(x)-mu_log10).^2./(2*sig_log10.^2));
% Set MH proposal options, adjust aiming for acceptance ratio around 0.3-0.4:
proposalWidthScale = 0.01;
MHOptions.proposalDistribution = @(x)x+proposalWidthScale*randn(size(x));
% Set MH runtime options (number of samples, burnin, thinning, etc.):
MHOptions.numberOfSamples = 20; MHOptions.burnin = 5; MHOptions.thin = 2;
% Run Metropolis-Hastings:
STL1_4state = STL1_4state.maximizeLikelihood(fitOptions=MHOptions, fitAlgorithm='MetropolisHastings');
%%
% Select models to include in multimodel:
ModelNames = {'Model_DUSP1','Model_RUNX1','Model_BIRC3'};
for i = 1:3
% Load and prepare codes for each model
Models{i} = SSIT(['seqModels/',ModelNames{i}]);
% Set free parameters
Models{i}.fittingOptions.modelVarsToFit = 1:9;
% Assign shared (1,2) and unshared (3,..,9) parameters:
ParInds{i} = [1,2,(3:9)+7*(i-1)];
end
Models{1}.formPropensitiesGeneral;
% Set a constraint on model parameters:
Constraint = @(x) -var(log10([x(3:9);x(7*1+(3:9));x(7*2+(3:9))]));
% Create and initialize multimodel:
combinedModel = SSITMultiModel(Models, ParInds, Constraint);
combinedModel = combinedModel.initializeStateSpaces();
% Fit the multimodel:
fitOptions = optimset('Display','iter','MaxIter',1000);
combinedModel = combinedModel.maximizeLikelihood(fitOptions=fitOptions);
%% Call Pipeline to Fit scRNA-seq Models
% Specify pipeline to apply to model and arguments
% ("../../SSIT/src/exampleData/examplePipelines/fittingPipelineExample.m")
Pipeline = 'fittingPipelineExample';
pipelineArgs.maxIter = 1000; pipelineArgs.display = 'iter';
pipelineArgs.makePlot = false; pipelineArgs.nRounds = 1;
% Launch cluster jobs for all genes.
DataFileName = 'data/Raw_DEX_UpRegulatedGenes_ForSSIT.csv';
TAB = readtable(DataFileName);
geneNames = fields(TAB);
for iGene = 2:length(geneNames)-4
modelName = ['Model_',geneNames{iGene}];
saveName = ['seqModels/',modelName];
logfile = ['logFiles/log',modelName];
if iGene==2
load(saveName)
eval([modelName,'.formPropensitiesGeneral;']);
end
cmd = SSIT.generateCommandLinePipeline(saveName,modelName,Pipeline,...
pipelineArgs=pipelineArgs,saveFileOut=saveName, ...
logFile=logfile,runNow=true,runOnCluster=true);
end