Skip to content

Commit 45b4237

Browse files
committed
Add descriptions for plotly buttons (an embeded HTML)
1 parent 60f692b commit 45b4237

22 files changed

+335
-62
lines changed

config/BMCBioinformatics2021.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"interpolation": 0.2,
66
"idx_reference_snapshot": 30,
77
"num_nearest_neighbors": [20],
8-
"projected_nodes": [1022, 6285, 4683, 6777, 7345, 3148, 10220, 6753, 4601, 3481, 51444, 9517, 51205, 9360, 1068, 9229, 1017, 1981, 9218, 55024],
8+
"projected_nodes": [1022, 6285, 4683, 6777, 7345, 3148, 10220, 6753, 4601, 3481, 51444, 9517, 51205, 9360, 1068, 9229, 1017, 1981, 9218, 55024, 306, 1520, 2212, 1281, 1277, 1287],
99
"perplexity": 20,
1010
"reference_nodes": "reference_nodes.json"
1111
}

config/HistWords-CN-GNN.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"embedding_dim": 128,
3+
"idx_reference_snapshot": 4,
4+
"interpolation": 0.2,
5+
"model_name": "GConvGRU",
6+
"num_nearest_neighbors": [20],
7+
"perplexity": 20,
8+
"projected_nodes": ["节约", "资源", "生态", "环境", "绿色", "气候", "地球"],
9+
"reference_nodes": "reference_nodes.json"
10+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

dygetiviz/data/dataloader.py renamed to dygetviz/data/dataloader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def load_data() -> dict:
127127

128128
elif args.dataset_name == "BMCBioinformatics2021":
129129

130+
plot_anomaly_labels = True
131+
130132
metadata_df = pd.read_excel(
131133
osp.join("data", args.dataset_name, "metadata.xlsx"))
132134
metadata_df = metadata_df.rename(columns={"entrez": "node"})

dygetviz/demo/annotate_scatterplot.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Import libraries
2+
import dash
3+
from dash import dcc, html
4+
from dash.dependencies import Input, Output
5+
import plotly.express as px
6+
import pandas as pd
7+
8+
# Sample data
9+
df = pd.DataFrame({
10+
'x': [1, 2, 3, 4, 5],
11+
'y': [1, 4, 2, 3, 5],
12+
'name': ['A', 'B', 'C', 'D', 'E']
13+
})
14+
15+
# Create a Dash app
16+
app = dash.Dash(__name__)
17+
18+
# Define the app layout
19+
app.layout = html.Div([
20+
dcc.Graph(
21+
id='scatter-plot',
22+
config={'staticPlot': False, 'displayModeBar': True},
23+
figure=px.scatter(df, x='x', y='y')
24+
)
25+
])
26+
27+
# List to keep track of current annotations
28+
annotations = []
29+
30+
31+
# Callback to annotate point on click
32+
@app.callback(
33+
Output('scatter-plot', 'figure'),
34+
Input('scatter-plot', 'clickData')
35+
)
36+
def display_click_data(clickData):
37+
global annotations
38+
if clickData:
39+
point_data = clickData['points'][0]
40+
idx = point_data['pointIndex']
41+
point_name = df['name'].iloc[idx]
42+
43+
# Check if the point is already annotated
44+
existing_annotation = next((a for a in annotations if
45+
a['x'] == point_data['x'] and a['y'] ==
46+
point_data['y']), None)
47+
48+
if existing_annotation:
49+
# Remove existing annotation
50+
annotations.remove(existing_annotation)
51+
else:
52+
# Add new annotation
53+
annotations.append({
54+
'x': point_data['x'],
55+
'y': point_data['y'],
56+
'xref': 'x',
57+
'yref': 'y',
58+
'text': point_name,
59+
'showarrow': False
60+
})
61+
62+
fig2 = go.Figure()
63+
64+
fig = px.scatter(df, x='x', y='y')
65+
fig.update_layout(annotations=annotations)
66+
return fig
67+
68+
69+
# Run the app
70+
if __name__ == '__main__':
71+
app.run_server(debug=False, port=8049)

dygetviz/demo/get_gene_name.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from Bio import Entrez
2+
3+
4+
def get_gene_name_by_entrez_id(entrez_id):
5+
Entrez.email = "[email protected]" # Always tell NCBI who you are
6+
handle = Entrez.efetch(db="gene", id=entrez_id, retmode="xml")
7+
records = Entrez.read(handle)
8+
9+
# The gene name can usually be found in the "Gene-ref" field, under "locus"
10+
try:
11+
gene_name = records[0]["Entrezgene_gene"]["Gene-ref"]["Gene-ref_locus"]
12+
return gene_name
13+
except (KeyError, IndexError):
14+
return None
15+
16+
17+
entrez_id = 5296
18+
gene_name = get_gene_name_by_entrez_id(entrez_id)
19+
20+
if gene_name:
21+
print(f"The gene name for Entrez ID {entrez_id} is {gene_name}.")
22+
else:
23+
print(f"No gene name found for Entrez ID {entrez_id}.")
24+
File renamed without changes.

0 commit comments

Comments
 (0)