I am trying to create a function that takes 2 DNA sequences as arguments and checks for 3 things (in this order):
- compares them to see if they are both the same length
- checks if they are both valid sequences (they must only contain the characters 'ACGT')
- Detrmines what type of mutation (transition or transversion) has occured between the two
I'm very new to coding so I'm not sure where my mistake is. I get no output from my code and when I do, it's an error. Any advice?
Here's what I've got so far:
dna_bases = ['ACGT']
ct = ['CT']
ag = ['AG']
def dna_comparison(seq1, seq2):
if len(seq1) != len(seq2):
print("Error: The sequences are different lengths.")
else:
for i in range(len(seq1)):
for ii in range(len(seq2)):
if seq1[i] or seq2[ii] not in dna_bases:
return False
break
else:
print("Valid sequences. The program will continue")
transitions = 0
transversions = 0
for i in range(len(seq1)):
if seq1[i] != seq2[i]:
if seq1[i] in ag and seq2[i] in ag:
transitions =+ 1
elif seq1[i] in ct and seq2[i] in ct:
transitions =+ 1
else:
transversion += 1
print (transitions)
print (transversions)
IIUC, you can do:
Prints: