alanclayrichard commited on
Commit
5cc7fac
·
1 Parent(s): ab2340e

add stacks pub link

Browse files
Files changed (2) hide show
  1. config.py +1 -2
  2. scripts/build_challenge_data.py +129 -1
config.py CHANGED
@@ -48,7 +48,7 @@ REQUIRE_COMPLETE_BUNDLE = False
48
 
49
  # ------------------------------- Links ------------------------------------------------
50
 
51
- CHALLENGE_ANNOUNCEMENT_LINK = "https://github.com/PrismScienceOrg/plug"
52
  DATASET_DOWNLOAD_LINK = f"https://huggingface.co/datasets/{PUBLIC_REPO}"
53
  TUTORIAL_LINK = "https://github.com/PrismScienceOrg/plug-baselines"
54
  PLUG_REPO_LINK = "https://github.com/prism-science/plug"
@@ -237,7 +237,6 @@ ranks by that benchmark's normalised score.
237
  ---
238
 
239
  {HOW_TO_PARTICIPATE_MD if CURRENT_PHASE == 1 else ""}
240
- ---
241
 
242
  ## Acknowledgements
243
  Authors: A. Clay Richard, Brian Cheung, and Stephanie A. Wankowicz
 
48
 
49
  # ------------------------------- Links ------------------------------------------------
50
 
51
+ CHALLENGE_ANNOUNCEMENT_LINK = "https://thestacks.org/publications/plug-benchmark"
52
  DATASET_DOWNLOAD_LINK = f"https://huggingface.co/datasets/{PUBLIC_REPO}"
53
  TUTORIAL_LINK = "https://github.com/PrismScienceOrg/plug-baselines"
54
  PLUG_REPO_LINK = "https://github.com/prism-science/plug"
 
237
  ---
238
 
239
  {HOW_TO_PARTICIPATE_MD if CURRENT_PHASE == 1 else ""}
 
240
 
241
  ## Acknowledgements
242
  Authors: A. Clay Richard, Brian Cheung, and Stephanie A. Wankowicz
scripts/build_challenge_data.py CHANGED
@@ -14,9 +14,14 @@ For each benchmark it writes, under ``--out`` (default ``.challenge-data/``)::
14
 
15
  public/<benchmark>/manifest.parquet every row: datapoint_id, row_index,
16
  protein id(s), [position], split
 
 
17
  public/<benchmark>/proteins.csv protein -> Lo-Hi split
18
  private/ground_truth/<benchmark>.parquet every row: the manifest plus its labels
19
 
 
 
 
20
  and refreshes the committed ``data/<benchmark>/proteins.csv`` and
21
  ``data/lohi_provenance.json``.
22
 
@@ -59,6 +64,34 @@ from plug_challenge.benchmarks import ( # noqa: E402
59
  get,
60
  )
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  def node_of(sequence: str) -> str:
64
  """Plug's id for a protein: a hash of its sequence (``plug.graph.node_of``)."""
@@ -220,10 +253,15 @@ def build(name: str, plug: Path, split_dir: Path, out: Path, repo_root: Path) ->
220
  if sorted(manifest.columns) != sorted(expected):
221
  raise ValueError(f"{name}: manifest has {list(manifest.columns)}, expected {expected}")
222
  manifest = manifest[expected]
 
 
 
223
 
224
  manifest.to_parquet(public / "manifest.parquet", index=False)
 
 
 
225
  truth.to_parquet(private / f"{name}.parquet", index=False)
226
- proteins = protein_splits(name, rows, split_dir)
227
  proteins.to_csv(public / "proteins.csv", index=False)
228
  committed = repo_root / "data" / name
229
  committed.mkdir(parents=True, exist_ok=True)
@@ -301,6 +339,95 @@ def protein_splits(name: str, rows: list[dict], split_dir: Path) -> pd.DataFrame
301
  ).sort_values("node", ignore_index=True)
302
 
303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  def main(argv: list[str] | None = None) -> int:
305
  """Build the challenge data for the requested benchmarks.
306
 
@@ -356,6 +483,7 @@ def main(argv: list[str] | None = None) -> int:
356
  "files": provenance.get("files", {}),
357
  }
358
  (repo_root / "data" / "lohi_provenance.json").write_text(json.dumps(record, indent=2) + "\n")
 
359
 
360
  print("\n== summary ==")
361
  for name, counts in summary.items():
 
14
 
15
  public/<benchmark>/manifest.parquet every row: datapoint_id, row_index,
16
  protein id(s), [position], split
17
+ public/<benchmark>/lohi_<split>.parquet the same rows, one file per Lo-Hi split
18
+ (lohi_train, lohi_val, lohi_test, excluded)
19
  public/<benchmark>/proteins.csv protein -> Lo-Hi split
20
  private/ground_truth/<benchmark>.parquet every row: the manifest plus its labels
21
 
22
+ plus ``public/README.md``, the dataset card, whose ``configs`` make the Hub's viewer
23
+ show one subset per benchmark with the Lo-Hi splits as its splits.
24
+
25
  and refreshes the committed ``data/<benchmark>/proteins.csv`` and
26
  ``data/lohi_provenance.json``.
27
 
 
64
  get,
65
  )
66
 
67
+ # The per-split files of a manifest, and the value of its `split` column each holds. The
68
+ # names carry "lohi_" so the Hub's viewer cannot be read as its default "train" split.
69
+ SPLIT_FILES = {"lohi_train": "train", "lohi_val": "val", "lohi_test": "test", "excluded": ""}
70
+ PROTEIN_COLUMNS = ["node", "protein", "split"]
71
+ SPACE_URL = "https://huggingface.co/spaces/PrismScienceOrg/PLUG-challenge"
72
+
73
+
74
+ def check_public(frame: pd.DataFrame, name: str, what: str) -> None:
75
+ """Refuse to publish anything but identifiers and splits.
76
+
77
+ The public repo is redistributed, and not every benchmark's licence allows its labels
78
+ to be (LP-PDBBind's does not). So every public file is checked against an allow-list
79
+ of columns, rather than against a list of known labels that a new one could miss.
80
+ """
81
+ spec = get(name)
82
+ allowed = (
83
+ PROTEIN_COLUMNS
84
+ if what == "proteins"
85
+ else [ID_COLUMN, "row_index", *spec.manifest_columns, SPLIT_COLUMN]
86
+ )
87
+ extra = sorted(set(frame.columns) - set(allowed))
88
+ leaked = sorted(set(frame.columns) & set(spec.truth_columns))
89
+ if extra or leaked:
90
+ raise ValueError(
91
+ f"{name} {what}: refusing to publish columns {extra or leaked}; "
92
+ f"only {allowed} may be public"
93
+ )
94
+
95
 
96
  def node_of(sequence: str) -> str:
97
  """Plug's id for a protein: a hash of its sequence (``plug.graph.node_of``)."""
 
253
  if sorted(manifest.columns) != sorted(expected):
254
  raise ValueError(f"{name}: manifest has {list(manifest.columns)}, expected {expected}")
255
  manifest = manifest[expected]
256
+ proteins = protein_splits(name, rows, split_dir)
257
+ check_public(manifest, name, "manifest")
258
+ check_public(proteins, name, "proteins")
259
 
260
  manifest.to_parquet(public / "manifest.parquet", index=False)
261
+ for filename, value in SPLIT_FILES.items():
262
+ part = manifest[manifest[SPLIT_COLUMN] == value]
263
+ part.to_parquet(public / f"{filename}.parquet", index=False)
264
  truth.to_parquet(private / f"{name}.parquet", index=False)
 
265
  proteins.to_csv(public / "proteins.csv", index=False)
266
  committed = repo_root / "data" / name
267
  committed.mkdir(parents=True, exist_ok=True)
 
339
  ).sort_values("node", ignore_index=True)
340
 
341
 
342
+ def write_card(public: Path) -> None:
343
+ """Write the public repo's dataset card from the manifests already in ``public``.
344
+
345
+ Without a card the Hub's viewer concatenates every manifest into one table and calls
346
+ it "train". The ``configs`` here give it one subset per benchmark, whose splits are
347
+ the per-split files, and one more subset for the protein lists.
348
+ """
349
+ names = [name for name in BENCHMARK_NAMES if (public / name / "manifest.parquet").exists()]
350
+ yaml = [
351
+ "---",
352
+ "pretty_name: PLUG challenge — Lo-Hi ids and splits",
353
+ "license: other",
354
+ "tags: [biology, proteins, benchmark, data-leakage]",
355
+ "configs:",
356
+ ]
357
+ for i, name in enumerate(names):
358
+ yaml.append(f"- config_name: {name}")
359
+ if i == 0:
360
+ yaml.append(" default: true")
361
+ yaml.append(" data_files:")
362
+ for filename in SPLIT_FILES:
363
+ yaml += [f" - split: {filename}", f" path: {name}/{filename}.parquet"]
364
+ yaml += ["- config_name: proteins", " data_files:"]
365
+ for name in names:
366
+ yaml += [f" - split: {name.replace('-', '_')}", f" path: {name}/proteins.csv"]
367
+ yaml.append("---")
368
+
369
+ table = [
370
+ "| Benchmark | Identifier columns | lohi_train | lohi_val | lohi_test | excluded |",
371
+ "|---|---|---:|---:|---:|---:|",
372
+ ]
373
+ for name in names:
374
+ counts = pd.read_parquet(public / name / "manifest.parquet", columns=[SPLIT_COLUMN])[
375
+ SPLIT_COLUMN
376
+ ].value_counts()
377
+ ids = ", ".join(f"`{c}`" for c in get(name).manifest_columns)
378
+ table.append(
379
+ f"| `{name}` | {ids} | "
380
+ + " | ".join(f"{int(counts.get(v, 0)):,}" for v in SPLIT_FILES.values())
381
+ + " |"
382
+ )
383
+
384
+ body = f"""
385
+ # PLUG challenge — Lo-Hi ids and splits
386
+
387
+ The public data of the [PLUG challenge]({SPACE_URL}): for each of {len(names)} protein
388
+ benchmarks, every datapoint's identifier and the Lo-Hi split it was given.
389
+ **There are no labels here** — see [Labels](#labels).
390
+
391
+ ## Layout
392
+
393
+ One subset per benchmark. Its splits are the Lo-Hi splits:
394
+
395
+ - `lohi_train`, `lohi_val`: train and tune on these (supervised track).
396
+ - `lohi_test`: the held-out rows the supervised track is scored on.
397
+ - `excluded`: rows the Lo-Hi k-cut dropped to keep similar proteins out of different
398
+ splits. The unsupervised track scores every row, these included.
399
+
400
+ {chr(10).join(table)}
401
+
402
+ Each file has `datapoint_id`, `row_index`, the benchmark's own identifier columns, and
403
+ `split`. `<benchmark>/manifest.parquet` holds all of a benchmark's rows in one file, with
404
+ `split` empty for an excluded row. The `proteins` subset lists each benchmark's proteins
405
+ (`node`, plug's sequence hash, shared across benchmarks) with the Lo-Hi split each was
406
+ assigned; `excluded` there marks a protein the k-cut gave up.
407
+
408
+ ## The `datapoint_id`
409
+
410
+ A row's position in the benchmark as plug's own loader yields it
411
+ (`plug.benchmarks.<Benchmark>.rows()`), so `"1234"` is the 1235th row. The per-residue
412
+ benchmarks (`allobench`, `passerrank`, `atlas`) add the 1-based residue: `"1234:56"`.
413
+ Submissions are keyed on it.
414
+
415
+ ## Labels
416
+
417
+ This repository holds **only identifiers and split assignments**. Not every benchmark's
418
+ licence allows its measurements to be redistributed (LP-PDBBind's does not), so no label,
419
+ sequence, mutation or ligand is published here. Load the rows, labels included, from the
420
+ original sources with plug's loaders: `row_index` is the row's position there. Each
421
+ benchmark's data stays under its original licence.
422
+
423
+ ## Submitting
424
+
425
+ See the [challenge Space]({SPACE_URL}) for the submission format, the two tracks and how
426
+ submissions are scored.
427
+ """
428
+ (public / "README.md").write_text("\n".join(yaml) + "\n" + body)
429
+
430
+
431
  def main(argv: list[str] | None = None) -> int:
432
  """Build the challenge data for the requested benchmarks.
433
 
 
483
  "files": provenance.get("files", {}),
484
  }
485
  (repo_root / "data" / "lohi_provenance.json").write_text(json.dumps(record, indent=2) + "\n")
486
+ write_card(args.out / "public")
487
 
488
  print("\n== summary ==")
489
  for name, counts in summary.items():