> For the complete documentation index, see [llms.txt](https://help.bioinsight.illumina.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.bioinsight.illumina.com/dragen/dragen-v4.6/product-guides/dragen-v4.6/dragen-dna-pipeline/sort-dupmark.md). Agents can also search and read this documentation through its [MCP server](https://help.bioinsight.illumina.com/~gitbook/mcp).

# Sorting and Duplicate Marking

The map/align system produces a BAM file sorted by reference sequence and position by default. Creating this BAM file typically eliminates the requirement to run samtools sort or any equivalent postprocessing command. The `‑‑enable-sort option` can be used to enable or disable creation of the BAM file, as follows:

* To enable, set to true.
* To disable, set to false.

On the reference hardware system, running with sort enabled increases run time for a 30x full genome by about 6--7 minutes.

## Duplicate Marking

Marking or removing duplicate aligned reads is a common best practice in whole-genome sequencing. Not doing so can bias variant calling and lead to incorrect results.

The DRAGEN system can mark or remove duplicate reads, and produces a BAM file with duplicates marked in the FLAG field, or with duplicates entirely removed.

In testing, enabling duplicate marking adds minimal run time over and above the time required to produce the sorted BAM file. The additional time is approximately 1--2 minutes for a 30x whole human genome, which is a huge improvement over the long run times of open source tools.

### The Duplicate Marking Algorithm

The DRAGEN duplicate-marking algorithm is modeled on the Picard toolkit's MarkDuplicates feature. All the aligned reads are grouped into subsets in which all the members of each subset are potential duplicates.

For two pairs to be duplicates, they must have the following:

* Identical alignment coordinates (position adjusted for soft- or hard-clips from the CIGAR) at both ends.
* Identical orientations (direction of the two ends, with the left-most coordinate being first).

In addition, an unpaired read may be marked as a duplicate if it has identical coordinate and orientation with either end of any other read, whether paired or not.

Unmapped read pairs are never marked as duplicates.

When DRAGEN has identified a group of duplicates, it picks one as the best of the group, and marks the others with the BAM duplicate flag (0x400, or decimal 1024). For this comparison, duplicates are scored based on the average sequence Phred quality. Pairs receive the sum of the scores of both ends, while unpaired reads get the score of the one mapped end. The idea of this score is to try, all other things being equal, to preserve the reads with the highest-quality base calls.

If two reads (or pairs) have exactly matching quality scores, DRAGEN breaks the tie by choosing the pair with the higher alignment score. If there are multiple pairs that also tie on this attribute, then DRAGEN chooses a winner arbitrarily.

The score for an unpaired read R is the average Phred quality score per base, calculated as follows:

![](https://400428970-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS6tWlZO1JqcbWYgnhR2X%2Fuploads%2Fgit-blob-615795568e95f46778a5951ee84fc03732f60fb5%2Fsort-dupmark.ScoreEquation.png?alt=media)

Where R is a BAM record, QUAL is its array of Phred quality scores, and dedup-min-qual is a DRAGEN configuration option with default value of 15. For a pair, the score is the sum of the scores for the two ends.

This score is stored as a one-byte number, with values rounded down to the nearest one-quarter. This rounding may lead to different duplicate marks from those chosen by Picard, but because the reads were very close in quality this has negligible impact on variant calling results.

### Duplicate Marking Limitations

The limitations to DRAGEN duplicate marking implementation are as follows:

* When there are two duplicate reads or pairs with very close Phred sequence quality scores, DRAGEN might choose a different winner from that chosen by Picard. These differences have negligible impact on variant calling results.
* If using a single FASTQ file as input, DRAGEN accepts only a single library ID as a command-line argument (RGLB). For this reason, the FASTQ inputs to the system must be already separated by library ID. Library ID cannot be used as a criterion for distinguishing non-duplicates.
* DRAGEN does not distinguish between optical and PCR duplicates.

### Duplicate Marking Settings

The following options can be used to configure duplicate marking in DRAGEN:

* `--enable-duplicate-marking` Set to true to enable duplicate marking. When `\--enable-duplicate-marking is enabled`, the output is sorted, regardless of the value of the enable-sort option.
* `--remove-duplicates` Set to true to suppress the output of duplicate records. If set to false, set the 0x400 flag in the FLAG field of duplicate BAM records. When --remove-duplicates is enabled, then enable- duplicate-marking is forced to enabled as well.
* `--dedup-min-qual`\
  Specifies the Phred quality score below which a base should be excluded from the quality score calculation used for choosing among duplicate reads.

## Optical Duplicate Marking

In addition to duplicate marking, DRAGEN can optionally count the number of optical duplicates. Optical duplicates meet the following criteria with regard to the winner read as determined by the duplicate marking algorithm above:

* The read has been marked as a PCR duplicate
* The read is in the same read group
* The read is on the same tile
* The read is within the X,Y distance threshold

The distance between reads to be considered optical duplicates is configurable, with the default distance being 100 pixels set for non-patterned flow cells. For patterned flow cells, it is recommended to manually set the pixel distance with the command line argument `--optical-duplicate-distance=2500`.

The module reports the total number of optical duplicates, both as a raw count and as a percentage of all marked duplicates.

This count includes two types of duplicates that both originate on the flow cell. Traditional optical duplicates occur on non-patterned flow cells, when the instrument's imaging software mistakes a single cluster for two adjacent clusters. Clustering duplicates occur on patterned flow cells, when a library fragment migrates from its original nanowell to a neighboring well before amplification. Both types produce duplicate reads that sit close together on the same tile, so DRAGEN detects and counts them together in a single optical duplicate metric. This behavior matches Picard, which also groups both types under its sequencing-duplicate category. The larger recommended pixel distance for patterned flow cells reflects the wider spacing typical of clustering duplicates.

### The Optical Duplicate Marking Algorithm

The optical duplicate marking algorithm is a "bounding-box" algorithm centered on the winner, the representative read chosen for each set of duplicates.

For each read, the bounding box is formed by extending the configured distance N (default 100 pixels) in both directions along the X and Y flow cell coordinates, producing a square region centered on the read. Two reads are candidates for the same optical duplicate group only when they share the same read group and lie on the same tile. Two boxes are said to overlap when their X ranges and their Y ranges both intersect. The boundary comparison is inclusive, so reads whose boxes touch exactly at an edge are treated as overlapping, matching the behavior of Picard.

In addition, there are cases where a duplicate read does not overlap the winner directly, but does overlap another duplicate that is itself an optical duplicate. These chains are handled through cascading bounding boxes. As each duplicate in the group is processed, its box is compared against the winner and against every duplicate already seen in the same group. Overlapping duplicates are merged into a single connected set. As a result, a chain of boxes that links back to the winner is grouped together, even when the reads at the ends of the chain are too far apart for their boxes to touch.

As a result, a duplicate is counted as an optical duplicate when either of the following is true:

* Its bounding box overlaps the bounding box of the winner directly.
* Its bounding box connects to the winner transitively through one or more intermediate duplicates whose boxes overlap in a continuous chain.

This transitive grouping ensures that clusters of optically adjacent reads on a tile are counted consistently, regardless of the order in which the duplicates are processed within the group.

### Optical Duplicate Settings

The following options can be used to configure optical duplicate marking in DRAGEN:

* `--enable-optical-duplicate-marking` Enables optical duplicate marking. (default=false)

Note: Optical duplicate marking requires that standard duplicate marking is enabled: `--enable-duplicate-marking=true`.

* `--optical-duplicate-distance` Sets the flow cell distance between reads for optical duplicate marking. (default=100 pixels)

Note: The X and Y flow cell coordinates, along with the tile number, are derived from the read name (QNAME). DRAGEN reads the last three colon-delimited fields of the standard Illumina read name, which encode the tile, X, and Y position of the cluster on the flow cell.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.bioinsight.illumina.com/dragen/dragen-v4.6/product-guides/dragen-v4.6/dragen-dna-pipeline/sort-dupmark.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
