#!/bin/bash -Ceuo pipefail
# Use local filesystem for manta's run directory to avoid filesystem
# consistency issues with pyflow on shared/network storage. See: https://github.com/Illumina/manta/issues/5
MANTA_RUN_DIR="/var/tmp/manta"
mkdir -p ${MANTA_RUN_DIR}
# Stage reference to local filesystem to avoid concurrent read failures from parallel workers on shared/network storage.
REF_DIR="/var/tmp/ref"
mkdir -p ${REF_DIR}
cp Homo_sapiens_assembly38.fasta Homo_sapiens_assembly38.fasta.fai ${REF_DIR}/
REF="${REF_DIR}/$(basename Homo_sapiens_assembly38.fasta)"
configManta.py \
--tumorBam HCC1395_tumor.recalibrated.bam \
--normalBam HCC1395_BL.recalibrated.bam \
--reference ${REF} \
\
--runDir ${MANTA_RUN_DIR} \
--callRegions xgen-exome-hyb-panel-v2-targets-hg38_AND_altera_v3_targets_postQC_hg38_chr21.bed.gz \
--exome
python ${MANTA_RUN_DIR}/runWorkflow.py -m local -j 14
mv ${MANTA_RUN_DIR}/results/variants/candidateSmallIndels.vcf.gz \
HCC1395_tumor_vs_HCC1395_BL.manta.candidate_small_indels.vcf.gz
mv ${MANTA_RUN_DIR}/results/variants/candidateSmallIndels.vcf.gz.tbi \
HCC1395_tumor_vs_HCC1395_BL.manta.candidate_small_indels.vcf.gz.tbi
mv ${MANTA_RUN_DIR}/results/variants/candidateSV.vcf.gz \
HCC1395_tumor_vs_HCC1395_BL.manta.candidate_sv.vcf.gz
mv ${MANTA_RUN_DIR}/results/variants/candidateSV.vcf.gz.tbi \
HCC1395_tumor_vs_HCC1395_BL.manta.candidate_sv.vcf.gz.tbi
mv ${MANTA_RUN_DIR}/results/variants/diploidSV.vcf.gz \
HCC1395_tumor_vs_HCC1395_BL.manta.diploid_sv.vcf.gz
mv ${MANTA_RUN_DIR}/results/variants/diploidSV.vcf.gz.tbi \
HCC1395_tumor_vs_HCC1395_BL.manta.diploid_sv.vcf.gz.tbi
mv ${MANTA_RUN_DIR}/results/variants/somaticSV.vcf.gz \
HCC1395_tumor_vs_HCC1395_BL.manta.somatic_sv.vcf.gz
mv ${MANTA_RUN_DIR}/results/variants/somaticSV.vcf.gz.tbi \
HCC1395_tumor_vs_HCC1395_BL.manta.somatic_sv.vcf.gz.tbi
cat <<-END_VERSIONS > versions.yml
"NFCORE_SAREK:SAREK:BAM_VARIANT_CALLING_SOMATIC_ALL:BAM_VARIANT_CALLING_SOMATIC_MANTA:MANTA_SOMATIC":
manta: $( configManta.py --version )
END_VERSIONS