|
| 1 | +function relative_path_from_tile_index = fix_line_shift_in_place_for_sample(... |
| 2 | + tile_root_path, sample_memo_folder_path, do_use_bqueue, do_actually_submit, do_run_in_debug_mode) |
| 3 | + |
| 4 | + % % Build an index of the paths to raw tiles |
| 5 | + % sample_tag = '2021-10-19' ; |
| 6 | + % analysis_tag = 'get-stragglers' ; |
| 7 | + % raw_tiles_path = sprintf('/groups/mousebrainmicro/mousebrainmicro/data/%s/Tiling', sample_tag) ; |
| 8 | + % script_folder_path = fileparts(mfilename('fullpath')) ; |
| 9 | + % sample_memo_folder_path = fullfile(script_folder_path, 'memos', sample_tag) ; |
| 10 | + % analysis_memo_folder_path = fullfile(sample_memo_folder_path, analysis_tag) ; |
| 11 | + % %line_fix_path = fullfile(analysis_memo_folder_path, 'stage_1_line_fix_output') ; |
| 12 | + % line_fix_path = sprintf('/nrs/mouselight/pipeline_output/%s/stage_1_line_fix_output', sample_tag) ; |
| 13 | + % do_write_ancillary_files = true ; |
| 14 | + |
| 15 | + % Set up the par pool |
| 16 | + use_this_fraction_of_cores(1) ; |
| 17 | + |
| 18 | + % Build the tile index |
| 19 | + do_force_computation = false ; |
| 20 | + raw_tile_index = compute_or_read_from_memo(sample_memo_folder_path, ... |
| 21 | + 'raw-tile-index', ... |
| 22 | + @()(build_raw_tile_index(tile_root_path)), ... |
| 23 | + do_force_computation) ; |
| 24 | + %tile_index_from_tile_ijk1 = raw_tile_index.tile_index_from_tile_ijk1 ; |
| 25 | + %ijk1_from_tile_index = raw_tile_index.ijk1_from_tile_index ; |
| 26 | + %xyz_from_tile_index = raw_tile_index.xyz_from_tile_index ; |
| 27 | + relative_path_from_tile_index = raw_tile_index.relative_path_from_tile_index ; |
| 28 | + %raw_tile_map_shape = size(tile_index_from_tile_ijk1) |
| 29 | + tile_count = length(relative_path_from_tile_index) |
| 30 | + |
| 31 | + % Read the original sample metadata |
| 32 | + original_sample_metadata = read_original_sample_metadata(tile_root_path) ; |
| 33 | + |
| 34 | + |
| 35 | + % |
| 36 | + % Figure out which tiles need to be run |
| 37 | + % |
| 38 | + |
| 39 | + fprintf('Determining which of the %d tiles need to be run...\n', tile_count) ; |
| 40 | + is_to_be_run_from_tile_index = true(tile_count, 1) ; |
| 41 | +% if do_force_computation , |
| 42 | +% is_to_be_run_from_tile_index = true(tile_count, 1) ; |
| 43 | +% else |
| 44 | +% is_to_be_run_from_tile_index = true(tile_count,1) ; |
| 45 | +% pbo = progress_bar_object(tile_count) ; |
| 46 | +% for tile_index = 1 : tile_count |
| 47 | +% tile_relative_path = relative_path_from_tile_index{tile_index} ; |
| 48 | +% is_to_be_run = ... |
| 49 | +% ~exist(fullfile(line_fix_path,tile_relative_path,'Xlineshift.txt'), 'file') ; |
| 50 | +% is_to_be_run_from_tile_index(tile_index) = is_to_be_run ; |
| 51 | +% pbo.update() ; %#ok<PFBNS> |
| 52 | +% end |
| 53 | +% end |
| 54 | + fprintf('Done determining which of the %d tiles need to be run.\n', tile_count) ; |
| 55 | + tile_index_from_tile_to_be_run_index = find(is_to_be_run_from_tile_index) ; |
| 56 | + relative_path_from_tile_to_be_run_index = relative_path_from_tile_index(is_to_be_run_from_tile_index) ; |
| 57 | + tile_to_be_run_count = length(tile_index_from_tile_to_be_run_index) |
| 58 | + |
| 59 | + |
| 60 | + % |
| 61 | + % Run line-fix on all tiles |
| 62 | + % |
| 63 | + |
| 64 | + % Create the bqueue |
| 65 | + max_running_slot_count = 800 ; |
| 66 | + bsub_option_string = '-P mouselight -J line-fix' ; |
| 67 | + slots_per_job = 2 ; |
| 68 | + stdouterr_file_path = '' ; % will go to /dev/null |
| 69 | + |
| 70 | + if do_use_bqueue , |
| 71 | + fprintf('Queuing line-fixing on %d tiles...\n', tile_to_be_run_count) ; |
| 72 | + bqueue = bqueue_type(do_actually_submit, max_running_slot_count) ; |
| 73 | + pbo = progress_bar_object(tile_to_be_run_count) ; |
| 74 | + for tile_to_be_run_index = 1 : tile_to_be_run_count , |
| 75 | + tile_relative_path = relative_path_from_tile_to_be_run_index{tile_to_be_run_index} ; |
| 76 | + %output_folder_path = fullfile(line_fix_path, tile_relative_path) ; |
| 77 | + %ensure_folder_exists(output_folder_path) ; % so stdout has somewhere to go |
| 78 | + %stdouterr_file_path = fullfile(output_folder_path, 'stdouterr-run-2.txt') ; |
| 79 | + bqueue.enqueue(slots_per_job, stdouterr_file_path, bsub_option_string, ... |
| 80 | + @fix_line_shift_in_place, ... |
| 81 | + tile_root_path, ... |
| 82 | + tile_relative_path, ... |
| 83 | + original_sample_metadata, ... |
| 84 | + do_run_in_debug_mode) ; |
| 85 | + pbo.update() ; |
| 86 | + end |
| 87 | + fprintf('Done queuing line-fixing on %d tiles.\n\n', tile_to_be_run_count) ; |
| 88 | + |
| 89 | + fprintf('Running queue on %d tiles...\n', length(bqueue.job_ids)) ; |
| 90 | + maximum_wait_time = inf ; |
| 91 | + do_show_progress_bar = true ; |
| 92 | + tic_id = tic() ; |
| 93 | + job_statuses = bqueue.run(maximum_wait_time, do_show_progress_bar) ; |
| 94 | + toc(tic_id) |
| 95 | + fprintf('Done running queue on %d tiles.\n', length(bqueue.job_ids)) ; |
| 96 | + job_statuses |
| 97 | + successful_job_count = sum(job_statuses==1) |
| 98 | + else |
| 99 | + fprintf('Running in-place line-fixing on %d tiles...\n', tile_to_be_run_count) ; |
| 100 | + pbo = progress_bar_object(tile_to_be_run_count) ; |
| 101 | + for tile_to_be_run_index = 1 : tile_to_be_run_count , |
| 102 | + tile_relative_path = relative_path_from_tile_to_be_run_index{tile_to_be_run_index} ; |
| 103 | + fix_line_shift_in_place( ... |
| 104 | + tile_root_path, ... |
| 105 | + tile_relative_path, ... |
| 106 | + original_sample_metadata, ... |
| 107 | + do_run_in_debug_mode) ; |
| 108 | + pbo.update() ; |
| 109 | + end |
| 110 | + fprintf('Done running in-place line-fixing on %d tiles.\n\n', tile_to_be_run_count) ; |
| 111 | + |
| 112 | + end |
| 113 | + |
| 114 | + % Finally, convert the original sample metadata to the sample metadata, |
| 115 | + % overwriting the existing file if needed. |
| 116 | + % This makes it easy to tell if a sample has been line-shifted. |
| 117 | + post_line_fix_sample_metadata = post_line_fix_sample_metadata_from_original_sample_metadata(original_sample_metadata) ; |
| 118 | + write_post_line_fix_sample_metadata(tile_root_path, post_line_fix_sample_metadata) ; |
| 119 | +end |
0 commit comments