Skip to content

Commit

Permalink
Move (and simplify) the renaming of targets to `bids.increment_runind…
Browse files Browse the repository at this point in the history
…ex()`
  • Loading branch information
marcelzwiers committed Feb 14, 2024
1 parent 9f66a47 commit bc951b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 5 additions & 1 deletion bidscoin/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,11 @@ def increment_runindex(outfolder: Path, bidsname: str, run: Run) -> str:
# Rename run-less to run-1
for runless_file in runless_files:
LOGGER.verbose(f"Found run-2 files for <<>> index, renaming\n{runless_file} -> {run1_name}")
runless_file.replace((outfolder/run1_name).with_suffix(''.join(runless_file.suffixes)))
run1_file = (outfolder/run1_name).with_suffix(''.join(runless_file.suffixes))
runless_file.replace(run1_file)
if runless_file in targets:
targets.remove(runless_file)
targets.add(run1_file)

return bidsname + bidsext

Expand Down
7 changes: 0 additions & 7 deletions bidscoin/plugins/dcm2niix2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,6 @@ def bidscoiner_plugin(session: Path, bidsmap: Bidsmap, bidsses: Path) -> Union[N
LOGGER.warning(f"Overwriting existing {newbidsfile} file -- check your results carefully!")
dcm2niixfile.replace(newbidsfile)
targets.add(newbidsfile)
if bids.get_bidsvalue(newbidsfile, 'run') == '2' and str(run['bids'].get('run') or '') == "<<>>":
# run-less file could be changed in the last call of increment_runindex within dcm2niixfiles loop
runless_bidsfile = bids.insert_bidskeyval(newbidsfile, 'run', '', False)
run1_bidsfile = bids.insert_bidskeyval(newbidsfile, 'run', '1', False)
if runless_bidsfile in targets and not runless_bidsfile.is_file() and run1_bidsfile.is_file():
targets.remove(runless_bidsfile)
targets.add(run1_bidsfile)

# Rename all associated files (i.e. the json-, bval- and bvec-files)
for oldfile in outfolder.glob(dcm2niixfile.with_suffix('').stem + '.*'):
Expand Down

0 comments on commit bc951b5

Please sign in to comment.