"You need to ensure that no integer division is performed in case you do not want to loose the decimal places. However, in Python you do not need to worry about this."
"The primer's properties are all in a suitable range. However, to evaluate the actual suitability of the primer, its mapping uniqueness and mapping capability to the site of interest are also relevant."
],
"metadata": {
"id": "f5SE2eaBsLEF"
}
},
{
"cell_type": "markdown",
"source": [
"**Additional exercises**"
],
"metadata": {
"id": "Yapp44wzin7Z"
}
},
{
"cell_type": "markdown",
"source": [
"2.5) Test if the primer contains a hairpin structure."
ValueError: could not convert string to float: 'Python'
%% Cell type:markdown id: tags:
---
1.7) What is a pitfall in regards to division when working with int/float?
%% Cell type:code id: tags:
```
a = 3
b = 2
print(a / b)
```
%%Output
1.5
%% Cell type:markdown id: tags:
You need to ensure that no integer division is performed in case you do not want to loose the decimal places. However, in Python you do not need to worry about this.
%% Cell type:markdown id: tags:
## Part2 - Functions
%% Cell type:markdown id: tags:
Primer:'ATGCCATGCATTCGACTACG'
%% Cell type:markdown id: tags:
---
2.1) Calculate length of primer and print it!
%% Cell type:code id: tags:
```
primer = "ATGCCATGCATTCGACTACG"
print(len(primer))
```
%% Output
20
%% Cell type:markdown id: tags:
---
2.2) Get number of 'G's and print it!
%% Cell type:code id: tags:
```
positions = [i for i in range(len(primer)) if primer[i] == 'G']
print(positions)
print(len(positions))
```
%%Output
[2, 7, 13, 19]
4
%% Cell type:markdown id: tags:
---
2.3) Write a function to analyze the nucleotide composition of a primer and print it!
gc_clamp = (primer[-1] == "G" or primer[-1] == "C") and (primer[-2] == "G" or primer[-2] == "C")
print(f"GC clamp: {gc_clamp}")
compute_primer_properties(primer)
```
%% Output
Length: 20
GC content: 50.0 %
Temperature: 60 degrees celsius
GC clamp: True
%% Cell type:markdown id: tags:
The primer's properties are all in a suitable range. However, to evaluate the actual suitability of the primer, its mapping uniqueness and mapping capability to the site of interest are also relevant.
%% Cell type:markdown id: tags:
**Additional exercises**
%% Cell type:markdown id: tags:
2.5) Test if the primer contains a hairpin structure.
%% Cell type:code id: tags:
```
def get_reverse_complement(sequence):
bases = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
rev_comp = []
for i in range(len(sequence)-1, -1, -1):
rev_comp += [bases[sequence[i]]]
return ''.join(rev_comp)
"""
Computes all exact matches between seq and other_seq
this method is naive and can be optimized
output is a list of 4-tuples of the form
(start position in seq, start position in other_seq, length of the match, matching string)