Sha256: 8ce5ccf1ec46e7d8d5f678f2a3d6544f8b27422c4698c6fb1ba7d84b64c0b07f

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

require_relative '../alphabet'

module Bioinform
  class ConsensusFormatter

    # ConsensusFormatter.new{|pos, el, nucleotide_index| el == pos.max }
    def initialize(&block)
      raise Error, 'block is necessary to create an instance of ConsensusFormatter'  unless block_given?
      @block = block
    end

    # Simplest consensus formatter which takes into account only maximal elements
    def self.by_maximal_elements
      self.new{|pos, el, nucleotide_index| el == pos.max }
    end


    def format_string(pm)
      pm.each_position.map{|pos| iupac_letter_by_position(pos) }.join
    end

    def nucleotide_indices_by_position(pos)
      pos.each_index.select{|nucleotide_index|
        @block.call(pos, pos[nucleotide_index], nucleotide_index)
      }
    end

    def iupac_letter_by_position(pos)
      nucleotide_indices = nucleotide_indices_by_position(pos)
      Bioinform::IUPAC::IUPACLettersByNucleotideIndices[nucleotide_indices]
    end

    private :nucleotide_indices_by_position, :iupac_letter_by_position
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bioinform-0.3.1 lib/bioinform/formatters/consensus_formatter.rb
bioinform-0.3.0 lib/bioinform/formatters/consensus_formatter.rb
bioinform-0.2.2 lib/bioinform/formatters/consensus_formatter.rb
bioinform-0.2.1 lib/bioinform/formatters/consensus_formatter.rb
bioinform-0.2.0 lib/bioinform/formatters/consensus_formatter.rb