Title / Description
Code 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)
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code