ImageJ run Coloc 2 in a macro, variables for filenames are not recognized

Hi everyone!

With the code beneath I want to perform colocalization analysis of all possible pairs of files (14 in total). According to the print command “print(Ch1, Ch2)”, all wanted combinations are generated. Unfortunately, it seems that the run Coloc 2 function does not understand that the “Ch1” and “Ch2” variables contain filenames… There is no error message, and all run commands are performed (196 times), but the tif files specified as Ch1 & Ch2 are ignored. Instead a previously (by default) selected pair of files is compared 196 times. Do I probably have to declare a certain format for “Ch1” and “Ch2”?

It would be great if someone could help me with my problem.
Thank you in advance!

roiManager("Select", 1);
//create array/list with file names [01.tif, ..., 14.tif]
a1 = newArray(15);
for (i=1; i<15; i++){
 if( i<10 )
   str = "0" + i + ".tif";
   str = "" + i + ".tif";
 a1[i] = str;
//delete 1st element
a2 = Array.slice(a1,1);

//generate all possible combinations of two file names [01.tif 01.tif, 01.tif 02.tif, ..., 14.tif 14.tif]

for (a=0; a<14; a++){
   Ch1 = a2[a];
   for (b=0; b<14; b++){
   		Ch2 = a2[b];
   		print(Ch1, Ch2);
   		//run Coloc 2
   		run("Coloc 2", "channel_1=Ch1  channel_2=Ch2 roi_or_mask=[ROI Manager] threshold_regression=Costes display_shuffled_images psf=3 costes_randomisations=10");


You are passing a string to the second argument of run() which is literally what is in the quotes. You need to construct it like this:
"channel_1="+ch1+" channel_2="+ch2+" roi..."
Otherwise you are telling Coloc 2 to use literally Ch1 and Ch2 and not the contents of the variable.


Ah cool, thank you, quantixed!
I didn’t know that you can interrupt the quotation marks within the run(). Now I will keep in mind.
I saw that Ch1 was taken literally and not as a variable, I just didn’t know how to put it as a variable…
Meanwhile I came up with almost the same solution by pre-creating the String and putting the whole String variable into the run command:

str2 = “channel_1=” + Ch1 + " channel_2=" + Ch2 + " roi_or_mask=[ROI Manager] threshold_regression=Costes display_shuffled_images psf=3 costes_randomisations=10";

run(“Coloc 2”, str2);