forked from chiulab/surpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_taxonomy_db.py
executable file
·79 lines (67 loc) · 2.01 KB
/
create_taxonomy_db.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
#!/usr/bin/python
#
# create_taxonomy_db.py
#
# This program creates the SQLite taxonomy database used by SURPI
# Chiu Laboratory
# University of California, San Francisco
# January, 2014
#
# Copyright (C) 2014 Scot Federman - All Rights Reserved
# SURPI has been released under a modified BSD license.
# Please see license file for details.
# Last revised 7/2/2014
import sqlite3
# Create names_nodes_scientific.db
print ("Creating names_nodes_scientific.db...")
conn = sqlite3.connect('names_nodes_scientific.db')
c = conn.cursor()
c.execute('''CREATE TABLE names (
taxid INTEGER PRIMARY KEY,
name TEXT)''')
with open('names_scientificname.dmp', 'r') as map_file:
for line in map_file:
line = line.split("|")
taxid = line[0].strip()
name = line[1].strip()
c.execute ("INSERT INTO names VALUES (?,?)", (taxid, name))
d = conn.cursor()
d.execute('''CREATE TABLE nodes (
taxid INTEGER PRIMARY KEY,
parent_taxid INTEGER,
rank TEXT)''')
with open('nodes.dmp', 'r') as map_file:
for line in map_file:
line = line.split("|")
taxid = line[0].strip()
parent_taxid = line[1].strip()
rank = line[2].strip()
d.execute ("INSERT INTO nodes VALUES (?,?,?)", (taxid, parent_taxid, rank))
conn.commit()
conn.close()
# Create gi_taxid_nucl.db
print ("Creating gi_taxid_nucl.db...")
conn = sqlite3.connect('gi_taxid_nucl.db')
c = conn.cursor()
c.execute('''CREATE TABLE gi_taxid (
gi INTEGER PRIMARY KEY,
taxid INTEGER)''')
with open('gi_taxid_nucl.dmp', 'r') as map_file:
for line in map_file:
line = line.split()
c.execute("INSERT INTO gi_taxid VALUES ("+line[0]+","+line[1]+")")
conn.commit()
conn.close()
# Create gi_taxid_prot.db
print ("Creating gi_taxid_prot.db...")
conn = sqlite3.connect('gi_taxid_prot.db')
c = conn.cursor()
c.execute('''CREATE TABLE gi_taxid (
gi INTEGER PRIMARY KEY,
taxid INTEGER)''')
with open('gi_taxid_prot.dmp', 'r') as map_file:
for line in map_file:
line = line.split()
c.execute("INSERT INTO gi_taxid VALUES ("+line[0]+","+line[1]+")")
conn.commit()
conn.close()