C5 Exercises#

c5e1: Percentage of amino acid residues#

Given a protein sequence and a residue (an amino acid): Calculate the percentage of that residue in the composition of the sequence and round it with one decimal

a. Use a function with two input parameters: the protein sequence and the residue. For each amino acid calculate its compositional percentage in the next sequence: “ACDEFGHIKLMNPQRSTVWY” (the different amino acids).

Also, use the next assertions to test the function:

assert protein_residue_percentage("MSRSLLLRFLLFLLLLPPLP", "M") == 5.0
assert protein_residue_percentage("MSRSLLLRFLLFLLLLPPLP", "r") == 10.0
assert protein_residue_percentage("msrslllrfllfllllpplp", "L") == 50.0
assert protein_residue_percentage("MSRSLLLRFLLFLLLLPPLP", "Y") == 0.0

b. Modify the function in such a way that it will get a list of residues instead of one residue and it will calculate the compositional percentage of all the residues from the list. If no list is provided it should provide the compositional percentage for the hydrophobic residues (A, I, L, M, F, W, Y, V).
Also, test the function with the next assertions:

assert protein_residues_percentage("MSRSLLLRFLLFLLLLPPLP", ["M"]) == 5.0
assert protein_residues_percentage("MSRSLLLRFLLFLLLLPPLP", ['M', 'L']) == 55.0
assert protein_residues_percentage("MSRSLLLRFLLFLLLLPPLP", ['F', 'S', 'L']) == 70.0
assert protein_residues_percentage("MSRSLLLRFLLFLLLLPPLP") == 65.0

Sample#

Input a:

seq = "ACDEFGHIKLMNPQRSTVWY" # the different amino acids

Output a:

ADEFGHIKLMNPQRSTVWY 20
A: 5.0
C: 5.0
D: 5.0
E: 5.0
F: 5.0
G: 5.0
H: 5.0
I: 5.0
K: 5.0
L: 5.0
M: 5.0
N: 5.0
P: 5.0
Q: 5.0
R: 5.0
S: 5.0
T: 5.0
V: 5.0
W: 5.0
Y: 5.0

Input b:

seq = "ACDEFGHIKLMNPQRSTVWY" # the different amino acids and no list is provided. 
                             # The function will use the hydrophobics by default

Output b:

ACDEFGHIKLMNPQRSTVWY 20
hydrophobic residues: 40.0