public interface GATKRead
extends htsjdk.samtools.util.Locatable
SAMRecord
(SAMRecordToGATKReadAdapter
)
Since the adapter classes wrap the raw reads without making a copy, care must be taken to avoid
exposing the encapsulated reads, particularly if modifying reads in-place. As a result, this interface
should probably only be implemented by core engine-level classes.
All GATKRead methods that return mutable reference types make defensive copies, with the exception
of the conversion method convertToSAMRecord(htsjdk.samtools.SAMFileHeader)
.
Note that Locatable.getContig()
and Locatable.getStart()
will not expose nominal positions assigned to unmapped
reads for sorting purposes -- for unmapped reads, these methods will always return null
or 0,
respectively. To access positions assigned to unmapped reads for sorting purposes, use getAssignedContig()
and getAssignedStart()
.Modifier and Type | Method and Description |
---|---|
void |
clearAttribute(java.lang.String attributeName)
Clear an individual attribute on the read.
|
void |
clearAttributes()
Clear all attributes on the read.
|
void |
clearTransientAttribute(java.lang.String attributeName)
Clear an individual transient attribute on the read.
|
default java.lang.String |
commonToString()
A human-digestable representation of the read.
|
htsjdk.samtools.SAMRecord |
convertToSAMRecord(htsjdk.samtools.SAMFileHeader header)
Convert this read into a SAMRecord.
|
GATKRead |
copy()
Return a copy of this read.
|
default int |
copyBaseQualities(int offset,
byte[] destination,
int destinationOffset,
int maxLength)
Copy base qualities into an existent byte array.
|
default int |
copyBases(int offset,
byte[] destination,
int destinationOffset,
int maxLength)
Copy the base into an existent byte array.
|
GATKRead |
deepCopy()
Return a deep copy of this read.
|
boolean |
failsVendorQualityCheck() |
default int |
getAdaptorBoundary()
Finds the adaptor boundary around the read and returns the first base inside the adaptor that is closest to
the read boundary.
|
java.lang.String |
getAssignedContig() |
int |
getAssignedStart() |
byte[] |
getAttributeAsByteArray(java.lang.String attributeName)
Retrieve the value of a particular attribute typed as a byte array.
|
java.lang.Integer |
getAttributeAsInteger(java.lang.String attributeName)
Retrieve the value of a particular attribute typed as an integer.
|
java.lang.String |
getAttributeAsString(java.lang.String attributeName)
Retrieve the value of a particular attribute typed as a String.
|
default byte |
getBase(int i) |
byte[] |
getBaseQualities() |
default byte[] |
getBaseQualitiesNoCopy() |
default byte |
getBaseQuality(int i) |
default int |
getBaseQualityCount() |
byte[] |
getBases() |
default byte[] |
getBasesNoCopy() |
default java.lang.String |
getBasesString() |
htsjdk.samtools.Cigar |
getCigar() |
default htsjdk.samtools.CigarElement |
getCigarElement(int i)
Return the cigar element at a given index.
|
default java.util.List<htsjdk.samtools.CigarElement> |
getCigarElements() |
int |
getFlags() |
int |
getFragmentLength()
Returns the observed length of the read's fragment (equivalent to TLEN in SAM).
|
int |
getLength() |
int |
getMappingQuality() |
java.lang.String |
getMateContig() |
int |
getMateStart() |
java.lang.String |
getName() |
default <T> java.util.Optional<T> |
getOptionalTransientAttribute(java.lang.Object key,
java.lang.Class<T> clazz)
Returns a transient attribute value as an
Optional . |
default java.util.Optional<htsjdk.samtools.SamPairUtil.PairOrientation> |
getPairOrientation()
Computes the pair orientation
|
java.lang.String |
getReadGroup() |
java.lang.String |
getSAMString()
Get a string representation of this read in SAM string format, terminated with '\n'.
|
default int |
getSoftEnd()
Calculates the reference coordinate for the end of the read taking into account soft clips but not hard clips.
|
default int |
getSoftStart()
Calculates the reference coordinate for the beginning of the read taking into account soft clips but not hard clips.
|
java.lang.Object |
getTransientAttribute(java.lang.Object key)
This is used to access a transient attribute store provided by the underlying implementation.
|
int |
getUnclippedEnd()
Returns the alignment end (1-based, inclusive) adjusted for clipped bases.
|
int |
getUnclippedStart()
Returns the alignment start (1-based, inclusive) adjusted for clipped bases.
|
boolean |
hasAttribute(java.lang.String attributeName)
Check whether this read has a particular attribute
|
default boolean |
hasBaseQualities()
Indicates whether there is any base-qualities.
|
default boolean |
hasBases()
Indicates whether there are any bases.
|
boolean |
isDuplicate() |
default boolean |
isEmpty() |
boolean |
isFirstOfPair() |
boolean |
isPaired() |
boolean |
isProperlyPaired() |
boolean |
isReverseStrand() |
boolean |
isSecondaryAlignment() |
boolean |
isSecondOfPair() |
boolean |
isSupplementaryAlignment() |
boolean |
isUnmapped() |
boolean |
isUnplaced()
Does the read have a position assigned to it for sorting purposes.
|
boolean |
mateIsReverseStrand() |
boolean |
mateIsUnmapped() |
boolean |
mateIsUnplaced()
Does the reads mate have a position assigned to it for sorting purposes..
|
default int |
numCigarElements()
The number of cigar elements in this read.
|
void |
reverseComplement()
Modify this read by reverse complementing its bases and reversing its quality scores.
|
void |
setAttribute(java.lang.String attributeName,
byte[] attributeValue)
Set a byte array attribute on the read.
|
void |
setAttribute(java.lang.String attributeName,
java.lang.Integer attributeValue)
Set an integer-valued attribute on the read.
|
void |
setAttribute(java.lang.String attributeName,
java.lang.String attributeValue)
Set a String-valued attribute on the read.
|
void |
setBaseQualities(byte[] baseQualities)
Set the read's base qualities.
|
void |
setBases(byte[] bases)
Set the read's sequence.
|
void |
setCigar(htsjdk.samtools.Cigar cigar)
Set the read's Cigar using an existing
Cigar object describing how the read aligns to the reference. |
void |
setCigar(java.lang.String cigarString)
Set the read's Cigar using a textual cigar String describing how the read aligns to the reference.
|
void |
setFailsVendorQualityCheck(boolean failsVendorQualityCheck)
Mark the read as failing platform/vendor quality checks
|
void |
setFragmentLength(int fragmentLength)
Set the observed length of the read's fragment (equivalent to TLEN in SAM).
|
void |
setIsDuplicate(boolean isDuplicate)
Mark the read as a PCR or optical duplicate.
|
void |
setIsFirstOfPair()
Mark the read as the first read of a pair.
|
void |
setIsPaired(boolean isPaired)
Mark the read as paired (having a mate) or not paired.
|
void |
setIsProperlyPaired(boolean isProperlyPaired)
Mark the read as properly paired (or not properly paired).
|
void |
setIsReverseStrand(boolean isReverseStrand)
Mark the read as being on the reverse (or forward) strand.
|
void |
setIsSecondaryAlignment(boolean isSecondaryAlignment)
Mark the read as a secondary alignment (an alternative to the primary alignment)
|
void |
setIsSecondOfPair()
Mark the read as the second read of a pair.
|
void |
setIsSupplementaryAlignment(boolean isSupplementaryAlignment)
Mark the read as a supplementary alignment (used in the representation of a chimeric alignment)
|
void |
setIsUnmapped()
Mark the read as unmapped (lacking a defined position on the genome).
|
void |
setIsUnplaced()
Mark the read as unmapped, and also removes mapping information from the read (i.e.
|
void |
setMappingQuality(int mappingQuality)
Set the mapping quality of this alignment, representing how likely the read maps to this position as
opposed to other locations.
|
void |
setMateIsReverseStrand(boolean mateIsReverseStrand)
Mark the read's mate as being on the reverse (or forward) strand.
|
void |
setMateIsUnmapped()
Mark the read's mate as unmapped (lacking a defined position on the genome).
|
void |
setMateIsUnplaced()
Mark the read's mate as unmapped (lacking a defined position on the genome).
|
void |
setMatePosition(htsjdk.samtools.util.Locatable locatable)
Set the position of the read's mate using the position of an existing
Locatable . |
void |
setMatePosition(java.lang.String contig,
int start)
Set the position of the read's mate (the contig and the start position).
|
void |
setName(java.lang.String name)
Set the name of the read (equivalent to QNAME in SAM), or set to
null if the read has no name. |
void |
setPosition(htsjdk.samtools.util.Locatable locatable)
Set the position of the read using the position of an existing
Locatable . |
void |
setPosition(java.lang.String contig,
int start)
Set the position of the read (the contig and the start position).
|
void |
setReadGroup(java.lang.String readGroupID)
Set the ID of the read group this read belongs to, or
null for none. |
void |
setTransientAttribute(java.lang.Object key,
java.lang.Object value)
This is used to access the transient attribute store in the underlying data type.
|
java.lang.String getName()
null
if the read has no name.int getFlags()
void setName(java.lang.String name)
null
if the read has no name.name
- new name for the readint getLength()
default boolean isEmpty()
void setPosition(java.lang.String contig, int start)
setIsUnmapped()
for that purpose.contig
- Contig the read is mapped tostart
- Start position of the read (1-based, inclusive)java.lang.IllegalArgumentException
- if contig is null or "*", or start is less than 1void setPosition(htsjdk.samtools.util.Locatable locatable)
Locatable
. Cannot be used to
set the read to an unmapped position; use setIsUnmapped()
for that purpose.locatable
- Locatable
representing the 1-based, inclusive position to assign to the readjava.lang.IllegalArgumentException
- if locatable is null, or its contig is null or "*", or its start position is less than 1java.lang.String getAssignedContig()
Locatable.getContig()
,
which does not expose positions assigned to unmapped reads, this method will gladly return a contig
assigned to an unmapped read (typically, this will be the contig of its mapped mate). Will return either
ReadConstants.UNSET_CONTIG
or null
for reads with no contig, depending on
the underlying read implementation.
Useful for sorting reads in standard BAM/SAM file order, with unmapped reads interleaved with their mapped
mates -- for other uses, clients should use Locatable.getContig()
int getAssignedStart()
Locatable.getStart()
,
which does not expose positions assigned to unmapped reads, this method will gladly return a start position
assigned to an unmapped read (typically, this will be the start position of its mapped mate). Will return
ReadConstants.UNSET_POSITION
for reads with no start position.
Useful for sorting reads in standard BAM/SAM file order, with unmapped reads interleaved with their mapped
mates -- for other uses, clients should use Locatable.getStart()
int getUnclippedStart()
ReadConstants.UNSET_POSITION
ReadConstants.UNSET_POSITION
if the read is unmapped.int getUnclippedEnd()
ReadConstants.UNSET_POSITION
ReadConstants.UNSET_POSITION
if the read is unmapped.default int getSoftStart()
getUnclippedStart()
adds soft and hard clips, this method only adds soft clips.default int getSoftEnd()
getUnclippedEnd()
adds soft and hard clips, this method only adds soft clips.default int getAdaptorBoundary()
java.lang.String getMateContig()
null
if the mate is unmappedjava.lang.IllegalStateException
- if the read is not paired (has no mate)int getMateStart()
ReadConstants.UNSET_POSITION
if the mate is unmapped.java.lang.IllegalStateException
- if the read is not paired (has no mate)void setMatePosition(java.lang.String contig, int start)
setMateIsUnmapped()
for that purpose.
Calling this method has the additional effect of marking the read as paired, as if setIsPaired(boolean)
were invoked with true.contig
- Contig the read's mate is mapped tostart
- Start position of the read's mate (1-based, inclusive)java.lang.IllegalArgumentException
- if contig is null or "*", or start is less than 1void setMatePosition(htsjdk.samtools.util.Locatable locatable)
Locatable
. Cannot be used to
set the read's mate to an unmapped position; use setMateIsUnmapped()
for that purpose.
Calling this method has the additional effect of marking the read as paired, as if setIsPaired(boolean)
were invoked with true.locatable
- Locatable
representing the 1-based, inclusive position to assign to the read's matejava.lang.IllegalArgumentException
- if locatable is null, or its contig is null or "*", or its start position is less than 1int getFragmentLength()
void setFragmentLength(int fragmentLength)
fragmentLength
- Observed length of the read's fragment; may be negative
if the mate maps to a lower position than the read,
or 0 if unknown.int getMappingQuality()
ReadConstants.NO_MAPPING_QUALITY
if there is none.void setMappingQuality(int mappingQuality)
ReadConstants.NO_MAPPING_QUALITY
if there is none.mappingQuality
- mapping quality of this alignment; must be between 0 and 255, inclusivejava.lang.IllegalArgumentException
- if the mapping quality is less than 0 or greater than 255byte[] getBases()
default byte[] getBasesNoCopy()
getBases()
in that implementations are free to avoid making a
defensive copy, if it's possible to avoid a copy.
WARNING: This method MAY NOT make a defensive copy of the bases array before returning it, so modifying the
returned array MAY alter the bases in the actual read. CALLER BEWARE!default int copyBases(int offset, byte[] destination, int destinationOffset, int maxLength)
offset
- the first base in the read to copydestination
- the destination array.destinationOffset
- the first base in the array to copy to.maxLength
- the maximum number of bases to copy.java.lang.IllegalArgumentException
- if any of:
destination
is null
,offset
for the read bases and destinationOffset
for destination
).destination
to hold to all the bases copied
(NOTE: a large maxLength
value won't result in an exception if the read does not have enough bases to overflow destination
)default int copyBaseQualities(int offset, byte[] destination, int destinationOffset, int maxLength)
offset
- the first base-quality in the read to copydestination
- the destination array.destinationOffset
- the first base-quality in the array to copy to.maxLength
- the maximum number of base-qualities to copy.java.lang.IllegalArgumentException
- if any of:
destination
is null
,offset
for the read base-qualities and destinationOffset
for destination
).destination
to hold to all the base-qualities copied
(NOTE: a large maxLength
value won't result in an exception if the read does not have enough base-qualities to overflow destination
)default boolean hasBases()
default boolean hasBaseQualities()
true
iff there is at least one base-quality.default byte getBase(int i)
java.lang.IllegalArgumentException
- if i is negative or of i is not smaller than the number
of bases (as reported by getLength()
. In particular, if no sequence is present.default java.lang.String getBasesString()
ReadConstants.NULL_SEQUENCE_STRING
if the read is empty.void setBases(byte[] bases)
bases
- The read sequence as ASCII bytes ACGTN=. May be empty or null if no sequence is present.byte[] getBaseQualities()
default byte[] getBaseQualitiesNoCopy()
getBaseQualities()
in that implementations are free to avoid making a
defensive copy, if it's possible to avoid a copy.
WARNING: This method MAY NOT make a defensive copy of the base qualities array before returning it, so modifying
the returned array MAY alter the base qualities in the read. CALLER BEWARE!default int getBaseQualityCount()
default byte getBaseQuality(int i)
java.lang.IllegalArgumentException
- if i is negative or of i is not smaller than the number
of base qualities (as reported by getBaseQualityCount()
.void setBaseQualities(byte[] baseQualities)
baseQualities
- Base qualities as binary phred scores (not ASCII); negative values not allowed.
May be empty or null if no base qualities are present.java.lang.IllegalArgumentException
- if an invalid (negative) base quality is providedhtsjdk.samtools.Cigar getCigar()
default java.util.List<htsjdk.samtools.CigarElement> getCigarElements()
default htsjdk.samtools.CigarElement getCigarElement(int i)
getCigarElements().get(i)
.
Subclasses may override, for example to reduce the memory allocation or improve speed.java.lang.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= numCigarElements()
)default int numCigarElements()
getCigar().numCigarElements()
.
Subclasses may override to provide more efficient implementations.void setCigar(htsjdk.samtools.Cigar cigar)
Cigar
object describing how the read aligns to the reference.cigar
- Cigar
object describing how the read aligns to the reference; May be null or empty
if the read has none.void setCigar(java.lang.String cigarString)
cigarString
- Cigar String describing how the read aligns to the reference; May be null or empty
if the read has none.java.lang.String getReadGroup()
null
for none.void setReadGroup(java.lang.String readGroupID)
null
for none.readGroupID
- ID of the read group this read belongs to, or null
for none.boolean isPaired()
GATKException.MissingReadField
- if this information is not availablevoid setIsPaired(boolean isPaired)
setIsProperlyPaired(boolean)
were invoked with false.isPaired
- True if this read is paired (ie., has a mate), otherwise false.boolean isProperlyPaired()
GATKException.MissingReadField
- if this information is not availablevoid setIsProperlyPaired(boolean isProperlyPaired)
setIsPaired(boolean)
were invoked with true.isProperlyPaired
- True if this read is paired and the orientation and the distance between reads from
the fragment are consistent with the sequencing protocol, otherwise false.boolean isUnmapped()
void setIsUnmapped()
setPosition(java.lang.String, int)
boolean isUnplaced()
void setIsUnplaced()
ReadConstants.UNSET_CONTIG
and position to ReadConstants.UNSET_POSITION
).
NOTE: this does not remove the cigar string from the read, use setCigar(Cigar)
To mark a read as mapped, use setPosition(java.lang.String, int)
boolean mateIsUnmapped()
java.lang.IllegalStateException
- if the read is not paired (has no mate)void setMateIsUnmapped()
ReadConstants.UNSET_CONTIG
and position to ReadConstants.UNSET_POSITION
).
To mark the read's mate as mapped, use setMatePosition(java.lang.String, int)
Calling this method has the additional effect of marking the read as paired, as if setIsPaired(boolean)
were invoked with true.boolean mateIsUnplaced()
void setMateIsUnplaced()
setMateIsUnmapped()
,
this method will revert the mapping information for the mate (i.e. sets the mate's contig to "*" and position to 0).
To mark the read's mate as mapped, use setMatePosition(java.lang.String, int)
Calling this method has the additional effect of marking the read as paired, as if setIsPaired(boolean)
were invoked with true.boolean isReverseStrand()
GATKException.MissingReadField
- if this information is not availablevoid setIsReverseStrand(boolean isReverseStrand)
isReverseStrand
- True if this read is on the reverse strand as opposed to the forward strand, otherwise false.boolean mateIsReverseStrand()
java.lang.IllegalStateException
- if the read is not paired (has no mate)GATKException.MissingReadField
- if this information is not availablevoid setMateIsReverseStrand(boolean mateIsReverseStrand)
setIsPaired(boolean)
were invoked with true.mateIsReverseStrand
- True if this read's mate is on the reverse strand as opposed to the forward strand,
otherwise false.boolean isFirstOfPair()
GATKException.MissingReadField
- if this information is not availablevoid setIsFirstOfPair()
setIsPaired(boolean)
were invoked with true, and also marks the read as NOT being the second of a pair.boolean isSecondOfPair()
GATKException.MissingReadField
- if this information is not availablevoid setIsSecondOfPair()
setIsPaired(boolean)
were invoked with true, and also marks the read as NOT being the first of a pair.boolean isSecondaryAlignment()
GATKException.MissingReadField
- if this information is not availablevoid setIsSecondaryAlignment(boolean isSecondaryAlignment)
isSecondaryAlignment
- True if this is a secondary alignment, otherwise false.boolean isSupplementaryAlignment()
GATKException.MissingReadField
- if this information is not availablevoid setIsSupplementaryAlignment(boolean isSupplementaryAlignment)
isSupplementaryAlignment
- True if this is a supplementary alignment, otherwise false.default java.util.Optional<htsjdk.samtools.SamPairUtil.PairOrientation> getPairOrientation()
java.lang.IllegalArgumentException
- If the read is not paired, or if either read or mate is unmappedboolean failsVendorQualityCheck()
GATKException.MissingReadField
- if this information is not availablevoid setFailsVendorQualityCheck(boolean failsVendorQualityCheck)
failsVendorQualityCheck
- True if this read fails platform/vendor quality checks, otherwise falseboolean isDuplicate()
GATKException.MissingReadField
- if this information is not availablevoid setIsDuplicate(boolean isDuplicate)
isDuplicate
- True if this read is a PCR or optical duplicate, otherwise false.boolean hasAttribute(java.lang.String attributeName)
attributeName
- name of the attribute to search forjava.lang.Integer getAttributeAsInteger(java.lang.String attributeName)
attributeName
- name of the attribute to retrievenull
if the attribute is not presentGATKException.ReadAttributeTypeMismatch
- if the attribute
value cannot be typed as an integerjava.lang.String getAttributeAsString(java.lang.String attributeName)
attributeName
- name of the attribute to retrievenull
if the attribute is not presentGATKException.ReadAttributeTypeMismatch
- if the attribute
value cannot be typed as a single String value.byte[] getAttributeAsByteArray(java.lang.String attributeName)
attributeName
- name of the attribute to retrievenull
if the attribute is not presentGATKException.ReadAttributeTypeMismatch
- if the attribute
value cannot be typed as a byte array.java.lang.Object getTransientAttribute(java.lang.Object key)
key
- key whose value is to be storeddefault <T> java.util.Optional<T> getOptionalTransientAttribute(java.lang.Object key, java.lang.Class<T> clazz)
Optional
.T
- the parametric type of the attribute value.key
- the key to the attribute.clazz
- the expected clazz of the attribute value.null
but a not-present optional instead.void setAttribute(java.lang.String attributeName, java.lang.Integer attributeValue)
attributeName
- Name of the attribute to set. Must be legal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
attributeValue
- Integer value of the attribute (may be null
)java.lang.IllegalArgumentException
- if the attribute name is illegal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
void setAttribute(java.lang.String attributeName, java.lang.String attributeValue)
attributeName
- Name of the attribute to set. Must be legal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
attributeValue
- String value of the attribute (may be null
)java.lang.IllegalArgumentException
- if the attribute name is illegal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
void setAttribute(java.lang.String attributeName, byte[] attributeValue)
attributeName
- Name of the attribute to set. Must be legal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
attributeValue
- byte array value of the attribute (may be null
or empty)java.lang.IllegalArgumentException
- if the attribute name is illegal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
void setTransientAttribute(java.lang.Object key, java.lang.Object value)
key
- key under which the value will be storedvalue
- value to storevoid clearAttribute(java.lang.String attributeName)
attributeName
- Name of the attribute to clear. Must be legal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
java.lang.IllegalArgumentException
- if the attribute name is illegal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
void clearAttributes()
void clearTransientAttribute(java.lang.String attributeName)
attributeName
- Name of the attribute to clear. Must be legal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
java.lang.IllegalArgumentException
- if the attribute name is illegal according to ReadUtils.assertAttributeNameIsLegal(java.lang.String)
GATKRead copy()
GATKRead deepCopy()
htsjdk.samtools.SAMRecord convertToSAMRecord(htsjdk.samtools.SAMFileHeader header)
header
- required header for the SAMRecordjava.lang.String getSAMString()
void reverseComplement()
default java.lang.String commonToString()