Skip to content

Commit

Permalink
Fix empty datasource.dataformat attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Sep 27, 2024
1 parent f5d17e9 commit 591cc42
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions bidscoin/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,9 @@ def get_matching_run(self, datasource: DataSource, runtime=False) -> Tuple[RunIt
If there is a match, the provenance of the bidsmap entry is returned, otherwise it will be ''
"""

if not datasource.dataformat and not datasource.has_plugin():
LOGGER.bcdebug(f"No dataformat/plugin support found when getting a matching run for: {datasource}")

unknowndatatypes = self.options.get('unknowntypes') or ['unknown_data']
ignoredatatypes = self.options.get('ignoretypes') or []
normaldatatypes = [dtype.datatype for dtype in self.dataformat(datasource.dataformat).datatypes if dtype not in unknowndatatypes + ignoredatatypes]
Expand Down Expand Up @@ -1366,6 +1369,9 @@ def get_run(self, datatype: Union[str, DataType], suffix_idx: Union[int, str], d
otherwise an empty dict
"""

if not datasource.dataformat and not datasource.has_plugin():
LOGGER.bcdebug(f"No dataformat/plugin support found when getting a run for: {datasource}")

datatype = str(datatype)

for index, _runitem in enumerate(self.dataformat(datasource.dataformat).datatype(datatype).runitems):
Expand Down
4 changes: 2 additions & 2 deletions bidscoin/plugins/nibabel2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def bidsmapper_plugin(session: Path, bidsmap_new: BidsMap, bidsmap_old: BidsMap,
for sourcefile in [file for file in session.rglob('*') if has_support(file)]:

# See if we can find a matching run in the old bidsmap
datasource = bids.DataSource(sourcefile, plugins, datasource.dataformat)
datasource = bids.DataSource(sourcefile, plugins, has_support(sourcefile))
run, match = bidsmap_old.get_matching_run(datasource)

# If not, see if we can find a matching run in the template
Expand Down Expand Up @@ -185,7 +185,7 @@ def bidscoiner_plugin(session: Path, bidsmap: BidsMap, bidsses: Path) -> None:
# Collect the different Nibabel source files for all files in the session
for source in sourcefiles:

datasource = bids.DataSource(source, {'nibabel2bids': options})
datasource = bids.DataSource(source, {'nibabel2bids': options}, has_support(source))
run, runid = bidsmap.get_matching_run(datasource, runtime=True)

# Check if we should ignore this run
Expand Down
4 changes: 2 additions & 2 deletions bidscoin/plugins/spec2nii2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def bidsmapper_plugin(session: Path, bidsmap_new: BidsMap, bidsmap_old: BidsMap,
# Update the bidsmap with the info from the source files
for sourcefile in [file for file in session.rglob('*') if has_support(file)]:

datasource = bids.DataSource(sourcefile, plugins)
datasource = bids.DataSource(sourcefile, plugins, has_support(sourcefile))

# Input checks
if datasource.dataformat not in template.dataformats + bidsmap_old.dataformats:
Expand Down Expand Up @@ -192,7 +192,7 @@ def bidscoiner_plugin(session: Path, bidsmap: BidsMap, bidsses: Path) -> Union[N
for source in sourcefiles:

# Get a data source, a matching run from the bidsmap
datasource = bids.DataSource(source, {'spec2nii2bids': options})
datasource = bids.DataSource(source, {'spec2nii2bids': options}, has_support(source))
run, runid = bidsmap.get_matching_run(datasource, runtime=True)

# Check if we should ignore this run
Expand Down

0 comments on commit 591cc42

Please sign in to comment.