Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -79,7 +79,7 @@ gene_names = []
|
|
79 |
descriptions = []
|
80 |
|
81 |
for gene_id in gene_ids:
|
82 |
-
try:
|
83 |
TGME49_id = TGME49_transcript_annotations.loc[TGME49_transcript_annotations["gene_id"] == gene_id]["TGME49_id"].values[0]
|
84 |
gene_name = TGME49_transcript_annotations.loc[TGME49_transcript_annotations["gene_id"] == gene_id]["gene_name"].values[0]
|
85 |
description = TGME49_transcript_annotations.loc[TGME49_transcript_annotations["gene_id"] == gene_id]["description"].values[0]
|
@@ -92,14 +92,27 @@ for gene_id in gene_ids:
|
|
92 |
TGME49_ids.append(TGME49_id)
|
93 |
gene_names.append(gene_name)
|
94 |
descriptions.append(description)
|
95 |
-
|
96 |
node_info = pd.DataFrame({
|
|
|
97 |
"gene_id" : gene_ids,
|
98 |
"gene_type" : gene_types,
|
99 |
"TGME49_id": TGME49_ids,
|
100 |
"gene_name": gene_names,
|
101 |
"description": description})
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
################################
|
104 |
# Use NetworkX to layout graph #
|
105 |
################################
|
@@ -107,25 +120,17 @@ node_info = pd.DataFrame({
|
|
107 |
# but I'm unsure how to do it through the streamlit-cytoscapejs interface :(
|
108 |
|
109 |
|
110 |
-
st.write(f"gene_id_1: {neighbors.gene_id_1.to_list()}")
|
111 |
-
st.write(f"gene_id_2: {neighbors.gene_id_2.to_list()}")
|
112 |
-
st.write(f"coexp_score: {neighbors.coexp_score.to_list()}")
|
113 |
-
st.write(f"gene_id_1: {len(neighbors.gene_id_1.to_list())}")
|
114 |
-
st.write(f"gene_id_2: {len(neighbors.gene_id_2.to_list())}")
|
115 |
-
st.write(f"coexp_score: {len(neighbors.coexp_score.to_list())}")
|
116 |
-
|
117 |
-
|
118 |
G = nx.Graph()
|
119 |
G.add_weighted_edges_from(
|
120 |
-
[neighbors.
|
121 |
-
neighbors.
|
122 |
-
neighbors.coexp_score.to_list()
|
123 |
layout = nx.spring_layout(G)
|
124 |
|
125 |
|
126 |
|
127 |
elements = []
|
128 |
-
for i in range(
|
129 |
elements.append({
|
130 |
"data": {
|
131 |
"id": gene_ids[i],
|
@@ -133,7 +138,7 @@ for i in range(3):# range(len(gene_ids)):
|
|
133 |
"position": {
|
134 |
"x" : layout[gene_ids[i]][0],
|
135 |
"y" : layout[gene_ids[i]][1]}})
|
136 |
-
for i in range(
|
137 |
edge = neighbors.iloc[i]
|
138 |
elements.append({
|
139 |
"data" : {
|
|
|
79 |
descriptions = []
|
80 |
|
81 |
for gene_id in gene_ids:
|
82 |
+
try:
|
83 |
TGME49_id = TGME49_transcript_annotations.loc[TGME49_transcript_annotations["gene_id"] == gene_id]["TGME49_id"].values[0]
|
84 |
gene_name = TGME49_transcript_annotations.loc[TGME49_transcript_annotations["gene_id"] == gene_id]["gene_name"].values[0]
|
85 |
description = TGME49_transcript_annotations.loc[TGME49_transcript_annotations["gene_id"] == gene_id]["description"].values[0]
|
|
|
92 |
TGME49_ids.append(TGME49_id)
|
93 |
gene_names.append(gene_name)
|
94 |
descriptions.append(description)
|
95 |
+
|
96 |
node_info = pd.DataFrame({
|
97 |
+
"gene_index": range(gene_ids),
|
98 |
"gene_id" : gene_ids,
|
99 |
"gene_type" : gene_types,
|
100 |
"TGME49_id": TGME49_ids,
|
101 |
"gene_name": gene_names,
|
102 |
"description": description})
|
103 |
|
104 |
+
neighbors = neighbors.merge(
|
105 |
+
right = node_info,
|
106 |
+
left_by = "gene_id_1",
|
107 |
+
right_by = "gene_id",
|
108 |
+
suffix = "_1")
|
109 |
+
|
110 |
+
neighbors = neighbors.merge(
|
111 |
+
right = node_info,
|
112 |
+
left_by = "gene_id_2",
|
113 |
+
right_by = "gene_id",
|
114 |
+
suffix = "_2")
|
115 |
+
|
116 |
################################
|
117 |
# Use NetworkX to layout graph #
|
118 |
################################
|
|
|
120 |
# but I'm unsure how to do it through the streamlit-cytoscapejs interface :(
|
121 |
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
G = nx.Graph()
|
124 |
G.add_weighted_edges_from(
|
125 |
+
[neighbors.gene_index_1.to_list(),
|
126 |
+
neighbors.gene_index_2.to_list(),
|
127 |
+
neighbors.coexp_score.to_list())
|
128 |
layout = nx.spring_layout(G)
|
129 |
|
130 |
|
131 |
|
132 |
elements = []
|
133 |
+
for i in range(len(gene_ids)):
|
134 |
elements.append({
|
135 |
"data": {
|
136 |
"id": gene_ids[i],
|
|
|
138 |
"position": {
|
139 |
"x" : layout[gene_ids[i]][0],
|
140 |
"y" : layout[gene_ids[i]][1]}})
|
141 |
+
for i in range(len(neighbors.index)):
|
142 |
edge = neighbors.iloc[i]
|
143 |
elements.append({
|
144 |
"data" : {
|