I have a text file in the following format:
AAAAATTTTTT
AAATTTTTTGGG
TTTDDDCCVVVVV
I am trying to calculate the number of occurrences of a character in sequence at start and end of the line.
I have written the following function:
def getStartEnd(sequence):
start = sequence[0]
end = sequence[-1]
startCount = 0
endCount = 0
for char in sequence:
if char == start:
startCount += 1
if ( char != start):
break
for char in reversed(sequence):
if char == end:
endCount += 1
if ( char != end):
break
return startCount, endCount
This function works independently on strings. For e.g.:
seq = "TTTDDDCCVVVVV"
a,b = getStartEnd(seq)
print a,b
But when I insert in a for loop, it gives the correct value only on the last line of the file.
file = open("Test.txt", 'r')
for line in file:
a,b = getStartEnd(str(line))
print a, b