|

|
|

|
|
|
|
|
|
# Session 7: Practice 1
|
|
# Session 7: Practice 1
|
|
|
|
|
... | @@ -32,9 +32,8 @@ |
... | @@ -32,9 +32,8 @@ |
|
The goal of this practice is to developt the **Seq Class** for working with **DNA sequences**. This library will be in a module called **Seq1** (The python file should be called Seq1.py). It is quite similar to **Seq0**, developed in the previous practice, but using an **Object Oriented approach**. We will also include several improvements
|
|
The goal of this practice is to developt the **Seq Class** for working with **DNA sequences**. This library will be in a module called **Seq1** (The python file should be called Seq1.py). It is quite similar to **Seq0**, developed in the previous practice, but using an **Object Oriented approach**. We will also include several improvements
|
|
|
|
|
|
These are all the normal **methods** that should be implemented in the **Seq Class**
|
|
These are all the normal **methods** that should be implemented in the **Seq Class**
|
|
|
|
|
|
| Method | Parameters | Return value | Description |
|
|
| Method | Parameters | Return value | Description |
|
|
|-----------------|-------------|--------------|--------------|
|
|
|--------|------------|--------------|-------------|
|
|
| **len** | None | integer | Calculate the total number of bases in the sequence |
|
|
| **len** | None | integer | Calculate the total number of bases in the sequence |
|
|
| **count_base**(base) | base: character | Integer | Calculate the number of the given base in the Sequence |
|
|
| **count_base**(base) | base: character | Integer | Calculate the number of the given base in the Sequence |
|
|
| **count** | None | A dicctionary | Calculate the number of all the bases in the sequence. A dicctionary with the results is returned. The keys are the bases and the values their number |
|
|
| **count** | None | A dicctionary | Calculate the number of all the bases in the sequence. A dicctionary with the results is returned. The keys are the bases and the values their number |
|
... | @@ -42,7 +41,7 @@ These are all the normal **methods** that should be implemented in the **Seq Cla |
... | @@ -42,7 +41,7 @@ These are all the normal **methods** that should be implemented in the **Seq Cla |
|
| **complement** | None | String | Return the complement sequence |
|
|
| **complement** | None | String | Return the complement sequence |
|
|
| **read_fasta**(filename) | filename: string | String | Open a DNA file in FASTA format and stored it inside the object |
|
|
| **read_fasta**(filename) | filename: string | String | Open a DNA file in FASTA format and stored it inside the object |
|
|
|
|
|
|
In addition, the **Class Seq** will have the **special method**s that we already know: **\_\_init\_\_()** for initializing the object and **\_\_str\_\_()** for printing the object as a sequence
|
|
In addition, the **Class Seq** will have the **special method**s that we already know: **\__init_\_()** for initializing the object and **\__str_\_()** for printing the object as a sequence
|
|
|
|
|
|
## Finish your previous practices
|
|
## Finish your previous practices
|
|
|
|
|
... | @@ -73,8 +72,8 @@ Sequence 1: (Length: 5) ACTGA |
... | @@ -73,8 +72,8 @@ Sequence 1: (Length: 5) ACTGA |
|
|
|
|
|
Process finished with exit code 0
|
|
Process finished with exit code 0
|
|
```
|
|
```
|
|
* **Considerations**:
|
|
|
|
The first thing you have to do is to **import** the **Seq Class** from the **Seq1 module**
|
|
* **Considerations**: The first thing you have to do is to **import** the **Seq Class** from the **Seq1 module**
|
|
|
|
|
|
```python3
|
|
```python3
|
|
from Seq1 import Seq
|
|
from Seq1 import Seq
|
... | @@ -83,6 +82,7 @@ from Seq1 import Seq |
... | @@ -83,6 +82,7 @@ from Seq1 import Seq |
|
### Exercise 2: Null sequences
|
|
### Exercise 2: Null sequences
|
|
|
|
|
|
We will manage **three types** of sequences: **Valid**, **Invalid** and **Null**:
|
|
We will manage **three types** of sequences: **Valid**, **Invalid** and **Null**:
|
|
|
|
|
|
* **Null**: Empty sequence "".It has no bases
|
|
* **Null**: Empty sequence "".It has no bases
|
|
* **Valid**: A sequence compose of the union of only the four valid bases: 'A', 'T', 'C', 'G'. Example: "ATTACG"
|
|
* **Valid**: A sequence compose of the union of only the four valid bases: 'A', 'T', 'C', 'G'. Example: "ATTACG"
|
|
* **Invalid**: A sequence that has one or more characters that are not valid bases. Example: "ATTXXG"
|
|
* **Invalid**: A sequence that has one or more characters that are not valid bases. Example: "ATTXXG"
|
... | @@ -97,9 +97,10 @@ s = Seq() |
... | @@ -97,9 +97,10 @@ s = Seq() |
|
# -- Creating a valid sequence
|
|
# -- Creating a valid sequence
|
|
s = Seq("TATAC")
|
|
s = Seq("TATAC")
|
|
```
|
|
```
|
|
The difference between the creation of the previous two object is that the first one has no arguments when calling Seq, and the second one has one. This means that the **argument** passed to the **\_\_init()\_\_** method is **optional**
|
|
|
|
|
|
|
|
For creating Null sequences the definition of the **\_\_init()\_\_** method should be like this:
|
|
The difference between the creation of the previous two object is that the first one has no arguments when calling Seq, and the second one has one. This means that the **argument** passed to the **\__init()\_\_** method is **optional**
|
|
|
|
|
|
|
|
For creating Null sequences the definition of the **\__init()\_\_** method should be like this:
|
|
|
|
|
|
```python3
|
|
```python3
|
|
def __init__(self, strbases="NULL"):
|
|
def __init__(self, strbases="NULL"):
|
... | @@ -107,7 +108,7 @@ def __init__(self, strbases="NULL"): |
... | @@ -107,7 +108,7 @@ def __init__(self, strbases="NULL"): |
|
|
|
|
|
It is used in python for creating **optional arguments**. If no argument is given, python automatically will create one with the default value to "NULL". This is the value we will use to identify the **null sequences**
|
|
It is used in python for creating **optional arguments**. If no argument is given, python automatically will create one with the default value to "NULL". This is the value we will use to identify the **null sequences**
|
|
|
|
|
|
When a Null sequence is created, the **\_\_init()\_\_** method will print the message: "NULL Seq Created"
|
|
When a Null sequence is created, the **\__init()\_\_** method will print the message: "NULL Seq Created"
|
|
|
|
|
|
* **Filename:** P1/Ex2.py
|
|
* **Filename:** P1/Ex2.py
|
|
* **Description**: Write a python program that creates first a null sequence and then a valid sequence. It should prints the objects. The output of the program should be:
|
|
* **Description**: Write a python program that creates first a null sequence and then a valid sequence. It should prints the objects. The output of the program should be:
|
... | @@ -119,7 +120,8 @@ New sequence created! |
... | @@ -119,7 +120,8 @@ New sequence created! |
|
Sequence 1: NULL
|
|
Sequence 1: NULL
|
|
Sequence 2: ACTGA
|
|
Sequence 2: ACTGA
|
|
```
|
|
```
|
|
* **Considerations**: The first you should do in the **\_\_init()\_\_** method is checking if it is a null sequence. If so, print the message on the console, assign the value to the **self.strbases** attribute and return. If it is not null, continue with the other checks
|
|
|
|
|
|
* **Considerations**: The first you should do in the **\__init()\_\_** method is checking if it is a null sequence. If so, print the message on the console, assign the value to the **self.strbases** attribute and return. If it is not null, continue with the other checks
|
|
|
|
|
|
### Exercise 3: Null, valid and invalid sequences
|
|
### Exercise 3: Null, valid and invalid sequences
|
|
|
|
|
... | @@ -155,6 +157,7 @@ The **len(self)** method should works with the **three types** of sequences. In |
... | @@ -155,6 +157,7 @@ The **len(self)** method should works with the **three types** of sequences. In |
|
|
|
|
|
* **Filename**: P0/Ex4.py
|
|
* **Filename**: P0/Ex4.py
|
|
* **Desription**: Write a python program that creates three sequences: null, valid and invalid. Then it prints their lengths and sequences on the console. This is what we should see on the **console:**
|
|
* **Desription**: Write a python program that creates three sequences: null, valid and invalid. Then it prints their lengths and sequences on the console. This is what we should see on the **console:**
|
|
|
|
|
|
```
|
|
```
|
|
-----| Practice 1, Exercise 4 |------
|
|
-----| Practice 1, Exercise 4 |------
|
|
NULL Seq created
|
|
NULL Seq created
|
... | @@ -275,6 +278,7 @@ s = Seq() |
... | @@ -275,6 +278,7 @@ s = Seq() |
|
# -- Initialize the null seq with the given file in fasta format
|
|
# -- Initialize the null seq with the given file in fasta format
|
|
s.read_fasta(FILENAME)
|
|
s.read_fasta(FILENAME)
|
|
```
|
|
```
|
|
|
|
|
|
After that, you can use the sequence s exactly in the same way than the other sequences initialized manually
|
|
After that, you can use the sequence s exactly in the same way than the other sequences initialized manually
|
|
|
|
|
|
* **Filename**: P0/Ex9.py
|
|
* **Filename**: P0/Ex9.py
|
... | @@ -290,6 +294,7 @@ Sequence : (Length: 1314) ATAGACCAAACATGAGAGGCTGTGAATGGTATAATCTTCGCCGT...(not sh |
... | @@ -290,6 +294,7 @@ Sequence : (Length: 1314) ATAGACCAAACATGAGAGGCTGTGAATGGTATAATCTTCGCCGT...(not sh |
|
|
|
|
|
Process finished with exit code 0
|
|
Process finished with exit code 0
|
|
```
|
|
```
|
|
|
|
|
|
As the U5 is very long, only the first characters are shown in this figure (but the exercise will show all the bases)
|
|
As the U5 is very long, only the first characters are shown in this figure (but the exercise will show all the bases)
|
|
|
|
|
|
### Exercise 10: processing the genes
|
|
### Exercise 10: processing the genes
|
... | | ... | |