283038245f96a43c92d9a0ac5608fa6f9b1931a0
[qpalma.git] / tests / test_qpalma_prediction.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import cPickle
5 import math
6 import numpy
7 import os.path
8 import pdb
9 import unittest
10
11 from qpalma_main import QPalma
12 from Utils import print_prediction
13
14 from createAlignmentFileFromPrediction import alignment_reconstruct
15
16 jp = os.path.join
17
18
19 class TestQPalmaPrediction(unittest.TestCase):
20 """
21 This class...
22 """
23
24 def _setUp(self):
25 data_fn = '/fml/ag-raetsch/home/fabio/tmp/vmatch_evaluation/spliced_1/dataset/prediction_set.pickle'
26
27 self.prediction_set = cPickle.load(open(data_fn))
28
29
30
31 def setUp(self):
32 print
33 self.prediction_set = {}
34
35 # xxxxxxxxxxx_______________________________________________________________________xxxxxxxxxxxxxxxxxxxxxxxxxxx
36 # 'tattttggaaggtatttcatctctccgacattgctctcaacactgtcccctccaatgcctagtccttttatttttttcttagttccaattcccttaaatacatctcacagtcttcttcttcttctcgattgcagtagc'
37
38 read = 'tattttggaagttccaattcccttaatacatctcacag'
39 currentQualities = [[30]*len(read)]
40
41 id = 1
42 chromo = 3
43 strand = '-'
44
45 tsize = 23470805
46
47 genomicSeq_start = tsize - (2038+10)
48 genomicSeq_stop = tsize - 1900 + 10
49 print 'Position: ',
50 print genomicSeq_start,genomicSeq_stop
51
52 currentSeqInfo = id,chromo,strand,genomicSeq_start,genomicSeq_stop
53
54 example = (currentSeqInfo,read,currentQualities)
55 self.prediction_set[id] = [example]
56
57 # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
58 # 'gctactgcaatcgagaagaagaagaagactgtgagatgtatttaagggaattggaactaagaaaaaaataaaaggactaggcattggaggggacagtgttgagagcaatgtcggagagatgaaataccttccaaaata'
59
60 read = 'gctactgcaatcgagaagaagaagaagactatgaaata'
61 currentQualities = [[40]*30+[22]*8]
62
63 id = 2
64 chromo = 3
65 strand = '+'
66
67 tsize = 23470805
68
69 genomicSeq_start = tsize - (2038+10)
70 genomicSeq_stop = tsize - 1900 + 10
71 print 'Position: ',
72 print genomicSeq_start,genomicSeq_stop
73
74 currentSeqInfo = id,chromo,strand,genomicSeq_start,genomicSeq_stop
75
76 example = (currentSeqInfo,read,currentQualities)
77 self.prediction_set[id] = [example]
78
79
80 def testAlignments(self):
81 run_dir = '/fml/ag-raetsch/home/fabio/tmp/newest_run/alignment/saved_run'
82
83 run = cPickle.load(open(jp(run_dir,'run_obj.pickle')))
84 run['name'] = 'test_run'
85 run['result_dir'] = '/fml/ag-raetsch/home/fabio/tmp/sandbox/testcases'
86
87 param_fn = jp(run_dir,'param_526.pickle')
88 param = cPickle.load(open(param_fn))
89
90 print self.prediction_set
91 for example_key in self.prediction_set.keys():
92 print 'Current example %d' % example_key
93
94 for example in self.prediction_set[example_key]:
95 print example
96 print 'size'
97 print len(example)
98
99 qp = QPalma(True)
100 #qp.init_prediction(run,set_name)
101 allPredictions = qp.predict(run,self.prediction_set,param)
102 for current_prediction in allPredictions:
103 align_str = print_prediction(current_prediction)
104 print align_str
105
106 id = current_prediction['id']
107 seq = current_prediction['read']
108 dna = current_prediction['dna']
109 chromo = current_prediction['chr']
110 strand = current_prediction['strand']
111 start_pos = current_prediction['start_pos']
112 predExons = current_prediction['predExons']
113
114 numExons = int(math.ceil(len(predExons) / 2))
115
116 print alignment_reconstruct(current_prediction,numExons)
117 #print id,start_pos,predExons
118
119
120 if __name__ == '__main__':
121 suite = unittest.TestLoader().loadTestsFromTestCase(TestQPalmaPrediction)
122 unittest.TextTestRunner(verbosity=2).run(suite)