Biostar Test Site

This is site is used for testing only. Visit: https://www.biostars.org to ask a question.

bowtie2 piped to samtools created many samtools.tmp.bam files, how to get the single .bam file?
1
0
Entering edit mode
2.2 years ago
dongchenchen ▴ 30

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!

alignment sort bowtie2 samtools • 1.6k views
ADD COMMENT
0
Entering edit mode

I have figured out. Thank you.

ADD REPLY
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 REPLY
0
Entering edit mode

Hi, how did you figure it out?

ADD REPLY
0
Entering edit mode
2.2 years ago
h.mon 32k

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 COMMENT

Login before adding your answer.

Traffic: 197 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6