# Class CRAMCompressionRecord

java.lang.Object
htsjdk.samtools.cram.structure.CRAMCompressionRecord

public class CRAMCompressionRecord extends Object
A CRAMRecord represents a SAMRecord that has been transformed to CRAM-style representation. This includes representing read bases as reference-relative read features, and representation of quality scores, tags, and BAM and CRAM flags.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`CF_DETACHED`
`static final int`
`CF_HAS_MATE_DOWNSTREAM`
`static final int`
`CF_QS_PRESERVED_AS_ARRAY`
`static final int`
`CF_UNKNOWN_BASES`
`static final int`
`MF_MATE_NEG_STRAND`
`static final int`
`MF_MATE_UNMAPPED`
`static final byte`
`MISSING_QUALITY_SCORE`
`static final int`
`NO_READGROUP_ID`

## Constructor Summary

Constructors
Constructor
Description
`CRAMCompressionRecord(long sequentialIndex, int bamFlags, int cramFlags, String readName, int readLength, int referenceIndex, int alignmentStart, int templateSize, int mappingQuality, byte[] qualityScores, byte[] readBases, List<ReadTag> readTags, List<ReadFeature> readFeaturesList, int readGroupID, int mateFlags, int mateReferenceIndex, int mateAlignmentStart, int recordsToNextFragment)`
Create a CRAMRecord from a set of values retrieved from a serialized Slice's data series streams.
`CRAMCompressionRecord(CRAMVersion cramVersion, CRAMEncodingStrategy encodingStrategy, SAMRecord samRecord, byte[] referenceBases, long sequentialIndex, Map<String,Integer> readGroupMap)`
Create a CRAMRecord from a SAMRecord.

## Method Summary

Modifier and Type
Method
Description
`void`
`assignReadName()`
Assign a synthetic read name based on the sequential index if no name was decoded.
`boolean`
`equals(Object o)`
`int`
`getAlignmentEnd()`
`int`
`getAlignmentStart()`
`int`
`getBAMFlags()`
`int`
`getCRAMFlags()`
`int`
`getMappingQuality()`
`int`
`getMateAlignmentStart()`
`int`
`getMateFlags()`
`int`
`getMateReferenceIndex()`
`CRAMCompressionRecord`
`getNextSegment()`
`CRAMCompressionRecord`
`getPreviousSegment()`
`byte[]`
`getQualityScores()`
`byte[]`
`getReadBases()`
`List<ReadFeature>`
`getReadFeatures()`
`int`
`getReadGroupID()`
`int`
`getReadLength()`
`String`
`getReadName()`
`int`
`getRecordsToNextFragment()`
`int`
`getReferenceIndex()`
`long`
`getSequentialIndex()`
`MutableInt`
`getTagIdsIndex()`
`List<ReadTag>`
`getTags()`
`int`
`getTemplateSize()`
`int`
`hashCode()`
`boolean`
`isDetached()`
Return true if this record stores mate information explicitly (detached state).
`static boolean`
`isDetached(int cramFlags)`
Test the detached bit in the given CRAM flags value.
`boolean`
`isFirstSegment()`
Return true if this record is the first segment in the template.
`boolean`
`isForcePreserveQualityScores()`
Return true if quality scores are preserved as a full array for this record.
`static boolean`
`isForcePreserveQualityScores(int cramFlags)`
Test the quality-scores-preserved-as-array bit in the given CRAM flags value.
`boolean`
`isHasMateDownStream()`
Return true if this record's CRAM flags indicate a downstream mate in the same slice.
`static boolean`
`isHasMateDownStream(int cramFlags)`
Test the has-mate-downstream bit in the given CRAM flags value.
`boolean`
`isLastSegment()`
Return true if this record is the last segment in the template.
`boolean`
`isNormalized()`
When a CRAM record is read from a CRAM stream, it is "raw" in that the record's read bases, quality scores, and mate graph are not stored directly as part of the record.
`boolean`
`isPlaced()`
Determine is read is "placed".
`boolean`
`isReadPaired()`
Return true if this record has the read-paired BAM flag set.
`boolean`
`isSecondaryAlignment()`
Return true if this record has the secondary alignment BAM flag set.
`boolean`
`isSegmentUnmapped()`
Does this record have the mapped flag set? This is independent of placement/alignment status.
`static boolean`
`isSegmentUnmapped(int bamFlags)`
Test the segment-unmapped bit in the given BAM flags value.
`boolean`
`isUnknownBases()`
Return true if the original sequence was unknown (SEQ="*").
`static boolean`
`isUnknownBases(int cramFlags)`
Test the unknown-bases bit in the given CRAM flags value.
`void`
`resolveQualityScores()`
Resolve the quality scores for this CRAM record based on preserved scores, read features and flags.
`void`
`restoreMateInfo()`
Restore mate information by walking the linked list of segments starting from this record, setting mate fields on each segment pair, and computing template length.
`void`
`restoreReadBases(CRAMReferenceRegion cramReferenceRegion, SubstitutionMatrix substitutionMatrix)`
Restore the actual read bases for this record.
`void`
`setDetached(boolean detached)`
Set or clear the detached CRAM flag (mate info stored explicitly).
`void`
`setNextSegment(CRAMCompressionRecord nextSegment)`
`void`
`setPreviousSegment(CRAMCompressionRecord previousSegment)`
`void`
`setTagIdsIndex(MutableInt tagIdsIndex)`
`void`
`setToDetachedState()`
Mark this record as detached — mate info stored explicitly via MF, NS, NP, TS data series.
`SAMRecord`
`toSAMRecord(SAMFileHeader samFileHeader)`
Create a SAMRecord from the CRAMRecord.

### Methods inherited from class Object

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

## Field Details

### CF_QS_PRESERVED_AS_ARRAY

public static final int CF_QS_PRESERVED_AS_ARRAY

See Also:
  - Constant Field Values

### CF_DETACHED

public static final int CF_DETACHED

See Also:
  - Constant Field Values

### CF_HAS_MATE_DOWNSTREAM

public static final int CF_HAS_MATE_DOWNSTREAM

See Also:
  - Constant Field Values

### CF_UNKNOWN_BASES

public static final int CF_UNKNOWN_BASES

See Also:
  - Constant Field Values

### NO_READGROUP_ID

public static final int NO_READGROUP_ID

See Also:
  - Constant Field Values

### MISSING_QUALITY_SCORE

public static final byte MISSING_QUALITY_SCORE

See Also:
  - Constant Field Values

### MF_MATE_NEG_STRAND

public static final int MF_MATE_NEG_STRAND

See Also:
  - Constant Field Values

### MF_MATE_UNMAPPED

public static final int MF_MATE_UNMAPPED

See Also:
  - Constant Field Values

## Constructor Details

### CRAMCompressionRecord

public CRAMCompressionRecord(CRAMVersion cramVersion, CRAMEncodingStrategy encodingStrategy, SAMRecord samRecord, byte[] referenceBases, long sequentialIndex, Map<String,Integer> readGroupMap)
Create a CRAMRecord from a SAMRecord.

Parameters:
  `cramVersion` -
  `encodingStrategy` -
  `samRecord` -
  `referenceBases` -
  `sequentialIndex` -
  `readGroupMap` -

### CRAMCompressionRecord

public CRAMCompressionRecord(long sequentialIndex, int bamFlags, int cramFlags, String readName, int readLength, int referenceIndex, int alignmentStart, int templateSize, int mappingQuality, byte[] qualityScores, byte[] readBases, List<ReadTag> readTags, List<ReadFeature> readFeaturesList, int readGroupID, int mateFlags, int mateReferenceIndex, int mateAlignmentStart, int recordsToNextFragment)
Create a CRAMRecord from a set of values retrieved from a serialized Slice's data series streams.

Parameters:
  `sequentialIndex` -
  `bamFlags` -
  `cramFlags` -
  `readName` -
  `readLength` -
  `referenceIndex` -
  `alignmentStart` -
  `templateSize` -
  `mappingQuality` -
  `qualityScores` -
  `readBases` -
  `readTags` -
  `readFeaturesList` -
  `readGroupID` -
  `mateFlags` -
  `mateReferenceIndex` -
  `mateAlignmentStart` -
  `recordsToNextFragment` -

## Method Details

### toSAMRecord

public SAMRecord toSAMRecord(SAMFileHeader samFileHeader)
Create a SAMRecord from the CRAMRecord.

Parameters:
  `samFileHeader` - SAMFileHeader
Returns:
  a SAMRecord

### assignReadName

public void assignReadName()
Assign a synthetic read name based on the sequential index if no name was decoded. Propagates the name to linked next/previous segments.

Note: supplementary and secondary reads are always DETACHED (never mate-linked), so they have no nextSegment/previousSegment and name propagation won’t help them. This is only safe because htsjdk always sets preserveReadNames=true when encoding (see `CompressionHeaderFactory.createCompressionHeader(List, boolean)`). If lossy read name mode were ever implemented, supplementary/secondary reads in different slices from their primaries would receive synthetic names that don’t match. htslib avoids this by forcing name preservation whenever SA tags are present and when not all template reads are in the same slice.

### isNormalized

public boolean isNormalized()
When a CRAM record is read from a CRAM stream, it is "raw" in that the record's read bases, quality scores, and mate graph are not stored directly as part of the record. These values must be resolved through the separate process of normalization, which is performed at Slice granularity (all records in a Slice are normalized at the same time). (see `Slice.normalizeCRAMRecords(List, CRAMReferenceRegion)`).

Returns:
  true if this record is normalized

### resolveQualityScores

public void resolveQualityScores()
Resolve the quality scores for this CRAM record based on preserved scores, read features and flags.

### restoreReadBases

public void restoreReadBases(CRAMReferenceRegion cramReferenceRegion, SubstitutionMatrix substitutionMatrix)
Restore the actual read bases for this record.

Parameters:
  `cramReferenceRegion` - CRAMReferenceRegion spanning the reference bases for this record, if reference bases are required (may be null for records with RR=false in the compression header)
  `substitutionMatrix` - substitution matrix to use for this record

### restoreMateInfo

public void restoreMateInfo()
Restore mate information by walking the linked list of segments starting from this record, setting mate fields on each segment pair, and computing template length.

### setToDetachedState

public void setToDetachedState()
Mark this record as detached — mate info stored explicitly via MF, NS, NP, TS data series.

### isPlaced

public boolean isPlaced()
Determine is read is "placed". For consistency with the rest of htsjdk, this only consults the alignmentStart (placed reads should also have a valid reference index, and unplaced reads should be unmapped; those two abberant conditions are logged as warnings).

Returns:
  true if the record is placed
See Also:
  - `isSegmentUnmapped()`

### getReadName

public String getReadName()

### getAlignmentStart

public int getAlignmentStart()

### getReadLength

public int getReadLength()

### getReadBases

public byte[] getReadBases()

### getQualityScores

public byte[] getQualityScores()

### getMappingQuality

public int getMappingQuality()

### getReferenceIndex

public int getReferenceIndex()

### getTemplateSize

public int getTemplateSize()

### getTags

public List<ReadTag> getTags()

### getRecordsToNextFragment

public int getRecordsToNextFragment()

### getReadFeatures

public List<ReadFeature> getReadFeatures()

### getReadGroupID

public int getReadGroupID()

Returns:
  read group id, or `NO_READGROUP_ID` if no read group assigned

### getBAMFlags

public int getBAMFlags()

### getMateReferenceIndex

public int getMateReferenceIndex()

### getMateAlignmentStart

public int getMateAlignmentStart()

### setTagIdsIndex

public void setTagIdsIndex(MutableInt tagIdsIndex)

### getTagIdsIndex

public MutableInt getTagIdsIndex()

### getMateFlags

public int getMateFlags()

### getCRAMFlags

public int getCRAMFlags()

### getAlignmentEnd

public int getAlignmentEnd()

Returns:
  the initialized alignmentEnd

### getSequentialIndex

public long getSequentialIndex()

### getNextSegment

public CRAMCompressionRecord getNextSegment()

### setNextSegment

public void setNextSegment(CRAMCompressionRecord nextSegment)

### getPreviousSegment

public CRAMCompressionRecord getPreviousSegment()

### setPreviousSegment

public void setPreviousSegment(CRAMCompressionRecord previousSegment)

### isSecondaryAlignment

public boolean isSecondaryAlignment()
Return true if this record has the secondary alignment BAM flag set.

### isHasMateDownStream

public boolean isHasMateDownStream()
Return true if this record's CRAM flags indicate a downstream mate in the same slice.

### isHasMateDownStream

public static boolean isHasMateDownStream(int cramFlags)
Test the has-mate-downstream bit in the given CRAM flags value.

### isDetached

public boolean isDetached()
Return true if this record stores mate information explicitly (detached state).

### isDetached

public static boolean isDetached(int cramFlags)
Test the detached bit in the given CRAM flags value.

### isForcePreserveQualityScores

public boolean isForcePreserveQualityScores()
Return true if quality scores are preserved as a full array for this record.

### isForcePreserveQualityScores

public static boolean isForcePreserveQualityScores(int cramFlags)
Test the quality-scores-preserved-as-array bit in the given CRAM flags value.

### isUnknownBases

public boolean isUnknownBases()
Return true if the original sequence was unknown (SEQ="*").

### isUnknownBases

public static boolean isUnknownBases(int cramFlags)
Test the unknown-bases bit in the given CRAM flags value.

### isReadPaired

public boolean isReadPaired()
Return true if this record has the read-paired BAM flag set.

### isSegmentUnmapped

public boolean isSegmentUnmapped()
Does this record have the mapped flag set? This is independent of placement/alignment status. Unmapped records may be stored in the same `Slice`s and `Container`s as mapped records if they are placed.

Returns:
  true if the record is unmapped
See Also:
  - `isPlaced()`

### isSegmentUnmapped

public static boolean isSegmentUnmapped(int bamFlags)
Test the segment-unmapped bit in the given BAM flags value.

### isFirstSegment

public boolean isFirstSegment()
Return true if this record is the first segment in the template.

### isLastSegment

public boolean isLastSegment()
Return true if this record is the last segment in the template.

### setDetached

public void setDetached(boolean detached)
Set or clear the detached CRAM flag (mate info stored explicitly).

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`