Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hub-courses
python_one_week_4_biologists_solutions
Commits
bdf447e8
Commit
bdf447e8
authored
Jun 09, 2021
by
Blaise Li
Browse files
Fix print, comment solution for kmer counting.
parent
f7903932
Pipeline
#58185
passed with stages
in 13 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
source/Collection_Data_Types.rst
View file @
bdf447e8
...
...
@@ -391,7 +391,7 @@ Compute the 6 mers occurences of the sequence above, and print each 6mer and it'
>>> s = s.replace('\n', '')
>>> kmers = get_kmer_occurences(s, 6)
>>> for kmer in kmers:
>>> print
kmer[0], '..', kmer[1]
>>> print
(
kmer[0], '..', kmer[1]
)
gcagag .. 2
aacttc .. 1
gcaact .. 1
...
...
source/_static/code/kmer.py
View file @
bdf447e8
def
get_kmer_occurences
(
seq
,
kmer_len
):
"""
return a list of tuple
return a list of tuple
each tuple contains a kmers present in seq and its occurence
"""
# Counter dictionary (keys will be kmers, values will be counts)
kmers
=
{}
stop
=
len
(
seq
)
-
kmer_len
for
i
in
range
(
stop
+
1
):
# Extract kmer starting at position i
kmer
=
seq
[
i
:
i
+
kmer_len
]
# Increment the count for kmer
# or create the entry the first time this kmer is seen
# using default value 0, plus 1
kmers
[
kmer
]
=
kmers
.
get
(
kmer
,
0
)
+
1
return
kmers
.
items
()
\ No newline at end of file
# pairs (kmer, count)
return
kmers
.
items
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment