1 /* objcode.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name: objcode.c
27 *
28 * Author: James Ostell
29 *
30 * Version Creation Date: 4/1/91
31 *
32 * $Revision: 6.15 $
33 *
34 * File Description: Object manager for module NCBI-SeqCode
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 * 05-13-93 Schuler All public functions are now declared LIBCALL.
41 *
42 *
43 * $Log: objcode.c,v $
44 * Revision 6.15 2015/10/23 00:04:24 kans
45 * NOIJRA Clear av DataVal variable on AsnWrite, needed for supporting Int8 integers in ASN.1
46 *
47 * Revision 6.14 2008/05/22 20:57:44 kans
48 * environment variables to allow reading from data/*.val, replaced tabs in source code with spaces
49 *
50 * Revision 6.13 2006/09/19 15:26:37 kans
51 * restored O and J to ncbistdaa now that BLAST is fixed
52 *
53 * Revision 6.12 2006/04/28 15:05:11 kans
54 * removed O and J from ncbistdaa to avoid breaking some BLAST programs
55 *
56 * Revision 6.11 2006/01/31 22:30:53 kans
57 * added O for pyrrolysine and J for leu or ile ambiguity
58 *
59 * Revision 6.10 2004/04/01 13:43:07 lavr
60 * Spell "occurred", "occurrence", and "occurring"
61 *
62 * Revision 6.9 2002/09/13 15:07:17 kans
63 * restored U Selenocysteine to iupacaa rather than kludge asn2gnbk
64 *
65 * Revision 6.8 2002/06/27 19:45:39 kans
66 * reverted U Selenocysteine addition to iupac
67 *
68 * Revision 6.7 2002/06/27 13:24:39 kans
69 * added U Selenocysteine to iupacaa, changed conversion tables to reflect that
70 *
71 * Revision 6.6 1999/04/23 12:47:43 madden
72 * Use PATH_MAX in SeqCodeSetLoad
73 *
74 * Revision 6.5 1999/01/19 19:38:57 vakatov
75 * Typo fixed(WIN16 rather than WIN_16)
76 *
77 * Revision 6.4 1999/01/19 19:08:14 kans
78 * text asn.1 for genetic code and sequence conversion tables only if not WIN_16
79 *
80 * Revision 6.3 1999/01/06 22:02:15 kans
81 * load gen code and seq code tables from asn strings in static memory as last resort to avoid need for data directory for some programs
82 *
83 * Revision 6.2 1998/12/29 19:56:26 kans
84 * more informative error message if FindPath fails
85 *
86 * Revision 6.1 1998/08/24 18:28:01 kans
87 * removed solaris -v -fd warnings
88 *
89 * Revision 6.0 1997/08/25 18:49:32 madden
90 * Revision changed to 6.0
91 *
92 * Revision 4.1 1997/06/19 18:40:59 vakatov
93 * [WIN32,MSVC++] Adopted for the "NCBIOBJ.LIB" DLL'ization
94 *
95 * Revision 4.0 1995/07/26 13:48:06 ostell
96 * force revision to 4.0
97 *
98 * Revision 3.1 1995/05/15 21:22:00 ostell
99 * added Log line
100 *
101 *
102 *
103 * ==========================================================================
104 */
105 #include <objcode.h> /* the pub interface */
106 #include <asncode.h> /* the AsnTool header */
107
108 static Boolean loaded = FALSE;
109
110 static SeqCodeSetPtr scspl = NULL; /* loaded SeqCodeTables and SeqMapTables */
111
112 /*****************************************************************************
113 *
114 * SeqCodeAsnLoad()
115 *
116 *****************************************************************************/
SeqCodeAsnLoad(void)117 NLM_EXTERN Boolean LIBCALL SeqCodeAsnLoad (void)
118 {
119 if (loaded)
120 return TRUE;
121 loaded = TRUE;
122
123 if (! AsnLoad())
124 {
125 loaded = FALSE;
126 return FALSE;
127 }
128 return TRUE;
129 }
130
131 /*****************************************************************************
132 *
133 * SeqMapTableNew()
134 *
135 *****************************************************************************/
SeqMapTableNew(void)136 NLM_EXTERN SeqMapTablePtr LIBCALL SeqMapTableNew (void)
137 {
138 return (SeqMapTablePtr)MemNew(sizeof(SeqMapTable));
139 }
140
141 /*****************************************************************************
142 *
143 * SeqMapTableFree(smtp)
144 * Frees a SeqMapTable and associated data
145 *
146 *****************************************************************************/
SeqMapTableFree(SeqMapTablePtr smtp)147 NLM_EXTERN SeqMapTablePtr LIBCALL SeqMapTableFree (SeqMapTablePtr smtp)
148 {
149 if (smtp == NULL)
150 return smtp;
151 MemFree(smtp->table);
152 return (SeqMapTablePtr)MemFree(smtp);
153 }
154 /*****************************************************************************
155 *
156 * SeqMapTableAsnWrite(smtp, aip, atp)
157 * atp is the current type (if identifier of a parent struct)
158 * if atp == NULL, then assumes it stands alone (SeqMapTable ::=)
159 *
160 *****************************************************************************/
SeqMapTableAsnWrite(SeqMapTablePtr smtp,AsnIoPtr aip,AsnTypePtr orig)161 NLM_EXTERN Boolean LIBCALL SeqMapTableAsnWrite (SeqMapTablePtr smtp, AsnIoPtr aip, AsnTypePtr orig)
162 {
163 DataVal av;
164 AsnTypePtr atp;
165 Uint1 i, num;
166 Uint1Ptr ipnt;
167 Boolean retval = FALSE;
168
169 if (! loaded)
170 {
171 if (! SeqCodeAsnLoad())
172 return FALSE;
173 }
174
175 if (aip == NULL)
176 return FALSE;
177
178 atp = AsnLinkType(orig, SEQ_MAP_TABLE); /* link local tree */
179 if (atp == NULL) return FALSE;
180
181 if (smtp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
182
183 MemSet ((Pointer) (&av), 0, sizeof (DataVal));
184
185 if (! AsnOpenStruct(aip, atp, (Pointer)smtp)) goto erret;
186
187 av.intvalue = smtp->from;
188 if (! AsnWrite(aip, SEQ_MAP_TABLE_from, &av)) goto erret;
189 av.intvalue = smtp->to;
190 if (! AsnWrite(aip, SEQ_MAP_TABLE_to, &av)) goto erret;
191 num = smtp->num;
192 av.intvalue = (Int4)num;
193 if (! AsnWrite(aip, SEQ_MAP_TABLE_num, &av)) goto erret;
194
195 if (smtp->start_at)
196 {
197 av.intvalue = (Int4)smtp->start_at;
198 if (! AsnWrite(aip, SEQ_MAP_TABLE_start_at, &av)) goto erret;
199 }
200 if (! AsnOpenStruct(aip, SEQ_MAP_TABLE_table, (Pointer)smtp->table)) goto erret;
201 ipnt = smtp->table;
202 for (i = 0; i < num; i++, ipnt++)
203 {
204 av.intvalue = (Int4)*ipnt;
205 if (! AsnWrite(aip, SEQ_MAP_TABLE_table_E, &av)) goto erret;
206 }
207 if (! AsnCloseStruct(aip, SEQ_MAP_TABLE_table, (Pointer)smtp->table)) goto erret;
208
209 if (! AsnCloseStruct(aip, atp, (Pointer)smtp)) goto erret;
210 retval = TRUE;
211 erret:
212 AsnUnlinkType(orig); /* unlink local tree */
213 return retval;
214 }
215
216 /*****************************************************************************
217 *
218 * SeqMapTableAsnRead(aip, atp)
219 * atp is the current type (if identifier of a parent struct)
220 * assumption is readIdent has occurred
221 * if atp == NULL, then assumes it stands alone and read ident
222 * has not occurred.
223 *
224 *****************************************************************************/
SeqMapTableAsnRead(AsnIoPtr aip,AsnTypePtr orig)225 NLM_EXTERN SeqMapTablePtr LIBCALL SeqMapTableAsnRead (AsnIoPtr aip, AsnTypePtr orig)
226 {
227 DataVal av;
228 AsnTypePtr atp;
229 SeqMapTablePtr smtp=NULL;
230 Uint1 i, num;
231 Uint1Ptr ipnt;
232
233 if (! loaded)
234 {
235 if (! SeqCodeAsnLoad())
236 return smtp;
237 }
238
239 if (aip == NULL)
240 return smtp;
241
242 if (orig == NULL) /* SeqMapTable ::= (self contained) */
243 atp = AsnReadId(aip, amp, SEQ_MAP_TABLE);
244 else
245 atp = AsnLinkType(orig, SEQ_MAP_TABLE); /* link in local tree */
246 if (atp == NULL) return smtp;
247
248 smtp = SeqMapTableNew();
249 if (smtp == NULL) goto erret;
250
251 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
252
253 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
254 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
255 smtp->from = (Uint1) av.intvalue;
256
257 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
258 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
259 smtp->to = (Uint1) av.intvalue;
260
261 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
262 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
263 num = (Uint1)av.intvalue;
264 smtp->num = num;
265 ipnt = (Uint1Ptr)MemNew((num * sizeof(Uint1)));
266 if (ipnt == NULL) goto erret;
267 smtp->table = ipnt;
268
269 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* start SEQUENCE OF */
270 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
271 if (atp == SEQ_MAP_TABLE_start_at)
272 {
273 smtp->start_at = (Uint1)av.intvalue;
274 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* start SEQUENCE OF */
275 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
276 }
277 i = 0;
278 while ((atp = AsnReadId(aip, amp, atp)) == SEQ_MAP_TABLE_table_E)
279 {
280 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
281 if (i < num)
282 *ipnt = (Uint1)av.intvalue;
283 else
284 {
285 ErrPost(CTX_NCBIOBJ, 1, "Too many codes in Seq-map-table. line %ld",
286 aip->linenumber);
287 goto erret;
288 }
289 ipnt++; i++;
290 }
291 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQUENCE OF */
292 if (i != num)
293 {
294 ErrPost(CTX_NCBIOBJ, 1, "Too few codes in Seq-map-table. line %ld",
295 aip->linenumber);
296 goto erret;
297 }
298
299 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* end struct */
300 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
301 ret:
302 AsnUnlinkType(orig); /* unlink local tree */
303 return smtp;
304 erret:
305 smtp = SeqMapTableFree(smtp);
306 goto ret;
307 }
308
309 /*****************************************************************************
310 *
311 * SeqMapTablePtr SeqMapTableFindObj(to, from)
312 *
313 *****************************************************************************/
SeqMapTableFindObj(Uint1 to,Uint1 from)314 NLM_EXTERN SeqMapTablePtr LIBCALL SeqMapTableFindObj (Uint1 to, Uint1 from)
315 {
316 SeqMapTablePtr smtp=NULL;
317
318 if (scspl == NULL)
319 {
320 if ((scspl = SeqCodeSetLoad()) == NULL)
321 return smtp;
322 }
323
324 smtp = scspl->maps;
325 while (smtp != NULL)
326 {
327 if ((smtp->to == to) && (smtp->from == from))
328 return smtp;
329 smtp = smtp->next;
330 }
331 return smtp;
332 }
333
334 /*****************************************************************************
335 *
336 * SeqCodeTableNew()
337 *
338 *****************************************************************************/
SeqCodeTableNew(void)339 NLM_EXTERN SeqCodeTablePtr LIBCALL SeqCodeTableNew (void)
340 {
341 return (SeqCodeTablePtr)MemNew(sizeof(SeqCodeTable));
342 }
343
344 /*****************************************************************************
345 *
346 * SeqCodeTableFree(sctp)
347 * Frees a SeqCodeTable and associated data
348 *
349 *****************************************************************************/
SeqCodeTableFree(SeqCodeTablePtr sctp)350 NLM_EXTERN SeqCodeTablePtr LIBCALL SeqCodeTableFree (SeqCodeTablePtr sctp)
351 {
352 CharPtr PNTR tmp;
353 Uint1 num, i;
354
355 if (sctp == NULL)
356 return sctp;
357
358 MemFree(sctp->letters);
359 num = sctp->num;
360 if (sctp->symbols != NULL)
361 {
362 tmp = sctp->symbols;
363 for (i = 0; i < num; i++, tmp++)
364 MemFree(*tmp);
365 MemFree(sctp->symbols);
366 }
367 if (sctp->names != NULL)
368 {
369 tmp = sctp->names;
370 for (i = 0; i < num; i++, tmp++)
371 MemFree(*tmp);
372 MemFree(sctp->names);
373 }
374 if (sctp->comps != NULL)
375 MemFree(sctp->comps);
376 return (SeqCodeTablePtr)MemFree(sctp);
377 }
378
379 /*****************************************************************************
380 *
381 * SeqCodeTableAsnWrite(sctp, aip, atp)
382 * atp is the current type (if identifier of a parent struct)
383 * if atp == NULL, then assumes it stands alone (SeqCodeTable ::=)
384 *
385 *****************************************************************************/
SeqCodeTableAsnWrite(SeqCodeTablePtr sctp,AsnIoPtr aip,AsnTypePtr orig)386 NLM_EXTERN Boolean LIBCALL SeqCodeTableAsnWrite (SeqCodeTablePtr sctp, AsnIoPtr aip, AsnTypePtr orig)
387 {
388 DataVal av;
389 AsnTypePtr atp;
390 Uint1 i, num;
391 Char tbuf[2];
392 Boolean retval = FALSE;
393
394 if (! loaded)
395 {
396 if (! SeqCodeAsnLoad())
397 return FALSE;
398 }
399
400 if (aip == NULL)
401 return FALSE;
402
403 atp = AsnLinkType(orig, SEQ_CODE_TABLE); /* link local tree */
404 if (atp == NULL) return FALSE;
405
406 if (sctp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
407
408 MemSet ((Pointer) (&av), 0, sizeof (DataVal));
409
410 if (! AsnOpenStruct(aip, atp, (Pointer)sctp)) goto erret;
411
412 av.intvalue = sctp->code;
413 if (! AsnWrite(aip, SEQ_CODE_TABLE_code, &av)) goto erret;
414 num = sctp->num;
415 av.intvalue = (Int4)num;
416 if (! AsnWrite(aip, SEQ_CODE_TABLE_num, &av)) goto erret;
417 av.boolvalue = sctp->one_letter;
418 if (! AsnWrite(aip, SEQ_CODE_TABLE_one_letter, &av)) goto erret;
419 if (sctp->start_at)
420 {
421 av.intvalue = (Int4)sctp->start_at;
422 if (! AsnWrite(aip, SEQ_CODE_TABLE_start_at, &av)) goto erret;
423 }
424
425 if (! AsnOpenStruct(aip, SEQ_CODE_TABLE_table, (Pointer)sctp)) goto erret;
426 tbuf[1] = '\0';
427
428 for (i = 0; i < num; i++)
429 {
430 if (! AsnOpenStruct(aip, SEQ_CODE_TABLE_table_E, (Pointer)sctp)) goto erret;
431 if (sctp->one_letter)
432 {
433 tbuf[0] = sctp->letters[i];
434 av.ptrvalue = tbuf;
435 }
436 else
437 av.ptrvalue = sctp->symbols[i];
438 if (! AsnWrite(aip, SEQ_CODE_TABLE_table_E_symbol, &av)) goto erret;
439
440 av.ptrvalue = sctp->names[i];
441 if (! AsnWrite(aip, SEQ_CODE_TABLE_table_E_name, &av)) goto erret;
442 if (! AsnCloseStruct(aip, SEQ_CODE_TABLE_table_E, (Pointer)sctp)) goto erret;
443 }
444 if (! AsnCloseStruct(aip, SEQ_CODE_TABLE_table, (Pointer)sctp)) goto erret;
445
446 if (sctp->comps != NULL)
447 {
448 if (! AsnOpenStruct(aip, SEQ_CODE_TABLE_comps, (Pointer)sctp->comps)) goto erret;
449 for (i = 0; i < num; i++)
450 {
451 av.intvalue = (Int4)sctp->comps[i];
452 if (! AsnWrite(aip, SEQ_CODE_TABLE_comps_E, &av)) goto erret;
453 }
454 if (! AsnCloseStruct(aip, SEQ_CODE_TABLE_comps, (Pointer)sctp->comps)) goto erret;
455 }
456 if (! AsnCloseStruct(aip, atp, (Pointer)sctp)) goto erret;
457 retval = TRUE;
458 erret:
459 AsnUnlinkType(orig); /* unlink local tree */
460 return retval;
461 }
462
463 /*****************************************************************************
464 *
465 * SeqCodeTableAsnRead(aip, atp)
466 * atp is the current type (if identifier of a parent struct)
467 * assumption is readIdent has occurred
468 * if atp == NULL, then assumes it stands alone and read ident
469 * has not occurred.
470 *
471 *****************************************************************************/
SeqCodeTableAsnRead(AsnIoPtr aip,AsnTypePtr orig)472 NLM_EXTERN SeqCodeTablePtr LIBCALL SeqCodeTableAsnRead (AsnIoPtr aip, AsnTypePtr orig)
473 {
474 DataVal av;
475 AsnTypePtr atp;
476 SeqCodeTablePtr sctp=NULL;
477 Uint1 i, num;
478
479 if (! loaded)
480 {
481 if (! SeqCodeAsnLoad())
482 return sctp;
483 }
484
485 if (aip == NULL)
486 return sctp;
487
488 if (orig == NULL) /* SeqCodeTable ::= (self contained) */
489 atp = AsnReadId(aip, amp, SEQ_CODE_TABLE);
490 else
491 atp = AsnLinkType(orig, SEQ_CODE_TABLE); /* link in local tree */
492 if (atp == NULL) return sctp;
493
494 sctp = SeqCodeTableNew();
495 if (sctp == NULL) goto erret;
496
497 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
498
499 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
500 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
501 sctp->code = (Uint1) av.intvalue;
502
503 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
504 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
505 num = (Uint1)av.intvalue;
506 sctp->num = num;
507
508 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
509 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
510 sctp->one_letter = av.boolvalue;
511
512 if (sctp->one_letter)
513 {
514 sctp->letters = (CharPtr)MemNew((num * sizeof(Char)));
515 if (sctp->letters == NULL) goto erret;
516 }
517 else
518 {
519 sctp->symbols = (CharPtr PNTR)MemNew((num * sizeof(CharPtr)));
520 if (sctp->symbols == NULL) goto erret;
521 }
522 sctp->names = (CharPtr PNTR)MemNew((num * sizeof(CharPtr)));
523 if (sctp->names == NULL) goto erret;
524
525 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* start SEQUENCE OF */
526 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
527 if (atp == SEQ_CODE_TABLE_start_at)
528 {
529 sctp->start_at = (Uint1)av.intvalue;
530 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* start SEQUENCE OF */
531 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
532 }
533 i = 0;
534 while ((atp = AsnReadId(aip, amp, atp)) == SEQ_CODE_TABLE_table_E)
535 {
536 if (i >= num)
537 {
538 ErrPost(CTX_NCBIOBJ, 1, "Too many codes in Seq-code-table %s. line %ld",
539 sctp->code, aip->linenumber);
540 goto erret;
541 }
542 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* start struct */
543 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
544 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* symbol */
545 if (sctp->one_letter)
546 {
547 sctp->letters[i] = *(CharPtr)av.ptrvalue;
548 MemFree(av.ptrvalue);
549 }
550 else
551 sctp->symbols[i] = (CharPtr)av.ptrvalue;
552 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* name */
553 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
554 sctp->names[i] = (CharPtr)av.ptrvalue;
555 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* end struct */
556 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
557 i++;
558 }
559 if (atp == NULL) goto erret;
560 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQUENCE OF */
561 if (i != num)
562 {
563 ErrPost(CTX_NCBIOBJ, 1, "Too few codes in Seq-code-table %s. line %ld",
564 sctp->code, aip->linenumber);
565 goto erret;
566 }
567
568 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
569 if (atp == SEQ_CODE_TABLE_comps) /* comps present */
570 {
571 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
572 sctp->comps = (Uint1Ptr)MemNew((num * sizeof(Uint1)));
573 if (sctp->comps == NULL) goto erret;
574 i = 0;
575 while ((atp = AsnReadId(aip, amp, atp)) == SEQ_CODE_TABLE_comps_E)
576 {
577 if (i == num)
578 {
579 ErrPost(CTX_NCBIOBJ, 1, "Too many comps in Seq-code-table. line %ld",
580 aip->linenumber);
581 goto erret;
582 }
583 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
584 sctp->comps[i] = (Uint1)av.intvalue;
585 i++;
586 }
587 if (i != num)
588 {
589 ErrPost(CTX_NCBIOBJ, 1, "Too few comps in Seq-code-table. line %ld",
590 aip->linenumber);
591 goto erret;
592 }
593 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end sequence of */
594 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
595 }
596 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
597 ret:
598 AsnUnlinkType(orig); /* unlink local tree */
599 return sctp;
600 erret:
601 sctp = SeqCodeTableFree(sctp);
602 goto ret;
603 }
604
605 /*****************************************************************************
606 *
607 * SeqCodeTablePtr SeqCodeTableFindObj(code)
608 *
609 *****************************************************************************/
SeqCodeTableFindObj(Uint1 code)610 NLM_EXTERN SeqCodeTablePtr LIBCALL SeqCodeTableFindObj (Uint1 code)
611 {
612 SeqCodeTablePtr sctp=NULL;
613
614 if (scspl == NULL)
615 {
616 if ((scspl = SeqCodeSetLoad()) == NULL)
617 return sctp;
618 }
619
620 sctp = scspl->codes;
621 while (sctp != NULL)
622 {
623 if (sctp->code == code)
624 return sctp;
625 sctp = sctp->next;
626 }
627 return sctp;
628 }
629
630 /*****************************************************************************
631 *
632 * SeqCodeSetNew()
633 *
634 *****************************************************************************/
SeqCodeSetNew(void)635 NLM_EXTERN SeqCodeSetPtr LIBCALL SeqCodeSetNew (void)
636 {
637 return (SeqCodeSetPtr)MemNew(sizeof(SeqCodeSet));
638 }
639
640 /*****************************************************************************
641 *
642 * SeqCodeSetFree(scsp)
643 * Frees a SeqCodeSet and associated data
644 *
645 *****************************************************************************/
SeqCodeSetFree(SeqCodeSetPtr scsp)646 NLM_EXTERN SeqCodeSetPtr LIBCALL SeqCodeSetFree (SeqCodeSetPtr scsp)
647 {
648 SeqCodeTablePtr sctp, sctpnext;
649 SeqMapTablePtr smtp, smtpnext;
650
651 sctp = scsp->codes;
652 while (sctp != NULL)
653 {
654 sctpnext = sctp->next;
655 SeqCodeTableFree(sctp);
656 sctp = sctpnext;
657 }
658 smtp = scsp->maps;
659 while (smtp != NULL)
660 {
661 smtpnext = smtp->next;
662 SeqMapTableFree(smtp);
663 smtp = smtpnext;
664 }
665 return (SeqCodeSetPtr)MemFree(scsp);
666 }
667
668 /*****************************************************************************
669 *
670 * SeqCodeSetAsnWrite(scsp, aip, atp)
671 * atp is the current type (if identifier of a parent struct)
672 * if atp == NULL, then assumes it stands alone (SeqCodeSet ::=)
673 *
674 *****************************************************************************/
SeqCodeSetAsnWrite(SeqCodeSetPtr scsp,AsnIoPtr aip,AsnTypePtr orig)675 NLM_EXTERN Boolean LIBCALL SeqCodeSetAsnWrite (SeqCodeSetPtr scsp, AsnIoPtr aip, AsnTypePtr orig)
676 {
677 AsnTypePtr atp;
678 SeqMapTablePtr smtp;
679 SeqCodeTablePtr sctp;
680 Boolean retval = FALSE;
681
682 if (! loaded)
683 {
684 if (! SeqCodeAsnLoad())
685 return FALSE;
686 }
687
688 if (aip == NULL)
689 return FALSE;
690
691 atp = AsnLinkType(orig, SEQ_CODE_SET); /* link local tree */
692 if (atp == NULL) return FALSE;
693
694 if (scsp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
695
696 if (! AsnOpenStruct(aip, atp, (Pointer)scsp)) goto erret;
697
698 if (scsp->codes != NULL)
699 {
700 if (! AsnOpenStruct(aip, SEQ_CODE_SET_codes, (Pointer)scsp->codes)) goto erret;
701 sctp = scsp->codes;
702 while (sctp != NULL)
703 {
704 if (! SeqCodeTableAsnWrite(sctp, aip, SEQ_CODE_SET_codes_E)) goto erret;
705 sctp = sctp->next;
706 }
707 if (! AsnCloseStruct(aip, SEQ_CODE_SET_codes, (Pointer)scsp->codes)) goto erret;
708 }
709
710 if (scsp->maps != NULL)
711 {
712 if (! AsnOpenStruct(aip, SEQ_CODE_SET_maps, (Pointer)scsp->maps)) goto erret;
713 smtp = scsp->maps;
714 while (smtp != NULL)
715 {
716 if (! SeqMapTableAsnWrite(smtp, aip, SEQ_CODE_SET_maps_E)) goto erret;
717 smtp = smtp->next;
718 }
719 if (! AsnCloseStruct(aip, SEQ_CODE_SET_maps, (Pointer)scsp->maps)) goto erret;
720 }
721
722 if (! AsnCloseStruct(aip, atp, (Pointer)scsp)) goto erret;
723 retval = TRUE;
724 erret:
725 AsnUnlinkType(orig); /* unlink local tree */
726 return retval;
727 }
728
729 /*****************************************************************************
730 *
731 * SeqCodeSetAsnRead(aip, atp)
732 * atp is the current type (if identifier of a parent struct)
733 * assumption is readIdent has occurred
734 * if atp == NULL, then assumes it stands alone and read ident
735 * has not occurred.
736 *
737 *****************************************************************************/
SeqCodeSetAsnRead(AsnIoPtr aip,AsnTypePtr orig)738 NLM_EXTERN SeqCodeSetPtr LIBCALL SeqCodeSetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
739 {
740 DataVal av;
741 AsnTypePtr atp, oldatp;
742 SeqCodeSetPtr scsp=NULL;
743 SeqMapTablePtr map, currmap = NULL;
744 SeqCodeTablePtr code, currcode = NULL;
745
746 if (! loaded)
747 {
748 if (! SeqCodeAsnLoad())
749 return scsp;
750 }
751
752 if (aip == NULL)
753 return scsp;
754
755 if (orig == NULL) /* SeqCodeSet ::= (self contained) */
756 atp = AsnReadId(aip, amp, SEQ_CODE_SET);
757 else
758 atp = AsnLinkType(orig, SEQ_CODE_SET); /* link in local tree */
759 oldatp = atp;
760 if (atp == NULL) return scsp;
761
762 scsp = SeqCodeSetNew();
763 if (scsp == NULL) goto erret;
764
765 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
766
767 while((atp = AsnReadId(aip, amp, atp)) != oldatp)
768 {
769 if (atp == NULL) goto erret;
770 if (atp == SEQ_CODE_SET_codes_E)
771 {
772 code = SeqCodeTableAsnRead(aip, atp);
773 if (code == NULL) goto erret;
774 if (scsp->codes == NULL)
775 scsp->codes = code;
776 else
777 currcode->next = code;
778 currcode = code;
779 }
780 else if (atp == SEQ_CODE_SET_maps_E)
781 {
782 map = SeqMapTableAsnRead(aip, atp);
783 if (map == NULL) goto erret;
784 if (scsp->maps == NULL)
785 scsp->maps = map;
786 else
787 currmap->next = map;
788 currmap = map;
789 }
790 else /* the other struct ends */
791 {
792 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
793 }
794 }
795 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
796 ret:
797 AsnUnlinkType(orig); /* unlink local tree */
798 return scsp;
799 erret:
800 scsp = SeqCodeSetFree(scsp);
801 goto ret;
802 }
803
804 /*****************************************************************************
805 *
806 * seqCodeSetMemStr as last resort embedded version of seqcode.prt
807 *
808 *****************************************************************************/
809
810 #ifndef WIN16
811 static CharPtr seqCodeSetMemStr = "Seq-code-set ::= {\n" \
812 "codes {\n" \
813 "{ code iupacna , num 25 , one-letter TRUE , start-at 65 , table {\n" \
814 "{ symbol \"A\", name \"Adenine\" },\n" \
815 "{ symbol \"B\" , name \"G or T or C\" },\n" \
816 "{ symbol \"C\", name \"Cytosine\" },\n" \
817 "{ symbol \"D\", name \"G or A or T\" },\n" \
818 "{ symbol \"\", name \"\" },\n" \
819 "{ symbol \"\", name \"\" },\n" \
820 "{ symbol \"G\", name \"Guanine\" },\n" \
821 "{ symbol \"H\", name \"A or C or T\" } ,\n" \
822 "{ symbol \"\", name \"\" },\n" \
823 "{ symbol \"\", name \"\" },\n" \
824 "{ symbol \"K\", name \"G or T\" },\n" \
825 "{ symbol \"\", name \"\"},\n" \
826 "{ symbol \"M\", name \"A or C\" },\n" \
827 "{ symbol \"N\", name \"A or G or C or T\" } ,\n" \
828 "{ symbol \"\", name \"\" },\n" \
829 "{ symbol \"\", name \"\" },\n" \
830 "{ symbol \"\", name \"\"},\n" \
831 "{ symbol \"R\", name \"G or A\"},\n" \
832 "{ symbol \"S\", name \"G or C\"},\n" \
833 "{ symbol \"T\", name \"Thymine\"},\n" \
834 "{ symbol \"\", name \"\"},\n" \
835 "{ symbol \"V\", name \"G or C or A\"},\n" \
836 "{ symbol \"W\", name \"A or T\" },\n" \
837 "{ symbol \"\", name \"\"},\n" \
838 "{ symbol \"Y\", name \"T or C\"} } ,\n" \
839 "comps { 84, 86, 71, 72, 69, 70, 67, 68, 73, 74, 77, 76, 75, 78, 79, 80, 81, 89, 83, 65, 85, 66, 87, 88, 82 } } ,\n" \
840 "{ code iupacaa , num 26 , one-letter TRUE , start-at 65 , table {\n" \
841 "{ symbol \"A\", name \"Alanine\" },\n" \
842 "{ symbol \"B\" , name \"Asp or Asn\" },\n" \
843 "{ symbol \"C\", name \"Cysteine\" },\n" \
844 "{ symbol \"D\", name \"Aspartic Acid\" },\n" \
845 "{ symbol \"E\", name \"Glutamic Acid\" },\n" \
846 "{ symbol \"F\", name \"Phenylalanine\" },\n" \
847 "{ symbol \"G\", name \"Glycine\" },\n" \
848 "{ symbol \"H\", name \"Histidine\"} ,\n" \
849 "{ symbol \"I\", name \"Isoleucine\" },\n" \
850 "{ symbol \"J\", name \"Leu or Ile\" },\n" \
851 "{ symbol \"K\", name \"Lysine\" },\n" \
852 "{ symbol \"L\", name \"Leucine\" },\n" \
853 "{ symbol \"M\", name \"Methionine\" },\n" \
854 "{ symbol \"N\", name \"Asparagine\"} ,\n" \
855 "{ symbol \"O\", name \"Pyrrolysine\" },\n" \
856 "{ symbol \"P\", name \"Proline\" },\n" \
857 "{ symbol \"Q\", name \"Glutamine\"},\n" \
858 "{ symbol \"R\", name \"Arginine\"},\n" \
859 "{ symbol \"S\", name \"Serine\"},\n" \
860 "{ symbol \"T\", name \"Threonine\"},\n" \
861 "{ symbol \"U\", name \"Selenocysteine\"},\n" \
862 "{ symbol \"V\", name \"Valine\"},\n" \
863 "{ symbol \"W\", name \"Tryptophan\" },\n" \
864 "{ symbol \"X\", name \"Undetermined or atypical\"},\n" \
865 "{ symbol \"Y\", name \"Tyrosine\"},\n" \
866 "{ symbol \"Z\", name \"Glu or Gln\" } } } ,\n" \
867 "{ code ncbieaa , num 49 , one-letter TRUE , start-at 42 , table {\n" \
868 "{ symbol \"*\", name \"Termination\" } ,\n" \
869 "{ symbol \"\", name \"\" } ,\n" \
870 "{ symbol \"\", name \"\" } ,\n" \
871 "{ symbol \"-\", name \"Gap\" } ,\n" \
872 "{ symbol \"\", name \"\"} ,\n" \
873 "{ symbol \"\", name \"\"} ,\n" \
874 "{ symbol \"\", name \"\"} ,\n" \
875 "{ symbol \"\", name \"\"} ,\n" \
876 "{ symbol \"\", name \"\"} ,\n" \
877 "{ symbol \"\", name \"\"} ,\n" \
878 "{ symbol \"\", name \"\"} ,\n" \
879 "{ symbol \"\", name \"\"} ,\n" \
880 "{ symbol \"\", name \"\"} ,\n" \
881 "{ symbol \"\", name \"\"} ,\n" \
882 "{ symbol \"\", name \"\"} ,\n" \
883 "{ symbol \"\", name \"\"} ,\n" \
884 "{ symbol \"\", name \"\"} ,\n" \
885 "{ symbol \"\", name \"\"} ,\n" \
886 "{ symbol \"\", name \"\"} ,\n" \
887 "{ symbol \"\", name \"\"} ,\n" \
888 "{ symbol \"\", name \"\"} ,\n" \
889 "{ symbol \"\", name \"\"} ,\n" \
890 "{ symbol \"\", name \"\"} ,\n" \
891 "{ symbol \"A\", name \"Alanine\" },\n" \
892 "{ symbol \"B\" , name \"Asp or Asn\" },\n" \
893 "{ symbol \"C\", name \"Cysteine\" },\n" \
894 "{ symbol \"D\", name \"Aspartic Acid\" },\n" \
895 "{ symbol \"E\", name \"Glutamic Acid\" },\n" \
896 "{ symbol \"F\", name \"Phenylalanine\" },\n" \
897 "{ symbol \"G\", name \"Glycine\" },\n" \
898 "{ symbol \"H\", name \"Histidine\" } ,\n" \
899 "{ symbol \"I\", name \"Isoleucine\" },\n" \
900 "{ symbol \"J\", name \"Leu or Ile\" },\n" \
901 "{ symbol \"K\", name \"Lysine\" },\n" \
902 "{ symbol \"L\", name \"Leucine\" },\n" \
903 "{ symbol \"M\", name \"Methionine\" },\n" \
904 "{ symbol \"N\", name \"Asparagine\" } ,\n" \
905 "{ symbol \"O\", name \"Pyrrolysine\" },\n" \
906 "{ symbol \"P\", name \"Proline\" },\n" \
907 "{ symbol \"Q\", name \"Glutamine\"},\n" \
908 "{ symbol \"R\", name \"Arginine\"},\n" \
909 "{ symbol \"S\", name \"Serine\"},\n" \
910 "{ symbol \"T\", name \"Threonine\"},\n" \
911 "{ symbol \"U\", name \"Selenocysteine\"},\n" \
912 "{ symbol \"V\", name \"Valine\"},\n" \
913 "{ symbol \"W\", name \"Tryptophan\" },\n" \
914 "{ symbol \"X\", name \"Undetermined or atypical\"},\n" \
915 "{ symbol \"Y\", name \"Tyrosine\"},\n" \
916 "{ symbol \"Z\", name \"Glu or Gln\" } } } ,\n" \
917 "{ code iupacaa3 , num 28 , one-letter FALSE , table {\n" \
918 "{ symbol \"---\", name \"Gap\" } ,\n" \
919 "{ symbol \"Ala\", name \"Alanine\" },\n" \
920 "{ symbol \"Asx\", name \"Asp or Asn\" },\n" \
921 "{ symbol \"Cys\", name \"Cysteine\" },\n" \
922 "{ symbol \"Asp\", name \"Aspartic Acid\" },\n" \
923 "{ symbol \"Glu\", name \"Glutamic Acid\" },\n" \
924 "{ symbol \"Phe\", name \"Phenylalanine\" },\n" \
925 "{ symbol \"Gly\", name \"Glycine\" },\n" \
926 "{ symbol \"His\", name \"Histidine\" } ,\n" \
927 "{ symbol \"Ile\", name \"Isoleucine\" },\n" \
928 "{ symbol \"Lys\", name \"Lysine\" },\n" \
929 "{ symbol \"Leu\", name \"Leucine\" },\n" \
930 "{ symbol \"Met\", name \"Methionine\" },\n" \
931 "{ symbol \"Asn\", name \"Asparagine\" } ,\n" \
932 "{ symbol \"Pro\", name \"Proline\" },\n" \
933 "{ symbol \"Gln\", name \"Glutamine\"},\n" \
934 "{ symbol \"Arg\", name \"Arginine\"},\n" \
935 "{ symbol \"Ser\", name \"Serine\"},\n" \
936 "{ symbol \"Thr\", name \"Threonine\"},\n" \
937 "{ symbol \"Val\", name \"Valine\"},\n" \
938 "{ symbol \"Trp\", name \"Tryptophan\" },\n" \
939 "{ symbol \"Xxx\", name \"Undetermined or atypical\"},\n" \
940 "{ symbol \"Tyr\", name \"Tyrosine\"},\n" \
941 "{ symbol \"Glx\", name \"Glu or Gln\" },\n" \
942 "{ symbol \"Sec\", name \"Selenocysteine\"},\n" \
943 "{ symbol \"Ter\", name \"Termination\"},\n" \
944 "{ symbol \"Pyl\", name \"Pyrrolysine\"},\n" \
945 "{ symbol \"Xle\", name \"Leu or Ile\" } } } ,\n" \
946 "{ code ncbistdaa , num 28 , one-letter TRUE , table {\n" \
947 "{ symbol \"-\", name \"Gap\" } ,\n" \
948 "{ symbol \"A\", name \"Alanine\" },\n" \
949 "{ symbol \"B\" , name \"Asp or Asn\" },\n" \
950 "{ symbol \"C\", name \"Cysteine\" },\n" \
951 "{ symbol \"D\", name \"Aspartic Acid\" },\n" \
952 "{ symbol \"E\", name \"Glutamic Acid\" },\n" \
953 "{ symbol \"F\", name \"Phenylalanine\" },\n" \
954 "{ symbol \"G\", name \"Glycine\" },\n" \
955 "{ symbol \"H\", name \"Histidine\" } ,\n" \
956 "{ symbol \"I\", name \"Isoleucine\" },\n" \
957 "{ symbol \"K\", name \"Lysine\" },\n" \
958 "{ symbol \"L\", name \"Leucine\" },\n" \
959 "{ symbol \"M\", name \"Methionine\" },\n" \
960 "{ symbol \"N\", name \"Asparagine\" } ,\n" \
961 "{ symbol \"P\", name \"Proline\" },\n" \
962 "{ symbol \"Q\", name \"Glutamine\"},\n" \
963 "{ symbol \"R\", name \"Arginine\"},\n" \
964 "{ symbol \"S\", name \"Serine\"},\n" \
965 "{ symbol \"T\", name \"Threoine\"},\n" \
966 "{ symbol \"V\", name \"Valine\"},\n" \
967 "{ symbol \"W\", name \"Tryptophan\" },\n" \
968 "{ symbol \"X\", name \"Undetermined or atypical\"},\n" \
969 "{ symbol \"Y\", name \"Tyrosine\"},\n" \
970 "{ symbol \"Z\", name \"Glu or Gln\" },\n" \
971 "{ symbol \"U\", name \"Selenocysteine\"},\n" \
972 "{ symbol \"*\", name \"Termination\"},\n" \
973 "{ symbol \"O\", name \"Pyrrolysine\"},\n" \
974 "{ symbol \"J\", name \"Leu or Ile\" } } } ,\n" \
975 "{ code ncbi2na , num 4 , one-letter TRUE , table {\n" \
976 "{ symbol \"A\", name \"Adenine\" },\n" \
977 "{ symbol \"C\", name \"Cytosine\" },\n" \
978 "{ symbol \"G\", name \"Guanine\" },\n" \
979 "{ symbol \"T\", name \"Thymine/Uracil\"} } ,\n" \
980 "comps { 3, 2, 1, 0 } } ,\n" \
981 "{ code ncbi4na , num 16 , one-letter TRUE , table {\n" \
982 "{ symbol \"-\", name \"Gap\"} ,\n" \
983 "{ symbol \"A\", name \"Adenine\" },\n" \
984 "{ symbol \"C\", name \"Cytosine\" },\n" \
985 "{ symbol \"M\", name \"A or C\" },\n" \
986 "{ symbol \"G\", name \"Guanine\" },\n" \
987 "{ symbol \"R\", name \"G or A\"},\n" \
988 "{ symbol \"S\", name \"G or C\"},\n" \
989 "{ symbol \"V\", name \"G or C or A\"},\n" \
990 "{ symbol \"T\", name \"Thymine/Uracil\"},\n" \
991 "{ symbol \"W\", name \"A or T\" },\n" \
992 "{ symbol \"Y\", name \"T or C\"} ,\n" \
993 "{ symbol \"H\", name \"A or C or T\" } ,\n" \
994 "{ symbol \"K\", name \"G or T\" },\n" \
995 "{ symbol \"D\", name \"G or A or T\" },\n" \
996 "{ symbol \"B\" , name \"G or T or C\" },\n" \
997 "{ symbol \"N\", name \"A or G or C or T\" } } ,\n" \
998 "comps { 0 , 8 , 4 , 12, 2 , 10, 6 , 14, 1 , 9 , 5 , 13, 3 , 11, 7 , 15 } } , } ,\n" \
999 "maps { { from iupacna , to ncbi2na , num 25 , start-at 65 ,\n" \
1000 "table { 0, 1, 1, 2, 255, 255, 2, 0, 255, 255, 2, 255, 1, 0, 255, 255, 255, 2, 1, 3, 255, 0, 3, 255, 3 } } ,\n" \
1001 "{ from iupacna , to ncbi4na , num 26 , start-at 64 ,\n" \
1002 "table { 0, 1, 14, 2, 13, 255, 255, 4, 11, 255, 255, 12, 255, 3, 15, 255, 255, 255, 5, 6, 8, 255, 7, 9, 255, 10 } } ,\n" \
1003 "{ from ncbi2na , to iupacna , num 4 ,\n" \
1004 "table { 65, 67, 71, 84 } } ,\n" \
1005 "{ from ncbi2na , to ncbi4na , num 4 ,\n" \
1006 "table { 1, 2, 4, 8 } } ,\n" \
1007 "{ from ncbi4na , to iupacna , num 16 ,\n" \
1008 "table { 78, 65, 67, 77, 71, 82, 83, 86, 84, 87, 89, 72, 75, 68, 66, 78 } } ,\n" \
1009 "{ from ncbi4na , to ncbi2na , num 16 ,\n" \
1010 "table { 3, 0, 1, 1, 2, 2, 1, 0, 3, 3, 3, 0, 2, 2, 1, 0 } } ,\n" \
1011 "{ from iupacaa , to ncbieaa , num 26 , start-at 65 ,\n" \
1012 "table { 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 } } ,\n" \
1013 "{ from ncbieaa , to iupacaa , num 49 , start-at 42 ,\n" \
1014 "table { 88 , 255, 255, 88, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\n" \
1015 "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 } } ,\n" \
1016 "{ from iupacaa , to ncbistdaa , num 26 , start-at 65 ,\n" \
1017 "table { 1 , 2 , 3 , 4, 5, 6, 7, 8, 9, 27, 10, 11, 12, 13, 26, 14, 15, 16, 17, 18, 24, 19, 20, 21, 22, 23 } } ,\n" \
1018 "{ from ncbieaa , to ncbistdaa , num 49 , start-at 42 ,\n" \
1019 "table { 25, 255, 255, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\n" \
1020 "1 , 2 , 3 , 4, 5, 6, 7, 8, 9, 27, 10, 11, 12, 13, 26, 14, 15, 16, 17, 18, 24, 19, 20, 21, 22, 23 } } ,\n" \
1021 "{ from ncbistdaa , to ncbieaa , num 28 ,\n" \
1022 "table { 45 , 65 , 66 , 67 , 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 85, 42, 79, 74} } ,\n" \
1023 "{ from ncbistdaa , to iupacaa , num 28 ,\n" \
1024 "table { 255 , 65 , 66 , 67 , 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 85, 255, 79, 74} } } };\n";
1025 #endif
1026
1027 /*****************************************************************************
1028 *
1029 * SeqCodeSetPtr SeqCodeSetLoad()
1030 * loads all current seqcodes
1031 * looks for "seqcode.val" in the "data" directory
1032 * now uses seqCodeSetMemStr if unable to find "data" directory
1033 *
1034 *****************************************************************************/
LoadSeqCodeFromLocalString(void)1035 static Boolean LoadSeqCodeFromLocalString (void)
1036
1037 {
1038 #ifndef WIN16
1039 AsnIoMemPtr aimp;
1040
1041 aimp = AsnIoMemOpen ("r", (BytePtr) seqCodeSetMemStr, (Int4) StringLen (seqCodeSetMemStr));
1042 if (aimp == NULL || aimp->aip == NULL) return FALSE;
1043 scspl = SeqCodeSetAsnRead (aimp->aip, NULL);
1044 AsnIoMemClose (aimp);
1045 #endif
1046 return (Boolean) (scspl != NULL);
1047 }
1048
SeqCodeSetLoad(void)1049 NLM_EXTERN SeqCodeSetPtr LIBCALL SeqCodeSetLoad (void)
1050 {
1051 Char buf[PATH_MAX];
1052 AsnIoPtr aip;
1053
1054 if (scspl != NULL)
1055 return scspl;
1056
1057 if (! loaded)
1058 {
1059 if (! SeqCodeAsnLoad())
1060 return (SeqCodeSetPtr)NULL;
1061 }
1062
1063 #ifdef OS_UNIX
1064 if (getenv ("USE_SEQCODE_FILE") == NULL) {
1065 if (LoadSeqCodeFromLocalString ()) {
1066 return scspl;
1067 }
1068 }
1069 #endif
1070
1071 if (! FindPath("ncbi", "ncbi", "data", buf, sizeof (buf)))
1072 {
1073
1074 if (LoadSeqCodeFromLocalString ()) {
1075 return scspl;
1076 }
1077
1078 ErrPost(CTX_NCBIOBJ, 1, "FindPath failed in SeqCodeSetLoad - ncbi configuration file missing or incorrect");
1079 return scspl;
1080 }
1081
1082 StringCat(buf, "seqcode.val");
1083 if ((aip = AsnIoOpen(buf, "rb")) == NULL)
1084 {
1085
1086 if (LoadSeqCodeFromLocalString ()) {
1087 return scspl;
1088 }
1089
1090 ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", buf);
1091 return scspl;
1092 }
1093
1094 scspl = SeqCodeSetAsnRead(aip, NULL);
1095
1096 AsnIoClose(aip);
1097 return scspl;
1098 }
1099
1100
1101