abbaf87f424149094be9eed7b8e5063750f81592
[qpalma.git] / cparser / test.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import qparser
5 import pdb
6
7 from qpalma.parsers import *
8
9
10 def cpu():
11 return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+\
12 resource.getrusage(resource.RUSAGE_SELF).ru_stime)
13
14
15 def test_module():
16 filename = 'allReads.full_20'
17 #filename = '/fml/ag-raetsch/share/projects/qpalma/solexa/new_run/allReads.full_10k'
18
19 start = cpu()
20 num_reads = qparser.parse_reads(filename)
21 stop = cpu()
22
23 print 'found %d num reads' % num_reads
24
25
26 def _test_module():
27 filename = '/fml/ag-raetsch/share/projects/qpalma/solexa/new_run/allReads.full_10k'
28
29 start = cpu()
30 map,result_1 = qparser.parse_reads(filename)
31 stop = cpu()
32
33 print stop - start
34
35 start = cpu()
36 result_2 = parse_filtered_reads(filename)
37 stop = cpu()
38
39 print stop - start
40
41 keys_1 = result_1.keys()
42 keys_2 = result_2.keys()
43
44 assert keys_1 == keys_2
45
46 all_eq = True
47
48 for key in keys_1:
49 elem_1 = result_1[key]
50 elem_2 = result_2[key]
51
52 att = "chr"
53 eq = elem_1[map[att]] == elem_2[att]
54 att = "seq"
55 eq = eq and elem_1[map[att]] == elem_2[att]
56 att = "strand"
57 eq = eq and elem_1[map[att]] == elem_2[att]
58 att = "splitpos"
59 eq = eq and elem_1[map[att]] == elem_2[att]
60 att = "read_size"
61 eq = eq and elem_1[map[att]] == elem_2[att]
62 att = "true_cut"
63 eq = eq and elem_1[map[att]] == elem_2[att]
64
65
66 att = "prb"
67 #eq = eq and elem_1[map[att]] == elem_2[att]
68 att = "cal_prb"
69 #eq = eq and elem_1[map[att]] == elem_2[att]
70 att = "chastity"
71 #eq = eq and elem_1[map[att]] == elem_2[att]
72
73
74 att = "gene_id"
75 eq = eq and elem_1[map[att]] == elem_2[att]
76 att = "p_start"
77 eq = eq and elem_1[map[att]] == elem_2[att]
78 att = "exon_stop"
79 eq = eq and elem_1[map[att]] == elem_2[att]
80 att = "exon_start"
81 eq = eq and elem_1[map[att]] == elem_2[att]
82 att = "p_stop"
83 eq = eq and elem_1[map[att]] == elem_2[att]
84
85 all_eq = all_eq and eq
86
87 print all_eq
88
89 if __name__ == '__main__':
90 test_module()