File size: 1,997 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pandas as pd
from pathlib import Path
import re

# Input
tsv_path = "sabdab_summary_all_sorted.tsv"
base_dir = Path("sabdab_dataset")

df = pd.read_csv(tsv_path, sep="\t")


def find_file(directory, pattern):
    if not directory.exists():
        return None

    regex = re.compile(pattern, re.IGNORECASE)

    for f in directory.iterdir():
        if f.is_file() and regex.fullmatch(f.name):
            # return actual existing path relative to sabdab_dataset
            return str(f.relative_to(base_dir.parent))

    return None


def get_paths(row):
    pdb = str(row["pdb"])
    H = str(row["Hchain"])
    L = str(row["Lchain"])

    pdb_dir = base_dir / pdb.lower()

    return pd.Series({
        "abangle": find_file(
            pdb_dir / "abangle",
            rf"{pdb}\.abangle"
        ),

        "annotation_H": find_file(
            pdb_dir / "annotation",
            rf"{pdb}_{H}_VH\.ann"
        ),

        "annotation_L": find_file(
            pdb_dir / "annotation",
            rf"{pdb}_{L}_VL\.ann"
        ),

        "imgt_H": find_file(
            pdb_dir / "imgt",
            rf"{pdb}_{H}_H\.ann"
        ),

        "imgt_L": find_file(
            pdb_dir / "imgt",
            rf"{pdb}_{L}_L\.ann"
        ),

        "sequence_raw": find_file(
            pdb_dir / "sequence",
            rf"{pdb}_raw\.pdb"
        ),

        "sequence_H": find_file(
            pdb_dir / "sequence",
            rf"{pdb}_{H}_VH\.fa"
        ),

        "sequence_L": find_file(
            pdb_dir / "sequence",
            rf"{pdb}_{L}_VL\.fa"
        ),

        "structure": find_file(
            pdb_dir / "structure",
            rf"{pdb}\.pdb"
        ),

        "structure_chothia": find_file(
            pdb_dir / "structure" / "chothia",
            rf"{pdb}\.pdb"
        ),
    })


# Apply row-wise
new_cols = df.apply(get_paths, axis=1)

df = pd.concat([df, new_cols], axis=1)

df.to_csv("sabdab_summary_all_with_paths.tsv", sep="\t", index=False)