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 = Bio::PAML::Codeml::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
44 def initialize(rates)
45   super(parse_rates(rates))
46 end

Private Instance Methods

parse_rates(text) click to toggle source
   # File lib/bio/appl/paml/codeml/rates.rb
50 def parse_rates(text)
51   re = /\s+(\d+)\s+(\d+)\s+([A-Z\*]+)\s+(\d+\.\d+)\s+(\d)/
52   array = Array.new
53   text.each_line do |line|
54     if re =~ line
55       match = Regexp.last_match
56       array[match[1].to_i] = {
57         :freq => match[2].to_i, 
58         :data => match[3], 
59         :rate => match[4].to_f }
60     end
61   end
62   array.compact
63 end