-
Notifications
You must be signed in to change notification settings - Fork 0
/
pitt_getStatus.m
137 lines (104 loc) · 3.34 KB
/
pitt_getStatus.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function [subs n] = pitt_getStatus(baseDir,procStage)
%
% function subs = pitt_getSubs(baseDir)
%
% This funtion will return a cell array of subjects' directories that contains
% which subjects need to be processed at a given stage of the pipeline.
%
% Author: LMP 2012
%
%#ok<*REMFF1>
%% Check INPUT
if notDefined('baseDir')
baseDir = uigetdir(pwd,'Select a Base Directory');
end
if ~exist('procStage','var') || ~isstr(procStage)
procStage = '';
end
%% Initialize the structure and the counters
subs.sort = {};
subs.anatproc = {};
subs.dti = {};
subs.freeseg = {};
subs.wbfibertrack = {};
subs.morifibertrack = {};
sns = 0;
sna = 0;
snd = 0;
snfs = 0;
snwbf = 0;
snmf = 0;
%% Return a cell array with the full paths to all subject directories
dirsTextFile = fullfile(baseDir,'.dirs.txt');
cmd = sprintf('ls -1 %s > %s', baseDir, dirsTextFile); system(cmd);
dirs = textread(dirsTextFile,'%s');
cmd = sprintf('rm %s', dirsTextFile); system(cmd);
% Loop over the array and return only those that are directories
for i = sort(1:numel(dirs),'descend');
if isdir(fullfile(baseDir,dirs{i})) && ~strcmp(dirs{i},'logs') && ~strcmp(dirs{i},'freesurfer')
dirs{i} = fullfile(baseDir,dirs{i});
else
dirs(i) = [];
end
end
% Return the total number of directories
n = numel(dirs);
%% Loop over the dirs and find which subjects need to be processed at each
% stage of the pipeline.
% Do it all here
% This is going to be a bunch of if statements to check if a given
% subject has the hidden files left behind after a given stage in the
% pipeline has been run.
for ii=1:numel(dirs)
mrdir = fullfile(dirs{ii},'mrDiffusion');
sorted = fullfile(mrdir,'.sorted');
anatproc = fullfile(mrdir,'.anatproc');
dtiproc = fullfile(mrdir,'.dtiproc');
fseg = fullfile(mrdir,'.freeseg');
wbfiberproc = fullfile(mrdir,'.wholebrainfiberproc');
morifiberproc = fullfile(mrdir,'.morifiberproc');
% Check for subjects that need to be sorted.
if exist(sorted,'file')
sns = sns+1;
subs.sort{sns} = dirs{ii};
end
% Check for subjects that need anatomy file processed
if exist(anatproc,'file')
sna = sna+1;
subs.anatproc{sna} = dirs{ii};
end
% Check for subjects that need diffusion data processed
if exist(dtiproc,'file')
snd = snd+1;
subs.dti{snd} = dirs{ii};
end
% Check for subjects that need freesurfer segmentation done
if exist(fseg,'file')
snfs = snfs+1;
subs.freeseg{snfs} = dirs{ii};
end
% Check for subjects that need whole-brain fibers created
if exist(wbfiberproc,'file')
snwbf = snwbf+1;
subs.wbfibertrack{snwbf} = dirs{ii};
end
% Check for subjects that need mori-fibers created
if exist(morifiberproc,'file')
snmf = snmf+1;
subs.morifibertrack{snmf} = dirs{ii};
end
end
%% Return subs cell array to the user switching on procStage input
switch lower(procStage)
case 'anatproc'
subs = subs.anatproc;
case 'dtiproc'
subs = subs.dti;
case 'freeseg'
subs = subs.freeseg;
case {'wbfibertrack', 'wholebrainfibertrack'}
subs = subs.wbfibertrack;
case {'morifibertrack', 'mori'}
subs = subs.morifibertrack;
end
return