From 71ed45c07f4b5a34e461c4072188463bc373cb3f Mon Sep 17 00:00:00 2001 From: free hacker <freeh4cker@gmail.com> Date: Fri, 19 Feb 2016 00:42:00 +0100 Subject: [PATCH] mv solution of matrix in dive into function as in course --- source/Dive_into_Functions.rst | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/source/Dive_into_Functions.rst b/source/Dive_into_Functions.rst index 26c4f8f..ad448bb 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>` . -- GitLab