Exemple #1
0
def thresh_diff(dens_thresh, thr, conn_model, network, ID, dir_path, mask,
                node_size, conn_matrix):
    from pynets import utils, thresholding

    if not dens_thresh:
        print("%s%.2f%s" % ('\nThresholding proportionally at: ',
                            100 * float(thr), '% ...\n'))
    else:
        print("%s%.2f%s" % ('\nThresholding to achieve density of: ',
                            100 * float(thr), '% ...\n'))

    if dens_thresh == False:
        ##Save thresholded
        conn_matrix_thr = thresholding.threshold_proportional(
            conn_matrix, float(thr))
        edge_threshold = str(float(thr) * 100) + '%'
        est_path = utils.create_est_path(ID, network, conn_model, thr, mask,
                                         dir_path, node_size)
    else:
        conn_matrix_thr = thresholding.density_thresholding(
            conn_matrix, float(thr))
        edge_threshold = str(float(thr) * 100) + '%'
        est_path = utils.create_est_path(ID, network, conn_model, thr, mask,
                                         dir_path, node_size)
    np.save(est_path, conn_matrix_thr)
    return (conn_matrix_thr, edge_threshold, est_path, thr, node_size, network)
Exemple #2
0
def thresh_and_fit(adapt_thresh, dens_thresh, thr, ts_within_nodes, conn_model,
                   network, ID, dir_path, mask):
    from pynets import utils, thresholding, graphestimation

    ##Adaptive thresholding scenario
    if adapt_thresh is not False:
        try:
            est_path2 = dir_path + '/' + ID + '_structural_est.txt'
            if os.path.isfile(est_path2) == True:
                #[conn_matrix_thr, est_path, edge_threshold, thr] = adaptive_thresholding(ts_within_nodes, conn_model, network, ID, est_path2, dir_path)
                ##Save unthresholded
                unthr_path = utils.create_unthr_path(ID, network, conn_model,
                                                     mask, dir_path)
                #np.savetxt(unthr_path, conn_matrix_thr, delimiter='\t')
                edge_threshold = str(float(thr) * 100) + '%'
            else:
                print('No structural mx found! Exiting...')
                sys.exit()
        except:
            print('No structural mx assigned! Exiting...')
            sys.exit()
    else:
        if not dens_thresh:
            print(
                '\nRunning graph estimation and thresholding proportionally at: '
                + str(thr) + '% ...\n')
        else:
            print(
                '\nRunning graph estimation and thresholding to achieve density of: '
                + str(100 * dens_thresh) + '% ...\n')
        ##Fit mat
        conn_matrix = graphestimation.get_conn_matrix(ts_within_nodes,
                                                      conn_model)

        ##Save unthresholded
        unthr_path = utils.create_unthr_path(ID, network, conn_model, mask,
                                             dir_path)
        np.savetxt(unthr_path, conn_matrix, delimiter='\t')

        if not dens_thresh:
            ##Save thresholded
            conn_matrix_thr = thresholding.threshold_proportional(
                conn_matrix, float(thr))
            edge_threshold = str(float(thr) * 100) + '%'
            est_path = utils.create_est_path(ID, network, conn_model, thr,
                                             mask, dir_path)
        else:
            conn_matrix_thr = thresholding.density_thresholding(
                conn_matrix, dens_thresh)
            edge_threshold = str((1 - float(dens_thresh)) * 100) + '%'
            est_path = utils.create_est_path(ID, network, conn_model,
                                             dens_thresh, mask, dir_path)
        np.savetxt(est_path, conn_matrix_thr, delimiter='\t')
    return (conn_matrix_thr, edge_threshold, est_path, thr)
Exemple #3
0
def thresh_diff(dens_thresh, thr, conn_model, network, ID, dir_path, mask,
                node_size, conn_matrix, parc):
    from pynets import utils, thresholding

    thr_perc = 100 * float(thr)
    edge_threshold = "%s%s" % (str(thr_perc), '%')
    if parc is True:
        node_size = 'parc'
    if dens_thresh is False:
        print("%s%.2f%s" %
              ('\nThresholding proportionally at: ', thr_perc, '% ...\n'))
    else:
        print("%s%.2f%s" %
              ('\nThresholding to achieve density of: ', thr_perc, '% ...\n'))

    if dens_thresh is False:
        conn_matrix_thr = thresholding.threshold_proportional(
            conn_matrix, float(thr))
    else:
        conn_matrix_thr = thresholding.density_thresholding(
            conn_matrix, float(thr))
    # Save thresholded mat
    est_path = utils.create_est_path(ID, network, conn_model, thr, mask,
                                     dir_path, node_size)
    np.save(est_path, conn_matrix_thr)
    return conn_matrix_thr, edge_threshold, est_path, thr, node_size, network
Exemple #4
0
def thresh_and_fit(dens_thresh, thr, ts_within_nodes, conn_model, network, ID,
                   dir_path, mask, node_size):
    from pynets import utils, thresholding, graphestimation

    thr_perc = 100 * float(thr)
    edge_threshold = "%s%s" % (str(thr_perc), '%')

    if not dens_thresh:
        print("%s%.2f%s" %
              ('\nThresholding proportionally at: ', thr_perc, '% ...\n'))
    else:
        print("%s%.2f%s" %
              ('\nThresholding to achieve density of: ', thr_perc, '% ...\n'))
    # Fit mat
    conn_matrix = graphestimation.get_conn_matrix(ts_within_nodes, conn_model)

    # Save unthresholded
    unthr_path = utils.create_unthr_path(ID, network, conn_model, mask,
                                         dir_path)
    np.save(unthr_path, conn_matrix)

    if dens_thresh is False:
        conn_matrix_thr = thresholding.threshold_proportional(
            conn_matrix, float(thr))
    else:
        conn_matrix_thr = thresholding.density_thresholding(
            conn_matrix, float(thr))
    # Save thresholded mat
    est_path = utils.create_est_path(ID, network, conn_model, thr, mask,
                                     dir_path, node_size)
    np.save(est_path, conn_matrix_thr)
    return conn_matrix_thr, edge_threshold, est_path, thr, node_size, network
Exemple #5
0
def thresh_diff(dens_thresh, thr, conn_model, network, ID, dir_path, mask,
                node_size, conn_matrix, parc, min_span_tree, disp_filt,
                atlas_select, uatlas_select, label_names, coords):
    from pynets import utils, thresholding

    thr_perc = 100 * float(thr)
    edge_threshold = "%s%s" % (str(thr_perc), '%')

    if parc is True:
        node_size = 'parc'

    if min_span_tree is True:
        print(
            'Using local thresholding option with the Minimum Spanning Tree (MST)...\n'
        )
        if dens_thresh is False:
            thr_type = 'MSTprop'
            conn_matrix_thr = thresholding.local_thresholding_prop(
                conn_matrix, thr)
        else:
            thr_type = 'MSTdens'
            conn_matrix_thr = thresholding.local_thresholding_dens(
                conn_matrix, thr)
    elif disp_filt is True:
        thr_type = 'DISPα'
        G1 = thresholding.disparity_filter(nx.from_numpy_array(conn_matrix))
        # G2 = nx.Graph([(u, v, d) for u, v, d in G1.edges(data=True) if d['alpha'] < thr])
        print('Computing edge disparity significance with alpha = %s' % thr)
        print('Filtered graph: nodes = %s, edges = %s' %
              (G1.number_of_nodes(), G1.number_of_edges()))
        # print('Backbone graph: nodes = %s, edges = %s' % (G2.number_of_nodes(), G2.number_of_edges()))
        #print(G2.edges(data=True))
        conn_matrix_thr = nx.to_numpy_array(G1)
    else:
        if dens_thresh is False:
            thr_type = 'prop'
            print("%s%.2f%s" %
                  ('\nThresholding proportionally at: ', thr_perc, '% ...\n'))
            conn_matrix_thr = thresholding.threshold_proportional(
                conn_matrix, float(thr))
        else:
            thr_type = 'dens'
            print("%s%.2f%s" % ('\nThresholding to achieve density of: ',
                                thr_perc, '% ...\n'))
            conn_matrix_thr = thresholding.density_thresholding(
                conn_matrix, float(thr))

    if not nx.is_connected(nx.from_numpy_matrix(conn_matrix_thr)):
        print('Warning: Fragmented graph')

    # Save thresholded mat
    smooth = 0
    est_path = utils.create_est_path(ID, network, conn_model, thr, mask,
                                     dir_path, node_size, smooth, thr_type)
    np.save(est_path, conn_matrix_thr)
    return conn_matrix_thr, edge_threshold, est_path, thr, node_size, network, conn_model, mask, atlas_select, uatlas_select, label_names, coords
Exemple #6
0
def build_est_path_list(multi_thr, min_thr, max_thr, step_thr, ID, network,
                        conn_model, thr, mask, dir_path, est_path_list):
    import numpy as np
    from pynets import utils
    if multi_thr == True:
        iter_thresh = [
            str(i) for i in np.round(np.arange(float(min_thr), float(max_thr),
                                               float(step_thr)),
                                     decimals=2).tolist()
        ]
        for thr in iter_thresh:
            est_path_tmp = utils.create_est_path(ID, network, conn_model, thr,
                                                 mask, dir_path)
            est_path_list.append(est_path_tmp)
    else:
        est_path_tmp = utils.create_est_path(ID, network, conn_model, thr,
                                             mask, dir_path)
        est_path_list.append(est_path_tmp)
        iter_thresh = [thr] * len(est_path_list)
    return (iter_thresh, est_path_list)