static void makeMap (SparseMatrix graph, int n, real* x, real* width, int* grouping, char** labels, float* fsz, float* rgb_r, float* rgb_g, float* rgb_b, params_t* pm, Agraph_t* g ) { int dim = pm->dim; int i, flag = 0; SparseMatrix poly_lines, polys, poly_point_map; real edge_bridge_tol = 0.; int npolys, nverts, *polys_groups, exclude_random; real *x_poly, *xcombined; enum {max_string_length = 1000}; enum {MAX_GRPS = 10000}; SparseMatrix country_graph; int improve_contiguity_n = pm->improve_contiguity_n; #ifdef TIME clock_t cpu; #endif int nr0, nart0; int nart, nrandom; exclude_random = TRUE; #if 0 if (argc >= 2) { fp = fopen(argv[1],"r"); graph = SparseMatrix_import_matrix_market(fp, FORMAT_CSR); } if (whatout == OUT_M){ printf("Show[{"); } #endif #ifdef TIME cpu = clock(); #endif nr0 = nrandom = pm->nrandom; nart0 = nart = pm->nart; make_map_from_rectangle_groups(exclude_random, pm->include_OK_points, n, dim, x, width, grouping, graph, pm->bbox_margin, &nrandom, &nart, pm->nedgep, pm->shore_depth_tol, edge_bridge_tol, &xcombined, &nverts, &x_poly, &npolys, &poly_lines, &polys, &polys_groups, &poly_point_map, &country_graph, pm->highlight_cluster, &flag); /* compute a good color permutation */ if (pm->color_optimize && country_graph && rgb_r && rgb_g && rgb_b) map_optimal_coloring(pm->seed, country_graph, rgb_r, rgb_g, rgb_b); #ifdef TIME fprintf(stderr, "map making time = %f\n",((real) (clock() - cpu)) / CLOCKS_PER_SEC); #endif /* now we check to see if all points in the same group are also in the same polygon, if not, the map is not very contiguous so we move point positions to improve contiguity */ if (graph && improve_contiguity_n) { for (i = 0; i < improve_contiguity_n; i++){ improve_contiguity(n, dim, grouping, poly_point_map, x, graph, width); nart = nart0; nrandom = nr0; make_map_from_rectangle_groups(exclude_random, pm->include_OK_points, n, dim, x, width, grouping, graph, pm->bbox_margin, &nrandom, &nart, pm->nedgep, pm->shore_depth_tol, edge_bridge_tol, &xcombined, &nverts, &x_poly, &npolys, &poly_lines, &polys, &polys_groups, &poly_point_map, &country_graph, pm->highlight_cluster, &flag); } assert(!flag); { SparseMatrix D; D = SparseMatrix_get_real_adjacency_matrix_symmetrized(graph); remove_overlap(dim, D, x, width, 1000, 5000., ELSCHEME_NONE, 0, NULL, NULL, &flag); nart = nart0; nrandom = nr0; make_map_from_rectangle_groups(exclude_random, pm->include_OK_points, n, dim, x, width, grouping, graph, pm->bbox_margin, &nrandom, &nart, pm->nedgep, pm->shore_depth_tol, edge_bridge_tol, &xcombined, &nverts, &x_poly, &npolys, &poly_lines, &polys, &polys_groups, &poly_point_map, &country_graph, pm->highlight_cluster, &flag); } assert(!flag); } #if 0 if (whatout == OUT_DOT){ #endif Dot_SetClusterColor(g, rgb_r, rgb_g, rgb_b, grouping); plot_dot_map(g, n, dim, x, polys, poly_lines, pm->line_width, pm->line_color, x_poly, polys_groups, labels, width, fsz, rgb_r, rgb_g, rgb_b, pm->plot_label, pm->bg_color, (pm->plotedges?graph:NULL), pm->outfile); #if 0 } goto RETURN; }
void remove_overlap(int dim, SparseMatrix A, real *x, real *label_sizes, int ntry, real initial_scaling, int edge_labeling_scheme, int n_constr_nodes, int *constr_nodes, SparseMatrix A_constr, int do_shrinking, int *flag){ /* edge_labeling_scheme: if ELSCHEME_NONE, n_constr_nodes/constr_nodes/A_constr are not used n_constr_nodes: number of nodes that has constraints, these are nodes that is . constrained to be close to the average of its neighbors. constr_nodes: a list of nodes that need to be constrained. If NULL, unused. A_constr: neighbors of node i are in the row i of this matrix. i needs to sit . in between these neighbors as much as possible. this must not be NULL . if constr_nodes != NULL. */ real lambda = 0.00; OverlapSmoother sm; int include_original_graph = 0, i; real LARGE = 100000; real avg_label_size, res = LARGE; real max_overlap = 0, min_overlap = 999; int neighborhood_only = TRUE; int has_penalty_terms = FALSE; real epsilon = 0.005; int shrink = 0; #ifdef TIME clock_t cpu; #endif #ifdef TIME cpu = clock(); #endif if (!label_sizes) return; if (initial_scaling < 0) { avg_label_size = 0; for (i = 0; i < A->m; i++) avg_label_size += label_sizes[i*dim]+label_sizes[i*dim+1]; /* for (i = 0; i < A->m; i++) avg_label_size += 2*MAX(label_sizes[i*dim],label_sizes[i*dim+1]);*/ avg_label_size /= A->m; scale_to_edge_length(dim, A, x, -initial_scaling*avg_label_size); } else if (initial_scaling > 0){ scale_to_edge_length(dim, A, x, initial_scaling); } if (!ntry) return; *flag = 0; #ifdef DEBUG _statistics[0] = _statistics[1] = 0.; {FILE*fp; fp = fopen("x1","w"); for (i = 0; i < A->m; i++){ fprintf(fp, "%f %f\n",x[i*2],x[i*2+1]); } fclose(fp); } #endif #ifdef ANIMATE {FILE*fp; fp = fopen("/tmp/m","wa"); fprintf(fp,"{"); #endif has_penalty_terms = (edge_labeling_scheme != ELSCHEME_NONE && n_constr_nodes > 0); for (i = 0; i < ntry; i++){ if (Verbose) print_bounding_box(A->m, dim, x); sm = OverlapSmoother_new(A, A->m, dim, lambda, x, label_sizes, include_original_graph, neighborhood_only, &max_overlap, &min_overlap, edge_labeling_scheme, n_constr_nodes, constr_nodes, A_constr, shrink); if (Verbose) fprintf(stderr, "overlap removal neighbors only?= %d iter -- %d, overlap factor = %g underlap factor = %g\n", neighborhood_only, i, max_overlap - 1, min_overlap); if (check_convergence(max_overlap, res, has_penalty_terms, epsilon)){ OverlapSmoother_delete(sm); if (neighborhood_only == FALSE){ break; } else { res = LARGE; neighborhood_only = FALSE; if (do_shrinking) shrink = 1; continue; } } res = OverlapSmoother_smooth(sm, dim, x); if (Verbose) fprintf(stderr,"res = %f\n",res); #ifdef ANIMATE if (i != 0) fprintf(fp,","); export_embedding(fp, dim, A, x, label_sizes); #endif OverlapSmoother_delete(sm); } if (Verbose) fprintf(stderr, "overlap removal neighbors only?= %d iter -- %d, overlap factor = %g underlap factor = %g\n", neighborhood_only, i, max_overlap - 1, min_overlap); #ifdef ANIMATE fprintf(fp,"}"); fclose(fp); } #endif if (has_penalty_terms){ /* now do without penalty */ remove_overlap(dim, A, x, label_sizes, ntry, 0., ELSCHEME_NONE, 0, NULL, NULL, do_shrinking, flag); } #ifdef DEBUG fprintf(stderr," number of cg iter = %f, number of stress majorization iter = %f number of overlap removal try = %d\n", _statistics[0], _statistics[1], i - 1); {FILE*fp; fp = fopen("x2","w"); for (i = 0; i < A->m; i++){ fprintf(fp, "%f %f\n",x[i*2],x[i*2+1]); } fclose(fp); } #endif #ifdef DEBUG {FILE*fp; fp = fopen("/tmp/m","w"); if (A) export_embedding(fp, dim, A, x, label_sizes); fclose(fp); } #endif #ifdef TIME fprintf(stderr, "post processing %f\n",((real) (clock() - cpu)) / CLOCKS_PER_SEC); #endif }
int main(int argc, char ** argv) { clock_t t0; t0 = clock(); bool print = true; if (argc==1) { help(); exit(0); } std::string cmd(argv[1]); //primitive programs that do not require help pages and summary statistics by default if (argc>1 && cmd=="view") { print = view(argc-1, ++argv); } else if (argc>1 && cmd=="index") { print = index(argc-1, ++argv); } else if (argc>1 && cmd=="merge") { print = merge(argc-1, ++argv); } else if (argc>1 && cmd=="paste") { print = paste(argc-1, ++argv); } else if (argc>1 && cmd=="concat") { print = concat(argc-1, ++argv); } else if (argc>1 && cmd=="subset") { subset(argc-1, ++argv); } else if (argc>1 && cmd=="decompose") { decompose(argc-1, ++argv); } else if (argc>1 && cmd=="normalize") { print = normalize(argc-1, ++argv); } else if (argc>1 && cmd=="config") { config(argc-1, ++argv); } else if (argc>1 && cmd=="mergedups") { merge_duplicate_variants(argc-1, ++argv); } else if (argc>1 && cmd=="remove_overlap") { remove_overlap(argc-1, ++argv); } else if (argc>1 && cmd=="peek") { peek(argc-1, ++argv); } else if (argc>1 && cmd=="partition") { partition(argc-1, ++argv); } else if (argc>1 && cmd=="annotate_variants") { annotate_variants(argc-1, ++argv); } else if (argc>1 && cmd=="annotate_regions") { annotate_regions(argc-1, ++argv); } else if (argc>1 && cmd=="annotate_dbsnp_rsid") { annotate_dbsnp_rsid(argc-1, ++argv); } else if (argc>1 && cmd=="discover") { discover(argc-1, ++argv); } else if (argc>1 && cmd=="merge_candidate_variants") { merge_candidate_variants(argc-1, ++argv); } else if (argc>1 && cmd=="union_variants") { union_variants(argc-1, ++argv); } else if (argc>1 && cmd=="genotype") { genotype2(argc-1, ++argv); } else if (argc>1 && cmd=="characterize") { genotype(argc-1, ++argv); } else if (argc>1 && cmd=="construct_probes") { construct_probes(argc-1, ++argv); } else if (argc>1 && cmd=="profile_indels") { profile_indels(argc-1, ++argv); } else if (argc>1 && cmd=="profile_snps") { profile_snps(argc-1, ++argv); } else if (argc>1 && cmd=="profile_mendelian") { profile_mendelian(argc-1, ++argv); } else if (argc>1 && cmd=="profile_na12878") { profile_na12878(argc-1, ++argv); } else if (argc>1 && cmd=="profile_chrom") { profile_chrom(argc-1, ++argv); } else if (argc>1 && cmd=="align") { align(argc-1, ++argv); } else if (argc>1 && cmd=="compute_features") { compute_features(argc-1, ++argv); } else if (argc>1 && cmd=="profile_afs") { profile_afs(argc-1, ++argv); } else if (argc>1 && cmd=="profile_hwe") { profile_hwe(argc-1, ++argv); } else if (argc>1 && cmd=="profile_len") { profile_len(argc-1, ++argv); } else if (argc>1 && cmd=="annotate_str") { annotate_str(argc-1, ++argv); } else if (argc>1 && cmd=="consolidate_variants") { consolidate_variants(argc-1, ++argv); } else { std::clog << "Command not found: " << argv[1] << "\n\n"; help(); exit(1); } if (print) { clock_t t1; t1 = clock(); print_time((float)(t1-t0)/CLOCKS_PER_SEC); } return 0; }