Skip to content

Commit 5ac59ad

Browse files
committed
fix: handle empty BedGraph/BED in make_bigwig_for_cleavage_sites
Guard bedGraphToBigWig calls with a non-empty file check to avoid the 'needLargeMem: trying to allocate 0 bytes' crash when a strand has no cleavage-site coverage. Apply the same guard to the bedtools groupby step in case cs.sorted.bed is also empty. Made-with: Cursor
1 parent fcc099a commit 5ac59ad

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

main.nf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,16 @@ process make_bigwig_for_cleavage_sites {
600600
sort -k1,1 -k2,2n minus.bg > minus.sorted.bg
601601
602602
# 6. Convert to BigWig
603-
bedGraphToBigWig plus.sorted.bg ${fasta}.fai ${sample_id}.plus.bigwig
604-
bedGraphToBigWig minus.sorted.bg ${fasta}.fai ${sample_id}.minus.bigwig
603+
[ -s plus.sorted.bg ] && bedGraphToBigWig plus.sorted.bg ${fasta}.fai ${sample_id}.plus.bigwig || touch ${sample_id}.plus.bigwig
604+
[ -s minus.sorted.bg ] && bedGraphToBigWig minus.sorted.bg ${fasta}.fai ${sample_id}.minus.bigwig || touch ${sample_id}.minus.bigwig
605605
606606
# 7. Generate Summary TSV (chr, start, end, strand, count)
607607
# bedtools groupby groups by chrom, start, end, strand and counts the read names
608-
bedtools groupby -i cs.sorted.bed -g 1,2,3,6 -c 4 -o count > ${sample_id}.read_sum.tsv
608+
if [ -s cs.sorted.bed ]; then
609+
bedtools groupby -i cs.sorted.bed -g 1,2,3,6 -c 4 -o count > ${sample_id}.read_sum.tsv
610+
else
611+
touch ${sample_id}.read_sum.tsv
612+
fi
609613
610614
# Clean up intermediate large files
611615
rm cs.bed plus.bg minus.bg plus.sorted.bg minus.sorted.bg

0 commit comments

Comments
 (0)