]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/cigar.rb
fixed wrap bug in seq.rb
[biopieces.git] / code_ruby / lib / maasha / cigar.rb
index 765a4faa056c0ba8a3a3683b474a26ea1059f91f..800fc1414104d755c99ab1d9e206d400d40a1242 100644 (file)
 
 # 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
 
@@ -58,6 +69,8 @@ class Cigar
     total
   end
 
+  # Method to return the number of matched
+  # residues in the CIGAR string.
   def matches
     total = 0
 
@@ -68,6 +81,8 @@ class Cigar
     total
   end
 
+  # Method to return the number of inserted
+  # residues in the CIGAR string.
   def insertions
     total = 0
 
@@ -78,6 +93,8 @@ class Cigar
     total
   end
 
+  # Method to return the number of deleted
+  # residues in the CIGAR string.
   def deletions
     total = 0
 
@@ -88,6 +105,8 @@ class Cigar
     total
   end
 
+  # Method to return the number of hard clipped
+  # residues in the CIGAR string.
   def clip_hard
     total = 0
 
@@ -98,6 +117,8 @@ class Cigar
     total
   end
 
+  # Method to return the number of soft clipped
+  # residues in the CIGAR string.
   def clip_soft
     total = 0
 
@@ -110,6 +131,9 @@ class Cigar
 
   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}"