code: func (c Cigar) IsValid(length int) bool {
  	var pos int
  	for i, co := range c {
  		ct := co.Type()
  		if ct == CigarHardClipped && i != 0 && i != len(c)-1 {
  			return false
  		}
  		if ct == CigarSoftClipped && i != 0 && i != len(c)-1 {
  			if c[i-1].Type() != CigarHardClipped && c[i+1].Type() != CigarHardClipped {
  				return false
  			}
  		}
  		con := ct.Consumes()
  		if pos < 0 && con.Query != 0 {
  			return false
  		}
  		length -= co.Len() * con.Query
  		pos += co.Len() * con.Reference
  	}
  	return length == 0
  }
docs: // IsValid returns whether the CIGAR string is valid for a record of the given
  // sequence length. Validity is defined by the sum of query consuming operations
  // matching the given length, clipping operations only being present at the ends
  // of alignments, and that CigarBack operations only result in query-consuming
  // positions at or right of the start of the alignment.