Donders-Institute / bidscoin

BIDScoin converts your source-level neuroimaging data to BIDS
https://bidscoin.readthedocs.io
GNU General Public License v3.0
131 stars 35 forks source link

Handling ABCD GE pepolar sequences and other split-files. #148

Closed ajschadler12 closed 2 years ago

ajschadler12 commented 2 years ago

Is your feature request related to a problem? Please describe. When dcm2niix converts an ABCD-style GE pepolar sequence (i.e. blip-up and blip-down as single spin-echo series), it normally splits it into two separate files. The bidsmap editor can only assign a single mapping for these sequences, when really a pair is needed (i.e. same label, with differing dir- labels).

This causes bidscoin to crash with a KeyError when writing to participants.tsv:

2022-08-26 12:44:39 - INFO | Writing sub-123 subject data to: /home/hamilton/bids/participants.tsv
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3621, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'fmap/sub-123_dir-AP_run-1_epia.nii.gz'

Describe the solution you'd like Either the program should be able to reverse the dir- label when it detects a GE ABCD pepolar sequence or the user needs the option to specify if a mapping corresponds to a split file, and how the split file should be treated.

marcelzwiers commented 2 years ago

Dealing with fieldmaps is tricky as they are stored in so many (sequence and vendor-dependent) ways. I would have to add an if-clausule to catch your use case, but I have no access to or experience with GE data. Can you possibly provide me with test data?

marcelzwiers commented 2 years ago

p.s. A single slice just from the fieldmap series (both RO directions) will do

ajschadler12 commented 2 years ago

Here is a full acquisition. The scan is of myself, so I have no qualms with sharing.

dcm2niix versions greater than v1.0.20211006 should support GE ABCD pepolar research sequences like this. By default, it will save two files, with volumes of each PE grouped. The json files differ in only two fields:

PE-1 PE-2
"PhaseEncodingPolarityGE": "Unflipped" "PhaseEncodingPolarityGE": "Flipped"
"PhaseEncodingDirection": "j-" "PhaseEncodingDirection": "j"
marcelzwiers commented 2 years ago

Ok, I made a fix for the crash, will have to work on proper handling of PhaseEncodingPolarityGE a bit more...

marcelzwiers commented 2 years ago

I think it should work now, you can test it with:

pip install --upgrade git+https://github.com/Donders-Institute/bidscoin    # Add --force-reinstall if needed
ajschadler12 commented 2 years ago

The previous fix (438b8a0) solved the issue of crashing.

The fix you just submitted, 1d0f8f2 unfortunately is causing a crash at the very end of the conversion:


Traceback (most recent call last):
  File "/home/ajschadler12/.local/bin//bidscoiner", line 8, in <module>
    sys.exit(main())
  File "/home/ajschadler12/.local/lib/python3.10/site-packages/bidscoin/bidscoiner.py", line 376, in main
    bidscoiner(rawfolder    = args.sourcefolder,
  File "/home/ajschadler12/.local/lib/python3.10/site-packages/bidscoin/bidscoiner.py", line 200, in bidscoiner
    module.bidscoiner_plugin(sesfolder, bidsmap, bidssession)
  File "/home/ajschadler12/.local/lib/python3.10/site-packages/bidscoin/plugins/dcm2niix2bids.py", line 277, in bidscoiner_plugin
    ext = ''.join(extrafile[0].suffixes)
IndexError: list index out of range
marcelzwiers commented 2 years ago

Ah, yes, I see (it didn't come up when I tested just the fieldmap). Can you try again?

ajschadler12 commented 2 years ago

That did it!

Incidentally, when I tried just testing the fieldmap, bidsmapper recognized the sequence as a P-file instead of a DICOM. (if that is a bug, can open a separate issue...)

marcelzwiers commented 2 years ago

That's p7 detection is done by the spec2nii2bids plugin (that you can probably remove from your bidsmap?). I think the p-file always has a .7 file extension, but one of your DICOM files also has that same extension. Doing a deeper check is slower, perhaps I should leave the spec2nii2bids plugin as an optional plugin instead of a default one...

marcelzwiers commented 2 years ago

The current implementation does not give full control over the dir label but I think I will leave like it is for now (as it's complicated due to BIDScoin's design to handle two sequences from one seriesfolder as separate series).

ajschadler12 commented 2 years ago

I think it should be fine for now. Users can use bulk-rename utilities to change "Flipped" or "Unflipped" to the desired direction