Assignment title: Information


NEED SOLUTION FOR THIS PROBLEM 1 and in the question it is stated as from the ssignment 3 problem. So I have given you that assignment 3 problem and its solution below after the problem 1 Problem 1: We return to the DNA class from Assignment 3. The most frequent k-mer problem seeks the set of substrings of length k (where integer k is an input) that occur most frequently. We add to the DNA class a most_frequent_kmers method that gets called with integer k and returns an array whose first element is the set of k-mers that occur most frequently in this DNA and whose second element is the number of times each one appears. >> dna1 = DNA.new('ATTGATTCCG') => ATTGATTCCG >> dna1.most_frequent_kmers(1) => [#<Set: {"T"}>, 4] >> dna1.most_frequent_kmers(2) => [#<Set: {"AT", "TT"}>, 2] >> dna1.most_frequent_kmers(3) => [#<Set: {"ATT"}>, 2] >> dna1.most_frequent_kmers(4) => [#<set: {"ATTG", "TTGA", "TGAT", "GATT", "ATTC", "TTCC", "TCCG"}>, 1] ASSIGNMNT 3 QUESTION WAS: A DNA strand is represented by a string of the characters A, C, G, and T, each of which represents a nucleotide. Each nucleotide has its complement as indicated by this Ruby hash: NUCLEOTIDE_COMPLEMENT = { 'A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C' } The reverse-complement of a DNA string is a new string in which each nucleotide is replaced by its complement and the string is reversed. Reverse-complements are important in bioinformatics since a strand of DNA can be read in forward direction or, equivalently, its complementary strand can be read in its forward direction, which is reverse of the original string's direction. Add the reverse_complement method to your DNA class. In response to reverse_complement, it returns a new DNA instance representing its reverse-complement. Note also that a == b if and only if DNA instances a and b represent the same DNA strand. >> dna1 = DNA.new('ATTGCC') => ATTGCC >> dna2 = dna1.reverse_complement => GGCAAT >> dna2 => GGCAAT >> dna1 => ATTGCC >> dna2.reverse_complement => ATTGCC >> dna1.reverse_complement.reverse_complement == dna1 => true SOLUTION: class DNA attr_reader :dna @@NUCLEOTIDE_COMPLEMENT = Hash['A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C'] def initialize(value) @dna = value end def display puts @dna end def reverse_complement raise StandardError.new('Passed string cannot be reversed because it is empty') if @dna.nil? || @dna.empty? end_loop = @dna.length new_string = '' while end_loop > 0 end_loop -= 1 # arrays start with 0, so we need to do end_loop -1 first new_string +=@@NUCLEOTIDE_COMPLEMENT[@dna[end_loop]] end return DNA.new(new_string) end def to_s dna end def ==(another_dna) self.dna == another_dna.dna end end dna1 = DNA.new('ATTGCC') dna1.display dna2 = dna1.reverse_complement dna2.display puts dna2 puts dna1 dna3 =dna2.reverse_complement dna3.display puts dna1.reverse_complement.reverse_complement == dna1