#!/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}")