Spaces:
Running on Zero
Running on Zero
Virtual OpenCell: show the full map by default, below the viewer
Browse filesFiles changed (2)
297 unmodified lines2982993003013023038 unmodified lines31231331431531631731823 unmodified lines3423433443453463473483493503513523533543553 unmodified lines359360361362363364365366367368369370371372373374297 unmodified linesprint(f"[startup] virtual OpenCell preload failed: {exc}")info0, thumbs0, image0, file0 = viewer.error_html(viewer.DEFAULT_GENE, exc), None, None, Noneumap0 = umap_plot(viewer.DEFAULT_GENE)with gr.Column(elem_id="virtual-opencell"):with gr.Row(elem_classes="vo-navbar", equal_height=True):8 unmodified linesinfo = gr.HTML(info0)gr.HTML(viewer.UMAP_HTML, padding=False)umap = gr.Plot(value=umap0, show_label=False, elem_classes="vo-umap")open_full = gr.Button("View full map", size="sm", variant="secondary", elem_id="vo-fullmap-open")with gr.Column(scale=6):with gr.Row():23 unmodified linest_max = gr.Slider(1, 150, value=defaults[5], step=1, label="Intensity max (%)")t_gamma = gr.Slider(0.5, 1.5, value=defaults[6], step=0.05, label="Gamma")# the full map: every image and every protein named; built only when opened (~2 MB)with gr.Column(visible=False, elem_id="vo-fullmap") as full_section:with gr.Row():gr.HTML('<div class="vo-target"><div class="vo-section-header">Full virtual staining map</div>''<div class="vo-section-caption">All 93,510 generated images, each protein named at the ''centre of its images; zoom in to separate the names</div></div>', padding=False)close_full = gr.Button("Close", size="sm", variant="secondary", scale=0, min_width=100)full_map = gr.Plot(show_label=False, elem_classes="vo-umap-full")gr.HTML(viewer.FOOTER_HTML)3 unmodified linesprotein.change(select_protein, inputs=[protein] + settings,outputs=[info, samples, image, index, download, umap])def open_full_map(gene):try:fig = viewer.umap_figure(gene, full=True)except Exception as exc:raise gr.Error(f"Could not load the map: {exc}") from excreturn gr.Column(visible=True), figopen_full.click(open_full_map, inputs=protein, outputs=[full_section, full_map]).then(None, js="() => document.getElementById('vo-fullmap')?.scrollIntoView({behavior: 'smooth'})")close_full.click(lambda: (gr.Column(visible=False), None), outputs=[full_section, full_map])# Redraws take milliseconds: no progress overlay, and a dragged slider only renders its latest valuesamples.select(select_sample, inputs=[protein] + settings, outputs=[image, index, download],show_progress="hidden")297 unmodified lines2982993003013023033043053063073088 unmodified lines31731831932032132223 unmodified lines3463473483493503513523533543553563573 unmodified lines361362363364365366297 unmodified linesprint(f"[startup] virtual OpenCell preload failed: {exc}")info0, thumbs0, image0, file0 = viewer.error_html(viewer.DEFAULT_GENE, exc), None, None, Noneumap0 = umap_plot(viewer.DEFAULT_GENE)try:full_map0 = viewer.umap_figure("", full=True)except Exception as exc: # the map is an extra; the images work without itprint(f"[virtual opencell] full map unavailable: {exc}")full_map0 = Nonewith gr.Column(elem_id="virtual-opencell"):with gr.Row(elem_classes="vo-navbar", equal_height=True):8 unmodified linesinfo = gr.HTML(info0)gr.HTML(viewer.UMAP_HTML, padding=False)umap = gr.Plot(value=umap0, show_label=False, elem_classes="vo-umap")with gr.Column(scale=6):with gr.Row():23 unmodified linest_max = gr.Slider(1, 150, value=defaults[5], step=1, label="Intensity max (%)")t_gamma = gr.Slider(0.5, 1.5, value=defaults[6], step=0.05, label="Gamma")# the full map: every image and every protein named. One fixed figure (~2 MB) sent with the# page; the panel map above follows the selection, so this one never has to be re-sentgr.HTML('<div class="vo-target"><div class="vo-section-header">Full virtual staining map</div>''<div class="vo-section-caption">All 93,510 generated images, each protein named at the ''centre of its images; zoom in to separate the names</div></div>', padding=False)gr.Plot(value=full_map0, show_label=False, elem_classes="vo-umap-full")gr.HTML(viewer.FOOTER_HTML)3 unmodified linesprotein.change(select_protein, inputs=[protein] + settings,outputs=[info, samples, image, index, download, umap])# Redraws take milliseconds: no progress overlay, and a dragged slider only renders its latest valuesamples.select(select_sample, inputs=[protein] + settings, outputs=[image, index, download],show_progress="hidden")
165 unmodified lines166167168169170171172118 unmodified lines29129229329429529629718 unmodified lines316317318319320321322323324325326327328329330331332333334335336337338165 unmodified lines"""The map of every protein's samples, coloured by OpenCell localization, with `gene` outlined.The panel map draws the backdrop subsample; full=True draws all 93,510 points and names everyprotein, like umap_embedding_selected_all.svg (about 2 MB, so only built when asked for)."""xy, labels, genes, backdrop = umap_data()points = np.arange(len(genes)) if full else backdrop118 unmodified lines<div class="vo-section-caption">Each dot is one generated image, placed by UMAP of its embedding from CELL-FM'sOpenCell ViT and coloured by OpenCell's localization of the real cell line. The background shows{UMAP_POINTS_PER_PROTEIN} images per protein; the selected protein shows all of its images, outlined in black.Click the map for the full map, with every image and every protein named.</div></div>"""18 unmodified linesHEAD = """<link rel="preconnect" href="https://fonts.googleapis.com"><link href="https://fonts.googleapis.com/css2?family=Lato:wght@300;400;600;700&family=Nunito+Sans:wght@300;400;700&display=swap" rel="stylesheet"><script>// A click on the panel map opens the full map (Gradio's plot has no click event). A drag is a// zoom or pan, not a click, so only presses that end where they started count.(() => {let down = null;document.addEventListener("pointerdown", (e) => {down = e.target.closest("#virtual-opencell .vo-umap") && !e.target.closest(".modebar")? [e.clientX, e.clientY] : null;}, true);document.addEventListener("pointerup", (e) => {if (down && Math.hypot(e.clientX - down[0], e.clientY - down[1]) < 5) {document.getElementById("vo-fullmap-open")?.click();}down = null;}, true);})();</script>"""# OpenCell's look (its stylesheet: navbar, clm-*, metadata-*, localization-grade-*,165 unmodified lines166167168169170171172118 unmodified lines29129229329429529629718 unmodified lines316317318319320321165 unmodified lines"""The map of every protein's samples, coloured by OpenCell localization, with `gene` outlined.The panel map draws the backdrop subsample; full=True draws all 93,510 points and names everyprotein, like umap_embedding_selected_all.svg (about 2 MB). An empty `gene` outlines nothing."""xy, labels, genes, backdrop = umap_data()points = np.arange(len(genes)) if full else backdrop118 unmodified lines<div class="vo-section-caption">Each dot is one generated image, placed by UMAP of its embedding from CELL-FM'sOpenCell ViT and coloured by OpenCell's localization of the real cell line. The background shows{UMAP_POINTS_PER_PROTEIN} images per protein; the selected protein shows all of its images, outlined in black.The full map, with every image and every protein named, is below.</div></div>"""18 unmodified linesHEAD = """<link rel="preconnect" href="https://fonts.googleapis.com"><link href="https://fonts.googleapis.com/css2?family=Lato:wght@300;400;600;700&family=Nunito+Sans:wght@300;400;700&display=swap" rel="stylesheet">"""# OpenCell's look (its stylesheet: navbar, clm-*, metadata-*, localization-grade-*,
app.py+11-19
cell_fm/apps/virtual_opencell/viewer.py+2-19