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
72f48d01
Commit
72f48d01
authored
3 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Typos.
parent
7bace4bf
No related branches found
No related tags found
No related merge requests found
Pipeline
#83388
passed
3 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/Collection_Data_Types.rst
+11
-11
11 additions, 11 deletions
source/Collection_Data_Types.rst
with
11 additions
and
11 deletions
source/Collection_Data_Types.rst
+
11
−
11
View file @
72f48d01
...
@@ -103,7 +103,7 @@ Exercise
...
@@ -103,7 +103,7 @@ Exercise
.. note::
.. note::
``sum`` is a function that returns the sum of all the elements of a list.
``sum`` is a function that returns the sum of all the elements of a list.
Wihout using the Python shell, tell what are the effects of the following statements::
Wi
t
hout using the Python shell, tell what are the effects of the following statements::
x = [1, 2, 3, 4]
x = [1, 2, 3, 4]
...
@@ -175,7 +175,7 @@ Draw the representation in memory of the ``x`` and ``y`` variables when the foll
...
@@ -175,7 +175,7 @@ Draw the representation in memory of the ``x`` and ``y`` variables when the foll
Exercise
Exercise
--------
--------
f
rom the list l = [1, 2, 3, 4, 5, 6, 7, 8, 9] generate 2 lists l1 containing all odd values, and l2 all even values.::
F
rom the list l = [1, 2, 3, 4, 5, 6, 7, 8, 9] generate 2 lists l1 containing all odd values, and l2 all even values.::
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
l1 = l[::2]
l1 = l[::2]
...
@@ -224,7 +224,7 @@ first implementation:
...
@@ -224,7 +224,7 @@ first implementation:
second implementation:
second implementation:
""""""""""""""""""""""
""""""""""""""""""""""
Mathematically speaking the generation of all codons can be the
c
artesian product
Mathematically speaking the generation of all codons can be the
C
artesian product
between 3 vectors 'acgt'.
between 3 vectors 'acgt'.
In python there is a function to do that in ``itertools module``: `https://docs.python.org/3/library/itertools.html#itertools.product <product>`_
In python there is a function to do that in ``itertools module``: `https://docs.python.org/3/library/itertools.html#itertools.product <product>`_
...
@@ -361,7 +361,7 @@ In the first algorithm.
...
@@ -361,7 +361,7 @@ In the first algorithm.
| So the algorithm is in O(sequence length)
| So the algorithm is in O(sequence length)
Compute the 6 mers occurences of the sequence above, and print each 6mer and it's occurence one per line.
Compute the 6 mers occur
r
ences of the sequence above, and print each 6mer and it's occur
r
ence one per line.
.. literalinclude:: _static/code/kmer.py
.. literalinclude:: _static/code/kmer.py
:linenos:
:linenos:
...
@@ -394,7 +394,7 @@ Compute the 6 mers occurences of the sequence above, and print each 6mer and it'
...
@@ -394,7 +394,7 @@ Compute the 6 mers occurences of the sequence above, and print each 6mer and it'
bonus:
bonus:
""""""
""""""
Print the kmers by ordered by occurences.
Print the kmers by ordered by occur
r
ences.
| see `https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types <sort>`_
| see `https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types <sort>`_
| see `https://docs.python.org/3/library/operator.html#operator.itemgetter <operator.itemgetter>`_
| see `https://docs.python.org/3/library/operator.html#operator.itemgetter <operator.itemgetter>`_
...
@@ -463,12 +463,12 @@ other solution
...
@@ -463,12 +463,12 @@ other solution
""""""""""""""
""""""""""""""
python provide an interesting method for our problem.
python provide an interesting method for our problem.
The ``translate`` method work on string and need a parameter which is a object
The ``translate`` method work
s
on
a
string and need
s
a parameter which is a
n
object
that can do the correspond
a
nce between characters in old string a the new one.
that can do the correspond
e
nce between characters in
the
old string a
nd
the new one.
``maketrans`` is a function in module ``string`` that allow us to build this object.
``maketrans`` is a function in module ``string`` that allow us to build this object.
``maketrans`` take 2 arguments, two strings, the first string contains the characters
``maketrans`` take 2 arguments, two strings, the first string contains the characters
to change, the second string the corresponding characters in the new string.
to change, the second string the corresponding characters in the new string.
Thus the two strings **must** have the same length. The correspond
a
nce between
Thus the two strings **must** have the same length. The correspond
e
nce between
the characters to change and their new values is made in function of their position.
the characters to change and their new values is made in function of their position.
the first character of the first string will be replaced by the first character of the second string,
the first character of the first string will be replaced by the first character of the second string,
the second character of the first string will be replaced by the second character of the second string, on so on.
the second character of the first string will be replaced by the second character of the second string, on so on.
...
@@ -555,13 +555,13 @@ with this algorithm we find if an enzyme cut the dna but we cannot find all cuts
...
@@ -555,13 +555,13 @@ with this algorithm we find if an enzyme cut the dna but we cannot find all cuts
for enz in enzymes:
for enz in enzymes:
print enz.name, dna_1.count(enz.sequence)
print enz.name, dna_1.count(enz.sequence)
t
he latter algorithm display the number of occurrence of each enzyme, But we cannot determine the position of every sites.
T
he latter algorithm display
s
the number of occurrence of each enzyme, But we cannot determine the position of every sites.
We will see how to do this later.
We will see how to do this later.
Bonus
Bonus
^^^^^
^^^^^
There is another kind of tuple which allow to access to it
m
es by index or name.
There is another kind of tuple which allow
s
to access to ite
m
s by index or name.
This data collection is called NamedTuple. The NamedTuple are not accessible directly they are in `collections` package,
This data collection is called NamedTuple. The NamedTuple are not accessible directly they are in `collections` package,
so we have to import it before to use it.
so we have to import it before to use it.
We also have to define which name correspond to which item::
We also have to define which name correspond to which item::
...
@@ -596,7 +596,7 @@ given the following dict : ::
...
@@ -596,7 +596,7 @@ given the following dict : ::
d = {1 : 'a', 2 : 'b', 3 : 'c' , 4 : 'd'}
d = {1 : 'a', 2 : 'b', 3 : 'c' , 4 : 'd'}
We want obtain a new dict with the keys and the values inverted so we will obtain: ::
We want
to
obtain a new dict with the keys and the values inverted so we will obtain: ::
inverted_d {'a': 1, 'c': 3, 'b': 2, 'd': 4}
inverted_d {'a': 1, 'c': 3, 'b': 2, 'd': 4}
...
...
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