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
ConstructorsModifierConstructorDescriptionprotectedSRALazyRecord(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
Modifier and TypeMethodDescriptionvoidRemoves all attributes.clone()Performs a deep copy of the SAMRecord and detaches a copy from NGS iteratorvoidIs being called when original NGS iterator is being moved to the next object.booleanFor records equality, we should only compare read id, reference and position on the reference.format()intgetAttribute(short tag) byte[]Do not modify the value returned by this method.protected SAMBinaryTagAndValuegetCigar()Do not modify the value returned by this method.booleanthe read is the first read in a pair.intgetFlags()It is preferable to use the get*Flag() methods that handle the flag word symbolically.intintintbooleanstrand of the mate (false for forward; true for reverse strand).Returns the mate reference index for this record.booleanthe mate is unmapped.booleanthe 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.booleanstrand of the query (false for forward; true for reverse strand).booleanthe read is paired in sequencing, no matter whether it is mapped in a pair.Returns the reference index for this record.booleanthe read is the second read in a pair.inthashCode()The same approach as with 'equals' method.booleanbooleanisValid(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) voidFor 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, 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, validateCigarMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
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
- Overrides:
getReferenceNamein classSAMRecord- Returns:
- Reference name, or NO_ALIGNMENT_REFERENCE_NAME (*) if the record has no reference name
-
setReferenceName
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
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
- Overrides:
getCigarStringin classSAMRecord
-
setCigarString
- Overrides:
setCigarStringin classSAMRecord
-
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
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
- Overrides:
getMateReferenceNamein classSAMRecord- Returns:
- Mate reference name, or NO_ALIGNMENT_REFERENCE_NAME (*) if the record has no mate reference name
-
setMateReferenceName
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
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 invalid input: '&' 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. -
setFlags
public void setFlags(int value) -
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
- Overrides:
getAttributein classSAMRecord- Parameters:
tag- Binary representation of a 2-char String tag as created by SAMTagUtil.- See Also:
-
setAttribute
- Overrides:
setAttributein classSAMRecord- Parameters:
tag- Binary representation of a 2-char String tag as created by SAMTagUtil.- See Also:
-
setAttribute
- Overrides:
setAttributein classSAMRecord
-
clearAttributes
public void clearAttributes()Description copied from class:SAMRecordRemoves all attributes.- Overrides:
clearAttributesin classSAMRecord
-
setAttributes
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
- Overrides:
getBinaryAttributesin classSAMRecord- Returns:
- Pointer to the first of the tags. Returns null if there are no tags.
-
isUnsignedArrayAttribute
- Overrides:
isUnsignedArrayAttributein 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:
clonein classSAMRecord- Returns:
- new object
- Throws:
CloneNotSupportedException
-
format
-
isValid
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.
-