Skip to content

Commit 615c41a

Browse files
committed
Added script for stage 1234 processing
1 parent 571064e commit 615c41a

3 files changed

+279
-0
lines changed

lpl_process_single_tile.m

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function lpl_process_single_tile(tile_relative_path, raw_root_path, line_fix_root_path, p_map_root_path, landmark_root_path, ...
2+
do_line_fix, do_force_computation, do_run_in_debug_mode)
3+
% sample date something like '2021-09-16'
4+
% tile_relative_path something like '2021-09-17/00/00000'
5+
6+
% Deal with args
7+
if ~exist('do_force_computation', 'var') || isempty(do_force_computation) ,
8+
do_force_computation = false ;
9+
end
10+
if ~exist('do_run_in_debug_mode', 'var') || isempty(do_run_in_debug_mode) ,
11+
do_run_in_debug_mode = false ;
12+
end
13+
14+
% % Generate paths to various things
15+
% raw_root_path = sprintf('/groups/mousebrainmicro/mousebrainmicro/data/%s/Tiling', sample_date) ;
16+
% line_fix_root_path = sprintf('/nrs/mouselight/pipeline_output/%s/stage_1_line_fix_output', sample_date) ;
17+
% p_map_root_path = sprintf('/nrs/mouselight/pipeline_output/%s/stage_2_classifier_output', sample_date) ;
18+
% landmarks_root_path = sprintf('/nrs/mouselight/pipeline_output/%s/stage_3_descriptor_output', sample_date) ;
19+
20+
% Find the tiles in the raw imagery folder
21+
raw_imagery_folder_path = fullfile(raw_root_path, tile_relative_path) ;
22+
[~,day_tile_index_string] = fileparts2(tile_relative_path) ; % e.g. '00000'
23+
raw_imagery_file_name_template = sprintf('%s-ngc.*.tif', day_tile_index_string) ;
24+
raw_imagery_file_path_template = fullfile(raw_imagery_folder_path, raw_imagery_file_name_template) ;
25+
raw_imagery_tile_file_names = simple_dir(raw_imagery_file_path_template) ;
26+
tile_file_count = length(raw_imagery_tile_file_names) ;
27+
28+
% Fix the line-shift
29+
if do_line_fix,
30+
fix_line_shift(raw_root_path, tile_relative_path, line_fix_root_path, do_force_computation, do_run_in_debug_mode) ;
31+
end
32+
33+
% Process each tile in turn
34+
if do_line_fix ,
35+
p_map_input_root_path = line_fix_root_path ;
36+
else
37+
p_map_input_root_path = raw_root_path ;
38+
end
39+
for tile_file_index = 1 : tile_file_count ,
40+
raw_imagery_tile_file_name = raw_imagery_tile_file_names{tile_file_index} ;
41+
lpl_process_single_tile_channel(...
42+
raw_imagery_tile_file_name, tile_relative_path, p_map_input_root_path, p_map_root_path, landmark_root_path) ;
43+
end
44+
end

lpl_process_single_tile_channel.m

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
function lpl_process_single_tile_channel(raw_tile_file_name, tile_relative_path, input_root_path, p_map_root_path, landmarks_root_path, ...
2+
do_force_computation, do_run_in_debug_mode)
3+
% Deal with args
4+
if ~exist('do_force_computation', 'var') || isempty(do_force_computation) ,
5+
do_force_computation = false ;
6+
end
7+
if ~exist('do_run_in_debug_mode', 'var') || isempty(do_run_in_debug_mode) ,
8+
do_run_in_debug_mode = false ;
9+
end
10+
11+
% Compute the p-map file path
12+
input_file_path = fullfile(input_root_path, tile_relative_path, raw_tile_file_name) ;
13+
[~,day_tile_index_as_string] = fileparts2(tile_relative_path) ;
14+
channel_index0_as_string = channel_index0_as_string_from_tile_file_name(raw_tile_file_name) ;
15+
p_map_file_name = sprintf('%s-prob.%s.h5', day_tile_index_as_string, channel_index0_as_string) ;
16+
p_map_tile_folder_path = fullfile(p_map_root_path, tile_relative_path) ;
17+
p_map_file_path = fullfile(p_map_tile_folder_path, p_map_file_name) ;
18+
19+
% Shell out to run Ilastik
20+
if do_force_computation || ~exist(p_map_file_path, 'file') ,
21+
ensure_folder_exists(p_map_tile_folder_path) ;
22+
23+
%script_path = mfilename('fullpath') ;
24+
%script_folder_path = fileparts(script_path) ;
25+
%ilastik_project_path = fullfile(script_folder_path, '/groups/mousebrainmicro/mousebrainmicro/pipeline-systems axon-classifier/axon_uint16.ilp') ;
26+
ilastik_project_path = '/groups/mousebrainmicro/mousebrainmicro/pipeline-systems/pipeline-a/apps/axon-classifier/axon_uint16.ilp' ;
27+
IL_PREFIX = '/groups/mousebrainmicro/mousebrainmicro/pipeline-systems/tools/ilastik-1.1.9-Linux' ;
28+
%IL_PREFIX = '/groups/mousebrainmicro/mousebrainmicro/Software/ilastik-1.3.3post2-Linux' ;
29+
%IL_PREFIX = '/groups/mousebrainmicro/mousebrainmicro/Software/ilastik-1.3.3-Linux' ;
30+
output_format = 'hdf5' ;
31+
%'multipage tiff', 'multipage tiff sequence', 'hdf5'
32+
python_path = fullfile(IL_PREFIX, 'bin/python') ;
33+
ilastik_dot_py_path = fullfile(IL_PREFIX, 'ilastik-meta/ilastik/ilastik.py') ;
34+
%command_line = sprintf(['export LAZYFLOW_THREADS=4 ; ' ...
35+
% 'export LAZYFLOW_TOTAL_RAM_MB=60000 ; ' ...
36+
% '"%s" ' ...
37+
command_line = sprintf(['export LAZYFLOW_THREADS=4 ; ' ...
38+
'export LAZYFLOW_TOTAL_RAM_MB=60000 ; ' ...
39+
'"%s" ' ...
40+
'"%s" ' ...
41+
'--headless ' ...
42+
'--readonly 1 ' ...
43+
'--cutout_subregion="[(None,None,None,0),(None,None,None,1)]" ' ...
44+
'--project="%s" ' ...
45+
'--output_filename_format="%s" ' ...
46+
'--output_format="%s" ' ...
47+
'"%s"'] , ...
48+
python_path, ...
49+
ilastik_dot_py_path, ...
50+
ilastik_project_path, ...
51+
p_map_file_path, ...
52+
output_format, ...
53+
input_file_path) ;
54+
fprintf('Ilastik command line: %s\n', command_line) ;
55+
system_with_error_handling(command_line) ;
56+
end
57+
58+
% Generate the landmarks from the p-map
59+
landmark_file_name = sprintf('%s-desc.%s.txt', day_tile_index_as_string, channel_index0_as_string) ;
60+
landmark_folder_path = fullfile(landmarks_root_path, tile_relative_path) ;
61+
landmark_file_path = fullfile(landmark_folder_path, landmark_file_name) ;
62+
63+
% Make sure the output folder exists
64+
ensure_folder_exists(landmark_folder_path) ;
65+
66+
% Run the core code
67+
siz = '[11 11 11]' ;
68+
sig1 = '[3.405500 3.405500 3.405500]' ;
69+
sig2 = '[4.049845 4.049845 4.049845]' ;
70+
ROI = '[5 1019 5 1531 5 250]' ;
71+
rt = '4' ;
72+
exitcode = dogDescriptor(p_map_file_path, landmark_file_path, siz, sig1, sig2, ROI, rt) ;
73+
if exitcode ~= 0 ,
74+
error('dogDescriptor() returned a nonzero exit code (%s) when trying to produce output file %s', exitcode, landmark_file_path) ;
75+
end
76+
end

run_all_tiles_through_1234_stages.m

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
% Set up the par pool
2+
use_this_fraction_of_cores(1) ;
3+
4+
% Set params for early jobs
5+
do_use_bsub = false ;
6+
do_actually_submit = false ;
7+
max_running_slot_count = inf ;
8+
bsub_option_string = '-P mouselight -J mouselight-pipeline-123' ;
9+
slots_per_job = 4 ;
10+
stdouterr_file_path = '' ; % will go to /dev/null
11+
12+
13+
% Build the tile index
14+
raw_tile_index = compute_or_read_from_memo(sample_memo_folder_path, ...
15+
'raw-tile-index', ...
16+
@()(build_raw_tile_index(raw_root_path)), ...
17+
do_force_computation) ;
18+
tile_index_from_tile_ijk1 = raw_tile_index.tile_index_from_tile_ijk1 ;
19+
ijk1_from_tile_index = raw_tile_index.ijk1_from_tile_index ;
20+
xyz_from_tile_index = raw_tile_index.xyz_from_tile_index ;
21+
relative_path_from_tile_index = raw_tile_index.relative_path_from_tile_index ;
22+
raw_tile_map_shape = size(tile_index_from_tile_ijk1)
23+
tile_count = length(relative_path_from_tile_index)
24+
25+
26+
27+
%
28+
% Figure out which tiles need to be run
29+
%
30+
31+
%is_to_be_run_from_tile_index = false(tile_count, 1) ;
32+
%is_to_be_run_from_tile_index(1:20) = true ;
33+
fprintf('Determining which of the %d tiles need to be LPLed...\n', tile_count) ;
34+
if do_force_computation ,
35+
is_to_be_run_from_tile_index = true(tile_count, 1) ;
36+
else
37+
is_to_be_run_from_tile_index = true(tile_count,1) ;
38+
parfor_progress(tile_count) ;
39+
parfor tile_index = 1 : tile_count
40+
tile_relative_path = relative_path_from_tile_index{tile_index} ;
41+
channel_0_tile_file_name = landmark_file_name_from_tile_relative_path(tile_relative_path, 0) ;
42+
channel_0_tile_file_path = fullfile(landmark_root_path, tile_relative_path, channel_0_tile_file_name) ;
43+
channel_1_tile_file_name = landmark_file_name_from_tile_relative_path(tile_relative_path, 1) ;
44+
channel_1_tile_file_path = fullfile(landmark_root_path, tile_relative_path, channel_1_tile_file_name) ;
45+
is_to_be_run = ...
46+
~(exist(channel_0_tile_file_path, 'file') && exist(channel_1_tile_file_path, 'file')) ;
47+
is_to_be_run_from_tile_index(tile_index) = is_to_be_run ;
48+
parfor_progress() ;
49+
end
50+
parfor_progress(0) ;
51+
end
52+
fprintf('Done determining which of the %d tiles need to be LPLed.\n', tile_count) ;
53+
tile_index_from_tile_to_be_run_index = find(is_to_be_run_from_tile_index) ;
54+
relative_path_from_tile_to_be_run_index = relative_path_from_tile_index(is_to_be_run_from_tile_index) ;
55+
tile_to_be_run_count = length(tile_index_from_tile_to_be_run_index)
56+
57+
58+
%
59+
% Run stages 123 on all tiles
60+
%
61+
62+
% Create the bqueue
63+
if do_use_bsub ,
64+
fprintf('Queueing LPL on %d tiles...\n', tile_to_be_run_count) ;
65+
bqueue = bqueue_type(do_actually_submit, max_running_slot_count) ;
66+
parfor_progress(tile_to_be_run_count) ;
67+
for tile_to_be_run_index = 1 : tile_to_be_run_count ,
68+
tile_relative_path = relative_path_from_tile_to_be_run_index{tile_to_be_run_index} ;
69+
%output_folder_path = fullfile(line_fix_path, tile_relative_path) ;
70+
%ensure_folder_exists(output_folder_path) ; % so stdout has somewhere to go
71+
%stdouterr_file_path = fullfile(output_folder_path, 'stdouterr-run-2.txt') ;
72+
bqueue.enqueue(slots_per_job, stdouterr_file_path, bsub_option_string, ...
73+
@lpl_process_single_tile, ...
74+
tile_relative_path, ...
75+
raw_root_path, ...
76+
line_fix_root_path, ...
77+
p_map_root_path, ...
78+
landmark_root_path, ...
79+
do_line_fix, ...
80+
do_force_computation) ;
81+
parfor_progress() ;
82+
end
83+
parfor_progress(0) ;
84+
fprintf('Done queueing LPL on %d tiles.\n\n', tile_to_be_run_count) ;
85+
86+
fprintf('LPLing queue on %d tiles...\n', length(bqueue.job_ids)) ;
87+
maximum_wait_time = inf ;
88+
do_show_progress_bar = true ;
89+
tic_id = tic() ;
90+
job_statuses = bqueue.run(maximum_wait_time, do_show_progress_bar) ;
91+
toc(tic_id)
92+
fprintf('Done LPLing queue on %d tiles.\n', length(bqueue.job_ids)) ;
93+
job_statuses
94+
successful_job_count = sum(job_statuses==1)
95+
else
96+
% Useful for debugging
97+
parfor_progress(tile_to_be_run_count) ;
98+
for tile_to_be_run_index = 1 : tile_to_be_run_count ,
99+
tile_relative_path = relative_path_from_tile_to_be_run_index{tile_to_be_run_index} ;
100+
%output_folder_path = fullfile(line_fix_path, tile_relative_path) ;
101+
%ensure_folder_exists(output_folder_path) ; % so stdout has somewhere to go
102+
%stdouterr_file_path = fullfile(output_folder_path, 'stdouterr-run-2.txt') ;
103+
lpl_process_single_tile( ...
104+
tile_relative_path, ...
105+
raw_root_path, ...
106+
line_fix_root_path, ...
107+
p_map_root_path, ...
108+
landmark_root_path, ...
109+
do_line_fix, ...
110+
do_force_computation) ;
111+
parfor_progress() ;
112+
end
113+
parfor_progress(0) ;
114+
end
115+
116+
117+
%
118+
% Run stage 4 (landmark matching)
119+
% We bqueue up a single job that will use 48 cores
120+
%
121+
122+
% New params for bjobs
123+
do_use_bsub = true ;
124+
do_actually_submit = true ;
125+
max_running_slot_count = inf ;
126+
bsub_option_string = '-P mouselight -J mouselight-landmark-matching' ;
127+
slots_per_job = 48 ;
128+
stdouterr_file_path = fullfile(script_folder_path, 'mouselight-landmark-matching.out.txt') ;
129+
130+
% Create the bqueue
131+
if do_use_bsub ,
132+
fprintf('Running landmark-matching (as single bsub job)...\n') ;
133+
bqueue = bqueue_type(do_actually_submit, max_running_slot_count) ;
134+
bqueue.enqueue(slots_per_job, stdouterr_file_path, bsub_option_string, ...
135+
@landmark_match_all_tiles_in_z, ...
136+
raw_root_path, ...
137+
sample_memo_folder_path, ...
138+
landmark_root_path, ...
139+
z_point_match_root_path, ...
140+
do_force_computation) ;
141+
maximum_wait_time = inf ;
142+
do_show_progress_bar = false ;
143+
tic_id = tic() ;
144+
job_statuses = bqueue.run(maximum_wait_time, do_show_progress_bar) ;
145+
toc(tic_id)
146+
if all(job_statuses==1) ,
147+
fprintf('Done running landmark-matching.\n\n') ;
148+
else
149+
fprintf('Done running landmark-matching, but the job returned a non-zero error code.\n\n') ;
150+
end
151+
else
152+
% Useful for debugging
153+
landmark_match_all_tiles_in_z( ...
154+
raw_root_path, ...
155+
sample_memo_folder_path, ...
156+
landmark_root_path, ...
157+
z_point_match_root_path, ...
158+
do_force_computation) ;
159+
end

0 commit comments

Comments
 (0)