File size: 1,848 Bytes
fc741fb
 
 
0e1164c
fc741fb
 
 
 
 
 
 
 
0e1164c
 
 
fc741fb
 
0e1164c
 
 
 
 
fc741fb
0e1164c
fc741fb
0e1164c
fc741fb
 
0e1164c
 
fc741fb
0e1164c
 
 
fc741fb
0e1164c
 
 
fc741fb
0e1164c
 
 
 
fc741fb
0e1164c
 
 
 
fc741fb
0e1164c
 
fc741fb
0e1164c
 
fc741fb
0e1164c
 
 
 
 
 
fc741fb
0e1164c
 
fc741fb
0e1164c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/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)