Esempio n. 1
0
def test_seg_patchmatch():

    # Create a node object
    seg_patchmatch = PatchMatch()

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

    # 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=get_custom_path('seg_PatchMatch'),
                                  in_file=in_file,
                                  mask_file=mask_file,
                                  db=db_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'im1_pm.nii'))

    assert seg_patchmatch.cmdline == expected_cmd
Esempio n. 2
0
def test_seg_calctopncc():
    """ Test interfaces for seg_CalctoNCC"""
    # Create a node object
    calctopncc = CalcTopNCC()

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

    # 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=get_custom_path('seg_CalcTopNCC'),
        in_file=in_file,
        file1=file1,
        file2=file2
    )

    assert calctopncc.cmdline == expected_cmd
Esempio n. 3
0
def test_int_binary_maths():

    # Create a node object
    ibinarym = BinaryMathsInteger()

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

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

    # Assign some input data
    in_file = example_data('im1.nii')
    ibinarym.inputs.in_file = in_file
    ibinarym.inputs.operand_value = 2
    ibinarym.inputs.operation = 'dil'
    ibinarym.inputs.output_datatype = 'float'

    expected_cmd = '{cmd} {in_file} -dil 2 -odt float {out_file}'.format(
        cmd=get_custom_path('seg_maths'),
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'im1_dil.nii'))

    assert ibinarym.cmdline == expected_cmd
Esempio n. 4
0
def test_seg_em():

    # Create a node object
    seg_em = EM()

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

    # 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=get_custom_path('seg_EM'),
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'im1_em.nii'),
        bc_out=os.path.join(os.getcwd(), 'im1_bc_em.nii'),
        out_outlier=os.path.join(os.getcwd(), 'im1_outlier_em.nii'))

    assert seg_em.cmdline == expected_cmd
Esempio n. 5
0
def test_steps():

    # Create a node object
    steps = LabelFusion()

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

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

    # Assign some input data
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    steps.inputs.in_file = in_file
    steps.inputs.kernel_size = 2.0
    steps.inputs.file_to_seg = file_to_seg
    steps.inputs.template_file = template_file
    steps.inputs.template_num = 2
    steps.inputs.classifier_type = 'STEPS'

    cmd_tmp = '{cmd} -in {in_file} -STEPS 2.000000 2 {file_to_seg} \
{template_file} -out {out_file}'

    expected_cmd = cmd_tmp.format(cmd=get_custom_path('seg_LabFusion'),
                                  in_file=in_file,
                                  file_to_seg=file_to_seg,
                                  template_file=template_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'im1_steps.nii'))

    assert steps.cmdline == expected_cmd
Esempio n. 6
0
def test_binary_maths():

    # Create a node object
    binarym = BinaryMaths()

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

    # 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=get_custom_path('seg_maths'),
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'im1_sub.nii'))

    assert binarym.cmdline == expected_cmd
Esempio n. 7
0
def test_seg_em():

    # Create a node object
    seg_em = EM()

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

    # 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=get_custom_path('seg_EM'),
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'im1_em.nii'),
        bc_out=os.path.join(os.getcwd(), 'im1_bc_em.nii'),
        out_outlier=os.path.join(os.getcwd(), 'im1_outlier_em.nii')
    )

    assert seg_em.cmdline == expected_cmd
Esempio n. 8
0
def test_mv():

    # Create a node object
    mv = LabelFusion()

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

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

    # Assign some input data
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    mv.inputs.in_file = in_file
    mv.inputs.file_to_seg = file_to_seg
    mv.inputs.template_file = template_file
    mv.inputs.template_num = 2
    mv.inputs.classifier_type = 'MV'
    mv.inputs.sm_ranking = 'ROINCC'
    mv.inputs.dilation_roi = 2

    cmd_tmp = '{cmd} -in {in_file} -MV -ROINCC 2 2 {file_to_seg} \
{template_file} -out {out_file}'
    expected_cmd = cmd_tmp.format(
                        cmd=get_custom_path('seg_LabFusion'),
                        in_file=in_file,
                        file_to_seg=file_to_seg,
                        template_file=template_file,
                        out_file=os.path.join(os.getcwd(), 'im1_mv.nii'))

    assert mv.cmdline == expected_cmd
Esempio n. 9
0
def test_seg_filllesions():

    # Create a node object
    seg_fill = FillLesions()

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

    # 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=get_custom_path('seg_FillLesions'),
                in_file=in_file,
                lesion_mask=lesion_mask,
                out_file=os.path.join(os.getcwd(), 'im1_lesions_filled.nii'))

    assert seg_fill.cmdline == expected_cmd
Esempio n. 10
0
def test_merge():

    # Create a node object
    merge = Merge()

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

    # 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=get_custom_path('seg_maths'),
        in_file=in_file,
        f1=file1,
        f2=file2,
        out_file=os.path.join(os.getcwd(), 'im1_merged.nii'))

    assert merge.cmdline == expected_cmd
Esempio n. 11
0
def test_staple():

    # Create a node object
    staple = LabelFusion()

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

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

    # Assign some input data
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    staple.inputs.in_file = in_file
    staple.inputs.kernel_size = 2.0
    staple.inputs.file_to_seg = file_to_seg
    staple.inputs.template_file = template_file
    staple.inputs.template_num = 2
    staple.inputs.classifier_type = 'STAPLE'

    cmd_tmp = '{cmd} -in {in_file} -STAPLE -ALL -out {out_file}'
    expected_cmd = cmd_tmp.format(
                        cmd=get_custom_path('seg_LabFusion'),
                        in_file=in_file,
                        file_to_seg=file_to_seg,
                        template_file=template_file,
                        out_file=os.path.join(os.getcwd(), 'im1_staple.nii'))

    assert staple.cmdline == expected_cmd
Esempio n. 12
0
def test_seg_patchmatch():

    # Create a reg_aladin object
    steps = STEPS()

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

    # Assign some input data
    in_file = example_data('im1.nii')
    steps.inputs.in_file = in_file
    steps.inputs.kernel_size = 2
    steps.inputs.warped_seg_file = in_file
    steps.inputs.warped_img_file = in_file
    steps.inputs.template_num = 2

    cmd_tmp = '{cmd} -in {warped_img_file} -STEPS 2.000000 2 {in_file} \
{warped_seg_file} -out {out_file}'
    expected_cmd = cmd_tmp.format(
                        cmd=get_custom_path('seg_LabFusion'),
                        warped_img_file=in_file,
                        in_file=in_file,
                        warped_seg_file=in_file,
                        out_file=os.path.join(os.getcwd(), 'im1_steps.nii'))
    # out_file=os.path.join(os.getcwd(), 'im1_pm.nii'))

    yield assert_equal, steps.cmdline, expected_cmd
Esempio n. 13
0
def test_tuple_maths():

    # Create a node object
    tuplem = TupleMaths()

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

    # 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=get_custom_path('seg_maths'),
        in_file=in_file,
        op=op_file,
        out_file=os.path.join(os.getcwd(), 'im1_lncc.nii'))

    assert tuplem.cmdline == expected_cmd
Esempio n. 14
0
def test_seg_patchmatch():

    # Create a node object
    seg_patchmatch = PatchMatch()

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

    # 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=get_custom_path('seg_PatchMatch'),
                        in_file=in_file,
                        mask_file=mask_file,
                        db=db_file,
                        out_file=os.path.join(os.getcwd(), 'im1_pm.nii'))

    assert seg_patchmatch.cmdline == expected_cmd
Esempio n. 15
0
def test_seg_filllesions():

    # Create a reg_aladin object
    seg_fill = FillLesions()

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

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

    expected_cmd = "{cmd} -i {in_file} -l {lesion_mask} -o {out_file}".format(
        cmd=get_custom_path("seg_FillLesions"),
        in_file=in_file,
        lesion_mask=in_file,
        out_file=os.path.join(os.getcwd(), "im1_lesions_filled.nii"),
    )

    yield assert_equal, seg_fill.cmdline, expected_cmd
Esempio n. 16
0
def test_binary_stats():
    # Create a node object
    binarys = BinaryStats()

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

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

    # Assign some input data
    in_file = example_data('im1.nii')
    binarys.inputs.in_file = in_file
    binarys.inputs.operand_value = 2
    binarys.inputs.operation = 'sa'

    expected_cmd = '{cmd} {in_file} -sa 2.00000000'.format(
        cmd=get_custom_path('seg_stats'), in_file=in_file)

    assert binarys.cmdline == expected_cmd
Esempio n. 17
0
def test_binary_stats():
    # Create a node object
    binarys = BinaryStats()

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

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

    # Assign some input data
    in_file = example_data('im1.nii')
    binarys.inputs.in_file = in_file
    binarys.inputs.operand_value = 2
    binarys.inputs.operation = 'sa'

    expected_cmd = '{cmd} {in_file} -sa 2.00000000'.format(
        cmd=get_custom_path('seg_stats'),
        in_file=in_file)

    assert binarys.cmdline == expected_cmd
Esempio n. 18
0
def test_unary_stats():
    """ Test for the seg_stats interfaces """
    # Create a node object
    unarys = UnaryStats()

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

    # 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=get_custom_path('seg_stats'),
        in_file=in_file)

    assert unarys.cmdline == expected_cmd
Esempio n. 19
0
def test_seg_maths():

    # Create a reg_aladin object
    unarym = UnaryMaths()

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

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

    expected_cmd = '{cmd} {in_file} -otsu {out_file}'.format(
                        cmd=get_custom_path('seg_maths'),
                        in_file=in_file,
                        out_file=os.path.join(os.getcwd(), 'im1_otsu.nii'))

    yield assert_equal, unarym.cmdline, expected_cmd

    # Create a reg_aladin object
    binarym = BinaryMaths()

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

    # 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'

    expected_cmd = '{cmd} {in_file} -sub 2.00000000 {out_file}'.format(
                        cmd=get_custom_path('seg_maths'),
                        in_file=in_file,
                        out_file=os.path.join(os.getcwd(), 'im1_maths.nii'))

    yield assert_equal, binarym.cmdline, expected_cmd
Esempio n. 20
0
def test_seg_patchmatch():

    # Create a reg_aladin object
    seg_patchmatch = PatchMatch()

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

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

    cmd_tmp = '{cmd} -i {in_file} -m {mask_file} -db {db} -o {out_file}'
    expected_cmd = cmd_tmp.format(
                        cmd=get_custom_path('seg_PatchMatch'),
                        in_file=in_file,
                        mask_file=in_file,
                        db=in_file,
                        out_file=os.path.join(os.getcwd(), 'im1_pm.nii'))

    yield assert_equal, seg_patchmatch.cmdline, expected_cmd
Esempio n. 21
0
def test_seg_em():

    # Create a reg_aladin object
    seg_em = EM()

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

    # 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=get_custom_path('seg_EM'),
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'im1_em.nii'),
        bc_out=os.path.join(os.getcwd(), 'im1_bc_em.nii'),
        out_outlier=os.path.join(os.getcwd(), 'im1_outlier_em.nii'))

    yield assert_equal, seg_em.cmdline, expected_cmd
Esempio n. 22
0
def test_unary_maths():

    # Create a node object
    unarym = UnaryMaths()

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

    # 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=get_custom_path('seg_maths'),
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'im1_otsu.nii'))

    assert unarym.cmdline == expected_cmd
Esempio n. 23
0
def test_seg_patchmatch():

    # Create a reg_aladin object
    calctopncc = CalcTopNCC()

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

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

    cmd_tmp = '{cmd} -target {in_file} -templates 2 {file1} {file2} -n 1'
    expected_cmd = cmd_tmp.format(
                        cmd=get_custom_path('seg_CalcTopNCC'),
                        in_file=in_file,
                        file1=in_file,
                        file2=in_file)
    # out_file=os.path.join(os.getcwd(), 'im1_pm.nii'))

    yield assert_equal, calctopncc.cmdline, expected_cmd
Esempio n. 24
0
def test_unary_maths():

    # Create a node object
    unarym = UnaryMaths()

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

    # 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=get_custom_path('seg_maths'),
        in_file=in_file,
        out_file=os.path.join(os.getcwd(), 'im1_otsu.nii'))

    assert unarym.cmdline == expected_cmd
Esempio n. 25
0
def test_seg_stats():

    # Create a reg_aladin object
    unarys = UnaryStats()

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

    # 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=get_custom_path('seg_stats'),
                        in_file=in_file)

    yield assert_equal, unarys.cmdline, expected_cmd

    # Create a reg_aladin object
    binarys = BinaryStats()

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

    # Assign some input data
    in_file = example_data('im1.nii')
    binarys.inputs.in_file = in_file
    binarys.inputs.operand_value = 1
    binarys.inputs.operation = 'sa'

    expected_cmd = '{cmd} {in_file} -sa 1.00000000'.format(
                        cmd=get_custom_path('seg_stats'),
                        in_file=in_file)

    yield assert_equal, binarys.cmdline, expected_cmd
Esempio n. 26
0
def test_seg_lab_fusion():
    """ Test interfaces for seg_labfusion"""
    # Create a node object
    steps = LabelFusion()

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

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

    # Assign some input data
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    steps.inputs.in_file = in_file
    steps.inputs.kernel_size = 2.0
    steps.inputs.file_to_seg = file_to_seg
    steps.inputs.template_file = template_file
    steps.inputs.template_num = 2
    steps.inputs.classifier_type = 'STEPS'

    cmd_tmp = '{cmd} -in {in_file} -STEPS 2.000000 2 {file_to_seg} \
{template_file} -out {out_file}'

    expected_cmd = cmd_tmp.format(cmd=get_custom_path('seg_LabFusion'),
                                  in_file=in_file,
                                  file_to_seg=file_to_seg,
                                  template_file=template_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'im1_steps.nii'))

    assert steps.cmdline == expected_cmd

    # Staple
    staple = LabelFusion(kernel_size=2.0,
                         template_num=2,
                         classifier_type='STAPLE')
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    staple.inputs.in_file = in_file
    staple.inputs.file_to_seg = file_to_seg
    staple.inputs.template_file = template_file

    cmd_tmp = '{cmd} -in {in_file} -STAPLE -ALL -out {out_file}'
    expected_cmd = cmd_tmp.format(cmd=get_custom_path('seg_LabFusion'),
                                  in_file=in_file,
                                  file_to_seg=file_to_seg,
                                  template_file=template_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'im1_staple.nii'))

    assert staple.cmdline == expected_cmd

    # Assign some input data
    mv_node = LabelFusion(template_num=2,
                          classifier_type='MV',
                          sm_ranking='ROINCC',
                          dilation_roi=2)
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    mv_node.inputs.in_file = in_file
    mv_node.inputs.file_to_seg = file_to_seg
    mv_node.inputs.template_file = template_file

    cmd_tmp = '{cmd} -in {in_file} -MV -ROINCC 2 2 {file_to_seg} \
{template_file} -out {out_file}'

    expected_cmd = cmd_tmp.format(cmd=get_custom_path('seg_LabFusion'),
                                  in_file=in_file,
                                  file_to_seg=file_to_seg,
                                  template_file=template_file,
                                  out_file=os.path.join(
                                      os.getcwd(), 'im1_mv.nii'))

    assert mv_node.cmdline == expected_cmd
Esempio n. 27
0
def test_seg_lab_fusion():
    """ Test interfaces for seg_labfusion"""
    # Create a node object
    steps = LabelFusion()

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

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

    # Assign some input data
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    steps.inputs.in_file = in_file
    steps.inputs.kernel_size = 2.0
    steps.inputs.file_to_seg = file_to_seg
    steps.inputs.template_file = template_file
    steps.inputs.template_num = 2
    steps.inputs.classifier_type = 'STEPS'

    cmd_tmp = '{cmd} -in {in_file} -STEPS 2.000000 2 {file_to_seg} \
{template_file} -out {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('seg_LabFusion'),
        in_file=in_file,
        file_to_seg=file_to_seg,
        template_file=template_file,
        out_file=os.path.join(os.getcwd(), 'im1_steps.nii')
    )

    assert steps.cmdline == expected_cmd

    # Staple
    staple = LabelFusion(kernel_size=2.0, template_num=2,
                         classifier_type='STAPLE')
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    staple.inputs.in_file = in_file
    staple.inputs.file_to_seg = file_to_seg
    staple.inputs.template_file = template_file

    cmd_tmp = '{cmd} -in {in_file} -STAPLE -ALL -out {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('seg_LabFusion'),
        in_file=in_file,
        file_to_seg=file_to_seg,
        template_file=template_file,
        out_file=os.path.join(os.getcwd(), 'im1_staple.nii')
    )

    assert staple.cmdline == expected_cmd

    # Assign some input data
    mv_node = LabelFusion(template_num=2, classifier_type='MV',
                          sm_ranking='ROINCC', dilation_roi=2)
    in_file = example_data('im1.nii')
    file_to_seg = example_data('im2.nii')
    template_file = example_data('im3.nii')
    mv_node.inputs.in_file = in_file
    mv_node.inputs.file_to_seg = file_to_seg
    mv_node.inputs.template_file = template_file

    cmd_tmp = '{cmd} -in {in_file} -MV -ROINCC 2 2 {file_to_seg} \
{template_file} -out {out_file}'
    expected_cmd = cmd_tmp.format(
        cmd=get_custom_path('seg_LabFusion'),
        in_file=in_file,
        file_to_seg=file_to_seg,
        template_file=template_file,
        out_file=os.path.join(os.getcwd(), 'im1_mv.nii')
    )

    assert mv_node.cmdline == expected_cmd