forked from erhanbas/pipeline-stitching
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpointmatch_task_local.m
124 lines (111 loc) · 4.7 KB
/
pointmatch_task_local.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
function pointmatch_task_local(brain,inputfolder,descriptorfolder,matchfolder,matfolder,directions,ch,runlocal)
%% deploys pointmatch function on array task
deployment(brain,inputfolder,descriptorfolder,matchfolder,matfolder,directions,ch,runlocal);
end
function deployment(brain,inputfolder,descriptorfolder,matchfolder,matfolder,directions,ch,runlocal);
%%
addpath(genpath('./functions'))
% addpath(genpath('./common'))
matlab_cluster_path = '/usr/local/matlab-2017a';
compiledfunc = '/groups/mousebrainmicro/home/base/CODE/MATLAB/compiledfunctions/pointmatch_task/pointmatch_task';
[mypath,mycomp] = fileparts(compiledfunc);
taskwrapper = fullfile(pwd,'cluster2.sh');
taskscript = fullfile(mypath,sprintf('run_%s.sh',mycomp));
if ~exist(fileparts(compiledfunc),'dir');
mkdir(fileparts(compiledfunc));
mfilename_ = mfilename('fullpath');
unix(sprintf('mcc -m -v -R -I %s -d %s -a %s',mfilename_,fileparts(compiledfunc),fullfile(fileparts(mfilename_),'functions')))
%,fullfile(fileparts(mfilename_),'common')
end
scopefile = fullfile(matfolder,'scopeloc.mat');
if ~exist(matfolder,'dir')
mkdir(matfolder)
end
if exist(scopefile,'file')
load(scopefile,'scopeloc')
else
newdash = 1; % set this to 1 for datasets acquired after 160404
[scopeloc] = getScopeCoordinates(inputfolder,newdash);% parse from acqusition files
save(fullfile(matfolder,'scopeloc.mat'),'neighbors','scopeloc','imsize_um','experimentfolder','inputfolder')
end
[neighbors] = buildNeighbor(scopeloc.gridix(:,1:3)); %[id -x -y +x +y -z +z] format
directionMap = containers.Map({'-X','-Y','X','Y','-Z','Z'},[ 2, 3, 4, 5, 6, 7]);
%%
maxnumofdesc = 10e3;
checkversion=1;
if 0
pixinit = zeros(size(neighbors,1),3);
nummatches = zeros(size(neighbors,1),1);
else
% load finished tile matches. find badly matched or missing tile pairs
[regpts,featmap] = loadMatchedFeatures(scopeloc,matchfolder,directions,checkversion);
% initalize missing tiles based on knn
numthr = 50;
[pixinit,nummatches] = initTiles(featmap,directions,scopeloc,numthr);
% sum(nummatches)
end
badtiles = nummatches<numthr & ~isnan(neighbors(:,directionMap(directions)));
%%
% generate a txt file with all tile pairs to be matched with optional shift
% values
% (filename,from,to,numcores,exitcode)
outlistfile = fullfile(pwd,'shfiles',sprintf('outlistfile_%s_%s.txt',brain,date));
if ~runlocal;fid = fopen(outlistfile,'w');else;fid=0;end
try parfor_progress(0);catch;end
parfor_progress(length(badtiles))
parfor ii = 1:length(badtiles)
if ~badtiles(ii)
parfor_progress;
continue
end
%%
tile1 = fullfile(descriptorfolder,scopeloc.relativepaths{ii});
acqusitionfolder1 = fileparts(scopeloc.filepath{ii});
iineig = neighbors(ii,directionMap(directions));
tile2 = fullfile(descriptorfolder,scopeloc.relativepaths{iineig});
acqusitionfolder2 = fileparts(scopeloc.filepath{iineig});
outfold =fullfile(matchfolder,scopeloc.relativepaths{ii});
if exist(fullfile(outfold,sprintf('match-%s-1.mat','Z')),'file')
parfor_progress;
continue
end
if runlocal
try
pointmatch(tile1,tile2,acqusitionfolder1,acqusitionfolder2,outfold,pixinit(ii,:),ch,maxnumofdesc,0);
catch
sprintf('%d',ii)
end
else
fprintf(fid,'%s %s %s %s %s %f %f %f %s %f\n',tile1,tile2,acqusitionfolder1,acqusitionfolder2,outfold,pixinit(ii,:),ch,maxnumofdesc);
end
parfor_progress;
end
parfor_progress(0);
if ~runlocal;fclose(fid);end
%%
if ~runlocal
%% task script (filename,from,to,numcores,exitcode)
%find number of random characters to choose from and %specify length of random string to generate
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';numRands = length(s);sLength = 10;
%-o /dev/null
esttime = 30*60;
numcores = 16;
exitcode = 0;
tottasks = sum(badtiles(:));
intervals = round(linspace(0,tottasks,round(tottasks/numcores)));
mkdir(fullfile(pwd,'shfiles'))
myfile = fullfile(pwd,'shfiles',sprintf('featmatchrun_%s_%s.sh',brain,date))
if ~runlocal; fid = fopen(myfile,'w'); end
for ii = 1:length(intervals)-1
from = intervals(ii)+1;
to = intervals(ii+1);
cmd = sprintf('''%s %s %s %s %d %d %d %d''',taskwrapper,taskscript,matlab_cluster_path,outlistfile,from,to,numcores,exitcode);
%generate random string
randString = s( ceil(rand(1,sLength)*numRands) );
name = sprintf('zm_%05d-%s',ii,randString);
mysub = sprintf('bsub -J %s -n%d -R"affinity[core(1)]" -We %d -o /dev/null %s\n',name,numcores,esttime/60,cmd);
fwrite(fid,mysub);
end
if ~runlocal; fclose(fid); unix(sprintf('chmod +x %s',myfile)); disp(myfile);end
end
end