-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_pcRegression_3746.m
97 lines (73 loc) · 3.35 KB
/
script_pcRegression_3746.m
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
% Author: Tara Martin
% Date: 20110415
%
% Purpose: extract input and output data from atlas.vpc, perform linear
% regression on data, store parameters, calculate predicted expression
% based on the regression parameters and store for comparison to actual
% expression.
%
%% Import atlas and initialize parameters
%uncomment to import atlas data:
%atlas = readpointcloud('atlas.vpc');
% dmel_atlas = readpointcloud('D_mel_wt__atlas__08_02_26.vpc');
% PCs to extract
regList = {'LacZ_0204' 'LacZ_0214'}; %mRNA inputs to regression
protRegList = {}; %protein inputs to regression
coeff_key = ['const' regList];
%geneList = {'LacZ_0204' 'eve'}; %outputs to fit
geneList = {'LacZ_0207' 'LacZ_0208' 'LacZ_0209' 'LacZ_0210' 'LacZ_0211'};
cohort = 5:9; %timepoints to include, normally 4:9
numNuc = 6078; %number of nuclei in atlas
regulators = zeros(numNuc*length(cohort), length(regList)); %initialize data structure
%% Extract PCs of regulators from atlases
% first get regulators with mRNA patterns
for j=1:length(regList)
for k=1:length(cohort)
fieldString = [regList{j} '__' num2str(cohort(k))];
if (~isfield(atlas, fieldString)) %check if PC is in atlas
warning('pcRegression:ExtractData', 'Atlas does not contain %s', fieldString);
else
eval(['reg = atlas.' fieldString ';']); %creates data holder 'reg'
regulators(((k-1)*numNuc+1):(k*numNuc),j) = reg; %concatenates all cohorts
end
end
warning('pcRegression:testing', 'Extracted %s from atlas.', regList{j});
end
% now get regulators with protein patterns
for j=1:length(protRegList)
for k=1:length(cohort)
fieldString = [protRegList{j} '__' num2str(cohort(k))];
if (~isfield(atlas, fieldString)) %check if PC is in atlas
warning('pcRegression:ExtractData', 'Dmel atlas does not contain %s', fieldString);
else
eval(['reg = dmel_atlas.' fieldString ';']); %creates data holder 'reg'
regulators(((k-1)*numNuc+1):(k*numNuc),(j+length(regList))) = reg; %concatenates all cohorts
end
end
warning('pcRegression:testing', 'Extracted %s from dmel atlas.', protRegList{j});
end
%% Extract vector of output values from atlas, fit each
for j=1:length(geneList)
pc =zeros(numNuc*length(cohort),1); %creates data holder 'pc'
for k=1:length(cohort)
fieldString = [geneList{j} '__' num2str(cohort(k))];
if (~isfield(atlas, fieldString))
warning('pcRegression:ExtractData', 'Atlas does not contain %s', fieldString);
else
eval(['pc(((k-1)*numNuc+1):(k*numNuc)) = atlas.' fieldString ';']); %stores cohort data in 'pc'
end
end
%threshold output data -- should do this in more coherent way ->
%mode+stdev
pc = gt(pc, 0.35);
% coeffs = glmfit(regulators, pc, 'binomial'); %logistic regression
% reg_fit = glmval(coeffs, regulators, 'logit'); %predicted expression given fit parameters
coeffs = glmfit(regulators, pc); %linear regression
reg_fit = glmval(coeffs, regulators, 'identity'); %predicted expression given fit parameters
%store PCs, coefficients of regression and predicted expression (fit)
eval(['pc_' geneList{j} '=pc;']);
eval(['coeffs_' geneList{j} ' = coeffs;']);
eval(['fit_' geneList{j} '= reg_fit;']);
end
%% Visualize results
%see pc_plots.m