Updated S6: Object Oriented Programming (markdown) authored by Rod Pérez's avatar Rod Pérez
...@@ -44,7 +44,7 @@ On the contrary, the [object oriented paradigm](https://en.wikipedia.org/wiki/Ob ...@@ -44,7 +44,7 @@ On the contrary, the [object oriented paradigm](https://en.wikipedia.org/wiki/Ob
## Working with sequences and functions ## Working with sequences and functions
In the previous session we developed our own **library of functions** (Seq0) for working with sequences. As an example let's use that library for performing some **simple calculations** on the sequence "ATTCCCGGGG". Save this example in the folder **Session-06** and call it **test-01.py** In the previous session we developed our own **library of functions** (Seq0) for working with sequences. As an example let's use a modified version of that library (some input parameters are different) for performing some **simple calculations** on the sequence "ATTCCCGGGG". Save this example in the folder **S6** and call it **test-01.py**
```python3 ```python3
from Seq0 import * from Seq0 import *
...@@ -61,6 +61,15 @@ print(f" C: {seq_count_base(seq1, 'C')}") ...@@ -61,6 +61,15 @@ print(f" C: {seq_count_base(seq1, 'C')}")
print(f" G: {seq_count_base(seq1, 'G')}") print(f" G: {seq_count_base(seq1, 'G')}")
``` ```
The headers of the functions in Seq0 that have changed are (you may want to try to implement it this way):
```python3
def seq_count_base(sequence, base=None):
# code
def seq_len(seq=None)
# code
```
This is what you get in the **console** when the program is **executed**: This is what you get in the **console** when the program is **executed**:
``` ```
...@@ -74,7 +83,7 @@ Seq: ATTCCCGGGG ...@@ -74,7 +83,7 @@ Seq: ATTCCCGGGG
G: 4 G: 4
``` ```
This **paradigm** is based on defining the data (variables) on one hand, and creating s**eparated functions** for working with that data. When calling the function you should pass the **data as parameters**. The data and function are **separated things** This **paradigm** we are following is based on defining the data (variables) on one hand, and creating **separated functions** for working with that data. When calling the function you should pass the data as **parameters**. Data and function are **separated**
Imagine that now we define a new sequence, but we make a mistake: Imagine that now we define a new sequence, but we make a mistake:
... ...
......