SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics
Similar Threads
Thread Thread Starter Forum Replies Last Post
samtools: "sort by name" and fast random access cycomatto Bioinformatics 7 01-22-2013 03:42 AM
Samtools sort output smaller than input Sylphide Bioinformatics 3 04-15-2011 01:12 PM
@HD SO field after samtools sort telos Bioinformatics 3 11-10-2010 06:12 AM
samtools sort running extremely slow tsucheta Bioinformatics 2 06-11-2010 06:30 AM
sort bioenvisage Bioinformatics 6 02-05-2010 11:03 AM

Reply
 
Thread Tools
Old 04-08-2011, 07:04 AM   #1
pederworning
Junior Member
 
Location: Copenhagen, Denmark

Join Date: Feb 2011
Posts: 5
Default samtools sort stdout

Hello

I am mapping reads from bacterial sequences to reference genomes and I am using bwa and samtools. I am trying to set up a pipeline and want to use stdin and stdout and pipe the data to avoid temporary files. I am using samtools-0.1.13.

Do you know if you can get the output of samtools sort to stdout?

The manual pages says that the -o option means stdout for samtools sort , but it doesn't seem to work on my system.

Here is the command line I have used to make quality filtering and sorting in one line and the error message I get:
>samtools view -b -q 30 5139_6_7.paired_ends.bam | samtools sort -o - > temp
Usage: samtools sort [-on] [-m <maxMem>] <in.bam> <out.prefix>

>samtools view -b -q 30 5139_6_7.paired_ends.bam | samtools sort - - > temp
And this makes as expected an empty temp file and the sorted alignment in "-.bam"

Do you know how I can avoid the *.bam output file?

Thanks
Peder Worning
pederworning is offline   Reply With Quote
Old 04-08-2011, 02:48 PM   #2
daler
Junior Member
 
Location: DC Metro area

Join Date: Feb 2011
Posts: 8
Default

Try providing an output prefix anyway. Even if you specify -o, I think samtools will use that prefix to create temp files if the BAM to be sorted won't fit in memory.

So to modify your example,

Code:
samtools view -b -q 30 in.bam | samtools sort -o - deleteme > out.bam
should result in a new out.bam file; deleteme.* may be created as intermediate files but will be cleaned up after the sort

Last edited by daler; 04-09-2011 at 07:08 AM. Reason: (edit: forgot the -o!)
daler is offline   Reply With Quote
Old 04-09-2011, 03:48 AM   #3
dawe
Senior Member
 
Location: 4530'25.22"N / 915'53.00"E

Join Date: Apr 2009
Posts: 258
Default

Quote:
Originally Posted by pederworning View Post
Do you know how I can avoid the *.bam output file?

Thanks
Peder Worning
AFAIK there's no way to do that. samtools sort doesn't handle stdout.

d
dawe is offline   Reply With Quote
Old 04-09-2011, 03:59 AM   #4
dawe
Senior Member
 
Location: 4530'25.22"N / 915'53.00"E

Join Date: Apr 2009
Posts: 258
Default

Quote:
Originally Posted by pederworning View Post
Do you know how I can avoid the *.bam output file?

Thanks
Peder Worning
AFAIK there's no way to do that. samtools sort doesn't handle stdout.

d
dawe is offline   Reply With Quote
Old 04-09-2011, 08:02 AM   #5
gaffa
Member
 
Location: Gothenburg/Uppsala, Sweden

Join Date: Oct 2010
Posts: 82
Default

The samtools "Working on a stream" page (http://samtools.sourceforge.net/pipe.shtml) says:

"In fact, most of samtools commands, except indexing and external sorting, recognize an input file `-' as stdin and an output file `-' as stdout."

I suppose the rationale is if you're sorting an input list, you can't send items away before you know which position in the output list they will have, making working on the stream trickier.
gaffa is offline   Reply With Quote
Reply

Tags
samtools sort, stdout

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -8. The time now is 06:16 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO