Class 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
    • 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:
        getAlignmentStart in class SAMRecord
        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 class SAMRecord
        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 class SAMRecord
        Returns:
        phred scaled mapping quality. 255 implies valid mapping but quality is hard to compute.
      • getReferenceName

        public String getReferenceName()
        Overrides:
        getReferenceName in class SAMRecord
        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: 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 class SAMRecord
        Parameters:
        value - - must not be null
      • getReferenceIndex

        public Integer 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 class SAMRecord
        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 class SAMRecord
        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.
      • getCigar

        public Cigar 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()
        Overrides:
        getCigar in class SAMRecord
        Returns:
        Cigar object for the read, or null if there is none.
      • 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 class SAMRecord
        Returns:
        read sequence as ASCII bytes ACGTN=.
      • 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 class SAMRecord
        Returns:
        Base qualities, as binary phred scores (not ASCII).
      • getMateAlignmentStart

        public int getMateAlignmentStart()
        Overrides:
        getMateAlignmentStart in class SAMRecord
        Returns:
        1-based inclusive leftmost position of the clipped mate sequence, or 0 if there is no position.
      • getMateReferenceName

        public String getMateReferenceName()
        Overrides:
        getMateReferenceName in class SAMRecord
        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: 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 class SAMRecord
        Parameters:
        value - - must not be null
      • getMateReferenceIndex

        public Integer 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 class SAMRecord
        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 class SAMRecord
        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 class SAMRecord
        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.
      • getFlags

        public int getFlags()
        Description copied from class: SAMRecord
        It is preferable to use the get*Flag() methods that handle the flag word symbolically.
        Overrides:
        getFlags in class SAMRecord
      • setFlags

        public void setFlags​(int value)
        Overrides:
        setFlags in class SAMRecord
      • getReadNegativeStrandFlag

        public boolean getReadNegativeStrandFlag()
        Description copied from class: SAMRecord
        strand of the query (false for forward; true for reverse strand).
        Overrides:
        getReadNegativeStrandFlag in class SAMRecord
      • 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 class SAMRecord
      • 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 class SAMRecord
      • 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 class SAMRecord
      • 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 class SAMRecord
      • 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 class SAMRecord
      • isSecondaryAlignment

        public boolean isSecondaryAlignment()
        Overrides:
        isSecondaryAlignment in class SAMRecord
        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 class SAMRecord
      • getMateNegativeStrandFlag

        public boolean getMateNegativeStrandFlag()
        Description copied from class: SAMRecord
        strand of the mate (false for forward; true for reverse strand).
        Overrides:
        getMateNegativeStrandFlag in class SAMRecord
      • 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 class SAMRecord
      • setMateUnmappedFlag

        public void setMateUnmappedFlag​(boolean flag)
        Description copied from class: SAMRecord
        the mate is unmapped.
        Overrides:
        setMateUnmappedFlag in class SAMRecord
      • getFirstOfPairFlag

        public boolean getFirstOfPairFlag()
        Description copied from class: SAMRecord
        the read is the first read in a pair.
        Overrides:
        getFirstOfPairFlag in class SAMRecord
      • setFirstOfPairFlag

        public void setFirstOfPairFlag​(boolean flag)
        Description copied from class: SAMRecord
        the read is the first read in a pair.
        Overrides:
        setFirstOfPairFlag in class SAMRecord
      • getSecondOfPairFlag

        public boolean getSecondOfPairFlag()
        Description copied from class: SAMRecord
        the read is the second read in a pair.
        Overrides:
        getSecondOfPairFlag in class SAMRecord
      • setSecondOfPairFlag

        public void setSecondOfPairFlag​(boolean flag)
        Description copied from class: SAMRecord
        the read is the second read in a pair.
        Overrides:
        setSecondOfPairFlag in class SAMRecord
      • setAttribute

        protected void setAttribute​(short tag,
                                    Object value,
                                    boolean isUnsignedArray)
        Overrides:
        setAttribute in class SAMRecord
      • setAttributes

        protected void setAttributes​(SAMBinaryTagAndValue attributes)
        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 class SAMRecord
      • isUnsignedArrayAttribute

        public boolean isUnsignedArrayAttribute​(String tag)
        Overrides:
        isUnsignedArrayAttribute in class SAMRecord
        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.
        Overrides:
        equals in class SAMRecord
        Parameters:
        o - other
        Returns:
        comparison result
      • hashCode

        public int hashCode()
        The same approach as with 'equals' method. We only load reference and position.
        Overrides:
        hashCode in class SAMRecord
      • format

        public String format()
        Overrides:
        format in class SAMRecord
        Returns:
        String representation of this.
      • isValid

        public List<SAMValidationError> isValid​(boolean firstOnly)
        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.
        Overrides:
        isValid in class SAMRecord
        Parameters:
        firstOnly - return only the first error if true, false otherwise
        Returns:
        null if valid. If invalid, returns a list of error messages.