Picard.SortSam (v4)

Sorts a SAM or BAM file in a specified order, indexes BAM files, and interconverts SAM and BAM files.

Author: Picard team (SAMTools), Marc-Danie Nazaire (Broad Institute)


  • Please use the SAMTools mailing Lists for Picard-related correspondence as the Picard team does not have its own mailing lists.


Algorithm Version: 4


The Picard.SortSam module sorts SAM or BAM files, indexes BAM files, and interconverts SAM and BAM files. The module implements the SortSam function from Picard (Github).

BAM format is the binary equivalent of the Sequence Alignment Map (SAM) format and a BAM file can be up to four times smaller than its SAM equivalent. For detailed information on these formats, see the September 2014 article titled Sequence Alignment/Map Format Specification by the SAM/BAM Format Specification Working Group.

  • This module will only generate an index file when the output format is BAM, and the sort order is coordinate.
    • The index file will have a BAI extension.
  • The module does not generate index files for SAM output files.
    • To index SAM files for use with the Integrative Genomics Viewer (IGV), refer to the igvtools section of IGV documentation.


Li H.*, Handsaker B.*, Wysoker A., Fennell T., Ruan J., Homer N., Marth G., Abecasis G., Durbin R. and 1000 Genome Project Data Processing Subgroup (2009) The Sequence alignment/map (SAM) format and SAMtools. Bioinformatics, 25, 2078-9. [PMID: 19505943]


Name Description
input file * Input file in SAM or BAM format
sort order *

Specifies the sort order by the following options:

  • coordinate: the file sorts by chromosome and start position
  • queryname: the file sorts by the read IDs
  • unsorted: this option is only supported when the Group Order in the SAM/BAM header is "none"

Default: coordinate

output format * Whether the file output format should be SAM or BAM. Default: BAM
output prefix * The prefix to use for the output file name.

* - required

Input Files

  1. BAM or SAM format file

Output Files

  1. <output.prefix>.sorted.<output.format>

This is the sorted SAM or BAM file.

  1. <output.filename>.bai

This file contains the index for the coordinate sorted BAM output file. 


Platform Dependencies

Task Type:
Preprocess & Utilities

CPU Type:

Operating System:

Java (minimum version 1.6)

Version Comments

Version Release Date Description
4 2013-05-07 Renamed from SortSam to Picard.SortSam
3 2011-04-01 Added output format parameter
2 2011-02-28 Added 1 sec to index file timestamp, and added notes to doc
1 2011-02-15