| import pandas as pd |
| from pathlib import Path |
| import re |
|
|
| |
| 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 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" |
| ), |
| }) |
|
|
|
|
| |
| 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) |