USE RUBY PROGRAMMING The most frequent k-mer problem seeks the set of substrings
ID: 3589166 • Letter: U
Question
USE RUBY PROGRAMMING
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]