Identifying files by name AND looping through ROIs

Hello!

I have a folder that has multiple image pairs in the red channel and the green channel. These have the same name but “ch00” or “ch01” at the end.
The green image for each pair has multiple ROI saved as an overlay already.

I’m trying to write a macro that I can use to do the following:

  1. Open up each green channel image
  2. Open the corresponding red channel image
  3. Send the green channel ROIs to the ROI manager.
  4. For each ROI, crop the ROI from the green image and red image.
  5. For the cropped pair, perform Coloc2 analysis
  6. Save the output

I have got the following so far (I know it’s a mess, I’ve got confused and lost doing it!). Can anybody please help me?

setBatchMode("show");
title=getTitle;

filestem=substring(title,0, 23)

run("8-bit");

list=getFileList('/Users/beckyjones/Desktop/New foldtpctpcer (2)/Arl8b/');

for(i=0;i<list.length;i++){

if (indexOf(list[i],filestem) && indexOf(list[i],"ch00")=1 ){
     run("8-bit");
     run("To ROI Manager");
     numROIs = roiManager("count");
	
	for(i=0; i<numROIs;i++) {
	roiManager("Select", i);
	run("Crop")
	}

selectWindow(title);
for(i=0; i<numROIs;i++) {

	roiManager("Select", i);
	run("Crop")
}

	run("Coloc 2", "roi_or_mask=<None> threshold_regression=Costes show_save_pdf_dialog spearman's_rank_correlation costes'_significance_test psf=3 costes_randomisations=100]");


}

So you are trying to do Coloc 2 on each ROI for each pair of images? For example, if you had 5 image pairs with 5 ROIs each, you would be doing 25 Coloc 2 operations?

Also, it appears you are missing a closing brace somewhere.

You have an assignment in the IF clause. You need to compare rather than to assign:
if (indexOf(list[i],filestem) && indexOf(list[i],"ch00")==1 ){
and probably you only want to test if(indexOf(list[i],"ch00")==-1 as you walk the file list and automatically will encounter all file names, opening ch00 and leaving ch01 alone for the time being. Or is there magic in substring(title,0, 23)?
Also, you don’t seem to open an image before you run the 8-bit command and add the ROI to the ROI manager. I would expect you to do so if you walk the file list to build the entire set of ROIs?

1 Like