Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Updated add-extra-config and included Initial configuration description in README.md [#861]https://github.com/BU-ISCIII/relecov-tools/pull/861
- Updated test workflows to load initial_config-relecov.yaml first [#861]https://github.com/BU-ISCIII/relecov-tools/pull/861
- Included three initial_config.yaml files for three projects: relecov, mepram & EQA2026 [#861]https://github.com/BU-ISCIII/relecov-tools/pull/861
- Normalize compact YYYYMMDD dates in read-lab-metadata [#867]https://github.com/BU-ISCIII/relecov-tools/pull/867

#### Fixes

Expand Down
11 changes: 11 additions & 0 deletions relecov_tools/read_lab_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,24 @@ def read_metadata_file(self):
)
if isinstance(key_for_checks, str) and "date" in key_for_checks.lower():
pattern = r"^\d{4}[-/.]\d{2}[-/.]\d{2}"
compact_pattern = r"^\d{8}$"
if isinstance(raw_value, dtime):
value = str(raw_value.date())
elif re.match(pattern, str(raw_value)):
value = re.match(
pattern,
str(raw_value).replace("/", "-").replace(".", "-"),
).group(0)
elif re.match(compact_pattern, str(raw_value)):
try:
value = dtime.strptime(str(raw_value), "%Y%m%d").strftime(
"%Y-%m-%d"
)
except ValueError:
log_text = f"Invalid date format in {raw_key}: {raw_value}"
self.logsum.add_error(sample=sample_id, entry=log_text)
stderr.print(f"[red]{log_text} for sample {sample_id}")
continue
else:
try:
value = str(int(float(str(raw_value))))
Expand Down
Loading