Saving multiple logs to single file by a macro



I have a macro measuring colocalisation by JACoP plugin. The output is written to the log file. I’m trying to change the macro to enable batch processing, but the problem is consolidating the results. I want the logs to form columns in the excel sheet. It’s easy to save a single log, but I don’t know how to automatically save them all in a single file as columns. The output from JACoP lookes like this:

Image A: C1
Image B: C2

Pearson's Coefficient:

I tried to paste it to the results table, but I only managed to paste it as a row rather than column, separated by \n, and Excel couldn’t read the resulting file as table. For this, I used this code:

for (i=0; i<list.length; i++) {
	open(directory + list[i]);
	setResult(1, i, result);

coloc() is my colocalisation function. I’m new to batch macro writing and any help would be very appreciated.


IF there are only three essential rows (the two image names and Pearson’s coefficient), grab these as you did with getInfo and keep three strings that you build by concatenating results of each run and a tab character. At the end of your loop, add to each of the three strings a newline and print them to a file.


Thanks. And how do I get just one line of the log by getInfo? I only know how to get the whole log.


Good day!

Here is a demo macro that shows how to get the three items as a tab-delimited string:

print("**************************************************\nImage A: C1\nImage B: C2\n\nPearson's Coefficient:\nr=0.624");
dataStr = split( getInfo("log"), "\n" );
str = substring( dataStr[1], indexOf( dataStr[1], ":" ) + 2, lengthOf( dataStr[1] ) ) + "\t";
str += substring( dataStr[2], indexOf( dataStr[2], ":" ) + 2, lengthOf( dataStr[1] ) ) + "\t";
str += substring( dataStr[5], indexOf( dataStr[5], "=" ) + 1, lengthOf( dataStr[5] ) ) + "\n";
print( str );




Herbie beat me to it and his excellent and complete example yields strings with the data in rows, e.g. when colocalisation between im1 and im2, im3 and im4 and between im5 and im6 with coefficients r1, r2 and r3:


It will give you enough information to split the individual log entries and build the output usint tabs (\t) and newlines (\n) for a column-wise output like


Building on Herbie’s code:


for (i=0;i<3;i++){
	print("**************************************************\nImage A: C"+i1+"\nImage B: C"+i2+"\n\nPearson's Coefficient:\nr=0.62"+i);
	dataStr = split( getInfo("log"), "\n" );
	str1 += substring( dataStr[1], indexOf( dataStr[1], ":" ) + 2, lengthOf( dataStr[1] ) ) + "\t";
	str2 += substring( dataStr[2], indexOf( dataStr[2], ":" ) + 2, lengthOf( dataStr[1] ) ) + "\t";
	str3 += substring( dataStr[5], indexOf( dataStr[5], "=" ) + 1, lengthOf( dataStr[5] ) ) + "\t";

print( str1 );
print( str2 );
print( str3 );exit();


Thank you both very much, it works now. I never worked with strings before.
Since my coloc function actually measures colocalisations between all the channels in the picture, I needed to adapt your code a bit, and sue setResult rather than print to get the table. It works nicely (although the part that makes it work with up to 4 channels is a bit clumsy, but I didn’t need a general version since I don’t use it for more than 4 channels. Here is the final version, in case you (or anyone in the future) are interested.

run("Clear Results");
directory=getDirectory("Choose a Directory");
list = getFileList(directory);
for (i=0; i<list.length; i++) {
	open(directory + list[i]);
	getDimensions(width, height, channels, slices, frames); // To get nubmer of channels to analyze
	if(channels>1) {
		if(channels>2) {
			if(channels>3) {
	for (j=0; j<measurements; j++) {
		dataStr = split( getInfo("log"), "\n" );
		ch1 = substring( dataStr[6*j+1], indexOf( dataStr[6*j+1], ":" ) + 2, lengthOf( dataStr[6*j+1] ) );
		ch2 = substring( dataStr[6*j+2], indexOf( dataStr[6*j+2], ":" ) + 2, lengthOf( dataStr[6*j+2] ) );
		r = substring( dataStr[6*j+5], indexOf( dataStr[6*j+5], "=" ) + 1, lengthOf( dataStr[6*j+5] ) );
		setResult("Image", i, tit);
		setResult("Coloc "+ch1+" "+ch2, i, r);

This way I get a table with names of the image and all the values for all the colocalisations in columns labelled by channels used for that particular calculation. It’s even better than I wanted.


Also for future reference: the way to generalise this for n channels is to use an array of strings, created by ch=newArray(n);