From 4043ad6b800f3e399e5481799913751cccb1588c Mon Sep 17 00:00:00 2001 From: Ali Hamraoui Date: Thu, 22 Aug 2024 14:39:28 +0200 Subject: [PATCH] FIX: fix time format for BAM and FASTQ extractors --- toulligqc/extractor_common.py | 8 +++++--- toulligqc/fastq_extractor.py | 5 +---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/toulligqc/extractor_common.py b/toulligqc/extractor_common.py index 872e71f..33aab14 100644 --- a/toulligqc/extractor_common.py +++ b/toulligqc/extractor_common.py @@ -432,9 +432,11 @@ def add_image_to_result(quiet, image_list, start_time, image): def timeISO_to_float(iso_datetime, format): """ """ - if '+' in iso_datetime: - iso_datetime = iso_datetime.split('+')[0] - dt = datetime.strptime(iso_datetime, format) + try: + dt = datetime.strptime(iso_datetime, format) + except: + format = '%Y-%m-%dT%H:%M:%SZ' + dt = datetime.strptime(iso_datetime, format) unix_timestamp = dt.timestamp() return unix_timestamp diff --git a/toulligqc/fastq_extractor.py b/toulligqc/fastq_extractor.py index 3e73b33..cb565df 100644 --- a/toulligqc/fastq_extractor.py +++ b/toulligqc/fastq_extractor.py @@ -375,10 +375,7 @@ def _extract_info_from_name(self, name): """ """ metadata = dict(x.split("=") for x in name.split(" ")[1:]) - try: - start_time = timeISO_to_float(metadata['start_time'], '%Y-%m-%dT%H:%M:%SZ') - except: - start_time = timeISO_to_float(metadata['start_time'], '%Y-%m-%dT%H:%M:%S.%f') + start_time = timeISO_to_float(metadata['start_time'], '%Y-%m-%dT%H:%M:%S.%f%z') if self.is_barcode: return start_time, metadata['ch'], metadata['barcode'] return start_time, metadata['ch'] \ No newline at end of file