+ added field to prediction dict
[qpalma.git] / scripts / createAlignmentFileFromPrediction.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4
5
6 import cPickle
7 import sys
8 import pydb
9 import pdb
10 import os
11 import os.path
12 import math
13
14 def prediction_on(filename):
15
16 allPredictions = cPickle.load(open(filename))
17
18 for current_example_pred in allPredictions:
19 gt_example = current_example_pred[0]
20
21 exampleId = gt_example['id']
22 originalEst = OriginalEsts[exampleIdx]
23
24 for elem_nr,current_pred in enumerate(current_example_pred[1:]):
25 current_pred
26 exampleId = curremt_pred['id']
27 predExons = current_pred['predExons']
28 trueExons = current_pred['trueExons']
29 predPositions = [elem + current_pred['alternative_start_pos'] for elem in predExons]
30 truePositions = [elem + current_pred['start_pos'] for elem in trueExons.flatten().tolist()[0]]
31
32 if predExons.shape == (2,2):
33 p1 = predExons[0,0]
34 p2 = predExons[0,1]
35 p3 = predExons[1,0]
36 p4 = predExons[1,1]
37
38 line = '%d\t%d\t%d\t%d\t%d\n' % (exampleId,p1,p2,p3,p4)
39
40 print line
41
42 def collect_prediction(current_dir,run_name):
43 """
44 Given the toplevel directory this function takes care that for each distinct
45 experiment the training and test predictions are evaluated.
46
47 """
48 train_suffix = '_allPredictions_TRAIN'
49 test_suffix = '_allPredictions_TEST'
50
51 jp = os.path.join
52 b2s = ['-','+']
53
54 currentRun = cPickle.load(open(jp(current_dir,'run_object.pickle')))
55 QFlag = currentRun['enable_quality_scores']
56 SSFlag = currentRun['enable_splice_signals']
57 ILFlag = currentRun['enable_intron_length']
58 currentRunId = '%s%s%s' % (b2s[QFlag],b2s[SSFlag],b2s[ILFlag])
59
60 filename = jp(current_dir,run_name)+train_suffix
61 print 'Prediction on: %s' % filename
62 train_result = prediction_on(filename)
63
64 filename = jp(current_dir,run_name)+test_suffix
65 print 'Prediction on: %s' % filename
66 test_result = prediction_on(filename)
67
68 return train_result,test_result,currentRunId
69
70
71 if __name__ == '__main__':
72 dir = sys.argv[1]
73 run_name = sys.argv[2]
74 collect_prediction(dir,run_name)