This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Samtools sort error with a bam file

I have raw data fastq.gz files for some samples. Using Hisat2 for aligning reads to genome and used samtools converted sam to bam format. Also used samtools sort for sorting the bam file. For all the samples I used following command:

hisat2 -p 8 --dta --rna-strandness RF --trim3 3 -x genome_snp_tran -1 /A.1.fastq.gz -2 /A.2.fastq.gz | samtools view -Sb - > A.bam
samtools sort -T /tmp/A.sorted -o A.sorted.bam A.bam  



A.1.fastq.gz 8.9G
A.2.fastq.gz 9.7G

For most of the samples this worked. For one sample I got an error at sorting step. I got the A.bam file (40G) but got an error for sorting.

[E::bgzf_flush] hwrite error (wrong size)
[E::bgzf_close] file write error
[bam_sort_core] failed to create temporary file "/tmp/A.sorted.0468.bam": No space left on device

What I have to do now?

rna-seq samtools sort bam

1 answer

The error you see is quite obvious: there is no disk space left on the device for the intermediate files written while sorting.

Note that you can shorten your command considerably and avoid an intermediate file by piping hisat2 directly into samtools sort:

hisat2 -p 8 --dta --rna-strandness RF --trim3 3 -x genome_snp_tran -1 /A.1.fastq.gz -2 /A.2.fastq.gz | samtools sort -o A.bam -

This probably requires a recent samtools version.

What I should do now for sorting step?

You'll additionally want to set a temporary directory with the -T option, like -T /some/place/with/space/FileName.

Bioinfo : Add this option to the command @Wouter provided above.

As you can see I added the sorting step to the end of the hisat command.

Thank you very much for the answers !!

Log in to answer this question.