Skip to content

Commit 605a2b6

Browse files
committed
add a bids-uri-specific check
1 parent 23c4dea commit 605a2b6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

cubids/cubids.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,16 @@ def change_filename(self, filepath, entities):
631631
# Coerce IntendedFor to a list.
632632
data["IntendedFor"] = listify(data["IntendedFor"])
633633
for item in data["IntendedFor"]:
634-
if item in _get_intended_for_reference(filepath):
634+
if item in _get_participant_relative_path(filepath):
635635
# remove old filename
636636
data["IntendedFor"].remove(item)
637637
# add new filename
638-
data["IntendedFor"].append(_get_intended_for_reference(new_path))
638+
data["IntendedFor"].append(_get_participant_relative_path(new_path))
639+
if item in _get_bidsuri(filepath):
640+
# remove old filename
641+
data["IntendedFor"].remove(item)
642+
# add new filename
643+
data["IntendedFor"].append(_get_bidsuri(new_path))
639644

640645
# update the json with the new data dictionary
641646
_update_json(filename_with_if, data)
@@ -757,7 +762,7 @@ def _purge_associations(self, scans):
757762
# sub, ses, modality only (no self.path)
758763
if_scans = []
759764
for scan in scans:
760-
if_scans.append(_get_intended_for_reference(self.path + scan))
765+
if_scans.append(_get_participant_relative_path(self.path + scan))
761766

762767
for path in Path(self.path).rglob("sub-*/*/fmap/*.json"):
763768
# json_file = self.layout.get_file(str(path))
@@ -1428,10 +1433,19 @@ def _file_to_entity_set(filename):
14281433
return _entities_to_entity_set(entities)
14291434

14301435

1431-
def _get_intended_for_reference(scan):
1436+
def _get_participant_relative_path(scan):
1437+
"""Build the relative-from-subject version of a Path to a file.
1438+
1439+
This is what will appear in the IntendedFor field of any association.
1440+
1441+
"""
14321442
return "/".join(Path(scan).parts[-3:])
14331443

14341444

1445+
def _get_bidsuri(scan):
1446+
return scan
1447+
1448+
14351449
def _get_param_groups(
14361450
files,
14371451
fieldmap_lookup,

0 commit comments

Comments
 (0)