+ added some testcases
[qpalma.git] / tests / test_qpalma_prediction.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import pdb
5 import unittest
6 import numpy
7 import os.path
8 import cPickle
9
10 from qpalma_main import QPalma
11 from Utils import pprint_alignment
12 from qpalma.sequence_utils import alphabet
13
14 jp = os.path.join
15
16
17 class TestQPalmaPrediction(unittest.TestCase):
18 """
19 This class...
20 """
21
22 def setUp(self):
23 self.prediction_set = {}
24
25 read = 'catctcacagtcttcttcttcttctcgattgcagtagc'
26 currentQualities = [[40]*len(read)]
27
28 id = 1
29 chromo = 3
30 strand = '-'
31
32 tsize = 23470805
33
34 genomicSeq_start = tsize - 2048
35 genomicSeq_stop = tsize - 1990
36
37 currentSeqInfo = id,chromo,strand,genomicSeq_start,genomicSeq_stop
38
39 example = (currentSeqInfo,read,currentQualities)
40
41 self.prediction_set[id] = [example]
42
43
44
45 def testAlignments(self):
46 run_dir = '/fml/ag-raetsch/home/fabio/tmp/newest_run/alignment/saved_run'
47
48 run = cPickle.load(open(jp(run_dir,'run_obj.pickle')))
49 run['name'] = 'test_run'
50 run['result_dir'] = '/fml/ag-raetsch/home/fabio/tmp/sandbox/testcases'
51
52 param_fn = jp(run_dir,'param_526.pickle')
53 param = cPickle.load(open(param_fn))
54
55 print self.prediction_set
56 for example_key in self.prediction_set.keys():
57 print 'Current example %d' % example_key
58
59 for example in self.prediction_set[example_key]:
60 print example
61 print 'size'
62 print len(example)
63
64 qp = QPalma(True)
65 #qp.init_prediction(run,set_name)
66 allPredictions = qp.predict(run,self.prediction_set,param)
67 for elem in allPredictions:
68 dna_array = elem['dna_array']
69 read_array = elem['read_array']
70
71 dna = map(lambda x: alphabet[x],dna_array)
72 read = map(lambda x: alphabet[x],read_array)
73
74 spliceAlign = elem['spliceAlign']
75 estAlign = elem['estAlign']
76
77 line1,line2,line3 = pprint_alignment(spliceAlign, estAlign, dna, read)
78 print line1
79 print line2
80 print line3
81
82
83 if __name__ == '__main__':
84 suite = unittest.TestLoader().loadTestsFromTestCase(TestQPalmaPrediction)
85 unittest.TextTestRunner(verbosity=2).run(suite)