Package htsjdk.samtools.sra
Class SRALazyRecord
java.lang.Object
htsjdk.samtools.SAMRecord
htsjdk.samtools.sra.SRALazyRecord
- All Implemented Interfaces:
HtsRecord
,Locatable
,Serializable
,Cloneable
Extends SAMRecord so that any of the fields will be loaded only when needed.
Since SRA is a column oriented database, it is very inefficient to load all the fields at once.
However, loading only set of actually needed fields will be even faster than in row oriented databases.
Because of that we are providing lazy loading of fields, flags and attributes.
Created by andrii.nikitiuk on 8/25/15.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class htsjdk.samtools.SAMRecord
SAMRecord.SAMTagAndValue
-
Field Summary
Fields inherited from class htsjdk.samtools.SAMRecord
MAX_INSERT_SIZE, mMateReferenceIndex, mReferenceIndex, NO_ALIGNMENT_CIGAR, NO_ALIGNMENT_REFERENCE_INDEX, NO_ALIGNMENT_REFERENCE_NAME, NO_ALIGNMENT_START, NO_MAPPING_QUALITY, NULL_QUALS, NULL_QUALS_STRING, NULL_SEQUENCE, NULL_SEQUENCE_STRING, serialVersionUID, TAGS_TO_REVERSE, TAGS_TO_REVERSE_COMPLEMENT, UNKNOWN_MAPPING_QUALITY
-
Constructor Summary
ModifierConstructorDescriptionprotected
SRALazyRecord
(SAMFileHeader header, SRAAccession accession, String readId, int unalignedReadFragmentIndex) protected
SRALazyRecord
(SAMFileHeader header, SRAAccession accession, String readId, String alignmentId) SRALazyRecord
(SAMFileHeader header, SRAAccession accession, ngs.ReadCollection run, ngs.AlignmentIterator alignmentIterator, String readId, String alignmentId) SRALazyRecord
(SAMFileHeader header, SRAAccession accession, ngs.ReadCollection run, ngs.ReadIterator unalignmentIterator, String readId, int unalignedReadFragmentIndex) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Removes all attributes.clone()
Performs a deep copy of the SAMRecord and detaches a copy from NGS iteratorvoid
Is being called when original NGS iterator is being moved to the next object.boolean
For records equality, we should only compare read id, reference and position on the reference.format()
int
getAttribute
(short tag) byte[]
Do not modify the value returned by this method.protected SAMBinaryTagAndValue
getCigar()
Do not modify the value returned by this method.boolean
the read is the first read in a pair.int
getFlags()
It is preferable to use the get*Flag() methods that handle the flag word symbolically.int
int
int
boolean
strand of the mate (false for forward; true for reverse strand).Returns the mate reference index for this record.boolean
the mate is unmapped.boolean
the read is mapped in a proper pair (depends on the protocol, normally inferred during alignment).byte[]
Do not modify the value returned by this method.boolean
strand of the query (false for forward; true for reverse strand).boolean
the read is paired in sequencing, no matter whether it is mapped in a pair.Returns the reference index for this record.boolean
the read is the second read in a pair.int
hashCode()
The same approach as with 'equals' method.boolean
boolean
isValid
(boolean firstOnly) Perform various validations of SAMRecord.void
setAlignmentStart
(int value) void
setAttribute
(short tag, Object value) protected void
setAttribute
(short tag, Object value, boolean isUnsignedArray) protected void
setAttributes
(SAMBinaryTagAndValue attributes) Replace any existing attributes with the given linked item.void
setBaseQualities
(byte[] value) void
For setting the Cigar string when changed.void
setCigarString
(String value) void
setFirstOfPairFlag
(boolean flag) the read is the first read in a pair.void
setFlags
(int value) void
setInferredInsertSize
(int value) void
setMappingQuality
(int value) void
setMateAlignmentStart
(int value) void
setMateNegativeStrandFlag
(boolean flag) strand of the mate (false for forward; true for reverse strand).void
setMateReferenceIndex
(int value) Updates the mate reference index.void
setMateReferenceName
(String value) Sets the mate reference name for this record.void
setMateUnmappedFlag
(boolean flag) the mate is unmapped.void
setProperPairFlag
(boolean flag) the read is mapped in a proper pair (depends on the protocol, normally inferred during alignment).void
setReadBases
(byte[] value) void
setReadNegativeStrandFlag
(boolean flag) strand of the query (false for forward; true for reverse strand).void
setReadPairedFlag
(boolean flag) the read is paired in sequencing, no matter whether it is mapped in a pair.void
setReferenceIndex
(int value) Updates the reference index.void
setReferenceName
(String value) Sets the reference name for this record.void
setSecondaryAlignment
(boolean flag) set whether this alignment is secondary (an alternative alignment of the read).void
setSecondOfPairFlag
(boolean flag) the read is the second read in a pair.Methods inherited from class htsjdk.samtools.SAMRecord
computeIndexingBinIfAbsent, deepCopy, eagerDecode, getAlignmentBlocks, getAlignmentEnd, getAttribute, getAttribute, getAttributes, getAttributesBinarySize, getBaseQualityString, getByteArrayAttribute, getByteArrayAttribute, getByteAttribute, getByteAttribute, getCharacterAttribute, getCharacterAttribute, getCigarLength, getContig, getDuplicateReadFlag, getEnd, getFileSource, getFloatArrayAttribute, getFloatArrayAttribute, getFloatAttribute, getFloatAttribute, getHeader, getIntegerAttribute, getIntegerAttribute, getNotPrimaryAlignmentFlag, getOriginalBaseQualities, getPairedReadName, getReadFailsVendorQualityCheckFlag, getReadGroup, getReadLength, getReadName, getReadNameLength, getReadPositionAtReferencePosition, getReadPositionAtReferencePosition, getReadPositionAtReferencePosition, getReadString, getReadUnmappedFlag, getReferencePositionAtReadPosition, getReferencePositionAtReadPosition, getSAMFlags, getSAMString, getShortAttribute, getShortAttribute, getSignedByteArrayAttribute, getSignedByteArrayAttribute, getSignedIntArrayAttribute, getSignedIntArrayAttribute, getSignedShortArrayAttribute, getSignedShortArrayAttribute, getStart, getStringAttribute, getStringAttribute, getSupplementaryAlignmentFlag, getTransientAttribute, getUnclippedEnd, getUnclippedStart, getUnsignedByteArrayAttribute, getUnsignedByteArrayAttribute, getUnsignedIntArrayAttribute, getUnsignedIntArrayAttribute, getUnsignedIntegerAttribute, getUnsignedIntegerAttribute, getUnsignedIntegerAttribute, getUnsignedShortArrayAttribute, getUnsignedShortArrayAttribute, getValidationStringency, getVariableBinaryRepresentation, hasAttribute, hasAttribute, initializeCigar, isAllowedAttributeValue, isSecondaryOrSupplementary, isValid, removeTransientAttribute, resolveIndexFromName, resolveNameFromIndex, reverseComplement, reverseComplement, reverseComplement, setAttribute, setAttribute, setAttribute, setBaseQualityString, setDuplicateReadFlag, setFileSource, setHeader, setHeaderStrict, setNotPrimaryAlignmentFlag, setOriginalBaseQualities, setReadFailsVendorQualityCheckFlag, setReadName, setReadString, setReadUmappedFlag, setReadUnmappedFlag, setSupplementaryAlignmentFlag, setTransientAttribute, setUnsignedArrayAttribute, setValidationStringency, toString, validateCigar
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface htsjdk.samtools.util.Locatable
contains, contigsMatch, getLengthOnReference, overlaps, withinDistanceOf
-
Constructor Details
-
SRALazyRecord
public SRALazyRecord(SAMFileHeader header, SRAAccession accession, ngs.ReadCollection run, ngs.AlignmentIterator alignmentIterator, String readId, String alignmentId) -
SRALazyRecord
public SRALazyRecord(SAMFileHeader header, SRAAccession accession, ngs.ReadCollection run, ngs.ReadIterator unalignmentIterator, String readId, int unalignedReadFragmentIndex) -
SRALazyRecord
protected SRALazyRecord(SAMFileHeader header, SRAAccession accession, String readId, String alignmentId) -
SRALazyRecord
protected SRALazyRecord(SAMFileHeader header, SRAAccession accession, String readId, int unalignedReadFragmentIndex)
-
-
Method Details
-
detachFromIterator
public void detachFromIterator()Is being called when original NGS iterator is being moved to the next object. Later, if any of uninitialized fields is requested, either Read object or Alignment has to be retrieved from ReadCollection -
getAlignmentStart
public int getAlignmentStart()- Overrides:
getAlignmentStart
in classSAMRecord
- Returns:
- 1-based inclusive leftmost position of the sequence remaining after clipping, or 0 if there is no position, e.g. for unmapped read.
-
setAlignmentStart
public void setAlignmentStart(int value) - Overrides:
setAlignmentStart
in classSAMRecord
- Parameters:
value
- 1-based inclusive leftmost position of the sequence remaining after clipping or 0 if there is no position, e.g. for unmapped read.
-
getMappingQuality
public int getMappingQuality()- Overrides:
getMappingQuality
in classSAMRecord
- Returns:
- phred scaled mapping quality. 255 implies valid mapping but quality is hard to compute.
-
setMappingQuality
public void setMappingQuality(int value) - Overrides:
setMappingQuality
in classSAMRecord
-
getReferenceName
- Overrides:
getReferenceName
in classSAMRecord
- Returns:
- Reference name, or NO_ALIGNMENT_REFERENCE_NAME (*) if the record has no reference name
-
setReferenceName
Description copied from class:SAMRecord
Sets the reference name for this record. If the record has a valid SAMFileHeader and the reference name is present in the associated sequence dictionary, the record's reference index will also be updated with the corresponding sequence index. If referenceName is NO_ALIGNMENT_REFERENCE_NAME, sets the reference index to NO_ALIGNMENT_REFERENCE_INDEX.- Overrides:
setReferenceName
in classSAMRecord
- Parameters:
value
- - must not be null
-
getReferenceIndex
Description copied from class:SAMRecord
Returns the reference index for this record. If the reference name for this record has previously been resolved against the sequence dictionary, the corresponding index is returned directly. Otherwise, the record must have a non-null SAMFileHeader that can be used to resolve the index for the record's current reference name, unless the reference name is NO_ALIGNMENT_REFERENCE_NAME. If the record has a header, and the name does not appear in the header's sequence dictionary, the value NO_ALIGNMENT_REFERENCE_INDEX (-1) will be returned. If the record does not have a header, an IllegalStateException is thrown.- Overrides:
getReferenceIndex
in classSAMRecord
- Returns:
- Index in the sequence dictionary of the reference sequence. If the read has no reference sequence, or if the reference name is not found in the sequence index, NO_ALIGNMENT_REFERENCE_INDEX (-1) is returned.
-
setReferenceIndex
public void setReferenceIndex(int value) Description copied from class:SAMRecord
Updates the reference index. The record must have a valid SAMFileHeader unless the referenceIndex parameter equals NO_ALIGNMENT_REFERENCE_INDEX, and the reference index must appear in the header's sequence dictionary. If the reference index is valid, the reference name will also be resolved and updated to the name for the sequence dictionary entry corresponding to the index.- Overrides:
setReferenceIndex
in classSAMRecord
- Parameters:
value
- Must either equal NO_ALIGNMENT_REFERENCE_INDEX (-1) indicating no reference, or the record must have a SAMFileHeader and the index must exist in the associated sequence dictionary.
-
getCigarString
- Overrides:
getCigarString
in classSAMRecord
-
setCigarString
- Overrides:
setCigarString
in classSAMRecord
-
getCigar
Description copied from class:SAMRecord
Do not modify the value returned by this method. If you want to change the Cigar, create a new Cigar and call setCigar() or call setCigarString() -
setCigar
Description copied from class:SAMRecord
For setting the Cigar string when changed. Note that this nulls the indexing bin, which would need to be recomputed on write (if needed). To avoid clobbering the indexing bin, useSAMRecord.initializeCigar(htsjdk.samtools.Cigar)
-
getReadBases
public byte[] getReadBases()Description copied from class:SAMRecord
Do not modify the value returned by this method. If you want to change the bases, create a new byte[] and call setReadBases() or call setReadString().- Overrides:
getReadBases
in classSAMRecord
- Returns:
- read sequence as ASCII bytes ACGTN=.
-
setReadBases
public void setReadBases(byte[] value) - Overrides:
setReadBases
in classSAMRecord
-
getBaseQualities
public byte[] getBaseQualities()Description copied from class:SAMRecord
Do not modify the value returned by this method. If you want to change the qualities, create a new byte[] and call setBaseQualities() or call setBaseQualityString().- Overrides:
getBaseQualities
in classSAMRecord
- Returns:
- Base qualities, as binary phred scores (not ASCII).
-
setBaseQualities
public void setBaseQualities(byte[] value) - Overrides:
setBaseQualities
in classSAMRecord
-
getMateAlignmentStart
public int getMateAlignmentStart()- Overrides:
getMateAlignmentStart
in classSAMRecord
- Returns:
- 1-based inclusive leftmost position of the clipped mate sequence, or 0 if there is no position.
-
setMateAlignmentStart
public void setMateAlignmentStart(int value) - Overrides:
setMateAlignmentStart
in classSAMRecord
-
getMateReferenceName
- Overrides:
getMateReferenceName
in classSAMRecord
- Returns:
- Mate reference name, or NO_ALIGNMENT_REFERENCE_NAME (*) if the record has no mate reference name
-
setMateReferenceName
Description copied from class:SAMRecord
Sets the mate reference name for this record. If the record has a valid SAMFileHeader and the mate reference name is present in the associated sequence dictionary, the record's mate reference index will also be updated with the corresponding sequence index. If mateReferenceName is NO_ALIGNMENT_REFERENCE_NAME, sets the mate reference index to NO_ALIGNMENT_REFERENCE_INDEX.- Overrides:
setMateReferenceName
in classSAMRecord
- Parameters:
value
- - must not be null
-
getMateReferenceIndex
Description copied from class:SAMRecord
Returns the mate reference index for this record. If the mate reference name for this record has previously been resolved against the sequence dictionary, the corresponding index is returned directly. Otherwise, the record must have a non-null SAMFileHeader that can be used to resolve the index for the record's current mate reference name, unless the mate reference name is NO_ALIGNMENT_REFERENCE_NAME. If the record has a header, and the name does not appear in the header's sequence dictionary, the value NO_ALIGNMENT_REFERENCE_INDEX (-1) will be returned. If the record does not have a header, an IllegalStateException is thrown.- Overrides:
getMateReferenceIndex
in classSAMRecord
- Returns:
- Index in the sequence dictionary of the mate reference sequence. If the read has no mate reference sequence, or if the mate reference name is not found in the sequence index, NO_ALIGNMENT_REFERENCE_INDEX (-1) is returned.
-
setMateReferenceIndex
public void setMateReferenceIndex(int value) Description copied from class:SAMRecord
Updates the mate reference index. The record must have a valid SAMFileHeader, and the mate reference index must appear in the header's sequence dictionary, unless the mateReferenceIndex parameter equals NO_ALIGNMENT_REFERENCE_INDEX. If the mate reference index is valid, the mate reference name will also be resolved and updated to the name for the sequence dictionary entry corresponding to the index.- Overrides:
setMateReferenceIndex
in classSAMRecord
- Parameters:
value
- Must either equal NO_ALIGNMENT_REFERENCE_INDEX (-1) indicating no reference, or the record must have a SAMFileHeader and the index must exist in the associated sequence dictionary.
-
getInferredInsertSize
public int getInferredInsertSize()- Overrides:
getInferredInsertSize
in classSAMRecord
- Returns:
- insert size (difference btw 5' end of read & 5' end of mate), if possible, else 0. Negative if mate maps to lower position than read.
-
setInferredInsertSize
public void setInferredInsertSize(int value) - Overrides:
setInferredInsertSize
in classSAMRecord
-
getFlags
public int getFlags()Description copied from class:SAMRecord
It is preferable to use the get*Flag() methods that handle the flag word symbolically. -
setFlags
public void setFlags(int value) -
getReadNegativeStrandFlag
public boolean getReadNegativeStrandFlag()Description copied from class:SAMRecord
strand of the query (false for forward; true for reverse strand).- Overrides:
getReadNegativeStrandFlag
in classSAMRecord
-
setReadNegativeStrandFlag
public void setReadNegativeStrandFlag(boolean flag) Description copied from class:SAMRecord
strand of the query (false for forward; true for reverse strand).- Overrides:
setReadNegativeStrandFlag
in classSAMRecord
-
getReadPairedFlag
public boolean getReadPairedFlag()Description copied from class:SAMRecord
the read is paired in sequencing, no matter whether it is mapped in a pair.- Overrides:
getReadPairedFlag
in classSAMRecord
-
setReadPairedFlag
public void setReadPairedFlag(boolean flag) Description copied from class:SAMRecord
the read is paired in sequencing, no matter whether it is mapped in a pair.- Overrides:
setReadPairedFlag
in classSAMRecord
-
getProperPairFlag
public boolean getProperPairFlag()Description copied from class:SAMRecord
the read is mapped in a proper pair (depends on the protocol, normally inferred during alignment).- Overrides:
getProperPairFlag
in classSAMRecord
-
setProperPairFlag
public void setProperPairFlag(boolean flag) Description copied from class:SAMRecord
the read is mapped in a proper pair (depends on the protocol, normally inferred during alignment).- Overrides:
setProperPairFlag
in classSAMRecord
-
isSecondaryAlignment
public boolean isSecondaryAlignment()- Overrides:
isSecondaryAlignment
in classSAMRecord
- Returns:
- whether the alignment is secondary (an alternative alignment of the read).
-
setSecondaryAlignment
public void setSecondaryAlignment(boolean flag) Description copied from class:SAMRecord
set whether this alignment is secondary (an alternative alignment of the read).- Overrides:
setSecondaryAlignment
in classSAMRecord
-
getMateNegativeStrandFlag
public boolean getMateNegativeStrandFlag()Description copied from class:SAMRecord
strand of the mate (false for forward; true for reverse strand).- Overrides:
getMateNegativeStrandFlag
in classSAMRecord
-
setMateNegativeStrandFlag
public void setMateNegativeStrandFlag(boolean flag) Description copied from class:SAMRecord
strand of the mate (false for forward; true for reverse strand).- Overrides:
setMateNegativeStrandFlag
in classSAMRecord
-
getMateUnmappedFlag
public boolean getMateUnmappedFlag()Description copied from class:SAMRecord
the mate is unmapped.- Overrides:
getMateUnmappedFlag
in classSAMRecord
-
setMateUnmappedFlag
public void setMateUnmappedFlag(boolean flag) Description copied from class:SAMRecord
the mate is unmapped.- Overrides:
setMateUnmappedFlag
in classSAMRecord
-
getFirstOfPairFlag
public boolean getFirstOfPairFlag()Description copied from class:SAMRecord
the read is the first read in a pair.- Overrides:
getFirstOfPairFlag
in classSAMRecord
-
setFirstOfPairFlag
public void setFirstOfPairFlag(boolean flag) Description copied from class:SAMRecord
the read is the first read in a pair.- Overrides:
setFirstOfPairFlag
in classSAMRecord
-
getSecondOfPairFlag
public boolean getSecondOfPairFlag()Description copied from class:SAMRecord
the read is the second read in a pair.- Overrides:
getSecondOfPairFlag
in classSAMRecord
-
setSecondOfPairFlag
public void setSecondOfPairFlag(boolean flag) Description copied from class:SAMRecord
the read is the second read in a pair.- Overrides:
setSecondOfPairFlag
in classSAMRecord
-
getAttribute
- Overrides:
getAttribute
in classSAMRecord
- Parameters:
tag
- Binary representation of a 2-char String tag as created by SAMTagUtil.- See Also:
-
setAttribute
- Overrides:
setAttribute
in classSAMRecord
- Parameters:
tag
- Binary representation of a 2-char String tag as created by SAMTagUtil.- See Also:
-
setAttribute
- Overrides:
setAttribute
in classSAMRecord
-
clearAttributes
public void clearAttributes()Description copied from class:SAMRecord
Removes all attributes.- Overrides:
clearAttributes
in classSAMRecord
-
setAttributes
Description copied from class:SAMRecord
Replace any existing attributes with the given linked item. NOTE: this method is intended to only be called from subclasses.- Overrides:
setAttributes
in classSAMRecord
-
getBinaryAttributes
- Overrides:
getBinaryAttributes
in classSAMRecord
- Returns:
- Pointer to the first of the tags. Returns null if there are no tags.
-
isUnsignedArrayAttribute
- Overrides:
isUnsignedArrayAttribute
in classSAMRecord
- Returns:
- True if this tag is an unsigned array, else false.
-
equals
For records equality, we should only compare read id, reference and position on the reference. Since read id is a constructor parameter, we only need to make sure that reference info is loaded. -
hashCode
public int hashCode()The same approach as with 'equals' method. We only load reference and position. -
clone
Performs a deep copy of the SAMRecord and detaches a copy from NGS iterator- Overrides:
clone
in classSAMRecord
- Returns:
- new object
- Throws:
CloneNotSupportedException
-
format
-
isValid
Description copied from class:SAMRecord
Perform various validations of SAMRecord. Note that this method deliberately returns null rather than Collections.emptyList() if there are no validation errors, because callers tend to assume that if a non-null list is returned, it is modifiable. A record with null a header may be validated by the isValid method, but the reference and mate reference indices, read group, sequence dictionary, and alignment start will not be fully validated unless a header is present.
-