From 761fe771865096fbf7b68dcda1ee51816a3055f1 Mon Sep 17 00:00:00 2001 From: Finlay Maguire Date: Mon, 26 Sep 2022 09:32:06 -0300 Subject: [PATCH] Initialise empty report before combining Hopefully this should address the sorting crash in #80 --- hAMRonization/summarize.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hAMRonization/summarize.py b/hAMRonization/summarize.py index 4dc3874..2e66dad 100644 --- a/hAMRonization/summarize.py +++ b/hAMRonization/summarize.py @@ -698,7 +698,12 @@ def summarize_reports(report_paths, summary_type, output_path=None): else: out_fh = sys.stdout - combined_report_data = [] + # initialise the combined report with an empty df with just headers + hamronized_fields = [ + field.name for field in dataclasses.fields(hAMRonizedResult) + ] + combined_report_data = [pd.DataFrame(columns=hamronized_fields)] + report_count = 0 for report in report_paths: @@ -740,12 +745,6 @@ def summarize_reports(report_paths, summary_type, output_path=None): file=sys.stderr, ) - # if empty create an empty summary file with fields - if len(combined_reports) == 0: - hamronized_fields = [ - field.name for field in dataclasses.fields(hAMRonizedResult) - ] - combined_reports = pd.DataFrame(columns=hamronized_fields) # sort records by input_file_name, tool_config i.e. toolname, version, # db_name, db_versions, and then within that by gene_symbol