Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hub-courses
python_one_week_4_biologists_solutions
Commits
27f60a48
Commit
27f60a48
authored
Feb 17, 2016
by
Bertrand Néron
Browse files
add code for OOP exercises
parent
5d43aa3e
Changes
4
Hide whitespace changes
Inline
Side-by-side
source/Object_Oriented_Programming.rst
0 → 100644
View file @
27f60a48
.. sectnum::
:start: 13
.. _Object_Oriented_Programming:
***************************
Object Oriented Programming
***************************
Exercises
=========
Exercise
--------
Exercise
--------
Exercise
--------
Exercise
--------
\ No newline at end of file
source/_static/code/enzyme.py
0 → 100644
View file @
27f60a48
class
Sequence
(
object
):
def
__init__
(
self
,
identifier
,
comment
,
seq
):
self
.
id
=
identifier
self
.
comment
=
comment
self
.
seq
=
self
.
_clean
(
seq
)
def
_clean
(
self
,
seq
):
"""
:param seq:
:return:
"""
return
seq
.
replace
(
'
\n
'
)
def
enzyme_filter
(
self
,
enzymes
):
"""
:param enzymes:
:return:
"""
enzymes_which_binds
=
[]
for
enz
in
enzymes
:
if
enz
.
binds
(
self
.
seq
):
enzymes_which_binds
.
append
(
enz
)
return
class
RestrictionEnzyme
(
object
):
def
__init__
(
self
,
name
,
binding
,
cut
,
end
,
comment
=
''
):
self
.
name
=
name
self
.
binding
=
binding
self
.
cut
=
cut
self
.
end
=
end
self
.
comment
=
comment
def
binds
(
self
,
seq
):
"""
:param seq:
:return:
"""
return
self
.
binding
in
seq
.
seq
\ No newline at end of file
source/_static/code/matrix_obj.py
0 → 100644
View file @
27f60a48
class
Matrix
(
object
):
def
__init__
(
self
,
row
,
col
,
val
=
None
):
self
.
_row
=
row
self
.
_col
=
col
self
.
_matrix
=
[]
for
i
in
range
(
row
):
c
=
[
val
]
*
col
self
.
_matrix
.
append
(
c
)
def
size
(
self
):
return
self
.
_row
,
self
.
_col
def
get_cell
(
self
,
row
,
col
):
self
.
_check_index
(
row
,
col
)
return
self
.
_matrix
[
i
][
j
]
def
matrix_set
(
self
,
row
,
col
,
val
):
self
.
_check_index
(
row
,
col
)
self
.
_matrix
[
row
][
col
]
=
val
def
__str__
(
self
):
s
=
''
for
i
in
range
(
self
.
_row
):
s
+=
self
.
_matrix
[
i
]
s
+=
'
\n
'
return
s
def
_check_index
(
self
,
row
,
col
):
if
not
(
0
<
row
<=
self
.
_row
)
or
not
(
0
<
col
<=
self
.
_col
):
raise
IndexError
(
"matrix index out of range"
)
source/_static/code/point.py
0 → 100644
View file @
27f60a48
import
math
class
Point
(
object
):
"""Class to handle point in a 2 dimensions space"""
def
__init__
(
self
,
x
,
y
):
"""
:param x: the value on the X-axis
:type x: float
:param y: the value on the Y-axis
:type y: float
"""
self
.
x
=
x
self
.
y
=
y
def
show
(
self
):
"""
:return: the coordinate of this point
:rtype: a tuple of 2 elements (float, float)
"""
return
(
self
.
x
,
self
.
y
)
def
move
(
self
,
x
,
y
):
"""
:param x: the value to move on the X-axis
:type x: float
:param y: the value to move on the Y-axis
:type y: float
"""
self
.
x
+=
x
self
.
y
+=
y
def
dist
(
self
,
pt
):
"""
:param pt: the point to compute the distance with
:type pt: :class:`Point` object
:return: the distance between this point ant pt
:rtype: int
"""
dx
=
pt
.
x
-
self
.
x
dy
=
pt
.
y
-
self
.
y
return
math
.
sqrt
(
dx
**
2
+
dy
**
2
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment