File: hyphob_function7.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (166 lines) | stat: -rw-r--r-- 4,714 bytes parent folder | download | duplicates (3)
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
160
161
162
163
164
165
166
/* Copyright (C) 2006 Damir Zucic */

/*=============================================================================

			    hyphob_function7.c

Purpose:
	Draw the hydrophobicity function F7.  The sequence stored to the
	main sequence buffer  is used  to calculate  the function value.

Input:
	(1) Pointer to the storage where the minimal function value will
	    be stored.
	(2) Pointer to the storage where the maximal function value will
	    be stored.
	(3) Pointer to RuntimeS structure.

Output:
	(1) Function F7 calculated and stored.
	(2) Return value.

Return value:
	(1) Positive on success.
	(2) Negative on failure.

Notes:
	(1) The function  F7 may be modified and used for many purposes.
	    Originally, it was introduced while searching for the method
	    which will be suitable for prediction of the porin secondary
	    structure.

========includes:============================================================*/

#include <stdio.h>

#include <math.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======function prototypes:=================================================*/

int		HyphobFunction1_ (double *, double *, RuntimeS *);
int		HyphobFunction2_ (double *, double *, RuntimeS *);
int		HyphobFunction3_ (double *, double *, RuntimeS *);
int		HyphobFunction4_ (double *, double *, RuntimeS *);
int		HyphobFunction5_ (double *, double *, RuntimeS *);
int		HyphobFunction6_ (double *, double *, RuntimeS *);
int		HyphobFunction7_ (double *, double *, RuntimeS *);
void		InitHyphob_ (RuntimeS *);

/*======calculate the hydrophobicity function F7:============================*/

int HyphobFunction7_ (double *f7minP, double *f7maxP, RuntimeS *runtimeSP)
{
int		residuesN, residueI;   /* Do not use size_t instead of int ! */
double		f1, f1min, f1max;
double		f4, f4min, f4max;
double		f7;
double		average_value;
int		windowI, combinedI;
double		weightA[5] = {1.00, 1.00, 1.00, 1.00, 1.00};

/*------prepare some parameters:---------------------------------------------*/

/* The number of residues in the sequence buffer: */
residuesN = (int) runtimeSP->residuesN;
if (residuesN == 0) return -1;

/*------initialize (reset) F7:-----------------------------------------------*/

/* Initialize F7: */
for (residueI = 0; residueI < residuesN; residueI++)
        {
        /* Reset the function F7, it might be initialized before: */
        *(runtimeSP->function7P + residueI) = 0.0;
        }

/*------calculate the function F1:-------------------------------------------*/

/* Calculate the function F1: */
HyphobFunction5_ (&f1min, &f1max, runtimeSP);

/*------calculate the function F4:-------------------------------------------*/

/* Calculate the function F4: */
HyphobFunction6_ (&f4min, &f4max, runtimeSP);

/*------calculate the function F7:-------------------------------------------*/

/* Initialize the extreme values: */
*f7minP = +999999.0;
*f7maxP = -999999.0;

/* Scan the sequence and calculate F7: */
for (residueI = 0; residueI < residuesN; residueI++)
	{
	/* Initialize the function value: */
	*(runtimeSP->function7P + residueI) = 0.0;

	/* 20060607.1258: */
	/* F7[i] = F1[i] - F4[i] */

	f1 = *(runtimeSP->function1P + residueI);
	f4 = *(runtimeSP->function4P + residueI);
	f7 = f1 - f4;

	/* Store the function value: */
	*(runtimeSP->function7P + residueI) = f7;
	}

/*------calculate the weighted average F7 value, over 5 residues:------------*/

#ifdef ALLDONE /*@@*/

for (residueI = 3; residueI < residuesN - 3; residueI++)
	{
	/* Reset the average value: */
	average_value = 0.0;

	/* Scan the sliding window: */
	for (windowI = 0; windowI < 5; windowI++)
		{
		/* Prepare and check the combined index: */
		combinedI = residueI + windowI - 2;
		if (combinedI < 0) continue;
		if (combinedI >= residuesN) continue;

		/* Copy the function value: */
		f7 = *(runtimeSP->function7P + combinedI);

		/* Add the weighted function value to the average value: */
		average_value += weightA[windowI] * f7;
		}

	/* Calculate and store the average value of F7: */
	average_value /= 5.0;		 /* Divide by 5 */
	*(runtimeSP->function7P + residueI) = average_value;
	}

#endif /*@@*/

/*------find the extreme values of F7:---------------------------------------*/

/* Find the extreme values of F7: */
for (residueI = 0; residueI < residuesN; residueI++)
	{
	/* Find extreme values for F7: */
	f7 = *(runtimeSP->function7P + residueI);
	if (f7 < *f7minP) *f7minP = f7;
	if (f7 > *f7maxP) *f7maxP = f7;
	}

/*---------------------------------------------------------------------------*/

return 1;
}

/*===========================================================================*/