22 lines
669 B
Mojo
22 lines
669 B
Mojo
# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
|
|
|
|
# How many times each word of K letters occurs in T.
|
|
def kmer_counts(t: String, k: Int) raises -> Dict[String, Int]:
|
|
# REQUIRE K >= 1
|
|
var counts = Dict[String, Int]()
|
|
var word: String
|
|
for i in range(t.count_codepoints() - k + 1):
|
|
var _piece2 = String("")
|
|
for _at1 in range(i, i + k):
|
|
_piece2 += String(t[codepoint=_at1])
|
|
word = _piece2
|
|
if word in counts:
|
|
counts[word] = counts[word] + 1
|
|
else:
|
|
counts[word] = 1
|
|
return counts.copy()
|
|
|
|
|
|
def main() raises:
|
|
print(kmer_counts("GATTACAGATT", 3))
|