Demo entry 2338172

Python3

   

Submitted by anonymous on Aug 05, 2015 at 00:09
Language: Python 3. Code size: 639 Bytes.

kmer_size = 12
def split_dna(dna, kmer_size):
    kmers = []
    for start in range(0,len(dna)-(kmer_size-1),1):
        kmer = dna[start:start+kmer_size]
        kmers.append(kmer)
    return kmers

kmer_counts = {}
dna_file = open('rosalind_1bba.txt','r')
for line in dna_file:
    dna = line.rstrip("\n")

    for kmer in split_dna(dna, kmer_size):
            current_count = kmer_counts.get(kmer, 0)
            new_count = current_count + 1
            kmer_counts[kmer] = new_count

max_kmers = ([key for key,val in kmer_counts.items() if val == max(kmer_counts.values())])
for kmer in max_kmers:
    print(kmer)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).