-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_stru_seq.py
More file actions
executable file
·66 lines (50 loc) · 1.94 KB
/
generate_stru_seq.py
File metadata and controls
executable file
·66 lines (50 loc) · 1.94 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
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
import os
import sys
import pandas as pd
sys.path.append("code")
from foldseek_util import get_struc_seq
def process_cif_files(directory, batch_size=100):
data = []
failed_ids = []
count = 0
for filename in os.listdir(directory):
if filename.endswith(".cif"):
path = os.path.join(directory, filename)
uniprot_id = filename.split(".")[0]
chain_found = False
for chain in [chr(i) for i in range(ord("A"), ord("Z") + 1)]:
try:
parsed_seqs = get_struc_seq(path, chains=[chain])
if chain in parsed_seqs:
seq, _, struc_seq = parsed_seqs[chain]
data.append(
{
"Uniprot_ID": uniprot_id,
"Alpha_seq": seq,
"Alpha_stru_seq": struc_seq,
}
)
count += 1
if count % batch_size == 0:
save_to_csv(data, append=True)
data = []
chain_found = True
break
except Exception as e:
print(f"Error processing {filename}: {e}")
if not chain_found:
failed_ids.append(uniprot_id)
if data:
save_to_csv(data, append=True)
if failed_ids:
with open("failed_pdb_ids_lit.txt", "w") as f:
for id in failed_ids:
f.write(f"{id}\n")
def save_to_csv(data, append=False):
df = pd.DataFrame(data)
mode = "a" if append else "w"
header = not append
# df.to_csv('Alphafold_pdb_seq.csv', mode=mode, index=False, header=header)
# df.to_csv('PDB_seq_ext.csv', mode=mode, index=False, header=header)
directory = "alphafold_approved"
process_cif_files(directory, batch_size=100)