%23%20Copyright%202026%20Riya%20Sinha%0A%22%22%22Tutorial%203%3A%20put%20stored%20model%20scores%20beside%20published%20evidence%2C%20then%20get%20the%20same%20table%20from%20a%20run%20spec.%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%20contextlib%0A%20%20%20%20from%20pathlib%20import%20Path%0A%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20pyarrow.parquet%20as%20pq%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%20CLINVAR_SOURCE%2C%0A%20%20%20%20%20%20%20%20COHORT_TSV%2C%0A%20%20%20%20%20%20%20%20E2G_SOURCE%2C%0A%20%20%20%20%20%20%20%20GENOME_BUILD%2C%0A%20%20%20%20%20%20%20%20GNOMAD_SOURCE%2C%0A%20%20%20%20%20%20%20%20JOB_ID%2C%0A%20%20%20%20%20%20%20%20PHYLOP_SOURCE%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%20SPLICEAI_SOURCE%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%20download_cache%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%20run_log%2C%0A%20%20%20%20%20%20%20%20spec_as_toml%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%203%20%C2%B7%20Put%20model%20scores%20beside%20evidence%0A%0A%20%20%20%20Tutorial%201%20stored%20Cherimoya's%20predictions%20for%20five%20variants.%20This%20tutorial%20reads%20them%20back%20and%20places%20them%0A%20%20%20%20beside%20what%20published%20datasets%20record%20about%20the%20same%20variants%3A%20how%20common%20each%20one%20is%20in%20gnomAD%2C%20how%20ClinVar%0A%20%20%20%20classifies%20it%2C%20how%20conserved%20its%20base%20is%2C%20and%20which%20genes%20its%20regulatory%20element%20is%20predicted%20to%20regulate.%20Along%0A%20%20%20%20the%20way%2C%20you%20will%20see%20which%20rule%20flagged%20each%20variant%2C%20and%20you%20will%20get%20the%20same%20table%20from%20a%20run%20spec%20without%0A%20%20%20%20scoring%20anything%20again.%0A%0A%20%20%20%20By%20the%20end%2C%20you%20will%20be%20able%20to%3A%0A%0A%20%20%20%201.%20open%20the%20score%20store%20from%20Tutorial%201%20and%20read%20its%20scores%20back%3B%0A%20%20%20%202.%20build%20annotation%20sources%20in%20Python%20for%20gnomAD%2C%20ClinVar%2C%20phyloP%20and%20Open%20Targets%20E2G%3B%0A%20%20%20%203.%20assemble%20scores%20and%20evidence%20into%20one%20result%20per%20variant%3B%0A%20%20%20%204.%20tell%20a%20model's%20reasons%20for%20flagging%20a%20variant%20from%20a%20source's%3B%0A%20%20%20%205.%20add%20a%20dataset%20you%20build%20yourself%2C%20with%20SpliceAI%20as%20the%20example%3B%20and%0A%20%20%20%206.%20produce%20the%20same%20table%20with%20%60altar.run.run%60%20from%20the%20same%20store.%0A%0A%20%20%20%20**Requirements%3A**%20the%20work%20directory%20of%20Tutorial%201%2C%20with%20its%20score%20store%20and%20%60series.json%60.%20Steps%201%20to%205%20need%0A%20%20%20%20network%20access%20and%20no%20GPU.%20They%20read%20a%20few%20megabytes%20of%20the%20published%20gnomAD%2C%20ClinVar%2C%20phyloP%20and%20Open%20Targets%0A%20%20%20%20copies%2C%20anonymously.%20Step%206%20needs%20a%20SpliceAI%20copy%20that%20you%20build%20from%20Illumina's%20licensed%20files%3B%20without%20one%2C%0A%20%20%20%20the%20step%20is%20skipped.%20Step%207%20configures%20Docker%20for%20the%20model%20but%20submits%20no%20task%2C%20because%20every%20variant%20is%0A%20%20%20%20already%20scored.%20If%20Tutorial%202%20stored%20AlphaGenome%20scores%2C%20the%20tables%20include%20them.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function(hide_code%3DTrue)%0Adef%20as_path(text%3A%20str)%20-%3E%20Path%3A%0A%20%20%20%20%22%22%22Read%20a%20path%20typed%20into%20the%20notebook%3A%20%60%60~%2F%60%60%20is%20the%20home%20directory%2C%20and%20a%20relative%20path%20is%20in%20the%20checkout.%22%22%22%0A%20%20%20%20path%20%3D%20Path(text.strip()).expanduser()%0A%20%20%20%20return%20path%20if%20path.is_absolute()%20else%20REPOSITORY_ROOT%20%2F%20path%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%20The%20tutorials%20share%20one%20work%20directory.%20Tutorial%201%20wrote%20its%20score%20store%20in%20the%20directory's%20cache%2C%0A%20%20%20%20%60.altar%2Fscores.sqlite%60%2C%20and%20a%20record%20of%20what%20it%20produced%2C%20%60series.json%60.%20This%20notebook%20reads%20both%2C%20and%20writes%0A%20%20%20%20its%20export%20to%20the%20run%20directory%2C%20%60altar-tutorials%2F%60.%20Keep%20the%20default%20unless%20you%20gave%20Tutorial%201%20another%0A%20%20%20%20directory.%20Passing%20%60--work-dir%20DIR%60%20on%20the%20command%20line%20sets%20it%20too.%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%20work_dir_input%0A%20%20%20%20return%20(work_dir_input%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20work_dir_input)%3A%0A%20%20%20%20series_dir%20%3D%20as_path(work_dir_input.value).resolve()%0A%20%20%20%20series%20%3D%20read_series(series_dir)%0A%20%20%20%20series_cache%20%3D%20cache_dir(series_dir)%0A%20%20%20%20score_store_path%20%3D%20series_cache%20%2F%20SCORE_STORE%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20CHERIMOYA_MODEL_KEY%20not%20in%20series.get(%22models%22%2C%20%7B%7D)%20or%20not%20score_store_path.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%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%60%7Bdisplay_path(series_dir)%7D%60%20holds%20no%20Cherimoya%20scores%20from%20Tutorial%201.%20Run%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%6001_score_with_cherimoya.py%60%20with%20this%20work%20directory%20first%2C%20or%20enter%20the%20directory%20you%20used.%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%20cherimoya_record%20%3D%20series%5B%22models%22%5D%5BCHERIMOYA_MODEL_KEY%5D%0A%20%20%20%20alphagenome_record%20%3D%20series%5B%22models%22%5D.get(ALPHAGENOME_MODEL_KEY)%0A%20%20%20%20cohort_tsv%20%3D%20Path(series.get(%22cohort%22%2C%20COHORT_TSV))%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20alphagenome_record%2C%0A%20%20%20%20%20%20%20%20cherimoya_record%2C%0A%20%20%20%20%20%20%20%20cohort_tsv%2C%0A%20%20%20%20%20%20%20%20score_store_path%2C%0A%20%20%20%20%20%20%20%20series%2C%0A%20%20%20%20%20%20%20%20series_cache%2C%0A%20%20%20%20%20%20%20%20series_dir%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20alphagenome_record%2C%0A%20%20%20%20cherimoya_record%2C%0A%20%20%20%20cohort_tsv%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20score_store_path%2C%0A%20%20%20%20series%2C%0A)%3A%0A%20%20%20%20_settings%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%22model%20key%22%2C%20%22value%22%3A%20CHERIMOYA_MODEL_KEY%2C%20%22role%22%3A%20%22names%20Cherimoya's%20rows%20in%20the%20store%22%7D%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%22setting%22%3A%20%22lineage%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22%2C%20%22.join(cherimoya_record%5B%22lineage_ids%22%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22the%20setup%20Tutorial%201%20scored%20with%22%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%20%20%20%20%7B%22setting%22%3A%20%22score%20store%22%2C%20%22value%22%3A%20display_path(score_store_path)%2C%20%22role%22%3A%20%22where%20the%20scores%20are%22%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22setting%22%3A%20%22cohort%22%2C%20%22value%22%3A%20display_path(cohort_tsv)%2C%20%22role%22%3A%20%22the%20variants%20Tutorial%201%20scored%22%7D%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%22setting%22%3A%20%22reference%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20series%5B%22reference%22%5D.get(%22name%22)%20or%20display_path(series%5B%22reference%22%5D%5B%22fasta%22%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22the%20genome%20Tutorial%201%20used%22%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%20%20%20%20%7B%22setting%22%3A%20%22job%20ID%22%2C%20%22value%22%3A%20JOB_ID%2C%20%22role%22%3A%20%22names%20the%20run's%20staged%20files%20in%20Step%207%22%7D%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%22setting%22%3A%20%22AlphaGenome%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20ALPHAGENOME_MODEL_KEY%20if%20alphagenome_record%20else%20%22not%20stored%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22added%20when%20Tutorial%202%20stored%20its%20scores%22%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(%22These%20values%20come%20from%20%60series.json%60.%20Check%20that%20they%20describe%20the%20run%20you%20made%20in%20Tutorial%201.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(_settings%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%201%3A%20read%20the%20stored%20scores%20back%0A%0A%20%20%20%20A%20score%20store%20keeps%20every%20model's%20predictions%20between%20runs.%20Tutorial%201%20wrote%20Cherimoya's%20scores%20into%0A%20%20%20%20%60scores.sqlite%60%20under%20the%20model%20key%20%60k562-dnase%60.%20The%20store%20also%20records%20each%20row's%20lineage%3A%20an%20ID%20for%20the%0A%20%20%20%20exact%20setup%20that%20produced%20it%2C%20from%20the%20checkpoints%20and%20runtime%20image%20to%20the%20genome%20and%20the%20scoring%20settings.%0A%0A%20%20%20%20To%20read%20the%20scores%2C%20describe%20the%20model%20with%20a%20%60ScoredModel%60%3A%0A%0A%20%20%20%20-%20%60model_id%60%20is%20the%20model%20key%3B%0A%20%20%20%20-%20%60plugin%60%20is%20the%20binding%2C%20which%20knows%20the%20score%20columns%20and%20the%20default%20rule%3B%0A%20%20%20%20-%20%60plugin_identity%60%20is%20the%20run%20identity%20that%20Tutorial%201%20recorded%20in%20%60series.json%60%3B%0A%20%20%20%20-%20%60reuse_policy%60%20says%20which%20lineages%20to%20read.%20%60ScoreReusePolicy.exactly(...)%60%20reads%20only%20the%20lineages%20Tutorial%201%0A%20%20%20%20%20%20checked%20the%20store%20against.%0A%0A%20%20%20%20%60materialize()%60%20then%20assembles%20one%20result%20per%20variant%20from%20the%20store.%20With%20no%20annotation%20sources%20yet%2C%20each%0A%20%20%20%20result%20holds%20only%20the%20model's%20scores.%20Check%20that%20every%20variant%20has%20a%20score%3A%20Step%207%20relies%20on%20it.%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%20alphagenome_record%2C%0A%20%20%20%20cherimoya_record%2C%0A%20%20%20%20cohort_tsv%2C%0A%20%20%20%20score_store_path%2C%0A)%3A%0A%20%20%20%20from%20altar.models%20import%20PluginRunIdentity%0A%20%20%20%20from%20altar.results%20import%20ScoredModel%2C%20ScoreReusePolicy%2C%20SqliteScoreStore%0A%20%20%20%20from%20altar.variants%20import%20load_variants%0A%20%20%20%20from%20altar_cherimoya%20import%20CherimoyaPlugin%0A%0A%20%20%20%20variant_ids%20%3D%20load_variants(str(cohort_tsv))%5B%22variant_id%22%5D.tolist()%0A%20%20%20%20models%20%3D%20%5B%0A%20%20%20%20%20%20%20%20ScoredModel(%0A%20%20%20%20%20%20%20%20%20%20%20%20model_id%3DCHERIMOYA_MODEL_KEY%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20model_name%3Dcherimoya_record%5B%22model_name%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20plugin%3DCherimoyaPlugin()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20plugin_identity%3DPluginRunIdentity.from_dict(cherimoya_record%5B%22plugin_identity%22%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20reuse_policy%3DScoreReusePolicy.exactly(cherimoya_record%5B%22lineage_ids%22%5D)%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%5D%0A%20%20%20%20if%20alphagenome_record%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20from%20altar_alphagenome%20import%20AlphaGenomePlugin%0A%0A%20%20%20%20%20%20%20%20models.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20ScoredModel(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20model_id%3DALPHAGENOME_MODEL_KEY%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20model_name%3Dalphagenome_record%5B%22model_name%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20plugin%3DAlphaGenomePlugin()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20plugin_identity%3DPluginRunIdentity.from_dict(alphagenome_record%5B%22plugin_identity%22%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20reuse_policy%3DScoreReusePolicy.exactly(alphagenome_record%5B%22lineage_ids%22%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20with%20SqliteScoreStore(str(score_store_path))%20as%20_store%3A%0A%20%20%20%20%20%20%20%20stored%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20result%20async%20for%20result%20in%20_store.materialize(variant_ids%3Dvariant_ids%2C%20models%3Dmodels%2C%20annotation_sources%3D%5B%5D)%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20return%20SqliteScoreStore%2C%20models%2C%20stored%2C%20variant_ids%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20models%2C%20stored)%3A%0A%20%20%20%20def%20model_score(result%2C%20model_key)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Return%20one%20model's%20score%20entry%20for%20a%20result%2C%20or%20an%20empty%20dict%20when%20the%20store%20has%20none.%22%22%22%0A%20%20%20%20%20%20%20%20return%20next((entry%20for%20entry%20in%20result.model_scores%20if%20entry%5B%22model_id%22%5D%20%3D%3D%20model_key)%2C%20%7B%7D)%0A%0A%20%20%20%20unscored%20%3D%20%7B%0A%20%20%20%20%20%20%20%20model.model_id%3A%20%5Bresult.variant_id%20for%20result%20in%20stored%20if%20not%20model_score(result%2C%20model.model_id)%5D%0A%20%20%20%20%20%20%20%20for%20model%20in%20models%0A%20%20%20%20%7D%0A%20%20%20%20_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%22variant_id%22%3A%20result.variant_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22counts_log2fc%22%3A%20model_score(result%2C%20CHERIMOYA_MODEL_KEY).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%20model_score(result%2C%20CHERIMOYA_MODEL_KEY).get(%22profile_l1%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%20result%20in%20stored%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20_missing%20%3D%20%7Bkey%3A%20ids%20for%20key%2C%20ids%20in%20unscored.items()%20if%20ids%7D%0A%20%20%20%20_status%20%3D%20(%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%20%22Some%20variants%20have%20no%20stored%20score%3A%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20%22%3B%20%22.join(f%22%60%7Bkey%7D%60%20lacks%20%7B'%2C%20'.join(ids)%7D%22%20for%20key%2C%20ids%20in%20_missing.items())%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20%22.%20Rerun%20the%20tutorial%20that%20scores%20that%20model%20with%20this%20cohort%20and%20work%20directory.%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)%0A%20%20%20%20%20%20%20%20if%20_missing%0A%20%20%20%20%20%20%20%20else%20mo.callout(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22All%20%7Blen(stored)%7D%20variants%20have%20stored%20scores%20for%20%7B'%2C%20'.join(f'%60%7Bkey%7D%60'%20for%20key%20in%20unscored)%7D.%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)%0A%20%20%20%20mo.vstack(%5B_status%2C%20mo.ui.table(_table%2C%20selection%3DNone)%5D)%0A%20%20%20%20return%20model_score%2C%20unscored%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%20build%20the%20evidence%20sources%0A%0A%20%20%20%20An%20annotation%20source%20looks%20variants%20up%20in%20a%20dataset%20that%20someone%20else%20published%2C%20such%20as%20gnomAD.%20It%20runs%20no%0A%20%20%20%20model.%20Each%20source%20declares%3A%0A%0A%20%20%20%20-%20its%20columns%2C%20such%20as%20%60gnomad_af%60%3B%0A%20%20%20%20-%20its%20release%20identity%3A%20the%20dataset%2C%20its%20release%20and%20its%20genome%20build%3B%0A%20%20%20%20-%20optionally%2C%20a%20rule%20that%20flags%20variants%2C%20as%20a%20model's%20rule%20does.%0A%0A%20%20%20%20The%20registry%20finds%20an%20installed%20source%20by%20the%20name%20a%20run%20spec%20gives%20as%20its%20%60type%60.%20%60from_keywords()%60%20takes%20the%0A%20%20%20%20same%20options%20as%20the%20spec's%20%60%5Bsources.%3Cname%3E.options%5D%60.%20With%20no%20options%2C%20the%20gnomAD%2C%20ClinVar%2C%20phyloP%20and%20Open%0A%20%20%20%20Targets%20E2G%20sources%20read%20the%20copies%20the%20Kundaje%20lab%20publishes%20in%20a%20public%20bucket%2C%20with%20no%20credentials.%0A%0A%20%20%20%20Two%20of%20the%20sources%20get%20a%20rule%3A%0A%0A%20%20%20%20-%20ClinVar's%20%60prioritize_pathogenic%3DTrue%60%20flags%20a%20pathogenic%20or%20likely%20pathogenic%20classification%20with%20at%20least%0A%20%20%20%20%20%20one%20review%20star.%20It%20is%20ClinVar's%20own%20rule%2C%20off%20by%20default.%0A%20%20%20%20-%20Open%20Targets%20E2G%20has%20no%20rule%20of%20its%20own.%20In%20Python%2C%20%60prioritize_predicate%60%20gives%20it%20one.%20Here%20it%20flags%20a%0A%20%20%20%20%20%20variant%20whose%20regulatory%20element%20has%20a%20gene%20link%20scored%20at%20least%200.8.%20This%20threshold%20demonstrates%20a%20source%0A%20%20%20%20%20%20rule%3B%20it%20is%20not%20a%20calibrated%20cutoff.%20A%20run%20spec%20cannot%20hold%20such%20a%20rule%2C%20so%20Step%207%20passes%20this%20source%20to%20the%0A%20%20%20%20%20%20run%20in%20code.%0A%0A%20%20%20%20%60name%3DE2G_SOURCE%60%20names%20the%20source%20%60e2g%60%20in%20the%20reasons%20a%20result%20lists.%20%60open_sources()%60%20builds%20a%20fresh%20set%20of%0A%20%20%20%20sources%20each%20time%20it%20is%20called%2C%20and%20each%20step%20that%20reads%20them%20closes%20them%20when%20it%20finishes.%20Step%207%20builds%20the%0A%20%20%20%20E2G%20source%20alone%2C%20with%20%60open_e2g()%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%20from%20altar.predicates%20import%20Col%2C%20Ge%2C%20Lit%0A%20%20%20%20from%20altar.sources%20import%20get_annotation_source_registry%0A%0A%20%20%20%20registry%20%3D%20get_annotation_source_registry()%0A%20%20%20%20e2g_rule%20%3D%20Ge(Col(%22link_top_score%22)%2C%20Lit(0.8))%0A%0A%20%20%20%20def%20open_e2g()%3A%0A%20%20%20%20%20%20%20%20return%20registry.get(%22opentargets_e2g%22).from_keywords(name%3DE2G_SOURCE%2C%20prioritize_predicate%3De2g_rule)%0A%0A%20%20%20%20def%20open_sources()%3A%0A%20%20%20%20%20%20%20%20return%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20registry.get(%22gnomad%22).from_keywords()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20registry.get(%22clinvar%22).from_keywords(prioritize_pathogenic%3DTrue)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20registry.get(%22phylop100way%22).from_keywords()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20open_e2g()%2C%0A%20%20%20%20%20%20%20%20%5D%0A%0A%20%20%20%20return%20open_e2g%2C%20open_sources%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%20Building%20a%20source%20opens%20its%20published%20copy%20and%20reads%20its%20metadata.%20Press%20**Open%20the%20published%20sources**%20to%0A%20%20%20%20build%20them%20and%20see%20what%20each%20one%20serves.%20The%20lookups%20in%20Step%203%20then%20read%20only%20the%20parts%20of%20each%20dataset%20that%0A%20%20%20%20the%20five%20variants%20fall%20in.%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%20open_button%20%3D%20mo.ui.run_button(label%3D%22Open%20the%20published%20sources%22%2C%20kind%3D%22success%22)%0A%20%20%20%20open_button%0A%20%20%20%20return%20(open_button%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20open_button%2C%20open_sources)%3A%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20not%20(open_button.value%20or%20execute_requested(mo.cli_args()))%2C%0A%20%20%20%20%20%20%20%20mo.md(%22Press%20**Open%20the%20published%20sources**%20to%20continue.%22)%2C%0A%20%20%20%20)%0A%20%20%20%20with%20contextlib.ExitStack()%20as%20_stack%3A%0A%20%20%20%20%20%20%20%20_sources%20%3D%20%5B_stack.enter_context(source)%20for%20source%20in%20open_sources()%5D%0A%20%20%20%20%20%20%20%20source_table%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%22name%22%3A%20source.name%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22release%22%3A%20source.identity().release%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22genome_build%22%3A%20source.identity().genome_build%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22columns%22%3A%20len(source.annotation_contract().columns)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22rule%22%3A%20%22none%22%20if%20source.prioritize_predicate()%20is%20None%20else%20source.prioritize_predicate().to_sql()%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%20source%20in%20_sources%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%20mo.ui.table(source_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%20Check%20the%20release%20of%20each%20source%3A%20it%20is%20part%20of%20the%20result's%20provenance%2C%20and%20Step%207's%20export%20records%20it.%20phyloP%0A%20%20%20%20keeps%20its%20own%20name%2C%20%60phylop100way%60%2C%20here%20and%20in%20Step%207%2C%20where%20its%20section%20is%20%60%5Bsources.phylop%5D%60%3A%20a%20source%0A%20%20%20%20reports%20the%20name%20it%20was%20built%20with%2C%20not%20the%20name%20of%20its%20spec%20section.%20It%20has%20no%20rule%2C%20so%20no%20result%20lists%20it%0A%20%20%20%20among%20its%20reasons.%0A%0A%20%20%20%20%23%23%20Step%203%3A%20assemble%20scores%20and%20evidence%0A%0A%20%20%20%20%60materialize()%60%20now%20joins%20the%20evidence.%20For%20each%20variant%20it%20reads%20the%20model's%20stored%20scores%2C%20looks%20the%20variant%0A%20%20%20%20up%20in%20every%20source%2C%20merges%20the%20sources'%20columns%20into%20%60annotations%60%2C%20and%20evaluates%20every%20rule.%20Nothing%20is%20scored%3A%0A%20%20%20%20the%20model's%20values%20come%20from%20the%20store.%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%20mo%2C%0A%20%20%20%20models%2C%0A%20%20%20%20open_button%2C%0A%20%20%20%20open_sources%2C%0A%20%20%20%20score_store_path%2C%0A%20%20%20%20variant_ids%2C%0A)%3A%0A%20%20%20%20mo.stop(not%20(open_button.value%20or%20execute_requested(mo.cli_args())))%0A%20%20%20%20with%20contextlib.ExitStack()%20as%20_stack%3A%0A%20%20%20%20%20%20%20%20_sources%20%3D%20%5B_stack.enter_context(source)%20for%20source%20in%20open_sources()%5D%0A%20%20%20%20%20%20%20%20with%20SqliteScoreStore(str(score_store_path))%20as%20_store%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20assembled%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20result%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20async%20for%20result%20in%20_store.materialize(%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%20models%3Dmodels%2C%20annotation_sources%3D_sources%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%20return%20(assembled%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(assembled%2C%20mo%2C%20model_score)%3A%0A%20%20%20%20_evidence%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%22variant_id%22%3A%20result.variant_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22counts_log2fc%22%3A%20model_score(result%2C%20CHERIMOYA_MODEL_KEY).get(%22counts_log2fc%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22gnomad_af%22%3A%20result.annotations.get(%22gnomad_af%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clinvar_classification%22%3A%20result.annotations.get(%22clinvar_classification%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22phylop100way%22%3A%20result.annotations.get(%22phylop100way%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22link_top_gene%22%3A%20result.annotations.get(%22link_top_gene%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22link_gene_count%22%3A%20result.annotations.get(%22link_gene_count%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%20result%20in%20assembled%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20dtype%3Dobject%2C%0A%20%20%20%20)%0A%20%20%20%20_common_frequency%20%3D%200.01%0A%20%20%20%20_common%20%3D%20sum(1%20for%20value%20in%20_evidence%5B%22gnomad_af%22%5D%20if%20value%20is%20not%20None%20and%20value%20%3E%3D%20_common_frequency)%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.ui.table(_evidence%2C%20selection%3DNone)%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%20Read%20the%20columns%20as%20follows%3A%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20%60counts_log2fc%60%3A%20Cherimoya's%20predicted%20log2%20change%20in%20K562%20accessibility%2C%20alternate%20minus%20reference.%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20%60gnomad_af%60%3A%20the%20alternate%20allele's%20frequency%20in%20gnomAD%20v4.1.1%20genomes%2C%20from%200%20to%201.%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20%60clinvar_classification%60%3A%20ClinVar's%20aggregate%20germline%20classification%2C%20in%20ClinVar's%20spelling.%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20%60phylop100way%60%3A%20a%20signed%20%E2%88%92log10%20p-value%20of%20conservation%20across%20100%20vertebrates.%20Positive%20values%20mean%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20the%20base%20evolves%20more%20slowly%20than%20neutral%3B%20values%20near%200%20are%20close%20to%20neutral.%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20%60link_top_gene%60%3A%20the%20Ensembl%20ID%20of%20the%20gene%20with%20the%20strongest%20Open%20Targets%20E2G%20link%20to%20the%20variant's%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20regulatory%20element.%20%60link_gene_count%60%20counts%20the%20linked%20genes.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20An%20empty%20cell%20means%20the%20source%20holds%20no%20record%20for%20that%20variant.%20It%20is%20not%20a%20zero.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B_common%7D%20of%20%7Blen(_evidence.index)%7D%20variants%20have%20a%20gnomAD%20frequency%20of%20at%20least%201%25.%20Genome-wide%0A%20%20%20%20%20%20%20%20%20%20%20%20association%20studies%20find%20such%20common%20variants%20with%20small%20effects%2C%20and%20ClinVar%20seldom%20classifies%20one%20as%0A%20%20%20%20%20%20%20%20%20%20%20%20pathogenic.%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%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%20tell%20a%20model's%20reasons%20from%20a%20source's%0A%0A%20%20%20%20Every%20result%20says%20whether%20it%20is%20prioritized%2C%20and%20why%3A%0A%0A%20%20%20%20-%20%60prioritized_model_ids%60%20lists%20the%20models%20whose%20rule%20returned%20true%3B%0A%20%20%20%20-%20%60prioritized_source_names%60%20lists%20the%20sources%20whose%20rule%20returned%20true%3B%0A%20%20%20%20-%20%60prioritized%60%20is%20true%20when%20either%20list%20is%20not%20empty.%0A%0A%20%20%20%20A%20rule%20has%20three%20outcomes%3A%20true%2C%20false%20or%20unknown.%20A%20rule%20that%20reads%20a%20missing%20value%20is%20unknown%2C%20and%20only%20true%0A%20%20%20%20counts.%20The%20%60k562-dnase%20rule%60%20column%20shows%20Cherimoya's%20own%20outcome%20for%20its%20default%20rule%2C%0A%20%20%20%20%60abs(counts_log2fc)%20%3E%3D%200.25%60.%20Like%20every%20default%20rule%2C%20it%20is%20a%20screening%20rule%2C%20not%20a%20calibrated%20clinical%20or%0A%20%20%20%20causal%20threshold.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(assembled%2C%20mo%2C%20model_score)%3A%0A%20%20%20%20_reasons%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%22variant_id%22%3A%20result.variant_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prioritized%22%3A%20result.prioritized%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prioritized_model_ids%22%3A%20result.prioritized_model_ids%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prioritized_source_names%22%3A%20result.prioritized_source_names%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22k562-dnase%20rule%22%3A%20model_score(result%2C%20CHERIMOYA_MODEL_KEY).get(%22prioritized%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%20result%20in%20assembled%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%20%20%20%20def%20_flagged_by(name%3A%20str%2C%20*%2C%20model%3A%20bool)%20-%3E%20str%3A%0A%20%20%20%20%20%20%20%20hits%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20result.variant_id%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20result%20in%20assembled%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20name%20in%20(result.prioritized_model_ids%20if%20model%20else%20result.prioritized_source_names)%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20return%20%22%2C%20%22.join(f%22%60%7Bvariant_id%7D%60%22%20for%20variant_id%20in%20hits)%20if%20hits%20else%20%22no%20variant%22%0A%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.ui.table(_reasons%2C%20selection%3DNone)%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%20In%20this%20table%3A%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20Cherimoya's%20rule%20flagged%20%7B_flagged_by(CHERIMOYA_MODEL_KEY%2C%20model%3DTrue)%7D.%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20ClinVar's%20rule%20flagged%20%7B_flagged_by(CLINVAR_SOURCE%2C%20model%3DFalse)%7D.%20Compare%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%60clinvar_classification%60%20in%20Step%203%3A%20the%20rule%20needs%20%60Pathogenic%60%20or%20%60Likely_pathogenic%60%20with%20at%20least%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20one%20review%20star.%0A%20%20%20%20%20%20%20%20%20%20%20%20-%20The%20E2G%20rule%20flagged%20%7B_flagged_by(E2G_SOURCE%2C%20model%3DFalse)%7D.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20When%20you%20report%20a%20prioritized%20variant%2C%20show%20the%20two%20lists%2C%20not%20only%20the%20flag.%20A%20predicted%20change%20in%20K562%0A%20%20%20%20%20%20%20%20%20%20%20%20accessibility%20and%20a%20predicted%20enhancer%E2%80%93gene%20link%20are%20different%20kinds%20of%20evidence%2C%20and%20the%20flag%20alone%0A%20%20%20%20%20%20%20%20%20%20%20%20does%20not%20say%20which%20one%20selected%20the%20variant.%20%5BWhat%20%22prioritized%22%20means%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fscience%2Fprioritization%2F)%0A%20%20%20%20%20%20%20%20%20%20%20%20covers%20the%20flag%20in%20full.%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%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%20read%20the%20linked%20genes%0A%0A%20%20%20%20Open%20Targets%20E2G%20links%20a%20regulatory%20element%20to%20the%20genes%20it%20is%20predicted%20to%20regulate.%20The%20predictions%20come%20from%0A%20%20%20%20ENCODE-rE2G%2C%20one%20set%20per%20biosample%2C%20and%20Open%20Targets%20keeps%20the%20links%20scored%200.6%20or%20more.%20%60link_genes%60%20holds%20every%0A%20%20%20%20link%20whose%20element%20overlaps%20the%20variant%2C%20strongest%20first.%20Each%20link%20records%20its%20gene%2C%20score%2C%20biosample%20and%0A%20%20%20%20element.%0A%0A%20%20%20%20The%20next%20cell%20counts%20the%20links%20per%20variant%20and%20gene.%20Open%20Targets%20gives%20no%20gene%20symbols%2C%20so%20look%20an%20ID%20up%20at%0A%20%20%20%20%5BEnsembl%5D(https%3A%2F%2Fwww.ensembl.org%2F).%20For%20example%2C%20%60ENSG00000134243%60%20is%20*SORT1*%20and%20%60ENSG00000130203%60%20is%20*APOE*.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(assembled)%3A%0A%20%20%20%20links%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%22variant_id%22%3A%20result.variant_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22gene_id%22%3A%20link%5B%22gene_id%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22score%22%3A%20link%5B%22score%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22biosample%22%3A%20link%5B%22biosample%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%20%20%20%20for%20result%20in%20assembled%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20link%20in%20result.annotations.get(%22link_genes%22%2C%20%5B%5D)%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20columns%3D%5B%22variant_id%22%2C%20%22gene_id%22%2C%20%22score%22%2C%20%22biosample%22%5D%2C%0A%20%20%20%20)%0A%20%20%20%20linked_genes%20%3D%20(%0A%20%20%20%20%20%20%20%20links.groupby(%5B%22variant_id%22%2C%20%22gene_id%22%5D)%0A%20%20%20%20%20%20%20%20.agg(links%3D(%22score%22%2C%20%22size%22)%2C%20best_score%3D(%22score%22%2C%20%22max%22)%2C%20biosamples%3D(%22biosample%22%2C%20%22nunique%22))%0A%20%20%20%20%20%20%20%20.reset_index()%0A%20%20%20%20%20%20%20%20.sort_values(%5B%22variant_id%22%2C%20%22best_score%22%5D%2C%20ascending%3D%5BTrue%2C%20False%5D)%0A%20%20%20%20%20%20%20%20.reset_index(drop%3DTrue)%0A%20%20%20%20)%0A%20%20%20%20linked_genes%0A%20%20%20%20return%20(links%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(assembled%2C%20links%2C%20mo)%3A%0A%20%20%20%20_unlinked%20%3D%20%5Bresult.variant_id%20for%20result%20in%20assembled%20if%20not%20result.annotations.get(%22link_genes%22)%5D%0A%20%20%20%20_k562%20%3D%20int(links%5B%22biosample%22%5D.str.contains(%22K562%22%2C%20case%3DFalse%2C%20na%3DFalse).sum())%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20A%20link%20says%20that%20ENCODE-rE2G%20predicts%20the%20element%20regulates%20the%20gene%20in%20that%20biosample.%20It%20is%20not%20a%20measured%0A%20%20%20%20effect%20of%20the%20variant.%20A%20variant%20can%20sit%20in%20elements%20linked%20to%20several%20genes%2C%20and%20the%20strongest%20link%20need%20not%0A%20%20%20%20name%20the%20gene%20the%20variant%20acts%20through.%20In%20the%20bundled%20cohort%2C%20%60chr1%3A109274968%3AG%3AT%60%20(rs12740374)%20is%20such%20a%20case.%0A%20%20%20%20Experiments%20tie%20it%20to%20*SORT1*%20in%20liver%20cells%20(%5BMusunuru%20et%20al.%2C%202010%5D(https%3A%2F%2Fdoi.org%2F10.1038%2Fnature09266))%2C%0A%20%20%20%20and%20*SORT1*%20is%20one%20of%20its%20linked%20genes%2C%20but%20its%20strongest%20link%20is%20to%20another%20gene.%0A%0A%20%20%20%20%7Blen(links.index)%7D%20links%20overlap%20these%20variants.%20%7B_k562%7D%20of%20them%20come%20from%20K562%2C%20the%20cell%20line%20whose%0A%20%20%20%20accessibility%20Cherimoya%20predicts.%20%7B%22%2C%20%22.join(f%22%60%7Bvariant_id%7D%60%22%20for%20variant_id%20in%20_unlinked)%20or%20%22No%20variant%22%7D%0A%20%20%20%20%7B%22overlaps%22%20if%20len(_unlinked)%20%3D%3D%201%20else%20%22overlap%22%7D%20no%20linked%20element%2C%20so%20its%20link%20columns%20are%20empty%20and%20the%20E2G%0A%20%20%20%20rule%20could%20not%20flag%20it.%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%206%3A%20add%20a%20dataset%20you%20build%20yourself%0A%0A%20%20%20%20Some%20datasets%20are%20not%20published%20by%20the%20lab%2C%20and%20you%20build%20your%20own%20copy%20instead.%20SpliceAI's%20precomputed%0A%20%20%20%20splice-change%20scores%20are%20one.%20Their%20terms%2C%20from%20Illumina%3A%0A%0A%20%20%20%20-%20the%20precomputed%20scores%20are%20free%20for%20academic%20and%20not-for-profit%20use%2C%20and%20other%20use%20requires%20a%20commercial%0A%20%20%20%20%20%20licence%20from%20Illumina%3B%0A%20%20%20%20-%20the%20SpliceAI%20code%20is%20under%20the%20PolyForm%20Strict%20License%201.0.0%2C%20and%20the%20trained%20models%20under%20CC%20BY-NC%204.0.%0A%0A%20%20%20%20Obtain%20the%20score%20files%20from%20Illumina%2C%20through%20the%20%5BSpliceAI%20repository%5D(https%3A%2F%2Fgithub.com%2FIllumina%2FSpliceAI)%2C%0A%20%20%20%20and%20check%20that%20your%20use%20is%20permitted.%20Then%20build%20a%20copy%20once%20with%20the%20binding's%20builder.%20For%20the%20raw%20hg38%0A%20%20%20%20scores%3A%0A%0A%20%20%20%20%60%60%60bash%0A%20%20%20%20altar-spliceai-build%20--genome-build%20hg38%20--release%201.3%20--raw%20%5C%0A%20%20%20%20%20%20--input%20spliceai_scores.raw.snv.hg38.vcf.gz%20spliceai_scores.raw.indel.hg38.vcf.gz%20%5C%0A%20%20%20%20%20%20--output%20spliceai-1.3-raw-hg38%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20The%20score%20files%20record%20neither%20their%20genome%20build%20nor%20their%20masking%2C%20so%20%60--genome-build%60%2C%20%60--release%60%20and%0A%20%20%20%20%60--raw%60%20state%20them.%20The%20builder%20writes%20them%20into%20every%20Parquet%20file.%20%60SpliceAISource.from_dataset()%60%20reads%20them%0A%20%20%20%20back%2C%20and%20the%20source%20then%20knows%20its%20release%20identity%20with%20no%20other%20option.%20Its%20default%20rule%20flags%20a%20variant%0A%20%20%20%20whose%20greatest%20delta%20score%2C%20%60spliceai_ds_max%60%2C%20is%20at%20least%200.5%2C%20SpliceAI's%20recommended%20cutoff.%0A%0A%20%20%20%20Enter%20the%20path%20of%20your%20copy.%20Without%20one%2C%20this%20step%20is%20skipped%20and%20Step%207%20runs%20without%20SpliceAI.%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%20spliceai_input%20%3D%20mo.ui.text(%0A%20%20%20%20%20%20%20%20value%3Ddisplay_path(download_cache(mo.cli_args())%20%2F%20%22spliceai%22%20%2F%20%22spliceai-1.3-raw-hg38%22)%2C%0A%20%20%20%20%20%20%20%20label%3D%22Your%20SpliceAI%20copy%20(the%20--output%20of%20altar-spliceai-build)%22%2C%0A%20%20%20%20%20%20%20%20full_width%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20spliceai_input%0A%20%20%20%20return%20(spliceai_input%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20spliceai_input)%3A%0A%20%20%20%20_candidate%20%3D%20as_path(spliceai_input.value)%0A%20%20%20%20spliceai_dataset%20%3D%20_candidate%20if%20_candidate.exists()%20else%20None%0A%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20mo.md(f%22Found%20a%20SpliceAI%20copy%20at%20%60%7Bdisplay_path(_candidate)%7D%60.%20Step%207%20adds%20it%20as%20%60%5Bsources.spliceai%5D%60.%22)%0A%20%20%20%20%20%20%20%20if%20spliceai_dataset%20is%20not%20None%0A%20%20%20%20%20%20%20%20else%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22There%20is%20no%20SpliceAI%20copy%20at%20%60%7Bdisplay_path(_candidate)%7D%60%2C%20so%20Step%206%20is%20skipped.%20Altar%20publishes%20no%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22SpliceAI%20scores%2C%20and%20this%20notebook%20cannot%20build%20them%20for%20you%3A%20they%20come%20from%20Illumina%20under%20the%20terms%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22above.%20Build%20a%20copy%20and%20enter%20its%20path%20to%20run%20this%20step.%20Step%207%20runs%20without%20SpliceAI.%22%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20kind%3D%22success%22%20if%20spliceai_dataset%20is%20not%20None%20else%20%22info%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%20(spliceai_dataset%2C)%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20SqliteScoreStore%2C%0A%20%20%20%20assembled%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20models%2C%0A%20%20%20%20open_sources%2C%0A%20%20%20%20score_store_path%2C%0A%20%20%20%20spliceai_dataset%2C%0A%20%20%20%20variant_ids%2C%0A)%3A%0A%20%20%20%20mo.stop(spliceai_dataset%20is%20None%20or%20not%20assembled)%0A%20%20%20%20from%20altar_spliceai%20import%20SpliceAISource%0A%0A%20%20%20%20with%20contextlib.ExitStack()%20as%20_stack%3A%0A%20%20%20%20%20%20%20%20_sources%20%3D%20%5B_stack.enter_context(source)%20for%20source%20in%20open_sources()%5D%0A%20%20%20%20%20%20%20%20_spliceai%20%3D%20_stack.enter_context(SpliceAISource.from_dataset(spliceai_dataset))%0A%20%20%20%20%20%20%20%20with%20SqliteScoreStore(str(score_store_path))%20as%20_store%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_with_spliceai%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20result%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20async%20for%20result%20in%20_store.materialize(%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%20models%3Dmodels%2C%20annotation_sources%3D%5B*_sources%2C%20_spliceai%5D%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_release%20%3D%20_spliceai.identity().release%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%22SpliceAI%20release%20%60%7B_release%7D%60%2C%20rule%20%60%7B_spliceai.prioritize_predicate().to_sql()%7D%60%3A%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(%0A%20%20%20%20%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%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%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%20%20%20%20%22variant_id%22%3A%20result.variant_id%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%20%20%20%20%22spliceai_ds_max%22%3A%20result.annotations.get(%22spliceai_ds_max%22)%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%20%20%20%20%22spliceai_symbol%22%3A%20result.annotations.get(%22spliceai_symbol%22)%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%20%20%20%20%22prioritized_source_names%22%3A%20result.prioritized_source_names%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%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20result%20in%20_with_spliceai%0A%20%20%20%20%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%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20selection%3DNone%2C%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(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22An%20empty%20%60spliceai_ds_max%60%20means%20Illumina's%20files%20hold%20no%20score%20for%20the%20variant%3A%20SpliceAI%20scores%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22variants%20within%20genes%20only.%20It%20is%20not%20a%20delta%20score%20of%200.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%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%207%3A%20get%20the%20same%20table%20from%20a%20run%20spec%0A%0A%20%20%20%20A%20run%20spec%20describes%20a%20whole%20run%20in%20one%20mapping%20or%20TOML%20file%3A%20the%20cohort%2C%20the%20models%2C%20the%20sources%2C%20the%20store%0A%20%20%20%20and%20the%20export.%20%60altar%20run%60%20reads%20one%20from%20the%20command%20line%2C%20and%20%60altar.run.run%60%20from%20Python.%20The%20spec%20below%0A%20%20%20%20names%20the%20same%20model%20key%2C%20store%2C%20cohort%2C%20reference%20and%20sources%20as%20the%20steps%20above.%0A%0A%20%20%20%20Before%20it%20scores%20anything%2C%20the%20run%20asks%20the%20store%20which%20variants%20lack%20a%20score%20under%20the%20model's%20current%0A%20%20%20%20lineage.%20The%20lineage%20depends%20on%20the%20checkpoints%2C%20the%20runtime%20image%2C%20the%20genome%20and%20the%20scoring%20settings.%20It%0A%20%20%20%20does%20not%20depend%20on%20how%20the%20run%20was%20started.%20Every%20variant%20already%20has%20a%20score%2C%20so%20the%20run%20submits%20no%20task.%20It%0A%20%20%20%20then%20assembles%20the%20results%20as%20Step%203%20did%20and%20writes%20the%20export%3A%20a%20Parquet%20table%20with%20one%20row%20per%20variant%2C%20in%0A%20%20%20%20%60export%2F%60%20in%20the%20run%20directory.%0A%0A%20%20%20%20%60%5Brun%5D%60%20names%20the%20series'%20two%20directories%3A%20%60work_dir%60%2C%20the%20run%20directory%2C%20and%20%60cache_dir%60%2C%20the%20cache%20Tutorial%201%0A%20%20%20%20filled.%20Started%20in%20the%20series%20work%20directory%2C%20%60altar%20run%60%20would%20find%20both%20without%20the%20two%20lines%2C%20since%20they%0A%20%20%20%20are%20its%20defaults%20there%20when%20%60ALTAR_CACHE_DIR%60%20is%20not%20set.%20The%20spec%20names%20no%20%60%5Bstore%5D%60%3A%20a%20run%20with%20models%20keeps%0A%20%20%20%20its%20scores%20in%20%60scores.sqlite%60%20in%20the%20cache%2C%20the%20store%20Tutorial%201%20wrote.%0A%0A%20%20%20%20Some%20parts%20of%20the%20spec%20are%20there%20for%20the%20model%2C%20though%20nothing%20is%20computed%3A%0A%0A%20%20%20%20-%20%60%5Bbackend%5D%60%20names%20the%20local%20Docker%20backend%2C%20because%20Cherimoya%20runs%20in%20containers.%20The%20run%20checks%20that%20Docker%0A%20%20%20%20%20%20can%20find%20the%20model's%20image%20before%20it%20reads%20the%20cohort.%20The%20backend%20shares%20files%20with%20its%20containers%20in%0A%20%20%20%20%20%20%60backend-data%2F%60%20in%20the%20cache%2C%20where%20Tutorial%201's%20backend%20put%20them.%0A%20%20%20%20-%20%60%5Bvariants%5D%20reference%60%20names%20the%20genome%20Tutorial%201%20fetched.%20The%20run%20reads%20the%20FASTA%20from%20the%20cache%20and%20takes%0A%20%20%20%20%20%20its%20digest%20and%20seqcol%20from%20the%20registry%20entry%2C%20and%20the%20model's%20lineage%20includes%20the%20seqcol.%0A%0A%20%20%20%20%60annotation_sources%3D%5B...%5D%60%20adds%20the%20E2G%20source%20with%20its%20rule%2C%20which%20the%20spec%20cannot%20hold.%20Press%20**Run%20the%0A%20%20%20%20spec**%20to%20run%20it.%20It%20writes%20the%20export%2C%20and%20records%20the%20export's%20path%20in%20%60series.json%60%20for%20Tutorial%204.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20alphagenome_record%2C%0A%20%20%20%20cherimoya_record%2C%0A%20%20%20%20cohort_tsv%2C%0A%20%20%20%20series%2C%0A%20%20%20%20series_cache%2C%0A%20%20%20%20series_dir%2C%0A%20%20%20%20spliceai_dataset%2C%0A)%3A%0A%20%20%20%20_reference%20%3D%20series%5B%22reference%22%5D%0A%20%20%20%20spec%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(series_dir))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22cache_dir%22%3A%20str(series_cache)%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(cohort_tsv)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20A%20genome%20fetched%20from%20the%20registry%20is%20named%3B%20a%20FASTA%20of%20your%20own%20is%20given%20with%20its%20digest.%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%22reference%22%3A%20_reference%5B%22name%22%5D%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20_reference.get(%22name%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%20%7B%22reference_fasta%22%3A%20_reference%5B%22fasta%22%5D%2C%20%22reference_digest%22%3A%20_reference%5B%22digest%22%5D%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20)%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%20CHERIMOYA_MODEL_KEY%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%22model_name%22%3A%20cherimoya_record%5B%22model_name%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22resource_manifest%22%3A%20cherimoya_record%5B%22resource_manifest%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%7D%2C%0A%20%20%20%20%20%20%20%20%22backend%22%3A%20%7B%22type%22%3A%20%22local%22%7D%2C%0A%20%20%20%20%20%20%20%20%22sources%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20GNOMAD_SOURCE%3A%20%7B%22type%22%3A%20%22gnomad%22%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20CLINVAR_SOURCE%3A%20%7B%22type%22%3A%20%22clinvar%22%2C%20%22options%22%3A%20%7B%22prioritize_pathogenic%22%3A%20True%7D%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20PHYLOP_SOURCE%3A%20%7B%22type%22%3A%20%22phylop100way%22%7D%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%7D%0A%20%20%20%20runtimes%20%3D%20%7B%7D%0A%20%20%20%20if%20alphagenome_record%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20from%20altar.connections%20import%20EnvironmentSecretResolver%0A%20%20%20%20%20%20%20%20from%20altar_alphagenome%20import%20AlphaGenomeRuntime%0A%0A%20%20%20%20%20%20%20%20spec%5B%22models%22%5D%5BALPHAGENOME_MODEL_KEY%5D%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22ALPHAGENOME%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22model_name%22%3A%20alphagenome_record%5B%22model_name%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22configuration%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22credential%22%3A%20%7B%22provider%22%3A%20%22env%22%2C%20%22name%22%3A%20%22ALPHAGENOME_API_KEY%22%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22scorers%22%3A%20alphagenome_record%5B%22scorers%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ontology_terms%22%3A%20alphagenome_record%5B%22ontology_terms%22%5D%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%7D%0A%20%20%20%20%20%20%20%20runtimes%5BALPHAGENOME_MODEL_KEY%5D%20%3D%20AlphaGenomeRuntime(secret_resolver%3DEnvironmentSecretResolver())%0A%20%20%20%20if%20spliceai_dataset%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20spec%5B%22sources%22%5D%5BSPLICEAI_SOURCE%5D%20%3D%20%7B%22type%22%3A%20%22spliceai%22%2C%20%22options%22%3A%20%7B%22dataset%22%3A%20str(spliceai_dataset)%7D%7D%0A%20%20%20%20return%20runtimes%2C%20spec%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20spec)%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(%22The%20same%20spec%20as%20the%20TOML%20file%20%60altar%20run%60%20reads.%20The%20E2G%20source%20is%20passed%20in%20code.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22%60%60%60toml%5Cn%7Bspec_as_toml(spec)%7D%60%60%60%22)%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%2C%20unscored)%3A%0A%20%20%20%20_missing%20%3D%20sorted(%7Bvariant_id%20for%20ids%20in%20unscored.values()%20for%20variant_id%20in%20ids%7D)%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20bool(_missing)%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%22Step%207%20is%20stopped%3A%20%7Blen(_missing)%7D%20%7B'variant%20has'%20if%20len(_missing)%20%3D%3D%201%20else%20'variants%20have'%7D%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22no%20stored%20score%2C%20and%20the%20run%20would%20score%20them%2C%20which%20submits%20GPU%20tasks%20or%20API%20calls.%20Finish%20the%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22tutorial%20that%20scores%20each%20model%20with%20this%20cohort%20and%20work%20directory%2C%20then%20rerun%20this%20notebook.%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%20run_button%20%3D%20mo.ui.run_button(%0A%20%20%20%20%20%20%20%20label%3D%22Run%20the%20spec%22%2C%0A%20%20%20%20%20%20%20%20kind%3D%22success%22%2C%0A%20%20%20%20%20%20%20%20tooltip%3D%22Every%20variant%20is%20already%20scored%2C%20so%20the%20run%20submits%20no%20task.%22%2C%0A%20%20%20%20)%0A%20%20%20%20run_button%0A%20%20%20%20return%20(run_button%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20run_button)%3A%0A%20%20%20%20run_requested%20%3D%20run_button.value%20or%20execute_requested(mo.cli_args())%0A%20%20%20%20run_lines%20%3D%20run_log()%0A%20%20%20%20run_lines.clear()%0A%20%20%20%20return%20run_lines%2C%20run_requested%0A%0A%0A%40app.cell%0Aasync%20def%20_(mo%2C%20open_e2g%2C%20run_requested%2C%20runtimes%2C%20spec)%3A%0A%20%20%20%20from%20altar.run%20import%20run%0A%0A%20%20%20%20mo.stop(not%20run_requested%2C%20mo.md(%22Press%20**Run%20the%20spec**%20to%20continue.%22))%0A%20%20%20%20with%20open_e2g()%20as%20_e2g%3A%0A%20%20%20%20%20%20%20%20summary%20%3D%20await%20run(spec%2C%20annotation_sources%3D%5B_e2g%5D%2C%20runtimes%3Druntimes)%0A%20%20%20%20return%20(summary%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20run_lines%2C%20series_dir%2C%20summary)%3A%0A%20%20%20%20write_series(series_dir%2C%20exports%3D%7B%2203%22%3A%20summary.export_uri%7D)%0A%20%20%20%20_models%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%22model%20key%22%3A%20model.name%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22candidates%22%3A%20model.candidate_count%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22already%20scored%22%3A%20model.cache_hit_count%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22scored%22%3A%20model.scored_count%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22batches%22%3A%20model.batch_count%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22rows%20added%22%3A%20model.added%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%20model%20in%20summary.models%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20_sources%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%22name%22%3A%20source.name%2C%20%22section%22%3A%20source.section%20or%20%22passed%20in%20code%22%2C%20%22release%22%3A%20source.identity%5B%22release%22%5D%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20source%20in%20summary.sources%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%22The%20run%20wrote%20%7Bsummary.variant_count%7D%20rows%20to%20%60%7Bdisplay_path(summary.export_uri)%7D%60.%20Its%20log%3A%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22%60%60%60text%5Cn%22%20%2B%20%22%5Cn%22.join(run_lines.lines)%20%2B%20%22%5Cn%60%60%60%22)%2C%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%22Check%20the%20model's%20line%20and%20the%20table%3A%20every%20candidate%20is%20already%20scored%2C%20with%20no%20batch%20and%20no%20row%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22added.%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.ui.table(_models%2C%20selection%3DNone)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22Each%20source's%20release%20is%20recorded%20in%20the%20export's%20provenance%3A%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(_sources%2C%20selection%3DNone)%2C%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%22Each%20source%20is%20listed%20by%20its%20own%20name.%20phyloP's%20section%20is%20%60%5Bsources.phylop%5D%60%2C%20but%20the%20summary%2C%20the%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22provenance%20and%20%60prioritized_source_names%60%20call%20it%20%60phylop100way%60.%20Filter%20on%20that%20name.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%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%2C%20summary)%3A%0A%20%20%20%20_prefix%20%3D%20summary.provenance%5B%22models%22%5D%5BCHERIMOYA_MODEL_KEY%5D%5B%22column_prefix%22%5D%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20The%20export%20names%20each%20model's%20columns%20with%20a%20prefix%3A%20the%20model's%20display%20name%20and%20a%20short%20hash%20of%20its%20model%0A%20%20%20%20key.%20Cherimoya's%20%60counts_log2fc%60%20is%20%60%7B_prefix%7D_counts_log2fc%60.%20The%20run%20summary's%20%60provenance%60%20records%20the%0A%20%20%20%20prefix.%20The%20next%20cell%20compares%20the%20export%20with%20Step%203's%20results%2C%20variant%20by%20variant.%20It%20reads%20the%20export%20with%0A%20%20%20%20pyarrow's%20%60to_pylist()%60%2C%20which%20keeps%20a%20missing%20value%20as%20%60None%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(assembled%2C%20model_score%2C%20summary)%3A%0A%20%20%20%20exported%20%3D%20%7Brow%5B%22variant_id%22%5D%3A%20row%20for%20row%20in%20pq.read_table(summary.export_uri).to_pylist()%7D%0A%20%20%20%20prefix%20%3D%20summary.provenance%5B%22models%22%5D%5BCHERIMOYA_MODEL_KEY%5D%5B%22column_prefix%22%5D%0A%20%20%20%20comparison%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%22variant_id%22%3A%20result.variant_id%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22same%20score%22%3A%20exported%5Bresult.variant_id%5D%5Bf%22%7Bprefix%7D_counts_log2fc%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%3D%20model_score(result%2C%20CHERIMOYA_MODEL_KEY)%5B%22counts_log2fc%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22same%20evidence%22%3A%20all(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20exported%5Bresult.variant_id%5D.get(column)%20%3D%3D%20value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20column%2C%20value%20in%20result.annotations.items()%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20isinstance(value%2C%20list%20%7C%20dict)%0A%20%20%20%20%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%20%20%20%20%22same%20reasons%22%3A%20exported%5Bresult.variant_id%5D%5B%22prioritized_model_ids%22%5D%20%3D%3D%20result.prioritized_model_ids%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20exported%5Bresult.variant_id%5D%5B%22prioritized_source_names%22%5D%20%3D%3D%20result.prioritized_source_names%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%20result%20in%20assembled%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20comparison%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%60stored%20scores%20%2B%20published%20sources%20%E2%86%92%20materialize%20%E2%86%92%20one%20result%20per%20variant%20%E2%86%92%20the%20same%20result%20from%20a%20run%20spec%60%0A%0A%20%20%20%20A%20model%20and%20an%20annotation%20source%20are%20separate%3A%20the%20score%20store%20keeps%20what%20models%20computed%2C%20and%20each%20source%20is%0A%20%20%20%20looked%20up%20when%20results%20are%20assembled.%20Each%20result%20keeps%20the%20reasons%20apart%2C%20in%20%60prioritized_model_ids%60%20and%0A%20%20%20%20%60prioritized_source_names%60.%20The%20run%20spec%20reached%20the%20same%20rows%20without%20scoring%20because%20the%20store%20is%20keyed%20by%0A%20%20%20%20model%20key%20and%20lineage%2C%20and%20both%20routes%20described%20the%20same%20setup.%0A%0A%20%20%20%20Rerun%20Step%207%3A%20the%20run%20again%20finds%20every%20variant%20already%20scored.%20Then%20try%20a%20source%20option%3A%20add%0A%20%20%20%20%60filters%3D%7B%22context_names%22%3A%20%5B%22liver%22%5D%7D%60%20to%20the%20E2G%20source%20in%20Step%202%20and%20see%20which%20links%20remain.%20A%20filter%20changes%0A%20%20%20%20the%20source's%20release%20identity%2C%20which%20the%20export%20records.%0A%0A%20%20%20%20%5BTutorial%204%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fstart%2Fnotebooks%2F04_custom_prioritization.html)%20reads%20this%20export%20and%0A%20%20%20%20writes%20a%20prioritization%20rule%20of%20your%20own.%20See%0A%20%20%20%20%5BStore%20and%20assemble%20results%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fpython%2Fstores%2F%23assemble-variant-results)%2C%0A%20%20%20%20%5BAnnotate%20variants%20with%20evidence%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fguides%2Fannotate%2F)%2C%0A%20%20%20%20%5BOpen%20Targets%20E2G%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fintegrations%2Fopentargets-e2g%2F)%2C%0A%20%20%20%20%5BSpliceAI%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fintegrations%2Fspliceai%2F)%20and%0A%20%20%20%20%5BUse%20Altar%20from%20Python%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fpython%2F)%20for%20more.%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
bbc9f349bc666bc0b818f2645a186337