Example #1
0
    def test_three(self):
        text = "((4, 5#1)2, (#1, 6)3);"
        enewick_graph = enewick_to_digraph(text)
        self.assertEqual(len(enewick_graph.nodes()), 6)
        enewick_graph = calc_hybrid(enewick_graph)
        leafs = get_leaf_nodes(enewick_graph)
        gold_leafs = ['1', '4', '6', ]
        self.assertItemsEqual(leafs, gold_leafs)

        clusters = ["1,2", "2,3"]
        gold = construct(clusters)
        g = enewick_to_phylonet(text)
        GM = GraphMatcher(g, gold)
        self.assertTrue(GM.is_isomorphic())
def benchmark_nets(g):
    # atributs varis
    arestes_llevables = len(removable_edges(g))
    fulles = len(get_leaf_nodes(g))
    nodes = len(g.nodes())
    arestes = len(g.edges())
    hibrids = len(hybrid_nodes(g))
    grau_hibriditzacio = hybridization_degree(g)
    es_treechild = is_treechild(g)
    nodes_conflictius = len(problematic_treechild_nodes(g))
    subarbres = potential_number_of_calls(g)
    temps_soft, temps_soft_cache = -1, -1
    n_families, temps_families = -1, -1
    # tree-child
    # poda amb timeout
    # if arestes_llevables > MAX_ARESTES:
    #     return
    if not es_treechild:
        try:
            log.debug("inici construccio {}".format(arestes_llevables))
            executor = ThreadPoolExecutor(max_workers=1)
            begin_families = time.time()
            future = executor.submit(construct_treechild, g)
            families = future.result(TIMEOUT)
            end_families = time.time()
            temps_families = end_families - begin_families
            n_families = len(families)
            log.debug("final {}".format(arestes_llevables))
        except TimeoutError:
            log.debug("timeout {}".format(arestes_llevables))
            n_familes, temps_families = -1, -1
    else:
        n_families, temps_families = 0, 0
    BenchmarkCase.create(
        test = TEST_NUMBER,
        fulles = fulles,
        nodes = nodes,
        arestes = arestes,
        hibrids = hibrids,
        subarbres = subarbres,
        grau_hibriditzacio = grau_hibriditzacio,
        temps_soft = temps_soft,
        temps_soft_cache = temps_soft_cache,
        arestes_llevables = arestes_llevables,
        es_treechild = es_treechild,
        nodes_conflictius = nodes_conflictius,
        temps_families = temps_families,
        n_families = n_families,
    )
Example #3
0
def test_case(g):
    test = TEST_NUMBER
    nodes = len(g.nodes())
    fulles = len(get_leaf_nodes(g))
    arestes = len(g.edges())
    hibrids = len(hybrid_nodes(g))
    grau_hibriditzacio = hybridization_degree(g)
    arestes_llevables = len(removable_edges(g))
    es_treechild = is_treechild(g)
    nodes_conflictius = len(problematic_treechild_nodes(g))
    subarbres = potential_number_of_calls(g)
    # soft
    if subarbres < MAX_SUBARBRES:
        begin_soft = time.time()
        cluster_soft_cache(g)
        end_soft = time.time()
        temps_soft = end_soft - begin_soft
        begin_soft_cache = time.time()
        for i in range(SOFT_TIMES):
            cluster_soft_cache(g)
        end_soft_cache = time.time()
        temps_soft_cache = (end_soft_cache - begin_soft_cache) / SOFT_TIMES
    else:
        temps_soft, temps_soft_cache = -1, -1
    # tree-child
    if not es_treechild:
        begin_families = time.time()
        families = construct_treechild(g)
        end_families = time.time()
        n_families = len(families)
        temps_families = end_families - begin_families
    else:
        n_families, temps_families = 0, 0
    BenchmarkCase.create(
        test = test,
        fulles = fulles,
        nodes = nodes,
        arestes = arestes,
        hibrids = hibrids,
        subarbres = subarbres,
        grau_hibriditzacio = grau_hibriditzacio,
        temps_soft = temps_soft,
        temps_soft_cache = temps_soft_cache,
        arestes_llevables = arestes_llevables,
        es_treechild = es_treechild,
        nodes_conflictius = nodes_conflictius,
        temps_families = temps_families,
        n_families = n_families,
    )
Example #4
0
def enewick_to_digraph(s):
    try:
        parsed = make_enewick_parser()(s)[0]
    except pyparsing.ParseException:
        raise MalformedNewickException("Malformed eNewick string")
    g = nx.DiGraph()
    _walk(g, parsed)
    # is_leaf = lambda x: not g.successors(x)
    # dfs = lambda x: dfs_preorder_nodes(g, x)
    trans_leafs = {}
    # remove the initial «#»
    for leaf in cluster_networks.get_leaf_nodes(g):
        trans_leafs[leaf] = re.sub("#", "", leaf)
    g = nx.relabel_nodes(g, trans_leafs)
    return g
Example #5
0
def benchmark_nets(g):
    # atributs varis
    arestes_llevables = len(removable_edges(g))
    fulles = len(get_leaf_nodes(g))
    nodes = len(g.nodes())
    arestes = len(g.edges())
    hibrids = len(hybrid_nodes(g))
    grau_hibriditzacio = hybridization_degree(g)
    es_treechild = is_treechild(g)
    nodes_conflictius = len(problematic_treechild_nodes(g))
    subarbres = potential_number_of_calls(g)
    temps_soft, temps_soft_cache = -1, -1
    n_families, temps_families = -1, -1
    # tree-child
    if not es_treechild:
        if arestes_llevables < MAX_ARESTES:
            begin_families = time.time()
            families = construct_treechild(g)
            end_families = time.time()
            temps_families = end_families - begin_families
            n_families = len(families)
    else:
        n_families, temps_families = 0, 0
    BenchmarkCase.create(
        test=TEST_NUMBER,
        fulles=fulles,
        nodes=nodes,
        arestes=arestes,
        hibrids=hibrids,
        subarbres=subarbres,
        grau_hibriditzacio=grau_hibriditzacio,
        temps_soft=temps_soft,
        temps_soft_cache=temps_soft_cache,
        arestes_llevables=arestes_llevables,
        es_treechild=es_treechild,
        nodes_conflictius=nodes_conflictius,
        temps_families=temps_families,
        n_families=n_families,
    )