From 4d8eb2a96a42c4df0c0331ae96ef17fcf4f86c29 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Thu, 2 Aug 2018 13:09:30 +0100 Subject: [PATCH] Unified mass-extraacting and mass-converting `mass-jxr-convert.sh` has been created, allowing the conversion of an entire directory of `.jxr` files. Additionally, use of `mass-jxr-convert.sh` has been integrated into `mass-czinspect.sh` (which was formerly known as `batch.sh`). --- bin/batch.sh | 63 -------------------- bin/mass-czinspect.sh | 126 ++++++++++++++++++++++++++++++++++++++++ bin/mass-jxr-convert.sh | 114 ++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+), 63 deletions(-) delete mode 100755 bin/batch.sh create mode 100755 bin/mass-czinspect.sh create mode 100755 bin/mass-jxr-convert.sh diff --git a/bin/batch.sh b/bin/batch.sh deleted file mode 100755 index 763d96b..0000000 --- a/bin/batch.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash -x - -set -e - -CZINSPECT="czinspect" - -usage () { - cat< - -This a wrapper script around czinspect, and will pass most options directly to -czinspect. - -czinspect's help text: ---- -$($CZINSPECT $opts -h $*) ---- -EOF -} - -error () { - echo "$@" >&2 - exit 1 -} - -outdir="" -opts="" - -while getopts "EShd:f:gaes:" opt; do - case $opt in - d) - outdir="$OPTARG" - ;; - h) - usage - exit 0 - ;; - E|S|a|e|g) - opts="$opts -$opt" - ;; - s|f) - opts="$opts -$opt $OPTARG" - ;; - esac -done - -shift $((OPTIND - 1)) - -if (( $# == 0 )); then - error "Missing input directory" -fi - -if [[ -z "$outdir" ]]; then - error "Missing output directory" -fi - -INDIR="$1" -indirsafe="$(echo $INDIR | sed 's/[[\.*^$,]/\\&/g')" - -find $INDIR -maxdepth 1 -name '*.czi' \ - | xargs -I'{}' sh -c "out=\"\$(echo '{}' \ - | sed 's,$indirsafe/*\(.*\).czi\$,$outdir/\1,g')\" ; \ - mkdir -p \"\$out\" ; '$CZINSPECT' $opts -d\"\$out\" '{}'" diff --git a/bin/mass-czinspect.sh b/bin/mass-czinspect.sh new file mode 100755 index 0000000..5a7fb6d --- /dev/null +++ b/bin/mass-czinspect.sh @@ -0,0 +1,126 @@ +#!/bin/bash + +set -e + +CZINSPECT="czinspect" +JXRCONVERT="mass-jxr-convert.sh -P1" + +usage () { + cat< + +This a wrapper script around a czi manipulation tool, and will pass most options +directly to said tool. + +mass-czinspect's options: + -d Output directory for output(s) of czinspect. + -P Number of maximum concurrent czinspect processes; passed + directly to xargs if used + -v Verbosity of output (default is 0 - silent) + -x Remove .czi files after extraction (caution!) + -t Specify output image type (default is '.jxr') + -v Verbosity of output (default is 0 - silent) + +czi manipulation tool in use: '$CZINSPECT' +jxr conversion tool in use: '$JXRCONVERT' + +czi extraction tool's help text: +--- +$($CZINSPECT $opts -h $*) +--- + +If -t is specified to be anything other than '.jxr', an image conversion tool is +used, limited to one process to allow the concurrency of many mass-czinspect +jobs. In this case, -v and -x are passed to it. Make sure the conversion tool +can convert to the image type you're specifying! + +jxr conversion tool's help text: +--- +$($JXRCONVERT -h $*) +--- +EOF +} + +error () { + echo "$@" >&2 + exit 1 +} + +outdir="" +opts="" +xargargs="" +destroy="" +suffix=".jxr" +verbosity=0 + +while getopts "xv:P:EShd:f:gaes:t:" opt; do + case $opt in + d) + outdir="$OPTARG" + ;; + h) + usage + exit 0 + ;; + E|S|a|e|g) + opts="$opts -$opt" + ;; + s|f) + opts="$opts -$opt $OPTARG" + ;; + v) + verbosity="$OPTARG" + ;; + P) + xargargs="$xargargs -$opt $OPTARG" + ;; + x) + destroy="1" + ;; + t) + suffix="$OPTARG" + ;; + esac +done + +shift $((OPTIND - 1)) + +if (( $# == 0 )); then + error "Missing input directory" +fi + +if [[ -z "$outdir" ]]; then + error "Missing output directory" +fi + +INDIR="$1" +indirsafe="$(echo $INDIR | sed 's/[[\.*^$,]/\\&/g')" + +EXEC="out=\"\$(echo '{}' | sed 's,$indirsafe/*\(.*\).czi\$,$outdir/\1,g')\"" + +if [[ -n "$verbosity" ]] ; then + EXEC="$EXEC && echo extracting '{}'" +fi + +EXEC="$EXEC && mkdir -p \"\$out\"" +EXEC="$EXEC && '$CZINSPECT' $opts -d\"\$out\" '{}'" + +if [[ -n "$destroy" ]] ; then + EXEC="$EXEC && rm -f '{}'" +fi + +if [[ "$suffix" != ".jxr" ]] ; then + jxrcflags="-v \"$verbosity\" -t \"$suffix\"" + + if [[ -n "$destroy" ]] ; then + jxrcflags="$jxrcflags -x" + fi + + if [[ -n "$verbose" ]] ; then + EXEC="$EXEC && echo converting tiles for '{}'" + fi + + EXEC="$EXEC && $JXRCONVERT $jxrcflags \"\$out\"" +fi + +find $INDIR -maxdepth 1 -name '*.czi' | xargs $xargargs -I'{}' sh -c "$EXEC" diff --git a/bin/mass-jxr-convert.sh b/bin/mass-jxr-convert.sh new file mode 100755 index 0000000..01197f7 --- /dev/null +++ b/bin/mass-jxr-convert.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +set -e + +JXRDECAPP="JxrDecApp" +CONVERT="vips --vips-concurrency=1 copy" + +JXRFMT="-i %s -o %s" + +usage () { + cat < + +mass-jxr-convert's options: + -d Output directory (defaults to input directory) + -x Destructive: remove old images after making new ones + -t Specify output image type (default is '.tif') + -P Number of processes to run simultaneously; + passed to xargs if used + -v Verbosity of output (default is 0 - silent) + -h Print this help message + +jxr conversion tool in use: '$JXRDECAPP' +general image converter in use: '$CONVERT' + +jxr conversion tool's help text: +=== +$($JXRDECAPP -h $*) +=== + +If -t is specified to be anything other than '.tif', a general image conversion +tool is used, limited to one process. MAke sure this converter can convert to +the image type you're specifying! + +general image converter's help text: +=== +$($CONVERT --help) +=== +EOF +} + +error () { + echo "$@" >& 2 + exit 1 +} + +OUTDIR="" +DESTROY="" +SUFFIX=".tif" +XARGSARGS="" +VERBOSITY=0 + +while getopts "d:hxt:P:v:" opt; do + case $opt in + d) + OUTDIR="$OPTARG" + ;; + h) + usage + exit 0 + ;; + x) + DESTROY="1" + ;; + t) + SUFFIX="$OPTARG" + ;; + P) + XARGSARGS="$XARGSARGS -$opt$OPTARG" + ;; + v) + VERBOSITY="$OPTARG" + ;; + esac +done + +shift $((OPTIND - 1)) + +if (( $# == 0 )); then + error "Missing input folder" +fi + +INDIR=$1 +INDIRSAFE="$(echo $INDIR | sed 's/[[\.*^$,]/\\&/g')" + +if [[ -z "$OUTDIR" ]]; then + OUTDIR="$INDIR" +fi + +EXEC="mid=\"\$(echo '{}' | sed 's,$INDIRSAFE/*\(.*\)\.jxr\$,$OUTDIR/\1,g')\"" + +if [[ -n "$VERBOSITY" ]]; then + EXEC="$EXEC && echo \"\$mid\"\"{.jxr->.tif}\"" +fi + +EXEC="$EXEC && $JXRDECAPP \$(printf -- '$JXRFMT' '{}' \"\$mid\"\".tif\")" + +if [[ -n "$DESTROY" ]] ; then + EXEC="$EXEC && rm -f '{}'" +fi + +if [ "$SUFFIX" != ".tif" ] ; then + if [[ -n "$VERBOSITY" ]] ; then + EXEC="$EXEC && echo \"\$mid\"\"{.tif->$SUFFIX}\"" + fi + + EXEC="$EXEC && $CONVERT \"\$mid\".tif \"\$mid\"\"$SUFFIX\"" + + if [[ -n "$DESTROY" ]] ; then + EXEC="$EXEC && rm -f \"\$mid\".tif" + fi +fi + +find $INDIR -maxdepth 1 -name '*.jxr' | xargs $XARGSARGS -I'{}' sh -c "$EXEC"