Class: Bioinform::ConversionAlgorithms::PWM2IupacPWMConverter
- Inherits:
-
Object
- Object
- Bioinform::ConversionAlgorithms::PWM2IupacPWMConverter
- Defined in:
- lib/bioinform/conversion_algorithms/pwm2iupac_pwm_converter.rb
Instance Attribute Summary collapse
-
#iupac_alphabet ⇒ Object
readonly
Returns the value of attribute iupac_alphabet.
Instance Method Summary collapse
- #convert(pwm) ⇒ Object
-
#initialize(options = {}) ⇒ PWM2IupacPWMConverter
constructor
A new instance of PWM2IupacPWMConverter.
Constructor Details
#initialize(options = {}) ⇒ PWM2IupacPWMConverter
Returns a new instance of PWM2IupacPWMConverter.
7 8 9 |
# File 'lib/bioinform/conversion_algorithms/pwm2iupac_pwm_converter.rb', line 7 def initialize( = {}) @iupac_alphabet = .fetch(:alphabet, NucleotideAlphabetWithN) end |
Instance Attribute Details
#iupac_alphabet ⇒ Object (readonly)
Returns the value of attribute iupac_alphabet.
6 7 8 |
# File 'lib/bioinform/conversion_algorithms/pwm2iupac_pwm_converter.rb', line 6 def iupac_alphabet @iupac_alphabet end |
Instance Method Details
#convert(pwm) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bioinform/conversion_algorithms/pwm2iupac_pwm_converter.rb', line 10 def convert(pwm) raise Error, "Can convert only PWMs" unless MotifModel.acts_as_pwm?(pwm) raise Error, 'this conversion is possible only for ACGT-nucleotide motifs' unless pwm.alphabet == NucleotideAlphabet iupac_matrix = pwm.each_position.map do |pos| @iupac_alphabet.each_letter.map do |letter| nucleotide_indices = IUPAC::NucleotideIndicesByIUPACLetter[letter] nucleotide_indices.inject(0.0){|sum, nucleotide_index| sum + pos[nucleotide_index] } / nucleotide_indices.size end end MotifModel::PWM.new(iupac_matrix, alphabet: @iupac_alphabet) end |