# http://samtools.sourceforge.net/SAM1.pdf
-require 'pp'
-
# Error class for all exceptions to do with CIGAR.
class CigarError < StandardError; end
-# Class to parse and write SAM files.
+# Class to manipulate CIGAR strings.
class Cigar
attr_accessor :cigar
+ # Method to initialize a CIGAR string.
def initialize(cigar)
@cigar = cigar
check_cigar
end
+ # Method to convert the CIGAR string to
+ # a printable string.
+ def to_s
+ @cigar
+ end
+
+ # Method to iterate over the length and operators
+ # in a CIGAR string.
def each
cigar.scan(/(\d+)([MIDNSHPX=])/).each do |len, op|
yield [len.to_i, op]
end
end
+ # Method to return the number length of
+ # the residues described in the CIGAR string.
+ # This length should match the length of the
+ # aligned sequence.
def length
total = 0
total
end
+ # Method to return the number of matched
+ # residues in the CIGAR string.
def matches
total = 0
total
end
+ # Method to return the number of inserted
+ # residues in the CIGAR string.
def insertions
total = 0
total
end
+ # Method to return the number of deleted
+ # residues in the CIGAR string.
def deletions
total = 0
total
end
+ # Method to return the number of hard clipped
+ # residues in the CIGAR string.
def clip_hard
total = 0
total
end
+ # Method to return the number of soft clipped
+ # residues in the CIGAR string.
def clip_soft
total = 0
private
+ # Method to check that the CIGAR string is formatted
+ # correctly, including hard clipping and soft clipping
+ # that cant be located internally.
def check_cigar
unless cigar =~ /^(\*|([0-9]+[MIDNSHPX=])+)$/
raise CigarError, "Bad cigar format: #{cigar}"