// Written by Cenna van Manen. // As input, the macro assumes all images in the chosen folder have the same number of channels and the channels are arranged in the same order. // Furthermore, make sure the files and foldername do not contain comma's (,) or semicolons (;). Last, the indicated folder should not contain any other files. // As output, separate folders will be generated to store the single plane tifs per channel, maintaining the original file names. print ("Starting channel splitter."); requires("1.52h") //Determine if the macro is called upon by another macro, otherwise the variables will be gathered here //Data format data_from_other_macro: input folder, general output folder, channel name list, channel names, image type, is silent mode data_from_other_macro = getArgument(); if (lengthOf(data_from_other_macro)>1){ data_from_other_macro = split(data_from_other_macro, ","); //Sets silent mode based on previously indicated preferences if(data_from_other_macro[4]){ setBatchMode(1); } else { setBatchMode(0); } chosen_folder = data_from_other_macro[0]; general_output_folder = data_from_other_macro[1]; channel_names_list = data_from_other_macro[2]; channel_names = split(channel_names_list, ";"); image_type = data_from_other_macro[3]; output_folders = CreateOutputDirectories(general_output_folder, channel_names); //Save the macro that was used File.copy(File.directory + File.name, general_output_folder + "Macro_used_to_split_channels.txt"); } else { print ("Choose input folder"); chosen_folder = getDirectory("Choose input folder"); channel_names = GetChannelNames(); RunSilentMode(); output_folders = CreateOutputDirectories(chosen_folder, channel_names); general_output_folder = File.getParent(output_folders[0]) + File.separator; //Save the macro that was used File.copy(File.directory + File.name, general_output_folder + "Macro_used_to_split_channels.txt"); image_type = GetInputType(chosen_folder); } SplitChannels(chosen_folder, output_folders, image_type); print ("Splitting channels finished."); //The user defines the number of channels and their names function GetChannelNames(){ Dialog.create("Give channel names"); Dialog.addMessage("Define the names of the channels you want to split as they are in the original file. Make sure to: " + "\n" + "-Supply the same amount of channels as are in the original file " + "\n"+ "-Name the channels in the correct order as in the original file " + "\n"+ "-Do not use any spaces. e.g. DAPI,488"); Dialog.addString ("Channel names", ""); Dialog.show(); channel_names_input = Dialog.getString(); channel_names = split(channel_names_input, ","); return channel_names; } //Create output directories function CreateOutputDirectories(input_folder, channel_names){ print ("Input_folder splitter: ", input_folder); parent_folder = File.getParent(input_folder); print ("Parent_folder splitter: ", parent_folder); main_output_folder = parent_folder + File.separator + "Split channels" + File.separator; output_folder_array = newArray(channel_names.length); File.makeDirectory(main_output_folder); for (i=0; i 1; if (is_image_stack){ image_is_stack_text = "a stack"; } else{ image_is_stack_text = "no stack"; } print(" This image is " + image_is_stack_text + "."); close(); return is_image_stack; } //Define if the macro will be ran in silent mode function RunSilentMode(){ silent_mode = getBoolean("Do you want to run the macro in silent mode? This will not open images while running." + "\n" + "If you select 'no' you will not be able to use the computer while the macro is running. "); setBatchMode(silent_mode); } //Splits the channels and if the input images are stacks the planes are merged function SplitChannels(input_folder, output_folder_array, image_type){ print ("Splitting channels and merging stacks:"); images = getFileList(input_folder); for (j=0; j 1){ run("Split Channels"); } windows = getList("image.titles"); for (k=0; k