@@ -442,6 +442,31 @@ def extract_mqc_data(table_headers: Union[str, Path]) -> Optional[pd.DataFrame]:
442
442
443
443
return join_df (result , data ) if data else result , columns_result
444
444
445
+ def add_n_consensus_clusters_to_mqc (dataframe : pd .DataFrame )-> pd .DataFrame :
446
+ """
447
+ Add the number of consensus clusters to the multiqc general stats data.
448
+ """
449
+ df = dataframe .copy ()
450
+ ordered_list = ["constraint" ] + [f"it{ i } " for i in range (100 , 0 , - 1 )] + ["itvariant-calling" , "consensus" , "singleton" ]
451
+ df ["step" ] = pd .Categorical (df ["step" ], categories = ordered_list , ordered = True )
452
+
453
+ last_iteration = df ["step" ].max ()
454
+ logger .info ("Last iteration: %s" , last_iteration )
455
+
456
+ # Count how often samples have the last iteration
457
+ last_iteration_count = df [df ["step" ] == last_iteration ].groupby ("sample" ).size ().to_frame (name = "# Final denovo clusters" )
458
+
459
+ if last_iteration_count .empty :
460
+ return None
461
+
462
+ # Add the number of consensus clusters to the general stats data
463
+ module = mqc .BaseMultiqcModule (name = "Consensus Count" , anchor = Anchor ("custom_data" ))
464
+ content = last_iteration_count .to_dict (orient = "index" )
465
+ module .general_stats_addcols (content )
466
+ mqc .report .modules .append (module )
467
+ return 0
468
+
469
+
445
470
446
471
def write_results (contigs_mqc : pd .DataFrame , constraints_mqc : pd .DataFrame , constraints_genstats : pd .DataFrame ) -> int :
447
472
@@ -455,6 +480,7 @@ def write_results(contigs_mqc: pd.DataFrame, constraints_mqc: pd.DataFrame, cons
455
480
samples .extend (contigs_mqc ["sample" ])
456
481
write_df (contigs_mqc .sort_values (by = ["sample" , "cluster" , "step" ]), "contigs_overview-with-iterations.tsv" , [])
457
482
table_plot = contigs_mqc [~ contigs_mqc .index .isin (generate_ignore_samples (contigs_mqc ))]
483
+ add_n_consensus_clusters_to_mqc (table_plot )
458
484
write_df (table_plot .sort_values (by = ["sample" , "cluster" , "step" ]), "contigs_overview.tsv" , [])
459
485
460
486
if not constraints_mqc .empty :
0 commit comments