using regular expression and creating a csv file from image file names

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

using regular expression and creating a csv file from image file names

Sean Burke
Hello Everyone,
                    I am trying to find out if it is possible to get information/annotation from my image file name (and path) and write that to a .csv file in ImageJ. Specifically I want to create a csv or text file with 3 column headers: File name, Channel, and Well. I have a folder with a bunch of files from a 96 well plate and each well has two channel images. I would like to organize the image names from the folder in this fashion automatically so the resulting csv table would look like the one below. I have read that this may be possible with regular expressions in ImageJ but I have no idea where to start with a macro for this. Does anyone have any advice where to get more information about doing something like this or a macro that does something similar for me to start from?

Four images in the folder:

Filename

Channel

Well

c:\full path\image experiment\Channel1-05-min-A01.tif

1

A01

c:\full path\image experiment\Channel2-05-min-A01.tif

2

A01

c:\full path\image experiment\Channel1-05-min-A02.tif

1

A02

c:\full path\image experiment\Channel2-05-min-A02.tif

2

A02



Sincerely,
Sean Burke
Reply | Threaded
Open this post in threaded view
|

Re: using regular expression and creating a csv file from image file names

Krs5
Dear Sean,

The code below might do what you want (not fully tested).

dirS = getDirectory("Select directory which contains the image files");
dirA = getDirectory("Select directory to save resulting text file");
list = getFileList(dirS);
print("filename\tChannel\twell");
for (i=0; i<list.length; i++) {
        path = dirS+list[i];
        name = File.getName(path);
        n = lengthOf(name);
        if (startsWith(name, "Channel1"))
                Channel = 1;
                else{
                         if (startsWith(name, "Channel2")) Channel = 2;
                                else exit("file name incorrect");
                }
        for (j=(n-4);j>0;j--){
                char = substring(name, j, (j+1));
                if (matches(char, "-")){
                        well = substring(name,(j+1), (n-4));
                        j=0;
                }
        }
        print(path+"\t"+Channel+"\t"+well);
}
selectWindow("Log")
saveAs("txt",dirA+"list.csv");
run("Close");

It expects only tif files in the directory
Best wishes

Kees


Dr Ir K.R. Straatman
Senior Experimental Officer
Centre for Core Biotechnology Services
College of Medicine, Biological Sciences and Psychology
University of Leicester

http://www.le.ac.uk/biochem/microscopy/home.html



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Sean Burke
Sent: 28 March 2012 00:38
To: [hidden email]
Subject: using regular expression and creating a csv file from image file names

Hello Everyone,
                    I am trying to find out if it is possible to get information/annotation from my image file name (and path) and write that to a .csv file in ImageJ. Specifically I want to create a csv or text file with 3 column headers: File name, Channel, and Well. I have a folder with a bunch of files from a 96 well plate and each well has two channel images. I would like to organize the image names from the folder in this fashion automatically so the resulting csv table would look like the one below. I have read that this may be possible with regular expressions in ImageJ but I have no idea where to start with a macro for this. Does anyone have any advice where to get more information about doing something like this or a macro that does something similar for me to start from?

Four images in the folder:

Filename

Channel

Well

c:\full path\image experiment\Channel1-05-min-A01.tif

1

A01

c:\full path\image experiment\Channel2-05-min-A01.tif

2

A01

c:\full path\image experiment\Channel1-05-min-A02.tif

1

A02

c:\full path\image experiment\Channel2-05-min-A02.tif

2

A02



Sincerely,
Sean Burke