Package htsjdk.samtools

# Class SAMRecordCoordinateComparator

java.lang.Object
htsjdk.samtools.SAMRecordCoordinateComparator

All Implemented Interfaces:
  `SAMRecordComparator`, `Serializable`, `Comparator<SAMRecord>`

public class SAMRecordCoordinateComparator extends Object implements SAMRecordComparator, Serializable
Comparator for sorting SAMRecords by coordinate. Note that the header is required because the order of sequences in the header defines the major sort order. Ideally this method would only return 0 for completely equal SAMRecords, so that sort is completely deterministic. This implementation does not achieve this completely, but it comes pretty close, while avoiding decoding the variable length fields, except for read name, which is decoded if coordinate and strand are equal. Extreme care must be taken to ensure the following: if A == B, then B == A if A invalid input: '<' B, then B > A if A invalid input: '<' B invalid input: '&'invalid input: '&' B invalid input: '<' C, then A invalid input: '<' C

See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`SAMRecordCoordinateComparator()`

## Method Summary

Modifier and Type
Method
Description
`int`
`compare(SAMRecord samRecord1, SAMRecord samRecord2)`
`int`
`fileOrderCompare(SAMRecord samRecord1, SAMRecord samRecord2)`
Less stringent compare method than the regular compare.

### Methods inherited from class java.lang.Object

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

### Methods inherited from interface java.util.Comparator

`equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

## Constructor Details

### SAMRecordCoordinateComparator

public SAMRecordCoordinateComparator()

## Method Details

### compare

public int compare(SAMRecord samRecord1, SAMRecord samRecord2)

Specified by:
  `compare` in interface `Comparator<SAMRecord>`

### fileOrderCompare

public int fileOrderCompare(SAMRecord samRecord1, SAMRecord samRecord2)
Less stringent compare method than the regular compare. If the two records are equal enough that their ordering in a sorted SAM file would be arbitrary, this method returns 0. If read is paired and unmapped, use the mate mapping to sort. Records being compared must have non-null SAMFileHeaders.

Specified by:
  `fileOrderCompare` in interface `SAMRecordComparator`
Returns:
  negative if samRecord1 invalid input: '<' samRecord2, 0 if equal, else positive