//Macro for aligning multiplexed images from multiple rounds of immunofluorescence/staining //All the images should be in one folder //Each round or multiplexing round should be named as layer 1 or round 1, layer 2, layer 3 etc... //There is an option to enter a custom name //Each marker name should be at the end of the file name after an underscore. //There should be a common marker in every round of multiplexing which can be used as a reference for aligning all the channels //This marker should be also in the file name //For example, //H2202Desc_Layer 1_Ganglia1_Hu //H2202Desc_Layer1_Ganglia1_5HT //H2202Desc_Layer2_Ganglia1_Hu //H2202Desc_Layer2_Ganglia1_SP //H2202Desc_Layer3_Ganglia1_Hu //H2202Desc_Layer3_Ganglia1_VAChT // In above, there are 3 rounds of multiplexing and in every round, "Hu" is the common reference marker //The script seggregates each round of IHC as Layer1, Layer 2, Layer 3 //looks for Hu in each channel, uses Hu in the first round as a reference, aligns Hu in each round to this image //The alignment information is then used for other markers in each round to align the images. //The output is aligned stack, stack of all reference marker and an ROI manager with information corresponding to the alignment (landmark correspondences) // Author: Pradeep Rajasekhar // July 2023 // License: BSD3 // // Copyright 2023 Pradeep Rajasekhar, Walter and Eliza Hall Institute of Medical Research // // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // print("\\Clear"); #@ File (style="directory",label="Select folder with immuno files") imageFolder #@ String(label="Enter name of common marker (Hu)") common_marker #@ Integer(value=2, min=1, max=10,label="Enter number of rounds of multiplexing") multiplex_no #@ String(label="Enter name that distinguishes each batch of multiplexing (Layer/Round)") layer #@ boolean(value=false) Choose_Save_Folder #@ boolean(value=false) Finetune_parameters if(Choose_Save_Folder) { save_dir = getDirectory("Enter Save Directory"); } else { save_dir = imageFolder; } //default values minimal_inlier_ratio=0.50; steps_per_scale_octave = 3; if(Finetune_parameters) { Dialog.create("Parameters for alignment (SIFT)"); Dialog.addMessage("Default values shown below will be used if no changes are made"); Dialog.addNumber("minimal_inlier_ratio", minimal_inlier_ratio); Dialog.addNumber("steps per scale octave", steps_per_scale_octave); Dialog.show(); minimal_inlier_ratio = Dialog.getNumber(); steps_per_scale_octave = Dialog.getNumber(); } print("Files being saved at "+save_dir); close("*"); roiManager("reset"); fs=File.separator; file_list=getFileList(imageFolder); common_marker=common_marker.toLowerCase; tissue_array=newArray(); setOption("ExpandableArrays", true); layer=layer.toLowerCase; //tissue_name=tissue_name.toLowerCase; file_name_lower=newArray(); file_name_counter=0; results_folder=save_dir+fs+"Results"+fs; print(results_folder); if(File.exists(results_folder)) { exit("Remove Results folder in directory"); } else { File.makeDirectory(results_folder); } print("Getting reference images"); for (i = 0; i width) max_image_size=height; newImage(common_marker+"_stack", bit_depth+"-bit black", width, height, 1); ref_stack=getTitle(); selectWindow(ref_image); run("Select All"); run("Copy"); run("Select None"); selectWindow(ref_stack); run("Paste"); setMetadata("Label", ref_image); //select reference image from first multiplex layer and ref image from next layer, find SIFT features and save as 2 ROIs for(i=1;i0) roi_counter+=2; } //setBatchMode("exit and display"); selectWindow(stack); no_channels=nSlices; Stack.setDimensions(no_channels, 1, 1); run("Make Composite", "display=Grayscale"); saveAs("tif", results_folder+"Aligned_Stack.tif"); roiManager("deselect"); roiManager("save", results_folder+"landmark_correspondences.zip"); close(ref_image); exit("Done"); //quality assessment using SSIM plugin