NCBI C Toolkit Cross Reference

C/object/objcode.c


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

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.