{ "cells": [ { "cell_type": "markdown", "id": "8b5ad102", "metadata": { "language": "markdown" }, "source": [ "# Raw repertoires to annotation tables\n", "\n", "Offline, tiny synthetic cohort and wide paired inputs. Repeated source IDs in different samples and a missing beta chain remain visible. Download the complete examples bundle so the shell script and raw inputs are beside this notebook." ] }, { "cell_type": "code", "execution_count": null, "id": "ffa396bc", "metadata": { "language": "python" }, "outputs": [], "source": [ "# Identify the installed CLI and print the fresh kernel environment.\n", "import os, sys, subprocess, tempfile, json\n", "from pathlib import Path\n", "from importlib.metadata import version\n", "os.environ[\"POLARS_MAX_THREADS\"] = \"1\"\n", "print(\"Python:\", sys.version, \"CLI interpreter:\", sys.executable)\n", "for package in (\"vdjmatch\", \"vdjtools\", \"seqtree\", \"polars\"):\n", " print(package, version(package))\n", "# Open this notebook from the repository root or the examples directory.\n", "examples = next((p for p in (Path.cwd()/\"examples\", Path.cwd())\n", " if (p/\"inputs/reference.tsv\").is_file()), None)\n", "if examples is None:\n", " raise RuntimeError(\"Use the downloaded complete examples bundle, not this notebook alone\")\n", "# Deterministic demonstration: no sampling or RNG seeds are used.\n", "output = Path(tempfile.mkdtemp(prefix=\"vdjmatch-example-\"))/\"fresh\"\n", "output.mkdir()\n", "print(\"Fresh output directory:\", output)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "2b0e1ddc", "metadata": { "language": "python" }, "outputs": [], "source": [ "# Run raw inputs with this kernel's installed CLI, on any supported platform.\n", "subprocess.run([sys.executable, \"-m\", \"vdjmatch.cli\", \"annotate\",\n", " \"--metadata\", str(examples/\"inputs/samples.tsv\"),\n", " \"--vdjdb\", str(examples/\"inputs/reference.tsv\"), \"--threads\", \"1\",\n", " \"--output-prefix\", str(output/\"cohort\")], check=True, timeout=120)\n", "subprocess.run([sys.executable, \"-m\", \"vdjmatch.cli\", \"annotate\",\n", " str(examples/\"inputs/paired.tsv\"), \"--locus\", \"paired\",\n", " \"--vdjdb\", str(examples/\"inputs/reference.tsv\"), \"--threads\", \"1\",\n", " \"--output-prefix\", str(output/\"paired\")], check=True, timeout=120)" ] }, { "cell_type": "code", "execution_count": null, "id": "1b0c0a3e", "metadata": { "language": "python" }, "outputs": [], "source": [ "# Analyze only final CLI tables, preserving sample and source identities.\n", "import polars as pl\n", "for prefix in (\"cohort\", \"paired\"):\n", " queries = pl.read_csv(output/(prefix+\".queries.tsv\"), separator=\"\\t\", infer_schema_length=0)\n", " selections = pl.read_csv(output/(prefix+\".selection.tsv\"), separator=\"\\t\", infer_schema_length=0)\n", " print(prefix, \"query rows:\", queries.height, \"selection rows:\", selections.height)\n", " identity = [c for c in (\"sample_id\", \"source_sequence_id\", \"clone_id\", \"status\", \"has_support\")\n", " if c in selections.columns]\n", " print(selections.select(identity))\n", " manifest = json.loads((output/(prefix+\".manifest.json\")).read_text())\n", " print(\"Native threads:\", manifest[\"native_threads\"])\n", "assert pl.read_csv(output/\"cohort.queries.tsv\", separator=\"\\t\").height == 4\n", "assert pl.read_csv(output/\"paired.queries.tsv\", separator=\"\\t\").height == 2\n" ] }, { "cell_type": "markdown", "id": "91c23da3", "metadata": { "language": "markdown" }, "source": [ "All displayed results come from fresh CLI tables. Raw synthetic `DEMO_A`/`DEMO_B` labels are software examples, not experimental binding truth. Keep no-hits and missing-chain dispositions. This example establishes neither accuracy nor a false-call threshold. Inspect the CLI manifests beside the tables for model, reference and resource settings. No computed outputs are committed or reused." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }