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

« back to all changes in this revision

Viewing changes to parse_sequence.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
                                parse_sequence.c
 
6
 
 
7
Purpose:
 
8
        Parse the sequence string.
 
9
 
 
10
Input:
 
11
        (1) Pointer to RuntimeS structure.
 
12
        (2) Pointer to the string which contains the sequence.
 
13
 
 
14
Output:
 
15
        (1) Sequence stored to the sequence buffer.
 
16
        (2) Return value.
 
17
 
 
18
Return value:
 
19
        (1) Positive on success.
 
20
        (2) Negative on failure.
 
21
 
 
22
Notes:
 
23
        (1) The sequence is expected in three letters code. One letter
 
24
            code may be missinterpreted as valid three letters code.
 
25
 
 
26
        (2) Space, comma, tab and semicolon may be used as separators.
 
27
 
 
28
========includes:============================================================*/
 
29
 
 
30
#include <stdio.h>
 
31
 
 
32
#include <string.h>
 
33
 
 
34
#include <X11/Xlib.h>
 
35
#include <X11/Xutil.h>
 
36
#include <X11/Xos.h>
 
37
#include <X11/Xatom.h>
 
38
 
 
39
#include "defines.h"
 
40
#include "commands.h"
 
41
#include "typedefs.h"
 
42
 
 
43
/*======function prototypes:=================================================*/
 
44
 
 
45
char            *ExtractToken_ (char *, int, char *, char *);
 
46
void            InitHyphob_ (RuntimeS *);
 
47
 
 
48
/*======parse sequence string:===============================================*/
 
49
 
 
50
int ParseSequence_ (RuntimeS *runtimeSP, char *stringP)
 
51
{
 
52
int             max_length, i;
 
53
char            *remainderP;
 
54
char            tokenA[SHORTSTRINGSIZE];
 
55
char            *P;
 
56
size_t          residueI = 0;
 
57
 
 
58
/* The maximal residue name length: */
 
59
max_length = RESNAMESIZE - 1;
 
60
 
 
61
/* Zero initialize the sequence buffer: */
 
62
runtimeSP->residuesN = 0;
 
63
for (i = 0; i < runtimeSP->sequence_buffer_size; i++)
 
64
        {
 
65
        *(runtimeSP->sequenceP + i) = '\0';
 
66
        }
 
67
 
 
68
/* Parse the string: */
 
69
remainderP = stringP;
 
70
while ((remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE,
 
71
                                    remainderP, " ,;\t\n")) != NULL)
 
72
        {
 
73
        /* Check the residue name size: */
 
74
        if (strlen (tokenA) > max_length)
 
75
                {
 
76
                sprintf (runtimeSP->messageA,
 
77
                         "Residue name %s too long!",
 
78
                         tokenA);
 
79
                runtimeSP->message_length = strlen (runtimeSP->messageA);
 
80
                return -1;
 
81
                }
 
82
 
 
83
        /* Copy the residue name to the sequence buffer: */
 
84
        P = runtimeSP->sequenceP + max_length * residueI;
 
85
        strcpy (P, tokenA);
 
86
 
 
87
        /* Update the residue index: */
 
88
        residueI++;
 
89
        }
 
90
 
 
91
/* Store the number of residues: */
 
92
runtimeSP->residuesN = residueI;
 
93
 
 
94
/* Reinitialize serial numbers: */
 
95
for (residueI = 0; residueI < runtimeSP->residuesN; residueI++)
 
96
        {
 
97
        *(runtimeSP->serialIP + residueI) = residueI + 1;
 
98
        }
 
99
 
 
100
/* Reinitialize disulfide flags: */
 
101
for (residueI = 0; residueI < runtimeSP->residuesN; residueI++)
 
102
        {
 
103
        *(runtimeSP->disulfideFP + residueI) = 0;
 
104
        }
 
105
 
 
106
/* Initialize hydrophobicity values: */
 
107
InitHyphob_ (runtimeSP);
 
108
 
 
109
/* Return positive value on success: */
 
110
return 1;
 
111
}
 
112
 
 
113
/*===========================================================================*/
 
114
 
 
115