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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hub-courses
python_one_week_4_biologists_solutions
Commits
a0e9f04a
Commit
a0e9f04a
authored
1 month ago
by
Bertrand NÉRON
Browse files
Options
Downloads
Patches
Plain Diff
fix solutions about matrices and similarity
there was a mismatch between exercises and solutions
parent
631665b2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/Dive_into_Functions.rst
+106
-11
106 additions, 11 deletions
source/Dive_into_Functions.rst
source/Modules_and_Packages.rst
+0
-39
0 additions, 39 deletions
source/Modules_and_Packages.rst
with
106 additions
and
50 deletions
source/Dive_into_Functions.rst
+
106
−
11
View file @
a0e9f04a
...
...
@@ -482,28 +482,123 @@ This function have to take the phase as parameter
.. _matrix_exercise:
Exercise
--------
Write a program that calculates the similarity of 2 RNA sequences.
In a new file named ``matrix.py`` Implement a matrix and functions to handle it.
choose the data structure of your choice.
The API (**A**\ pplication **P**\ rogramming **I**\ nterface) to implement is the following:
**maker**
have parameter:
* the number of rows
* the number of columns
* a default value to fill the matrix
and return a matrix of rows_num x col_num
**size**
have parameter:
* a matrix
return the number of rows, and number of columns
**get_cell**
have parameter:
* a matrix
* the number of rows
* the number of columns
the content of cell corresponding to row number x col number
**set_cell**
have parameter:
* a matrix
* the row number of cell to set
* the column number of cell to set
* the value to set in cell
set the value val in cell specified by row number x column number
**to_str**
have parameter:
* a matrix
return a string representation of the matrix
**mult**
have parameter:
* a matrix
* val the value to multiply the matrix with
return a new matrix which is the scalar product of matrix x val
**get_row**
have parameter:
* a matrix
* the number of rows
return a copy of the row corresponding to row number
**set_row**
have parameter:
* a matrix
* the row number
* the value to put in cells of the row
set value in each cells of the row specify by the row number
**get_col**
have parameter:
* a matrix
* the column number
return a copy of the column corresponding to the column number
**set_col**
have parameter:
* a matrix
* the column number
* the value to put in cells
set all cells of a column with value
**replace_col**
have parameter:
* a matrix
* the column number to replace
* the list of values to use as replacement of column
replace a column col_no with list of values
**replace_row**
have parameter:
* a matrix
* the row number to replace
* the list of values to use as replacement of row
* To compute the similarity you need to parse a file containing the :download:`similarity matrix <_static/data/similarity_matrix>`.
replace a row row_no with list of values
**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 (list of columns)
.. literalinclude:: _static/code/
matrix
.py
.. literalinclude:: _static/code/
similarity
.py
:linenos:
:language: python
:download:`matrix.py <_static/code/
matrix
.py>` .
:download:`matrix.py <_static/code/
similarity
.py>` .
Second implementation (bad variable naming, no documentation)
...
...
This diff is collapsed.
Click to expand it.
source/Modules_and_Packages.rst
+
0
−
39
View file @
a0e9f04a
...
...
@@ -11,45 +11,6 @@ Exercises
=========
Exercise
--------
Implement a matrix and functions to handle it.
choose the data structure of your choice.
The API (**A**\ pplication **P**\ rogramming **I**\ nterface) to implement is the following:
We propose 2 implementations. These 2 implementations work with a list of lists as matrix modelling.
But it is possible to implement it with a single list or a dict of list, ...
The first implementation follow the api used explicit name for inner variables and good documentation.
.. literalinclude:: _static/code/matrix.py
:linenos:
:language: python
:download:`matrix.py <_static/code/matrix.py>` .
But the problem with this implementation is, if we decide to change the inner model for a dixt of list for instance.
We must reimplements most of the functions.
In the following implementation we have only 4 functions that handle directly the lists. All other functions
manipulate the matrix through these 4 functions. So if we change the inner model we will have to modifiy
only these functions. This implementation will be more maintainable.
But this implementation use one letter names for inner variables and is poorly documented which not help
to maintain or develop with this.
The Best solution should be the second implementation but with the name of variables and documentation as in the firsr
implementation.
.. literalinclude:: _static/code/matrix2.py
:linenos:
:language: python
:download:`matrix2.py <_static/code/matrix2.py>` .
Exercise
--------
...
...
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