Ejemplo n.º 1
0
Archivo: graph.c Proyecto: gyc2015/GYC
/*
 * new_graph
 *
 * @graph: an uninitialized graph.
 * @edges: the edges to add, the first two elements refer to
 *         the "from" and "to" items of the first edge respectively.
 * @n: the number of vertices.
 * @directed: specifies whether the created graph is directed.
 */
int new_graph(graph_t *graph, vector_int *edges,int n, int directed)
{
	assert(0 == (vector_int_size(edges) % 2));
	assert(0 <= vector_int_min(edges));

	int max = vector_int_max(edges);
	n = (n > max) ? n : (max + 1);
	new_graph_empty(graph, n, directed);
	if (vector_int_size(edges) > 0)
		graph_add_edges(graph, edges,0);

	return 0;
}
Ejemplo n.º 2
0
int graph_randomized_graph(graph_t *graph, int vc, int ec, int directed)
{
    new_graph_empty(graph, vc, directed);
    vector_int edges;
    vector_int_init(&edges, 2);

    graph_neimode_t mode = (directed) ? GRAPH_OUT : GRAPH_ALL;
    int v = 0, w = 0, i = 0;
    while(i < ec) {
        while (v == w || graph_edge_contains(graph, v, w, mode)) {
            v = random() % vc;
            w = random() % vc;
        }
        VECTOR(edges)[0] = v;
        VECTOR(edges)[1] = w;
        graph_add_edges(graph, &edges, 0);
        i++;
    }

    vector_int_destroy(&edges);
    return 0;
}
Ejemplo n.º 3
0
dstring_t *haplo_split(GapIO *io, snp_t *snp, int nsnps, int verbose,
		       double min_score, int two_pass, int fast_mode,
		       double c_offset, int max_sets) {
    graph *g;
    edge *e;
    dstring_t *ds;

    verbosity = verbose;
    g = graph_from_snps(io, snp, nsnps, c_offset);
    if (verbosity >= 3)
	print_matrix(g);

    graph_add_edges(g);
    graph_calc_chimeric_scores(g);
    graph_calc_link_scores(g, 1);
    if (verbosity >= 3)
	graph_print(g, 0);

    if (verbosity)
	puts("Merging graph nodes");

    while ((e = best_edge(g)) && (e->linkage_score > min_score)) {
	if (verbosity >= 1) {
	    putchar('.');
	    fflush(stdout);
	}
	merge_node(g, e);
	graph_calc_link_scores(g, fast_mode ? 0 : 1);
	if (verbosity >= 4) {
	    print_matrix(g);
	    graph_print(g, 1);
	}
    }
    if (verbosity >= 1)
	puts("");

    /* graph_print(g, 1); */

    if (two_pass) {
	/* Add fake zero-score edges if we want just 2-haplotypes */
	add_zero_edges(g);
	graph_calc_link_scores(g, 1);
	if (verbosity >= 4)
	    graph_print(g, 1);

	puts("===pass 2===");
	while ((e = best_edge(g)) && (e->linkage_score > min_score)) {
	    merge_node(g, e);
	    graph_calc_link_scores(g, fast_mode ? 0 : 1);
	    /* graph_print(g, 1); */
	}
	/* graph_print(g, 1); */
    }

    /* Force number of groups to be X? */
    if (max_sets) {
	int ngroups = count_groups(g);
	add_zero_edges(g);
	for (; ngroups > max_sets; ngroups--) {
	    e = best_edge(g);
	    if (!e) {
		printf("Bailed out as no edge connecting groups\n");
		break;
	    }
	    merge_node(g, e);
	    graph_calc_link_scores(g, fast_mode ? 0 : 1);
	}
    }

    /* print_groups(g); */

    ds = list_groups(g);
    graph_destroy(g);

    return ds;
}