* Understand how Classes (new concept to acquire) work
* Understand how Classes (new concept to acquire) work
* Create our first Class
* Create our first Class
...
@@ -34,7 +35,7 @@
...
@@ -34,7 +35,7 @@
## Introduction
## Introduction
All the python programs that you have developed so far use the **classical paradigm** of the [procedural programming](https://en.wikipedia.org/wiki/Procedural_programming). The main idea is to use **functions** that can be called at any point during the program's execution.
All python programs that you have developed so far use the **classical paradigm** of the [procedural programming](https://en.wikipedia.org/wiki/Procedural_programming). The main idea is to use **functions** that can be called at any point during the program's execution.
The problem to be solved is divided into smaller parts, implemented using **functions**, **data structures** and **variables**.
The problem to be solved is divided into smaller parts, implemented using **functions**, **data structures** and **variables**.
...
@@ -359,7 +360,7 @@ Gene: CGTAAC
...
@@ -359,7 +360,7 @@ Gene: CGTAAC
#### Expanding the Gene Class
#### Expanding the Gene Class
The **Gene** is a kind of **specialized sequence**. Not all the sequences are Genes, but all the genes are sequences. We can **expand** the **Gene class** by adding more information that is not present in the general sequences. For example the **name** (usually the genes have a special name).
The **Gene** is a **special sequence**. Not all the sequences are Genes, but all the genes are sequences. We can **expand** the **Gene class** by adding more information that is not present in the general sequences. For example the **name** (usually the genes have a special name).
Let's create a new \__init_\_ file method that includes a new optional parameter: the name of the Gene
Let's create a new \__init_\_ file method that includes a new optional parameter: the name of the Gene
...
@@ -378,7 +379,7 @@ class Gene(Seq):
...
@@ -378,7 +379,7 @@ class Gene(Seq):
print("New gene created")
print("New gene created")
```
```
As the Gene is also a Seq, for creating a Gene first we should call the **init** function from the Seq class (_super_). We do it by calling the **super().init(strbases)** method, and then we add the properties of the Gene. In this case, only its name.
As the Gene is also a Seq, for creating a Gene first we should call the **init** function from the Seq class (_super_). We do it by calling the **super().__init__(strbases)** method, and then we add the properties of the Gene. In this case, only its name.
When creating the Gene in the main program, we specify its **name** as a parameter, for example FRAT1:
When creating the Gene in the main program, we specify its **name** as a parameter, for example FRAT1:
...
@@ -514,7 +515,7 @@ New sequence created!
...
@@ -514,7 +515,7 @@ New sequence created!
The goal of this exercise is to detect **incorrect sequences**.
The goal of this exercise is to detect **incorrect sequences**.
***Filename**: S06/e1.py
***Filename**: S06/e1.py
***Description**: Modify the \__ini_\_ method of the Seq class so that it detects whether the given string only contains valid bases ('A', 'C', 'G' and 'T'). If a different character is found, the sequence should be initialized with the **"ERROR"** string, and the message **"INCORRECT Sequence detected"** should be printed in the console.
***Description**: Modify the \___ini__\_ method of the Seq class so that it detects whether the given string only contains valid bases ('A', 'C', 'G' and 'T'). If a different character is found, the sequence should be initialized with the **"ERROR"** string, and the message **"INCORRECT Sequence detected"** should be printed in the console.
When the previous **main program** is executed, this is what should be printed on the console:
When the previous **main program** is executed, this is what should be printed on the console:
We need to develop some **functions** to create sequences for **testing** the Seq objects. For instance, the function **generate_seqs(pattern, number)**, that has two parameters, will create a **list** with the provided _number_ of sequences. All the sequences are created from the given**pattern**. This pattern is a string of one or more valid bases. The first sequence of the list will have the provided pattern, the second, the pattern will be repeated twice, in the third the patter will be repeated three times, and so on.
We need to develop some **functions** to create sequences for **testing** the Seq objects. For instance, the function **generate_seqs(pattern, number)**, that has two parameters, will create a **list** with the provided _number_ of sequences. All sequences are created from the provided**pattern**. This pattern is a string of one or more valid bases. The first sequence of the list will be the pattern, the second will consist in the pattern repeated twice, in the third, the pattern will be repeated three times, and so on.
Therefore, if we call the function generate_seqs() with the parameters ("A", 3), a list of 3 sequences is returned. The bases in every sequence will be: "A", "AA" and "AAA"
Therefore, if we call the function generate_seqs() with the parameters ("A", 3), a list of 3 sequences is returned. The bases in every sequence will be: "A", "AA" and "AAA"