/* See {msm_image_tools.h} */ /* Last edited on 2008-01-29 17:21:29 by hcgl */ #define msm_image_tools_C_COPYRIGHT \ "Copyright � 2007 by the State University of Campinas (UNICAMP)" #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void msm_image_seq_seq_score_write_named ( msm_seq_desc_t *xp, msm_seq_desc_t *yp, msm_rung_score_proc_t *score, msm_pairing_t *pr, char *name, char *tag ) { int nx = xp->npos; int ny = yp->npos; msm_image_t *gim = msm_image_alloc(1, nx, ny,TRUE); fprintf(stderr, " image size = %d � %d scale factor = %d\n", nx, ny, gim->scale); /* Paint the sample-to-sample distances: */ msm_image_seq_seq_score_paint(xp, yp, score, gim, 0, 0); /* Find pixel value range: */ double lov, hiv; msm_image_compute_min_max_range(gim, 0, &lov, &hiv); /* Compute the maximum abs value of data: */ double maxf = (fabs(lov) > fabs(hiv) ? fabs(lov) : fabs(hiv)); /* Reduce that value to better show the interesting part of the plot: */ maxf = 0.25*maxf; /* Colorize the image: */ msm_image_t *cim = msm_image_colorize(gim, maxf); if (pr != NULL) { float clr[3] = { 0.000, 0.700, 0.000 }; /* Dark green. */ msm_image_pairing_paint(pr, nx, ny, clr, FALSE, cim, 0, 0); } /* Write image: */ msm_image_write_as_pnm(cim, 0, 1, name, tag); /* Reclaim image space: */ float_image_free(gim->fim); free(gim); float_image_free(cim->fim); free(cim); } void msm_image_cand_write_named(msm_cand_t *cd, float v, char *name, char *tag) { /* Get sequence sizes {nx,ny}: */ int nx = cd->seq[0].npos; int ny = cd->seq[1].npos; /* Choose the unscaled image size {nix,niy = nx,ny}, for folded plot: */ int nix = nx, niy = ny; /* Allocate the virtual image {img}: */ msm_image_t *img = msm_image_alloc(1, nix, niy,TRUE); /* Fill the image with "no value": */ float_image_fill(img->fim, (float)(-INF)); /* Paint candidate on image: */ msm_image_cand_paint(cd, &v, FALSE, img, 0, 0); /* Normalize image and write it out: */ msm_image_normalize_and_write_as_pgm(img, name, tag); /* Reclaim image space: */ float_image_free(img->fim); free(img); } void msm_image_cand_vec_write_named ( msm_cand_vec_t *cdv, msm_seq_desc_t *xp, msm_seq_desc_t *yp, bool_t scale, /* TRUE to adjust the scale to avoid large images. */ char *name, char *tag ) { /* Get sequence sizes {nx,ny}: */ int nx = xp->npos; int ny = yp->npos; /* Choose the unscaled image size {nix,niy = nx,ny}, for folded plot: */ int nix = nx, niy = ny; /* Allocate the virtual image {img}: */ msm_image_t *img = msm_image_alloc(1, nix, niy,scale); /* Paint candidates: */ msm_image_cand_vec_paint(cdv, xp, yp, img, 0, 0); /* Normalize image and write it out: */ msm_image_normalize_and_write_as_pgm(img, name, tag); /* Reclaim image space: */ float_image_free(img->fim); free(img); } void msm_image_dyn_tableau_write_named ( int nx, /* Length of first sequence. */ int ny, /* Length of second sequence. */ msm_dyn_tableau_t *tb, /* Tableau to plot. */ msm_rung_t gopt, /* Optimal end-rung or {msm_rung_none} */ bool_t scale, /* TRUE to adjust the scale to avoid large images. */ bool_t colorize, /* TRUE to map scores to RGB colors instead of gray values. */ char *name, /* Prefix for file name. */ char *tag /* Tag for file name. */ ) { /* Find out the X and Y ranges covered by {tb}: */ int xMin, xMax; /* Min and max X in {tb}. */ int yMin, yMax; /* Min and max Y in {tb}. */ msm_dyn_tableau_get_X_Y_ranges(tb, &xMin, &xMax, &yMin, &yMax); fprintf(stderr, "plotting tableau\n"); fprintf(stderr, " coordinate ranges"); fprintf(stderr, "[%4d .. %4d]�[%4d .. %4d]\n", xMin, xMax, yMin, yMax); /* Choose the unscaled image size {nix,niy = nx,ny}, for UNfolded plot: */ int NVX = xMax - xMin + 1; int NVY = yMax - yMin + 1; /* Allocate a virtual greyscale image {gim}: */ msm_image_t *gim = msm_image_alloc(1, NVX, NVY,scale); /* Initialize the image with {-INF}: */ float_image_fill(gim->fim, -INF); /* Paint tableau {tb} into float image {gim}, note maximum abs value {maxf}: */ msm_image_dyn_tableau_scores_paint(nx, ny, tb, gim, xMin, yMin); /* Find the pixel value range {[-maxf _ +maxf]}: */ double lov, hiv; msm_image_compute_min_max_range(gim, 0, &lov, &hiv); double maxf = (fabs(lov) > fabs(hiv) ? fabs(lov) : fabs(hiv)); float opath_clr[3]; /* Color for the optimum path. */ msm_image_t *cim = NULL; double vmin,vmax; if(colorize){ /* Convert {gim} to a color pnm image. Maps 0 to gray, {-maxf} to blue, {+maxf} to red. */ cim = msm_image_colorize(gim, maxf); assert(cim->fim->sz[0] == 3); /* Hope so. */ /* Paint the indices that are multiples of {nx} or {ny} in green: */ opath_clr[0] = 0.000; opath_clr[1] = 0.800; opath_clr[2] = 0.000; /* Slightly dark reddish yellow */ vmin = 0; vmax = 1; }else{ cim = gim; assert(cim->fim->sz[0] == 1); /* Hope so. */ opath_clr[0] = opath_clr[1] = opath_clr[2] = 0.000; /* Black. */ vmin = lov; vmax = hiv; } /* Paint the optimum path: */ msm_image_dyn_tableau_pairing_paint(nx, ny, tb, gopt, opath_clr, cim, xMin, yMin); /* Write {cim} to PPM image. */ msm_image_write_as_pnm(cim, vmin, vmax, name, tag); /* Reclaim the image's storage: */ if(cim != gim) { float_image_free(cim->fim); free(cim); } float_image_free(gim->fim); free(gim); }