From: martinahansen Date: Thu, 16 Dec 2010 12:17:47 +0000 (+0000) Subject: speedup fix of max_homopol X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=13f4ed32debae50e9212343ef65a4cf42fa8b39c;p=biopieces.git speedup fix of max_homopol git-svn-id: http://biopieces.googlecode.com/svn/trunk@1190 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/Maasha/lib/seq.rb b/code_ruby/Maasha/lib/seq.rb index a6f071d..23e6965 100644 --- a/code_ruby/Maasha/lib/seq.rb +++ b/code_ruby/Maasha/lib/seq.rb @@ -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