@@ -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 )
0 commit comments