-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConstructExpresionMatrix.m
76 lines (69 loc) · 3.32 KB
/
ConstructExpresionMatrix.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
%%% 13 Feb. 2013
%%% Arrange all gene expressions in one big matrix
clear all;
filesDirectory = '/tudelft.net/staff-bulk/ewi/insy/DBL/amahfouz/MatlabFiles/NuclearReceptors/files/';
dataFolder = [filesDirectory 'expressionData/'];
% get annotation information of voxels using the reference atlas at
% resolution = 200µm
annoationGridFile = [filesDirectory 'gridAnnotation/gridAnnotation.raw'];
SIZE = [67 41 58]; % 200 micron volume size
fid = fopen(annoationGridFile, 'r', 'l');
referenceVol = fread(fid, prod(SIZE), 'uint16');
fclose(fid);
referenceVol = reshape(referenceVol, SIZE);
% extract indices of labeled (i.e. brain) voxels from in the left
% hemisphere from an ARA mask (sent by Lydia) - that mask also filters
% voxels that have more than 20% missing data
maskVol = metaImageRead([filesDirectory 'gridAnnotation/image_mask.mhd']);
maskVol = permute(maskVol, [2 1 3]);
maskVol(maskVol > 0) = 1;
referenceVol = referenceVol .* double(maskVol);
brainInd = find(referenceVol ~= 0);
voxelAnnotation = referenceVol(brainInd);
save([filesDirectory 'voxelAnnotation.mat'], 'voxelAnnotation');
save([filesDirectory 'brainInd.mat'], 'brainInd');
clear referenceVol;
% first load the coronal genes
coronalExperimentsFolder = [dataFolder 'coronal/'];
genesFolders = dir(coronalExperimentsFolder);
for i = 1 : length(genesFolders)-2
geneExperimentName = genesFolders(i+2).name;
fileName = [coronalExperimentsFolder geneExperimentName '/energy.raw'];
fid = fopen(fileName, 'r', 'l');
geneExperimentData = fread(fid, prod(SIZE), 'float');
fclose(fid);
geneExperimentData = reshape(geneExperimentData, SIZE);
brainOnlyData = geneExperimentData(brainInd);
clear geneExperimentData;
expressionMatrix(:,i) = brainOnlyData';
clear brainOnlyData;
listOfGenes{i} = geneExperimentName(1 : strfind(geneExperimentName, '_')-1);
listOfExperimentNumbers{i} = geneExperimentName(strfind(geneExperimentName, '_')+1 : end);
clear geneExperimentName; clear fileName; clear geneExperimentName;
end
clear genesFolders;
save([filesDirectory 'expressionMatrix.mat'], 'expressionMatrix', '-v7.3');
save([filesDirectory 'listOfGenes.mat'], 'listOfGenes');
save([filesDirectory 'listOfExperimentNumbers.mat'], 'listOfExperimentNumbers');
% second load the sagittal genes
coronalExperimentsFolder = [dataFolder 'sagittal/'];
genesFolders = dir(coronalExperimentsFolder);
for i = 1 : length(genesFolders)-2
geneExperimentName = genesFolders(i+2).name;
fileName = [coronalExperimentsFolder geneExperimentName '/energy.raw'];
fid = fopen(fileName, 'r', 'l');
geneExperimentData = fread(fid, prod(SIZE), 'float');
fclose(fid);
geneExperimentData = reshape(geneExperimentData, SIZE);
brainOnlyData = geneExperimentData(brainInd);
clear geneExperimentData;
expressionMatrix(:,i) = brainOnlyData';
clear brainOnlyData;
listOfGenes{i} = geneExperimentName(1 : strfind(geneExperimentName, '_')-1);
listOfExperimentNumbers{i} = geneExperimentName(strfind(geneExperimentName, '_')+1 : end);
clear geneExperimentName; clear fileName; clear geneExperimentName;
end
clear genesFolders;
save([filesDirectory 'expressionMatrix_sagittal.mat'], 'expressionMatrix', '-v7.3');
save([filesDirectory 'listOfGenes_sagittal.mat'], 'listOfGenes');
save([filesDirectory 'listOfExperimentNumbers_sagittal.mat'], 'listOfExperimentNumbers');