This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools sort: legacy usage

Hi,

I am trying to run the command samtools sort -@ 12 in.bam -O bam in_sorted using samtools version 1.1.

However this gives me the error:

Legacy usage: samtools sort [options...] <in.bam> <out.prefix>
Options: 

  -f         Use <out.prefix> as full final filename rather than prefix
  -o         Write final output to stdout rather than <out.prefix>.bam
  -l,m,n,@   Similar to corresponding options above

Usage: samtools sort [options...] [in.bam]

Options:

  -l INT     Set compression level, from 0 (uncompressed) to 9 (best)
  -m INT     Set maximum memory per thread; suffix K/M/G recognized [768M]
  -n         Sort by read name
  -o FILE    Write final output to FILE rather than standard output
  -O FORMAT  Write output as FORMAT ('sam'/'bam'/'cram')   (either -O or
  -T PREFIX  Write temporary files to PREFIX.nnnn.bam       -T is required)
  -@ INT     Set number of sorting and compression threads [1]

Should I not use -O and -@ with this version of samtools to specify that I want to use 12 threads and my output to be a bam file?

Thank you in advance for your help!

samtools metagenomics genome sort

Is there a good-enough reason to do this? Shouldn't you rather use the most up to date version and that syntax?

I am trying to use the most up to date version of the syntax. My understanding was that the options -@ and -O are the new versions, not the legacy version?

I don't know when -@ was introduced, but you no longer need -O. samtools finds the file format based on the extension specified by -o.

So you can do samtools sort -@12 -o sorted_alignment.bam myalignment.bam

I tried this and it worked. Thank you for your help!!

1 answer

edit:

As you are using SAMtools 1.1, you should use the "current" command line, not the "legacy":

samtools sort -@ 12 -o in_sort.bam in.bam

end of edit:

If you want to follow the "legacy" usage, you can't put an option between in.bam and out.prefix, so your command line should be:

samtools sort -@ 12 -O bam in.bam in_sorted

Hi,

Thank you for your help!

I tried this, but I still got the same error?

I assumed I was not using the "legacy usage" as both -@ and -O are included in the given options of the new version?

Try:

samtools sort -@ 12 -o in_sort.bam in.bam

I tried this and it worked. Thank you for your help!!

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.
Upvote|Bookmark|Accept

Log in to answer this question.