From 9ac5195b680a7b6120dd93876ea79ad3e4d6ccfc Mon Sep 17 00:00:00 2001 From: Marcel Zwiers Date: Fri, 5 Apr 2024 17:59:54 +0200 Subject: [PATCH] Filter out the false-positive dcm2niixfile in the outer for loop (Github issue #232) --- bidscoin/plugins/dcm2niix2bids.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bidscoin/plugins/dcm2niix2bids.py b/bidscoin/plugins/dcm2niix2bids.py index f89720fb..be63b7f8 100644 --- a/bidscoin/plugins/dcm2niix2bids.py +++ b/bidscoin/plugins/dcm2niix2bids.py @@ -379,6 +379,11 @@ def bidscoiner_plugin(session: Path, bidsmap: Bidsmap, bidsses: Path) -> Union[N for dcm2niixfile in dcm2niixfiles: + # Filter out false-positive (-> glob) dcm2niixfiles, e.g. postfix = 'echo-1' (see Github issue #232) + if not re.match(r'.*_echo-[0-9]*\.nii', str(dcm2niixfile)): + LOGGER.bcdebug(f"Skipping false positive dcm2niixfile: {dcm2niixfile}") + continue + # Strip each dcm2niix postfix and assign it to bids entities in a newly constructed bidsname ext = ''.join(dcm2niixfile.suffixes) postfixes = dcm2niixfile.name.split(bidsname)[1].rsplit(ext)[0].split('_')[1:] @@ -387,9 +392,6 @@ def bidscoiner_plugin(session: Path, bidsmap: Bidsmap, bidsses: Path) -> Union[N # Patch the echo entity in the newbidsname with the dcm2niix echo info # NB: We can't rely on the bids-entity info here because manufacturers can e.g. put multiple echos in one series / run-folder if 'echo' in run['bids'] and postfix.startswith('e'): - if not re.fullmatch('e[0-9]*', postfix): # A false match, e.g. postfix = 'echo-1' (see Github issue #232) - LOGGER.bcdebug(f"Skipping false positive postfix: {postfix} in {dcm2niixfile}") - continue echonr = f"_{postfix}".replace('_e','') # E.g. postfix='e1' if not echonr: echonr = '1'