-
Notifications
You must be signed in to change notification settings - Fork 7
Session 7: Practice 1

- Time: 2h
- Date: Wednesday, Feb-19th-2020
-
Goals:
- Creating our first Class Module for working with DNA sequences
- Introduction
- Finish your previous practices
- Exercises
- TODO
- End of the session
- Author
- Credits
- License
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
| Method | Parameters | Return value | Description |
|---|---|---|---|
| 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 | 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 |
| reverse | None | String | Return the reverse sequence |
| complement | None | String | Return the complement sequence |
| read_fasta(filename) | filename: string | String | Open a DNA file in FASTA format and return the sequence as a string (It should only contains the characters 'A', 'T', 'G' or 'C |
In addition, the Class Seq will have the special methods that we already know: __init__() for initializing the object and __str__() for printing the object as a sequence
Before starting Practice 1, spend time finishing the previous practices. This practice is based on this previous work
We will develop the Seq class incrementally, starting from your work on the Session 6
Create a new python file, called Seq1.py in the P1 folder. This file is our module, that we will import from our exercises. Remember that for doing so, you have first to mark the P1 folder as Sources Root
Copy the Seq Class that you have already developed in the exercises of Session 6 in the Seq1.py file
- Filename: P1/Seq1.py
- Description: This file where the Seq Class for working with DNA sequences is stored. It is our Seq1 module
The goal of this first exercise is making sure that you can access to the Seq class from external files
- Filename: P1/Ex1.py
- Description: Write a python program that creates an object with the sequence "ACTGA" and prints its length and the sequence itself. The output should be like this:
-----| Exercise 1 |------
New sequence created!
Sequence 1: (Length: 5) ACTGA
Process finished with exit code 0
- Considerations: The first thing you have to do is to import the Seq Class from the Seq1 module
from Seq1 import SeqWe will manage three types of sequences: Valid, Invalid and Null:
- 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"
- Invalid: A sequence that has one or more characters that are not valid bases. Example: "ATTXXG"
In this exercise we will implement the Null sequences
The null sequences are created by calling the Seq() class with no arguments:
# -- Creating a Null sequence
s = Seq()
# -- Creating a valid sequence
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:
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
When a Null sequence is created, the __init()__ method will print the message: "NULL Seq Created"
- 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:
-----| Practice 1, Exercise 2 |------
NULL Seq created
New sequence created!
Sequence 1: NULL
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
In this exercise we will make sure that our Seq class works ok with the three types of sequences. We will create this three sequences:
# -- Create a Null sequence
s1 = Seq()
# -- Create a valid sequence
s2 = Seq("ACTGA")
# -- Create an invalid sequence
s3 = Seq("Invalid sequence")- Filename: P1/E3.py
- Description: Write a python program that creates three sequences: null, valid and invalid. Then it prints the objects in the console. This is what we should see on the console:
-----| Practice 1, Exercise 3 |------
NULL Seq created
New sequence created!
INVALID Seq!
Sequence 1: NULL
Sequence 2: ACTGA
Sequence 3: ERROR
The len() method should works with the three types of sequences. In case the sequence is Null or invalid, the length should be always 0. Implement this behaviour in the Seq Class
- 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:
-----| Practice 1, Exercise 4 |------
NULL Seq created
New sequence created!
INVALID Seq!
Sequence 1: (Length: 0) NULL
Sequence 2: (Length: 5) ACTGA
Sequence 3: (Length: 0) ERROR
Process finished with exit code 0
Implement the count_base(base) method. If the sequence is Null or invalid, the return value should be 0
- Filename: P0/Ex5.py
- Desription: Write a python program that creates three sequences: null, valid and invalid. Then it prints their lengths, sequences and the number of bases on the console. This is what we should see on the console:
-----| Practice 1, Exercise 5 |------
NULL Seq created
New sequence created!
INVALID Seq!
Sequence 0: (Length: 0) NULL
A: 0, C: 0, T: 0, G: 0,
Sequence 1: (Length: 5) ACTGA
A: 2, C: 1, T: 1, G: 1,
Sequence 2: (Length: 0) ERROR
A: 0, C: 0, T: 0, G: 0,
Process finished with exit code 0
Implement the count() method. If the sequence is Null or invalid, the returned dictionary should have all its values to 0
- Filename: P0/Ex6.py
- Desription: Write a python program that creates three sequences: null, valid and invalid. Then it prints their lengths, sequences and dictionary returned by the count() method. This is what we should see on the console:
-----| Practice 1, Exercise 6 |------
NULL Seq created
New sequence created!
INVALID Seq!
Sequence 0: (Length: 0) NULL
Bases: {'A': 0, 'T': 0, 'C': 0, 'G': 0}
Sequence 1: (Length: 5) ACTGA
Bases: {'A': 2, 'T': 1, 'C': 1, 'G': 1}
Sequence 2: (Length: 0) ERROR
Bases: {'A': 0, 'T': 0, 'C': 0, 'G': 0}
Process finished with exit code 0
Write a python program that automatically calculate the answer to this question:
- Which is the most frequent base in each gene?
- Filename: P0/Ex8.py
- Output: This is what should be seen on the console after the execution. The X letter is the answer for that gene (The value is not shown in this output, you should calculate it)
-----| Exercise 7 |------
Gene U5: Most frequent Base: X
Gene ADA: Most frequent Base: X
Gene FRAT1: Most frequent Base: X
Gene FXN: Most frequent Base: X
Gene U5: Most frequent Base: X
Process finished with exit code 0
The session is finished. Make sure, during this week, that everything in this list is checked!
- You have all the items of the session 6 checked!
- Your working repo contains the P1 Folder with the following files:
- Ex1.py
- Ex2.py
- Ex3.py
- Ex4.py
- Ex5.py
- Ex6.py
- Ex7.py
- Ex8.py
- Seq0.py
- All the previous files have been pushed to your remote Github repo
- Juan González-Gómez (Obijuan)

- Alvaro del Castillo. He designed and created the original content of this subject. Thanks a lot :-)

S0: Introduction
S1: Tools I
S2: Tools II
S3: Practicing with the tools
S8: Client-Server-1
S9: Client-Server-2
S10: Client-server-3
S11: Client-server-4
S12: HTTP protocol-1
S13: HTTP protocol-2
S14: HTTP module
S15: HTTP module
S16: HTML forms
S17: HTML forms