@@ -2,10 +2,8 @@ rule arriba_extra:
22 """
33 Created:
44 2024-03-29 20:01:56
5- Note:
6- The run_arriba.sh script is available here:
7- https://github.com/suhrig/arriba/blob/master/run_arriba.sh
8- and I could improve my snakemake workflow splitting it into the STAR rule, the arriba call and the samtools index.
5+ Modified:
6+ 2025-10-28 - Replaced run_arriba.sh with direct STAR/arriba calls to support --outTmpDir
97 Test:
108 out/arriba/pe_fq_GRCh38viral_ENSEMBL104/agent/trim_-v2/ln/alias/sst/all_samples/fastq/113281_PICCL/fusions.tsv
119 """
@@ -19,7 +17,8 @@ rule arriba_extra:
1917 bam = "out/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}/Aligned.sortedByCoord.out.bam" ,
2018 bai = "out/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}/Aligned.sortedByCoord.out.bam.bai"
2119 params :
22- outdir = "out/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}"
20+ outdir = "out/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}" ,
21+ tmpdir = "/tmp/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}"
2322 wildcard_constraints :
2423 tool = "arriba/pe_fq" ,
2524 arriba_fa_id = "GRCh38viral" ,
@@ -30,34 +29,139 @@ rule arriba_extra:
3029 8
3130 shell :
3231 """
32+ WDIR=`pwd`
3333 ARRIBA_FILES=$CONDA_PREFIX/var/lib/arriba
3434
35- # Using arriba_fa_id we can decide which suffix to use for blacklist, known_fusions and protein_domains:
35+ # Clean tmp dir if previous execution was interrupted
36+ rm -rf {params.tmpdir}
37+ mkdir -p `dirname {params.tmpdir}`
3638
39+ # Using arriba_fa_id we can decide which suffix to use for blacklist, known_fusions and protein_domains:
3740 if [[ {wildcards.arriba_fa_id} == *"GRCh38"* ]] || [[ {wildcards.arriba_fa_id} == *"hg38"* ]]; then
38- STEM="_hg38_GRCh38_v2.4.0 "
41+ BASE="_hg38_GRCh38 "
3942 elif [[ {wildcards.arriba_fa_id} == *"GRCh37"* ]] || [[ {wildcards.arriba_fa_id} == *"hg19"* ]]; then
40- STEM="_hg19_hs37d5_GRCh37_v2.4.0 "
43+ BASE="_hg19_hs37d5_GRCh37 "
4144 else
4245 echo "Invalid arriba_fa_id"
4346 exit 1
4447 fi
48+
49+ # Auto-detect the version from available files in ARRIBA_FILES
50+ BLACKLIST_FILE=$(ls $ARRIBA_FILES/blacklist${{BASE}}_v*.tsv.gz 2>/dev/null | head -n1)
51+ if [[ -z "$BLACKLIST_FILE" ]]; then
52+ echo "Error: No blacklist file found matching pattern: $ARRIBA_FILES/blacklist${{BASE}}_v*.tsv.gz"
53+ exit 1
54+ fi
55+
56+ # Extract the full stem (including version) from the detected file
57+ STEM=$(basename "$BLACKLIST_FILE" .tsv.gz | sed "s/blacklist//")
4558
4659 cd {params.outdir}
4760
48- run_arriba.sh \
49- {WDIR}/out/arriba/download_references_{wildcards.arriba_fa_id}_{wildcards.arriba_gtf_id}/STAR_index_{wildcards.arriba_fa_id}_{wildcards.arriba_gtf_id} \
50- {WDIR}/{input.gtf} \
51- {WDIR}/{input.fa} \
52- $ARRIBA_FILES/blacklist$STEM.tsv.gz \
53- $ARRIBA_FILES/known_fusions$STEM.tsv.gz \
54- $ARRIBA_FILES/protein_domains$STEM.gff3 \
55- {threads} \
56- {WDIR}/{input.fq1} \
57- {WDIR}/{input.fq2}
58-
61+ # Run STAR with arriba settings and output to tmpdir for FIFO operations
62+ STAR \
63+ --runThreadN {threads} \
64+ --genomeDir $WDIR/out/arriba/download_references_{wildcards.arriba_fa_id}_{wildcards.arriba_gtf_id}/STAR_index_{wildcards.arriba_fa_id}_{wildcards.arriba_gtf_id} \
65+ --genomeLoad NoSharedMemory \
66+ --readFilesIn $WDIR/{input.fq1} $WDIR/{input.fq2} \
67+ --readFilesCommand zcat \
68+ --outStd BAM_Unsorted \
69+ --outSAMtype BAM Unsorted \
70+ --outSAMunmapped Within \
71+ --outBAMcompression 0 \
72+ --outTmpDir {params.tmpdir} \
73+ --outFilterMultimapNmax 50 \
74+ --peOverlapNbasesMin 10 \
75+ --alignSplicedMateMapLminOverLmate 0.5 \
76+ --alignSJstitchMismatchNmax 5 -1 5 5 \
77+ --chimSegmentMin 10 \
78+ --chimOutType WithinBAM HardClip \
79+ --chimJunctionOverhangMin 10 \
80+ --chimScoreDropMax 30 \
81+ --chimScoreJunctionNonGTAG 0 \
82+ --chimScoreSeparation 1 \
83+ --chimSegmentReadGapMax 3 \
84+ --chimMultimapNmax 50 | \
85+ tee Aligned.out.bam | \
86+ arriba \
87+ -x /dev/stdin \
88+ -o fusions.tsv \
89+ -O fusions.discarded.tsv \
90+ -a $WDIR/{input.fa} \
91+ -g $WDIR/{input.gtf} \
92+ -b $ARRIBA_FILES/blacklist$STEM.tsv.gz \
93+ -k $ARRIBA_FILES/known_fusions$STEM.tsv.gz \
94+ -t $ARRIBA_FILES/known_fusions$STEM.tsv.gz \
95+ -p $ARRIBA_FILES/protein_domains$STEM.gff3
96+
97+ # Sort and index BAM
98+ samtools sort -@ {threads} -m $((40000/{threads}))M -T tmp -O bam Aligned.out.bam > Aligned.sortedByCoord.out.bam
99+ rm -f Aligned.out.bam
100+ samtools index Aligned.sortedByCoord.out.bam
59101 """
60102
103+ # Commenting original rule for reference.
104+ # I had to replicate run_arriba.sh content here to be able to use --outTmpDir in STAR call to avoid FIFO issue
105+ # rule arriba_extra:
106+ # """
107+ # Created:
108+ # 2024-03-29 20:01:56
109+ # Note:
110+ # The run_arriba.sh script is available here:
111+ # https://github.com/suhrig/arriba/blob/master/run_arriba.sh
112+ # and I could improve my snakemake workflow splitting it into the STAR rule, the arriba call and the samtools index.
113+ # Test:
114+ # out/arriba/pe_fq_GRCh38viral_ENSEMBL104/agent/trim_-v2/ln/alias/sst/all_samples/fastq/113281_PICCL/fusions.tsv
115+ # """
116+ # input:
117+ # fq1 = "out/{filler}_1.fastq.gz",
118+ # fq2 = "out/{filler}_2.fastq.gz",
119+ # gtf = "out/arriba/download_references_{arriba_fa_id}_{arriba_gtf_id}/{arriba_gtf_id}.gtf",
120+ # fa = "out/arriba/download_references_{arriba_fa_id}_{arriba_gtf_id}/{arriba_fa_id}.fa"
121+ # output:
122+ # tsv = "out/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}/fusions.tsv",
123+ # bam = "out/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}/Aligned.sortedByCoord.out.bam",
124+ # bai = "out/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}/Aligned.sortedByCoord.out.bam.bai"
125+ # params:
126+ # outdir = "out/{tool}_{arriba_fa_id}_{arriba_gtf_id}/{filler}"
127+ # wildcard_constraints:
128+ # tool="arriba/pe_fq",
129+ # arriba_fa_id = "GRCh38viral",
130+ # arriba_gtf_id = "ENSEMBL104"
131+ # conda:
132+ # "../envs/arriba.yaml"
133+ # threads:
134+ # 8
135+ # shell:
136+ # """
137+ # ARRIBA_FILES=$CONDA_PREFIX/var/lib/arriba
138+
139+ # # Using arriba_fa_id we can decide which suffix to use for blacklist, known_fusions and protein_domains:
140+
141+ # if [[ {wildcards.arriba_fa_id} == *"GRCh38"* ]] || [[ {wildcards.arriba_fa_id} == *"hg38"* ]]; then
142+ # STEM="_hg38_GRCh38_v2.5.0"
143+ # elif [[ {wildcards.arriba_fa_id} == *"GRCh37"* ]] || [[ {wildcards.arriba_fa_id} == *"hg19"* ]]; then
144+ # STEM="_hg19_hs37d5_GRCh37_v2.5.0"
145+ # else
146+ # echo "Invalid arriba_fa_id"
147+ # exit 1
148+ # fi
149+
150+ # cd {params.outdir}
151+
152+ # run_arriba.sh \
153+ # {WDIR}/out/arriba/download_references_{wildcards.arriba_fa_id}_{wildcards.arriba_gtf_id}/STAR_index_{wildcards.arriba_fa_id}_{wildcards.arriba_gtf_id} \
154+ # {WDIR}/{input.gtf} \
155+ # {WDIR}/{input.fa} \
156+ # $ARRIBA_FILES/blacklist$STEM.tsv.gz \
157+ # $ARRIBA_FILES/known_fusions$STEM.tsv.gz \
158+ # $ARRIBA_FILES/protein_domains$STEM.gff3 \
159+ # {threads} \
160+ # {WDIR}/{input.fq1} \
161+ # {WDIR}/{input.fq2}
162+
163+ # """
164+
61165rule arriba_draw_fusions :
62166 """
63167 Created:
@@ -91,9 +195,9 @@ rule arriba_draw_fusions:
91195 # Using arriba_fa_id we can decide which suffix to use for cytobands and protein_domains:
92196
93197 if [[ {wildcards.arriba_fa_id} == *"GRCh38"* ]] || [[ {wildcards.arriba_fa_id} == *"hg38"* ]]; then
94- STEM="_hg38_GRCh38_v2.4 .0"
198+ STEM="_hg38_GRCh38_v2.5 .0"
95199 elif [[ {wildcards.arriba_fa_id} == *"GRCh37"* ]] || [[ {wildcards.arriba_fa_id} == *"hg19"* ]]; then
96- STEM="_hg19_hs37d5_GRCh37_v2.4 .0"
200+ STEM="_hg19_hs37d5_GRCh37_v2.5 .0"
97201 else
98202 echo "Invalid arriba_fa_id"
99203 exit 1
0 commit comments