%23%20Copyright%202026%20Riya%20Sinha%0A%22%22%22Tutorial%202%3A%20add%20hosted%20AlphaGenome%20predictions%20to%20the%20tutorial%20cohort.%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%20json%0A%20%20%20%20from%20dataclasses%20import%20replace%0A%20%20%20%20from%20pathlib%20import%20Path%0A%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20from%20_series%20import%20(%0A%20%20%20%20%20%20%20%20ALPHAGENOME_MODEL_KEY%2C%0A%20%20%20%20%20%20%20%20CHERIMOYA_MODEL_KEY%2C%0A%20%20%20%20%20%20%20%20COHORT_TSV%2C%0A%20%20%20%20%20%20%20%20DETAIL_STORE%2C%0A%20%20%20%20%20%20%20%20GENOME_BUILD%2C%0A%20%20%20%20%20%20%20%20JOB_ID%2C%0A%20%20%20%20%20%20%20%20REPOSITORY_ROOT%2C%0A%20%20%20%20%20%20%20%20SCORE_STORE%2C%0A%20%20%20%20%20%20%20%20cache_dir%2C%0A%20%20%20%20%20%20%20%20display_path%2C%0A%20%20%20%20%20%20%20%20execute_requested%2C%0A%20%20%20%20%20%20%20%20read_series%2C%0A%20%20%20%20%20%20%20%20run_dir%2C%0A%20%20%20%20%20%20%20%20work_dir%2C%0A%20%20%20%20%20%20%20%20write_series%2C%0A%20%20%20%20)%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%202%20%C2%B7%20Add%20hosted%20predictions%20from%20AlphaGenome%0A%0A%20%20%20%20This%20tutorial%20scores%20the%20tutorial%20cohort%20with%20AlphaGenome%2C%20Google%20DeepMind's%20model%20of%20how%20a%20variant%20changes%0A%20%20%20%20genomic%20tracks%20such%20as%20DNase%20accessibility%20and%20RNA-seq%20coverage.%20Altar%20calls%20AlphaGenome's%20hosted%20API%20from%0A%20%20%20%20this%20notebook%2C%20one%20call%20per%20variant.%20Along%20the%20way%2C%20you%20will%20see%20how%20a%20hosted%20model%20differs%20from%20the%20container%0A%20%20%20%20model%20in%20Tutorial%201%3A%20it%20runs%20inside%20this%20Python%20process%2C%20it%20needs%20a%20credential%20instead%20of%20model%20weights%2C%20and%0A%20%20%20%20it%20returns%20a%20per-track%20table%20beside%20its%20one-row%20summary.%0A%0A%20%20%20%20By%20the%20end%2C%20you%20will%20be%20able%20to%3A%0A%0A%20%20%20%201.%20choose%20the%20scorers%20and%20tissues%20that%20define%20an%20AlphaGenome%20model%20instance%3B%0A%20%20%20%202.%20give%20the%20model%20a%20credential%20without%20writing%20the%20key%20into%20any%20file%3B%0A%20%20%20%203.%20find%20which%20variants%20still%20need%20an%20API%20call%20before%20making%20one%3B%0A%20%20%20%204.%20call%20the%20API%20once%20for%20the%20variants%20that%20need%20it%3B%0A%20%20%20%205.%20read%20the%20one-row%20summary%20and%20the%20per-track%20%60track_scores%60%20table%3B%20and%0A%20%20%20%206.%20put%20AlphaGenome%20beside%20Cherimoya%20and%20say%20what%20the%20comparison%20can%20and%20cannot%20show.%0A%0A%20%20%20%20This%20notebook%20builds%20on%20%5BTutorial%201%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fstart%2Fnotebooks%2F01_score_with_cherimoya.html)%2C%0A%20%20%20%20which%20scored%20the%20same%20five%20variants%20with%20Cherimoya.%20Tutorial%201%20is%20optional%20here.%20AlphaGenome%20reads%20no%20genome%0A%20%20%20%20file%2C%20so%20Steps%201%20to%208%20run%20without%20it%2C%20and%20Step%209%20says%20when%20there%20is%20nothing%20to%20compare.%0A%20%20%20%20%5BTutorial%203%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fstart%2Fnotebooks%2F03_join_evidence.html)%20then%20joins%20these%0A%20%20%20%20scores%20to%20published%20evidence.%0A%0A%20%20%20%20**Requirements%3A**%20Steps%207%20to%209%20need%20an%20AlphaGenome%20API%20key%20in%20the%20environment%20variable%0A%20%20%20%20%60ALPHAGENOME_API_KEY%60.%20Without%20one%2C%20the%20notebook%20runs%20Steps%201%20to%206%20and%20stops%20at%20the%20key%20check%20with%20what%20to%0A%20%20%20%20set.%20Unlike%20Tutorial%201%2C%20nothing%20here%20needs%20Docker%2C%20a%20GPU%20or%20a%20download.%20Each%20variant%20is%20one%20API%20call%20against%0A%20%20%20%20your%20quota%2C%20so%20the%20tutorial%20cohort%20uses%20five.%20The%20API%20is%20free%20for%20non-commercial%20research%20under%20the%0A%20%20%20%20%5BAlphaGenome%20Terms%20of%20Service%5D(https%3A%2F%2Falphagenome.google%2Fterms).%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%201%3A%20open%20the%20series%0A%0A%20%20%20%20The%20tutorials%20share%20one%20work%20directory.%20Tutorial%201%20wrote%20Cherimoya's%20scores%20to%20%60scores.sqlite%60%20in%20its%20cache%2C%0A%20%20%20%20%60.altar%2F%60%2C%20and%20recorded%20what%20it%20ran%20in%20%60series.json%60.%20This%20notebook%20adds%20AlphaGenome's%20scores%20to%20the%20same%0A%20%20%20%20store%2C%20so%20Step%209%20can%20read%20both%20models%20from%20one%20place.%0A%0A%20%20%20%20The%20directory%20defaults%20to%20%60~%2F.cache%2Faltar%2Ftutorials%2Fseries%60.%20Change%20it%20only%20if%20you%20gave%20Tutorial%201%20another%0A%20%20%20%20one%3A%20both%20notebooks%20must%20name%20the%20same%20directory.%0A%0A%20%20%20%20Keep%20the%20tutorial%20cohort%20for%20a%20first%20run.%20Every%20variant%20you%20add%20costs%20one%20API%20call.%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%3Ddisplay_path(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%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%3Ddisplay_path(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(%5Bwork_dir_input%2C%20variant_source%2C%20variant_path_input%5D)%0A%20%20%20%20return%20variant_path_input%2C%20variant_source%2C%20work_dir_input%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20variant_path_input%2C%20variant_source%2C%20work_dir_input)%3A%0A%20%20%20%20series_dir%20%3D%20Path(work_dir_input.value).expanduser().resolve()%0A%20%20%20%20series_dir.mkdir(parents%3DTrue%2C%20exist_ok%3DTrue)%0A%20%20%20%20series_cache%20%3D%20cache_dir(series_dir)%0A%20%20%20%20series_run_dir%20%3D%20run_dir(series_dir)%0A%20%20%20%20if%20variant_source.value%20%3D%3D%20%22bundled%22%3A%0A%20%20%20%20%20%20%20%20cohort_tsv%20%3D%20COHORT_TSV%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_typed%20%3D%20Path(variant_path_input.value).expanduser()%0A%20%20%20%20%20%20%20%20cohort_tsv%20%3D%20(_typed%20if%20_typed.is_absolute()%20else%20REPOSITORY_ROOT%20%2F%20_typed).resolve()%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20not%20cohort_tsv.is_file()%2C%0A%20%20%20%20%20%20%20%20mo.callout(f%22Variant%20TSV%20does%20not%20exist%3A%20%60%7Bdisplay_path(cohort_tsv)%7D%60%22%2C%20kind%3D%22danger%22)%2C%0A%20%20%20%20)%0A%20%20%20%20series%20%3D%20read_series(series_dir)%0A%20%20%20%20return%20cohort_tsv%2C%20series%2C%20series_cache%2C%20series_dir%2C%20series_run_dir%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20series)%3A%0A%20%20%20%20cherimoya_record%20%3D%20series.get(%22models%22%2C%20%7B%7D).get(CHERIMOYA_MODEL_KEY)%0A%20%20%20%20if%20cherimoya_record%3A%0A%20%20%20%20%20%20%20%20_series_status%20%3D%20mo.callout(%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%22Tutorial%201%20has%20run%20in%20this%20directory.%20It%20stored%20Cherimoya's%20scores%20under%20the%20model%20key%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%60%7BCHERIMOYA_MODEL_KEY%7D%60%2C%20and%20Step%209%20will%20read%20them%20beside%20AlphaGenome's.%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%20kind%3D%22success%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_series_status%20%3D%20mo.callout(%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%20%22Tutorial%201%20has%20not%20run%20in%20this%20directory%2C%20so%20it%20holds%20no%20Cherimoya%20scores.%20You%20can%20continue%3A%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22AlphaGenome%20needs%20no%20genome%20or%20model%20files.%20Step%209%20will%20skip%20the%20joint%20table.%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%20kind%3D%22info%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20_series_status%0A%20%20%20%20return%20(cherimoya_record%2C)%0A%0A%0A%40app.cell%0Adef%20_(cohort_tsv%2C%20mo)%3A%0A%20%20%20%20from%20altar.variants%20import%20load_variants%0A%0A%20%20%20%20variants%20%3D%20load_variants(str(cohort_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_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20run%20uses%20the%20series'%20identifiers%3A%0A%0A%20%20%20%20-%20%60job_id%60%20names%20this%20piece%20of%20work.%20It%20labels%20staged%20files%20and%20is%20not%20part%20of%20the%20stored%20scores'%20identity.%0A%20%20%20%20-%20%60model_key%60%20is%20the%20name%20AlphaGenome's%20rows%20are%20stored%20under.%20Tutorials%203%20and%204%20look%20for%20AlphaGenome's%0A%20%20%20%20%20%20scores%20under%20this%20key.%20Keep%20it%20while%20Step%202%20selects%20liver.%20When%20you%20choose%20other%20tissues%2C%20change%20the%20key%0A%20%20%20%20%20%20too%2C%20such%20as%20%60alphagenome-brain%60%2C%20so%20the%20name%20still%20says%20what%20the%20rows%20measure.%0A%20%20%20%20-%20%60model_name%60%20is%20the%20label%20shown%20in%20results.%0A%20%20%20%20-%20%60genome_build%60%20names%20the%20assembly%20of%20the%20variants'%20coordinates.%20AlphaGenome%20scores%20human%20variants%20on%20hg38.%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%20JOB_ID%0A%20%20%20%20model_key%20%3D%20ALPHAGENOME_MODEL_KEY%0A%20%20%20%20model_name%20%3D%20%22AlphaGenome%20liver%22%0A%20%20%20%20genome_build%20%3D%20GENOME_BUILD%0A%20%20%20%20return%20genome_build%2C%20job_id%2C%20model_key%2C%20model_name%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%202%3A%20choose%20scorers%20and%20tissues%0A%0A%20%20%20%20AlphaGenome%20predicts%20thousands%20of%20tracks%20for%20each%20variant%3A%20one%20per%20assay%2C%20tissue%20or%20cell%20type%2C%20and%20strand.%0A%20%20%20%20Two%20settings%20choose%20which%20of%20them%20Altar%20keeps%3A%0A%0A%20%20%20%20-%20%60scorers%60%20choose%20the%20kinds%20of%20output%2C%20such%20as%20%60DNASE%60%20for%20chromatin%20accessibility%20or%20%60RNA_SEQ%60%20for%20gene%0A%20%20%20%20%20%20expression.%20Each%20scorer%20compares%20the%20alternate%20allele's%20predicted%20tracks%20with%20the%20reference%20allele's.%0A%20%20%20%20-%20%60ontology_terms%60%20choose%20tissues%20and%20cell%20types%20by%20ontology%20ID.%20%60UBERON%3A0002107%60%20is%20liver.%20The%20API%20returns%0A%20%20%20%20%20%20every%20tissue%2C%20and%20Altar%20keeps%20the%20tracks%20whose%20%60ontology_curie%60%20is%20in%20this%20list.%0A%0A%20%20%20%20The%20defaults%2C%20DNase%20and%20RNA-seq%20in%20liver%2C%20suit%20this%20cohort.%20Most%20of%20its%20variants%20sit%20at%20liver%20and%20lipid%20loci%2C%0A%20%20%20%20such%20as%20the%20*SORT1*%20variant%20%60chr1%3A109274968%3AG%3AT%60.%20An%20empty%20scorer%20list%20asks%20for%20every%20recommended%20scorer.%20An%0A%20%20%20%20empty%20tissue%20list%20keeps%20every%20track%2C%20and%20the%20one-row%20summary%20in%20Step%208%20then%20takes%20its%20maximum%20over%20thousands%0A%20%20%20%20of%20tracks.%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%20scorer_input%20%3D%20mo.ui.multiselect(%0A%20%20%20%20%20%20%20%20options%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22ATAC%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22CAGE%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22CHIP_HISTONE%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22CHIP_TF%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22DNASE%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22POLYADENYLATION%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22PROCAP%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22RNA_SEQ%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22SPLICE_JUNCTIONS%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22SPLICE_SITES%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22SPLICE_SITE_USAGE%22%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20value%3D%5B%22DNASE%22%2C%20%22RNA_SEQ%22%5D%2C%0A%20%20%20%20%20%20%20%20label%3D%22Scorers%22%2C%0A%20%20%20%20)%0A%20%20%20%20tissue_input%20%3D%20mo.ui.text(%0A%20%20%20%20%20%20%20%20value%3D%22UBERON%3A0002107%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22Ontology%20terms%2C%20comma-separated%20(UBERON%3A0002107%20is%20liver)%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(%5Bscorer_input%2C%20tissue_input%5D)%0A%20%20%20%20return%20scorer_input%2C%20tissue_input%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(scorer_input%2C%20tissue_input)%3A%0A%20%20%20%20scorers%20%3D%20tuple(scorer_input.value)%0A%20%20%20%20ontology_terms%20%3D%20tuple(term.strip()%20for%20term%20in%20tissue_input.value.split(%22%2C%22)%20if%20term.strip())%0A%20%20%20%20return%20ontology_terms%2C%20scorers%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%20A%20model%20binding%20is%20the%20package%20that%20connects%20one%20model%20to%20Altar.%20%60AlphaGenomePlugin%60%20describes%20what%0A%20%20%20%20AlphaGenome%20returns%20and%20how%20to%20call%20it.%20It%20reduces%20each%20variant's%20kept%20tracks%20to%20one%20primary%20row%2C%20with%20the%0A%20%20%20%20columns%20below.%20It%20also%20stores%20each%20kept%20track%20as%20one%20row%20of%20a%20detail%20table%2C%20%60track_scores%60.%20Creating%20the%20plugin%0A%20%20%20%20loads%20only%20this%20description.%20The%20API%20client%20is%20created%20in%20Step%207.%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_alphagenome%20import%20AlphaGenomePlugin%0A%0A%20%20%20%20plugin%20%3D%20AlphaGenomePlugin()%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%20_track_schema%20%3D%20plugin.manifest.detail_schema(%22track_scores%22)%0A%20%20%20%20_outputs%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%7B%22table%22%3A%20%22primary%20row%22%2C%20%22column%22%3A%20field.name%2C%20%22type%22%3A%20field.dtype%2C%20%22meaning%22%3A%20field.meaning%7D%0A%20%20%20%20%20%20%20%20for%20field%20in%20plugin.manifest.result_schema.fields%0A%20%20%20%20%5D%0A%20%20%20%20_outputs.append(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22table%22%3A%20%22track_scores%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20f%22%7Blen(_track_schema.fields)%7D%20columns%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22one%20row%20per%20track%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22meaning%22%3A%20_track_schema.description%2C%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20)%0A%20%20%20%20mo.ui.table(pd.DataFrame(_outputs)%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%203%3A%20reference%20the%20credential%0A%0A%20%20%20%20AlphaGenome%20needs%20an%20API%20key.%20Altar%20never%20stores%20the%20key.%20The%20configuration%20holds%20a%20%60SecretReference%60%0A%20%20%20%20instead%3A%20a%20pointer%20that%20says%20where%20to%20find%20the%20key%20when%20the%20model%20runs.%20It%20has%20two%20parts%3A%0A%0A%20%20%20%20-%20%60provider%60%20names%20where%20the%20secret%20is%20kept.%20%60%22env%22%60%20means%20an%20environment%20variable.%0A%20%20%20%20-%20%60name%60%20names%20the%20variable%2C%20here%20%60ALPHAGENOME_API_KEY%60.%0A%0A%20%20%20%20When%20the%20model%20runs%2C%20a%20secret%20resolver%20turns%20the%20reference%20into%20the%20key.%20Step%207%20passes%0A%20%20%20%20%60EnvironmentSecretResolver%60%2C%20which%20reads%20the%20variable.%20%60altar%20run%60%20passes%20the%20same%20resolver.%0A%20%20%20%20%60EnvironmentSecretResolver%60%20is%20%5BProvisional%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Freference%2Fmaturity%2F)%3A%20it%0A%20%20%20%20works%20and%20is%20documented%2C%20and%20is%20expected%20to%20change.%0A%0A%20%20%20%20%60AlphaGenomeConfiguration%60%20combines%20the%20credential%20reference%20with%20the%20selection%20from%20Step%202.%20The%20table%20below%0A%20%20%20%20is%20the%20configuration%20as%20Altar%20saves%20it.%20The%20reference%20appears%20in%20it%2C%20and%20the%20key%20does%20not.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ontology_terms%2C%20scorers)%3A%0A%20%20%20%20from%20altar.models%20import%20SecretReference%0A%20%20%20%20from%20altar_alphagenome%20import%20AlphaGenomeConfiguration%0A%0A%20%20%20%20credential%20%3D%20SecretReference(provider%3D%22env%22%2C%20name%3D%22ALPHAGENOME_API_KEY%22)%0A%20%20%20%20configuration%20%3D%20AlphaGenomeConfiguration(%0A%20%20%20%20%20%20%20%20credential%3Dcredential%2C%0A%20%20%20%20%20%20%20%20scorers%3Dscorers%2C%0A%20%20%20%20%20%20%20%20ontology_terms%3Dontology_terms%2C%0A%20%20%20%20)%0A%20%20%20%20return%20AlphaGenomeConfiguration%2C%20SecretReference%2C%20configuration%2C%20credential%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(configuration%2C%20mo)%3A%0A%20%20%20%20_saved%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%7B%22field%22%3A%20field%2C%20%22value%22%3A%20json.dumps(value)%7D%20for%20field%2C%20value%20in%20configuration.to_dict().items()%5D%0A%20%20%20%20)%0A%20%20%20%20mo.ui.table(_saved%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%60model%60%2C%20%60sequence_length%60%20and%20%60organism%60%20keep%20their%20defaults%3A%20the%20hosted%20production%20model%2C%20a%201%20Mb%20window%0A%20%20%20%20centered%20on%20the%20variant%2C%20and%20human.%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%20build%20the%20request%0A%0A%20%20%20%20A%20%60ScoringRequest%60%20is%20the%20complete%20description%20of%20one%20model%20invocation.%20It%20names%20the%20job%2C%20the%20model%20key%2C%20the%0A%20%20%20%20configuration%20and%20the%20run%20inputs.%20AlphaGenome's%20run%20inputs%20are%20the%20genome%20build%20and%20the%20variants%20to%20score.%0A%20%20%20%20The%20request%20below%20is%20a%20template%20without%20variants.%20Step%205%20fills%20in%20the%20variants%20that%20need%20scoring.%0A%0A%20%20%20%20Tutorial%201's%20plan%20was%20a%20set%20of%20container%20tasks.%20AlphaGenome's%20binding%20returns%20an%20inline%20plan%20instead%3A%20a%0A%20%20%20%20function%20that%20runs%20in%20this%20Python%20process%20and%20calls%20the%20API.%20It%20needs%20no%20execution%20backend%2C%20no%20file%0A%20%20%20%20mapping%20and%20no%20reference%20FASTA.%20The%20request's%20%60resolver%60%20therefore%20stays%20the%20default%20%60PathResolver()%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(configuration%2C%20genome_build%2C%20job_id%2C%20model_key%2C%20plugin)%3A%0A%20%20%20%20from%20altar.execution%20import%20PathResolver%0A%20%20%20%20from%20altar.models%20import%20ScoringRequest%0A%20%20%20%20from%20altar_alphagenome%20import%20AlphaGenomeRunInputs%0A%0A%20%20%20%20template_request%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_key%2C%0A%20%20%20%20%20%20%20%20configuration%3Dconfiguration%2C%0A%20%20%20%20%20%20%20%20run_inputs%3DAlphaGenomeRunInputs(genome_build%3Dgenome_build)%2C%0A%20%20%20%20%20%20%20%20output%3Dplugin.default_output%2C%0A%20%20%20%20%20%20%20%20resolver%3DPathResolver()%2C%0A%20%20%20%20)%0A%20%20%20%20template_plan%20%3D%20plugin.build_scoring_plan(template_request)%0A%20%20%20%20return%20template_plan%2C%20template_request%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20template_plan)%3A%0A%20%20%20%20_identity%20%3D%20template_plan.plugin_identity%0A%20%20%20%20mo.ui.table(%0A%20%20%20%20%20%20%20%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%22field%22%3A%20%22plan%20type%22%2C%20%22value%22%3A%20type(template_plan).__name__%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%22field%22%3A%20%22executor%22%2C%20%22value%22%3A%20template_plan.executor%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%22field%22%3A%20%22plugin%22%2C%20%22value%22%3A%20f%22%7B_identity.plugin_id%7D%20%7B_identity.plugin_version%7D%22%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%22field%22%3A%20%22genome%20build%22%2C%20%22value%22%3A%20_identity.genome_build%7D%2C%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%22field%22%3A%20%22hosted%20model%20and%20SDK%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22%3B%20%22.join(runtime.identity%20for%20runtime%20in%20_identity.runtimes)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20selection%3DNone%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%20The%20plan%20carries%20the%20run's%20identity%3A%20the%20binding%2C%20the%20configuration%2C%20the%20genome%20build%2C%20and%20the%20hosted%20model%0A%20%20%20%20and%20SDK%20version.%20The%20score%20store%20groups%20stored%20rows%20by%20lineage.%20A%20lineage%20is%20one%20scientific%20setup%20of%20a%20model%3A%0A%20%20%20%20runs%20that%20would%20compute%20the%20same%20values%20share%20a%20lineage%20ID%2C%20and%20runs%20that%20would%20not%20get%20different%20ones.%0A%0A%20%20%20%20The%20table%20compares%20the%20lineage%20of%20your%20selection%20with%20a%20few%20variations.%20Scorers%20and%20tissues%20enter%20the%0A%20%20%20%20lineage%2C%20and%20their%20order%20does%20not.%20The%20credential%20reference%20does%20not%20enter%20it%20either%3A%20moving%20the%20key%20to%0A%20%20%20%20another%20variable%20keeps%20the%20stored%20scores%20reusable.%20Choosing%20other%20tissues%20makes%20a%20new%20lineage%2C%20which%20Step%205%0A%20%20%20%20would%20find%20unscored.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20AlphaGenomeConfiguration%2C%0A%20%20%20%20SecretReference%2C%0A%20%20%20%20configuration%2C%0A%20%20%20%20credential%2C%0A%20%20%20%20ontology_terms%2C%0A%20%20%20%20plugin%2C%0A%20%20%20%20scorers%2C%0A%20%20%20%20template_request%2C%0A)%3A%0A%20%20%20%20from%20altar.results%20import%20ScoreLineage%0A%0A%20%20%20%20def%20lineage_id(candidate)%3A%0A%20%20%20%20%20%20%20%20plan%20%3D%20plugin.build_scoring_plan(replace(template_request%2C%20configuration%3Dcandidate))%0A%20%20%20%20%20%20%20%20return%20ScoreLineage.from_run(plan.plugin_identity%2C%20plugin.score_columns()).lineage_id%0A%0A%20%20%20%20variations%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22your%20selection%22%3A%20configuration%2C%0A%20%20%20%20%20%20%20%20%22scorers%20in%20reverse%20order%22%3A%20AlphaGenomeConfiguration(%0A%20%20%20%20%20%20%20%20%20%20%20%20credential%3Dcredential%2C%20scorers%3Dtuple(reversed(scorers))%2C%20ontology_terms%3Dontology_terms%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%22key%20in%20another%20variable%22%3A%20AlphaGenomeConfiguration(%0A%20%20%20%20%20%20%20%20%20%20%20%20credential%3DSecretReference(provider%3D%22env%22%2C%20name%3D%22MY_ALPHAGENOME_KEY%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scorers%3Dscorers%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20ontology_terms%3Dontology_terms%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%22brain%20instead%20(UBERON%3A0000955)%22%3A%20AlphaGenomeConfiguration(%0A%20%20%20%20%20%20%20%20%20%20%20%20credential%3Dcredential%2C%20scorers%3Dscorers%2C%20ontology_terms%3D(%22UBERON%3A0000955%22%2C)%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%7D%0A%20%20%20%20variation_lineages%20%3D%20%7Bname%3A%20lineage_id(candidate)%20for%20name%2C%20candidate%20in%20variations.items()%7D%0A%20%20%20%20return%20(variation_lineages%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20variation_lineages)%3A%0A%20%20%20%20_yours%20%3D%20variation_lineages%5B%22your%20selection%22%5D%0A%20%20%20%20mo.ui.table(%0A%20%20%20%20%20%20%20%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%22setup%22%3A%20name%2C%20%22lineage_id%22%3A%20lineage%2C%20%22same%20lineage%20as%20yours%22%3A%20lineage%20%3D%3D%20_yours%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20name%2C%20lineage%20in%20variation_lineages.items()%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20selection%3DNone%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%205%3A%20find%20what%20needs%20scoring%0A%0A%20%20%20%20Before%20calling%20the%20API%2C%20ask%20the%20stores%20which%20variants%20they%20already%20hold.%20%60prepare_scoring_batches()%60%20reads%0A%20%20%20%20the%20cohort%20and%20drops%20repeated%20variants.%20It%20sets%20aside%20variants%20the%20model%20cannot%20score%20and%20looks%20up%20the%20rest.%0A%20%20%20%20A%20variant%20counts%20as%20stored%20only%20when%20its%20primary%20row%20and%20its%20%60track_scores%60%20rows%20are%20both%20present%20under%20an%0A%20%20%20%20accepted%20lineage.%20The%20remaining%20variants%20are%20packed%20into%20batches%2C%20and%20each%20batch%20becomes%20one%20request.%0A%0A%20%20%20%20This%20step%20opens%20two%20SQLite%20files%20in%20the%20series%20cache%2C%20%60.altar%2F%60%2C%20and%20creates%20them%20on%20a%20first%20run%3A%0A%0A%20%20%20%20-%20%60scores.sqlite%60%2C%20the%20score%20store%2C%20with%20lineages%20on.%20Tutorial%201%20wrote%20Cherimoya's%20rows%20here.%0A%20%20%20%20-%20%60scores.details.sqlite%60%2C%20the%20detail%20store%2C%20which%20holds%20%60track_scores%60.%20%60altar%20run%60%20keeps%20its%20details%20in%0A%20%20%20%20%20%20the%20same%20file%20beside%20its%20default%20store.%0A%0A%20%20%20%20The%20variant%20files%20preparation%20writes%20go%20under%20%60staging%2F%60%20in%20the%20run%20directory%2C%20as%20Tutorial%201's%20did.%0A%0A%20%20%20%20It%20reads%20only%20local%20files%20and%20makes%20no%20API%20call.%20On%20a%20first%20run%20every%20variant%20needs%20scoring.%20After%20Step%207%2C%0A%20%20%20%20a%20rerun%20finds%20them%20all%20stored.%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%20cohort_tsv%2C%0A%20%20%20%20plugin%2C%0A%20%20%20%20series_cache%2C%0A%20%20%20%20series_run_dir%2C%0A%20%20%20%20template_request%2C%0A)%3A%0A%20%20%20%20from%20altar.execution%20import%20LocalStorage%2C%20Transfer%0A%20%20%20%20from%20altar.results%20import%20SqliteDetailStore%2C%20SqliteScoreStore%0A%20%20%20%20from%20altar.scoring%20import%20prepare_scoring_batches%0A%0A%20%20%20%20score_database%20%3D%20series_cache%20%2F%20SCORE_STORE%0A%20%20%20%20detail_database%20%3D%20series_cache%20%2F%20DETAIL_STORE%0A%0A%20%20%20%20def%20_staged(transfer)%3A%0A%20%20%20%20%20%20%20%20return%20replace(transfer%2C%20uri%3Dstr(series_run_dir%20%2F%20%22staging%22%20%2F%20transfer.logical_path))%0A%0A%20%20%20%20with%20(%0A%20%20%20%20%20%20%20%20SqliteScoreStore(str(score_database)%2C%20lineages%3DTrue)%20as%20_scores%2C%0A%20%20%20%20%20%20%20%20SqliteDetailStore(str(detail_database))%20as%20_details%2C%0A%20%20%20%20)%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_request%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20candidate_variants%3DTransfer(uri%3Dstr(cohort_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%20detail_store%3D_details%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20storage%3DLocalStorage()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20destination_transfer%3D_staged%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20max_variants_per_batch%3D100%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20SqliteDetailStore%2C%0A%20%20%20%20%20%20%20%20SqliteScoreStore%2C%0A%20%20%20%20%20%20%20%20detail_database%2C%0A%20%20%20%20%20%20%20%20preparation%2C%0A%20%20%20%20%20%20%20%20score_database%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20preparation)%3A%0A%20%20%20%20_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%22count%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%22count%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%22count%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%22count%22%3A%20%22already%20stored%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%22count%22%3A%20%22need%20an%20API%20call%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%20_batches%20%3D%20len(preparation.batches)%0A%20%20%20%20_message%20%3D%20(%0A%20%20%20%20%20%20%20%20f%22%7Bpreparation.unscored_count%7D%20of%20%7Bpreparation.candidate_count%7D%20variants%20need%20an%20API%20call%2C%20in%20%22%0A%20%20%20%20%20%20%20%20f%22%7B_batches%7D%20%7B'batch'%20if%20_batches%20%3D%3D%201%20else%20'batches'%7D.%22%0A%20%20%20%20%20%20%20%20if%20preparation.unscored_count%0A%20%20%20%20%20%20%20%20else%20f%22All%20%7Bpreparation.candidate_count%7D%20variants%20are%20already%20stored.%20Step%207%20will%20make%20no%20API%20call.%22%0A%20%20%20%20)%0A%20%20%20%20mo.vstack(%5Bmo.callout(_message%2C%20kind%3D%22info%22)%2C%20mo.ui.table(_counts%2C%20selection%3DNone)%5D)%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%20check%20the%20key%0A%0A%20%20%20%20Step%207%20is%20the%20first%20operation%20that%20calls%20the%20API.%20Before%20it%2C%20check%20that%20the%20key%20is%20available.%20The%20check%0A%20%20%20%20asks%20the%20resolver%20Step%207%20uses%20and%20never%20displays%20the%20key.%20When%20every%20variant%20is%20already%20stored%2C%20no%20key%20is%0A%20%20%20%20needed%2C%20and%20the%20notebook%20goes%20on%20to%20read%20the%20stored%20rows.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(credential)%3A%0A%20%20%20%20from%20altar.access%20import%20EnvironmentSecretResolver%0A%0A%20%20%20%20secret_resolver%20%3D%20EnvironmentSecretResolver()%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20secret_resolver(credential)%0A%20%20%20%20except%20LookupError%20as%20error%3A%0A%20%20%20%20%20%20%20%20key_problem%20%3D%20str(error)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20key_problem%20%3D%20None%0A%20%20%20%20return%20key_problem%2C%20secret_resolver%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(key_problem%2C%20mo%2C%20preparation)%3A%0A%20%20%20%20needs_api%20%3D%20preparation.unscored_count%20%3E%200%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20needs_api%20and%20key_problem%20is%20not%20None%2C%0A%20%20%20%20%20%20%20%20mo.callout(%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%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%23%23%23%20Set%20your%20AlphaGenome%20API%20key%20to%20continue%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20AlphaGenome%20needs%20a%20key%20for%20the%20%7Bpreparation.unscored_count%7D%20variants%20Step%205%20found%20unscored%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20%60ALPHAGENOME_API_KEY%60%20is%20not%20set%20where%20marimo%20runs.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%201.%20Get%20an%20AlphaGenome%20API%20key%2C%20as%20the%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5BAlphaGenome%20repository%5D(https%3A%2F%2Fgithub.com%2Fgoogle-deepmind%2Falphagenome)%20describes.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%202.%20In%20a%20terminal%2C%20run%20%60export%20ALPHAGENOME_API_KEY%3D...%60%20with%20your%20key.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%203.%20Start%20marimo%20from%20that%20terminal%20and%20open%20this%20notebook%20again.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Steps%207%20to%209%20below%20describe%20what%20the%20call%20returns.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%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%20kind%3D%22warn%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20)%0A%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20%22The%20key%20is%20set.%22%20if%20needs_api%20else%20%22Every%20variant%20is%20stored%2C%20so%20this%20run%20needs%20no%20key.%22%2C%0A%20%20%20%20%20%20%20%20kind%3D%22success%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%20(needs_api%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%207%3A%20call%20the%20API%20and%20store%20the%20scores%0A%0A%20%20%20%20Press%20**Call%20AlphaGenome**%20to%20score%20the%20variants%20Step%205%20found.%20For%20each%20batch%2C%20%60run_scoring()%60%20will%3A%0A%0A%20%20%20%201.%20resolve%20%60ALPHAGENOME_API_KEY%60%20through%20the%20secret%20resolver%3B%0A%20%20%20%202.%20call%20the%20API%20once%20per%20variant%2C%20at%20most%20four%20calls%20at%20a%20time%3B%0A%20%20%20%203.%20keep%20the%20tracks%20of%20the%20tissues%20from%20Step%202%20and%20reduce%20them%20to%20one%20primary%20row%20per%20variant%3B%20and%0A%20%20%20%204.%20write%20the%20%60track_scores%60%20rows%20to%20the%20detail%20store%2C%20then%20the%20primary%20rows%20to%20the%20score%20store.%0A%0A%20%20%20%20This%20button%20is%20the%20first%20operation%20that%20uses%20your%20quota.%20The%20tutorial%20cohort%20takes%20five%20calls.%20A%20call%20that%0A%20%20%20%20fails%20leaves%20its%20variant%20unscored%20and%20logs%20a%20warning%2C%20and%20the%20next%20run%20calls%20again%20for%20that%20variant%20only.%0A%0A%20%20%20%20%60AlphaGenomeRuntime%60%20carries%20the%20resolver%20to%20the%20plan.%20It%20exists%20only%20while%20the%20notebook%20runs%2C%20and%20nothing%0A%20%20%20%20in%20it%20is%20stored.%20After%20the%20run%2C%20the%20notebook%20records%20the%20model%20key%20and%20lineage%20in%20%60series.json%60%2C%20where%0A%20%20%20%20Tutorials%203%20and%204%20find%20them.%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%20needs_api)%3A%0A%20%20%20%20call_api%20%3D%20mo.ui.run_button(%0A%20%20%20%20%20%20%20%20label%3D%22Call%20AlphaGenome%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%20needs_api%2C%0A%20%20%20%20%20%20%20%20tooltip%3D%22Calls%20the%20hosted%20AlphaGenome%20API%20once%20for%20each%20variant%20Step%205%20found%20unscored.%22%2C%0A%20%20%20%20)%0A%20%20%20%20call_api%0A%20%20%20%20return%20(call_api%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(call_api%2C%20mo%2C%20needs_api%2C%20preparation)%3A%0A%20%20%20%20mo.stop(needs_api%20and%20not%20(call_api.value%20or%20execute_requested(mo.cli_args())))%0A%20%20%20%20batches_to_call%20%3D%20preparation.batches%0A%20%20%20%20return%20(batches_to_call%2C)%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20SqliteDetailStore%2C%0A%20%20%20%20SqliteScoreStore%2C%0A%20%20%20%20batches_to_call%2C%0A%20%20%20%20detail_database%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%20secret_resolver%2C%0A)%3A%0A%20%20%20%20from%20altar.scoring%20import%20run_scoring%0A%20%20%20%20from%20altar_alphagenome%20import%20AlphaGenomeRuntime%0A%0A%20%20%20%20runtime%20%3D%20AlphaGenomeRuntime(secret_resolver%3Dsecret_resolver)%0A%20%20%20%20api_runs%20%3D%20%5B%5D%0A%20%20%20%20with%20(%0A%20%20%20%20%20%20%20%20SqliteScoreStore(str(score_database)%2C%20lineages%3DTrue)%20as%20_scores%2C%0A%20%20%20%20%20%20%20%20SqliteDetailStore(str(detail_database))%20as%20_details%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20for%20_batch%20in%20batches_to_call%3A%0A%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%20plugin%2C%0A%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%20model_name%3Dmodel_name%2C%0A%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%20detail_store%3D_details%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20runtime%3Druntime%2C%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%20api_runs.append(_result)%0A%20%20%20%20%23%20The%20identity%20the%20rows%20are%20stored%20under.%20With%20no%20call%2C%20it%20is%20the%20identity%20Step%205%20checked%20the%20stores%20against.%0A%20%20%20%20alphagenome_identity%20%3D%20api_runs%5B-1%5D.plugin_identity%20if%20api_runs%20else%20preparation.plugin_identity%0A%20%20%20%20return%20alphagenome_identity%2C%20api_runs%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(api_runs%2C%20mo%2C%20preparation)%3A%0A%20%20%20%20if%20api_runs%3A%0A%20%20%20%20%20%20%20%20_summary%20%3D%20mo.ui.table(%0A%20%20%20%20%20%20%20%20%20%20%20%20pd.DataFrame(%0A%20%20%20%20%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%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%20%20%20%20%22batch%22%3A%20index%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22variants%20called%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%20%20%20%20%22primary%20rows%20added%22%3A%20run.added%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22primary%20rows%20skipped%22%3A%20run.skipped%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22variants%20without%20rows%22%3A%20run.variants_without_rows%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22track_scores%20rows%20added%22%3A%20sum(detail.added%20for%20detail%20in%20run.details)%2C%0A%20%20%20%20%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%20%20%20%20%20for%20index%2C%20(batch%2C%20run)%20in%20enumerate(zip(preparation.batches%2C%20api_runs%2C%20strict%3DTrue))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%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%20selection%3DNone%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_summary%20%3D%20mo.callout(%22No%20API%20call%20was%20needed.%20Steps%208%20and%209%20read%20the%20stored%20rows.%22%2C%20kind%3D%22info%22)%0A%20%20%20%20_summary%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20alphagenome_identity%2C%0A%20%20%20%20model_key%2C%0A%20%20%20%20model_name%2C%0A%20%20%20%20ontology_terms%2C%0A%20%20%20%20preparation%2C%0A%20%20%20%20scorers%2C%0A%20%20%20%20series_dir%2C%0A)%3A%0A%20%20%20%20write_series(%0A%20%20%20%20%20%20%20%20series_dir%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_key%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%20alphagenome_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%22scorers%22%3A%20list(scorers)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ontology_terms%22%3A%20list(ontology_terms)%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%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%20read%20the%20summary%20row%20and%20the%20track%20table%0A%0A%20%20%20%20The%20score%20store%20holds%20one%20primary%20row%20per%20variant.%20To%20read%20it%2C%20assemble%20the%20results.%20A%20%60ScoredModel%60%20names%0A%20%20%20%20the%20model%20key%2C%20its%20binding%20and%20the%20identity%20whose%20rows%20to%20read.%20%60materialize()%60%20returns%20one%20result%20per%0A%20%20%20%20variant.%20%60ScoreReusePolicy.exactly(...)%60%20limits%20the%20read%20to%20the%20lineages%20Step%205%20checked.%20Rows%20from%20another%0A%20%20%20%20tissue%20selection%20stored%20under%20the%20same%20key%20stay%20out.%0A%0A%20%20%20%20Read%20the%20primary%20columns%20as%20follows%3A%0A%0A%20%20%20%20-%20%60top_output_type%60%20and%20%60top_track%60%20name%20the%20kept%20track%20with%20the%20largest%20absolute%20raw%20score.%0A%20%20%20%20-%20%60max_abs_raw_score%60%20is%20that%20track's%20absolute%20raw%20score%2C%20in%20its%20scorer's%20units.%20It%20has%20no%20sign.%0A%20%20%20%20-%20%60top_track_abs_quantile_score%60%20is%20the%20same%20track's%20absolute%20quantile%20score%2C%20from%200%20to%201.%20A%20quantile%20score%0A%20%20%20%20%20%20says%20how%20extreme%20the%20raw%20score%20is%20among%20AlphaGenome's%20scores%20for%20common%20variants%20on%20that%20track.%0A%20%20%20%20-%20%60max_abs_quantile_score%60%20is%20the%20largest%20absolute%20quantile%20score%20over%20all%20kept%20tracks.%20It%20may%20come%20from%0A%20%20%20%20%20%20another%20track.%0A%20%20%20%20-%20%60n_tracks_scored%60%20counts%20the%20kept%20tracks.%20It%20equals%20the%20variant's%20number%20of%20%60track_scores%60%20rows.%0A%0A%20%20%20%20%60prioritized%60%20reports%20the%20binding's%20default%20rule%3A%20%60max_abs_raw_score%20%3E%3D%200.5%60%20and%0A%20%20%20%20%60top_track_abs_quantile_score%20%3E%3D%200.9%60%2C%20both%20from%20the%20same%20track.%20This%20is%20a%20screening%20default%2C%20not%20a%0A%20%20%20%20calibrated%20clinical%20or%20causal%20threshold.%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%20SqliteScoreStore%2C%0A%20%20%20%20alphagenome_identity%2C%0A%20%20%20%20model_key%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%20alphagenome_model%20%3D%20ScoredModel(%0A%20%20%20%20%20%20%20%20model_key%2C%0A%20%20%20%20%20%20%20%20model_name%2C%0A%20%20%20%20%20%20%20%20plugin%2C%0A%20%20%20%20%20%20%20%20alphagenome_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%20alphagenome_results%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20result%0A%20%20%20%20%20%20%20%20%20%20%20%20async%20for%20result%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%5Balphagenome_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%20return%20(%0A%20%20%20%20%20%20%20%20ScoreReusePolicy%2C%0A%20%20%20%20%20%20%20%20ScoredModel%2C%0A%20%20%20%20%20%20%20%20alphagenome_model%2C%0A%20%20%20%20%20%20%20%20alphagenome_results%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(alphagenome_results%2C%20mo%2C%20plugin)%3A%0A%20%20%20%20_columns%20%3D%20%5Bfield.name%20for%20field%20in%20plugin.manifest.result_schema.fields%5D%0A%20%20%20%20_rows%20%3D%20%5B%5D%0A%20%20%20%20for%20_result%20in%20alphagenome_results%3A%0A%20%20%20%20%20%20%20%20_score%20%3D%20_result.model_scores%5B0%5D%20if%20_result.model_scores%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_result.variant_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20**%7Bcolumn%3A%20_score.get(column)%20for%20column%20in%20_columns%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prioritized%22%3A%20_score.get(%22prioritized%22%2C%20False)%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%20mo.ui.table(pd.DataFrame(_rows)%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%20The%20summary%20row%20describes%20one%20track%20per%20variant.%20The%20detail%20store%20holds%20every%20kept%20track%20as%20a%20row%20of%0A%20%20%20%20%60track_scores%60%2C%20and%20%60read_rows()%60%20returns%20them.%20The%20read%20below%20passes%20the%20summary's%20model%20key%20and%20lineage%0A%20%20%20%20IDs%2C%20so%20it%20reads%20the%20same%20selection.%0A%0A%20%20%20%20Each%20row%20names%20its%20scorer%2C%20its%20track%20and%20the%20biosample%20the%20track%20was%20measured%20in.%20%60RNA_SEQ%60%20rows%20also%20name%0A%20%20%20%20a%20gene%3A%20that%20scorer%20reports%20the%20effect%20on%20each%20nearby%20gene's%20expression.%20%60raw_score%60%20is%20the%20alternate%0A%20%20%20%20allele's%20effect%20on%20the%20track%2C%20and%20its%20sign%20gives%20the%20direction.%20%60quantile_score%60%20is%20its%20calibrated%0A%20%20%20%20counterpart.%0A%0A%20%20%20%20Choose%20a%20variant%20to%20see%20its%20tracks%2C%20ordered%20by%20absolute%20raw%20score.%20The%20*SORT1*%20variant%0A%20%20%20%20%60chr1%3A109274968%3AG%3AT%60%20is%20a%20well-studied%20liver%20regulatory%20variant%20to%20start%20with.%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%20SqliteDetailStore%2C%0A%20%20%20%20alphagenome_model%2C%0A%20%20%20%20detail_database%2C%0A%20%20%20%20variant_ids%2C%0A)%3A%0A%20%20%20%20with%20SqliteDetailStore(str(detail_database))%20as%20_details%3A%0A%20%20%20%20%20%20%20%20track_rows%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%20row%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20async%20for%20row%20in%20_details.read_rows(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20model_id%3Dalphagenome_model.model_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20detail_name%3D%22track_scores%22%2C%0A%20%20%20%20%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%20%20%20%20%20accepted_lineage_ids%3Dalphagenome_model.reuse_policy.accepted_lineage_ids%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%20%5D%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20return%20(track_rows%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20track_rows%2C%20variant_ids)%3A%0A%20%20%20%20track_variant%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20options%3Dvariant_ids%2C%0A%20%20%20%20%20%20%20%20value%3Dvariant_ids%5B0%5D%2C%0A%20%20%20%20%20%20%20%20label%3Df%22Variant%20(%7Blen(track_rows)%7D%20track%20rows%20across%20the%20cohort)%22%2C%0A%20%20%20%20)%0A%20%20%20%20track_variant%0A%20%20%20%20return%20(track_variant%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20track_rows%2C%20track_variant)%3A%0A%20%20%20%20_shown%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%22variant_scorer%22%2C%0A%20%20%20%20%20%20%20%20%22output_type%22%2C%0A%20%20%20%20%20%20%20%20%22biosample_name%22%2C%0A%20%20%20%20%20%20%20%20%22track_name%22%2C%0A%20%20%20%20%20%20%20%20%22track_strand%22%2C%0A%20%20%20%20%20%20%20%20%22gene_name%22%2C%0A%20%20%20%20%20%20%20%20%22raw_score%22%2C%0A%20%20%20%20%20%20%20%20%22quantile_score%22%2C%0A%20%20%20%20%5D%0A%20%20%20%20if%20track_rows.empty%3A%0A%20%20%20%20%20%20%20%20_tracks%20%3D%20mo.callout(%22The%20detail%20store%20holds%20no%20%60track_scores%60%20rows%20for%20this%20cohort.%22%2C%20kind%3D%22info%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_selected%20%3D%20track_rows%5Btrack_rows%5B%22variant_id%22%5D%20%3D%3D%20track_variant.value%5D%0A%20%20%20%20%20%20%20%20_selected%20%3D%20_selected.reindex(_selected%5B%22raw_score%22%5D.abs().sort_values(ascending%3DFalse).index)%0A%20%20%20%20%20%20%20%20_tracks%20%3D%20mo.vstack(%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%20mo.md(f%22%7Blen(_selected)%7D%20kept%20tracks%20for%20%60%7Btrack_variant.value%7D%60.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(_selected%5B%5Bcolumn%20for%20column%20in%20_shown%20if%20column%20in%20_selected%5D%5D%2C%20selection%3DNone)%2C%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_tracks%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%209%3A%20put%20AlphaGenome%20beside%20Cherimoya%0A%0A%20%20%20%20With%20both%20models%20in%20one%20store%2C%20%60materialize()%60%20assembles%20them%20into%20one%20result%20per%20variant.%20Each%20model%20gets%0A%20%20%20%20its%20own%20%60ScoredModel%60%20and%20keeps%20its%20own%20rule.%20%60prioritized_model_ids%60%20lists%20the%20models%20whose%20rule%20matched.%0A%0A%20%20%20%20Compare%20the%20two%20with%20care%2C%20because%20they%20answer%20different%20questions%3A%0A%0A%20%20%20%20-%20Cherimoya's%20%60counts_log2fc%60%20is%20the%20predicted%20change%20in%20DNase%20accessibility%20at%20the%20variant%20in%20K562%2C%20a%0A%20%20%20%20%20%20leukemia%20cell%20line.%20It%20is%20signed.%0A%20%20%20%20-%20AlphaGenome's%20%60max_abs_raw_score%60%20is%20the%20largest%20effect%20across%20the%20liver%20DNase%20and%20RNA-seq%20tracks.%20It%20has%0A%20%20%20%20%20%20no%20sign%2C%20and%20its%20units%20depend%20on%20the%20scorer%20of%20that%20track.%0A%0A%20%20%20%20The%20cell%20type%2C%20assays%2C%20units%20and%20sign%20differ%2C%20and%20each%20threshold%20was%20set%20for%20its%20own%20model.%20A%20variant%20that%0A%20%20%20%20one%20model%20flags%20and%20the%20other%20does%20not%20is%20expected%2C%20and%20agreement%20between%20them%20is%20not%20confirmation.%20The%0A%20%20%20%20liver%20tracks%20are%20the%20closer%20context%20for%20this%20cohort.%20Tutorial%201%20used%20K562%20because%20its%20checkpoints%20are%20the%0A%20%20%20%20validated%20ones.%20%5BComparing%20models%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fscience%2Fprioritization%2F%23comparing-models)%0A%20%20%20%20says%20when%20raw%20values%20can%20be%20compared.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cherimoya_record%2C%20mo)%3A%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20not%20cherimoya_record%2C%0A%20%20%20%20%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Tutorial%201%20has%20not%20stored%20Cherimoya%20scores%20in%20this%20work%20directory%2C%20so%20there%20is%20no%20joint%20table.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Run%20Tutorial%201%20with%20the%20same%20work%20directory%2C%20then%20rerun%20this%20notebook.%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)%0A%20%20%20%20from%20altar.models%20import%20PluginRunIdentity%0A%0A%20%20%20%20cherimoya_identity%20%3D%20PluginRunIdentity.from_dict(cherimoya_record%5B%22plugin_identity%22%5D)%0A%20%20%20%20cherimoya_lineage_ids%20%3D%20tuple(cherimoya_record%5B%22lineage_ids%22%5D)%0A%20%20%20%20cherimoya_name%20%3D%20cherimoya_record%5B%22model_name%22%5D%0A%20%20%20%20return%20cherimoya_identity%2C%20cherimoya_lineage_ids%2C%20cherimoya_name%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20ScoreReusePolicy%2C%0A%20%20%20%20ScoredModel%2C%0A%20%20%20%20SqliteScoreStore%2C%0A%20%20%20%20alphagenome_model%2C%0A%20%20%20%20cherimoya_identity%2C%0A%20%20%20%20cherimoya_lineage_ids%2C%0A%20%20%20%20cherimoya_name%2C%0A%20%20%20%20score_database%2C%0A%20%20%20%20variant_ids%2C%0A)%3A%0A%20%20%20%20from%20altar_cherimoya%20import%20CherimoyaPlugin%0A%0A%20%20%20%20cherimoya_model%20%3D%20ScoredModel(%0A%20%20%20%20%20%20%20%20CHERIMOYA_MODEL_KEY%2C%0A%20%20%20%20%20%20%20%20cherimoya_name%2C%0A%20%20%20%20%20%20%20%20CherimoyaPlugin()%2C%0A%20%20%20%20%20%20%20%20cherimoya_identity%2C%0A%20%20%20%20%20%20%20%20reuse_policy%3DScoreReusePolicy.exactly(cherimoya_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%20joint_results%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20result%0A%20%20%20%20%20%20%20%20%20%20%20%20async%20for%20result%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%5Bcherimoya_model%2C%20alphagenome_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%20return%20(joint_results%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(joint_results%2C%20mo%2C%20model_key)%3A%0A%20%20%20%20_rows%20%3D%20%5B%5D%0A%20%20%20%20for%20_result%20in%20joint_results%3A%0A%20%20%20%20%20%20%20%20_scores%20%3D%20%7Bscore%5B%22model_id%22%5D%3A%20score%20for%20score%20in%20_result.model_scores%7D%0A%20%20%20%20%20%20%20%20_cherimoya%20%3D%20_scores.get(CHERIMOYA_MODEL_KEY%2C%20%7B%7D)%0A%20%20%20%20%20%20%20%20_alphagenome%20%3D%20_scores.get(model_key%2C%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_result.variant_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cherimoya%20counts_log2fc%22%3A%20_cherimoya.get(%22counts_log2fc%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cherimoya%20prioritized%22%3A%20_cherimoya.get(%22prioritized%22%2C%20False)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22alphagenome%20max_abs_raw_score%22%3A%20_alphagenome.get(%22max_abs_raw_score%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22alphagenome%20top_track%22%3A%20_alphagenome.get(%22top_track%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22alphagenome%20prioritized%22%3A%20_alphagenome.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_result.prioritized_model_ids%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%20mo.ui.table(pd.DataFrame(_rows)%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%20Review%20the%20workflow%0A%0A%20%20%20%20The%20path%20through%20Altar%20was%3A%0A%0A%20%20%20%20%60scorers%20and%20tissues%20%E2%86%92%20configuration%20with%20a%20credential%20reference%20%E2%86%92%20inline%20plan%20%E2%86%92%20store%20check%20%E2%86%92%20API%20calls%20%E2%86%92%0A%20%20%20%20primary%20rows%20and%20track_scores%20%E2%86%92%20one%20result%20with%20both%20models%60%0A%0A%20%20%20%20Compared%20with%20Tutorial%201%2C%20the%20model%20ran%20inside%20this%20process.%20Nothing%20was%20staged%20for%20it%2C%20and%20no%20backend%20ran%0A%20%20%20%20it.%20The%20key%20stayed%20in%20the%20environment%3A%20the%20stores%20and%20%60series.json%60%20hold%20only%20the%20reference.%0A%0A%20%20%20%20Rerun%20the%20notebook%20with%20the%20same%20work%20directory.%20Step%205%20should%20find%20every%20variant%20stored%2C%20Step%206%20should%20need%0A%20%20%20%20no%20key%2C%20and%20Step%207%20should%20make%20no%20call.%20Then%20try%20another%20tissue%20in%20Step%202%2C%20after%20giving%20it%20its%20own%20model%20key%0A%20%20%20%20in%20Step%201.%20Step%204%20shows%20a%20new%20lineage%2C%20and%20Step%205%20finds%20every%20variant%20unscored%20for%20it.%0A%0A%20%20%20%20The%20same%20model%20as%20a%20section%20of%20an%20%60altar%20run%60%20spec%20has%20the%20same%20lineage%20as%20this%20notebook's%3A%0A%0A%20%20%20%20%60%60%60toml%0A%20%20%20%20%5Bmodels.alphagenome-liver%5D%0A%20%20%20%20type%20%3D%20%22ALPHAGENOME%22%0A%0A%20%20%20%20%5Bmodels.alphagenome-liver.configuration%5D%0A%20%20%20%20credential%20%3D%20%7B%20provider%20%3D%20%22env%22%2C%20name%20%3D%20%22ALPHAGENOME_API_KEY%22%20%7D%0A%20%20%20%20ontology_terms%20%3D%20%5B%22UBERON%3A0002107%22%5D%0A%20%20%20%20scorers%20%3D%20%5B%22DNASE%22%2C%20%22RNA_SEQ%22%5D%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20For%20more%20depth%2C%20see%20the%20%5BAlphaGenome%20page%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fintegrations%2Falphagenome%2F)%2C%0A%20%20%20%20%5BGive%20a%20hosted%20model%20its%20credentials%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fguides%2Fscore%2F%23give-a-hosted-model-its-credentials)%0A%20%20%20%20and%20%5BRead%20details%20and%20artifacts%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fguides%2Fresults%2F%23read-details-and-artifacts).%0A%0A%20%20%20%20%5BTutorial%203%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fstart%2Fnotebooks%2F03_join_evidence.html)%20puts%20these%20scores%0A%20%20%20%20beside%20published%20evidence%3A%20population%20frequency%2C%20clinical%20classifications%2C%20conservation%20and%20enhancer%E2%80%93gene%0A%20%20%20%20links.%20It%20adds%20AlphaGenome's%20columns%20when%20this%20store%20holds%20them.%0A%20%20%20%20%22%22%22)%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
f303a819fddce81e9123f693489eb122