Skip to content
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

bids_ME heuristic: add test for the dataset that raised #541, add support for MEGRE #547

Merged
merged 8 commits into from
Apr 5, 2022
9 changes: 8 additions & 1 deletion heudiconv/heuristics/bids_ME.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ def infotodict(seqinfo):
subindex: sub index within group
"""
bold = create_key('sub-{subject}/func/sub-{subject}_task-test_run-{item}_bold')
megre_mag = create_key('sub-{subject}/anat/sub-{subject}_part-mag_MEGRE')
megre_phase = create_key('sub-{subject}/anat/sub-{subject}_part-phase_MEGRE')

info = {bold: []}
info = {bold: [], megre_mag: [], megre_phase: []}
for s in seqinfo:
if '_ME_' in s.series_description:
info[bold].append(s.series_id)
if 'GRE_QSM' in s.series_description:
if s.image_type[2] == 'M':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this code block is not covered by tests... what data was supposed to have it covered?

info[megre_mag].append(s.series_id)
elif s.image_type[2] == 'P':
info[megre_phase].append(s.series_id)
return info
39 changes: 39 additions & 0 deletions heudiconv/tests/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@
KeyInfoForForce,
BIDSFile,
)
from heudiconv.cli.run import main as runner

from .utils import (
fetch_data,
gen_heudiconv_args,
TESTS_DATA_PATH,
)

import pytest

have_datalad = True
try:
from datalad.support.exceptions import IncompleteResultsError
except ImportError:
have_datalad = False


def gen_rand_label(label_size, label_seed, seed_stdout=True):
seed(label_seed)
rand_char = ''.join(choice(string.ascii_letters) for _ in range(label_size-1))
Expand Down Expand Up @@ -1116,3 +1126,32 @@ def test_BIDSFile():
# -for an existing entity, you can overwrite it with "set":
my_bids_file.set('echo', '2')
assert my_bids_file['echo'] == '2'


@pytest.mark.skipif(not have_datalad, reason="no datalad")
def test_ME_mag_phase_conversion(tmpdir, subID='MEGRE', heuristic='bids_ME'):
""" Unit test for the case of multi-echo GRE data with
magnitude and phase.
The different echoes should be labeled automatically.
"""
tmpdir.chdir()
tmppath = tmpdir.strpath
try:
datadir = fetch_data(tmppath, "dicoms/velasco/{subID}")
yarikoptic marked this conversation as resolved.
Show resolved Hide resolved
except IncompleteResultsError as exc:
pytest.skip("Failed to fetch test data: %s" % str(exc))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note -- this line is "covered" which means that the test just skipped... I think I might see the reason

pvelasco marked this conversation as resolved.
Show resolved Hide resolved

outdir = tmpdir.mkdir('out').strpath
args = gen_heudiconv_args(datadir, outdir, subID, heuristic)
runner(args) # run conversion

# Check that the expected files have been extracted.
# This also checks that the "echo" entity comes before "part":
for part in ['mag', 'phase']:
for e in range(1,4):
for ext in ['nii.gz', 'json']:
assert op.exists(
op.join(outdir, 'sub-%s', 'anat', 'sub-%s_echo-%s_part-%s_MEGRE.%s')
% (subID, subID, e, part, ext)
)