예제 #1
0
def test_regress_covar():
    """ test regress_covar"""
    _make_tmp_dir()

    extract_mean_wm_ts = ExtractMeanTS()
    extract_mean_wm_ts.inputs.file_4D = img_file
    extract_mean_wm_ts.inputs.mask_file = wm_mask_file
    extract_mean_wm_ts.inputs.suffix = "wm"
    mean_wm_ts_file = extract_mean_wm_ts.run().outputs.mean_masked_ts_file

    extract_mean_csf_ts = ExtractMeanTS()
    extract_mean_csf_ts.inputs.file_4D = img_file
    extract_mean_csf_ts.inputs.mask_file = csf_mask_file
    extract_mean_csf_ts.inputs.suffix = "csf"
    mean_csf_ts_file = extract_mean_csf_ts.run().outputs.mean_masked_ts_file

    extra_ts = ExtractTS()
    extra_ts.inputs.indexed_rois_file = indexed_mask_file
    extra_ts.inputs.file_4D = img_file
    masked_ts_file = extra_ts.run().outputs.mean_masked_ts_file

    regress_covar = RegressCovar()
    regress_covar.inputs.masked_ts_file = masked_ts_file
    regress_covar.inputs.mean_wm_ts_file = mean_wm_ts_file
    regress_covar.inputs.mean_csf_ts_file = mean_csf_ts_file

    val = regress_covar.run().outputs
    print(val)

    os.remove(val.resid_ts_file)

    os.remove(masked_ts_file)
    os.remove(mean_csf_ts_file)
    os.remove(mean_wm_ts_file)
예제 #2
0
def test_return_net_list():
    """
    test transforming matrix as np.array to list of edges
    """
    _make_tmp_dir()
    conmat = np.load(conmat_file)
    list_conmat = return_net_list(conmat, int_factor=1000)
    assert list_conmat.shape[1] == 3
예제 #3
0
def test_export_Louvain_net_from_list():
    """testing Louvain Traag file building (for sake of compatibility of older
    codes)"""
    _make_tmp_dir()
    coords = np.loadtxt(coords_file)
    Z_list = np.loadtxt(Z_list_file)
    Z_Louvain_file = os.path.abspath("Z_Louvain.txt")
    export_Louvain_net_from_list(Z_Louvain_file, Z_list, coords)
    assert os.path.exists(Z_Louvain_file)
예제 #4
0
def test_compute_net_list():
    """ test ComputeNetList"""
    _make_tmp_dir()
    compute_net_list = ComputeNetList()
    compute_net_list.inputs.Z_cor_mat_file = conmat_file

    val = compute_net_list.run().outputs
    print(val)
    assert os.path.exists(val.net_List_file)
    os.remove(val.net_List_file)
예제 #5
0
def test_prep_rada():
    """test PrepRada"""
    _make_tmp_dir()

    prep_rada = PrepRada()
    prep_rada.inputs.net_List_file = Z_list_file
    prep_rada.inputs.network_type = "U"
    val = prep_rada.run().outputs

    assert os.path.exists(val.Pajek_net_file)
예제 #6
0
def test_extract_ts():
    """ test ExtractTS"""
    _make_tmp_dir()

    extra_ts = ExtractTS()
    extra_ts.inputs.indexed_rois_file = indexed_mask_file
    extra_ts.inputs.file_4D = img_file

    val = extra_ts.run().outputs
    print(val)
    assert os.path.exists(val.mean_masked_ts_file)
    os.remove(val.mean_masked_ts_file)
예제 #7
0
def test_KCore_undirected():
    _make_tmp_dir()

    np_mat_file = os.path.abspath("rand_bin_mat.npy")
    np.save(np_mat_file, np_mat)

    kcore = KCore()
    kcore.inputs.np_mat_file = os.path.abspath("rand_bin_mat.npy")
    kcore.inputs.is_directed = False
    kcore.run()

    assert os.path.exists(os.path.abspath("coreness.npy"))
    assert os.path.exists(os.path.abspath("distrib_k.npy"))
예제 #8
0
def test_extract_mean_ts():
    """test ExtractMeanTS"""
    _make_tmp_dir()

    extract_mean_ts = ExtractMeanTS()
    extract_mean_ts.inputs.file_4D = img_file
    extract_mean_ts.inputs.mask_file = wm_mask_file
    extract_mean_ts.inputs.suffix = "wm"

    val = extract_mean_ts.run().outputs
    print(val)
    assert os.path.exists(val.mean_masked_ts_file)
    os.remove(val.mean_masked_ts_file)
예제 #9
0
def test_comm_rada():
    """test CommRada"""
    _make_tmp_dir()

    comm_rada = CommRada()
    comm_rada.inputs.Pajek_net_file = Pajek_net_file
    comm_rada.inputs.optim_seq = "WS trfr 1"

    val = comm_rada.run().outputs

    assert os.path.exists(val.rada_lol_file)
    assert os.path.exists(val.rada_log_file)
    assert os.path.exists(val.lol_log_file)
예제 #10
0
def test_compute_module_mat_prop():
    """ test ComputeModuleMatProp"""
    _make_tmp_dir()

    compute_module_graph_prop = ComputeModuleMatProp()
    compute_module_graph_prop.inputs.rada_lol_file = lol_file
    compute_module_graph_prop.inputs.Pajek_net_file = Pajek_net_file
    compute_module_graph_prop.inputs.conmat_file = conmat_file

    val = compute_module_graph_prop.run().outputs
    print(val)

    assert os.path.exists(val.df_avgmat_file)
예제 #11
0
def test_compute_conf_cor_mat():
    """test ComputeConfCorMat"""
    _make_tmp_dir()

    extract_mean_wm_ts = ExtractMeanTS()
    extract_mean_wm_ts.inputs.file_4D = img_file
    extract_mean_wm_ts.inputs.filter_thr = 0.9
    extract_mean_wm_ts.inputs.filter_mask_file = csf_mask_file
    extract_mean_wm_ts.inputs.suffix = "wm"
    mean_wm_ts_file = extract_mean_wm_ts.run().outputs.mean_masked_ts_file

    extract_mean_csf_ts = ExtractMeanTS()
    extract_mean_csf_ts.inputs.file_4D = img_file
    extract_mean_csf_ts.inputs.filter_thr = 0.9
    extract_mean_csf_ts.inputs.filter_mask_file = csf_mask_file
    extract_mean_csf_ts.inputs.suffix = "csf"
    mean_csf_ts_file = extract_mean_csf_ts.run().outputs.mean_masked_ts_file

    extra_ts = ExtractTS()
    extra_ts.inputs.indexed_rois_file = indexed_mask_file
    extra_ts.inputs.file_4D = img_file
    masked_ts_file = extra_ts.run().outputs.mean_masked_ts_file

    regress_covar = RegressCovar()
    regress_covar.inputs.masked_ts_file = masked_ts_file
    regress_covar.inputs.mean_wm_ts_file = mean_wm_ts_file
    regress_covar.inputs.mean_csf_ts_file = mean_csf_ts_file

    resid_ts_file = regress_covar.run().outputs.resid_ts_file

    compute_conf_cor_mat = ComputeConfCorMat()
    compute_conf_cor_mat.inputs.ts_file = resid_ts_file

    val = compute_conf_cor_mat.run().outputs
    print(val)

    assert os.path.exists(val.cor_mat_file)
    assert os.path.exists(val.Z_cor_mat_file)
    assert os.path.exists(val.conf_cor_mat_file)
    assert os.path.exists(val.Z_conf_cor_mat_file)

    os.remove(val.cor_mat_file)
    os.remove(val.conf_cor_mat_file)
    os.remove(val.Z_cor_mat_file)
    os.remove(val.Z_conf_cor_mat_file)

    os.remove(resid_ts_file)
    os.remove(masked_ts_file)
    os.remove(mean_csf_ts_file)
    os.remove(mean_wm_ts_file)
예제 #12
0
def test_net_prop_rada():
    """test NetPropRada"""
    _make_tmp_dir()

    net_prop_rada = NetPropRada()
    net_prop_rada.inputs.Pajek_net_file = Pajek_net_file

    val = net_prop_rada.run().outputs

    assert os.path.exists(val.global_file)
    assert os.path.exists(val.dists_file)
    assert os.path.exists(val.degrees_file)
    assert os.path.exists(val.nodes_file)
    assert os.path.exists(val.edges_betw_file)
    assert os.path.exists(val.rada_log_file)
예제 #13
0
def test_compute_node_roles():
    """ test ComputeNodeRoles"""
    _make_tmp_dir()

    compute_node_roles = ComputeNodeRoles()
    compute_node_roles.inputs.rada_lol_file = lol_file
    compute_node_roles.inputs.Pajek_net_file = Pajek_net_file

    val = compute_node_roles.run().outputs
    print(val)
    assert os.path.exists(val.node_roles_file)
    assert os.path.exists(val.all_Z_com_degree_file)
    assert os.path.exists(val.all_participation_coeff_file)

    os.remove(val.node_roles_file)
    os.remove(val.all_Z_com_degree_file)
    os.remove(val.all_participation_coeff_file)
예제 #14
0
def test_split_ts():
    """ test SplitTS"""
    _make_tmp_dir()

    extract_mean_wm_ts = ExtractMeanTS()
    extract_mean_wm_ts.inputs.file_4D = img_file
    extract_mean_wm_ts.inputs.filter_thr = 0.9
    extract_mean_wm_ts.inputs.filter_mask_file = csf_mask_file
    extract_mean_wm_ts.inputs.suffix = "wm"
    mean_wm_ts_file = extract_mean_wm_ts.run().outputs.mean_masked_ts_file

    extract_mean_csf_ts = ExtractMeanTS()
    extract_mean_csf_ts.inputs.file_4D = img_file
    extract_mean_csf_ts.inputs.filter_thr = 0.9
    extract_mean_csf_ts.inputs.filter_mask_file = csf_mask_file
    extract_mean_csf_ts.inputs.suffix = "csf"
    mean_csf_ts_file = extract_mean_csf_ts.run().outputs.mean_masked_ts_file

    extra_ts = ExtractTS()
    extra_ts.inputs.indexed_rois_file = indexed_mask_file
    extra_ts.inputs.file_4D = img_file
    masked_ts_file = extra_ts.run().outputs.mean_masked_ts_file

    regress_covar = RegressCovar()
    regress_covar.inputs.masked_ts_file = masked_ts_file
    regress_covar.inputs.mean_wm_ts_file = mean_wm_ts_file
    regress_covar.inputs.mean_csf_ts_file = mean_csf_ts_file
    resid_ts_file = regress_covar.run().outputs.resid_ts_file

    split_ts = SplitTS()
    split_ts.inputs.ts_file = resid_ts_file
    split_ts.inputs.win_length = 10
    split_ts.inputs.offset = 5

    splitted_ts_files = split_ts.run().outputs.splitted_ts_files
    assert len(splitted_ts_files) != 0
    assert os.path.exists(splitted_ts_files[0])

    for splitted_ts_file in splitted_ts_files:

        os.remove(splitted_ts_file)
예제 #15
0
def test_create_pipeline_nii_to_conmat():
    tmp_dir = _make_tmp_dir()
    wf = create_pipeline_nii_to_conmat(main_path=tmp_dir,
                                       pipeline_name="nii_to_conmat_full")

    wf.inputs.inputnode.nii_4D_file = nii_4D_file
    wf.inputs.inputnode.ROI_mask_file = indexed_mask_file

    wf.inputs.inputnode.gm_anat_file = gm_anat_file
    wf.inputs.inputnode.wm_anat_file = wm_anat_file
    wf.inputs.inputnode.csf_anat_file = csf_anat_file

    # Warning, is necessary, otherwise Figures are removed!
    wf.config['execution'] = {"remove_unnecessary_outputs": False}

    wf.run()
예제 #16
0
def test_read_Pajek_corres_nodes():
    """Test reading corres node vector given a Pajek .net file"""
    _make_tmp_dir()
    corres = read_Pajek_corres_nodes(Pajek_net_file)
    print(corres)
예제 #17
0
def test_read_Pajek_corres_nodes_and_sparse_matrix():
    """Test reading corres node vector and sparse graph representation
    given a Pajek .net file"""
    _make_tmp_dir()
    corres, sp = read_Pajek_corres_nodes_and_sparse_matrix(Pajek_net_file)
    assert len(corres) == sp.todense().shape[0]