hf-preimplantation-portal / pages /1_Gene_Expression.py
matq007's picture
feat: move from streamlit to hugging spaces
0e1164c unverified
#!/usr/bin/env python
import streamlit as st
from constants import DEFAULT_DR, DEFAULT_META
from utils import fetch_resource, plot_feature, plot_sc_embedding, ui_model_selection
st.set_page_config(layout="wide")
st.markdown("""
# Gene expression
Levels of gene activity along differentiation.
""")
ui_model_selection()
if st.session_state["SPECIE"] and st.session_state["VERSION"]:
adata = fetch_resource(st.session_state["SPECIE"], st.session_state["VERSION"])
sl_dr = st.sidebar.selectbox(
"**Dimension reduction**",
adata.obsm_keys(),
index=adata.obsm_keys().index(DEFAULT_DR),
placeholder="Select method ...",
)
st.sidebar.markdown(
f"Visualization done on `{adata.uns['neighbors']['params']['use_rep']}` space."
)
sl_metadata = st.sidebar.selectbox(
"**Metadata**",
adata.obs.columns,
index=adata.obs.columns.get_loc(DEFAULT_META),
placeholder="Select column ...",
)
sl_feature = st.sidebar.selectbox(
"**Gene**",
sorted(adata.raw.var_names),
index=0,
placeholder="Select gene ...",
)
is_imputed = sl_feature in adata.var_names
sl_denoised = st.sidebar.checkbox(
"Use denoised expression?",
help="Denoised expression is sampled from the decoder.",
disabled=(not is_imputed),
)
col1, col2 = st.columns(2)
plot_sc_embedding(adata, group_by=sl_metadata, reduction_key=sl_dr, ax=col1)
plot_sc_embedding(
adata, feature=sl_feature, reduction_key=sl_dr, layer=sl_denoised, ax=col2
)
st.markdown("## Raw gene expression")
plot_feature(adata, feature=sl_feature, group_by=sl_metadata, kind="box")