Debian Codegraph @

hmmer/src/heatmap.c

raw symbols SCIP
1 /* working version of heat map displays in PostScript
2 * evolving toward eventual inclusion in Easel
3 *
4 * SRE, Thu Jan 25 09:51:18 2007 [Janelia] [Elgar, Enigma Variations]
5 */
6 #include <p7_config.h>
7
8 #include <stdio.h>
9 #include <math.h>
10
11 #include "easel.h"
12 #include "esl_dmatrix.h"
13
14
15 /* dmx_Visualize()
16 * Incept: SRE, Wed Jan 24 11:58:21 2007 [Janelia]
17 *
18 * Purpose:
19 *
20 * Color scheme roughly follows Tufte, Envisioning
21 * Information, p.91, where he shows a beautiful
22 * bathymetric chart. The CMYK values conjoin two
23 * recommendations from ColorBrewer (Cindy Brewer
24 * and Mark Harrower)
25 * [http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer.html],
26 * specifically the 9-class sequential2 Blues and
27 * 9-class sequential YlOrBr.
28 *
29 * Might eventually become part of Easel, once mature?
30 *
31 * Note: Binning rules basically follow same convention as
32 * esl_histogram. nb = xmax-xmin/w, so w = xmax-xmin/nb;
33 * picking bin is (int) ceil((x - xmin)/w) - 1. (xref
34 * esl_histogram_Score2Bin()). This makes bin b contain
35 * values bw+min < x <= (b+1)w+min. (Which means that
36 * min itself falls in bin -1, whoops - but we catch
37 * all bin<0 and bin>=nshades and put them in the extremes.
38 *
39 * Args:
40 *
41 * Returns:
42 *
43 * Throws: (no abnormal error conditions)
44 *
45 * Xref:
46 */
47 int
48 dmx_Visualize(FILE *fp, ESL_DMATRIX *D, double min, double max)
49 {
50 int nshades = 18;
51 double cyan[] = { 1.00, 1.00, 0.90, 0.75, 0.57, 0.38, 0.24, 0.13, 0.03,
52 0.00, 0.00, 0.00, 0.00, 0.00, 0.07, 0.20, 0.40, 0.60};
53 double magenta[] = { 0.55, 0.45, 0.34, 0.22, 0.14, 0.08, 0.06, 0.03, 0.01,
54 0.00, 0.03, 0.11, 0.23, 0.40, 0.55, 0.67, 0.75, 0.80};
55 double yellow[] = { 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
56 0.10, 0.25, 0.40, 0.65, 0.80, 0.90, 1.00, 1.00, 1.00};
57 double black[] = { 0.30, 0.07, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
58 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00};
59 double w;
60 int i,j;
61 int bin;
62 int boxsize; /* box size in points */
63 int xcoord, ycoord; /* postscript coords in points */
64 int leftmargin;
65 int bottommargin;
66
67 /* Set some defaults that might become arguments later.
68 */
69 leftmargin = 20;
70 bottommargin = 20;
71
72 /* Determine some working parameters
73 */
74 w = (max-min) / (double) nshades; /* w = bin size for assigning values->colors*/
75 boxsize = ESL_MIN( (792 - bottommargin) / D->n,
76 (612 - leftmargin) / D->m);
77
78 /* or start from j=i, to do diagonals */
79
80 for (i = 0; i < D->n; i++)
81 for (j = 0; j < D->m; j++)
82 {
83 xcoord = j * boxsize + leftmargin;
84 ycoord = (D->n-i+1) * boxsize + bottommargin;
85
86 if (D->mx[i][j] == -eslINFINITY) bin = 0;
87 else if (D->mx[i][j] == eslINFINITY) bin = nshades-1;
88 else {
89 bin = (int) ceil((D->mx[i][j] - min) / w) - 1;
90 if (bin < 0) bin = 0;
91 if (bin >= nshades) bin = nshades-1;
92 }
93
94 fprintf(fp, "newpath\n");
95 fprintf(fp, " %d %d moveto\n", xcoord, ycoord);
96 fprintf(fp, " 0 %d rlineto\n", boxsize);
97 fprintf(fp, " %d 0 rlineto\n", boxsize);
98 fprintf(fp, " 0 -%d rlineto\n", boxsize);
99 fprintf(fp, " closepath\n");
100 fprintf(fp, " %.2f %.2f %.2f %.2f setcmykcolor\n",
101 cyan[bin], magenta[bin], yellow[bin], black[bin]);
102 fprintf(fp, " fill\n");
103 }
104 fprintf(fp, "showpage\n");
105 return eslOK;
106 }