This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bwa-mem: [bam_sort_core] merging from 0 files and 3 in-memory blocks

Hello,

I'm running bwa mem on paired-end single digested RAD-seq data. I'm using the following command:

bwa mem -t $threads -M $genome $input1 $input2 | samtools view -b -@ $threads | samtools sort -@ $threads -m 7G > ${output}.bam

with threads=3 and input 1 and 2, corresponding to the single-end and paired-end reads, respectively.

In the .log files I get at the end this message:

main] Real time: 178.000 sec; CPU: 359.533 sec
[bam_sort_core] merging from 0 files and 3 in-memory blocks...

It is to be considered an error? What does it mean exactly? could be that I have some problem with memory and I have to increase it?

bwa

input 1 and 2, corresponding to the single-end and paired-end reads

If input1 are the single-end reads, and input2 are the paired-end reads in an interleaved file, BWA will incorrectly interpret the pairing and produce wrong results. If you want to mix single- and paired-end reads in the same run, you have to append the single-end reads at the end of the forward (or R1) file from the paired-end reads.

Do you mean that I should do something like that ?

cat $input1 > sampleA.fq.gz
cat $input2 >> sampleA.fq.gz

bwa mem -t $threads -M $genome sampleA.fq.gz

No. However, my initial suggestion is wrong, I think I may have mixed bbmap (or some other program) and bwa methods for handling a mix of paired- and single-end reads.

For bwa, you have to interleave the forward and reverse paired-end reads, append the single end to this file, and use the -p flag. Suppose the paired-end reads are in the files R1.fastq and R2.fastq, and the single-end reads are in the file single.fastq, you need to:

reformat.sh in1=R1.fastq in2=R2.fastq out=interleaved.fastq
cat interleaved.fastq single.fastq > concat.fastq
bwa mem -t $threads -p -M $genome concat.fastq > mapping.sam

1 answer

It's not an error, a normal message from samtools sort. For sorting it stores reads either in memory or in temporary files, and that's what you are informed about.

Note that you (with a reasonably recent samtools) can also pipe directly to samtools sort, specifying the output with -o

bwa mem -t $threads -M $genome $input1 $input2 | samtools sort -@ $threads -m 7G -o ${output}.bam

Log in to answer this question.