コード例 #1
0
def test_check_for_custom_measure_stats_files_mgh_format():
    expected_subject2_testdata_dir = os.path.join(TEST_DATA_DIR, 'subject2')
    if not os.path.isdir(expected_subject2_testdata_dir):
        pytest.skip("Test data missing: e.g., directory '%s' does not exist. You can get all test data by running './develop/get_test_data_all.bash' in the repo root." % expected_subject2_testdata_dir)
    subjects_list = ['subject1', 'subject2']
    bdi = bd.BrainDescriptors(TEST_DATA_DIR, subjects_list, hemi='rh')
    bdi.check_for_custom_measure_stats_files(["aparc"], ["area"], morph_file_format="mgh")
コード例 #2
0
def test_braindescriptors_init_with_invalid_hemi():
    expected_subject2_testdata_dir = os.path.join(TEST_DATA_DIR, 'subject2')
    if not os.path.isdir(expected_subject2_testdata_dir):
        pytest.skip("Test data missing: e.g., directory '%s' does not exist. You can get all test data by running './develop/get_test_data_all.bash' in the repo root." % expected_subject2_testdata_dir)
    subjects_list = ['subject1', 'subject2']
    with pytest.raises(ValueError) as exc_info:
            bdi = bd.BrainDescriptors(TEST_DATA_DIR, subjects_list, hemi='nosuchhemi')
    assert "hemi must be one of {'lh', 'rh', 'both'} but is" in str(exc_info.value)
    assert "nosuchhemi" in str(exc_info.value)
コード例 #3
0
def test_check_for_NaNs_no_descriptors_yet():
    expected_subject2_testdata_dir = os.path.join(TEST_DATA_DIR, 'subject2')
    if not os.path.isdir(expected_subject2_testdata_dir):
        pytest.skip("Test data missing: e.g., directory '%s' does not exist. You can get all test data by running './develop/get_test_data_all.bash' in the repo root." % expected_subject2_testdata_dir)
    subjects_list = ['subject1', 'subject2']
    bdi = bd.BrainDescriptors(TEST_DATA_DIR, subjects_list, hemi='lh')
    subjects_over_threshold, descriptors_over_threshold, nan_share_per_subject, nan_share_per_descriptor = bdi.check_for_NaNs()
    assert len(subjects_over_threshold) == 0
    assert len(descriptors_over_threshold) == 0
コード例 #4
0
def test_braindescriptors_add_standard_stats():
    expected_subject2_testdata_dir = os.path.join(TEST_DATA_DIR, 'subject2')
    if not os.path.isdir(expected_subject2_testdata_dir):
        pytest.skip("Test data missing: e.g., directory '%s' does not exist. You can get all test data by running './develop/get_test_data_all.bash' in the repo root." % expected_subject2_testdata_dir)
    subjects_list = ['subject1', 'subject2']
    bdi = bd.BrainDescriptors(TEST_DATA_DIR, subjects_list)
    bdi.add_standard_stats()
    assert len(bdi.descriptor_names) == 3426
    assert bdi.descriptor_values.shape == (2, 3426)
コード例 #5
0
def test_check_for_custom_measure_stats_files_invalid_format():
    expected_subject2_testdata_dir = os.path.join(TEST_DATA_DIR, 'subject2')
    if not os.path.isdir(expected_subject2_testdata_dir):
        pytest.skip("Test data missing: e.g., directory '%s' does not exist. You can get all test data by running './develop/get_test_data_all.bash' in the repo root." % expected_subject2_testdata_dir)
    subjects_list = ['subject1', 'subject2']
    bdi = bd.BrainDescriptors(TEST_DATA_DIR, subjects_list, hemi='rh')
    with pytest.raises(ValueError) as exc_info:
        bdi.check_for_custom_measure_stats_files(["aparc"], ["area"], morph_file_format="nosuchformat")
    assert "nosuchformat" in str(exc_info.value)
    assert "morph_file_format must be one of" in str(exc_info.value)
コード例 #6
0
def test_braindescriptors_init_with_hemi():
    expected_subject2_testdata_dir = os.path.join(TEST_DATA_DIR, 'subject2')
    if not os.path.isdir(expected_subject2_testdata_dir):
        pytest.skip("Test data missing: e.g., directory '%s' does not exist. You can get all test data by running './develop/get_test_data_all.bash' in the repo root." % expected_subject2_testdata_dir)
    subjects_list = ['subject1', 'subject2']
    bdi = bd.BrainDescriptors(TEST_DATA_DIR, subjects_list, hemi='lh')
    bdi.report_descriptors()
    bdi.check_for_hemi_dependent_file([])
    assert len(bdi.subjects_list) == 2
    assert len(bdi.descriptor_names) == 0
    assert bdi.descriptor_values.shape == (2, 0)
    assert len(bdi.hemis) == 1
コード例 #7
0
def test_braindescriptors_parcellation_stats():
    expected_subject2_testdata_dir = os.path.join(TEST_DATA_DIR, 'subject2')
    if not os.path.isdir(expected_subject2_testdata_dir):
        pytest.skip("Test data missing: e.g., directory '%s' does not exist. You can get all test data by running './develop/get_test_data_all.bash' in the repo root." % expected_subject2_testdata_dir)
    subjects_list = ['subject1', 'subject2']
    bdi = bd.BrainDescriptors(TEST_DATA_DIR, subjects_list)
    bdi.add_parcellation_stats(['aparc', 'aparc.a2009s'])
    bdi.add_segmentation_stats(['aseg'])
    bdi.add_custom_measure_stats(['aparc'], ['area'])
    bdi.add_curv_stats()
    assert len(bdi.descriptor_names) == 3089
    assert bdi.descriptor_values.shape == (2, 3089)
コード例 #8
0
def run_desc():
    #subjects_list = ['subject1', 'subject2']
    #subjects_dir = os.path.join("tests", "test_data")

    subjects_dir = os.path.join(os.getenv("HOME"), "data", "abide",
                                "structural")
    #subjects_dir = os.path.join("/Volumes", "shared-1", "projects", "abide", "structural")
    subjects_file = os.path.join(subjects_dir, 'subjects.txt')
    subjects_list = brainload.nitools.read_subjects_file(subjects_file)

    logging.basicConfig(level=logging.INFO)

    bdi = bd.BrainDescriptors(subjects_dir, subjects_list)
    bdi.add_parcellation_stats(['aparc', 'aparc.a2009s'])
    bdi.add_segmentation_stats(['aseg'])
    #bdi.add_custom_measure_stats(['aparc'], ['area'])
    bdi.add_custom_measure_stats(['aparc', 'aparc.a2009s'], [
        'area', 'area.pial', 'curv', 'curv.pial', 'jacobian_white', 'sulc',
        'thickness', 'truncation', 'volume'
    ])

    #bdi.report_descriptors()

    bdi._check_for_duplicate_descriptor_names()
    subjects_over_threshold, descriptors_over_threshold, nan_share_per_subject, nan_share_per_descriptor = bdi.check_for_NaNs(
    )

    do_plot_nans = False
    if do_plot_nans:
        plot_hist(nan_share_per_subject, "NaN share per subject")
        plot_hist(nan_share_per_descriptor, "NaN share per descriptor")

    data_output_file = "braindescriptors.csv"
    subjects_output_file = "subjects.txt"
    bdi.save(data_output_file, subjects_file=subjects_output_file)
    logging.info(
        "Saved values of %d descriptors for each of the %d subjects to file '%s'. Subject order for data written to file '%s'."
        % (len(bdi.descriptor_names), len(
            bdi.subjects_list), data_output_file, subjects_output_file))