File size: 908 Bytes
bb8455b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
import csv

summary_file = "sabdab_summary_all_with_paths.tsv"
nr_file = "all_nr.tsv"
output_file = "sabdab_summary_with_nr_flag.tsv"

# Read all pdb IDs from the non-redundant set
nr_pdbs = set()
with open(nr_file, newline="") as f:
    reader = csv.DictReader(f, delimiter="\t")
    for row in reader:
        nr_pdbs.add(row["pdb"].strip().lower())

# Process the summary file and add the new column
with open(summary_file, newline="") as infile, open(output_file, "w", newline="") as outfile:
    reader = csv.DictReader(infile, delimiter="\t")
    fieldnames = reader.fieldnames + ["in_nr_set"]

    writer = csv.DictWriter(outfile, fieldnames=fieldnames, delimiter="\t")
    writer.writeheader()

    for row in reader:
        pdb = row["pdb"].strip().lower()
        row["in_nr_set"] = str(pdb in nr_pdbs)
        writer.writerow(row)

print(f"Output written to {output_file}")