Skip to content

Commit ef06bb8

Browse files
New Viz fix and demo db
1 parent a6a1e32 commit ef06bb8

File tree

4 files changed

+51
-31
lines changed

4 files changed

+51
-31
lines changed

app/historeport/routes.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def histo_download():
4949
df = db_to_df()
5050
df, features_col = table_to_df(df, onto_tree)
5151
df = df.replace({-0.25: np.nan})
52-
resp = make_response(df.to_csv())
52+
resp = make_response(df.to_csv(index=False))
5353
resp.headers["Content-Disposition"] = "attachment; filename=text_reports.csv"
5454
resp.headers["Content-Type"] = "text/csv"
5555
return resp
@@ -220,18 +220,13 @@ def predict_diag_boqa():
220220
Returns:
221221
str: JSON string with the best prediction results and its score
222222
"""
223-
class_label = {
224-
"CNM": "Centronuclear Myopathy",
225-
"COM": "Core Myopathy",
226-
"NM": "Nemaline Myopathy",
227-
}
228223
raw_data = request.get_data()
229224
results = get_boqa_pred(raw_data)
230225
return (
231226
json.dumps(
232227
{
233228
"success": True,
234-
"class": class_label[results[0]],
229+
"class": results[0],
235230
"proba": round(results[1], 2),
236231
}
237232
),

app/histostats/vizualisation.py

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,7 @@ def process_df(df):
8181
Returns:
8282
Dataframe: Processed DataFrame with modified values
8383
"""
84-
df = df.replace(
85-
{
86-
"COM_CCD": "COM",
87-
"COM_MMM": "COM",
88-
"NM_CAP": "NM",
89-
"CFTD": "OTHER",
90-
"NON_CM": "OTHER",
91-
"CM": "UNCLEAR",
92-
}
93-
)
84+
df["gene_diag"].replace({"": "N/A"}, inplace=True)
9485
df = df.replace({-0.25: np.nan, 0.25: 1, 0.5: 1, 0.75: 1})
9586
return df
9687

@@ -147,8 +138,14 @@ def create_plotly_viz(df):
147138
graphJSON2 = json.loads(fig2.to_json())
148139

149140
gene_diag = df["gene_diag"].value_counts()
141+
gene_diag_label = []
142+
for i in list(gene_diag.index):
143+
if len(i.split(" ")) > 1:
144+
gene_diag_label.append(i.split(" ")[1])
145+
else:
146+
gene_diag_label.append(i)
150147
fig3 = px.bar(
151-
x=gene_diag.index,
148+
x=gene_diag_label,
152149
y=gene_diag,
153150
text=gene_diag,
154151
color=gene_diag.index.astype(str),
@@ -163,6 +160,9 @@ def create_plotly_viz(df):
163160
graphJSON3 = json.loads(fig3.to_json())
164161

165162
conclusion = df["conclusion"].value_counts()
163+
conclusion_label = []
164+
for i in list(conclusion.index):
165+
conclusion_label.append(string_breaker(i, 15))
166166
fig4 = px.bar(
167167
x=conclusion.index,
168168
y=conclusion,
@@ -172,7 +172,12 @@ def create_plotly_viz(df):
172172
title="Cohort repartition by myopathy diagnosis",
173173
)
174174
fig4.update_layout(
175-
xaxis_title="Myopathy class", yaxis_title="Number of reports", showlegend=False
175+
xaxis_title="Myopathy class",
176+
yaxis_title="Number of reports",
177+
showlegend=False,
178+
)
179+
fig4.update_xaxes(
180+
tickmode="array", tickvals=conclusion.index, ticktext=conclusion_label
176181
)
177182
graphJSON4 = json.loads(fig4.to_json())
178183

@@ -217,14 +222,6 @@ def generate_stat_per(df, features_col):
217222
df_per_diag = pd.DataFrame(
218223
list_per_diag, columns=["Diag", "N", "Feature", "Count", "Frequency"]
219224
)
220-
df_per_diag.replace(
221-
{
222-
"NM": "Nemaline Myopathy",
223-
"CNM": "Centronuclear Myopathy",
224-
"COM": "Core Myopathy",
225-
},
226-
inplace=True,
227-
)
228225
df_per_gene.to_csv(
229226
os.path.join(current_app.config["VIZ_FOLDER"], "stat_per_gene.csv"), index=False
230227
)
@@ -275,6 +272,9 @@ def generate_UNCLEAR(df):
275272
"""
276273
df_unclear = df[df["conclusion"] == "UNCLEAR"]
277274
conclusion_boqa = df_unclear["BOQA_prediction"].value_counts()
275+
labels_trim = []
276+
for i in list(conclusion_boqa.index):
277+
labels_trim.append(string_breaker(i, 15))
278278
fig = px.bar(
279279
x=conclusion_boqa.index,
280280
y=conclusion_boqa,
@@ -288,6 +288,9 @@ def generate_UNCLEAR(df):
288288
yaxis_title="Number of reports",
289289
showlegend=False,
290290
)
291+
fig.update_xaxes(
292+
tickmode="array", tickvals=conclusion_boqa.index, ticktext=labels_trim
293+
)
291294
graph_UNCLEAR = json.loads(fig.to_json())
292295
return graph_UNCLEAR
293296

@@ -305,13 +308,22 @@ def generate_confusion_BOQA(df):
305308
df_no_unclear = df[(df["conclusion"] != "UNCLEAR") & (df["conclusion"] != "OTHER")]
306309
y_true = df_no_unclear["conclusion"].to_list()
307310
y_pred = df_no_unclear["BOQA_prediction"].to_list()
311+
labels = ["No_Pred"] + df_no_unclear["conclusion"].unique().tolist()
312+
labels_trim = []
313+
for i in list(labels):
314+
labels_trim.append(string_breaker(i, 15))
308315
matrix_results = confusion_matrix(
309-
y_true, y_pred, labels=["No_Pred", "CNM", "COM", "NM"]
316+
# y_true, y_pred, labels=["No_Pred", "CNM", "COM", "NM"]
317+
y_true,
318+
y_pred,
319+
labels=labels,
310320
)
311321
fig = ff.create_annotated_heatmap(
312322
z=matrix_results,
313-
x=["No_Pred", "CNM", "COM", "NM"],
314-
y=["No_Pred", "CNM", "COM", "NM"],
323+
x=labels_trim,
324+
y=labels_trim,
325+
# x=["No_Pred", "CNM", "COM", "NM"],
326+
# y=["No_Pred", "CNM", "COM", "NM"],
315327
colorscale="Viridis",
316328
)
317329
fig.update_layout(
@@ -426,3 +438,14 @@ def update_correlation_data(corrMatrix):
426438
os.path.join(current_app.config["ONTOLOGY_FOLDER"], "ontology.json"), "w"
427439
) as fp:
428440
json.dump(onto, fp, indent=4)
441+
442+
443+
def string_breaker(s, max_length=10):
444+
# s = s.split(" ")
445+
# s_elem_len = [len(i) for i in s]
446+
lines_nb = int(len(s) / max_length)
447+
new_string = []
448+
for i in range(lines_nb):
449+
new_string.append(s[i * max_length : i * max_length + max_length])
450+
new_string.append(s[lines_nb * max_length :])
451+
return "<br>".join(new_string)

app/imgupload/routes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def img_index():
5454
@login_required
5555
def img_download():
5656
df = pd.read_sql(db.session.query(Image).statement, db.session.bind)
57-
df.to_csv(os.path.join(current_app.config["IMAGES_FOLDER"], "images_db.csv"))
57+
df.to_csv(
58+
os.path.join(current_app.config["IMAGES_FOLDER"], "images_db.csv"), index=False
59+
)
5860
with tarfile.open(
5961
os.path.join(current_app.config["DATA_FOLDER"], "image_data.tar.gz"), "w:gz"
6062
) as tar:

data/database/app.db.demo

356 KB
Binary file not shown.

0 commit comments

Comments
 (0)