Batch Processing Coloc2 with two images from different directories

Hi everyone,

So I’m trying to write a macro to batch analyze photos for colocalization using the coloc2 plugin in imageJ. I have two directories that contain preprocessed images, all ordered the same way between the two different directories. I basically want to do coloc2 analysis for each pair of images in the different directories. I then save the PDF in a third directory.

I’m having trouble getting the macro to work. It runs for a brief second and then says the command is finished. I’m not sure if I am using the wrong language during the “run(coloc2…)” command, or if there is something else wrong. Could someone help me out here? The code is listed below.

macro "batch_coloc2" {
	count = 1;
	setBatchMode(true);
	file1 = getDirectory("C1");
	list1 = getFileList(file1);
	n1 = lengthOf(list1);
	file2 = getDirectory("C2");
	list2 = getFileList(file2);
	n2 = lengthOf(list2);
	file3 = getDirectory("Output");
	small = n1;
	if(small<n2){
		small = n2;

		for (i=0; small<1; i++){
			open(file1+list1[1]);
			open(file2+list2[1]);
			run("Coloc 2", "channel_1=["+list[1]+"] channel_2=["+list[2]+"] roi_or_mask=<None> threshold_regression=Costes display_images_in_result spearman's_rank_correlation manders'_correlation costes'_significance_test psf=3 costes_randomisations=10");
			save(file3);
			close();
		}
	}
}

Hi @anzellar,

use File.separator:

open(file1 + File.separator + list1[1]);

Nico

Hi @VirtualSlide,

I tried that in my code, but still get the same outcome. I even tried adding in a pause for 10 sec after the coloc2 command, but it seems that the command is terminating before it even gets to the coloc2 command. Any other suggestions?

Anthony

Hey @anzellar

not sure if this code does what it’s supposed to do:

Shouldn’t it be

for (i=0; i<small; i++){
    open(file1+list1[i]);

Furthermore, the curly bracket after the if should close before the for, no?

Could you please try?

Cheers,
Robert

1 Like

Hi @haesleinhuepf,

Thank you for the suggestions. You were absolutely correct. I made some changes to the code based off some other suggestions, but here is the updated version. The macro reads all the way through and runs the coloc2 command for each file.

`macro "batch_coloc2" {
	count = 1;
	setBatchMode(true);
	file1 = getDirectory("C1");
	list1 = getFileList(file1);
	n1 = list1.length;
	file2 = getDirectory("C2");
	list2 = getFileList(file2);
	n2 = list2.length;
	file3 = getDirectory("Output");
	small = n1;
	if(small<n2){
		small = n2;

	} for (i=0; i<small; i++){
			open(file1 + File.separator + list1[i]);
			print(list1[i]);
			open(file2 + File.separator + list2[i]);
			print(list2[i]);
			run("Coloc 2", "channel_1=["+list1[i]+"] channel_2=["+list2[i]+"] roi_or_mask=<None> threshold_regression=Costes display_images_in_result spearman's_rank_correlation manders'_correlation costes'_significance_test psf=3 costes_randomisations=10");
			save(file3);
			close();
		}
} 
`

Now I just have to figure out how to save the PDF the coloc2 program produces as a result to the Output Directory. I imagine I will have to provide language that selects the PDF and then run the save command.

Thanks guys for all of your help! I really appreciate it!

Best,

Anthony