From 16ddd5380918744dfbf065b27e19c59d9e74bba6 Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Wed, 25 Sep 2024 09:18:26 -0400 Subject: [PATCH] Bigstitcher spark (#1) * changes to get bigstitcher spark working * specify mem and threads from cli wrapper --- Dockerfile | 8 +++- spark_custom_install | 100 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100755 spark_custom_install diff --git a/Dockerfile b/Dockerfile index 55613b9..07dab5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto #install maven hdf5-tools deps, 7zip (for zarr zipstore archiving) -RUN apt-get update && apt-get install -y maven hdf5-tools libblosc-dev p7zip-full && mkdir -p /opt/bin +RUN apt-get update && apt-get install -y maven hdf5-tools libblosc-dev p7zip-full libxtst-dev && mkdir -p /opt/bin ENV PATH $PATH:/opt/bin @@ -44,7 +44,11 @@ ENV PATH $PATH:/opt/bin RUN cd /opt && git clone https://github.com/saalfeldlab/n5-utils && cd n5-utils && ./install /opt/bin #install bigstitcher-spark, and customize launcher to include args for mem and cpu -RUN cd /opt && git clone https://github.com/akhanf/BigStitcher-Spark.git && cd BigStitcher-Spark && ./install -t 32 -m 128 && cp -v affine-fusion /opt/bin && cp -v target/BigStitcher-Spark-0.0.2-SNAPSHOT.jar /opt/bin +RUN cd /opt && git clone https://github.com/akhanf/BigStitcher-Spark.git +COPY spark_custom_install /opt/BigStitcher-Spark/install +RUN cd /opt/BigStitcher-Spark && ./install -t 32 -m 128 + +ENV PATH $PATH:/opt/BigStitcher-Spark # Install Fiji. RUN mkdir /opt/fiji \ diff --git a/spark_custom_install b/spark_custom_install new file mode 100755 index 0000000..24ec763 --- /dev/null +++ b/spark_custom_install @@ -0,0 +1,100 @@ +#!/bin/bash + +# This script is shamelessly extended from https://github.com/saalfeldlab/n5-utils, thanks @axtimwalde & co! + +USERTHREADS="-1" +USERMEM="-1" + +while [[ $# -gt 0 ]]; do + case $1 in + -t|--threads) + USERTHREADS="$2" + shift # past argument + shift # past value + ;; + -m|--mem) + USERMEM="$2" + shift # past argument + shift # past value + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + esac +done + +if [ $USERTHREADS == "-1" ]; then + echo "You did not define the number of threads for Java/Spark can use, will be set automatically. You could do it by e.g.: './install -t 8' for 8 threads." +fi + + +VERSION="0.0.2-SNAPSHOT" +INSTALL_DIR=$(pwd) +#INSTALL_DIR=${1:-$(pwd)} + +echo "" +echo "Installing into $INSTALL_DIR (for local execution)" + +echo 'Building the code' + +sleep 2 + +#mvn clean install +#echo 'Building a fatjar, which can also be used for cluster/cloud execution' +mvn clean install -P fatjar -Dmaven.repo.local=/opt/BigStitcher-Spark/repo +mvn -Dmdep.outputFile=cp.txt -Dmdep.includeScope=runtime dependency:build-classpath -Dmaven.repo.local=/opt/BigStitcher-Spark/repo + + +# function that installs one command +# $1 - command name +# $2 - java class containing the functionality +install_command () { + echo "Installing '$1' command into" $INSTALL_DIR + + echo '#!/bin/bash' > $1 + echo '' >> $1 + echo 'if [ "$#" -lt 2 ]; then echo "Usage: $0 "; exit 1; fi' >> $1 + echo 'MEM=$1' >> $1 + echo 'THREADS=$2' >> $1 + echo 'shift 2' >> $1 + echo "JAR=/opt/BigStitcher-Spark/repo/net/preibisch/BigStitcher-Spark/${VERSION}/BigStitcher-Spark-${VERSION}.jar" >> $1 + echo 'java \' >> $1 + echo ' -Xmx${MEM}g -Dspark.master=local[${THREADS}] \' >> $1 + echo -n ' -cp $JAR:' >> $1 + echo -n $(cat cp.txt) >> $1 + echo ' \' >> $1 + echo ' '$2' "$@"' >> $1 + + chmod a+x $1 +} + +echo 'Installing workflow tools ...' + +install_command resave "net.preibisch.bigstitcher.spark.SparkResaveN5" +install_command detect-interestpoints "net.preibisch.bigstitcher.spark.SparkInterestPointDetection" +install_command match-interestpoints "net.preibisch.bigstitcher.spark.SparkGeometricDescriptorMatching" +install_command stitching "net.preibisch.bigstitcher.spark.SparkPairwiseStitching" +install_command solver "net.preibisch.bigstitcher.spark.Solver" +install_command affine-fusion "net.preibisch.bigstitcher.spark.SparkAffineFusion" +install_command nonrigid-fusion "net.preibisch.bigstitcher.spark.SparkNonRigidFusion" + +echo 'Installing utils ...' + +install_command downsample "net.preibisch.bigstitcher.spark.SparkDownsample" +install_command clear-interestpoints "net.preibisch.bigstitcher.spark.ClearInterestPoints" +install_command clear-registrations "net.preibisch.bigstitcher.spark.ClearRegistrations" +install_command transform-points "net.preibisch.bigstitcher.spark.TransformPoints" + + +if [ $(pwd) == "$INSTALL_DIR" ]; then + echo "Installation directory equals current directory, we are done." +else + echo "Creating directory $INSTALL_DIR and moving files..." + mkdir -p $INSTALL_DIR + mv affine-fusion $INSTALL_DIR/ +fi + +rm cp.txt + +echo "Installation finished."