· 6 years ago · Jun 26, 2019, 03:32 PM
1accession accession.version taxid gi
2V00184 V00184.1 44689 7184
3V00185 V00185.1 44689 7186
4V00187 V00187.1 44689 7190
5X07806 X07806.1 7227 8179
6
7import sqlite3
8import time
9
10start = time.time()
11
12connection = sqlite3.connect("test.sqlite")
13cursor = connection.cursor()
14
15cursor.execute("""
16 CREATE TABLE IF NOT EXISTS map (
17 accession TEXT PRIMARY KEY,
18 accession_version TEXT,
19 taxid TEXT, gi TEXT
20 )""")
21
22
23def read_large_file(f):
24 """Generator for the file"""
25 for l in f:
26 yield l.strip().split()
27
28with open("test_file.map", "r") as f:
29 next(f) # ignore header
30 cursor.executemany("INSERT INTO map VALUES (?, ?, ?, ?)", read_large_file(f))
31
32cursor.close()
33connection.commit()
34connection.close()
35
36print(time.time() - start)