import pandas as pd import numpy as np # This was downloaded from https://github.com/tommyhuangthu/SAAINT/tree/main/saaintdb saaint_db = pd.read_csv('saaintdb_20260226_all.csv') # Add 'PDB_ID_chain' column (will be used as unique ID) # Add 'hl_label' column (HL, H_only, L_only) def chain_ok(x): # Check if chain ID is valid (not NaN and not "N.A.") if pd.isna(x): return False x = str(x).strip() return (x != "") and (x.upper() not in {"N.A."}) def hl_label_from_row(row): # Determine HL status label for each row h_ok = chain_ok(row["H_chain_ID"]) l_ok = chain_ok(row["L_chain_ID"]) if h_ok and l_ok: return "HL" elif h_ok and (not l_ok): return "H_only" elif (not h_ok) and l_ok: return "L_only" else: return "none" def make_unique_id(row): # Create a unique identifier based on PDB ID and chain IDs pdb_id = str(row["PDB_ID"]).strip() heavy = str(row["H_chain_ID"]).strip() if not pd.isna(row["H_chain_ID"]) else "" light = str(row["L_chain_ID"]).strip() if not pd.isna(row["L_chain_ID"]) else "" h_ok = chain_ok(heavy) l_ok = chain_ok(light) if h_ok and l_ok: return f"{pdb_id}_{heavy}_{light}" elif h_ok: return f"{pdb_id}_{heavy}" elif l_ok: return f"{pdb_id}_{light}" else: return pdb_id # 1) Generate unique IDs for each antibody chain combination saaint_db["PDB_ID_chain"] = saaint_db.apply(make_unique_id, axis=1) # 2) Generate HL status label (strata) for each row saaint_db["hl_label"] = saaint_db.apply(hl_label_from_row, axis=1) # 3) Create a PDB-level summary (remove duplicates caused by multiple rows per PDB) pdb_summary = ( saaint_db[["PDB_ID", "hl_label"]] .drop_duplicates(subset=["PDB_ID"]) .copy() ) # 4) Print the number of unique PDB entries per HL label print("=== Number of unique PDBs per hl_label ===") print(pdb_summary["hl_label"].value_counts(dropna=False).to_string())