# Class SortSam

java.lang.Object
picard.cmdline.CommandLineProgram
picard.sam.SortSam

@DocumentedFeature public class SortSam extends CommandLineProgram
Sorts a SAM or BAM file.

### Summary

This tool sorts the input SAM or BAM file by coordinate, queryname (QNAME), or some other property of the SAM record. The SortOrder of a SAM/BAM file is found in the SAM file header tag labeled SO.

For a coordinate sorted SAM/BAM file, read alignments are sorted first by the reference sequence name (RNAME) field using the reference sequence dictionary tag labeled SQ. Alignments within these subgroups are secondarily sorted using the left-most mapping position of the read (POS). Subsequent to this sorting scheme, alignments are listed arbitrarily.

For queryname-sorted alignments, the tool orders records deterministically by queryname field followed by record strand orientation flag, primary record flag, and secondary alignment flag. (See `SAMRecordQueryNameComparator.compare(SAMRecord, SAMRecord)`} for details). This ordering may change in the future.

### Inputs

- Input BAM or SAM file to sort
- Sorted BAM or SAM output file
- Sort order of output file

### Usage example:

        java -jar picard.jar SortSam \
        INPUT=input.bam \
        OUTPUT=sorted.bam \
        SORT_ORDER=coordinate

## Field Summary

Fields
Modifier and Type
Field
Description
`File`
`INPUT`
`File`
`OUTPUT`
`picard.sam.SortSam.SortOrder`
`SORT_ORDER`

### Fields inherited from class CommandLineProgram

`COMPRESSION_LEVEL, CREATE_INDEX, CREATE_MD5_FILE, MAX_ALLOWABLE_ONE_LINE_SUMMARY_LENGTH, MAX_RECORDS_IN_RAM, QUIET, REFERENCE_SEQUENCE, referenceSequence, specialArgumentsCollection, SYNTAX_TRANSITION_URL, TMP_DIR, USE_JDK_DEFLATER, USE_JDK_INFLATER, VALIDATION_STRINGENCY, VERBOSITY`

## Constructor Summary

Constructors
Constructor
Description
`SortSam()`

## Method Summary

Modifier and Type
Method
Description
`protected int`
`doWork()`
Do the work after command line has been parsed.

### Methods inherited from class CommandLineProgram

`checkRInstallation, customCommandLineValidation, getCommandLine, getCommandLineParser, getCommandLineParserForArgs, getDefaultHeaders, getFaqLink, getMetricsFile, getPGRecord, getStandardUsagePreamble, getStandardUsagePreamble, getVersion, hasWebDocumentation, instanceMain, instanceMainWithExit, makeReferenceArgumentCollection, parseArgs, requiresReference, setDefaultHeaders, useLegacyParser`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### INPUT

@Argument(doc="The SAM, BAM or CRAM file to sort.", shortName="I") public File INPUT

### OUTPUT

@Argument(doc="The sorted SAM, BAM or CRAM output file. ", shortName="O") public File OUTPUT

### SORT_ORDER

@Argument(shortName="SO", doc="Sort order of output file. ") public picard.sam.SortSam.SortOrder SORT_ORDER

## Constructor Details

### SortSam

public SortSam()

## Method Details

### doWork

protected int doWork()
Description copied from class: `CommandLineProgram`
Do the work after command line has been parsed. RuntimeException may be thrown by this method, and are reported appropriately.

Specified by:
  `doWork` in class `CommandLineProgram`
Returns:
  program exit status.