forked from LauraDugue/endo_exo_MRI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadROIdnoiseBOOT.m
125 lines (109 loc) · 4.11 KB
/
loadROIdnoiseBOOT.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
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
% loadROIcoranal.m
%
% usage: loadROIdnoise(view, <roiname>, <scanList>, <groupNum>, matchScanNum, matchGroupNum)
% by: eli & laura
% date: 01/13/15
% purpose:
%
function rois = loadROIdnoiseBOOT(view, whichAnal, roiname, scanList, groupNum, varagin);
rois = {};
% check arguments
if nargin < 1
help loadROIdnoise
return
end
% no view specified
if ieNotDefined('view')
view = newView('Volume');
end
% get the roi directory
roidir = viewGet(view,'roidir');
% get group and scan
if ieNotDefined('groupNum')
groupNum = viewGet(view,'currentGroup');
end
groupName = viewGet(view,'groupName',groupNum);
if ieNotDefined('scanList')
%scanList = viewGet(view,'currentScan');
scanList = 1;
end
% set the current group
view = viewSet(view,'currentGroup',groupNum);
% if there is no roi, ask the user to select
if ieNotDefined('roiname')
roiname = getPathStrDialog(viewGet(view,'roiDir'),'Choose one or more ROIs','*.mat','on');
end
%make into a cell array
roiname = cellArray(roiname);
% load the analysis
view = loadAnalysis(view, ['glmdnoise/dnoiseAnal_' whichAnal '_boot.mat']);
% extract the params
d = viewGet(view, 'd');
ehdr = d.ehdr;
ehdrste = d.ehdrste;
boot = d.boot;
% load the rois in turn
for roinum = 1:length(roiname)
% see if we have to paste roi directory on
if isstr(roiname{roinum}) && ~isfile(sprintf('%s.mat',stripext(roiname{roinum})))
roiname{roinum} = fullfile(roidir,stripext(roiname{roinum}));
end
% check for file
if isstr(roiname{roinum}) && ~isfile(sprintf('%s.mat',stripext(roiname{roinum})))
disp(sprintf('(loadROIdnoise) Could not find roi %s',roiname{roinum}));
dir(fullfile(roidir,'*.mat'))
elseif isnumeric(roiname{roinum}) && ((roiname{roinum} < 1) || (roiname{roinum} > viewGet(view,'numberOfROIs')))
disp(sprintf('(loadROIdnoise) No ROI number %i (number of ROIs = %i)',roiname{roinum},viewGet(view,'numberOfROIs')));
else
% load the roi, if the name is actually a struct
% then assume it is an roi struct. if it is a number choose
% from a loaded roi
if isstr(roiname{roinum})
roi = load(roiname{roinum});
elseif isnumeric(roiname{roinum})
thisroi = viewGet(view,'roi',roiname{roinum});
roi.(fixBadChars(thisroi.name)) = thisroi;
else
roi.(fixBadChars(roiname{roinum}.name)) = roiname{roinum};
end
roiFieldnames = fieldnames(roi);
% get all the rois
for roinum = 1:length(roiFieldnames)
disppercent(-inf,sprintf('Loading tSeries from roi: %s, group: %s',roiFieldnames{roinum}, groupName));
for scanNum = 1:length(scanList)
% get current scan number
scanNum = scanList(scanNum);
rois{end+1} = roi.(roiFieldnames{roinum});
% set a field in the roi for which scan we are collecting from
rois{end}.scanNum = scanNum;
rois{end}.groupNum = groupNum;
% convert to scan coordinates
rois{end}.scanCoords = getROICoordinates(view,rois{end},scanNum,groupNum);
%rois{end}.scanCoords = getROICoordinatesMatching(view, rois{end}, scanNum, matchScanNum, groupNum, matchGroupNum);
% if there are no scanCoords then set to empty and continue
if isempty(rois{end}.scanCoords)
rois{end}.n = 0;
rois{end}.tSeries = [];
continue;
end
% get x y and s in array form
x = rois{end}.scanCoords(1,:);
y = rois{end}.scanCoords(2,:);
s = rois{end}.scanCoords(3,:);
% set the n
rois{end}.n = length(x);
% load the tseries, voxel-by-voxel
% for now we always load by block, but if memory is an issue, we can
% switch this if statement and load voxels indiviudally from file
% load each voxel time series indiviudally
for voxnum = 1:rois{end}.n
rois{end}.ehdr(voxnum,:) = squeeze(ehdr(x(voxnum),y(voxnum),s(voxnum),:))';
rois{end}.ehdrste(voxnum,:) = squeeze(ehdrste(x(voxnum),y(voxnum),s(voxnum),:))';
rois{end}.boot(voxnum,:,:) = squeeze(boot(x(voxnum),y(voxnum),s(voxnum),:,:))';
end
disppercent(roinum/length(roiFieldnames));
end
disppercent(inf);
end
end
end