]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/sam.rb
worked on unit tests for sam.rb
[biopieces.git] / code_ruby / lib / maasha / sam.rb
index 0161cd7fee757a98194fdc53158811fe9e96ac7b..b82c6b1b2742f6f3757d1b90c8a598502ec9844b 100644 (file)
@@ -309,31 +309,41 @@ class Sam < Filesys
     raise SamError, "Bad mapq: #{mapq}" unless (0 .. 2**8 - 1).include? mapq
   end
 
-  # Method to check cigar.
+  # Method to check cigar string.
   def check_cigar(cigar, seq)
     raise SamError, "Bad cigar: #{cigar}" unless cigar =~ /^(\*|([0-9]+[MIDNSHPX=])+)$/
 
-    # Check cigar hard clipping only at ends.
+    unless cigar == '*'
+      check_cigar_hard_clip(cigar)
+      check_cigar_soft_clip(cigar)
+      check_cigar_seq_len(cigar, seq) unless seq == '*'
+    end
+  end
+
+  # Method to check cigar hard clipping only at ends.
+  def check_cigar_hard_clip(cigar)
     if cigar.gsub(/^[0-9]+H|[0-9]+H$/, "").match('H')
       raise SamError, "Bad cigar with internal H: #{cigar}"
     end
+  end
 
-    # Check cigar soft clipping only at ends or H.
+  # Method to check cigar soft clipping only at ends or H.
+  def check_cigar_soft_clip(cigar)
     if cigar.gsub(/^[0-9]+H|[0-9]+H$/, "").gsub(/^[0-9]+S|[0-9]+S$/, "").match('S')
       raise SamError, "Bad cigar with internal S: #{cigar}"
     end
+  end
 
-    # Check cigar length matches sequence length.
-    unless cigar == '*' or seq == '*'
-      cigar_len = 0
-      
-      cigar.scan(/([0-9]+)([MIDNSHPX=])/).each do |len, op|
-        cigar_len += len.to_i if op =~ /[MISX=]/
-      end
+  # Method to check cigar length matches sequence length.
+  def check_cigar_seq_len(cigar, seq)
+    cigar_len = 0
 
-      if cigar_len != seq.length
-        raise SamError, "cigar and sequence length mismatch: #{cigar_len} != #{seq.length}"
-      end
+    cigar.scan(/([0-9]+)([MIDNSHPX=])/).each do |len, op|
+      cigar_len += len.to_i if op =~ /[MISX=]/
+    end
+
+    if cigar_len != seq.length
+      raise SamError, "cigar and sequence length mismatch: #{cigar_len} != #{seq.length}"
     end
   end