-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniprotDB.py
52 lines (40 loc) · 2.08 KB
/
UniprotDB.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
import sqlite3
class UniprotDB(object):
def __init__(self, databaseName):
self.db = sqlite3.connect(databaseName)
self.c = self.db.cursor()
def close(self):
self.db.close()
def deleteProteins(self):
self.c.execute("DROP TABLE IF EXISTS proteins")
self.db.commit()
def createTables(self):
self.c.execute("CREATE TABLE IF NOT EXISTS proteins(proteinID TEXT PRIMARY KEY, name TEXT, fullName TEXT, description TEXT, sequence TEXT, organism TEXT)")
self.db.commit()
def addProtein(self, proteinID, name, fullName, description, sequence, organism):
self.c.execute("INSERT INTO proteins(proteinID, name, fullName, description, sequence, organism) VALUES ('"+ proteinID + "','" + name +"','"+ fullName +"','" + description +"','" + sequence +"','" + organism +"')")
self.db.commit()
def extractProteinSeqFromSpecieCsv(self, organism):
output = open('Protein_Specie.csv', 'w+')
self.c.execute("SELECT proteinID, sequence FROM proteins WHERE organism ='"+ organism +"'")
while True:
row = self.c.fetchone()
if row == None:
break
print(row[0] + ';' + row[1], file = output)
def extractProteinSeqFromSpecie(self, organism):
self.c.execute("SELECT proteinID, sequence FROM proteins WHERE organism ='"+ organism +"'")
proteins = list(self.c.fetchall())
return proteins
def extractProteinSeqFromSpecie25(self, organism):
self.c.execute("SELECT proteinID, sequence FROM proteins WHERE organism ='"+ organism +"'")
proteins = list(self.c.fetchall())
return proteins
def extractProteins(self):
self.c.execute("SELECT proteinID, sequence FROM proteins")
proteins = list(self.c.fetchall())
return proteins
def extractProteinInformation(self, queryID):
self.c.execute("SELECT proteinID, name, description, organism, fullName, sequence FROM proteins WHERE proteinID = '" + queryID + "'")
information = self.c.fetchone()
return information