#!/bin/bash -Ceuo pipefail
# Install the TiH-HRD package to a local library
mkdir -p R_libs
R CMD INSTALL --library=R_libs hrd_score_altera_bam
export R_LIBS_USER=${PWD}/R_libs
# Identify the path to the HRD-Altera script
SCRIPT_PATH=$(Rscript -e "system.file('exec', 'hrd_altera_bam.R', package = 'HRDscoreAlteraBam')" | cut -f 2 -d ' ' | sed 's/"//g')
# Run the HRD-Altera script
Rscript ${SCRIPT_PATH} \
--sample_id "custom_Sig_18_tumor_normal" \
--output_dir "." \
--bypass_segments "custom_Sig_18_tumor_normal.segments.csv" \
--bypass_ploidy "custom_Sig_18_tumor_normal.purity_ploidy.csv" \
--somatic_vcf_file "custom_Sig_18_tumor_normal.vcf.gz" \
--vendor altera --config_file hrd_score_altera_config.260123.json --cnv_signatures_file cnv_signatures_signatera.251008.tsv --ridge_model_file ridge_models.260126.tsv --facets_lib_path env
cat <<-END_VERSIONS > versions.yml
"NFCORE_SAREK:SAREK:BAM_VARIANT_CALLING_SOMATIC_ALL:TIH_HRD_PLTF":
hrd_calling: $(Rscript -e 'packageVersion("HRDscoreAlteraBam")' 2>/dev/null | cut -f2 -d ' ' | iconv -f utf-8 -t ascii//translit || echo "unknown")
r-base: $(Rscript -e 'cat(as.character(getRversion()))' 2>/dev/null || echo "4.3.3")
END_VERSIONS