File: parse_sequence.c

package info (click to toggle)
garlic 1.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,192 kB
  • ctags: 1,368
  • sloc: ansic: 49,603; makefile: 1,079
file content (117 lines) | stat: -rw-r--r-- 2,743 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
/* Copyright (C) 2000-2003 Damir Zucic */

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

				parse_sequence.c

Purpose:
	Parse the sequence string.

Input:
	(1) Pointer to RuntimeS structure.
	(2) Pointer to the string which contains the sequence.

Output:
	(1) Sequence stored to the sequence buffer.
	(2) Return value.

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

Notes:
	(1) The sequence is expected in three letters code. One letter
	    code may be missinterpreted as valid three letters code.

	(2) Space, comma, tab and semicolon may be used as separators.

========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 "commands.h"
#include "typedefs.h"

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

char		*ExtractToken_ (char *, int, char *, char *);
void		InitHyphob_ (RuntimeS *);

/*======parse sequence string:===============================================*/

int ParseSequence_ (RuntimeS *runtimeSP, char *stringP)
{
int		max_length, i;
char		*remainderP;
char		tokenA[SHORTSTRINGSIZE];
char		*P;
size_t		residueI = 0;

/* The maximal residue name length: */
max_length = RESNAMESIZE - 1;

/* Reset the number of residues in sequence: */
runtimeSP->residuesN = 0;

/* Zero initialize the sequence buffer: */
for (i = 0; i < (int) runtimeSP->sequence_buffer_size; i++)
	{
	*(runtimeSP->sequenceP + i) = '\0';
	}

/* Parse the string: */
remainderP = stringP;
while ((remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE,
				    remainderP, " ,;\t\n")) != NULL)
	{
	/* Check the residue name size: */
	if ((int) strlen (tokenA) > max_length)
		{
		sprintf (runtimeSP->messageA,
			 "Residue name %s too long!",
			 tokenA);
		runtimeSP->message_length = strlen (runtimeSP->messageA);
		return -1;
		}

	/* Copy the residue name to the sequence buffer: */
	P = runtimeSP->sequenceP + max_length * residueI;
	strcpy (P, tokenA);

	/* Update the residue index: */
	residueI++;
	}

/* Store the number of residues: */
runtimeSP->residuesN = residueI;

/* Reinitialize serial numbers: */
for (residueI = 0; residueI < runtimeSP->residuesN; residueI++)
	{
	*(runtimeSP->serialIP + residueI) = residueI + 1;
	}

/* Reinitialize disulfide flags: */
for (residueI = 0; residueI < runtimeSP->residuesN; residueI++)
	{
	*(runtimeSP->disulfideFP + residueI) = 0;
	}

/* Initialize hydrophobicity values: */
InitHyphob_ (runtimeSP);

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

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