Turn any AI agent into an AI Scientist. The #1 Agent Skills library for science, used by 250,000+ scientists worldwide. 177 ready-to-use validated skills plus 100+ scientific databases covering biology, chemistry, medicine, and drug discovery. Compatible with Cursor, Claude Code, Codex, Pi, Antigravity, and the open Agent Skills standard.
Python agent-skillsai-scientistbioinformaticschemoinformaticsclaudeclaude-skillsclaudecodeclinical-researchcomputational-biologydata-analysisdrug-discoverygenomicsmaterials-sciencemetabolomicsproteomicsscientific-computingscientific-visualization
Add AlphaGenome
Timothy Kassis97c59021d34e
diff --git a/README.md b/README.mdindex f7cf8d14..906646c8 100644--- a/README.md+++ b/README.md@@ -3,7 +3,7 @@[](LICENSE.md)[](https://arxiv.org/abs/2609.00065)[](pyproject.toml)-[](#-whats-included)+[](#-whats-included)[](#-whats-included)[](https://agentskills.io/)[](https://agent-plugins.org/)@@ -17,7 +17,7 @@> **🔔 Claude Scientific Skills is now Scientific Agent Skills.** Same skills, broader compatibility — now works with any AI agent that supports the open [Agent Skills](https://agentskills.io/) standard, not just Claude.-> **New: [K-Dense BYOK](https://github.com/K-Dense-AI/k-dense-byok)** — A free, open-source AI co-scientist that runs on your desktop, powered by Scientific Agent Skills. Bring your own API keys, pick from 40+ models, and get a full research workspace with web search, file handling, 100+ scientific databases, and access to all 165 skills in this repo. Your data stays on your computer, and you can optionally scale to cloud compute via [Modal](https://modal.com/) for heavy workloads. [Get started here.](https://github.com/K-Dense-AI/k-dense-byok)+> **New: [K-Dense BYOK](https://github.com/K-Dense-AI/k-dense-byok)** — A free, open-source AI co-scientist that runs on your desktop, powered by Scientific Agent Skills. Bring your own API keys, pick from 40+ models, and get a full research workspace with web search, file handling, 100+ scientific databases, and access to all 166 skills in this repo. Your data stays on your computer, and you can optionally scale to cloud compute via [Modal](https://modal.com/) for heavy workloads. [Get started here.](https://github.com/K-Dense-AI/k-dense-byok)> **🎥 Webinar recording — [Getting Started with K-Dense BYOK](https://youtu.be/Du3BIE48DKc?si=9dPpETKSc2PeQbvU)**> A hands-on walkthrough of [K-Dense BYOK](https://github.com/K-Dense-AI/k-dense-byok), our free, open-source AI co-scientist that runs locally on your own machine and is powered by Scientific Agent Skills. We cover how to set it up, bring your own API keys, and run real research workflows with these skills. No prior technical experience needed. **[Watch the recording →](https://youtu.be/Du3BIE48DKc?si=9dPpETKSc2PeQbvU)**@@ -26,7 +26,7 @@> **📄 Paper:** Scientific Agent Skills is described in [*Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents*](https://arxiv.org/abs/2609.00065) (arXiv:2609.00065). If you use these skills in your research, please [cite the paper](#-citation).-A comprehensive collection of **165 ready-to-use scientific and research skills** (covering cancer genomics, individual-level 1000 Genomes queries, hosted regulatory-sequence prediction, live pathogen-variant surveillance, analytical method validation, PK/PD modelling and dose selection, full-text biomedical and regulatory literature retrieval, drug-target binding, bounded biomedical knowledge graph search, molecular dynamics, RNA velocity, microbiome foundation models, geospatial science, time series forecasting, scientific ML resource discovery via Hugging Science, 78+ scientific databases, and more) for any AI agent that supports the open [Agent Skills](https://agentskills.io/) standard, created by [K-Dense](https://k-dense.ai). The repository is also a portable [Agent Plugins](https://agent-plugins.org/) package (`plugin.json` + `skills/`), so plugin-capable clients can load the whole collection as one plugin. Works with **Cursor, Claude Code, Codex, Google Antigravity, and more**. Transform your AI agent into a research assistant capable of executing complex multi-step scientific workflows across biology, chemistry, medicine, and beyond.+A comprehensive collection of **166 ready-to-use scientific and research skills** (covering cancer genomics, individual-level 1000 Genomes queries, genome-wide precomputed variant effects from the AlphaGenome Atlas, hosted regulatory-sequence prediction, live pathogen-variant surveillance, analytical method validation, PK/PD modelling and dose selection, full-text biomedical and regulatory literature retrieval, drug-target binding, bounded biomedical knowledge graph search, molecular dynamics, RNA velocity, microbiome foundation models, geospatial science, time series forecasting, scientific ML resource discovery via Hugging Science, 78+ scientific databases, and more) for any AI agent that supports the open [Agent Skills](https://agentskills.io/) standard, created by [K-Dense](https://k-dense.ai). The repository is also a portable [Agent Plugins](https://agent-plugins.org/) package (`plugin.json` + `skills/`), so plugin-capable clients can load the whole collection as one plugin. Works with **Cursor, Claude Code, Codex, Google Antigravity, and more**. Transform your AI agent into a research assistant capable of executing complex multi-step scientific workflows across biology, chemistry, medicine, and beyond.> ⭐ **Help make AI for science easier to discover:** If Scientific Agent Skills saves you time, teaches your agent a workflow, or helps your lab move faster, please [star this repository](https://github.com/K-Dense-AI/scientific-agent-skills). A star is a public signal that these open, reusable research skills are worth maintaining: it helps scientists, engineers, and open-source contributors find the project, shows which agent-skill standards are gaining real adoption, and gives us a clear reason to keep expanding the collection for the community.@@ -74,9 +74,9 @@ Recorded walkthroughs of these skills on real research tasks, from the [K-Dense## 📦 What's Included-This repository provides **165 scientific and research skills** organized into the following categories:+This repository provides **166 scientific and research skills** organized into the following categories:-- **100+ Scientific & Financial Databases** - A unified database-lookup skill provides deterministic, provenance-rich access to 78 public databases (PubChem, ChEMBL, UniProt, COSMIC, ClinicalTrials.gov, FRED, USPTO, and more), plus dedicated skills for DepMap, Imaging Data Commons, PrimeKG, NCATS ARAX, U.S. Treasury Fiscal Data, Hugging Science, OneKGPd, and Genomic Intelligence. Multi-database packages like BioServices (~40 bioinformatics services), BioPython (39 NCBI sub-databases via Entrez), and gget (20+ genomics databases) add further coverage+- **100+ Scientific & Financial Databases** - A unified database-lookup skill provides deterministic, provenance-rich access to 78 public databases (PubChem, ChEMBL, UniProt, COSMIC, ClinicalTrials.gov, FRED, USPTO, and more), plus dedicated skills for DepMap, Imaging Data Commons, PrimeKG, NCATS ARAX, U.S. Treasury Fiscal Data, Hugging Science, OneKGPd, Genomic Intelligence, and AlphaGenome (Atlas lookups and model scoring). Multi-database packages like BioServices (~40 bioinformatics services), BioPython (39 NCBI sub-databases via Entrez), and gget (20+ genomics databases) add further coverage- **70+ Optimized Python Package Skills** - Explicitly defined, version-aware workflows for RDKit, Scanpy, PyTorch Lightning, scikit-learn, PyTDC, PathML, pydicom, NeuroKit2, PufferLib, QuTiP, GeoPandas, pymatgen, BioPython, Qiskit, Molecular Dynamics (OpenMM/MDAnalysis), and others. The agent can still use *any* Python package; these skills provide stronger, safer guidance for the packages listed- **9 Scientific Integration Skills** - Explicitly defined skills for Benchling, DNAnexus, LatchBio, OMERO, Protocols.io, Open Notebook, Ginkgo Cloud Lab, LabArchives, and Opentrons. Again, the agent is not limited to these — any API or platform reachable from Python is fair game; these skills are the optimized, pre-documented paths- **30+ Analysis & Communication Tools** - Literature review, evidence-traceable scientific writing, confidential peer review, document processing, Paperclip (full-text papers, FDA/PMDA/EMA filings, and trial registries with line-pinned citations), Paperzilla, Exa Search, macro-free PPTX posters, slides, schematics, infographics, Mermaid diagrams, and more@@ -121,7 +121,7 @@ Each skill includes:- **Multi-Step Workflows** - Execute complex pipelines with a single prompt### 🎯 **Comprehensive Coverage**-- **165 Skills** - Extensive coverage across all major scientific domains+- **166 Skills** - Extensive coverage across all major scientific domains- **100+ Databases** - Unified access to 78+ databases via database-lookup, plus dedicated data access skills and multi-database packages like BioServices, BioPython, and gget- **70+ Optimized Python Package Skills** - Current, version-scoped guidance for packages including RDKit, Scanpy, PyTorch Lightning, scikit-learn, PyTDC, pydicom, PufferLib, QuTiP, GeoPandas, pymatgen, Qiskit, Molecular Dynamics (OpenMM/MDAnalysis), scVelo, and TimesFM (the agent can use any Python package; these are the pre-documented paths)@@ -228,7 +228,7 @@ For Hermes versions that support skill taps, add the repository as a tap:hermes skills tap add K-Dense-AI/scientific-agent-skills```-Every `SKILL.md` has YAML frontmatter, but legacy and community skills vary in `metadata` formatting (block or flow style) and optional extension fields. Repository updates must keep `metadata.version` as a quoted numeric string and pass canonical `skills-ref validate ./skills/<skill-name>` checks. Hosts may interpret optional metadata and credential prompts differently, so verify behavior on the target host. Because 165 skills add up to a lot of standing context, consider installing a topical subset rather than the whole collection.+Every `SKILL.md` has YAML frontmatter, but legacy and community skills vary in `metadata` formatting (block or flow style) and optional extension fields. Repository updates must keep `metadata.version` as a quoted numeric string and pass canonical `skills-ref validate ./skills/<skill-name>` checks. Hosts may interpret optional metadata and credential prompts differently, so verify behavior on the target host. Because 166 skills add up to a lot of standing context, consider installing a topical subset rather than the whole collection.> **NemoClaw note:** NemoClaw runs agents inside NVIDIA OpenShell with default-deny outbound networking. Skills are discovered and loaded normally, but any skill that needs the network — package installs via `uv`, or API calls (Exa, Parallel, Benchling, NCBI, Materials Project, …) — only works once the operator pre-approves the relevant domains in the OpenShell TUI.@@ -433,6 +433,7 @@ networks, and search GEO for similar patterns.- **Variant Database Management**: Build scalable VCF databases with TileDB-VCF for incremental sample addition, efficient population-scale queries, and compressed storage of genomic variant data- **Population Genomics**: Query variants, cohort sample IDs, and relatedness in the 3,202-person GRCh38 1000 Genomes cohort with OneKGPd- **Regulatory Sequence Models**: Run hosted Genomic Intelligence promoter, splice, enhancer, chromatin, expression, and gene-annotation predictions for research—not clinical or diagnostic decisions+- **Variant Effect Prediction**: Look up AlphaGenome Atlas AVI scores, Phred ranks, feature attributions, and per-tissue track effects for any GRCh38 SNV, or score variants and run in silico mutagenesis with the AlphaGenome model — for research prioritisation, not diagnosis- **Pathogen Surveillance**: Track which viral lineages are circulating now and how fast they are growing (SARS-CoV-2, influenza including H5N1, RSV, mpox, measles, dengue) through the GenSpectrum LAPIS API, with reporting lag measured rather than assumed- **Gene Discovery**: Query NCBI Gene, UniProt, and Ensembl for comprehensive gene information- **Network Analysis**: Identify protein-protein interactions via STRING, map to pathways (KEGG, Reactome)@@ -467,19 +468,20 @@ networks, and search GEO for similar patterns.## 📚 Available Skills-This repository contains **165 scientific and research skills** organized across multiple domains. Each skill provides comprehensive documentation, code examples, and best practices for working with scientific libraries, databases, and tools.+This repository contains **166 scientific and research skills** organized across multiple domains. Each skill provides comprehensive documentation, code examples, and best practices for working with scientific libraries, databases, and tools.### Skill Categories> **Note:** The Python package and integration skills listed below are *explicitly defined* skills — curated with documentation, examples, and best practices for stronger, more reliable performance. They are not a ceiling: the agent can install and use *any* Python package or call *any* API, even without a dedicated skill. The skills listed simply make common workflows faster and more dependable.-#### 🧬 **Bioinformatics & Genomics** (27 skills)+#### 🧬 **Bioinformatics & Genomics** (28 skills)- RNA-seq pipelines: Bulk RNA-seq (end-to-end FASTQ -> counts -> DE -> enrichment orchestrator)- Sequence analysis: BioPython, pysam, scikit-bio, BioServices- Single-cell analysis: Scanpy, AnnData, scvi-tools, scVelo (RNA velocity), Arboreto, Cellxgene Census- Genomic tools: gget, current geniml/Gtars interval workflows, deepTools, FlowIO, Polars-Bio, Zarr, TileDB-VCF- Coordinate hygiene: Genomic Coordinates (convert intervals across BED/GFF/GTF/VCF/SAM/WIG conventions, normalise variant representations, and catch 0-based vs 1-based and assembly/contig-naming mismatches before they corrupt an analysis)- Population and sequence intelligence: OneKGPd (individual-level 1000 Genomes cohort queries) and Genomic Intelligence (hosted regulatory/gene-expression predictions; research only)+- Variant effect prediction: AlphaGenome (DeepMind's AlphaGenome Atlas of precomputed effects for every GRCh38 SNV — AVI score with Phred rank and 18 SHAP feature attributions, plus raw and quantile scores across 9,440 RNA-seq, DNase, ATAC, ChIP, CAGE, splicing and contact-map tracks — and on-demand model scoring, in silico mutagenesis and REF-vs-ALT track prediction for human and mouse; research only, not clinical)- Differential expression: PyDESeq2- Functional enrichment: Pathway Enrichment (ORA, GSEA/preranked, ssGSEA via gseapy + g:Profiler; GO, KEGG, Reactome, WikiPathways, MSigDB)- Phylogenetics: ETE Toolkit, Phylogenetics (MAFFT, IQ-TREE 2, FastTree)@@ -600,6 +602,7 @@ This repository contains **165 scientific and research skills** organized across- Scientific ML resource catalog: Hugging Science (curated index of datasets, models, blog posts, and interactive Spaces across 17 scientific domains — astronomy, biology, chemistry, climate, genomics, materials science, medicine, physics, scientific reasoning, and more — with usage patterns for `datasets`, `transformers`, and `gradio_client`)- Individual-level population genomics: OneKGPd (3,202-person high-coverage 1000 Genomes cohort queries)- Hosted regulatory genomics: Genomic Intelligence (promoter, splice, enhancer, chromatin, expression, and gene-annotation predictions for research use)+- Precomputed variant effects: AlphaGenome (Atlas lookups for every GRCh38 SNV with AVI, Phred, SHAP feature attributions, and per-track scores; on-demand AlphaGenome model scoring for indels, mouse, and custom scorers; Atlas website deep links)- Ontology identifiers: Ontology Term Resolution (resolve free-text tissue, cell-type, disease, phenotype, assay, chemical, organism, and developmental-stage labels to term IDs and validate CURIEs against EBI OLS4, for GEO/ENA/BioSamples/CELLxGENE/HCA/ISA-Tab metadata)- Live pathogen surveillance: Pathogen Variant Surveillance (which viral lineages are circulating now, how fast they are growing, and what mutations they carry — SARS-CoV-2, influenza including H5N1, RSV, mpox, measles, dengue and more through the GenSpectrum LAPIS API, with lineage names resolved against the live pango-designation nomenclature and reporting lag measured rather than assumed)@@ -919,7 +922,7 @@ If you also need to cite a specific version of the repository itself (for exampltitle = {Scientific Agent Skills: A Comprehensive Collection of Scientific Tools for AI Agents},year = {2026},url = {https://github.com/K-Dense-AI/scientific-agent-skills},- note = {165 skills covering databases, packages, integrations, and analysis tools}+ note = {166 skills covering databases, packages, integrations, and analysis tools}}```diff --git a/docs/examples.md b/docs/examples.mdindex 8bae0b13..23561439 100644--- a/docs/examples.md+++ b/docs/examples.md@@ -4,7 +4,7 @@ Worked, interdisciplinary examples showing how the skills in this repository comend-to-end research workflows. Every skill in `skills/` appears in at least one example, andevery skill named in an example exists in the directory.-**Coverage reviewed:** 2026-09-13 against all 165 current skills. The+**Coverage reviewed:** 2026-09-13 against all 166 current skills. The[skill catalog](skills.md) links to each source workflow. These are illustrativeresearch prompts, not records of completed studies or validated analysis results.@@ -3766,6 +3766,7 @@ plausible in the relevant tissue.- `genomic-coordinates` - Build, chr-prefix, and variant-representation hygiene across every source- `onekgpd` - 1000 Genomes individual-level genotypes, LD context, and population allele frequencies- `genomic-intelligence` - Hosted DNA language models for promoter, splice, enhancer, chromatin-state, and sequence-to-expression prediction+- `alphagenome` - AlphaGenome Atlas AVI scores, Phred ranks, and feature attributions for every hg38 SNV in the credible set, per-tissue Atlas track scores, and on-demand model scoring for indels- `transformers` - Run or fine-tune sequence models locally when the hosted API is not appropriate- `deeptools` - Coverage tracks, matrices, and heatmaps over ATAC/ChIP/DNase signal- `geniml` - Genomic interval embeddings and region-set similarity@@ -3780,9 +3781,9 @@ plausible in the relevant tissue.**Starting prompt**:```text-Use the genomic-coordinates, onekgpd, genomic-intelligence, deeptools,-polars-bio, database-lookup, ontology-term-resolution, statistical-analysis,-and scientific-writing skills.+Use the genomic-coordinates, onekgpd, alphagenome, genomic-intelligence,+deeptools, polars-bio, database-lookup, ontology-term-resolution,+statistical-analysis, and scientific-writing skills.Goal: for this locus, a ranked credible set of candidate causal variants, eachwith a proposed mechanism and the single experiment that would falsify it.@@ -3831,6 +3832,15 @@ Step 3: Match the tissue before looking at any functional datadifferent question, and mixing the two is the most common failure in this analysisStep 4: Predict regulatory consequence from sequence+- Start with the AlphaGenome Atlas through the alphagenome skill: every hg38 SNV in the+ credible set already has an AVI score, a genome-wide Phred rank, and 18 feature+ attributions that say whether the score comes from splicing, TF binding,+ accessibility, or conservation alone. Rank the set by Phred rather than applying one+ hard cut-off; pathogenic regulatory variants sit in lower AVI bins than coding ones+- Then pull the Atlas RNA_SEQ, DNASE, and CHIP_TF track scores for the ontology-matched+ tissue from Step 3, not the genome-wide maximum. Indels and swapped REF alleles are+ not in the Atlas: score those on demand with the AlphaGenome model, and link every+ reported variant to the Atlas website so a reviewer can inspect the REF and ALT tracks- Read genomic-intelligence's current task schemas before extracting paired referenceand alternate windows. Preserve the assembly, coordinates, strand, and REF check- Select only models appropriate for the organism and question: the hosted DeepSTARRdiff --git a/docs/skills.md b/docs/skills.mdindex d5224189..16186b59 100644--- a/docs/skills.md+++ b/docs/skills.md@@ -1,6 +1,6 @@# Scientific Skills-All **165 skills** in this checkout, grouped by domain. Summaries mirror each skill's+All **166 skills** in this checkout, grouped by domain. Summaries mirror each skill'scurrent `description`; open its linked `SKILL.md` for setup, tested versions, workflows,and limitations. See [workflow examples](examples.md) for ways to combine them.@@ -49,6 +49,7 @@ and limitations. See [workflow examples](examples.md) for ways to combine them.## Scientific Packages### Bioinformatics & Genomics+- **[AlphaGenome](../skills/alphagenome/SKILL.md)** - Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool.- **[AnnData](../skills/anndata/SKILL.md)** - Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.- **[Arboreto](../skills/arboreto/SKILL.md)** - Infer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Supports distributed computation for large-scale datasets.- **[Biopython](../skills/biopython/SKILL.md)** - Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.diff --git a/plugin.json b/plugin.jsonindex 1d9199b6..a70a41fd 100644--- a/plugin.json+++ b/plugin.json@@ -1,7 +1,7 @@{"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json","name": "scientific-agent-skills",- "version": "2.68.0",+ "version": "2.69.0","description": "Ready-to-use scientific and research Agent Skills for biology, chemistry, medicine, and related workflows.","author": {"name": "K-Dense Inc.",diff --git a/pyproject.toml b/pyproject.tomlindex 53bdf382..5cbaff11 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -1,6 +1,6 @@[project]name = "scientific-agent-skills"-version = "2.68.0"+version = "2.69.0"description = "A set of ready to use Agent Skills for research, science, engineering, analysis, finance and writing."readme = "README.md"requires-python = ">=3.13"diff --git a/skills/alphagenome/SKILL.md b/skills/alphagenome/SKILL.mdnew file mode 100644index 00000000..c1fd656d--- /dev/null+++ b/skills/alphagenome/SKILL.md@@ -0,0 +1,275 @@+---+name: alphagenome+description: "Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool."+license: MIT+compatibility: "Python 3.10+ with the alphagenome package (0.9.0 or later for the Atlas client; brings numpy, pandas, anndata, grpcio). Network access to gdmscience.googleapis.com:443 and a free non-commercial AlphaGenome API key in ALPHAGENOME_API_KEY (ALPHA_GENOME_API_KEY also read). Human data is GRCh38 only; mouse is mm10 (model only)."+allowed-tools: Read Write Edit Bash+metadata:+ version: "1.0"+ skill-author: K-Dense Inc.+ upstream-version: "alphagenome 0.9.0"+ last-reviewed: "2026-09-13"+ openclaw:+ primaryEnv: ALPHAGENOME_API_KEY+ envVars:+ - name: ALPHAGENOME_API_KEY+ required: true+ description: AlphaGenome API key, free for non-commercial use from deepmind.google.com/science/alphagenome. ALPHA_GENOME_API_KEY is accepted as an alternative spelling.+---++# AlphaGenome and the AlphaGenome Atlas++AlphaGenome is DeepMind's sequence-to-function model: 1 Mb of DNA in, base-pair+predictions for eleven assay types across thousands of human and mouse tracks+out. The **AlphaGenome Atlas** (released 2026-09-08) is that model run once over+every possible single-nucleotide change in GRCh38, about 9 billion variants,+stored with a single ranking number, the **AlphaGenome Variant Impact (AVI)**+score, its genome-wide percentile, and an 18-way attribution of what drives it.+Both are reached through one `pip install alphagenome` and one API key.++> Research and theoretical modelling only. Outputs must not be used to train+> other models, and are not for diagnostic procedures or medical decisions.++## When to use which++| You have | Use | Why |+| --- | --- | --- |+| hg38 SNVs (a VCF, a credible set, a region up to ~1 kb) | **Atlas** via `scripts/atlas_query.py` | precomputed, higher quota, includes AVI and attributions |+| indels, mouse variants, a non-reference background, a custom scorer or window | **model** via `scripts/score_variants.py` or Python | the Atlas is SNV-only and hg38-only |+| a hypothesis to explain (which motif, which tissue, REF vs ALT tracks) | model `predict_variant` + plots, Atlas track scores, portal link | mechanism, not just rank |+| GRCh37 coordinates, rsIDs, unnormalised indels | `genomic-coordinates` first, then come back | wrong build or swapped REF gives a plausible wrong answer |+| ClinVar assertions, gene-disease validity, ACMG framing | `folklore-variant-evidence`, `database-lookup` | AlphaGenome is one evidence line, never the verdict |+| promoter/enhancer/expression predictions without a DeepMind key | `genomic-intelligence` | different provider, keyless demo tier |++## Setup++```bash+uv pip install alphagenome # PyPI; tested on Python 3.12 and 3.13, alphagenome 0.9.0+export ALPHAGENOME_API_KEY="..." # https://deepmind.google.com/science/alphagenome+cd skills/alphagenome/scripts+python atlas_query.py scorers # proves key + network in one call+```++Never put the key on a command line or in a file you commit; the scripts only+read it from the environment. An invalid key surfaces as `ValueError: API key+not valid`, not as a permission error.++## The coordinate contract++- A variant is **1-based** `chr:pos:ref>alt` (`chr22:36201698:A>C`). gnomAD+ (`22-36201698-A-C`), GTEx (`chr22_36201698_A_C_b38`), and Open Targets+ spellings are accepted by the scripts and by `genome.Variant.from_str`.+- An interval on the command line is **1-based closed** `chr:start-end`; the+ SDK's `genome.Interval` is **0-based half-open**. The scripts convert.+- Human is **GRCh38 only**. The Atlas key is `chr:pos:alt`; REF is implied by+ the reference, so a variant with REF and ALT swapped, or on GRCh37, returns a+ wrong record silently. Check REF against the FASTA before trusting a lookup.+- rsIDs are not accepted by the API or the portal. Resolve them to coordinates.+- Use the `chr` prefix; `MT` becomes `chrM`.++## Atlas workflow++### 1. Rank with AVI++```bash+python atlas_query.py avi --variant chr22:36201698:A>C chr9:128225994:G>A+python atlas_query.py avi --input candidates.vcf --min-phred 20 -o avi.tsv+python atlas_query.py avi --interval chr11:5225727-5226575 --top-k 25 -o hbb_window.tsv+python atlas_query.py avi --input credible_set.tsv --with-tracks -o avi_tracks.tsv+```++Output, one row per variant:++| Column | Meaning |+| --- | --- |+| `avi_raw` | composite model output (the 18 attributions sum to it) |+| `avi_cdf_quantile` | cumulative quantile against all genome-wide SNVs, as served |+| `avi_tail_quantile`, `avi_phred`, `avi_top_percent` | `tail = 1 - cdf`, `phred = -10 log10(tail)`; Phred 20 = top 1 %, 30 = top 0.1 % |+| `top_feature`, `top_feature_value` | largest absolute SHAP attribution and its value |+| `fi_MERGED_SPLICING` ... `fi_IS_DELETION` | all 18 attributions (keys in `references/atlas.md`) |+| `top_track_*` (with `--with-tracks`) | the strongest track behind the top feature: scorer, track, biosample, ontology CURIE, gene, raw score |+| `atlas_url` | deep link to the variant on the portal |+| `error` | per-variant lookup failure (indel, `N` base, wrong REF) instead of a crash |++The Atlas report's advice: **rank, do not threshold**, and pick thresholds by+region or application. Pathogenic regulatory variants sit in lower AVI bins+than protein-truncating or splice-motif variants, so a single genome-wide+cut-off under-calls exactly the variants this resource was built for.++Read the attribution before the number. `MERGED_SPLICING` or `ALPHAMISSENSE`+on top means a splice or coding mechanism; `MAX_ABS_DNASE`, `MAX_ABS_CHIP_TF`,+`MAX_ABS_RNA_SEQ` mean a regulatory mechanism you can resolve by track;+`CACTUS_241_WAY` or `PHASTCONS_470_WAY` on top means conservation is carrying+the score and the molecular mechanism is not resolved.++### 2. Resolve the mechanism by track++```bash+python atlas_query.py scorers # what the server serves right now+python atlas_query.py tracks --scorer RNA_SEQ --query colon # find ontology CURIEs+python atlas_query.py scores --variant chr22:36201698:A>C \+ --scorers RNA_SEQ DNASE SPLICE_SITE_USAGE --ontology UBERON:0001157 -o colon.tsv+python atlas_query.py scores --interval chr11:5225727-5226575 --scorers CHIP_TF --gene HBB -o hbb_tf.tsv+```++One row per variant x track (x gene for `RNA_SEQ`, `POLYADENYLATION`,+`SPLICE_*`), with `raw_score` and, where served, `quantile_score`. Track-level+scorer names: `ATAC`, `DNASE`, `CHIP_TF`, `CHIP_HISTONE`, `CAGE`, `PROCAP`,+`RNA_SEQ`, `POLYADENYLATION`, `SPLICE_SITES`, `SPLICE_SITE_USAGE`,+`SPLICE_JUNCTIONS`, `CONTACT_MAPS`, plus `*_ACTIVE` variants; `scorers` is the+authority on the live list. Filter by the tissue the question is about, not+by the genome-wide maximum: 9,440 tracks means something is always extreme+somewhere.++### 3. Send the reader to the portal++```bash+python atlas_link.py variant chr22:36201698:A>C --biosample "colon" --modalities RNA_SEQ,DNASE,CHIP_TF+python atlas_link.py locus chr11:5225727-5226575 --tf GATA1+python atlas_link.py gene HBB --markdown+```++No key, no network. The site shows the AVI track, per-modality heatmaps over+every biosample, REF-vs-ALT prediction tracks, and motif instances. Attach a+link to every variant you report.++### In Python++```python+import os+from alphagenome.atlas import atlas+from alphagenome.data import genome++client = atlas.create(os.environ["ALPHAGENOME_API_KEY"], timeout=30)+scores = client.query_variant(+ genome.Variant.from_str("chr22:36201698:A>C"),+ requested_scorers=["AVI_SCORE", "AVI_SCORE_FEATURE_IMPORTANCE", "RNA_SEQ"],+ ontology_terms=["UBERON:0001157"], # optional; ignored for scorers without ontology metadata+)+avi = scores["AVI_SCORE"] # AnnData: X (1,1) raw; layers['quantiles'] (1,1) cdf+fi = scores["AVI_SCORE_FEATURE_IMPORTANCE"] # AnnData: X (1,18); var['name'] = feature keys+rna = scores["RNA_SEQ"] # AnnData: obs = variant x gene, var = tracks, X = log2 FC+client.query_interval(genome.Interval("chr11", 5225726, 5226575), requested_scorers=["AVI_SCORE"])+```++`query_interval` returns all 3 SNVs per base, in 32 bp chunks. Keep windows+to about 1 kb (3,000 variants); `atlas_query.py` refuses more unless+`--max-window` is raised. `query_variants` stops at the first failed lookup;+the script queries one variant at a time so misses become `error` cells.++## Model workflow++### Score variants the Atlas does not hold++```bash+python score_variants.py --variant chr22:36201698:A>C -o scores.tsv # 12 recommended scorers, 1 Mb+python score_variants.py --input indels.vcf --scorers RNA_SEQ SPLICE_SITE_USAGE \+ --ontology UBERON:0001157 --min-abs-quantile 0.99 -o colon.tsv+python score_variants.py --organism mouse --variant chr7:45000000:A>G --sequence-length 500KB+python score_variants.py --list-scorers+python score_variants.py --list-tracks --output-type RNA_SEQ --query liver -o tracks.tsv+```++Output is the official tidy table from `variant_scorers.tidy_scores`: one row+per variant x scorer x track (x gene) with `raw_score` and `quantile_score`,+sorted by |raw|. Default scorers are the 12 recommended difference scorers;+`--include-active` adds the seven `*_ACTIVE` activity scorers. At most 20+scorers per request.++```python+from alphagenome.models import dna_client, variant_scorers+model = dna_client.create(os.environ["ALPHAGENOME_API_KEY"])+variant = genome.Variant.from_str("chr22:36201698:A>C")+interval = variant.reference_interval.resize(dna_client.SEQUENCE_LENGTH_1MB)+adatas = model.score_variant(interval, variant, variant_scorers=[variant_scorers.RECOMMENDED_VARIANT_SCORERS["RNA_SEQ"]])+df = variant_scorers.tidy_scores(adatas) # filter df.ontology_curie afterwards; score_variant takes no ontology_terms+```++### Predict tracks and mutagenise++```python+vo = model.predict_variant(interval, variant,+ requested_outputs=[dna_client.OutputType.RNA_SEQ, dna_client.OutputType.DNASE],+ ontology_terms=["UBERON:0001157"])+vo.reference.rna_seq.values, vo.alternate.rna_seq.values # (1048576, n_tracks)++window = genome.Interval("chr20", 3_753_000, 3_753_400).resize(dna_client.SEQUENCE_LENGTH_16KB)+ism = model.score_ism_variants(interval=window, ism_interval=window.resize(256),+ variant_scorers=[variant_scorers.CenterMaskScorer(+ requested_output=dna_client.OutputType.DNASE, width=501,+ aggregation_type=variant_scorers.AggregationType.DIFF_MEAN)])+```++Supported windows: 16 kb, 100 kb, 500 kb, 1 Mb (`2**14` to `2**20`); 1 Mb is+the default and is required for distal enhancers and contact maps. Ontology+terms are CURIEs (`UBERON:0002048` lung, `CL:0000084` T cell); discover them+with `--list-tracks` or `model.output_metadata(...).concatenate()`. Plotting,+gene annotation (GENCODE v46 Feather on GCS), splicing and haplotype recipes:+`references/model-api.md`.++## Reading the numbers++Always report raw score **and** quantile or Phred, with the scorer, track,+biosample CURIE, and gene. `raw_score` is the effect size on the scorer's scale+(RNA_SEQ is log2 fold change: -1 is half); `quantile_score` is the rank against+common variants and saturates near 0.99999. A quantile above 0.99 with |raw| <+0.1 is the standard artefact of a quiet region and means **no effect**. Unsigned+scorers (`SPLICE_*`, `POLYADENYLATION`, `CONTACT_MAPS`, `*_ACTIVE`) have no+direction. Most variants are benign; "AlphaGenome predicts no molecular effect"+is a complete answer, and a variant inside a peak whose REF and ALT tracks are+identical is not "disrupting" anything. Full rules, tissue matching, and the+reporting checklist: `references/interpretation.md`.++What the model cannot see: trans effects, non-polyadenylated RNAs (snRNA genes+such as *RNU4-2*), cell types absent from training, protein-level consequences+(AlphaMissense is folded into AVI for that), RNA structure and miRNA biology,+diploid dosage, developmental time, species other than human and mouse.++## Limits, quota, terms++- Atlas: GRCh38 SNVs only for now; indels were scored for the paper and are+ promised later. Reference `N` bases were never scored.+- Quotas are per key and unpublished; the Atlas is documented as having a+ larger query rate than on-demand prediction. Transient `RESOURCE_EXHAUSTED`+ and `UNAVAILABLE` are retried by the client (5 attempts, back-off to 60 s).+- Access tiers (Atlas report): AVI scores are also a **permissively licensed**+ Tabix download at https://alphagenome.google/downloads; feature attributions+ and splicing scores are non-commercial downloads; all other raw track scores+ are API-only and non-commercial. Commercial API access is "coming soon" via+ Google Cloud Model Garden.+- The `alphagenome` client is Apache-2.0; model weights and outputs carry+ DeepMind's terms. Cite Avsec et al., *Nature* 649:1206 (2026) and the Atlas+ report (Cheng, Taylor, Nicolaisen, Pan, Bycroft, Perino, Ward et al., 2026).++## References++- `references/atlas.md` - what the Atlas contains, the 19 scorer+ configurations with track counts, AVI training and the 18 features, quantile+ to Phred, the client API and AnnData layout, error mapping, access tiers,+ portal URL grammar, GTF and download locations.+- `references/model-api.md` - `dna_client` cheat sheet: coordinates, sequence+ lengths, output types and track counts, ontology metadata, predict and score+ calls, recommended scorer configurations, ISM, gene annotation, plotting.+- `references/interpretation.md` - raw versus quantile, AVI thresholds,+ tissue matching, negative results, model blind spots, coordinate hygiene,+ reporting checklist.+- Scripts: `scripts/atlas_query.py` (Atlas: `avi`, `scores`, `scorers`,+ `tracks`), `scripts/score_variants.py` (model scoring, `--list-scorers`,+ `--list-tracks`), `scripts/atlas_link.py` (portal deep links, offline).++## Citing Scientific Agent Skills++This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a+manuscript, report, presentation, or code release, add the paper to the references or+software section and tell the user you did so:++> Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent+> Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065.+> https://doi.org/10.48550/arXiv.2609.00065++Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the+latest arXiv version, so never append a version suffix such as `v1`. When network access is+available, fetch https://arxiv.org/abs/2609.00065 (or+http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take+the author list, year, and version from that record. If the record lists a journal reference+or publisher DOI, cite the published version instead.diff --git a/skills/alphagenome/references/atlas.md b/skills/alphagenome/references/atlas.mdnew file mode 100644index 00000000..9559aa53--- /dev/null+++ b/skills/alphagenome/references/atlas.md@@ -0,0 +1,226 @@+# AlphaGenome Atlas: data model, scorers, AVI, and access++Verified against `alphagenome` 0.9.0 (released 2026-09-08, the first version+with `alphagenome.atlas`), the Atlas technical report (Cheng, Taylor,+Nicolaisen, Pan, Bycroft, Perino, Ward, *et al.*, "AlphaGenome Atlas: in silico+mutagenesis of the entire human genome improves prioritization and+interpretation of non-coding variants", 2026 preprint), and DeepMind's own+Atlas agent skills in `google-deepmind/science-skills`. Anything marked+*unverified* could not be checked without an API key.++## What is in the Atlas++| Item | Value |+| --- | --- |+| Genome build | GRCh38 / hg38 only. Gene annotations: GENCODE v46. |+| Variants | Every possible SNV at every non-`N` reference base (about 9 billion). Over 100 million observed indels (gnomAD v4.1, UK Biobank, All of Us) were scored for the paper, but the public API is currently limited to SNVs; indel expansion is promised "upon final publication". |+| Model | The distilled AlphaGenome model, 1 Mb input centred on a 128 bp scoring window (so a variant sits within 64 bp of the centre; the paper shows this does not change scores). |+| Per-variant content | Raw scores for every track of 19 recommended scorer configurations (about 27,000 scalars per variant, about 15,000 without the `_ACTIVE` scorers), the AVI score with its quantile, 18 SHAP feature attributions, and motif instances. |+| Motifs | 2,601 motifs (94 main TF labels, 122 zinc-finger labels, 464 composite patterns) and about 253 billion motif instances. Browsable on the portal; bulk download promised. |+| Size | About 1 PB. |++### Index key semantics++Each record is keyed by `chromosome:position:alt` on GRCh38. The REF allele is+implied by the reference and is **not** part of the key, so:++- a variant written with REF and ALT swapped (for example minor-allele-first+ from a GWAS table) is a **lookup miss**, not an error;+- non-reference to non-reference substitutions do not exist;+- positions where the reference is `N` were never scored;+- GRCh37 coordinates return wrong-but-plausible answers. Lift over first.++Check REF against the reference FASTA before trusting any Atlas result+(`genomic-coordinates` has `normalize_variant.py` and `check_contigs.py`).++## The scorers (Table S1 of the report)++`requested_scorers=` takes these names. Track counts are for human; the+`_ACTIVE` names are the natural spelling of the "(Active)" rows but were not+verified against a live `scorer_metadata()` call.++| Name | Scorer class | Parameters | Biosamples | Tracks | Signed | Obs axis |+| --- | --- | --- | --- | --- | --- | --- |+| `ATAC` | CenterMaskScorer | width 501, DIFF_LOG2_SUM | 167 | 167 | yes | variant |+| `DNASE` | CenterMaskScorer | width 501, DIFF_LOG2_SUM | 305 | 305 | yes | variant |+| `CHIP_TF` | CenterMaskScorer | width 501, DIFF_LOG2_SUM | 163 | 1,617 | yes | variant |+| `CHIP_HISTONE` | CenterMaskScorer | width 2001, DIFF_LOG2_SUM | 219 | 1,116 | yes | variant |+| `CAGE` | CenterMaskScorer | width 501, DIFF_LOG2_SUM | 264 | 546 | yes | variant |+| `PROCAP` | CenterMaskScorer | width 501, DIFF_LOG2_SUM | 6 | 12 | yes | variant |+| `RNA_SEQ` | GeneMaskLFCScorer | log fold change over exons | 285 | 371 | yes | variant x gene |+| `POLYADENYLATION` | PolyadenylationScorer | max log-fold change of isoform ratio | 285 | 371 | no | variant x gene |+| `SPLICE_SITES` | GeneMaskSplicingScorer | SPLICE_SITES, width None | - | 2 (donor, acceptor) | no | variant x gene |+| `SPLICE_SITE_USAGE` | GeneMaskSplicingScorer | SPLICE_SITE_USAGE, width None | 282 | 367 | no | variant x gene |+| `SPLICE_JUNCTIONS` | SpliceJunctionScorer | | 282 | 367 | no | variant x junction |+| `CONTACT_MAPS` | ContactMapScorer | | 12 | 28 | no | variant |+| `*_ACTIVE` (ATAC, DNASE, CHIP_TF, CHIP_HISTONE, CAGE, PROCAP, RNA_SEQ) | same widths, ACTIVE_SUM / GeneMaskActiveScorer | absolute activity of the stronger allele, not a difference | as above | as above | no | as above |+| `AVI_SCORE` | composite | one score per variant | - | 1 | no | variant |+| `AVI_SCORE_FEATURE_IMPORTANCE` | SHAP | 18 attribution values | - | 18 | yes | variant |++"Signed" scorers can go negative (ALT lowers the signal). For unsigned scorers+the direction is not meaningful; only magnitude ranks.++The whole catalogue is 9,440 tracks. `python scripts/atlas_query.py tracks+--scorer RNA_SEQ --query liver` shows the metadata for any of them.++## AlphaGenome Variant Impact (AVI)++AVI is a small neural network trained on **proxy labels**: gnomAD v4.1 variants+with a group-maximum filtering allele frequency above 0.001 are "proxy benign"+(about 2e7), below 0.001 "proxy impactful" (about 1e8). It therefore learns to+rank variants by how strongly negative selection appears to act on them, using+18 features:++| Group | Features (`var['name']` keys) |+| --- | --- |+| AlphaGenome, max absolute effect across all tracks and genes | `MAX_ABS_ATAC`, `MAX_ABS_DNASE`, `MAX_ABS_CHIP_TF`, `MAX_ABS_CHIP_HISTONE`, `MAX_ABS_CAGE`, `MAX_ABS_PROCAP`, `MAX_ABS_RNA_SEQ`, `MAX_ABS_POLYADENYLATION`, `MAX_ABS_CONTACT_MAPS` |+| AlphaGenome splicing (sites + usage + junctions/5, each max over genes) | `MERGED_SPLICING` |+| Protein | `ALPHAMISSENSE` (0 when there is no AlphaMissense prediction) |+| Conservation | `CACTUS_241_WAY` (Zoonomia phyloP, range -20 to 8.9), `PHASTCONS_470_WAY` |+| VEP loss-of-function indicators | `PROTEIN_TERMINATION` (stop gained or frameshift), `START_LOST`, `STOP_LOST` |+| Indel type | `IS_INSERTION`, `IS_DELETION` |++The 18 SHAP values (expected-gradients approximation, reference = all features+zero) **sum to the raw AVI score**, so the attribution tells you which modality+drives a high score: splicing, a TF-binding change, conservation alone, or a+coding consequence via AlphaMissense.++### Raw, quantile, Phred++The Atlas returns the raw score in `X` and a **cumulative quantile** against all+genome-wide SNVs in `layers['quantiles']`. Convert as DeepMind's tools do:++```text+tail = 1 - cdf_quantile # fraction of SNVs scoring at least this high+phred = -10 * log10(tail) # 10 = top 10 %, 20 = top 1 %, 30 = top 0.1 %, 40 = top 0.01 %+top % = 10 ** (-phred / 10) * 100+```++Indel Phred scores are placed on the SNV quantile curve. The report's guidance:+AVI is applicable to coding and non-coding variants, but **use region- or+application-aware thresholds and prefer ranking over hard cut-offs**. Pathogenic+regulatory variants land in lower AVI bins than pathogenic protein-truncating or+splice-motif variants, so one genome-wide cut-off under-calls regulatory hits.++### Benchmarks and case studies (report, for context only)++State-of-the-art on ClinVar non-coding, saturation genome editing, and TraitGym+style benchmarks against CADD, GPN-Star, and AlphaMissense after removing+training-set overlap; resolution of an epileptic-encephalopathy case in the+GREGoR cohort via a *DNM1* variant missed by prior tools; a 22 % increase in+detectable rare non-coding associations for circulating proteins in UK Biobank.++## Client API (`alphagenome.atlas.atlas`)++```python+from alphagenome.atlas import atlas+from alphagenome.data import genome++client = atlas.create(api_key, timeout=30) # gRPC to gdmscience.googleapis.com:443++client.scorer_metadata() # -> {name: ScorerMetadata(name, is_signed, track_metadata: DataFrame)}++client.query_variant(+ genome.Variant.from_str("chr22:36201698:A>C"), # 1-based position+ requested_scorers=["AVI_SCORE", "AVI_SCORE_FEATURE_IMPORTANCE", "RNA_SEQ"],+ ontology_terms=None, # e.g. ["UBERON:0001157", "CL:0000084"]; strings or OntologyTerm+ gene_ids=None, # Ensembl IDs, gene-centric scorers only+ gene_names=None, # symbols, gene-centric scorers only+) # -> {scorer_name: AnnData}++client.query_variants([...], requested_scorers=[...], progress_bar=True, max_workers=10)+client.query_interval(genome.Interval("chr11", 5225726, 5226575), requested_scorers=[...])+```++- `genome.Interval` is **0-based half-open**; `genome.Variant.position` is+ **1-based**. `Variant.from_str` also accepts gnomAD (`22-1024-A-C`), GTEx+ (`chr22_1024_A_C_b38`), and Open Targets spellings via `VariantFormat`.+- `query_interval` splits the window into 32 bp chunks, walks the pagination,+ and returns every SNV in it (3 per base). A 1 kb window is 3,000 variants and+ takes a few seconds; DeepMind's tool refuses windows above 1,000 bp by+ default, and so does `scripts/atlas_query.py` (`--max-window`).+- `query_variants` re-raises the first failed lookup; `scripts/atlas_query.py`+ queries one variant at a time so a single miss becomes an `error` cell.+- Each AnnData: `X` = raw scores (obs x tracks, `float32`), `obs['variant']` =+ `genome.Variant`, plus `gene_id`, `gene_name`, `strand`, `junction_Start`,+ `junction_End` for gene-centric scorers; `var` = track metadata (`name`,+ `strand`, `ontology_curie`, `biosample_name`, `biosample_type`, assay title,+ `gtex_tissue`, `transcription_factor`, `histone_mark` where applicable);+ `layers['quantiles']` when the server sent calibrated quantiles.+- `AVI_SCORE`: `X` shape (n, 1). `AVI_SCORE_FEATURE_IMPORTANCE`: `X` shape+ (n, 18), `var['name']` = the feature keys above.+- An `ontology_terms` filter is ignored for scorers whose tracks have no+ ontology metadata (the filter string is built that way), so `SPLICE_SITES`+ and the AVI scorers still come back.++### Errors++`atlas.handle_rpc_error` maps gRPC status to Python exceptions:++| gRPC status | Python | Typical cause |+| --- | --- | --- |+| `INVALID_ARGUMENT`, `NOT_FOUND` | `ValueError` | bad key ("API key not valid"), unknown scorer name, variant not in the Atlas (indel, `N` base, wrong REF) |+| `UNAUTHENTICATED`, `PERMISSION_DENIED` | `PermissionError` | key without Atlas access, terms not accepted |+| `DEADLINE_EXCEEDED` | `TimeoutError` | 60 s per-call timeout |+| `OUT_OF_RANGE` | `IndexError` | interval past the contig end |+| `RESOURCE_EXHAUSTED`, `UNAVAILABLE` | retried by the channel: 5 attempts, exponential back-off 1 s to 60 s | quota or transient outage |++An invalid key surfaces as `ValueError`, not `PermissionError` (checked live+with a dummy key on 2026-09-13).++## Access tiers and terms++From the report's Data Availability section and the AlphaGenome terms:++| Data | Access | Route |+| --- | --- | --- |+| AVI scores, all hg38 SNVs | **permissive** licence, commercial use allowed | static download (Tabix) at https://alphagenome.google/downloads |+| AVI scores | non-commercial | API (`AVI_SCORE`) |+| AVI feature attributions | non-commercial | static download (Tabix) and API (`AVI_SCORE_FEATURE_IMPORTANCE`) |+| Splicing scores | non-commercial | static download (Tabix) and API |+| All other raw Atlas track scores | non-commercial | **API only** |+| Motif compendium and instances | browse on the portal; bulk download promised | portal |+| Commercial API access | "coming soon" via Google Cloud Model Garden | - |++Model and Atlas outputs are for research and theoretical modelling, may not be+used to train other machine-learning models, and are not for diagnostic+procedures or medical decision-making. The website is free for non-commercial+use. Query rates are demand-dependent and unpublished; the docs say the Atlas+"will typically have a larger query rate" than on-demand model predictions.++## The portal++`https://deepmind.google.com/science/alphagenome/atlas` (also reachable as+`https://alphagenome.google/atlas`). Query parameters, from DeepMind's link+builder:++| Parameter | Meaning |+| --- | --- |+| `q` | variant `chr:pos:ref>alt` (1-based), interval `chr:start-end` (1-based closed), gene symbol, or Ensembl gene ID. **rsIDs are not accepted.** |+| `m` | view: `variant`, `locus`, `entity` (gene), `motifs` |+| `i` | viewport interval, needed before motif instances render |+| `f` | filters: `BIOSAMPLE_NAME:K562`, `BIOSAMPLE_TYPE:...` (AND), `SCORER_MODALITY:RNA-seq`, `ASSAY_TRANSCRIPTOR_FACTOR:GATA1`, `ASSAY_HISTONE_MARK:H3K27ac` (OR within the assay group), `GENE_NAME:HBB` |+| `lItems` | layout: `avi`, `section:RNA_SEQ`, `section:DNASE`, `section:CHIP_TF`, ..., `pinned:<track key>` |+| `scores`, `md`, `tpRenames`, `tpLegendTitle` | the `/atlas/track-predictions` REF-vs-ALT comparison page |++Because RNA-seq and DNase tracks carry no TF code, a filter made only of TF+predicates hides them; add `SCORER_MODALITY:RNA-seq,SCORER_MODALITY:DNase`+alongside (`scripts/atlas_link.py` does this automatically).++## Bulk files and annotations++- GENCODE v46 GTF as Feather, the annotation behind both Atlas and model gene+ scores: `https://storage.googleapis.com/alphagenome/reference/gencode/hg38/gencode.v46.annotation.gtf.gz.feather`+ (about 318 MB, roughly 4 GB RAM in pandas; column names are capitalised:+ `Feature`, `Start`, `End`, `Strand`). Load with `pd.read_feather` and use+ `alphagenome.data.gene_annotation` helpers (`filter_to_mane_select_transcript`,+ `get_gene_interval`, `extract_tss`) so gene models match the scores.+- AVI Tabix downloads: https://alphagenome.google/downloads (not inspected here).++## Citing++Cite both the Atlas report (above) and the model paper: Avsec Ž. *et al.*,+"Advancing regulatory variant effect prediction with AlphaGenome", *Nature*+649, 1206-1218 (2026), doi:10.1038/s41586-025-10014-0. Software:+https://github.com/google-deepmind/alphagenome (Apache-2.0 client; the model+weights and outputs carry separate terms).diff --git a/skills/alphagenome/references/interpretation.md b/skills/alphagenome/references/interpretation.mdnew file mode 100644index 00000000..18381589--- /dev/null+++ b/skills/alphagenome/references/interpretation.md@@ -0,0 +1,139 @@+# Interpreting AlphaGenome and Atlas scores++Distilled from the AlphaGenome and Atlas papers, the official FAQ, and the+interpretation guide DeepMind ships with its own AlphaGenome agent skill.+Everything here is a rule for writing up a prediction, not a claim about+biology.++## The frame++AlphaGenome predicts what a genomics assay would read out from a DNA sequence.+An Atlas or model score is therefore a **predicted molecular effect in a+biosample the model was trained on**, nothing more:++- It is not pathogenicity. AVI is trained to separate rare from common+ variants; that correlates with impact and is validated on ClinVar, but a high+ AVI is one line of evidence in a chain, "not sufficient evidence on its own"+ (Atlas report, Discussion).+- It is not a measurement. Predictions are correlative and can be wrong in+ either direction; independent epigenomic or functional data decides.+- It is not clinical. Terms of use and the report both exclude diagnostic use.+ Never turn a score into a diagnosis, penetrance, prognosis, or treatment+ statement. If the question is clinical, answer about molecular mechanism and+ say so.++## Raw score and quantile: always both++| Quantity | What it is | Use it for |+| --- | --- | --- |+| `raw_score` | effect size on the scorer's own scale (RNA_SEQ: log2 fold change; center-mask scorers: log2 ratio of summed signal; splicing: change in probability or usage) | magnitude, direction, comparing tissues **within one scorer** |+| `quantile_score` | rank against common variants (gnomAD v3 MAF > 0.01), signed, saturates near +/-0.99999 | unusualness; comparing across scorers |+| AVI `avi_raw` | composite model output | ranking within a set |+| AVI Phred | -10 log10(1 - cdf); 10 / 20 / 30 = top 10 % / 1 % / 0.1 % of all SNVs | genome-wide rank, thresholds |++Rules of thumb for `raw_score`, derived mainly from RNA-seq and to be checked+against the plotted tracks:++| \|raw\| | Reading |+| --- | --- |+| < 0.1 | no meaningful effect, whatever the quantile says |+| 0.1 to 0.5 | weak; report as a possible subtle change |+| 0.5 to 1.0 | moderate (about 1.4x to 2x for RNA-seq) |+| > 1.0 | strong (more than 2x for RNA-seq); -4 is a 16-fold reduction |++Raw scores are not percentages. Quote them with the scorer name and track.++**The common trap: high quantile, tiny raw score.** In low-expression genes and+quiet regions the background distribution is so narrow that a raw change of+0.05 ranks above 0.99. Report "no significant predicted effect" and name the+artefact. Conversely a raw -1.5 with quantile 0.9 in a highly variable track is+still a large predicted effect worth mentioning.++Unsigned scorers (`POLYADENYLATION`, `SPLICE_*`, `CONTACT_MAPS`, all+`*_ACTIVE`) have no direction; `*_ACTIVE` scores are the activity of the+stronger allele and cannot be read as a difference at all.++## AVI thresholds++The report recommends **ranking over hard cut-offs** and thresholds that are+"genomic region- or application-aware": pathogenic regulatory variants sit in+lower AVI bins than pathogenic protein-truncating or splice-motif variants, so a+single genome-wide Phred cut-off systematically under-calls regulatory hits.+Practical pattern:++1. Rank the candidate set by Phred and report the ranks.+2. State the top-percentile the Phred implies (Phred 20 = top 1 % of SNVs).+3. Read the feature attribution. `MERGED_SPLICING` or `ALPHAMISSENSE` dominant+ means a coding or splice mechanism; `MAX_ABS_DNASE` / `MAX_ABS_CHIP_TF` /+ `MAX_ABS_RNA_SEQ` mean a regulatory mechanism you can drill into by track;+ `CACTUS_241_WAY` / `PHASTCONS_470_WAY` dominant means conservation is+ carrying the score and the molecular mechanism is **not** resolved by AVI.+4. Only then drill into the per-track scores for the matched tissue.++## Tissue matching++- Choose biosamples by the disease's organ system and cell type, resolved to+ ontology terms, not by name similarity. Cardiac muscle is not smooth muscle;+ a fibroblast line is not brain.+- Report both the tissue with the largest predicted effect and the+ disease-relevant tissue, even when the latter shows nothing. An unexpected+ top tissue is a finding; a silent relevant tissue is also a finding.+- If the specific cell type has no track, fall back to the organ and say so.+- Evidence from an unrelated tissue is evidence about a different question.++## Negative results++Most variants are benign and the model will say so. "AlphaGenome predicts no+molecular effect in the 305 DNase and 371 RNA-seq tracks" is a complete,+valuable answer. Do not invent a cryptic splice site or an enhancer disruption+that the tracks do not show; do not infer disruption from location in a peak+when REF and ALT tracks are identical.++## What the model cannot see++- **Trans effects.** Only cis-regulatory grammar in a 1 Mb window; nothing about+ TF abundance, signalling, or the rest of the genome.+- **Training-data gaps.** Poly(A)-selected RNA-seq misses non-polyadenylated+ RNAs (snRNAs such as *RNU4-2* / *RNU4ATAC*); many cell types are absent;+ coverage is uneven across assays. A flat prediction in an untrained cell type+ is absence of data, not absence of effect.+- **Protein-level consequences.** Missense stability, catalysis, folding: use+ AlphaMissense (already an AVI feature) or protein tools.+- **Post-transcriptional biology** beyond splicing and polyadenylation: RNA+ structure, miRNA processing, localisation, translation.+- **Diploidy.** One haplotype per prediction; no heterozygous dosage, no+ compound effects unless you build the haplotype sequence yourself (the+ "haplotype workaround" tutorial).+- **Developmental time and stimulus context.** Static biosample profiles only.+- **Indels in the Atlas.** Scored for the paper, not yet served; use the model.+ Very large structural variants are unreliable everywhere.+- **Other species.** Only human and mouse were trained; nothing else is+ benchmarked.++## Coordinate hygiene before any lookup++1. Assembly must be GRCh38 for the Atlas (hg38 for the human model, mm10 for+ mouse). Lift over GRCh37 sources first and re-check REF.+2. REF must equal the reference base; the Atlas key ignores REF, so a swapped+ allele silently returns the wrong record.+3. Variants are 1-based, `genome.Interval` is 0-based half-open. Converting a+ 1-based closed `chr:start-end` means `start - 1, end`.+4. Left-normalise indels before scoring with the model.+5. Keep the `chr` prefix (`chrM` for the mitochondrion).++The `genomic-coordinates` skill covers all of this with scripts.++## Reporting checklist++- Name the source: "AlphaGenome Atlas (AVI, precomputed)" or "AlphaGenome model+ (on-demand, 1 Mb window)", with the client version and the date of the query.+- For every variant: raw score **and** quantile or Phred, the scorer, the track+ or biosample and its ontology CURIE, and the gene for gene-centric scorers.+- Direction as words ("predicted 2.3-fold lower HBB expression in erythroblast+ RNA-seq"), never a bare number.+- Say which claims rest on the model alone and which have independent support.+- Link each variant to the Atlas website so a reader can inspect the tracks+ (`scripts/atlas_link.py`).+- Close with the limitation that applies (untrained tissue, conservation-driven+ AVI, non-polyadenylated gene, ...), and the standard research-only statement.+- Cite the AlphaGenome paper and the Atlas report.diff --git a/skills/alphagenome/references/model-api.md b/skills/alphagenome/references/model-api.mdnew file mode 100644index 00000000..6fde0ee1--- /dev/null+++ b/skills/alphagenome/references/model-api.md@@ -0,0 +1,230 @@+# AlphaGenome model API (`alphagenome.models.dna_client`)++Verified against `alphagenome` 0.9.0. The client is a thin gRPC wrapper: no+weights, no GPU, one API key. The same key serves the Atlas.++## Setup++```bash+uv pip install alphagenome # PyPI; Python >= 3.10, tested here on 3.12 and 3.13+export ALPHAGENOME_API_KEY=... # https://deepmind.google.com/science/alphagenome+```++```python+import os+from alphagenome.data import gene_annotation, genome, transcript+from alphagenome.models import dna_client, variant_scorers+from alphagenome.visualization import plot_components++dna_model = dna_client.create(os.environ["ALPHAGENOME_API_KEY"], timeout=30)+```++`alphagenome.colab_utils.get_api_key()` reads `ALPHA_GENOME_API_KEY` (note the+underscore) or a Colab secret of that name. The scripts here accept both.++## Coordinates and inputs++| Object | Convention |+| --- | --- |+| `genome.Interval(chromosome, start, end, strand='.')` | **0-based, half-open** |+| `genome.Variant(chromosome, position, reference_bases, alternate_bases, name='')` | **1-based** position, VCF-style anchored alleles |+| `genome.Variant.from_str("chr22:36201698:A>C")` | adds `chr` if missing; `VariantFormat.GNOMAD` (`22-1024-A-C`), `GTEX` (`chr22_1024_A_C_b38`), `OPEN_TARGETS` (`22_1024_A_C`), `OPEN_TARGETS_BIGQUERY` (`22:1024:A:C`) |+| `variant.reference_interval.resize(width)` | the usual way to build the model window around a variant |+| Human | hg38 (GRCh38.p13) |+| Mouse | mm10 (GRCm38.p6), `organism=dna_client.Organism.MUS_MUSCULUS` |++Supported input widths (`dna_client.SUPPORTED_SEQUENCE_LENGTHS`):++| Name | bp | Use |+| --- | --- | --- |+| `SEQUENCE_LENGTH_16KB` | 16,384 | ISM scans, fast iteration |+| `SEQUENCE_LENGTH_100KB` | 131,072 | |+| `SEQUENCE_LENGTH_500KB` | 524,288 | |+| `SEQUENCE_LENGTH_1MB` | 1,048,576 | default; best accuracy, needed for distal enhancers and contact maps |++Any other width raises. Sequences may contain `N` (pad with `'N'` for short+constructs: `seq.center(dna_client.SEQUENCE_LENGTH_1MB, 'N')`). 2 kb inputs were+removed in 0.5.0.++## Output types (`dna_client.OutputType`)++| Type | Signal | Resolution | Human tracks |+| --- | --- | --- | --- |+| `ATAC`, `DNASE` | chromatin accessibility | 1 bp | 167 / 305 |+| `CHIP_TF` | TF binding ChIP-seq | 1 bp | 1,617 |+| `CHIP_HISTONE` | histone marks | 128 bp | 1,116 |+| `CAGE`, `PROCAP` | transcription initiation (5' ends) | 1 bp | 546 / 12 (PROCAP human only) |+| `RNA_SEQ` | stranded coverage | 1 bp | 667 |+| `SPLICE_SITES` | donor/acceptor probability | 1 bp | 2 (strand-merged) |+| `SPLICE_SITE_USAGE` | fraction of transcripts using each site | 1 bp | 734 |+| `SPLICE_JUNCTIONS` | split-read counts per junction | junction | 734 |+| `CONTACT_MAPS` | 3D contact probability | 2,048 bp bins | 28 |++5,563 human tracks in total. Every track row carries `name`, `strand`,+`ontology_curie`, `biosample_name`, `biosample_type`, plus `gtex_tissue`+(RNA_SEQ, SPLICE_*), `transcription_factor` (CHIP_TF), `histone_mark`+(CHIP_HISTONE). Discover them with:++```python+meta = dna_model.output_metadata(dna_client.Organism.HOMO_SAPIENS)+df = meta.concatenate() # every output type in one DataFrame+df[df.biosample_name.str.contains("liver", case=False)][["output_type", "name", "ontology_curie", "biosample_name"]]+```++or `python scripts/score_variants.py --list-tracks --query liver -o tracks.tsv`.++Ontology terms are CURIEs: `UBERON:0002048` (lung), `UBERON:0001157` (colon,+transverse), `UBERON:0001114` (right liver lobe), `CL:0000084` (T cell),+`CL:0000236` (B cell), `EFO:0002067` (K562), `CLO:...` for cell lines.+Passing `ontology_terms=None` returns every track. The `ontology-term-resolution`+skill turns free text into validated CURIEs; then confirm the term exists in+`output_metadata`, because the model only has tracks for its training biosamples.++## Predictions++```python+interval = genome.Interval("chr22", 36_201_698 - 2**19, 36_201_698 + 2**19) # 1 Mb++out = dna_model.predict_interval(+ interval=interval,+ requested_outputs=[dna_client.OutputType.RNA_SEQ, dna_client.OutputType.DNASE],+ ontology_terms=["UBERON:0001157"],+)+out.rna_seq.values.shape # (1048576, n_tracks) float32+out.rna_seq.metadata # track DataFrame+out.rna_seq.interval, out.rna_seq.resolution++variant = genome.Variant.from_str("chr22:36201698:A>C")+vo = dna_model.predict_variant(+ interval=variant.reference_interval.resize(dna_client.SEQUENCE_LENGTH_1MB),+ variant=variant,+ requested_outputs=[dna_client.OutputType.RNA_SEQ],+ ontology_terms=["UBERON:0001157"],+)+vo.reference.rna_seq, vo.alternate.rna_seq # TrackData for REF and ALT haplotypes++out = dna_model.predict_sequence(sequence="ACGT...", requested_outputs=[...], ontology_terms=[...])+```++`predict_variants` / `predict_intervals` / `predict_sequences` take lists and run+in parallel (`max_workers`, default 5). `TrackData` supports+`filter_to_positive_strand()`, `select_tracks_by_name()`, `slice_by_interval()`,+`resize()`, `change_resolution()`, `reverse_complement()`, and NumPy-style+`tdata[interval, mask]` indexing.++## Variant scoring++```python+scorers = list(variant_scorers.RECOMMENDED_VARIANT_SCORERS.values()) # 19 configurations+adatas = dna_model.score_variant(interval, variant, variant_scorers=scorers) # list[AnnData], one per scorer+df = variant_scorers.tidy_scores(adatas, match_gene_strand=True) # long DataFrame+df[["variant_id", "output_type", "variant_scorer", "gene_name", "biosample_name",+ "ontology_curie", "raw_score", "quantile_score"]]++# many variants, same window size+adatas = dna_model.score_variants(+ [v.reference_interval.resize(dna_client.SEQUENCE_LENGTH_1MB) for v in variants],+ variants, scorers, organism=dna_client.Organism.HOMO_SAPIENS, max_workers=5)+df = variant_scorers.tidy_scores(adatas)+```++`score_variant` has **no** `ontology_terms` argument: filter `df` on+`ontology_curie` or `biosample_name` afterwards (or on `adata.var`). At most 20+scorers per request, no duplicates. `merge_stranded_gene_tracks=True`+(default) merges + and - RNA-seq tracks for gene-centric scorers.++### Recommended scorers (`RECOMMENDED_VARIANT_SCORERS`)++| Key | Class | Configuration | Meaning of `raw_score` |+| --- | --- | --- | --- |+| `ATAC`, `DNASE`, `CHIP_TF`, `CAGE`, `PROCAP` | `CenterMaskScorer` | width 501, `DIFF_LOG2_SUM` | log2(sum ALT + 1) - log2(sum REF + 1) over the 501 bp around the variant |+| `CHIP_HISTONE` | `CenterMaskScorer` | width 2001, `DIFF_LOG2_SUM` | same, 2 kb window |+| `RNA_SEQ` | `GeneMaskLFCScorer` | | log2 fold change of exon coverage per gene overlapping the window (-1 = halved) |+| `RNA_SEQ_ACTIVE` | `GeneMaskActiveScorer` | | log activity of the more active allele; **not** a difference |+| `SPLICE_SITES`, `SPLICE_SITE_USAGE` | `GeneMaskSplicingScorer` | width None | max change in site probability / usage within the gene |+| `SPLICE_JUNCTIONS` | `SpliceJunctionScorer` | | change in junction counts, per junction |+| `POLYADENYLATION` | `PolyadenylationScorer` | | max log fold change in poly(A) isoform ratio; human only |+| `CONTACT_MAPS` | `ContactMapScorer` | | change in contact probability |+| `*_ACTIVE` (ATAC, DNASE, CHIP_TF, CHIP_HISTONE, CAGE, PROCAP) | `CenterMaskScorer` | `ACTIVE_SUM` | activity of the stronger allele |++Custom configurations: `CenterMaskScorer(requested_output, width in {None, 501,+2001, 10001, 100001, 200001}, aggregation_type in {DIFF_MEAN, DIFF_SUM,+DIFF_SUM_LOG2, DIFF_LOG2_SUM, L2_DIFF, L2_DIFF_LOG1P, ACTIVE_MEAN, ACTIVE_SUM})`+and `GeneMaskSplicingScorer(..., width in {None, 101, 1001, 10001})`.++`quantile_score` is the rank of `raw_score` against a background of common+variants (gnomAD v3 MAF > 0.01) for that scorer and track, signed like the raw+score and saturating at about +/-0.99999. Use it to judge unusualness, the raw+score to judge magnitude, and never one without the other+(`references/interpretation.md`).++## In silico mutagenesis++```python+window = genome.Interval("chr20", 3_753_000, 3_753_400).resize(dna_client.SEQUENCE_LENGTH_16KB)+ism_interval = window.resize(256) # mutate the central 256 bp (3 x 256 variants)+scorer = variant_scorers.CenterMaskScorer(+ requested_output=dna_client.OutputType.DNASE, width=501,+ aggregation_type=variant_scorers.AggregationType.DIFF_MEAN)+scores = dna_model.score_ism_variants(interval=window, ism_interval=ism_interval,+ variant_scorers=[scorer], interval_variant=None)+# scores: list (per variant) of list (per scorer) of AnnData+from alphagenome.interpretation import ism+matrix = ism.ism_matrix([s[0].X[0, track_index] for s in scores], variants=[s[0].uns["variant"] for s in scores])+plot_components.plot([plot_components.SeqLogo(matrix, scores=..., ylabel="ISM")], interval=ism_interval)+```++`interval_variant=` runs the scan on the ALT haplotype. The client chunks ISM+requests to 10 bp per call; a 256 bp scan is about 26 requests. For an hg38 SNV+window the Atlas already holds the answer (`atlas_query.py avi --interval`), so+reserve live ISM for mouse, non-reference backgrounds, or custom scorers.++## Gene annotation and plots++```python+import pandas as pd+gtf = pd.read_feather("https://storage.googleapis.com/alphagenome/reference/gencode/hg38/gencode.v46.annotation.gtf.gz.feather")+gtf = gene_annotation.filter_protein_coding(gtf)+gtf = gene_annotation.filter_to_mane_select_transcript(gtf) # or filter_to_longest_transcript+interval = gene_annotation.get_gene_interval(gtf, gene_symbol="HBB").resize(dna_client.SEQUENCE_LENGTH_1MB)+transcripts = transcript.TranscriptExtractor(gtf).extract(interval)++plot_components.plot(+ [+ plot_components.TranscriptAnnotation(transcripts),+ plot_components.OverlaidTracks({"REF": vo.reference.rna_seq, "ALT": vo.alternate.rna_seq},+ colors={"REF": "dimgrey", "ALT": "red"}),+ ],+ interval=variant.reference_interval.resize(20_000),+ annotations=[plot_components.VariantAnnotation([variant])],+)+```++Components: `Tracks`, `OverlaidTracks`, `ContactMaps`, `ContactMapsDiff`,+`TranscriptAnnotation`, `SeqLogo`, `Sashimi` (splice junctions; filter by+strand yourself, it has no `strand` argument), with `IntervalAnnotation` and+`VariantAnnotation` overlays. The Feather GTF uses capitalised column names+(`Feature`, `Start`, `End`, `Strand`). Mouse annotations: GENCODE vM23 at the+same bucket path with `mm10`.++## Errors, retries, quota++`dna_client` wraps calls in `retry_rpc` (retries on `RESOURCE_EXHAUSTED` and+`UNAVAILABLE`). gRPC errors surface as `grpc.RpcError`; `error.code()` tells you+whether it is a bad key (`UNAUTHENTICATED` / `INVALID_ARGUMENT`), a quota stop+(`RESOURCE_EXHAUSTED`), or a bad argument. Quotas are per key and unpublished;+the API is free for non-commercial use, and DeepMind states outputs may not be+used to train other ML models. Commercial use goes through Google Cloud Model+Garden.++## Official material++- Docs: https://www.alphagenomedocs.com/ (quick start, essential commands,+ batch variant scoring, splicing variant scoring, PSI derivation, haplotype+ workaround, tissue ontology mapping, visualisation tour, FAQ).+- Code: https://github.com/google-deepmind/alphagenome (client) and+ https://github.com/google-deepmind/alphagenome_research (model code).+- DeepMind agent skills with worked variant reports:+ https://github.com/google-deepmind/science-skills (Apache-2.0).+- Paper: Avsec Ž. *et al.*, *Nature* 649, 1206-1218 (2026),+ doi:10.1038/s41586-025-10014-0.diff --git a/skills/alphagenome/scripts/_common.py b/skills/alphagenome/scripts/_common.pynew file mode 100644index 00000000..3f6c505c--- /dev/null+++ b/skills/alphagenome/scripts/_common.py@@ -0,0 +1,511 @@+"""Shared helpers for the alphagenome skill scripts.++Standard library only, so variant parsing, interval arithmetic, API-key+discovery, Phred conversion, and table export all work (and are testable)+without the ``alphagenome`` package installed. The scripts import the SDK+lazily through :func:`require_alphagenome`.+"""++from __future__ import annotations++import csv+import io+import json+import math+import os+import re+import sys+from collections.abc import Iterable, Mapping, Sequence+from dataclasses import dataclass, field+from pathlib import Path++# --------------------------------------------------------------------------+# constants+# --------------------------------------------------------------------------++#: Environment variables checked, in order, for the AlphaGenome API key.+#: The first spelling is what DeepMind's own agent skills use; the second is+#: what ``alphagenome.colab_utils.get_api_key`` reads by default.+API_KEY_ENV_VARS: tuple[str, ...] = ("ALPHAGENOME_API_KEY", "ALPHA_GENOME_API_KEY")++GET_KEY_URL = "https://deepmind.google.com/science/alphagenome"+ATLAS_BASE_URL = "https://deepmind.google.com/science/alphagenome/atlas"+ATLAS_TRACK_PREDICTIONS_URL = f"{ATLAS_BASE_URL}/track-predictions"+DOCS_URL = "https://www.alphagenomedocs.com/"++#: GENCODE v46 annotation used by the Atlas and the model, as a Feather file+#: (about 318 MB; needs roughly 4 GB of RAM to load with pandas).+GTF_FEATHER_URL = (+ "https://storage.googleapis.com/alphagenome/reference/gencode/hg38/"+ "gencode.v46.annotation.gtf.gz.feather"+)++#: Atlas scorer names for the composite AlphaGenome Variant Impact score and+#: its 18-way SHAP feature attribution.+AVI_SCORER = "AVI_SCORE"+AVI_FEATURES_SCORER = "AVI_SCORE_FEATURE_IMPORTANCE"+AVI_SCORERS: tuple[str, str] = (AVI_SCORER, AVI_FEATURES_SCORER)++#: The 18 AVI input features, keyed by the ``var['name']`` values returned by+#: the ``AVI_SCORE_FEATURE_IMPORTANCE`` scorer. Value: (display name, category,+#: Atlas track scorers that feed the feature; empty for annotation features).+AVI_FEATURES: dict[str, tuple[str, str, tuple[str, ...]]] = {+ "MERGED_SPLICING": (+ "Splicing",+ "Splicing",+ ("SPLICE_SITES", "SPLICE_SITE_USAGE", "SPLICE_JUNCTIONS"),+ ),+ "MAX_ABS_RNA_SEQ": ("RNA-seq", "Transcription", ("RNA_SEQ",)),+ "MAX_ABS_ATAC": ("ATAC-seq", "Chromatin accessibility", ("ATAC",)),+ "MAX_ABS_DNASE": ("DNase-seq", "Chromatin accessibility", ("DNASE",)),+ "MAX_ABS_CHIP_TF": ("ChIP-TF", "Transcription factor binding", ("CHIP_TF",)),+ "MAX_ABS_CHIP_HISTONE": ("ChIP-Histone", "Histone modification", ("CHIP_HISTONE",)),+ "MAX_ABS_CAGE": ("CAGE", "Transcription initiation", ("CAGE",)),+ "MAX_ABS_PROCAP": ("PRO-cap", "Transcription initiation", ("PROCAP",)),+ "MAX_ABS_POLYADENYLATION": ("Polyadenylation", "Transcription", ("POLYADENYLATION",)),+ "MAX_ABS_CONTACT_MAPS": ("3D genome contacts", "3D genome organization", ("CONTACT_MAPS",)),+ "ALPHAMISSENSE": ("AlphaMissense", "Protein impact", ()),+ "CACTUS_241_WAY": ("Zoonomia Cactus 241-way", "Evolutionary conservation", ()),+ "PHASTCONS_470_WAY": ("PhastCons 470-way", "Evolutionary conservation", ()),+ "PROTEIN_TERMINATION": ("Protein termination", "Coding consequence", ()),+ "START_LOST": ("Start lost", "Coding consequence", ()),+ "STOP_LOST": ("Stop lost", "Coding consequence", ()),+ "IS_INSERTION": ("Insertion", "Indel type", ()),+ "IS_DELETION": ("Deletion", "Indel type", ()),+}++#: Atlas track-level scorers (one AnnData each; tracks on the ``var`` axis).+#: ``scorer_metadata()`` is the authority on what the server currently serves.+ATLAS_TRACK_SCORERS: tuple[str, ...] = (+ "ATAC",+ "DNASE",+ "CHIP_TF",+ "CHIP_HISTONE",+ "CAGE",+ "PROCAP",+ "RNA_SEQ",+ "POLYADENYLATION",+ "SPLICE_SITES",+ "SPLICE_SITE_USAGE",+ "SPLICE_JUNCTIONS",+ "CONTACT_MAPS",+)++#: Per-position substitution count the Atlas stores (three alternates per base).+SNVS_PER_BASE = 3++INSTALL_HINT = (+ "alphagenome is not installed. Run: uv pip install alphagenome "+ "(or invoke with: uv run --with alphagenome <script>)"+)++# --------------------------------------------------------------------------+# variants and intervals+# --------------------------------------------------------------------------++_VALID_BASES = frozenset("ACGTN")+++@dataclass(frozen=True)+class VariantSpec:+ """A variant in VCF terms: 1-based position, explicit REF and ALT."""++ chromosome: str+ position: int+ ref: str+ alt: str+ name: str = field(default="", compare=False)++ def __str__(self) -> str:+ return f"{self.chromosome}:{self.position}:{self.ref}>{self.alt}"++ @property+ def is_snv(self) -> bool:+ return len(self.ref) == 1 and len(self.alt) == 1++ def to_row(self) -> dict[str, object]:+ return {+ "variant": str(self),+ "chromosome": self.chromosome,+ "position": self.position,+ "ref": self.ref,+ "alt": self.alt,+ "name": self.name,+ }+++def normalize_chromosome(contig: str) -> str:+ """Return the ``chr``-prefixed spelling the Atlas and model expect.++ ``MT`` and ``M`` become ``chrM``; ``chr`` is added when missing. Nothing+ else is rewritten: an unplaced contig stays as given.+ """+ text = str(contig).strip()+ if not text:+ raise ValueError("empty chromosome name")+ if text.lower().startswith("chr"):+ text = text[3:]+ if text.upper() in {"MT", "M"}:+ return "chrM"+ return f"chr{text}"+++# Accepted spellings. Group order is always chrom, pos, ref, alt.+_VARIANT_PATTERNS: tuple[tuple[str, re.Pattern[str]], ...] = (+ # chr22:1024:A>C (AlphaGenome default) and chr22:1024:A:C (Open Targets BigQuery)+ ("default", re.compile(r"^(\w+):(\d+):([ACGTNacgtn]+)[>:]([ACGTNacgtn]+)$")),+ # 22-1024-A-C (gnomAD)+ ("gnomad", re.compile(r"^(\w+)-(\d+)-([ACGTNacgtn]+)-([ACGTNacgtn]+)$")),+ # chr22_1024_A_C_b38 (GTEx, build suffix optional) and 22_1024_A_C (Open Targets)+ ("gtex", re.compile(r"^(\w+?)_(\d+)_([ACGTNacgtn]+)_([ACGTNacgtn]+)(?:_b38)?$")),+)+++def parse_variant_string(text: str, name: str = "") -> VariantSpec:+ """Parse ``chr:pos:ref>alt`` and the gnomAD, GTEx, and Open Targets spellings.++ Positions are 1-based, as in VCF and on the Atlas website. Bases are+ upper-cased. Raises ``ValueError`` on anything else, including rsIDs,+ which neither the Atlas API nor the portal accept.+ """+ candidate = text.strip()+ for _, pattern in _VARIANT_PATTERNS:+ match = pattern.match(candidate)+ if match:+ chrom, pos, ref, alt = match.groups()+ return VariantSpec(+ chromosome=normalize_chromosome(chrom),+ position=int(pos),+ ref=ref.upper(),+ alt=alt.upper(),+ name=name,+ )+ raise ValueError(+ f"cannot parse variant {text!r}; use chr:pos:ref>alt with a 1-based "+ "position (also accepted: 22-1024-A-C, chr22_1024_A_C_b38, 22:1024:A:C). "+ "rsIDs are not supported - resolve them to coordinates first."+ )+++def parse_interval_string(text: str) -> tuple[str, int, int]:+ """Parse a 1-based closed ``chr:start-end`` into 0-based half-open bounds.++ Returns ``(chromosome, start0, end)`` ready for ``genome.Interval``.+ Thousands separators are tolerated.+ """+ candidate = text.strip().replace(",", "")+ match = re.match(r"^(\w+):(\d+)-(\d+)$", candidate)+ if not match:+ raise ValueError(f"cannot parse interval {text!r}; expected chr:start-end (1-based, closed)")+ chrom, start, end = match.group(1), int(match.group(2)), int(match.group(3))+ if start < 1:+ raise ValueError(f"interval start must be >= 1 (got {start}); coordinates are 1-based")+ if end < start:+ raise ValueError(f"interval end {end} is before start {start}")+ return normalize_chromosome(chrom), start - 1, end+++def interval_width(start0: int, end: int) -> int:+ return end - start0+++def _split_delimited(path: Path) -> tuple[list[str], list[list[str]]]:+ text = path.read_text(encoding="utf-8")+ sample = text[:4096]+ if path.suffix.lower() == ".csv":+ delimiter = ","+ elif "\t" in sample:+ delimiter = "\t"+ else:+ try:+ delimiter = csv.Sniffer().sniff(sample, delimiters=",\t;").delimiter+ except csv.Error:+ delimiter = ","+ reader = csv.reader(io.StringIO(text), delimiter=delimiter)+ rows = [row for row in reader if row and any(cell.strip() for cell in row)]+ if not rows:+ return [], []+ header = [cell.strip() for cell in rows[0]]+ return header, rows[1:]+++_SYMBOLIC_ALT = re.compile(r"^(<.*>|\*|\.)$")+++def read_vcf(path: Path) -> tuple[list[VariantSpec], list[str]]:+ """Read the CHROM/POS/ID/REF/ALT columns of a VCF, splitting multi-allelic ALTs.++ Returns ``(variants, warnings)``. Symbolic alleles (``<DEL>``, ``*``, ``.``)+ and breakends are skipped with a warning; the Atlas has no entry for them.+ """+ variants: list[VariantSpec] = []+ warnings: list[str] = []+ with path.open(encoding="utf-8") as handle:+ for line_number, line in enumerate(handle, start=1):+ if not line.strip() or line.startswith("#"):+ continue+ fields = line.rstrip("\n").split("\t")+ if len(fields) < 5:+ warnings.append(f"line {line_number}: fewer than 5 columns, skipped")+ continue+ chrom, pos, identifier, ref, alts = fields[:5]+ for alt in alts.split(","):+ if _SYMBOLIC_ALT.match(alt) or "[" in alt or "]" in alt:+ warnings.append(f"line {line_number}: symbolic allele {alt!r} skipped")+ continue+ if not set(ref.upper()) <= _VALID_BASES or not set(alt.upper()) <= _VALID_BASES:+ warnings.append(f"line {line_number}: non-ACGTN allele {ref}>{alt} skipped")+ continue+ variants.append(+ VariantSpec(+ chromosome=normalize_chromosome(chrom),+ position=int(pos),+ ref=ref.upper(),+ alt=alt.upper(),+ name="" if identifier in {".", ""} else identifier,+ )+ )+ return variants, warnings+++def read_variant_table(path: str | Path) -> tuple[list[VariantSpec], list[str]]:+ """Read variants from a VCF or a delimited table.++ Delimited files need either a ``variant`` (or ``variant_id`` / ``id``)+ column holding ``chr:pos:ref>alt`` strings, or ``CHROM``/``POS``/``REF``/+ ``ALT`` columns (case-insensitive; ``chromosome``/``position`` also work),+ matching the layout of the official batch-scoring notebook.+ """+ file_path = Path(path)+ if not file_path.exists():+ raise FileNotFoundError(file_path)+ if file_path.suffix.lower() == ".vcf" or file_path.name.lower().endswith(".vcf.gz"):+ if file_path.name.lower().endswith(".gz"):+ raise ValueError("gzipped VCF is not supported by this helper; decompress it first")+ return read_vcf(file_path)++ header, rows = _split_delimited(file_path)+ if not header:+ return [], [f"{file_path.name}: empty file"]+ lookup = {name.lower(): index for index, name in enumerate(header)}++ def column(*names: str) -> int | None:+ for name in names:+ if name in lookup:+ return lookup[name]+ return None++ chrom_col = column("chrom", "chromosome", "chr", "#chrom")+ pos_col = column("pos", "position")+ ref_col = column("ref", "reference_bases", "reference")+ alt_col = column("alt", "alternate_bases", "alternate")+ id_col = column("variant_id", "id", "name", "rsid")+ variant_col = column("variant", "variant_str", "variant_string")++ variants: list[VariantSpec] = []+ warnings: list[str] = []+ if None not in (chrom_col, pos_col, ref_col, alt_col):+ for index, row in enumerate(rows, start=2):+ try:+ variants.append(+ VariantSpec(+ chromosome=normalize_chromosome(row[chrom_col]),+ position=int(row[pos_col]),+ ref=row[ref_col].strip().upper(),+ alt=row[alt_col].strip().upper(),+ name=row[id_col].strip() if id_col is not None and id_col < len(row) else "",+ )+ )+ except (ValueError, IndexError) as error:+ warnings.append(f"line {index}: {error}")+ elif variant_col is not None or id_col is not None:+ source = variant_col if variant_col is not None else id_col+ for index, row in enumerate(rows, start=2):+ try:+ text = row[source]+ name = row[id_col].strip() if id_col is not None and id_col != source and id_col < len(row) else ""+ variants.append(parse_variant_string(text, name=name))+ except (ValueError, IndexError) as error:+ warnings.append(f"line {index}: {error}")+ else:+ raise ValueError(+ f"{file_path.name}: need CHROM/POS/REF/ALT columns or a 'variant' column; "+ f"found {header}"+ )+ return variants, warnings+++def collect_variants(+ variant_args: Sequence[str] | None,+ input_path: str | None,+) -> tuple[list[VariantSpec], list[str]]:+ """Merge ``--variant`` strings and an ``--input`` file into one list."""+ variants: list[VariantSpec] = []+ warnings: list[str] = []+ for text in variant_args or ():+ variants.append(parse_variant_string(text))+ if input_path:+ from_file, file_warnings = read_variant_table(input_path)+ variants.extend(from_file)+ warnings.extend(file_warnings)+ return variants, warnings+++# --------------------------------------------------------------------------+# credentials and SDK+# --------------------------------------------------------------------------+++def load_api_key(env_var: str | None = None) -> str:+ """Return the API key from the environment, or exit with instructions.++ Never accepts the key on the command line: it would land in shell history+ and process listings.+ """+ names = (env_var,) if env_var else API_KEY_ENV_VARS+ for name in names:+ value = os.environ.get(name, "").strip()+ if value:+ return value+ raise SystemExit(+ f"No AlphaGenome API key found in {', '.join(names)}. Request a key at "+ f"{GET_KEY_URL} (free for non-commercial use) and export it, for example:\n"+ f" export {names[0]}=...\n"+ "Never paste the key into a command line or commit it."+ )+++def require_alphagenome():+ """Import and return the ``alphagenome`` package, or exit with an install hint."""+ try:+ import alphagenome # noqa: F401 (import check only)+ except ImportError:+ print(INSTALL_HINT, file=sys.stderr)+ sys.exit(2)+ return alphagenome+++# --------------------------------------------------------------------------+# score arithmetic+# --------------------------------------------------------------------------+++def cdf_to_tail_and_phred(cdf_quantile: float, floor: float = 1e-7) -> tuple[float, float]:+ """Convert the Atlas ``quantiles`` layer (a CDF value) to (tail quantile, Phred).++ The Atlas stores the cumulative quantile of the AVI raw score against all+ genome-wide SNVs. ``tail = 1 - cdf`` is the fraction of SNVs scoring at+ least this high; ``phred = -10 * log10(tail)``, so Phred 20 is the top 1%.+ The tail is floored so a saturated quantile does not become infinity.+ """+ if not math.isfinite(cdf_quantile):+ return float("nan"), float("nan")+ tail = max(floor, 1.0 - float(cdf_quantile))+ return tail, -10.0 * math.log10(tail)+++def phred_to_top_percent(phred: float) -> float:+ """Phred 20 -> 1.0 (top 1%); Phred 30 -> 0.1 (top 0.1%)."""+ if not math.isfinite(phred):+ return float("nan")+ return (10.0 ** (-phred / 10.0)) * 100.0+++def feature_display_name(key: str) -> str:+ entry = AVI_FEATURES.get(key)+ return entry[0] if entry else key+++def portal_variant_url(variant: str) -> str:+ """Deep link to one variant on the Atlas website (AVI track shown).++ ``atlas_link.py`` builds the full range of portal URLs; this is the+ minimal form the query scripts attach to every scored variant.+ """+ from urllib.parse import quote # noqa: PLC0415++ return f"{ATLAS_BASE_URL}?q={quote(variant, safe=':')}&m=variant&lItems=avi"+++# --------------------------------------------------------------------------+# output+# --------------------------------------------------------------------------++_FORMATS = ("tsv", "csv", "json", "parquet")+++def _stringify(value: object) -> object:+ if value is None:+ return ""+ if isinstance(value, float):+ if math.isnan(value):+ return ""+ return f"{value:.6g}"+ return value+++def write_rows(+ rows: Sequence[Mapping[str, object]],+ output: str | None,+ fmt: str = "tsv",+ columns: Sequence[str] | None = None,+) -> None:+ """Write rows to ``output`` (or stdout) as TSV, CSV, JSON, or Parquet.++ Column order is the first-seen key order unless ``columns`` is given.+ Parquet needs pandas and pyarrow, both of which ``alphagenome`` installs.+ """+ if fmt not in _FORMATS:+ raise ValueError(f"unknown format {fmt!r}; choose from {_FORMATS}")+ if columns is None:+ seen: dict[str, None] = {}+ for row in rows:+ for key in row:+ seen.setdefault(key, None)+ columns = list(seen)++ if fmt == "parquet":+ if not output:+ raise ValueError("parquet output needs -o/--output")+ import pandas as pd # noqa: PLC0415 (optional dependency)++ pd.DataFrame(list(rows), columns=list(columns)).to_parquet(output, index=False)+ return++ if fmt == "json":+ text = json.dumps([{key: row.get(key) for key in columns} for row in rows], indent=2, default=str)+ text += "\n"+ else:+ buffer = io.StringIO()+ writer = csv.writer(buffer, delimiter="\t" if fmt == "tsv" else ",", lineterminator="\n")+ writer.writerow(columns)+ for row in rows:+ writer.writerow([_stringify(row.get(key)) for key in columns])+ text = buffer.getvalue()++ if output:+ Path(output).write_text(text, encoding="utf-8")+ else:+ sys.stdout.write(text)+++def warn(message: str) -> None:+ print(f"warning: {message}", file=sys.stderr)+++def format_from_output(output: str | None, explicit: str | None) -> str:+ """Pick an output format: explicit flag, else file extension, else TSV."""+ if explicit:+ return explicit+ if output:+ suffix = Path(output).suffix.lower().lstrip(".")+ if suffix in _FORMATS:+ return suffix+ if suffix == "txt":+ return "tsv"+ return "tsv"+++def chunked(items: Sequence, size: int) -> Iterable[Sequence]:+ for start in range(0, len(items), size):+ yield items[start : start + size]diff --git a/skills/alphagenome/scripts/atlas_link.py b/skills/alphagenome/scripts/atlas_link.pynew file mode 100644index 00000000..8311f6ee--- /dev/null+++ b/skills/alphagenome/scripts/atlas_link.py@@ -0,0 +1,202 @@+#!/usr/bin/env python3+"""Build deep links into the AlphaGenome Atlas website. Standard library only.++The portal at https://deepmind.google.com/science/alphagenome/atlas is the+no-code face of the Atlas: AVI score, per-modality heatmaps across every+biosample, and motif maps. Linking a scored variant to it lets a reader check+the prediction tracks behind a number. Positions are 1-based, intervals are+1-based closed, and rsIDs are not accepted by the site.++Examples:+ python atlas_link.py variant chr9:128225994:G>A+ python atlas_link.py variant chr9:128225994:G>A --biosample K562 --modalities RNA_SEQ,DNASE,CHIP_TF --tf GATA1+ python atlas_link.py locus chr11:5225727-5226575 --modalities RNA_SEQ,DNASE+ python atlas_link.py gene HBB+ python atlas_link.py motifs chr11:5225727-5226575+ python atlas_link.py variant chr9:128225994:G>A --markdown+"""++from __future__ import annotations++import argparse+import sys+import urllib.parse+from collections.abc import Sequence++import _common as common++MODES = ("variant", "locus", "gene", "motifs")++#: Layout sections the portal renders (``lItems=section:<MODALITY>``).+SECTION_MODALITIES: tuple[str, ...] = (+ "RNA_SEQ",+ "DNASE",+ "ATAC",+ "CHIP_TF",+ "CHIP_HISTONE",+ "CAGE",+ "PROCAP",+ "POLYADENYLATION",+ "SPLICE_JUNCTIONS",+ "SPLICE_SITE_USAGE",+ "SPLICE_SITES",+ "CONTACT_MAPS",+)++#: ``f=SCORER_MODALITY:<display name>`` filter values used by the site.+MODALITY_FILTER_NAMES: dict[str, str] = {+ "RNA_SEQ": "RNA-seq",+ "DNASE": "DNase",+ "ATAC": "ATAC-seq",+ "CHIP_TF": "ChIP-TF",+ "CHIP_HISTONE": "ChIP-Histone",+ "CAGE": "CAGE",+ "PROCAP": "PRO-cap",+ "POLYADENYLATION": "Polyadenylation",+ "SPLICE_JUNCTIONS": "Splice junctions",+ "SPLICE_SITE_USAGE": "Splice site usage",+}++DEFAULT_MODALITIES: tuple[str, ...] = ("RNA_SEQ", "DNASE", "CHIP_TF")+++def parse_modalities(text: str | Sequence[str] | None) -> list[str]:+ if not text:+ return []+ items = text.split(",") if isinstance(text, str) else list(text)+ result = []+ for item in items:+ name = item.strip().upper()+ if not name:+ continue+ if name not in SECTION_MODALITIES:+ raise ValueError(f"unknown modality {item!r}; choose from {', '.join(SECTION_MODALITIES)}")+ result.append(name)+ return result+++def build_filter(+ biosample: str | None = None,+ modalities: Sequence[str] = (),+ tfs: Sequence[str] = (),+ histone_marks: Sequence[str] = (),+) -> str | None:+ """The ``f=`` predicate list.++ Biosample predicates AND together; assay predicates (modality, TF, histone+ mark) OR together. RNA-seq and DNase tracks carry no TF code, so a+ TF-only assay filter hides them; when TFs are given, RNA-seq and DNase+ are added so the expression and accessibility context stays visible.+ """+ parts: list[str] = []+ if biosample:+ parts.append(f"BIOSAMPLE_NAME:{biosample}")+ active = list(modalities)+ if tfs:+ for required in ("RNA_SEQ", "DNASE"):+ if required not in active:+ active.append(required)+ for modality in active:+ display = MODALITY_FILTER_NAMES.get(modality.upper())+ if display:+ parts.append(f"SCORER_MODALITY:{display}")+ for tf in tfs:+ parts.append(f"ASSAY_TRANSCRIPTOR_FACTOR:{tf}")+ for mark in histone_marks:+ parts.append(f"ASSAY_HISTONE_MARK:{mark}")+ return ",".join(parts) if parts else None+++def build_layout(include_avi: bool = True, modalities: Sequence[str] = ()) -> str:+ items = ["avi"] if include_avi else []+ items.extend(f"section:{modality.upper()}" for modality in modalities)+ return ",".join(items) if items else "avi"+++def build_url(+ mode: str,+ query: str,+ *,+ biosample: str | None = None,+ modalities: Sequence[str] = DEFAULT_MODALITIES,+ tfs: Sequence[str] = (),+ histone_marks: Sequence[str] = (),+ include_avi: bool = True,+ zoom: str | None = None,+) -> str:+ """Assemble a portal URL.++ ``mode`` is ``variant`` (``q`` = ``chr:pos:ref>alt``), ``locus`` (``q`` =+ 1-based closed ``chr:start-end``), ``gene`` (``q`` = symbol or Ensembl+ ID, portal mode ``entity``), or ``motifs`` (``q`` = interval, motif view).+ """+ if mode not in MODES:+ raise ValueError(f"mode must be one of {MODES}")+ if mode == "variant":+ spec = common.parse_variant_string(query)+ q = str(spec)+ portal_mode = "variant"+ elif mode in {"locus", "motifs"}:+ chromosome, start0, end = common.parse_interval_string(query)+ q = f"{chromosome}:{start0 + 1}-{end}"+ portal_mode = "locus" if mode == "locus" else "motifs"+ else:+ q = query.strip()+ if not q:+ raise ValueError("gene query is empty")+ portal_mode = "entity"++ params: dict[str, str] = {"q": q, "m": portal_mode, "lItems": build_layout(include_avi, modalities)}+ if zoom:+ chromosome, start0, end = common.parse_interval_string(zoom)+ params["i"] = f"{chromosome}:{start0 + 1}-{end}"+ filter_string = build_filter(biosample, modalities, tfs, histone_marks)+ if filter_string:+ params["f"] = filter_string+ return f"{common.ATLAS_BASE_URL}?" + urllib.parse.urlencode(params, quote_via=urllib.parse.quote, safe=":,-")+++def build_parser() -> argparse.ArgumentParser:+ parser = argparse.ArgumentParser(+ prog="atlas_link.py",+ description="Build AlphaGenome Atlas website deep links (no network, no key).",+ epilog=__doc__.split("Examples:", 1)[-1],+ formatter_class=argparse.RawDescriptionHelpFormatter,+ )+ parser.add_argument("mode", choices=MODES, help="what the query is")+ parser.add_argument("query", help="chr:pos:ref>alt, chr:start-end (1-based closed), or a gene symbol / Ensembl ID")+ parser.add_argument("--biosample", metavar="NAME", help="biosample name filter, e.g. K562 or 'heart left ventricle'")+ parser.add_argument("--modalities", default=",".join(DEFAULT_MODALITIES), metavar="A,B,C", help=f"layout sections (default {','.join(DEFAULT_MODALITIES)})")+ parser.add_argument("--tf", nargs="+", metavar="TF", default=(), help="ChIP-TF transcription factor filters")+ parser.add_argument("--histone-mark", nargs="+", metavar="MARK", default=(), help="ChIP-Histone mark filters, e.g. H3K27ac")+ parser.add_argument("--no-avi", action="store_true", help="omit the AVI track from the layout")+ parser.add_argument("--zoom", metavar="CHR:START-END", help="viewport interval (1-based closed); needed for motif rendering")+ parser.add_argument("--markdown", action="store_true", help="print a Markdown link instead of a bare URL")+ return parser+++def main(argv: Sequence[str] | None = None) -> int:+ args = build_parser().parse_args(argv)+ try:+ url = build_url(+ args.mode,+ args.query,+ biosample=args.biosample,+ modalities=parse_modalities(args.modalities),+ tfs=tuple(args.tf),+ histone_marks=tuple(args.histone_mark),+ include_avi=not args.no_avi,+ zoom=args.zoom,+ )+ except ValueError as error:+ print(f"error: {error}", file=sys.stderr)+ return 1+ if args.markdown:+ print(f"[{args.query} on AlphaGenome Atlas]({url})")+ else:+ print(url)+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/skills/alphagenome/scripts/atlas_query.py b/skills/alphagenome/scripts/atlas_query.pynew file mode 100644index 00000000..494f84a2--- /dev/null+++ b/skills/alphagenome/scripts/atlas_query.py@@ -0,0 +1,522 @@+#!/usr/bin/env python3+# /// script+# requires-python = ">=3.10"+# dependencies = ["alphagenome>=0.9.0"]+# ///+"""Query the AlphaGenome Atlas: precomputed variant effects for every hg38 SNV.++Four subcommands, all against the ``alphagenome.atlas`` gRPC client:++ avi AlphaGenome Variant Impact (AVI) score, Phred, and the 18 SHAP+ feature attributions for variants or for every SNV in a window.+ scores Raw and quantile scores from the track-level scorers (RNA_SEQ,+ DNASE, CHIP_TF, SPLICE_SITE_USAGE, ...) as one tidy row per+ variant x track (x gene, for gene-centric scorers).+ scorers The scorers the server currently serves, with track counts.+ tracks The track catalogue behind a scorer (biosample, ontology CURIE,+ assay, TF, histone mark) for choosing ontology filters.++Coordinates: variants are 1-based ``chr:pos:ref>alt``; ``--interval`` is a+1-based closed ``chr:start-end``. The Atlas is GRCh38 (hg38) only and the REF+allele must match the reference: a swapped REF/ALT is a lookup miss, not an+error. Reads the API key from ALPHAGENOME_API_KEY (or ALPHA_GENOME_API_KEY).++Examples:+ python atlas_query.py avi --variant chr22:36201698:A>C chr9:128225994:G>A+ python atlas_query.py avi --input candidates.vcf --min-phred 20 -o avi.tsv+ python atlas_query.py avi --interval chr11:5225727-5226575 --top-k 25+ python atlas_query.py scores --variant chr22:36201698:A>C \\+ --scorers RNA_SEQ SPLICE_SITE_USAGE --ontology UBERON:0001157 -o scores.tsv+ python atlas_query.py scorers+ python atlas_query.py tracks --scorer CHIP_TF --query GATA1+"""++from __future__ import annotations++import argparse+import concurrent.futures+import math+import sys+from collections.abc import Mapping, Sequence+from typing import Any++import _common as common++DEFAULT_MAX_WINDOW_BP = 1_000+DEFAULT_WORKERS = 8+TRACK_METADATA_COLUMNS = (+ "name",+ "strand",+ "ontology_curie",+ "biosample_name",+ "biosample_type",+ "Assay title",+ "assay_title",+ "gtex_tissue",+ "transcription_factor",+ "histone_mark",+ "data_source",+)+++# --------------------------------------------------------------------------+# pure conversion helpers (unit-tested with synthetic AnnData)+# --------------------------------------------------------------------------+++def _obs_variant_strings(adata) -> list[str]:+ if adata.obs is None or "variant" not in adata.obs.columns:+ return [str(index) for index in adata.obs_names]+ return [str(value) for value in adata.obs["variant"].tolist()]+++def _feature_names(adata) -> list[str]:+ if adata.var is not None and "name" in adata.var.columns:+ return [str(value) for value in adata.var["name"].tolist()]+ return [str(value) for value in adata.var_names]+++def _layer(adata, name: str):+ try:+ return adata.layers[name] if name in adata.layers else None+ except (KeyError, TypeError):+ return None+++def summarize_avi(avi_adata, fi_adata=None) -> list[dict[str, Any]]:+ """One row per variant from the ``AVI_SCORE`` and feature-importance AnnData.++ Columns: variant, avi_raw, avi_cdf_quantile, avi_tail_quantile, avi_phred,+ avi_top_percent, top_feature_key, top_feature, top_feature_value, and one+ ``fi_<KEY>`` column per attribution. Missing attributions leave NaN.+ """+ import numpy as np # noqa: PLC0415++ rows: list[dict[str, Any]] = []+ if avi_adata is None or avi_adata.X is None or avi_adata.X.shape[0] == 0:+ return rows++ variants = _obs_variant_strings(avi_adata)+ raw = np.asarray(avi_adata.X, dtype=float).reshape(len(variants), -1)+ quantiles = _layer(avi_adata, "quantiles")+ if quantiles is not None:+ quantiles = np.asarray(quantiles, dtype=float).reshape(len(variants), -1)++ fi_by_variant: dict[str, np.ndarray] = {}+ fi_names: list[str] = []+ if fi_adata is not None and fi_adata.X is not None and fi_adata.X.shape[0] > 0:+ fi_names = _feature_names(fi_adata)+ fi_matrix = np.asarray(fi_adata.X, dtype=float).reshape(fi_adata.X.shape[0], -1)+ for variant, values in zip(_obs_variant_strings(fi_adata), fi_matrix, strict=True):+ fi_by_variant[variant] = values++ for index, variant in enumerate(variants):+ row: dict[str, Any] = {"variant": variant}+ row["avi_raw"] = float(raw[index, 0]) if raw.shape[1] else float("nan")+ if quantiles is not None and quantiles.shape[1]:+ cdf = float(quantiles[index, 0])+ tail, phred = common.cdf_to_tail_and_phred(cdf)+ else:+ cdf, tail, phred = float("nan"), float("nan"), float("nan")+ row["avi_cdf_quantile"] = cdf+ row["avi_tail_quantile"] = tail+ row["avi_phred"] = phred+ row["avi_top_percent"] = common.phred_to_top_percent(phred)++ values = fi_by_variant.get(variant)+ if values is not None and len(fi_names) == len(values):+ top = int(np.argmax(np.abs(values)))+ row["top_feature_key"] = fi_names[top]+ row["top_feature"] = common.feature_display_name(fi_names[top])+ row["top_feature_value"] = float(values[top])+ for name, value in zip(fi_names, values, strict=True):+ row[f"fi_{name}"] = float(value)+ else:+ row["top_feature_key"] = ""+ row["top_feature"] = ""+ row["top_feature_value"] = float("nan")+ row["atlas_url"] = common.portal_variant_url(variant)+ rows.append(row)+ return rows+++def tidy_atlas_scores(scores: Mapping[str, Any]) -> list[dict[str, Any]]:+ """Flatten ``{scorer: AnnData}`` into one row per (obs row, track).++ ``obs`` rows are variants, or variant x gene for the gene-centric scorers+ (RNA_SEQ, POLYADENYLATION, SPLICE_*); ``var`` rows are tracks. Raw scores+ come from ``X`` and, when the server sent them, quantile scores from the+ ``quantiles`` layer.+ """+ import numpy as np # noqa: PLC0415++ rows: list[dict[str, Any]] = []+ for scorer, adata in scores.items():+ if adata is None or adata.X is None or 0 in adata.X.shape:+ continue+ matrix = np.asarray(adata.X, dtype=float)+ quantiles = _layer(adata, "quantiles")+ if quantiles is not None:+ quantiles = np.asarray(quantiles, dtype=float)+ obs = adata.obs if adata.obs is not None else None+ var = adata.var if adata.var is not None else None+ var_columns = [column for column in TRACK_METADATA_COLUMNS if var is not None and column in var.columns]+ obs_columns = [+ column+ for column in ("gene_id", "gene_name", "strand", "junction_Start", "junction_End")+ if obs is not None and column in obs.columns+ ]+ variants = _obs_variant_strings(adata)+ for i in range(matrix.shape[0]):+ base: dict[str, Any] = {"variant": variants[i], "scorer": scorer}+ for column in obs_columns:+ key = {"strand": "gene_strand", "junction_Start": "junction_start", "junction_End": "junction_end"}.get(+ column, column+ )+ base[key] = obs.iloc[i][column]+ for j in range(matrix.shape[1]):+ row = dict(base)+ row["track_index"] = j+ for column in var_columns:+ key = "assay_title" if column == "Assay title" else column+ row[f"track_{key}" if key in {"name", "strand"} else key] = var.iloc[j][column]+ row["raw_score"] = float(matrix[i, j])+ if quantiles is not None:+ row["quantile_score"] = float(quantiles[i, j])+ rows.append(row)+ return rows+++def max_abs_track(adata) -> dict[str, Any] | None:+ """The single largest |score| entry of a track-scorer AnnData, with its metadata."""+ import numpy as np # noqa: PLC0415++ if adata is None or adata.X is None or 0 in adata.X.shape:+ return None+ matrix = np.asarray(adata.X, dtype=float)+ flat = int(np.nanargmax(np.abs(matrix)))+ i, j = divmod(flat, matrix.shape[1])+ result: dict[str, Any] = {"raw_score": float(matrix[i, j]), "track_index": j}+ if adata.var is not None:+ for column in ("name", "biosample_name", "ontology_curie", "transcription_factor", "histone_mark"):+ if column in adata.var.columns:+ result[column] = adata.var.iloc[j][column]+ if adata.obs is not None:+ for column in ("gene_name", "gene_id"):+ if column in adata.obs.columns:+ result[column] = adata.obs.iloc[i][column]+ return result+++def scorer_rows(metadata: Mapping[str, Any]) -> list[dict[str, Any]]:+ rows = []+ for name, meta in metadata.items():+ frame = getattr(meta, "track_metadata", None)+ row: dict[str, Any] = {+ "scorer": name,+ "is_signed": bool(getattr(meta, "is_signed", False)),+ "n_tracks": int(len(frame)) if frame is not None else 0,+ }+ if frame is not None and "biosample_name" in frame.columns:+ row["n_biosamples"] = int(frame["biosample_name"].nunique())+ if frame is not None and "ontology_curie" in frame.columns:+ row["n_ontology_terms"] = int(frame["ontology_curie"].nunique())+ rows.append(row)+ return sorted(rows, key=lambda item: item["scorer"])+++def track_rows(metadata: Mapping[str, Any], scorer: str | None, query: str | None) -> list[dict[str, Any]]:+ rows: list[dict[str, Any]] = []+ needle = query.lower() if query else None+ for name, meta in metadata.items():+ if scorer and name != scorer:+ continue+ frame = getattr(meta, "track_metadata", None)+ if frame is None or frame.empty:+ continue+ for index, (_, record) in enumerate(frame.iterrows()):+ row: dict[str, Any] = {"scorer": name, "track_index": index}+ for column in TRACK_METADATA_COLUMNS:+ if column in frame.columns:+ key = "assay_title" if column == "Assay title" else column+ row[key] = record[column]+ if needle and not any(needle in str(value).lower() for value in row.values()):+ continue+ rows.append(row)+ return rows+++# --------------------------------------------------------------------------+# client plumbing+# --------------------------------------------------------------------------+++def make_client(args: argparse.Namespace):+ api_key = common.load_api_key(args.api_key_env)+ common.require_alphagenome()+ import grpc # noqa: PLC0415+ from alphagenome.atlas import atlas # noqa: PLC0415++ try:+ return atlas.create(api_key, timeout=args.timeout)+ except grpc.FutureTimeoutError as error: # pragma: no cover - network+ raise SystemExit(+ f"could not reach the Atlas service within {args.timeout}s "+ "(gdmscience.googleapis.com:443); check network access and proxies"+ ) from error+++def to_genome_variant(spec: common.VariantSpec):+ from alphagenome.data import genome # noqa: PLC0415++ return genome.Variant(+ chromosome=spec.chromosome,+ position=spec.position,+ reference_bases=spec.ref,+ alternate_bases=spec.alt,+ name=spec.name,+ )+++def to_genome_interval(text: str, max_window: int):+ from alphagenome.data import genome # noqa: PLC0415++ chromosome, start0, end = common.parse_interval_string(text)+ width = common.interval_width(start0, end)+ if width > max_window:+ raise SystemExit(+ f"interval is {width:,} bp, above --max-window {max_window:,} bp. Each base "+ f"expands to {common.SNVS_PER_BASE} variants; raise --max-window deliberately."+ )+ return genome.Interval(chromosome=chromosome, start=start0, end=end)+++def _query_each(+ client,+ specs: Sequence[common.VariantSpec],+ requested_scorers: Sequence[str],+ workers: int,+ **filters: Any,+) -> list[tuple[common.VariantSpec, Mapping[str, Any] | None, str]]:+ """Query variants one by one, keeping per-variant failures as messages."""++ def one(spec: common.VariantSpec):+ try:+ result = client.query_variant(to_genome_variant(spec), requested_scorers=list(requested_scorers), **filters)+ return spec, result, ""+ except Exception as error: # noqa: BLE001 - surfaced per variant+ return spec, None, f"{type(error).__name__}: {error}"++ if workers <= 1 or len(specs) <= 1:+ return [one(spec) for spec in specs]+ with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as pool:+ return list(pool.map(one, specs))+++# --------------------------------------------------------------------------+# subcommands+# --------------------------------------------------------------------------+++def cmd_avi(args: argparse.Namespace) -> int:+ client = make_client(args)+ rows: list[dict[str, Any]] = []++ if args.interval:+ interval = to_genome_interval(args.interval, args.max_window)+ scores = client.query_interval(interval, requested_scorers=list(common.AVI_SCORERS), progress_bar=False)+ rows = summarize_avi(scores.get(common.AVI_SCORER), scores.get(common.AVI_FEATURES_SCORER))+ for row in rows:+ row["error"] = ""+ else:+ specs, warnings = common.collect_variants(args.variant, args.input)+ for message in warnings:+ common.warn(message)+ if not specs:+ raise SystemExit("no variants given; use --variant, --input, or --interval")+ indels = [spec for spec in specs if not spec.is_snv]+ if indels:+ common.warn(+ f"{len(indels)} indel(s) requested; the public Atlas API currently serves "+ "genome-wide SNVs, so indels may come back as lookup misses"+ )+ for spec, scores, error in _query_each(client, specs, common.AVI_SCORERS, args.workers):+ if scores is None:+ row = spec.to_row()+ row.update({"avi_raw": float("nan"), "avi_phred": float("nan"), "error": error})+ rows.append(row)+ continue+ summary = summarize_avi(scores.get(common.AVI_SCORER), scores.get(common.AVI_FEATURES_SCORER))+ if not summary:+ row = spec.to_row()+ row.update({"avi_raw": float("nan"), "avi_phred": float("nan"), "error": "no AVI_SCORE returned"})+ rows.append(row)+ continue+ row = spec.to_row()+ row.update(summary[0])+ row["variant"] = str(spec)+ row["error"] = ""+ rows.append(row)++ if args.with_tracks:+ for row in rows:+ key = row.get("top_feature_key") or ""+ scorers = common.AVI_FEATURES.get(key, ("", "", ()))[2]+ if not scorers or row.get("error"):+ continue+ try:+ spec = common.parse_variant_string(row["variant"])+ detail = client.query_variant(to_genome_variant(spec), requested_scorers=list(scorers))+ except Exception as error: # noqa: BLE001+ row["top_track_error"] = f"{type(error).__name__}: {error}"+ continue+ best = None+ for scorer in scorers:+ hit = max_abs_track(detail.get(scorer))+ if hit and (best is None or abs(hit["raw_score"]) > abs(best[1]["raw_score"])):+ best = (scorer, hit)+ if best:+ scorer, hit = best+ row["top_track_scorer"] = scorer+ row["top_track_name"] = hit.get("name", "")+ row["top_track_biosample"] = hit.get("biosample_name", "")+ row["top_track_ontology"] = hit.get("ontology_curie", "")+ row["top_track_gene"] = hit.get("gene_name", "")+ row["top_track_raw_score"] = hit["raw_score"]++ if args.min_phred is not None:+ rows = [row for row in rows if row.get("error") or (isinstance(row.get("avi_phred"), float) and row["avi_phred"] >= args.min_phred)]++ rows.sort(key=lambda row: -(row.get("avi_phred") if isinstance(row.get("avi_phred"), float) and math.isfinite(row["avi_phred"]) else -1))+ if args.top_k:+ rows = rows[: args.top_k]++ if not args.output and len(rows) > 50 and not args.force_stdout:+ raise SystemExit(f"{len(rows)} rows; write them with -o FILE (or pass --force-stdout)")+ common.write_rows(rows, args.output, common.format_from_output(args.output, args.format))+ return 0+++def cmd_scores(args: argparse.Namespace) -> int:+ client = make_client(args)+ requested = list(args.scorers)+ filters = {+ "ontology_terms": args.ontology or None,+ "gene_names": args.gene or None,+ "gene_ids": args.gene_id or None,+ }+ rows: list[dict[str, Any]] = []+ if args.interval:+ interval = to_genome_interval(args.interval, args.max_window)+ scores = client.query_interval(interval, requested_scorers=requested, progress_bar=False, **filters)+ rows = tidy_atlas_scores(scores)+ else:+ specs, warnings = common.collect_variants(args.variant, args.input)+ for message in warnings:+ common.warn(message)+ if not specs:+ raise SystemExit("no variants given; use --variant, --input, or --interval")+ for spec, scores, error in _query_each(client, specs, requested, args.workers, **filters):+ if scores is None:+ common.warn(f"{spec}: {error}")+ rows.append({"variant": str(spec), "scorer": "", "error": error})+ continue+ rows.extend(tidy_atlas_scores(scores))++ if args.min_abs_quantile is not None:+ rows = [+ row+ for row in rows+ if "quantile_score" not in row or abs(row["quantile_score"] - 0.5) * 2 >= args.min_abs_quantile+ ]+ if not args.output and len(rows) > 200 and not args.force_stdout:+ raise SystemExit(f"{len(rows)} rows; write them with -o FILE (or pass --force-stdout)")+ common.write_rows(rows, args.output, common.format_from_output(args.output, args.format))+ return 0+++def cmd_scorers(args: argparse.Namespace) -> int:+ client = make_client(args)+ rows = scorer_rows(client.scorer_metadata())+ common.write_rows(rows, args.output, common.format_from_output(args.output, args.format))+ return 0+++def cmd_tracks(args: argparse.Namespace) -> int:+ client = make_client(args)+ rows = track_rows(client.scorer_metadata(), args.scorer, args.query)+ if not args.output and len(rows) > 200 and not args.force_stdout:+ raise SystemExit(+ f"{len(rows)} tracks match; narrow with --scorer/--query or write them with -o FILE"+ )+ common.write_rows(rows, args.output, common.format_from_output(args.output, args.format))+ return 0+++# --------------------------------------------------------------------------+# CLI+# --------------------------------------------------------------------------+++def _add_common(parser: argparse.ArgumentParser) -> None:+ parser.add_argument("-o", "--output", help="write here instead of stdout (extension picks the format)")+ parser.add_argument("--format", choices=("tsv", "csv", "json", "parquet"), help="override the output format")+ parser.add_argument("--api-key-env", metavar="NAME", help="environment variable holding the key (default: ALPHAGENOME_API_KEY, then ALPHA_GENOME_API_KEY)")+ parser.add_argument("--timeout", type=float, default=30.0, help="seconds to wait for the gRPC channel (default 30)")+ parser.add_argument("--force-stdout", action="store_true", help="print large tables to stdout anyway")+++def _add_variant_inputs(parser: argparse.ArgumentParser) -> None:+ parser.add_argument("--variant", nargs="+", metavar="CHR:POS:REF>ALT", help="one or more variants (1-based; gnomAD/GTEx spellings accepted)")+ parser.add_argument("--input", metavar="FILE", help="VCF, or TSV/CSV with CHROM/POS/REF/ALT or a 'variant' column")+ parser.add_argument("--interval", metavar="CHR:START-END", help="1-based closed window: every SNV in it (3 per base)")+ parser.add_argument("--max-window", type=int, default=DEFAULT_MAX_WINDOW_BP, help=f"refuse --interval wider than this (default {DEFAULT_MAX_WINDOW_BP} bp)")+ parser.add_argument("--workers", type=int, default=DEFAULT_WORKERS, help=f"parallel variant queries (default {DEFAULT_WORKERS})")+++def build_parser() -> argparse.ArgumentParser:+ parser = argparse.ArgumentParser(+ prog="atlas_query.py",+ description="Query the AlphaGenome Atlas (precomputed variant effects, hg38).",+ epilog=__doc__.split("Examples:", 1)[-1] if "Examples:" in __doc__ else None,+ formatter_class=argparse.RawDescriptionHelpFormatter,+ )+ sub = parser.add_subparsers(dest="command", required=True)++ avi = sub.add_parser("avi", help="AVI score, Phred, and feature attributions")+ _add_variant_inputs(avi)+ avi.add_argument("--min-phred", type=float, help="keep variants with AVI Phred >= this (20 = top 1%%)")+ avi.add_argument("--top-k", type=int, help="keep the K highest-Phred variants")+ avi.add_argument("--with-tracks", action="store_true", help="also report the strongest track behind the top feature (one extra query per variant)")+ _add_common(avi)+ avi.set_defaults(func=cmd_avi)++ scores = sub.add_parser("scores", help="raw + quantile scores from the track-level scorers")+ _add_variant_inputs(scores)+ scores.add_argument("--scorers", nargs="+", default=["RNA_SEQ"], metavar="NAME", help="Atlas scorer names (see `scorers`); default RNA_SEQ")+ scores.add_argument("--ontology", nargs="+", metavar="CURIE", help="keep tracks for these ontology terms, e.g. UBERON:0001157 CL:0000084")+ scores.add_argument("--gene", nargs="+", metavar="SYMBOL", help="gene-centric scorers: keep these gene symbols")+ scores.add_argument("--gene-id", nargs="+", metavar="ENSG", help="gene-centric scorers: keep these Ensembl gene IDs")+ scores.add_argument("--min-abs-quantile", type=float, help="keep rows whose quantile is at least this far from 0.5, rescaled to 0..1 (0.99 keeps the 0.5%% tails)")+ _add_common(scores)+ scores.set_defaults(func=cmd_scores)++ scorers = sub.add_parser("scorers", help="list the scorers the Atlas currently serves")+ _add_common(scorers)+ scorers.set_defaults(func=cmd_scorers)++ tracks = sub.add_parser("tracks", help="track catalogue (biosample, ontology CURIE, assay) per scorer")+ tracks.add_argument("--scorer", metavar="NAME", help="restrict to one scorer")+ tracks.add_argument("--query", metavar="TEXT", help="case-insensitive substring over every column")+ _add_common(tracks)+ tracks.set_defaults(func=cmd_tracks)+ return parser+++def main(argv: Sequence[str] | None = None) -> int:+ args = build_parser().parse_args(argv)+ return args.func(args)+++if __name__ == "__main__":+ sys.exit(main())diff --git a/skills/alphagenome/scripts/score_variants.py b/skills/alphagenome/scripts/score_variants.pynew file mode 100644index 00000000..0b595a23--- /dev/null+++ b/skills/alphagenome/scripts/score_variants.py@@ -0,0 +1,233 @@+#!/usr/bin/env python3+# /// script+# requires-python = ">=3.10"+# dependencies = ["alphagenome>=0.9.0"]+# ///+"""Score variants on demand with the AlphaGenome model API (human or mouse).++Use this when a variant is not in the Atlas (indels, mouse, non-reference+REF alleles, a haplotype background) or when you need a scorer configuration+the Atlas did not precompute. For hg38 SNVs, ``atlas_query.py`` is faster and+has a larger quota.++Each variant is scored inside a window centred on it (default 1 Mb, the+model's full context) with the recommended scorers, and the result is the+official tidy long table: one row per variant x scorer x track (x gene).++Examples:+ python score_variants.py --variant chr22:36201698:A>C -o scores.tsv+ python score_variants.py --input variants.vcf --scorers RNA_SEQ SPLICE_SITE_USAGE \\+ --ontology UBERON:0001157 --min-abs-quantile 0.99 -o colon.tsv+ python score_variants.py --organism mouse --variant chr7:45000000:A>G --sequence-length 500KB+ python score_variants.py --list-scorers+ python score_variants.py --list-tracks --output-type RNA_SEQ --query liver -o tracks.tsv+"""++from __future__ import annotations++import argparse+import sys+from collections.abc import Sequence+from typing import Any++import _common as common++#: Supported input windows. Longer context is better; 1 Mb is the default.+SEQUENCE_LENGTHS: dict[str, int] = {+ "16KB": 2**14,+ "100KB": 2**17,+ "500KB": 2**19,+ "1MB": 2**20,+}++ORGANISMS = ("human", "mouse")+MAX_SCORERS_PER_REQUEST = 20+++def parse_sequence_length(text: str) -> int:+ key = text.strip().upper().replace(" ", "")+ if key in SEQUENCE_LENGTHS:+ return SEQUENCE_LENGTHS[key]+ if key.isdigit() and int(key) in SEQUENCE_LENGTHS.values():+ return int(key)+ raise ValueError(f"sequence length must be one of {', '.join(SEQUENCE_LENGTHS)} (got {text!r})")+++def select_scorers(names: Sequence[str] | None, organism: str, include_active: bool = False) -> list[Any]:+ """Pick recommended scorer configurations by name, validated for the organism.++ With no names, every recommended scorer is used except the ``*_ACTIVE``+ variants (absolute activity of the allele, not the REF-ALT difference),+ which are only useful when explicitly asked for.+ """+ from alphagenome.models import dna_client, variant_scorers # noqa: PLC0415++ recommended = variant_scorers.RECOMMENDED_VARIANT_SCORERS+ organism_enum = dna_client.Organism.HOMO_SAPIENS if organism == "human" else dna_client.Organism.MUS_MUSCULUS+ if names:+ unknown = [name for name in names if name not in recommended]+ if unknown:+ raise ValueError(f"unknown scorer(s) {unknown}; choose from {sorted(recommended)}")+ chosen = list(dict.fromkeys(names))+ else:+ chosen = [name for name in recommended if include_active or not name.endswith("_ACTIVE")]+ selected = []+ for name in chosen:+ scorer = recommended[name]+ supported = variant_scorers.SUPPORTED_ORGANISMS[scorer.base_variant_scorer]+ if organism_enum.to_proto() not in supported:+ common.warn(f"scorer {name} is not available for {organism}; skipped")+ continue+ selected.append(scorer)+ if len(selected) > MAX_SCORERS_PER_REQUEST:+ raise ValueError(f"at most {MAX_SCORERS_PER_REQUEST} scorers per request; {len(selected)} selected")+ return selected+++def make_model(args: argparse.Namespace):+ api_key = common.load_api_key(args.api_key_env)+ common.require_alphagenome()+ import grpc # noqa: PLC0415+ from alphagenome.models import dna_client # noqa: PLC0415++ try:+ return dna_client.create(api_key, timeout=args.timeout)+ except grpc.FutureTimeoutError as error: # pragma: no cover - network+ raise SystemExit(+ f"could not reach the AlphaGenome service within {args.timeout}s "+ "(gdmscience.googleapis.com:443); check network access and proxies"+ ) from error+++def organism_enum(name: str):+ from alphagenome.models import dna_client # noqa: PLC0415++ return dna_client.Organism.HOMO_SAPIENS if name == "human" else dna_client.Organism.MUS_MUSCULUS+++def list_tracks(model, args: argparse.Namespace) -> int:+ metadata = model.output_metadata(organism_enum(args.organism)).concatenate()+ frame = metadata+ if args.output_type:+ wanted = {name.upper() for name in args.output_type}+ column = "output_type" if "output_type" in frame.columns else None+ if column:+ frame = frame[frame[column].astype(str).str.upper().str.replace("OUTPUTTYPE.", "", regex=False).isin(wanted)]+ if args.query:+ needle = args.query.lower()+ mask = frame.astype(str).apply(lambda column: column.str.lower().str.contains(needle, regex=False)).any(axis=1)+ frame = frame[mask]+ rows = frame.to_dict("records")+ if not args.output and len(rows) > 200 and not args.force_stdout:+ raise SystemExit(f"{len(rows)} tracks match; narrow with --output-type/--query or write them with -o FILE")+ common.write_rows(rows, args.output, common.format_from_output(args.output, args.format))+ return 0+++def list_scorers() -> int:+ from alphagenome.models import variant_scorers # noqa: PLC0415++ rows = []+ for name, scorer in variant_scorers.RECOMMENDED_VARIANT_SCORERS.items():+ row: dict[str, Any] = {"name": name, "scorer": type(scorer).__name__}+ for attribute in ("requested_output", "width", "aggregation_type"):+ value = getattr(scorer, attribute, None)+ if value is not None:+ row[attribute] = getattr(value, "name", value)+ rows.append(row)+ common.write_rows(rows, None, "tsv")+ return 0+++def score(model, args: argparse.Namespace) -> int:+ from alphagenome.models import variant_scorers # noqa: PLC0415++ specs, warnings = common.collect_variants(args.variant, args.input)+ for message in warnings:+ common.warn(message)+ if not specs:+ raise SystemExit("no variants given; use --variant and/or --input")++ length = parse_sequence_length(args.sequence_length)+ scorers = select_scorers(args.scorers, args.organism, include_active=args.include_active)+ if not scorers:+ raise SystemExit("no scorers left after organism filtering")++ from alphagenome.data import genome # noqa: PLC0415++ variants = [+ genome.Variant(spec.chromosome, spec.position, spec.ref, spec.alt, name=spec.name or str(spec)) for spec in specs+ ]+ intervals = [variant.reference_interval.resize(length) for variant in variants]+ results = model.score_variants(+ intervals,+ variants,+ scorers,+ organism=organism_enum(args.organism),+ progress_bar=False,+ max_workers=args.workers,+ )+ frame = variant_scorers.tidy_scores(results, match_gene_strand=True)+ if frame is None or frame.empty:+ raise SystemExit("the model returned no scores")++ if args.ontology and "ontology_curie" in frame.columns:+ frame = frame[frame["ontology_curie"].isin(set(args.ontology))]+ if args.biosample and "biosample_name" in frame.columns:+ frame = frame[frame["biosample_name"].astype(str).str.contains(args.biosample, case=False, regex=False)]+ if args.gene and "gene_name" in frame.columns:+ frame = frame[frame["gene_name"].isin(set(args.gene)) | frame["gene_name"].isna()]+ if args.min_abs_quantile is not None and "quantile_score" in frame.columns:+ frame = frame[frame["quantile_score"].abs() >= args.min_abs_quantile]++ frame = frame.sort_values("raw_score", key=lambda column: column.abs(), ascending=False)+ rows = frame.to_dict("records")+ if not args.output and len(rows) > 200 and not args.force_stdout:+ raise SystemExit(f"{len(rows)} rows; write them with -o FILE (or pass --force-stdout)")+ common.write_rows(rows, args.output, common.format_from_output(args.output, args.format))+ return 0+++def build_parser() -> argparse.ArgumentParser:+ parser = argparse.ArgumentParser(+ prog="score_variants.py",+ description="Score variants on demand with the AlphaGenome model (recommended scorers, tidy output).",+ epilog=__doc__.split("Examples:", 1)[-1],+ formatter_class=argparse.RawDescriptionHelpFormatter,+ )+ parser.add_argument("--variant", nargs="+", metavar="CHR:POS:REF>ALT", help="one or more variants (1-based)")+ parser.add_argument("--input", metavar="FILE", help="VCF, or TSV/CSV with CHROM/POS/REF/ALT or a 'variant' column")+ parser.add_argument("--scorers", nargs="+", metavar="NAME", help="recommended scorer names (default: all non-ACTIVE); see --list-scorers")+ parser.add_argument("--include-active", action="store_true", help="also run the *_ACTIVE scorers when --scorers is omitted")+ parser.add_argument("--sequence-length", default="1MB", help="16KB, 100KB, 500KB, or 1MB (default 1MB)")+ parser.add_argument("--organism", choices=ORGANISMS, default="human", help="human (hg38) or mouse (mm10)")+ parser.add_argument("--ontology", nargs="+", metavar="CURIE", help="keep tracks with these ontology CURIEs (post-hoc filter)")+ parser.add_argument("--biosample", metavar="TEXT", help="keep tracks whose biosample name contains this text")+ parser.add_argument("--gene", nargs="+", metavar="SYMBOL", help="keep gene-centric rows for these symbols")+ parser.add_argument("--min-abs-quantile", type=float, help="keep rows with |quantile_score| >= this (e.g. 0.99)")+ parser.add_argument("--workers", type=int, default=5, help="parallel requests (default 5)")+ parser.add_argument("--list-scorers", action="store_true", help="print the recommended scorer configurations and exit")+ parser.add_argument("--list-tracks", action="store_true", help="print the model's track metadata (ontology CURIEs, biosamples) and exit")+ parser.add_argument("--output-type", nargs="+", metavar="TYPE", help="with --list-tracks: restrict to output types, e.g. RNA_SEQ DNASE")+ parser.add_argument("--query", metavar="TEXT", help="with --list-tracks: case-insensitive substring filter")+ parser.add_argument("-o", "--output", help="write here instead of stdout (extension picks the format)")+ parser.add_argument("--format", choices=("tsv", "csv", "json", "parquet"), help="override the output format")+ parser.add_argument("--api-key-env", metavar="NAME", help="environment variable holding the key (default: ALPHAGENOME_API_KEY, then ALPHA_GENOME_API_KEY)")+ parser.add_argument("--timeout", type=float, default=30.0, help="seconds to wait for the gRPC channel (default 30)")+ parser.add_argument("--force-stdout", action="store_true", help="print large tables to stdout anyway")+ return parser+++def main(argv: Sequence[str] | None = None) -> int:+ args = build_parser().parse_args(argv)+ if args.list_scorers:+ common.require_alphagenome()+ return list_scorers()+ model = make_model(args)+ if args.list_tracks:+ return list_tracks(model, args)+ return score(model, args)+++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests/alphagenome/fixtures/variants.csv b/tests/alphagenome/fixtures/variants.csvnew file mode 100644index 00000000..0ff678b7--- /dev/null+++ b/tests/alphagenome/fixtures/variants.csv@@ -0,0 +1,4 @@+variant,note+chr22:36201698:A>C,first+22-36201698-A-G,gnomad spelling+rs12345,unsupporteddiff --git a/tests/alphagenome/fixtures/variants.tsv b/tests/alphagenome/fixtures/variants.tsvnew file mode 100644index 00000000..832af9ef--- /dev/null+++ b/tests/alphagenome/fixtures/variants.tsv@@ -0,0 +1,4 @@+variant_id CHROM POS REF ALT+rs_a chr22 36201698 A C+rs_b 9 128225994 G A+bad chr1 notanumber A Tdiff --git a/tests/alphagenome/fixtures/variants.vcf b/tests/alphagenome/fixtures/variants.vcfnew file mode 100644index 00000000..2dc21871--- /dev/null+++ b/tests/alphagenome/fixtures/variants.vcf@@ -0,0 +1,7 @@+##fileformat=VCFv4.2+##contig=<ID=chr22,length=50818468>+#CHROM POS ID REF ALT QUAL FILTER INFO+chr22 36201698 rs1 A C,G 50 PASS .+22 36201700 . AT A 50 PASS .+chr22 36201800 sv1 N <DEL> 50 PASS SVTYPE=DEL+MT 100 . G A 50 PASS .diff --git a/tests/alphagenome/test_scripts.py b/tests/alphagenome/test_scripts.pynew file mode 100644index 00000000..4f32b752--- /dev/null+++ b/tests/alphagenome/test_scripts.py@@ -0,0 +1,635 @@+"""Tests for the alphagenome skill scripts.++Nothing here touches the network. The parsing, coordinate, Phred, export, and+portal-link tests run in the bare project environment; the tests that build+AnnData objects or drive the CLIs against a fake Atlas client need the+``alphagenome`` package and skip cleanly without it. Run them for real with:++ python tests/run_all.py --isolated alphagenome+"""++from __future__ import annotations++import importlib.util+import io+import json+import os+import sys+import tempfile+import unittest+from contextlib import redirect_stderr, redirect_stdout+from pathlib import Path+from types import SimpleNamespace+from unittest import mock++import skill_contract++SKILL_ROOT = Path(__file__).resolve().parents[2] / "skills" / "alphagenome"+SCRIPTS_DIR = SKILL_ROOT / "scripts"+FIXTURES = Path(__file__).resolve().parent / "fixtures"++if str(SCRIPTS_DIR) not in sys.path:+ sys.path.insert(0, str(SCRIPTS_DIR))+++def _load_script(name: str):+ spec = importlib.util.spec_from_file_location(name, SCRIPTS_DIR / f"{name}.py")+ assert spec and spec.loader+ module = importlib.util.module_from_spec(spec)+ sys.modules[name] = module+ spec.loader.exec_module(module)+ return module+++common = _load_script("_common")+atlas_link = _load_script("atlas_link")+atlas_query = _load_script("atlas_query")+score_variants = _load_script("score_variants")++try: # the SDK-dependent half+ import anndata+ import numpy as np+ import pandas as pd+ from alphagenome.data import genome++ HAVE_SDK = True+except ImportError: # pragma: no cover - bare project environment+ HAVE_SDK = False+++def run_main(module, argv):+ out, err = io.StringIO(), io.StringIO()+ with redirect_stdout(out), redirect_stderr(err):+ code = module.main(argv)+ return code, out.getvalue(), err.getvalue()+++def rows_from_tsv(text):+ lines = [line for line in text.splitlines() if line]+ header = lines[0].split("\t")+ return [dict(zip(header, line.split("\t"))) for line in lines[1:]]+++# ---------------------------------------------------------------------------+# shared contract+# ---------------------------------------------------------------------------++CliHelpTests = skill_contract.cli.help_test_case(SKILL_ROOT)+++# ---------------------------------------------------------------------------+# _common: parsing and arithmetic (standard library only)+# ---------------------------------------------------------------------------+++class ChromosomeTests(unittest.TestCase):+ def test_chr_prefix_is_added_once(self):+ self.assertEqual(common.normalize_chromosome("22"), "chr22")+ self.assertEqual(common.normalize_chromosome("chr22"), "chr22")+ self.assertEqual(common.normalize_chromosome("CHRX"), "chrX")++ def test_mitochondrion_spellings_collapse(self):+ for spelling in ("MT", "M", "chrM", "chrMT"):+ self.assertEqual(common.normalize_chromosome(spelling), "chrM")++ def test_empty_is_rejected(self):+ with self.assertRaises(ValueError):+ common.normalize_chromosome(" ")+++class VariantParsingTests(unittest.TestCase):+ def test_default_gnomad_gtex_and_open_targets_spellings_agree(self):+ expected = common.VariantSpec("chr22", 36201698, "A", "C")+ for text in (+ "chr22:36201698:A>C",+ "22:36201698:A>C",+ "22-36201698-A-C",+ "chr22_36201698_A_C_b38",+ "22_36201698_A_C",+ "22:36201698:A:C",+ ):+ with self.subTest(text=text):+ self.assertEqual(common.parse_variant_string(text), expected)++ def test_bases_are_uppercased_and_indels_kept(self):+ spec = common.parse_variant_string("chr1:100:at>a")+ self.assertEqual((spec.ref, spec.alt), ("AT", "A"))+ self.assertFalse(spec.is_snv)+ self.assertTrue(common.parse_variant_string("chr1:100:A>T").is_snv)++ def test_rsid_and_garbage_are_rejected_with_guidance(self):+ for text in ("rs12345", "chr1:100", "chr1:100:A", "chr1:100:A>Z", "chr1:x:A>T"):+ with self.subTest(text=text), self.assertRaises(ValueError) as caught:+ common.parse_variant_string(text)+ self.assertIn("1-based", str(caught.exception))++ def test_string_form_round_trips(self):+ spec = common.parse_variant_string("22-36201698-A-C")+ self.assertEqual(str(spec), "chr22:36201698:A>C")+ self.assertEqual(spec.to_row()["position"], 36201698)+++class IntervalParsingTests(unittest.TestCase):+ def test_one_based_closed_becomes_zero_based_half_open(self):+ self.assertEqual(common.parse_interval_string("chr11:5225727-5226575"), ("chr11", 5225726, 5226575))+ self.assertEqual(common.interval_width(5225726, 5226575), 849)++ def test_thousands_separators_and_missing_prefix(self):+ self.assertEqual(common.parse_interval_string("11:5,225,727-5,226,575"), ("chr11", 5225726, 5226575))++ def test_single_base_window_has_width_one(self):+ chrom, start, end = common.parse_interval_string("chr1:100-100")+ self.assertEqual(end - start, 1)++ def test_invalid_intervals_are_rejected(self):+ for text in ("chr1:0-10", "chr1:20-10", "chr1:10", "chr1-10-20"):+ with self.subTest(text=text), self.assertRaises(ValueError):+ common.parse_interval_string(text)+++class VariantFileTests(unittest.TestCase):+ def test_tsv_with_vcf_style_columns(self):+ variants, warnings = common.read_variant_table(FIXTURES / "variants.tsv")+ self.assertEqual([str(v) for v in variants], ["chr22:36201698:A>C", "chr9:128225994:G>A"])+ self.assertEqual(variants[0].name, "rs_a")+ self.assertEqual(len(warnings), 1)+ self.assertIn("line 4", warnings[0])++ def test_csv_with_variant_column_reports_unparseable_rows(self):+ variants, warnings = common.read_variant_table(FIXTURES / "variants.csv")+ self.assertEqual([str(v) for v in variants], ["chr22:36201698:A>C", "chr22:36201698:A>G"])+ self.assertEqual(len(warnings), 1)+ self.assertIn("rs12345", warnings[0])++ def test_vcf_splits_multiallelic_and_skips_symbolic(self):+ variants, warnings = common.read_variant_table(FIXTURES / "variants.vcf")+ self.assertEqual(+ [str(v) for v in variants],+ ["chr22:36201698:A>C", "chr22:36201698:A>G", "chr22:36201700:AT>A", "chrM:100:G>A"],+ )+ self.assertEqual(variants[0].name, "rs1")+ self.assertEqual(variants[2].name, "")+ self.assertTrue(any("<DEL>" in message for message in warnings))++ def test_missing_columns_are_an_error(self):+ with tempfile.TemporaryDirectory() as tmp:+ path = Path(tmp) / "odd.tsv"+ path.write_text("gene\tscore\nHBB\t1\n", encoding="utf-8")+ with self.assertRaises(ValueError) as caught:+ common.read_variant_table(path)+ self.assertIn("CHROM/POS/REF/ALT", str(caught.exception))++ def test_missing_file_is_an_error(self):+ with self.assertRaises(FileNotFoundError):+ common.read_variant_table(FIXTURES / "nope.tsv")++ def test_collect_variants_merges_flags_and_file(self):+ variants, warnings = common.collect_variants(["chr1:100:A>T"], str(FIXTURES / "variants.tsv"))+ self.assertEqual(len(variants), 3)+ self.assertEqual(str(variants[0]), "chr1:100:A>T")+ self.assertEqual(len(warnings), 1)+++class ScoreArithmeticTests(unittest.TestCase):+ def test_phred_scale_matches_the_report(self):+ for cdf, phred in ((0.9, 10.0), (0.99, 20.0), (0.999, 30.0)):+ tail, value = common.cdf_to_tail_and_phred(cdf)+ self.assertAlmostEqual(tail, 1 - cdf, places=9)+ self.assertAlmostEqual(value, phred, places=6)++ def test_saturated_quantile_is_floored_not_infinite(self):+ tail, phred = common.cdf_to_tail_and_phred(1.0)+ self.assertEqual(tail, 1e-7)+ self.assertAlmostEqual(phred, 70.0)++ def test_nan_propagates(self):+ tail, phred = common.cdf_to_tail_and_phred(float("nan"))+ self.assertTrue(tail != tail and phred != phred)++ def test_top_percent(self):+ self.assertAlmostEqual(common.phred_to_top_percent(20.0), 1.0)+ self.assertAlmostEqual(common.phred_to_top_percent(30.0), 0.1)++ def test_feature_display_names_cover_all_eighteen(self):+ self.assertEqual(len(common.AVI_FEATURES), 18)+ self.assertEqual(common.feature_display_name("MERGED_SPLICING"), "Splicing")+ self.assertEqual(common.feature_display_name("UNKNOWN_KEY"), "UNKNOWN_KEY")+ splicing_scorers = common.AVI_FEATURES["MERGED_SPLICING"][2]+ self.assertEqual(set(splicing_scorers), {"SPLICE_SITES", "SPLICE_SITE_USAGE", "SPLICE_JUNCTIONS"})+++class ExportTests(unittest.TestCase):+ ROWS = [{"variant": "chr1:1:A>T", "score": 1.23456789, "note": None}, {"variant": "chr1:2:A>T", "score": float("nan")}]++ def test_tsv_to_stdout_orders_columns_by_first_appearance(self):+ out = io.StringIO()+ with redirect_stdout(out):+ common.write_rows(self.ROWS, None, "tsv")+ rows = rows_from_tsv(out.getvalue())+ self.assertEqual(list(rows[0]), ["variant", "score", "note"])+ self.assertEqual(rows[0]["score"], "1.23457")+ self.assertEqual(rows[1]["score"], "")++ def test_json_to_file(self):+ with tempfile.TemporaryDirectory() as tmp:+ path = Path(tmp) / "out.json"+ common.write_rows(self.ROWS, str(path), "json")+ data = json.loads(path.read_text(encoding="utf-8"))+ self.assertEqual(data[0]["variant"], "chr1:1:A>T")+ self.assertIsNone(data[0]["note"])++ def test_format_follows_extension_then_flag(self):+ self.assertEqual(common.format_from_output("x.csv", None), "csv")+ self.assertEqual(common.format_from_output("x.parquet", None), "parquet")+ self.assertEqual(common.format_from_output("x.txt", None), "tsv")+ self.assertEqual(common.format_from_output("x.csv", "json"), "json")+ self.assertEqual(common.format_from_output(None, None), "tsv")++ def test_unknown_format_and_parquet_without_path_are_rejected(self):+ with self.assertRaises(ValueError):+ common.write_rows(self.ROWS, None, "xlsx")+ with self.assertRaises(ValueError):+ common.write_rows(self.ROWS, None, "parquet")+++class ApiKeyTests(unittest.TestCase):+ def test_primary_then_fallback_spelling(self):+ with mock.patch.dict(os.environ, {"ALPHAGENOME_API_KEY": "primary", "ALPHA_GENOME_API_KEY": "fallback"}):+ self.assertEqual(common.load_api_key(), "primary")+ with mock.patch.dict(os.environ, {"ALPHA_GENOME_API_KEY": "fallback"}, clear=True):+ self.assertEqual(common.load_api_key(), "fallback")++ def test_explicit_variable_name(self):+ with mock.patch.dict(os.environ, {"MY_KEY": "abc"}, clear=True):+ self.assertEqual(common.load_api_key("MY_KEY"), "abc")++ def test_missing_key_exits_with_signup_url(self):+ with mock.patch.dict(os.environ, {}, clear=True), self.assertRaises(SystemExit) as caught:+ common.load_api_key()+ self.assertIn("deepmind.google.com/science/alphagenome", str(caught.exception))++ def test_portal_url_encodes_the_allele_separator(self):+ url = common.portal_variant_url("chr22:36201698:A>C")+ self.assertTrue(url.startswith(common.ATLAS_BASE_URL))+ self.assertIn("q=chr22:36201698:A%3EC", url)+ self.assertIn("m=variant", url)+++# ---------------------------------------------------------------------------+# atlas_link.py (standard library only)+# ---------------------------------------------------------------------------+++class AtlasLinkTests(unittest.TestCase):+ def test_variant_link_normalises_and_encodes(self):+ url = atlas_link.build_url("variant", "22-36201698-A-C")+ self.assertIn("q=chr22:36201698:A%3EC", url)+ self.assertIn("m=variant", url)+ self.assertIn("lItems=avi,section:RNA_SEQ,section:DNASE,section:CHIP_TF", url)++ def test_locus_link_keeps_one_based_closed_coordinates(self):+ url = atlas_link.build_url("locus", "11:5,225,727-5,226,575", modalities=("RNA_SEQ",))+ self.assertIn("q=chr11:5225727-5226575", url)+ self.assertIn("m=locus", url)+ self.assertIn("f=SCORER_MODALITY:RNA-seq", url)++ def test_gene_uses_entity_mode_and_motifs_take_zoom(self):+ self.assertIn("q=HBB&m=entity", atlas_link.build_url("gene", "HBB"))+ url = atlas_link.build_url("motifs", "chr11:5225727-5226575", zoom="chr11:5225800-5226000", include_avi=False)+ self.assertIn("m=motifs", url)+ self.assertIn("i=chr11:5225800-5226000", url)+ self.assertNotIn("avi", url.split("lItems=")[1].split("&")[0])++ def test_tf_filter_pulls_in_rna_seq_and_dnase(self):+ filter_string = atlas_link.build_filter(biosample="K562", modalities=("CHIP_TF",), tfs=("GATA1",))+ self.assertEqual(+ filter_string,+ "BIOSAMPLE_NAME:K562,SCORER_MODALITY:ChIP-TF,SCORER_MODALITY:RNA-seq,SCORER_MODALITY:DNase,ASSAY_TRANSCRIPTOR_FACTOR:GATA1",+ )+ self.assertIsNone(atlas_link.build_filter())++ def test_modalities_are_validated(self):+ self.assertEqual(atlas_link.parse_modalities("rna_seq, dnase"), ["RNA_SEQ", "DNASE"])+ with self.assertRaises(ValueError):+ atlas_link.parse_modalities("RNA_SEQ,WHATEVER")+ with self.assertRaises(ValueError):+ atlas_link.build_url("nonsense", "HBB")++ def test_cli_prints_url_or_markdown_and_rejects_rsids(self):+ code, out, _ = run_main(atlas_link, ["variant", "chr9:128225994:G>A", "--biosample", "K562", "--tf", "GATA1"])+ self.assertEqual(code, 0)+ self.assertIn("BIOSAMPLE_NAME:K562", out)+ code, out, _ = run_main(atlas_link, ["gene", "HBB", "--markdown"])+ self.assertEqual(code, 0)+ self.assertTrue(out.startswith("[HBB on AlphaGenome Atlas](https://"))+ code, _, err = run_main(atlas_link, ["variant", "rs12345"])+ self.assertEqual(code, 1)+ self.assertIn("rsIDs are not supported", err)+++# ---------------------------------------------------------------------------+# score_variants.py helpers+# ---------------------------------------------------------------------------+++class SequenceLengthTests(unittest.TestCase):+ def test_names_and_integers(self):+ self.assertEqual(score_variants.parse_sequence_length("1MB"), 2**20)+ self.assertEqual(score_variants.parse_sequence_length("16kb"), 2**14)+ self.assertEqual(score_variants.parse_sequence_length("524288"), 2**19)+ with self.assertRaises(ValueError):+ score_variants.parse_sequence_length("2KB")++ @unittest.skipUnless(HAVE_SDK, "alphagenome not installed")+ def test_lengths_match_the_sdk_constants(self):+ from alphagenome.models import dna_client++ self.assertEqual(+ set(score_variants.SEQUENCE_LENGTHS.values()), set(dna_client.SUPPORTED_SEQUENCE_LENGTHS.values())+ )++[email protected](HAVE_SDK, "alphagenome not installed")+class ScorerSelectionTests(unittest.TestCase):+ def test_default_excludes_active_scorers(self):+ chosen = score_variants.select_scorers(None, "human")+ self.assertEqual(len(chosen), 12)+ self.assertTrue(all("ACTIVE" not in type(s).__name__.upper() or "GeneMaskActive" not in type(s).__name__ for s in chosen))+ self.assertEqual(len(score_variants.select_scorers(None, "human", include_active=True)), 19)++ def test_mouse_drops_polyadenylation(self):+ err = io.StringIO()+ with redirect_stderr(err):+ chosen = score_variants.select_scorers(None, "mouse")+ self.assertEqual(len(chosen), 11)+ self.assertIn("POLYADENYLATION", err.getvalue())++ def test_named_selection_and_unknown_names(self):+ chosen = score_variants.select_scorers(["RNA_SEQ", "SPLICE_SITE_USAGE", "RNA_SEQ"], "human")+ self.assertEqual([type(s).__name__ for s in chosen], ["GeneMaskLFCScorer", "GeneMaskSplicingScorer"])+ with self.assertRaises(ValueError) as caught:+ score_variants.select_scorers(["NOT_A_SCORER"], "human")+ self.assertIn("NOT_A_SCORER", str(caught.exception))++ def test_list_scorers_needs_no_network(self):+ code, out, _ = run_main(score_variants, ["--list-scorers"])+ self.assertEqual(code, 0)+ rows = rows_from_tsv(out)+ self.assertEqual(len(rows), 19)+ self.assertIn("RNA_SEQ", {row["name"] for row in rows})+++# ---------------------------------------------------------------------------+# atlas_query.py against a fake Atlas client+# ---------------------------------------------------------------------------++if HAVE_SDK:+ FEATURE_KEYS = list(common.AVI_FEATURES)++ def _variant(text):+ return genome.Variant.from_str(text)++ def _avi_adata(variants, raws, cdfs):+ return anndata.AnnData(+ X=np.asarray(raws, dtype=np.float32).reshape(-1, 1),+ obs=pd.DataFrame({"variant": variants}, index=[str(i) for i in range(len(variants))]),+ var=pd.DataFrame({"name": ["AVI_SCORE"]}, index=["0"]),+ layers={"quantiles": np.asarray(cdfs, dtype=np.float32).reshape(-1, 1)},+ )++ def _fi_adata(variants, top_index):+ matrix = np.full((len(variants), 18), 0.01, dtype=np.float32)+ matrix[:, top_index] = 0.9+ return anndata.AnnData(+ X=matrix,+ obs=pd.DataFrame({"variant": variants}, index=[str(i) for i in range(len(variants))]),+ var=pd.DataFrame({"name": FEATURE_KEYS}, index=[str(i) for i in range(18)]),+ )++ TRACKS = pd.DataFrame(+ {+ "name": ["UBERON:0001114 polyA plus RNA-seq", "UBERON:0001157 polyA plus RNA-seq", "CL:0000084 total RNA-seq"],+ "strand": [".", ".", "."],+ "ontology_curie": ["UBERON:0001114", "UBERON:0001157", "CL:0000084"],+ "biosample_name": ["right lobe of liver", "transverse colon", "T cell"],+ "biosample_type": ["tissue", "tissue", "primary_cell"],+ },+ index=["0", "1", "2"],+ )++ def _rna_adata(variant):+ return anndata.AnnData(+ X=np.array([[0.05, -1.4, 0.2], [0.0, 0.3, -0.6]], dtype=np.float32),+ obs=pd.DataFrame(+ {"gene_id": ["ENSG0001", "ENSG0002"], "gene_name": ["HBB", "HBD"], "strand": ["-", "-"], "variant": [variant, variant]},+ index=["0", "1"],+ ),+ var=TRACKS.copy(),+ layers={"quantiles": np.array([[0.55, 0.002, 0.7], [0.5, 0.8, 0.03]], dtype=np.float32)},+ )++ class FakeAtlasClient:+ """Serves canned AnnData shaped like the live Atlas responses."""++ def __init__(self):+ self.calls = []++ def query_variant(self, variant, requested_scorers, **filters):+ self.calls.append(("variant", str(variant), tuple(requested_scorers), filters))+ if variant.position == 999:+ raise ValueError("variant not found in Atlas")+ out = {}+ if common.AVI_SCORER in requested_scorers:+ out[common.AVI_SCORER] = _avi_adata([variant], [2.5], [0.995])+ if common.AVI_FEATURES_SCORER in requested_scorers:+ out[common.AVI_FEATURES_SCORER] = _fi_adata([variant], FEATURE_KEYS.index("MAX_ABS_RNA_SEQ"))+ if "RNA_SEQ" in requested_scorers:+ out["RNA_SEQ"] = _rna_adata(variant)+ return out++ def query_interval(self, interval, requested_scorers, progress_bar=True, **filters):+ self.calls.append(("interval", str(interval), tuple(requested_scorers), filters))+ variants, raws, cdfs = [], [], []+ for offset in range(interval.width):+ for alt in "CGT":+ variants.append(genome.Variant(interval.chromosome, interval.start + offset + 1, "A", alt))+ raws.append(float(offset))+ cdfs.append(0.5 + 0.49 * offset / max(1, interval.width - 1))+ out = {}+ if common.AVI_SCORER in requested_scorers:+ out[common.AVI_SCORER] = _avi_adata(variants, raws, cdfs)+ if common.AVI_FEATURES_SCORER in requested_scorers:+ out[common.AVI_FEATURES_SCORER] = _fi_adata(variants, FEATURE_KEYS.index("MERGED_SPLICING"))+ if "RNA_SEQ" in requested_scorers:+ out["RNA_SEQ"] = _rna_adata(variants[0])+ return out++ def scorer_metadata(self):+ return {+ "RNA_SEQ": SimpleNamespace(name="RNA_SEQ", is_signed=True, track_metadata=TRACKS.copy()),+ "AVI_SCORE": SimpleNamespace(name="AVI_SCORE", is_signed=False, track_metadata=pd.DataFrame()),+ }++[email protected](HAVE_SDK, "alphagenome not installed")+class AtlasConversionTests(unittest.TestCase):+ def test_summarize_avi_computes_phred_and_top_feature(self):+ variant = _variant("chr22:36201698:A>C")+ rows = atlas_query.summarize_avi(_avi_adata([variant], [2.5], [0.99]), _fi_adata([variant], FEATURE_KEYS.index("ALPHAMISSENSE")))+ self.assertEqual(len(rows), 1)+ row = rows[0]+ self.assertEqual(row["variant"], "chr22:36201698:A>C")+ self.assertAlmostEqual(row["avi_raw"], 2.5, places=5)+ self.assertAlmostEqual(row["avi_phred"], 20.0, places=3)+ self.assertAlmostEqual(row["avi_top_percent"], 1.0, places=3)+ self.assertEqual(row["top_feature_key"], "ALPHAMISSENSE")+ self.assertEqual(row["top_feature"], "AlphaMissense")+ self.assertEqual(len([key for key in row if key.startswith("fi_")]), 18)+ self.assertIn("A%3EC", row["atlas_url"])++ def test_summarize_avi_without_attributions_or_quantiles(self):+ variant = _variant("chr1:5:A>T")+ adata = _avi_adata([variant], [0.1], [0.5])+ del adata.layers["quantiles"]+ rows = atlas_query.summarize_avi(adata, None)+ self.assertEqual(rows[0]["top_feature_key"], "")+ self.assertTrue(rows[0]["avi_phred"] != rows[0]["avi_phred"]) # NaN+ self.assertEqual(atlas_query.summarize_avi(None, None), [])++ def test_tidy_atlas_scores_is_one_row_per_gene_track(self):+ rows = atlas_query.tidy_atlas_scores({"RNA_SEQ": _rna_adata(_variant("chr11:5227002:T>A"))})+ self.assertEqual(len(rows), 6)+ strongest = min(rows, key=lambda row: row["raw_score"])+ self.assertEqual(strongest["gene_name"], "HBB")+ self.assertEqual(strongest["biosample_name"], "transverse colon")+ self.assertEqual(strongest["ontology_curie"], "UBERON:0001157")+ self.assertAlmostEqual(strongest["quantile_score"], 0.002, places=5)+ self.assertEqual(strongest["gene_strand"], "-")+ self.assertEqual(rows[0]["track_index"], 0)++ def test_max_abs_track_and_metadata_rows(self):+ hit = atlas_query.max_abs_track(_rna_adata(_variant("chr11:5227002:T>A")))+ self.assertAlmostEqual(hit["raw_score"], -1.4, places=5)+ self.assertEqual(hit["gene_name"], "HBB")+ metadata = FakeAtlasClient().scorer_metadata()+ scorers = atlas_query.scorer_rows(metadata)+ self.assertEqual([row["scorer"] for row in scorers], ["AVI_SCORE", "RNA_SEQ"])+ self.assertEqual(scorers[1]["n_tracks"], 3)+ self.assertEqual(scorers[1]["n_biosamples"], 3)+ tracks = atlas_query.track_rows(metadata, "RNA_SEQ", "colon")+ self.assertEqual(len(tracks), 1)+ self.assertEqual(tracks[0]["ontology_curie"], "UBERON:0001157")+ self.assertEqual(len(atlas_query.track_rows(metadata, None, None)), 3)++[email protected](HAVE_SDK, "alphagenome not installed")+class AtlasQueryCliTests(unittest.TestCase):+ def setUp(self):+ self.client = FakeAtlasClient()+ patcher = mock.patch.object(atlas_query, "make_client", return_value=self.client)+ patcher.start()+ self.addCleanup(patcher.stop)+ self.tmp = tempfile.TemporaryDirectory()+ self.addCleanup(self.tmp.cleanup)++ def test_avi_for_variants_writes_one_row_each_and_keeps_failures(self):+ out_path = Path(self.tmp.name) / "avi.tsv"+ code, _, err = run_main(+ atlas_query,+ ["avi", "--variant", "chr22:36201698:A>C", "chr1:999:A>T", "--workers", "1", "-o", str(out_path)],+ )+ self.assertEqual(code, 0)+ rows = rows_from_tsv(out_path.read_text(encoding="utf-8"))+ self.assertEqual(len(rows), 2)+ good = next(row for row in rows if row["variant"] == "chr22:36201698:A>C")+ self.assertAlmostEqual(float(good["avi_phred"]), 23.0103, places=3)+ self.assertEqual(good["top_feature_key"], "MAX_ABS_RNA_SEQ")+ self.assertEqual(good["error"], "")+ bad = next(row for row in rows if row["variant"] == "chr1:999:A>T")+ self.assertIn("not found", bad["error"])+ self.assertEqual(bad["avi_phred"], "")+ self.assertEqual(self.client.calls[0][2], common.AVI_SCORERS)++ def test_avi_from_vcf_warns_about_indels_and_filters_by_phred(self):+ out_path = Path(self.tmp.name) / "avi.json"+ code, _, err = run_main(+ atlas_query,+ ["avi", "--input", str(FIXTURES / "variants.vcf"), "--min-phred", "20", "--workers", "1", "-o", str(out_path)],+ )+ self.assertEqual(code, 0)+ self.assertIn("indel", err)+ rows = json.loads(out_path.read_text(encoding="utf-8"))+ self.assertEqual(len(rows), 4)+ self.assertTrue(all(row["avi_phred"] >= 20 for row in rows))++ def test_avi_with_tracks_adds_the_strongest_track(self):+ code, out, _ = run_main(atlas_query, ["avi", "--variant", "chr22:36201698:A>C", "--with-tracks", "--format", "json"])+ self.assertEqual(code, 0)+ row = json.loads(out)[0]+ self.assertEqual(row["top_track_scorer"], "RNA_SEQ")+ self.assertEqual(row["top_track_biosample"], "transverse colon")+ self.assertEqual(row["top_track_gene"], "HBB")+ self.assertEqual(self.client.calls[1][2], ("RNA_SEQ",))++ def test_avi_interval_scans_three_variants_per_base_and_sorts(self):+ out_path = Path(self.tmp.name) / "window.tsv"+ code, _, _ = run_main(atlas_query, ["avi", "--interval", "chr11:5225727-5225736", "--top-k", "5", "-o", str(out_path)])+ self.assertEqual(code, 0)+ rows = rows_from_tsv(out_path.read_text(encoding="utf-8"))+ self.assertEqual(len(rows), 5)+ phreds = [float(row["avi_phred"]) for row in rows]+ self.assertEqual(phreds, sorted(phreds, reverse=True))+ self.assertEqual(self.client.calls[0][1], "chr11:5225726-5225736:.")++ def test_avi_interval_refuses_wide_windows_and_large_stdout(self):+ with self.assertRaises(SystemExit) as caught:+ run_main(atlas_query, ["avi", "--interval", "chr11:1-5000"])+ self.assertIn("--max-window", str(caught.exception))+ with self.assertRaises(SystemExit) as caught:+ run_main(atlas_query, ["avi", "--interval", "chr11:1-40"])+ self.assertIn("-o FILE", str(caught.exception))+ code, out, _ = run_main(atlas_query, ["avi", "--interval", "chr11:1-40", "--force-stdout"])+ self.assertEqual(code, 0)+ self.assertEqual(len(rows_from_tsv(out)), 120)++ def test_avi_without_inputs_exits(self):+ with self.assertRaises(SystemExit):+ run_main(atlas_query, ["avi"])++ def test_scores_forwards_filters_and_flattens(self):+ out_path = Path(self.tmp.name) / "scores.csv"+ code, _, _ = run_main(+ atlas_query,+ [+ "scores", "--variant", "chr11:5227002:T>A", "--scorers", "RNA_SEQ",+ "--ontology", "UBERON:0001157", "--gene", "HBB", "--workers", "1", "-o", str(out_path),+ ],+ )+ self.assertEqual(code, 0)+ filters = self.client.calls[0][3]+ self.assertEqual(filters["ontology_terms"], ["UBERON:0001157"])+ self.assertEqual(filters["gene_names"], ["HBB"])+ text = out_path.read_text(encoding="utf-8")+ self.assertEqual(len(text.strip().splitlines()), 7) # header + 2 genes x 3 tracks+ self.assertIn("quantile_score", text.splitlines()[0])++ def test_scores_min_abs_quantile_keeps_tails(self):+ code, out, _ = run_main(+ atlas_query,+ ["scores", "--variant", "chr11:5227002:T>A", "--scorers", "RNA_SEQ", "--min-abs-quantile", "0.9", "--workers", "1"],+ )+ self.assertEqual(code, 0)+ rows = rows_from_tsv(out)+ self.assertEqual({row["quantile_score"] for row in rows}, {"0.002", "0.03"})++ def test_scorers_and_tracks_subcommands(self):+ code, out, _ = run_main(atlas_query, ["scorers"])+ self.assertEqual(code, 0)+ self.assertEqual([row["scorer"] for row in rows_from_tsv(out)], ["AVI_SCORE", "RNA_SEQ"])+ code, out, _ = run_main(atlas_query, ["tracks", "--query", "t cell", "--format", "json"])+ self.assertEqual(code, 0)+ self.assertEqual(json.loads(out)[0]["ontology_curie"], "CL:0000084")+++if __name__ == "__main__":+ unittest.main()diff --git a/tests/skill-requirements.toml b/tests/skill-requirements.tomlindex 06258ae7..ccf01b82 100644--- a/tests/skill-requirements.toml+++ b/tests/skill-requirements.toml@@ -514,6 +514,9 @@ packages = ["dnaerys"][skills.genomic-intelligence]packages = ["requests"]+[skills.alphagenome]+packages = ["alphagenome"]+[skills.dhdna-profiler]packages = []