Skip to content

Commit

Permalink
Filter out the false-positive dcm2niixfile in the outer for loop (Git…
Browse files Browse the repository at this point in the history
…hub issue #232)
  • Loading branch information
marcelzwiers committed Apr 5, 2024
1 parent 93589dd commit 9ac5195
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bidscoin/plugins/dcm2niix2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand All @@ -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'
Expand Down

0 comments on commit 9ac5195

Please sign in to comment.