Esempio n. 1
0
def get_link_score(component, score_file):
    # print 'Scoring started'
    # matlab_function = "getEigenScore('" + component_dir + "', '" + score_file + "')"
    # subprocess.call([matlab_path, "-nosplash", "-nodisplay", "-r", matlab_function])
    # component = []
    # with open(component_dir) as f:
    #     lines = f.readlines()
    # for line in lines:
    #     items = line.split('\t')
    #     component.append([int(items[0]), int(items[1]), float(items[2]), float(items[3])])
    link_score, lambda0 = gES.main(component, score_file, tol='1e-10')
Esempio n. 2
0
def get_link_score(component_dir, score_file):
    component = []
    with open(component_dir) as f:
        lines = f.readlines()
    for line in lines:
        items = line.split('\t')
        component.append(
            [int(items[0]),
             int(items[1]),
             float(items[2]),
             float(items[3])])
    link_score, lambda0 = gES.main(component, score_file, tol='1e-10')
Esempio n. 3
0
def get_dynamic_graphs(inp):
    links, active_nodes, segment_index_arr, root_dir_component, smallest_segments, root_dir = inp
    G_size = {}
    active_node_arr = {}
    max_n = None
    min_n = None
    for segment_index in segment_index_arr:
        index = 1
        segment = smallest_segments[segment_index]
        coarse_input_dir = root_dir_component + 'coarse' + str(
            segment[0]) + '_' + str(segment[1]) + '.txt'
        root_dir_component = root_dir + '/' + percent + '/'
        component = []
        score_dir = root_dir_component + 'score' + str(segment[0]) + '_' + str(
            segment[1]) + '.txt'
        #####get active nodes and links in each min_seg
        active_node_arr[segment_index] = []
        c_nodes = {}
        for key in links:
            link = links[key]
            if (link[2] == None) and (link[3] == None):
                component.append([link[0], link[1], 0.02, 0.02])
                for nn in [link[0], link[1]]:
                    try:
                        c_nodes[nn]
                    except KeyError:
                        c_nodes[nn] = index
                        index += 1
            elif (link[2] == None) and (link[3] >= segment[1]):
                component.append([link[0], link[1], 0.02, 0.02])
                for nn in [link[0], link[1]]:
                    try:
                        c_nodes[nn]
                    except KeyError:
                        c_nodes[nn] = index
                        index += 1
            elif (link[2] <= segment[1]) and (link[3] == None):
                component.append([link[0], link[1], 0.02, 0.02])
                for nn in [link[0], link[1]]:
                    try:
                        c_nodes[nn]
                    except KeyError:
                        c_nodes[nn] = index
                        index += 1
            elif (link[2] <= segment[1]) and (link[3] >= segment[1]):
                component.append([link[0], link[1], 0.02, 0.02])
                for nn in [link[0], link[1]]:
                    try:
                        c_nodes[nn]
                    except KeyError:
                        c_nodes[nn] = index
                        index += 1
        tmp_active = {}
        if segment[0] in active_nodes:
            for a_node in active_nodes[segment[0]]:
                if a_node in c_nodes:
                    active_node_arr[segment_index].append(c_nodes[a_node])
                    tmp_active[c_nodes[a_node]] = 0

        with open(coarse_input_dir, 'w') as f:
            for ii in range(len(component)):
                n1, n2, t1, t2 = component[ii]
                component[ii] = [c_nodes[n1], c_nodes[n2], t1, t2]
                n1, n2, t1, t2 = component[ii]
                f.write(
                    str(n1) + '\t' + str(n2) + '\t' + str(t1) + '\t' +
                    str(t2) + '\n')

        gES.main(component, score_dir, tol='1e-10')
        ###update score files
        with open(score_dir) as f:
            lines = f.readlines()
        with open(score_dir, 'w') as f:
            for line in lines:
                items = line.split('\t')
                n1 = int(items[0])
                n2 = int(items[1])
                s = float(items[2])
                both_active = (n1 in tmp_active) and (n2 in tmp_active)
                both_inactive = (not (n1 in tmp_active)) and (
                    not (n2 in tmp_active))
                if both_active or both_inactive:
                    f.write(str(n1) + '\t' + str(n2) + '\t' + str(s) + '\n')
        ###
        if max_n == None:
            max_n = len(c_nodes)
        if min_n == None:
            min_n = len(c_nodes)
        if len(c_nodes) > max_n:
            max_n = len(c_nodes)
        if len(c_nodes) < min_n:
            min_n = len(c_nodes)
        G_size[segment_index] = len(c_nodes)

    return G_size, min_n, max_n, active_node_arr