Upload src/01_build_list.py with huggingface_hub
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148#!/usr/bin/env python3"""Scan pieces/2026_01_26 for cullpdb_* list and .fasta pairs. Writes:1) cullpdb_list_fasta_index.csv - paired only, with full paths2) cullpdb_full_compiled_list.csv - every list and every fasta found (full compiled list)"""import csvimport refrom pathlib import Pathfrom typing import Optional
SCRIPT_DIR = Path(__file__).resolve().parentBASE = SCRIPT_DIR.parentCULLPDB_DIR = BASE / "pieces" / "2026_01_26"CURATED_DIR = BASE / "curated_csv"OUT_CSV = CURATED_DIR / "cullpdb_list_fasta_index.csv"FULL_LIST_CSV = CURATED_DIR / "cullpdb_full_compiled_list.csv"
# cullpdb_pc20.0_res0.0-1.0_noBrks_len40-10000_R0.2_Xray_d2026_01_26_chains300PAT = re.compile( r"^cullpdb_pc([\d.]+)_res([\d.]+)-([\d.]+)_" r"(?:(noBrks)_)?" r"len40-10000_R([\d.]+)_" r"(.+?)_d\d{4}_\d{2}_\d{2}_chains(\d+)$")
def parse_basename(name: str) -> Optional[dict]: base = name.removesuffix(".fasta") m = PAT.match(base) if not m: return None pc, res_min, res_max, no_brks, r_cutoff, methods, n_chains = m.groups() n = int(n_chains) no_brk = no_brks is not None return { "list_basename": base, "fasta_basename": base + ".fasta", "n_chains": n, "pc": float(pc), "resolution": f"{res_min}-{res_max}", "no_breaks": "yes" if no_brk else "no", "R": float(r_cutoff), "Nmethods": methods, }
def main(): dir_path = Path(CULLPDB_DIR) if not dir_path.is_dir(): print(f"Missing cullpdb dir: {dir_path}") return dir_path = dir_path.resolve() # Collect every basename that has a list and/or fasta bases = set() for p in dir_path.iterdir(): if not p.is_file(): continue name = p.name if not name.startswith("cullpdb_") or "len40-10000" not in name: continue base = name.removesuffix(".fasta") bases.add(base)
# Full compiled list: one row per basename, list path + fasta path (full), and parsed params full_rows = [] paired_rows = [] for base in sorted(bases): list_path = dir_path / base fasta_path = dir_path / (base + ".fasta") list_exists = list_path.exists() fasta_exists = fasta_path.exists() parsed = parse_basename(base) if not parsed: full_rows.append({ "list_basename": base, "fasta_basename": base + ".fasta", "list_path": str(list_path) if list_exists else "", "fasta_path": str(fasta_path) if fasta_exists else "", "list_exists": list_exists, "fasta_exists": fasta_exists, "paired": list_exists and fasta_exists, "n_chains": "", "pc": "", "resolution": "", "no_breaks": "", "R": "", "Nmethods": "", }) continue row_full = { "list_basename": base, "fasta_basename": base + ".fasta", "list_path": str(list_path) if list_exists else "", "fasta_path": str(fasta_path) if fasta_exists else "", "list_exists": list_exists, "fasta_exists": fasta_exists, "paired": list_exists and fasta_exists, "n_chains": parsed["n_chains"], "pc": parsed["pc"], "resolution": parsed["resolution"], "no_breaks": parsed["no_breaks"], "R": parsed["R"], "Nmethods": parsed["Nmethods"], } full_rows.append(row_full) if list_exists and fasta_exists: paired_rows.append({ "list_basename": base, "fasta_basename": base + ".fasta", "list_path": str(list_path), "fasta_path": str(fasta_path), "n_chains": parsed["n_chains"], "pc": parsed["pc"], "resolution": parsed["resolution"], "no_breaks": parsed["no_breaks"], "R": parsed["R"], "Nmethods": parsed["Nmethods"], })
CURATED_DIR.mkdir(parents=True, exist_ok=True) # 1) Paired index with full paths fieldnames = [ "list_basename", "fasta_basename", "list_path", "fasta_path", "n_chains", "pc", "resolution", "no_breaks", "R", "Nmethods", ] with open(OUT_CSV, "w", newline="") as f: w = csv.DictWriter(f, fieldnames=fieldnames) w.writeheader() w.writerows(paired_rows) print(f"Wrote {OUT_CSV} with {len(paired_rows)} list↔fasta pairs (full paths).")
# 2) Full compiled list: every basename, list/fasta paths and exists flags full_fieldnames = [ "list_basename", "fasta_basename", "list_path", "fasta_path", "list_exists", "fasta_exists", "paired", "n_chains", "pc", "resolution", "no_breaks", "R", "Nmethods", ] with open(FULL_LIST_CSV, "w", newline="") as f: w = csv.DictWriter(f, fieldnames=full_fieldnames) w.writeheader() w.writerows(full_rows) n_paired = sum(1 for r in full_rows if r["paired"]) print(f"Wrote {FULL_LIST_CSV} with {len(full_rows)} entries (full compiled list); {n_paired} paired.")
if __name__ == "__main__": main()src/01_build_list.pyAdded+148