Hi all,
Thanks for reading this macro question from a beginner. I'm trying to open a bunch of .oib files, split into their individual channels, then rename C=0 to include "GFP", C=1 "RFP" and don't bother with C=2). Then save the GFP and RFP files. My original folder has three .oib files, each with these three channels. The code below works fine for the first two .oib files, but doesn't complete the third one so I end up with file 1 GFP, file 1 RFP file 2 GFP, file 2 RFP file 3 GFP all saved correctly but file 3 C=1 and C=2 channels untouched. Worse still, if I have six original files, both file 5 and file 6 have C=0 saved as GFP fine, but both C=1 channels untouched. I'm guessing it is a problem with the number of times it runs the second "for" loop? I tried getting it to print the loop numbers etc to work out what what going on but the numbers don't make sense to me. Can anyone offer any suggestions? Thanks very much for your help, Cath dir1 = getDirectory("Choose source directory"); list = getFileList(dir1); dir2 = getDirectory("Choose destination directory"); for (i=0; i<list.length; i++) { path = dir1+list[i]; print("list length" + list.length); run("Bio-Formats", "open=&path split_channels"); for (img=1; img<=nImages; img++) { print("loop" + i); print("nImages" + nImages); selectImage(img); title = getTitle; if(matches(title, ".*C=0.*")) { saveAs("tif", dir2 + title + "EGFP"); close(); } if(matches(title, ".*C=1.*")) { saveAs("tif", dir2 + title + "RFP"); close(); } if(matches(title, ".*C=2.*")) { close(); } print("end"); print(""); } } |
Hi Cath,
the 'close()' commands in the inner loop change the value of your loop limit expression ('img<=nImages') while looping. Do the cleanup of images after the loop: src=getDirectory("Source"); list=getFileList(src); dst=getDirectory("Destination"); for (i=0; i<list.length; i++) { path=src+list[i]; run("Bio-Formats", "open=&path split_channels"); for (j=1; j<=nImages; j++) { selectImage(j); title = getTitle; if (endsWith(title,"C=0")) { save(dst+title+" EGFP.tif"); } if (endsWith(title,"C=1")) { save(dst+title+" RFP.tif"); } } run("Close All"); } -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Cath Heyward Sent: 16 January 2015 11:01 To: [hidden email] Subject: help with macro loop? Hi all, Thanks for reading this macro question from a beginner. I'm trying to open a bunch of .oib files, split into their individual channels, then rename C=0 to include "GFP", C=1 "RFP" and don't bother with C=2). Then save the GFP and RFP files. My original folder has three .oib files, each with these three channels. The code below works fine for the first two .oib files, but doesn't complete the third one so I end up with file 1 GFP, file 1 RFP file 2 GFP, file 2 RFP file 3 GFP all saved correctly but file 3 C=1 and C=2 channels untouched. Worse still, if I have six original files, both file 5 and file 6 have C=0 saved as GFP fine, but both C=1 channels untouched. I'm guessing it is a problem with the number of times it runs the second "for" loop? I tried getting it to print the loop numbers etc to work out what what going on but the numbers don't make sense to me. Can anyone offer any suggestions? Thanks very much for your help, Cath dir1 = getDirectory("Choose source directory"); list = getFileList(dir1); dir2 = getDirectory("Choose destination directory"); for (i=0; i<list.length; i++) { path = dir1+list[i]; print("list length" + list.length); run("Bio-Formats", "open=&path split_channels"); for (img=1; img<=nImages; img++) { print("loop" + i); print("nImages" + nImages); selectImage(img); title = getTitle; if(matches(title, ".*C=0.*")) { saveAs("tif", dir2 + title + "EGFP"); close(); } if(matches(title, ".*C=1.*")) { saveAs("tif", dir2 + title + "RFP"); close(); } if(matches(title, ".*C=2.*")) { close(); } print("end"); print(""); } } -- View this message in context: http://imagej.1557.x6.nabble.com/help-with-macro-loop-tp5011248.html Sent from the ImageJ mailing list archive at Nabble.com. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |