Package htsjdk.samtools.sra
Class SRALazyRecord
- java.lang.Object
-
- htsjdk.samtools.SAMRecord
-
- htsjdk.samtools.sra.SRALazyRecord
-
- All Implemented Interfaces:
Locatable,Serializable,Cloneable
public class SRALazyRecord extends SAMRecord
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:
- Serialized Form
-
-
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
Constructors Modifier Constructor Description protectedSRALazyRecord(SAMFileHeader header, SRAAccession accession, String readId, int unalignedReadFragmentIndex)protectedSRALazyRecord(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearAttributes()Removes all attributes.Objectclone()Performs a deep copy of the SAMRecord and detaches a copy from NGS iteratorvoiddetachFromIterator()Is being called when original NGS iterator is being moved to the next object.booleanequals(Object o)For records equality, we should only compare read id, reference and position on the reference.Stringformat()intgetAlignmentStart()ObjectgetAttribute(short tag)byte[]getBaseQualities()Do not modify the value returned by this method.protected SAMBinaryTagAndValuegetBinaryAttributes()CigargetCigar()Do not modify the value returned by this method.StringgetCigarString()booleangetFirstOfPairFlag()the read is the first read in a pair.intgetFlags()It is preferable to use the get*Flag() methods that handle the flag word symbolically.intgetInferredInsertSize()intgetMappingQuality()intgetMateAlignmentStart()booleangetMateNegativeStrandFlag()strand of the mate (false for forward; true for reverse strand).IntegergetMateReferenceIndex()Returns the mate reference index for this record.StringgetMateReferenceName()booleangetMateUnmappedFlag()the mate is unmapped.booleangetProperPairFlag()the read is mapped in a proper pair (depends on the protocol, normally inferred during alignment).byte[]getReadBases()Do not modify the value returned by this method.booleangetReadNegativeStrandFlag()strand of the query (false for forward; true for reverse strand).booleangetReadPairedFlag()the read is paired in sequencing, no matter whether it is mapped in a pair.IntegergetReferenceIndex()Returns the reference index for this record.StringgetReferenceName()booleangetSecondOfPairFlag()the read is the second read in a pair.inthashCode()The same approach as with 'equals' method.booleanisSecondaryAlignment()booleanisUnsignedArrayAttribute(String tag)List<SAMValidationError>isValid(boolean firstOnly)Perform various validations of SAMRecord.voidsetAlignmentStart(int value)voidsetAttribute(short tag, Object value)protected voidsetAttribute(short tag, Object value, boolean isUnsignedArray)protected voidsetAttributes(SAMBinaryTagAndValue attributes)Replace any existing attributes with the given linked item.voidsetBaseQualities(byte[] value)voidsetCigar(Cigar value)For setting the Cigar string when changed.voidsetCigarString(String value)voidsetFirstOfPairFlag(boolean flag)the read is the first read in a pair.voidsetFlags(int value)voidsetInferredInsertSize(int value)voidsetMappingQuality(int value)voidsetMateAlignmentStart(int value)voidsetMateNegativeStrandFlag(boolean flag)strand of the mate (false for forward; true for reverse strand).voidsetMateReferenceIndex(int value)Updates the mate reference index.voidsetMateReferenceName(String value)Sets the mate reference name for this record.voidsetMateUnmappedFlag(boolean flag)the mate is unmapped.voidsetProperPairFlag(boolean flag)the read is mapped in a proper pair (depends on the protocol, normally inferred during alignment).voidsetReadBases(byte[] value)voidsetReadNegativeStrandFlag(boolean flag)strand of the query (false for forward; true for reverse strand).voidsetReadPairedFlag(boolean flag)the read is paired in sequencing, no matter whether it is mapped in a pair.voidsetReferenceIndex(int value)Updates the reference index.voidsetReferenceName(String value)Sets the reference name for this record.voidsetSecondaryAlignment(boolean flag)set whether this alignment is secondary (an alternative alignment of the read).voidsetSecondOfPairFlag(boolean flag)the read is the second read in a pair.-
Methods inherited from class htsjdk.samtools.SAMRecord
computeIndexingBinIfAbsent, deepCopy, eagerDecode, getAlignmentBlocks, getAlignmentEnd, getAttribute, getAttributes, getAttributesBinarySize, getBaseQualityString, getByteArrayAttribute, getByteAttribute, getCharacterAttribute, getCigarLength, getContig, getDuplicateReadFlag, getEnd, getFileSource, getFloatArrayAttribute, getFloatAttribute, getHeader, getIntegerAttribute, getNotPrimaryAlignmentFlag, getOriginalBaseQualities, getPairedReadName, getReadFailsVendorQualityCheckFlag, getReadGroup, getReadLength, getReadName, getReadNameLength, getReadPositionAtReferencePosition, getReadPositionAtReferencePosition, getReadPositionAtReferencePosition, getReadString, getReadUnmappedFlag, getReferencePositionAtReadPosition, getReferencePositionAtReadPosition, getSAMFlags, getSAMString, getShortAttribute, getSignedByteArrayAttribute, getSignedIntArrayAttribute, getSignedShortArrayAttribute, getStart, getStringAttribute, getSupplementaryAlignmentFlag, getTransientAttribute, getUnclippedEnd, getUnclippedStart, getUnsignedByteArrayAttribute, getUnsignedIntArrayAttribute, getUnsignedIntegerAttribute, getUnsignedIntegerAttribute, getUnsignedShortArrayAttribute, getValidationStringency, getVariableBinaryRepresentation, hasAttribute, initializeCigar, isAllowedAttributeValue, isSecondaryOrSupplementary, isValid, removeTransientAttribute, resolveIndexFromName, resolveNameFromIndex, reverseComplement, reverseComplement, reverseComplement, 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 Detail
-
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 Detail
-
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:
getAlignmentStartin 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:
setAlignmentStartin 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:
getMappingQualityin classSAMRecord- Returns:
- phred scaled mapping quality. 255 implies valid mapping but quality is hard to compute.
-
setMappingQuality
public void setMappingQuality(int value)
- Overrides:
setMappingQualityin classSAMRecord
-
getReferenceName
public String getReferenceName()
- Overrides:
getReferenceNamein classSAMRecord- Returns:
- Reference name, or NO_ALIGNMENT_REFERENCE_NAME (*) if the record has no reference name
-
setReferenceName
public void setReferenceName(String value)
Description copied from class:SAMRecordSets 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:
setReferenceNamein classSAMRecord- Parameters:
value- - must not be null
-
getReferenceIndex
public Integer getReferenceIndex()
Description copied from class:SAMRecordReturns 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:
getReferenceIndexin 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:SAMRecordUpdates 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:
setReferenceIndexin 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
public String getCigarString()
- Overrides:
getCigarStringin classSAMRecord
-
setCigarString
public void setCigarString(String value)
- Overrides:
setCigarStringin classSAMRecord
-
getCigar
public Cigar getCigar()
Description copied from class:SAMRecordDo 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
public void setCigar(Cigar value)
Description copied from class:SAMRecordFor 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:SAMRecordDo 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:
getReadBasesin classSAMRecord- Returns:
- read sequence as ASCII bytes ACGTN=.
-
setReadBases
public void setReadBases(byte[] value)
- Overrides:
setReadBasesin classSAMRecord
-
getBaseQualities
public byte[] getBaseQualities()
Description copied from class:SAMRecordDo 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:
getBaseQualitiesin classSAMRecord- Returns:
- Base qualities, as binary phred scores (not ASCII).
-
setBaseQualities
public void setBaseQualities(byte[] value)
- Overrides:
setBaseQualitiesin classSAMRecord
-
getMateAlignmentStart
public int getMateAlignmentStart()
- Overrides:
getMateAlignmentStartin 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:
setMateAlignmentStartin classSAMRecord
-
getMateReferenceName
public String getMateReferenceName()
- Overrides:
getMateReferenceNamein classSAMRecord- Returns:
- Mate reference name, or NO_ALIGNMENT_REFERENCE_NAME (*) if the record has no mate reference name
-
setMateReferenceName
public void setMateReferenceName(String value)
Description copied from class:SAMRecordSets 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:
setMateReferenceNamein classSAMRecord- Parameters:
value- - must not be null
-
getMateReferenceIndex
public Integer getMateReferenceIndex()
Description copied from class:SAMRecordReturns 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:
getMateReferenceIndexin 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:SAMRecordUpdates 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:
setMateReferenceIndexin 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:
getInferredInsertSizein 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:
setInferredInsertSizein classSAMRecord
-
getFlags
public int getFlags()
Description copied from class:SAMRecordIt is preferable to use the get*Flag() methods that handle the flag word symbolically.
-
getReadNegativeStrandFlag
public boolean getReadNegativeStrandFlag()
Description copied from class:SAMRecordstrand of the query (false for forward; true for reverse strand).- Overrides:
getReadNegativeStrandFlagin classSAMRecord
-
setReadNegativeStrandFlag
public void setReadNegativeStrandFlag(boolean flag)
Description copied from class:SAMRecordstrand of the query (false for forward; true for reverse strand).- Overrides:
setReadNegativeStrandFlagin classSAMRecord
-
getReadPairedFlag
public boolean getReadPairedFlag()
Description copied from class:SAMRecordthe read is paired in sequencing, no matter whether it is mapped in a pair.- Overrides:
getReadPairedFlagin classSAMRecord
-
setReadPairedFlag
public void setReadPairedFlag(boolean flag)
Description copied from class:SAMRecordthe read is paired in sequencing, no matter whether it is mapped in a pair.- Overrides:
setReadPairedFlagin classSAMRecord
-
getProperPairFlag
public boolean getProperPairFlag()
Description copied from class:SAMRecordthe read is mapped in a proper pair (depends on the protocol, normally inferred during alignment).- Overrides:
getProperPairFlagin classSAMRecord
-
setProperPairFlag
public void setProperPairFlag(boolean flag)
Description copied from class:SAMRecordthe read is mapped in a proper pair (depends on the protocol, normally inferred during alignment).- Overrides:
setProperPairFlagin classSAMRecord
-
isSecondaryAlignment
public boolean isSecondaryAlignment()
- Overrides:
isSecondaryAlignmentin classSAMRecord- Returns:
- whether the alignment is secondary (an alternative alignment of the read).
-
setSecondaryAlignment
public void setSecondaryAlignment(boolean flag)
Description copied from class:SAMRecordset whether this alignment is secondary (an alternative alignment of the read).- Overrides:
setSecondaryAlignmentin classSAMRecord
-
getMateNegativeStrandFlag
public boolean getMateNegativeStrandFlag()
Description copied from class:SAMRecordstrand of the mate (false for forward; true for reverse strand).- Overrides:
getMateNegativeStrandFlagin classSAMRecord
-
setMateNegativeStrandFlag
public void setMateNegativeStrandFlag(boolean flag)
Description copied from class:SAMRecordstrand of the mate (false for forward; true for reverse strand).- Overrides:
setMateNegativeStrandFlagin classSAMRecord
-
getMateUnmappedFlag
public boolean getMateUnmappedFlag()
Description copied from class:SAMRecordthe mate is unmapped.- Overrides:
getMateUnmappedFlagin classSAMRecord
-
setMateUnmappedFlag
public void setMateUnmappedFlag(boolean flag)
Description copied from class:SAMRecordthe mate is unmapped.- Overrides:
setMateUnmappedFlagin classSAMRecord
-
getFirstOfPairFlag
public boolean getFirstOfPairFlag()
Description copied from class:SAMRecordthe read is the first read in a pair.- Overrides:
getFirstOfPairFlagin classSAMRecord
-
setFirstOfPairFlag
public void setFirstOfPairFlag(boolean flag)
Description copied from class:SAMRecordthe read is the first read in a pair.- Overrides:
setFirstOfPairFlagin classSAMRecord
-
getSecondOfPairFlag
public boolean getSecondOfPairFlag()
Description copied from class:SAMRecordthe read is the second read in a pair.- Overrides:
getSecondOfPairFlagin classSAMRecord
-
setSecondOfPairFlag
public void setSecondOfPairFlag(boolean flag)
Description copied from class:SAMRecordthe read is the second read in a pair.- Overrides:
setSecondOfPairFlagin classSAMRecord
-
getAttribute
public Object getAttribute(short tag)
- Overrides:
getAttributein classSAMRecord- Parameters:
tag- Binary representation of a 2-char String tag as created by SAMTagUtil.- See Also:
SAMRecord.getAttribute(java.lang.String)
-
setAttribute
public void setAttribute(short tag, Object value)- Overrides:
setAttributein classSAMRecord- Parameters:
tag- Binary representation of a 2-char String tag as created by SAMTagUtil.- See Also:
SAMRecord.setAttribute(java.lang.String, java.lang.Object)
-
setAttribute
protected void setAttribute(short tag, Object value, boolean isUnsignedArray)- Overrides:
setAttributein classSAMRecord
-
clearAttributes
public void clearAttributes()
Description copied from class:SAMRecordRemoves all attributes.- Overrides:
clearAttributesin classSAMRecord
-
setAttributes
protected void setAttributes(SAMBinaryTagAndValue attributes)
Description copied from class:SAMRecordReplace any existing attributes with the given linked item. NOTE: this method is intended to only be called from subclasses.- Overrides:
setAttributesin classSAMRecord
-
getBinaryAttributes
protected SAMBinaryTagAndValue getBinaryAttributes()
- Overrides:
getBinaryAttributesin classSAMRecord- Returns:
- Pointer to the first of the tags. Returns null if there are no tags.
-
isUnsignedArrayAttribute
public boolean isUnsignedArrayAttribute(String tag)
- Overrides:
isUnsignedArrayAttributein classSAMRecord- Returns:
- True if this tag is an unsigned array, else false.
-
equals
public boolean equals(Object o)
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
public Object clone() throws CloneNotSupportedException
Performs a deep copy of the SAMRecord and detaches a copy from NGS iterator- Overrides:
clonein classSAMRecord- Returns:
- new object
- Throws:
CloneNotSupportedException
-
format
public String format()
-
isValid
public List<SAMValidationError> isValid(boolean firstOnly)
Description copied from class:SAMRecordPerform 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.
-
-