Sha256: 6c71c6032bbdbb748ed3a5523fd4236888347e2c043b633ff71b66bf9390e483

Contents?: true

Size: 1.75 KB

Versions: 15

Compression:

Stored size: 1.75 KB

Contents

#
# = bio/appl/paml/codeml/report.rb - Codeml report parser
#
# Copyright::  Copyright (C) 2008 Michael D. Barton <mail@michaelbarton.me.uk>
#
# License::    The Ruby License
#
# == Description
#
# This file contains a class that implement a simple interface to Codeml output file
#
# == References
#
# * http://abacus.gene.ucl.ac.uk/software/paml.html
#

require 'bio/appl/paml/codeml'

module Bio::PAML
  class Codeml

    # == Description
    #
    # A simple class for parsing codeml output.
    #
    # WARNING: This data is parsed using a regex from the output file, and
    # so will take the first result found. If using multiple tree's, your
    # milage may vary. See the source for the regular expressions.
    #
    # require 'bio'
    #
    # report = Bio::PAML::Codeml::Report.new(File.open(codeml_output_file).read)
    # report.gene_rate  # => Rate of gene evolution as defined be alpha
    # report.tree_lengh # => Estimated phylogetic tree length
    class Report < Bio::PAML::Common::Report

      attr_reader :tree_log_likelihood, :tree_length, :alpha, :tree

      def initialize(codeml_report)
        @tree_log_likelihood = pull_tree_log_likelihood(codeml_report)
        @tree_length = pull_tree_length(codeml_report)
        @alpha = pull_alpha(codeml_report)
        @tree = pull_tree(codeml_report)
      end

      private

      def pull_tree_log_likelihood(text)
        text[/lnL\(.+\):\s+(-?\d+(\.\d+)?)/,1].to_f
      end

      
      def pull_tree_length(text)
        text[/tree length\s+=\s+ (-?\d+(\.\d+)?)/,1].to_f
      end

      def pull_alpha(text)
        text[/alpha .+ =\s+(-?\d+(\.\d+)?)/,1].to_f
      end

      def pull_tree(text)
        text[/([^\n]+)\n\nDetailed/m,1]
      end

    end # End Report
  end # End Codeml
end # End Bio::PAML

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
bioruby-bio-1.2.9.9001 lib/bio/appl/paml/codeml/report.rb
bioruby-bio-1.2.9.9501 lib/bio/appl/paml/codeml/report.rb
bioruby-bio-1.3.0.5000 lib/bio/appl/paml/codeml/report.rb
bioruby-bio-1.3.0.9901 lib/bio/appl/paml/codeml/report.rb
bioruby-bio-1.3.0 lib/bio/appl/paml/codeml/report.rb
bioruby-bio-1.3.1.5000 lib/bio/appl/paml/codeml/report.rb
ngoto-bio-1.2.9.9001 lib/bio/appl/paml/codeml/report.rb
ngoto-bio-1.2.9.9501 lib/bio/appl/paml/codeml/report.rb
ngoto-bio-1.3.0.5000 lib/bio/appl/paml/codeml/report.rb
ngoto-bio-1.3.0 lib/bio/appl/paml/codeml/report.rb
ngoto-bio-1.3.1.5000 lib/bio/appl/paml/codeml/report.rb
wwood-bioruby-1.2.11 lib/bio/appl/paml/codeml/report.rb
bio-1.4.0 lib/bio/appl/paml/codeml/report.rb
bio-1.3.1 lib/bio/appl/paml/codeml/report.rb
bio-1.3.0 lib/bio/appl/paml/codeml/report.rb