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
541cd289
Unverified
Commit
541cd289
authored
4 years ago
by
Bertrand NÉRON
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitlab.pasteur.fr:hub-courses/python_one_week_4_biologists_solutions
parents
97bc8a3e
bdf447e8
No related branches found
No related tags found
No related merge requests found
Pipeline
#58219
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 @
541cd289
...
@@ -391,7 +391,7 @@ Compute the 6 mers occurences of the sequence above, and print each 6mer and it'
...
@@ -391,7 +391,7 @@ Compute the 6 mers occurences of the sequence above, and print each 6mer and it'
>>> s = s.replace('\n', '')
>>> s = s.replace('\n', '')
>>> kmers = get_kmer_occurences(s, 6)
>>> kmers = get_kmer_occurences(s, 6)
>>> for kmer in kmers:
>>> for kmer in kmers:
>>> print
kmer[0], '..', kmer[1]
>>> print
(
kmer[0], '..', kmer[1]
)
gcagag .. 2
gcagag .. 2
aacttc .. 1
aacttc .. 1
gcaact .. 1
gcaact .. 1
...
...
This diff is collapsed.
Click to expand it.
source/_static/code/kmer.py
+
8
−
2
View file @
541cd289
def
get_kmer_occurences
(
seq
,
kmer_len
):
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
each tuple contains a kmers present in seq and its occurence
"""
"""
# Counter dictionary (keys will be kmers, values will be counts)
kmers
=
{}
kmers
=
{}
stop
=
len
(
seq
)
-
kmer_len
stop
=
len
(
seq
)
-
kmer_len
for
i
in
range
(
stop
+
1
):
for
i
in
range
(
stop
+
1
):
# Extract kmer starting at position i
kmer
=
seq
[
i
:
i
+
kmer_len
]
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
kmers
[
kmer
]
=
kmers
.
get
(
kmer
,
0
)
+
1
return
kmers
.
items
()
# pairs (kmer, count)
\ No newline at end of file
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