@@ -81,16 +81,7 @@ def process_df(df):
81
81
Returns:
82
82
Dataframe: Processed DataFrame with modified values
83
83
"""
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 )
94
85
df = df .replace ({- 0.25 : np .nan , 0.25 : 1 , 0.5 : 1 , 0.75 : 1 })
95
86
return df
96
87
@@ -147,8 +138,14 @@ def create_plotly_viz(df):
147
138
graphJSON2 = json .loads (fig2 .to_json ())
148
139
149
140
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 )
150
147
fig3 = px .bar (
151
- x = gene_diag . index ,
148
+ x = gene_diag_label ,
152
149
y = gene_diag ,
153
150
text = gene_diag ,
154
151
color = gene_diag .index .astype (str ),
@@ -163,6 +160,9 @@ def create_plotly_viz(df):
163
160
graphJSON3 = json .loads (fig3 .to_json ())
164
161
165
162
conclusion = df ["conclusion" ].value_counts ()
163
+ conclusion_label = []
164
+ for i in list (conclusion .index ):
165
+ conclusion_label .append (string_breaker (i , 15 ))
166
166
fig4 = px .bar (
167
167
x = conclusion .index ,
168
168
y = conclusion ,
@@ -172,7 +172,12 @@ def create_plotly_viz(df):
172
172
title = "Cohort repartition by myopathy diagnosis" ,
173
173
)
174
174
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
176
181
)
177
182
graphJSON4 = json .loads (fig4 .to_json ())
178
183
@@ -217,14 +222,6 @@ def generate_stat_per(df, features_col):
217
222
df_per_diag = pd .DataFrame (
218
223
list_per_diag , columns = ["Diag" , "N" , "Feature" , "Count" , "Frequency" ]
219
224
)
220
- df_per_diag .replace (
221
- {
222
- "NM" : "Nemaline Myopathy" ,
223
- "CNM" : "Centronuclear Myopathy" ,
224
- "COM" : "Core Myopathy" ,
225
- },
226
- inplace = True ,
227
- )
228
225
df_per_gene .to_csv (
229
226
os .path .join (current_app .config ["VIZ_FOLDER" ], "stat_per_gene.csv" ), index = False
230
227
)
@@ -275,6 +272,9 @@ def generate_UNCLEAR(df):
275
272
"""
276
273
df_unclear = df [df ["conclusion" ] == "UNCLEAR" ]
277
274
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 ))
278
278
fig = px .bar (
279
279
x = conclusion_boqa .index ,
280
280
y = conclusion_boqa ,
@@ -288,6 +288,9 @@ def generate_UNCLEAR(df):
288
288
yaxis_title = "Number of reports" ,
289
289
showlegend = False ,
290
290
)
291
+ fig .update_xaxes (
292
+ tickmode = "array" , tickvals = conclusion_boqa .index , ticktext = labels_trim
293
+ )
291
294
graph_UNCLEAR = json .loads (fig .to_json ())
292
295
return graph_UNCLEAR
293
296
@@ -305,13 +308,22 @@ def generate_confusion_BOQA(df):
305
308
df_no_unclear = df [(df ["conclusion" ] != "UNCLEAR" ) & (df ["conclusion" ] != "OTHER" )]
306
309
y_true = df_no_unclear ["conclusion" ].to_list ()
307
310
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 ))
308
315
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 ,
310
320
)
311
321
fig = ff .create_annotated_heatmap (
312
322
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"],
315
327
colorscale = "Viridis" ,
316
328
)
317
329
fig .update_layout (
@@ -426,3 +438,14 @@ def update_correlation_data(corrMatrix):
426
438
os .path .join (current_app .config ["ONTOLOGY_FOLDER" ], "ontology.json" ), "w"
427
439
) as fp :
428
440
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 )
0 commit comments