-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfs_funcdir.m
53 lines (45 loc) · 1.66 KB
/
fs_funcdir.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
function [funcDir, sessList] = fs_funcdir(funcDir, strPattern, setdir)
% [funcDir, sessList] = fs_funcdir(funcDir, strPattern)
%
% This function sets $FUNCTIONALS_DIR in FreeSurfer.
%
% Inputs:
% funcDir <str> the path to functional data. This path will
% also be saved as FUNCTIONALS_DIR.
% strPattern <str> wildcard strings for identifying session names.
% It will be used to identify all the sessions. E.g.,
% it can be "Face*" (without quotes).
% setdir <boo> 1 [default]: setenv SUBJECTS_DIR; 0: do not
% set env.
%
% Output:
% funcDir <str> path to the functional folder.
% sessList <cell str> a list of session codes.
% save funcDir to $FUNCTIONALS_DIR if applicable.
%
% Creatd by Haiyang Jin (18-Dec-2019)
if ~exist('funcDir', 'var') || isempty(funcDir)
funcDir = getenv('FUNCTIONALS_DIR');
if ~exist('setdir', 'var') || isempty(setdir); setdir = 0; end
end
if ~exist('strPattern', 'var') || isempty(strPattern)
strPattern = '';
end
if ~exist('setdir', 'var') || isempty(setdir)
setdir = 1;
end
if isempty(funcDir) && setdir
error('Please set $FUNCTIONALS_DIR with fs_funcdir().')
end
% make sure the struDir exists
assert(logical(exist(funcDir, 'dir')), 'Cannot find the directory: \n%s...', funcDir);
% set the environmental variable of FUNCTIONALS_DIR
if setdir
setenv('FUNCTIONALS_DIR', funcDir);
end
% sessions (bold subject codes)
tmpDir = dir(fullfile(funcDir, strPattern));
isSessDir = [tmpDir.isdir] & ~ismember({tmpDir.name}, {'.', '..'});
sessDir = tmpDir(isSessDir);
sessList = {sessDir.name}';
end