ee8e9af379845dfccd63df44f74d869d4d1aa87f
[qpalma.git] / tools / evaluatePrediction.py
1 #!/usr/bin/env python
2 # -*- coding:latin-1 -*-
3
4 import sys
5 import cPickle
6
7 ground_truth = cPickle.load(sys.argv[1])
8 prediction = cPickle.load(sys.argv[2])
9
10 ESTs = ground_truth['TestEsts']
11 Exons = ground_truth['TestExon']
12 Acc = ground_truth['TestAcc']
13 Don = ground_truth['TestDon']
14 DNA = ground_truth['Test']
15
16 totalWrongPos = [0]*len(prediction)
17
18 for pos,alignmentObj in enumerate(prediction):
19 predPos = zips(alignmentObj.tStarts, alignmentObj.tEnds)
20 wrongPos = 0
21
22 for predExonStart,predExonStop in predPos:
23
24 for pos,currentExons in enumerate(Exons):
25 for idx in range(1,len(currentExons)-1):
26
27 intronStart = currentExons[idx][1]
28 intronStop = currentExons[idx+1][0]
29
30 # est is covering full intron
31 if intronStart > predExonStart and intronStop < predExonStop:
32 #fprintf(fh,sprintf(' %s is completely overlapping from %d %d\n',currentESTName,intronStart,intronStop));
33 wrongPos += intronStop-intronStart
34 # est is nested inside intron
35 elif intronStart < predExonStart and intronStop > predExonStop:
36 #fprintf(fh,sprintf(' %s is completely inside intron from %d %d\n',currentESTName,predExonStart,predExonStop));
37 wrongPos += intronStop-intronStart
38 # end of exonth is nested inside predExoniction
39 elif intronStart > predExonStart and predExonStop > intronStart and intronStop > predExonStop:
40 #fprintf(fh,sprintf('%s is upstream overlapping from %d %d\n',currentESTName,intronStart,predExonStop));
41 wrongPos += intronStop-intronStart
42 # predExoniction is nested inside exonth
43 elif intronStart < predExonStart and predExonStart < intronStop and intronStop < predExonStop:
44 #fprintf(fh,sprintf('%s is downstream overlapping from %d %d\n',currentESTName,predExonStart,intronStop));
45 wrongPos += intronStop-intronStart
46 else:
47 pass
48
49 totalWrongPositions[pos] = wrongPos