The exercise says the following:
"""
Pairwise comparision of DNA sequences is a popular technique used in Bioinformatics. It usually involves some scoring scheme to express the degree of similarity. Write a function that compares two DNA sequences based on the following scoring scheme: +1 for a match, +3 for each consecutive match and -1 for each mismatch.
Examples
>>> print pairwiseScore("ATTCGT", "ATCTAT")
ATTCGT
|| |
ATCTAT
Score: 2
>>> print pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA")
GATAAATCTGGTCT
|| ||| |
CATTCATCATGCAA
Score: 4
>>>
"""
so i wrote the following, which was continuously working until i started playing with it, now i cant find whats wrong with it! please help me by pointing out where i went wrong?
def pariwiseScore(seqA, seqB):
h = []
c = []
for x in range(0,len(seqA)):
if seqA[x] == seqB[x]:
h.append('|')
else:
h.append(' ')
if len(h) > 1:
if h[x] == '|':
try:
if h[x] == h[x-1]:
c.append(3)
except IndexError:
c.append(1)
elif h[x] == ' ':
c.append(-1)
else:
if h[x] == '|':
c.append(1)
elif h[x] == ' ':
c.append(-1)
a = "".join(h)
return seqA, '\n', a, '\n', seqB, '\n', 'Score: %I' % sum(c)
Any help is much appreciated.