%23%20Copyright%202026%20Riya%20Sinha%0A%22%22%22Tutorial%204%3A%20write%20a%20prioritization%20rule%20of%20your%20own%20over%20Tutorial%203's%20export%2C%20and%20save%20it%20as%20a%20policy.%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%20import%20sqlite3%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%20E2G_SOURCE%2C%0A%20%20%20%20%20%20%20%20REPOSITORY_ROOT%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%20file_digest%2C%0A%20%20%20%20%20%20%20%20read_series%2C%0A%20%20%20%20%20%20%20%20work_dir%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%204%20%C2%B7%20Write%20your%20own%20prioritization%20rule%0A%0A%20%20%20%20In%20Tutorial%203%2C%20the%20rules%20of%20Cherimoya's%20binding%2C%20ClinVar%20and%20the%20E2G%20source%20decided%20which%20variants%20were%0A%20%20%20%20prioritized.%20Those%20rules%20were%20chosen%20by%20each%20binding's%20authors%2C%20or%20set%20as%20a%20demonstration.%20This%20tutorial%20writes%0A%20%20%20%20a%20rule%20of%20your%20own%20over%20Tutorial%203's%20export%3A%20one%20that%20combines%20a%20model's%20predicted%20effect%20with%20evidence%20from%0A%20%20%20%20the%20published%20datasets%2C%20at%20thresholds%20you%20choose.%20Along%20the%20way%2C%20you%20will%20see%20how%20a%20rule%20treats%20a%20missing%0A%20%20%20%20value%2C%20and%20you%20will%20save%20the%20rule%20as%20a%20record%20of%20your%20analysis.%0A%0A%20%20%20%20By%20the%20end%2C%20you%20will%20be%20able%20to%3A%0A%0A%20%20%20%201.%20load%20an%20export%20and%20read%20which%20model%20and%20data%20releases%20produced%20its%20columns%3B%0A%20%20%20%202.%20list%20the%20rules%20that%20set%20the%20export's%20%60prioritized%60%20flags%3B%0A%20%20%20%203.%20write%20a%20model%20rule%20and%20an%20evidence%20rule%2C%20and%20combine%20them%3B%0A%20%20%20%204.%20tell%20a%20rule%20that%20is%20unknown%20for%20a%20variant%20from%20one%20that%20is%20false%3B%0A%20%20%20%205.%20render%20the%20rule%20as%20SQL%20and%20check%20it%20against%20the%20Python%20result%3B%20and%0A%20%20%20%206.%20save%20the%20rule%2C%20its%20thresholds%20and%20the%20export's%20provenance%20as%20a%20policy%20file.%0A%0A%20%20%20%20**Requirements%3A**%20the%20export%20that%20Tutorial%203%20wrote%20in%20Step%207.%20Nothing%20is%20downloaded%2C%20scored%20or%20looked%20up%2C%20and%0A%20%20%20%20no%20store%20is%20opened.%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%203%20recorded%20its%20export's%20location%20in%20%60series.json%60%20there.%0A%20%20%20%20Keep%20the%20default%20unless%20you%20gave%20the%20earlier%20tutorials%20another%20directory.%20Passing%20%60--work-dir%20DIR%60%20on%20the%0A%20%20%20%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%20_recorded%20%3D%20series.get(%22exports%22%2C%20%7B%7D).get(%2203%22)%0A%20%20%20%20export_dir%20%3D%20None%20if%20_recorded%20is%20None%20else%20Path(_recorded)%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20export_dir%20is%20None%20or%20not%20any(export_dir.glob(%22part-*.parquet%22))%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%20has%20no%20export%20from%20Tutorial%203.%20Run%20%6003_join_evidence.py%60%20with%20this%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22work%20directory%20to%20its%20last%20step%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%20mo.md(f%22Tutorial%203's%20export%3A%20%60%7Bdisplay_path(export_dir)%7D%60.%22)%0A%20%20%20%20return%20export_dir%2C%20series%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%20load%20the%20export%20and%20its%20provenance%0A%0A%20%20%20%20The%20export%20is%20a%20Parquet%20table%20with%20one%20row%20per%20variant.%20Its%20columns%20are%3A%0A%0A%20%20%20%20-%20%60variant_id%60%20and%20%60prioritized%60%3B%0A%20%20%20%20-%20each%20source's%20columns%2C%20such%20as%20%60gnomad_af%60%20and%20%60link_top_score%60%3B%0A%20%20%20%20-%20each%20model's%20score%20columns%2C%20under%20the%20model's%20prefix%3B%0A%20%20%20%20-%20%60prioritized_model_ids%60%20and%20%60prioritized_source_names%60%2C%20the%20models%20and%20sources%20whose%20rule%20flagged%20the%20row.%0A%0A%20%20%20%20The%20file%20also%20carries%20its%20provenance%20under%20the%20Parquet%20metadata%20key%20%60altar.provenance%60.%20It%20names%2C%20for%20each%0A%20%20%20%20model%2C%20the%20column%20prefix%20and%20the%20lineage%20the%20scores%20came%20from%2C%20and%20for%20each%20source%2C%20the%20release%20it%20served.%20A%0A%20%20%20%20file%20shared%20on%20its%20own%20still%20says%20where%20its%20columns%20came%20from.%0A%0A%20%20%20%20The%20next%20cell%20reads%20the%20rows%20with%20pyarrow's%20%60to_pylist()%60%2C%20which%20keeps%20a%20missing%20value%20as%20%60None%60.%20pandas%20would%0A%20%20%20%20turn%20a%20missing%20number%20into%20NaN%2C%20and%20a%20rule%20treats%20NaN%20as%20a%20value%2C%20not%20as%20missing.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(export_dir)%3A%0A%20%20%20%20export_file%20%3D%20min(export_dir.glob(%22part-*.parquet%22))%0A%20%20%20%20provenance%20%3D%20json.loads(pq.read_metadata(export_file).metadata%5Bb%22altar.provenance%22%5D)%0A%20%20%20%20rows%20%3D%20pq.read_table(export_file).to_pylist()%0A%20%20%20%20cherimoya_prefix%20%3D%20provenance%5B%22models%22%5D%5BCHERIMOYA_MODEL_KEY%5D%5B%22column_prefix%22%5D%0A%20%20%20%20return%20cherimoya_prefix%2C%20export_file%2C%20provenance%2C%20rows%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20provenance%2C%20rows)%3A%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%20key%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22column%20prefix%22%3A%20entry%5B%22column_prefix%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22lineages%20read%22%3A%20%22%2C%20%22.join(lineage%5B%22lineage_id%22%5D%20for%20lineage%20in%20entry%5B%22reuse%22%5D%5B%22lineages%22%5D%20or%20%5B%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%20key%2C%20entry%20in%20provenance%5B%22models%22%5D.items()%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%22source%22%3A%20name%2C%20%22release%22%3A%20None%20if%20identity%20is%20None%20else%20identity%5B%22release%22%5D%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20name%2C%20identity%20in%20provenance%5B%22sources%22%5D.items()%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%20export%20holds%20%7Blen(rows)%7D%20rows%20and%20%7Blen(rows%5B0%5D)%7D%20columns.%20Its%20models%3A%22)%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(%22Its%20sources%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%22A%20source%20is%20listed%20by%20its%20own%20name%2C%20not%20its%20spec%20section%3A%20phyloP%2C%20from%20%60%5Bsources.phylop%5D%60%2C%20is%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%60phylop100way%60%20here%20and%20in%20%60prioritized_source_names%60.%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%202%3A%20list%20the%20rules%20behind%20the%20export's%20flags%0A%0A%20%20%20%20A%20rule%20is%20a%20predicate%3A%20an%20expression%20over%20a%20variant's%20columns%20that%20is%20true%2C%20false%20or%20unknown.%20Altar%20builds%20one%0A%20%20%20%20as%20a%20%60Predicate%60%20object%2C%20which%20renders%20as%20a%20Python%20function%20and%20as%20SQL.%20These%20rules%20set%20the%20export's%20flags%3A%0A%0A%20%20%20%20-%20Cherimoya's%20binding%20declares%20its%20default%20rule%2C%20%60prioritize_predicate()%60.%0A%20%20%20%20-%20ClinVar's%20rule%2C%20%60PATHOGENIC_PREDICATE%60%2C%20runs%20only%20because%20Tutorial%203%20set%20%60prioritize_pathogenic%60.%0A%20%20%20%20-%20Open%20Targets%20E2G%20has%20no%20rule%20of%20its%20own.%20Tutorial%203%20gave%20it%20%60link_top_score%20%3E%3D%200.8%60%20in%20code%2C%20as%20a%0A%20%20%20%20%20%20demonstration.%0A%20%20%20%20-%20gnomAD%20and%20phyloP%20have%20no%20rule.%0A%0A%20%20%20%20A%20model's%20rule%20reads%20the%20model's%20own%20columns%20by%20their%20short%20names%2C%20such%20as%20%60counts_log2fc%60.%20In%20the%20export%2C%0A%20%20%20%20the%20same%20columns%20carry%20the%20model's%20prefix.%20Each%20default%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%0Adef%20_(provenance)%3A%0A%20%20%20%20from%20altar.predicates%20import%20Abs%2C%20And%2C%20Col%2C%20Ge%2C%20IsNull%2C%20Lit%2C%20Not%2C%20Or%0A%20%20%20%20from%20altar_cherimoya%20import%20CherimoyaPlugin%0A%20%20%20%20from%20altar_clinvar%20import%20PATHOGENIC_PREDICATE%0A%0A%20%20%20%20export_rules%20%3D%20%7B%0A%20%20%20%20%20%20%20%20CHERIMOYA_MODEL_KEY%3A%20CherimoyaPlugin().prioritize_predicate()%2C%0A%20%20%20%20%20%20%20%20CLINVAR_SOURCE%3A%20PATHOGENIC_PREDICATE%2C%0A%20%20%20%20%20%20%20%20E2G_SOURCE%3A%20Ge(Col(%22link_top_score%22)%2C%20Lit(0.8))%2C%0A%20%20%20%20%7D%0A%20%20%20%20if%20ALPHAGENOME_MODEL_KEY%20in%20provenance%5B%22models%22%5D%3A%0A%20%20%20%20%20%20%20%20from%20altar_alphagenome%20import%20AlphaGenomePlugin%0A%0A%20%20%20%20%20%20%20%20export_rules%5BALPHAGENOME_MODEL_KEY%5D%20%3D%20AlphaGenomePlugin().prioritize_predicate()%0A%20%20%20%20return%20Abs%2C%20And%2C%20Col%2C%20Ge%2C%20IsNull%2C%20Lit%2C%20Not%2C%20Or%2C%20export_rules%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(export_rules%2C%20mo%2C%20rows)%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%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22rule%20of%22%3A%20name%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22SQL%22%3A%20rule.to_sql()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22rows%20it%20flagged%22%3A%20sum(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%20in%20row%5B%22prioritized_model_ids%22%5D%20or%20name%20in%20row%5B%22prioritized_source_names%22%5D%20for%20row%20in%20rows%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%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20name%2C%20rule%20in%20export_rules.items()%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20mo.ui.table(_counts%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%20write%20a%20model%20rule%0A%0A%20%20%20%20A%20rule%20of%20your%20own%20reads%20the%20export%2C%20so%20it%20names%20the%20model's%20columns%20with%20their%20prefix.%20Cherimoya's%0A%20%20%20%20%60counts_log2fc%60%20is%20the%20predicted%20log2%20change%20in%20K562%20accessibility%2C%20alternate%20minus%20reference.%20Its%20absolute%0A%20%20%20%20value%20measures%20the%20size%20of%20the%20change%20in%20either%20direction%3A%200.25%20is%20a%20change%20of%20about%2019%25%20in%20predicted%20counts%2C%0A%20%20%20%20and%201.0%20is%20a%20doubling%20or%20halving.%0A%0A%20%20%20%20The%20slider%20starts%20at%200.25%2C%20the%20binding's%20default%2C%20so%20the%20rule%20starts%20out%20matching%20Cherimoya's%20own.%20Move%20it%20to%0A%20%20%20%20see%20which%20variants%20pass.%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%20provenance%2C%20series)%3A%0A%20%20%20%20log2fc_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D0.0%2C%20stop%3D1.0%2C%20step%3D0.05%2C%20value%3D0.25%2C%20label%3D%22Minimum%20%7Ccounts_log2fc%7C%22%2C%20show_value%3DTrue%0A%20%20%20%20)%0A%20%20%20%20has_alphagenome%20%3D%20ALPHAGENOME_MODEL_KEY%20in%20provenance%5B%22models%22%5D%20and%20ALPHAGENOME_MODEL_KEY%20in%20series.get(%0A%20%20%20%20%20%20%20%20%22models%22%2C%20%7B%7D%0A%20%20%20%20)%0A%20%20%20%20quantile_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D0.5%2C%20stop%3D1.0%2C%20step%3D0.01%2C%20value%3D0.9%2C%20label%3D%22Minimum%20AlphaGenome%20quantile%20score%22%2C%20show_value%3DTrue%0A%20%20%20%20)%0A%20%20%20%20mo.vstack(%5Blog2fc_slider%2C%20quantile_slider%5D%20if%20has_alphagenome%20else%20%5Blog2fc_slider%5D)%0A%20%20%20%20return%20has_alphagenome%2C%20log2fc_slider%2C%20quantile_slider%0A%0A%0A%40app.cell%0Adef%20_(Abs%2C%20Col%2C%20Ge%2C%20Lit%2C%20cherimoya_prefix%2C%20log2fc_slider)%3A%0A%20%20%20%20cherimoya_rule%20%3D%20Ge(Abs(Col(f%22%7Bcherimoya_prefix%7D_counts_log2fc%22))%2C%20Lit(log2fc_slider.value))%0A%20%20%20%20return%20(cherimoya_rule%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(has_alphagenome%2C%20mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20The%20store%20also%20holds%20AlphaGenome's%20liver%20predictions%20from%20Tutorial%202.%20The%20next%20cell%20adds%20an%20AlphaGenome%20rule%0A%20%20%20%20%20%20%20%20on%20%60max_abs_quantile_score%60%3A%20the%20largest%20absolute%20quantile%20score%20among%20the%20liver%20tracks%2C%20from%200%20to%201.%20The%0A%20%20%20%20%20%20%20%20slider%20starts%20at%200.9%2C%20the%20quantile%20cutoff%20of%20AlphaGenome's%20default%20rule.%20The%20model%20rule%20then%20flags%20a%20variant%0A%20%20%20%20%20%20%20%20when%20either%20model's%20rule%20is%20true.%20The%20two%20models%20answer%20different%20questions%2C%20K562%20accessibility%20and%20liver%0A%20%20%20%20%20%20%20%20tracks%2C%20so%20either%20one%20can%20flag%20a%20variant%20the%20other%20does%20not.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20if%20has_alphagenome%0A%20%20%20%20%20%20%20%20else%20r%22%22%22%0A%20%20%20%20%20%20%20%20The%20export%20has%20no%20AlphaGenome%20columns%2C%20because%20Tutorial%202%20stored%20no%20AlphaGenome%20scores%20in%20this%20work%0A%20%20%20%20%20%20%20%20directory.%20The%20model%20rule%20uses%20Cherimoya%20alone.%20After%20you%20run%20Tutorial%202%20and%20then%20Tutorial%203%20again%2C%20this%0A%20%20%20%20%20%20%20%20step%20adds%20an%20AlphaGenome%20rule.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20Col%2C%0A%20%20%20%20Ge%2C%0A%20%20%20%20Lit%2C%0A%20%20%20%20Or%2C%0A%20%20%20%20cherimoya_rule%2C%0A%20%20%20%20has_alphagenome%2C%0A%20%20%20%20provenance%2C%0A%20%20%20%20quantile_slider%2C%0A)%3A%0A%20%20%20%20if%20has_alphagenome%3A%0A%20%20%20%20%20%20%20%20alphagenome_prefix%20%3D%20provenance%5B%22models%22%5D%5BALPHAGENOME_MODEL_KEY%5D%5B%22column_prefix%22%5D%0A%20%20%20%20%20%20%20%20alphagenome_rule%20%3D%20Ge(Col(f%22%7Balphagenome_prefix%7D_max_abs_quantile_score%22)%2C%20Lit(quantile_slider.value))%0A%20%20%20%20%20%20%20%20model_rule%20%3D%20Or(cherimoya_rule%2C%20alphagenome_rule)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20model_rule%20%3D%20cherimoya_rule%0A%20%20%20%20return%20(model_rule%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%204%3A%20write%20an%20evidence%20rule%0A%0A%20%20%20%20An%20evidence%20rule%20reads%20the%20sources'%20columns.%20This%20one%20flags%20a%20variant%20that%20either%20sits%20in%20a%20regulatory%20element%0A%20%20%20%20with%20a%20gene%20link%2C%20or%20sits%20at%20a%20conserved%20base%3A%0A%0A%20%20%20%20-%20%60link_top_score%60%20is%20the%20ENCODE-rE2G%20score%20of%20the%20variant's%20strongest%20Open%20Targets%20E2G%20link.%20Open%20Targets%20keeps%0A%20%20%20%20%20%20links%20scored%200.6%20or%20more%2C%20so%20the%20default%2C%200.6%2C%20accepts%20any%20link%20in%20the%20data.%0A%20%20%20%20-%20%60phylop100way%60%20is%20phyloP's%20conservation%20score%2C%20a%20signed%20%E2%88%92log10%20p-value.%20The%20default%2C%202.0%2C%20asks%20for%20a%20base%0A%20%20%20%20%20%20conserved%20at%20about%20p%20%3D%200.01.%0A%0A%20%20%20%20A%20variant%20with%20no%20E2G%20link%20has%20no%20%60link_top_score%60.%20By%20default%20the%20rule%20leaves%20such%20a%20value%20missing%2C%20and%20Step%206%0A%20%20%20%20shows%20what%20that%20does.%20Tick%20the%20box%20to%20state%20instead%20that%20a%20missing%20value%20counts%20as%20false.%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%20link_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D0.6%2C%20stop%3D1.0%2C%20step%3D0.05%2C%20value%3D0.6%2C%20label%3D%22Minimum%20link_top_score%22%2C%20show_value%3DTrue%0A%20%20%20%20)%0A%20%20%20%20phylop_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D0.0%2C%20stop%3D6.0%2C%20step%3D0.5%2C%20value%3D2.0%2C%20label%3D%22Minimum%20phylop100way%22%2C%20show_value%3DTrue%0A%20%20%20%20)%0A%20%20%20%20missing_is_false%20%3D%20mo.ui.checkbox(value%3DFalse%2C%20label%3D%22Count%20a%20missing%20value%20as%20false%22)%0A%20%20%20%20mo.vstack(%5Blink_slider%2C%20phylop_slider%2C%20missing_is_false%5D)%0A%20%20%20%20return%20link_slider%2C%20missing_is_false%2C%20phylop_slider%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20And%2C%0A%20%20%20%20Col%2C%0A%20%20%20%20Ge%2C%0A%20%20%20%20IsNull%2C%0A%20%20%20%20Lit%2C%0A%20%20%20%20Not%2C%0A%20%20%20%20Or%2C%0A%20%20%20%20link_slider%2C%0A%20%20%20%20missing_is_false%2C%0A%20%20%20%20phylop_slider%2C%0A)%3A%0A%20%20%20%20def%20at_least(column%2C%20threshold)%3A%0A%20%20%20%20%20%20%20%20%22%22%22%60column%20%3E%3D%20threshold%60%3B%20with%20the%20box%20ticked%2C%20a%20missing%20value%20makes%20it%20false%20instead%20of%20unknown.%22%22%22%0A%20%20%20%20%20%20%20%20test%20%3D%20Ge(Col(column)%2C%20Lit(threshold))%0A%20%20%20%20%20%20%20%20return%20And(Not(IsNull(Col(column)))%2C%20test)%20if%20missing_is_false.value%20else%20test%0A%0A%20%20%20%20evidence_rule%20%3D%20Or(at_least(%22link_top_score%22%2C%20link_slider.value)%2C%20at_least(%22phylop100way%22%2C%20phylop_slider.value))%0A%20%20%20%20return%20(evidence_rule%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%205%3A%20combine%20the%20two%20rules%0A%0A%20%20%20%20%60And%60%20asks%20for%20both%20a%20predicted%20effect%20and%20supporting%20evidence.%20%60Or%60%20accepts%20either.%20The%20default%20is%20%60And%60%3A%20a%0A%20%20%20%20variant%20passes%20when%20the%20model%20predicts%20an%20effect%20and%20the%20evidence%20places%20it%20in%20a%20linked%20element%20or%20at%20a%0A%20%20%20%20conserved%20base.%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%20combination%20%3D%20mo.ui.radio(%0A%20%20%20%20%20%20%20%20options%3D%5B%22And%22%2C%20%22Or%22%5D%2C%20value%3D%22And%22%2C%20label%3D%22Combine%20the%20model%20rule%20and%20the%20evidence%20rule%20with%22%0A%20%20%20%20)%0A%20%20%20%20combination%0A%20%20%20%20return%20(combination%2C)%0A%0A%0A%40app.cell%0Adef%20_(And%2C%20Or%2C%20combination%2C%20evidence_rule%2C%20model_rule)%3A%0A%20%20%20%20my_rule%20%3D%20And(model_rule%2C%20evidence_rule)%20if%20combination.value%20%3D%3D%20%22And%22%20else%20Or(model_rule%2C%20evidence_rule)%0A%20%20%20%20return%20(my_rule%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%206%3A%20evaluate%20the%20rule%2C%20and%20see%20what%20a%20missing%20value%20does%0A%0A%20%20%20%20%60evaluate(row)%60%20returns%20%60True%60%2C%20%60False%60%20or%20%60None%60.%20%60None%60%20means%20unknown%3A%20the%20rule%20read%20a%20missing%20value%20and%20could%0A%20%20%20%20not%20decide.%20Unknown%20follows%20SQL's%20three-valued%20logic%3A%0A%0A%20%20%20%20-%20%60And%60%20is%20false%20if%20any%20part%20is%20false.%20Otherwise%20it%20is%20unknown%20if%20any%20part%20is%20unknown.%0A%20%20%20%20-%20%60Or%60%20is%20true%20if%20any%20part%20is%20true.%20Otherwise%20it%20is%20unknown%20if%20any%20part%20is%20unknown.%0A%0A%20%20%20%20%60to_python()%60%20returns%20a%20function%20that%20matches%20only%20a%20definite%20%60True%60%2C%20as%20a%20SQL%20%60WHERE%60%20does.%20An%20unknown%20row%20is%0A%20%20%20%20not%20selected%2C%20but%20it%20differs%20from%20a%20row%20the%20rule%20saw%20and%20rejected%3A%20a%20value%20it%20needed%20is%20missing.%20The%20table%20shows%0A%20%20%20%20each%20part's%20result%20and%20the%20whole%20rule's.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(evidence_rule%2C%20model_rule%2C%20my_rule%2C%20rows)%3A%0A%20%20%20%20matches%20%3D%20my_rule.to_python()%0A%20%20%20%20evaluated%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%20row%5B%22variant_id%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22model%20rule%22%3A%20model_rule.evaluate(row)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22evidence%20rule%22%3A%20evidence_rule.evaluate(row)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22my%20rule%22%3A%20my_rule.evaluate(row)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22selected%22%3A%20matches(row)%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%20row%20in%20rows%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%20evaluated%0A%20%20%20%20return%20(evaluated%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20And%2C%0A%20%20%20%20Or%2C%0A%20%20%20%20cherimoya_prefix%2C%0A%20%20%20%20combination%2C%0A%20%20%20%20evidence_rule%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_rule%2C%0A%20%20%20%20my_rule%2C%0A%20%20%20%20rows%2C%0A)%3A%0A%20%20%20%20def%20_shown(value)%3A%0A%20%20%20%20%20%20%20%20return%20%22unknown%22%20if%20value%20is%20None%20else%20str(value).lower()%0A%0A%20%20%20%20_other%20%3D%20%22Or%22%20if%20combination.value%20%3D%3D%20%22And%22%20else%20%22And%22%0A%20%20%20%20_other_rule%20%3D%20(Or%20if%20_other%20%3D%3D%20%22Or%22%20else%20And)(model_rule%2C%20evidence_rule)%0A%20%20%20%20_columns%20%3D%20%5Bf%22%7Bcherimoya_prefix%7D_counts_log2fc%22%2C%20%22link_top_score%22%2C%20%22phylop100way%22%5D%0A%20%20%20%20_lines%20%3D%20%5B%5D%0A%20%20%20%20for%20_row%20in%20rows%3A%0A%20%20%20%20%20%20%20%20_parts%20%3D%20%7B%22model%22%3A%20model_rule.evaluate(_row)%2C%20%22evidence%22%3A%20evidence_rule.evaluate(_row)%7D%0A%20%20%20%20%20%20%20%20_unknown%20%3D%20%5Bname%20for%20name%2C%20value%20in%20_parts.items()%20if%20value%20is%20None%5D%0A%20%20%20%20%20%20%20%20if%20not%20_unknown%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20_lacks%20%3D%20%22%2C%20%22.join(f%22%60%7Bcolumn%7D%60%22%20for%20column%20in%20_columns%20if%20_row.get(column)%20is%20None)%0A%20%20%20%20%20%20%20%20_lines.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22-%20%60%7B_row%5B'variant_id'%5D%7D%60%20lacks%20%7B_lacks%7D%2C%20so%20the%20%7B'%20and%20'.join(_unknown)%7D%20rule%20is%20unknown.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22Combined%20with%20%60%7Bcombination.value%7D%60%2C%20your%20rule%20is%20%7B_shown(my_rule.evaluate(_row))%7D%3B%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22with%20%60%7B_other%7D%60%2C%20it%20would%20be%20%7B_shown(_other_rule.evaluate(_row))%7D.%22%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22Neither%20part%20of%20the%20rule%20is%20unknown%20for%20any%20row%20at%20these%20settings.%22%0A%20%20%20%20%20%20%20%20if%20not%20_lines%0A%20%20%20%20%20%20%20%20else%20%22Rows%20where%20a%20part%20of%20the%20rule%20is%20unknown%3A%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%2B%20%22%5Cn%22.join(_lines)%0A%20%20%20%20%20%20%20%20%2B%20%22%5Cn%5Cn%60And%60%20with%20a%20false%20part%20is%20false%20whatever%20the%20unknown%20part%20holds%2C%20and%20%60Or%60%20with%20a%20true%20part%20is%20true.%20%22%0A%20%20%20%20%20%20%20%20%22Otherwise%20the%20unknown%20carries%20through.%20Tick%20the%20box%20in%20Step%204%20to%20count%20a%20missing%20value%20as%20false.%22%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%20compare%20with%20the%20export's%20flags%0A%0A%20%20%20%20The%20export's%20%60prioritized%60%20column%20comes%20from%20the%20rules%20in%20Step%202.%20Your%20rule%20is%20a%20separate%20analysis%3A%20it%20does%20not%0A%20%20%20%20change%20the%20export.%20Rows%20where%20the%20two%20disagree%20show%20what%20your%20thresholds%20and%20your%20combination%20changed.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(evaluated%2C%20mo%2C%20rows)%3A%0A%20%20%20%20_compare%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%20row%5B%22variant_id%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22export%20prioritized%22%3A%20row%5B%22prioritized%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prioritized_model_ids%22%3A%20row%5B%22prioritized_model_ids%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prioritized_source_names%22%3A%20row%5B%22prioritized_source_names%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22my%20rule%20selects%22%3A%20bool(selected)%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%20row%2C%20selected%20in%20zip(rows%2C%20evaluated%5B%22selected%22%5D%2C%20strict%3DTrue)%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20mo.ui.table(_compare%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%208%3A%20render%20the%20rule%20as%20SQL%0A%0A%20%20%20%20%60to_sql()%60%20renders%20the%20same%20rule%20as%20a%20SQL%20boolean%20expression.%20A%20warehouse%20store%20runs%20this%20rendering%20in%20its%20own%0A%20%20%20%20query%2C%20where%20the%20Python%20rendering%20would%20mean%20reading%20every%20row%20out%20first.%20The%20next%20cell%20loads%20the%20rule's%20columns%0A%20%20%20%20into%20an%20in-memory%20SQLite%20table%20and%20selects%20the%20rows%20that%20match.%20The%20SQL%20and%20Python%20renderings%20should%20select%20the%0A%20%20%20%20same%20variants%2C%20unknown%20rows%20included%3A%20neither%20selects%20them.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(evaluated%2C%20my_rule%2C%20rows)%3A%0A%20%20%20%20rule_sql%20%3D%20my_rule.to_sql()%0A%20%20%20%20scalar_columns%20%3D%20%5Bcolumn%20for%20column%20in%20rows%5B0%5D%20if%20not%20any(isinstance(row%5Bcolumn%5D%2C%20list%20%7C%20dict)%20for%20row%20in%20rows)%5D%0A%20%20%20%20with%20sqlite3.connect(%22%3Amemory%3A%22)%20as%20_database%3A%0A%20%20%20%20%20%20%20%20pd.DataFrame(rows)%5Bscalar_columns%5D.to_sql(%22export%22%2C%20_database%2C%20index%3DFalse)%0A%20%20%20%20%20%20%20%20_query%20%3D%20f%22SELECT%20variant_id%20FROM%20export%20WHERE%20%7Brule_sql%7D%22%20%20%23%20noqa%3A%20S608%20-%20the%20rule's%20SQL%2C%20on%20an%20in-memory%20copy%0A%20%20%20%20%20%20%20%20sql_selected%20%3D%20%7Bvariant_id%20for%20(variant_id%2C)%20in%20_database.execute(_query)%7D%0A%20%20%20%20python_selected%20%3D%20set(evaluated.loc%5Bevaluated%5B%22selected%22%5D%2C%20%22variant_id%22%5D)%0A%20%20%20%20return%20python_selected%2C%20rule_sql%2C%20sql_selected%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20python_selected%2C%20rule_sql%2C%20sql_selected)%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(f%22%60%60%60sql%5Cn%7Brule_sql%7D%5Cn%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.callout(%0A%20%20%20%20%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%20%20%20%20f%22SQL%20selects%20%7Blen(sql_selected)%7D%20%7B'variant'%20if%20len(sql_selected)%20%3D%3D%201%20else%20'variants'%7D%20and%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22Python%20selects%20%7Blen(python_selected)%7D%3A%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20(%22the%20same%20ones.%22%20if%20sql_selected%20%3D%3D%20python_selected%20else%20%22they%20differ.%22)%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%20kind%3D%22success%22%20if%20sql_selected%20%3D%3D%20python_selected%20else%20%22danger%22%2C%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%209%3A%20save%20the%20rule%20as%20your%20policy%0A%0A%20%20%20%20A%20rule%20you%20use%20to%20choose%20variants%20is%20a%20policy%20of%20your%20own%2C%20separate%20from%20Altar's%20results.%20Version%20it%20as%20you%0A%20%20%20%20would%20any%20analysis%20choice.%20The%20policy%20file%20records%3A%0A%0A%20%20%20%20-%20the%20rule%20as%20SQL%2C%20and%20its%20two%20parts%3B%0A%20%20%20%20-%20the%20thresholds%20and%20the%20combination%20you%20chose%2C%20and%20what%20a%20missing%20value%20means%3B%0A%20%20%20%20-%20the%20export%20it%20was%20evaluated%20on%3A%20its%20path%2C%20its%20SHA-256%20and%20its%20provenance%3B%0A%20%20%20%20-%20the%20variants%20the%20rule%20selected%2C%20and%20those%20it%20left%20unknown.%0A%0A%20%20%20%20Name%20the%20policy%2C%20then%20press%20**Save%20the%20policy**.%20The%20file%20goes%20in%20%60policies%2F%60%20in%20Tutorial%203's%20run%20directory%2C%0A%20%20%20%20beside%20the%20export.%20Saving%20again%20under%20the%20same%20name%20replaces%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%20policy_name%20%3D%20mo.ui.text(value%3D%22tutorial-04%22%2C%20label%3D%22Policy%20name%22)%0A%20%20%20%20save_button%20%3D%20mo.ui.run_button(label%3D%22Save%20the%20policy%22%2C%20kind%3D%22success%22)%0A%20%20%20%20mo.hstack(%5Bpolicy_name%2C%20save_button%5D%2C%20justify%3D%22start%22%2C%20align%3D%22end%22)%0A%20%20%20%20return%20policy_name%2C%20save_button%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20combination%2C%0A%20%20%20%20evaluated%2C%0A%20%20%20%20evidence_rule%2C%0A%20%20%20%20export_dir%2C%0A%20%20%20%20export_file%2C%0A%20%20%20%20has_alphagenome%2C%0A%20%20%20%20link_slider%2C%0A%20%20%20%20log2fc_slider%2C%0A%20%20%20%20missing_is_false%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_rule%2C%0A%20%20%20%20phylop_slider%2C%0A%20%20%20%20policy_name%2C%0A%20%20%20%20provenance%2C%0A%20%20%20%20quantile_slider%2C%0A%20%20%20%20rule_sql%2C%0A%20%20%20%20save_button%2C%0A%20%20%20%20sql_selected%2C%0A)%3A%0A%20%20%20%20mo.stop(%0A%20%20%20%20%20%20%20%20not%20(save_button.value%20or%20execute_requested(mo.cli_args()))%2C%0A%20%20%20%20%20%20%20%20mo.md(%22Press%20**Save%20the%20policy**%20to%20write%20the%20file.%22)%2C%0A%20%20%20%20)%0A%20%20%20%20thresholds%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22abs_counts_log2fc_min%22%3A%20log2fc_slider.value%2C%0A%20%20%20%20%20%20%20%20%22link_top_score_min%22%3A%20link_slider.value%2C%0A%20%20%20%20%20%20%20%20%22phylop100way_min%22%3A%20phylop_slider.value%2C%0A%20%20%20%20%7D%0A%20%20%20%20if%20has_alphagenome%3A%0A%20%20%20%20%20%20%20%20thresholds%5B%22alphagenome_max_abs_quantile_score_min%22%5D%20%3D%20quantile_slider.value%0A%20%20%20%20policy%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22name%22%3A%20policy_name.value%2C%0A%20%20%20%20%20%20%20%20%22rule_sql%22%3A%20rule_sql%2C%0A%20%20%20%20%20%20%20%20%22parts%22%3A%20%7B%22model%22%3A%20model_rule.to_sql()%2C%20%22evidence%22%3A%20evidence_rule.to_sql()%7D%2C%0A%20%20%20%20%20%20%20%20%22combination%22%3A%20combination.value%2C%0A%20%20%20%20%20%20%20%20%22thresholds%22%3A%20thresholds%2C%0A%20%20%20%20%20%20%20%20%22missing_values%22%3A%20%22false%22%20if%20missing_is_false.value%20else%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22export%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22file%22%3A%20str(export_file)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22sha256%22%3A%20file_digest(export_file)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22provenance%22%3A%20provenance%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22selected%22%3A%20sorted(sql_selected)%2C%0A%20%20%20%20%20%20%20%20%22unknown%22%3A%20sorted(evaluated.loc%5Bevaluated%5B%22my%20rule%22%5D.isna()%2C%20%22variant_id%22%5D)%2C%0A%20%20%20%20%7D%0A%20%20%20%20policy_path%20%3D%20export_dir.parent%20%2F%20%22policies%22%20%2F%20f%22%7Bpolicy_name.value%7D.json%22%0A%20%20%20%20policy_path.parent.mkdir(parents%3DTrue%2C%20exist_ok%3DTrue)%0A%20%20%20%20_written%20%3D%20policy_path.write_text(json.dumps(policy%2C%20indent%3D2)%20%2B%20%22%5Cn%22)%0A%20%20%20%20return%20(policy_path%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20policy_path)%3A%0A%20%20%20%20mo.callout(mo.md(f%22Saved%20the%20policy%20to%20%60%7Bdisplay_path(policy_path)%7D%60.%22)%2C%20kind%3D%22success%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Review%20the%20workflow%0A%0A%20%20%20%20The%20path%20was%3A%0A%0A%20%20%20%20%60export%20%2B%20provenance%20%E2%86%92%20your%20predicates%20%E2%86%92%20three-valued%20result%20%E2%86%92%20SQL%20%E2%86%92%20a%20saved%20policy%60%0A%0A%20%20%20%20The%20export%20kept%20the%20reasons%20of%20each%20default%20rule%2C%20and%20your%20rule%20sits%20beside%20them%20without%20changing%20them.%20A%20rule%0A%20%20%20%20is%20unknown%2C%20not%20false%2C%20when%20it%20reads%20a%20missing%20value.%20Decide%20what%20a%20missing%20value%20means%20for%20your%20question%2C%20and%0A%20%20%20%20write%20that%20into%20the%20rule%20with%20%60IsNull%60.%0A%0A%20%20%20%20Move%20the%20sliders%20and%20see%20the%20selection%20change%2C%20then%20save%20a%20second%20policy%20under%20another%20name.%20To%20keep%20a%20rule%0A%20%20%20%20from%20one%20run%20to%20the%20next%2C%20keep%20its%20policy%20file%20with%20the%20analysis%20that%20used%20it.%20A%20weighting%20across%20models%2C%20or%20a%0A%20%20%20%20learned%20ranking%2C%20is%20also%20a%20policy%20of%20your%20own.%0A%0A%20%20%20%20See%20%5BWrite%20a%20prioritization%20rule%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fpython%2Fpredicates%2F)%2C%0A%20%20%20%20%5BWhat%20%22prioritized%22%20means%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fscience%2Fprioritization%2F)%20and%0A%20%20%20%20%5BgnomAD%20filtering%5D(https%3A%2F%2Fkundajelab.github.io%2Faltar%2Fintegrations%2Fgnomad%2F%23filtering)%20for%20rarity%20rules%20over%20the%0A%20%20%20%20same%20export.%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
c23650cdf7e0bcbffa3a3275bd5d1077