File: weighted_hydrophobicity.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 (127 lines) | stat: -rw-r--r-- 3,400 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
/* Copyright (C) 2006 Damir Zucic */

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

			weighted_hydrophobicity.c

Purpose:
	Calculate the (average) weighted hydrophobicity.

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

Output:
	(1) Weighted hydrophobicity calculated and stored.
	(2) Return value.

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

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

#include <stdio.h>

#include <string.h>

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

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

/*======calculate the weighted hydrophobicity:===============================*/

int WeightedHydrophobicity_ (double *min_valueP, double *max_valueP,
			     RuntimeS *runtimeSP)
{
int             residuesN, residueI;   /* Do not use size_t instead of int ! */
int		used_residuesN;
static int	window_width = 11, half_window_width = 5;
static double	weightA[11] =  {+1.0, +1.0, +1.0, +1.0, +1.0,
				 0.0,
				-1.0, -1.0, -1.0, -1.0, -1.0};
int		windowI, combinedI;
double		hydrophobicity, weighted_hydrophobicity = 0;

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

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

/*------calculate the weighted hydrophobicity:--------------------------------*/

/* Initialize the extreme values: */
*min_valueP = +999999.0;
*max_valueP = -999999.0;

/* Scan the sequence: */
for (residueI = 0; residueI < residuesN; residueI++)
	{
	/* Reset the number of residues used for weighting: */
	used_residuesN = 0;

	/* Reset the weighted hydrophobicity: */
	weighted_hydrophobicity = 0.0;

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

		/* The hydrophobicity of the residue defined by combinedI: */
		hydrophobicity =
			(double) *(runtimeSP->hydrophobicityP + combinedI);

		/* Update the weighted hydrophobicity: */
		weighted_hydrophobicity += hydrophobicity * weightA[windowI];

		/* Increase the number of residues used for averaging: */
		used_residuesN++;
		}

	/* Check how many residues were used: */
	if (used_residuesN == window_width)
		{
		weighted_hydrophobicity /= (double) window_width;
		}
	else weighted_hydrophobicity = 0.0;

	/* Store the weighted hydrophobicity: */
	*(runtimeSP->weighted_hydrophobicityP + residueI) =
						weighted_hydrophobicity;

	/* Dummy values should not be used to determine extremes: */
	if (used_residuesN != window_width) continue;

	/* Find the extreme values: */
	if (weighted_hydrophobicity < *min_valueP)
		{
		*min_valueP = weighted_hydrophobicity;
		}
	if (weighted_hydrophobicity > *max_valueP)
		{
		*max_valueP = weighted_hydrophobicity;
		}

	/* End of residueI loop: */
	}

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

return 1;
}

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