From d7799a390ed6dccb569b3571f4c38b7a88ac66ad Mon Sep 17 00:00:00 2001 From: Daniel-VM Date: Tue, 9 Apr 2024 12:22:23 +0200 Subject: [PATCH] add reviewer sugestions #258 --- .../assets/pipeline_utils/viralrecon.py | 19 ++++++++++++++----- relecov_tools/conf/bioinfo_config.json | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/relecov_tools/assets/pipeline_utils/viralrecon.py b/relecov_tools/assets/pipeline_utils/viralrecon.py index 07240c05..5d001c22 100644 --- a/relecov_tools/assets/pipeline_utils/viralrecon.py +++ b/relecov_tools/assets/pipeline_utils/viralrecon.py @@ -136,17 +136,26 @@ def convert_to_json(self, samp_dict): j_list = [] # Grab date from filename result_regex = re.search( - "variants_long_table_(.*).csv", os.path.basename(self.file_path) + "variants_long_table(?:_\d{8})?\.csv", os.path.basename(self.file_path) ) + stderr.print(result_regex.group(0)) if result_regex is None: - log.error("Analysis date not found in filename, aborting") stderr.print( - "[red]Error: filename must include analysis date in format YYYYMMDD" + "[EROR]\tWARN: Couldn't find variants long table file. Expected file name is:\n\t" + + "variants_long_table.csv or variants_long_table_YYYYMMDD.csv. Aborting..." ) - stderr.print("[red]e.g. variants_long_table_20220830.csv") sys.exit(1) + else: + date_regex = re.search(r"(\d{8})", result_regex.group()) + if date_regex is not None: + analysis_date = date_regex + stderr.print(f"[green]\tDate {analysis_date.group()} found in {self.file_path}") + else: + analysis_date = "Not Provided [GENEPIO:0001668]" + stderr.print(f"[yellow]\tWARN:No analysis date found in long table: {self.file_path}") + for key, values in samp_dict.items(): - j_dict = {"sample_name": key, "analysis_date": result_regex.group(1)} + j_dict = {"sample_name": key, "analysis_date": analysis_date.group()} j_dict["variants"] = values j_list.append(j_dict) return j_list diff --git a/relecov_tools/conf/bioinfo_config.json b/relecov_tools/conf/bioinfo_config.json index 80a052b4..8789f387 100644 --- a/relecov_tools/conf/bioinfo_config.json +++ b/relecov_tools/conf/bioinfo_config.json @@ -1,7 +1,7 @@ { "viralrecon": { "mapping_stats": { - "fn": "mapping_illumina_stats.tab", + "fn": "mapping_illumina_stats(?:_\\d{8})?\\.tab", "sample_col_idx": 5, "header_row_idx": 1, "required": true, @@ -37,7 +37,7 @@ } }, "variants_long_table": { - "fn": "variants_long_table(?:_\\d{8})?\\.csv$", + "fn": "variants_long_table(?:_\\d{8})?\\.csv", "sample_col_idx": 1, "header_row_idx": 1, "required": true,