%23%20Copyright%202026%20Riya%20Sinha%0A%22%22%22Tutorial%201%3A%20score%20a%20variant%20cohort%20locally%20with%20Cherimoya.%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.24.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0Awith%20app.setup(hide_code%3DTrue)%3A%0A%20%20%20%20import%20asyncio%0A%20%20%20%20from%20dataclasses%20import%20asdict%2C%20replace%0A%20%20%20%20from%20pathlib%20import%20Path%0A%0A%20%20%20%20import%20_series%20as%20series%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20from%20altar.models%20import%20sha256_file%2C%20verify_file%0A%20%20%20%20from%20altar.results%20import%20SqliteScoreStore%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Tutorial%201%20%C2%B7%20Score%20variants%20locally%20with%20Cherimoya%0A%0A%20%20%20%20This%20tutorial%20scores%20a%20small%20variant%20cohort%20with%20the%20Cherimoya%20CATv1%20K562%20DNase%20model%20(%60ENCSR000EOT%60).%0A%20%20%20%20Along%20the%20way%2C%20you%20will%20see%20how%20Altar%20describes%20model%20inputs%2C%20finds%20the%20variants%20that%20still%20need%20scores%2C%0A%20%20%20%20turns%20them%20into%20container%20tasks%2C%20and%20stores%20the%20resulting%20scores%20for%20later%20analysis.%0A%0A%20%20%20%20By%20the%20end%2C%20you%20will%20be%20able%20to%3A%0A%0A%20%20%20%201.%20load%20five%20GRCh38%20variants%20from%20a%20canonical%20TSV%3B%0A%20%20%20%202.%20prepare%20the%20reference%20genome%20and%20five%20model%20checkpoints%3B%0A%20%20%20%203.%20find%20which%20variants%20need%20scoring%3B%0A%20%20%20%204.%20inspect%20the%20work%20Altar%20plans%20to%20submit%3B%0A%20%20%20%205.%20run%20the%20model%20locally%20with%20Docker%20and%20an%20NVIDIA%20GPU%3B%20and%0A%20%20%20%206.%20examine%20the%20scores%20and%20default%20prioritization%20result%20for%20each%20variant.%0A%0A%20%20%20%20Start%20with%20the%20included%20Open%20Targets%20variants%20so%20you%20can%20inspect%20each%20stage%20without%20waiting%20on%20a%20large%0A%20%20%20%20cohort.%20You%20can%20select%20another%20TSV%20in%20Step%201%20after%20completing%20the%20workflow%20once.%0A%0A%20%20%20%20This%20tutorial%20starts%20the%20series'%20score%20store.%20Tutorial%200%20looks%20up%20published%20evidence%20for%20the%20same%20five%0A%20%20%20%20variants%20and%20needs%20no%20GPU%3B%20this%20one%20does%20not%20depend%20on%20it.%20Tutorials%203%20and%204%20read%20the%20scores%20this%20one%20writes.%0A%0A%20%20%20%20**Requirements%3A**%20Step%2012%20needs%20Docker.%20An%20NVIDIA%20GPU%20is%20recommended.%20Without%20one%2C%20choose%20the%20CPU%20in%20Step%206%3A%0A%20%20%20%20the%20five%20tutorial%20variants%20took%20about%20a%20minute%20on%20a%2064-core%20server%2C%20and%20a%20large%20cohort%20is%20much%20slower%20than%20on%0A%20%20%20%20a%20GPU.%20Step%202%20fetches%20UCSC%20hg38%20(984%20MB%20to%20download%2C%20about%203.3%20GB%20unpacked)%20and%20five%20checkpoints%20of%202.5%20MB%0A%20%20%20%20each%2C%20and%20caches%20them.%20Step%2012%20pulls%20the%203.4%20GB%20runtime%20image%20the%20first%20time%20it%20runs.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20execute%20%3D%20series.execute_requested(mo.cli_args())%0A%20%20%20%20download_cache%20%3D%20series.download_cache(mo.cli_args())%0A%20%20%20%20cpu_requested%20%3D%20%22cpu%22%20in%20mo.cli_args()%20and%20str(mo.cli_args()%5B%22cpu%22%5D).strip().lower()%20not%20in%20%7B%0A%20%20%20%20%20%20%20%20%220%22%2C%0A%20%20%20%20%20%20%20%20%22false%22%2C%0A%20%20%20%20%20%20%20%20%22no%22%2C%0A%20%20%20%20%20%20%20%20%22off%22%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20cpu_requested%2C%20download_cache%2C%20execute%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Series%20settings%0A%0A%20%20%20%20Every%20notebook%20of%20the%20series%20reads%20and%20writes%20one%20work%20directory%2C%20%60~%2F.cache%2Faltar%2Ftutorials%2Fseries%60%20by%0A%20%20%20%20default.%20This%20notebook%20keeps%20the%20genome%20it%20fetches%2C%20the%20scores%20it%20computes%20and%20a%20record%20of%20the%20run%20there%2C%20and%0A%20%20%20%20Tutorials%202%2C%203%20and%204%20read%20them.%20Step%204%20shows%20what%20goes%20where.%20Change%20the%20directory%20here%2C%20or%20start%20the%20notebook%0A%20%20%20%20with%20%60--%20--work-dir%20DIR%60%3B%20the%20later%20notebooks%20must%20name%20the%20same%20one.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20work_dir_input%20%3D%20mo.ui.text(%0A%20%20%20%20%20%20%20%20value%3Dseries.display_path(series.work_dir(mo.cli_args()))%2C%0A%20%20%20%20%20%20%20%20label%3D%22Series%20work%20directory%22%2C%0A%20%20%20%20%20%20%20%20full_width%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20work_dir_input%0A%20%20%20%20return%20(work_dir_input%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(work_dir_input)%3A%0A%20%20%20%20work_dir%20%3D%20Path(work_dir_input.value).expanduser().resolve()%0A%20%20%20%20cache_dir%20%3D%20series.cache_dir(work_dir)%0A%20%20%20%20run_dir%20%3D%20series.run_dir(work_dir)%0A%20%20%20%20work_dir.mkdir(parents%3DTrue%2C%20exist_ok%3DTrue)%0A%20%20%20%20return%20cache_dir%2C%20run_dir%2C%20work_dir%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%201%3A%20choose%20variants%0A%0A%20%20%20%20A%20scoring%20run%20starts%20with%20a%20cohort%20in%20Altar's%20canonical%20variant%20format%3A%20a%20headerless%2C%20tab-separated%20file%0A%20%20%20%20containing%20%60chromosome%60%2C%20one-based%20%60position%60%2C%20%60reference%60%2C%20%60alternate%60%2C%20and%20an%20optional%20source%20ID.%0A%20%20%20%20For%20example%3A%0A%0A%20%20%20%20%60%60%60text%0A%20%20%20%20chr1%20%20%20%20109274968%20%20%20%20G%20%20%20%20T%20%20%20%201_109274968_G_T%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20%60load_variants()%60%20validates%20these%20fields%20and%20derives%20a%20%60variant_id%60%20such%20as%20%60chr1%3A109274968%3AG%3AT%60.%20Altar%0A%20%20%20%20uses%20that%20ID%20to%20match%20scores%20and%20annotations%20for%20the%20same%20allele.%20Before%20continuing%2C%20check%20that%20the%20table%0A%20%20%20%20contains%20the%20variants%20you%20intended%20and%20that%20their%20coordinates%20and%20reference%20alleles%20use%20GRCh38%2C%20the%0A%20%20%20%20reference%20selected%20in%20Step%202.%0A%0A%20%20%20%20Select%20the%20included%20five%20%5BOpen%20Targets%20GRCh38%20variants%5D(https%3A%2F%2Fplatform-docs.opentargets.org%2Fvariant)%20to%0A%20%20%20%20follow%20the%20tutorial%2C%20or%20choose%20your%20own%20file%20with%20the%20same%20columns.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20variant_source%20%3D%20mo.ui.radio(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Use%20the%20tutorial%20cohort%20(5%20Open%20Targets%20variants)%22%3A%20%22bundled%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Choose%20a%20canonical%20variant%20TSV%22%3A%20%22existing%22%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20value%3D%22Use%20the%20tutorial%20cohort%20(5%20Open%20Targets%20variants)%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22Variant%20input%22%2C%0A%20%20%20%20)%0A%20%20%20%20variant_path_input%20%3D%20mo.ui.text(%0A%20%20%20%20%20%20%20%20value%3Dseries.display_path(series.COHORT_TSV)%2C%0A%20%20%20%20%20%20%20%20label%3D%22TSV%20path%20(used%20when%20'Choose%20a%20canonical%20variant%20TSV'%20is%20selected)%22%2C%0A%20%20%20%20%20%20%20%20full_width%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20mo.vstack(%5Bvariant_source%2C%20variant_path_input%5D)%0A%20%20%20%20return%20variant_path_input%2C%20variant_source%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20variant_path_input%2C%20variant_source)%3A%0A%20%20%20%20variant_tsv%20%3D%20(%0A%20%20%20%20%20%20%20%20Path(series.COHORT_TSV)%0A%20%20%20%20%20%20%20%20if%20variant_source.value%20%3D%3D%20%22bundled%22%0A%20%20%20%20%20%20%20%20else%20Path(variant_path_input.value).expanduser().resolve()%0A%20%20%20%20)%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20not%20variant_tsv.is_file()%2C%0A%20%20%20%20%20%20%20%20mo.callout(f%22Variant%20TSV%20does%20not%20exist%3A%20%60%7Bseries.display_path(variant_tsv)%7D%60%22%2C%20kind%3D%22danger%22)%2C%0A%20%20%20%20)%0A%20%20%20%20return%20(variant_tsv%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20variant_tsv)%3A%0A%20%20%20%20from%20altar.variants%20import%20load_variants%0A%0A%20%20%20%20variants%20%3D%20load_variants(str(variant_tsv))%0A%20%20%20%20if%20variants.empty%3A%0A%20%20%20%20%20%20%20%20raise%20ValueError(%22the%20selected%20variant%20TSV%20contains%20no%20variants%22)%0A%20%20%20%20variant_ids%20%3D%20variants%5B%22variant_id%22%5D.tolist()%0A%20%20%20%20mo.ui.table(variants%2C%20selection%3DNone)%0A%20%20%20%20return%20(variant_ids%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_dir%2C%20download_cache%2C%20mo)%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%20Step%202%3A%20prepare%20the%20genome%20and%20model%0A%0A%20%20%20%20Cherimoya%20reads%20sequence%20from%20an%20hg38%20FASTA%20and%20combines%20predictions%20from%20five%20CATv1%20checkpoints%2C%20one%20per%0A%20%20%20%20training%20fold%2C%20all%20trained%20on%20one%20ENCODE%20accessibility%20experiment.%0A%0A%20%20%20%20Altar%20finds%20reference%20genomes%20in%20a%20registry%3A%20an%20index%20of%20genomes%20and%20models%20in%20which%20each%20entry%20names%20its%0A%20%20%20%20files%20at%20fixed%20addresses%2C%20each%20with%20a%20SHA-256%20digest.%20%60altar%20resources%20fetch%20hg38%60%20downloads%20the%20entry%20%60hg38%60%0A%20%20%20%20and%20checks%20every%20file%20against%20its%20digest%3B%20the%20next%20cell%20makes%20the%20same%20call%20from%20Python%20with%20%60fetch_entry()%60.%0A%20%20%20%20A%20run%20never%20downloads.%20It%20reads%20the%20fetched%20genome%20from%20its%20cache%2C%20and%20%60fetched_entry()%60%20finds%20it%20there.%0A%0A%20%20%20%20For%20a%20first%20run%2C%20keep%20both%20download%20options%20and%20press%20**Prepare%20and%20validate%20selected%20resources**.%20The%0A%20%20%20%20notebook%20will%3A%0A%0A%20%20%20%20-%20fetch%20UCSC's%20hg38%20FASTA%3A%20download%20%60hg38.fa.gz%60%2C%20check%20it%20against%20UCSC's%20checksum%2C%20unpack%20it%2C%20check%20the%0A%20%20%20%20%20%20FASTA%20against%20the%20digest%20the%20registry%20records%2C%20and%20index%20it%3B%0A%20%20%20%20-%20download%20the%20experiment's%20five%20checkpoints%20with%20%60fetch_official_resources()%60%2C%20which%20writes%0A%20%20%20%20%20%20%60cherimoya.resources.json%60%20beside%20them%3B%20and%0A%20%20%20%20-%20read%20that%20manifest%20into%20the%20model's%20configuration%20and%20verify%20each%20checkpoint%20against%20its%20digest.%0A%0A%20%20%20%20The%20genome%20goes%20into%20the%20series%20cache%2C%20%60%7Bseries.display_path(cache_dir)%7D%60%2C%20under%20its%20digest.%20The%20registry%0A%20%20%20%20entry's%20digest%20identifies%20the%20genome%20in%20Step%207%2C%20so%20the%20notebook%20never%20hashes%20the%203.3%20GB%20file%20itself.%20On%20later%0A%20%20%20%20runs%20the%20fetch%20finds%20the%20file%20already%20checked%20and%20downloads%20nothing.%0A%0A%20%20%20%20%60fetch_official_resources()%60%20is%20the%20Python%20form%20of%20the%20%60altar-cherimoya-resources%20fetch-official%60%20command%3A%0A%20%20%20%20Cherimoya's%20checkpoints%20are%20not%20in%20a%20registry%20yet.%20They%20are%20cached%20under%0A%20%20%20%20%60%7Bseries.display_path(download_cache)%7D%60%2C%20and%20later%20runs%20verify%20the%20cached%20files%20instead%20of%20downloading%20them%0A%20%20%20%20again.%20If%20you%20already%20have%20either%20resource%2C%20choose%20its%20**Use%20an%20existing...**%20option%20and%20give%20the%20path.%0A%0A%20%20%20%20The%20identifiers%20below%20make%20the%20resource%20selection%20explicit%3A%0A%0A%20%20%20%20-%20%60genome_build%60%20names%20the%20assembly%20of%20the%20cohort's%20coordinates.%0A%20%20%20%20-%20%60reference%60%20names%20the%20FASTA%20in%20the%20genome%20registry.%20%60hg38%60%20is%20the%20short%20name%20of%20%60grch38%2Fucsc%2Fhg38%60%3A%20the%0A%20%20%20%20%20%20assembly%2C%20who%20publishes%20the%20file%2C%20and%20the%20publisher's%20name%20for%20it.%20Another%20GRCh38%20FASTA%2C%0A%20%20%20%20%20%20%60grch38%2Fncbi%2Fno-alt-analysis-set%60%2C%20the%20one%20ENCODE%20distributes%2C%20differs%20from%20UCSC's%20in%20sequence%20on%2018%20of%20the%0A%20%20%20%20%20%2025%20chromosomes.%20Scores%20depend%20on%20the%20exact%20FASTA%2C%20so%20each%20one%20scores%20under%20its%20own%20identity.%20Keep%20%60hg38%60%0A%20%20%20%20%20%20unless%20your%20other%20analyses%20use%20another%3B%20%60altar%20resources%20genome%60%20lists%20them.%0A%20%20%20%20-%20%60experiment_accession%60%20names%20the%20checkpoint%20ensemble%20in%20the%0A%20%20%20%20%20%20%5BCATv1%20atlas%5D(https%3A%2F%2Fhuggingface.co%2Fprogrammable-genomics%2FCATv1).%0A%0A%20%20%20%20The%20bundled%20cohort%20is%20mostly%20liver%20and%20lipid%20loci.%20*SORT1*%20rs12740374%2C%20the%20first%20variant%2C%20acts%20in%0A%20%20%20%20hepatocytes.%20K562%20is%20a%20blood%20cancer%20cell%20line%2C%20so%20K562%20accessibility%20is%20a%20demonstration%20choice%20here.%0A%20%20%20%20%60ENCSR000EOT%60%20is%20the%20experiment%20Altar's%20Cherimoya%20validation%20used.%20For%20these%20loci%2C%20the%20HepG2%20DNase-seq%0A%20%20%20%20experiment%20%60ENCSR149XIL%60%2C%20listed%20in%20the%20atlas's%20%60CATv1-metadata.tsv%60%2C%20is%20the%20closer%20choice.%20To%20score%20with%0A%20%20%20%20it%2C%20change%20%60experiment_accession%60%20here%20and%20choose%20another%20model%20key%20in%20Step%204.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20genome_build%20%3D%20series.GENOME_BUILD%0A%20%20%20%20reference%20%3D%20series.REFERENCE%0A%20%20%20%20experiment_accession%20%3D%20%22ENCSR000EOT%22%0A%20%20%20%20return%20experiment_accession%2C%20genome_build%2C%20reference%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(download_cache%2C%20experiment_accession%2C%20mo%2C%20reference)%3A%0A%20%20%20%20default_model_manifest%20%3D%20(%0A%20%20%20%20%20%20%20%20download_cache%20%2F%20%22models%22%20%2F%20%22cherimoya%22%20%2F%20%22CATv1%22%20%2F%20experiment_accession%20%2F%20%22cherimoya.resources.json%22%0A%20%20%20%20)%0A%20%20%20%20genome_source%20%3D%20mo.ui.radio(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22Fetch%20%7Breference%7D%20from%20the%20genome%20registry%22%3A%20%22registry%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Use%20an%20existing%20hg38%20FASTA%22%3A%20%22existing%22%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20value%3Df%22Fetch%20%7Breference%7D%20from%20the%20genome%20registry%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22Reference%20genome%22%2C%0A%20%20%20%20)%0A%20%20%20%20genome_path_input%20%3D%20mo.ui.text(%0A%20%20%20%20%20%20%20%20placeholder%3D%22%2Fpath%2Fto%2Fhg38.fa%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22Existing%20FASTA%20path%22%2C%0A%20%20%20%20%20%20%20%20full_width%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20model_source%20%3D%20mo.ui.radio(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22Download%2Fcache%20the%20%7Bexperiment_accession%7D%20checkpoints%22%3A%20%22download%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Use%20an%20existing%20cherimoya.resources.json%22%3A%20%22existing%22%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20value%3Df%22Download%2Fcache%20the%20%7Bexperiment_accession%7D%20checkpoints%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22Cherimoya%20model%22%2C%0A%20%20%20%20)%0A%20%20%20%20model_manifest_input%20%3D%20mo.ui.text(%0A%20%20%20%20%20%20%20%20value%3Dseries.display_path(default_model_manifest)%2C%0A%20%20%20%20%20%20%20%20label%3D%22Existing%20cherimoya.resources.json%20path%22%2C%0A%20%20%20%20%20%20%20%20full_width%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20prepare_resources%20%3D%20mo.ui.run_button(%0A%20%20%20%20%20%20%20%20label%3D%22Prepare%20and%20validate%20selected%20resources%22%2C%0A%20%20%20%20%20%20%20%20kind%3D%22success%22%2C%0A%20%20%20%20)%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.hstack(%5Bgenome_source%2C%20model_source%5D%2C%20widths%3D%22equal%22%2C%20gap%3D2)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20genome_path_input%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20model_manifest_input%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20prepare_resources%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20default_model_manifest%2C%0A%20%20%20%20%20%20%20%20genome_path_input%2C%0A%20%20%20%20%20%20%20%20genome_source%2C%0A%20%20%20%20%20%20%20%20model_manifest_input%2C%0A%20%20%20%20%20%20%20%20model_source%2C%0A%20%20%20%20%20%20%20%20prepare_resources%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20default_model_manifest%2C%0A%20%20%20%20execute%2C%0A%20%20%20%20genome_path_input%2C%0A%20%20%20%20genome_source%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_manifest_input%2C%0A%20%20%20%20model_source%2C%0A%20%20%20%20prepare_resources%2C%0A)%3A%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20not%20(prepare_resources.value%20or%20execute)%2C%0A%20%20%20%20%20%20%20%20mo.callout(%22Press%20**Prepare%20and%20validate%20selected%20resources**%20to%20continue.%22%2C%20kind%3D%22info%22)%2C%0A%20%20%20%20)%0A%20%20%20%20own_fasta%20%3D%20None%0A%20%20%20%20if%20genome_source.value%20%3D%3D%20%22existing%22%3A%0A%20%20%20%20%20%20%20%20own_fasta%20%3D%20Path(genome_path_input.value).expanduser().resolve()%0A%20%20%20%20%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20%20%20%20%20not%20own_fasta.is_file()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.callout(f%22The%20reference%20FASTA%20does%20not%20exist%3A%20%60%7Bseries.display_path(own_fasta)%7D%60%22%2C%20kind%3D%22danger%22)%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20resource_manifest%20%3D%20(%0A%20%20%20%20%20%20%20%20default_model_manifest%0A%20%20%20%20%20%20%20%20if%20model_source.value%20%3D%3D%20%22download%22%0A%20%20%20%20%20%20%20%20else%20Path(model_manifest_input.value).expanduser().resolve()%0A%20%20%20%20)%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20model_source.value%20%3D%3D%20%22existing%22%20and%20not%20resource_manifest.is_file()%2C%0A%20%20%20%20%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22The%20resource%20manifest%20does%20not%20exist%3A%20%60%7Bseries.display_path(resource_manifest)%7D%60%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20kind%3D%22danger%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20)%0A%20%20%20%20return%20own_fasta%2C%20resource_manifest%0A%0A%0A%40app.cell%0Aasync%20def%20_(cache_dir%2C%20mo%2C%20own_fasta%2C%20reference)%3A%0A%20%20%20%20from%20altar.registries%20import%20GENOME_REGISTRY%2C%20fetch_entry%2C%20fetched_entry%2C%20parse_entry_name%2C%20registries_from%0A%0A%20%20%20%20if%20own_fasta%20is%20None%3A%0A%20%20%20%20%20%20%20%20registries%20%3D%20registries_from()%0A%20%20%20%20%20%20%20%20genome_name%20%3D%20parse_entry_name(reference%2C%20default_registry%3DGENOME_REGISTRY%2C%20registries%3Dregistries)%0A%20%20%20%20%20%20%20%20with%20mo.status.spinner(%0A%20%20%20%20%20%20%20%20%20%20%20%20title%3Df%22Fetching%20%7Breference%7D%20into%20the%20series%20cache%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20subtitle%3D%22A%20first%20fetch%20downloads%20984%20MB%20and%20takes%20several%20minutes%3B%20a%20fetched%20genome%20is%20reused.%22%2C%0A%20%20%20%20%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20asyncio.to_thread(fetch_entry%2C%20registries%2C%20genome_name%2C%20cache_dir)%0A%20%20%20%20%20%20%20%20genome_entry%20%3D%20fetched_entry(registries%2C%20genome_name%2C%20cache_dir)%0A%20%20%20%20%20%20%20%20reference_entry%20%3D%20genome_entry.name%0A%20%20%20%20%20%20%20%20reference_fasta%20%3D%20genome_entry.fasta%0A%20%20%20%20%20%20%20%20reference_digest%20%3D%20genome_entry.entry.genome.fasta.digest%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%23%20Your%20own%20FASTA%20has%20no%20registry%20entry%20to%20give%20its%20digest%2C%20so%20hash%20it%3A%20this%20reads%20all%203.3%20GB.%0A%20%20%20%20%20%20%20%20reference_entry%20%3D%20None%0A%20%20%20%20%20%20%20%20reference_fasta%20%3D%20own_fasta%0A%20%20%20%20%20%20%20%20with%20mo.status.spinner(title%3D%22Hashing%20the%20reference%20FASTA%22%2C%20subtitle%3D%22This%20reads%20the%20whole%20file.%22)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20reference_digest%20%3D%20await%20asyncio.to_thread(sha256_file%2C%20reference_fasta)%0A%20%20%20%20return%20reference_digest%2C%20reference_entry%2C%20reference_fasta%0A%0A%0A%40app.cell%0Aasync%20def%20_(experiment_accession%2C%20mo%2C%20resource_manifest)%3A%0A%20%20%20%20from%20altar_cherimoya%20import%20CherimoyaConfiguration%0A%20%20%20%20from%20altar_cherimoya.resources%20import%20fetch_official_resources%0A%0A%20%20%20%20if%20not%20resource_manifest.is_file()%3A%0A%20%20%20%20%20%20%20%20with%20mo.status.spinner(title%3Df%22Downloading%20the%20five%20%7Bexperiment_accession%7D%20checkpoints%22)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20asyncio.to_thread(fetch_official_resources%2C%20experiment_accession%2C%20resource_manifest.parent)%0A%20%20%20%20configuration%20%3D%20CherimoyaConfiguration.from_resource_manifest(resource_manifest)%0A%20%20%20%20for%20_fold%2C%20_weight%20in%20enumerate(configuration.weights)%3A%0A%20%20%20%20%20%20%20%20verify_file(_weight.uri%2C%20_weight.digest%2C%20label%3Df%22fold%20%7B_fold%7D%20checkpoint%22)%0A%20%20%20%20return%20(configuration%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20configuration%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20reference_digest%2C%0A%20%20%20%20reference_entry%2C%0A%20%20%20%20reference_fasta%2C%0A%20%20%20%20resource_manifest%2C%0A)%3A%0A%20%20%20%20from%20altar_cherimoya.resources%20import%20manifest_resources%0A%0A%20%20%20%20resource_status%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22reference%20entry%22%3A%20reference_entry%20or%20%22your%20own%20FASTA%22%2C%0A%20%20%20%20%20%20%20%20%22reference%20FASTA%22%3A%20series.display_path(reference_fasta)%2C%0A%20%20%20%20%20%20%20%20%22reference%20digest%22%3A%20reference_digest%2C%0A%20%20%20%20%20%20%20%20%22resource%20manifest%22%3A%20series.display_path(resource_manifest)%2C%0A%20%20%20%20%20%20%20%20%22experiment%22%3A%20manifest_resources(resource_manifest).experiment_accession%2C%0A%20%20%20%20%20%20%20%20%22verified%20checkpoints%22%3A%20len(configuration.weights)%2C%0A%20%20%20%20%7D%0A%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22**Resources%20are%20ready.**%20Confirm%20that%20these%20paths%20point%20to%20the%20intended%20genome%20and%20model.%20The%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22digests%20identify%20the%20exact%20files%20that%20will%20be%20scored.%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%20%22%5Cn%22.join(f%22-%20**%7Bname%7D%3A**%20%60%7Bvalue%7D%60%22%20for%20name%2C%20value%20in%20resource_status.items())%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20kind%3D%22success%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%203%3A%20inspect%20Cherimoya's%20scoring%20interface%0A%0A%20%20%20%20A%20model%20plugin%20is%20the%20adapter%20between%20Altar's%20common%20scoring%20workflow%20and%20one%20model%20family.%20The%0A%20%20%20%20%60CherimoyaPlugin%60%20defines%20Cherimoya's%20configuration%20and%20result%20contract%2C%20converts%20a%20scoring%20request%20into%0A%20%20%20%20Cherimoya%20container%20tasks%2C%20and%20decodes%20their%20outputs%20into%20Altar%20score%20rows.%0A%0A%20%20%20%20Instantiating%20the%20plugin%20loads%20this%20lightweight%20planning%20and%20result%20interface.%20The%20model%20checkpoints%20are%0A%20%20%20%20loaded%20later%20by%20the%20runtime%20container.%20The%20summary%20below%20shows%20the%20score%20columns%20and%20default%0A%20%20%20%20prioritization%20rule%20that%20affect%20the%20stored%20results.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20altar_cherimoya%20import%20CherimoyaPlugin%0A%0A%20%20%20%20plugin%20%3D%20CherimoyaPlugin()%0A%20%20%20%20return%20(plugin%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20plugin)%3A%0A%20%20%20%20plugin_summary%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22plugin%22%3A%20plugin.manifest.plugin_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22plugin_version%22%3A%20plugin.manifest.plugin_version%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22score_columns%22%3A%20%22%2C%20%22.join(column.name%20for%20column%20in%20plugin.score_columns())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22default_predicate%22%3A%20plugin.prioritize_predicate().to_sql()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20mo.ui.table(plugin_summary%2C%20selection%3DNone)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Cherimoya%20reports%20two%20complementary%20measures%20of%20the%20alternate%20allele's%20predicted%20effect%3A%0A%0A%20%20%20%20-%20%60counts_log2fc%60%20is%20the%20alternate-minus-reference%20log2%20effect%20on%20the%20model's%20single-track%0A%20%20%20%20%20%20%60log(count%20%2B%201)%60%20head.%20Its%20sign%20gives%20the%20predicted%20direction%20of%20the%20counts%20effect.%0A%20%20%20%20-%20%60profile_l1%60%20is%20the%20L1%20distance%20between%20the%20alternate%20and%20reference%20softmax-normalized%20profiles.%20It%20is%20a%0A%20%20%20%20%20%20non-negative%20measure%20of%20how%20much%20the%20predicted%20profile%20shape%20changes.%0A%0A%20%20%20%20The%20installed%20plugin's%20default%20rule%20flags%20a%20variant%20when%20%60abs(counts_log2fc)%20%3E%3D%200.25%60.%20This%20is%20a%20useful%0A%20%20%20%20workflow%20default%2C%20not%20a%20calibrated%20clinical%20or%20causal%20threshold.%0A%0A%20%20%20%20The%20result%20table%20in%20Step%2013%20will%20show%20both%20measurements%20and%20whether%20this%20rule%20matched%20each%20variant.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%204%3A%20name%20the%20run%0A%0A%20%20%20%20Altar%20uses%20identifiers%20to%20keep%20the%20files%20and%20stored%20scores%20from%20different%20runs%20distinguishable%3A%0A%0A%20%20%20%20-%20%60job_id%60%20names%20this%20analysis.%20It%20groups%20the%20run's%20files%20and%20does%20not%20decide%20which%20scores%20are%20reused.%0A%20%20%20%20-%20%60model_id%60%20is%20the%20model%20key%2C%20the%20stable%20name%20attached%20to%20every%20stored%20score%20row.%20%60altar%20run%60%20uses%20the%0A%20%20%20%20%20%20%60%3Cname%3E%60%20of%20a%20%60%5Bmodels.%3Cname%3E%5D%60%20section%20the%20same%20way.%20The%20series%20uses%20%60k562-dnase%60.%0A%20%20%20%20-%20%60model_name%60%20is%20the%20label%20shown%20when%20results%20are%20presented.%0A%0A%20%20%20%20Reuse%20a%20model%20key%20for%20the%20same%20model.%20A%20changed%20setting%20under%20the%20same%20key%20is%20stored%20beside%20the%20earlier%0A%20%20%20%20scores%20(Step%209%20explains%20how).%20Choose%20another%20key%20when%20you%20switch%20to%20another%20experiment%2C%20such%20as%0A%20%20%20%20%60hepg2-dnase%60%20for%20%60ENCSR149XIL%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20job_id%20%3D%20series.JOB_ID%0A%20%20%20%20model_id%20%3D%20series.CHERIMOYA_MODEL_KEY%0A%20%20%20%20model_name%20%3D%20%22Cherimoya%20K562%20DNase%22%0A%20%20%20%20return%20job_id%2C%20model_id%2C%20model_name%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_dir%2C%20mo%2C%20run_dir%2C%20work_dir)%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20The%20series%20work%20directory%2C%20%60%7Bseries.display_path(work_dir)%7D%60%2C%20is%20laid%20out%20as%20%60altar%20run%60%20lays%20out%20the%0A%20%20%20%20directory%20it%20starts%20in.%20Tutorials%202%2C%203%20and%204%20open%20the%20same%20directory%3A%0A%0A%20%20%20%20-%20%60.altar%2F%60%2C%20the%20cache%2C%20holds%20what%20a%20later%20run%20reuses%3A%20the%20genome%20Step%202%20fetched%2C%20under%20%60resources%2F%60%3B%0A%20%20%20%20%20%20%60scores.sqlite%60%2C%20the%20score%20store%3B%20and%20%60backend-data%2F%60%2C%20the%20directory%20the%20containers%20share%20in%20Step%2012.%0A%20%20%20%20%20%20%60altar%20run%60%20keeps%20its%20cache%20in%20%60.altar%60%20in%20the%20directory%20it%20starts%20in%2C%20unless%20%60%5Brun%5D%20cache_dir%60%20names%0A%20%20%20%20%20%20another.%0A%20%20%20%20-%20%60%7Brun_dir.name%7D%2F%60%2C%20the%20run%20directory%2C%20is%20named%20by%20the%20job%20ID%2C%20as%20%60altar%20run%60%20names%20it.%20It%20holds%20the%0A%20%20%20%20%20%20variant%20files%20preparation%20writes%20in%20Step%209%2C%20under%20%60staging%2F%60%2C%20and%20the%20result%20files%20collected%20from%20the%0A%20%20%20%20%20%20containers%2C%20under%20%60results%2F%60.%20Nothing%20a%20later%20run%20needs%20is%20kept%20there%2C%20so%20deleting%20it%20loses%20no%20scores.%0A%20%20%20%20-%20%60series.json%60%20records%20this%20run%20for%20the%20next%20tutorials.%0A%0A%20%20%20%20Here%20the%20cache%20is%20%60%7Bseries.display_path(cache_dir)%7D%60%20and%20the%20run%20directory%0A%20%20%20%20%60%7Bseries.display_path(run_dir)%7D%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%205%3A%20preview%20the%20logical%20paths%0A%0A%20%20%20%20A%20%60ScoringLayout%60%20is%20the%20shared%20naming%20convention%20for%20the%20files%20in%20a%20scoring%20run.%20It%20uses%20the%20identifiers%0A%20%20%20%20above%20to%20produce%20storage-relative%20paths%20for%20the%20reference%2C%20cohort%2C%20checkpoints%2C%20and%20results.%20The%20plugin%0A%20%20%20%20can%20therefore%20build%20container%20commands%20using%20stable%20names%2C%20while%20the%20storage%20layer%20decides%20where%20those%0A%20%20%20%20files%20live.%20Every%20request%20uses%20this%20layout%20unless%20you%20give%20it%20another.%0A%0A%20%20%20%20The%20table%20previews%20the%20names%20that%20will%20appear%20in%20the%20execution%20plan.%20Step%209%20numbers%20the%20batches%20of%0A%20%20%20%20variants%20from%200%2C%20so%20the%20cohort%20and%20result%20names%20are%20batch%200's.%20Step%2011%20connects%20each%20input%20name%20to%20a%0A%20%20%20%20file%20on%20this%20machine.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(genome_build%2C%20job_id%2C%20model_id)%3A%0A%20%20%20%20from%20altar.models%20import%20ScoringLayout%0A%0A%20%20%20%20layout%20%3D%20ScoringLayout()%0A%20%20%20%20example_logical_paths%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22reference%20genome%22%3A%20layout.genome_fasta(genome_build)%2C%0A%20%20%20%20%20%20%20%20%22variants%2C%20batch%200%22%3A%20layout.model_variants_file(job_id%2C%20model_id%2C%200)%2C%0A%20%20%20%20%20%20%20%20%22fold%200%20checkpoint%22%3A%20layout.fold_model_file(model_id%2C%200%2C%20%22.torch%22)%2C%0A%20%20%20%20%20%20%20%20%22final%20result%2C%20batch%200%22%3A%20layout.scoring_result_file(job_id%2C%20model_id%2C%200)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20(example_logical_paths%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(example_logical_paths%2C%20mo)%3A%0A%20%20%20%20logical_paths%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%7B%22role%22%3A%20role%2C%20%22logical_path%22%3A%20logical_path%7D%20for%20role%2C%20logical_path%20in%20example_logical_paths.items()%5D%0A%20%20%20%20)%0A%20%20%20%20mo.ui.table(logical_paths%2C%20selection%3DNone)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%206%3A%20choose%20how%20to%20move%20files%20and%20run%20tasks%0A%0A%20%20%20%20This%20tutorial%20runs%20containers%20with%20local%20Docker%20and%20stages%20their%20files%20through%20local%20storage.%20These%20are%0A%20%20%20%20separate%20responsibilities%3A%0A%0A%20%20%20%20-%20%60LocalStorage%60%20stages%20declared%20inputs%20and%20collects%20declared%20outputs.%0A%20%20%20%20-%20%60LocalDockerExecutionBackend%60%20starts%20and%20monitors%20the%20containers%20in%20the%20plan.%0A%0A%20%20%20%20Keeping%20these%20roles%20separate%20lets%20the%20same%20scoring%20request%20pair%20with%20another%20supported%20storage%20or%0A%20%20%20%20execution%20backend.%20The%20backend's%20%60data_root%60%20is%20the%20directory%20Docker%20mounts%20into%20every%20container%20at%0A%20%20%20%20%60%2Fmnt%2Fvolume%60.%20The%20backend%20keeps%20its%20own%20copy%20of%20each%20task's%20inputs%20there%2C%203.3%20GB%20for%20hg38%2C%20and%20reads%20the%0A%20%20%20%20task's%20outputs%20back%20from%20it.%20Here%20it%20is%20%60backend-data%2F%60%20in%20the%20series%20cache%2C%20where%20%60altar%20run%60%20puts%20it%20when%0A%20%20%20%20%60%5Bbackend%5D%60%20names%20none%2C%20so%20Tutorial%203's%20run%20finds%20the%20copies%20this%20one%20makes.%0A%20%20%20%20%5BRun%20tasks%20on%20a%20GPU%20or%20a%20cluster%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fguides%2Fcompute%2F)%20covers%20the%20other%0A%20%20%20%20backends.%0A%0A%20%20%20%20Each%20task%20in%20a%20plan%20carries%20a%20resource%20request%3A%20the%20memory%20it%20needs%20and%20whether%20it%20needs%20a%20GPU.%20Each%0A%20%20%20%20Cherimoya%20fold%20task%20asks%20for%20one%20NVIDIA%20GPU.%20Choose%20where%20the%20tasks%20run%3A%0A%0A%20%20%20%20-%20**NVIDIA%20GPU**%2C%20the%20default%2C%20passes%20one%20GPU%20to%20each%20fold%20task.%0A%20%20%20%20-%20**CPU**%20runs%20the%20same%20tasks%20without%20a%20GPU.%20The%20five%20tutorial%20variants%20took%20about%20a%20minute%20on%20a%2064-core%0A%20%20%20%20%20%20server%3B%20a%20large%20cohort%20is%20much%20slower%20than%20on%20a%20GPU.%20Use%20it%20on%20a%20machine%20without%20a%20GPU%2C%20or%20start%20the%0A%20%20%20%20%20%20notebook%20with%20%60--%20--cpu%60.%0A%0A%20%20%20%20On%20a%20machine%20whose%20GPUs%20other%20people%20use%2C%20list%20the%20free%20ones%20under%20**GPU%20devices**%2C%20by%20the%20index%0A%20%20%20%20%60nvidia-smi%60%20shows.%20The%20backend%20then%20forms%20a%20GPU%20pool%20of%20those%20devices%20and%20gives%20each%20task%20one%20of%20them%20to%0A%20%20%20%20itself%3B%20a%20task%20waits%20while%20every%20device%20in%20the%20pool%20is%20busy.%20Left%20empty%2C%20Docker%20chooses%20from%20all%20of%20the%0A%20%20%20%20machine's%20GPUs.%20The%20field%20starts%20from%20%60CUDA_VISIBLE_DEVICES%60%20when%20it%20is%20set.%0A%0A%20%20%20%20A%20spec%20mapper%20adjusts%20each%20task%20before%20it%20is%20submitted.%20It%20may%20change%20the%20resource%20request%2C%20but%20not%20the%0A%20%20%20%20image%2C%20the%20command%20or%20the%20files.%20The%20CPU%20choice%20uses%20one%20that%20drops%20the%20GPU%20request%2C%20as%20%60altar%20run%60%20does%20for%0A%20%20%20%20%60%5Bbackend%5D%20cpu_only%20%3D%20true%60.%20Neither%20choice%20changes%20the%20scores'%20lineage%2C%20so%20a%20later%20run%20on%20a%20GPU%20reuses%0A%20%20%20%20scores%20computed%20on%20the%20CPU.%20CPU%20and%20GPU%20scores%20differ%20within%20the%20tolerance%20Step%2012%20gives%20for%20repeated%20GPU%0A%20%20%20%20runs.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cpu_requested%2C%20mo)%3A%0A%20%20%20%20import%20os%20as%20_os%0A%20%20%20%20import%20re%20as%20_re%0A%0A%20%20%20%20_visible%20%3D%20_os.environ.get(%22CUDA_VISIBLE_DEVICES%22%2C%20%22%22).replace(%22%20%22%2C%20%22%22)%0A%20%20%20%20run_on%20%3D%20mo.ui.radio(%0A%20%20%20%20%20%20%20%20%7B%22NVIDIA%20GPU%22%3A%20%22gpu%22%2C%20%22CPU%20(slower%20for%20a%20large%20cohort)%22%3A%20%22cpu%22%7D%2C%0A%20%20%20%20%20%20%20%20value%3D%22CPU%20(slower%20for%20a%20large%20cohort)%22%20if%20cpu_requested%20else%20%22NVIDIA%20GPU%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22Run%20on%22%2C%0A%20%20%20%20)%0A%20%20%20%20gpu_devices_input%20%3D%20mo.ui.text(%0A%20%20%20%20%20%20%20%20value%3D_visible%20if%20_re.fullmatch(r%22%5Cd%2B(%2C%5Cd%2B)*%22%2C%20_visible)%20else%20%22%22%2C%0A%20%20%20%20%20%20%20%20placeholder%3D%22any%20GPU%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22GPU%20devices%2C%20comma-separated%20(used%20when%20running%20on%20an%20NVIDIA%20GPU)%22%2C%0A%20%20%20%20)%0A%20%20%20%20mo.vstack(%5Brun_on%2C%20gpu_devices_input%5D)%0A%20%20%20%20return%20gpu_devices_input%2C%20run_on%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(gpu_devices_input%2C%20mo)%3A%0A%20%20%20%20_typed%20%3D%20%5Bitem.strip()%20for%20item%20in%20gpu_devices_input.value.split(%22%2C%22)%20if%20item.strip()%5D%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20not%20all(item.isdigit()%20for%20item%20in%20_typed)%2C%0A%20%20%20%20%20%20%20%20mo.callout(%22List%20GPU%20devices%20by%20number%2C%20such%20as%20%601%60%20or%20%601%2C2%60%2C%20or%20leave%20the%20field%20empty.%22%2C%20kind%3D%22danger%22)%2C%0A%20%20%20%20)%0A%20%20%20%20gpu_devices%20%3D%20%5Bint(item)%20for%20item%20in%20_typed%5D%0A%20%20%20%20return%20(gpu_devices%2C)%0A%0A%0A%40app.cell%0Adef%20_(cache_dir%2C%20gpu_devices%2C%20run_on)%3A%0A%20%20%20%20from%20altar.execution%20import%20LocalDockerExecutionBackend%2C%20LocalStorage%0A%0A%20%20%20%20def%20cpu_only(spec)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Drop%20a%20task's%20GPU%20request%3B%20the%20runtime%20then%20runs%20on%20the%20CPU.%22%22%22%0A%20%20%20%20%20%20%20%20return%20replace(spec%2C%20resources%3Dreplace(spec.resources%2C%20gpu%3DNone))%0A%0A%20%20%20%20spec_mapper%20%3D%20cpu_only%20if%20run_on.value%20%3D%3D%20%22cpu%22%20else%20None%0A%20%20%20%20gpu_pools%20%3D%20%7B%22gpu%22%3A%20%7B%22devices%22%3A%20gpu_devices%7D%7D%20if%20gpu_devices%20and%20spec_mapper%20is%20None%20else%20None%0A%0A%20%20%20%20artifact_storage%20%3D%20LocalStorage()%0A%20%20%20%20backend%20%3D%20LocalDockerExecutionBackend(%0A%20%20%20%20%20%20%20%20data_root%3Dstr(cache_dir%20%2F%20%22backend-data%22)%2C%0A%20%20%20%20%20%20%20%20storage%3Dartifact_storage%2C%0A%20%20%20%20%20%20%20%20pools%3Dgpu_pools%2C%0A%20%20%20%20)%0A%20%20%20%20return%20artifact_storage%2C%20backend%2C%20gpu_pools%2C%20spec_mapper%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(artifact_storage%2C%20backend%2C%20cache_dir%2C%20gpu_pools%2C%20mo%2C%20spec_mapper)%3A%0A%20%20%20%20if%20spec_mapper%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20_runs_on%20%3D%20%22the%20CPU%22%0A%20%20%20%20elif%20gpu_pools%3A%0A%20%20%20%20%20%20%20%20_runs_on%20%3D%20%22GPU%20%22%20%2B%20%22%2C%20%22.join(map(str%2C%20gpu_pools%5B%22gpu%22%5D%5B%22devices%22%5D))%20%2B%20%22%2C%20one%20device%20per%20task%22%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_runs_on%20%3D%20%22any%20GPU%2C%20as%20Docker%20chooses%22%0A%20%20%20%20backend_summary%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22setting%22%3A%20%22artifact%20storage%22%2C%20%22value%22%3A%20type(artifact_storage).__name__%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22setting%22%3A%20%22execution%20backend%22%2C%20%22value%22%3A%20type(backend).__name__%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22setting%22%3A%20%22data_root%22%2C%20%22value%22%3A%20series.display_path(cache_dir%20%2F%20%22backend-data%22)%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22setting%22%3A%20%22fold%20tasks%20run%20on%22%2C%20%22value%22%3A%20_runs_on%7D%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20mo.ui.table(backend_summary%2C%20selection%3DNone)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%207%3A%20describe%20the%20exact%20model%20and%20genome%20inputs%0A%0A%20%20%20%20A%20%60ResourceReference%60%20is%20Altar's%20description%20of%20an%20external%20file%20used%20by%20a%20model.%20It%20pairs%20a%20retrievable%0A%20%20%20%20location%20with%20a%20content%20identity%3A%0A%0A%20%20%20%20-%20%60uri%60%20tells%20storage%20where%20the%20file%20can%20be%20found%3B%0A%20%20%20%20-%20%60digest%60%20identifies%20the%20file's%20exact%20bytes%20with%20SHA-256.%0A%0A%20%20%20%20This%20means%20a%20file%20can%20move%20to%20another%20location%20while%20retaining%20the%20same%20content%20identity%2C%20and%20a%20changed%0A%20%20%20%20file%20at%20the%20same%20path%20is%20recognized%20as%20a%20different%20resource.%20Step%202%20read%20one%20reference%20per%20checkpoint%20from%0A%20%20%20%20the%20manifest.%20The%20next%20cell%20creates%20one%20for%20the%20reference%20FASTA%2C%20with%20the%20digest%20its%20registry%20entry%20records%2C%0A%20%20%20%20or%2C%20for%20a%20FASTA%20of%20your%20own%2C%20the%20digest%20Step%202%20computed.%0A%0A%20%20%20%20Resource%20references%20identify%20individual%20files.%20Two%20Cherimoya%20objects%20assign%20those%20files%20their%20roles%20in%0A%20%20%20%20scoring%3A%0A%0A%20%20%20%20-%20%60CherimoyaConfiguration%60%2C%20from%20Step%202%2C%20defines%20the%20reusable%20model%20from%20its%20five%20checkpoints%20and%20runtime%0A%20%20%20%20%20%20settings.%0A%20%20%20%20-%20%60CherimoyaRunInputs%60%20supplies%20the%20reference%20assembly%20and%20FASTA%20for%20this%20run.%0A%0A%20%20%20%20The%20run%20uses%20the%20binding's%20digest-pinned%20default%20runtime%20image%3B%20the%20configuration%20holds%20none.%20Together%2C%20these%0A%20%20%20%20objects%20give%20Altar%20enough%20information%20to%20recognize%20which%20model%20and%20genome%20produced%20a%20stored%20score.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(genome_build%2C%20reference_digest%2C%20reference_fasta)%3A%0A%20%20%20%20from%20altar.models%20import%20ResourceReference%0A%20%20%20%20from%20altar_cherimoya%20import%20CherimoyaRunInputs%0A%0A%20%20%20%20reference_genome%20%3D%20ResourceReference(uri%3Dstr(reference_fasta)%2C%20digest%3Dreference_digest)%0A%20%20%20%20run_inputs%20%3D%20CherimoyaRunInputs(genome_build%3Dgenome_build%2C%20genome%3Dreference_genome)%0A%20%20%20%20return%20(run_inputs%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(configuration%2C%20mo%2C%20run_inputs)%3A%0A%20%20%20%20from%20altar_cherimoya%20import%20DEFAULT_IMAGE%20as%20_DEFAULT_IMAGE%0A%0A%20%20%20%20resource_table%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20*(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20f%22fold%20%7Bfold%7D%20checkpoint%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22uri%22%3A%20series.display_path(weight.uri)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22digest%22%3A%20weight.digest%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20fold%2C%20weight%20in%20enumerate(configuration.weights)%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22reference%20genome%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22uri%22%3A%20series.display_path(run_inputs.genome.uri)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22digest%22%3A%20run_inputs.genome.digest%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22Runtime%20image%3A%20%60%7B_DEFAULT_IMAGE%7D%60%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(resource_table%2C%20selection%3DNone)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%208%3A%20assemble%20the%20template%20request%0A%0A%20%20%20%20A%20%60ScoringRequest%60%20is%20the%20complete%20description%20of%20one%20model%20invocation.%20It%20binds%20the%20model%20definition%20and%0A%20%20%20%20biological%20inputs%20to%20the%20run%20identifiers%2C%20requested%20output%2C%20and%20backend%20path%20convention.%20The%20plugin%0A%20%20%20%20consumes%20a%20request%20to%20produce%20an%20execution%20plan.%0A%0A%20%20%20%20This%20request%20is%20a%20template%3A%20it%20names%20no%20batch%20of%20variants.%20Step%209%20copies%20it%20once%20for%20each%20batch%20that%20needs%0A%20%20%20%20scoring.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(backend%2C%20configuration%2C%20job_id%2C%20model_id%2C%20plugin%2C%20run_inputs)%3A%0A%20%20%20%20from%20altar.models%20import%20ScoringRequest%0A%0A%20%20%20%20template%20%3D%20ScoringRequest(%0A%20%20%20%20%20%20%20%20job_id%3Djob_id%2C%0A%20%20%20%20%20%20%20%20model_id%3Dmodel_id%2C%0A%20%20%20%20%20%20%20%20configuration%3Dconfiguration%2C%0A%20%20%20%20%20%20%20%20run_inputs%3Drun_inputs%2C%0A%20%20%20%20%20%20%20%20output%3Dplugin.default_output%2C%0A%20%20%20%20%20%20%20%20resolver%3Dbackend.path_resolver()%2C%0A%20%20%20%20)%0A%20%20%20%20return%20(template%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%209%3A%20find%20what%20needs%20scoring%0A%0A%20%20%20%20Preparation%20compares%20the%20cohort%20with%20the%20score%20store%20before%20any%20task%20runs.%20%60prepare_scoring_batches()%60%3A%0A%0A%20%20%20%201.%20reads%20the%20cohort%20and%20drops%20repeated%20variants%3B%0A%20%20%20%202.%20sets%20aside%20variants%20the%20model%20cannot%20score%2C%20such%20as%20one%20whose%20reference%20allele%20does%20not%20match%0A%20%20%20%20%20%20%20%60reference_fasta%60%3B%0A%20%20%20%203.%20looks%20each%20remaining%20variant%20up%20in%20the%20store%3B%0A%20%20%20%204.%20packs%20the%20variants%20it%20does%20not%20find%20into%20batches%20of%20at%20most%20%60max_variants_per_batch%60%3B%20and%0A%20%20%20%205.%20writes%20each%20batch's%20variant%20file%20under%20%60staging%2F%60%20in%20the%20run%20directory%2C%20and%20copies%20the%20template%20into%20one%0A%20%20%20%20%20%20%20request%20per%20batch.%0A%0A%20%20%20%20A%20variant%20counts%20as%20already%20scored%20only%20when%20the%20store%20holds%20a%20score%20from%20the%20same%20computation%3A%20the%20same%0A%20%20%20%20checkpoints%2C%20settings%2C%20runtime%20image%2C%20genome%20build%20and%20reference%20genome.%20The%20scores%20from%20one%20computation%0A%20%20%20%20form%20a%20lineage.%20A%20store%20that%20keeps%20lineages%20holds%20each%20lineage%20beside%20the%20others.%20A%20changed%20setting%20under%20the%0A%20%20%20%20same%20model%20key%20then%20adds%20a%20lineage%2C%20where%20a%20store%20without%20lineages%20refuses%20it.%20The%20store%20here%20is%20a%0A%20%20%20%20%60SqliteScoreStore%60%20with%20%60lineages%3DTrue%60%20at%20%60scores.sqlite%60%20in%20the%20series%20cache%2C%20the%20store%20%60altar%20run%60%20creates%0A%20%20%20%20there%20when%20a%20spec%20has%20no%20%60%5Bstore%5D%60.%20%5BScore%20reuse%20and%0A%20%20%20%20provenance%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fscience%2Flineage%2F)%20lists%20what%20defines%20a%20computation.%0A%0A%20%20%20%20%60max_variants_per_batch%60%20caps%20the%20variants%20in%20one%20request%3B%2010%2C000%20is%20the%20%60altar%20run%60%20default.%20Preparation%0A%20%20%20%20reads%20the%20store%20and%20writes%20small%20TSV%20files.%20It%20downloads%20nothing%20and%20submits%20no%20task.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20artifact_storage%2C%0A%20%20%20%20cache_dir%2C%0A%20%20%20%20plugin%2C%0A%20%20%20%20reference_fasta%2C%0A%20%20%20%20run_dir%2C%0A%20%20%20%20template%2C%0A%20%20%20%20variant_tsv%2C%0A)%3A%0A%20%20%20%20from%20altar.execution%20import%20Transfer%0A%20%20%20%20from%20altar.scoring%20import%20prepare_scoring_batches%0A%0A%20%20%20%20max_variants_per_batch%20%3D%2010_000%0A%20%20%20%20score_database%20%3D%20cache_dir%20%2F%20series.SCORE_STORE%0A%0A%20%20%20%20def%20staged(transfer)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Place%20each%20file%20preparation%20writes%20under%20staging%2F%20in%20the%20run%20directory.%22%22%22%0A%20%20%20%20%20%20%20%20return%20replace(transfer%2C%20uri%3Dstr(run_dir%20%2F%20%22staging%22%20%2F%20transfer.logical_path))%0A%0A%20%20%20%20with%20SqliteScoreStore(str(score_database)%2C%20lineages%3DTrue)%20as%20_scores%3A%0A%20%20%20%20%20%20%20%20preparation%20%3D%20await%20prepare_scoring_batches(%0A%20%20%20%20%20%20%20%20%20%20%20%20plugin%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20template%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20candidate_variants%3DTransfer(uri%3Dstr(variant_tsv)%2C%20logical_path%3D%22candidates.tsv%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20score_store%3D_scores%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20storage%3Dartifact_storage%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20destination_transfer%3Dstaged%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20max_variants_per_batch%3Dmax_variants_per_batch%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20reference_fasta%3Dreference_fasta%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20return%20preparation%2C%20score_database%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20preparation)%3A%0A%20%20%20%20preparation_counts%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22measure%22%3A%20%22unique%20candidates%22%2C%20%22variants%22%3A%20preparation.candidate_count%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22measure%22%3A%20%22repeated%20rows%20dropped%22%2C%20%22variants%22%3A%20preparation.duplicate_count%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22measure%22%3A%20%22set%20aside%20as%20ineligible%22%2C%20%22variants%22%3A%20preparation.ineligible_count%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22measure%22%3A%20%22already%20scored%22%2C%20%22variants%22%3A%20preparation.cache_hit_count%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22measure%22%3A%20%22need%20scoring%22%2C%20%22variants%22%3A%20preparation.unscored_count%7D%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20lineage_table%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22lineage_id%22%3A%20lineage_id%2C%20%22how%20it%20was%20chosen%22%3A%20str(step)%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20lineage_id%2C%20step%20in%20zip(preparation.resolution.lineage_ids%2C%20preparation.resolution.steps%2C%20strict%3DTrue)%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20outputs%20%3D%20%5B%0A%20%20%20%20%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Bpreparation.unscored_count%7D%20of%20%7Bpreparation.candidate_count%7D%20variants%20need%20scoring%2C%20in%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Blen(preparation.batches)%7D%20%7B'batch'%20if%20len(preparation.batches)%20%3D%3D%201%20else%20'batches'%7D.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Bpreparation.cache_hit_count%7D%20are%20already%20scored.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20kind%3D%22info%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20mo.ui.table(preparation_counts%2C%20selection%3DNone)%2C%0A%20%20%20%20%20%20%20%20mo.md(%22The%20lineages%20preparation%20checked%2C%20in%20order%3A%22)%2C%0A%20%20%20%20%20%20%20%20mo.ui.table(lineage_table%2C%20selection%3DNone)%2C%0A%20%20%20%20%5D%0A%20%20%20%20if%20preparation.ineligible_variants%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20outputs%20%2B%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22Variants%20set%20aside%2C%20with%20the%20reason%3A%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(pd.read_csv(preparation.ineligible_variants.uri%2C%20sep%3D%22%5Ct%22)%2C%20selection%3DNone)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20mo.vstack(outputs)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20On%20a%20first%20run%2C%20all%20five%20variants%20need%20scoring%20in%20one%20batch.%20Rerun%20the%20notebook%20with%20the%20same%20work%0A%20%20%20%20directory%20and%20all%20five%20are%20already%20scored%2C%20with%20no%20batch%20to%20run.%20The%20first%20lineage%2C%20%60current%60%2C%20is%20the%20one%0A%20%20%20%20this%20run%20computes.%20Any%20others%20are%20older%20lineages%20the%20binding%20declares%20equivalent%20or%20that%20a%20reuse%20policy%0A%20%20%20%20accepts%3B%20here%20there%20are%20none.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%2010%3A%20inspect%20the%20work%20before%20execution%0A%0A%20%20%20%20%60build_scoring_plan()%60%20turns%20a%20request%20into%20a%20concrete%20task%20graph%20that%20can%20be%20inspected%20before%20execution.%0A%20%20%20%20Cherimoya%20expands%20each%20batch's%20request%20into%20five%20independent%20fold%20tasks%2C%20one%20per%20checkpoint%2C%20and%20a%0A%20%20%20%20summarization%20task%20that%20averages%20their%20outputs%20after%20all%20five%20succeed.%0A%0A%20%20%20%20The%20table%20shows%20the%20plan%20for%20the%20first%20batch.%20When%20every%20variant%20is%20already%20scored%20there%20is%20no%20batch%2C%20and%0A%20%20%20%20it%20shows%20the%20template's%20plan%20instead.%20Each%20row%20is%20one%20container%20task.%20Check%20the%20stage%2C%20image%2C%20resource%0A%20%20%20%20request%2C%20inputs%2C%20outputs%2C%20and%20command%20before%20continuing.%20The%20%60gpu%60%20column%20follows%20the%20choice%20in%20Step%206.%20The%0A%20%20%20%20commands%20use%20the%20logical%20paths%20from%20Step%205%3B%20execution%20begins%20in%20Step%2012.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plugin%2C%20preparation%2C%20template)%3A%0A%20%20%20%20plan_request%20%3D%20preparation.batches%5B0%5D.request%20if%20preparation.batches%20else%20template%0A%20%20%20%20plan%20%3D%20plugin.build_scoring_plan(plan_request)%0A%20%20%20%20return%20(plan%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20plan%2C%20spec_mapper)%3A%0A%20%20%20%20_mapped%20%3D%20spec_mapper%20or%20(lambda%20spec%3A%20spec)%0A%20%20%20%20_stages%20%3D%20%5B(f%22fold%20%7Bindex%7D%22%2C%20task)%20for%20index%2C%20task%20in%20enumerate(plan.shards)%5D%0A%20%20%20%20if%20plan.summarize%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20_stages.append((%22summarize%22%2C%20plan.summarize))%0A%20%20%20%20plan_tasks%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22stage%22%3A%20stage%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22kind%22%3A%20task.kind%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22image%22%3A%20task.image%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22gpu%22%3A%20_mapped(task).resources.gpu%20or%20%22none%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22memory_gb%22%3A%20_mapped(task).resources.memory_gb%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22inputs%22%3A%20len(task.inputs)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22outputs%22%3A%20len(task.outputs)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22command%22%3A%20%22%20%22.join(task.command)%2C%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20for%20stage%2C%20task%20in%20_stages%0A%20%20%20%20%5D%0A%20%20%20%20plan_table%20%3D%20pd.DataFrame(plan_tasks)%0A%20%20%20%20mo.ui.table(plan_table%2C%20selection%3DNone)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%2011%3A%20map%20logical%20inputs%20to%20local%20files%0A%0A%20%20%20%20The%20plan%20names%20each%20file%20it%20reads%20by%20a%20logical%20path%2C%20and%20local%20storage%20also%20needs%20its%20location%20on%20this%0A%20%20%20%20machine.%20The%20plan's%20inputs%20are%20of%20two%20kinds%3A%0A%0A%20%20%20%20-%20The%20checkpoints%20and%20the%20FASTA%20are%20resources.%20Each%20of%20their%20transfers%20already%20carries%20the%20resource's%20%60uri%60%0A%20%20%20%20%20%20and%20%60digest%60%2C%20and%20the%20backend%20checks%20the%20digest%20when%20it%20copies%20the%20file%20into%20%60backend-data%2F%60.%0A%20%20%20%20-%20The%20batch's%20variant%20file%20is%20named%20only%20by%20its%20logical%20path.%20Preparation%20staged%20it%20in%20Step%209%2C%20and%0A%20%20%20%20%20%20%60batch.variant_input%60%20says%20where.%0A%0A%20%20%20%20%60input_transfer_for(batch)%60%20maps%20the%20batch's%20variant%20file%20to%20its%20staged%20copy%20and%20leaves%20the%20resources%20as%0A%20%20%20%20declared.%20%60output_transfer()%60%20collects%20each%20result%20under%20%60results%2F%60%20in%20the%20run%20directory.%0A%0A%20%20%20%20Use%20the%20table%20to%20verify%20the%20reference%2C%20the%20variant%20file%2C%20and%20all%20five%20checkpoints%20before%20execution.%20With%20a%0A%20%20%20%20different%20storage%20adapter%2C%20these%20locations%20could%20be%20object-store%20URIs%20while%20the%20plan's%20logical%20names%20stay%0A%20%20%20%20the%20same.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(run_dir)%3A%0A%20%20%20%20def%20input_transfer_for(batch)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Read%20the%20batch's%20variant%20file%20where%20preparation%20staged%20it%3B%20leave%20the%20resources%20as%20declared.%22%22%22%0A%0A%20%20%20%20%20%20%20%20def%20input_transfer(transfer)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20batch.variant_input%20if%20transfer.logical_path%20%3D%3D%20batch.variant_input.logical_path%20else%20transfer%0A%0A%20%20%20%20%20%20%20%20return%20input_transfer%0A%0A%20%20%20%20def%20output_transfer(transfer)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Collect%20every%20output%20under%20results%2F%20in%20the%20run%20directory.%22%22%22%0A%20%20%20%20%20%20%20%20return%20replace(transfer%2C%20uri%3Dstr(run_dir%20%2F%20%22results%22%20%2F%20transfer.logical_path))%0A%0A%20%20%20%20return%20input_transfer_for%2C%20output_transfer%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(input_transfer_for%2C%20mo%2C%20plan%2C%20preparation)%3A%0A%20%20%20%20_mapped%20%3D%20input_transfer_for(preparation.batches%5B0%5D)%20if%20preparation.batches%20else%20(lambda%20transfer%3A%20transfer)%0A%20%20%20%20_inputs%20%3D%20%7Btransfer.logical_path%3A%20_mapped(transfer)%20for%20task%20in%20plan.shards%20for%20transfer%20in%20task.inputs%7D%0A%20%20%20%20transfer_table%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22logical_path%22%3A%20logical_path%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22host_source%22%3A%20series.display_path(transfer.uri)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22digest%22%3A%20transfer.digest%20or%20%22%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20logical_path%2C%20transfer%20in%20_inputs.items()%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20mo.ui.table(transfer_table%2C%20selection%3DNone)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%2012%3A%20execute%20the%20plan%20and%20store%20its%20scores%0A%0A%20%20%20%20Press%20**Run%20Cherimoya%20locally**%20to%20execute%20every%20batch.%20For%20each%20batch%2C%20%60run_scoring()%60%20will%3A%0A%0A%20%20%20%201.%20stage%20the%20FASTA%2C%20the%20batch's%20variant%20file%2C%20and%20the%20five%20checkpoints%20under%20their%20logical%20paths%2C%20checking%0A%20%20%20%20%20%20%20each%20resource's%20digest%3B%0A%20%20%20%202.%20submit%20and%20monitor%20the%20five%20fold%20tasks%2C%20with%20the%20spec%20mapper%20and%20GPU%20devices%20from%20Step%206%3B%0A%20%20%20%203.%20start%20the%20summarizer%20after%20every%20fold%20has%20succeeded%3B%0A%20%20%20%204.%20validate%20and%20decode%20the%20summarized%20result%20TSV%3B%20and%0A%20%20%20%205.%20write%20the%20resulting%20score%20rows%20to%20SQLite%20under%20this%20run's%20lineage.%0A%0A%20%20%20%20This%20button%20is%20the%20first%20operation%20that%20submits%20compute.%20Docker%20pulls%20the%203.4%20GB%20runtime%20image%20once%2C%20before%0A%20%20%20%20the%20first%20task%20starts.%20On%20an%20NVIDIA%20L40S%2C%20each%20fold%20takes%20about%20a%20minute%2C%20most%20of%20it%20start-up.%20With%20one%20GPU%0A%20%20%20%20device%20listed%20in%20Step%206%2C%20the%20five%20folds%20take%20turns%20on%20it%3B%20on%20the%20CPU%2C%20the%20five%20tutorial%20variants%20took%20about%20a%0A%20%20%20%20minute%20on%20a%2064-core%20server.%20When%20every%20variant%20is%20already%20scored%2C%20the%20button%20is%20disabled%20and%20Step%2013%20reads%0A%20%20%20%20the%20stored%20scores.%0A%0A%20%20%20%20Repeat%20GPU%20runs%20are%20not%20bit-identical.%20On%20an%20NVIDIA%20L40S%2C%20repeated%20runs%20differed%20by%20up%20to%203.4e-3%20in%0A%20%20%20%20%60counts_log2fc%60%20(%5BCherimoya%3A%20Compute%20and%0A%20%20%20%20scale%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fintegrations%2Fcherimoya%2F%23compute-and-scale)).%20Compare%20GPU%20scores%0A%20%20%20%20with%20a%20tolerance.%20CPU%20runs%20are%20byte-identical%20from%20run%20to%20run.%20For%20the%20five%20tutorial%20variants%2C%20CPU%20scores%0A%20%20%20%20differed%20from%20an%20earlier%20GPU%20run%20by%20up%20to%201.9e-3%2C%20within%20that%20tolerance.%20A%20stored%20score%20is%20reused%20as%20stored%2C%0A%20%20%20%20so%20rerunning%20this%20notebook%20reads%20the%20same%20numbers.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20preparation)%3A%0A%20%20%20%20run_model%20%3D%20mo.ui.run_button(%0A%20%20%20%20%20%20%20%20label%3D%22Run%20Cherimoya%20locally%22%2C%0A%20%20%20%20%20%20%20%20kind%3D%22success%22%2C%0A%20%20%20%20%20%20%20%20disabled%3Dnot%20preparation.batches%2C%0A%20%20%20%20%20%20%20%20tooltip%3D%22Stages%20the%20resources%20and%20submits%20the%20five%20CATv1%20fold%20tasks%20of%20each%20batch%20through%20Docker.%22%2C%0A%20%20%20%20)%0A%20%20%20%20run_model%0A%20%20%20%20return%20(run_model%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(execute%2C%20mo%2C%20preparation%2C%20run_model)%3A%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20bool(preparation.batches)%20and%20not%20(run_model.value%20or%20execute)%2C%0A%20%20%20%20%20%20%20%20mo.callout(%22Press%20**Run%20Cherimoya%20locally**%20to%20score%20the%20variants.%22%2C%20kind%3D%22info%22)%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20artifact_storage%2C%0A%20%20%20%20backend%2C%0A%20%20%20%20input_transfer_for%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_name%2C%0A%20%20%20%20output_transfer%2C%0A%20%20%20%20plugin%2C%0A%20%20%20%20preparation%2C%0A%20%20%20%20score_database%2C%0A%20%20%20%20spec_mapper%2C%0A)%3A%0A%20%20%20%20from%20altar.scoring%20import%20run_scoring%0A%0A%20%20%20%20batch_results%20%3D%20%5B%5D%0A%20%20%20%20with%20SqliteScoreStore(str(score_database)%2C%20lineages%3DTrue)%20as%20_scores%3A%0A%20%20%20%20%20%20%20%20for%20_batch%20in%20preparation.batches%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20with%20mo.status.spinner(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20title%3Df%22Scoring%20batch%20%7B_batch.request.scoring_batch%7D%3A%20%7B_batch.variant_count%7D%20variants%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_result%20%3D%20await%20run_scoring(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20plugin%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_batch.request%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20model_name%3Dmodel_name%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20score_store%3D_scores%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20backend%3Dbackend%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20storage%3Dartifact_storage%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20input_transfer%3Dinput_transfer_for(_batch)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20output_transfer%3Doutput_transfer%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20spec_mapper%3Dspec_mapper%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20batch_results.append(_result)%0A%20%20%20%20return%20(batch_results%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(batch_results%2C%20mo%2C%20preparation)%3A%0A%20%20%20%20if%20batch_results%3A%0A%20%20%20%20%20%20%20%20_summary%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22batch%22%3A%20batch.request.scoring_batch%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22variants%22%3A%20batch.variant_count%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22rows%20added%22%3A%20result.added%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22rows%20skipped%22%3A%20result.skipped%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20batch%2C%20result%20in%20zip(preparation.batches%2C%20batch_results%2C%20strict%3DTrue)%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20_output%20%3D%20mo.ui.table(_summary%2C%20selection%3DNone)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_output%20%3D%20mo.callout(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22No%20batch%20to%20run%3A%20all%20%7Bpreparation.cache_hit_count%7D%20eligible%20variants%20already%20have%20stored%20scores.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20kind%3D%22success%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20_output%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Step%2013%3A%20materialize%20a%20per-variant%20result%20table%0A%0A%20%20%20%20The%20scores%20are%20stored%20in%20a%20normalized%20form%20that%20can%20hold%20many%20models%20and%20annotation%20sources.%0A%20%20%20%20%60materialize()%60%20assembles%20them%20into%20one%20result%20per%20requested%20variant%2C%20and%20evaluates%20the%20default%0A%20%20%20%20prioritization%20rule%20from%20Step%203.%20Each%20model%20it%20reads%20is%20a%20%60ScoredModel%60%3A%20the%20model%20key%20and%20name%2C%20the%20plugin%2C%0A%20%20%20%20the%20run%20identity%2C%20and%20a%20reuse%20policy.%0A%0A%20%20%20%20A%20reuse%20policy%20says%20which%20lineages%20a%20read%20accepts.%20%60ScoreReusePolicy.exactly(...)%60%20accepts%20exactly%20the%0A%20%20%20%20lineages%20preparation%20checked%20in%20Step%209.%20The%20table%20therefore%20holds%20the%20scores%20preparation%20counted%20as%20already%0A%20%20%20%20scored%20and%20the%20scores%20Step%2012%20wrote.%20%60altar%20run%60%20reads%20its%20results%20back%20the%20same%20way.%0A%0A%20%20%20%20Materialization%20is%20a%20SQLite%20query%20over%20the%20stored%20rows.%20Tutorial%203%20uses%20the%20same%20operation%20to%20put%20these%0A%20%20%20%20scores%20beside%20published%20evidence.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20batch_results%2C%0A%20%20%20%20model_id%2C%0A%20%20%20%20model_name%2C%0A%20%20%20%20plugin%2C%0A%20%20%20%20preparation%2C%0A%20%20%20%20score_database%2C%0A%20%20%20%20variant_ids%2C%0A)%3A%0A%20%20%20%20from%20altar.results%20import%20ScoredModel%2C%20ScoreReusePolicy%0A%0A%20%20%20%20scored_model%20%3D%20ScoredModel(%0A%20%20%20%20%20%20%20%20model_id%3Dmodel_id%2C%0A%20%20%20%20%20%20%20%20model_name%3Dmodel_name%2C%0A%20%20%20%20%20%20%20%20plugin%3Dplugin%2C%0A%20%20%20%20%20%20%20%20plugin_identity%3Dpreparation.plugin_identity%2C%0A%20%20%20%20%20%20%20%20reuse_policy%3DScoreReusePolicy.exactly(preparation.resolution.lineage_ids)%2C%0A%20%20%20%20)%0A%20%20%20%20with%20SqliteScoreStore(str(score_database)%2C%20lineages%3DTrue)%20as%20_scores%3A%0A%20%20%20%20%20%20%20%20materialized%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20item%0A%20%20%20%20%20%20%20%20%20%20%20%20async%20for%20item%20in%20_scores.materialize(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20variant_ids%3Dvariant_ids%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20models%3D%5Bscored_model%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20annotation_sources%3D%5B%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20rows_added%20%3D%20sum(result.added%20for%20result%20in%20batch_results)%0A%20%20%20%20return%20materialized%2C%20rows_added%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(materialized)%3A%0A%20%20%20%20_rows%20%3D%20%5B%5D%0A%20%20%20%20for%20_result%20in%20materialized%3A%0A%20%20%20%20%20%20%20%20_item%20%3D%20asdict(_result)%0A%20%20%20%20%20%20%20%20_score%20%3D%20_item%5B%22model_scores%22%5D%5B0%5D%20if%20_item%5B%22model_scores%22%5D%20else%20%7B%7D%0A%20%20%20%20%20%20%20%20_rows.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22variant_id%22%3A%20_item%5B%22variant_id%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22counts_log2fc%22%3A%20_score.get(%22counts_log2fc%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22profile_l1%22%3A%20_score.get(%22profile_l1%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22default_prioritized%22%3A%20_score.get(%22prioritized%22%2C%20False)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prioritized_model_ids%22%3A%20_item%5B%22prioritized_model_ids%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20results%20%3D%20pd.DataFrame(_rows)%0A%20%20%20%20return%20(results%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20plugin%2C%20preparation%2C%20results%2C%20rows_added)%3A%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22**Run%20status%3A**%20%7Brows_added%7D%20rows%20added%20by%20this%20run%3B%20%7Bpreparation.cache_hit_count%7D%20variants%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22were%20already%20scored.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20Cherimoya's%20default%20predicate%20is%20%60%7Bplugin.prioritize_predicate().to_sql()%7D%60.%20Read%20the%20columns%20as%0A%20%20%20%20%20%20%20%20%20%20%20%20follows%3A%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20**%60counts_log2fc%60**%3A%20signed%20alternate-versus-reference%20effect%20on%20predicted%20counts%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20**%60profile_l1%60**%3A%20magnitude%20of%20the%20change%20in%20the%20normalized%20profile%20shape%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20**%60default_prioritized%60**%3A%20whether%20this%20model's%20default%20predicate%20evaluated%20to%20true%3B%20and%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20**%60prioritized_model_ids%60**%3A%20which%20model%20keys%20flagged%20the%20variant%2C%20useful%20once%20several%20models%20are%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20materialized%20together.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20Prioritization%20here%20means%20that%20the%20plugin's%20declared%20rule%20matched.%20It%20is%20not%2C%20by%20itself%2C%20a%0A%20%20%20%20%20%20%20%20%20%20%20%20pathogenicity%20or%20causal%20claim.%20K562%20accessibility%20may%20not%20change%20at%20loci%20that%20act%20in%20liver.%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(results%2C%20selection%3DNone)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Record%20the%20run%20for%20the%20next%20tutorials%0A%0A%20%20%20%20The%20last%20cell%20writes%20%60series.json%60%20in%20the%20work%20directory.%20It%20records%20the%20job%2C%20the%20cohort%2C%20the%20reference%0A%20%20%20%20genome's%20registry%20name%2C%20FASTA%20and%20digest%2C%20and%2C%20under%20the%20model%20key%2C%20the%20model%20name%2C%20the%20run%20identity%2C%20the%0A%20%20%20%20lineages%20preparation%20checked%2C%20and%20the%20resource%20manifest.%20Tutorials%202%2C%203%20and%204%20read%20it%20instead%20of%20asking%20you%20to%0A%20%20%20%20type%20the%20same%20values%20again.%20It%20is%20written%20only%20once%20the%20store%20holds%20scores%20for%20the%20cohort.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20genome_build%2C%0A%20%20%20%20job_id%2C%0A%20%20%20%20materialized%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_id%2C%0A%20%20%20%20model_name%2C%0A%20%20%20%20preparation%2C%0A%20%20%20%20reference%2C%0A%20%20%20%20reference_digest%2C%0A%20%20%20%20reference_entry%2C%0A%20%20%20%20reference_fasta%2C%0A%20%20%20%20resource_manifest%2C%0A%20%20%20%20variant_tsv%2C%0A%20%20%20%20work_dir%2C%0A)%3A%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20not%20any(variant.model_scores%20for%20variant%20in%20materialized)%2C%0A%20%20%20%20%20%20%20%20mo.callout(%22No%20variant%20has%20a%20Cherimoya%20score%20yet.%20Run%20Step%2012%20first.%22%2C%20kind%3D%22warn%22)%2C%0A%20%20%20%20)%0A%20%20%20%20series.write_series(%0A%20%20%20%20%20%20%20%20work_dir%2C%0A%20%20%20%20%20%20%20%20job_id%3Djob_id%2C%0A%20%20%20%20%20%20%20%20genome_build%3Dgenome_build%2C%0A%20%20%20%20%20%20%20%20cohort%3Dstr(variant_tsv)%2C%0A%20%20%20%20%20%20%20%20reference%3D%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20reference%20if%20reference_entry%20else%20None%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22entry%22%3A%20reference_entry%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22fasta%22%3A%20str(reference_fasta)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22digest%22%3A%20reference_digest%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20models%3D%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20model_id%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22model_name%22%3A%20model_name%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22plugin_identity%22%3A%20preparation.plugin_identity.to_dict()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22lineage_ids%22%3A%20list(preparation.resolution.lineage_ids)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22resource_manifest%22%3A%20str(resource_manifest)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20)%0A%20%20%20%20mo.callout(f%22Recorded%20this%20run%20in%20%60%7Bseries.display_path(work_dir%20%2F%20'series.json')%7D%60.%22%2C%20kind%3D%22success%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Review%20the%20workflow%0A%0A%20%20%20%20The%20complete%20path%20through%20Altar%20was%3A%0A%0A%20%20%20%20%60variant%20TSV%20%E2%86%92%20template%20request%20%E2%86%92%20preparation%20%E2%86%92%20portable%20plan%20%E2%86%92%20Docker%20tasks%20%E2%86%92%20SQLite%20scores%20%E2%86%92%20materialized%0A%20%20%20%20variants%60%0A%0A%20%20%20%20These%20pieces%20can%20vary%20independently.%20The%20same%20model%20configuration%20can%20score%20another%20cohort%3B%20logical%0A%20%20%20%20inputs%20can%20map%20to%20different%20storage%3B%20and%20another%20supported%20backend%20can%20execute%20the%20plan.%20The%20querying%0A%20%20%20%20interface%20remains%20the%20same%2C%20while%20the%20score%20store%20keeps%20the%20decoded%20values%20and%20the%20lineage%20that%20says%20which%0A%20%20%20%20computation%20produced%20them.%0A%0A%20%20%20%20Rerun%20the%20notebook%20with%20the%20same%20work%20directory.%20Step%209%20should%20find%20all%20five%20scores%20and%20prepare%20no%20batch%2C%0A%20%20%20%20and%20Step%2012%20runs%20nothing.%20Then%20select%20another%20canonical%20TSV%20in%20Step%201%3A%20variants%20already%20present%20in%20the%0A%20%20%20%20store%20are%20found%2C%20while%20new%20variants%20are%20packed%20into%20a%20batch%20for%20scoring.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20cache_dir%2C%0A%20%20%20%20genome_build%2C%0A%20%20%20%20gpu_pools%2C%0A%20%20%20%20job_id%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_id%2C%0A%20%20%20%20model_name%2C%0A%20%20%20%20reference%2C%0A%20%20%20%20reference_entry%2C%0A%20%20%20%20reference_fasta%2C%0A%20%20%20%20resource_manifest%2C%0A%20%20%20%20run_dir%2C%0A%20%20%20%20spec_mapper%2C%0A%20%20%20%20variant_tsv%2C%0A%20%20%20%20work_dir%2C%0A)%3A%0A%20%20%20%20_backend%20%3D%20%7B%22type%22%3A%20%22local%22%7D%0A%20%20%20%20if%20spec_mapper%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20_backend%5B%22cpu_only%22%5D%20%3D%20True%0A%20%20%20%20elif%20gpu_pools%3A%0A%20%20%20%20%20%20%20%20_backend%5B%22options%22%5D%20%3D%20%7B%22pools%22%3A%20gpu_pools%7D%0A%20%20%20%20run_spec%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22run%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22job_id%22%3A%20job_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22genome_build%22%3A%20genome_build%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22work_dir%22%3A%20str(run_dir)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22cache_dir%22%3A%20str(cache_dir)%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22variants%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22path%22%3A%20str(variant_tsv)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20**(%7B%22reference%22%3A%20reference%7D%20if%20reference_entry%20else%20%7B%22reference_fasta%22%3A%20str(reference_fasta)%7D)%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22models%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20model_id%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22CHERIMOYA%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22resource_manifest%22%3A%20str(resource_manifest)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22model_name%22%3A%20model_name%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22backend%22%3A%20_backend%2C%0A%20%20%20%20%7D%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%60altar%20run%60%20makes%20the%20same%20calls%20from%20a%20run%20spec.%20This%20spec%20scores%20the%20same%20cohort%20with%20the%20same%20model%0A%20%20%20%20%20%20%20%20%20%20%20%20key%2C%20reference%20and%20cache.%20%60altar%20run%60%20on%20it%20reports%20all%20five%20variants%20as%20already%20scored%20and%20runs%20no%0A%20%20%20%20%20%20%20%20%20%20%20%20task.%20Tutorial%203%20runs%20it%20with%20evidence%20sources%20added.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20The%20spec%20names%20no%20%60%5Bstore%5D%60%20and%20no%20%60data_root%60%3A%20%60altar%20run%60%20keeps%20its%20scores%20in%20%60scores.sqlite%60%20and%0A%20%20%20%20%20%20%20%20%20%20%20%20its%20container%20files%20in%20%60backend-data%2F%60%2C%20both%20in%20%60cache_dir%60%2C%20which%20is%20where%20this%20notebook%20put%20them.%0A%20%20%20%20%20%20%20%20%20%20%20%20%60reference%60%20names%20the%20fetched%20genome%3B%20the%20run%20reads%20it%20from%20the%20cache%20and%20takes%20its%20digest%20from%20the%0A%20%20%20%20%20%20%20%20%20%20%20%20registry%20entry.%20Started%20in%20%60%7Bseries.display_path(work_dir)%7D%60%2C%20%60altar%20run%60%20would%20also%20find%0A%20%20%20%20%20%20%20%20%20%20%20%20%60work_dir%60%20and%20%60cache_dir%60%20without%20the%20two%20lines%3A%20they%20are%20its%20defaults%20there%2C%20unless%0A%20%20%20%20%20%20%20%20%20%20%20%20%60ALTAR_CACHE_DIR%60%20names%20another%20cache.%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22%60%60%60toml%5Cn%7Bseries.spec_as_toml(run_spec)%7D%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20Next%2C%20tutorial%202%20adds%20hosted%20AlphaGenome%20predictions%20for%20the%20same%20cohort%3B%20it%20is%20optional%20and%20needs%0A%20%20%20%20%20%20%20%20%20%20%20%20an%20API%20key.%20Tutorial%203%20puts%20these%20scores%20beside%20published%20evidence%2C%20and%20tutorial%204%20writes%20your%20own%0A%20%20%20%20%20%20%20%20%20%20%20%20prioritization%20rule.%20For%20depth%2C%20see%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BCherimoya%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fintegrations%2Fcherimoya%2F)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BFind%20and%20fetch%20models%20and%20genomes%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fguides%2Fresources%2F)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BScore%20a%20cohort%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fpython%2Fscoring%2F)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BStore%20and%20assemble%20results%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fpython%2Fstores%2F)%2C%20and%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BScore%20reuse%20and%20provenance%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fscience%2Flineage%2F).%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
054e68589471c399091578be19712635