|
36 | 36 | ) |
37 | 37 |
|
38 | 38 |
|
39 | | -def getRelPathToBIDS(filepath, bids_root): |
| 39 | +def getRelPathToBIDS(filepath, bids_root, bidsuri_format=False): |
40 | 40 | """ |
41 | 41 | This function returns a relative file link that is relative to the BIDS root directory. |
42 | 42 |
|
43 | 43 | :param filename: absolute path + file |
44 | 44 | :param bids_root: absolute path to BIDS directory |
| 45 | + :param bidsuri_format: if True, BIDS URI format is created with bids:: prefix |
45 | 46 | :return: relative path to file, relative to BIDS root |
46 | 47 | """ |
47 | 48 | path, file = os.path.split(filepath) |
48 | 49 |
|
49 | 50 | relpath = path.replace(bids_root, "") |
50 | | - return os.path.join(relpath, file) |
| 51 | + file_relpath = os.path.join(relpath, file) |
| 52 | + if bidsuri_format: |
| 53 | + file_relpath = f'bids::{file_relpath.lstrip("/")}' |
| 54 | + return file_relpath |
51 | 55 |
|
52 | 56 |
|
53 | 57 | def getsha512(filename): |
@@ -311,7 +315,9 @@ def addimagingsessions( |
311 | 315 | acq_obj.add_attributes( |
312 | 316 | { |
313 | 317 | Constants.NIDM_FILENAME: getRelPathToBIDS( |
314 | | - join(file_tpl.dirname, file_tpl.filename), directory |
| 318 | + join(file_tpl.dirname, file_tpl.filename), |
| 319 | + directory, |
| 320 | + bidsuri_format=True, |
315 | 321 | ) |
316 | 322 | } |
317 | 323 | ) |
@@ -458,7 +464,9 @@ def addimagingsessions( |
458 | 464 | acq_obj.add_attributes( |
459 | 465 | { |
460 | 466 | Constants.NIDM_FILENAME: getRelPathToBIDS( |
461 | | - join(file_tpl.dirname, file_tpl.filename), directory |
| 467 | + join(file_tpl.dirname, file_tpl.filename), |
| 468 | + directory, |
| 469 | + bidsuri_format=True, |
462 | 470 | ) |
463 | 471 | } |
464 | 472 | ) |
@@ -554,7 +562,7 @@ def addimagingsessions( |
554 | 562 | PROV_TYPE: Constants.NIDM_MRI_BOLD_EVENTS, |
555 | 563 | BIDS_Constants.json_keys["TaskName"]: json_data["TaskName"], |
556 | 564 | Constants.NIDM_FILENAME: getRelPathToBIDS( |
557 | | - events_file[0].filename, directory |
| 565 | + events_file[0].filename, directory, bidsuri_format=True |
558 | 566 | ), |
559 | 567 | } |
560 | 568 | ) |
@@ -661,7 +669,9 @@ def addimagingsessions( |
661 | 669 | acq_obj.add_attributes( |
662 | 670 | { |
663 | 671 | Constants.NIDM_FILENAME: getRelPathToBIDS( |
664 | | - join(file_tpl.dirname, file_tpl.filename), directory |
| 672 | + join(file_tpl.dirname, file_tpl.filename), |
| 673 | + directory, |
| 674 | + bidsuri_format=True, |
665 | 675 | ) |
666 | 676 | } |
667 | 677 | ) |
@@ -765,7 +775,9 @@ def addimagingsessions( |
765 | 775 | acq_obj.add_attributes( |
766 | 776 | { |
767 | 777 | Constants.NIDM_FILENAME: getRelPathToBIDS( |
768 | | - join(file_tpl.dirname, file_tpl.filename), directory |
| 778 | + join(file_tpl.dirname, file_tpl.filename), |
| 779 | + directory, |
| 780 | + bidsuri_format=True, |
769 | 781 | ) |
770 | 782 | } |
771 | 783 | ) |
@@ -846,6 +858,7 @@ def addimagingsessions( |
846 | 858 | ), |
847 | 859 | ), |
848 | 860 | directory, |
| 861 | + bidsuri_format=True, |
849 | 862 | ) |
850 | 863 | } |
851 | 864 | ) |
@@ -905,6 +918,7 @@ def addimagingsessions( |
905 | 918 | ), |
906 | 919 | ), |
907 | 920 | directory, |
| 921 | + bidsuri_format=True, |
908 | 922 | ) |
909 | 923 | } |
910 | 924 | ) |
@@ -1114,7 +1128,9 @@ def bidsmri2project(directory, args): |
1114 | 1128 | acq_entity.add_attributes( |
1115 | 1129 | { |
1116 | 1130 | Constants.NIDM_FILENAME: getRelPathToBIDS( |
1117 | | - os.path.join(directory, "participants.tsv"), directory |
| 1131 | + os.path.join(directory, "participants.tsv"), |
| 1132 | + directory, |
| 1133 | + bidsuri_format=True, |
1118 | 1134 | ) |
1119 | 1135 | } |
1120 | 1136 | ) |
@@ -1153,7 +1169,9 @@ def bidsmri2project(directory, args): |
1153 | 1169 | Namespace("bids", Constants.BIDS), "sidecar_file" |
1154 | 1170 | ), |
1155 | 1171 | Constants.NIDM_FILENAME: getRelPathToBIDS( |
1156 | | - os.path.join(directory, "participants.json"), directory |
| 1172 | + os.path.join(directory, "participants.json"), |
| 1173 | + directory, |
| 1174 | + bidsuri_format=True, |
1157 | 1175 | ), |
1158 | 1176 | } |
1159 | 1177 | ) |
@@ -1376,7 +1394,11 @@ def bidsmri2project(directory, args): |
1376 | 1394 |
|
1377 | 1395 | # link TSV file |
1378 | 1396 | acq_entity.add_attributes( |
1379 | | - {Constants.NIDM_FILENAME: getRelPathToBIDS(tsv_file, directory)} |
| 1397 | + { |
| 1398 | + Constants.NIDM_FILENAME: getRelPathToBIDS( |
| 1399 | + tsv_file, directory, bidsuri_format=True |
| 1400 | + ) |
| 1401 | + } |
1380 | 1402 | ) |
1381 | 1403 |
|
1382 | 1404 | # if there are git annex sources for participants.tsv file then add them |
@@ -1408,7 +1430,7 @@ def bidsmri2project(directory, args): |
1408 | 1430 | { |
1409 | 1431 | PROV_TYPE: Constants.BIDS["sidecar_file"], |
1410 | 1432 | Constants.NIDM_FILENAME: getRelPathToBIDS( |
1411 | | - data_dict, directory |
| 1433 | + data_dict, directory, bidsuri_format=True |
1412 | 1434 | ), |
1413 | 1435 | } |
1414 | 1436 | ) |
|
0 commit comments