maom commited on
Commit
e2ef0ff
·
verified ·
1 Parent(s): a22e86a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +139 -0
app.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import streamlit as st
3
+ import numpy as np
4
+ import pandas as pd
5
+ import altair as alt
6
+
7
+ st.set_page_config(layout='wide')
8
+
9
+ # parse out feature_names from URL query args to it's possible to link to this page
10
+ query_params = st.query_params
11
+ if "feature_name_1" in query_params.keys():
12
+ feature_name_1 = query_params["feature_name_1"]
13
+ else:
14
+ feature_name_1 = "C3_06330W_A"
15
+
16
+ if "feature_name_2" in query_params.keys():
17
+ feature_name_2 = query_params["feature_name_2"]
18
+ else:
19
+ feature_name_2 = "C3_06180C_A"
20
+
21
+
22
+
23
+
24
+ st.markdown("""
25
+ # CaurisCEN Expression Scatter
26
+ **CaurisCEN** is a co-expression network for *Candida auris* built on 577 RNA-seq runs across 2 96-well plates formats in 3 biological replicas.
27
+ A pair of genes are said to be co-expressed when their expression is correlated across different conditions and
28
+ is often a marker for genes to be involved in similar processes.
29
+ To Cite:
30
+ Rapala JR, MJ O'Meara, TR O'Meara
31
+ CaurisCEN: A Co-Expression Network for Candida auris
32
+ * Code available at https://github.com/maomlab/CalCEN/tree/master/vignettes/CaurisCEN
33
+ * Full network and dataset: https://huggingface.co/datasets/maomlab/CaurisCEN
34
+
35
+ ## Plot scatter plot expression for a pair of genes across studies.
36
+ Put in the ``B9J08 e.g. B9J08_000884`` chromosome feature name for two genes.
37
+ """)
38
+
39
+ gene_metadata = datasets.load_dataset(
40
+ path = "maomlab/CaurisCEN",
41
+ name = "gene_metadata",
42
+ data_dir = "gene_metadata/data")['train'].to_pandas()
43
+
44
+ expression_runs = datasets.load_dataset(
45
+ path = "maomlab/CaurisCEN",
46
+ name = "run_metadata",
47
+ data_dir = "run_metadata/data")['train'].to_pandas()
48
+
49
+ expression_matrix = datasets.load_dataset(
50
+ path = "maomlab/CaurisCEN",
51
+ name = "expression_matrix",
52
+ data_dir = "expression_matrix")['train'].to_pandas()
53
+
54
+
55
+ #DEBUG
56
+ print(f"estimated_expression shape: {estimated_expression.shape}")
57
+
58
+ col1, col2, col3, padding = st.columns(spec = [0.2, 0.2, 0.2, 0.4])
59
+ with col1:
60
+ feature_name_1 = st.text_input(
61
+ label = "Feature Name 1",
62
+ value = f"{feature_name_1}",
63
+ max_chars = 10,
64
+ help = "B9J08 Locus Tag e.g. B9J08_000884")
65
+
66
+ with col2:
67
+ feature_name_2 = st.text_input(
68
+ label = "Feature Name 2",
69
+ value = f"{feature_name_2}",
70
+ max_chars = 10,
71
+ help = "B9J08 New Locus Tag e.g. B9J08_004112")
72
+
73
+ # check the user input
74
+ try:
75
+ feature_name_1 = gene_metadata.loc[gene_metadata["locus_tag_old"] == feature_name_1]["feature_name"].values[0]
76
+ gene_name_1 = gene_metadata.loc[gene_metadata["locus_tag_old"] == feature_name_1]["gene_name"].values[0]
77
+ description_1 = gene_metadata.loc[gene_metadata["locus_tag_old"] == feature_name_1]["description"].values[0]
78
+ except:
79
+ st.error(f"Unable to locate Feature Name for gene 1: {feature_name_1}, it should be of the form 'B9J08_######'")
80
+
81
+ try:
82
+ feature_name_2 = gene_metadata.loc[chromosome_features["locus_tag_old"] == feature_name_2]["feature_name"].values[0]
83
+ gene_name_2 = gene_metadata.loc[chromosome_features["locus_tag_old"] == feature_name_2]["gene_name"].values[0]
84
+ description_2 = gene_metadata.loc[chromosome_features["locus_tag_old"] == feature_name_2]["description"].values[0]
85
+ except:
86
+ st.error(f"Unable to locate Feature Name for gene 2: {feature_name_2}, it should be of the form 'B9J08_######'")
87
+
88
+ expression_1 = expression_matrix.loc[expression_matrix["gene"] == feature_name_1].transpose()[1:].to_numpy()
89
+ expression_2 = expression_matrix.loc[expression_matrix["gene"] == feature_name_2].transpose()[1:].to_numpy()
90
+
91
+ chart_data = pd.DataFrame({
92
+ "feature_name_1": feature_name_1,
93
+ "feature_name_2": feature_name_2,
94
+ "expression_1": expression_1,
95
+ "expression_2": expression_2,
96
+ "log_expression_1": np.log10(expression_1 + 1),
97
+ "log_expression_2": np.log10(expression_2 + 1),
98
+ "run_accession": expression_matrix.columns[1:]})
99
+ chart_data = chart_data.merge(
100
+ right = expression_runs,
101
+ on = "run_accession")
102
+
103
+ with col3:
104
+ st.text('') # help alignment with input box
105
+ st.download_button(
106
+ label = "Download data as TSV",
107
+ data = chart_data.to_csv(sep ='\t').encode('utf-8'),
108
+ file_name = f"CalCEN_expression_{feature_name_1}_vs_{feature_name_2}.tsv",
109
+ mime = "text/csv")
110
+
111
+
112
+ st.markdown(f"""
113
+ #### Gene 1:
114
+ * *Gene ID*: [{feature_name_1}](http://www.candidagenome.org/cgi-bin/locus.pl?locus={feature_name_1}&organism=C_auris_B8441)
115
+ {'* *Gene Name*:' + gene_name_1 if gene_name_1 is not None else ''}
116
+ * *Description*: {description_1}
117
+ * *Top [Co-Expressed Partners](https://huggingface.co/spaces/maomlab/CaurisCEN-TopHits?feature_name={feature_name_1})*
118
+
119
+ #### Gene 2:
120
+ * *Gene ID*: [{feature_name_2}](http://www.candidagenome.org/cgi-bin/locus.pl?locus={feature_name_2}&organism=C_auris_B8441)
121
+ {'* *Gene Name*:' + gene_name_2 if gene_name_2 is not None else ''}
122
+ * *Description*: {description_2}
123
+ * *Top [Co-Expressed Partners](https://huggingface.co/spaces/maomlab/CaurisCEN-TopHits?feature_name={feature_name_2})*
124
+ """)
125
+
126
+ chart = (
127
+ alt.Chart(
128
+ chart_data,
129
+ width = 750,
130
+ height = 750)
131
+ .mark_circle()
132
+ .encode(
133
+ x=alt.X("log_expression_1", title=f"Log10[{feature_name_1}+1] Expression"),
134
+ y=alt.Y("log_expression_2", title=f"Log10[{feature_name_2}+1] Expression"),
135
+ color=alt.Color("study_accession", title="Study Accession"),
136
+ tooltip=["run_accession", "study_accession"]))
137
+
138
+ st.altair_chart(
139
+ chart)