File: extract_vector.c

package info (click to toggle)
garlic 1.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 4,440 kB
  • ctags: 1,403
  • sloc: ansic: 52,465; makefile: 1,134
file content (172 lines) | stat: -rw-r--r-- 6,291 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
160
161
162
163
164
165
166
167
168
169
170
171
172
/* Copyright (C) 2001-2003 Damir Zucic */

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

				extract_vector.c

Purpose:
	Find the highest average hydrophobicity using the current sliding
	window width. Extract the coordinates of eight atoms which define
	the start and the end of the window which has this maximum at the
	center and prepare one vector.

Input:
	(1) Pointer to VectorS structure, where the extracted vector will
	    be stored.
	(2) Pointer to MolComplexS structure,  with the chosen structure.
	(3) Pointer to RuntimeS structure.
	(4) The threshold value for the average hydrophobicity.

Output:
	(1) On success, one vector will be prepared and initialized.
	(2) Return value.

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

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

#include <stdio.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		ExtractCA_ (VectorS *, AtomS *, size_t, size_t);

/*======extract vector:======================================================*/

int ExtractVector_ (VectorS *vectorSP,
		    MolComplexS *mol_complexSP, RuntimeS *runtimeSP,
		    double threshold)
{
int		residuesN, residueI;
int		window_width, half_window_width;
double		max_average_hyphob, min_average_hyphob;
int		central_residueI, window_startI, window_endI;
double		average_hyphob;
int		vectors_extractedN;
ResidueS	*residueSP;
VectorS		vector1S, vector2S, vector3S, vector4S;
VectorS		vector5S, vector6S, vector7S, vector8S;

/* Copy the number of residues: */
residuesN = mol_complexSP->residuesN;
if (residuesN == 0) return -1;

/* The sliding window width should be at least eight: */
window_width = runtimeSP->sliding_window_width;
if (window_width < 8) return -2;
half_window_width = window_width / 2;

/* Initialize the maximal and minimal average hydrophobicity: */
max_average_hyphob = -999999.0;
min_average_hyphob =  999999.0;

/* Initialize the index  of the residue  which is */
/* in the middle of the most hydrophobic segment. */
central_residueI = -1;

/* Find the sequence position with the highest average hydrophobicity. */
/* Find also the values of maximal and minimal average hydrophobicity. */
for (residueI = 0; residueI < residuesN; residueI++)
	{
	average_hyphob = *(runtimeSP->average_hydrophobicityP + residueI);
	if (average_hyphob > max_average_hyphob)
		{
		max_average_hyphob = average_hyphob;
		central_residueI = residueI;
		}
	else if (average_hyphob < min_average_hyphob)
		{
		min_average_hyphob = average_hyphob;
		}
	}

/* This should never happen but I am paranoic: */
if (central_residueI == -1) return -3;

/* Check is the maximal average hydrophobicity above the threshold: */
if (max_average_hyphob < threshold) return -4;

/* Now use  the index of  the central residue  to define  the entire */
/* sliding window which contains the maximal average hydrophobicity: */
window_startI = central_residueI - half_window_width;
window_endI   = window_startI + window_width;

/* Check both indices; if the central residue is too close */
/* to the first or to the last residue, discard this peak: */
if ((window_startI < 0) || (window_startI >= residuesN)) return -5;

/* Use  the first  four residues  from  the  sliding  window  to */
/* define  the first point  in space and the last  four residues */
/* to define  the second point  in space.  Use these  two points */
/* to prepare  the initial normal vector.  This vector should be */
/* approximately perpendicular to the membrane.  The coordinates */
/* of CA atoms are used (some structures contain only CA atoms). */

/* Prepare eight vectors: */
vectors_extractedN = 0;
residueSP = mol_complexSP->residueSP + window_startI;
vectors_extractedN += ExtractCA_ (&vector1S, mol_complexSP->atomSP,
				  residueSP->residue_startI,
				  residueSP->residue_endI);
residueSP = mol_complexSP->residueSP + window_startI + 1;
vectors_extractedN += ExtractCA_ (&vector2S, mol_complexSP->atomSP,
				  residueSP->residue_startI,
				  residueSP->residue_endI);
residueSP = mol_complexSP->residueSP + window_startI + 2;
vectors_extractedN += ExtractCA_ (&vector3S, mol_complexSP->atomSP,
				  residueSP->residue_startI,
				  residueSP->residue_endI);
residueSP = mol_complexSP->residueSP + window_startI + 3;
vectors_extractedN += ExtractCA_ (&vector4S, mol_complexSP->atomSP,
                                  residueSP->residue_startI,
                                  residueSP->residue_endI);
residueSP = mol_complexSP->residueSP + window_endI;
vectors_extractedN += ExtractCA_ (&vector5S, mol_complexSP->atomSP,
				  residueSP->residue_startI,
				  residueSP->residue_endI);
residueSP = mol_complexSP->residueSP + window_endI - 1;
vectors_extractedN += ExtractCA_ (&vector6S, mol_complexSP->atomSP,
				  residueSP->residue_startI,
				  residueSP->residue_endI);
residueSP = mol_complexSP->residueSP + window_endI - 2;
vectors_extractedN += ExtractCA_ (&vector7S, mol_complexSP->atomSP,
				  residueSP->residue_startI,
				  residueSP->residue_endI);
residueSP = mol_complexSP->residueSP + window_endI - 3;
vectors_extractedN += ExtractCA_ (&vector8S, mol_complexSP->atomSP,
				  residueSP->residue_startI,
				  residueSP->residue_endI);
if (vectors_extractedN != 8) return -6;

/* The first (crude) estimate of the normal vector: */
vectorSP->x = vector5S.x + vector6S.x + vector7S.x + vector8S.x
	    - vector1S.x - vector2S.x - vector3S.x - vector4S.x;
vectorSP->y = vector5S.y + vector6S.y + vector7S.y + vector8S.y
	    - vector1S.y - vector2S.y - vector3S.y - vector4S.y;
vectorSP->z = vector5S.z + vector6S.z + vector7S.z + vector8S.z
	    - vector1S.z - vector2S.z - vector3S.z - vector4S.z;

/* Remove the highest peak. Replace the average hydrophobicities */
/* in the whole interval by the  minimal average hydrophobicity. */
for (residueI = window_startI; residueI <= window_endI; residueI++)
	{
	*(runtimeSP->average_hydrophobicityP + residueI) = min_average_hyphob;
	}

/* Return positive value on success: */
return 1;
}

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