Class Cigar

java.lang.Object
htsjdk.samtools.Cigar
All Implemented Interfaces:
Serializable, Iterable<CigarElement>

public class Cigar extends Object implements Serializable, Iterable<CigarElement>
A list of CigarElements, which describes how a read aligns with the reference. E.g. the Cigar string 10M1D25M means * match or mismatch for 10 bases * deletion of 1 base * match or mismatch for 25 bases c.f. https://samtools.github.io/hts-specs/SAMv1.pdf for complete CIGAR specification.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getCigarElements

      public List<CigarElement> getCigarElements()
    • getCigarElement

      public CigarElement getCigarElement(int i)
    • add

      public void add(CigarElement cigarElement)
    • numCigarElements

      public int numCigarElements()
    • isEmpty

      public boolean isEmpty()
    • getReferenceLength

      public int getReferenceLength()
      Returns:
      The number of reference bases that the read covers, excluding padding.
    • getPaddedReferenceLength

      public int getPaddedReferenceLength()
      Returns:
      The number of reference bases that the read covers, including padding.
    • getReadLength

      public int getReadLength()
      Returns:
      The number of read bases that the read covers.
    • getReadLength

      public static int getReadLength(List<CigarElement> cigarElements)
      Returns:
      The number of read bases that the read covers.
    • isValid

      public List<SAMValidationError> isValid(String readName, long recordNumber)
      Exhaustive validation of CIGAR. 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.
      Parameters:
      readName - For error reporting only. May be null if not known.
      recordNumber - For error reporting only. May be -1 if not known.
      Returns:
      List of validation errors, or null if no errors.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • fromCigarOperators

      public static Cigar fromCigarOperators(List<CigarOperator> cigarOperators)
      build a new Cigar object from a list of cigar operators. This can be used if you have the operators associated to each base in the read. e.g: read length =10 with cigar= [M,M,M,M,M,M,M,M,M,M], here fromCigarOperators would generate the cigar '10M' later the user resolved the 'M' to '=' or 'X', the array is now [=,=,=,=,=,X,X,=,=,=] fromCigarOperators would generate the cigar '5M2X3M'
    • fromCigarString

      public static Cigar fromCigarString(String cigarString)
      Decode a Cigar from a SAM formatted CIGAR String, uses TextCigarCodec.decode(String) Only performs minimal validation.
      Parameters:
      cigarString - A SAM formatted CIGAR string.
      Returns:
      a new Cigar
    • iterator

      public Iterator<CigarElement> iterator()
      shortcut to getCigarElements().iterator()
      Specified by:
      iterator in interface Iterable<CigarElement>
    • containsOperator

      public boolean containsOperator(CigarOperator operator)
      returns true if the cigar string contains the given operator
    • getFirstCigarElement

      public CigarElement getFirstCigarElement()
      returns the first cigar element
    • getLastCigarElement

      public CigarElement getLastCigarElement()
      returns the last cigar element
    • isLeftClipped

      public boolean isLeftClipped()
      returns true if the cigar string starts With a clipping operator
    • isRightClipped

      public boolean isRightClipped()
      returns true if the cigar string ends With a clipping operator
    • isClipped

      public boolean isClipped()
      returns true if the cigar is clipped
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object