maom commited on
Commit
7d0aa96
·
verified ·
1 Parent(s): 5f46d91

initial app

Browse files
Files changed (1) hide show
  1. app.py +141 -0
app.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import streamlit as st
3
+ from st_aggrid import AgGrid, GridOptionsBuilder, JsCode
4
+
5
+ st.set_page_config(layout='wide')
6
+
7
+ # parse out gene_ids from URL query args to it's possible to link to this page
8
+ query_params = st.query_params
9
+ if "gene_id" in query_params.keys():
10
+ gene_id = query_params["gene_id"]
11
+ else:
12
+ gene_id = "TGME49_231630"
13
+
14
+
15
+ st.markdown("""
16
+ # ToxoCEN Top50 co-expressed partners
17
+
18
+ **ToxoCEN** is a co-expression network for *Cryptococcus neoformans* built on 719 RNA-seq runs across 39 studies.
19
+ A pair of genes are said to be co-expressed when their expression is correlated across different conditions and
20
+ is often a marker for genes to be involved in similar processes.
21
+
22
+ To Cite:<br>
23
+ CS Arnold, Y Wang, VB Carruthers, MJ O'Meara ToxoCEN: A Co-Expression Network for Toxoplasma gondii
24
+ * Code available at https://github.com/maomlab/CalCEN/tree/master/vignettes/ToxoCEN
25
+ * Full network and dataset: https://huggingface.co/datasets/maomlab/ToxoCEN
26
+
27
+ ## Look up top-coexpressed partners:
28
+ Put in the ``TGME49_######`` gene_id for a gene and expand the table to get the top 50 co-expressed genes.
29
+ ``coexp_score`` ranges between ``[0-1]``, where ``1`` is the best and greater than ``0.85`` can be considered significant.
30
+ """)
31
+
32
+ top_coexp_hits = datasets.load_dataset(
33
+ path = "maomlab/ToxoCEN",
34
+ data_files = {"top_coexp_hits": "top_coexp_hits.tsv"})
35
+ top_coexp_hits = top_coexp_hits["top_coexp_hits"].to_pandas()
36
+
37
+ col1, col2, col3 = st.columns(spec = [0.3, 0.2, 0.5])
38
+ with col1:
39
+ gene_id = st.text_input(
40
+ label = "Gene ID",
41
+ value = f"{gene_id}",
42
+ max_chars = 10,
43
+ help = "TGME49 Gene ID e.g. CTGME49_231630")
44
+
45
+ top_coexp_hits = top_coexp_hits[
46
+ top_coexp_hits.gene_id_1 == gene_id]
47
+ top_coexp_hits = top_coexp_hits[[
48
+ 'gene_id_1', 'gene_name_1', 'description_1',
49
+ 'gene_id_2', 'gene_name_2', 'description_2',
50
+ 'coexp_score', 'blastp_EValue']]
51
+ top_coexp_hits["scatter_link"] = top_coexp_hits.apply(
52
+ lambda row: f"https://huggingface.co/spaces/maomlab/ToxoCEN-ExpressionScatter?gene_id_1={row.gene_id_1}&gene_id_2={row.gene_id_2}",
53
+ axis = 1)
54
+
55
+ top_coexp_hits.reset_index()
56
+
57
+ with col2:
58
+ st.text('') # help alignment with input box
59
+ st.download_button(
60
+ label = "Download data as TSV",
61
+ data = top_coexp_hits.to_csv(sep ='\t').encode('utf-8'),
62
+ file_name = f"top_coexp_hits_{gene_id}.tsv",
63
+ mime = "text/csv")
64
+
65
+ # third column is padding only
66
+
67
+
68
+ ######### Table #########
69
+
70
+ fungidb_link_renderer = JsCode("""
71
+ class UrlCellRenderer {
72
+ init(params) {
73
+ this.eGui = document.createElement('a');
74
+ this.eGui.innerText = params.value;
75
+ this.eGui.setAttribute('href', "https://toxodb.org/toxo/app/record/gene/" + params.value);
76
+ this.eGui.setAttribute('style', "text-decoration:none");
77
+ this.eGui.setAttribute('target', "_blank");
78
+ }
79
+ getGui() {
80
+ return this.eGui;
81
+ }
82
+ }
83
+ """)
84
+
85
+ coexp_scatter_link_renderer = JsCode("""
86
+ class UrlCellRenderer {
87
+ init(params) {
88
+ this.eGui = document.createElement('a');
89
+ this.eGui.innerText = 'plot';
90
+ this.eGui.setAttribute('href', params.value);
91
+ this.eGui.setAttribute('style', "text-decoration:none");
92
+ this.eGui.setAttribute('target', "_blank");
93
+ }
94
+ getGui() {
95
+ return this.eGui;
96
+ }
97
+ }
98
+ """)
99
+
100
+
101
+
102
+ grid_option_builder = GridOptionsBuilder()
103
+ grid_option_builder.configure_auto_height()
104
+ grid_option_builder.configure_default_column(
105
+ filterable=False,
106
+ groupable=False,
107
+ editable=False,
108
+ wrapText=True,
109
+ autoHeight=True)
110
+ grid_option_builder.configure_column("gene_id_1", header_name="GeneID 1", pinned="left", cellRenderer=fungidb_link_renderer, width=550)
111
+ grid_option_builder.configure_column("gene_name_1", header_name="Gene 1", pinned="left", width=500)
112
+ grid_option_builder.configure_column("description_1", header_name="Description 1", width=1600)
113
+ grid_option_builder.configure_column("gene_id_2", header_name="GeneID 2", pinned="left", cellRenderer=fungidb_link_renderer, width=550)
114
+ grid_option_builder.configure_column("gene_name_2", header_name="Gene 2", pinned="left", width=500)
115
+ grid_option_builder.configure_column("description_2", header_name="Description 2", width=1600)
116
+ grid_option_builder.configure_column(
117
+ "coexp_score",
118
+ header_name="Coexp Score",
119
+ type=["numericColumn", "customNumericFormat"],
120
+ precision=3,
121
+ width=600)
122
+ grid_option_builder.configure_column(
123
+ "blast_EValue",
124
+ header_name="Blast E-value",
125
+ type=["numericColumn", "customNumericFormat"],
126
+ precision=3,
127
+ width=600)
128
+ grid_option_builder.configure_column(
129
+ "scatter_link",
130
+ header_name="Expression Scatterplot",
131
+ cellRenderer=coexp_scatter_link_renderer,
132
+ width=550)
133
+
134
+ grid_option_builder.configure_selection(selection_mode=False, use_checkbox=False)
135
+
136
+ AgGrid(
137
+ data = top_coexp_hits,
138
+ gridOptions = grid_option_builder.build(),
139
+ fit_columns_on_grid_load=True,
140
+ theme="streamlit",
141
+ allow_unsafe_jscode=True)