Macro for Blind Analyses

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro for Blind Analyses

Adam N. Berman
Hey All,

I am looking for a specific macro to help make things more efficient in my
lab's "blind" analyses.

The ideal macro would be one that could:

(1) Export a group of "lsm" files to TIF or JPEG;

(2) Name each new TIF/JPEG with a generic name for the blind analysis, like
a.[date].jpeg, b.[date].jpeg, c.[date].jpeg, etc...

(3) Create an Excel file that correlates the name of the original lsm files
to the newly generated names of the TIF/ JPEG. That way, after the analysis
is complete, it will be easy to find which TIF/JPEG images correlates to
each of the original lsm images.

Has anyone heard of a macro like this? Has anyone created one? Does anyone
know of an existing way to do this?

As it stands now, doing blind studies in my lab takes an excruciatingly long
time to prepare. First, we export each file individually, rename each one
generically, and manually input the data into an excel file. For 100 images,
it may take more than an hour of mindless labor which could be spent doing
other productive things.

Any help would be greatly appreciated.

Thanks!

- Adam
Reply | Threaded
Open this post in threaded view
|

Re: Macro for Blind Analyses

lechristophe
Hi Adam,

I gave a shot at this some time ago. I wrote a macro called "Shuffler" that
randomize images to a new folder, keeping a log of the correspondance
between randomized names and original names. As an extra, it keeps channels
grouped under the same randomized name, meaning that all channels for each
image are renamed in the same way.

It works with a folder containing tiffs (all channels in the same folder),
channels must have something in the name to discriminate them (like -CH01 or
any other string, it is user-defined).

It is a very crude 1.0 version and I'm absolutely not sure there is no bug
or glitch, as I did'nt use it much. If you want to test it I'd be very happy
to have your comments.

The macro is here :
http://www.cleterrier.net/Macros/Shuffler_1.0.txt

Christophe



On Wed, Jul 14, 2010 at 10:20, Adam N. Berman <[hidden email]> wrote:

> Hey All,
>
> I am looking for a specific macro to help make things more efficient in my
> lab's "blind" analyses.
>
> The ideal macro would be one that could:
>
> (1) Export a group of "lsm" files to TIF or JPEG;
>
> (2) Name each new TIF/JPEG with a generic name for the blind analysis, like
> a.[date].jpeg, b.[date].jpeg, c.[date].jpeg, etc...
>
> (3) Create an Excel file that correlates the name of the original lsm files
> to the newly generated names of the TIF/ JPEG. That way, after the analysis
> is complete, it will be easy to find which TIF/JPEG images correlates to
> each of the original lsm images.
>
> Has anyone heard of a macro like this? Has anyone created one? Does anyone
> know of an existing way to do this?
>
> As it stands now, doing blind studies in my lab takes an excruciatingly
> long
> time to prepare. First, we export each file individually, rename each one
> generically, and manually input the data into an excel file. For 100
> images,
> it may take more than an hour of mindless labor which could be spent doing
> other productive things.
>
> Any help would be greatly appreciated.
>
> Thanks!
>
> - Adam
>
Reply | Threaded
Open this post in threaded view
|

Re: Macro for Blind Analyses

Damien
This post was updated on .
Hi Christophe,

Just saying thanks for your macro. Worked like a charm for me.
- I just removed line 199 which saves the original file in the destination folder because I had no use for it.
- also a subsidiary remark that if your pictures have only one channel, the user choice of channel names can be problematic. I solved it quick and dirty by putting as channel 1 name the extension of the files ("tif"), but I think ideally it would be nice if the macro worked when you uncheck all of the channels (I felt lazy about it and didn't make the modification).

But again overall a simple and handy tool.

Best,
Reply | Threaded
Open this post in threaded view
|

Re: Macro for Blind Analyses

Martin Höhne
In reply to this post by Adam N. Berman
Hi Adam,

I wrote something similar which might fit your needs. The code is probably a bit confusing, but it works in our hands.

The first macro "randomizes" a folder with images. I.e. a subfolder is generated with randomized filenames. In addition a text file is generated that has the random name and the original names in two columns.

The second macro lets you de-randomize your randomized files. It uses the text file generated with the first macro and makes files with this name pattern: randomname__originalname.

I copy both macros below, maybe they are of use for someone.

Martin

***randomizer*****************************************

requires("1.46c")
/*
Macro randomizes the file names of all files in the selected direcotry

- the selected directory must only contain image files
- randomized files will be stored in a subfolder
- in the original folder a file "randomizelist.txt" will be created that contains a two column list with newname and originalname
- this file is needed for the De-randomization (other macro)

Martin Hoehne feb 2012
_file_randomizer_v09
*/

run("Bio-Formats Macro Extensions");  //This will enable the bioformats macro functions; needed for zvi files

print("\\Clear"); //clear the log

source_dir = getDirectory("Source Directory");

setBatchMode(true);
list = getFileList(source_dir); //list is already an array
File.makeDirectory(source_dir+File.separator+"randomized"); // new directory for Data
zufallliste=newArray(0); // this array will be filled with the randomized file names
for (i=0; i<list.length; i++) {
        zufall = round(random*(100000)); // generate randomized filename

        // ensure that zufall is a 5-digit number -- needed later on for sorting
        // numerical and alphabetical sorting have to give the same result!!!
        if (zufall < 10000) {
                do {
                        zufall=zufall*10;
                       
                } while zufall<10000;
        }
        if (zufall > 99999) {
                do {
                        zufall=zufall/10;
                       
                } while zufall>99999;
        }
        zufallliste=Array.concat(zufallliste, zufall); //zufallliste is an array containing the randomized file names

        // open an image
        Ext.openImagePlus(source_dir + "/" + list[i]);// mit open werden zvi nicht geoeffnet
       
        // delete the original filename info from the metadata (displayed in the image header in imageJ)
        setMetadata("Label", "randomized_filename");
       
        // save the file with the randomized filename (will later be renamed)
        saveAs("tiff", source_dir+File.separator+"randomized"+File.separator+zufall+".tif"); ;
        close();
       
}

// rename the randomized files with a shorter finalname (1,2,3....) --better readable than the long randomnames
// the random names (5 digit numbers) are sorted, and after sorting they [alphabetically because it is a string] smallest name
// (number) is changed to 1, the second to 2 ....
// since all randomnames are 5 digit numbers, the alphabetically sorting has the same result as sorting according to the number.
// "decipher table": create an array with randomnames and originalnames fused into one string (and "random__" in between)
       
        bothnames=newArray(list.length);
        for (i=0; i<list.length; i++) {
                bothnames[i]=""+zufallliste[i]+"random__"+list[i];
        }
       
        // sort the array (smallest numbered filenames first), e.g.
        // 34321random_realname1, 65433random_realname2, ....
        Array.sort(bothnames);
               
        // create a txt file with finalname (1,2,3 ...) and original name (the part after "random__" in the array elements) [tab separated]
        for (i=0; i<bothnames.length; i++) {
                wo=indexOf(bothnames[i], "random__");
                File.append(i+1+"\t"+substring(bothnames[i], wo+8), source_dir+File.separator+"Randomizelist.txt"); // Appends string to the end of the specified file.
        }

// assign the final names
Array.sort(zufallliste);

for (i=0; i<zufallliste.length; i++) {
        finalname=i+1;
        //next two lines:
        //randomname is the name of the file after randomization
        //endname is the name the file will finally get (including path)
        randomname=source_dir+File.separator+"randomized"+File.separator+zufallliste[i]+".tif";
        endname=source_dir+File.separator+"randomized"+File.separator+finalname+".tif";
       
        File.rename(randomname, endname);
}
setBatchMode(false);
print("Your files are randomized");





*****de-randomizer*******************

/*
 files that are randomized with the file_randomizer macro can be
 de-randomized with this macro

 - the user is aked for the Randomizelist.txt file generated by the randomizer macro
 - the user is aked for the folder that contains the randomized files
 - this folder must contain only the randomized files
 - de-randomized files are stored in a subfolder that is automatically generated
 - the are named according to this scheme: randomized-name__original-name

Martin Hoehne, July 2012
_file_de-randomizer_v03
*/

 
print("\\Clear"); //clear the log

rndpath=File.openDialog("Select the Randomizelist.txt file");
if (endsWith(rndpath,".txt")) {
        liste=File.openAsString(rndpath);
        listarr = split(liste, "\t\n"); //listarr[n] = ranomized name, listarr[n+1] = original name
        filenumber=lengthOf(listarr);
}
else exit("quit macro. \nNot a txt file!");

source_dir = getDirectory("Directory with randomized files");
setBatchMode(true);
if (File.exists(source_dir)) {
    list = getFileList(source_dir); //list is already an array
                if (list.length!=(filenumber/2)) exit("quit macro -- Randomizelist.txt and the number of files in your folder do not match");
                File.makeDirectory(source_dir+File.separator+"DErandomized"); // new directory for de-randomized files
               
                for (i=0; i<list.length; i++) {
                        open(source_dir + "/" + list[i]);

                        //bildID = getImageID();
                        //selectImage(bildID);
                       
                        // create namecore for results
                        //bild=getTitle(); // Bildnamen ohne Pfad ermitteln - braucht man um das Fenster auszuwaehlen
                        bildcore=File.nameWithoutExtension;

       
               


                        //the randomized file name for the result files is replaced here with the randomized-name__original-name
                        for (m=0; m<filenumber; m=m+2){
                                if (bildcore == listarr[m]) {
                                        bildcore = listarr[m]+"__"+listarr[m+1];
                                }
                        }
                       
                        // delete the new filename info from the metadata (displayed in the image header in imageJ)
                        setMetadata("Label", bildcore);

                        saveAs("tiff", source_dir+File.separator+File.separator+"DErandomized"+File.separator+bildcore+".tif");
                }
        }
run("Close All");
setBatchMode(false);
print("Your files are de-randomized");