From b30da837bc648d9083307809a84d164b21e94171 Mon Sep 17 00:00:00 2001 From: Laurent Guerard <laurent.guerard@unibas.ch> Date: Tue, 14 Jan 2025 11:24:07 +0100 Subject: [PATCH] Refactor fiber typing to use loop --- 2c_fibertyping.py | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/2c_fibertyping.py b/2c_fibertyping.py index e10c3a2..ffc1520 100755 --- a/2c_fibertyping.py +++ b/2c_fibertyping.py @@ -528,29 +528,21 @@ positive_c2_c3 = list( set(all_fiber_subsets[1]).intersection(all_fiber_subsets[ positive_c1_c2_c3 = list( set(positive_c1_c2).intersection(all_fiber_subsets[2]) ) # update ROI color & results table for double and triple positives -if len(positive_c1_c2) > 0: - preset_results_column( rt, "channel " + str(fiber_channel_1) + "," + str(fiber_channel_2) + " positive (magenta)", "NO" ) - change_subset_roi_color(rm, positive_c1_c2, "magenta") - save_selected_rois( rm, positive_c1_c2, output_dir + "/" + raw_image_title + "_positive_fiber_rois_c" + str(fiber_channel_1) + "_c" + str(fiber_channel_2) + ".zip") - add_results( rt, "channel " + str(fiber_channel_1) + "," + str(fiber_channel_2) + " positive (magenta)", positive_c1_c2, "YES") - -if len(positive_c1_c3) > 0: - preset_results_column( rt, "channel " + str(fiber_channel_1) + "," + str(fiber_channel_3) + " positive (yellow)", "NO" ) - change_subset_roi_color(rm, positive_c1_c3, "yellow") - save_selected_rois( rm, positive_c1_c3, output_dir + "/" + raw_image_title + "_positive_fiber_rois_c" + str(fiber_channel_1) + "_c" + str(fiber_channel_3) + ".zip") - add_results( rt, "channel " + str(fiber_channel_1) + "," + str(fiber_channel_3) + " positive (yellow)", positive_c1_c3, "YES") - -if len(positive_c2_c3) > 0: - preset_results_column( rt, "channel " + str(fiber_channel_2) + "," + str(fiber_channel_3) + " positive (cyan)", "NO" ) - change_subset_roi_color(rm, positive_c2_c3, "cyan") - save_selected_rois( rm, positive_c2_c3, output_dir + "/" + raw_image_title + "_positive_fiber_rois_c" + str(fiber_channel_2) + "_c" + str(fiber_channel_3) + ".zip") - add_results( rt, "channel " + str(fiber_channel_2) + "," + str(fiber_channel_3) + " positive (cyan)", positive_c2_c3, "YES") - -if len(positive_c1_c2_c3) > 0: - preset_results_column( rt, "channel " + str(fiber_channel_1) + "," + str(fiber_channel_2) + "," + str(fiber_channel_3) + " positive(white)", "NO" ) - change_subset_roi_color(rm, positive_c1_c2_c3, "white") - save_selected_rois( rm, positive_c1_c2_c3, output_dir + "/" + raw_image_title + "_positive_fiber_rois_c" + str(fiber_channel_1) + "_c" + str(fiber_channel_2) + "_c" + str(fiber_channel_3) + ".zip") - add_results( rt, "channel " + str(fiber_channel_1) + "," + str(fiber_channel_2) + "," + str(fiber_channel_3) + " positive(white)", positive_c1_c2_c3, "YES") +channels = [ + (positive_c1_c2, [fiber_channel_1, fiber_channel_2], "magenta"), + (positive_c1_c3, [fiber_channel_1, fiber_channel_3], "yellow"), + (positive_c2_c3, [fiber_channel_2, fiber_channel_3], "cyan"), + (positive_c1_c2_c3, [fiber_channel_1, fiber_channel_2, fiber_channel_3], "white") +] + +for positives, ch_nums, color in channels: + if positives: + ch_str = ",".join(map(str, ch_nums)) + color_label = "channel %s positive (%s)" % (ch_str, color) + preset_results_column(rt, color_label.replace(',', '-'), "NO") + change_subset_roi_color(rm, positives, color) + save_selected_rois(rm, positives, "%s/%s_positive_fiber_rois_c%s.zip" % (output_dir, raw_image_title, '_c'.join(map(str, ch_nums)))) + add_results(rt, color_label.replace(',', '-'), positives, "YES") # save all results together save_all_rois( rm, output_dir + "/" + raw_image_title + "_all_fiber_type_rois_color-coded.zip" ) -- GitLab