Skip to content

Commit

Permalink
Add data export option
Browse files Browse the repository at this point in the history
  • Loading branch information
nictru committed Mar 14, 2024
1 parent 13c2e23 commit d006bdf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from shiny import App, reactive, ui
import scanpy as sc
import os

from composition import composition_server, composition_ui
from export import export_ui, export_server
from dgea.dgea import dgea_server, dgea_ui

with open("data/input.txt") as f:
filename = "data/" + f.read().strip()
name = filename.replace(".h5ad", "")


adata = sc.read_h5ad(filename)
categorical_columns = adata.obs.select_dtypes(include="category").columns.to_list()

Expand All @@ -17,8 +20,9 @@
composition_ui("composition")
),
ui.nav_panel("Differential expression analysis",
dgea_ui("dgea")
),
dgea_ui("dgea")),
ui.nav_panel("Data export",
export_ui("export")),
title=f"SIMBA🦁 downstream: {name}",
id="page"
)
Expand All @@ -28,8 +32,7 @@ def server(input, output, session):
_dataframe = reactive.value(adata.obs)
_adata = reactive.value(adata)
composition_server("composition", _dataframe)
export_server("export")
dgea_server("dgea", _adata)



app = App(app_ui, server)
59 changes: 59 additions & 0 deletions export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from shiny import reactive, ui, render, module
import os
import re

annotations_directory = "data/annotations"

def get_files(regex, directory=annotations_directory):
return [os.path.join(directory, f)
for f in os.listdir(directory)
if regex.match(f)]

def get_gene_sets():
regex = re.compile(r".*-gene-sets-[A-Z0-9]+.csv")
return get_files(regex)

def get_cell_labels():
regex = re.compile(r".*-cell-labels-[A-Z0-9]+.csv")
return get_files(regex)


@module.ui
def export_ui():
return ui.input_action_button("update", "Update"), \
ui.navset_tab(
ui.nav_panel("Gene sets",
ui.output_ui("render_gene_sets")
),
ui.nav_panel("Cell labels",
ui.output_ui("render_cell_labels")
)
)


@module.server
def export_server(input, output, session):
_gene_sets = reactive.value([])
_cell_labels = reactive.value([])

@reactive.effect
@reactive.event(input["update"])
def update_files():
files = get_gene_sets()
_gene_sets.set(files)

files = get_cell_labels()
_cell_labels.set(files)


@render.ui
def render_gene_sets():
gene_sets = _gene_sets.get()

return [ui.input_action_button(f"download_{os.path.basename(f).replace('-', '_')[:-4]}", f"Download {os.path.basename(f)}") for f in gene_sets]

@render.ui
def render_cell_labels():
cell_labels = _cell_labels.get()

return [ui.input_action_button(f"download_{os.path.basename(f).replace('-', '_')[:-4]}", f"Download {os.path.basename(f)}") for f in cell_labels]

0 comments on commit d006bdf

Please sign in to comment.