Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Oct 30, 2024
1 parent aec8b47 commit 18e1b8e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
9 changes: 3 additions & 6 deletions bidscoin/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,8 @@ def __init__(self, yamlfile: Path, folder: Path=templatefolder, plugins: Iterabl
if entitykey not in runitem.bids and entitykey not in ('sub', 'ses'):
LOGGER.info(f"Adding missing {dataformat}>{datatype}>{suffix} bidsmap entity key: {entitykey}")
runitem.bids[entitykey] = ''
if entitykey == 'part' and not isinstance(runitem.bids['part'], list):
if runitem.bids['part'] in ('', 'mag', 'phase', 'real', 'imag', None):
runitem.bids['part'] = ['', 'mag', 'phase', 'real', 'imag', ('', 'mag', 'phase', 'real', 'imag').index(runitem.bids['part'] or '')]
else:
runitem.bids['part'] = ['', 'mag', 'phase', 'real', 'imag', runitem.bids['part'], 5]
if entitykey == 'part' and not isinstance(runitem.bids['part'], list) and runitem.bids['part'] in ('', 'mag', 'phase', 'real', 'imag', None):
runitem.bids['part'] = ['', 'mag', 'phase', 'real', 'imag', ('', 'mag', 'phase', 'real', 'imag').index(runitem.bids['part'] or '')]

# Validate the bidsmap entries
self.check(checks)
Expand Down Expand Up @@ -1258,7 +1255,7 @@ def validate(self, level: int=1) -> bool:
ignore = check_ignore(datatype, bidsignore) or check_ignore(bidsname+'.json', bidsignore, 'file')
ignore_1 = datatype in ignoretypes or ignore
ignore_2 = datatype in ignoretypes
for ext in extensions: # NB: `ext` used to be '.json', which is more generic (but see https://github.com/bids-standard/bids-validator/issues/2113)
for ext in extensions + ['.tsv' if runitem.bids['suffix']=='events' else '.dum']: # NB: `ext` used to be '.json', which is more generic (but see https://github.com/bids-standard/bids-validator/issues/2113)
if bidstest := bids_validator.BIDSValidator().is_bids(f"/sub-{sanitize(dataformat)}/{datatype}/{bidsname}{ext}"): break
if level==3 or (abs(level)==2 and not ignore_2) or (-2<level<2 and not ignore_1):
valid = valid and bidstest
Expand Down
2 changes: 1 addition & 1 deletion bidscoin/bidseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ def accept_run(self):
bidsvalid = validrun
datatype = self.target_run.datatype
if not (bids.check_ignore(datatype,self.bidsignore) or bids.check_ignore(bidsname.name,self.bidsignore,'file') or datatype in self.ignoredatatypes):
for ext in bids.extensions: # NB: `ext` used to be '.json', which is more generic (but see https://github.com/bids-standard/bids-validator/issues/2113)
for ext in bids.extensions + ['.tsv' if self.target_run.bids['suffix']=='events' else '.dum']: # NB: `ext` used to be '.json', which is more generic (but see https://github.com/bids-standard/bids-validator/issues/2113)
if bidsvalid := BIDSValidator().is_bids((Path('/')/self.subid/self.sesid/bidsname).with_suffix(ext).as_posix()): break

# If the bidsname is not valid, ask the user if that's OK
Expand Down
4 changes: 2 additions & 2 deletions bidscoin/bidsmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str,
LOGGER.bcdebug(f"Regular expression metacharacters found in {sesprefix}, this may cause errors later on...")
if not rawfolder.is_dir():
raise SystemExit(f"\n[ERROR] Exiting the program because your sourcefolder argument '{sourcefolder}' was not found")
if not templatefile.is_file():
raise SystemExit(f"\n[ERROR] Exiting the program because your template bidsmap '{templatefile}' was not found")

# Start logging
if force:
Expand All @@ -75,6 +73,8 @@ def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str,
bidsmap_old = BidsMap(bidsmapfile, bidscoinfolder, plugins)
bidsmapfile = bidsmap_old.filepath
template = BidsMap(templatefile, plugins=plugins, checks=(True, True, False))
if not template.filepath.is_file():
raise SystemExit(f"\n[ERROR] Exiting the program because your template bidsmap '{templatefile}' was not found")
template.check_template()

# Create the new bidsmap as a copy / bidsmap skeleton with only data types without run-items (i.e. empty lists)
Expand Down
4 changes: 2 additions & 2 deletions bidscoin/heuristics/bidsmap_bids2bids.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ Nibabel:
dir: <filename:sub-.*_dir-(.*?)_.*\.nii.*>
run: <<>>
echo:
part: ['', mag, phase, real, imag, 0]
part: <filename:sub-.*_part-(.*?)_.*\.nii.*>
suffix: asl
meta: &perf_meta
ArterialSpinLabelingType: "CASL / PCASL / PASL"
Expand Down Expand Up @@ -647,7 +647,7 @@ Nibabel:
dir: <filename:sub-.*_dir-(.*?)_.*\.nii.*>
run: <<>>
chunk: <filename:sub-.*_chunk-(.*?)_.*\.nii.*>
part: ['', mag, phase, real, imag, 0]
part: <filename:sub-.*_part-(.*?)_.*\.nii.*>
suffix: epi
meta: *fmap_meta
- properties:
Expand Down

0 comments on commit 18e1b8e

Please sign in to comment.