Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hmftools-chord 2.1.0_beta #51149

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions recipes/hmftools-chord/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

TGT="$PREFIX/share/$PKG_NAME-$PKG_VERSION-$PKG_BUILDNUM"
[ -d "$TGT" ] || mkdir -p $TGT
[ -d "${PREFIX}/bin" ] || mkdir -p "${PREFIX}/bin"

cd "${SRC_DIR}"
mv jar/chord*.jar $TGT/chord.jar
${R} CMD INSTALL --build src/chord/src/main/R/mutSigExtractor
${R} CMD INSTALL --build src/chord/src/main/R/CHORD

cp $RECIPE_DIR/chord.sh $TGT/chord
ln -s $TGT/chord ${PREFIX}/bin/
69 changes: 69 additions & 0 deletions recipes/hmftools-chord/chord.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# hmftools CHORD executable shell script
# https://github.com/hartwigmedical/hmftools/tree/master/chord
set -eu -o pipefail

export LC_ALL=en_US.UTF-8

# Find original directory of bash script, resolving symlinks
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in/246128#246128
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

JAR_DIR=$DIR
ENV_PREFIX="$(dirname $(dirname $DIR))"
# Use Java installed with Anaconda to ensure correct version
java="$ENV_PREFIX/bin/java"

# if JAVA_HOME is set (non-empty), use it. Otherwise keep "java"
if [ -n "${JAVA_HOME:=}" ]; then
if [ -e "$JAVA_HOME/bin/java" ]; then
java="$JAVA_HOME/bin/java"
fi
fi

# extract memory and system property Java arguments from the list of provided arguments
# http://java.dzone.com/articles/better-java-shell-script
default_jvm_mem_opts="-Xms512m -Xmx1g"
jvm_mem_opts=""
jvm_prop_opts=""
pass_args=""
for arg in "$@"; do
case $arg in
'-D'*)
jvm_prop_opts="$jvm_prop_opts $arg"
;;
'-XX'*)
jvm_prop_opts="$jvm_prop_opts $arg"
;;
'-Xm'*)
jvm_mem_opts="$jvm_mem_opts $arg"
;;
*)
if [[ ${pass_args} == '' ]] #needed to avoid preceeding space on first arg e.g. ' MarkDuplicates'
then
pass_args="$arg"
else
pass_args="$pass_args \"$arg\"" #quotes later arguments to avoid problem with ()s in MarkDuplicates regex arg
fi
;;
esac
done

if [ "$jvm_mem_opts" == "" ]; then
jvm_mem_opts="$default_jvm_mem_opts"
fi

pass_arr=($pass_args)
if [[ ${pass_arr[0]:=} == com.hartwig.* ]]
then
eval "$java" $jvm_mem_opts $jvm_prop_opts -cp "$JAR_DIR/chord.jar" $pass_args
else
eval "$java" $jvm_mem_opts $jvm_prop_opts -jar "$JAR_DIR/chord.jar" $pass_args
fi
Comment on lines +62 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve command execution for better security and robustness

While the logic for determining how to execute the Java command is sound, there are some security and robustness concerns in this section.

  1. The use of eval can be dangerous if the inputs are not properly sanitized. Consider removing eval and using arrays for argument handling.

  2. The word splitting warning on line 62 should be addressed.

Here's a suggested refactor to address these issues:

-pass_arr=($pass_args)
-if [[ ${pass_arr[0]:=} == com.hartwig.* ]]
+if [[ ${pass_args[0]:=} == com.hartwig.* ]]
 then
-    eval "$java" $jvm_mem_opts $jvm_prop_opts -cp "$JAR_DIR/chord.jar" $pass_args
+    "$java" $jvm_mem_opts $jvm_prop_opts -cp "$JAR_DIR/chord.jar" "${pass_args[@]}"
 else
-    eval "$java" $jvm_mem_opts $jvm_prop_opts -jar "$JAR_DIR/chord.jar" $pass_args
+    "$java" $jvm_mem_opts $jvm_prop_opts -jar "$JAR_DIR/chord.jar" "${pass_args[@]}"
 fi

This refactored version:

  1. Removes the use of eval, improving security.
  2. Uses the array directly, avoiding word splitting issues.
  3. Properly expands the pass_args array using "${pass_args[@]}".

These changes make the script more secure and robust against potential injection attacks or unexpected behavior with special characters in arguments.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pass_arr=($pass_args)
if [[ ${pass_arr[0]:=} == com.hartwig.* ]]
then
eval "$java" $jvm_mem_opts $jvm_prop_opts -cp "$JAR_DIR/chord.jar" $pass_args
else
eval "$java" $jvm_mem_opts $jvm_prop_opts -jar "$JAR_DIR/chord.jar" $pass_args
fi
if [[ ${pass_args[0]:=} == com.hartwig.* ]]
then
"$java" $jvm_mem_opts $jvm_prop_opts -cp "$JAR_DIR/chord.jar" "${pass_args[@]}"
else
"$java" $jvm_mem_opts $jvm_prop_opts -jar "$JAR_DIR/chord.jar" "${pass_args[@]}"
fi
🧰 Tools
🪛 Shellcheck

[warning] 62-62: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)

exit
50 changes: 50 additions & 0 deletions recipes/hmftools-chord/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% set version = "2.1.0_beta" %}
{% set sha256_jar = "26d0a40e20635c4b797d28e0c7819b1653c9f8fa28180b9a556215d22387968c" %}
{% set sha256_src = "ed039e7b405130a1e52df71c3535c6a5ed8aab0f80724bc83df88ae14aeaa257" %}

package:
name: hmftools-chord
version: '{{ version }}'

source:
- folder: jar
url: https://github.com/hartwigmedical/hmftools/releases/download/chord-v{{ version }}/chord-{{ version }}.jar
sha256: '{{ sha256_jar }}'
- folder: src
url: https://github.com/hartwigmedical/hmftools/archive/refs/tags/chord-v{{ version }}.tar.gz
sha256: '{{ sha256_src }}'

build:
noarch: generic
number: 0
run_exports:
- {{ pin_subpackage("hmftools-chord", max_pin="x.x") }}

requirements:
host:
- r-base
- r-randomforest
- r-stringr
- bioconductor-bsgenome
- bioconductor-bsgenome.hsapiens.ucsc.hg19
- bioconductor-bsgenome.hsapiens.ucsc.hg38
run:
- openjdk >=8
- r-base
- r-randomforest
- r-stringr
- bioconductor-bsgenome
- bioconductor-bsgenome.hsapiens.ucsc.hg19
- bioconductor-bsgenome.hsapiens.ucsc.hg38

test:
commands:
- $R -e "library('CHORD')"
- $R -e "library('mutSigExtractor')"
- 'chord com.hartwig.hmftools.chord.ChordRunner -version | grep CHORD'

about:
home: https://github.com/hartwigmedical/hmftools/blob/master/chord/
license: GPL-3.0-only
scwatts marked this conversation as resolved.
Show resolved Hide resolved
license_family: GPL3
summary: Predict HRD using somatic mutations contexts