#!/bin/bash -euo pipefail
python -u /usr/local/src/CTAT-SPLICING/STAR_to_cancer_introns.py \
--SJ_tab_file HD789_0002_RNA_0008_23H5VFLT4_s19.SJ.out.tab \
--chimJ_file HD789_0002_RNA_0008_23H5VFLT4_s19.Chimeric.out.junction \
--bam_file HD789_0002_RNA_0008_23H5VFLT4_s19.Aligned.sortedByCoord.out.bam \
--output_prefix HD789_0002_RNA_0008_23H5VFLT4_s19 \
--ctat_genome_lib ctat_genome_lib_build_dir \
--vis --sample_name HD789_0002_RNA_0008_23H5VFLT4_s19
# Sort output files to ensure consistent ordering across runs while preserving headers
if [ -f HD789_0002_RNA_0008_23H5VFLT4_s19.cancer.introns ]; then
# Extract header (first line) and sort data lines by fourth column (uniq_mapped) descending, then by first column (intron)
head -n 1 HD789_0002_RNA_0008_23H5VFLT4_s19.cancer.introns > HD789_0002_RNA_0008_23H5VFLT4_s19.cancer.introns.tmp
tail -n +2 HD789_0002_RNA_0008_23H5VFLT4_s19.cancer.introns | LC_ALL=C sort -k4,4nr -k1,1 >> HD789_0002_RNA_0008_23H5VFLT4_s19.cancer.introns.tmp
mv HD789_0002_RNA_0008_23H5VFLT4_s19.cancer.introns.tmp HD789_0002_RNA_0008_23H5VFLT4_s19.cancer.introns
fi
cat <<-END_VERSIONS > versions.yml
"NFCORE_RNAFUSION:RNAFUSION:CTATSPLICING_STARTOCANCERINTRONS":
ctat-splicing: 0.0.3
END_VERSIONS