diff --git a/source/Dive_into_Functions.rst b/source/Dive_into_Functions.rst index 26c4f8fb4ad3597b41f3d5e91ea4fd549df5708b..ad448bb06c321fbc066e5e0c7f680dab0d87823c 100644 --- a/source/Dive_into_Functions.rst +++ b/source/Dive_into_Functions.rst @@ -492,4 +492,36 @@ This function have to take the phase as parameter :download:`translate.py <_static/code/translate.py>` . - \ No newline at end of file + +.. _matrix_exercise: + +Exercise +-------- + +Write a program that calculates the similarity of 2 RNA sequences. + +* To compute the similarity you need to parse a file containing the :download:`similarity matrix <_static/data/similarity_matrix>`. + + **Hint**: use the module containing the functions that handle a matrix from previous chapter. + put this matrix.py file in a directory named "my_python_lib" in your home or Desktop + and import it in your current program (the similarity script must be placed elsewhere). +* The similarity of the 2 sequences is the sum of base similarities. + so you have to compare the first base of two sequences and use the matrix to get the similarity + from the similarity table, on so on for all bases then sum these similarities. + +First implementation + +.. literalinclude:: _static/code/matrix.py + :linenos: + :language: python + +:download:`matrix.py <_static/code/matrix.py>` . + + +Second implementation + +.. literalinclude:: _static/code/matrix2.py + :linenos: + :language: python + +:download:`matrix2.py <_static/code/matrix2.py>` .