1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Load sequence from file.
11
(1) Pointer to RuntimeS structure.
14
(1) Sequence stored to the sequence buffer.
18
(1) Positive on success.
19
(2) Negative on failure.
22
(1) The sequence is expected in three letters code or in FASTA
23
format (one letter code, but the first character in title
24
line is '>'). If not in FASTA format, one letter code may
25
be missinterpreted as valid three letters code. File format
26
is free, but the maximal input line should not exceed
29
(2) Space, comma, tab, semicolon and newline are interpreted as
30
separators. Lines beginning with # (numbersign) are treated
31
as comments. Empty lines are ignored. This applies to both
32
three letters code and to FASTA format.
34
(3) The original command string is used because the copy was
35
converted to uppercase.
37
========includes:============================================================*/
45
#include <X11/Xutil.h>
47
#include <X11/Xatom.h>
52
/*======function prototypes:=================================================*/
54
char *ExtractToken_ (char *, int, char *, char *);
55
int ReadFasta_ (RuntimeS *, char *);
56
FILE *OpenFileForReading_ (char *);
57
void InitHyphob_ (RuntimeS *);
59
/*======load sequence from file:=============================================*/
61
int LoadSequence_ (RuntimeS *runtimeSP)
64
char lineA[STRINGSIZE];
66
char tokenA[STRINGSIZE];
75
/* The maximal residue name length: */
76
max_length = RESNAMESIZE - 1;
78
/* Zero initialize the sequence buffer: */
79
runtimeSP->residuesN = 0;
80
for (i = 0; i < runtimeSP->sequence_buffer_size; i++)
82
*(runtimeSP->sequenceP + i) = '\0';
85
/* Copy the original command string: */
86
strncpy (lineA, runtimeSP->curr_commandA, STRINGSIZE - 1);
87
lineA[STRINGSIZE - 1] = '\0';
89
/* Skip two tokens: */
90
remainderP = ExtractToken_ (tokenA, STRINGSIZE, lineA, " \t\n");
91
if (!remainderP) return -1;
92
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
93
if (!remainderP) return -2;
95
/* The third token should contain the file name: */
96
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
99
strcpy (runtimeSP->messageA, "File name missing!");
100
runtimeSP->message_length = strlen (runtimeSP->messageA);
104
/* Try to interpret file as FASTA (one letter code): */
105
if (ReadFasta_ (runtimeSP, tokenA) > 0) return 1;
107
/* If this point is reached, the input file was not in FASTA format. */
109
/* Try to open file: */
110
fileP = OpenFileForReading_ (tokenA);
113
strcpy (runtimeSP->messageA, "Failed to open file!");
114
runtimeSP->message_length = strlen (runtimeSP->messageA);
118
/* Read file, line by line: */
119
while (fgets (lineA, STRINGSIZE, fileP))
121
/* Lines beginning with # are treated as comments: */
122
if (lineA[0] == '#') continue;
124
/* Convert to uppercase: */
126
while ((n = *P++) != '\0') *(P - 1) = toupper (n);
130
while ((remainderP = ExtractToken_ (tokenA, STRINGSIZE,
131
remainderP, " ,;\t\n")) != NULL)
133
/* Check the token length - it should */
134
/* not contain more than max_length characters: */
135
token_length = strlen (tokenA);
136
if (token_length > max_length)
138
sprintf (runtimeSP->messageA,
139
"Bad residue name: %s", tokenA);
140
runtimeSP->message_length =
141
strlen (runtimeSP->messageA);
146
/* If this token contains nothing but digits, ignore it: */
148
for (i = 0; i < token_length; i++)
150
if ((isdigit (tokenA[i]) == 0) &&
151
(tokenA[i] != '-') && (tokenA[i] != '+'))
157
if (numberF) continue;
159
/* Check is there enough space left in the buffer: */
160
offset = max_length * residueI;
161
if (offset > runtimeSP->sequence_buffer_size - 10 * max_length)
163
strcpy (runtimeSP->messageA, "Sequence too long!");
164
runtimeSP->message_length =
165
strlen (runtimeSP->messageA);
170
/* Copy the residue name to the sequence buffer: */
171
P = runtimeSP->sequenceP + offset;
172
strncpy (P, tokenA, max_length);
174
/* Update the residue index: */
182
/* Store the number of residues: */
183
runtimeSP->residuesN = residueI;
185
/* Initialize serial numbers: */
186
for (residueI = 0; residueI < runtimeSP->residuesN; residueI++)
188
*(runtimeSP->serialIP + residueI) = residueI + 1;
191
/* Initialize disulfide flags: */
192
for (residueI = 0; residueI < runtimeSP->residuesN; residueI++)
194
*(runtimeSP->disulfideFP + residueI) = 0;
197
/* Initialize hydrophobicity values: */
198
InitHyphob_ (runtimeSP);
200
/* Return positive value on success: */
204
/*===========================================================================*/