-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrWithGene.m
62 lines (51 loc) · 2.19 KB
/
corrWithGene.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
%%% 18 Feb. 2013
%%% A function that returns a sorted list of genes based on the correlation
%%% with a gene of interest based on the expression within a specific
%%% structure
function corrWithGene(gene, str, geneslist, expNums, expPlanes, ...
vAnn, bIndx, fDir, eMat, resDir)
% find the index of the gene within the list of genes
gene_index = find(strcmpi(geneslist, gene) == 1);
if isempty(gene_index)
display('seed gene not found');
else
gene_experimentNos = expNums(gene_index);
gene_experimentPlanes = expPlanes(gene_index);
% get the list of voxels covering the structure of interest
inclVoxAnnotations = indicateSubStr(str, fDir);
inclVoxelsInd = find(ismember(vAnn, inclVoxAnnotations) == 1);
% brain indecies corresponding to str
strInds = bIndx(inclVoxelsInd);
% prepare data for the correlation function
geneOfInterestExp = eMat(inclVoxelsInd, gene_index);
dataMat = eMat(inclVoxelsInd, :);
% calculate the correlation between all probe-pairs of the gene of interest
% and all the other genes
% NOTE: calculations are done pair-wise, because at each step we want to
% ignore voxels with missing values
for i = 1 : size(geneOfInterestExp,2)
[notMissing1 ~] = find(geneOfInterestExp(:,i) ~= -1);
for j = 1 : size(dataMat,2)
[notMissing2 ~] = find(dataMat(:,j) ~= -1);
nm = intersect(notMissing1, notMissing2);
if length(nm) >= 5
[c(i,j) pval(i,j)] = corr(geneOfInterestExp(nm,i), dataMat(nm,j), 'type', 'Pearson');
nmVoxels(i,j) = length(nm);
else
c(i,j) = -2;
pval(i,j) = -1;
nmVoxels(i,j) = 0;
end
clear notMissing2; clear nm;
end
clear missing1;
end
% save the results
save([resDir gene '_' str '.mat'], 'c');
save([resDir gene '_' str '_PVAL.mat'], 'pval');
save([resDir str '_voxels.mat'], 'inclVoxelsInd');
save([resDir str '_strInds.mat'], 'strInds');
save([resDir str '_nmVoxels.mat'], 'nmVoxels');
save([resDir gene '_expNumbers.mat'], 'gene_experimentNos');
save([resDir gene '_expPlane.mat'], 'gene_experimentPlanes');
end