Commit 561097d6 authored by Blaise Li's avatar Blaise Li
Browse files

Minor language and format updates.

parent 9f15a02a
Pipeline #58073 passed with stages
in 13 seconds
...@@ -277,25 +277,26 @@ We will see how to determine all occurrences of restriction sites when we learn ...@@ -277,25 +277,26 @@ We will see how to determine all occurrences of restriction sites when we learn
Exercise Exercise
-------- --------
We want to perform a PCR on sv40, can you give the length and the sequence of the amplicon? We want to perform a PCR on sv40. Can you give the length and the sequence of the amplicon?
Write a function which have 3 parameters ``sequence``, ``primer_1`` and ``primer_2`` Write a function which has 3 parameters ``sequence``, ``primer_1`` and ``primer_2`` and returns the amplicon length.
* *We consider only the cases where primer_1 and primer_2 are present in sequence* * *We consider only the cases where primer_1 and primer_2 are present in the sequence.*
* *to simplify the exercise, the 2 primers can be read directly on the sv40 sequence.* * *To simplify the exercise, the 2 primers can be read directly in the sv40 sequence (i.e. no need to reverse-complement).*
test you algorithm with the following primers Test you algorithm with the following primers:
| primer_1 : 5' CGGGACTATGGTTGCTGACT 3' | primer_1 : 5' CGGGACTATGGTTGCTGACT 3'
| primer_2 : 5' TCTTTCCGCCTCAGAAGGTA 3' | primer_2 : 5' TCTTTCCGCCTCAGAAGGTA 3'
Write the pseudocode before to implement it. Write the function in pseudocode before implementing it.
| *function amplicon_len(sequence primer_1, primer_2)* | *function amplicon_len(sequence primer_1, primer_2)*
| *pos_1 <- find position of primer_1 in sequence* | *pos_1 <- find position of primer_1 in sequence*
| *pos_2 <- find position of primer_2 in sequence* | *pos_2 <- find position of primer_2 in sequence*
| *amplicon length <- pos_2 + length(primer_2) - pos_1* | *amplicon length <- pos_2 + length(primer_2) - pos_1*
| *return amplicon length* | *return amplicon length*
.. literalinclude:: _static/code/amplicon_len.py .. literalinclude:: _static/code/amplicon_len.py
...@@ -304,44 +305,50 @@ Write the pseudocode before to implement it. ...@@ -304,44 +305,50 @@ Write the pseudocode before to implement it.
:: ::
>>> import sv40 >>> import sv40
>>> import fasta_to_one_line >>> import fasta_to_one_line
>>> >>>
>>> sequence = fasta_to_one_line(sv40) >>> sequence = fasta_to_one_line(sv40)
>>> print amplicon_len(sequence, first_primer, second_primer ) >>> print amplicon_len(sequence, first_primer, second_primer )
199 199
:download:`amplicon_len.py <_static/code/amplicon_len.py>` . :download:`amplicon_len.py <_static/code/amplicon_len.py>`.
Exercise Exercise
-------- --------
reverse the following sequence "TACCTTCTGAGGCGGAAAGA" (don't compute the complement): :: #. Reverse the following sequence ``"TACCTTCTGAGGCGGAAAGA"`` (don't compute the complement).
::
>>> "TACCTTCTGAGGCGGAAAGA"[::-1] >>> "TACCTTCTGAGGCGGAAAGA"[::-1]
or # or
>>> s = "TACCTTCTGAGGCGGAAAGA" >>> s = "TACCTTCTGAGGCGGAAAGA"
>>> l = list(s) >>> l = list(s)
# take care reverse() reverse a list in place (the method do a side effect and return None ) # take care reverse() reverse a list in place (the method do a side effect and return None )
# so if you don't have a object reference on the list you cannot get the reversed list! # so if you don't have a object reference on the list you cannot get the reversed list!
>>> l.reverse() >>> l.reverse()
>>> print l >>> print l
>>> ''.join(l) >>> ''.join(l)
or # or
>>> rev_s = reversed(s) >>> rev_s = reversed(s)
''.join(rev_s) ''.join(rev_s)
The most efficient way to reverse a string or a list is the way using the slice. The most efficient way to reverse a string or a list is the way using the slice.
.. #. Using the shorter string ``s = 'gaattc'`` draw what happens in memory when you reverse ``s``.
Exercise Exercise
-------- --------
| The il2_human contains 4 cysteins (C) in positions 9, 78, 125, 145. | The ``il2_human`` sequence contains 4 cysteins (C) in positions 9, 78, 125, 145.
| We want to generate the sequence of a mutatnt were the cysteins 78 and 125 are replaced by serins (S) | We want to generate the sequence of a mutant where the cysteins 78 and 125 are replaced by serins (S)
| Write the pseudocode, before to propose an implementation: | Write the pseudocode, before proposing an implementation:
We have to take care of the string numbered vs sequence numbered: We have to take care of the difference between Python string numbering and usual position numbering:
| C in seq -> in string | C in seq -> in string
| 9 -> 8 | 9 -> 8
...@@ -350,36 +357,34 @@ We have to take care of the string numbered vs sequence numbered: ...@@ -350,36 +357,34 @@ We have to take care of the string numbered vs sequence numbered:
| 145 -> 144 | 145 -> 144
| *generate 3 slices from the il2_human* | *generate 3 slices from the il2_human*
| *head <- from the begining and cut between the first cytein and the second* | *head <- from the begining and cut between the first cystein and the second*
| *body <- include the 2nd and 3rd cystein* | *body <- include the 2nd and 3rd cystein*
| *tail <- cut after the 3rd cystein until the end* | *tail <- cut after the 3rd cystein until the end*
| *replace body cystein by serin* | *replace body cystein by serin*
| *make new sequence with head body_mutate tail* | *make new sequence with head body_mutate tail*
il2_human =
'MYRMQLLSCIALSLALVTNSAPTSSSTKKTQLQLEHLLLDLQMILNGINNYKNPKLTRMLTFKFYMPKKATELKHLQCLEEELKPLEEVLNLAQSKNFHLRPRDLISNINVIVLELKGSETTFMCEYADETATIVEFLNRWITFCQSIISTLT'
:: ::
head = il2_human[:77] il2_human = 'MYRMQLLSCIALSLALVTNSAPTSSSTKKTQLQLEHLLLDLQMILNGINNYKNPKLTRMLTFKFYMPKKATELKHLQCLEEELKPLEEVLNLAQSKNFHLRPRDLISNINVIVLELKGSETTFMCEYADETATIVEFLNRWITFCQSIISTLT'
body = il2_human[77:125] head = il2_human[:77]
tail = il2_human[126:] body = il2_human[77:125]
body_mutate = body.replace('C', 'S') tail = il2_human[126:]
il2_mutate = head + body_mutate + tail body_mutate = body.replace('C', 'S')
il2_mutate = head + body_mutate + tail
Exercise Exercise
-------- --------
Write a function Write a function which:
* which take a sequence as parameter * takes a sequence as parameter;
* compute the GC% * computes the GC%;
* and return it * and returns it;
* display the results readable for human as a micro report like this: * displays the results as a "human-readable" micro report like this:
'the sv40 is 5243 bp length and have 40.80% gc' ``'The sv40 is 5243 bp length and has 40.80% gc'``.
use sv40 sequence to test your function. Use the sv40 sequence to test your function.
.. literalinclude:: _static/code/gc_percent.py .. literalinclude:: _static/code/gc_percent.py
:linenos: :linenos:
...@@ -387,14 +392,14 @@ use sv40 sequence to test your function. ...@@ -387,14 +392,14 @@ use sv40 sequence to test your function.
:: ::
>>> import sv40 >>> import sv40
>>> import fasta_to_one_line >>> import fasta_to_one_line
>>> import gc_percent >>> import gc_percent
>>> >>>
>>> sequence = fasta_to_one_line(sv40) >>> sequence = fasta_to_one_line(sv40)
>>> gc_pc = gc_percent(sequence) >>> gc_pc = gc_percent(sequence)
>>> report = "the sv40 is {0} bp length and have {1:.2%} gc".format(len(sequence), gc_pc) >>> report = "The sv40 is {0} bp length and has {1:.2%} gc".format(len(sequence), gc_pc)
>>> print report >>> print report
'the sv40 is 5243 bp length and have 40.80% gc' 'The sv40 is 5243 bp length and has 40.80% gc'
:download:`gc_percent.py <_static/code/gc_percent.py>` . :download:`gc_percent.py <_static/code/gc_percent.py>` .
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment