Пример #1
0
def test_reg_jacobian_jac_l():

    # Create a reg_jacobian object
    nr = RegJacobian()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_jacobian')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.trans_file = trans_file
    nr.inputs.type = 'jacL'
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jacL {jac}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_jacobian'),
                                  ref=ref_file,
                                  trans=trans_file,
                                  jac=os.path.join(os.getcwd(),
                                                   'warpfield_jacL.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #2
0
def test_reg_average_avg_lts():

    # Create a reg_average object
    nr = RegAverage()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_average')

    # Assign some input data
    one_file = example_data('TransformParameters.0.txt')
    two_file = example_data('ants_Affine.txt')
    three_file = example_data('elastix.txt')
    nr.inputs.avg_lts_files = [one_file, two_file, three_file]
    nr.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f:
        argv = f.read()
    os.remove(reg_average_cmd)

    expected_argv = ('%s %s -avg_lts %s %s %s' %
                     (get_custom_path('reg_average'),
                      os.path.join(os.getcwd(), 'avg_out.txt'), one_file,
                      two_file, three_file))

    assert argv == expected_argv

    expected_cmd = ('%s --cmd_file %s' %
                    (get_custom_path('reg_average'), reg_average_cmd))

    assert nr.cmdline == expected_cmd
Пример #3
0
def test_reg_f3d():

    # Create a reg_f3d object
    nr = RegF3D()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_f3d')

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    rmask_file = example_data('mask.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.flo_file = flo_file
    nr.inputs.rmask_file = rmask_file
    nr.inputs.omp_core_val = 4
    nr.inputs.vel_flag = True
    nr.inputs.be_val = 0.1
    nr.inputs.le_val = 0.1

    expected_cmd = get_custom_path('reg_f3d') + ' ' + '-be 0.100000 ' +\
                   '-cpp ' + os.getcwd() + os.sep + 'im2_cpp.nii.gz ' +'-flo ' + flo_file + ' ' +\
                   '-le 0.100000 ' + '-omp 4 ' + '-ref ' + ref_file + ' ' +\
                   '-res ' + os.getcwd() + os.sep + 'im2_res.nii.gz ' + '-rmask ' + rmask_file + ' ' + '-vel'
    yield assert_equal, nr.cmdline, expected_cmd
Пример #4
0
def test_reg_tools_iso():

    # Create a reg_tools object
    nr = RegTools()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_tools')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    nr.inputs.in_file = in_file
    nr.inputs.iso_flag = True
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -in {in_file} -iso -omp 4 -out {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_tools'),
                                  in_file=in_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'im1_tools.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #5
0
def test_reg_average_avg_nii():

    # Create a reg_average object
    nr = RegAverage()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_average')

    # Assign some input data
    one_file = example_data('im1.nii')
    two_file = example_data('im2.nii')
    three_file = example_data('im3.nii')
    nr.inputs.avg_files = [one_file, two_file, three_file]
    nr.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f:
        argv = f.read()
    os.remove(reg_average_cmd)

    expected_argv = '%s %s -avg %s %s %s' % (get_custom_path(
        'reg_average'), os.path.join(
            os.getcwd(), 'avg_out.nii.gz'), one_file, two_file, three_file)

    assert argv == expected_argv

    expected_cmd = ('%s --cmd_file %s' %
                    (get_custom_path('reg_average'), reg_average_cmd))

    assert nr.cmdline == expected_cmd
Пример #6
0
def test_reg_average_avg_nii():

    # Create a reg_average object
    nr = RegAverage()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_average')

    # Assign some input data
    one_file = example_data('im1.nii')
    two_file = example_data('im2.nii')
    three_file = example_data('im3.nii')
    nr.inputs.avg_files = [one_file, two_file, three_file]
    nr.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f:
        argv = f.read()
    os.remove(reg_average_cmd)

    expected_argv = '%s %s -avg %s %s %s' % (get_custom_path('reg_average'),
                                             os.path.join(os.getcwd(),
                                                          'avg_out.nii.gz'),
                                             one_file, two_file, three_file)

    yield assert_equal, argv, expected_argv

    expected_cmd = ('%s --cmd_file %s'
                    % (get_custom_path('reg_average'), reg_average_cmd))

    yield assert_equal, nr.cmdline, expected_cmd
Пример #7
0
def test_reg_tools_iso():

    # Create a reg_tools object
    nr = RegTools()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_tools')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    nr.inputs.in_file = in_file
    nr.inputs.iso_flag = True
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -in {in_file} -iso -omp 4 -out {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_tools'),
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'im1_tools.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #8
0
def test_reg_resample_blank():

    # Create a reg_resample object
    nr = RegResample()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_resample')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    trans_file = example_data('warpfield.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.flo_file = flo_file
    nr.inputs.trans_file = trans_file
    nr.inputs.type = 'blank'
    nr.inputs.inter_val = 'LIN'
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -flo {flo} -inter 1 -omp 4 -ref {ref} -trans {trans} \
-blank {blank}'

    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_resample'),
                                  flo=flo_file,
                                  ref=ref_file,
                                  trans=trans_file,
                                  blank=os.path.join(os.getcwd(),
                                                     'im2_blank.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #9
0
def test_reg_jacobian_jac_l():

    # Create a reg_jacobian object
    nr = RegJacobian()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_jacobian')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.trans_file = trans_file
    nr.inputs.type = 'jacL'
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jacL {jac}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_jacobian'),
        ref=ref_file,
        trans=trans_file,
        jac=os.path.join(os.getcwd(), 'warpfield_jacL.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #10
0
def test_reg_f3d():
    """ tests for reg_f3d interface"""
    # Create a reg_f3d object
    nr_f3d = RegF3D()

    # Check if the command is properly defined
    assert nr_f3d.cmd == get_custom_path('reg_f3d')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_f3d.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    rmask_file = example_data('mask.nii')
    nr_f3d.inputs.ref_file = ref_file
    nr_f3d.inputs.flo_file = flo_file
    nr_f3d.inputs.rmask_file = rmask_file
    nr_f3d.inputs.omp_core_val = 4
    nr_f3d.inputs.vel_flag = True
    nr_f3d.inputs.be_val = 0.1
    nr_f3d.inputs.le_val = 0.1

    cmd_tmp = '{cmd} -be 0.100000 -cpp {cpp} -flo {flo} -le 0.100000 -omp 4 \
-ref {ref} -res {res} -rmask {rmask} -vel'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_f3d'),
        cpp=os.path.join(os.getcwd(), 'im2_cpp.nii.gz'),
        flo=flo_file,
        ref=ref_file,
        res=os.path.join(os.getcwd(), 'im2_res.nii.gz'),
        rmask=rmask_file)

    assert nr_f3d.cmdline == expected_cmd
Пример #11
0
def test_reg_aladin():
    """ tests for reg_aladin interface"""
    # Create a reg_aladin object
    nr_aladin = RegAladin()

    # Check if the command is properly defined
    assert nr_aladin.cmd == get_custom_path('reg_aladin')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_aladin.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    rmask_file = example_data('mask.nii')
    nr_aladin.inputs.ref_file = ref_file
    nr_aladin.inputs.flo_file = flo_file
    nr_aladin.inputs.rmask_file = rmask_file
    nr_aladin.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -aff {aff} -flo {flo} -omp 4 -ref {ref} -res {res} \
-rmask {rmask}'

    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_aladin'),
        aff='im2_aff.txt',
        flo=flo_file,
        ref=ref_file,
        res='im2_res.nii.gz',
        rmask=rmask_file,
    )

    assert nr_aladin.cmdline == expected_cmd
Пример #12
0
def test_reg_average_avg_lts():

    # Create a reg_average object
    nr = RegAverage()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_average')

    # Assign some input data
    one_file = example_data('TransformParameters.0.txt')
    two_file = example_data('ants_Affine.txt')
    three_file = example_data('elastix.txt')
    nr.inputs.avg_lts_files = [one_file, two_file, three_file]
    nr.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f:
        argv = f.read()
    os.remove(reg_average_cmd)

    expected_argv = ('%s %s -avg_lts %s %s %s'
                     % (get_custom_path('reg_average'),
                        os.path.join(os.getcwd(), 'avg_out.txt'),
                        one_file, two_file, three_file))

    yield assert_equal, argv, expected_argv

    expected_cmd = ('%s --cmd_file %s'
                    % (get_custom_path('reg_average'), reg_average_cmd))

    yield assert_equal, nr.cmdline, expected_cmd
Пример #13
0
def test_reg_transform_comp_nii():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_transform')

    # Assign some input data
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    trans2_file = example_data('anatomical.nii')
    nr.inputs.ref1_file = ref_file
    nr.inputs.comp_input2 = trans2_file
    nr.inputs.comp_input = trans_file
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -ref {ref_file} -omp 4 -comp {trans1} {trans2} {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_transform'),
        ref_file=ref_file,
        trans1=trans_file,
        trans2=trans2_file,
        out_file=os.path.join(os.getcwd(), 'warpfield_trans.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #14
0
def test_reg_aladin():

    # Create a reg_aladin object
    nr = RegAladin()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_aladin')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    rmask_file = example_data('mask.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.flo_file = flo_file
    nr.inputs.rmask_file = rmask_file
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -aff {aff} -flo {flo} -omp 4 -ref {ref} -res {res} \
-rmask {rmask}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_aladin'),
        aff=os.path.join(os.getcwd(), 'im2_aff.txt'),
        flo=flo_file,
        ref=ref_file,
        res=os.path.join(os.getcwd(), 'im2_res.nii.gz'),
        rmask=rmask_file)

    assert nr.cmdline == expected_cmd
Пример #15
0
def test_reg_resample_blank():

    # Create a reg_resample object
    nr = RegResample()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_resample')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    trans_file = example_data('warpfield.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.flo_file = flo_file
    nr.inputs.trans_file = trans_file
    nr.inputs.type = 'blank'
    nr.inputs.inter_val = 'LIN'
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -flo {flo} -inter 1 -omp 4 -ref {ref} -trans {trans} \
-blank {blank}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_resample'),
        flo=flo_file,
        ref=ref_file,
        trans=trans_file,
        blank=os.path.join(os.getcwd(), 'im2_blank.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #16
0
def test_reg_transform_comp_nii():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_transform')

    # Assign some input data
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    trans2_file = example_data('anatomical.nii')
    nr.inputs.ref1_file = ref_file
    nr.inputs.comp_input2 = trans2_file
    nr.inputs.comp_input = trans_file
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -ref {ref_file} -omp 4 -comp {trans1} {trans2} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  ref_file=ref_file,
                                  trans1=trans_file,
                                  trans2=trans2_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'warpfield_trans.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #17
0
def test_reg_measure():
    """ tests for reg_measure interface """
    # Create a reg_measure object
    nr_measure = RegMeasure()

    # Check if the command is properly defined
    assert nr_measure.cmd == get_custom_path('reg_measure')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_measure.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    nr_measure.inputs.ref_file = ref_file
    nr_measure.inputs.flo_file = flo_file
    nr_measure.inputs.measure_type = 'lncc'
    nr_measure.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -flo {flo} -lncc -omp 4 -out {out} -ref {ref}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_measure'),
        flo=flo_file,
        out='im2_lncc.txt',
        ref=ref_file)

    assert nr_measure.cmdline == expected_cmd
Пример #18
0
def test_reg_measure():
    """ tests for reg_measure interface """
    # Create a reg_measure object
    nr_measure = RegMeasure()

    # Check if the command is properly defined
    assert nr_measure.cmd == get_custom_path('reg_measure')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_measure.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    nr_measure.inputs.ref_file = ref_file
    nr_measure.inputs.flo_file = flo_file
    nr_measure.inputs.measure_type = 'lncc'
    nr_measure.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -flo {flo} -lncc -omp 4 -out {out} -ref {ref}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_measure'),
                                  flo=flo_file,
                                  out=os.path.join(os.getcwd(),
                                                   'im2_lncc.txt'),
                                  ref=ref_file)

    assert nr_measure.cmdline == expected_cmd
Пример #19
0
def test_reg_jacobian_jac():
    """ Test interface for RegJacobian """
    # Create a reg_jacobian object
    nr_jacobian = RegJacobian()

    # Check if the command is properly defined
    assert nr_jacobian.cmd == get_custom_path('reg_jacobian')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_jacobian.run()

    # Test Reg Jacobian: jac
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr_jacobian.inputs.ref_file = ref_file
    nr_jacobian.inputs.trans_file = trans_file
    nr_jacobian.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jac {jac}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_jacobian'),
                                  ref=ref_file,
                                  trans=trans_file,
                                  jac=os.path.join(os.getcwd(),
                                                   'warpfield_jac.nii.gz'))

    assert nr_jacobian.cmdline == expected_cmd

    # Test Reg Jacobian: jac m
    nr_jacobian_2 = RegJacobian(type='jacM', omp_core_val=4)
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr_jacobian_2.inputs.ref_file = ref_file
    nr_jacobian_2.inputs.trans_file = trans_file

    cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jacM {jac}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_jacobian'),
                                  ref=ref_file,
                                  trans=trans_file,
                                  jac=os.path.join(os.getcwd(),
                                                   'warpfield_jacM.nii.gz'))

    assert nr_jacobian_2.cmdline == expected_cmd

    # Test Reg Jacobian: jac l
    nr_jacobian_3 = RegJacobian(type='jacL', omp_core_val=4)
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr_jacobian_3.inputs.ref_file = ref_file
    nr_jacobian_3.inputs.trans_file = trans_file

    cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jacL {jac}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_jacobian'),
                                  ref=ref_file,
                                  trans=trans_file,
                                  jac=os.path.join(os.getcwd(),
                                                   'warpfield_jacL.nii.gz'))

    assert nr_jacobian_3.cmdline == expected_cmd
Пример #20
0
def test_reg_jacobian_jac():
    """ Test interface for RegJacobian """
    # Create a reg_jacobian object
    nr_jacobian = RegJacobian()

    # Check if the command is properly defined
    assert nr_jacobian.cmd == get_custom_path('reg_jacobian')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_jacobian.run()

    # Test Reg Jacobian: jac
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr_jacobian.inputs.ref_file = ref_file
    nr_jacobian.inputs.trans_file = trans_file
    nr_jacobian.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jac {jac}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_jacobian'),
        ref=ref_file,
        trans=trans_file,
        jac='warpfield_jac.nii.gz')

    assert nr_jacobian.cmdline == expected_cmd

    # Test Reg Jacobian: jac m
    nr_jacobian_2 = RegJacobian(type='jacM', omp_core_val=4)
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr_jacobian_2.inputs.ref_file = ref_file
    nr_jacobian_2.inputs.trans_file = trans_file

    cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jacM {jac}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_jacobian'),
        ref=ref_file,
        trans=trans_file,
        jac='warpfield_jacM.nii.gz')

    assert nr_jacobian_2.cmdline == expected_cmd

    # Test Reg Jacobian: jac l
    nr_jacobian_3 = RegJacobian(type='jacL', omp_core_val=4)
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr_jacobian_3.inputs.ref_file = ref_file
    nr_jacobian_3.inputs.trans_file = trans_file

    cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jacL {jac}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_jacobian'),
        ref=ref_file,
        trans=trans_file,
        jac='warpfield_jacL.nii.gz')

    assert nr_jacobian_3.cmdline == expected_cmd
Пример #21
0
def test_reg_resample_res():
    """ tests for reg_resample interface """
    # Create a reg_resample object
    nr_resample = RegResample()

    # Check if the command is properly defined
    assert nr_resample.cmd == get_custom_path('reg_resample')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_resample.run()

    # Resample res
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    trans_file = example_data('warpfield.nii')
    nr_resample.inputs.ref_file = ref_file
    nr_resample.inputs.flo_file = flo_file
    nr_resample.inputs.trans_file = trans_file
    nr_resample.inputs.inter_val = 'LIN'
    nr_resample.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -flo {flo} -inter 1 -omp 4 -ref {ref} -trans {trans} \
-res {res}'

    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_resample'),
                                  flo=flo_file,
                                  ref=ref_file,
                                  trans=trans_file,
                                  res='im2_res.nii.gz')

    assert nr_resample.cmdline == expected_cmd

    # test_reg_resample_blank()
    nr_resample_2 = RegResample(type='blank', inter_val='LIN', omp_core_val=4)
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    trans_file = example_data('warpfield.nii')
    nr_resample_2.inputs.ref_file = ref_file
    nr_resample_2.inputs.flo_file = flo_file
    nr_resample_2.inputs.trans_file = trans_file

    cmd_tmp = '{cmd} -flo {flo} -inter 1 -omp 4 -ref {ref} -trans {trans} \
-blank {blank}'

    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_resample'),
                                  flo=flo_file,
                                  ref=ref_file,
                                  trans=trans_file,
                                  blank='im2_blank.nii.gz')

    assert nr_resample_2.cmdline == expected_cmd
Пример #22
0
def test_reg_resample_res():
    """ tests for reg_resample interface """
    # Create a reg_resample object
    nr_resample = RegResample()

    # Check if the command is properly defined
    assert nr_resample.cmd == get_custom_path('reg_resample')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_resample.run()

    # Resample res
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    trans_file = example_data('warpfield.nii')
    nr_resample.inputs.ref_file = ref_file
    nr_resample.inputs.flo_file = flo_file
    nr_resample.inputs.trans_file = trans_file
    nr_resample.inputs.inter_val = 'LIN'
    nr_resample.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -flo {flo} -inter 1 -omp 4 -ref {ref} -trans {trans} \
-res {res}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_resample'),
        flo=flo_file,
        ref=ref_file,
        trans=trans_file,
        res='im2_res.nii.gz')

    assert nr_resample.cmdline == expected_cmd

    # test_reg_resample_blank()
    nr_resample_2 = RegResample(type='blank', inter_val='LIN', omp_core_val=4)
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    trans_file = example_data('warpfield.nii')
    nr_resample_2.inputs.ref_file = ref_file
    nr_resample_2.inputs.flo_file = flo_file
    nr_resample_2.inputs.trans_file = trans_file

    cmd_tmp = '{cmd} -flo {flo} -inter 1 -omp 4 -ref {ref} -trans {trans} \
-blank {blank}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_resample'),
        flo=flo_file,
        ref=ref_file,
        trans=trans_file,
        blank='im2_blank.nii.gz')

    assert nr_resample_2.cmdline == expected_cmd
Пример #23
0
def test_seg_patchmatch():

    # Create a node object
    seg_patchmatch = PatchMatch()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_PatchMatch', env_dir='NIFTYSEGDIR')
    assert seg_patchmatch.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        seg_patchmatch.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    mask_file = example_data('im2.nii')
    db_file = example_data('db.xml')
    seg_patchmatch.inputs.in_file = in_file
    seg_patchmatch.inputs.mask_file = mask_file
    seg_patchmatch.inputs.database_file = db_file

    cmd_tmp = '{cmd} -i {in_file} -m {mask_file} -db {db} -o {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=cmd,
        in_file=in_file,
        mask_file=mask_file,
        db=db_file,
        out_file='im1_pm.nii.gz',
    )

    assert seg_patchmatch.cmdline == expected_cmd
Пример #24
0
def test_seg_calctopncc():
    """ Test interfaces for seg_CalctoNCC"""
    # Create a node object
    calctopncc = CalcTopNCC()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_CalcTopNCC', env_dir='NIFTYSEGDIR')
    assert calctopncc.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        calctopncc.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    file1 = example_data('im2.nii')
    file2 = example_data('im3.nii')
    calctopncc.inputs.in_file = in_file
    calctopncc.inputs.num_templates = 2
    calctopncc.inputs.in_templates = [file1, file2]
    calctopncc.inputs.top_templates = 1

    cmd_tmp = '{cmd} -target {in_file} -templates 2 {file1} {file2} -n 1'
    expected_cmd = cmd_tmp.format(
        cmd=cmd,
        in_file=in_file,
        file1=file1,
        file2=file2,
    )

    assert calctopncc.cmdline == expected_cmd
Пример #25
0
def test_seg_em():

    # Create a node object
    seg_em = EM()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_EM', env_dir='NIFTYSEGDIR')
    assert seg_em.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        seg_em.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    seg_em.inputs.in_file = in_file
    seg_em.inputs.no_prior = 4

    cmd_tmp = '{cmd} -in {in_file} -nopriors 4 -bc_out {bc_out} -out \
{out_file} -out_outlier {out_outlier}'
    expected_cmd = cmd_tmp.format(
        cmd=cmd,
        in_file=in_file,
        out_file='im1_em.nii.gz',
        bc_out='im1_bc_em.nii.gz',
        out_outlier='im1_outlier_em.nii.gz',
    )

    assert seg_em.cmdline == expected_cmd
Пример #26
0
def test_merge():

    # Create a node object
    merge = Merge()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_maths', env_dir='NIFTYSEGDIR')
    assert merge.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        merge.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    file1 = example_data('im2.nii')
    file2 = example_data('im3.nii')
    merge.inputs.in_file = in_file
    merge.inputs.merge_files = [file1, file2]
    merge.inputs.dimension = 2
    merge.inputs.output_datatype = 'float'

    cmd_tmp = '{cmd} {in_file} -merge 2 2 {f1} {f2} -odt float {out_file}'
    expected_cmd = cmd_tmp.format(cmd=cmd,
                                  in_file=in_file,
                                  f1=file1,
                                  f2=file2,
                                  out_file='im1_merged.nii')

    assert merge.cmdline == expected_cmd
Пример #27
0
def test_binary_maths():

    # Create a node object
    binarym = BinaryMaths()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_maths', env_dir='NIFTYSEGDIR')
    assert binarym.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        binarym.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    binarym.inputs.in_file = in_file
    binarym.inputs.operand_value = 2.0
    binarym.inputs.operation = 'sub'
    binarym.inputs.output_datatype = 'float'

    cmd_tmp = '{cmd} {in_file} -sub 2.00000000 -odt float {out_file}'
    expected_cmd = cmd_tmp.format(cmd=cmd,
                                  in_file=in_file,
                                  out_file='im1_sub.nii')

    assert binarym.cmdline == expected_cmd
Пример #28
0
def test_seg_filllesions():

    # Create a node object
    seg_fill = FillLesions()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_FillLesions', env_dir='NIFTYSEGDIR')
    assert seg_fill.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        seg_fill.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    lesion_mask = example_data('im2.nii')
    seg_fill.inputs.in_file = in_file
    seg_fill.inputs.lesion_mask = lesion_mask

    expected_cmd = '{cmd} -i {in_file} -l {lesion_mask} -o {out_file}'.format(
        cmd=cmd,
        in_file=in_file,
        lesion_mask=lesion_mask,
        out_file='im1_lesions_filled.nii.gz',
    )

    assert seg_fill.cmdline == expected_cmd
Пример #29
0
def test_reg_transform_def():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_transform')

    # Assign some input data
    trans_file = example_data('warpfield.nii')
    nr.inputs.def_input = trans_file
    nr.inputs.omp_core_val = 4

    expected_cmd = get_custom_path('reg_transform') + ' -omp 4 ' +\
                   '-def ' + trans_file + ' ' + os.getcwd() + os.sep + 'warpfield_trans.nii.gz'
    yield assert_equal, nr.cmdline, expected_cmd
Пример #30
0
def test_seg_em():

    # Create a node object
    seg_em = EM()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_EM', env_dir='NIFTYSEGDIR')
    assert seg_em.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        seg_em.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    seg_em.inputs.in_file = in_file
    seg_em.inputs.no_prior = 4

    cmd_tmp = '{cmd} -in {in_file} -nopriors 4 -bc_out {bc_out} -out \
{out_file} -out_outlier {out_outlier}'

    expected_cmd = cmd_tmp.format(
        cmd=cmd,
        in_file=in_file,
        out_file='im1_em.nii.gz',
        bc_out='im1_bc_em.nii.gz',
        out_outlier='im1_outlier_em.nii.gz',
    )

    assert seg_em.cmdline == expected_cmd
Пример #31
0
def test_tuple_maths():

    # Create a node object
    tuplem = TupleMaths()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_maths', env_dir='NIFTYSEGDIR')
    assert tuplem.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        tuplem.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    op_file = example_data('im2.nii')
    tuplem.inputs.in_file = in_file
    tuplem.inputs.operation = 'lncc'
    tuplem.inputs.operand_file1 = op_file
    tuplem.inputs.operand_value2 = 2.0
    tuplem.inputs.output_datatype = 'float'

    cmd_tmp = '{cmd} {in_file} -lncc {op} 2.00000000 -odt float {out_file}'
    expected_cmd = cmd_tmp.format(cmd=cmd,
                                  in_file=in_file,
                                  op=op_file,
                                  out_file='im1_lncc.nii')

    assert tuplem.cmdline == expected_cmd
Пример #32
0
def test_reg_tools_iso():

    # Create a reg_tools object
    nr = RegTools()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_tools')

    # Assign some input data
    in_file = example_data('im1.nii')
    nr.inputs.in_file = in_file
    nr.inputs.iso_flag = True
    nr.inputs.omp_core_val = 4

    expected_cmd = get_custom_path('reg_tools') + ' ' + '-in ' + in_file + ' -iso ' +\
                   '-omp 4 ' + '-out ' + os.getcwd() + os.sep + 'im1_tools.nii.gz'
    yield assert_equal, nr.cmdline, expected_cmd
Пример #33
0
def test_reg_average_demean3():

    # Create a reg_average object
    nr = RegAverage()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_average')

    # Assign some input data
    ref_file = example_data('anatomical.nii')
    one_file = example_data('im1.nii')
    two_file = example_data('im2.nii')
    three_file = example_data('im3.nii')
    aff1_file = example_data('TransformParameters.0.txt')
    aff2_file = example_data('ants_Affine.txt')
    aff3_file = example_data('elastix.txt')
    trans1_file = example_data('roi01.nii')
    trans2_file = example_data('roi02.nii')
    trans3_file = example_data('roi03.nii')
    nr.inputs.warp_files = [aff1_file, trans1_file, one_file,
                            aff2_file, trans2_file, two_file,
                            aff3_file, trans3_file, three_file]
    nr.inputs.demean3_ref_file = ref_file
    nr.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f:
        argv = f.read()
    os.remove(reg_average_cmd)

    expected_argv = ('%s %s -demean3 %s %s %s %s %s %s %s %s %s %s'
                     % (get_custom_path('reg_average'),
                        os.path.join(os.getcwd(), 'avg_out.nii.gz'),
                        ref_file,
                        aff1_file, trans1_file, one_file,
                        aff2_file, trans2_file, two_file,
                        aff3_file, trans3_file, three_file))

    yield assert_equal, argv, expected_argv

    expected_cmd = ('%s --cmd_file %s'
                    % (get_custom_path('reg_average'), reg_average_cmd))

    yield assert_equal, nr.cmdline, expected_cmd
Пример #34
0
def test_reg_transform_comp_txt():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_transform')

    # Assign some input data
    aff1_file = example_data('ants_Affine.txt')
    aff2_file = example_data('elastix.txt')
    nr.inputs.comp_input2 = aff2_file
    nr.inputs.comp_input = aff1_file
    nr.inputs.omp_core_val = 4

    expected_cmd = get_custom_path('reg_transform') + ' -omp 4 ' +\
                   '-comp ' + aff1_file + ' ' + aff2_file + ' ' + os.getcwd() + os.sep + 'ants_Affine_trans.txt'
    yield assert_equal, nr.cmdline, expected_cmd
Пример #35
0
def test_reg_jacobian_jac():

    # Create a reg_jacobian object
    nr = RegJacobian()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_jacobian')

    # Assign some input data
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.trans_file = trans_file
    nr.inputs.omp_core_val = 4

    expected_cmd = get_custom_path('reg_jacobian') + ' -omp 4 ' + '-ref ' + ref_file + ' ' +\
                   '-trans ' + trans_file + ' -jac ' + os.getcwd() + os.sep + 'warpfield_jac.nii.gz'
    yield assert_equal, nr.cmdline, expected_cmd
Пример #36
0
def test_reg_average_demean3():

    # Create a reg_average object
    nr = RegAverage()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_average')

    # Assign some input data
    ref_file = example_data('anatomical.nii')
    one_file = example_data('im1.nii')
    two_file = example_data('im2.nii')
    three_file = example_data('im3.nii')
    aff1_file = example_data('TransformParameters.0.txt')
    aff2_file = example_data('ants_Affine.txt')
    aff3_file = example_data('elastix.txt')
    trans1_file = example_data('roi01.nii')
    trans2_file = example_data('roi02.nii')
    trans3_file = example_data('roi03.nii')
    nr.inputs.warp_files = [
        aff1_file, trans1_file, one_file, aff2_file, trans2_file, two_file,
        aff3_file, trans3_file, three_file
    ]
    nr.inputs.demean3_ref_file = ref_file
    nr.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f:
        argv = f.read()
    os.remove(reg_average_cmd)

    expected_argv = ('%s %s -demean3 %s %s %s %s %s %s %s %s %s %s' %
                     (get_custom_path('reg_average'),
                      os.path.join(os.getcwd(), 'avg_out.nii.gz'), ref_file,
                      aff1_file, trans1_file, one_file, aff2_file, trans2_file,
                      two_file, aff3_file, trans3_file, three_file))

    assert argv == expected_argv

    expected_cmd = ('%s --cmd_file %s' %
                    (get_custom_path('reg_average'), reg_average_cmd))

    assert nr.cmdline == expected_cmd
Пример #37
0
def test_reg_measure():

    # Create a reg_measure object
    nr = RegMeasure()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_measure')

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.flo_file = flo_file
    nr.inputs.measure_type = 'lncc'
    nr.inputs.omp_core_val = 4

    expected_cmd = get_custom_path('reg_measure') + ' ' + '-flo ' + flo_file + ' ' + '-lncc ' + '-omp 4 '+\
                   '-out ' + os.getcwd() + os.sep + 'im2_lncc.txt ' + '-ref ' + ref_file
    yield assert_equal, nr.cmdline, expected_cmd
Пример #38
0
def test_reg_transform_flirt():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_transform')

    # Assign some input data
    aff_file = example_data('elastix.txt')
    ref_file = example_data('im1.nii')
    in_file = example_data('im2.nii')
    nr.inputs.flirt_2_nr_input = (aff_file, ref_file, in_file)
    nr.inputs.omp_core_val = 4

    expected_cmd = get_custom_path('reg_transform') + ' -omp 4 ' +\
                   '-flirtAff2NR ' + '%s %s %s' % (aff_file, ref_file, in_file) + ' ' +\
                   os.getcwd() + os.sep + 'elastix_trans.txt'
    yield assert_equal, nr.cmdline, expected_cmd
Пример #39
0
def test_reg_transform_def():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_transform')

    # Assign some input data
    trans_file = example_data('warpfield.nii')
    nr.inputs.def_input = trans_file
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -def {trans_file} {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_transform'),
        trans_file=trans_file,
        out_file=os.path.join(os.getcwd(), 'warpfield_trans.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #40
0
def test_reg_transform_def():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_transform')

    # Assign some input data
    trans_file = example_data('warpfield.nii')
    nr.inputs.def_input = trans_file
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -def {trans_file} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  trans_file=trans_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'warpfield_trans.nii.gz'))

    assert nr.cmdline == expected_cmd
Пример #41
0
def test_fit_asl():
    """ Testing FitAsl interface."""
    # Create the test node
    fit_asl = FitAsl()

    # Check if the command is properly defined
    cmd = get_custom_path('fit_asl', env_dir='NIFTYFIT_DIR')
    assert fit_asl.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        fit_asl.run()

    # Tests on the interface:
    # Runs cbf fitting assuming all tissue is GM!
    in_file = example_data('asl.nii.gz')
    fit_asl.inputs.source_file = in_file

    cmd_tmp = '{cmd} -source {in_file} -cbf {cbf} -error {error} -syn {syn}'
    expected_cmd = cmd_tmp.format(
        cmd=cmd,
        in_file=in_file,
        cbf='asl_cbf.nii.gz',
        error='asl_error.nii.gz',
        syn='asl_syn.nii.gz',
    )

    assert fit_asl.cmdline == expected_cmd

    # Runs cbf fitting using IR/SR T1 data to estimate the local T1 and uses
    # the segmentation data to fit tissue specific blood flow parameters
    # (lambda,transit times,T1)
    fit_asl2 = FitAsl(sig=True)
    in_file = example_data('asl.nii.gz')
    t1map = example_data('T1map.nii.gz')
    seg = example_data('segmentation0.nii.gz')
    fit_asl2.inputs.source_file = in_file
    fit_asl2.inputs.t1map = t1map
    fit_asl2.inputs.seg = seg

    cmd_tmp = '{cmd} -source {in_file} -cbf {cbf} -error {error} \
-seg {seg} -sig -syn {syn} -t1map {t1map}'
    expected_cmd = cmd_tmp.format(
        cmd=cmd,
        in_file=in_file,
        t1map=t1map,
        seg=seg,
        cbf='asl_cbf.nii.gz',
        error='asl_error.nii.gz',
        syn='asl_syn.nii.gz',
    )

    assert fit_asl2.cmdline == expected_cmd
Пример #42
0
def test_reg_average_avg_ref():

    # Create a reg_average object
    nr = RegAverage()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_average')

    # Assign some input data
    ref_file = example_data('anatomical.nii')
    one_file = example_data('im1.nii')
    two_file = example_data('im2.nii')
    three_file = example_data('im3.nii')
    trans1_file = example_data('roi01.nii')
    trans2_file = example_data('roi02.nii')
    trans3_file = example_data('roi03.nii')
    nr.inputs.warp_files = [trans1_file, one_file,
                            trans2_file, two_file,
                            trans3_file, three_file]
    nr.inputs.avg_ref_file = ref_file
    nr.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f:
        argv = f.read()
    os.remove(reg_average_cmd)

    expected_argv = ('%s %s -avg_tran %s %s %s %s %s %s %s'
                     % (get_custom_path('reg_average'),
                        os.path.join(os.getcwd(), 'avg_out.nii.gz'),
                        ref_file, trans1_file, one_file, trans2_file, two_file,
                        trans3_file, three_file))

    assert argv == expected_argv

    expected_cmd = ('%s --cmd_file %s'
                    % (get_custom_path('reg_average'), reg_average_cmd))

    assert nr.cmdline == expected_cmd
Пример #43
0
def test_reg_aladin():

    # Create a reg_aladin object
    nr = RegAladin()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path("reg_aladin")

    # Assign some input data
    ref_file = example_data("im1.nii")
    flo_file = example_data("im2.nii")
    rmask_file = example_data("mask.nii")
    nr.inputs.ref_file = ref_file
    nr.inputs.flo_file = flo_file
    nr.inputs.rmask_file = rmask_file
    nr.inputs.omp_core_val = 4

    expected_cmd = (
        get_custom_path("reg_aladin")
        + " "
        + "-aff "
        + os.getcwd()
        + os.sep
        + "im2_aff.txt "
        + "-flo "
        + flo_file
        + " "
        + "-omp 4 "
        + "-ref "
        + ref_file
        + " "
        + "-res "
        + os.getcwd()
        + os.sep
        + "im2_res.nii.gz "
        + "-rmask "
        + rmask_file
    )
    yield assert_equal, nr.cmdline, expected_cmd
Пример #44
0
def test_reg_resample_res():

    # Create a reg_resample object
    nr = RegResample()

    # Check if the command is properly defined
    yield assert_equal, nr.cmd, get_custom_path('reg_resample')

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    trans_file = example_data('warpfield.nii')
    nr.inputs.ref_file = ref_file
    nr.inputs.flo_file = flo_file
    nr.inputs.trans_file = trans_file
    nr.inputs.inter_val = 'LIN'
    nr.inputs.omp_core_val = 4

    expected_cmd = get_custom_path('reg_resample') + ' ' + '-flo ' + flo_file + ' ' + '-inter 1 -omp 4 ' +\
                   '-ref ' + ref_file + ' ' + '-trans ' + trans_file + ' ' +\
                   '-res ' + os.getcwd() + os.sep + 'im2_res.nii.gz'
    yield assert_equal, nr.cmdline, expected_cmd
Пример #45
0
def test_reg_tools_mul():
    """ tests for reg_tools interface """
    # Create a reg_tools object
    nr_tools = RegTools()

    # Check if the command is properly defined
    assert nr_tools.cmd == get_custom_path('reg_tools')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_tools.run()

    # Test reg_tools: mul
    in_file = example_data('im1.nii')
    nr_tools.inputs.in_file = in_file
    nr_tools.inputs.mul_val = 4
    nr_tools.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -in {in_file} -mul 4.0 -omp 4 -out {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_tools'),
                                  in_file=in_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'im1_tools.nii.gz'))

    assert nr_tools.cmdline == expected_cmd

    # Test reg_tools: iso
    nr_tools_2 = RegTools(iso_flag=True, omp_core_val=4)
    in_file = example_data('im1.nii')
    nr_tools_2.inputs.in_file = in_file

    cmd_tmp = '{cmd} -in {in_file} -iso -omp 4 -out {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_tools'),
                                  in_file=in_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'im1_tools.nii.gz'))

    assert nr_tools_2.cmdline == expected_cmd
Пример #46
0
def test_reg_tools_mul():
    """ tests for reg_tools interface """
    # Create a reg_tools object
    nr_tools = RegTools()

    # Check if the command is properly defined
    assert nr_tools.cmd == get_custom_path('reg_tools')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_tools.run()

    # Test reg_tools: mul
    in_file = example_data('im1.nii')
    nr_tools.inputs.in_file = in_file
    nr_tools.inputs.mul_val = 4
    nr_tools.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -in {in_file} -mul 4.0 -omp 4 -out {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_tools'),
        in_file=in_file,
        out_file='im1_tools.nii.gz')

    assert nr_tools.cmdline == expected_cmd

    # Test reg_tools: iso
    nr_tools_2 = RegTools(iso_flag=True, omp_core_val=4)
    in_file = example_data('im1.nii')
    nr_tools_2.inputs.in_file = in_file

    cmd_tmp = '{cmd} -in {in_file} -iso -omp 4 -out {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_tools'),
        in_file=in_file,
        out_file='im1_tools.nii.gz')

    assert nr_tools_2.cmdline == expected_cmd
Пример #47
0
def test_reg_transform_comp_txt():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_transform')

    # Assign some input data
    aff1_file = example_data('ants_Affine.txt')
    aff2_file = example_data('elastix.txt')
    nr.inputs.comp_input2 = aff2_file
    nr.inputs.comp_input = aff1_file
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -comp {aff1} {aff2} {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_transform'),
        aff1=aff1_file,
        aff2=aff2_file,
        out_file=os.path.join(os.getcwd(), 'ants_Affine_trans.txt'))

    assert nr.cmdline == expected_cmd
Пример #48
0
def test_reg_transform_comp_txt():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_transform')

    # Assign some input data
    aff1_file = example_data('ants_Affine.txt')
    aff2_file = example_data('elastix.txt')
    nr.inputs.comp_input2 = aff2_file
    nr.inputs.comp_input = aff1_file
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -comp {aff1} {aff2} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  aff1=aff1_file,
                                  aff2=aff2_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'ants_Affine_trans.txt'))

    assert nr.cmdline == expected_cmd
Пример #49
0
def test_reg_f3d():
    """ tests for reg_f3d interface"""
    # Create a reg_f3d object
    nr_f3d = RegF3D()

    # Check if the command is properly defined
    assert nr_f3d.cmd == get_custom_path('reg_f3d')

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        nr_f3d.run()

    # Assign some input data
    ref_file = example_data('im1.nii')
    flo_file = example_data('im2.nii')
    rmask_file = example_data('mask.nii')
    nr_f3d.inputs.ref_file = ref_file
    nr_f3d.inputs.flo_file = flo_file
    nr_f3d.inputs.rmask_file = rmask_file
    nr_f3d.inputs.omp_core_val = 4
    nr_f3d.inputs.vel_flag = True
    nr_f3d.inputs.be_val = 0.1
    nr_f3d.inputs.le_val = 0.1

    cmd_tmp = '{cmd} -be 0.100000 -cpp {cpp} -flo {flo} -le 0.100000 -omp 4 \
-ref {ref} -res {res} -rmask {rmask} -vel'

    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_f3d'),
        cpp='im2_cpp.nii.gz',
        flo=flo_file,
        ref=ref_file,
        res='im2_res.nii.gz',
        rmask=rmask_file,
    )

    assert nr_f3d.cmdline == expected_cmd
Пример #50
0
def test_reg_transform_flirt():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_transform')

    # Assign some input data
    aff_file = example_data('elastix.txt')
    ref_file = example_data('im1.nii')
    in_file = example_data('im2.nii')
    nr.inputs.flirt_2_nr_input = (aff_file, ref_file, in_file)
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -flirtAff2NR {aff} {ref} {in_file} {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('reg_transform'),
        aff=aff_file,
        ref=ref_file,
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'elastix_trans.txt'))

    assert nr.cmdline == expected_cmd
Пример #51
0
def test_reg_transform_flirt():

    # Create a reg_transform object
    nr = RegTransform()

    # Check if the command is properly defined
    assert nr.cmd == get_custom_path('reg_transform')

    # Assign some input data
    aff_file = example_data('elastix.txt')
    ref_file = example_data('im1.nii')
    in_file = example_data('im2.nii')
    nr.inputs.flirt_2_nr_input = (aff_file, ref_file, in_file)
    nr.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -flirtAff2NR {aff} {ref} {in_file} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  aff=aff_file,
                                  ref=ref_file,
                                  in_file=in_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'elastix_trans.txt'))

    assert nr.cmdline == expected_cmd
Пример #52
0
def test_dwi_tool():
    """ Testing DwiTool interface."""
    # Create a node object
    dwi_tool = DwiTool()

    # Check if the command is properly defined
    cmd = get_custom_path('dwi_tool', env_dir='NIFTYFITDIR')
    assert dwi_tool.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        dwi_tool.run()

    # Assign some input data
    in_file = example_data('dwi.nii.gz')
    bval_file = example_data('bvals')
    bvec_file = example_data('bvecs')
    b0_file = example_data('b0.nii')
    mask_file = example_data('mask.nii.gz')
    dwi_tool.inputs.source_file = in_file
    dwi_tool.inputs.mask_file = mask_file
    dwi_tool.inputs.bval_file = bval_file
    dwi_tool.inputs.bvec_file = bvec_file
    dwi_tool.inputs.b0_file = b0_file
    dwi_tool.inputs.dti_flag = True

    cmd_tmp = '{cmd} -source {in_file} -bval {bval} -bvec {bvec} -b0 {b0} \
-mask {mask} -dti -famap {fa} -logdti2 {log} -mcmap {mc} -mdmap {md} \
-rgbmap {rgb} -syn {syn} -v1map {v1}'

    expected_cmd = cmd_tmp.format(cmd=cmd,
                                  in_file=in_file,
                                  bval=bval_file,
                                  bvec=bvec_file,
                                  b0=b0_file,
                                  mask=mask_file,
                                  fa='dwi_famap.nii.gz',
                                  log='dwi_logdti2.nii.gz',
                                  mc='dwi_mcmap.nii.gz',
                                  md='dwi_mdmap.nii.gz',
                                  rgb='dwi_rgbmap.nii.gz',
                                  syn='dwi_syn.nii.gz',
                                  v1='dwi_v1map.nii.gz')

    assert dwi_tool.cmdline == expected_cmd
Пример #53
0
def test_fit_dwi():
    """ Testing FitDwi interface."""
    # Create a node object
    fit_dwi = FitDwi()

    # Check if the command is properly defined
    cmd = get_custom_path('fit_dwi', env_dir='NIFTYFITDIR')
    assert fit_dwi.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        fit_dwi.run()

    # Assign some input data
    in_file = example_data('dwi.nii.gz')
    bval_file = example_data('bvals')
    bvec_file = example_data('bvecs')
    fit_dwi.inputs.source_file = in_file
    fit_dwi.inputs.bval_file = bval_file
    fit_dwi.inputs.bvec_file = bvec_file
    fit_dwi.inputs.dti_flag = True

    cmd_tmp = '{cmd} -source {in_file} -bval {bval} -bvec {bvec} -dti \
-error {error} -famap {fa} -mcmap {mc} -mcout {mcout} -mdmap {md} -nodiff \
{nodiff} -res {res} -rgbmap {rgb} -syn {syn} -tenmap2 {ten2}  -v1map {v1}'

    expected_cmd = cmd_tmp.format(cmd=cmd,
                                  in_file=in_file,
                                  bval=bval_file,
                                  bvec=bvec_file,
                                  error='dwi_error.nii.gz',
                                  fa='dwi_famap.nii.gz',
                                  mc='dwi_mcmap.nii.gz',
                                  md='dwi_mdmap.nii.gz',
                                  nodiff='dwi_no_diff.nii.gz',
                                  res='dwi_resmap.nii.gz',
                                  rgb='dwi_rgbmap.nii.gz',
                                  syn='dwi_syn.nii.gz',
                                  ten2='dwi_tenmap2.nii.gz',
                                  v1='dwi_v1map.nii.gz',
                                  mcout='dwi_mcout.txt')

    assert fit_dwi.cmdline == expected_cmd
Пример #54
0
def test_unary_stats():
    """ Test for the seg_stats interfaces """
    # Create a node object
    unarys = UnaryStats()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_stats', env_dir='NIFTYSEGDIR')
    assert unarys.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        unarys.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    unarys.inputs.in_file = in_file
    unarys.inputs.operation = 'a'

    expected_cmd = '{cmd} {in_file} -a'.format(cmd=cmd, in_file=in_file)

    assert unarys.cmdline == expected_cmd
Пример #55
0
def test_unary_maths():

    # Create a node object
    unarym = UnaryMaths()

    # Check if the command is properly defined
    cmd = get_custom_path('seg_maths', env_dir='NIFTYSEGDIR')
    assert unarym.cmd == cmd

    # test raising error with mandatory args absent
    with pytest.raises(ValueError):
        unarym.run()

    # Assign some input data
    in_file = example_data('im1.nii')
    unarym.inputs.in_file = in_file
    unarym.inputs.operation = 'otsu'
    unarym.inputs.output_datatype = 'float'

    expected_cmd = '{cmd} {in_file} -otsu -odt float {out_file}'.format(
        cmd=cmd, in_file=in_file, out_file='im1_otsu.nii')

    assert unarym.cmdline == expected_cmd
Пример #56
0
def test_reg_transform_def():
    """ tests for reg_transform interface """
    # Create a reg_transform object
    nr_transform = RegTransform()

    # Check if the command is properly defined
    assert nr_transform.cmd == get_custom_path('reg_transform')

    # Assign some input data
    trans_file = example_data('warpfield.nii')
    nr_transform.inputs.def_input = trans_file
    nr_transform.inputs.omp_core_val = 4

    cmd_tmp = '{cmd} -omp 4 -def {trans_file} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  trans_file=trans_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'warpfield_trans.nii.gz'))

    assert nr_transform.cmdline == expected_cmd

    # Test reg_transform: def ref
    nr_transform_2 = RegTransform(omp_core_val=4)
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    nr_transform_2.inputs.ref1_file = ref_file
    nr_transform_2.inputs.def_input = trans_file

    cmd_tmp = '{cmd} -ref {ref_file} -omp 4 -def {trans_file} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  ref_file=ref_file,
                                  trans_file=trans_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'warpfield_trans.nii.gz'))

    assert nr_transform_2.cmdline == expected_cmd

    # Test reg_transform: comp nii
    nr_transform_3 = RegTransform(omp_core_val=4)
    ref_file = example_data('im1.nii')
    trans_file = example_data('warpfield.nii')
    trans2_file = example_data('anatomical.nii')
    nr_transform_3.inputs.ref1_file = ref_file
    nr_transform_3.inputs.comp_input2 = trans2_file
    nr_transform_3.inputs.comp_input = trans_file

    cmd_tmp = '{cmd} -ref {ref_file} -omp 4 -comp {trans1} {trans2} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  ref_file=ref_file,
                                  trans1=trans_file,
                                  trans2=trans2_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'warpfield_trans.nii.gz'))

    assert nr_transform_3.cmdline == expected_cmd

    # Test reg_transform: comp txt
    nr_transform_4 = RegTransform(omp_core_val=4)
    aff1_file = example_data('ants_Affine.txt')
    aff2_file = example_data('elastix.txt')
    nr_transform_4.inputs.comp_input2 = aff2_file
    nr_transform_4.inputs.comp_input = aff1_file

    cmd_tmp = '{cmd} -omp 4 -comp {aff1} {aff2} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  aff1=aff1_file,
                                  aff2=aff2_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'ants_Affine_trans.txt'))

    assert nr_transform_4.cmdline == expected_cmd

    # Test reg_transform: comp
    nr_transform_5 = RegTransform(omp_core_val=4)
    trans_file = example_data('warpfield.nii')
    aff_file = example_data('elastix.txt')
    nr_transform_5.inputs.comp_input2 = trans_file
    nr_transform_5.inputs.comp_input = aff_file

    cmd_tmp = '{cmd} -omp 4 -comp {aff} {trans} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  aff=aff_file,
                                  trans=trans_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'elastix_trans.nii.gz'))

    assert nr_transform_5.cmdline == expected_cmd

    # Test reg_transform: flirt
    nr_transform_6 = RegTransform(omp_core_val=4)
    aff_file = example_data('elastix.txt')
    ref_file = example_data('im1.nii')
    in_file = example_data('im2.nii')
    nr_transform_6.inputs.flirt_2_nr_input = (aff_file, ref_file, in_file)

    cmd_tmp = '{cmd} -omp 4 -flirtAff2NR {aff} {ref} {in_file} {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('reg_transform'),
                                  aff=aff_file,
                                  ref=ref_file,
                                  in_file=in_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'elastix_trans.txt'))

    assert nr_transform_6.cmdline == expected_cmd
Пример #57
0
def test_reg_average():
    """ tests for reg_average interface """
    # Create a reg_average object
    nr_average = RegAverage()

    # Check if the command is properly defined
    assert nr_average.cmd == get_custom_path('reg_average')

    # Average niis
    one_file = example_data('im1.nii')
    two_file = example_data('im2.nii')
    three_file = example_data('im3.nii')
    nr_average.inputs.avg_files = [one_file, two_file, three_file]
    generated_cmd = nr_average.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f_obj:
        argv = f_obj.read()
    os.remove(reg_average_cmd)

    expected_argv = '%s %s -avg %s %s %s' % (get_custom_path(
        'reg_average'), os.path.join(
            os.getcwd(), 'avg_out.nii.gz'), one_file, two_file, three_file)

    assert argv.decode('utf-8') == expected_argv

    # Test command line with text file
    expected_cmd = ('%s --cmd_file %s' %
                    (get_custom_path('reg_average'), reg_average_cmd))

    assert generated_cmd == expected_cmd

    # Test Reg Average: average txt
    nr_average_2 = RegAverage()
    one_file = example_data('TransformParameters.0.txt')
    two_file = example_data('ants_Affine.txt')
    three_file = example_data('elastix.txt')
    nr_average_2.inputs.avg_files = [one_file, two_file, three_file]
    generated_cmd = nr_average_2.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f_obj:
        argv = f_obj.read()
    os.remove(reg_average_cmd)

    expected_argv = '%s %s -avg %s %s %s' % (
        get_custom_path('reg_average'), os.path.join(
            os.getcwd(), 'avg_out.txt'), one_file, two_file, three_file)

    assert argv.decode('utf-8') == expected_argv

    # Test Reg Average: average list
    nr_average_3 = RegAverage()
    one_file = example_data('TransformParameters.0.txt')
    two_file = example_data('ants_Affine.txt')
    three_file = example_data('elastix.txt')
    nr_average_3.inputs.avg_lts_files = [one_file, two_file, three_file]
    generated_cmd = nr_average_3.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f_obj:
        argv = f_obj.read()
    os.remove(reg_average_cmd)

    expected_argv = ('%s %s -avg_lts %s %s %s' %
                     (get_custom_path('reg_average'),
                      os.path.join(os.getcwd(), 'avg_out.txt'), one_file,
                      two_file, three_file))

    assert argv.decode('utf-8') == expected_argv

    # Test Reg Average: average ref
    nr_average_4 = RegAverage()
    ref_file = example_data('anatomical.nii')
    one_file = example_data('im1.nii')
    two_file = example_data('im2.nii')
    three_file = example_data('im3.nii')
    trans1_file = example_data('roi01.nii')
    trans2_file = example_data('roi02.nii')
    trans3_file = example_data('roi03.nii')
    nr_average_4.inputs.warp_files = [
        trans1_file, one_file, trans2_file, two_file, trans3_file, three_file
    ]
    nr_average_4.inputs.avg_ref_file = ref_file
    generated_cmd = nr_average_4.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f_obj:
        argv = f_obj.read()
    os.remove(reg_average_cmd)

    expected_argv = (
        '%s %s -avg_tran %s %s %s %s %s %s %s' %
        (get_custom_path('reg_average'),
         os.path.join(os.getcwd(), 'avg_out.nii.gz'), ref_file, trans1_file,
         one_file, trans2_file, two_file, trans3_file, three_file))

    assert argv.decode('utf-8') == expected_argv

    # Test Reg Average: demean3
    nr_average_5 = RegAverage()
    ref_file = example_data('anatomical.nii')
    one_file = example_data('im1.nii')
    two_file = example_data('im2.nii')
    three_file = example_data('im3.nii')
    aff1_file = example_data('TransformParameters.0.txt')
    aff2_file = example_data('ants_Affine.txt')
    aff3_file = example_data('elastix.txt')
    trans1_file = example_data('roi01.nii')
    trans2_file = example_data('roi02.nii')
    trans3_file = example_data('roi03.nii')
    nr_average_5.inputs.warp_files = [
        aff1_file, trans1_file, one_file, aff2_file, trans2_file, two_file,
        aff3_file, trans3_file, three_file
    ]
    nr_average_5.inputs.demean3_ref_file = ref_file
    generated_cmd = nr_average_5.cmdline

    # Read the reg_average_cmd
    reg_average_cmd = os.path.join(os.getcwd(), 'reg_average_cmd')
    with open(reg_average_cmd, 'rb') as f_obj:
        argv = f_obj.read()
    os.remove(reg_average_cmd)

    expected_argv = ('%s %s -demean3 %s %s %s %s %s %s %s %s %s %s' %
                     (get_custom_path('reg_average'),
                      os.path.join(os.getcwd(), 'avg_out.nii.gz'), ref_file,
                      aff1_file, trans1_file, one_file, aff2_file, trans2_file,
                      two_file, aff3_file, trans3_file, three_file))

    assert argv.decode('utf-8') == expected_argv