/
benchmark.py
executable file
·148 lines (140 loc) · 5.37 KB
/
benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /usr/bin/env python
#coding=utf-8
import sqlite3
import sys
from sqlitedb import sqlitedb
from CAREdb import CAREdb
import time
SQL=["attach ':memory:' as cache",
"create table cache.Scanned as select * from Scanned",
"create table cache.Instance as select * from Instance",
#"select REF_SeqName from Scanned where REF_MotifSeq=498",
"select REF_SeqName from Scanned where REF_MotifSeq=498",
"""
select distinct count(*) from
(select REF_SeqName from Scanned where REF_MotifSeq=498
INTERSECT
select REF_SeqName from Scanned where REF_MotifSeq=237)
""",
"""
select count(distinct REF_SeqName) from Scanned where REF_MotifSeq in (
select REF_MotifSeq from instance where REF_Motif=498)
""",
"""
select count(distinct REF_SeqName) from Scanned where REF_MotifSeq in (
select distinct REF_MotifSeq from instance where REF_Motif=498)
""",
"select REF_MotifSeq from instance where REF_Motif=498",
"select distinct REF_MotifSeq from instance where REF_Motif=498",
"select count(REF_MotifSeq) from instance where REF_Motif=498",
"select count(distinct REF_MotifSeq) from instance where REF_Motif=498",
"""
SELECT DISTINCT REF_SeqName
FROM cache.Scanned
WHERE REF_MotifSeq IN (
SELECT REF_MotifSeq
FROM cache.Instance
WHERE REF_Motif=3)
""",
"""
SELECT DISTINCT REF_SeqName
FROM Scanned
WHERE REF_MotifSeq IN (
SELECT REF_MotifSeq
FROM Instance
WHERE REF_Motif=3)
"""
]
SQL2=["attach ':memory:' as cache",
"create table cache.Scanned as select * from Scanned",
"create table cache.Instance as select * from Instance",
#"select REF_SeqName from cache.Scanned where REF_MotifSeq=498",
"""
select distinct count(*) from
(select REF_SeqName from Scanned where REF_MotifSeq=1
INTERSECT
select REF_SeqName from Scanned where REF_MotifSeq=3)
""",
"""
select count(distinct REF_SeqName) from
(select REF_SeqName from cache.Scanned where REF_MotifSeq=1
INTERSECT
select REF_SeqName from cache.Scanned where REF_MotifSeq=3)
""",
"""
select count(distinct REF_SeqName) from
(select distinct REF_SeqName from cache.Scanned where REF_MotifSeq in (
select REF_MotifSeq from cache.Instance where REF_Motif=1)
INTERSECT
select distinct REF_SeqName from cache.Scanned where REF_MotifSeq in (
select REF_MotifSeq from cache.Instance where REF_Motif=3))
""",
"""
select count(distinct REF_SeqName) from
(select distinct REF_SeqName from cache.Scanned where REF_MotifSeq in (
select REF_MotifSeq from Instance where REF_Motif=1)
INTERSECT
select distinct REF_SeqName from cache.Scanned where REF_MotifSeq in (
select REF_MotifSeq from Instance where REF_Motif=3))
""",
"""
select count(distinct REF_SeqName) from
(select distinct REF_SeqName from cache.Scanned where REF_MotifSeq in (
select distinct REF_MotifSeq from cache.Instance where REF_Motif=1)
INTERSECT
select distinct REF_SeqName from cache.Scanned where REF_MotifSeq in (
select distinct REF_MotifSeq from cache.Instance where REF_Motif=3))
""",
"""
select count(distinct REF_SeqName) from cache.Scanned where REF_MotifSeq in (
select REF_MotifSeq from cache.Instance where REF_Motif=1)
""",
"""
select count(distinct REF_SeqName) from cache.Scanned where REF_MotifSeq in (
select REF_MotifSeq from cache.Instance where REF_Motif=1)
""",
"""
select count(distinct REF_SeqName) from cache.Instance,cache.Scanned
where REF_Motif=1 and cache.Scanned.REF_MotifSeq=cache.Instance.REF_MotifSeq
""",
"""
select count(distinct REF_SeqName) from cache.Instance,cache.Scanned
where cache.Scanned.REF_MotifSeq=cache.Instance.REF_MotifSeq and REF_Motif=1
"""
]
SQL3=[
"""
SELECT REF_SeqName,REF_Motif,REF_Organism,Description,start,stop,strand,pValue
FROM cache.Instance,cache.Scanned
WHERE cache.Instance.REF_MotifSeq=cache.Scanned.REF_MotifSeq
AND REF_SeqName in ('40747','10669','1620','5828','30256','10402')
""",
]
benchmark=CAREdb('RAP_3kbp.db')
benchmark.cache('Instance')
benchmark.cache('Scanned',['REF_SeqName','REF_MotifSeq','start','stop','strand','pValue'],SeqName=['40747','10669','1620','5828','30256','10402'])
for sql in SQL3:
print sql
timestamp=time.time()
benchmark.cur.execute(sql)
print [rs[0] for rs in benchmark.cur.fetchall()]
print time.time()-timestamp
'''
print "------------"
tables=['Scanned','cache.Scanned']
for tname in tables:
timestamp=time.time()
#benchmark.select(tname)
benchmark.cache(colums=['REF_SeqName','REF_MotifSeq'])
print time.time()-timestamp
benchmark=CAREdb('RAP_3kbp.db')
timestamp=time.time()
#benchmark.select('Motif_SeqName',['REF_SeqName','REF_Motif'])
print time.time()-timestamp
print "--------------"
timestamp=time.time()
#benchmark.cache('Scanned',['REF_SeqName','REF_MotifSeq','start'])
#benchmark.select('cache.Motif_SeqName',['REF_SeqName','REF_Motif'])
print len(benchmark.loadDB2dict('fa_file',1,0))
print time.time()-timestamp
'''