forked from erhanbas/mouse2syglass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syglassrun.m
73 lines (65 loc) · 2.45 KB
/
syglassrun.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
function syglassrun(samplepath,outfolder,rerun)
% inputs:
% samplepath: name of the sample folder
% outfolder: target folder to create syglass files
% rerun: binary flag to recreate output of ls file. This will save
% time if you want to use the result of "ls" from a previous
% session
% example run:
% sample = '2018-07-02-raw_new';
% samplepath = fullfile('/nrs/mouselight/SAMPLES/',sample);
% outfolder = fullfile(samplepath,'syglass-ch0');
% rerun = 0;
% syglassrun(samplepath,outfolder,rerun)
if nargin<1
sample = '2018-08-15';
samplepath = fullfile('/nrs/mouselight/SAMPLES/',sample);
outfolder = fullfile(samplepath,'syglass-ch0');
rerun = 0;
else
[samplefolder,sample] = fileparts(samplepath);
if nargin<3
rerun = 1;
end
end
if rerun;unix(sprintf('rm -rdf ./tmpfiles'));mkdir('./tmpfiles');end
if ~exist(fullfile('./tmpfiles',sample),'dir'); mkdir('./tmpfiles',sample);end
pythonpath = '/groups/mousebrainmicro/home/base/anaconda3/envs/syglass/bin/python';
scriptpath = '/groups/mousebrainmicro/mousebrainmicro/Software/syGlassConverter/singleThreadedCacher.py';
addpath(genpath('./common'))
opt = configparser(fullfile(samplepath,'/transform.txt'));
maxlevel = opt.nl-1;
clear opt
%%
for level=0:maxlevel
mysh = sprintf('./syglassrun-%d-ch0.sh',level);
args.level=level;
args.ext = '0.tif';
opt.seqtemp = fullfile('./tmpfiles',sample,sprintf('filelist-%d.txt',level));
opt.inputfolder = samplepath;
if exist(opt.seqtemp, 'file') == 2
% load file directly
else
args.fid = fopen(opt.seqtemp,'w');
recdir(opt.inputfolder,args)
end
fid=fopen(opt.seqtemp,'r');
myfiles = textscan(fid,'%s');myfiles = myfiles{1};fclose(fid);
fid = fopen(mysh,'w');
for ii=1:length(myfiles)
infold = [fileparts(myfiles{ii}),'/'];
relativepath = infold(length(samplepath)+1:end);
outfold = [fullfile(outfolder,relativepath)];
if length(relativepath)>2&strcmp(relativepath(1:3),'ktx') % skip any ktx files
continue
end
if ~exist(outfold,'dir')
mkdir(outfold)
unix(sprintf('chmod g+rwx %s',outfold));
end
myarg = sprintf('bsub -n1 -We 1 -J t-%d-%05d -o /dev/null ''%s %s %s %s''\n',level,ii,pythonpath,scriptpath,infold,outfold);
fwrite(fid,myarg);
end
fclose(fid);
unix(sprintf('chmod g+rwx %s',mysh));
end