Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python_one_week_4_biologists_solutions
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hub-courses
python_one_week_4_biologists_solutions
Commits
bdf447e8
Commit
bdf447e8
authored
4 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Fix print, comment solution for kmer counting.
parent
f7903932
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#58185
passed
4 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/Collection_Data_Types.rst
+1
-1
1 addition, 1 deletion
source/Collection_Data_Types.rst
source/_static/code/kmer.py
+8
-2
8 additions, 2 deletions
source/_static/code/kmer.py
with
9 additions
and
3 deletions
source/Collection_Data_Types.rst
+
1
−
1
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
...
...
This diff is collapsed.
Click to expand it.
source/_static/code/kmer.py
+
8
−
2
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment