Spaces:
Sleeping
Sleeping
add support for setting thresholds
Browse files
app.py
CHANGED
|
@@ -14,11 +14,19 @@ if "gene_ids" in query_params.keys():
|
|
| 14 |
input_gene_ids = query_params["gene_ids"]
|
| 15 |
else:
|
| 16 |
input_gene_ids = "TGME49_231630,TGME49_230210"
|
| 17 |
-
|
| 18 |
# use "\n" as the separator so it shows correctly in the text area
|
| 19 |
input_gene_ids = input_gene_ids.replace(",", "\n")
|
| 20 |
-
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
st.markdown("""
|
| 24 |
# ToxoCEN Network
|
|
@@ -54,7 +62,32 @@ with col1:
|
|
| 54 |
value = f"{input_gene_ids}",
|
| 55 |
help = "TGME49 Gene IDs e.g. TGME49_231630")
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
##################################
|
| 60 |
# Parse and check the user input #
|
|
@@ -70,12 +103,14 @@ for input_gene_id in input_gene_ids.split("\n"):
|
|
| 70 |
|
| 71 |
neighbors = []
|
| 72 |
for seed_gene_id in seed_gene_ids:
|
| 73 |
-
|
| 74 |
-
top_coexp_hits[
|
| 75 |
(top_coexp_hits.gene_id_1 == seed_gene_id) & (top_coexp_hits.coexp_score > coexp_score_threshold)])
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
neighbors = pd.concat(neighbors)
|
| 78 |
-
|
| 79 |
neighbor_gene_ids = list(set(neighbors.gene_id_2))
|
| 80 |
gene_ids = seed_gene_ids + neighbor_gene_ids
|
| 81 |
gene_types = ['seed'] * len(seed_gene_ids) + ['neighbor'] * len(neighbor_gene_ids)
|
|
|
|
| 14 |
input_gene_ids = query_params["gene_ids"]
|
| 15 |
else:
|
| 16 |
input_gene_ids = "TGME49_231630,TGME49_230210"
|
| 17 |
+
|
| 18 |
# use "\n" as the separator so it shows correctly in the text area
|
| 19 |
input_gene_ids = input_gene_ids.replace(",", "\n")
|
|
|
|
| 20 |
|
| 21 |
+
if "coexp_score_threshold" in query_params.keys():
|
| 22 |
+
coexp_score_threshold = query_params["coexp_score_threshold"]
|
| 23 |
+
else:
|
| 24 |
+
coexp_score_threshold = "0.85"
|
| 25 |
+
|
| 26 |
+
if "max_per_gene" in query_params.keys():
|
| 27 |
+
max_per_gene = query_params["max_per_gene"]
|
| 28 |
+
else:
|
| 29 |
+
max_per_gene = "25"
|
| 30 |
|
| 31 |
st.markdown("""
|
| 32 |
# ToxoCEN Network
|
|
|
|
| 62 |
value = f"{input_gene_ids}",
|
| 63 |
help = "TGME49 Gene IDs e.g. TGME49_231630")
|
| 64 |
|
| 65 |
+
|
| 66 |
+
with col2:
|
| 67 |
+
coexp_score_threshold = st.text_input(
|
| 68 |
+
label = "Co-expression threshold [0-1]",
|
| 69 |
+
value = f"{coexp_score_threshold}",
|
| 70 |
+
help = "Default: 0.85")
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
coexp_score_threshold = float(coexp_score_threshold)
|
| 74 |
+
except:
|
| 75 |
+
st.error(f"Co-expression threshold should be a number between 0 and 1, instead it is '{coexp_score_threshold}'")
|
| 76 |
+
if coexp_score_threshold < 0 or 1 < coexp_score_threshold:
|
| 77 |
+
st.error(f"Co-expression threshold should be a number between 0 and 1, instead it is '{coexp_score_threshold}'")
|
| 78 |
+
|
| 79 |
+
max_per_gene = st.text_input(
|
| 80 |
+
label = "Max per gene",
|
| 81 |
+
value = f"{max_per_gene}",
|
| 82 |
+
help = "Default: 25")
|
| 83 |
+
|
| 84 |
+
try:
|
| 85 |
+
max_per_gene = int(max_per_gene)
|
| 86 |
+
except:
|
| 87 |
+
st.error(f"Max per gene should be a number greater than 0, instead it is '{max_per_gene}'")
|
| 88 |
+
if max_per_gene <= 0:
|
| 89 |
+
st.error(f"Max per gene should be a number greater than 0, instead it is '{max_per_gene}'")
|
| 90 |
+
|
| 91 |
|
| 92 |
##################################
|
| 93 |
# Parse and check the user input #
|
|
|
|
| 103 |
|
| 104 |
neighbors = []
|
| 105 |
for seed_gene_id in seed_gene_ids:
|
| 106 |
+
hits = top_coexp_hits[
|
|
|
|
| 107 |
(top_coexp_hits.gene_id_1 == seed_gene_id) & (top_coexp_hits.coexp_score > coexp_score_threshold)])
|
| 108 |
+
if len(hits.index) > max_per_gene:
|
| 109 |
+
hits = hits[0:max_per_gene]
|
| 110 |
+
neighbors.append(hits)
|
| 111 |
|
| 112 |
neighbors = pd.concat(neighbors)
|
| 113 |
+
|
| 114 |
neighbor_gene_ids = list(set(neighbors.gene_id_2))
|
| 115 |
gene_ids = seed_gene_ids + neighbor_gene_ids
|
| 116 |
gene_types = ['seed'] * len(seed_gene_ids) + ['neighbor'] * len(neighbor_gene_ids)
|