Skip to content

Commit

Permalink
Fix bidsmap filepath resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Sep 27, 2024
1 parent 28c3261 commit 94ad31c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
5 changes: 2 additions & 3 deletions bidscoin/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def __init__(self, yamlfile: Path, folder: Path=templatefolder, plugins: Iterabl
has precedence over folder and bidsmap.yaml has precedence over the bidsmap_template.
:param yamlfile: The full pathname or basename of the bidsmap yaml-file
:param folder: Used when yamlfile=basename and not in the pwd: yamlfile is then assumed to be in the (bidscoin)folder. A bidsignore file in folder will be added to the bidsmap bidsignore items
:param folder: Used when yamlfile=basename and not in the pwd: yamlfile is then assumed to be in the (bids/code/bidscoin)folder. A bidsignore file in folder will be added to the bidsmap bidsignore items
:param plugins: List of plugins to be used (with default options, overrules the plugin list in the study/template bidsmaps). Leave empty to use all plugins in the bidsmap
:param checks: Booleans to check if all (bidskeys, bids-suffixes, bids-values) in the run are present according to the BIDS schema specifications
"""
Expand All @@ -893,8 +893,7 @@ def __init__(self, yamlfile: Path, folder: Path=templatefolder, plugins: Iterabl
yamlfile = yamlfile.with_suffix('.yaml') # Add a standard file-extension if needed
if len(yamlfile.parents) == 1 and not yamlfile.is_file():
yamlfile = folder/yamlfile # Get the full path to the bidsmap yaml-file
yamlfile = yamlfile.resolve()
self.filepath = yamlfile if yamlfile.is_file() else Path()
self.filepath = yamlfile = yamlfile.resolve()
"""The full path to the bidsmap yaml-file"""
if not yamlfile.is_file():
if yamlfile.name: LOGGER.info(f"No bidsmap file found: {yamlfile}")
Expand Down
2 changes: 1 addition & 1 deletion bidscoin/bidsapps/fixmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def fixmeta(bidsfolder: str, pattern: str, metadata: dict, participant: list, bi

# Load the bidsmap data (-> plugins)
bidsmap = bids.BidsMap(Path(bidsmap or 'bidsmap.yaml'), bidsdir/'code'/'bidscoin', checks=(False, False, False))
if not bidsmap.filepath:
if not bidsmap.filepath.is_file():
bidsmap = bids.BidsMap(bidsmap_template, checks=(False, False, False))
plugins = bidsmap.plugins
provdata = bids.bidsprov(bidsdir)
Expand Down
4 changes: 2 additions & 2 deletions bidscoin/bidseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, bidsfolder: Path, input_bidsmap: BidsMap, template_bidsmap: B
self.setWindowIcon(QtGui.QIcon(str(BIDSCOIN_ICON)))
self.set_menu_statusbar()

if not input_bidsmap.filepath.name:
if not input_bidsmap.filepath.is_file():
filename, _ = QFileDialog.getOpenFileName(self, 'Open a bidsmap file', str(bidsfolder), 'YAML Files (*.yaml *.yml);;All Files (*)')
if filename:
input_bidsmap = BidsMap(Path(filename))
Expand Down Expand Up @@ -868,7 +868,7 @@ def save_bidsmap(self):
"""Check and save the bidsmap to file"""

for dataformat in self.dataformats:
if 'fmap' in self.output_bidsmap.dataformat(dataformat):
if 'fmap' in self.output_bidsmap.dataformat(dataformat).datatypes:
for runitem in self.output_bidsmap.dataformat(dataformat).datatype('fmap').runitems:
if not (runitem.meta.get('B0FieldSource') or runitem.meta.get('B0FieldIdentifier') or runitem.meta.get('IntendedFor')):
LOGGER.warning(f"B0FieldIdentifier/IntendedFor fieldmap value is empty for {dataformat} run-item: {runitem}")
Expand Down
11 changes: 6 additions & 5 deletions bidscoin/bidsmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str,

# Get the heuristics for filling the new bidsmap (NB: plugins are stored in the bidsmaps)
bidsmap_old = BidsMap(bidsmapfile, bidscoinfolder, plugins)
bidsmapfile = bidsmap_old.filepath
template = BidsMap(templatefile, plugins=plugins, checks=(True, True, False))
template.check_template()

# Create the new bidsmap as a copy / bidsmap skeleton with only data types without run-items (i.e. empty lists)
if force and bidsmap_old.filepath.name:
if force and bidsmap_old.filepath.is_file():
LOGGER.info(f"Deleting previous bidsmap: {bidsmap_old.filepath}")
bidsmap_old.filepath.unlink()
bidsmap_old.filepath = Path()
bidsmap_new = copy.deepcopy(bidsmap_old if bidsmap_old.filepath.name else template)
bidsmap_new = copy.deepcopy(bidsmap_old if bidsmap_old.filepath.is_file() else template)
bidsmap_new.delete_runs()
bidsmap_new.filepath = bidsmapfile.resolve()
bidsmap_new.filepath = bidsmapfile
template.options = bidsmap_new.options # Always use the options of the new bidsmap
template.plugins = bidsmap_new.plugins # Always use the plugins of the new bidsmap
if unzip:
Expand All @@ -95,7 +96,7 @@ def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str,
subprefix, sesprefix = setprefix(bidsmap_new, subprefix, sesprefix, rawfolder, update = not no_update)

# Start with an empty skeleton if we don't have an old bidsmap (due to loading failure or deletion by force)
if not bidsmap_old.filepath.name:
if not bidsmap_old.filepath.is_file():
bidsmap_old = copy.deepcopy(bidsmap_new)

# Import the data scanning plugins
Expand Down Expand Up @@ -156,7 +157,7 @@ def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str,
mainwin = bidseditor.MainWindow(bidsfolder, bidsmap_new, template)
mainwin.show()

if not bidsmap_new.filepath.name or not uptodate:
if not bidsmap_new.filepath.is_file() or not uptodate:
messagebox = QMessageBox(mainwin)
messagebox.setText(f"The bidsmapper has finished scanning {rawfolder}\n\n"
f"Please carefully check all the different BIDS output names "
Expand Down
2 changes: 1 addition & 1 deletion bidscoin/utilities/bidsparticipants.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def bidsparticipants(sourcefolder: str, bidsfolder: str, keys: list, bidsmap: st

# Get the bidsmap sub-/ses-prefix from the bidsmap YAML-file
bidsmap = BidsMap(Path(bidsmap), bidsfolder/'code'/'bidscoin', checks=(False, False, False))
if not bidsmap.filepath.name:
if not bidsmap.filepath.is_file():
LOGGER.info('Make sure to run "bidsmapper" first, exiting now')
return
subprefix = bidsmap.options['subprefix']
Expand Down

0 comments on commit 94ad31c

Please sign in to comment.