-
Notifications
You must be signed in to change notification settings - Fork 134
[ENH] Adds extraction of physio signals from DICOMs #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
pvelasco
wants to merge
25
commits into
nipy:master
Choose a base branch
from
cbinyu:dcm_physio
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f4e8cfd
[ENH] Adds extraction of physio signals from DICOMs
pvelasco e832ae6
Adds heuristic for physio extraction.
pvelasco aff779f
Moves the installation of `bidsphysio` to `info.py`
pvelasco 9de4bd6
Minor formating in heudiconv/convert.py
pvelasco e935490
Minor formating in heudiconv/convert.py
pvelasco 9de5114
Minor formating in heudiconv/dicoms.py
pvelasco 892bc6a
Minor formatting updates
pvelasco e2774f5
Minor formatting updates
pvelasco cca6c7c
Adds `assert_cwd_unchanged` to `test_regression`
pvelasco 532c630
RF: convert - convert_physio returns if bids_options is None
pvelasco 4ac551e
ENH: Adds "AcquisitionTime" to the `seqinfo`
pvelasco 5b33646
Switch back order of seqinfo_fields
pvelasco 74d55d5
Switch back order of SeqInfo arguments in dicom.py
pvelasco 0fb0c2f
Adds unittest to check "time" in the right position in dicominfo.tsv
pvelasco 46c0bdb
ENH: Allows the user to save the Phoenix Report (Siemens) in the sour…
pvelasco 371d006
Changed calls to bidsphysio to conform with newest version
pvelasco 81ec2a2
Merge branch 'master' into dcm_physio
pvelasco 2768e7a
BF(py3.5): explicitly case path to str for open
yarikoptic fe3fc34
ENH(minor): sort imports
yarikoptic 38d6360
Merge pull request #6 from cbinyu/adds_acq_time_to_seqinfo
pvelasco 593062f
Merge branch 'dcm_physio' into handles_phoenix_file
pvelasco 62841a7
Merge pull request #7 from cbinyu/handles_phoenix_file
pvelasco 5c78593
Add environment marker (Py>3.5) for dcm2bids requirement.
pvelasco 0745845
Change name of extra_requires from dcm2bids to physio
pvelasco 15e4a49
Delete some unneeded checks in the bids_physio heuristic.
pvelasco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,6 +288,8 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov, | |
if outtype == 'dicom': | ||
convert_dicom(item_dicoms, bids_options, prefix, | ||
outdir, tempdirs, symlink, overwrite) | ||
elif outtype == 'physio': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we would need to document that, e.g. at https://github.com/nipy/heudiconv/blob/HEAD/docs/heuristics.rst#infotodictseqinfos (make it all into a nice itemized list there for |
||
convert_physio(item_dicoms, bids_options, prefix) | ||
elif outtype in ['nii', 'nii.gz']: | ||
assert converter == 'dcm2niix', ('Invalid converter ' | ||
'{}'.format(converter)) | ||
|
@@ -407,6 +409,43 @@ def convert_dicom(item_dicoms, bids_options, prefix, | |
shutil.copyfile(filename, outfile) | ||
|
||
|
||
def convert_physio(item_dicoms, bids_options, prefix): | ||
"""Save DICOM physiology as BIDS physio files | ||
Parameters | ||
pvelasco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
---------- | ||
item_dicoms : list of filenames | ||
DICOMs to save | ||
bids_options : list or None | ||
If not None then save to BIDS format. List may be empty | ||
or contain bids specific options | ||
prefix : string | ||
Conversion outname | ||
Returns | ||
pvelasco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
------- | ||
None | ||
""" | ||
if bids_options is not None: | ||
try: | ||
pvelasco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from bidsphysio import dcm2bidsphysio | ||
except ImportError: | ||
lgr.warning( | ||
"Dcm2bidsphysio not found. " | ||
"Not extracting physiological recordings." | ||
) | ||
return | ||
|
||
item_dicoms = list(map(op.abspath, item_dicoms)) # absolute paths | ||
if len(item_dicoms)>1: | ||
pvelasco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
lgr.warning( | ||
"More than one PHYSIO file has been found for this series. " | ||
"If each file corresponds to a different signal, all is OK. " | ||
"If multiple files have the same signal, only the signal " | ||
"from the last file will be saved." | ||
) | ||
for dicom_file in item_dicoms: | ||
dcm2bidsphysio.dcm2bids( dicom_file, prefix ) | ||
pvelasco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def nipype_convert(item_dicoms, prefix, with_prov, bids_options, tmpdir, dcmconfig=None): | ||
""" | ||
Converts DICOMs grouped from heuristic using Nipype's Dcm2niix interface. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
""" | ||
Heuristic demonstrating extraction of physiological data from CMRR | ||
fMRI DICOMs | ||
|
||
We want to make sure the run number for the _sbref, _phase and | ||
_physio matches that of the corresponding _bold. For "normal" | ||
scanning, you can just rely on the {item} value, but if you have a | ||
functional run with just saving the magnitude and then one saving | ||
both magnitude and phase, you would have _run-01_bold, _run-02_bold | ||
and _run-01_phase, but the phase image corresponds to _run-02_bold, | ||
so the run number in the filename will not match | ||
""" | ||
|
||
|
||
def create_key(template, outtype=('nii.gz',), annotation_classes=None): | ||
if template is None or not template: | ||
raise ValueError('Template must be a valid format string') | ||
return template, outtype, annotation_classes | ||
|
||
def infotodict(seqinfo): | ||
"""Heuristic evaluator for determining which runs belong where | ||
|
||
allowed template fields - follow python string module: | ||
|
||
item: index within category | ||
subject: participant id | ||
seqitem: run number during scanning | ||
subindex: sub index within group | ||
""" | ||
|
||
info = {} | ||
run_no = 0 | ||
for idx, s in enumerate(seqinfo): | ||
# We want to make sure the _SBRef, PhysioLog and phase series | ||
# (if present) are labeled the same as the main (magnitude) | ||
# image. So we only focus on the magnitude series (to exclude | ||
# phase images) without _SBRef at the end of the series_ | ||
# description and then we search if the phase and/or _SBRef | ||
# are present. | ||
if ( | ||
'epfid2d' in s.sequence_name | ||
and ( | ||
'M' in s.image_type | ||
or 'FMRI' in s.image_type | ||
) | ||
and not s.series_description.lower().endswith('_sbref') | ||
and not 'DERIVED' in s.image_type | ||
): | ||
run_no += 1 | ||
bold = create_key( | ||
'sub-{subject}/func/sub-{subject}_task-test_run-%02d_bold' % run_no | ||
) | ||
info[bold] = [{'item': s.series_id}] | ||
next_series = idx+1 # used for physio log below | ||
|
||
### is phase image present? ### | ||
# At least for Siemens systems, if magnitude/phase was | ||
# selected, the phase images come as a separate series | ||
# immediatelly following the magnitude series. | ||
# (note: make sure you don't check beyond the number of | ||
# elements in seqinfo...) | ||
if ( | ||
idx+1 < len(seqinfo) | ||
and 'P' in seqinfo[idx+1].image_type | ||
): | ||
phase = create_key( | ||
'sub-{subject}/func/sub-{subject}_task-test_run-%02d_phase' % run_no | ||
) | ||
info[phase] = [{'item': seqinfo[idx+1].series_id}] | ||
next_series = idx+2 # used for physio log below | ||
|
||
### SBREF ### | ||
# here, within the functional run code, check to see if | ||
# the previous run's series_description ended in _sbref, | ||
# to assign the same run number. | ||
if ( | ||
idx > 0 | ||
and seqinfo[idx-1].series_description.lower().endswith('_sbref') | ||
): | ||
sbref = create_key( | ||
'sub-{subject}/func/sub-{subject}_task-test_run-%02d_sbref' % run_no | ||
) | ||
info[sbref] = [{'item': seqinfo[idx-1].series_id}] | ||
|
||
### PHYSIO LOG ### | ||
# here, within the functional run code, check to see if | ||
# the next run image_type lists "PHYSIO", to assign the | ||
# same run number. | ||
if ( | ||
next_series < len(seqinfo) | ||
and 'PHYSIO' in seqinfo[next_series].image_type | ||
): | ||
physio = create_key( | ||
'sub-{subject}/func/sub-{subject}_task-test_run-%02d_physio' % run_no, | ||
outtype = ('physio',) | ||
) | ||
info[physio] = [{'item': seqinfo[next_series].series_id}] | ||
|
||
return info |
Binary file added
BIN
+171 KB
heudiconv/tests/data/samplePhysio/01+physio_test/samplePhysio+01+physio_test_01+00001.dcm
Binary file not shown.
Binary file added
BIN
+171 KB
heudiconv/tests/data/samplePhysio/01+physio_test/samplePhysio+01+physio_test_01+00002.dcm
Binary file not shown.
Binary file added
BIN
+171 KB
heudiconv/tests/data/samplePhysio/01+physio_test/samplePhysio+01+physio_test_01+00003.dcm
Binary file not shown.
Binary file added
BIN
+171 KB
heudiconv/tests/data/samplePhysio/01+physio_test/samplePhysio+01+physio_test_01+00004.dcm
Binary file not shown.
Binary file added
BIN
+171 KB
heudiconv/tests/data/samplePhysio/01+physio_test/samplePhysio+01+physio_test_01+00005.dcm
Binary file not shown.
Binary file added
BIN
+317 KB
heudiconv/tests/data/samplePhysio/02+physio_test/samplePhysio+02+physio_test+00001.dcm
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
samplePhysio dataset | ||
|
||
It contains phantom functional images and physiological recordings | ||
using CMRR Multi-Band EPI saved as DICOMs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.