diff --git a/spim_registration/timelapse/Snakefile b/spim_registration/timelapse/Snakefile index 0431faad2c1a19570722fa6c6e1b0778d551ebb0..5faec2cf7f7fc810f44db01f2adbf48b5281ed2d 100755 --- a/spim_registration/timelapse/Snakefile +++ b/spim_registration/timelapse/Snakefile @@ -63,7 +63,7 @@ rule define_xml_czi: jdir=JOBDIR, path_bsh=config["common"]["bsh_directory"] + config["define_xml_czi"]["bsh_file"]) - cmd_string += "> {log} 2>&1" + cmd_string += "> {log} 2>&1 && touch {output}" shell(cmd_string) # defining xml for tif dataset @@ -74,24 +74,24 @@ rule define_xml_tif: log: "define_xml_tif.log" run: cmd_string = produce_string( - """{fiji-prefix} {fiji-app} \ - -Dimage_file_directory={jdir} \ - -Dtimepoints={timepoints} \ - -Dacquisition_angles={acquisition_angles} \ - -Dchannels={channels} \ - -Dimage_file_pattern={image_file_pattern} \ - -Dpixel_distance_x={pixel_distance_x} \ - -Dpixel_distance_y={pixel_distance_y} \ - -Dpixel_distance_z={pixel_distance_z} \ - -Dpixel_unit={pixel_unit} \ - -Dxml_filename={first_xml_filename} \ - -Dtype_of_dataset={type_of_dataset} \ - -Dmultiple_timepoints={multiple_timepoints} \ - -Dmultiple_channels={multiple_channels} \ - -Dmultiple_illumination_directions={multiple_illumination_directions} \ - -Dmultiple_angles={multiple_angles} \ - -Dimglib_container={imglib_container} \ - -- --no-splash {path_bsh}""", + """{fiji-prefix} {fiji-app} \ + -Dimage_file_directory={jdir} \ + -Dtimepoints={timepoints} \ + -Dacquisition_angles={acquisition_angles} \ + -Dchannels={channels} \ + -Dimage_file_pattern={image_file_pattern} \ + -Dpixel_distance_x={pixel_distance_x} \ + -Dpixel_distance_y={pixel_distance_y} \ + -Dpixel_distance_z={pixel_distance_z} \ + -Dpixel_unit={pixel_unit} \ + -Dxml_filename={first_xml_filename} \ + -Dtype_of_dataset={type_of_dataset} \ + -Dmultiple_timepoints={multiple_timepoints} \ + -Dmultiple_channels={multiple_channels} \ + -Dmultiple_illumination_directions={multiple_illumination_directions} \ + -Dmultiple_angles={multiple_angles} \ + -Dimglib_container={imglib_container} \ + -- --no-splash {path_bsh}""", config["common"], config["define_xml_tif"], jdir=JOBDIR, @@ -101,13 +101,16 @@ rule define_xml_tif: # resave .czi dataset as hdf5 rule resave_czi_hdf5: - input: rules.define_xml_czi.output, glob.glob('*.czi') - output: "hdf5_Stock68.h5", "hdf5_Stock68.xml" +# input: config["common"]["first_xml_filename"] + ".xml" + input: rules.define_xml_tif.output, glob.glob('*.tif') +# output: "hdf5_Stock68.h5", "hdf5_Stock68.xml" + output: config["common"]["hdf5_xml_filename"] + ".xml", config["common"]["hdf5_xml_filename"] + ".h5" message: "Execute resave_hdf5 on {input}" # threads: int(config["resave_hdf5"]["parallel_timepoints"]) # parallel timepoints should tell me how many timepoints to expect log: "export_czi.log" run: - part_string = produce_string("""{fiji-prefix} {fiji-app} \ + part_string = produce_string( + """{fiji-prefix} {fiji-app} \ -Dimage_file_directory={jdir} \ -Dfirst_xml_filename={first_xml_filename} \ -Dhdf5_xml_filename={hdf5_xml_filename} \ @@ -140,38 +143,39 @@ rule registration: run: cmd_string = produce_string( """{fiji-prefix} {fiji-app} \ --Dparallel_timepoints={file_id_w} \ --Dimage_file_directory={jdir} \ --Dxml_filename={input_xml} \ --Dprocess_timepoint={timepoint} \ --Dprocess_channel={channel} \ --Dprocess_illumination={illuminations} \ --Dprocess_angle={angle} \ --Dprocessing_channel={proc-ch} \ --Dlabel_interest_points={label_interest_points} \ --Dtype_of_registration={type_of_registration} \ --Dtype_of_detection={type_of_detection} \ --Dsubpixel_localization={subpixel_localization} \ --Dimglib_container={imglib_container} \ --Dradius_1={radius_1} \ --Dradius_2={radius_2} \ --Dthreshold={threshold} \ --Dinitial_sigma={initial_sigma} \ --Dthreshold_gaussian={threshold_gaussian} \ --Dregistration_algorithm={algorithm} \ --Dinterest_points_channel_0={interest_points_channel_0} \ --Dinterest_points_channel_1={interest_points_channel_1} \ --Dfix_tiles={fix_tiles} \ --Dmap_back_tiles={map_back_tiles} \ --Dtransformation_model={transformation_model} \ --Dmodel_to_regularize_with={model_to_regularize_with} \ --Dlambda={lambda} \ --Dallowed_error_for_ransac={allowed_error_for_ransac} \ --Ddetection_min_max={detection_min_max} \ --- --no-splash {bsh_file}""", + -Dparallel_timepoints={file_id_w} \ + -Dimage_file_directory={jdir} \ + -Dxml_filename={input_xml} \ + -Dprocess_timepoint={timepoint} \ + -Dprocess_channel={channel} \ + -Dprocess_illumination={illuminations} \ + -Dprocess_angle={angle} \ + -Dprocessing_channel={proc-ch} \ + -Dlabel_interest_points={label_interest_points} \ + -Dtype_of_registration={type_of_registration} \ + -Dtype_of_detection={type_of_detection} \ + -Dsubpixel_localization={subpixel_localization} \ + -Dimglib_container={imglib_container} \ + -Dradius_1={radius_1} \ + -Dradius_2={radius_2} \ + -Dthreshold={threshold} \ + -Dinitial_sigma={initial_sigma} \ + -Dthreshold_gaussian={threshold_gaussian} \ + -Dregistration_algorithm={algorithm} \ + -Dinterest_points_channel_0={interest_points_channel_0} \ + -Dinterest_points_channel_1={interest_points_channel_1} \ + -Dfix_tiles={fix_tiles} \ + -Dmap_back_tiles={map_back_tiles} \ + -Dtransformation_model={transformation_model} \ + -Dmodel_to_regularize_with={model_to_regularize_with} \ + -Dlambda={lambda} \ + -Dallowed_error_for_ransac={allowed_error_for_ransac} \ + -Ddetection_min_max={detection_min_max} \ + -- --no-splash {path_bsh}""", config["common"], config["registration"], file_id_w="{wildcards.file_id}", + path_bsh=config["common"]["bsh_directory"] + config["registration"]["bsh_file"], jdir=JOBDIR, input_xml="{wildcards.xml_base}") cmd_string += "> {log} 2>&1 && touch {output}" @@ -184,17 +188,56 @@ rule xml_merge: output: "{xml_base}_merge.xml" log: "{xml_base}_merge.log" run: - cmd_string = produce_string("{fiji-prefix} {fiji-app} -Dimage_file_directory={jdir} -Dmerged_xml={output} -- --no-splash {bsh_file} > {log} 2>&1", + cmd_string = produce_string( + """{fiji-prefix} {fiji-app} \ + -Dimage_file_directory={jdir} \ + -Dmerged_xml={output} \ + -- --no-splash {path_bsh}""", config["common"], config["xml_merge"], log="{log}", + path_bsh=config["common"]["bsh_directory"] + config["xml_merge"]["bsh_file"], jdir=JOBDIR, output="{output}") + cmd_string += "> {log} 2>&1 && touch {output}" shell(cmd_string) -rule external_trafo: +rule timelapse: input: rules.xml_merge.output - output: rules.xml_merge.output[0] + "_external_trafo" + output: rules.xml_merge.output[0] + "_timelapse" + log: "timelapse.log" + run: + cmd_string = produce_string( + """{fiji-prefix} {fiji-app} \ + -Dimage_file_directory={jdir} \ + -Dmerged_xml={input} \ + -Dtimelapse_process_timepoints={timelapse_process_timepoints} \ + -Dprocess_channel_timelapse={channel} \ + -Dprocess_illumination={illuminations} \ + -Dprocess_angle={angle} \ + -Dreference_timepoint={reference_timepoint} \ + -Dchannel_1={proc-ch} \ + -Dtype_of_registration_timelapse={type_of_registration_timelapse} \ + -Dregistration_algorithm={registration_algorithm} \ + -Dreg_1_interest_points_channel={interest_points_channel_0} \ + -Dreg_2_interest_points_channel={interest_points_channel_1} \ + -Dtransformation_model={transformation_model} \ + -Dmodel_to_regularize_with={model_to_regularize_with} \ + -Dlambda={lambda} \ + -Dallowed_error_for_ransac={allowed_error_for_ransac} \ + -Dsignificance={significance} \ + -- --no-splash {path_bsh}""", + config["common"], + config["registration"], + config["timelapse"], + input="{input}", + path_bsh=config["common"]["bsh_directory"] + config["timelapse"]["bsh_file"], + jdir=JOBDIR) + shell(cmd_string) + +rule external_trafo: + input: rules.timelapse.output + output: rules.timelapse.output[0] + "_external_trafo" log: "external_trafo.log" run: cmd_string = produce_string("""{fiji-prefix} {fiji-app} \ @@ -208,9 +251,10 @@ rule external_trafo: -Dapply_transformation={apply_transformation} \ -Ddefine_mode_transform={define_mode_transform} \ -Dmatrix_transform={matrix_transform} \ --- --no-splash {bsh_file}""", +-- --no-splash {path_bsh}""", config["common"], config["external_transform"], + path_bsh=config["common"]["bsh_directory"] + config["external_trafo"]["bsh_file"], jdir=JOBDIR, input="{input}") cmd_string += "> {log} 2>&1 && touch {output}" @@ -249,10 +293,11 @@ rule deconvolution: -Dpsf_size_y={psf_size_y} \ -Dpsf_size_z={psf_size_z} \ -Diterations={iterations} \ - -- --no-splash {bsh_file}""", + -- --no-splash {path_bsh}""", config["common"], config["deconvolution"], file_id_w="{wildcards.file_id}", + path_bsh=config["common"]["bsh_directory"] + config["deconvolution"]["bsh_file"], jdir=JOBDIR, merged_xml_file="{input.merged_xml}" ) diff --git a/spim_registration/timelapse/timelapse_registration.bsh b/spim_registration/timelapse/timelapse_registration.bsh new file mode 100755 index 0000000000000000000000000000000000000000..e27c1fbb018bc512c33d13eff552cdaf15a8cb68 --- /dev/null +++ b/spim_registration/timelapse/timelapse_registration.bsh @@ -0,0 +1,92 @@ +// Load Fiji dependencies +import ij.IJ; // calls imagej +import ij.Prefs; // calls imagej settings +import ij.ImagePlus; +import java.lang.Runtime; +import java.io.File; +import java.io.FilenameFilter; + +runtime = Runtime.getRuntime(); +System.out.println(runtime.availableProcessors() + " cores available for multi-threading"); + +Prefs.setThreads(1); // defines the number of threads allowed +print("Threads: "+Prefs.getThreads()); // prints thread setting in output + +// Load xml file +System.out.println("---------------------------------------------------------"); +System.out.println("Xml file:"); + +xml_path = System.getProperty( "image_file_directory" ); +merged_xml = System.getProperty( "merged_xml" ); + +System.out.println( "selected_xml = " + xml_path + merged_xml + ".xml"); + +// General Registration Parameters and Channel Settings +System.out.println("---------------------------------------------------------"); +System.out.println( "General parameters: " ); +timelapse_process_timepoints = System.getProperty( "timelapse_process_timepoints" ); +process_channel_timelapse = System.getProperty( "process_channel_timelapse" ); +process_illumination = System.getProperty( "process_illumination" ); +process_angle = System.getProperty( "process_angle" ); +channel_1 = System.getProperty( "channel_1" ); +channel_2 = System.getProperty( "channel_2" ); + +System.out.println( "process_timepoints = " + timelapse_process_timepoints ); +System.out.println( "process_channel = " + process_channel_timelapse ); +System.out.println( "process_illumination = " + process_illumination ); +System.out.println( "process_angle = " + process_angle ); +System.out.println( "channel_1 = " + channel_1 ); +System.out.println( "channel_2 = " + channel_2 ); + +// Timelapse registration Parameter +System.out.println("---------------------------------------------------------"); +System.out.println( "Timelapse Registration: " ); + +reference_timepoint = System.getProperty( "reference_timepoint" ); +System.out.println( "reference_timepoint=" + reference_timepoint ); + +type_of_registration_timelapse = System.getProperty( "type_of_registration_timelapse" ); +registration_algorithm = System.getProperty( "registration_algorithm" ); +reg_1_interest_points_channel = System.getProperty( "reg_1_interest_points_channel" ); +reg_2_interest_points_channel = System.getProperty( "reg_2_interest_points_channel" ); // Dual Channel + +System.out.println( "type_of_registration = " + type_of_registration_timelapse ); +System.out.println( "registration_algorithm = " + registration_algorithm ); +System.out.println( "interest_points_channel_" + channel_1 + " = " + reg_1_interest_points_channel ); +System.out.println( "interest_points_channel_" + channel_2 + " = " + reg_2_interest_points_channel ); + +transformation_model = System.getProperty( "transformation_model" ); +model_to_regularize_with = System.getProperty( "model_to_regularize_with" ); +float lambda = Float.parseFloat( System.getProperty( "lambda" ) ); +int allowed_error_for_ransac = Integer.parseInt( System.getProperty( "allowed_error_for_ransac" ) ); +significance = System.getProperty( "significance" ); + +System.out.println( "transformation = " + transformation ); +System.out.println( "model_to_regularize_with = " + model_to_regularize_with ); +System.out.println( "lambda = " + lambda ); +System.out.println( "allowed_error_for_ransac = " + allowed_error_for_ransac ); +System.out.println( "significance = " + significance ); + +System.out.println( "=======================================================" ); +System.out.println( "Starting Timelapse Registration" ); +IJ.run("Register Dataset based on Interest Points", + "select_xml=" + xml_path + merged_xml + ".xml " + + "process_angle=[" + process_angle + "] " + + "process_channel=[" + process_channel_timelapse + "] " + + "process_illumination=[" + process_illumination + "] " + + "process_timepoint=[" + timelapse_process_timepoints + "] " + + "registration_algorithm=[" + registration_algorithm + "] " + + "type_of_registration=[" + type_of_registration_timelapse + "] " + + "interest_points_channel_" + channel_1 + "=" + reg_1_interest_points_channel + " " + +// "interest_points_channel_" + channel_2 + "=" + reg_2_interest_points_channel + " " + // Dual Channel + "reference=" + reference_timepoint + " " + + "consider_each_timepoint_as_rigid_unit " + + "transformation=" + transformation_model + " " + + "regularize_model " + + "model_to_regularize_with=" + model_to_regularize_with + " " + + "lamba=" + lambda + " " + + "allowed_error_for_ransac=" + allowed_error_for_ransac + " " + + "significance=" + significance + ""); + +/* shutdown */ +runtime.exit(0); diff --git a/spim_registration/timelapse/tomancak_czi.json b/spim_registration/timelapse/tomancak_czi.json index 16e167b908b48317fd6cbc500293ed76906eb368..7a5d46f710ed22805805c561d4bc47df4754a50d 100755 --- a/spim_registration/timelapse/tomancak_czi.json +++ b/spim_registration/timelapse/tomancak_czi.json @@ -29,20 +29,6 @@ "bsh_file" : "define_czi.bsh" }, - "resave_czi_hdf5" : - { - "parallel_timepoints" : "2", - "resave_angle" : "\"All angles\"", - "resave_channel" : "\"All channels\"", - "resave_illumination" : "\"All illuminations\"", - "resave_timepoint" : "\"All Timepoints\"", - "subsampling_factors" : "\"{{ {{1,1,1}}, {{2,2,1}}, {{4,4,1}}, {{8,8,1}} }}\"", - "hdf5_chunk_sizes" : "\"{{ {{32,32,4}}, {{32,32,4}}, {{16,16,16}}, {{16,16,16}} }}\"", - "timepoints_per_partition" : "1", - "setups_per_partition" : "0", - "bsh_file" : "export.bsh" - }, - "define_xml_tif" : { "timepoints" : "1-2", @@ -62,6 +48,20 @@ "bsh_file" : "define_tif_zip.bsh" }, + "resave_czi_hdf5" : + { + "parallel_timepoints" : "2", + "resave_angle" : "\"All angles\"", + "resave_channel" : "\"All channels\"", + "resave_illumination" : "\"All illuminations\"", + "resave_timepoint" : "\"All Timepoints\"", + "subsampling_factors" : "\"{{ {{1,1,1}}, {{2,2,1}}, {{4,4,1}}, {{8,8,1}} }}\"", + "hdf5_chunk_sizes" : "\"{{ {{32,32,4}}, {{32,32,4}}, {{16,16,16}}, {{16,16,16}} }}\"", + "timepoints_per_partition" : "1", + "setups_per_partition" : "0", + "bsh_file" : "export.bsh" + }, + "registration" : { "timepoint" : "\"Single Timepoint (Select from List)\"", @@ -72,16 +72,15 @@ "algorithm" : "\"Fast 3d geometric hashing (rotation invariant)\"", "label_interest_points" : "\"beads\"", "type_of_registration" : "\"Register timepoints individually\"", - "type_of_registration_timelapse" : "\"Match against one reference timepoint (no global optimization)\"", "type_of_detection" : "\"Difference-of-Mean (Integral image based)\"" , "subpixel_localization" : "\"3-dimensional quadratic fit\"", "imglib_container" : "\"ArrayImg (faster)\"", "radius_1" : "2", "radius_2" : "3", "threshold" : "0.005", - "interest_points_channel_0" : "\"[DO NOT register this channel]\"" , - "interest_points_channel_1" : "\"beads\"", - "fix_tiles" : "\"Fix first tile\"" , + "interest_points_channel_0" : "\"beads\"", + "interest_points_channel_1" : "\"[DO NOT register this channel]\"", + "fix_tiles" : "\"Fix first tile\"", "map_back_tiles" : "\"Map back to first tile using rigid model\"", "transformation_model" : "Affine", "model_to_regularize_with" : "Rigid", @@ -97,6 +96,14 @@ { "bsh_file" : "xml_merge.bsh" }, + + "timelapse" : + { + "reference_timepoint" : "0", + "timelapse_process_timepoints" : "\"All Timepoints\"", + "type_of_registration_timelapse" : "\"Match against one reference timepoint (no global optimization)\"", + "bsh_file" : "timelapse_registration.bsh" + }, "external_transform" : {