This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Short Read Aligner - Output To Bam/Sam Only Aligned Reads

I want to align PE Illumina reads (FastQ) onto very short reference (mitochondrial). I'm not interested in reads that didn't align...

Do you know any short read aligner that can output BAM file? Or how to limit SAM output to aligned sequences only?

aligner short bam

Often it is counterproductive to filter the output right away. You may need the information on unaligned/unpaired reads at some point. Usually it is better to first generate the full SAM file, then filter it as the answers below show it.

1 answer

Please refer to this question

Any aligner will probably send alignments to stdout, so you can do something like

aligner input.fastq ... | samtools view -SF 0x04 -b - > only.aligned.bam

(And use -f 0x02 to require properly paired reads).

Where the -F flag removes unaligned reads. See the manual.

Just a minor tweak: you'll need the -S flag for samtools to indicate that it is accepting SAM (not BAM) as input.

Right you are. Thanks.

does samtools view read from stdin? In my case it didn't.

@Leszek, I updated the example command if you use - as the filename, samtools view will read from stdin.

Log in to answer this question.