Help debugging GDSC particle overlap macro

Hi - I need some help finishing this macro.

Fiji keeps telling me that it expects a ‘)’ in line 23 (run(“Particle Overlap”, …). I might be crazy, but I don’t think there are any missing parentheses. I made sure that it’s calling all of the variables inside the run command appropriately by printing them individually and checking in the debugging window. I’m wondering if the ‘)’ error might mean something else?

ISHmask = getDirectory("ISH masked slices Directory")
//particle mask; open first; files will end with (red)
imageISH = getDirectory("Image slices Directory")
//particle image; open second; files will end with -1
CBmask = getDirectory("CB masked slices Directory")
//overlap mask; open third; files will end with (green)
results = File.openDialog("Results File (must be .csv)")
//excel file for the data

ISHmaskname = getFileList(ISHmask);
imageISHname = getFileList(imageISH);
CBmaskname = getFileList(CBmask);
for (i = 0; i < ISHmaskname.length; i++)
       batchpartover(ISHmask, imageISH, CBmask, ISHmaskname[i], imageISHname[i], CBmaskname[i],results);

function batchpartover(ISHmask, imageISH, CBmask, ISHmaskname, imageISHname, CBmaskname, results){
	open(ISHmask + ISHmaskname);
	open(imageISH + imageISHname);
	open(CBmask + CBmaskname);

	run("Particle Overlap", "particle_mask=["+ISHmaskname+"] particle_image=["+imageISHname+"+"-1"] overlap_mask=["+CBmaskname+"] file=["+results+"]");

	run("Close All");


Your problem is in line 23 in the particle_image part:

" particle_image=["+imageISHname+"+"-1"]  "

The red parts of the code are strings.
With the + symbol you add the value of a variable like imageISHname to the string.
But the -1 is not a variable nor a string. So the code breaks.

I guess the "+ was added erroneously, it needs to be written like this:

run("Particle Overlap", "particle_mask=["+ISHmaskname+"] particle_image=[" + imageISHname + "-1] overlap_mask=["+CBmaskname+"] file=["+results+"]");

Don’t worry if you don’t see things like this.
It takes practice. After some time these things just pop out like a sore thumb.

Thank you! Your fix worked. I was trying to concatenate a “-1” onto the “imageISHname” filename.

So I guess this means Fiji won’t treat any character inside quotations as a string? And that I can concatenate things just by writing them next to each other inside brackets?

The [ ] brackets ensure Fiji ignores any spaces within a string that you send to it. They have nothing to do with what is a string or not.

Strings are all characters that are within quotations “”.

Strings can be concatenated by the plus symbol.

Please review the Macro Language tutorial, specifically the operator parts:

Will do! Sorry - last question. Why isn’t -1 a string in the original code I wrote (in your answer you say that -1 isn’t a variable or a string)? I understand that -1 by itself is an integer, but by putting it in quotations, don’t I make it into a string?

I just want to make sure I understand the reason why ["+imageISHname+"-1] is correct but ["+imageISHname+"+"-1"] is wrong.

It was not within a quotation, that is the thing.
You will see in the macro editor and also the format above that the -1 had a different color:

" string " -1 " string "

but should be:


That is indicating that it is not a string.
You opened the quotations somewhere and closed it before the -1.
The only way to recognize this is the color.

I see - so theoretically “-1” is fine, but I just made another mistake somewhere else, haha.

Thank you so much - sorry for the naive questions!