hf-preimplantation-portal / pages /2_Differentially_Expressed_Genes.py
matq007's picture
feat: move from streamlit to hugging spaces
0e1164c unverified
#!/usr/bin/env python
import streamlit as st
from utils import fetch_resource, get_degs, ui_model_selection
st.set_page_config(layout="wide")
st.markdown("""
# Differentially expressed genes
Genes below have been determined using `sc.tl.rank_genes_groups` where `t-test_overestim_var`
is the default method.
""")
ui_model_selection()
filter_flag = []
if st.session_state["SPECIE"] and st.session_state["VERSION"]:
adata = fetch_resource(st.session_state["SPECIE"], st.session_state["VERSION"])
degs_by = st.sidebar.selectbox(
"**Select by**",
[x for x in adata.uns_keys() if "degs" in x],
index=None,
placeholder="Differentially expressed genes by",
)
if degs_by:
degs = get_degs(adata, degs_by)
group = st.sidebar.multiselect(
"**Cell type**", degs["group"].unique(), placeholder="Select group ..."
)
genes = st.sidebar.multiselect(
"**Gene**", sorted(degs["names"].unique()), placeholder="Select genes ..."
)
foldchange = st.sidebar.number_input(
"**Log2 fold-change**",
value=1,
)
pval_adj = st.sidebar.number_input(
"**Adjusted p-value**",
value=0.05,
)
if group:
filter_flag.append("group == @group")
if genes:
filter_flag.append("@genes in names")
if foldchange:
filter_flag.append(
"logfoldchanges > @foldchange"
if foldchange > 0
else "logfoldchanges < @foldchange"
)
if pval_adj:
filter_flag.append("pvals_adj < @pval_adj")
subset = degs.query(" & ".join(filter_flag)) if filter_flag else degs
st.dataframe(subset, use_container_width=True, height=650)