~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to draw_plots.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                draw_plots.c
 
6
 
 
7
Purpose:
 
8
        Draw hydrophobicity plots.  This function is used if the main win.
 
9
        drawing mode is equal to four. The sequence stored to the sequence
 
10
        buffer is used to calculate requested functions.
 
11
 
 
12
Input:
 
13
        (1) Pointer to RuntimeS structure, with some runtime data.
 
14
        (2) Pointer to GUIS structure, with GUI data.
 
15
        (3) Pointer to NearestAtomS structure,  with information about the
 
16
            atom occupying the given pixel.
 
17
        (4) The number of pixels in the main window free area.
 
18
        (5) The refreshI,  used to check the  NearestAtomS associated with
 
19
            a given pixel. It is currently unused in this function.
 
20
 
 
21
Output:
 
22
        (1) Hydrophobicity plots should be drawn to the main window.
 
23
        (2) Return value.
 
24
 
 
25
Return value:
 
26
        (1) The number of residues used in calculation.
 
27
 
 
28
Notes:
 
29
        (1) The initial drawing destination is the hidden pixmap,  and the
 
30
            content of this pixmap is copied later to the main window.
 
31
 
 
32
        (2) The residue index is stored as the atomic index.  The function
 
33
            value  (averaged hydrophobicity,  hydrophobic moment etc.)  is
 
34
            stored as z coordinate.
 
35
 
 
36
========includes:============================================================*/
 
37
 
 
38
#include <stdio.h>
 
39
 
 
40
#include <string.h>
 
41
#include <math.h>
 
42
 
 
43
#include <X11/Xlib.h>
 
44
#include <X11/Xutil.h>
 
45
#include <X11/Xos.h>
 
46
#include <X11/Xatom.h>
 
47
 
 
48
#include "defines.h"
 
49
#include "typedefs.h"
 
50
 
 
51
/*======function prototypes:=================================================*/
 
52
 
 
53
int             RefreshPixmap_ (Display *, Pixmap, GC,
 
54
                                unsigned int, unsigned int, unsigned long);
 
55
int             ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *);
 
56
 
 
57
/*======draw hydrophobicity plots:===========================================*/
 
58
 
 
59
size_t DrawPlots_ (RuntimeS *runtimeSP, GUIS *guiSP,
 
60
                  NearestAtomS *nearest_atomSP, size_t pixelsN,
 
61
                  unsigned int refreshI)
 
62
{
 
63
int             residuesN, residueI;   /* Do not use size_t instead of int ! */
 
64
int             used_residuesN;
 
65
int             serialI, range_startI, range_endI, residues_in_plotN = 0;
 
66
int             plotI = 0;
 
67
int             window_width, half_window_width, windowI, combinedI;
 
68
double          angle_step, angle;
 
69
double          hydrophobicity, averaged_hydrophobicity = 0;
 
70
double          min_average_hyphob, max_average_hyphob;
 
71
double          hydrophobic_moment, abs_squared, moment_x, moment_y;
 
72
double          min_hyphob_moment, max_hyphob_moment;
 
73
int             screen_width, screen_height;
 
74
int             screen_margin_x, screen_margin_top, screen_margin_bottom;
 
75
int             screen_delta_x, screen_delta_y;
 
76
int             residue_screen_width, half_residue_width;
 
77
int             residues_per_sectionN;
 
78
int             sectionsN, sectionI;
 
79
int             section_width, section_height;
 
80
int             frame_x0, frame_x1, frame_y0, frame_y1;
 
81
int             section_y0;
 
82
unsigned long   color1ID, color2ID, color3ID, color4ID;
 
83
RGBS            rgbS;
 
84
double          ordinate_min, ordinate_max, ordinate_range, ordinate_scale;
 
85
int             local_residueI;
 
86
int             screen_x0, screen_x1, screen_y0, screen_y1;
 
87
double          d;
 
88
int             residue_serialI;
 
89
char            stringA[SHORTSTRINGSIZE];
 
90
int             string_length;
 
91
int             text_height, text_ascent, text_width, half_text_width;
 
92
int             old_screen_y = 0, screen_x, screen_y;
 
93
int             draw_vertical_lineF = 0;
 
94
size_t          pixelI;
 
95
NearestAtomS    *curr_pixelSP;
 
96
int             shift = 0;
 
97
 
 
98
/*------prepare some parameters:---------------------------------------------*/
 
99
 
 
100
/* The number of residues in sequence buffer: */
 
101
residuesN = (int) runtimeSP->residuesN;
 
102
if (residuesN == 0)
 
103
        {
 
104
        strcpy (runtimeSP->messageA, "The sequence buffer is empty!");
 
105
        runtimeSP->message_length = strlen (runtimeSP->messageA);
 
106
        return 0;
 
107
        }
 
108
 
 
109
/* Paranoid check - at least one flag should be different from zero: */
 
110
if ((runtimeSP->averaged_hydrophobicityF == 0) &&
 
111
    (runtimeSP->hydrophobic_momentF      == 0)) return 0;
 
112
 
 
113
/* Residue serial range: */
 
114
range_startI = runtimeSP->range_startI;
 
115
range_endI   = runtimeSP->range_endI;
 
116
 
 
117
/* Count the number of residues in the specified range: */
 
118
for (residueI = 0; residueI < residuesN; residueI++)
 
119
        {
 
120
        /* Check is the residue serial index inside the range: */
 
121
        serialI = *(runtimeSP->serialIP + residueI);
 
122
        if ((serialI < range_startI) || (serialI > range_endI)) continue;
 
123
 
 
124
        /* Increase the count of residues if current */
 
125
        /* residue  belongs to  the specified range: */
 
126
        residues_in_plotN++;
 
127
        }
 
128
 
 
129
/* Check the number of residues in a plot: */
 
130
if (residues_in_plotN == 0)
 
131
        {
 
132
        strcpy (runtimeSP->messageA, "The specified range is empty!");
 
133
        runtimeSP->message_length = strlen (runtimeSP->messageA);
 
134
        return 0;
 
135
        }
 
136
 
 
137
/* The sliding window width: */
 
138
window_width = runtimeSP->sliding_window_width;
 
139
half_window_width = window_width / 2;
 
140
 
 
141
/* The helix step angle: */
 
142
angle_step = DEG_TO_RAD * runtimeSP->helix_step_angle;
 
143
 
 
144
/*------refresh the hidden pixmap:-------------------------------------------*/
 
145
 
 
146
/* Refresh the hidden pixmap, where drawing will be done: */
 
147
RefreshPixmap_ (guiSP->displaySP,
 
148
                guiSP->main_hidden_pixmapID,
 
149
                guiSP->theGCA[0],
 
150
                guiSP->control_winS.x0, guiSP->input_winS.y0,
 
151
                guiSP->main_winS.bg_colorID);
 
152
 
 
153
/*------calculate the averaged hydrophobicity:-------------------------------*/
 
154
 
 
155
/* Initialize the extreme values: */
 
156
min_average_hyphob = +999999;
 
157
max_average_hyphob = -999999;
 
158
 
 
159
/* Scan the sequence: */
 
160
for (residueI = 0; residueI < residuesN; residueI++)
 
161
        {
 
162
        /* Reset the number of residues used for averaging: */
 
163
        used_residuesN = 0;
 
164
 
 
165
        /* Reset the averaged hydrophobicity: */
 
166
        averaged_hydrophobicity = 0.0;
 
167
 
 
168
        /* Scan the sliding window: */
 
169
        for (windowI = 0; windowI < window_width; windowI++)
 
170
                {
 
171
                /* Prepare and check the combined index: */
 
172
                combinedI = residueI - half_window_width + windowI;
 
173
                if (combinedI < 0) continue;
 
174
                if (combinedI >= residuesN) continue;
 
175
 
 
176
                /* The hydrophobicity of the residue defined by combinedI: */
 
177
                hydrophobicity =
 
178
                        (double) *(runtimeSP->hydrophobicityP + combinedI);
 
179
 
 
180
                /* Add hydrophobicity to the total: */
 
181
                averaged_hydrophobicity += hydrophobicity;
 
182
 
 
183
                /* Increase the number of residues used for averaging: */
 
184
                used_residuesN++;
 
185
                }
 
186
 
 
187
        /* Check how many residues were used: */
 
188
        if (used_residuesN == window_width)
 
189
                {
 
190
                averaged_hydrophobicity /= (double) window_width;
 
191
                }
 
192
        else averaged_hydrophobicity = 0.0;
 
193
 
 
194
        /* Store the average hydrophobicity: */
 
195
        *(runtimeSP->averaged_hydrophobicityP + residueI) =
 
196
                                        (float) averaged_hydrophobicity;
 
197
 
 
198
        /* Dummy values should not be used to determine extremes: */
 
199
        if (used_residuesN != window_width) continue;
 
200
 
 
201
        /* Find the extreme values: */
 
202
        if (averaged_hydrophobicity < min_average_hyphob)
 
203
                {
 
204
                min_average_hyphob = averaged_hydrophobicity;
 
205
                }
 
206
        if (averaged_hydrophobicity > max_average_hyphob)
 
207
                {
 
208
                max_average_hyphob = averaged_hydrophobicity;
 
209
                }
 
210
        }
 
211
 
 
212
/*------calculate the hydrophobic moment:------------------------------------*/
 
213
 
 
214
/* Initialize the extreme values: */
 
215
min_hyphob_moment = +999999;
 
216
max_hyphob_moment = -999999;
 
217
 
 
218
/* Scan the sequence: */
 
219
for (residueI = 0; residueI < residuesN; residueI++)
 
220
        {
 
221
        /* Reset the number of residues used for calculation: */
 
222
        used_residuesN = 0;
 
223
 
 
224
        /* Reset the projections: */
 
225
        moment_x = 0.0;
 
226
        moment_y = 0.0;
 
227
 
 
228
        /* Scan the sliding window: */
 
229
        for (windowI = 0; windowI < window_width; windowI++)
 
230
                {
 
231
                /* Prepare and check the combined index: */
 
232
                combinedI = residueI - half_window_width + windowI;
 
233
                if (combinedI < 0) continue;
 
234
                if (combinedI >= residuesN) continue;
 
235
 
 
236
                /* The hydrophobicity of the residue defined by combinedI: */
 
237
                hydrophobicity = *(runtimeSP->hydrophobicityP + combinedI);
 
238
 
 
239
                /* The angle: */
 
240
                angle = angle_step * (double) windowI;
 
241
 
 
242
                /* Hydrophobic moment projections: */
 
243
                moment_x += (double) hydrophobicity * cos (angle);
 
244
                moment_y += (double) hydrophobicity * sin (angle);
 
245
 
 
246
                /* Increase the number of residues used for calculation: */
 
247
                used_residuesN++;
 
248
                }
 
249
 
 
250
        /* Calculate the hydrophobic moment: */
 
251
        abs_squared = moment_x * moment_x + moment_y * moment_y;
 
252
        if (used_residuesN == window_width)
 
253
                {
 
254
                hydrophobic_moment = sqrt (abs_squared) /
 
255
                                     (double) window_width;
 
256
                }
 
257
        else hydrophobic_moment = 0.0;
 
258
 
 
259
        /* Store the hydrophobic moment: */
 
260
        *(runtimeSP->hydrophobic_momentP + residueI) =
 
261
                                        (float) hydrophobic_moment;
 
262
 
 
263
        /* Dummy values should not be used to determine extreme values: */
 
264
        if (used_residuesN != window_width) continue;
 
265
 
 
266
        /* Find the extreme values: */
 
267
        if (hydrophobic_moment < min_hyphob_moment)
 
268
                {
 
269
                min_hyphob_moment = hydrophobic_moment;
 
270
                }
 
271
        if (hydrophobic_moment > max_hyphob_moment)
 
272
                {
 
273
                max_hyphob_moment = hydrophobic_moment;
 
274
                }
 
275
        }
 
276
 
 
277
/*------prepare geometric parameters:----------------------------------------*/
 
278
 
 
279
/* Width, height and margins (margins will be updated later): */
 
280
screen_width  = guiSP->main_win_free_area_width;
 
281
screen_height = guiSP->main_win_free_area_height;
 
282
screen_margin_x = screen_width / 40;
 
283
if (screen_margin_x < 4) screen_margin_x = 4;
 
284
screen_margin_bottom = screen_height / 40;
 
285
if (screen_margin_bottom < 4) screen_margin_bottom = 4;
 
286
screen_margin_top = 2 * screen_margin_bottom + guiSP->main_winS.font_height;
 
287
screen_delta_x = screen_width  - 2 * screen_margin_x;
 
288
if (screen_delta_x < 10) screen_delta_x = 10;
 
289
screen_delta_y = screen_height - screen_margin_top - screen_margin_bottom;
 
290
if (screen_delta_y < 10) screen_delta_y = 10;
 
291
 
 
292
/* Break the entire sequence range  into more */
 
293
/* parts, if the number of residues is large: */
 
294
residue_screen_width = RESIDUE_WIDTH;
 
295
half_residue_width = residue_screen_width / 2;
 
296
if (residue_screen_width <= 0) return 0;
 
297
residues_per_sectionN = screen_delta_x / residue_screen_width;
 
298
if (residues_per_sectionN == 0) sectionsN = 1;
 
299
else sectionsN = (residues_in_plotN + residues_per_sectionN - 1) /
 
300
                  residues_per_sectionN;
 
301
 
 
302
/* The screen height should be divided into equal portions: */
 
303
if (sectionsN == 0) section_height = screen_delta_y;
 
304
else section_height = screen_delta_y / sectionsN;
 
305
 
 
306
/* Avoid ugly proportions: */
 
307
if (section_height / residue_screen_width > 80)
 
308
        {
 
309
        section_height = 80 * residue_screen_width;
 
310
        }
 
311
 
 
312
/* Update plot width, height and margins: */
 
313
if (residues_in_plotN > residues_per_sectionN)
 
314
        {
 
315
        screen_delta_x = residues_per_sectionN  * residue_screen_width;
 
316
        }
 
317
else
 
318
        {
 
319
        screen_delta_x = residues_in_plotN * residue_screen_width;
 
320
        }
 
321
screen_margin_x = (screen_width - screen_delta_x) / 2;
 
322
screen_margin_bottom = (screen_height -
 
323
                        section_height * sectionsN -
 
324
                        guiSP->main_winS.font_height) / 3;
 
325
if (screen_margin_bottom < 4) screen_margin_bottom = 4;
 
326
screen_margin_top = 2 * screen_margin_bottom + guiSP->main_winS.font_height;
 
327
 
 
328
/* Set the section width: */
 
329
section_width = screen_delta_x;
 
330
 
 
331
/*------draw frames:---------------------------------------------------------*/
 
332
 
 
333
/* Frame left and right edge: */
 
334
frame_x0 = screen_margin_x;
 
335
frame_x1 = frame_x0 + section_width;
 
336
 
 
337
/* Frame top and bottom edge: */
 
338
frame_y0 = screen_margin_top;
 
339
frame_y1 = screen_margin_top + sectionsN * section_height;
 
340
 
 
341
/* Prepare colors: */
 
342
ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:3333/3333/3333", "black");
 
343
ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:6666/6666/6666", "black");
 
344
ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:AAAA/AAAA/AAAA", "white");
 
345
ParseColor_ (&rgbS, &color4ID, guiSP, "RGB:EEEE/EEEE/EEEE", "white");
 
346
XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID);
 
347
XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID);
 
348
XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID);
 
349
XSetForeground (guiSP->displaySP, guiSP->theGCA[4], color4ID);
 
350
XSetForeground (guiSP->displaySP, guiSP->theGCA[5], color3ID);
 
351
XSetForeground (guiSP->displaySP, guiSP->theGCA[6], color2ID);
 
352
XSetForeground (guiSP->displaySP, guiSP->theGCA[7], color1ID);
 
353
 
 
354
/* Draw vertical lines: */
 
355
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1],
 
356
           frame_x0 - 3, frame_y0 - 3, frame_x0 - 3, frame_y1 + 3);
 
357
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2],
 
358
           frame_x0 - 2, frame_y0 - 3, frame_x0 - 2, frame_y1 + 3);
 
359
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3],
 
360
           frame_x0 - 1, frame_y0 - 3, frame_x0 - 1, frame_y1 + 3);
 
361
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4],
 
362
           frame_x0 - 0, frame_y0 - 3, frame_x0 - 0, frame_y1 + 3);
 
363
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[5],
 
364
           frame_x0 + 1, frame_y0 - 3, frame_x0 + 1, frame_y1 + 3);
 
365
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[6],
 
366
           frame_x0 + 2, frame_y0 - 3, frame_x0 + 2, frame_y1 + 3);
 
367
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[7],
 
368
           frame_x0 + 3, frame_y0 - 3, frame_x0 + 3, frame_y1 + 3);
 
369
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1],
 
370
           frame_x1 - 3, frame_y0 - 3, frame_x1 - 3, frame_y1 + 3);
 
371
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2],
 
372
           frame_x1 - 2, frame_y0 - 3, frame_x1 - 2, frame_y1 + 3);
 
373
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3],
 
374
           frame_x1 - 1, frame_y0 - 3, frame_x1 - 1, frame_y1 + 3);
 
375
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4],
 
376
           frame_x1 - 0, frame_y0 - 3, frame_x1 - 0, frame_y1 + 3);
 
377
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[5],
 
378
           frame_x1 + 1, frame_y0 - 3, frame_x1 + 1, frame_y1 + 3);
 
379
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[6],
 
380
           frame_x1 + 2, frame_y0 - 3, frame_x1 + 2, frame_y1 + 3);
 
381
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[7],
 
382
           frame_x1 + 3, frame_y0 - 3, frame_x1 + 3, frame_y1 + 3);
 
383
 
 
384
/* Draw horizontal lines: */
 
385
for (sectionI = 0; sectionI <= sectionsN; sectionI++)
 
386
        {
 
387
        section_y0 = screen_margin_top + sectionI * section_height;
 
388
        XDrawLine (guiSP->displaySP,
 
389
                   guiSP->main_hidden_pixmapID,
 
390
                   guiSP->theGCA[1],
 
391
                   frame_x0 + 3, section_y0 - 3,
 
392
                   frame_x1 - 3, section_y0 - 3);
 
393
        XDrawLine (guiSP->displaySP,
 
394
                   guiSP->main_hidden_pixmapID,
 
395
                   guiSP->theGCA[2],
 
396
                   frame_x0 + 2, section_y0 - 2,
 
397
                   frame_x1 - 2, section_y0 - 2);
 
398
        XDrawLine (guiSP->displaySP,
 
399
                   guiSP->main_hidden_pixmapID,
 
400
                   guiSP->theGCA[3],
 
401
                   frame_x0 + 1, section_y0 - 1,
 
402
                   frame_x1 - 1, section_y0 - 1);
 
403
        XDrawLine (guiSP->displaySP,
 
404
                   guiSP->main_hidden_pixmapID,
 
405
                   guiSP->theGCA[4],
 
406
                   frame_x0 + 0, section_y0 - 0,
 
407
                   frame_x1 - 0, section_y0 - 0);
 
408
        XDrawLine (guiSP->displaySP,
 
409
                   guiSP->main_hidden_pixmapID,
 
410
                   guiSP->theGCA[5],
 
411
                   frame_x0 + 1, section_y0 + 1,
 
412
                   frame_x1 - 1, section_y0 + 1);
 
413
        XDrawLine (guiSP->displaySP,
 
414
                   guiSP->main_hidden_pixmapID,
 
415
                   guiSP->theGCA[6],
 
416
                   frame_x0 + 2, section_y0 + 2,
 
417
                   frame_x1 - 2, section_y0 + 2);
 
418
        XDrawLine (guiSP->displaySP,
 
419
                   guiSP->main_hidden_pixmapID,
 
420
                   guiSP->theGCA[7],
 
421
                   frame_x0 + 3, section_y0 + 3,
 
422
                   frame_x1 - 3, section_y0 + 3);
 
423
        }
 
424
 
 
425
/* Fix top and bottom of the frame: */
 
426
section_y0 = screen_margin_top;
 
427
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1],
 
428
           frame_x0 - 3, section_y0 - 3, frame_x1 + 3, section_y0 - 3);
 
429
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2],
 
430
           frame_x0 - 2, section_y0 - 2, frame_x1 + 2, section_y0 - 2);
 
431
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3],
 
432
           frame_x0 - 1, section_y0 - 1, frame_x1 + 1, section_y0 - 1);
 
433
section_y0 = screen_margin_top + sectionsN * section_height;
 
434
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1],
 
435
           frame_x0 - 3, section_y0 + 3, frame_x1 + 3, section_y0 + 3);
 
436
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2],
 
437
           frame_x0 - 2, section_y0 + 2, frame_x1 + 2, section_y0 + 2);
 
438
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3],
 
439
           frame_x0 - 1, section_y0 + 1, frame_x1 + 1, section_y0 + 1);
 
440
 
 
441
/*------prepare ordinate extreme values and scale factor:--------------------*/
 
442
 
 
443
/* Prepare extreme values for the ordinate axis: */
 
444
ordinate_min = +999999;
 
445
ordinate_max = -999999;
 
446
if (runtimeSP->averaged_hydrophobicityF)
 
447
        {
 
448
        if (min_average_hyphob < ordinate_min)
 
449
                {
 
450
                ordinate_min = min_average_hyphob;
 
451
                }
 
452
        if (max_average_hyphob > ordinate_max)
 
453
                {
 
454
                ordinate_max = max_average_hyphob;
 
455
                }
 
456
        }
 
457
if (runtimeSP->hydrophobic_momentF)
 
458
        {
 
459
        if (min_hyphob_moment < ordinate_min)
 
460
                {
 
461
                ordinate_min = min_hyphob_moment;
 
462
                }
 
463
        if (max_hyphob_moment > ordinate_max)
 
464
                {
 
465
                ordinate_max = max_hyphob_moment;
 
466
                }
 
467
        }
 
468
 
 
469
/* Shift both values slightly for esthetic reasons: */
 
470
ordinate_range = ordinate_max - ordinate_min;
 
471
ordinate_min -= 0.15 * ordinate_range; 
 
472
ordinate_max += 0.15 * ordinate_range;
 
473
 
 
474
/* Prepare the ordinate scale factor: */
 
475
ordinate_range = ordinate_max - ordinate_min;
 
476
if (ordinate_range != 0.0)
 
477
        {
 
478
        ordinate_scale = (double) section_height / ordinate_range;
 
479
        }
 
480
else ordinate_scale = 0.0;
 
481
 
 
482
/*------draw vertical grid (every 10 residues):------------------------------*/
 
483
 
 
484
/* Initialize the plot index: */
 
485
plotI = 9;
 
486
 
 
487
/* Scan the sequence: */
 
488
for (residueI = 9; residueI < residuesN; residueI += 10)
 
489
        {
 
490
        /* Check is the residue serial index inside the range: */
 
491
        serialI = *(runtimeSP->serialIP + residueI);
 
492
        if ((serialI < range_startI) || (serialI > range_endI))
 
493
                {
 
494
                continue;
 
495
                }
 
496
 
 
497
        /* Prepare the position: */
 
498
        sectionI = plotI / residues_per_sectionN;
 
499
        local_residueI = plotI % residues_per_sectionN;
 
500
        screen_x = screen_margin_x + local_residueI * residue_screen_width;
 
501
        if ((screen_x >= frame_x1 - 3) || (screen_x <= frame_x0 + 3))
 
502
                {
 
503
                plotI += 10;
 
504
                continue;
 
505
                }
 
506
        screen_y0 = screen_margin_top + (sectionI + 1) * section_height - 4;
 
507
        screen_y1 = screen_margin_top + sectionI * section_height + 4;
 
508
 
 
509
        /* Draw line: */
 
510
        XDrawLine (guiSP->displaySP,
 
511
                   guiSP->main_hidden_pixmapID,
 
512
                   guiSP->theGCA[2],
 
513
                   screen_x, screen_y0, screen_x, screen_y1);
 
514
        XDrawLine (guiSP->displaySP,
 
515
                   guiSP->main_hidden_pixmapID,
 
516
                   guiSP->theGCA[4],
 
517
                   screen_x + 1, screen_y0, screen_x + 1, screen_y1);
 
518
 
 
519
        /* Update the plot index: */
 
520
        plotI += 10;
 
521
        }
 
522
 
 
523
/*------draw abscisa:--------------------------------------------------------*/
 
524
 
 
525
/* Left and right extent of the abscisa axis: */
 
526
screen_x0 = frame_x0 + 4;
 
527
screen_x1 = frame_x1 - 4;
 
528
 
 
529
/* Draw abscisa in each section: */
 
530
if ((ordinate_min < 0.0) && (ordinate_max > 0.0))
 
531
        {
 
532
        for (sectionI = 0; sectionI < sectionsN; sectionI++)
 
533
                {
 
534
                d = -ordinate_min * ordinate_scale;
 
535
                screen_y0 = screen_margin_top +
 
536
                            (sectionI + 1) * section_height -
 
537
                            (int) d;
 
538
                XDrawLine (guiSP->displaySP,
 
539
                           guiSP->main_hidden_pixmapID,
 
540
                           guiSP->theGCA[2],
 
541
                           screen_x0, screen_y0 + 1, screen_x1, screen_y0 + 1);
 
542
                XDrawLine (guiSP->displaySP,
 
543
                           guiSP->main_hidden_pixmapID,
 
544
                           guiSP->theGCA[3],
 
545
                           screen_x0, screen_y0, screen_x1, screen_y0);
 
546
                XDrawLine (guiSP->displaySP,
 
547
                           guiSP->main_hidden_pixmapID,
 
548
                           guiSP->theGCA[4],
 
549
                           screen_x0, screen_y0 - 1, screen_x1, screen_y0 - 1);
 
550
                }
 
551
        }
 
552
 
 
553
/*------draw labels:---------------------------------------------------------*/
 
554
 
 
555
/* Text height and ascent for the main window font: */
 
556
text_height = guiSP->main_winS.font_height;
 
557
text_ascent = guiSP->main_winS.fontSP->ascent;
 
558
 
 
559
/* Prepare the text color: */
 
560
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
 
561
                guiSP->main_winS.fg_colorID);
 
562
 
 
563
/* Reset the plot index: */
 
564
plotI = 9;
 
565
 
 
566
/* Scan the sequence: */
 
567
for (residueI = 9; residueI < residuesN; residueI += 10)
 
568
        {
 
569
        /* Use the stored sequence index: */
 
570
        residue_serialI = *(runtimeSP->serialIP + residueI);
 
571
 
 
572
        /* Check is the residue serial index inside the range: */
 
573
        if ((residue_serialI < range_startI) ||
 
574
            (residue_serialI > range_endI))
 
575
                {
 
576
                continue;
 
577
                }
 
578
 
 
579
        /* Prepare section index and local residue index: */
 
580
        sectionI = plotI / residues_per_sectionN;
 
581
        local_residueI = plotI % residues_per_sectionN;
 
582
 
 
583
        /* Prepare the label: */
 
584
        sprintf (stringA, "%d", residue_serialI);
 
585
        string_length = strlen (stringA);
 
586
        text_width = XTextWidth (guiSP->main_winS.fontSP,
 
587
                                 stringA, strlen (stringA));
 
588
        half_text_width = text_width / 2;
 
589
 
 
590
        /* Prepare the position where the label should be drawn: */
 
591
        screen_x = screen_margin_x +
 
592
                   local_residueI * residue_screen_width -
 
593
                   half_text_width;
 
594
        if ((screen_x >= frame_x1 - text_width - 3) ||
 
595
            (screen_x <= frame_x0 + 3))
 
596
                {
 
597
                plotI += 10;
 
598
                continue;
 
599
                }
 
600
        d = -ordinate_min * ordinate_scale;
 
601
        screen_y = screen_margin_top + (sectionI + 1) * section_height - 5;
 
602
 
 
603
        /* Draw the label: */
 
604
        XDrawString (guiSP->displaySP,
 
605
                     guiSP->main_hidden_pixmapID,
 
606
                     guiSP->theGCA[0],
 
607
                     screen_x, screen_y,
 
608
                     stringA, strlen (stringA));
 
609
 
 
610
        /* Update the plot index: */
 
611
        plotI += 10;
 
612
        }
 
613
 
 
614
/*------draw averaged hydrophobicity:----------------------------------------*/
 
615
 
 
616
if (runtimeSP->averaged_hydrophobicityF)
 
617
        {
 
618
        /* Prepare three colors for averaged hydrophobicity: */
 
619
        ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:FFFF/8888/8888", "white");
 
620
        ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:FFFF/0000/0000", "white");
 
621
        ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:8888/0000/0000", "black");
 
622
        XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID);
 
623
        XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID);
 
624
        XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID);
 
625
 
 
626
        /* Reset the plot index: */
 
627
        plotI = 0;
 
628
 
 
629
        /* Scan the sequence: */
 
630
        for (residueI = 0; residueI <= residuesN; residueI++)
 
631
                {
 
632
                /* Check is the residue serial index inside the range: */
 
633
                serialI = *(runtimeSP->serialIP + residueI);
 
634
                if ((serialI < range_startI) || (serialI > range_endI))
 
635
                        {
 
636
                        continue;
 
637
                        }
 
638
 
 
639
                /* Copy the averaged hydrophobicity: */
 
640
                averaged_hydrophobicity =
 
641
                        (double) *(runtimeSP->averaged_hydrophobicityP +
 
642
                                   residueI);
 
643
 
 
644
                /* Prepare screen coordinates: */
 
645
                sectionI = plotI / residues_per_sectionN;
 
646
                local_residueI = plotI % residues_per_sectionN;
 
647
                screen_x0 = screen_margin_x +
 
648
                            local_residueI * residue_screen_width -
 
649
                            half_residue_width - 1;
 
650
                screen_x1 = screen_x0 + residue_screen_width + 2;
 
651
                d = (averaged_hydrophobicity - ordinate_min) * ordinate_scale;
 
652
                screen_y0 = screen_margin_top + sectionI * section_height;
 
653
                screen_y1 = screen_y0 + section_height;
 
654
                screen_y  = screen_y1 - (int) d;
 
655
 
 
656
                /* If residue is near the N or C term., draw nothing: */
 
657
                local_residueI = plotI % residues_per_sectionN;
 
658
                if ((plotI < half_window_width) ||
 
659
                    (plotI > residues_in_plotN - window_width))
 
660
                        {
 
661
                        old_screen_y = screen_y0;
 
662
                        plotI++;
 
663
                        continue;
 
664
                        }
 
665
 
 
666
                /* Draw triple line: */
 
667
                XDrawLine (guiSP->displaySP,
 
668
                           guiSP->main_hidden_pixmapID,
 
669
                           guiSP->theGCA[1],
 
670
                           screen_x0, screen_y - 1,
 
671
                           screen_x1, screen_y - 1);
 
672
                XDrawLine (guiSP->displaySP,
 
673
                           guiSP->main_hidden_pixmapID,
 
674
                           guiSP->theGCA[2],
 
675
                           screen_x0, screen_y,
 
676
                           screen_x1, screen_y);
 
677
                XDrawLine (guiSP->displaySP,
 
678
                           guiSP->main_hidden_pixmapID,
 
679
                           guiSP->theGCA[3],
 
680
                           screen_x0, screen_y + 1,
 
681
                           screen_x1, screen_y + 1);
 
682
 
 
683
                /* Initialize  the flag  which says is */
 
684
                /* it necessary to draw vertical line: */
 
685
                draw_vertical_lineF = 1;
 
686
 
 
687
                /* For the first residue in the current */
 
688
                /* section  do not draw  vertical line: */
 
689
                local_residueI = plotI % residues_per_sectionN;
 
690
                if (local_residueI == 0)
 
691
                        {
 
692
                        old_screen_y = screen_y0;
 
693
                        draw_vertical_lineF = 0;
 
694
                        }
 
695
 
 
696
                /* For the first visible residue, do not draw vertical line: */
 
697
                if (plotI == half_window_width)
 
698
                        {
 
699
                        old_screen_y = screen_y;
 
700
                        draw_vertical_lineF = 0;
 
701
                        }
 
702
 
 
703
                /* Check is it necessary to draw vertical line: */
 
704
                if (old_screen_y == screen_y)
 
705
                        {
 
706
                        old_screen_y = screen_y;
 
707
                        draw_vertical_lineF = 0;
 
708
                        }
 
709
 
 
710
                /* Prepare the shift which is required to draw corners; take */
 
711
                /* the next res. if there is no need to draw vertical lines: */
 
712
                if (old_screen_y < screen_y) shift = -1;
 
713
                else shift = +1;
 
714
 
 
715
                /* Draw three vertical lines: */
 
716
                if (draw_vertical_lineF)
 
717
                        {
 
718
                        XDrawLine (guiSP->displaySP,
 
719
                                   guiSP->main_hidden_pixmapID,
 
720
                                   guiSP->theGCA[1],
 
721
                                   screen_x0, old_screen_y - shift,
 
722
                                   screen_x0, screen_y - shift);
 
723
                        XDrawLine (guiSP->displaySP,
 
724
                                   guiSP->main_hidden_pixmapID,
 
725
                                   guiSP->theGCA[2],
 
726
                                   screen_x0 + 1, old_screen_y,
 
727
                                   screen_x0 + 1, screen_y);
 
728
                        XDrawLine (guiSP->displaySP,
 
729
                                   guiSP->main_hidden_pixmapID,
 
730
                                   guiSP->theGCA[3],
 
731
                                   screen_x0 + 2, old_screen_y + shift,
 
732
                                   screen_x0 + 2, screen_y + shift);
 
733
                        }
 
734
 
 
735
                /* Copy the y coordinate for later use: */
 
736
                old_screen_y = screen_y;
 
737
 
 
738
                /* Fill NearestAtomS array: */
 
739
                for (screen_x  = screen_x0 + 2;
 
740
                     screen_x <= screen_x1 - 1;
 
741
                     screen_x++)
 
742
                        {
 
743
                        for (screen_y  = screen_y0;
 
744
                             screen_y <= screen_y1;
 
745
                             screen_y++)
 
746
                                {
 
747
                                /* Prepare index  to the array */
 
748
                                /* of NearestAtomS structures: */
 
749
                                pixelI = guiSP->main_win_free_area_width *
 
750
                                         screen_y + screen_x;
 
751
 
 
752
                                /* Check the pixel index: */
 
753
                                if (pixelI >= pixelsN) continue;
 
754
 
 
755
                                /* Pointer to  NearestAtomS struct. */
 
756
                                /* assigned to current coordinates: */
 
757
                                curr_pixelSP = nearest_atomSP + pixelI;
 
758
 
 
759
                                /* Refresh NearestAtomS associated with */
 
760
                                /* this pixel;  residue index is stored */
 
761
                                /* to location reserved for atom index. */
 
762
                                curr_pixelSP->last_refreshI = refreshI;
 
763
                                curr_pixelSP->atomI = residueI;
 
764
                                curr_pixelSP->z = averaged_hydrophobicity;
 
765
                                }
 
766
                        }
 
767
 
 
768
                /* Update the plot index: */
 
769
                plotI++;
 
770
                }
 
771
        }
 
772
 
 
773
/*------draw hydrophobic moment:---------------------------------------------*/
 
774
 
 
775
if (runtimeSP->hydrophobic_momentF)
 
776
        {
 
777
        /* Prepare three colors for hydrophobic moment: */
 
778
        ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:8888/DDDD/FFFF", "white");
 
779
        ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:0000/8888/FFFF", "white");
 
780
        ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:0000/4444/8888", "black");
 
781
        XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID);
 
782
        XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID);
 
783
        XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID);
 
784
 
 
785
        /* Reset the plot index: */
 
786
        plotI = 0;
 
787
 
 
788
        /* Scan the sequence: */
 
789
        for (residueI = 0; residueI <= residuesN; residueI++)
 
790
                {
 
791
                /* Check is the residue serial index inside the range: */
 
792
                serialI = *(runtimeSP->serialIP + residueI);
 
793
                if ((serialI < range_startI) || (serialI > range_endI))
 
794
                        {
 
795
                        continue;
 
796
                        }
 
797
 
 
798
                /* Copy the hydrophobic moment: */
 
799
                hydrophobic_moment =
 
800
                        (double) *(runtimeSP->hydrophobic_momentP +
 
801
                                   residueI);
 
802
 
 
803
                /* Prepare screen coordinates: */
 
804
                sectionI = plotI / residues_per_sectionN;
 
805
                local_residueI = plotI % residues_per_sectionN;
 
806
                screen_x0 = screen_margin_x +
 
807
                            local_residueI * residue_screen_width -
 
808
                            half_residue_width - 1;
 
809
                screen_x1 = screen_x0 + residue_screen_width + 2;
 
810
                d = (hydrophobic_moment - ordinate_min) * ordinate_scale;
 
811
 
 
812
                screen_y0 = screen_margin_top + sectionI * section_height;
 
813
                screen_y1 = screen_y0 + section_height;
 
814
                screen_y  = screen_y1 - (int) d;
 
815
 
 
816
                /* If residue is near the N or C term., draw nothing: */
 
817
                local_residueI = plotI % residues_per_sectionN;
 
818
                if ((plotI < half_window_width) ||
 
819
                    (plotI > residues_in_plotN - window_width))
 
820
                        {
 
821
                        old_screen_y = screen_y;
 
822
                        plotI++;
 
823
                        continue;
 
824
                        }
 
825
 
 
826
                /* Draw triple line: */
 
827
                XDrawLine (guiSP->displaySP,
 
828
                           guiSP->main_hidden_pixmapID,
 
829
                           guiSP->theGCA[1],
 
830
                           screen_x0, screen_y - 1,
 
831
                           screen_x1, screen_y - 1);
 
832
                XDrawLine (guiSP->displaySP,
 
833
                           guiSP->main_hidden_pixmapID,
 
834
                           guiSP->theGCA[2],
 
835
                           screen_x0, screen_y,
 
836
                           screen_x1, screen_y);
 
837
                XDrawLine (guiSP->displaySP,
 
838
                           guiSP->main_hidden_pixmapID,
 
839
                           guiSP->theGCA[3],
 
840
                           screen_x0, screen_y + 1,
 
841
                           screen_x1, screen_y + 1);
 
842
 
 
843
                /* Initialize  the flag  which says is */
 
844
                /* it necessary to draw vertical line: */
 
845
                draw_vertical_lineF = 1;
 
846
 
 
847
                /* For the first residue in the current */
 
848
                /* section  do not draw  vertical line: */
 
849
                local_residueI = plotI % residues_per_sectionN;
 
850
                if (local_residueI == 0)
 
851
                        {
 
852
                        old_screen_y = screen_y0;
 
853
                        draw_vertical_lineF = 0;
 
854
                        }
 
855
 
 
856
                /* For the first visible residue, do not draw vertical line: */
 
857
                if (plotI == half_window_width)
 
858
                        {
 
859
                        old_screen_y = screen_y;
 
860
                        draw_vertical_lineF = 0;
 
861
                        }
 
862
 
 
863
                /* Check is it necessary to draw vertical line: */
 
864
                if (old_screen_y == screen_y)
 
865
                        {
 
866
                        old_screen_y = screen_y;
 
867
                        draw_vertical_lineF = 0;
 
868
                        }
 
869
 
 
870
                /* Prepare the shift which is required to draw corners; take */
 
871
                /* the next res. if there is no need to draw vertical lines: */
 
872
                if (old_screen_y < screen_y0) shift = -1;
 
873
                else shift = +1;
 
874
 
 
875
                /* Draw three vertical lines: */
 
876
                if (draw_vertical_lineF)
 
877
                        {
 
878
                        XDrawLine (guiSP->displaySP,
 
879
                                   guiSP->main_hidden_pixmapID,
 
880
                                   guiSP->theGCA[1],
 
881
                                   screen_x0, old_screen_y - shift,
 
882
                                   screen_x0, screen_y - shift);
 
883
                        XDrawLine (guiSP->displaySP,
 
884
                                   guiSP->main_hidden_pixmapID,
 
885
                                   guiSP->theGCA[2],
 
886
                                   screen_x0 + 1, old_screen_y,
 
887
                                   screen_x0 + 1, screen_y);
 
888
                        XDrawLine (guiSP->displaySP,
 
889
                                   guiSP->main_hidden_pixmapID,
 
890
                                   guiSP->theGCA[3],
 
891
                                   screen_x0 + 2, old_screen_y + shift,
 
892
                                   screen_x0 + 2, screen_y + shift);
 
893
                        }
 
894
 
 
895
                /* Copy the y coordinate for later use: */
 
896
                old_screen_y = screen_y;
 
897
 
 
898
                /* Fill NearestAtomS array: */
 
899
                for (screen_x = screen_x0 + 2;
 
900
                     screen_x <= screen_x1 - 1;
 
901
                     screen_x++)
 
902
                        {
 
903
                        for (screen_y  = screen_y0;
 
904
                             screen_y <= screen_y1;
 
905
                             screen_y++)
 
906
                                {
 
907
                                /* Prepare index  to the array */
 
908
                                /* of NearestAtomS structures: */
 
909
                                pixelI = guiSP->main_win_free_area_width *
 
910
                                         screen_y + screen_x;
 
911
 
 
912
                                /* Check the pixel index: */
 
913
                                if (pixelI >= pixelsN) continue;
 
914
 
 
915
                                /* Pointer to  NearestAtomS struct. */
 
916
                                /* assigned to current coordinates: */
 
917
                                curr_pixelSP = nearest_atomSP + pixelI;
 
918
 
 
919
                                /* Refresh NearestAtomS associated with */
 
920
                                /* this pixel;  residue index is stored */
 
921
                                /* to location reserved for atom index. */
 
922
                                curr_pixelSP->last_refreshI = refreshI;
 
923
                                curr_pixelSP->atomI = residueI;
 
924
                                curr_pixelSP->z = hydrophobic_moment;
 
925
                                }
 
926
                        }
 
927
 
 
928
                /* Update the plot index: */
 
929
                plotI++;
 
930
                }
 
931
        }
 
932
 
 
933
/*------copy the prepared image to the main window:--------------------------*/
 
934
 
 
935
/* Copy hidden pixmap to the main window: */
 
936
XCopyArea (guiSP->displaySP,
 
937
           guiSP->main_hidden_pixmapID, guiSP->main_winS.ID,
 
938
           guiSP->theGCA[0],
 
939
           0, 0,
 
940
           guiSP->main_win_free_area_width, guiSP->main_win_free_area_height,
 
941
           0, 0);
 
942
 
 
943
return (size_t) residuesN;
 
944
}
 
945
 
 
946
/*===========================================================================*/
 
947
 
 
948