Exemple #1
0
    def close_connected_nodes(self):
        for node in self._nodesIn_:
            if not node._stop_flag_.is_set():
                node.close_connection('Server being shut down')
                node.join()

        for node in self._nodesOut_:
            if not node._stop_flag_.is_set():
                node.close_connection('Server being shut down')
                node.join()
Exemple #2
0
def process_orthologs(filename, nodes, gene_to_num):
    with open(filename, 'r') as file:
        for line in file.readlines():
            blocks = line.split();
            if blocks[0] != "Ensembl":
                i = gene_to_num[blocks[0]]
                for gene in blocks:
                    if gene in gene_to_num: #some orthologs could be from additional chromosomes
                        j = gene_to_num[gene]
                        node.join(nodes, i, j)
Exemple #3
0
def process_paralogs(filename, nodes, gene_to_num):
    with open(filename, 'r') as file:
        for line in file.readlines():
            blocks = line.split()
            if blocks[0] != "Ensembl":
                if len(blocks) == 1:
                    continue
                if blocks[1] in gene_to_num: #some paralogs could be from additional chromosomes
                    i = gene_to_num[blocks[0]]
                    j = gene_to_num[blocks[1]]
                    node.join(nodes, i, j)
Exemple #4
0
def pgma(seq_names, seqs, score_matrix, kind):
    n = len(seqs)
    nodes = [node.Node(i, seq_names[i], seqs[i]) for i in range(0, n)]
    count = [1 for _ in range(0, n)]
    scores = [[0 for _ in range(0, n)] for _ in range(0, n)]
    minus_infinity = -10000000000
    for i in range(0, n):
        for j in range(i + 1, n):
            score = pairwise_alignment.seq_alignment(seqs[i], seqs[j], score_matrix)
            scores[i][j] = score
            scores[j][i] = score
    for i in range(0, n):
        scores[i][i] = minus_infinity

    clusters = {}
    for i in range(0, n):
        clusters[i] = 1

    for _ in range(0, n - 1):
        argmax1 = -1
        argmax2 = -1
        max = minus_infinity
        for i in range(0, n):
            if i in clusters:
                for j in range(i + 1, n):
                    if j in clusters:
                        if scores[i][j] > max:
                            max = scores[i][j]
                            argmax1 = i
                            argmax2 = j

        i1, i2 = node.join(nodes, argmax1, argmax2, score_matrix) # first will present new cluster

        #recalc_scores
        if kind == 'w':
            for k in range(0, n):
                if k != i1:
                    new_score = float(scores[i1][k] + scores[i2][k]) / 2
                    scores[i1][k] = new_score
                    scores[k][i1] = new_score
        else:
            for k in range(0, n):
                if k != i1:
                    new_score = float(scores[i1][k] * count[i1] + scores[i2][k] * count[i2]) / (count[i1] + count[i2])
                    scores[i1][k] = new_score
                    scores[k][i1] = new_score

        del clusters[i2]

        count[i1] += count[i2]

    root_index = node.find(nodes, 0)
    return nodes[root_index].seq_names, nodes[root_index].seqs
def neigbor_joining(seq_names, seqs, score_matrix):
    n = len(seqs)
    nodes = [node.Node(i, seq_names[i], seqs[i]) for i in range(0, n)]
    count = [1 for _ in range(0, n)]
    scores = [[0 for _ in range(0, n)] for _ in range(0, n)]
    minus_infinity = -10000000000
    for i in range(0, n):
        for j in range(i + 1, n):
            score = pairwise_alignment.seq_alignment(seqs[i], seqs[j], score_matrix)
            scores[i][j] = score
            scores[j][i] = score
    for i in range(0, n):
        scores[i][i] = 0

    clusters = {}
    for i in range(0, n):
        clusters[i] = 1

    for lolo in range(0, n - 1):
        argmax1 = -1
        argmax2 = -1
        max = minus_infinity
        r = len(clusters)
        for i in range(0, n):
            if i in clusters:
                for j in range(i + 1, n):
                    if j in clusters:
                        score = scores[i][j] * (r - 2) - sum_scores(scores[i], clusters) - sum_scores(scores[j], clusters)
                        if score > max:
                            max = score
                            argmax1 = i
                            argmax2 = j

        i1, i2 = node.join(nodes, argmax1, argmax2, score_matrix) # first will present new cluster

        #recalc_scores
        for k in range(0, n):
            if k != i1 and k!= i2:
                new_score = float(scores[i1][k] + scores[i2][k] - scores[i1][i2]) / 2
                scores[i1][k] = new_score
                scores[k][i1] = new_score

        del clusters[i2]

        count[i1] += count[i2]

    root_index = node.find(nodes, 0)
    return nodes[root_index].seq_names, nodes[root_index].seqs
Exemple #6
0
def join_ring(node_name, node_port):
    othernode = node.Node_Info(node_name, node_port)
    node.join(othernode)
Exemple #7
0
    node.thisNode = node.Node_Info(node.IPAddr, node.ctrlPort)
    Internal_service = serve.Internal_Service()
    node.add_service(Internal_service)
    node.add_service(serve.ECHO_service())
    node.net_server = start(node.thisNode, node.handle_message)
    database = db.Shelver("test.db")
    node.add_service(database)

    TOPO = Topology_Service.Topology()
    node.add_service(TOPO)

    if len(sys.argv) > 2:
        node_name = sys.argv[2]
        node_port = int(sys.argv[3])
        othernode = node.Node_Info(node_name, node_port)
        node.join(othernode)
        print node.thisNode
        print othernode
        #f = lambda : node.join(othernode)
        #t = Thread(target=f)
        #t.start()
    else:
        node.create()
        #t = Thread(target = node.create)
        #t.start()
    node.startup()
    while True:
        cmd = raw_input(">>")
        if cmd[:6] == "get f ":
            x = int(cmd[6:])
            print node.fingerTable[x]