Question: Aligning, Sorting and Converting to bam at the same command - possible?
gravatar for Samuel
5 days ago by
Samuel0 wrote:

Is it possible to align, sort and convert to bam using a pipeline?


bowtie .... | samtools sort | samtools view -bS -o sorted_output.bam

In case that is possible, is this solution very inefficient in terms of demands on the pc?

bam sorting alignment • 89 views
ADD COMMENTlink modified 5 days ago by swbarnes27.2k • written 5 days ago by Samuel0

not too familiar with bowtie but yes if it produces sam with a header or bam. No need to do a samtools view after, samtools sort handles bam files. Why would it be inefficient? having to wait for the entire file to sort chunks, increasing your storage 2X is more efficient?

ADD REPLYlink written 5 days ago by Gabriel R.2.6k
gravatar for swbarnes2
5 days ago by
United States
swbarnes27.2k wrote:

Most people pipe everything through like that. You probably don't need the view command, I'm pretty sure newer versions of samtools sort will take .sam as input and always output .bam

ADD COMMENTlink written 5 days ago by swbarnes27.2k

Samtools outputs whatever you specify, either via suffixlike .sam or .bam or via the -O parameter (SAM/BAM), so yes the view is not necessary. It is a good approaches to use piles and it saves time by avoiding intermediate files which have to be written to disk. The larger your memory, the more efficient it is. samtools sort has an option -m to specify how many RAM to use for sorting before spilling data to disk as intermediate file once allocated memory is full. You pipes can be arbitrarily long in theory, I have commands in some specialized pipelines that go through 10 tools without producing a single intermediate file.

ADD REPLYlink modified 5 days ago • written 5 days ago by ATpoint28k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1130 users visited in the last hour