I have a tab separated input file (input.txt) like:

Protein_id Prot_Length Actual_Positions Predicted _Positions
P_02929 239 103-151 57-82, 93-125, 132-164
P_02926 236 101-121, 137-145 44-165
From this range of actual and predicted positions (and total length), I need to calculate true positive (TP), true negative (TN), false positive (FP) and false negative (FN) values (in %) and calculate sensitivity and specificity from it (see calculation in output file). I need to print the output.txt file which look somewhat like:

Protein_id Prot_Length Actual_Positions Predicted _Positions TP(%) FP(%) TN(%) FN(%) TPR(Sensitivity)=TP/(TP+FN) TNR(Specificity)=TN/(FP + TN)
P_02929 239 103-151 57-82, 93-125, 132-164
P_02926 236 101-121, 137-145 44-165
Although previously I calculate the actual positions (consensus) with this:

Code:
data = [(5,15),(20,38),(25,50),(30,35),(50,60),(55,70),(80,90)]

    def sortCoord(d):
	coords = []
 
	for coord in d:
		coords.append(('s',coord[0]))
		coords.append(('e',coord[1]))

	coords.sort(key = lambda x : x[0], reverse = True)

	coords.sort(key = lambda x : x[1])

	return coords

    def overlap(c):
	
	count = 0
	posA = 0

	level = 1
	out = []
	for pos in c:
		if pos[0] == 's':
			count = 1
			level += 1
			posA = pos[1]
		if pos[0] == 'e':
			level -=1
			count -=1

		if count == 0:
                    
			if level > 1:
				out.append((posA, pos[1], level))

	return out

    def consensus(c):
	
	count = 0
	posA = 0
	out = []
	for pos in c:
		if count == 0:
			posA = pos[1]
		if pos[0] == 's':
			count += 1
		if pos[0] == 'e':
			count -=1

		if count == 0:
			out.append((posA, pos[1]))

	return out

    sortedCoords = sortCoord(data)

    consensusData = consensus(sortedCoords)
    print consensusData
But with my beginner level knowledge of python, I don't know at all how to do this. Please help.

Thank you very much for your consideration.