BrkRaw / brkraw

BrkRaw: A comprehensive tool to access raw Bruker Biospin MRI data
https://brkraw.github.io
GNU General Public License v3.0
44 stars 27 forks source link

Multiple runs of the same modality conflict #76

Closed milaurose closed 2 years ago

milaurose commented 2 years ago

Describe the bug When the dataset includes multiple runs of the same modality, runningbrkraw bids_convert gives a conflict error saying that the run index must be unique. This occurs even when a unique run number has been entered into the datasheet. It appears as though the code is not actually checking the run value, may be an indentation bug (in https://github.com/BrkRaw/brkraw/blob/main/brkraw/scripts/brkraw.py#L397-L414)?

To Reproduce Steps to reproduce the behavior:

  1. Generate the datasheet brkraw bids_helper ./dataset/ ./bids_datasheet.xlsx -j
  2. Modify the datasheet to manually specify a unique run number whenever there are multiple runs of the same type of scan. Fill in other fields as well (see screenshots of original datasheet and modified datasheet).
  3. Run brkraw bids_convert /data/scratch/mila/dataset/ /data/scratch/mila/bids_datasheet_modified.xlsx -o /data/scratch/mila/outputs/
  4. Error:
    Inspect input BIDS datasheet...
    Converting 20211026_191002_MCH_FMR_PHG_DXN_1_1...
    Traceback (most recent call last):
    File "/home/cic/uromil/miniconda3/envs/brkraw/bin/brkraw", line 8, in <module>
    sys.exit(main())
    File "/home/cic/uromil/miniconda3/envs/brkraw/lib/python3.7/site-packages/brkraw/scripts/brkraw.py", line 458, in main
    ''.format(sub_row.ScanID))
    shleeh.errors.ValueConflictInField: ScanID:[9] Conflict error. The [run] index value must be unique among the scans with the same modality.
  5. The outputs folder is empty, except for the following file: sub-PHG001/fmap/{sub_row.FileName}_run-{str(sub_row.run).zfill(2)}_fieldmap.nii.gz

Additional testing

  1. Remove row 3 (the second fieldmap run) from the datasheet.
  2. Run brkraw bids_convert /data/scratch/mila/dataset/ /data/scratch/mila/bids_datasheet_modified_without_two_fieldmaps.xlsx -o /data/scratch/mila/outputs_without_two_fieldmaps/
  3. No errors arise and the following 4 files are produced: sub-PHG001/fmap/sub-PHG001_acq-B0map_fieldmap.nii.gz, sub-PHG001/func/sub-PHG001_task-rest_acq-EPI_bold.nii.gz, sub-PHG001/func/sub-PHG001_task-stim_acq-EPI_bold.nii.gz, sub-PHG001/anat/sub-PHG001_acq-RARE_T2w.nii.gz
  4. So, the code runs correctly but the run information is still not included in the names of the functional scans, despite being specified as two unique runs in the datasheet.

Expected behavior I would expect it to produce 5 files titled with the run numbers specified: sub-PHG001/fmap/sub-PHG001_acq-B0map_run-1_fieldmap.nii.gz, sub-PHG001/fmap/sub-PHG001_acq-B0map_run-2_fieldmap.nii.gz, sub-PHG001/func/sub-PHG001_task-rest_acq-EPI_run-1_bold.nii.gz, sub-PHG001/func/sub-PHG001_task-stim_acq-EPI_run-2_bold.nii.gz, sub-PHG001/anat/sub-PHG001_acq-RARE_T2w.nii.gz

Screenshots The original datasheet created by bids_helper: brkraw_issue_datasheet_original

The modified datasheet with run information manually specified: brkraw_issue_datasheet

Versions bruker==0.3.7 Python 3.7.3

Thanks so much!

gdevenyi commented 2 years ago

According to the BIDS spec, incrementing run values for the same scan type should be allowed/supported

Run - an uninterrupted repetition of data acquisition that has the same acquisition parameters and task (however events can change from run to run due to different subject response or randomized nature of the stimuli). Run is a synonym of a data acquisition. Note that "uninterrupted" may look different by modality due to the nature of the recording. For example, in MRI or [MEG] (04-modality-specific-files/02-magnetoencephalography.md), if a subject leaves the scanner, the acquisition must be restarted. For some types of PET acquisitions, a subject may leave and re-enter the scanner without interrupting the scan.

dvm-shlee commented 2 years ago

@milaurose Sorry for the delayed response, I think the commit 600a529e6b3e09d02c9b88de52c8df6e99944bac had solved this issue. The issue was happened due to the missing 'f' option on the string, now it will work normally. The latest version is now 0.3.8-rc1

Thank you!