-
Notifications
You must be signed in to change notification settings - Fork 0
/
enqueueManyExperiments.m
executable file
·114 lines (114 loc) · 4.14 KB
/
enqueueManyExperiments.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
function queue=enqueueManyExperiments(rootNode,config_file,hEvalGui,queue)
if nargin<2
config_file='';
end
if nargin<3
if ~isstruct(rootNode)
error('MATLAB:AutoTipTrack:enqueueManyExperiments:WrongArguments','enqueueManyExperiments must be called either with a uitreenode as first argument AND a gui handle or with a path string as first argument');
end
hEvalGui=[];
end
if nargin<4
queue=QueueElementClass.empty;
end
if ~isstruct(rootNode)
%we assume that root node is a uitreenode and we have a gui
useGUI=true;
else
useGUI=false;
end
files=dir(rootNode.getValue);
if exist(rootNode.getValue,'file')~=2 && exist(rootNode.getValue,'file')~=7
error('MATLAB:AutoTipTrack:enqueueManyExperiments:FileNotFound', 'File not found: "%s"',rootNode.getValue);
end
for n=1:length(files)
fullPath=fullfile(rootNode.getValue,files(n).name);
if useGUI
%create the node and add it to the root node
node=EvalGui.createNode(fullPath,true);
else
node.getValue=fullPath;
end
if files(n).isdir
isDot=strcmp(files(n).name,{'.','..','.git','eval','ignore','eval_old','done','names'});
isDot(end+1)=~isempty(regexp(files(n).name,'.*_mcrCache','once','start')); %#ok<AGROW>
if ~any(isDot) %if we don't ignore the directory, check if it contains images
children=dir(fullPath);
foundImages=false;
numTiffs=0;
for i=1:length(children)
isTiff=~cellfun(@isempty,regexpi(children(i).name,{'^(?![.]).*\.tif','^(?![.]).*\.tiff'}));
if any(isTiff)
info = imfinfo(fullfile(fullPath,children(i).name));
if numel(info)>1 %if we have a multipage tiff
specific_conf=fullfile(fullPath,'config.mat');
if exist(specific_conf, 'file')~=2
success=copyfile(config_file,specific_conf);
if ~success
specific_conf=config_file;
end
end
if useGUI
rootNode.add(node);
end
queue=enqueueExperiment(node,specific_conf,hEvalGui,queue);
foundImages=true;
break;
else
numTiffs=numTiffs+1;
if numTiffs>1%make sure that there is more than one image before we start tracking
%if we have many tiffs in a subfolder, the rootnode is
%actually just one experiment, enqueue that one
specific_conf=fullfile(rootNode.getValue, 'config.mat');
if exist(specific_conf, 'file')~=2
success=copyfile(config_file,specific_conf);
if ~success
specific_conf=config_file;
end
end
queue=enqueueExperiment(rootNode,specific_conf,hEvalGui,queue);
foundImages=true;
break;
end
end
end
isStk=~cellfun(@isempty,regexpi(children(i).name,{'^(?![.]).*\.stk','^(?![.]).*\.nd2'}));
if any(isStk)
specific_conf=fullfile(fullPath,'config.mat');
if exist(specific_conf, 'file')~=2
success=copyfile(config_file,specific_conf);
if ~success
specific_conf=config_file;
end
end
if useGUI
rootNode.add(node);
end
queue=enqueueExperiment(node,specific_conf,hEvalGui,queue);
foundImages=true;
break;
end
end
if ~foundImages %if none of the child folders contained images recursively descend into the child folder
if useGUI
rootNode.add(node);
end
queue=enqueueManyExperiments(node, config_file, hEvalGui,queue);
end
end
else %if files(n) is not a directory
isStk=~cellfun(@isempty,regexpi(files(n).name,{'^(?![.]).*\.stk','^(?![.]).*\.nd2'}));
isTiff=~cellfun(@isempty,regexpi(files(n).name,{'^(?![.]).*\.tif','^(?![.]).*\.tiff'}));
if any(isTiff)
info = imfinfo(fullPath);
if numel(info)>1 %if we have a multipage tiff
isStk=true;
end
end
if any(isStk) %if we have stacks in the rootNode, this is actually just one experiment, enqueue that.
queue=enqueueExperiment(rootNode,config_file,hEvalGui,queue);
break;
end
end
end
end