-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_plasmids.py
More file actions
36 lines (31 loc) · 1.14 KB
/
update_plasmids.py
File metadata and controls
36 lines (31 loc) · 1.14 KB
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
"""
Add plasmids from the kits to the plasmids directory if they are not already present.
"""
import glob
from opencloning.dna_functions import request_from_addgene
import asyncio
import time
import pandas
kits = glob.glob("kits/*")
existing_plasmids = glob.glob("addgene_plasmids/*.gb")
existing_addgene_ids = [p.split("/")[-1][:-3] for p in existing_plasmids]
for kit in kits:
plasmids = glob.glob(f"{kit}/plasmids.tsv")
if len(plasmids) != 1:
raise Exception(f"Expected 1 plasmid file in {kit}, but found {len(plasmids)}")
plasmids_file = plasmids[0]
with open(plasmids_file, "r") as f:
df = pandas.read_csv(f, sep="\t", dtype=str)
df = df.fillna("")
addgene_ids = df["addgene_id"].tolist()
requests_made = 0
for addgene_id in addgene_ids:
if addgene_id in existing_addgene_ids:
continue
print(f"Requesting {addgene_id}")
seq = asyncio.run(request_from_addgene(addgene_id))
requests_made += 1
with open(f"addgene_plasmids/{addgene_id}.gb", "w") as f:
f.write(seq.format("genbank"))
if requests_made % 10 == 0:
time.sleep(2)