-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_interaction.py
63 lines (45 loc) · 1.46 KB
/
db_interaction.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 25 20:40:30 2021
@author: anderjackf
"""
import sqlite3
def insert_org(db_path,org_data):
con = sqlite3.connect(db_path)
cur = con.cursor()
sql = "insert into Organism"
sql += "(accession,bp,type,structure,date,definition,completness,organism_name) "
sql += "values('{}','{}','{}','{}','{}','{}','{}','{}');"
sql = sql.format(org_data[0],org_data[1],org_data[2],org_data[3],
org_data[4],org_data[5],org_data[6],org_data[7])
cur.execute(sql)
con.commit()
con.close()
def insert_protein(db_path,prot_data):
con = sqlite3.connect(db_path)
cur = con.cursor()
sql = "insert into Protein"
sql += "(accession,id,product,position,translation_table,seq) "
sql += "values(?,?,?,?,?,?)"
cur.executemany(sql, prot_data)
con.commit()
con.close()
def insert_comment(db_path,comment_data):
con = sqlite3.connect(db_path)
cur = con.cursor()
sql = "insert into Comments"
sql += "(accession,comment,value) "
sql += "values(?,?,?)"
cur.executemany(sql, comment_data)
con.commit()
con.close()
def forgot_all(path):
con = sqlite3.connect(path)
cur = con.cursor()
cur.execute("DELETE from Organism")
cur.execute("DELETE from Protein")
cur.execute("DELETE from Comments")
cur.execute("DELETE from sqlite_sequence")
con.commit()
con.close()