documents:100922imagej_cluster
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
documents:100922imagej_cluster [2010/10/01 11:34] – kota | documents:100922imagej_cluster [2016/05/24 12:46] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 7: | Line 7: | ||
* headless.jar | * headless.jar | ||
* This .jar file manages to work with ImageJ headlessly. | * This .jar file manages to work with ImageJ headlessly. | ||
- | * download headless.jar file from [[http:// | + | * accessible by / |
+ | * Otherwise, | ||
* blobs.tif | * blobs.tif | ||
- | * You could download this by Normal ImageJ (with-head, or GUI). [File -> Open Samples -> Blob]. Save it in the current directory /home/miura/test | + | * You could download this by Normal ImageJ (with-head, or GUI). [File -> Open Samples -> Blob]. Save it in the current directory /home/<your username> |
* headlesstest.ijm | * headlesstest.ijm | ||
- | * You must created this ImageJ macro file and save it in the current directory. See below. | + | * You must write an ImageJ macro file and save it in the current directory. See below. |
* testpbs.sh | * testpbs.sh | ||
- | * You must created this ImageJ macro file and save it in the current directory. See below. | + | * You must write a shell script |
**Write an ImageJ macro** that does the actual processing. | **Write an ImageJ macro** that does the actual processing. | ||
Line 33: | Line 34: | ||
#PBS -N TestPBS | #PBS -N TestPBS | ||
#PBS -l walltime=1: | #PBS -l walltime=1: | ||
- | / | + | / |
</ | </ | ||
Some more explanation: | Some more explanation: | ||
Line 44: | Line 45: | ||
* Argument for the IJ macro is a file with full path information. This is just to be explicit, as base directory is / | * Argument for the IJ macro is a file with full path information. This is just to be explicit, as base directory is / | ||
- | | + | **Login to sub-master** from SSH secure shell, and then type below: |
< | < | ||
cd / | cd / | ||
Line 51: | Line 52: | ||
If you see that the processed file appearing in / | If you see that the processed file appearing in / | ||
* Throwing the job to cluster: | * Throwing the job to cluster: | ||
- | * | + | < |
+ | / | ||
+ | </ | ||
if you see the processed file in / | if you see the processed file in / | ||
Line 58: | Line 61: | ||
Using plugin is a bit tricky. In case of desktop ImageJ, what you need to install plugin is simply drug and drop .class or .jar files to plugins folder within imageJ folder. With headless mode, you need to do the following: | Using plugin is a bit tricky. In case of desktop ImageJ, what you need to install plugin is simply drug and drop .class or .jar files to plugins folder within imageJ folder. With headless mode, you need to do the following: | ||
* explicitly state where the plugins folder resides by setting -ijpath. | * explicitly state where the plugins folder resides by setting -ijpath. | ||
- | * all plugins must not be in jar. They all have to be class files. | + | * <del>all plugins must not be in jar. They all have to be class files.</ |
- | * if you only have jar file, then you should open it by zip archiver and extract all class files. File hierarchy should be maintained within the plugin folder. | + | * <del>if you only have jar file, then you should open it by zip archiver and extract all class files. File hierarchy should be maintained within the plugin folder.</ |
- | ... so the java command would look like this: | + | ... so the java command would look like this: Macro file " |
< | < | ||
- | / | + | cd ~ |
+ | |||
+ | / | ||
</ | </ | ||
- | and the plugins folder resides within /home/miura/test. | + | and the plugins folder resides within /g/almf/software/ |
===== Spreading Jobs with qsub ===== | ===== Spreading Jobs with qsub ===== | ||
Line 71: | Line 78: | ||
For example, if there are 100 files to be image-processed, | For example, if there are 100 files to be image-processed, | ||
- | Here is a script | + | Preparation of scripts could be automated. [[http:// |
+ | There are 7 arguments required to run this script. | ||
+ | |||
+ | * arg[0]: path to the folder cotaining images to be processed | ||
+ | * arg[1]: path to the output folder for processed images | ||
+ | * arg[2]: path to the folder where scripts will be saved | ||
+ | * arg[3]: prefix of job shell scrips. should be longer than 2 chars | ||
+ | * arg[4]: path to ij jars | ||
+ | * arg[5]: path to IJ macro | ||
+ | * arg[6]: IJ macro name | ||
+ | |||
+ | |||
+ | After generating files, change the permission to all the script files so that they could be executed. Should be something like (if your job script prefix is job_): | ||
+ | < | ||
+ | |||
+ | chmod +x job_* | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Example work flow ==== | ||
+ | |||
+ | In this example, job scripts generator (written in ImageJ macro) is executed. This generator also generates job array script. Each job script then executes java command on corresponding image/ | ||
+ | |||
+ | File hierarchy environment is as follows: | ||
+ | |||
+ | * current directory: / | ||
+ | * images are in: / | ||
+ | * ij.jar and headless.jar are in / | ||
+ | * imageJ macro for generating shell scripts is at: / | ||
+ | * imageJ macro for image processing is at: / | ||
+ | < | ||
+ | % / | ||
+ | % chmod +x testdest/ | ||
+ | % qsub testdest/ | ||
+ | </ | ||
+ | * 1st line creates job scripts and a job array script. | ||
+ | * 2nd line changed the permission of job scripts | ||
+ | * 3rd line throws the job to the cluster | ||
+ | |||
+ | Above steps could be written in a meta-shell script as follows. Then all you need to do is just execute one line, sh <name of script> | ||
+ | |||
+ | |||
+ | <sxh shell> | ||
+ | #!/bin/sh | ||
+ | #script for imageJ cluster calculation | ||
+ | |||
+ | # path to IJ jar file | ||
+ | IJJARS="/ | ||
+ | |||
+ | # path to images and stacks | ||
+ | SRCPATH="/ | ||
+ | |||
+ | # path to job array generator macro | ||
+ | JOBGENPATH="/ | ||
+ | |||
+ | # name of job array generator | ||
+ | JOBGENNAME=" | ||
+ | |||
+ | # path to save job scripts and job array script | ||
+ | JOBPATH="/ | ||
+ | |||
+ | # base name (prefix) of job script generated for each images/ | ||
+ | JOBPREF=" | ||
+ | |||
+ | echo "IJ full-path ${IJJARS}/ | ||
+ | |||
+ | #timer | ||
+ | jobstart=$(date +%s) | ||
+ | # | ||
+ | |||
+ | / | ||
+ | |||
+ | chmod +x ${JOBPATH}/ | ||
+ | |||
+ | qsub ${JOBPATH}/ | ||
+ | |||
+ | # timer | ||
+ | jobend=$(date +%s) | ||
+ | # | ||
+ | echo "Time: $((jobend-jobstart)) secs." | ||
+ | #echo "Time: $((jobendN-jobstartN)) nano-sec." | ||
+ | |||
+ | |||
+ | </ | ||
+ | ===== Automated Script (Only from within EMBL network) ===== | ||
+ | |||
+ | Automated Script is available in the ALMF server (clust5fullp.sh). With this script, you only need to invoke the script with two arguments. | ||
+ | * arg[0]: full path to the directory containing image/stack files | ||
+ | * arg[1]: name of the imageJ macro you want to apply. | ||
+ | |||
+ | < | ||
+ | sh / | ||
+ | </ | ||
+ | |||
+ | argument < | ||
+ | |||
+ | argument <Name of ImageJ Macro> is the file name of ImageJ macro, and **this file should be placed under / | ||
+ | |||
+ | For example, your command could be | ||
+ | < | ||
+ | sh / | ||
+ | </ | ||
+ | |||
+ | This script will create two new folders in the directory same as where the image directory is (*_job and *_proc). Processed images or stacks will be saved under *_proc. \\ | ||
+ | Besides, so-called job reports (text files containing output messages) will appear in your current directory where you executed the command. | ||
+ | |||
+ | The script could be viewed in the link below: [[http:// | ||
+ | |||
+ | ===== Example Scripts ===== | ||
+ | ==== Cluster ImageJ processing script ==== | ||
+ | |||
+ | Sample Shell Script that does all. | ||
+ | <sxh shell> | ||
+ | #!/bin/sh | ||
+ | #script for imageJ cluster calculation | ||
+ | # | ||
+ | # | ||
+ | |||
+ | imgdir=$1 | ||
+ | if test -d ${imgdir} | ||
+ | then | ||
+ | echo ${imgdir}" | ||
+ | else | ||
+ | echo ${imgdir}" | ||
+ | exit 1 | ||
+ | fi | ||
+ | outdir=${imgdir}" | ||
+ | if test -d ${outdir} | ||
+ | then | ||
+ | echo ${outdir}" | ||
+ | else | ||
+ | mkdir ${outdir} | ||
+ | echo ${outdir}" | ||
+ | fi | ||
+ | jobdir=${imgdir}" | ||
+ | if test -d ${jobdir} | ||
+ | then | ||
+ | echo ${jobdir}" | ||
+ | else | ||
+ | mkdir ${jobdir} | ||
+ | echo ${jobdir}" | ||
+ | fi | ||
+ | |||
+ | # | ||
+ | |||
+ | # path to IJ jar file | ||
+ | IJJARS="/ | ||
+ | |||
+ | # path to images and stacks | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | SRCPATH=${imgdir} | ||
+ | |||
+ | #path to output directory | ||
+ | # | ||
+ | OUTPATH=${outdir} | ||
+ | |||
+ | # path to job array generator macro | ||
+ | # | ||
+ | JOBGENPATH="/ | ||
+ | |||
+ | # name of job array generator | ||
+ | JOBGENNAME=" | ||
+ | |||
+ | # path to save job scripts and job array script | ||
+ | # | ||
+ | # | ||
+ | JOBPATH=${jobdir} | ||
+ | |||
+ | # base name (prefix) of job script generated for each images/ | ||
+ | # | ||
+ | JOBPREF=" | ||
+ | |||
+ | # path to image processing IJ macro | ||
+ | # | ||
+ | IJMACROPATH="/ | ||
+ | |||
+ | # image processing IJ macro name | ||
+ | IJMACRONAME=" | ||
+ | |||
+ | echo "IJ full-path ${IJJARS}/ | ||
+ | |||
+ | #timer | ||
+ | jobstart=$(date +%s) | ||
+ | # | ||
+ | |||
+ | macroarg=${SRCPATH}: | ||
+ | echo ${macroarg} | ||
+ | |||
+ | / | ||
+ | |||
+ | chmod +x ${JOBPATH}/ | ||
+ | |||
+ | qsub ${JOBPATH}/ | ||
+ | |||
+ | # timer | ||
+ | jobend=$(date +%s) | ||
+ | # | ||
+ | echo "Time: $((jobend-jobstart)) secs." | ||
+ | #echo "Time: $((jobendN-jobstartN)) nano-sec." | ||
+ | </ | ||
+ | ==== Sample ImageJ macro for Generating Job Array ==== | ||
+ | The ImageJ macro below is the actual content of the script above (called in line 75). it generates one script for one image/ | ||
< | < | ||
/* ImageJ macro for generating shell scripts to be used by qsub array | /* ImageJ macro for generating shell scripts to be used by qsub array | ||
Line 79: | Line 289: | ||
...better be written as a shell script in future. | ...better be written as a shell script in future. | ||
- | to use this macro, adjust path variables BASEP, IJMACROFILE, | + | to use this macro, adjust path variable |
you might probably need to change the name of imageJ jar file of var_ijjar | you might probably need to change the name of imageJ jar file of var_ijjar | ||
| | ||
| | ||
- | | + | arg[1]: path to the output folder for processed images |
- | arg[2]: prefix of job shell scrips. should be longer than 2 chars | + | arg[2]: path to the folder where scripts will be saved |
+ | arg[3]: prefix of job shell scrips. should be longer than 2 chars | ||
+ | arg[4]: path to ij jars | ||
+ | arg[5]: path to IJ macro | ||
+ | arg[6]: IJ macro name | ||
| | ||
Line 92: | Line 306: | ||
/* path where batch file (IJ macro) is placed,*/ | /* path where batch file (IJ macro) is placed,*/ | ||
- | var BASEP = " | + | var BASEP = " |
/* file name of IJ macro*/ | /* file name of IJ macro*/ | ||
Line 98: | Line 312: | ||
/* path to folder where ij.jar and plugins folder is*/ | /* path to folder where ij.jar and plugins folder is*/ | ||
- | var IJP = " | + | var IJP = " |
/* path to SUN java*/ | /* path to SUN java*/ | ||
var SUN_JAVA = " | var SUN_JAVA = " | ||
- | var var_headless | + | var var_headless; |
- | var var_ijjar | + | var var_ijjar; |
- | var var_ijpath | + | var var_ijpath; |
- | var var_batchfile | + | var var_batchfile; |
- | var var_batcharg | + | var var_batcharg; |
- | + | var vars; | |
- | var vars = var_headless | + | |
- | + var_ijjar | + | |
- | + var_ijpath | + | |
- | + var_batchfile | + | |
- | + var_batcharg; | + | |
var jobfilePrefix = " | var jobfilePrefix = " | ||
arg = getArgument(); | arg = getArgument(); | ||
+ | print(arg); | ||
argA = split(arg, ":" | argA = split(arg, ":" | ||
+ | //for (i=0; i< | ||
+ | if (argA.length != 7){ | ||
+ | print(" | ||
+ | print(" | ||
+ | exit(); | ||
+ | } | ||
srcdir = argA[0]; | srcdir = argA[0]; | ||
- | destdir | + | outdir |
- | argjobprefix | + | destdir |
+ | argjobprefix = argA[3]; | ||
if (lengthOf(argjobprefix)> | if (lengthOf(argjobprefix)> | ||
jobfilePrefix = argjobprefix; | jobfilePrefix = argjobprefix; | ||
} | } | ||
+ | IJP = argA[4]; | ||
+ | BASEP = argA[5]; | ||
+ | IJMACROFILE = argA[6]; | ||
+ | |||
+ | print(" | ||
+ | |||
+ | setVariables(); | ||
vars += srcdir + File.separator; | vars += srcdir + File.separator; | ||
+ | |||
print(" | print(" | ||
- | print(" | + | print(" |
+ | print(" | ||
+ | print(" | ||
+ | print(" | ||
+ | print(" | ||
if (!File.isDirectory(srcdir)) { | if (!File.isDirectory(srcdir)) { | ||
print(" | print(" | ||
+ | exit(); | ||
+ | } | ||
+ | if (!File.isDirectory(outdir)) { | ||
+ | print(" | ||
exit(); | exit(); | ||
} | } | ||
Line 136: | Line 370: | ||
File.makeDirectory(destdir); | File.makeDirectory(destdir); | ||
} | } | ||
+ | if (!File.isDirectory(IJP)) { | ||
+ | print(" | ||
+ | exit(); | ||
+ | } | ||
+ | if (!File.isDirectory(BASEP)) { | ||
+ | print(" | ||
+ | exit(); | ||
+ | } | ||
+ | if (!File.exists(BASEP + File.separator + IJMACROFILE)) { | ||
+ | print(" | ||
+ | exit(); | ||
+ | } | ||
+ | |||
filesA = getFileList(srcdir); | filesA = getFileList(srcdir); | ||
jobfilename = " | jobfilename = " | ||
Line 152: | Line 399: | ||
File.saveString(jobarraystring, | File.saveString(jobarraystring, | ||
+ | |||
+ | function setVariables(){ | ||
+ | var_headless = " | ||
+ | var_ijjar = " | ||
+ | var_ijpath = " | ||
+ | var_batchfile = " | ||
+ | var_batcharg = " | ||
+ | |||
+ | vars = var_headless | ||
+ | + var_ijjar | ||
+ | + var_ijpath | ||
+ | + var_batchfile | ||
+ | + var_batcharg; | ||
+ | } | ||
+ | |||
function generateJobScript(filename, | function generateJobScript(filename, | ||
Line 169: | Line 431: | ||
} | } | ||
- | </ | ||
- | Create a text file as above and save it to a directory where you could access (in the command below, the file is named JCreate.ijm). Then type the following command. | ||
- | **/ | ||
- | **\\ | ||
- | |||
- | In above case, all the scripts will be generated under | ||
- | |||
- | / | ||
- | |||
- | for all the files in | ||
- | |||
- | / | ||
- | |||
- | after generating files, change the permission to all the script files so that they could be executed. Should be something like | ||
- | < | ||
- | chmod +x job_* | ||
</ | </ | ||
- | ==== Example work flow ==== | ||
- | |||
- | In this example, job scripts generator (written in ImageJ macro) is executed. This generator also generates job array script. Each job script then executes java command on corresponding image/ | ||
- | |||
- | File hierarchy environment is as follows: | ||
- | |||
- | * current directory: / | ||
- | * images are in: / | ||
- | * ij.jar and headless.jar are in / | ||
- | * imageJ macro for generating shell scripts is at: / | ||
- | * imageJ macro for image processing is at: / | ||
- | < | ||
- | % / | ||
- | % chmod +x testdest/ | ||
- | % qsub testdest/ | ||
- | </ | ||
- | * 1st line creates job scripts and a job array script. | ||
- | * 2nd line changed the permission of job scripts | ||
- | * 3rd line throws the job to the cluster | ||
- | |||
- | Above steps could be written in a meta-shell script as follows. Then all you need to do is just execute one line, sh <name of script> | ||
- | |||
- | < | ||
- | #!/bin/sh | ||
- | #script for imageJ cluster calculation | ||
- | |||
- | # path to IJ jar file | ||
- | IJJARS="/ | ||
- | |||
- | # path to images and stacks | ||
- | SRCPATH="/ | ||
- | |||
- | # path to job array generator macro | ||
- | JOBGENPATH="/ | ||
- | |||
- | # name of job array generator | ||
- | JOBGENNAME=" | ||
- | |||
- | # path to save job scripts and job array script | ||
- | JOBPATH="/ | ||
- | |||
- | # base name (prefix) of job script generated for each images/ | ||
- | JOBPREF=" | ||
- | |||
- | echo "IJ full-path ${IJJARS}/ | ||
- | |||
- | #timer | ||
- | jobstart=$(date +%s) | ||
- | # | ||
- | |||
- | / | ||
- | |||
- | chmod +x ${JOBPATH}/ | ||
- | |||
- | qsub ${JOBPATH}/ | ||
- | |||
- | # timer | ||
- | jobend=$(date +%s) | ||
- | # | ||
- | echo "Time: $((jobend-jobstart)) secs." | ||
- | #echo "Time: $((jobendN-jobstartN)) nano-sec." | ||
- | |||
- | |||
- | </ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
Line 309: | Line 484: | ||
===== Acknowledgements ===== | ===== Acknowledgements ===== | ||
- | Thanks to Frank Thommen(SCB) | + | Thanks to Frank Thommen(SCB), Andres Lindau (IT support) and Christian Tischer (ALMF) for their great help and suggestions. |
documents/100922imagej_cluster.txt · Last modified: 2016/05/24 12:46 by 127.0.0.1