class Bio::PAML::Codeml::Rates
Description¶ ↑
A simple class for parsing the codeml rates file.
WARNING: The order of the parsed data should be correct, however will not necessarily correspond to the position in the alignment. For instance codeml ignores columns that contains gaps, and therefore there will not be any estimated rate data.
Usage¶ ↑
site_rates = ::new(File.open(@tmp_dir + “/rates”).read) site_rate.first # => Number of times that column appears site_rate.[:rate] # => Estimated rate of evolution site_rate.last # => The content of the column, as a string
# This class delegates to an array, so will respond to all array methods site_rates.max {|x,y| x <=> y } # => Fastest evolving column site_rates.detect {|x| x > 1 } # => Columns appearing more than once
Public Class Methods
new(rates)
click to toggle source
Calls superclass method
# File lib/bio/appl/paml/codeml/rates.rb, line 44 def initialize(rates) super(parse_rates(rates)) end
Private Instance Methods
parse_rates(text)
click to toggle source
# File lib/bio/appl/paml/codeml/rates.rb, line 50 def parse_rates(text) re = /\s+(\d+)\s+(\d+)\s+([A-Z\*]+)\s+(\d+\.\d+)\s+(\d)/ array = Array.new text.each_line do |line| if re =~ line match = Regexp.last_match array[match[1].to_i] = { :freq => match[2].to_i, :data => match[3], :rate => match[4].to_f } end end array.compact end