From: Martin Hansen Date: 2010-08-30T23:55:54+09:00 Subject: Re: Speed issues iterating over chars > You could do this though > > seq.gsub! /./ do |m| > scores[$`.length].ord - BASE_SOLEXA < cutoff ? m.downcase! : m > end > > Not too nice though. You could however do some preparation, e.g. > store scores as an Array of Fixnum instead of using #ord. Yes, converting scores to arrays is bad since the scores are parsed from files as strings (millions of them). And I am unsure if substr substitutions are very efficient ... We need to trick this into the regex engine somehow. How about transforming scores to a mask string like this: 000111 where 1 indicates that the corresponding sequence char should be lowercased (that can be done with tr). Then we plug this onto the sequence string: seq = "ATCGAT000111" And then we construct a regex with a forward looking identifier that reads the mask and manipulates the ATCG chars? Martin -- Posted via http://www.ruby-forum.com/.