Skip to content
Snippets Groups Projects

Add python scripts to run registration on the cluster

Merged Constantin Pape requested to merge registration-wrapper into master
2 unresolved threads
Files
2
@@ -98,27 +98,51 @@ def apply_for_file(input_path, output_path,
transformation_file, fiji_executable,
elastix_directory, tmp_folder, n_threads):
assert os.path.exists(elastix_directory)
assert os.path.exists(tmp_folder)
assert os.path.exists(input_path)
assert os.path.exists(transformation_file)
assert os.path.exists(os.path.split(output_path)[0])
# transformix arguments need to be passed as one string,
# with individual arguments comma separated
# the argument to transformaix needs to be one large comma separated string
transformix_argument = ["elastixDirectory=\'%s\'" % elastix_directory,
"workingDirectory=\'%s\'" % tmp_folder,
"inputImageFile=\'%s\'" % input_path,
"transformationFile=\'%s\'" % transformation_file,
"outputFile=\'%s\'" % output_path,
"outputModality=\'Save as BigDataViewer .xml/.h5\'",
"numThreads=\'1\'"] # TODO why do we use numThreads=1 and not the same as in -c?
transformix_argument = ",".join(transformix_argument)
transformix_argument = "\"%s\"" % transformix_argument
# command based on https://github.com/embl-cba/fiji-plugin-elastixWrapper/issues/2:
# srun --mem 16000 -n 1 -N 1 -c 8 -t 30:00 -o $OUT -e $ERR
# /g/almf/software/Fiji.app/ImageJ-linux64 --ij2 --headless --run "Transformix"
# "elastixDirectory='/g/almf/software/elastix_v4.8', workingDirectory='$TMPDIR',
# inputImageFile='$INPUT_IMAGE',transformationFile='/g/cba/exchange/platy-trafos/linear/TransformParameters.BSpline10-3Channels.0.txt
# outputFile='$OUTPUT_IMAGE',outputModality='Save as BigDataViewer .xml/.h5',numThreads='1'"
cmd = [fiji_executable, "--ij2", "--headless", "--run", "Transformix",
"elastix_directory=%s" % elastix_directory,
"workingDirectory=%s" % tmp_folder,
"inputImageFile=%s" % input_path,
"transformationFile=%s" % transformation_file,
"outputFile=%s" % output_path,
"outputModality=\'Save as BigDataViewer .xml/.h5\'",
"numThreads=1"] # TODO why do we use numThreads=1 and not the same as -c in the slurm command?
cmd = [fiji_executable, "--ij2", "--headless", "--run", "\"Transformix\"", transformix_argument]
cmd_str = " ".join(cmd)
fu.log("Calling the following command:")
fu.log(cmd_str)
# the elastix wrapper only works properly if we set these as environment variables as well, see
# TODO make issue about this
# os.environ['TMPDIR'] = tmp_folder
os.environ['TRAFO'] = transformation_file
try:
check_output(cmd)
# check_output(cmd)
# the CLI parser is very awkward (to put it nicely).
# I could only get it to work by passing the whole command string
# and setting shell to True.
# otherwise, it would parse something wrong, and do nothing but
# throwing a warning:
# [WARNING] Ignoring invalid argument: --run
check_output([cmd_str], shell=True)
except CalledProcessError as e:
raise RuntimeError(e.output)
Loading