File size: 1,989 Bytes
d3f6b75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
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())