> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/clara/parabricks/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/clara/parabricks/_mcp/server.

# bamsort

Sort BAM files.

This tool can sort the reads within a BAM file in a variety of ways, including
by position in the genome (coordinate) or read name (queryname). This enables
compatibility with the requirements of different downstream tools.

Five sort modes are supported:

* coordinate (Picard-compatible)
* coordinate (fgbio-compatible)
* queryname (Picard-compatible)
* queryname (fgbio-compatible)
* template coordinate sort (fgbio-compatible)

Allowed values for **--sort-order** are as follows:

* coordinate \[default]
* queryname
* templatecoordinate

Allowed values for **--sort-compatibility** are as follows:

* picard \[default]
* fgbio

*coordinate* and *queryname* sorting can be done in either *picard* or *fgbio* mode.
*templatecoordinate* can only be done in fgbio mode.

Refer to the [bamsort Reference](#options) section for a detailed listing of all available options.

## Quick Start

```sh
# This command assumes all the inputs are in the current working directory and all the outputs go to the same place.
docker run --rm --gpus all --volume $(pwd):/workdir --volume $(pwd):/outputdir \
    --workdir /workdir \
    nvcr.io/nvidia/clara/clara-parabricks:4.7.1-1 \
    pbrun bamsort \
    --ref /workdir/${REFERENCE_FILE} \
    --in-bam /workdir/${INPUT_BAM} \
    --out-bam /outputdir/${OUTPUT_BAM} \
    --sort-order coordinate
```

## Compatible Picard Command

The command below is the Picard counterpart of the Parabricks command above. The output
from this command will be identical to the output from the above command.

```sh
$ java -Xmx30g -jar picard.jar SortSam \
    I=<INPUT_DIR>/${INPUT_BAM} \
    O=<OUTPUT_DIR>/${OUTPUT_BAM}
```

## Options