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

Dataops 907 update hs metrics #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
36 changes: 23 additions & 13 deletions run_hs_metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
#SBATCH -o hs_metrics.%j.out

#
# Run CollectHsMtrics for all recalibrated BAM files in an analysis folder
# Run CollectHsMtrics for all markduplicate BAM/CRAM files in an analysis folder
#

BAITS=$1
TARGETS=$2
ANALYSISDIR=$3
INBAM=$4
INFILE=$4
METRICS=$5

# singularity container used by sarek, provides CollectHsMetrics
CONTAINER=/vulpes/ngi/containers/sarek/nfcore-sarek-2.7.img
# Genome reference needed for CRAM files
REF="/sw/data/uppnex/ToolBox/hg38bundle/Homo_sapiens_assembly38.fasta"

# singularity container for GATK version used by Sarek3.4.2, provides CollectHsMetrics
CONTAINER="/vulpes/ngi/containers/biocontainers/singularity-gatk4-4.5.0.0--py36hdfd78af_0.img"

#
# NOTE: This script is re-used for submitting sbatch jobs, in which case 5 parameters will be used. Users
Expand All @@ -29,29 +32,36 @@ CONTAINER=/vulpes/ngi/containers/sarek/nfcore-sarek-2.7.img
if [[ $# -eq 3 ]]
then

# This is the functionality when the user runs the script with 3 parameters. BAM files will be located
# This is the functionality when the user runs the script with 3 parameters. BAM/CRAM files will be located
# and sbatch jobs for collecting metrics dispatched

find "${ANALYSISDIR}/results/Preprocessing" -path "*/Recalibrated/*.bam" |while read -r BAM
find "${ANALYSISDIR}/results/preprocessing/markduplicates/" -path "*/*.bam" -o -path "*/*.cram" | while read -r ALIGNMENTFILE
do
BAMDIR="$(dirname "${BAM}")"
BAMNAME="$(basename "${BAM}")"
ALIGNMENTDIR="$(dirname "${ALIGNMENTFILE}")"
ALIGNMENTNAME="$(basename "${ALIGNMENTFILE}")"

# construct the path for the metrics file
HSDIR="${BAMDIR/Preprocessing/Reports}"
HSDIR="${HSDIR/Recalibrated/HsMetrics}"
HSFILE="${BAMNAME/.bam/.hs_metrics}"
HSDIR="${ALNDIR/preprocessing/reports}"
HSDIR="${HSDIR/markduplicates/HsMetrics}"
EXTENSION="${ALIGNMENTNAME##*.}"
HSFILE="${ALIGNMENTNAME%.${EXTENSION}}.hs_metrics"

mkdir -p "$HSDIR"
sbatch -J "${HSFILE}" -o "${HSDIR}/${HSFILE}.out" "$0" "$BAITS" "$TARGETS" "$ANALYSISDIR" "$BAM" "${HSDIR}/${HSFILE}"
sbatch -J "${HSFILE}" -o "${HSDIR}/${HSFILE}.out" "$0" "$BAITS" "$TARGETS" "$ANALYSISDIR" "$ALIGNMENTFILE" "${HSDIR}/${HSFILE}"
done

elif [[ $# -eq 5 ]]
then

# This is the functionality when the script is run as a sbatch job and launched with 5 parameters

singularity exec $CONTAINER gatk --java-options -Xmx28g CollectHsMetrics --INPUT=$INBAM --OUTPUT=$METRICS --MAX_RECORDS_IN_RAM=50000000 --BAIT_INTERVALS=$BAITS --TARGET_INTERVALS=$TARGETS
singularity exec $CONTAINER gatk --java-options -Xmx28g CollectHsMetrics \
--INPUT $INFILE \
--OUTPUT $METRICS \
--MAX_RECORDS_IN_RAM 50000000 \
--BAIT_INTERVALS $BAITS \
--TARGET_INTERVALS $TARGETS \
--REFERENCE_SEQUENCE $REF
matrulda marked this conversation as resolved.
Show resolved Hide resolved

else
echo
Expand Down