]> git.donarmstrong.com Git - biopieces.git/commitdiff
speedup fix of max_homopol
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 16 Dec 2010 12:17:47 +0000 (12:17 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 16 Dec 2010 12:17:47 +0000 (12:17 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1190 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/Maasha/lib/seq.rb

index a6f071d9ba298a0c809945457a6a713ec3f7471e..23e69658782beb3f8b66d1f5924e287c7f0a08f4 100644 (file)
@@ -165,12 +165,12 @@ class Seq
   # Method that returns the length of the longest homopolymeric stretch
   # found in a sequence.
   def homopol_max
-    max = 0
+    max = 1
 
-    if self.seq
-      self.seq.upcase.scan(/[A]+|[T]+|[G]+|[C]+|[N]+/) do |match|
-        max = [match.size, max].max
-      end
+    return 0 if self.seq.nil? or self.seq.empty?
+
+    self.seq.upcase.scan(/A{#{max},}|T{#{max},}|G{#{max},}|C{#{max},}|N{#{max},}/) do |match|
+      max = [match.size, max].max
     end
 
     max