PDA

View Full Version : possible to bwa -> sam -> bam via pipe?


Kotoro
07-18-2011, 02:57 PM
Is it possible to output bwa output directly into samtools view to convert into bam format without using intermediate files? I am running low on hard disk space and I am attempting to automate my script. I would like to convert my bwa output to bam, sort it, and index it. I know the sam-bam conversion can be piped into the sort command, but is it possible for the samtools view to take its input from STDIN?

Kotoro
07-18-2011, 03:21 PM
figured out on linux at least, if I give it the filename /dev/stdin that will satisfy it since the OS does the work, even though samtools does not appear to be expressly programmed to switch to stdin.

It appears to be working too, which is going to save me some headaches.

--edit

apparently I could also have done this with named pipes

dawe
07-19-2011, 01:20 AM
Is it possible to output bwa output directly into samtools view to convert into bam format without using intermediate files? I am running low on hard disk space and I am attempting to automate my script. I would like to convert my bwa output to bam, sort it, and index it. I know the sam-bam conversion can be piped into the sort command, but is it possible for the samtools view to take its input from STDIN?

bwa + samtools have been developed with pipes in mind:

$ bwa aln [OPTIONS] [DB] [FASTQ] | bwa samse [OPTIONS] [DB] - [FASTQ] | samtools view -Su - | samtools sort - [PREFIX]

HTH

d

gavin.oliver
07-19-2011, 02:22 AM
bwa + samtools have been developed with pipes in mind:

$ bwa aln [OPTIONS] [DB] [FASTQ] | bwa samse [OPTIONS] [DB] - [FASTQ] | samtools view -Su - | samtools sort - [PREFIX]

HTH

d

Is the same thing somehow possible for PE reads?

dawe
07-19-2011, 02:25 AM
Is the same thing somehow possible for PE reads?

Almost, this should work (essentially it is a double process substitution).

$ bwa sampe [OPTIONS] [DB] <(bwa aln [OPTIONS] [DB] [FASTQ1]) <(bwa aln [OPTIONS] [DB] [FASTQ2]) [FASTQ1] [FASTQ2] | samtools view -Su - | samtools sort - [PREFIX]

gavin.oliver
07-19-2011, 02:34 AM
Thanks!

The wonders of the command line, eh? :)