Sha256: 758cda98c300c15d41f02ad7053dad151b72265e59150e537377ff03cb20c1b3

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require "rubygems"
require "set"
require "narray"
require "facets"

class Environment

  @@amino_acids  = "ACDEFGHIKLMNPQRSTVWYJ".split("")

  attr_accessor :number,
                :label,
                :freq_array,
                :prob_array,
                :logodd_array,
                :smooth_prob_array

  def initialize(number, label)
    @number             = number
    @label              = label
    @freq_array         = NArray.int(21)
    @prob_array         = NArray.float(21)
    @logodd_array       = NArray.float(21)
    @smooth_prob_array  = NArray.float(21)
  end

  def add_residue_count(a, inc = 1)
    @freq_array[@@amino_acids.index(a.upcase)] += inc
  end

  def label_set
    label.split("").map_with_index { |l, i| "#{i}#{l}" }.to_set
  end

  def to_s
    "#{number}-#{label}"
  end
end

if $0 == __FILE__

  require "test/unit"

  class TestEnvironment < Test::Unit::TestCase

    def setup
      @env = Environment.new(1, "AHaSon")
    end

    def test_label_set
      assert_equal(%w[0A 1H 2a 3S 4o 5n].to_set, @env.label_set)
    end

    def test_to_s
      assert_equal("1-AHaSon", @env.to_s)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubst-0.0.1 lib/environment.rb