Spaces:
Sleeping
Sleeping
Update dashboard.py
Browse files- dashboard.py +36 -36
dashboard.py
CHANGED
|
@@ -48,14 +48,23 @@ def read_freq_map(filename):
|
|
| 48 |
freqmap = dict(zip(df[column_0], df[column_1]))
|
| 49 |
return freqmap
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
entityTypesFreqMap = read_freq_map('entityTypes.tsv')
|
| 54 |
relationTypesFreqMap = read_freq_map('relationTypes.tsv')
|
| 55 |
topDrugEntities = read_freq_map('topDrugs.tsv')
|
| 56 |
topConditionEntities = read_freq_map('topConditions.tsv')
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
|
| 61 |
grouping_filtered = pd.read_csv(os.path.join(data, 'drugReviewsCausal_relations.tsv'), sep=" ")
|
|
@@ -82,16 +91,14 @@ def create_ent_bar_charts(ents, **kwargs):
|
|
| 82 |
|
| 83 |
def create_ontology_bar_charts(ents, **kwargs):
|
| 84 |
if ents=='Drug':
|
| 85 |
-
dictionary = topDrugOnts
|
| 86 |
df = pd.DataFrame({
|
| 87 |
-
'
|
| 88 |
-
'
|
| 89 |
-
'
|
| 90 |
-
'url': list(dictionary.keys()) # using full keys as hyperlinks
|
| 91 |
})
|
| 92 |
# Create bar chart with label as x-axis
|
| 93 |
bars = hv.Bars(df, kdims=['Drug_Ontologies'], vdims=['Frequency'])
|
| 94 |
-
bars
|
| 95 |
framewise=True,
|
| 96 |
tools=['hover'],
|
| 97 |
width=1200,
|
|
@@ -102,46 +109,39 @@ def create_ontology_bar_charts(ents, **kwargs):
|
|
| 102 |
ylabel='Frequency',
|
| 103 |
hover_tooltips=[
|
| 104 |
("Drug_Ontologies", "@Drug_Ontologies"),
|
| 105 |
-
("Frequency", "@Frequency")
|
| 106 |
-
("Link", "@url")
|
| 107 |
]
|
| 108 |
)
|
| 109 |
links_panel = pn.Column(
|
| 110 |
*[pn.pane.Markdown(f"[{row.Drug_Ontologies}]({row.url})", width=400) for _, row in df.iterrows()],
|
| 111 |
name='Links'
|
| 112 |
)
|
| 113 |
-
layout = pn.Row(bars,
|
| 114 |
return layout
|
| 115 |
elif ents=='Condition':
|
| 116 |
-
dictionary = topConditionOnts
|
| 117 |
df = pd.DataFrame({
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
})
|
| 123 |
# Create bar chart with label as x-axis
|
| 124 |
bars = hv.Bars(df, kdims=['Condition_Ontologies'], vdims=['Frequency'])
|
| 125 |
-
bars
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
("Link", "@url")
|
| 138 |
-
]
|
| 139 |
-
)
|
| 140 |
links_panel = pn.Column(
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
)
|
| 144 |
-
layout = pn.Row(bars, pn.pane.Markdown("### Full URLs:"), links_panel)
|
| 145 |
return layout
|
| 146 |
|
| 147 |
############################# WIDGETS & CALLBACK ###########################################
|
|
|
|
| 48 |
freqmap = dict(zip(df[column_0], df[column_1]))
|
| 49 |
return freqmap
|
| 50 |
|
| 51 |
+
def read_ont_freq_dataframe(filename):
|
| 52 |
+
df = pd.read_csv(os.path.join(data,filename), sep=' ')
|
| 53 |
+
print(df)
|
| 54 |
+
if 'Unnamed: 0' in df.columns:
|
| 55 |
+
df = df.drop('Unnamed: 0', axis=1)
|
| 56 |
+
column_0 = df.columns[0]
|
| 57 |
+
column_1 = df.columns[1]
|
| 58 |
+
freqmap = dict(zip(df[column_0], df[column_1]))
|
| 59 |
+
return freqmap
|
| 60 |
|
| 61 |
|
| 62 |
entityTypesFreqMap = read_freq_map('entityTypes.tsv')
|
| 63 |
relationTypesFreqMap = read_freq_map('relationTypes.tsv')
|
| 64 |
topDrugEntities = read_freq_map('topDrugs.tsv')
|
| 65 |
topConditionEntities = read_freq_map('topConditions.tsv')
|
| 66 |
+
topDrugOnts_df = pd.read_csv(os.path.join(data,'topDrugOntologies.tsv'), sep=' ')
|
| 67 |
+
topConditionOnts_df = pd.read_csv(os.path.join(data,'topConditionOntologies.tsv'), sep=' ')
|
| 68 |
|
| 69 |
|
| 70 |
grouping_filtered = pd.read_csv(os.path.join(data, 'drugReviewsCausal_relations.tsv'), sep=" ")
|
|
|
|
| 91 |
|
| 92 |
def create_ontology_bar_charts(ents, **kwargs):
|
| 93 |
if ents=='Drug':
|
|
|
|
| 94 |
df = pd.DataFrame({
|
| 95 |
+
'Drug_Ontologies': [ont.split('/')[-1] for ont in topDrugOnts_df['ontology']],
|
| 96 |
+
'Frequency': list(topDrugOnts_df['count']),
|
| 97 |
+
'url': list(topDrugOnts_df['ontology_url']) # using full keys as hyperlinks
|
|
|
|
| 98 |
})
|
| 99 |
# Create bar chart with label as x-axis
|
| 100 |
bars = hv.Bars(df, kdims=['Drug_Ontologies'], vdims=['Frequency'])
|
| 101 |
+
bars.opts(
|
| 102 |
framewise=True,
|
| 103 |
tools=['hover'],
|
| 104 |
width=1200,
|
|
|
|
| 109 |
ylabel='Frequency',
|
| 110 |
hover_tooltips=[
|
| 111 |
("Drug_Ontologies", "@Drug_Ontologies"),
|
| 112 |
+
("Frequency", "@Frequency")
|
|
|
|
| 113 |
]
|
| 114 |
)
|
| 115 |
links_panel = pn.Column(
|
| 116 |
*[pn.pane.Markdown(f"[{row.Drug_Ontologies}]({row.url})", width=400) for _, row in df.iterrows()],
|
| 117 |
name='Links'
|
| 118 |
)
|
| 119 |
+
layout = pn.Row(bars, links_panel)
|
| 120 |
return layout
|
| 121 |
elif ents=='Condition':
|
|
|
|
| 122 |
df = pd.DataFrame({
|
| 123 |
+
'Condition_Ontologies': [ont.split('/')[-1] for ont in topConditionOnts_df['ontology']],
|
| 124 |
+
'Frequency': list(topConditionOnts_df['count']),
|
| 125 |
+
'url': list(topConditionOnts_df['ontology_url']) # using full keys as hyperlinks
|
| 126 |
+
})
|
|
|
|
| 127 |
# Create bar chart with label as x-axis
|
| 128 |
bars = hv.Bars(df, kdims=['Condition_Ontologies'], vdims=['Frequency'])
|
| 129 |
+
bars.opts(
|
| 130 |
+
framewise=True,
|
| 131 |
+
tools=['hover'],
|
| 132 |
+
width=1200,
|
| 133 |
+
height=600,
|
| 134 |
+
show_legend=True,
|
| 135 |
+
xrotation=45,
|
| 136 |
+
xlabel='Condition_Ontologies',
|
| 137 |
+
ylabel='Frequency',
|
| 138 |
+
hover_tooltips=[
|
| 139 |
+
("Condition Ontologies", "@Condition Ontologies"),
|
| 140 |
+
("Frequency", "@Frequency") ])
|
|
|
|
|
|
|
|
|
|
| 141 |
links_panel = pn.Column(
|
| 142 |
+
*[pn.pane.Markdown(f"[{row.Condition_Ontologies}]({row.url})", width=400) for _, row in df.iterrows()],
|
| 143 |
+
name='Links')
|
| 144 |
+
layout = pn.Row(bars, links_panel)
|
|
|
|
| 145 |
return layout
|
| 146 |
|
| 147 |
############################# WIDGETS & CALLBACK ###########################################
|