Biostar Beta. Not for public use.
bowtie2 piped to samtools created many samtools.tmp.bam files, how to get the single .bam file?
0
Entering edit mode
15 months ago
dongchenchen • 10

Hi,

I am doing a RNA-Seq analysis and want to map my reads back to the assembly I got from Trinity. Below are my commands. I was hoping to get a single output file named low1.bam. Instead I got a lot of tmp files named like below: samtools.40306.3656.tmp.0000.bam, samtools.40306.3656.tmp.0001.bam ...

bowtie2 --local --no-unal -x Trinity.fasta -q -1 low1_S3_L001_R1_001.fastq   -2 low1_S3_L001_R2_001.fastq -p 20 \
  | samtools view -Sb - \
  | samtools sort -o - - > low1.bam

I am using the latest bowtie2 and samtools version.

Thank you!

ADD COMMENTlink
0
Entering edit mode

I have figured out. Thank you.

ADD REPLYlink
0
Entering edit mode

There is nothing wrong with you adding an answer to your own question, but please do add a real answer. How did you solve the problem?

ADD REPLYlink
0
Entering edit mode
14 months ago
h.mon 25k
Brazil

The sorting of bam files is memory intensive, and samtools needs to create a lot of intermediary files (you can decrease the number of intermediary files, and increase sorting speed, by increasing the memory with samtools sort -m 8G). By defaut, samtools sort output to stdout, and you can output to a file with the -o low1.bam - which means you are using the -o option incorrectly. So samtools is creating all the necessary temporary files with a made-up name, usually the temporary file names it would be low1.0000.bam, low1.0001.bam, and so on.

With the latest version of samtools, you can sort directly, the intermediary samtools view is not needed. And without the -h option, the resulting bam file wouldn't contain headers.

bowtie2 --local --no-unal -x Trinity.fasta -q -1 low1_S3_L001_R1_001.fastq   -2 low1_S3_L001_R2_001.fastq -p 20 \
  | samtools sort -o low1.bam -
ADD COMMENTlink

Login before adding your answer.

Similar Posts
Loading Similar Posts
Powered by the version 2.1