-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunScan.m
54 lines (50 loc) · 1.85 KB
/
RunScan.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
classdef RunScan < Run & handle
methods
function obj = RunScan(path, name, path_left)
if nargin<2
error('A run needs a name and a path');
end
[~, str_name, ~] = fileparts(name);
obj@Run(path, str_name, path_left);
end
function set_scans(obj, ~)
obj.scans = [];
num_scans = size(spm_vol(obj.path),1);
scans = cell(num_scans, 1);
scans(:, 1) = {obj.path};
for i = 1:size(scans)
scans{i} = [scans{i} ',' num2str(i)];
end
obj.scans = scans;
end
function move_scans(obj, from, to)
obj.scans = cellfun(@(x)(strrep(x, from, to)), obj.scans, 'UniformOutput', 0);
end
function cache(obj, from, to)
old_path = obj.path;
move_scans(obj, from, to);
new_path = strrep(obj.path, from, to);
[folder, ~, ext] = fileparts(new_path);
mkdir(folder);
copyfile(old_path, obj.path);
if strcmp(ext,'.img')
old_hdr_path =strrep(old_path, 'img', 'hdr');
new_hdr_path =strrep(new_path, 'img', 'hdr');
copyfile(old_hdr_path, new_hdr_path)
end
obj.path = new_path;
obj.uncache_path = old_path;
end
function uncache(obj)
copyfile(fileparts(obj.path), fileparts(obj.uncache_path));
obj.path = obj.uncache_path;
obj.uncache_path = [];
end
function n = spm_select_get_nbframes(file)
% spm_select_get_nbframes(file) Get the number of volumes of a 4D nifti file, excerpt from SPM12 spm_select.m
N = nifti(file);
dim = [N.dat.dim 1 1 1 1 1];
n = dim(4);
end
end
end