Skip to content

Commit 723120d

Browse files
committed
Improve PDB table and add functionality for PDB index
1 parent 1587d30 commit 723120d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

code/database.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def add_pdb(db_fn, pdb_fn):
7878

7979
# todo: check if pdb file already exists in database and if so don't add it
8080
# or handle the exception that occurs when you try to add it anyway (sqlite3.IntegrityError)
81-
sql = "INSERT INTO pdb_file(pdb_fn, aa_sequence, seq_len) VALUES(?,?,?)"
81+
sql = "INSERT OR IGNORE INTO pdb_file(pdb_fn, aa_sequence, seq_len) VALUES(?,?,?)"
8282
con = sqlite3.connect(db_fn)
8383
cur = con.cursor()
8484
cur.execute(sql, (basename(pdb_fn), seq, len(seq)))
@@ -105,6 +105,17 @@ def main(args):
105105
for pdb_fn in pdb_fns:
106106
add_pdb(args.db_fn, pdb_fn)
107107

108+
elif args.mode == "pdb_index":
109+
# create a PDB file index, similar to the database table from "add_pdbs" above
110+
# todo: better file for this code? it's similar to add_pdbs so keeping it here for now
111+
pdb_dir = "pdb_files/prepared_pdb_files"
112+
pdb_fns = [join(pdb_dir, x) for x in os.listdir(pdb_dir) if x.endswith(".pdb")]
113+
with open(join(pdb_dir, "index.csv"), "w") as f:
114+
f.write("pdb_fn,aa_sequence,seq_len\n")
115+
for pdb_fn in pdb_fns:
116+
seq = utils.get_seq_from_pdb(pdb_fn)
117+
f.write("{},{},{}\n".format(basename(pdb_fn), seq, len(seq)))
118+
108119

109120
if __name__ == "__main__":
110121
parser = argparse.ArgumentParser(
@@ -115,7 +126,7 @@ def main(args):
115126
parser.add_argument("mode",
116127
help="run mode",
117128
type=str,
118-
choices=["create", "add_pdbs"])
129+
choices=["create", "add_pdbs", "pdb_index"])
119130

120131
parser.add_argument("--db_fn",
121132
help="path to database file",

0 commit comments

Comments
 (0)