I am trying to write a code in Python to takes in a list of DNA sequence and return scores based on the following factors:
- If the base is A or T, 0 should be added to the previous number
- If the base is G, 1 should be added
- If the base is C, 1 should be subtracted.
such that given the following DNA sequence, "CATGGGCATCGGCCATACGCC", the output should be [0 -1 -1 -1 0 1 2 1 1 1 0 1 2 1 0 0 0 0 -1 0 -1 -2]
I have tried this code
seq = "CATGGGCATCGGCCATACGCC"
def skew(seq):
list_seq = list(seq)
values = [0]
for base in list_seq:
if base == "A" or "T":
values.append(values[-1])
elif base == "C":
values.append(values[-1] - 1)
elif base == "G":
values.append(values[-1] + 1)
else:
return "Invalid text"
return values
This is the output
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]