-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate_sqlite.py
41 lines (30 loc) · 1.15 KB
/
update_sqlite.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
import SQLite
def update_database(con, db_name):
cur = con.cursor()
cur.execute(
"CREATE TABLE IF NOT EXISTS meta_data("
"upload_id INT,"
"sid_meta1_name TEXT,"
"sid_meta2_name TEXT,"
"sid_meta3_name TEXT,"
"contains_crosslink BOOLEAN)"
)
# add meta columns
try:
cur.execute('ALTER TABLE spectrum_identifications ADD COLUMN meta1 TEXT')
cur.execute('ALTER TABLE spectrum_identifications ADD COLUMN meta2 TEXT')
cur.execute('ALTER TABLE spectrum_identifications ADD COLUMN meta3 TEXT')
except Exception:
print('{}: Meta columns exist already - not updated'.format(db_name))
try:
# add precursor information from peak list file to DB
cur.execute('ALTER TABLE spectra ADD COLUMN precursor_mz TEXT')
cur.execute('ALTER TABLE spectra ADD COLUMN precursor_charge TEXT')
except Exception:
print('{}: spectrum precursor columns exist already - not updated'.format(db_name))
con.commit()
return True
import glob
for db_name in glob.glob("./dbs/saved/*.db"):
con = SQLite.connect(db_name)
update_database(con, db_name)