File: plot_quality.c

package info (click to toggle)
staden 2.0.0%2Bb11-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 21,556 kB
  • sloc: ansic: 240,603; tcl: 65,360; cpp: 12,854; makefile: 11,201; sh: 2,952; fortran: 2,033; perl: 63; awk: 46
file content (159 lines) | stat: -rw-r--r-- 3,662 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <tk.h>
#include "IO1.h"
#include "newgap_cmds.h"
#include "template_display.h"
#include "gap_globals.h"
#include "misc.h"
#include "qual.h"

/* frame name for tk */
#define FRAME_LEN 30

void
glevel(char current,
       float Y0,
       float YP1,
       float YP2,
       float YM1,
       float YM2,
       float *yfrom,
       float *yto)
{
    switch(current) {
    case R_GOOD_GOOD_EQ:
        *yfrom = Y0;
        *yto = Y0;
	break;
    case R_GOOD_NONE:
        *yfrom = Y0;
        *yto = YM1;
	break;
    case R_NONE_GOOD:
        *yfrom = Y0;
        *yto = YP1;
	break;
    case R_BAD_BAD:
        *yfrom = YP1;
        *yto = YM1;
	break;
    case R_GOOD_GOOD_NE:
        *yfrom = YP2;
        *yto = YM2;
	break;
    case R_GOOD_BAD:
        *yfrom = Y0;
        *yto = YM1;
	break;
    case R_BAD_GOOD:
        *yfrom = Y0;
        *yto = YP1;
	break;
    case R_BAD_NONE:
        *yfrom = YP1;
        *yto = YM1;
	break;
    case R_NONE_BAD:
        *yfrom = YP1;
        *yto = YM1;
	break;
    case R_NONE_NONE:
	break;
        *yfrom = YP1;
        *yto = YM1;
    default:
        verror(ERR_FATAL, "quality_plot","incorrect value to glevel()");
    }
} /* end glevel */

/*
 * Removes a quality plot from the item display
 */
void plot_quality_shutdown(char *win_name) {
    Tcl_VarEval(GetInterp(), "DeleteQualPlot ", win_name, NULL);
}

/*
 * each code has its own level and we draw rectangles for segments of
 * the same code
 * The coordinate system is xmin to xmax, and ymin to ymax which here
 * are set to 1, sequence_length; -2, 2
 */
void
plot_quality(char *seq,
	     int seq_len,
             char *win_name,
	     GapIO *io,
	     int init)
{
    float Y0  = 0.;
    float YP1 = 1.;
    float YP2 = 2.;
    float YM1 = -1.;
    float YM2 = -2.;
    int xmin = 0;
    int xmax = seq_len;
    float ymin = YM2;
    float ymax = YP2;
    int i;
    int xfrom, xto;
    float yfrom, yto;
    char current;
    char cmd[1024];

    char q_name[FRAME_LEN];
    char *scroll = "x";

    sprintf(q_name, "%s.quality", win_name);

    if (init) {
	/* add a new canvas to current view */
	/* view = cur_view; */
	sprintf(cmd, "CreateQualPlot %d %s %d %d", *handle_io(io), win_name,
		xmin, xmax);
	Tcl_Eval(GetInterp(), cmd);
	sprintf(cmd, "%s,disp_quality", win_name);
    } else {
	/* Delete the old plot */
 	Tcl_VarEval(GetInterp(), q_name, " delete all", NULL);
    }

    i = 1;
    current = seq[i];
    xfrom = i;
    while (i < seq_len) {
        if (current != seq[i]) {
            /* printf("not equal cur %c seq(%d) %c \n", current, i, seq[i]); */
            glevel(current, Y0, YP1, YP2, YM1, YM2, &yfrom, &yto);
	    xto = i /* - 1 */;

	    sprintf(cmd,"plot_rec %s %d %.20f %d %.20f "
		    "%.20f %.20f %.20f %.20f %.20f %.20f %.20f",
		    q_name, xfrom, yfrom, xto, yto,
		    Y0, YP1, YP2, YM1, YM2,
		    ymin, ymax);
#ifdef DEBUG
	    printf("%s %s \n", GetInterpResult(), cmd);
#endif
	    Tcl_Eval(GetInterp(), cmd);
            current = seq[i];
	    xfrom = i;
        }
        i++;
    }
    /* we have reached the end so finish off last rectangle */
    glevel(current, Y0, YP1, YP2, YM1, YM2, &yfrom, &yto);
    xto = i;
    sprintf(cmd,"plot_rec %s %d %.20f %d %.20f "
            "%.20f %.20f %.20f %.20f %.20f %.20f %.20f",
            q_name, xfrom, yfrom, xto, yto,
            Y0, YP1, YP2, YM1, YM2,
            ymin, ymax);
    Tcl_Eval(GetInterp(), cmd);

    /* dreadful hack necessary because C doesn't know about the Consts that
     * tcl knows about
     */
    sprintf(cmd, "SetQualityCanvas %s %s %s %d %d", q_name, win_name, scroll, xmin, xmax);
    Tcl_Eval(GetInterp(), cmd);

}