NCBI C Toolkit Cross Reference

C/object/objfeat.c


  1 /*  objfeat.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:  objfeat.c
 27 *
 28 * Author:  James Ostell
 29 *   
 30 * Version Creation Date: 4/1/91
 31 *
 32 * $Revision: 6.45 $
 33 *
 34 * File Description:  Object manager for module NCBI-SeqFeat
 35 *
 36 * Modifications:  
 37 * --------------------------------------------------------------------------
 38 * Date       Name        Description of modification
 39 * -------  ----------  -----------------------------------------------------
 40 *
 41 * ==========================================================================
 42 */
 43 
 44 /** for ErrPostEx() ****/
 45 
 46 static char *this_module = "ncbiobj";
 47 #define THIS_MODULE this_module
 48 static char *this_file = __FILE__;
 49 #define THIS_FILE this_file
 50 
 51 /**********************/
 52 
 53 #include <objfeat.h>           /* the features interface */
 54 #include <asnfeat.h>        /* the AsnTool header */
 55 #include <objmgr.h>
 56 #include <objfdef.h>
 57 
 58 static Boolean loaded = FALSE;
 59 
 60 /*****************************************************************************
 61 *
 62 *   SeqFeat ObjMgr Routines
 63 *
 64 *****************************************************************************/
 65 static Pointer LIBCALLBACK SeqFeatNewFunc (void)
 66 {
 67     return (Pointer) SeqFeatNew();
 68 }
 69 
 70 static Pointer LIBCALLBACK SeqFeatFreeFunc (Pointer data)
 71 {
 72     return (Pointer) SeqFeatFree ((SeqFeatPtr) data);
 73 }
 74 
 75 static Boolean LIBCALLBACK SeqFeatAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
 76 {
 77     return SeqFeatAsnWrite((SeqFeatPtr)data, aip, atp);
 78 }
 79 
 80 static Pointer LIBCALLBACK SeqFeatAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
 81 {
 82     return (Pointer) SeqFeatAsnRead (aip, atp);
 83 }
 84 
 85 static Int2 LIBCALLBACK SeqFeatLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
 86 {
 87     Int2 rsult = 0;
 88 
 89     switch (content)
 90     {
 91         case OM_LABEL_TYPE:
 92         case OM_LABEL_CONTENT:
 93         case OM_LABEL_BOTH:
 94             rsult = FeatDefLabel((SeqFeatPtr)data, buffer, buflen, content);
 95             break;
 96         case OM_LABEL_SUMMARY:
 97         default:
 98             rsult = FeatDefLabel((SeqFeatPtr)data, buffer, buflen, OM_LABEL_BOTH);
 99             break;
100     }
101     return rsult;
102 }
103 
104 static Uint2 LIBCALLBACK SeqFeatSubTypeFunc (Pointer ptr)
105 {
106     if (ptr == NULL)
107         return 0;
108     return (Uint2)FindFeatDefType((SeqFeatPtr)ptr);
109 }
110 
111 /*****************************************************************************
112 *
113 *   SeqFeatAsnLoad()
114 *      requires SeqAsnLoad() to be called first
115 *
116 *****************************************************************************/
117 NLM_EXTERN Boolean LIBCALL SeqFeatAsnLoad (void)
118 {
119     if (loaded)
120         return TRUE;
121     loaded = TRUE;
122 
123     if (! GeneralAsnLoad())
124     {
125         loaded = FALSE;
126         return FALSE;
127     }
128     if (! SeqLocAsnLoad())      /* SeqLoc refers to Seqfeat and vice versa */
129     {
130         loaded = FALSE;
131         return FALSE;
132     }
133     if (! PubAsnLoad())
134     {
135         loaded = FALSE;
136         return FALSE;
137     }
138     if ( ! AsnLoad())
139     {
140         loaded = FALSE;
141         return FALSE;
142     }
143 
144     ObjMgrTypeLoad(OBJ_SEQFEAT, "Seq-feat", "SeqFeat", "Sequence Feature",
145         SEQ_FEAT, SeqFeatNewFunc, SeqFeatAsnReadFunc, SeqFeatAsnWriteFunc,
146         SeqFeatFreeFunc, SeqFeatLabelFunc, SeqFeatSubTypeFunc);
147 
148     return TRUE;
149 }
150 
151 /*****************************************************************************
152 *
153 *   SeqFeat Routines
154 *
155 *****************************************************************************/
156 /*****************************************************************************
157 *
158 *   SeqFeatNew()
159 *
160 *****************************************************************************/
161 NLM_EXTERN SeqFeatPtr LIBCALL SeqFeatNew (void)
162 {
163     return (SeqFeatPtr)MemNew(sizeof(SeqFeat));
164 }
165 
166 /*****************************************************************************
167 *
168 *   SeqFeatFree(sfp)
169 *       Frees one SeqFeat and associated data
170 *
171 *****************************************************************************/
172 NLM_EXTERN SeqFeatPtr LIBCALL SeqFeatFree (SeqFeatPtr sfp)
173 {
174     ValNodePtr vnp, next=NULL;
175   UserObjectPtr uop, unp = NULL;
176 
177     if (sfp == NULL)
178         return (SeqFeatPtr)NULL;
179 
180     SeqFeatIdFree(&sfp->id);
181     SeqFeatDataFree(&sfp->data);
182     MemFree(sfp->title);
183     MemFree(sfp->comment);
184     UserObjectFree(sfp->ext);
185     SeqLocFree(sfp->product);
186     SeqLocFree(sfp->location);
187     GBQualFree(sfp->qual);
188     PubSetFree(sfp->cit);
189     SeqFeatXrefFree(sfp->xref);
190     for (vnp = sfp->dbxref; vnp != NULL; vnp = next)
191     {
192         next = vnp->next;
193         DbtagFree((DbtagPtr)(vnp->data.ptrvalue));
194         MemFree(vnp);
195     }
196     MemFree(sfp->except_text);
197     for (vnp = sfp->ids; vnp != NULL; vnp = next)
198     {
199         next = vnp->next;
200         SeqFeatIdFree((ChoicePtr)(vnp->data.ptrvalue));
201         MemFree(vnp);
202     }
203     /*
204     AsnGenericChoiceSeqOfFree (sfp->ids, (AsnOptFreeFunc) SeqFeatIdFree);
205     */
206     for (uop = sfp->exts; uop != NULL; uop = unp)
207     {
208         unp = uop->next;
209         UserObjectFree(uop);
210     }
211     /*
212   AsnGenericUserSeqOfFree (sfp->exts, (AsnOptFreeFunc) UserObjectFree);
213   */
214 
215     ObjMgrDelete(OBJ_SEQFEAT, (Pointer)sfp);
216 
217     return (SeqFeatPtr)MemFree(sfp);
218 }
219 
220 /*****************************************************************************
221 *
222 *   SeqFeatAsnWrite(sfp, aip, atp)
223 *       atp is the current type (if identifier of a parent struct)
224 *       if atp == NULL, then assumes it stands alone (SeqFeat ::=)
225 *
226 *****************************************************************************/
227 NLM_EXTERN Boolean LIBCALL SeqFeatAsnWrite (SeqFeatPtr sfp, AsnIoPtr aip, AsnTypePtr orig)
228 {
229     DataVal av;
230     AsnTypePtr atp;
231     GBQualPtr gbp;
232     Boolean retval = FALSE;
233     SeqFeatXrefPtr sfxp;
234     ValNodePtr vnp;
235   UserObjectPtr uop;
236 
237     if (! loaded)
238     {
239         if (! SeqFeatAsnLoad())
240             return FALSE;
241     }
242 
243     if (aip == NULL)
244         return FALSE;
245 
246     atp = AsnLinkType(orig, SEQ_FEAT);   /* link local tree */
247     if (atp == NULL)
248         return FALSE;
249 
250     if (sfp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
251 
252     if (! AsnOpenStruct(aip, atp, (Pointer)sfp))
253         goto erret;
254 
255     if (sfp->id.choice)              /* feat-id present */
256     {
257         if (! SeqFeatIdAsnWrite(&sfp->id, aip, SEQ_FEAT_id))
258             goto erret;
259     }
260 
261     if (! SeqFeatDataAsnWrite(&sfp->data, aip, SEQ_FEAT_data)) goto erret;
262 
263 
264     av.boolvalue = TRUE;
265     if (sfp->partial)
266     {
267         if (! AsnWrite(aip, SEQ_FEAT_partial, &av)) goto erret;
268     }
269     if (sfp->excpt)
270     {
271         if (! AsnWrite(aip, SEQ_FEAT_except, &av)) goto erret;
272     }
273     if (sfp->comment != NULL)
274     {
275         av.ptrvalue = sfp->comment;
276         if (! AsnWrite(aip, SEQ_FEAT_comment, &av)) goto erret;
277     }
278     if (sfp->product != NULL)
279     {
280         if (! SeqLocAsnWrite(sfp->product, aip, SEQ_FEAT_product))
281             goto erret;
282     }
283     if (sfp->location != NULL)
284     {
285         if (! SeqLocAsnWrite(sfp->location, aip, SEQ_FEAT_location))
286             goto erret;
287     }
288     if (sfp->qual != NULL)
289     {                                  /* SEQUENCE OF */
290         if (! AsnOpenStruct(aip, SEQ_FEAT_qual, (Pointer)sfp->qual))
291             goto erret;
292         gbp = sfp->qual;
293         while (gbp != NULL)
294         {
295             if (! GBQualAsnWrite(gbp, aip, SEQ_FEAT_qual_E))
296                 goto erret;
297             gbp = gbp->next;
298         }
299         if (! AsnCloseStruct(aip, SEQ_FEAT_qual, (Pointer)sfp->qual))
300             goto erret;
301     }
302     if (sfp->title != NULL)
303     {
304         av.ptrvalue = (Pointer) sfp->title;
305         if (! AsnWrite(aip, SEQ_FEAT_title, &av)) goto erret;
306     }
307     if (sfp->ext != NULL)
308     {
309         if (! UserObjectAsnWrite(sfp->ext, aip, SEQ_FEAT_ext))
310             goto erret;
311     }
312 
313     if (sfp->cit != NULL)
314     {
315         if (! PubSetAsnWrite(sfp->cit, aip, SEQ_FEAT_cit))
316             goto erret;
317     }
318 
319     if (sfp->exp_ev)
320     {
321         av.intvalue = (Int4)sfp->exp_ev;
322         if (! AsnWrite(aip, SEQ_FEAT_exp_ev, &av)) goto erret;
323     }
324 
325     if (sfp->xref != NULL)
326     {
327         if (! AsnOpenStruct(aip, SEQ_FEAT_xref, (Pointer)sfp->xref))
328             goto erret;
329         sfxp = sfp->xref;
330         while (sfxp != NULL)
331         {
332             if (! SeqFeatXrefAsnWrite(sfxp, aip, SEQ_FEAT_xref_E))
333                 goto erret;
334             sfxp = sfxp->next;
335         }
336         if (! AsnCloseStruct(aip, SEQ_FEAT_xref, (Pointer)sfp->xref))
337             goto erret;
338     }
339 
340     if (sfp->dbxref != NULL)
341     {
342         if (! AsnOpenStruct(aip, SEQ_FEAT_dbxref, (Pointer)sfp->dbxref))
343             goto erret;
344         vnp = sfp->dbxref;
345         while (vnp != NULL)
346         {
347             if (! DbtagAsnWrite((DbtagPtr)(vnp->data.ptrvalue), aip, SEQ_FEAT_dbxref_E))
348                 goto erret;
349             vnp = vnp->next;
350         }
351         if (! AsnCloseStruct(aip, SEQ_FEAT_dbxref, (Pointer)sfp->dbxref))
352             goto erret;
353     }
354     if (sfp->pseudo)
355     {
356         av.boolvalue = TRUE;
357         if ((aip->spec_version == 0) || (aip->spec_version >= 6))
358         {
359         if (! AsnWrite(aip, SEQ_FEAT_pseudo, &av)) goto erret;
360         }
361     }
362     if (sfp->except_text != NULL)
363     {
364         av.ptrvalue = sfp->except_text;
365         if ((aip->spec_version == 0) || (aip->spec_version >= 6))
366         {
367         if (! AsnWrite(aip, SEQ_FEAT_except_text, &av)) goto erret;
368         }
369     }
370     if (sfp->ids != NULL)
371     {
372         if (! AsnOpenStruct(aip, SEQ_FEAT_ids, (Pointer)sfp->ids))
373             goto erret;
374         vnp = sfp->ids;
375         while (vnp != NULL)
376         {
377             if (! SeqFeatIdAsnWrite((ChoicePtr)(vnp->data.ptrvalue), aip, SEQ_FEAT_ids_E))
378                 goto erret;
379             vnp = vnp->next;
380         }
381         if (! AsnCloseStruct(aip, SEQ_FEAT_ids, (Pointer)sfp->ids))
382             goto erret;
383         /*
384         AsnGenericChoiceSeqOfAsnWrite (sfp->ids, (AsnWriteFunc) SeqFeatIdAsnWrite, aip, SEQ_FEAT_ids, SEQ_FEAT_ids_E);
385         */
386     }
387     if (sfp->exts != NULL)
388     {
389         if (! AsnOpenStruct(aip, SEQ_FEAT_exts, (Pointer)sfp->exts))
390             goto erret;
391         uop = sfp->exts;
392         while (uop != NULL)
393         {
394             if (! UserObjectAsnWrite(uop, aip, SEQ_FEAT_exts_E))
395                 goto erret;
396             uop = uop->next;
397         }
398         if (! AsnCloseStruct(aip, SEQ_FEAT_exts, (Pointer)sfp->exts))
399             goto erret;
400         /*
401         AsnGenericUserSeqOfAsnWrite (sfp->exts, (AsnWriteFunc) UserObjectAsnWrite, aip, SEQ_FEAT_exts, SEQ_FEAT_exts_E);
402         */
403     }
404     if (! AsnCloseStruct(aip, atp, (Pointer)sfp))
405         goto erret;
406     retval = TRUE;
407 erret:
408     AsnUnlinkType(orig);       /* unlink local tree */
409     return retval;
410 }
411 
412 /*****************************************************************************
413 *
414 *   SeqFeatAsnRead(aip, atp)
415 *       atp is the current type (if identifier of a parent struct)
416 *            assumption is readIdent has occurred
417 *       if atp == NULL, then assumes it stands alone and read ident
418 *            has not occurred.
419 *
420 *****************************************************************************/
421 NLM_EXTERN SeqFeatPtr LIBCALL SeqFeatAsnRead (AsnIoPtr aip, AsnTypePtr orig)
422 {
423     DataVal av;
424     AsnTypePtr atp, oldtype;
425     SeqFeatPtr sfp;
426     GBQualPtr gbq, gbqlast = NULL;
427     SeqFeatXrefPtr sfxp, sfxplast = NULL;
428     ValNodePtr vnp, vnplast = NULL;
429     DbtagPtr dbtp;
430   Choice id;
431   ChoicePtr cp;
432     UserObjectPtr  uop, last = NULL;
433 
434     if (! loaded)
435     {
436         if (! SeqFeatAsnLoad())
437             return (SeqFeatPtr)NULL;
438     }
439 
440     if (aip == NULL)
441         return (SeqFeatPtr)NULL;
442 
443     if (orig == NULL)           /* SeqFeat ::= (self contained) */
444         atp = AsnReadId(aip, amp, SEQ_FEAT);
445     else
446         atp = AsnLinkType(orig, SEQ_FEAT);    /* link in local tree */
447     oldtype = atp;
448     if (atp == NULL)
449         return (SeqFeatPtr)NULL;
450 
451     sfp = SeqFeatNew();
452     if (sfp == NULL)
453         goto erret;
454 
455     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
456     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)
457     {
458         if (atp == NULL)
459             goto erret;
460         if (atp == SEQ_FEAT_id)
461         {
462             if (! SeqFeatIdAsnRead(aip, atp, &sfp->id))
463                 goto erret;
464         }
465         else if (atp == SEQ_FEAT_data)
466         {
467             if (! SeqFeatDataAsnRead(aip, atp, &sfp->data))
468                 goto erret;
469         }
470         else if (atp == SEQ_FEAT_product)
471         {
472             sfp->product = SeqLocAsnRead(aip, atp);
473             if (sfp->product == NULL) goto erret;
474         }
475         else if (atp == SEQ_FEAT_location)
476         {
477             sfp->location = SeqLocAsnRead(aip, atp);
478             if (sfp->location == NULL) goto erret;
479         }
480         else if (atp == SEQ_FEAT_qual_E)
481         {
482             gbq = GBQualAsnRead(aip, atp);
483             if (gbq == NULL) goto erret;
484             if (gbqlast == NULL)
485                 sfp->qual = gbq;
486             else
487                 gbqlast->next = gbq;
488             gbqlast = gbq;
489         }
490         else if (atp == SEQ_FEAT_ext)
491         {
492             sfp->ext = UserObjectAsnRead(aip, atp);
493             if (sfp->ext == NULL)
494                 goto erret;
495         }
496         else if (atp == SEQ_FEAT_cit)
497         {
498             sfp->cit = PubSetAsnRead(aip, atp);
499             if (sfp->cit == NULL)
500                 goto erret;
501         }
502         else if (atp == SEQ_FEAT_xref_E)
503         {
504             sfxp = SeqFeatXrefAsnRead(aip, atp);
505             if (sfxp == NULL) goto erret;
506             if (sfxplast == NULL)
507                 sfp->xref = sfxp;
508             else
509                 sfxplast->next = sfxp;
510             sfxplast = sfxp;
511         }
512         else if (atp == SEQ_FEAT_dbxref_E)
513         {
514             dbtp = DbtagAsnRead(aip, atp);
515             if (dbtp == NULL) goto erret;
516             vnp = ValNodeNew(vnplast);
517             if (vnplast == NULL)
518                 sfp->dbxref = vnp;
519             vnplast = vnp;
520             vnp->data.ptrvalue = (Pointer)dbtp;
521         }
522         else if (atp == SEQ_FEAT_ids)
523         {
524         atp = AsnLinkType (SEQ_FEAT_ids, FEAT_ID);
525         if (atp == NULL) goto erret;
526         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the SEQUENCE */
527             while ((atp = AsnReadId(aip, amp, atp)) == SEQ_FEAT_ids_E) {
528                 if (! SeqFeatIdAsnRead(aip, atp, &id))
529                     goto erret;
530                 cp = (ChoicePtr) MemNew (sizeof (Choice));
531                 if (cp == NULL) goto erret;
532                 cp->choice = id.choice;
533                 if (id.choice) {
534                     cp->value.intvalue = id.value.intvalue;
535                 } else {
536                     cp->value.ptrvalue = id.value.ptrvalue;
537                 }
538                 ValNodeAddPointer (&(sfp->ids), 0, (Pointer) cp);
539             }
540         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the END STRUCT */
541         AsnUnlinkType (SEQ_FEAT_ids);
542             /*
543             sfp->ids = AsnGenericChoiceSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) SeqFeatIdAsnRead, (AsnOptFreeFunc) SeqFeatIdFree);
544             if (isError && sfp->ids == NULL) {
545                 goto erret;
546             }
547             */
548     }
549     else if (atp == SEQ_FEAT_exts)
550     {
551         atp = AsnLinkType (SEQ_FEAT_exts, FEAT_ID);
552         if (atp == NULL) goto erret;
553         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the SEQUENCE */
554             while ((atp = AsnReadId(aip, amp, atp)) == SEQ_FEAT_exts_E) {
555             uop = UserObjectAsnRead (aip, atp);
556             if (uop == NULL) goto erret;
557             if (last != NULL) {
558               last->next = uop;
559             }
560             if (sfp->exts == NULL) {
561               sfp->exts = uop;
562             }
563             last = uop;
564             }
565         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the END STRUCT */
566         AsnUnlinkType (SEQ_FEAT_exts);
567             /*
568             sfp->exts = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) UserObjectAsnRead, (AsnOptFreeFunc) UserObjectFree);
569             if (isError && sfp->exts == NULL) {
570                 goto erret;
571             }
572             */
573         }
574         else
575         {
576             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
577             if (atp == SEQ_FEAT_partial)
578                 sfp->partial = av.boolvalue;
579             else if (atp == SEQ_FEAT_except)
580                 sfp->excpt = av.boolvalue;
581             else if (atp == SEQ_FEAT_comment)
582                 sfp->comment = (CharPtr) av.ptrvalue;
583             else if (atp == SEQ_FEAT_title)
584                 sfp->title = (CharPtr) av.ptrvalue;
585             else if (atp == SEQ_FEAT_exp_ev)
586                 sfp->exp_ev = (Uint1) av.intvalue;
587             else if (atp == SEQ_FEAT_pseudo)
588                 sfp->pseudo = av.boolvalue;
589             else if (atp == SEQ_FEAT_except_text)
590                 sfp->except_text = (CharPtr)(av.ptrvalue);
591         }
592     }
593     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
594 ret:
595     AsnUnlinkType(orig);       /* unlink local tree */
596     return sfp;
597 erret:
598     aip->io_failure = TRUE;
599     sfp = SeqFeatFree(sfp);
600     goto ret;
601 }
602 
603 /*****************************************************************************
604 *
605 *   SeqFeatSetAsnWrite(sfp, aip, set, element)
606 *
607 *****************************************************************************/
608 NLM_EXTERN Boolean LIBCALL SeqFeatSetAsnWrite (SeqFeatPtr sfp, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
609 {
610     return SeqFeatSetAsnWriteExtra(sfp, aip, set, element, (ValNodePtr) NULL);
611 }
612 
613 /*****************************************************************************
614 *
615 *   SeqFeatSetAsnWriteExtra(sfp, aip, set, element, extras)
616 *      this is to accomodate extra features from SeqEntryAsnOut()
617 *
618 *****************************************************************************/
619 NLM_EXTERN Boolean LIBCALL SeqFeatSetAsnWriteExtra (SeqFeatPtr sfp, AsnIoPtr aip,
620                     AsnTypePtr set, AsnTypePtr element, ValNodePtr extras)
621 {
622     AsnTypePtr atp;
623     SeqFeatPtr oldsfp, tsfp;
624     Boolean retval = FALSE;
625     Int2 ctr = 0;
626 
627     if (! loaded)
628     {
629         if (! SeqFeatAsnLoad())
630             return FALSE;
631     }
632 
633     if (aip == NULL)
634         return FALSE;
635 
636     atp = AsnLinkType(element, SEQ_FEAT);   /* link local tree */
637     if (atp == NULL)
638         return FALSE;
639 
640     oldsfp = sfp;
641     if (extras != NULL)   /* this is an extra set of feats */
642         oldsfp = (SeqFeatPtr)(extras->data.ptrvalue);
643 
644     if (! AsnOpenStruct(aip, set, (Pointer)oldsfp))
645         goto erret;
646 
647     while (sfp != NULL)
648     {
649         if (! SeqFeatAsnWrite(sfp, aip, atp))
650             goto erret;
651         sfp = sfp->next;
652         ctr++;
653         if (ctr == 20)
654         {
655             if (! ProgMon("Write SeqFeat"))
656                 goto erret;
657             ctr = 0;
658         }
659 
660     }
661 
662     while (extras != NULL)
663     {
664     tsfp = (SeqFeatPtr)(extras->data.ptrvalue);
665     if (! SeqFeatAsnWrite(tsfp, aip, atp))
666         goto erret;
667     extras = extras->next;
668     }
669 
670     if (! AsnCloseStruct(aip, set, (Pointer)oldsfp))
671         goto erret;
672     retval = TRUE;
673 erret:
674     AsnUnlinkType(element);       /* unlink local tree */
675     return retval;
676 }
677 
678 /*****************************************************************************
679 *
680 *   SeqFeatSetAsnRead(aip, set, element)
681 *
682 *****************************************************************************/
683 NLM_EXTERN SeqFeatPtr LIBCALL SeqFeatSetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
684 {
685     DataVal av;
686     AsnTypePtr atp;
687     SeqFeatPtr sfp, curr = NULL, first = NULL;
688     Int2 ctr = 0;
689 
690     if (aip == NULL)
691         return (SeqFeatPtr)NULL;
692 
693     AsnLinkType(element, SEQ_FEAT);    /* link in local tree */
694     atp = set;
695 
696     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
697     while ((atp = AsnReadId(aip, amp, atp)) == element)
698     {
699         sfp = SeqFeatAsnRead(aip, atp);
700         if (sfp == NULL)
701             goto erret;
702         if (first == NULL)
703             first = sfp;
704         else
705             curr->next = sfp;
706         curr = sfp;
707         ctr++;
708         if (ctr == 20)
709         {
710             if (! ProgMon("Read SeqFeat"))
711                 goto erret;
712             ctr = 0;
713         }
714 
715     }
716     if (atp == NULL)
717         goto erret;
718     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
719     if (first == NULL)
720         ErrPostEx(SEV_WARNING, 0, 0, "Empty SET OF Seq-feat. line %ld", (long) aip->linenumber);
721 ret:
722     AsnUnlinkType(element);       /* unlink local tree */
723     return first;
724 erret:
725     while (first != NULL)
726     {
727         curr = first;
728         first = curr->next;
729         SeqFeatFree(curr);
730     }
731     goto ret;
732 }
733 
734 /*****************************************************************************
735 *
736 *   SeqFeatDataFree(cp)
737 *
738 *****************************************************************************/
739 NLM_EXTERN void LIBCALL SeqFeatDataFree(ChoicePtr cp)
740 {
741     Pointer pnt;
742 
743     pnt = cp->value.ptrvalue;
744     switch (cp->choice)
745     {
746         case SEQFEAT_GENE :
747             GeneRefFree((GeneRefPtr)pnt);
748             break;
749         case SEQFEAT_ORG :
750             OrgRefFree((OrgRefPtr)pnt);
751             break;
752         case SEQFEAT_CDREGION :
753             CdRegionFree((CdRegionPtr)pnt);
754             break;
755         case SEQFEAT_PROT :
756             ProtRefFree((ProtRefPtr)pnt);
757             break;
758         case SEQFEAT_RNA :
759             RnaRefFree((RnaRefPtr)pnt);
760             break;
761         case SEQFEAT_PUB :
762             PubdescFree((PubdescPtr)pnt);
763             break;
764         case SEQFEAT_SEQ :         /* seq */
765             SeqLocFree((ValNodePtr)pnt);
766             break;
767         case SEQFEAT_IMP :
768             ImpFeatFree((ImpFeatPtr)pnt);
769             break;
770         case SEQFEAT_REGION:        /* region */
771         case SEQFEAT_NON_STD_RESIDUE :       /* non-std residue */
772         case SEQFEAT_HET:       /* heterogen */
773             MemFree(pnt);
774             break;
775         case SEQFEAT_COMMENT:       /* comment - nothing */
776         case SEQFEAT_BOND:       /* bond - int */
777         case SEQFEAT_SITE:       /* site - int */
778         case SEQFEAT_PSEC_STR:       /* psec_struct - int */
779             break;
780         case SEQFEAT_RSITE:
781             RsiteRefFree((RsiteRefPtr)pnt);
782             break;
783         case SEQFEAT_USER:
784             UserObjectFree((UserObjectPtr)pnt);
785             break;
786         case SEQFEAT_TXINIT:
787             TxinitFree((TxinitPtr)pnt);
788             break;
789         case SEQFEAT_NUM:
790             NumberingFree((NumberingPtr)pnt);
791             break;
792         case SEQFEAT_BIOSRC:
793             BioSourceFree((BioSourcePtr)pnt);
794             break;
795         case SEQFEAT_CLONEREF:
796             CloneRefFree((CloneRefPtr)pnt);
797             break;
798     }
799     return;
800 }
801 
802 /*****************************************************************************
803 *
804 *   SeqFeatDataAsnWrite(cp, aip, atp)
805 *       atp is the current type (if identifier of a parent struct)
806 *       if atp == NULL, then assumes it stands alone (SeqFeatData ::=)
807 *
808 *****************************************************************************/
809 NLM_EXTERN Boolean LIBCALL SeqFeatDataAsnWrite (ChoicePtr cp, AsnIoPtr aip, AsnTypePtr orig)
810 {
811     DataVal av;
812     Pointer pnt;
813     AsnTypePtr atp;
814     Boolean retval = FALSE;
815 
816     if (! loaded)
817     {
818         if (! SeqFeatAsnLoad())
819             return FALSE;
820     }
821 
822     if (aip == NULL)
823         return FALSE;
824 
825     atp = AsnLinkType(orig, SEQFEATDATA);   /* link local tree */
826     if (atp == NULL)
827         return FALSE;
828 
829     if (cp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
830 
831     pnt = cp->value.ptrvalue;
832     av.ptrvalue = pnt;
833     if (! AsnWriteChoice(aip, atp, (Int2)cp->choice, &av)) goto erret;
834 
835     switch (cp->choice)
836     {
837         case SEQFEAT_GENE :
838             if (! GeneRefAsnWrite((GeneRefPtr)pnt, aip, SEQFEATDATA_gene))
839                 goto erret;
840             break;
841         case SEQFEAT_ORG :
842             if (! OrgRefAsnWrite((OrgRefPtr)pnt, aip, SEQFEATDATA_org))
843                 goto erret;
844             break;
845         case SEQFEAT_CDREGION :
846             if (! CdRegionAsnWrite((CdRegionPtr)pnt, aip, SEQFEATDATA_cdregion))
847                 goto erret;
848             break;
849         case SEQFEAT_PROT :
850             if (! ProtRefAsnWrite((ProtRefPtr)pnt, aip, SEQFEATDATA_prot))
851                 goto erret;
852             break;
853         case SEQFEAT_RNA :
854             if (! RnaRefAsnWrite((RnaRefPtr)pnt, aip, SEQFEATDATA_rna))
855                 goto erret;
856             break;
857         case SEQFEAT_PUB:
858             if (! PubdescAsnWrite((PubdescPtr)pnt, aip, SEQFEATDATA_pub))
859                 goto erret;
860             break;
861         case SEQFEAT_SEQ:         /* seq reference */
862             if (! SeqLocAsnWrite((ValNodePtr)pnt, aip, SEQFEATDATA_seq))
863                 goto erret;
864             break;
865         case SEQFEAT_IMP:
866             if (! ImpFeatAsnWrite((ImpFeatPtr)pnt, aip, SEQFEATDATA_imp))
867                 goto erret;
868             break;
869         case SEQFEAT_REGION:        /* region */
870             av.ptrvalue = pnt;
871             if (! AsnWrite(aip, SEQFEATDATA_region, &av)) goto erret;
872             break;
873         case SEQFEAT_COMMENT:       /* comment - nothing */
874             if (! AsnWrite(aip, SEQFEATDATA_comment, &av)) goto erret;
875             break;
876         case SEQFEAT_BOND:       /* bond - int */
877             av.intvalue = cp->value.intvalue;
878             if (! AsnWrite(aip, SEQFEATDATA_bond, &av)) goto erret;
879             break;
880         case SEQFEAT_SITE:       /* site - int */
881             av.intvalue = cp->value.intvalue;
882             if (! AsnWrite(aip, SEQFEATDATA_site, &av)) goto erret;
883             break;
884         case SEQFEAT_RSITE:       /* rsite-ref */
885             if (! RsiteRefAsnWrite((RsiteRefPtr)pnt, aip, SEQFEATDATA_rsite))
886                 goto erret;
887             break;
888         case SEQFEAT_USER:       /* user object */
889             if (! UserObjectAsnWrite((UserObjectPtr)pnt, aip, SEQFEATDATA_user))
890                 goto erret;
891             break;
892         case SEQFEAT_TXINIT:
893             if (! TxinitAsnWrite((TxinitPtr)pnt, aip, SEQFEATDATA_txinit))
894                 goto erret;
895             break;
896         case SEQFEAT_NUM:
897             if (! NumberingAsnWrite((NumberingPtr)pnt, aip, SEQFEATDATA_num))
898                 goto erret;
899             break;
900         case SEQFEAT_PSEC_STR:       /* psec-struct - int */
901             av.intvalue = cp->value.intvalue;
902             if (! AsnWrite(aip, SEQFEATDATA_psec_str, &av)) goto erret;
903             break;
904         case SEQFEAT_NON_STD_RESIDUE:        /* non-std residue */
905             av.ptrvalue = pnt;
906             if (! AsnWrite(aip, SEQFEATDATA_non_std_residue, &av)) goto erret;
907             break;
908         case SEQFEAT_HET:        /* heterogen */
909             av.ptrvalue = pnt;
910             if (! AsnWrite(aip, SEQFEATDATA_het, &av)) goto erret;
911             break;
912         case SEQFEAT_BIOSRC:
913             if (! BioSourceAsnWrite((BioSourcePtr)pnt, aip, SEQFEATDATA_biosrc))
914                 goto erret;
915             break;
916         case SEQFEAT_CLONEREF:
917             if (! CloneRefAsnWrite((CloneRefPtr)pnt, aip, SEQFEATDATA_clone))
918                 goto erret;
919             break;
920     }
921 
922     retval = TRUE;
923 erret:
924     AsnUnlinkType(orig);       /* unlink local tree */
925     return retval;
926 }
927 
928 /*****************************************************************************
929 *
930 *   SeqFeatDataAsnRead(aip, atp, cp)
931 *       atp is the current type (if identifier of a parent struct)
932 *            assumption is readIdent has occurred
933 *       if atp == NULL, then assumes it stands alone and read ident
934 *            has not occurred.
935 *
936 *****************************************************************************/
937 NLM_EXTERN Boolean LIBCALL SeqFeatDataAsnRead (AsnIoPtr aip, AsnTypePtr orig, ChoicePtr cp)
938 {
939     DataVal av;
940     AsnTypePtr atp;
941     Boolean retval = FALSE;
942 
943     if (! loaded)
944     {
945         if (! SeqFeatAsnLoad())
946             return retval;
947     }
948 
949     if (aip == NULL)
950         return retval;
951 
952     if (orig == NULL)           /* SeqFeatData ::= (self contained) */
953         atp = AsnReadId(aip, amp, SEQFEATDATA);
954     else
955         atp = AsnLinkType(orig, SEQFEATDATA);    /* link in local tree */
956     if (atp == NULL)
957         return retval;
958 
959     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read CHOICE */
960     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
961     if (atp == SEQFEATDATA_gene)
962     {
963         cp->choice = SEQFEAT_GENE ;
964         cp->value.ptrvalue = (Pointer)GeneRefAsnRead(aip, atp);
965         if (cp->value.ptrvalue == NULL)
966             goto erret;
967     }
968     else if (atp == SEQFEATDATA_org)
969     {
970         cp->choice = SEQFEAT_ORG ;
971         cp->value.ptrvalue = (Pointer)OrgRefAsnRead(aip, atp);
972         if (cp->value.ptrvalue == NULL)
973             goto erret;
974     }
975     else if (atp == SEQFEATDATA_cdregion)
976     {
977         cp->choice = SEQFEAT_CDREGION ;
978         cp->value.ptrvalue = (Pointer)CdRegionAsnRead(aip, atp);
979         if (cp->value.ptrvalue == NULL)
980             goto erret;
981     }
982     else if (atp == SEQFEATDATA_prot)
983     {
984         cp->choice = SEQFEAT_PROT ;
985         cp->value.ptrvalue = (Pointer)ProtRefAsnRead(aip, atp);
986         if (cp->value.ptrvalue == NULL)
987             goto erret;
988     }
989     else if (atp == SEQFEATDATA_rna)
990     {
991         cp->choice = SEQFEAT_RNA ;
992         cp->value.ptrvalue = (Pointer)RnaRefAsnRead(aip, atp);
993         if (cp->value.ptrvalue == NULL)
994             goto erret;
995     }
996     else if (atp == SEQFEATDATA_pub)
997     {
998         cp->choice = SEQFEAT_PUB ;
999         cp->value.ptrvalue = (Pointer)PubdescAsnRead(aip, atp);
1000         if (cp->value.ptrvalue == NULL)
1001             goto erret;
1002     }
1003     else if (atp == SEQFEATDATA_seq)
1004     {
1005         cp->choice = SEQFEAT_SEQ ;
1006         cp->value.ptrvalue = (Pointer)SeqLocAsnRead(aip, atp);
1007         if (cp->value.ptrvalue == NULL)
1008             goto erret;
1009     }
1010     else if (atp == SEQFEATDATA_imp)
1011     {
1012         cp->choice = SEQFEAT_IMP ;
1013         cp->value.ptrvalue = (Pointer)ImpFeatAsnRead(aip, atp);
1014         if (cp->value.ptrvalue == NULL)
1015             goto erret;
1016     }
1017     else if (atp == SEQFEATDATA_region)
1018     {
1019         cp->choice = SEQFEAT_REGION ;
1020         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1021         cp->value.ptrvalue = av.ptrvalue;
1022     }
1023     else if (atp == SEQFEATDATA_comment)
1024     {
1025         cp->choice = SEQFEAT_COMMENT ;
1026         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1027     }
1028     else if (atp == SEQFEATDATA_bond)
1029     {
1030         cp->choice = SEQFEAT_BOND ;
1031         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1032         cp->value.intvalue = av.intvalue;
1033     }
1034     else if (atp == SEQFEATDATA_site)
1035     {
1036         cp->choice = SEQFEAT_SITE ;
1037         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1038         cp->value.intvalue = av.intvalue;
1039     }
1040     else if (atp == SEQFEATDATA_rsite)
1041     {
1042         cp->choice = SEQFEAT_RSITE ;
1043         cp->value.ptrvalue = (Pointer)RsiteRefAsnRead(aip, atp);
1044         if (cp->value.ptrvalue == NULL)
1045             goto erret;
1046     }
1047     else if (atp == SEQFEATDATA_user)
1048     {
1049         cp->choice = SEQFEAT_USER ;
1050         cp->value.ptrvalue = (Pointer)UserObjectAsnRead(aip, atp);
1051         if (cp->value.ptrvalue == NULL)
1052             goto erret;
1053     }
1054     else if (atp == SEQFEATDATA_txinit)
1055     {
1056         cp->choice = SEQFEAT_TXINIT ;
1057         cp->value.ptrvalue = (Pointer)TxinitAsnRead(aip, atp);
1058         if (cp->value.ptrvalue == NULL)
1059             goto erret;
1060     }
1061     else if (atp == SEQFEATDATA_num)
1062     {
1063         cp->choice = SEQFEAT_NUM ;
1064         cp->value.ptrvalue = (Pointer)NumberingAsnRead(aip, atp);
1065         if (cp->value.ptrvalue == NULL)
1066             goto erret;
1067     }
1068     else if (atp == SEQFEATDATA_psec_str)
1069     {
1070         cp->choice = SEQFEAT_PSEC_STR ;
1071         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1072         cp->value.intvalue = av.intvalue;
1073     }
1074     else if (atp == SEQFEATDATA_non_std_residue)
1075     {
1076         cp->choice = SEQFEAT_NON_STD_RESIDUE ;
1077         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1078         cp->value.ptrvalue = av.ptrvalue;
1079     }
1080     else if (atp == SEQFEATDATA_het)
1081     {
1082         cp->choice = SEQFEAT_HET ;
1083         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1084         cp->value.ptrvalue = av.ptrvalue;
1085     }
1086     else if (atp == SEQFEATDATA_biosrc)
1087     {
1088         cp->choice = SEQFEAT_BIOSRC ;
1089         cp->value.ptrvalue = (Pointer)BioSourceAsnRead(aip, atp);
1090         if (cp->value.ptrvalue == NULL)
1091             goto erret;
1092     }
1093     else if (atp == SEQFEATDATA_clone)
1094     {
1095         cp->choice = SEQFEAT_CLONEREF ;
1096         cp->value.ptrvalue = (Pointer)CloneRefAsnRead(aip, atp);
1097         if (cp->value.ptrvalue == NULL)
1098             goto erret;
1099     }
1100 
1101     retval = TRUE;
1102 erret:
1103     AsnUnlinkType(orig);       /* unlink local tree */
1104     return retval;
1105 }
1106 
1107 /*****************************************************************************
1108 *
1109 *   GBQualNew()
1110 *
1111 *****************************************************************************/
1112 NLM_EXTERN GBQualPtr LIBCALL GBQualNew (void)
1113 {
1114     return (GBQualPtr)MemNew(sizeof(GBQual));
1115 }
1116 
1117 /*****************************************************************************
1118 *
1119 *   GBQualFree(gbp)
1120 *       Frees a chain of GBQual and associated data
1121 *
1122 *****************************************************************************/
1123 NLM_EXTERN GBQualPtr LIBCALL GBQualFree (GBQualPtr gbp)
1124 {
1125     GBQualPtr next;
1126 
1127     while (gbp != NULL)
1128     {
1129         next = gbp->next;
1130         MemFree(gbp->qual);
1131         MemFree(gbp->val);
1132         MemFree(gbp);
1133         gbp = next;
1134     }
1135     return (GBQualPtr)NULL;
1136 }
1137 
1138 /*****************************************************************************
1139 *
1140 *   GBQualAsnWrite(gbp, aip, atp)
1141 *       atp is the current type (if identifier of a parent struct)
1142 *       if atp == NULL, then assumes it stands alone (GBQual ::=)
1143 *
1144 *****************************************************************************/
1145 NLM_EXTERN Boolean LIBCALL GBQualAsnWrite (GBQualPtr gbp, AsnIoPtr aip, AsnTypePtr orig)
1146 {
1147     DataVal av;
1148     AsnTypePtr atp;
1149     Boolean retval = FALSE;
1150 
1151     if (! loaded)
1152     {
1153         if (! SeqFeatAsnLoad())
1154             return FALSE;
1155     }
1156 
1157     if (aip == NULL)
1158         return FALSE;
1159 
1160     atp = AsnLinkType(orig, GB_QUAL);   /* link local tree */
1161     if (atp == NULL)
1162         return FALSE;
1163 
1164     if (gbp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1165 
1166     if (! AsnOpenStruct(aip, atp, (Pointer)gbp))
1167         goto erret;
1168 
1169     av.ptrvalue = (Pointer)gbp->qual;
1170     if (! AsnWrite(aip, GB_QUAL_qual, &av)) goto erret;
1171     av.ptrvalue = (Pointer)gbp->val;
1172     if (! AsnWrite(aip, GB_QUAL_val, &av)) goto erret;
1173 
1174     if (! AsnCloseStruct(aip, atp, (Pointer)gbp))
1175         goto erret;
1176     retval = TRUE;
1177 erret:
1178     AsnUnlinkType(orig);       /* unlink local tree */
1179     return retval;
1180 }
1181 
1182 /*****************************************************************************
1183 *
1184 *   GBQualAsnRead(aip, atp)
1185 *       atp is the current type (if identifier of a parent struct)
1186 *            assumption is readIdent has occurred
1187 *       if atp == NULL, then assumes it stands alone and read ident
1188 *            has not occurred.
1189 *
1190 *****************************************************************************/
1191 NLM_EXTERN GBQualPtr LIBCALL GBQualAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1192 {
1193     DataVal av;
1194     AsnTypePtr atp;
1195     GBQualPtr gbp=NULL;
1196 
1197     if (! loaded)
1198     {
1199         if (! SeqFeatAsnLoad())
1200             return gbp;
1201     }
1202 
1203     if (aip == NULL)
1204         return gbp;
1205 
1206     if (orig == NULL)           /* GBQual ::= (self contained) */
1207         atp = AsnReadId(aip, amp, GB_QUAL);
1208     else
1209         atp = AsnLinkType(orig, GB_QUAL);    /* link in local tree */
1210     if (atp == NULL)
1211         return gbp;
1212 
1213     gbp = GBQualNew();
1214     if (gbp == NULL)
1215         goto erret;
1216 
1217     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
1218 
1219     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1220     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1221     gbp->qual = (CharPtr)av.ptrvalue;
1222     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1223     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1224     gbp->val = (CharPtr)av.ptrvalue;
1225     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1226     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
1227 ret:
1228     AsnUnlinkType(orig);       /* unlink local tree */
1229     return gbp;
1230 erret:
1231     gbp = GBQualFree(gbp);
1232     goto ret;
1233 }
1234 
1235 /*****************************************************************************
1236 *
1237 *   SeqFeatXrefNew()
1238 *
1239 *****************************************************************************/
1240 NLM_EXTERN SeqFeatXrefPtr LIBCALL SeqFeatXrefNew (void)
1241 {
1242     return (SeqFeatXrefPtr)MemNew(sizeof(SeqFeatXref));
1243 }
1244 
1245 /*****************************************************************************
1246 *
1247 *   SeqFeatToXref(sfp)
1248 *       Copy a SeqFeat to an Xref
1249 *       Currently only works on Gene-ref and Prot-ref
1250 *
1251 *****************************************************************************/
1252 NLM_EXTERN SeqFeatXrefPtr LIBCALL SeqFeatToXref (SeqFeatPtr sfp)
1253 {
1254     SeqFeatXrefPtr sfxp;
1255 
1256     if (sfp == NULL)
1257         return (SeqFeatXrefPtr)NULL;
1258 
1259     sfxp = SeqFeatXrefNew();
1260     if (sfxp == NULL) return NULL;
1261     SeqFeatIdDup(&sfxp->id, &sfp->id);
1262     switch (sfp->data.choice)
1263     {
1264         case SEQFEAT_GENE :
1265             sfxp->data.value.ptrvalue = (Pointer) GeneRefDup((GeneRefPtr)sfp->data.value.ptrvalue);
1266             sfxp->data.choice = sfp->data.choice;
1267             break;
1268         case SEQFEAT_PROT :
1269             sfxp->data.value.ptrvalue = (Pointer) ProtRefDup((ProtRefPtr)sfp->data.value.ptrvalue);
1270             sfxp->data.choice = sfp->data.choice;
1271             break;
1272         default:
1273             ErrPostEx(SEV_WARNING, 0, 0, "Unsupported SeqFeatToXref");
1274             break;
1275     }
1276 
1277     return sfxp;
1278 }
1279 
1280 /*****************************************************************************
1281 *
1282 *   SeqFeatXrefFree(sfxp)
1283 *       Frees a chain of SeqFeatXref and associated data
1284 *
1285 *****************************************************************************/
1286 NLM_EXTERN SeqFeatXrefPtr LIBCALL SeqFeatXrefFree (SeqFeatXrefPtr sfxp)
1287 {
1288     SeqFeatXrefPtr next;
1289 
1290     while (sfxp != NULL)
1291     {
1292         next = sfxp->next;
1293         SeqFeatIdFree(&sfxp->id);
1294         SeqFeatDataFree(&sfxp->data);
1295         MemFree(sfxp);
1296         sfxp = next;
1297     }
1298     return (SeqFeatXrefPtr)NULL;
1299 }
1300 
1301 /*****************************************************************************
1302 *
1303 *   SeqFeatXrefAsnWrite(sfxp, aip, atp)
1304 *       atp is the current type (if identifier of a parent struct)
1305 *       if atp == NULL, then assumes it stands alone (SeqFeatXref ::=)
1306 *
1307 *****************************************************************************/
1308 NLM_EXTERN Boolean LIBCALL SeqFeatXrefAsnWrite (SeqFeatXrefPtr sfxp, AsnIoPtr aip, AsnTypePtr orig)
1309 {
1310     AsnTypePtr atp;
1311     Boolean retval = FALSE;
1312 
1313     if (! loaded)
1314     {
1315         if (! SeqFeatAsnLoad())
1316             return FALSE;
1317     }
1318 
1319     if (aip == NULL)
1320         return FALSE;
1321 
1322     atp = AsnLinkType(orig, SEQFEATXREF);   /* link local tree */
1323     if (atp == NULL)
1324         return FALSE;
1325 
1326     if (sfxp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1327 
1328     if (! AsnOpenStruct(aip, atp, (Pointer)sfxp))
1329         goto erret;
1330 
1331     if (sfxp->id.choice)              /* feat-id present */
1332     {
1333         if (! SeqFeatIdAsnWrite(&sfxp->id, aip, SEQFEATXREF_id))
1334             goto erret;
1335     }
1336 
1337     if (sfxp->data.choice)            /* data present */
1338     {
1339         if (! SeqFeatDataAsnWrite(&sfxp->data, aip, SEQFEATXREF_data))
1340             goto erret;
1341     }
1342 
1343     if (! AsnCloseStruct(aip, atp, (Pointer)sfxp))
1344         goto erret;
1345     retval = TRUE;
1346 erret:
1347     AsnUnlinkType(orig);       /* unlink local tree */
1348     return retval;
1349 }
1350 
1351 /*****************************************************************************
1352 *
1353 *   SeqFeatXrefAsnRead(aip, atp)
1354 *       atp is the current type (if identifier of a parent struct)
1355 *            assumption is readIdent has occurred
1356 *       if atp == NULL, then assumes it stands alone and read ident
1357 *            has not occurred.
1358 *
1359 *****************************************************************************/
1360 NLM_EXTERN SeqFeatXrefPtr LIBCALL SeqFeatXrefAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1361 {
1362     DataVal av;
1363     AsnTypePtr atp;
1364     SeqFeatXrefPtr sfxp;
1365 
1366     if (! loaded)
1367     {
1368         if (! SeqFeatAsnLoad())
1369             return (SeqFeatXrefPtr)NULL;
1370     }
1371 
1372     if (aip == NULL)
1373         return (SeqFeatXrefPtr)NULL;
1374 
1375     if (orig == NULL)           /* SeqFeatXref ::= (self contained) */
1376         atp = AsnReadId(aip, amp, SEQFEATXREF);
1377     else
1378         atp = AsnLinkType(orig, SEQFEATXREF);    /* link in local tree */
1379     if (atp == NULL)
1380         return (SeqFeatXrefPtr)NULL;
1381 
1382     sfxp = SeqFeatXrefNew();
1383     if (sfxp == NULL)
1384         goto erret;
1385 
1386     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
1387     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1388 
1389     if (atp == SEQFEATXREF_id)
1390     {
1391         if (! SeqFeatIdAsnRead(aip, atp, &sfxp->id))
1392             goto erret;
1393         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1394     }
1395 
1396     if (atp == SEQFEATXREF_data)
1397     {
1398         if (! SeqFeatDataAsnRead(aip, atp, &sfxp->data))
1399             goto erret;
1400         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1401     }
1402 
1403     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
1404 ret:
1405     AsnUnlinkType(orig);       /* unlink local tree */
1406     return sfxp;
1407 erret:
1408     sfxp = SeqFeatXrefFree(sfxp);
1409     goto ret;
1410 }
1411 
1412 /*****************************************************************************
1413 *
1414 *   CdRegionNew()
1415 *
1416 *****************************************************************************/
1417 NLM_EXTERN CdRegionPtr LIBCALL CdRegionNew (void)
1418 {
1419     return (CdRegionPtr)MemNew(sizeof(CdRegion));
1420 }
1421 
1422 /*****************************************************************************
1423 *
1424 *   CdRegionFree(cdp)
1425 *       Frees a CdRegion and associated data
1426 *
1427 *****************************************************************************/
1428 NLM_EXTERN CdRegionPtr LIBCALL CdRegionFree (CdRegionPtr cdp)
1429 {
1430     if (cdp == NULL)
1431         return cdp;
1432 
1433     GeneticCodeFree(cdp->genetic_code);
1434     CodeBreakFree(cdp->code_break);
1435     return (CdRegionPtr)MemFree(cdp);
1436 }
1437 
1438 /*****************************************************************************
1439 *
1440 *   CdRegionAsnWrite(cdp, aip, atp)
1441 *       atp is the current type (if identifier of a parent struct)
1442 *       if atp == NULL, then assumes it stands alone (CdRegion ::=)
1443 *
1444 *****************************************************************************/
1445 NLM_EXTERN Boolean LIBCALL CdRegionAsnWrite (CdRegionPtr cdp, AsnIoPtr aip, AsnTypePtr orig)
1446 {
1447     DataVal av;
1448     AsnTypePtr atp;
1449     CodeBreakPtr cbp;
1450     Boolean retval = FALSE;
1451 
1452     if (! loaded)
1453     {
1454         if (! SeqFeatAsnLoad())
1455             return FALSE;
1456     }
1457 
1458     if (aip == NULL)
1459         return FALSE;
1460 
1461     atp = AsnLinkType(orig, CDREGION);   /* link local tree */
1462     if (atp == NULL)
1463         return FALSE;
1464 
1465     if (cdp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1466 
1467     if (! AsnOpenStruct(aip, atp, (Pointer)cdp))
1468         goto erret;
1469     
1470     if (cdp->orf)
1471     {
1472         av.boolvalue = cdp->orf;
1473         if (! AsnWrite(aip, CDREGION_orf, &av)) goto erret;
1474     }
1475     if (cdp->frame)
1476     {
1477         av.intvalue = cdp->frame;
1478         if (! AsnWrite(aip, CDREGION_frame, &av)) goto erret;
1479     }
1480     if (cdp->conflict)
1481     {
1482         av.boolvalue = cdp->conflict;
1483         if (! AsnWrite(aip, CDREGION_conflict, &av)) goto erret;
1484     }
1485     if (cdp->gaps)
1486     {
1487         av.intvalue = cdp->gaps;
1488         if (! AsnWrite(aip, CDREGION_gaps, &av)) goto erret;
1489     }
1490     if (cdp->mismatch)
1491     {
1492         av.intvalue = cdp->mismatch;
1493         if (! AsnWrite(aip, CDREGION_mismatch, &av)) goto erret;
1494     }
1495     if (cdp->genetic_code != NULL)
1496     {
1497         if (! GeneticCodeAsnWrite(cdp->genetic_code, aip, CDREGION_code))
1498             goto erret;
1499     }
1500     if (cdp->code_break != NULL)
1501     {
1502         if (! AsnOpenStruct(aip, CDREGION_code_break, (Pointer)cdp->code_break))
1503             goto erret;
1504         cbp = cdp->code_break;
1505         while (cbp != NULL)
1506         {
1507             if (! CodeBreakAsnWrite(cbp, aip, CDREGION_code_break_E))
1508                 goto erret;
1509             cbp = cbp->next;
1510         }
1511         if (! AsnCloseStruct(aip, CDREGION_code_break, (Pointer)cdp->code_break))
1512             goto erret;
1513     }
1514     if (cdp->stops)
1515     {
1516         av.intvalue = cdp->stops;
1517         if (! AsnWrite(aip, CDREGION_stops, &av)) goto erret;
1518     }
1519 
1520     if (! AsnCloseStruct(aip, atp, (Pointer)cdp))
1521         goto erret;
1522     retval = TRUE;
1523 erret:
1524     AsnUnlinkType(orig);       /* unlink local tree */
1525     return retval;
1526 }
1527 
1528 /*****************************************************************************
1529 *
1530 *   CdRegionAsnRead(aip, atp)
1531 *       atp is the current type (if identifier of a parent struct)
1532 *            assumption is readIdent has occurred
1533 *       if atp == NULL, then assumes it stands alone and read ident
1534 *            has not occurred.
1535 *
1536 *****************************************************************************/
1537 NLM_EXTERN CdRegionPtr LIBCALL CdRegionAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1538 {
1539     DataVal av;
1540     AsnTypePtr atp, oldatp;
1541     CdRegionPtr cdp;
1542     CodeBreakPtr curr, next;
1543 
1544     if (! loaded)
1545     {
1546         if (! SeqFeatAsnLoad())
1547             return (CdRegionPtr)NULL;
1548     }
1549 
1550     if (aip == NULL)
1551         return (CdRegionPtr)NULL;
1552 
1553     if (orig == NULL)           /* CdRegion ::= (self contained) */
1554         atp = AsnReadId(aip, amp, CDREGION);
1555     else
1556         atp = AsnLinkType(orig, CDREGION);    /* link in local tree */
1557     oldatp = atp;
1558     if (atp == NULL)
1559         return (CdRegionPtr)NULL;
1560 
1561     cdp = CdRegionNew();
1562     if (cdp == NULL)
1563         goto erret;
1564 
1565     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
1566     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
1567     {
1568         if (atp == NULL)
1569             goto erret;
1570         if (atp == CDREGION_code)
1571         {
1572             cdp->genetic_code = GeneticCodeAsnRead(aip, atp);
1573             if (cdp->genetic_code == NULL)
1574                 goto erret;
1575         }
1576         else
1577         {
1578             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1579             if (atp == CDREGION_orf)
1580                 cdp->orf = av.boolvalue;
1581             else if (atp == CDREGION_conflict)
1582                 cdp->conflict = av.boolvalue;
1583             else if (atp == CDREGION_gaps)
1584             {
1585                 if (av.intvalue > 255)
1586                     av.intvalue = 255;
1587                 cdp->gaps = (Uint1)av.intvalue;
1588             }
1589             else if (atp == CDREGION_frame)
1590             {
1591                 if (av.intvalue > 255)
1592                     av.intvalue = 255;
1593                 cdp->frame = (Uint1)av.intvalue;
1594             }
1595             else if (atp == CDREGION_mismatch)
1596             {
1597                 if (av.intvalue > 255)
1598                     av.intvalue = 255;
1599                 cdp->mismatch = (Uint1)av.intvalue;
1600             }
1601             else if (atp == CDREGION_stops)
1602             {
1603                 if (av.intvalue > 255)
1604                     av.intvalue = 255;
1605                 cdp->stops = (Uint1)av.intvalue;
1606             }
1607             else if (atp == CDREGION_code_break)
1608             {
1609                 curr = NULL;
1610                 while ((atp = AsnReadId(aip, amp, atp)) == CDREGION_code_break_E)
1611                 {
1612                     next = CodeBreakAsnRead(aip, atp);
1613                     if (next == NULL)
1614                         goto erret;
1615                     if (cdp->code_break == NULL)
1616                         cdp->code_break = next;
1617                     else
1618                         curr->next = next;
1619                     curr = next;
1620                 }
1621                 if (atp == NULL)
1622                     goto erret;
1623                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1624             }
1625 
1626         }
1627     }
1628 
1629     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
1630 ret:
1631     AsnUnlinkType(orig);       /* unlink local tree */
1632     return cdp;
1633 erret:
1634     cdp = CdRegionFree(cdp);
1635     goto ret;
1636 }
1637 
1638 static GeneticCodePtr genetic_codes = NULL;    /* array of ValNodes */
1639 static Boolean GeneticCodeAdd PROTO((GeneticCodePtr gc));
1640 
1641 /*****************************************************************************
1642 *
1643 *   GeneticCodeNew()
1644 *       returns a ValNodePtr for the head of the chain
1645 *       first ValNode has the choice 254, 
1646 *       The chain of GeneticCode elements is attached to data.ptrvalue of
1647 *         this first node.
1648 *
1649 *****************************************************************************/
1650 NLM_EXTERN GeneticCodePtr LIBCALL GeneticCodeNew (void)
1651 {
1652     GeneticCodePtr gc;
1653 
1654     gc = ValNodeNew(NULL);
1655     if (gc == NULL) return gc;
1656     gc->choice = 254;
1657 
1658     return gc;
1659 }
1660 
1661 /*****************************************************************************
1662 *
1663 *   GeneticCodeAdd()
1664 *       Adds to genetic_codes global list
1665 *       This should only be used by GeneticCodeTableRead()
1666 *
1667 *****************************************************************************/
1668 static Boolean GeneticCodeAdd (GeneticCodePtr gc)
1669 {
1670     GeneticCodePtr tmp;
1671 
1672     if (gc == NULL)
1673         return FALSE;
1674 
1675     if (genetic_codes == NULL)
1676         genetic_codes = gc;
1677     else
1678     {
1679         tmp = genetic_codes;
1680         while (tmp->next != NULL)
1681             tmp = tmp->next;
1682         tmp->next = gc;
1683     }
1684 
1685     return TRUE;
1686 }
1687 
1688 /*****************************************************************************
1689 *
1690 *   GeneticCodeFree(gcp)
1691 *       Frees a GeneticCode and associated data
1692 *
1693 *****************************************************************************/
1694 NLM_EXTERN GeneticCodePtr LIBCALL GeneticCodeFree (GeneticCodePtr gcp)
1695 {
1696     ValNodePtr prev, next;
1697 
1698     if (gcp == NULL)
1699         return (GeneticCodePtr)NULL;
1700 
1701     if (gcp->choice == 254)   /* head of chain */
1702     {
1703         next = genetic_codes;
1704         prev = NULL;
1705         while ((next != NULL) && (gcp != next))
1706         {
1707             prev = next;
1708             next = prev->next;
1709         }
1710 
1711         if (next != NULL)      /* found it */
1712         {
1713             if (prev != NULL)   /* not the first one */
1714                 prev->next = next->next;
1715             else
1716                 genetic_codes = next->next;
1717             gcp->next = NULL;
1718         }
1719 
1720         prev = gcp;
1721         gcp = (GeneticCodePtr) prev->data.ptrvalue;
1722         MemFree(prev);
1723     }
1724 
1725     while (gcp != NULL)
1726     {
1727         next = gcp->next;
1728         switch (gcp->choice)
1729         {
1730             case 1:   /* name */
1731             case 3:   /* ncbieaa */
1732             case 6:   /* sncbieaa */
1733                 MemFree(gcp->data.ptrvalue);
1734                 break;
1735             case 4:   /* ncbi8aa */
1736             case 5:      /* ncbistdaa */
1737             case 7:   /* sncbi8aa */
1738             case 8:   /* sncbistdaa */
1739                 BSFree((ByteStorePtr)gcp->data.ptrvalue);
1740                 break;
1741             default:
1742                 break;
1743         }
1744         MemFree(gcp);
1745         gcp = next;
1746     }
1747     return (GeneticCodePtr)NULL;
1748 }
1749 
1750 /*****************************************************************************
1751 *
1752 *   GeneticCodeAsnWrite(gcp, aip, atp)
1753 *       atp is the current type (if identifier of a parent struct)
1754 *       if atp == NULL, then assumes it stands alone (GeneticCode ::=)
1755 *
1756 *****************************************************************************/
1757 NLM_EXTERN Boolean LIBCALL GeneticCodeAsnWrite (GeneticCodePtr gcp, AsnIoPtr aip, AsnTypePtr orig)
1758 {
1759     GeneticCodePtr tmp;
1760     DataVal av;
1761     AsnTypePtr atp, gtp;
1762     Boolean retval = FALSE;
1763 
1764     if (! loaded)
1765     {
1766         if (! SeqFeatAsnLoad())
1767             return FALSE;
1768     }
1769 
1770     if (aip == NULL)
1771         return FALSE;
1772 
1773     atp = AsnLinkType(orig, GENETIC_CODE);   /* link local tree */
1774     if (atp == NULL)
1775         return FALSE;
1776 
1777     if (gcp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1778 
1779     if (! AsnOpenStruct(aip, atp, (Pointer)gcp))
1780         goto erret;
1781 
1782     tmp = (ValNodePtr) gcp->data.ptrvalue;
1783     while (tmp != NULL)
1784     {   
1785         switch (tmp->choice)
1786         {
1787             case 1:   /* name */
1788                 gtp = GENETIC_CODE_E_name;
1789                 break;
1790             case 2:
1791                 gtp = GENETIC_CODE_E_id;
1792                 break;
1793             case 3:   /* ncbieaa */
1794                 gtp = GENETIC_CODE_E_ncbieaa;
1795                 break;
1796             case 4:      /* ncbi8aa */
1797                 gtp = GENETIC_CODE_E_ncbi8aa;
1798                 break;
1799             case 5:   /* ncbistdaa */
1800                 gtp = GENETIC_CODE_E_ncbistdaa;
1801                 break;
1802             case 6:   /* sncbieaa */
1803                 gtp = GENETIC_CODE_E_sncbieaa;
1804                 break;
1805             case 7:      /* sncbi8aa */
1806                 gtp = GENETIC_CODE_E_sncbi8aa;
1807                 break;
1808             case 8:   /* sncbistdaa */
1809                 gtp = GENETIC_CODE_E_sncbistdaa;
1810                 break;
1811             default:
1812                 ErrPostEx(SEV_WARNING, 0, 0, "Unsupported GeneticCode Type = %d", (int)gcp->choice);
1813                 goto erret;
1814         }
1815         
1816         av.ptrvalue = tmp;
1817         if (! AsnWriteChoice(aip, GENETIC_CODE_E, (Int2)tmp->choice, &av)) goto erret;
1818         if (! AsnWrite(aip, gtp, &tmp->data)) goto erret;
1819         tmp = tmp->next;
1820     }
1821 
1822     if (! AsnCloseStruct(aip, atp, (Pointer)gcp))
1823         goto erret;
1824     retval = TRUE;
1825 erret:
1826     AsnUnlinkType(orig);       /* unlink local tree */
1827     return retval;
1828 }
1829 /*****************************************************************************
1830 *
1831 *   GeneticCodePtr GeneticCodeAsnRead(aip, atp)
1832 *       atp is the current type (if identifier of a parent struct)
1833 *            assumption is readIdent has occurred
1834 *       if atp == NULL, then assumes it stands alone and read ident
1835 *            has not occurred.
1836 *
1837 *****************************************************************************/
1838 NLM_EXTERN GeneticCodePtr LIBCALL GeneticCodeAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1839 {
1840     DataVal av;
1841     AsnTypePtr atp;
1842     GeneticCodePtr gcp = NULL, tmp = NULL;
1843 
1844     if (! loaded)
1845     {
1846         if (! SeqFeatAsnLoad())
1847             return 0;
1848     }
1849 
1850     if (aip == NULL)
1851         return 0;
1852 
1853     if (orig == NULL)           /* GeneticCode ::= (self contained) */
1854         atp = AsnReadId(aip, amp, GENETIC_CODE);
1855     else
1856         atp = AsnLinkType(orig, GENETIC_CODE);    /* link in local tree */
1857     if (atp == NULL)
1858         return 0;
1859 
1860     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
1861 
1862     gcp = GeneticCodeNew();
1863     if (gcp == NULL) goto erret;
1864 
1865     while((atp = AsnReadId(aip, amp, atp)) == GENETIC_CODE_E)
1866     {
1867         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1868         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;    /* what kind? */
1869 
1870         tmp = ValNodeNew(tmp);
1871         if (tmp == NULL) goto erret;
1872         if (gcp->data.ptrvalue == NULL)
1873             gcp->data.ptrvalue = tmp;
1874 
1875         if (AsnReadVal(aip, atp, &tmp->data) <= 0) goto erret;
1876 
1877         if (atp == GENETIC_CODE_E_name)
1878             tmp->choice = 1;
1879         else if (atp == GENETIC_CODE_E_id)
1880             tmp->choice = 2;
1881         else if (atp == GENETIC_CODE_E_ncbieaa)
1882             tmp->choice = 3;
1883         else if (atp == GENETIC_CODE_E_ncbi8aa)
1884             tmp->choice = 4;
1885         else if (atp == GENETIC_CODE_E_ncbistdaa)
1886             tmp->choice = 5;
1887         else if (atp == GENETIC_CODE_E_sncbieaa)
1888             tmp->choice = 6;
1889         else if (atp == GENETIC_CODE_E_sncbi8aa)
1890             tmp->choice = 7;
1891         else if (atp == GENETIC_CODE_E_sncbistdaa)
1892             tmp->choice = 8;
1893         else
1894             tmp->choice = 255;   /* unrecognized */
1895     }
1896     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
1897     goto ret;
1898 
1899 erret:
1900     gcp = GeneticCodeFree(gcp);
1901 ret:
1902     AsnUnlinkType(orig);       /* unlink local tree */
1903     return gcp;
1904 }
1905 
1906 /*****************************************************************************
1907 *
1908 *   genCodeTblMemStr as last resort embedded version of gc.prt
1909 *
1910 *****************************************************************************/
1911 
1912 #ifndef WIN16
1913 static CharPtr genCodeTblMemStr = "Genetic-code-table ::= {\n" \
1914 "{ name \"Standard\" , name \"SGC0\" , id 1 ,\n" \
1915 "ncbieaa  \"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1916 "sncbieaa \"---M---------------M---------------M----------------------------\" } ,\n" \
1917 "{ name \"Vertebrate Mitochondrial\" , name \"SGC1\" , id 2 ,\n" \
1918 "ncbieaa  \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG\",\n" \
1919 "sncbieaa \"--------------------------------MMMM---------------M------------\" } ,\n" \
1920 "{ name \"Yeast Mitochondrial\" , name \"SGC2\" , id 3 ,\n" \
1921 "ncbieaa  \"FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1922 "sncbieaa \"----------------------------------MM----------------------------\" } ,\n" \
1923 "{ name \"Mold Mitochondrial; Protozoan Mitochondrial; Coelenterate\n" \
1924 "Mitochondrial; Mycoplasma; Spiroplasma\" ,\n" \
1925 "name \"SGC3\" , id 4 ,\n" \
1926 "ncbieaa  \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1927 "sncbieaa \"--MM---------------M------------MMMM---------------M------------\" } ,\n" \
1928 "{ name \"Invertebrate Mitochondrial\" , name \"SGC4\" , id 5 ,\n" \
1929 "ncbieaa  \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG\",\n" \
1930 "sncbieaa \"---M----------------------------MMMM---------------M------------\" } ,\n" \
1931 "{ name \"Ciliate Nuclear; Dasycladacean Nuclear; Hexamita Nuclear\" ,\n" \
1932 "name \"SGC5\" , id 6 ,\n" \
1933 "ncbieaa  \"FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1934 "sncbieaa \"-----------------------------------M----------------------------\" } ,\n" \
1935 "{ name \"Echinoderm Mitochondrial; Flatworm Mitochondrial\" , name \"SGC8\" , id 9 ,\n" \
1936 "ncbieaa  \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG\",\n" \
1937 "sncbieaa \"-----------------------------------M---------------M------------\" } ,\n" \
1938 "{ name \"Euplotid Nuclear\" , name \"SGC9\" , id 10 ,\n" \
1939 "ncbieaa  \"FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1940 "sncbieaa \"-----------------------------------M----------------------------\" } ,\n" \
1941 "{ name \"Bacterial, Archaeal and Plant Plastid\" , id 11 ,\n" \
1942 "ncbieaa  \"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1943 "sncbieaa \"---M---------------M------------MMMM---------------M------------\" } ,\n" \
1944 "{ name \"Alternative Yeast Nuclear\" , id 12 ,\n" \
1945 "ncbieaa  \"FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1946 "sncbieaa \"-------------------M---------------M----------------------------\" } ,\n" \
1947 "{ name \"Ascidian Mitochondrial\" , id 13 ,\n" \
1948 "ncbieaa  \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG\",\n" \
1949 "sncbieaa \"---M------------------------------MM---------------M------------\" } ,\n" \
1950 "{ name \"Alternative Flatworm Mitochondrial\" , id 14 ,\n" \
1951 "ncbieaa  \"FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG\",\n" \
1952 "sncbieaa \"-----------------------------------M----------------------------\" } ,\n" \
1953 "{ name \"Blepharisma Macronuclear\" , id 15 ,\n" \
1954 "ncbieaa  \"FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1955 "sncbieaa \"-----------------------------------M----------------------------\" } ,\n" \
1956 "{ name \"Chlorophycean Mitochondrial\" , id 16 ,\n" \
1957 "ncbieaa  \"FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1958 "sncbieaa \"-----------------------------------M----------------------------\" } ,\n" \
1959 "{ name \"Trematode Mitochondrial\" , id 21 ,\n" \
1960 "ncbieaa  \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG\",\n" \
1961 "sncbieaa \"-----------------------------------M---------------M------------\" } ,\n" \
1962 "{ name \"Scenedesmus obliquus Mitochondrial\" , id 22 ,\n" \
1963 "ncbieaa  \"FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1964 "sncbieaa \"-----------------------------------M----------------------------\" } ,\n" \
1965 "{ name \"Thraustochytrium Mitochondrial\" , id 23 ,\n" \
1966 "ncbieaa  \"FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n" \
1967 "sncbieaa \"--------------------------------M--M---------------M------------\" } };\n";
1968 #endif
1969 
1970 /*****************************************************************************
1971 *
1972 *   GeneticCodePtr GeneticCodeTableLoad()
1973 *       loads all current genetic codes
1974 *       looks for "gc.val" in the "data" directory
1975 *       now uses genCodeTblMemStr if unable to find "data" directory
1976 *
1977 *****************************************************************************/
1978 static Boolean LoadGenCodeFromLocalString (void)
1979 
1980 {
1981 #ifndef WIN16
1982   AsnIoMemPtr aimp;
1983 
1984   aimp = AsnIoMemOpen ("r", (BytePtr) genCodeTblMemStr, (Int4) StringLen (genCodeTblMemStr));
1985   if (aimp == NULL || aimp->aip == NULL) return FALSE;
1986   GeneticCodeTableAsnRead (aimp->aip, NULL);
1987   AsnIoMemClose (aimp);
1988 #endif
1989   return (Boolean) (genetic_codes != NULL);
1990 }
1991 
1992 NLM_EXTERN GeneticCodePtr LIBCALL GeneticCodeTableLoad (void)
1993 {
1994     Char buf[PATH_MAX];
1995     AsnIoPtr aip;
1996 
1997     if (genetic_codes != NULL)
1998         return genetic_codes;
1999 
2000     if (! loaded)
2001     {
2002         if (! SeqFeatAsnLoad())
2003             return (GeneticCodePtr)NULL;
2004     }
2005 
2006 #ifdef OS_UNIX
2007     if (getenv ("USE_GENCODE_FILE") == NULL) {
2008           if (LoadGenCodeFromLocalString ()) {
2009               return genetic_codes;
2010           }
2011     }
2012 #endif
2013 
2014     if (! FindPath("ncbi", "ncbi", "data", buf, sizeof (buf)))
2015     {
2016 
2017         if (LoadGenCodeFromLocalString ()) {
2018             return genetic_codes;
2019         }
2020 
2021         ErrPostEx(SEV_WARNING, 0, 0, "FindPath failed in GeneticCodeTableLoad - ncbi configuration file missing or incorrect");
2022         return genetic_codes;
2023     }
2024 
2025     StringCat(buf, "gc.val");
2026     if ((aip = AsnIoOpen(buf, "rb")) == NULL)
2027     {
2028 
2029         if (LoadGenCodeFromLocalString ()) {
2030             return genetic_codes;
2031         }
2032 
2033         ErrPostEx(SEV_WARNING, 0, 0, "Couldn't open [%s]", buf);
2034         return genetic_codes;
2035     }
2036 
2037     GeneticCodeTableAsnRead(aip, NULL);
2038 
2039     AsnIoClose(aip);
2040     return genetic_codes;
2041 }
2042 
2043 /*****************************************************************************
2044 *
2045 *   GeneticCodeFind (id, name)
2046 *       if (name == NULL)  finds by id
2047 *       returns NULL, if can't find anything
2048 *
2049 *****************************************************************************/
2050 NLM_EXTERN GeneticCodePtr LIBCALL GeneticCodeFind (Int4 id, CharPtr name)
2051 {
2052     GeneticCodePtr gcp;
2053     ValNodePtr tmp;
2054 
2055     if (GeneticCodeTableLoad() == NULL)
2056         return (GeneticCodePtr)NULL;
2057 
2058     for (gcp = genetic_codes; gcp != NULL; gcp = gcp->next)
2059     {
2060         for (tmp = (ValNodePtr) gcp->data.ptrvalue; tmp != NULL; tmp = tmp->next)
2061         {
2062             switch (tmp->choice)
2063             {
2064                 case 1:   /* name */
2065                     if (name != NULL)
2066                     {
2067                         if (! StringICmp(name, (CharPtr)tmp->data.ptrvalue))
2068                             return gcp;
2069                     }
2070                     break;
2071                 case 2:   /* id */
2072                     if (name == NULL)
2073                     {
2074                         if (id == tmp->data.intvalue)
2075                             return gcp;
2076                     }
2077                     break;
2078                 default:
2079                     break;
2080             }
2081         }
2082     }
2083 
2084     return (GeneticCodePtr)NULL;
2085 }
2086 
2087 
2088 /*****************************************************************************
2089 *
2090 *   GeneticCodeTableAsnWrite(gcp, aip, atp)
2091 *       atp is the current type (if identifier of a parent struct)
2092 *       if atp == NULL, then assumes it stands alone (Genetic-code-table ::=)
2093 *
2094 *****************************************************************************/
2095 NLM_EXTERN Boolean LIBCALL GeneticCodeTableAsnWrite (GeneticCodePtr gcp, AsnIoPtr aip, AsnTypePtr orig)
2096 {
2097     GeneticCodePtr tmp;
2098     AsnTypePtr atp;
2099     Boolean retval = FALSE;
2100 
2101     if (! loaded)
2102     {
2103         if (! SeqFeatAsnLoad())
2104             return FALSE;
2105     }
2106 
2107     if (aip == NULL)
2108         return FALSE;
2109 
2110     atp = AsnLinkType(orig, GENETIC_CODE_TABLE);   /* link local tree */
2111     if (atp == NULL)
2112         return FALSE;
2113 
2114     if (gcp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2115 
2116     if (! AsnOpenStruct(aip, atp, (Pointer)gcp))
2117         goto erret;
2118     
2119     tmp = gcp;
2120     while (tmp != NULL)
2121     {
2122         if (! GeneticCodeAsnWrite(tmp, aip, GENETIC_CODE_TABLE_E))
2123             goto erret;
2124         tmp = tmp->next;
2125     }
2126 
2127     if (! AsnCloseStruct(aip, atp, (Pointer)gcp))
2128         goto erret;
2129     retval = TRUE;
2130 erret:
2131     AsnUnlinkType(orig);       /* unlink local tree */
2132     return retval;
2133 }
2134 
2135 /*****************************************************************************
2136 *
2137 *   GeneticCodePtr GeneticCodeTableAsnRead(aip, atp)
2138 *       atp is the current type (if identifier of a parent struct)
2139 *            assumption is readIdent has occurred
2140 *       if atp == NULL, then assumes it stands alone and read ident
2141 *            has not occurred.
2142 *
2143 *****************************************************************************/
2144 NLM_EXTERN GeneticCodePtr LIBCALL GeneticCodeTableAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2145 {
2146     DataVal av;
2147     AsnTypePtr atp;
2148     GeneticCodePtr gcp = NULL, tmp = NULL;
2149 
2150     if (! loaded)
2151     {
2152         if (! SeqFeatAsnLoad())
2153             return 0;
2154     }
2155 
2156     if (aip == NULL)
2157         return 0;
2158 
2159     if (orig == NULL)           /* Genetic-code-table ::= (self contained) */
2160         atp = AsnReadId(aip, amp, GENETIC_CODE_TABLE);
2161     else
2162         atp = AsnLinkType(orig, GENETIC_CODE_TABLE);    /* link in local tree */
2163     if (atp == NULL)
2164         return 0;
2165 
2166     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
2167 
2168     while((atp = AsnReadId(aip, amp, atp)) == GENETIC_CODE_TABLE_E)
2169     {
2170         if ((tmp = GeneticCodeAsnRead(aip, atp)) == NULL) goto erret;
2171         if (gcp == NULL)     /* keep first one */
2172             gcp = tmp;
2173         GeneticCodeAdd(tmp);   /* add to global genetic_codes */
2174     }
2175     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
2176     goto ret;
2177 
2178 erret:
2179     while (gcp != NULL)
2180     {
2181         tmp = gcp->next;
2182         gcp = GeneticCodeFree(gcp);
2183         gcp = tmp;
2184     }
2185 ret:
2186     AsnUnlinkType(orig);       /* unlink local tree */
2187     return gcp;
2188 }
2189 
2190 /*****************************************************************************
2191 *
2192 *   CodeBreakNew()
2193 *
2194 *****************************************************************************/
2195 NLM_EXTERN CodeBreakPtr LIBCALL CodeBreakNew (void)
2196 {
2197     return (CodeBreakPtr)MemNew(sizeof(CodeBreak));
2198 }
2199 
2200 /*****************************************************************************
2201 *
2202 *   CodeBreakFree(cbp)
2203 *       Frees a chain of CodeBreak and associated data
2204 *
2205 *****************************************************************************/
2206 NLM_EXTERN CodeBreakPtr LIBCALL CodeBreakFree (CodeBreakPtr cbp)
2207 {
2208     CodeBreakPtr next;
2209 
2210     while (cbp != NULL)
2211     {
2212         next = cbp->next;
2213         SeqLocFree(cbp->loc);
2214         MemFree(cbp);
2215         cbp = next;
2216     }
2217     return (CodeBreakPtr)NULL;
2218 }
2219 
2220 /*****************************************************************************
2221 *
2222 *   CodeBreakAsnWrite(cbp, aip, atp)
2223 *       atp is the current type (if identifier of a parent struct)
2224 *       if atp == NULL, then assumes it stands alone (CodeBreak ::=)
2225 *
2226 *****************************************************************************/
2227 NLM_EXTERN Boolean LIBCALL CodeBreakAsnWrite (CodeBreakPtr cbp, AsnIoPtr aip, AsnTypePtr orig)
2228 {
2229     DataVal av;
2230     AsnTypePtr atp, tmp;
2231     Boolean retval = FALSE;
2232 
2233     if (! loaded)
2234     {
2235         if (! SeqFeatAsnLoad())
2236             return FALSE;
2237     }
2238 
2239     if (aip == NULL)
2240         return FALSE;
2241 
2242     atp = AsnLinkType(orig, CODE_BREAK);   /* link local tree */
2243     if (atp == NULL)
2244         return FALSE;
2245 
2246     if (cbp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2247 
2248     if (! AsnOpenStruct(aip, atp, (Pointer)cbp))
2249         goto erret;
2250 
2251     if (! SeqLocAsnWrite(cbp->loc, aip, CODE_BREAK_loc))
2252         goto erret;
2253     av.intvalue = cbp->aa.value.intvalue;
2254     if (! AsnWriteChoice(aip, CODE_BREAK_aa, (Int2)cbp->aa.choice, &av)) goto erret;
2255     switch(cbp->aa.choice)
2256     {
2257         case 1:
2258             tmp = CODE_BREAK_aa_ncbieaa;
2259             break;
2260         case 2:
2261             tmp = CODE_BREAK_aa_ncbi8aa;
2262             break;
2263         case 3:
2264             tmp = CODE_BREAK_aa_ncbistdaa;
2265             break;
2266     }
2267     if (! AsnWrite(aip, tmp, &av)) goto erret;
2268     if (! AsnCloseStruct(aip, atp, (Pointer)cbp))
2269         goto erret;
2270     retval = TRUE;
2271 erret:
2272     AsnUnlinkType(orig);       /* unlink local tree */
2273     return retval;
2274 }
2275 
2276 /*****************************************************************************
2277 *
2278 *   CodeBreakAsnRead(aip, atp)
2279 *       atp is the current type (if identifier of a parent struct)
2280 *            assumption is readIdent has occurred
2281 *       if atp == NULL, then assumes it stands alone and read ident
2282 *            has not occurred.
2283 *
2284 *****************************************************************************/
2285 NLM_EXTERN CodeBreakPtr LIBCALL CodeBreakAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2286 {
2287     DataVal av;
2288     AsnTypePtr atp;
2289     CodeBreakPtr cbp;
2290     Uint1 choice = 0;
2291 
2292     if (! loaded)
2293     {
2294         if (! SeqFeatAsnLoad())
2295             return (CodeBreakPtr)NULL;
2296     }
2297 
2298     if (aip == NULL)
2299         return (CodeBreakPtr)NULL;
2300 
2301     if (orig == NULL)           /* CodeBreak ::= (self contained) */
2302         atp = AsnReadId(aip, amp, CODE_BREAK);
2303     else
2304         atp = AsnLinkType(orig, CODE_BREAK);    /* link in local tree */
2305     if (atp == NULL)
2306         return (CodeBreakPtr)NULL;
2307 
2308     cbp = CodeBreakNew();
2309     if (cbp == NULL)
2310         goto erret;
2311 
2312     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
2313     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;   /* location */
2314     cbp->loc = SeqLocAsnRead(aip, atp);
2315     if (cbp->loc == NULL)
2316         goto erret;
2317     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;    /* read the CHOICE */
2318     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2319     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;    /* the aa */
2320     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2321     cbp->aa.value.intvalue = av.intvalue;
2322     if (atp == CODE_BREAK_aa_ncbieaa)
2323         choice = 1;
2324     else if (atp == CODE_BREAK_aa_ncbi8aa)
2325         choice = 2;
2326     else if (atp == CODE_BREAK_aa_ncbistdaa)
2327         choice = 3;
2328     cbp->aa.choice = choice;
2329 
2330     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
2331     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
2332 ret:
2333     AsnUnlinkType(orig);       /* unlink local tree */
2334     return cbp;
2335 erret:
2336     cbp = CodeBreakFree(cbp);
2337     goto ret;
2338 }
2339 
2340 /*****************************************************************************
2341 *
2342 *   ImpFeatNew()
2343 *
2344 *****************************************************************************/
2345 NLM_EXTERN ImpFeatPtr LIBCALL ImpFeatNew (void)
2346 {
2347     return (ImpFeatPtr)MemNew(sizeof(ImpFeat));
2348 }
2349 
2350 /*****************************************************************************
2351 *
2352 *   ImpFeatFree(ifp)
2353 *       Frees an ImpFeat and associated data
2354 *
2355 *****************************************************************************/
2356 NLM_EXTERN ImpFeatPtr LIBCALL ImpFeatFree (ImpFeatPtr ifp)
2357 {
2358     if (ifp == NULL)
2359         return (ImpFeatPtr)NULL;
2360 
2361     MemFree(ifp->key);
2362     MemFree(ifp->loc);
2363     MemFree(ifp->descr);
2364     return (ImpFeatPtr)MemFree(ifp);
2365 }
2366 
2367 /*****************************************************************************
2368 *
2369 *   ImpFeatAsnWrite(ifp, aip, atp)
2370 *       atp is the current type (if identifier of a parent struct)
2371 *       if atp == NULL, then assumes it stands alone (ImpFeat ::=)
2372 *
2373 *****************************************************************************/
2374 NLM_EXTERN Boolean LIBCALL ImpFeatAsnWrite (ImpFeatPtr ifp, AsnIoPtr aip, AsnTypePtr orig)
2375 {
2376     DataVal av;
2377     AsnTypePtr atp;
2378     Boolean retval = FALSE;
2379 
2380     if (! loaded)
2381     {
2382         if (! SeqFeatAsnLoad())
2383             return FALSE;
2384     }
2385 
2386     if (aip == NULL)
2387         return FALSE;
2388 
2389     atp = AsnLinkType(orig, IMP_FEAT);   /* link local tree */
2390     if (atp == NULL)
2391         return FALSE;
2392 
2393     if (ifp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2394 
2395     if (! AsnOpenStruct(aip, atp, (Pointer)ifp))
2396         goto erret;
2397 
2398     av.ptrvalue = ifp->key;
2399     if (! AsnWrite(aip, IMP_FEAT_key, &av)) goto erret;
2400     if (ifp->loc != NULL)
2401     {
2402         av.ptrvalue = ifp->loc;
2403         if (! AsnWrite(aip, IMP_FEAT_loc, &av)) goto erret;
2404     }
2405     if (ifp->descr != NULL)
2406     {
2407         av.ptrvalue = ifp->descr;
2408         if (! AsnWrite(aip, IMP_FEAT_descr, &av)) goto erret;
2409     }
2410     if (! AsnCloseStruct(aip, atp, (Pointer)ifp))
2411         goto erret;
2412     retval = TRUE;
2413 erret:
2414     AsnUnlinkType(orig);       /* unlink local tree */
2415     return retval;
2416 }
2417 
2418 /*****************************************************************************
2419 *
2420 *   ImpFeatAsnRead(aip, atp)
2421 *       atp is the current type (if identifier of a parent struct)
2422 *            assumption is readIdent has occurred
2423 *       if atp == NULL, then assumes it stands alone and read ident
2424 *            has not occurred.
2425 *
2426 *****************************************************************************/
2427 NLM_EXTERN ImpFeatPtr LIBCALL ImpFeatAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2428 {
2429     DataVal av;
2430     AsnTypePtr atp, oldatp;
2431     ImpFeatPtr ifp;
2432 
2433     if (! loaded)
2434     {
2435         if (! SeqFeatAsnLoad())
2436             return (ImpFeatPtr)NULL;
2437     }
2438 
2439     if (aip == NULL)
2440         return (ImpFeatPtr)NULL;
2441 
2442     if (orig == NULL)           /* ImpFeat ::= (self contained) */
2443         atp = AsnReadId(aip, amp, IMP_FEAT);
2444     else
2445         atp = AsnLinkType(orig, IMP_FEAT);    /* link in local tree */
2446     oldatp = atp;
2447 
2448     if (atp == NULL)
2449         return (ImpFeatPtr)NULL;
2450 
2451     ifp = ImpFeatNew();
2452     if (ifp == NULL)
2453         goto erret;
2454 
2455     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
2456 
2457     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
2458     {
2459         if (atp == NULL)
2460             goto erret;
2461         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2462         if (atp == IMP_FEAT_key)
2463             ifp->key = (CharPtr)av.ptrvalue;
2464         else if (atp == IMP_FEAT_loc)
2465             ifp->loc = (CharPtr)av.ptrvalue;
2466         else if (atp == IMP_FEAT_descr)
2467             ifp->descr = (CharPtr)av.ptrvalue;
2468     }
2469     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
2470 ret:
2471     AsnUnlinkType(orig);       /* unlink local tree */
2472     return ifp;
2473 erret:
2474     ifp = ImpFeatFree(ifp);
2475     goto ret;
2476 }
2477 
2478 /*****************************************************************************
2479 *
2480 *   RnaRefNew()
2481 *
2482 *****************************************************************************/
2483 NLM_EXTERN RnaRefPtr LIBCALL RnaRefNew (void)
2484 {
2485     return (RnaRefPtr)MemNew(sizeof(RnaRef));
2486 }
2487 
2488 /*****************************************************************************
2489 *
2490 *   RnaRefFree(rrp)
2491 *       Frees an RnaRef and associated data
2492 *
2493 *****************************************************************************/
2494 NLM_EXTERN RnaRefPtr LIBCALL RnaRefFree (RnaRefPtr rrp)
2495 {
2496     tRNAPtr trna;
2497     RNAGenPtr rgp;
2498 
2499     if (rrp == NULL)
2500         return (RnaRefPtr)NULL;
2501     
2502     if (rrp->ext.choice == 1)  /* name */
2503         MemFree(rrp->ext.value.ptrvalue);
2504     else if (rrp->ext.choice == 2)   /* tRNA */
2505     {
2506         trna = (tRNAPtr)(rrp->ext.value.ptrvalue);
2507         SeqLocFree(trna->anticodon);
2508         MemFree(trna);
2509     }
2510     else if (rrp->ext.choice == 3)   /* gen */
2511     {
2512         rgp = (RNAGenPtr)(rrp->ext.value.ptrvalue);
2513         RNAGenFree(rgp);
2514     }
2515     return (RnaRefPtr)MemFree(rrp);
2516 }
2517 
2518 /*****************************************************************************
2519 *
2520 *   RnaRefAsnWrite(rrp, aip, atp)
2521 *       atp is the current type (if identifier of a parent struct)
2522 *       if atp == NULL, then assumes it stands alone (RnaRef ::=)
2523 *
2524 *****************************************************************************/
2525 NLM_EXTERN Boolean LIBCALL RnaRefAsnWrite (RnaRefPtr rrp, AsnIoPtr aip, AsnTypePtr orig)
2526 {
2527     DataVal av;
2528     AsnTypePtr atp, tmp = NULL;
2529     tRNAPtr trna;
2530     RNAGenPtr rgp;
2531     Int2 i;
2532     Boolean first = TRUE, retval = FALSE;
2533 
2534     if (! loaded)
2535     {
2536         if (! SeqFeatAsnLoad())
2537             return FALSE;
2538     }
2539 
2540     if (aip == NULL)
2541         return FALSE;
2542 
2543     atp = AsnLinkType(orig, RNA_REF);   /* link local tree */
2544     if (atp == NULL)
2545         return FALSE;
2546 
2547     if (rrp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2548 
2549     if (! AsnOpenStruct(aip, atp, (Pointer)rrp))
2550         goto erret;
2551 
2552     av.intvalue = rrp->type;
2553     if (! AsnWrite(aip, RNA_REF_type, &av)) goto erret;
2554     if (rrp->pseudo)
2555     {
2556         av.boolvalue = rrp->pseudo;
2557         if (! AsnWrite(aip, RNA_REF_pseudo, &av)) goto erret;
2558     }
2559     if (rrp->ext.choice)
2560     {
2561         av.ptrvalue = rrp->ext.value.ptrvalue;
2562         if (! AsnWriteChoice(aip, RNA_REF_ext, (Int2)rrp->ext.choice, &av)) goto erret;
2563         if (rrp->ext.choice == 1)   /* name */
2564         {
2565             if (! AsnWrite(aip, RNA_REF_ext_name, &av)) goto erret;
2566         }
2567         else if (rrp->ext.choice == 2)   /* trna */
2568         {
2569             trna = (tRNAPtr)rrp->ext.value.ptrvalue;
2570             if (! AsnOpenStruct(aip, RNA_REF_ext_tRNA, (Pointer)trna))
2571                 goto erret;
2572             if (trna->aatype)
2573             {
2574                 av.intvalue = trna->aa;
2575                 if (! AsnWriteChoice(aip, TRNA_EXT_aa, (Int2)trna->aatype, &av)) goto erret;
2576                 switch (trna->aatype)
2577                 {
2578                     case 1:
2579                         tmp = TRNA_EXT_aa_iupacaa;
2580                         break;
2581                     case 2:
2582                         tmp = TRNA_EXT_aa_ncbieaa;
2583                         break;
2584                     case 3:
2585                         tmp = TRNA_EXT_aa_ncbi8aa;
2586                         break;
2587                     case 4:
2588                         tmp = TRNA_EXT_aa_ncbistdaa;
2589                         break;
2590                 }
2591                 if (! AsnWrite(aip, tmp, &av)) goto erret;
2592             }
2593             for (i = 0; i < 6; i++)
2594             {
2595                 if (trna->codon[i] != 255)
2596                 {
2597                     if (first)
2598                     {
2599                         if (! AsnOpenStruct(aip, TRNA_EXT_codon, (Pointer)trna->codon))
2600                             goto erret;
2601                         first = FALSE;
2602                     }
2603                     av.intvalue = trna->codon[i];
2604                     if (! AsnWrite(aip, TRNA_EXT_codon_E, &av)) goto erret;
2605                 }
2606             }
2607             if (! first)    /* wrote one */
2608                 if (! AsnCloseStruct(aip, TRNA_EXT_codon, (Pointer)trna->codon))
2609                     goto erret;
2610             if (trna->anticodon != NULL)
2611                 if (! SeqLocAsnWrite(trna->anticodon, aip, TRNA_EXT_anticodon))
2612                     goto erret;
2613 
2614             if (! AsnCloseStruct(aip, RNA_REF_ext_tRNA, (Pointer)trna))
2615                 goto erret;
2616         }
2617         else if (rrp->ext.choice == 3)   /* gen */
2618         {
2619             rgp = (RNAGenPtr)(rrp->ext.value.ptrvalue);
2620             if (! RNAGenAsnWrite (rgp, aip, RNA_REF_ext_gen))
2621                 goto erret;
2622         }
2623     }
2624     if (! AsnCloseStruct(aip, atp, (Pointer)rrp))
2625         goto erret;
2626     retval = TRUE;
2627 erret:
2628     AsnUnlinkType(orig);       /* unlink local tree */
2629     return retval;
2630 }
2631 
2632 /*****************************************************************************
2633 *
2634 *   RnaRefAsnRead(aip, atp)
2635 *       atp is the current type (if identifier of a parent struct)
2636 *            assumption is readIdent has occurred
2637 *       if atp == NULL, then assumes it stands alone and read ident
2638 *            has not occurred.
2639 *
2640 *****************************************************************************/
2641 NLM_EXTERN RnaRefPtr LIBCALL RnaRefAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2642 {
2643     DataVal av;
2644     AsnTypePtr atp, oldatp;
2645     RnaRefPtr rrp;
2646     tRNAPtr trna = NULL;
2647     Int2 i = 0;
2648 
2649     if (! loaded)
2650     {
2651         if (! SeqFeatAsnLoad())
2652             return (RnaRefPtr)NULL;
2653     }
2654 
2655     if (aip == NULL)
2656         return (RnaRefPtr)NULL;
2657 
2658     if (orig == NULL)           /* RnaRef ::= (self contained) */
2659         atp = AsnReadId(aip, amp, RNA_REF);
2660     else
2661         atp = AsnLinkType(orig, RNA_REF);    /* link in local tree */
2662     oldatp = atp;
2663     if (atp == NULL)
2664         return (RnaRefPtr)NULL;
2665 
2666     rrp = RnaRefNew();
2667     if (rrp == NULL)
2668         goto erret;
2669 
2670     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
2671 
2672     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
2673     {
2674         if (atp == NULL)
2675             goto erret;
2676         if (atp == TRNA_EXT_anticodon)
2677         {
2678             trna->anticodon = SeqLocAsnRead(aip, atp);
2679             if (trna->anticodon == NULL) goto erret;
2680         }
2681         else
2682         {
2683             if (atp == RNA_REF_type)
2684             {
2685                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2686                 rrp->type = (Uint1)av.intvalue;
2687             }
2688             else if (atp == RNA_REF_pseudo)
2689             {
2690                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2691                 rrp->pseudo = av.boolvalue;
2692             }
2693             else if (atp == RNA_REF_ext_name)
2694             {
2695                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2696                 rrp->ext.choice = 1;
2697                 rrp->ext.value.ptrvalue = av.ptrvalue;
2698             }
2699             else if (atp == RNA_REF_ext_tRNA)   /* its a trna */
2700             {
2701                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2702                 if (trna == NULL)   /* first time */
2703                 {
2704                     rrp->ext.choice = 2;
2705                     trna = (tRNAPtr)MemNew(sizeof(tRNA));
2706                     if (trna == NULL)
2707                         goto erret;
2708                     rrp->ext.value.ptrvalue = trna;
2709                     for (i = 0; i < 6; i++)
2710                         trna->codon[i] = 255;   /* not used */
2711                     i = 0;
2712                 }
2713             }
2714             else if (atp == TRNA_EXT_aa_iupacaa)
2715             {
2716                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2717                 trna->aatype = 1;
2718                 trna->aa = (Uint1)av.intvalue;
2719             }
2720             else if (atp == TRNA_EXT_aa_ncbieaa)
2721             {
2722                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2723                 trna->aatype = 2;
2724                 trna->aa = (Uint1)av.intvalue;
2725             }
2726             else if (atp == TRNA_EXT_aa_ncbi8aa)
2727             {
2728                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2729                 trna->aatype = 3;
2730                 trna->aa = (Uint1)av.intvalue;
2731             }
2732             else if (atp == TRNA_EXT_aa_ncbistdaa)
2733             {
2734                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2735                 trna->aatype = 4;
2736                 trna->aa = (Uint1)av.intvalue;
2737             }
2738             else if (atp == TRNA_EXT_codon_E)
2739             {
2740                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2741                 if (i < 6) {
2742                     trna->codon[i] = (Uint1)av.intvalue;
2743                 }
2744                 i++;
2745             }
2746             else if (atp == RNA_REF_ext_gen)
2747             {
2748                 rrp->ext.choice = 3;
2749                 rrp->ext.value.ptrvalue = RNAGenAsnRead (aip, atp);
2750             } else {
2751                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2752             }
2753         }
2754     }
2755     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
2756 ret:
2757     AsnUnlinkType(orig);       /* unlink local tree */
2758     return rrp;
2759 erret:
2760     rrp = RnaRefFree(rrp);
2761     goto ret;
2762 }
2763 
2764 
2765 
2766 /**************************************************
2767 *
2768 *    RNAQualNew()
2769 *
2770 **************************************************/
2771 NLM_EXTERN 
2772 RNAQualPtr LIBCALL
2773 RNAQualNew(void)
2774 {
2775    RNAQualPtr rqp = MemNew((size_t) sizeof(RNAQual));
2776 
2777    return rqp;
2778 
2779 }
2780 
2781 
2782 /**************************************************
2783 *
2784 *    RNAQualFree()
2785 *
2786 **************************************************/
2787 NLM_EXTERN 
2788 RNAQualPtr LIBCALL
2789 RNAQualFree(RNAQualPtr rqp)
2790 {
2791 
2792    if(rqp == NULL) {
2793       return NULL;
2794    }
2795    MemFree(rqp -> qual);
2796    MemFree(rqp -> val);
2797    return MemFree(rqp);
2798 }
2799 
2800 
2801 /**************************************************
2802 *
2803 *    RNAQualAsnRead()
2804 *
2805 **************************************************/
2806 NLM_EXTERN 
2807 RNAQualPtr LIBCALL
2808 RNAQualAsnRead(AsnIoPtr aip, AsnTypePtr orig)
2809 {
2810    DataVal av;
2811    AsnTypePtr atp;
2812    AsnReadFunc func;
2813    RNAQualPtr rqp;
2814 
2815    if (! loaded)
2816    {
2817       if (! SeqFeatAsnLoad()) {
2818          return NULL;
2819       }
2820    }
2821 
2822    if (aip == NULL) {
2823       return NULL;
2824    }
2825 
2826    if (orig == NULL) {         /* RNAQual ::= (self contained) */
2827       atp = AsnReadId(aip, amp, RNA_QUAL);
2828    } else {
2829       atp = AsnLinkType(orig, RNA_QUAL);
2830    }
2831    /* link in local tree */
2832    if (atp == NULL) {
2833       return NULL;
2834    }
2835 
2836    rqp = RNAQualNew();
2837    if (rqp == NULL) {
2838       goto erret;
2839    }
2840    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
2841       goto erret;
2842    }
2843 
2844    atp = AsnReadId(aip,amp, atp);
2845    func = NULL;
2846 
2847    if (atp == RNA_QUAL_qual) {
2848       if ( AsnReadVal(aip, atp, &av) <= 0) {
2849          goto erret;
2850       }
2851       rqp -> qual = av.ptrvalue;
2852       atp = AsnReadId(aip,amp, atp);
2853    }
2854    if (atp == RNA_QUAL_val) {
2855       if ( AsnReadVal(aip, atp, &av) <= 0) {
2856          goto erret;
2857       }
2858       rqp -> val = av.ptrvalue;
2859       atp = AsnReadId(aip,amp, atp);
2860    }
2861 
2862    if (AsnReadVal(aip, atp, &av) <= 0) {
2863       goto erret;
2864    }
2865    /* end struct */
2866 
2867 ret:
2868    AsnUnlinkType(orig);       /* unlink local tree */
2869    return rqp;
2870 
2871 erret:
2872    aip -> io_failure = TRUE;
2873    rqp = RNAQualFree(rqp);
2874    goto ret;
2875 }
2876 
2877 
2878 
2879 /**************************************************
2880 *
2881 *    RNAQualAsnWrite()
2882 *
2883 **************************************************/
2884 NLM_EXTERN Boolean LIBCALL 
2885 RNAQualAsnWrite(RNAQualPtr rqp, AsnIoPtr aip, AsnTypePtr orig)
2886 {
2887    DataVal av;
2888    AsnTypePtr atp;
2889    Boolean retval = FALSE;
2890 
2891    if (! loaded)
2892    {
2893       if (! SeqFeatAsnLoad()) {
2894          return FALSE;
2895       }
2896    }
2897 
2898    if (aip == NULL) {
2899       return FALSE;
2900    }
2901 
2902    atp = AsnLinkType(orig, RNA_QUAL);   /* link local tree */
2903    if (atp == NULL) {
2904       return FALSE;
2905    }
2906 
2907    if (rqp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2908    if (! AsnOpenStruct(aip, atp, (Pointer) rqp)) {
2909       goto erret;
2910    }
2911 
2912    if (rqp -> qual != NULL) {
2913       av.ptrvalue = rqp -> qual;
2914       retval = AsnWrite(aip, RNA_QUAL_qual,  &av);
2915    }
2916    if (rqp -> val != NULL) {
2917       av.ptrvalue = rqp -> val;
2918       retval = AsnWrite(aip, RNA_QUAL_val,  &av);
2919    }
2920    if (! AsnCloseStruct(aip, atp, (Pointer)rqp)) {
2921       goto erret;
2922    }
2923    retval = TRUE;
2924 
2925 erret:
2926    AsnUnlinkType(orig);       /* unlink local tree */
2927    return retval;
2928 }
2929 
2930 
2931 
2932 /**************************************************
2933 *
2934 *    RNAQualSetFree()
2935 *
2936 **************************************************/
2937 NLM_EXTERN 
2938 RNAQualSetPtr LIBCALL
2939 RNAQualSetFree(RNAQualSetPtr rqp)
2940 {
2941 
2942    if(rqp == NULL) {
2943       return NULL;
2944    }
2945    AsnGenericUserSeqOfFree(rqp,  (AsnOptFreeFunc) RNAQualFree);
2946    return NULL;
2947 }
2948 
2949 
2950 /**************************************************
2951 *
2952 *    RNAQualSetAsnRead()
2953 *
2954 **************************************************/
2955 NLM_EXTERN 
2956 RNAQualSetPtr LIBCALL
2957 RNAQualSetAsnRead(AsnIoPtr aip, AsnTypePtr orig)
2958 {
2959    AsnTypePtr atp;
2960    Boolean isError = FALSE;
2961    AsnReadFunc func;
2962    RNAQualSetPtr rqp;
2963 
2964    if (! loaded)
2965    {
2966       if (! SeqFeatAsnLoad()) {
2967          return NULL;
2968       }
2969    }
2970 
2971    if (aip == NULL) {
2972       return NULL;
2973    }
2974 
2975    if (orig == NULL) {         /* RNAQualSet ::= (self contained) */
2976       atp = AsnReadId(aip, amp, RNA_QUAL_SET);
2977    } else {
2978       atp = AsnLinkType(orig, RNA_QUAL_SET);
2979    }
2980    /* link in local tree */
2981    if (atp == NULL) {
2982       return NULL;
2983    }
2984 
2985    func = NULL;
2986 
2987    rqp  = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) RNAQualAsnRead, (AsnOptFreeFunc) RNAQualFree);
2988    if (isError && rqp  == NULL) {
2989       goto erret;
2990    }
2991 
2992 
2993 
2994 ret:
2995    AsnUnlinkType(orig);       /* unlink local tree */
2996    return rqp;
2997 
2998 erret:
2999    aip -> io_failure = TRUE;
3000    rqp = RNAQualSetFree(rqp);
3001    goto ret;
3002 }
3003 
3004 
3005 
3006 /**************************************************
3007 *
3008 *    RNAQualSetAsnWrite()
3009 *
3010 **************************************************/
3011 NLM_EXTERN Boolean LIBCALL 
3012 RNAQualSetAsnWrite(RNAQualSetPtr rqp, AsnIoPtr aip, AsnTypePtr orig)
3013 {
3014    AsnTypePtr atp;
3015    Boolean retval = FALSE;
3016 
3017    if (! loaded)
3018    {
3019       if (! SeqFeatAsnLoad()) {
3020          return FALSE;
3021       }
3022    }
3023 
3024    if (aip == NULL) {
3025       return FALSE;
3026    }
3027 
3028    atp = AsnLinkType(orig, RNA_QUAL_SET);   /* link local tree */
3029    if (atp == NULL) {
3030       return FALSE;
3031    }
3032 
3033    if (rqp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3034    retval = AsnGenericUserSeqOfAsnWrite(rqp , (AsnWriteFunc) RNAQualAsnWrite, aip, atp, RNA_QUAL_SET_E);
3035    retval = TRUE;
3036 
3037 erret:
3038    AsnUnlinkType(orig);       /* unlink local tree */
3039    return retval;
3040 }
3041 
3042 
3043 /**************************************************
3044 *
3045 *    RNAGenNew()
3046 *
3047 **************************************************/
3048 NLM_EXTERN 
3049 RNAGenPtr LIBCALL
3050 RNAGenNew(void)
3051 {
3052    RNAGenPtr rgp = MemNew((size_t) sizeof(RNAGen));
3053    return rgp;
3054 
3055 }
3056 
3057 
3058 /**************************************************
3059 *
3060 *    RNAGenFree()
3061 *
3062 **************************************************/
3063 NLM_EXTERN 
3064 RNAGenPtr LIBCALL
3065 RNAGenFree(RNAGenPtr rgp)
3066 {
3067 
3068    if(rgp == NULL) {
3069       return NULL;
3070    }
3071    MemFree(rgp -> _class);
3072    MemFree(rgp -> product);
3073    RNAQualSetFree(rgp -> quals);
3074    return MemFree(rgp);
3075 }
3076 
3077 
3078 /**************************************************
3079 *
3080 *    RNAGenAsnRead()
3081 *
3082 **************************************************/
3083 NLM_EXTERN 
3084 RNAGenPtr LIBCALL
3085 RNAGenAsnRead(AsnIoPtr aip, AsnTypePtr orig)
3086 {
3087    DataVal av;
3088    AsnTypePtr atp;
3089    AsnReadFunc func;
3090    RNAGenPtr rgp;
3091 
3092    if (! loaded)
3093    {
3094       if (! SeqFeatAsnLoad()) {
3095          return NULL;
3096       }
3097    }
3098 
3099    if (aip == NULL) {
3100       return NULL;
3101    }
3102 
3103    if (orig == NULL) {         /* RNAGen ::= (self contained) */
3104       atp = AsnReadId(aip, amp, RNA_GEN);
3105    } else {
3106       atp = AsnLinkType(orig, RNA_GEN);
3107    }
3108    /* link in local tree */
3109    if (atp == NULL) {
3110       return NULL;
3111    }
3112 
3113    rgp = RNAGenNew();
3114    if (rgp == NULL) {
3115       goto erret;
3116    }
3117    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
3118       goto erret;
3119    }
3120 
3121    atp = AsnReadId(aip,amp, atp);
3122    func = NULL;
3123 
3124    if (atp == RNA_GEN_class) {
3125       if ( AsnReadVal(aip, atp, &av) <= 0) {
3126          goto erret;
3127       }
3128       rgp -> _class = av.ptrvalue;
3129       atp = AsnReadId(aip,amp, atp);
3130    }
3131    if (atp == RNA_GEN_product) {
3132       if ( AsnReadVal(aip, atp, &av) <= 0) {
3133          goto erret;
3134       }
3135       rgp -> product = av.ptrvalue;
3136       atp = AsnReadId(aip,amp, atp);
3137    }
3138    if (atp == RNA_GEN_quals) {
3139       rgp -> quals = RNAQualSetAsnRead(aip, atp);
3140       if (aip -> io_failure) {
3141          goto erret;
3142       }
3143       atp = AsnReadId(aip,amp, atp);
3144    }
3145 
3146    if (AsnReadVal(aip, atp, &av) <= 0) {
3147       goto erret;
3148    }
3149    /* end struct */
3150 
3151 ret:
3152    AsnUnlinkType(orig);       /* unlink local tree */
3153    return rgp;
3154 
3155 erret:
3156    aip -> io_failure = TRUE;
3157    rgp = RNAGenFree(rgp);
3158    goto ret;
3159 }
3160 
3161 
3162 
3163 /**************************************************
3164 *
3165 *    RNAGenAsnWrite()
3166 *
3167 **************************************************/
3168 NLM_EXTERN Boolean LIBCALL 
3169 RNAGenAsnWrite(RNAGenPtr rgp, AsnIoPtr aip, AsnTypePtr orig)
3170 {
3171    DataVal av;
3172    AsnTypePtr atp;
3173    Boolean retval = FALSE;
3174 
3175    if (! loaded)
3176    {
3177       if (! SeqFeatAsnLoad()) {
3178          return FALSE;
3179       }
3180    }
3181 
3182    if (aip == NULL) {
3183       return FALSE;
3184    }
3185 
3186    atp = AsnLinkType(orig, RNA_GEN);   /* link local tree */
3187    if (atp == NULL) {
3188       return FALSE;
3189    }
3190 
3191    if (rgp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3192    if (! AsnOpenStruct(aip, atp, (Pointer) rgp)) {
3193       goto erret;
3194    }
3195 
3196    if (rgp -> _class != NULL) {
3197       av.ptrvalue = rgp -> _class;
3198       retval = AsnWrite(aip, RNA_GEN_class,  &av);
3199    }
3200    if (rgp -> product != NULL) {
3201       av.ptrvalue = rgp -> product;
3202       retval = AsnWrite(aip, RNA_GEN_product,  &av);
3203    }
3204    if (rgp -> quals != NULL) {
3205       if ( ! RNAQualSetAsnWrite(rgp -> quals, aip, RNA_GEN_quals)) {
3206          goto erret;
3207       }
3208    }
3209    if (! AsnCloseStruct(aip, atp, (Pointer)rgp)) {
3210       goto erret;
3211    }
3212    retval = TRUE;
3213 
3214 erret:
3215    AsnUnlinkType(orig);       /* unlink local tree */
3216    return retval;
3217 }
3218 
3219 
3220 
3221 
3222 /**************************************************
3223 *
3224 *    GeneNomenclatureNew()
3225 *
3226 **************************************************/
3227 NLM_EXTERN 
3228 GeneNomenclaturePtr LIBCALL
3229 GeneNomenclatureNew (void)
3230 {
3231    GeneNomenclaturePtr gnp = MemNew((size_t) sizeof(GeneNomenclature));
3232 
3233    return gnp;
3234 
3235 }
3236 
3237 
3238 /**************************************************
3239 *
3240 *    GeneNomenclatureFree()
3241 *
3242 **************************************************/
3243 NLM_EXTERN 
3244 GeneNomenclaturePtr LIBCALL
3245 GeneNomenclatureFree (GeneNomenclaturePtr gnp)
3246 {
3247 
3248    if (gnp == NULL) {
3249       return NULL;
3250    }
3251    MemFree(gnp -> symbol);
3252    MemFree(gnp -> name);
3253    DbtagFree(gnp -> source);
3254    return MemFree(gnp);
3255 }
3256 
3257 
3258 /**************************************************
3259 *
3260 *    GeneNomenclatureAsnRead()
3261 *
3262 **************************************************/
3263 NLM_EXTERN 
3264 GeneNomenclaturePtr LIBCALL
3265 GeneNomenclatureAsnRead (AsnIoPtr aip, AsnTypePtr orig)
3266 {
3267    DataVal av;
3268    AsnTypePtr atp;
3269    AsnReadFunc func;
3270    GeneNomenclaturePtr gnp;
3271 
3272    if (! loaded)
3273    {
3274       if (! SeqFeatAsnLoad()) {
3275          return NULL;
3276       }
3277    }
3278 
3279    if (aip == NULL) {
3280       return NULL;
3281    }
3282 
3283    if (orig == NULL) {         /* GeneNomenclature ::= (self contained) */
3284       atp = AsnReadId(aip, amp, GENE_NOMENCLATURE);
3285    } else {
3286       atp = AsnLinkType(orig, GENE_NOMENCLATURE);
3287    }
3288    /* link in local tree */
3289    if (atp == NULL) {
3290       return NULL;
3291    }
3292 
3293    gnp = GeneNomenclatureNew();
3294    if (gnp == NULL) {
3295       goto erret;
3296    }
3297    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
3298       goto erret;
3299    }
3300 
3301    atp = AsnReadId(aip,amp, atp);
3302    func = NULL;
3303 
3304    if (atp == GENE_NOMENCLATURE_status) {
3305       if ( AsnReadVal(aip, atp, &av) <= 0) {
3306          goto erret;
3307       }
3308       gnp -> status = av.intvalue;
3309       atp = AsnReadId(aip,amp, atp);
3310    }
3311    if (atp == GENE_NOMENCLATURE_symbol) {
3312       if ( AsnReadVal(aip, atp, &av) <= 0) {
3313          goto erret;
3314       }
3315       gnp -> symbol = av.ptrvalue;
3316       atp = AsnReadId(aip,amp, atp);
3317    }
3318    if (atp == GENE_NOMENCLATURE_name) {
3319       if ( AsnReadVal(aip, atp, &av) <= 0) {
3320          goto erret;
3321       }
3322       gnp -> name = av.ptrvalue;
3323       atp = AsnReadId(aip,amp, atp);
3324    }
3325    if (atp == GENE_NOMENCLATURE_source) {
3326       gnp -> source = DbtagAsnRead(aip, atp);
3327       if (aip -> io_failure) {
3328          goto erret;
3329       }
3330       atp = AsnReadId(aip,amp, atp);
3331    }
3332 
3333    if (AsnReadVal(aip, atp, &av) <= 0) {
3334       goto erret;
3335    }
3336    /* end struct */
3337 
3338 ret:
3339    AsnUnlinkType(orig);       /* unlink local tree */
3340    return gnp;
3341 
3342 erret:
3343    aip -> io_failure = TRUE;
3344    gnp = GeneNomenclatureFree(gnp);
3345    goto ret;
3346 }
3347 
3348 
3349 /**************************************************
3350 *
3351 *    GeneNomenclatureAsnWrite()
3352 *
3353 **************************************************/
3354 NLM_EXTERN Boolean LIBCALL 
3355 GeneNomenclatureAsnWrite (GeneNomenclaturePtr gnp, AsnIoPtr aip, AsnTypePtr orig)
3356 {
3357    DataVal av;
3358    AsnTypePtr atp;
3359    Boolean retval = FALSE;
3360 
3361    if (! loaded)
3362    {
3363       if (! SeqFeatAsnLoad()) {
3364          return FALSE;
3365       }
3366    }
3367 
3368    if (aip == NULL) {
3369       return FALSE;
3370    }
3371 
3372    atp = AsnLinkType(orig, GENE_NOMENCLATURE);   /* link local tree */
3373    if (atp == NULL) {
3374       return FALSE;
3375    }
3376 
3377    if (gnp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3378    if (! AsnOpenStruct(aip, atp, (Pointer) gnp)) {
3379       goto erret;
3380    }
3381 
3382    av.intvalue = gnp -> status;
3383    retval = AsnWrite(aip, GENE_NOMENCLATURE_status,  &av);
3384    if (gnp -> symbol != NULL) {
3385       av.ptrvalue = gnp -> symbol;
3386       retval = AsnWrite(aip, GENE_NOMENCLATURE_symbol,  &av);
3387    }
3388    if (gnp -> name != NULL) {
3389       av.ptrvalue = gnp -> name;
3390       retval = AsnWrite(aip, GENE_NOMENCLATURE_name,  &av);
3391    }
3392    if (gnp -> source != NULL) {
3393       if ( ! DbtagAsnWrite(gnp -> source, aip, GENE_NOMENCLATURE_source)) {
3394          goto erret;
3395       }
3396    }
3397    if (! AsnCloseStruct(aip, atp, (Pointer)gnp)) {
3398       goto erret;
3399    }
3400    retval = TRUE;
3401 
3402 erret:
3403    AsnUnlinkType(orig);       /* unlink local tree */
3404    return retval;
3405 }
3406 
3407 
3408 
3409 /*****************************************************************************
3410 *
3411 *   GeneRefNew()
3412 *
3413 *****************************************************************************/
3414 NLM_EXTERN GeneRefPtr LIBCALL GeneRefNew (void)
3415 {
3416     return (GeneRefPtr)MemNew(sizeof(GeneRef));
3417 }
3418 
3419 /*****************************************************************************
3420 *
3421 *   GeneRefFree(grp)
3422 *       Frees an GeneRef and associated data
3423 *
3424 *****************************************************************************/
3425 NLM_EXTERN GeneRefPtr LIBCALL GeneRefFree (GeneRefPtr grp)
3426 {
3427     ValNodePtr anp, next;
3428 
3429     if (grp == NULL)
3430         return (GeneRefPtr)NULL;
3431 
3432     MemFree(grp->locus);
3433     MemFree(grp->allele);
3434     MemFree(grp->desc);
3435     MemFree(grp->maploc);
3436     anp = grp->db;
3437     while (anp != NULL)
3438     {
3439         next = anp->next;
3440         DbtagFree((DbtagPtr)anp->data.ptrvalue);
3441         MemFree(anp);
3442         anp = next;
3443     }
3444     anp = grp->syn;
3445     while (anp != NULL)
3446     {
3447         next = anp->next;
3448         MemFree(anp->data.ptrvalue);
3449         MemFree(anp);
3450         anp = next;
3451     }
3452     MemFree (grp->locus_tag);
3453     GeneNomenclatureFree (grp->formal_name);
3454     return (GeneRefPtr)MemFree(grp);
3455 }
3456 
3457 /*****************************************************************************
3458 *
3459 *   GeneRefDup(grp)
3460 *       Duplicates an GeneRef and associated data
3461 *
3462 *****************************************************************************/
3463 NLM_EXTERN GeneRefPtr LIBCALL GeneRefDup (GeneRefPtr grp)
3464 {
3465     ValNodePtr anp, vnp;
3466     GeneRefPtr ngp;
3467 
3468     if (grp == NULL)
3469         return (GeneRefPtr)NULL;
3470 
3471     ngp = GeneRefNew();
3472     if (ngp == NULL) return ngp;
3473 
3474     if (grp->locus != NULL)
3475         ngp->locus = StringSave(grp->locus);
3476     if (grp->allele != NULL)
3477         ngp->allele = StringSave(grp->allele);
3478     if (grp->desc != NULL)
3479         ngp->desc = StringSave(grp->desc);
3480     if (grp->maploc != NULL)
3481         ngp->maploc = StringSave(grp->maploc);
3482     anp = grp->db;
3483     while (anp != NULL)
3484     {
3485         vnp = ValNodeNew(ngp->db);
3486         if (vnp == NULL) return GeneRefFree(ngp);
3487         if (ngp->db == NULL)
3488             ngp->db = vnp;
3489         vnp->data.ptrvalue = (Pointer)DbtagDup((DbtagPtr)anp->data.ptrvalue);
3490         anp = anp->next;
3491     }
3492     anp = grp->syn;
3493     while (anp != NULL)
3494     {
3495         vnp = ValNodeNew(ngp->syn);
3496         if (vnp == NULL) return GeneRefFree(ngp);
3497         if (ngp->syn == NULL)
3498             ngp->syn = vnp;
3499         vnp->data.ptrvalue = (Pointer)StringSave((CharPtr)anp->data.ptrvalue);
3500         anp = anp->next;
3501     }
3502     if (grp->locus_tag != NULL)
3503         ngp->locus_tag = StringSave(grp->locus_tag);
3504     if (grp->formal_name != NULL) {
3505       ngp = AsnIoMemCopy ((Pointer) grp->formal_name,
3506                           (AsnReadFunc) GeneNomenclatureAsnRead,
3507                           (AsnWriteFunc) GeneNomenclatureAsnWrite);
3508     }
3509     return ngp;
3510 }
3511 
3512 /*****************************************************************************
3513 *
3514 *   GeneRefAsnWrite(grp, aip, atp)
3515 *       atp is the current type (if identifier of a parent struct)
3516 *       if atp == NULL, then assumes it stands alone (GeneRef ::=)
3517 *
3518 *****************************************************************************/
3519 NLM_EXTERN Boolean LIBCALL GeneRefAsnWrite (GeneRefPtr grp, AsnIoPtr aip, AsnTypePtr orig)
3520 {
3521     DataVal av;
3522     AsnTypePtr atp;
3523     ValNodePtr anp;
3524     Boolean retval = FALSE;
3525 
3526     if (! loaded)
3527     {
3528         if (! SeqFeatAsnLoad())
3529             return FALSE;
3530     }
3531 
3532     if (aip == NULL)
3533         return FALSE;
3534 
3535     atp = AsnLinkType(orig, GENE_REF);   /* link local tree */
3536     if (atp == NULL)
3537         return FALSE;
3538 
3539     if (grp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3540 
3541     if (! AsnOpenStruct(aip, atp, (Pointer)grp))
3542         goto erret;
3543 
3544     if (grp->locus != NULL)
3545     {
3546         av.ptrvalue = grp->locus;
3547         if (! AsnWrite(aip, GENE_REF_locus, &av)) goto erret;
3548     }
3549     if (grp->allele != NULL)
3550     {
3551         av.ptrvalue = grp->allele;
3552         if (! AsnWrite(aip, GENE_REF_allele, &av)) goto erret;
3553     }
3554     if (grp->desc != NULL)
3555     {
3556         av.ptrvalue = grp->desc;
3557         if (! AsnWrite(aip, GENE_REF_desc, &av)) goto erret;
3558     }
3559     if (grp->maploc != NULL)
3560     {
3561         av.ptrvalue = grp->maploc;
3562         if (! AsnWrite(aip, GENE_REF_maploc, &av)) goto erret;
3563     }
3564     if (grp->pseudo)
3565     {
3566         av.boolvalue = grp->pseudo;
3567         if (! AsnWrite(aip, GENE_REF_pseudo, &av)) goto erret;
3568     }
3569     if (grp->db != NULL)
3570     {
3571         anp = grp->db;
3572         if (! AsnOpenStruct(aip, GENE_REF_db, (Pointer)grp->db))
3573             goto erret;
3574         while (anp != NULL)
3575         {
3576             if (! DbtagAsnWrite((DbtagPtr)anp->data.ptrvalue, aip, GENE_REF_db_E))
3577                 goto erret;
3578             anp = anp->next;
3579         }
3580         if (! AsnCloseStruct(aip, GENE_REF_db, (Pointer)grp->db))
3581             goto erret;
3582     }
3583     if (grp->syn != NULL)
3584     {
3585         anp = grp->syn;
3586         if (! AsnOpenStruct(aip, GENE_REF_syn, (Pointer)grp->syn))
3587             goto erret;
3588         while (anp != NULL)
3589         {
3590             if (! AsnWrite(aip, GENE_REF_syn_E, &anp->data)) goto erret;
3591             anp = anp->next;
3592         }
3593         if (! AsnCloseStruct(aip, GENE_REF_syn, (Pointer)grp->syn))
3594             goto erret;
3595     }
3596     if (grp->locus_tag != NULL)
3597     {
3598         av.ptrvalue = grp->locus_tag;
3599         if (! AsnWrite(aip, GENE_REF_locus_tag, &av)) goto erret;
3600     }
3601    if (grp->formal_name != NULL) {
3602       if ( ! GeneNomenclatureAsnWrite(grp->formal_name, aip, GENE_REF_formal_name)) {
3603          goto erret;
3604       }
3605    }
3606     if (! AsnCloseStruct(aip, atp, (Pointer)grp))
3607         goto erret;
3608     retval = TRUE;
3609 erret:
3610     AsnUnlinkType(orig);       /* unlink local tree */
3611     return retval;
3612 }
3613 
3614 /*****************************************************************************
3615 *
3616 *   GeneRefAsnRead(aip, atp)
3617 *       atp is the current type (if identifier of a parent struct)
3618 *            assumption is readIdent has occurred
3619 *       if atp == NULL, then assumes it stands alone and read ident
3620 *            has not occurred.
3621 *
3622 *****************************************************************************/
3623 NLM_EXTERN GeneRefPtr LIBCALL GeneRefAsnRead (AsnIoPtr aip, AsnTypePtr orig)
3624 {
3625     DataVal av;
3626     AsnTypePtr atp, oldatp;
3627     GeneRefPtr grp;
3628     ValNodePtr anp;
3629 
3630     if (! loaded)
3631     {
3632         if (! SeqFeatAsnLoad())
3633             return (GeneRefPtr)NULL;
3634     }
3635 
3636     if (aip == NULL)
3637         return (GeneRefPtr)NULL;
3638 
3639     if (orig == NULL)           /* GeneRef ::= (self contained) */
3640         atp = AsnReadId(aip, amp, GENE_REF);
3641     else
3642         atp = AsnLinkType(orig, GENE_REF);    /* link in local tree */
3643     oldatp = atp;
3644     if (atp == NULL)
3645         return (GeneRefPtr)NULL;
3646 
3647     grp = GeneRefNew();
3648     if (grp == NULL)
3649         goto erret;
3650 
3651     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
3652 
3653     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
3654     {
3655         if (atp == NULL)
3656             goto erret;
3657         if (atp == GENE_REF_locus) {
3658            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3659             grp->locus = (CharPtr)av.ptrvalue;
3660         } else if (atp == GENE_REF_allele) {
3661            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3662             grp->allele = (CharPtr)av.ptrvalue;
3663         } else if (atp == GENE_REF_desc) {
3664            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3665             grp->desc = (CharPtr)av.ptrvalue;
3666         } else if (atp == GENE_REF_maploc) {
3667            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3668             grp->maploc = (CharPtr)av.ptrvalue;
3669         } else if (atp == GENE_REF_pseudo) {
3670            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3671             grp->pseudo = av.boolvalue;
3672         } else if (atp == GENE_REF_db)
3673         {
3674            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3675             while ((atp = AsnReadId(aip, amp, atp)) == GENE_REF_db_E)
3676             {
3677                 anp = ValNodeNew(grp->db);
3678                 if (anp == NULL)
3679                     goto erret;
3680                 if (grp->db == NULL)
3681                     grp->db = anp;
3682                 anp->data.ptrvalue = (Pointer)DbtagAsnRead(aip, atp);
3683                 if (anp->data.ptrvalue == NULL)
3684                     goto erret;
3685             }
3686             if (atp == NULL)
3687                 goto erret;
3688             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end SET OF */
3689         }
3690         else if (atp == GENE_REF_syn)
3691         {
3692            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3693             while ((atp = AsnReadId(aip, amp, atp)) == GENE_REF_syn_E)
3694             {
3695                 anp = ValNodeNew(grp->syn);
3696                 if (anp == NULL)
3697                     goto erret;
3698                 if (grp->syn == NULL)
3699                     grp->syn = anp;
3700                 if (AsnReadVal(aip, atp, &anp->data) <= 0) goto erret;
3701             }
3702             if (atp == NULL)
3703                 goto erret;
3704             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end SET OF */
3705         }
3706         else if (atp == GENE_REF_locus_tag) {
3707            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3708            grp->locus_tag = (CharPtr)av.ptrvalue;
3709         } else if (atp == GENE_REF_formal_name) {
3710             grp->formal_name = GeneNomenclatureAsnRead(aip, atp);
3711             if (aip -> io_failure) goto erret;
3712         }
3713     }
3714     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
3715 ret:
3716     AsnUnlinkType(orig);       /* unlink local tree */
3717     return grp;
3718 erret:
3719     grp = GeneRefFree(grp);
3720     goto ret;
3721 }
3722 
3723 /*****************************************************************************
3724 *
3725 *   OrgRefNew()
3726 *
3727 *****************************************************************************/
3728 NLM_EXTERN OrgRefPtr LIBCALL OrgRefNew (void)
3729 {
3730     return (OrgRefPtr)MemNew(sizeof(OrgRef));
3731 }
3732 
3733 /*****************************************************************************
3734 *
3735 *   OrgRefFree(orp)
3736 *       Frees an OrgRef and associated data
3737 *
3738 *****************************************************************************/
3739 NLM_EXTERN OrgRefPtr LIBCALL OrgRefFree (OrgRefPtr orp)
3740 {
3741     ValNodePtr anp, next;
3742 
3743     if (orp == NULL)
3744         return (OrgRefPtr)NULL;
3745 
3746     orp->taxname = MemFree(orp->taxname);
3747     orp->common = MemFree(orp->common);
3748     ValNodeFreeData(orp->mod);
3749     orp->mod = NULL;
3750     anp = orp->db;
3751     while (anp != NULL)
3752     {
3753         next = anp->next;
3754         DbtagFree((DbtagPtr)anp->data.ptrvalue);
3755         MemFree(anp);
3756         anp = next;
3757     }
3758     orp->db = NULL;
3759     ValNodeFreeData(orp->syn);
3760     orp->syn = NULL;
3761     OrgNameFree(orp->orgname);
3762     orp->orgname = NULL;
3763     return (OrgRefPtr)MemFree(orp);
3764 }
3765 
3766 /*****************************************************************************
3767 *
3768 *   OrgRefAsnWrite(orp, aip, atp)
3769 *       atp is the current type (if identifier of a parent struct)
3770 *       if atp == NULL, then assumes it stands alone (OrgRef ::=)
3771 *
3772 *****************************************************************************/
3773 NLM_EXTERN Boolean LIBCALL OrgRefAsnWrite (OrgRefPtr orp, AsnIoPtr aip, AsnTypePtr orig)
3774 {
3775     DataVal av;
3776     AsnTypePtr atp;
3777     ValNodePtr anp;
3778     Boolean retval = FALSE;
3779 
3780     if (! loaded)
3781     {
3782         if (! SeqFeatAsnLoad())
3783             return FALSE;
3784     }
3785 
3786     if (aip == NULL)
3787         return FALSE;
3788 
3789     atp = AsnLinkType(orig, ORG_REF);   /* link local tree */
3790     if (atp == NULL)
3791         return FALSE;
3792 
3793     if (orp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3794 
3795     if (! AsnOpenStruct(aip, atp, (Pointer)orp))
3796         goto erret;
3797 
3798     if (orp->taxname != NULL)
3799     {
3800         av.ptrvalue = orp->taxname;
3801         if (! AsnWrite(aip, ORG_REF_taxname, &av)) goto erret;
3802     }
3803     if (orp->common != NULL)
3804     {
3805         av.ptrvalue = orp->common;
3806         if (! AsnWrite(aip, ORG_REF_common, &av)) goto erret;
3807     }
3808     if (orp->mod != NULL)
3809     {
3810         anp = orp->mod;
3811         if (! AsnOpenStruct(aip, ORG_REF_mod, (Pointer)orp->mod))
3812             goto erret;
3813         while (anp != NULL)
3814         {
3815             av.ptrvalue = anp->data.ptrvalue;
3816             if (! AsnWrite(aip, ORG_REF_mod_E, &av)) goto erret;
3817             anp = anp->next;
3818         }
3819         if (! AsnCloseStruct(aip, ORG_REF_mod, (Pointer)orp->mod))
3820             goto erret;
3821     }
3822     if (orp->db != NULL)
3823     {
3824         anp = orp->db;
3825         if (! AsnOpenStruct(aip, ORG_REF_db, (Pointer)orp->db))
3826             goto erret;
3827         while (anp != NULL)
3828         {
3829             if (! DbtagAsnWrite((DbtagPtr)anp->data.ptrvalue, aip, ORG_REF_db_E))
3830                 goto erret;
3831             anp = anp->next;
3832         }
3833         if (! AsnCloseStruct(aip, ORG_REF_db, (Pointer)orp->db))
3834             goto erret;
3835     }
3836     if (orp->syn != NULL)
3837     {
3838         anp = orp->syn;
3839         if (! AsnOpenStruct(aip, ORG_REF_syn, (Pointer)orp->syn))
3840             goto erret;
3841         while (anp != NULL)
3842         {
3843             av.ptrvalue = anp->data.ptrvalue;
3844             if (! AsnWrite(aip, ORG_REF_syn_E, &av)) goto erret;
3845             anp = anp->next;
3846         }
3847         if (! AsnCloseStruct(aip, ORG_REF_syn, (Pointer)orp->syn))
3848             goto erret;
3849     }
3850     if (orp->orgname != NULL)
3851     {
3852         if (! OrgNameAsnWrite(orp->orgname, aip, ORG_REF_orgname))
3853             goto erret;
3854     }
3855     if (! AsnCloseStruct(aip, atp, (Pointer)orp))
3856         goto erret;
3857     retval = TRUE;
3858 erret:
3859     AsnUnlinkType(orig);       /* unlink local tree */
3860     return retval;
3861 }
3862 
3863 /*****************************************************************************
3864 *
3865 *   OrgRefAsnRead(aip, atp)
3866 *       atp is the current type (if identifier of a parent struct)
3867 *            assumption is readIdent has occurred
3868 *       if atp == NULL, then assumes it stands alone and read ident
3869 *            has not occurred.
3870 *
3871 *****************************************************************************/
3872 NLM_EXTERN OrgRefPtr LIBCALL OrgRefAsnRead (AsnIoPtr aip, AsnTypePtr orig)
3873 {
3874     DataVal av;
3875     AsnTypePtr atp, oldatp;
3876     OrgRefPtr orp;
3877     ValNodePtr anp;
3878 
3879     if (! loaded)
3880     {
3881         if (! SeqFeatAsnLoad())
3882             return (OrgRefPtr)NULL;
3883     }
3884 
3885     if (aip == NULL)
3886         return (OrgRefPtr)NULL;
3887 
3888     if (orig == NULL)           /* OrgRef ::= (self contained) */
3889         atp = AsnReadId(aip, amp, ORG_REF);
3890     else
3891         atp = AsnLinkType(orig, ORG_REF);    /* link in local tree */
3892     oldatp = atp;
3893     if (atp == NULL)
3894         return (OrgRefPtr)NULL;
3895 
3896     orp = OrgRefNew();
3897     if (orp == NULL)
3898         goto erret;
3899 
3900     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
3901 
3902     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
3903     {
3904         if (atp == NULL)
3905             goto erret;
3906         if (atp == ORG_REF_orgname)
3907         {
3908             orp->orgname = OrgNameAsnRead(aip, atp);
3909             if (orp->orgname == NULL) goto erret;
3910         } else {
3911             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3912             if (atp == ORG_REF_taxname)
3913                 orp->taxname = (CharPtr)av.ptrvalue;
3914             else if (atp == ORG_REF_common)
3915                 orp->common = (CharPtr)av.ptrvalue;
3916             else if (atp == ORG_REF_mod_E)
3917             {
3918                 anp = ValNodeNew(orp->mod);
3919                 if (anp == NULL)
3920                     goto erret;
3921                 anp->data.ptrvalue = av.ptrvalue;
3922                 if (orp->mod == NULL)
3923                     orp->mod = anp;
3924             }
3925             else if (atp == ORG_REF_db)
3926             {
3927                 while ((atp = AsnReadId(aip, amp, atp)) == ORG_REF_db_E)
3928                 {
3929                     anp = ValNodeNew(orp->db);
3930                     if (anp == NULL)
3931                         goto erret;
3932                     if (orp->db == NULL)
3933                         orp->db = anp;
3934                     anp->data.ptrvalue = (Pointer)DbtagAsnRead(aip, atp);
3935                     if (anp->data.ptrvalue == NULL)
3936                         goto erret;
3937                 }
3938                 if (atp == NULL)
3939                     goto erret;
3940                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end SET OF */
3941             }
3942             else if (atp == ORG_REF_syn_E)
3943             {
3944                 anp = ValNodeNew(orp->syn);
3945                 if (anp == NULL)
3946                     goto erret;
3947                 anp->data.ptrvalue = av.ptrvalue;
3948                 if (orp->syn == NULL)
3949                     orp->syn = anp;
3950             }
3951         }
3952     }
3953     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
3954 ret:
3955     AsnUnlinkType(orig);       /* unlink local tree */
3956     return orp;
3957 erret:
3958     orp = OrgRefFree(orp);
3959     goto ret;
3960 }
3961 
3962 /*****************************************************************************
3963 *
3964 *   ValNodeStringMatch(vnp1, vnp2)
3965 *
3966 *   This function is used by OrgRefMatch.
3967 *****************************************************************************/
3968 static Boolean ValNodeStringMatch (ValNodePtr vnp1, ValNodePtr vnp2)
3969 {
3970   if (vnp1 == NULL && vnp2 == NULL)
3971   {
3972     return TRUE;
3973   }
3974   else if (vnp1 == NULL || vnp2 == NULL)
3975   {
3976     return FALSE;
3977   }
3978   else if (vnp1->choice != vnp2->choice)
3979   {
3980     return FALSE;
3981   }
3982   else if (StringCmp (vnp1->data.ptrvalue, vnp2->data.ptrvalue) != 0)
3983   {
3984     return FALSE;
3985   }
3986   else
3987   {
3988     return ValNodeStringMatch (vnp1->next, vnp2->next);
3989   }
3990 }
3991 
3992 
3993 /*****************************************************************************
3994 *
3995 *   ValNodeDbtagMatch(vnp1, vnp2)
3996 *
3997 *   This function is used by OrgRefMatch.
3998 *****************************************************************************/
3999 static Boolean ValNodeDbtagMatch (ValNodePtr vnp1, ValNodePtr vnp2)
4000 {
4001   if (vnp1 == NULL && vnp2 == NULL)
4002   {
4003     return TRUE;
4004   }
4005   else if (vnp1 == NULL || vnp2 == NULL)
4006   {
4007     return FALSE;
4008   }
4009   else if (vnp1->choice != vnp2->choice)
4010   {
4011     return FALSE;
4012   }
4013   else if (!DbtagMatch (vnp1->data.ptrvalue, vnp2->data.ptrvalue))
4014   {
4015     return FALSE;
4016   }
4017   else
4018   {
4019     return ValNodeDbtagMatch (vnp1->next, vnp2->next);
4020   }
4021 }
4022 
4023 /*****************************************************************************
4024 *
4025 *   OrgRefMatch(orp1, orp2)
4026 *
4027 *****************************************************************************/
4028 NLM_EXTERN Boolean LIBCALL OrgRefMatch (OrgRefPtr orp1, OrgRefPtr orp2)
4029 {
4030   if (orp1 == NULL && orp2 == NULL)
4031   {
4032     return TRUE;
4033   }
4034   else if (orp1 == NULL || orp2 == NULL)
4035   {
4036     return FALSE;
4037   }
4038   else if (StringCmp (orp1->taxname, orp2->taxname) != 0
4039            || StringCmp (orp1->common, orp2->common) != 0)
4040   {
4041     return FALSE;
4042   }
4043   else if (!ValNodeStringMatch (orp1->syn, orp2->syn)
4044           || ! ValNodeDbtagMatch (orp1->db, orp2->db))
4045   {
4046     return FALSE;
4047   }
4048   else if (! OrgNameMatch (orp1->orgname, orp2->orgname))
4049   {
4050     return FALSE;
4051   }
4052   else
4053   {
4054     return TRUE;
4055   }  
4056 }
4057 
4058 
4059 /*****************************************************************************
4060 *
4061 *   OrgNameNew()
4062 *
4063 *****************************************************************************/
4064 NLM_EXTERN OrgNamePtr LIBCALL OrgNameNew (void)
4065 {
4066     return (OrgNamePtr)MemNew(sizeof(OrgName));
4067 }
4068 
4069 /*****************************************************************************
4070 *
4071 *   OrgNameFree(onp)
4072 *       Frees an OrgName and associated data
4073 *
4074 *****************************************************************************/
4075 NLM_EXTERN OrgNamePtr LIBCALL OrgNameFree (OrgNamePtr onp)
4076 {
4077     if (onp == NULL)
4078         return (OrgNamePtr)NULL;
4079 
4080     switch (onp->choice)
4081     {
4082         case 1:      /* binomial name */
4083         case 4:      /* named hydrid */
4084             BinomialOrgNameFree((BinomialOrgNamePtr)(onp->data));
4085             break;
4086         case 2:      /* virus name */
4087             MemFree(onp->data);
4088             break;
4089         case 3:   /* hybrid */
4090             OrgNameSetFree((OrgNamePtr)(onp->data));
4091             break;
4092         case 5:   /* partially characterized name */
4093             TaxElementSetFree((TaxElementPtr)(onp->data));
4094             break;
4095 
4096     }
4097     MemFree(onp->attrib);
4098     OrgModSetFree(onp->mod);
4099      MemFree(onp->lineage);
4100      MemFree(onp->div);
4101     return (OrgNamePtr)MemFree(onp);
4102 }
4103 
4104 /*****************************************************************************
4105 *
4106 *   OrgNameAsnWrite(onp, aip, atp)
4107 *       atp is the current type (if identifier of a parent struct)
4108 *       if atp == NULL, then assumes it stands alone (OrgName ::=)
4109 *
4110 *****************************************************************************/
4111 NLM_EXTERN Boolean LIBCALL OrgNameAsnWrite (OrgNamePtr onp, AsnIoPtr aip, AsnTypePtr orig)
4112 {
4113     DataVal av;
4114     AsnTypePtr atp;
4115     Boolean retval = FALSE;
4116 
4117     if (! loaded)
4118     {
4119         if (! SeqFeatAsnLoad())
4120             return FALSE;
4121     }
4122 
4123     if (aip == NULL)
4124         return FALSE;
4125 
4126     atp = AsnLinkType(orig, ORGNAME);   /* link local tree */
4127     if (atp == NULL)
4128         return FALSE;
4129 
4130     if (onp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
4131 
4132     if (! AsnOpenStruct(aip, atp, (Pointer)onp))
4133         goto erret;
4134 
4135     if (onp->choice != 0)
4136     {
4137     if (! AsnWriteChoice(aip, ORGNAME_name, (Int2)onp->choice, &av)) goto erret;
4138 
4139 
4140     switch (onp->choice)
4141     {
4142         case 1:      /* binomial name */
4143             if (! BinomialOrgNameAsnWrite((BinomialOrgNamePtr)(onp->data), aip, ORGNAME_name_binomial))
4144                 goto erret;
4145             break;
4146         case 2:      /* virus name */
4147             av.ptrvalue = onp->data;
4148             if (AsnWrite(aip, ORGNAME_name_virus, &av) <= 0)
4149                 goto erret;
4150             break;
4151         case 3:   /* hybrid */
4152             if (! OrgNameSetAsnWrite((OrgNamePtr)(onp->data), aip, ORGNAME_name_hybrid, MULTIORGNAME_E))
4153                 goto erret;
4154             break;
4155         case 4:      /* named hybrid */
4156             if (! BinomialOrgNameAsnWrite((BinomialOrgNamePtr)(onp->data), aip, ORGNAME_name_namedhybrid))
4157                 goto erret;
4158             break;
4159         case 5:   /* partially characterized name */
4160             if (! TaxElementSetAsnWrite((TaxElementPtr)(onp->data), aip, ORGNAME_name_partial, PARTIALORGNAME_E))
4161                 goto erret;
4162             break;
4163 
4164     }
4165     }
4166 
4167     if (onp->attrib != NULL)
4168     {
4169         av.ptrvalue = onp->attrib;
4170         if (! AsnWrite(aip, ORGNAME_attrib, &av)) goto erret;
4171     }
4172     if (onp->mod != NULL)
4173     {
4174         if (! OrgModSetAsnWrite(onp->mod, aip, ORGNAME_mod, ORGNAME_mod_E))
4175             goto erret;
4176     }
4177 
4178     if (onp->lineage != NULL)
4179     {
4180           if (aip->spec_version == 3)    /* ASN3 strip new value */
4181           {
4182               ErrPostEx(SEV_ERROR,0,0,"ASN3: OrgName.lineage stripped");
4183           }
4184           else
4185           {
4186         av.ptrvalue = onp->lineage;
4187         if (! AsnWrite(aip, ORGNAME_lineage, &av)) goto erret;
4188          }      
4189     }
4190 
4191     if (onp->gcode)
4192     {
4193           if (aip->spec_version == 3)    /* ASN3 strip new value */
4194           {
4195               ErrPostEx(SEV_ERROR,0,0,"ASN3: OrgName.gcode stripped");
4196           }
4197           else
4198           {
4199         av.intvalue = (Int4)(onp->gcode);
4200         if (! AsnWrite(aip, ORGNAME_gcode, &av)) goto erret;
4201          }      
4202     }
4203 
4204     if (onp->mgcode)
4205     {
4206           if (aip->spec_version == 3)    /* ASN3 strip new value */
4207           {
4208               ErrPostEx(SEV_ERROR,0,0,"ASN3:  OrgName.mgcode stripped");
4209           }
4210           else
4211           {
4212         av.intvalue = (Int4)(onp->mgcode);
4213         if (! AsnWrite(aip, ORGNAME_mgcode, &av)) goto erret;
4214          }      
4215     }
4216 
4217     if (onp->div != NULL)
4218     {
4219           if (aip->spec_version > 0 && aip->spec_version < 5)    /* ASN4 strip new value */
4220           {
4221               ErrPostEx(SEV_ERROR,0,0,"ASN3: OrgName.lineage stripped");
4222           }
4223           else
4224           {
4225         av.ptrvalue = onp->div;
4226         if (! AsnWrite(aip, ORGNAME_div, &av)) goto erret;
4227          }      
4228     }
4229 
4230 
4231     if (! AsnCloseStruct(aip, atp, (Pointer)onp))
4232         goto erret;
4233     retval = TRUE;
4234 erret:
4235     AsnUnlinkType(orig);       /* unlink local tree */
4236     return retval;
4237 }
4238 
4239 /*****************************************************************************
4240 *
4241 *   OrgNameAsnRead(aip, atp)
4242 *       atp is the current type (if identifier of a parent struct)
4243 *            assumption is readIdent has occurred
4244 *       if atp == NULL, then assumes it stands alone and read ident
4245 *            has not occurred.
4246 *
4247 *****************************************************************************/
4248 NLM_EXTERN OrgNamePtr LIBCALL OrgNameAsnRead (AsnIoPtr aip, AsnTypePtr orig)
4249 {
4250     DataVal av;
4251     AsnTypePtr atp, oldatp;
4252     OrgNamePtr onp;
4253 
4254     if (! loaded)
4255     {
4256         if (! SeqFeatAsnLoad())
4257             return (OrgNamePtr)NULL;
4258     }
4259 
4260     if (aip == NULL)
4261         return (OrgNamePtr)NULL;
4262 
4263     if (orig == NULL)           /* OrgName ::= (self contained) */
4264         atp = AsnReadId(aip, amp, ORGNAME);
4265     else
4266         atp = AsnLinkType(orig, ORGNAME);    /* link in local tree */
4267     oldatp = atp;
4268     if (atp == NULL)
4269         return (OrgNamePtr)NULL;
4270 
4271     onp = OrgNameNew();
4272     if (onp == NULL)
4273         goto erret;
4274 
4275     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
4276 
4277     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
4278     {
4279         if (atp == NULL)
4280             goto erret;
4281         if (atp == ORGNAME_name_binomial)
4282         {
4283             onp->choice = 1;
4284             onp->data = (Pointer)BinomialOrgNameAsnRead(aip, atp);
4285             if (onp->data == NULL) goto erret;
4286         }
4287         else if (atp == ORGNAME_name_hybrid)
4288         {
4289             onp->choice = 3;
4290             onp->data = (Pointer)OrgNameSetAsnRead(aip, atp, MULTIORGNAME_E);
4291             if (onp->data == NULL) goto erret;
4292         }
4293         else if (atp == ORGNAME_name_namedhybrid)
4294         {
4295             onp->choice = 4;
4296             onp->data = (Pointer)BinomialOrgNameAsnRead(aip, atp);
4297             if (onp->data == NULL) goto erret;
4298         }
4299         else if (atp == ORGNAME_name_partial)
4300         {
4301             onp->choice = 5;
4302             onp->data = (Pointer)TaxElementSetAsnRead(aip, atp, PARTIALORGNAME_E);
4303             if (onp->data == NULL) goto erret;
4304         }
4305         else if (atp == ORGNAME_mod)
4306         {
4307             onp->mod = OrgModSetAsnRead(aip, atp, ORGNAME_mod_E);
4308             if (onp->mod == NULL) goto erret;
4309         }
4310         else
4311         {
4312          if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
4313          if (atp == ORGNAME_name_virus)
4314             {
4315                 onp->choice = 2;
4316                 onp->data = av.ptrvalue;
4317             }
4318             else if (atp == ORGNAME_attrib)
4319                 onp->attrib = (CharPtr)av.ptrvalue;
4320             else if (atp == ORGNAME_lineage)
4321             {
4322                if (aip->spec_version == 3)    /* ASN3 strip new value */
4323               {
4324                   ErrPostEx(SEV_ERROR,0,0,"ASN3:  OrgName.lineage stripped");
4325                 MemFree((CharPtr)(av.ptrvalue));
4326               }
4327               else
4328                 onp->lineage = (CharPtr)av.ptrvalue;
4329            }
4330             else if (atp == ORGNAME_gcode)
4331             {
4332                if (aip->spec_version == 3)    /* ASN3 strip new value */
4333               {
4334                   ErrPostEx(SEV_ERROR,0,0,"ASN3:  OrgName.gcode stripped");
4335               }
4336               else
4337                 onp->gcode = (Uint1)av.intvalue;
4338            }
4339             else if (atp == ORGNAME_mgcode)
4340             {
4341                if (aip->spec_version == 3)    /* ASN3 strip new value */
4342               {
4343                   ErrPostEx(SEV_ERROR,0,0,"ASN3:  OrgName.mgcode stripped");
4344               }
4345               else
4346                 onp->mgcode = (Uint1)av.intvalue;
4347            }
4348             else if (atp == ORGNAME_div)
4349             {
4350                if (aip->spec_version > 0 && aip->spec_version < 5)    /* ASN4 strip new value */
4351               {
4352                   ErrPostEx(SEV_ERROR,0,0,"ASN4:  OrgName.div stripped");
4353               }
4354               else
4355                 onp->div = (CharPtr)(av.ptrvalue);
4356            }
4357         }
4358     }
4359     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
4360 ret:
4361     AsnUnlinkType(orig);       /* unlink local tree */
4362     return onp;
4363 erret:
4364     onp = OrgNameFree(onp);
4365     goto ret;
4366 }
4367 
4368 /*****************************************************************************
4369 *
4370 *   OrgNameSetFree (onp)
4371 *
4372 *****************************************************************************/
4373 NLM_EXTERN OrgNamePtr LIBCALL OrgNameSetFree (OrgNamePtr onp)
4374 {
4375     OrgNamePtr next;
4376 
4377     while (onp != NULL)
4378     {
4379         next = onp->next;
4380         OrgNameFree(onp);
4381         onp = next;
4382     }
4383     return onp;
4384 }
4385 
4386 /*****************************************************************************
4387 *
4388 *   OrgNameSetAsnWrite(onp, aip, set, element)
4389 *
4390 *****************************************************************************/
4391 NLM_EXTERN Boolean LIBCALL OrgNameSetAsnWrite (OrgNamePtr onp, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
4392 {
4393     AsnTypePtr atp;
4394     OrgNamePtr oldonp;
4395     Boolean retval = FALSE;
4396 
4397     if (! loaded)
4398     {
4399         if (! SeqFeatAsnLoad())
4400             return FALSE;
4401     }
4402 
4403     if (aip == NULL)
4404         return FALSE;
4405 
4406     atp = AsnLinkType(element, ORGNAME);   /* link local tree */
4407     if (atp == NULL)
4408         return FALSE;
4409     oldonp = onp;
4410 
4411     if (! AsnOpenStruct(aip, set, (Pointer)oldonp))
4412         goto erret;
4413 
4414     while (onp != NULL)
4415     {
4416         if (! OrgNameAsnWrite(onp, aip, atp))
4417             goto erret;
4418         onp = onp->next;
4419     }
4420 
4421     if (! AsnCloseStruct(aip, set, (Pointer)oldonp))
4422         goto erret;
4423     retval = TRUE;
4424 erret:
4425     AsnUnlinkType(element);       /* unlink local tree */
4426     return retval;
4427 }
4428 
4429 /*****************************************************************************
4430 *
4431 *   OrgNameSetAsnRead(aip, set, element)
4432 *
4433 *****************************************************************************/
4434 NLM_EXTERN OrgNamePtr LIBCALL OrgNameSetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
4435 {
4436     DataVal av;
4437     AsnTypePtr atp;
4438     OrgNamePtr onp, curr = NULL, first = NULL;
4439 
4440     if (aip == NULL)
4441         return (OrgNamePtr)NULL;
4442 
4443     AsnLinkType(element, ORGNAME);    /* link in local tree */
4444     atp = set;
4445 
4446     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
4447     while ((atp = AsnReadId(aip, amp, atp)) == element)
4448     {
4449         onp = OrgNameAsnRead(aip, atp);
4450         if (onp == NULL)
4451             goto erret;
4452         if (first == NULL)
4453             first = onp;
4454         else
4455             curr->next = onp;
4456         curr = onp;
4457     }
4458     if (atp == NULL)
4459         goto erret;
4460     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
4461     if (first == NULL)
4462         ErrPostEx(SEV_WARNING, 0, 0, "Empty SET OF OrgName. line %ld", (long) aip->linenumber);
4463 ret:
4464     AsnUnlinkType(element);       /* unlink local tree */
4465     return first;
4466 erret:
4467     first = OrgNameSetFree(first);
4468     goto ret;
4469 }
4470 
4471 /*****************************************************************************
4472 *
4473 *   OrgNameMatch (onp1, onp2)
4474 *
4475 *****************************************************************************/
4476 NLM_EXTERN Boolean LIBCALL OrgNameMatch (OrgNamePtr onp1, OrgNamePtr onp2)
4477 {
4478     if (onp1 == NULL && onp2 == NULL)
4479   {
4480     return TRUE;
4481   }
4482   else if (onp1 == NULL || onp2 == NULL)
4483   {
4484     return FALSE;
4485   }
4486   else if (onp1->choice != onp2->choice
4487            || onp1->gcode != onp2->gcode
4488            || onp2->mgcode != onp2->mgcode
4489            || StringCmp (onp1->attrib, onp2->attrib) != 0
4490            || StringCmp (onp1->lineage, onp2->lineage) != 0
4491            || StringCmp (onp1->div, onp2->div) != 0
4492            || ! OrgModSetMatch (onp1->mod, onp2->mod)
4493            || ! OrgNameMatch (onp1->next, onp2->next))
4494   {
4495     return FALSE;
4496   }
4497   else
4498   {
4499     return TRUE;
4500   }  
4501 }
4502 
4503 /*****************************************************************************
4504 *
4505 *   ProtRefNew()
4506 *
4507 *****************************************************************************/
4508 NLM_EXTERN ProtRefPtr LIBCALL ProtRefNew (void)
4509 {
4510     return (ProtRefPtr)MemNew(sizeof(ProtRef));
4511 }
4512 
4513 /*****************************************************************************
4514 *
4515 *   ProtRefFree(prp)
4516 *       Frees an ProtRef and associated data
4517 *
4518 *****************************************************************************/
4519 NLM_EXTERN ProtRefPtr LIBCALL ProtRefFree (ProtRefPtr prp)
4520 {
4521     ValNodePtr anp, next;
4522 
4523     if (prp == NULL)
4524         return (ProtRefPtr)NULL;
4525 
4526     MemFree(prp->desc);
4527     anp = prp->name;
4528     while (anp != NULL)
4529     {
4530         next = anp->next;
4531         MemFree(anp->data.ptrvalue);
4532         MemFree(anp);
4533         anp = next;
4534     }
4535     anp = prp->ec;
4536     while (anp != NULL)
4537     {
4538         next = anp->next;
4539         MemFree(anp->data.ptrvalue);
4540         MemFree(anp);
4541         anp = next;
4542     }
4543     anp = prp->activity;
4544     while (anp != NULL)
4545     {
4546         next = anp->next;
4547         MemFree(anp->data.ptrvalue);
4548         MemFree(anp);
4549         anp = next;
4550     }
4551     anp = prp->db;
4552     while (anp != NULL)
4553     {
4554         next = anp->next;
4555         DbtagFree((DbtagPtr)anp->data.ptrvalue);
4556         MemFree(anp);
4557         anp = next;
4558     }
4559     return (ProtRefPtr)MemFree(prp);
4560 }
4561 
4562 /*****************************************************************************
4563 *
4564 *   ProtRefDup(prp)
4565 *       Duplicates an ProtRef and associated data
4566 *
4567 *****************************************************************************/
4568 NLM_EXTERN ProtRefPtr LIBCALL ProtRefDup (ProtRefPtr prp)
4569 {
4570     ValNodePtr anp, vnp;
4571     ProtRefPtr npp;
4572 
4573     if (prp == NULL)
4574         return (ProtRefPtr)NULL;
4575 
4576     npp = ProtRefNew();
4577     if (npp == NULL) return npp;
4578 
4579     if (prp->desc != NULL)
4580         npp->desc = StringSave(prp->desc);
4581     anp = prp->name;
4582     while (anp != NULL)
4583     {
4584         vnp = ValNodeNew(npp->name);
4585         if (vnp == NULL) return ProtRefFree(prp);
4586         if (npp->name == NULL)
4587             npp->name = vnp;
4588         vnp->data.ptrvalue = StringSave((CharPtr)anp->data.ptrvalue);
4589         anp = anp->next;
4590     }
4591     anp = prp->ec;
4592     while (anp != NULL)
4593     {
4594         vnp = ValNodeNew(npp->ec);
4595         if (vnp == NULL) return ProtRefFree(prp);
4596         if (npp->ec == NULL)
4597             npp->ec = vnp;
4598         vnp->data.ptrvalue = StringSave((CharPtr)anp->data.ptrvalue);
4599         anp = anp->next;
4600     }
4601     anp = prp->activity;
4602     while (anp != NULL)
4603     {
4604         vnp = ValNodeNew(npp->activity);
4605         if (vnp == NULL) return ProtRefFree(prp);
4606         if (npp->activity == NULL)
4607             npp->activity = vnp;
4608         vnp->data.ptrvalue = StringSave((CharPtr)anp->data.ptrvalue);
4609         anp = anp->next;
4610     }
4611     anp = prp->db;
4612     while (anp != NULL)
4613     {
4614         vnp = ValNodeNew(npp->db);
4615         if (vnp == NULL) return ProtRefFree(prp);
4616         if (npp->db == NULL)
4617             npp->db = vnp;
4618         vnp->data.ptrvalue = DbtagDup((DbtagPtr)anp->data.ptrvalue);
4619         anp = anp->next;
4620     }
4621     npp->processed = prp->processed;
4622     return npp;
4623 }
4624 
4625 /*****************************************************************************
4626 *
4627 *   ProtRefAsnWrite(prp, aip, atp)
4628 *       atp is the current type (if identifier of a parent struct)
4629 *       if atp == NULL, then assumes it stands alone (ProtRef ::=)
4630 *
4631 *****************************************************************************/
4632 NLM_EXTERN Boolean LIBCALL ProtRefAsnWrite (ProtRefPtr prp, AsnIoPtr aip, AsnTypePtr orig)
4633 {
4634     DataVal av;
4635     AsnTypePtr atp;
4636     ValNodePtr anp;
4637     Boolean retval = FALSE;
4638 
4639     if (! loaded)
4640     {
4641         if (! SeqFeatAsnLoad())
4642             return FALSE;
4643     }
4644 
4645     if (aip == NULL)
4646         return FALSE;
4647 
4648     atp = AsnLinkType(orig, PROT_REF);   /* link local tree */
4649     if (atp == NULL)
4650         return FALSE;
4651 
4652     if (prp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
4653 
4654     if (! AsnOpenStruct(aip, atp, (Pointer)prp))
4655         goto erret;
4656 
4657     if (prp->name != NULL)
4658     {
4659         if (! AsnOpenStruct(aip, PROT_REF_name, (Pointer)prp->name))
4660             goto erret;
4661         anp = prp->name;
4662         while (anp != NULL)
4663         {
4664             if (! AsnWrite(aip, PROT_REF_name_E, &anp->data))
4665                 goto erret;
4666             anp = anp->next;
4667         }
4668         if (! AsnCloseStruct(aip, PROT_REF_name, (Pointer)prp->name))
4669             goto erret;
4670     }
4671     if (prp->desc != NULL)
4672     {
4673         av.ptrvalue = prp->desc;
4674         if (! AsnWrite(aip, PROT_REF_desc, &av)) goto erret;
4675     }
4676     if (prp->ec != NULL)
4677     {
4678         if (! AsnOpenStruct(aip, PROT_REF_ec, (Pointer)prp->ec))
4679             goto erret;
4680         anp = prp->ec;
4681         while (anp != NULL)
4682         {
4683             if (! AsnWrite(aip, PROT_REF_ec_E, &anp->data))
4684                 goto erret;
4685             anp = anp->next;
4686         }
4687         if (! AsnCloseStruct(aip, PROT_REF_ec, (Pointer)prp->ec))
4688             goto erret;
4689     }
4690     if (prp->activity != NULL)
4691     {
4692         if (! AsnOpenStruct(aip, PROT_REF_activity, (Pointer)prp->activity))
4693             goto erret;
4694         anp = prp->activity;
4695         while (anp != NULL)
4696         {
4697             if (! AsnWrite(aip, PROT_REF_activity_E, &anp->data))
4698                 goto erret;
4699             anp = anp->next;
4700         }
4701         if (! AsnCloseStruct(aip, PROT_REF_activity, (Pointer)prp->activity))
4702             goto erret;
4703     }
4704     if (prp->db != NULL)
4705     {
4706         anp = prp->db;
4707         if (! AsnOpenStruct(aip, PROT_REF_db, (Pointer)prp->db))
4708             goto erret;
4709         while (anp != NULL)
4710         {
4711             if (! DbtagAsnWrite((DbtagPtr)anp->data.ptrvalue, aip, PROT_REF_db_E))
4712                 goto erret;
4713             anp = anp->next;
4714         }
4715         if (! AsnCloseStruct(aip, PROT_REF_db, (Pointer)prp->db))
4716             goto erret;
4717     }
4718     if (prp->processed)
4719     {
4720         if ((prp->processed < 3) || (aip->spec_version == 0 || aip->spec_version > 4))
4721         {
4722             av.intvalue = (Int4)(prp->processed);
4723             if (AsnWrite(aip, PROT_REF_processed, &av) <= 0) goto erret;
4724         }
4725     }
4726 
4727     if (! AsnCloseStruct(aip, atp, (Pointer)prp))
4728         goto erret;
4729     retval = TRUE;
4730 erret:
4731     AsnUnlinkType(orig);       /* unlink local tree */
4732     return retval;
4733 }
4734 
4735 /*****************************************************************************
4736 *
4737 *   ProtRefAsnRead(aip, atp)
4738 *       atp is the current type (if identifier of a parent struct)
4739 *            assumption is readIdent has occurred
4740 *       if atp == NULL, then assumes it stands alone and read ident
4741 *            has not occurred.
4742 *
4743 *****************************************************************************/
4744 NLM_EXTERN ProtRefPtr LIBCALL ProtRefAsnRead (AsnIoPtr aip, AsnTypePtr orig)
4745 {
4746     DataVal av;
4747     AsnTypePtr atp, oldatp;
4748     ProtRefPtr prp;
4749     ValNodePtr anp;
4750 
4751     if (! loaded)
4752     {
4753         if (! SeqFeatAsnLoad())
4754             return (ProtRefPtr)NULL;
4755     }
4756 
4757     if (aip == NULL)
4758         return (ProtRefPtr)NULL;
4759 
4760     if (orig == NULL)           /* ProtRef ::= (self contained) */
4761         atp = AsnReadId(aip, amp, PROT_REF);
4762     else
4763         atp = AsnLinkType(orig, PROT_REF);    /* link in local tree */
4764     oldatp = atp;
4765     if (atp == NULL)
4766         return (ProtRefPtr)NULL;
4767 
4768     prp = ProtRefNew();
4769     if (prp == NULL)
4770         goto erret;
4771 
4772     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
4773 
4774     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
4775     {
4776         if (atp == NULL)
4777             goto erret;
4778         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
4779         if (atp == PROT_REF_desc)
4780             prp->desc = (CharPtr)av.ptrvalue;
4781         else if (atp == PROT_REF_name)
4782         {
4783             while ((atp = AsnReadId(aip, amp, atp)) == PROT_REF_name_E)
4784             {
4785                 anp = ValNodeNew(prp->name);
4786                 if (anp == NULL)
4787                     goto erret;
4788                 if (prp->name == NULL)
4789                     prp->name = anp;
4790                 if (AsnReadVal(aip, atp, &anp->data) <= 0) goto erret;
4791             }
4792             if (atp == NULL)
4793                 goto erret;
4794             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end SET OF */
4795         }
4796         else if (atp == PROT_REF_ec)
4797         {
4798             while ((atp = AsnReadId(aip, amp, atp)) == PROT_REF_ec_E)
4799             {
4800                 anp = ValNodeNew(prp->ec);
4801                 if (anp == NULL)
4802                     goto erret;
4803                 if (prp->ec == NULL)
4804                     prp->ec = anp;
4805                 if (AsnReadVal(aip, atp, &anp->data) <= 0) goto erret;
4806             }
4807             if (atp == NULL)
4808                 goto erret;
4809             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end SET OF */
4810         }
4811         else if (atp == PROT_REF_activity)
4812         {
4813             while ((atp = AsnReadId(aip, amp, atp)) == PROT_REF_activity_E)
4814             {
4815                 anp = ValNodeNew(prp->activity);
4816                 if (anp == NULL)
4817                     goto erret;
4818                 if (prp->activity == NULL)
4819                     prp->activity = anp;
4820                 if (AsnReadVal(aip, atp, &anp->data) <= 0) goto erret;
4821             }
4822             if (atp == NULL)
4823                 goto erret;
4824             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end SET OF */
4825         }
4826         else if (atp == PROT_REF_db)
4827         {
4828             while ((atp = AsnReadId(aip, amp, atp)) == PROT_REF_db_E)
4829             {
4830                 anp = ValNodeNew(prp->db);
4831                 if (anp == NULL)
4832                     goto erret;
4833                 if (prp->db == NULL)
4834                     prp->db = anp;
4835                 anp->data.ptrvalue = (Pointer)DbtagAsnRead(aip, atp);
4836                 if (anp->data.ptrvalue == NULL)
4837                     goto erret;
4838             }
4839             if (atp == NULL)
4840                 goto erret;
4841             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end SET OF */
4842         }
4843         else if (atp == PROT_REF_processed)
4844             prp->processed = (Uint1)(av.intvalue);
4845     }
4846     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
4847 ret:
4848     AsnUnlinkType(orig);       /* unlink local tree */
4849     return prp;
4850 erret:
4851     prp = ProtRefFree(prp);
4852     goto ret;
4853 }
4854 
4855 /*****************************************************************************
4856 *
4857 *   RsiteRefFree(rrp)
4858 *       Frees an RsiteRef and associated data
4859 *
4860 *****************************************************************************/
4861 NLM_EXTERN RsiteRefPtr LIBCALL RsiteRefFree (RsiteRefPtr rrp)
4862 {
4863     if (rrp == NULL)
4864         return (RsiteRefPtr)NULL;
4865 
4866     if (rrp->choice == 1)   /* str */
4867         MemFree(rrp->data.ptrvalue);
4868     else
4869         DbtagFree((DbtagPtr)rrp->data.ptrvalue);
4870     return (RsiteRefPtr)MemFree(rrp);
4871 }
4872 
4873 /*****************************************************************************
4874 *
4875 *   RsiteRefAsnWrite(rrp, aip, atp)
4876 *       atp is the current type (if identifier of a parent struct)
4877 *       if atp == NULL, then assumes it stands alone (RsiteRef ::=)
4878 *
4879 *****************************************************************************/
4880 NLM_EXTERN Boolean LIBCALL RsiteRefAsnWrite (RsiteRefPtr rrp, AsnIoPtr aip, AsnTypePtr orig)
4881 {
4882     DataVal av;
4883     AsnTypePtr atp;
4884     Boolean retval = FALSE;
4885 
4886     if (! loaded)
4887     {
4888         if (! SeqFeatAsnLoad())
4889             return FALSE;
4890     }
4891 
4892     if (aip == NULL)
4893         return FALSE;
4894 
4895     atp = AsnLinkType(orig, RSITE_REF);   /* link local tree */
4896     if (atp == NULL)
4897         return FALSE;
4898 
4899     if (rrp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
4900 
4901     if (! AsnWrite(aip, atp, &av)) goto erret;     /* CHOICE */
4902     switch (rrp->choice)
4903     {
4904         case 1:
4905             if (! AsnWrite(aip, RSITE_REF_str, &rrp->data))
4906                 goto erret;
4907             break;
4908         case 2:
4909             if (! DbtagAsnWrite((DbtagPtr)rrp->data.ptrvalue, aip, RSITE_REF_db))
4910                 goto erret;
4911             break;
4912     }
4913     retval = TRUE;
4914 erret:
4915     AsnUnlinkType(orig);       /* unlink local tree */
4916     return retval;
4917 }
4918 
4919 /*****************************************************************************
4920 *
4921 *   RsiteRefAsnRead(aip, atp)
4922 *       atp is the current type (if identifier of a parent struct)
4923 *            assumption is readIdent has occurred
4924 *       if atp == NULL, then assumes it stands alone and read ident
4925 *            has not occurred.
4926 *
4927 *****************************************************************************/
4928 NLM_EXTERN RsiteRefPtr LIBCALL RsiteRefAsnRead (AsnIoPtr aip, AsnTypePtr orig)
4929 {
4930     DataVal av;
4931     AsnTypePtr atp;
4932     RsiteRefPtr rrp;
4933 
4934     if (! loaded)
4935     {
4936         if (! SeqFeatAsnLoad())
4937             return (RsiteRefPtr)NULL;
4938     }
4939 
4940     if (aip == NULL)
4941         return (RsiteRefPtr)NULL;
4942 
4943     if (orig == NULL)           /* RsiteRef ::= (self contained) */
4944         atp = AsnReadId(aip, amp, RSITE_REF);
4945     else
4946         atp = AsnLinkType(orig, RSITE_REF);    /* link in local tree */
4947     if (atp == NULL)
4948         return (RsiteRefPtr)NULL;
4949 
4950     rrp = ValNodeNew(NULL);
4951     if (rrp == NULL)
4952         goto erret;
4953 
4954     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the CHOICE */
4955     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;   /* which CHOICE */
4956     if (atp == NULL)
4957         goto erret;
4958     if (atp == RSITE_REF_str)
4959     {
4960         rrp->choice = 1;
4961         if (AsnReadVal(aip, atp, &rrp->data) <= 0)
4962             goto erret;
4963     }
4964     else if (atp == RSITE_REF_db)
4965     {
4966         rrp->choice = 2;
4967         rrp->data.ptrvalue = (Pointer) DbtagAsnRead(aip, atp);
4968         if (rrp->data.ptrvalue == NULL)
4969             goto erret;
4970     }
4971 ret:
4972     AsnUnlinkType(orig);       /* unlink local tree */
4973     return rrp;
4974 erret:
4975     rrp = RsiteRefFree(rrp);
4976     goto ret;
4977 }
4978 
4979 /*****************************************************************************
4980 *
4981 *   SeqFeatIdFree(cp)
4982 *       Frees one SeqFeatId's associated data
4983 *       Does NOT free the Choice itself
4984 *
4985 *****************************************************************************/
4986 NLM_EXTERN void LIBCALL SeqFeatIdFree (ChoicePtr cp)
4987 {
4988     Pointer pnt;
4989 
4990     if (cp == NULL)
4991         return;
4992 
4993     pnt = cp->value.ptrvalue;
4994     switch (cp->choice)
4995     {
4996         case 1:     /* gibb id */
4997             cp->value.intvalue = 0;
4998             break;
4999         case 2:     /* giim id */
5000             cp->value.ptrvalue = GiimFree((GiimPtr)pnt);
5001             break;
5002         case 3:
5003             cp->value.ptrvalue = ObjectIdFree((ObjectIdPtr)pnt);
5004             break;
5005         case 4:
5006             cp->value.ptrvalue = DbtagFree((DbtagPtr)pnt);
5007             break;
5008     }
5009     cp->choice = 0;
5010     return;
5011 }
5012 
5013 /*****************************************************************************
5014 *
5015 *   SeqFeatIdDup(dest, src)
5016 *       Duplicates one SeqFeatId's associated data
5017 *
5018 *****************************************************************************/
5019 NLM_EXTERN Boolean LIBCALL SeqFeatIdDup (ChoicePtr dest, ChoicePtr src)
5020 {
5021     GiimPtr ga, gb;
5022 
5023     if (src == NULL)
5024         return FALSE;
5025 
5026     dest->choice = src->choice;
5027     switch (src->choice)
5028     {
5029         case 1:     /* gibb */
5030             dest->value.intvalue = src->value.intvalue;
5031             break;
5032         case 2:     /* giim id */
5033             ga = (GiimPtr) src->value.ptrvalue;
5034             gb = GiimNew();
5035             if (gb == NULL) return FALSE;
5036             gb->id = ga->id;
5037             gb->db = StringSave(ga->db);
5038             gb->release = StringSave(ga->release);
5039             dest->value.ptrvalue = gb;
5040             break;
5041         case 3:
5042             dest->value.ptrvalue = ObjectIdDup((ObjectIdPtr)src->value.ptrvalue);
5043             break;
5044         case 4:
5045             dest->value.ptrvalue = DbtagDup((DbtagPtr)src->value.ptrvalue);
5046             break;
5047     }
5048     return TRUE;
5049 }
5050 
5051 /*****************************************************************************
5052 *
5053 *   SeqFeatIdAsnWrite(cp, aip, atp)
5054 *       atp is the current type (if identifier of a parent struct)
5055 *       if atp == NULL, then assumes it stands alone (SeqFeatId ::=)
5056 *
5057 *****************************************************************************/
5058 NLM_EXTERN Boolean LIBCALL SeqFeatIdAsnWrite (ChoicePtr cp, AsnIoPtr aip, AsnTypePtr orig)
5059 {
5060     DataVal av;
5061     AsnTypePtr atp;
5062     Boolean retval = FALSE;
5063 
5064     if (! loaded)
5065     {
5066         if (! SeqFeatAsnLoad())
5067             return FALSE;
5068     }
5069 
5070     if (aip == NULL)
5071         return FALSE;
5072 
5073     atp = AsnLinkType(orig, FEAT_ID);   /* link local tree */
5074     if (atp == NULL)
5075         return FALSE;
5076 
5077     if (cp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
5078 
5079     if (cp->choice)              /* feat-id present */
5080     {
5081         if (! AsnWrite(aip, atp, &av)) goto erret;   /* CHOICE */
5082         if (cp->choice == 1)           /* gibb */
5083         {
5084             av.intvalue = cp->value.intvalue;
5085             if (! AsnWrite(aip, FEAT_ID_gibb, &av)) goto erret;
5086         }
5087         else if (cp->choice == 2)      /* giim */
5088         {
5089             if (! GiimAsnWrite((GiimPtr)cp->value.ptrvalue, aip, FEAT_ID_giim))
5090                 goto erret;
5091         }
5092         else if (cp->choice == 3)      /* local */
5093         {
5094             if (! ObjectIdAsnWrite((ObjectIdPtr)cp->value.ptrvalue, aip, FEAT_ID_local))
5095                 goto erret;
5096         }
5097         else if (cp->choice == 4)      /* general */
5098         {
5099             if (! DbtagAsnWrite((DbtagPtr)cp->value.ptrvalue, aip, FEAT_ID_general))
5100                 goto erret;
5101         }
5102     }
5103     retval = TRUE;
5104 erret:
5105     AsnUnlinkType(orig);       /* unlink local tree */
5106     return retval;
5107 }
5108 
5109 /*****************************************************************************
5110 *
5111 *   SeqFeatIdAsnRead(aip, atp, cp)
5112 *       atp is the current type (if identifier of a parent struct)
5113 *            assumption is readIdent has occurred
5114 *       if atp == NULL, then assumes it stands alone and read ident
5115 *            has not occurred.
5116 *
5117 *****************************************************************************/
5118 NLM_EXTERN Boolean LIBCALL SeqFeatIdAsnRead (AsnIoPtr aip, AsnTypePtr orig, ChoicePtr cp)
5119 {
5120     DataVal av;
5121     AsnTypePtr atp;
5122     Boolean retval = FALSE;
5123 
5124     if (! loaded)
5125     {
5126         if (! SeqFeatAsnLoad())
5127             return retval;
5128     }
5129 
5130     if (aip == NULL)
5131         return retval;
5132 
5133     if (orig == NULL)           /* SeqFeatId ::= (self contained) */
5134         atp = AsnReadId(aip, amp, FEAT_ID);
5135     else
5136         atp = AsnLinkType(orig, FEAT_ID);    /* link in local tree */
5137     if (atp == NULL)
5138         return retval;
5139 
5140     if (AsnReadVal(aip, atp, &av) <= 0)    /* read CHOICE */
5141         goto erret;
5142     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
5143     if (atp == FEAT_ID_gibb)
5144     {
5145         cp->choice = 1;
5146         if (AsnReadVal(aip, atp, &av) <= 0)
5147             goto erret;
5148         cp->value.intvalue = av.intvalue;
5149     }
5150     else if (atp == FEAT_ID_giim)
5151     {
5152         cp->choice = 2;
5153         cp->value.ptrvalue = (Pointer)GiimAsnRead(aip, atp);
5154         if (cp->value.ptrvalue == NULL)
5155             goto erret;
5156     }
5157     else if (atp == FEAT_ID_local)
5158     {
5159         cp->choice = 3;
5160         cp->value.ptrvalue = (Pointer)ObjectIdAsnRead(aip, atp);
5161         if (cp->value.ptrvalue == NULL)
5162             goto erret;
5163     }
5164     else if (atp == FEAT_ID_general)
5165     {
5166         cp->choice = 4;
5167         cp->value.ptrvalue = (Pointer)DbtagAsnRead(aip, atp);
5168         if (cp->value.ptrvalue == NULL)
5169             goto erret;
5170     }
5171     retval = TRUE;
5172 erret:
5173     AsnUnlinkType(orig);       /* unlink local tree */
5174     return retval;
5175 }
5176 
5177 /*****************************************************************************
5178 *
5179 *   TxinitNew()
5180 *
5181 *****************************************************************************/
5182 NLM_EXTERN TxinitPtr LIBCALL TxinitNew (void)
5183 {
5184     TxinitPtr txp;
5185 
5186     txp = (TxinitPtr)MemNew(sizeof(Txinit));
5187     if (txp == NULL) return txp;
5188     txp->inittype = 255;
5189     return txp;
5190 }
5191 
5192 /*****************************************************************************
5193 *
5194 *   TxinitFree(txp)
5195 *       Frees a Txinit and associated data
5196 *
5197 *****************************************************************************/
5198 NLM_EXTERN TxinitPtr LIBCALL TxinitFree (TxinitPtr txp)
5199 {
5200     ValNodePtr anp, next;
5201     TxEvidencePtr txep, txnext;
5202 
5203     if (txp == NULL)
5204         return (TxinitPtr)NULL;
5205 
5206     MemFree(txp->name);
5207     ValNodeFreeData(txp->syn);
5208     anp = txp->gene;
5209     while (anp != NULL)
5210     {
5211         next = anp->next;
5212         GeneRefFree((GeneRefPtr)anp->data.ptrvalue);
5213         MemFree(anp);
5214         anp = next;
5215     }
5216     anp = txp->protein;
5217     while (anp != NULL)
5218     {
5219         next = anp->next;
5220         ProtRefFree((ProtRefPtr)anp->data.ptrvalue);
5221         MemFree(anp);
5222         anp = next;
5223     }
5224     ValNodeFreeData(txp->rna);
5225     MemFree(txp->expression);
5226     MemFree(txp->txdescr);
5227     OrgRefFree(txp->txorg);
5228     txep = txp->evidence;
5229     while (txep != NULL)
5230     {
5231         txnext = txep->next;
5232         MemFree(txep);
5233         txep = txnext;
5234     }
5235 
5236     return (TxinitPtr)MemFree(txp);
5237 }
5238 
5239 /*****************************************************************************
5240 *
5241 *   TxinitAsnWrite(txp, aip, atp)
5242 *       atp is the current type (if identifier of a parent struct)
5243 *       if atp == NULL, then assumes it stands alone (Txinit ::=)
5244 *
5245 *****************************************************************************/
5246 NLM_EXTERN Boolean LIBCALL TxinitAsnWrite (TxinitPtr txp, AsnIoPtr aip, AsnTypePtr orig)
5247 {
5248     DataVal av;
5249     AsnTypePtr atp;
5250     ValNodePtr anp;
5251     TxEvidencePtr txep;
5252     Boolean retval = FALSE;
5253 
5254     if (! loaded)
5255     {
5256         if (! SeqFeatAsnLoad())
5257             return FALSE;
5258     }
5259 
5260     if (aip == NULL)
5261         return FALSE;
5262 
5263     atp = AsnLinkType(orig, TXINIT);   /* link local tree */
5264     if (atp == NULL)
5265         return FALSE;
5266 
5267     if (txp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
5268 
5269     if (! AsnOpenStruct(aip, atp, (Pointer)txp))
5270         goto erret;
5271 
5272     av.ptrvalue = (Pointer)txp->name;
5273     if (! AsnWrite(aip, TXINIT_name, &av)) goto erret;
5274     if (txp->syn != NULL)
5275     {
5276         anp = txp->syn;
5277         if (! AsnOpenStruct(aip, TXINIT_syn, (Pointer)txp->syn))
5278             goto erret;
5279         while (anp != NULL)
5280         {
5281             av.ptrvalue = anp->data.ptrvalue;
5282             if (! AsnWrite(aip, TXINIT_syn_E, &av)) goto erret;
5283             anp = anp->next;
5284         }
5285         if (! AsnCloseStruct(aip, TXINIT_syn, (Pointer)txp->syn))
5286             goto erret;
5287     }
5288     if (txp->gene != NULL)
5289     {
5290         anp = txp->gene;
5291         if (! AsnOpenStruct(aip, TXINIT_gene, (Pointer)txp->gene))
5292             goto erret;
5293         while (anp != NULL)
5294         {
5295             if (! GeneRefAsnWrite((GeneRefPtr)anp->data.ptrvalue, aip, TXINIT_gene_E))
5296                 goto erret;
5297             anp = anp->next;
5298         }
5299         if (! AsnCloseStruct(aip, TXINIT_gene, (Pointer)txp->gene))
5300             goto erret;
5301     }
5302     if (txp->protein != NULL)
5303     {
5304         anp = txp->protein;
5305         if (! AsnOpenStruct(aip, TXINIT_protein, (Pointer)txp->protein))
5306             goto erret;
5307         while (anp != NULL)
5308         {
5309             if (! ProtRefAsnWrite((ProtRefPtr)anp->data.ptrvalue, aip, TXINIT_protein_E))
5310                 goto erret;
5311             anp = anp->next;
5312         }
5313         if (! AsnCloseStruct(aip, TXINIT_protein, (Pointer)txp->protein))
5314             goto erret;
5315     }
5316     if (txp->rna != NULL)
5317     {
5318         anp = txp->rna;
5319         if (! AsnOpenStruct(aip, TXINIT_rna, (Pointer)txp->rna))
5320             goto erret;
5321         while (anp != NULL)
5322         {
5323             av.ptrvalue = anp->data.ptrvalue;
5324             if (! AsnWrite(aip, TXINIT_rna_E, &av)) goto erret;
5325             anp = anp->next;
5326         }
5327         if (! AsnCloseStruct(aip, TXINIT_rna, (Pointer)txp->rna))
5328             goto erret;
5329     }
5330     if (txp->expression != NULL)
5331     {
5332         av.ptrvalue = (Pointer)txp->expression;
5333         if (! AsnWrite(aip, TXINIT_expression, &av)) goto erret;
5334     }
5335 
5336     av.intvalue = (Int4)txp->txsystem;
5337     if (! AsnWrite(aip, TXINIT_txsystem, &av)) goto erret;
5338 
5339     if (txp->txdescr != NULL)
5340     {
5341         av.ptrvalue = (Pointer)txp->txdescr;
5342         if (! AsnWrite(aip, TXINIT_txdescr, &av)) goto erret;
5343     }
5344 
5345     if (txp->txorg != NULL)
5346     {
5347         if (! OrgRefAsnWrite(txp->txorg, aip, TXINIT_txorg))
5348             goto erret;
5349     }
5350 
5351     if (txp->mapping_precise)
5352     {
5353         av.boolvalue = TRUE;
5354         if (! AsnWrite(aip, TXINIT_mapping_precise, &av)) goto erret;
5355     }
5356 
5357     if (txp->location_accurate)
5358     {
5359         av.boolvalue = TRUE;
5360         if (! AsnWrite(aip, TXINIT_location_accurate, &av)) goto erret;
5361     }
5362 
5363     if (txp->inittype != 255)
5364     {
5365         av.intvalue = (Int4) txp->inittype;
5366         if (! AsnWrite(aip, TXINIT_inittype, &av)) goto erret;
5367     }
5368 
5369     if (txp->evidence != NULL)
5370     {
5371         txep = txp->evidence;
5372         if (! AsnOpenStruct(aip, TXINIT_evidence, (Pointer)txp->evidence))
5373             goto erret;
5374         while (txep != NULL)
5375         {
5376             if (! AsnOpenStruct(aip, TXINIT_evidence_E, (Pointer)txep))
5377                 goto erret;
5378             av.intvalue = (Int4) txep->exp_code;
5379             if (! AsnWrite(aip, TX_EVIDENCE_exp_code, &av)) goto erret;
5380             if (txep->exp_sys != 1)
5381             {
5382                 av.intvalue = (Int4) txep->exp_sys;
5383                 if (! AsnWrite(aip, TX_EVIDENCE_expression_system, &av)) goto erret;
5384             }
5385             if (txep->low_prec_data)
5386             {
5387                 av.boolvalue = TRUE;
5388                 if (! AsnWrite(aip, TX_EVIDENCE_low_prec_data, &av)) goto erret;
5389             }
5390             if (txep->from_homolog)
5391             {
5392                 av.boolvalue = TRUE;
5393                 if (! AsnWrite(aip, TX_EVIDENCE_from_homolog, &av)) goto erret;
5394             }
5395             if (! AsnCloseStruct(aip, TXINIT_evidence_E, (Pointer)txep))
5396                 goto erret;
5397             txep = txep->next;
5398         }
5399         if (! AsnCloseStruct(aip, TXINIT_evidence, (Pointer)txp->evidence))
5400             goto erret;
5401     }
5402 
5403     if (! AsnCloseStruct(aip, atp, (Pointer)txp))
5404         goto erret;
5405     retval = TRUE;
5406 erret:
5407     AsnUnlinkType(orig);       /* unlink local tree */
5408     return retval;
5409 }
5410 
5411 /*****************************************************************************
5412 *
5413 *   TxinitAsnRead(aip, atp)
5414 *       atp is the current type (if identifier of a parent struct)
5415 *            assumption is readIdent has occurred
5416 *       if atp == NULL, then assumes it stands alone and read ident
5417 *            has not occurred.
5418 *
5419 *****************************************************************************/
5420 NLM_EXTERN TxinitPtr LIBCALL TxinitAsnRead (AsnIoPtr aip, AsnTypePtr orig)
5421 {
5422     DataVal av;
5423     AsnTypePtr atp, oldatp;
5424     TxinitPtr txp;
5425     ValNodePtr curr, last;
5426     TxEvidencePtr txep, txlast;
5427 
5428     if (! loaded)
5429     {
5430         if (! SeqFeatAsnLoad())
5431             return (TxinitPtr)NULL;
5432     }
5433 
5434     if (aip == NULL)
5435         return (TxinitPtr)NULL;
5436 
5437     if (orig == NULL)           /* Txinit ::= (self contained) */
5438         atp = AsnReadId(aip, amp, TXINIT);
5439     else
5440         atp = AsnLinkType(orig, TXINIT);    /* link in local tree */
5441     oldatp = atp;
5442     if (atp == NULL)
5443         return (TxinitPtr)NULL;
5444 
5445     txp = TxinitNew();
5446     if (txp == NULL)
5447         return txp;
5448 
5449     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
5450 
5451     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
5452     {
5453         if (atp == NULL)
5454             goto erret;
5455         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
5456         if (atp == TXINIT_name)
5457             txp->name = (CharPtr)av.ptrvalue;
5458         else if (atp == TXINIT_syn)
5459         {
5460             last = NULL;
5461             while ((atp = AsnReadId(aip, amp, atp)) == TXINIT_syn_E)
5462             {
5463                 curr = ValNodeNew(last);
5464                 if (curr == NULL)
5465                     goto erret;
5466                 if (AsnReadVal(aip, atp, &curr->data) <= 0) goto erret;
5467                 if (last == NULL)
5468                     txp->syn = curr;
5469                 last = curr;
5470             }
5471             if (atp == NULL)
5472                 goto erret;
5473             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
5474         }
5475         else if (atp == TXINIT_gene)
5476         {
5477             last = NULL;
5478             while ((atp = AsnReadId(aip, amp, atp)) == TXINIT_gene_E)
5479             {
5480                 curr = ValNodeNew(last);
5481                 if (curr == NULL)
5482                     goto erret;
5483                 curr->data.ptrvalue = (Pointer)GeneRefAsnRead(aip, atp);
5484                 if (curr->data.ptrvalue == NULL)
5485                     goto erret;
5486                 if (last == NULL)
5487                     txp->gene = curr;
5488                 last = curr;
5489             }
5490             if (atp == NULL)
5491                 goto erret;
5492             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
5493         }
5494         else if (atp == TXINIT_protein)
5495         {
5496             last = NULL;
5497             while ((atp = AsnReadId(aip, amp, atp)) == TXINIT_protein_E)
5498             {
5499                 curr = ValNodeNew(last);
5500                 if (curr == NULL)
5501                     goto erret;
5502                 curr->data.ptrvalue = (Pointer)ProtRefAsnRead(aip, atp);
5503                 if (curr->data.ptrvalue == NULL)
5504                     goto erret;
5505                 if (last == NULL)
5506                     txp->protein = curr;
5507                 last = curr;
5508             }
5509             if (atp == NULL)
5510                 goto erret;
5511             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
5512         }
5513         else if (atp == TXINIT_rna)
5514         {
5515             last = NULL;
5516             while ((atp = AsnReadId(aip, amp, atp)) == TXINIT_rna_E)
5517             {
5518                 curr = ValNodeNew(last);
5519                 if (curr == NULL)
5520                     goto erret;
5521                 if (AsnReadVal(aip, atp, &curr->data) <= 0) goto erret;
5522                 if (last == NULL)
5523                     txp->rna = curr;
5524                 last = curr;
5525             }
5526             if (atp == NULL)
5527                 goto erret;
5528             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
5529         }
5530         else if (atp == TXINIT_expression)
5531             txp->expression = (CharPtr)av.ptrvalue;
5532         else if (atp == TXINIT_txsystem)
5533             txp->txsystem = (Uint1)av.intvalue;
5534         else if (atp == TXINIT_txdescr)
5535             txp->txdescr = (CharPtr)av.ptrvalue;
5536         else if (atp == TXINIT_txorg)
5537         {
5538             txp->txorg = OrgRefAsnRead(aip, atp);
5539             if (txp->txorg == NULL)
5540                 goto erret;
5541         }
5542         else if (atp == TXINIT_mapping_precise)
5543             txp->mapping_precise = av.boolvalue;
5544         else if (atp == TXINIT_location_accurate)
5545             txp->location_accurate = av.boolvalue;
5546         else if (atp == TXINIT_inittype)
5547             txp->inittype = (Uint1)av.intvalue;
5548         else if (atp == TXINIT_evidence)
5549         {
5550             txlast = NULL;
5551             txep = NULL;
5552             while ((atp = AsnReadId(aip, amp, atp)) != TXINIT_evidence)
5553             {
5554                 if (atp == NULL)
5555                     goto erret;
5556                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
5557                 if ((atp == TXINIT_evidence_E) && (av.intvalue == START_STRUCT))
5558                 {
5559                     txep = (TxEvidencePtr)MemNew(sizeof(TxEvidence));
5560                     if (txep == NULL)
5561                         goto erret;
5562                     txep->exp_sys = 1;    /* default */
5563                     if (txlast != NULL)
5564                         txlast->next = txep;
5565                     else
5566                         txp->evidence = txep;
5567                     txlast = txep;
5568                 }
5569                 else if (atp == TX_EVIDENCE_exp_code)
5570                     txep->exp_code = (Uint1) av.intvalue;
5571                 else if (atp == TX_EVIDENCE_expression_system)
5572                     txep->exp_sys = (Uint1) av.intvalue;
5573                 else if (atp == TX_EVIDENCE_low_prec_data)
5574                     txep->low_prec_data = av.boolvalue;
5575                 else if (atp == TX_EVIDENCE_from_homolog)
5576                     txep->from_homolog = av.boolvalue;
5577             }
5578             if (atp == NULL)
5579                 goto erret;
5580             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
5581         }
5582     }
5583     if (atp == NULL)
5584         goto erret;
5585     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
5586 ret:
5587     AsnUnlinkType(orig);       /* unlink local tree */
5588     return txp;
5589 erret:
5590     txp = TxinitFree(txp);
5591     goto ret;
5592 }
5593 
5594 
5595 /*****************************************************************************
5596 *
5597 *   OrgModNew()
5598 *
5599 *****************************************************************************/
5600 NLM_EXTERN OrgModPtr LIBCALL OrgModNew (void)
5601 {
5602     return (OrgModPtr)MemNew(sizeof(OrgMod));
5603 }
5604 
5605 /*****************************************************************************
5606 *
5607 *   OrgModFree(omp)
5608 *       Frees an OrgMod and associated data
5609 *
5610 *****************************************************************************/
5611 NLM_EXTERN OrgModPtr LIBCALL OrgModFree (OrgModPtr omp)
5612 {
5613     if (omp == NULL)
5614         return (OrgModPtr)NULL;
5615 
5616     MemFree(omp->subname);
5617     MemFree(omp->attrib);
5618     return (OrgModPtr)MemFree(omp);
5619 }
5620 
5621 /*****************************************************************************
5622 *
5623 *   OrgModAsnWrite(omp, aip, atp)
5624 *       atp is the current type (if identifier of a parent struct)
5625 *       if atp == NULL, then assumes it stands alone (OrgMod ::=)
5626 *
5627 *****************************************************************************/
5628 NLM_EXTERN Boolean LIBCALL OrgModAsnWrite (OrgModPtr omp, AsnIoPtr aip, AsnTypePtr orig)
5629 {
5630     DataVal av;
5631     AsnTypePtr atp;
5632     Boolean retval = FALSE;
5633 
5634     if (! loaded)
5635     {
5636         if (! SeqFeatAsnLoad())
5637             return FALSE;
5638     }
5639 
5640     if (aip == NULL)
5641         return FALSE;
5642 
5643     atp = AsnLinkType(orig, ORGMOD);   /* link local tree */
5644     if (atp == NULL)
5645         return FALSE;
5646 
5647     if (omp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
5648 
5649     if (! AsnOpenStruct(aip, atp, (Pointer)omp))
5650         goto erret;
5651 
5652     av.intvalue = (Int4)(omp->subtype);
5653     if (AsnWrite(aip, ORGMOD_subtype, &av) <= 0) goto erret;
5654 
5655     if (omp->subname != NULL)
5656     {
5657         av.ptrvalue = omp->subname;
5658         if (! AsnWrite(aip, ORGMOD_subname, &av)) goto erret;
5659     }
5660 
5661     if (omp->attrib != NULL)
5662     {
5663         av.ptrvalue = omp->attrib;
5664         if (! AsnWrite(aip, ORGMOD_attrib, &av)) goto erret;
5665     }
5666 
5667     if (! AsnCloseStruct(aip, atp, (Pointer)omp))
5668         goto erret;
5669     retval = TRUE;
5670 erret:
5671     AsnUnlinkType(orig);       /* unlink local tree */
5672     return retval;
5673 }
5674 
5675 /*****************************************************************************
5676 *
5677 *   OrgModAsnRead(aip, atp)
5678 *       atp is the current type (if identifier of a parent struct)
5679 *            assumption is readIdent has occurred
5680 *       if atp == NULL, then assumes it stands alone and read ident
5681 *            has not occurred.
5682 *
5683 *****************************************************************************/
5684 NLM_EXTERN OrgModPtr LIBCALL OrgModAsnRead (AsnIoPtr aip, AsnTypePtr orig)
5685 {
5686     DataVal av;
5687     AsnTypePtr atp, oldatp;
5688     OrgModPtr omp;
5689 
5690     if (! loaded)
5691     {
5692         if (! SeqFeatAsnLoad())
5693             return (OrgModPtr)NULL;
5694     }
5695 
5696     if (aip == NULL)
5697         return (OrgModPtr)NULL;
5698 
5699     if (orig == NULL)           /* OrgMod ::= (self contained) */
5700         atp = AsnReadId(aip, amp, ORGMOD);
5701     else
5702         atp = AsnLinkType(orig, ORGMOD);    /* link in local tree */
5703     oldatp = atp;
5704     if (atp == NULL)
5705         return (OrgModPtr)NULL;
5706 
5707     omp = OrgModNew();
5708     if (omp == NULL)
5709         goto erret;
5710 
5711     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
5712 
5713     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
5714     {
5715         if (atp == NULL)
5716             goto erret;
5717         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
5718         if (atp == ORGMOD_subtype)
5719             omp->subtype = (Uint1)(av.intvalue);
5720         else if (atp == ORGMOD_subname)
5721             omp->subname = (CharPtr)(av.ptrvalue);
5722         else if (atp == ORGMOD_attrib)
5723             omp->attrib = (CharPtr)(av.ptrvalue);
5724     }
5725     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
5726 ret:
5727     AsnUnlinkType(orig);       /* unlink local tree */
5728     return omp;
5729 erret:
5730     omp = OrgModFree(omp);
5731     goto ret;
5732 }
5733 
5734 /*****************************************************************************
5735 *
5736 *   OrgModSetFree (omp)
5737 *
5738 *****************************************************************************/
5739 NLM_EXTERN OrgModPtr LIBCALL OrgModSetFree (OrgModPtr omp)
5740 {
5741     OrgModPtr next;
5742 
5743     while (omp != NULL)
5744     {
5745         next = omp->next;
5746         OrgModFree(omp);
5747         omp = next;
5748     }
5749     return omp;
5750 }
5751 
5752 /*****************************************************************************
5753 *
5754 *   OrgModSetAsnWrite(omp, aip, set, element)
5755 *
5756 *****************************************************************************/
5757 NLM_EXTERN Boolean LIBCALL OrgModSetAsnWrite (OrgModPtr omp, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
5758 {
5759     AsnTypePtr atp;
5760     OrgModPtr oldomp;
5761     Boolean retval = FALSE;
5762 
5763     if (! loaded)
5764     {
5765         if (! SeqFeatAsnLoad())
5766             return FALSE;
5767     }
5768 
5769     if (aip == NULL)
5770         return FALSE;
5771 
5772     atp = AsnLinkType(element, ORGMOD);   /* link local tree */
5773     if (atp == NULL)
5774         return FALSE;
5775     oldomp = omp;
5776 
5777     if (! AsnOpenStruct(aip, set, (Pointer)oldomp))
5778         goto erret;
5779 
5780     while (omp != NULL)
5781     {
5782         if (! OrgModAsnWrite(omp, aip, atp))
5783             goto erret;
5784         omp = omp->next;
5785     }
5786 
5787     if (! AsnCloseStruct(aip, set, (Pointer)oldomp))
5788         goto erret;
5789     retval = TRUE;
5790 erret:
5791     AsnUnlinkType(element);       /* unlink local tree */
5792     return retval;
5793 }
5794 
5795 /*****************************************************************************
5796 *
5797 *   OrgModSetAsnRead(aip, set, element)
5798 *
5799 *****************************************************************************/
5800 NLM_EXTERN OrgModPtr LIBCALL OrgModSetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
5801 {
5802     DataVal av;
5803     AsnTypePtr atp;
5804     OrgModPtr omp, curr = NULL, first = NULL;
5805 
5806     if (aip == NULL)
5807         return (OrgModPtr)NULL;
5808 
5809     AsnLinkType(element, ORGMOD);    /* link in local tree */
5810     atp = set;
5811 
5812     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
5813     while ((atp = AsnReadId(aip, amp, atp)) == element)
5814     {
5815         omp = OrgModAsnRead(aip, atp);
5816         if (omp == NULL)
5817             goto erret;
5818         if (first == NULL)
5819             first = omp;
5820         else
5821             curr->next = omp;
5822         curr = omp;
5823     }
5824     if (atp == NULL)
5825         goto erret;
5826     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
5827     if (first == NULL)
5828         ErrPostEx(SEV_WARNING, 0, 0, "Empty SET OF OrgMod. line %ld", (long) aip->linenumber);
5829 ret:
5830     AsnUnlinkType(element);       /* unlink local tree */
5831     return first;
5832 erret:
5833     first = OrgModSetFree(first);
5834     goto ret;
5835 }
5836 
5837 /*****************************************************************************
5838 *
5839 *   OrgModSetMatch (mod1, mod2)
5840 *
5841 *****************************************************************************/
5842 NLM_EXTERN Boolean LIBCALL OrgModSetMatch (OrgModPtr mod1, OrgModPtr mod2)
5843 {
5844   if (mod1 == NULL && mod2 == NULL)
5845   {
5846     return TRUE;
5847   }
5848   else if (mod1 == NULL || mod2 == NULL)
5849   {
5850     return FALSE;
5851   }
5852   else if (mod1->subtype != mod2->subtype
5853            || StringCmp (mod1->attrib, mod2->attrib) != 0
5854            || StringCmp (mod1->subname, mod2->subname) != 0)
5855   {
5856     return FALSE;
5857   }
5858   else
5859   {
5860     return OrgModSetMatch (mod1->next, mod2->next);
5861   }
5862 }
5863 
5864 /*****************************************************************************
5865 *
5866 *   TaxElementNew()
5867 *
5868 *****************************************************************************/
5869 NLM_EXTERN TaxElementPtr LIBCALL TaxElementNew (void)
5870 {
5871     return (TaxElementPtr)MemNew(sizeof(TaxElement));
5872 }
5873 
5874 /*****************************************************************************
5875 *
5876 *   TaxElementFree(tep)
5877 *       Frees an TaxElement and associated data
5878 *
5879 *****************************************************************************/
5880 NLM_EXTERN TaxElementPtr LIBCALL TaxElementFree (TaxElementPtr tep)
5881 {
5882     if (tep == NULL)
5883         return (TaxElementPtr)NULL;
5884 
5885     MemFree(tep->level);
5886     MemFree(tep->name);
5887     return (TaxElementPtr)MemFree(tep);
5888 }
5889 
5890 /*****************************************************************************
5891 *
5892 *   TaxElementAsnWrite(tep, aip, atp)
5893 *       atp is the current type (if identifier of a parent struct)
5894 *       if atp == NULL, then assumes it stands alone (TaxElement ::=)
5895 *
5896 *****************************************************************************/
5897 NLM_EXTERN Boolean LIBCALL TaxElementAsnWrite (TaxElementPtr tep, AsnIoPtr aip, AsnTypePtr orig)
5898 {
5899     DataVal av;
5900     AsnTypePtr atp;
5901     Boolean retval = FALSE;
5902 
5903     if (! loaded)
5904     {
5905         if (! SeqFeatAsnLoad())
5906             return FALSE;
5907     }
5908 
5909     if (aip == NULL)
5910         return FALSE;
5911 
5912     atp = AsnLinkType(orig, TAXELEMENT);   /* link local tree */
5913     if (atp == NULL)
5914         return FALSE;
5915 
5916     if (tep == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
5917 
5918     if (! AsnOpenStruct(aip, atp, (Pointer)tep))
5919         goto erret;
5920 
5921         av.intvalue = (Int4)(tep->fixed_level);
5922         if (AsnWrite(aip, TAXELEMENT_fixed_level, &av) <= 0) goto erret;
5923 
5924     if (tep->level != NULL)
5925     {
5926         av.ptrvalue = tep->level;
5927         if (! AsnWrite(aip, TAXELEMENT_level, &av)) goto erret;
5928     }
5929 
5930     if (tep->name != NULL)
5931     {
5932         av.ptrvalue = tep->name;
5933         if (! AsnWrite(aip, TAXELEMENT_name, &av)) goto erret;
5934     }
5935 
5936     if (! AsnCloseStruct(aip, atp, (Pointer)tep))
5937         goto erret;
5938     retval = TRUE;
5939 erret:
5940     AsnUnlinkType(orig);       /* unlink local tree */
5941     return retval;
5942 }
5943 
5944 /*****************************************************************************
5945 *
5946 *   TaxElementAsnRead(aip, atp)
5947 *       atp is the current type (if identifier of a parent struct)
5948 *            assumption is readIdent has occurred
5949 *       if atp == NULL, then assumes it stands alone and read ident
5950 *            has not occurred.
5951 *
5952 *****************************************************************************/
5953 NLM_EXTERN TaxElementPtr LIBCALL TaxElementAsnRead (AsnIoPtr aip, AsnTypePtr orig)
5954 {
5955     DataVal av;
5956     AsnTypePtr atp, oldatp;
5957     TaxElementPtr tep;
5958 
5959     if (! loaded)
5960     {
5961         if (! SeqFeatAsnLoad())
5962             return (TaxElementPtr)NULL;
5963     }
5964 
5965     if (aip == NULL)
5966         return (TaxElementPtr)NULL;
5967 
5968     if (orig == NULL)           /* TaxElement ::= (self contained) */
5969         atp = AsnReadId(aip, amp, TAXELEMENT);
5970     else
5971         atp = AsnLinkType(orig, TAXELEMENT);    /* link in local tree */
5972     oldatp = atp;
5973     if (atp == NULL)
5974         return (TaxElementPtr)NULL;
5975 
5976     tep = TaxElementNew();
5977     if (tep == NULL)
5978         goto erret;
5979 
5980     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
5981 
5982     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
5983     {
5984         if (atp == NULL)
5985             goto erret;
5986         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
5987         if (atp == TAXELEMENT_fixed_level)
5988             tep->fixed_level = (Uint1)(av.intvalue);
5989         else if (atp == TAXELEMENT_level)
5990             tep->level = (CharPtr)(av.ptrvalue);
5991         else if (atp == TAXELEMENT_name)
5992             tep->name = (CharPtr)(av.ptrvalue);
5993     }
5994     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
5995 ret:
5996     AsnUnlinkType(orig);       /* unlink local tree */
5997     return tep;
5998 erret:
5999     tep = TaxElementFree(tep);
6000     goto ret;
6001 }
6002 
6003 /*****************************************************************************
6004 *
6005 *   TaxElementSetFree (tep)
6006 *
6007 *****************************************************************************/
6008 NLM_EXTERN TaxElementPtr LIBCALL TaxElementSetFree (TaxElementPtr tep)
6009 {
6010     TaxElementPtr next;
6011 
6012     while (tep != NULL)
6013     {
6014         next = tep->next;
6015         TaxElementFree(tep);
6016         tep = next;
6017     }
6018     return tep;
6019 }
6020 
6021 /*****************************************************************************
6022 *
6023 *   TaxElementSetAsnWrite(tep, aip, set, element)
6024 *
6025 *****************************************************************************/
6026 NLM_EXTERN Boolean LIBCALL TaxElementSetAsnWrite (TaxElementPtr tep, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
6027 {
6028     AsnTypePtr atp;
6029     TaxElementPtr oldtep;
6030     Boolean retval = FALSE;
6031 
6032     if (! loaded)
6033     {
6034         if (! SeqFeatAsnLoad())
6035             return FALSE;
6036     }
6037 
6038     if (aip == NULL)
6039         return FALSE;
6040 
6041     atp = AsnLinkType(element, TAXELEMENT);   /* link local tree */
6042     if (atp == NULL)
6043         return FALSE;
6044     oldtep = tep;
6045 
6046     if (! AsnOpenStruct(aip, set, (Pointer)oldtep))
6047         goto erret;
6048 
6049     while (tep != NULL)
6050     {
6051         if (! TaxElementAsnWrite(tep, aip, atp))
6052             goto erret;
6053         tep = tep->next;
6054     }
6055 
6056     if (! AsnCloseStruct(aip, set, (Pointer)oldtep))
6057         goto erret;
6058     retval = TRUE;
6059 erret:
6060     AsnUnlinkType(element);       /* unlink local tree */
6061     return retval;
6062 }
6063 
6064 /*****************************************************************************
6065 *
6066 *   TaxElementSetAsnRead(aip, set, element)
6067 *
6068 *****************************************************************************/
6069 NLM_EXTERN TaxElementPtr LIBCALL TaxElementSetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
6070 {
6071     DataVal av;
6072     AsnTypePtr atp;
6073     TaxElementPtr tep, curr = NULL, first = NULL;
6074 
6075     if (aip == NULL)
6076         return (TaxElementPtr)NULL;
6077 
6078     AsnLinkType(element, TAXELEMENT);    /* link in local tree */
6079     atp = set;
6080 
6081     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
6082     while ((atp = AsnReadId(aip, amp, atp)) == element)
6083     {
6084         tep = TaxElementAsnRead(aip, atp);
6085         if (tep == NULL)
6086             goto erret;
6087         if (first == NULL)
6088             first = tep;
6089         else
6090             curr->next = tep;
6091         curr = tep;
6092     }
6093     if (atp == NULL)
6094         goto erret;
6095     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
6096     if (first == NULL)
6097         ErrPostEx(SEV_WARNING, 0, 0, "Empty SET OF TaxElement. line %ld", (long) aip->linenumber);
6098 ret:
6099     AsnUnlinkType(element);       /* unlink local tree */
6100     return first;
6101 erret:
6102     first = TaxElementSetFree(first);
6103     goto ret;
6104 }
6105 
6106 /*****************************************************************************
6107 *
6108 *   BinomialOrgNameNew()
6109 *
6110 *****************************************************************************/
6111 NLM_EXTERN BinomialOrgNamePtr LIBCALL BinomialOrgNameNew (void)
6112 {
6113     return (BinomialOrgNamePtr)MemNew(sizeof(BinomialOrgName));
6114 }
6115 
6116 /*****************************************************************************
6117 *
6118 *   BinomialOrgNameFree(bop)
6119 *       Frees an BinomialOrgName and associated data
6120 *
6121 *****************************************************************************/
6122 NLM_EXTERN BinomialOrgNamePtr LIBCALL BinomialOrgNameFree (BinomialOrgNamePtr bop)
6123 {
6124     if (bop == NULL)
6125         return (BinomialOrgNamePtr)NULL;
6126 
6127     MemFree(bop->genus);
6128     MemFree(bop->species);
6129     MemFree(bop->subspecies);
6130     return (BinomialOrgNamePtr)MemFree(bop);
6131 }
6132 
6133 /*****************************************************************************
6134 *
6135 *   BinomialOrgNameAsnWrite(bop, aip, atp)
6136 *       atp is the current type (if identifier of a parent struct)
6137 *       if atp == NULL, then assumes it stands alone (BinomialOrgName ::=)
6138 *
6139 *****************************************************************************/
6140 NLM_EXTERN Boolean LIBCALL BinomialOrgNameAsnWrite (BinomialOrgNamePtr bop, AsnIoPtr aip, AsnTypePtr orig)
6141 {
6142     DataVal av;
6143     AsnTypePtr atp;
6144     Boolean retval = FALSE;
6145 
6146     if (! loaded)
6147     {
6148         if (! SeqFeatAsnLoad())
6149             return FALSE;
6150     }
6151 
6152     if (aip == NULL)
6153         return FALSE;
6154 
6155     atp = AsnLinkType(orig, BINOMIALORGNAME);   /* link local tree */
6156     if (atp == NULL)
6157         return FALSE;
6158 
6159     if (bop == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
6160 
6161     if (! AsnOpenStruct(aip, atp, (Pointer)bop))
6162         goto erret;
6163 
6164     if (bop->genus != NULL)
6165     {
6166         av.ptrvalue = bop->genus;
6167         if (! AsnWrite(aip, BINOMIALORGNAME_genus, &av)) goto erret;
6168     }
6169 
6170     if (bop->species != NULL)
6171     {
6172         av.ptrvalue = bop->species;
6173         if (! AsnWrite(aip, BINOMIALORGNAME_species, &av)) goto erret;
6174     }
6175 
6176     if (bop->subspecies != NULL)
6177     {
6178         av.ptrvalue = bop->subspecies;
6179         if (! AsnWrite(aip, BINOMIALORGNAME_subspecies, &av)) goto erret;
6180     }
6181 
6182     if (! AsnCloseStruct(aip, atp, (Pointer)bop))
6183         goto erret;
6184     retval = TRUE;
6185 erret:
6186     AsnUnlinkType(orig);       /* unlink local tree */
6187     return retval;
6188 }
6189 
6190 /*****************************************************************************
6191 *
6192 *   BinomialOrgNameAsnRead(aip, atp)
6193 *       atp is the current type (if identifier of a parent struct)
6194 *            assumption is readIdent has occurred
6195 *       if atp == NULL, then assumes it stands alone and read ident
6196 *            has not occurred.
6197 *
6198 *****************************************************************************/
6199 NLM_EXTERN BinomialOrgNamePtr LIBCALL BinomialOrgNameAsnRead (AsnIoPtr aip, AsnTypePtr orig)
6200 {
6201     DataVal av;
6202     AsnTypePtr atp, oldatp;
6203     BinomialOrgNamePtr bop;
6204 
6205     if (! loaded)
6206     {
6207         if (! SeqFeatAsnLoad())
6208             return (BinomialOrgNamePtr)NULL;
6209     }
6210 
6211     if (aip == NULL)
6212         return (BinomialOrgNamePtr)NULL;
6213 
6214     if (orig == NULL)           /* BinomialOrgName ::= (self contained) */
6215         atp = AsnReadId(aip, amp, BINOMIALORGNAME);
6216     else
6217         atp = AsnLinkType(orig, BINOMIALORGNAME);    /* link in local tree */
6218     oldatp = atp;
6219     if (atp == NULL)
6220         return (BinomialOrgNamePtr)NULL;
6221 
6222     bop = BinomialOrgNameNew();
6223     if (bop == NULL)
6224         goto erret;
6225 
6226     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
6227 
6228     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
6229     {
6230         if (atp == NULL)
6231             goto erret;
6232         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
6233         if (atp == BINOMIALORGNAME_genus)
6234             bop->genus = (CharPtr)(av.ptrvalue);
6235         else if (atp == BINOMIALORGNAME_species)
6236             bop->species = (CharPtr)(av.ptrvalue);
6237         else if (atp == BINOMIALORGNAME_subspecies)
6238             bop->subspecies = (CharPtr)(av.ptrvalue);
6239     }
6240     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
6241 ret:
6242     AsnUnlinkType(orig);       /* unlink local tree */
6243     return bop;
6244 erret:
6245     bop = BinomialOrgNameFree(bop);
6246     goto ret;
6247 }
6248 
6249 
6250 /*****************************************************************************
6251 *
6252 *   BioSourceNew()
6253 *
6254 *****************************************************************************/
6255 NLM_EXTERN BioSourcePtr LIBCALL BioSourceNew (void)
6256 {
6257     return (BioSourcePtr)MemNew(sizeof(BioSource));
6258 }
6259 
6260 /*****************************************************************************
6261 *
6262 *   BioSourceFree(bsp)
6263 *       Frees an BioSource and associated data
6264 *
6265 *****************************************************************************/
6266 NLM_EXTERN BioSourcePtr LIBCALL BioSourceFree (BioSourcePtr bsp)
6267 {
6268     if (bsp == NULL)
6269         return (BioSourcePtr)NULL;
6270 
6271     OrgRefFree(bsp->org);
6272     SubSourceSetFree(bsp->subtype);
6273     PCRReactionSetFree(bsp->pcr_primers);
6274     return (BioSourcePtr)MemFree(bsp);
6275 }
6276 
6277 /*****************************************************************************
6278 *
6279 *   BioSourceAsnWrite(bsp, aip, atp)
6280 *       atp is the current type (if identifier of a parent struct)
6281 *       if atp == NULL, then assumes it stands alone (BioSource ::=)
6282 *
6283 *****************************************************************************/
6284 NLM_EXTERN Boolean LIBCALL BioSourceAsnWrite (BioSourcePtr bsp, AsnIoPtr aip, AsnTypePtr orig)
6285 {
6286     DataVal av;
6287     AsnTypePtr atp;
6288     Boolean retval = FALSE;
6289 
6290     if (! loaded)
6291     {
6292         if (! SeqFeatAsnLoad())
6293             return FALSE;
6294     }
6295 
6296     if (aip == NULL)
6297         return FALSE;
6298 
6299     atp = AsnLinkType(orig, BIOSOURCE);   /* link local tree */
6300     if (atp == NULL)
6301         return FALSE;
6302 
6303     if (bsp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
6304 
6305     if (! AsnOpenStruct(aip, atp, (Pointer)bsp))
6306         goto erret;
6307 
6308     if (bsp->genome)
6309     {
6310         if ((bsp->genome < 14) || (aip->spec_version == 0 || aip->spec_version > 4))
6311         {
6312             av.intvalue = (Int4)bsp->genome;
6313             if (! AsnWrite(aip, BIOSOURCE_genome, &av)) goto erret;
6314         }
6315     }
6316 
6317     if (bsp->origin)
6318     {
6319         av.intvalue = (Int4)bsp->origin;
6320         if (! AsnWrite(aip, BIOSOURCE_origin, &av)) goto erret;
6321     }
6322 
6323     if (bsp->org != NULL)
6324     {
6325         if (! OrgRefAsnWrite(bsp->org, aip, BIOSOURCE_org))
6326             goto erret;
6327     }
6328 
6329     if (bsp->subtype != NULL)
6330     {
6331         if (! SubSourceSetAsnWrite(bsp->subtype, aip, BIOSOURCE_subtype, BIOSOURCE_subtype_E))
6332             goto erret;
6333     }
6334 
6335     if ((bsp->is_focus) && ((aip->spec_version == 0) || (aip->spec_version >= 6)))
6336     {
6337         av.ptrvalue = NULL;
6338         if (! AsnWrite(aip, BIOSOURCE_is_focus, &av))
6339             goto erret;
6340     }
6341 
6342     if (bsp->pcr_primers != NULL) {
6343         if (! PCRReactionSetAsnWrite(bsp->pcr_primers, aip, BIOSOURCE_pcr_primers)) {
6344             goto erret;
6345         }
6346     }
6347 
6348     if (! AsnCloseStruct(aip, atp, (Pointer)bsp))
6349         goto erret;
6350     retval = TRUE;
6351 erret:
6352     AsnUnlinkType(orig);       /* unlink local tree */
6353     return retval;
6354 }
6355 
6356 /*****************************************************************************
6357 *
6358 *   BioSourceAsnRead(aip, atp)
6359 *       atp is the current type (if identifier of a parent struct)
6360 *            assumption is readIdent has occurred
6361 *       if atp == NULL, then assumes it stands alone and read ident
6362 *            has not occurred.
6363 *
6364 *****************************************************************************/
6365 NLM_EXTERN BioSourcePtr LIBCALL BioSourceAsnRead (AsnIoPtr aip, AsnTypePtr orig)
6366 {
6367     DataVal av;
6368     AsnTypePtr atp, oldatp;
6369     BioSourcePtr bsp;
6370 
6371     if (! loaded)
6372     {
6373         if (! SeqFeatAsnLoad())
6374             return (BioSourcePtr)NULL;
6375     }
6376 
6377     if (aip == NULL)
6378         return (BioSourcePtr)NULL;
6379 
6380     if (orig == NULL)           /* BioSource ::= (self contained) */
6381         atp = AsnReadId(aip, amp, BIOSOURCE);
6382     else
6383         atp = AsnLinkType(orig, BIOSOURCE);    /* link in local tree */
6384     oldatp = atp;
6385     if (atp == NULL)
6386         return (BioSourcePtr)NULL;
6387 
6388     bsp = BioSourceNew();
6389     if (bsp == NULL)
6390         goto erret;
6391 
6392     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
6393 
6394     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
6395     {
6396         if (atp == NULL)
6397             goto erret;
6398         if (atp == BIOSOURCE_org)
6399         {
6400             bsp->org = OrgRefAsnRead(aip, atp);
6401             if (bsp->org == NULL) goto erret;
6402         }
6403         else if (atp == BIOSOURCE_subtype)
6404         {
6405             bsp->subtype = SubSourceSetAsnRead(aip, atp, BIOSOURCE_subtype_E);
6406             if (bsp->subtype == NULL) goto erret;
6407         }
6408         else if (atp == BIOSOURCE_pcr_primers)
6409         {
6410             bsp->pcr_primers = PCRReactionSetAsnRead(aip, atp);
6411             if (bsp->pcr_primers == NULL) goto erret;
6412         }
6413         else
6414         {
6415             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
6416             if (atp == BIOSOURCE_genome)
6417                 bsp->genome = (Uint1)(av.intvalue);
6418             else if (atp == BIOSOURCE_origin)
6419                 bsp->origin = (Uint1)(av.intvalue);
6420             else if (atp == BIOSOURCE_is_focus)
6421                 bsp->is_focus = TRUE;
6422         }
6423     }
6424     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
6425 ret:
6426     AsnUnlinkType(orig);       /* unlink local tree */
6427     return bsp;
6428 erret:
6429     bsp = BioSourceFree(bsp);
6430     goto ret;
6431 }
6432 
6433 /*****************************************************************************
6434 *
6435 *   BioSourceMatch(biop1, biop2)
6436 *
6437 *****************************************************************************/
6438 NLM_EXTERN Boolean LIBCALL BioSourceMatch (BioSourcePtr biop1, BioSourcePtr biop2)
6439 {
6440   if (biop1 == NULL && biop2 == NULL)
6441   {
6442     return TRUE;
6443   }
6444   else if (biop1 == NULL || biop2 == NULL)
6445   {
6446     return FALSE;
6447   }
6448   else if (biop1->origin != biop2->origin
6449            || biop1->is_focus != biop2->is_focus
6450            || ! OrgRefMatch (biop1->org, biop2->org)
6451            || ! SubSourceSetMatch (biop1->subtype, biop2->subtype))
6452   {
6453     return FALSE;
6454   }
6455   else if (biop1->genome == biop2->genome
6456            || (biop1->genome == 0 && biop2->genome == 1)
6457            || (biop1->genome == 1 && biop2->genome == 0))
6458   {
6459     return TRUE;
6460   }
6461   else
6462   {
6463     return FALSE;
6464   }
6465 }
6466 
6467 /*****************************************************************************
6468 *
6469 *   SubSourceNew()
6470 *
6471 *****************************************************************************/
6472 NLM_EXTERN SubSourcePtr LIBCALL SubSourceNew (void)
6473 {
6474     return (SubSourcePtr)MemNew(sizeof(SubSource));
6475 }
6476 
6477 /*****************************************************************************
6478 *
6479 *   SubSourceFree(ssp)
6480 *       Frees an SubSource and associated data
6481 *
6482 *****************************************************************************/
6483 NLM_EXTERN SubSourcePtr LIBCALL SubSourceFree (SubSourcePtr ssp)
6484 {
6485     if (ssp == NULL)
6486         return (SubSourcePtr)NULL;
6487 
6488     MemFree(ssp->name);
6489     MemFree(ssp->attrib);
6490     return (SubSourcePtr)MemFree(ssp);
6491 }
6492 
6493 /*****************************************************************************
6494 *
6495 *   SubSourceAsnWrite(ssp, aip, atp)
6496 *       atp is the current type (if identifier of a parent struct)
6497 *       if atp == NULL, then assumes it stands alone (SubSource ::=)
6498 *
6499 *****************************************************************************/
6500 NLM_EXTERN Boolean LIBCALL SubSourceAsnWrite (SubSourcePtr ssp, AsnIoPtr aip, AsnTypePtr orig)
6501 {
6502     DataVal av;
6503     AsnTypePtr atp;
6504     Boolean retval = FALSE;
6505 
6506     if (! loaded)
6507     {
6508         if (! SeqFeatAsnLoad())
6509             return FALSE;
6510     }
6511 
6512     if (aip == NULL)
6513         return FALSE;
6514 
6515     atp = AsnLinkType(orig, SUBSOURCE);   /* link local tree */
6516     if (atp == NULL)
6517         return FALSE;
6518 
6519     if (ssp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
6520 
6521     if (! AsnOpenStruct(aip, atp, (Pointer)ssp))
6522         goto erret;
6523 
6524     av.intvalue = (Int4)(ssp->subtype);
6525     if (AsnWrite(aip, SUBSOURCE_subtype, &av) <= 0) goto erret;
6526 
6527     if (ssp->name != NULL)
6528     {
6529         av.ptrvalue = ssp->name;
6530         if (! AsnWrite(aip, SUBSOURCE_name, &av)) goto erret;
6531     }
6532 
6533     if (ssp->attrib != NULL)
6534     {
6535         av.ptrvalue = ssp->attrib;
6536         if (! AsnWrite(aip, SUBSOURCE_attrib, &av)) goto erret;
6537     }
6538 
6539     if (! AsnCloseStruct(aip, atp, (Pointer)ssp))
6540         goto erret;
6541     retval = TRUE;
6542 erret:
6543     AsnUnlinkType(orig);       /* unlink local tree */
6544     return retval;
6545 }
6546 
6547 /*****************************************************************************
6548 *
6549 *   SubSourceAsnRead(aip, atp)
6550 *       atp is the current type (if identifier of a parent struct)
6551 *            assumption is readIdent has occurred
6552 *       if atp == NULL, then assumes it stands alone and read ident
6553 *            has not occurred.
6554 *
6555 *****************************************************************************/
6556 NLM_EXTERN SubSourcePtr LIBCALL SubSourceAsnRead (AsnIoPtr aip, AsnTypePtr orig)
6557 {
6558     DataVal av;
6559     AsnTypePtr atp, oldatp;
6560     SubSourcePtr ssp;
6561 
6562     if (! loaded)
6563     {
6564         if (! SeqFeatAsnLoad())
6565             return (SubSourcePtr)NULL;
6566     }
6567 
6568     if (aip == NULL)
6569         return (SubSourcePtr)NULL;
6570 
6571     if (orig == NULL)           /* SubSource ::= (self contained) */
6572         atp = AsnReadId(aip, amp, SUBSOURCE);
6573     else
6574         atp = AsnLinkType(orig, SUBSOURCE);    /* link in local tree */
6575     oldatp = atp;
6576     if (atp == NULL)
6577         return (SubSourcePtr)NULL;
6578 
6579     ssp = SubSourceNew();
6580     if (ssp == NULL)
6581         goto erret;
6582 
6583     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
6584 
6585     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
6586     {
6587         if (atp == NULL)
6588             goto erret;
6589         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
6590         if (atp == SUBSOURCE_subtype)
6591             ssp->subtype = (Uint1)(av.intvalue);
6592         else if (atp == SUBSOURCE_name)
6593             ssp->name = (CharPtr)(av.ptrvalue);
6594         else if (atp == SUBSOURCE_attrib)
6595             ssp->attrib = (CharPtr)(av.ptrvalue);
6596     }
6597     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
6598 ret:
6599     AsnUnlinkType(orig);       /* unlink local tree */
6600     return ssp;
6601 erret:
6602     ssp = SubSourceFree(ssp);
6603     goto ret;
6604 }
6605 
6606 /*****************************************************************************
6607 *
6608 *   SubSourceSetFree (ssp)
6609 *
6610 *****************************************************************************/
6611 NLM_EXTERN SubSourcePtr LIBCALL SubSourceSetFree (SubSourcePtr ssp)
6612 {
6613     SubSourcePtr next;
6614 
6615     while (ssp != NULL)
6616     {
6617         next = ssp->next;
6618         SubSourceFree(ssp);
6619         ssp = next;
6620     }
6621     return ssp;
6622 }
6623 
6624 /*****************************************************************************
6625 *
6626 *   SubSourceSetAsnWrite(ssp, aip, set, element)
6627 *
6628 *****************************************************************************/
6629 NLM_EXTERN Boolean LIBCALL SubSourceSetAsnWrite (SubSourcePtr ssp, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
6630 {
6631     AsnTypePtr atp;
6632     SubSourcePtr oldssp;
6633     Boolean retval = FALSE;
6634 
6635     if (! loaded)
6636     {
6637         if (! SeqFeatAsnLoad())
6638             return FALSE;
6639     }
6640 
6641     if (aip == NULL)
6642         return FALSE;
6643 
6644     atp = AsnLinkType(element, SUBSOURCE);   /* link local tree */
6645     if (atp == NULL)
6646         return FALSE;
6647     oldssp = ssp;
6648 
6649     if (! AsnOpenStruct(aip, set, (Pointer)oldssp))
6650         goto erret;
6651 
6652     while (ssp != NULL)
6653     {
6654         if (! SubSourceAsnWrite(ssp, aip, atp))
6655             goto erret;
6656         ssp = ssp->next;
6657     }
6658 
6659     if (! AsnCloseStruct(aip, set, (Pointer)oldssp))
6660         goto erret;
6661     retval = TRUE;
6662 erret:
6663     AsnUnlinkType(element);       /* unlink local tree */
6664     return retval;
6665 }
6666 
6667 /*****************************************************************************
6668 *
6669 *   SubSourceSetAsnRead(aip, set, element)
6670 *
6671 *****************************************************************************/
6672 NLM_EXTERN SubSourcePtr LIBCALL SubSourceSetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
6673 {
6674     DataVal av;
6675     AsnTypePtr atp;
6676     SubSourcePtr ssp, curr = NULL, first = NULL;
6677 
6678     if (aip == NULL)
6679         return (SubSourcePtr)NULL;
6680 
6681     AsnLinkType(element, SUBSOURCE);    /* link in local tree */
6682     atp = set;
6683 
6684     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the start struct */
6685     while ((atp = AsnReadId(aip, amp, atp)) == element)
6686     {
6687         ssp = SubSourceAsnRead(aip, atp);
6688         if (ssp == NULL)
6689             goto erret;
6690         if (first == NULL)
6691             first = ssp;
6692         else
6693             curr->next = ssp;
6694         curr = ssp;
6695     }
6696     if (atp == NULL)
6697         goto erret;
6698     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct */
6699     if (first == NULL)
6700         ErrPostEx(SEV_WARNING, 0, 0, "Empty SET OF SubSource. line %ld", (long) aip->linenumber);
6701 ret:
6702     AsnUnlinkType(element);       /* unlink local tree */
6703     return first;
6704 erret:
6705     first = SubSourceSetFree(first);
6706     goto ret;
6707 }
6708 
6709 /*****************************************************************************
6710 *
6711 *   SubSourceSetMatch(ssp1, ssp2)
6712 *
6713 *****************************************************************************/
6714 NLM_EXTERN Boolean LIBCALL SubSourceSetMatch (SubSourcePtr ssp1, SubSourcePtr ssp2)
6715 {
6716   while (ssp1 != NULL && ssp2 != NULL)
6717   {
6718     if (ssp1->subtype != ssp2->subtype)
6719     {
6720       return FALSE;
6721     }
6722     else if (StringCmp (ssp1->name, ssp2->name) != 0)
6723     {
6724       return FALSE;
6725     }
6726     else if (StringCmp (ssp1->attrib, ssp2->attrib) != 0)
6727     {
6728       return FALSE;
6729     }
6730     
6731     ssp1 = ssp1->next;
6732     ssp2 = ssp2->next;
6733   }
6734  
6735   if (ssp1 == NULL && ssp2 == NULL)
6736   {
6737     return TRUE;
6738   }
6739   else
6740   {
6741     return FALSE;
6742   }
6743 }
6744 
6745 /**************************************************
6746 *
6747 *    PCRPrimerNew()
6748 *
6749 **************************************************/
6750 NLM_EXTERN 
6751 PCRPrimerPtr LIBCALL
6752 PCRPrimerNew(void)
6753 {
6754    PCRPrimerPtr ptr = MemNew((size_t) sizeof(PCRPrimer));
6755 
6756    return ptr;
6757 
6758 }
6759 
6760 /**************************************************
6761 *
6762 *    PCRPrimerFree()
6763 *
6764 **************************************************/
6765 NLM_EXTERN 
6766 PCRPrimerPtr LIBCALL
6767 PCRPrimerFree(PCRPrimerPtr ptr)
6768 {
6769 
6770    if(ptr == NULL) {
6771       return NULL;
6772    }
6773    MemFree(ptr -> seq);
6774    MemFree(ptr -> name);
6775    return MemFree(ptr);
6776 }
6777 
6778 /**************************************************
6779 *
6780 *    PCRPrimerAsnRead()
6781 *
6782 **************************************************/
6783 NLM_EXTERN 
6784 PCRPrimerPtr LIBCALL
6785 PCRPrimerAsnRead(AsnIoPtr aip, AsnTypePtr orig)
6786 {
6787    DataVal av;
6788    AsnTypePtr atp;
6789    AsnReadFunc func;
6790    PCRPrimerPtr ptr;
6791 
6792     if (! loaded)
6793     {
6794         if (! SeqFeatAsnLoad())
6795             return (PCRPrimerPtr)NULL;
6796     }
6797 
6798    if (aip == NULL) {
6799       return NULL;
6800    }
6801 
6802    if (orig == NULL) {         /* PCRPrimer ::= (self contained) */
6803       atp = AsnReadId(aip, amp, PCRPRIMER);
6804    } else {
6805       atp = AsnLinkType(orig, PCRPRIMER);
6806    }
6807    /* link in local tree */
6808    if (atp == NULL) {
6809       return NULL;
6810    }
6811 
6812    ptr = PCRPrimerNew();
6813    if (ptr == NULL) {
6814       goto erret;
6815    }
6816    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
6817       goto erret;
6818    }
6819 
6820    atp = AsnReadId(aip,amp, atp);
6821    func = NULL;
6822 
6823    if (atp == PCRPRIMER_seq) {
6824       if ( AsnReadVal(aip, atp, &av) <= 0) {
6825          goto erret;
6826       }
6827       ptr -> seq = av.ptrvalue;
6828       atp = AsnReadId(aip,amp, atp);
6829    }
6830    if (atp == PCRPRIMER_name) {
6831       if ( AsnReadVal(aip, atp, &av) <= 0) {
6832          goto erret;
6833       }
6834       ptr -> name = av.ptrvalue;
6835       atp = AsnReadId(aip,amp, atp);
6836    }
6837 
6838    if (AsnReadVal(aip, atp, &av) <= 0) {
6839       goto erret;
6840    }
6841    /* end struct */
6842 
6843 ret:
6844    AsnUnlinkType(orig);       /* unlink local tree */
6845    return ptr;
6846 
6847 erret:
6848    aip -> io_failure = TRUE;
6849    ptr = PCRPrimerFree(ptr);
6850    goto ret;
6851 }
6852 
6853 /**************************************************
6854 *
6855 *    PCRPrimerAsnWrite()
6856 *
6857 **************************************************/
6858 NLM_EXTERN Boolean LIBCALL 
6859 PCRPrimerAsnWrite(PCRPrimerPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
6860 {
6861    DataVal av;
6862    AsnTypePtr atp;
6863    Boolean retval = FALSE;
6864 
6865     if (! loaded)
6866     {
6867         if (! SeqFeatAsnLoad())
6868             return FALSE;
6869     }
6870 
6871    if (aip == NULL) {
6872       return FALSE;
6873    }
6874 
6875    atp = AsnLinkType(orig, PCRPRIMER);   /* link local tree */
6876    if (atp == NULL) {
6877       return FALSE;
6878    }
6879 
6880    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
6881    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
6882       goto erret;
6883    }
6884 
6885    if (ptr -> seq != NULL) {
6886       av.ptrvalue = ptr -> seq;
6887       retval = AsnWrite(aip, PCRPRIMER_seq,  &av);
6888    }
6889    if (ptr -> name != NULL) {
6890       av.ptrvalue = ptr -> name;
6891       retval = AsnWrite(aip, PCRPRIMER_name,  &av);
6892    }
6893    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
6894       goto erret;
6895    }
6896    retval = TRUE;
6897 
6898 erret:
6899    AsnUnlinkType(orig);       /* unlink local tree */
6900    return retval;
6901 }
6902 
6903 /**************************************************
6904 *
6905 *    PCRPrimerSetFree()
6906 *
6907 **************************************************/
6908 NLM_EXTERN 
6909 PCRPrimerSetPtr LIBCALL
6910 PCRPrimerSetFree(PCRPrimerSetPtr ptr)
6911 {
6912 
6913    if(ptr == NULL) {
6914       return NULL;
6915    }
6916    AsnGenericUserSeqOfFree(ptr,  (AsnOptFreeFunc) PCRPrimerFree);
6917    return NULL;
6918 }
6919 
6920 /**************************************************
6921 *
6922 *    PCRPrimerSetAsnRead()
6923 *
6924 **************************************************/
6925 NLM_EXTERN 
6926 PCRPrimerSetPtr LIBCALL
6927 PCRPrimerSetAsnRead(AsnIoPtr aip, AsnTypePtr orig)
6928 {
6929    AsnTypePtr atp;
6930    Boolean isError = FALSE;
6931    AsnReadFunc func;
6932    PCRPrimerSetPtr ptr;
6933 
6934     if (! loaded)
6935     {
6936         if (! SeqFeatAsnLoad())
6937             return (PCRPrimerSetPtr)NULL;
6938     }
6939 
6940    if (aip == NULL) {
6941       return NULL;
6942    }
6943 
6944    if (orig == NULL) {         /* PCRPrimerSet ::= (self contained) */
6945       atp = AsnReadId(aip, amp, PCRPRIMERSET);
6946    } else {
6947       atp = AsnLinkType(orig, PCRPRIMERSET);
6948    }
6949    /* link in local tree */
6950    if (atp == NULL) {
6951       return NULL;
6952    }
6953 
6954    func = NULL;
6955 
6956    ptr  = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) PCRPrimerAsnRead, (AsnOptFreeFunc) PCRPrimerFree);
6957    if (isError && ptr  == NULL) {
6958       goto erret;
6959    }
6960 
6961 
6962 
6963 ret:
6964    AsnUnlinkType(orig);       /* unlink local tree */
6965    return ptr;
6966 
6967 erret:
6968    aip -> io_failure = TRUE;
6969    ptr = PCRPrimerSetFree(ptr);
6970    goto ret;
6971 }
6972 
6973 /**************************************************
6974 *
6975 *    PCRPrimerSetAsnWrite()
6976 *
6977 **************************************************/
6978 NLM_EXTERN Boolean LIBCALL 
6979 PCRPrimerSetAsnWrite(PCRPrimerSetPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
6980 {
6981    AsnTypePtr atp;
6982    Boolean retval = FALSE;
6983 
6984     if (! loaded)
6985     {
6986         if (! SeqFeatAsnLoad())
6987             return FALSE;
6988     }
6989 
6990    if (aip == NULL) {
6991       return FALSE;
6992    }
6993 
6994    atp = AsnLinkType(orig, PCRPRIMERSET);   /* link local tree */
6995    if (atp == NULL) {
6996       return FALSE;
6997    }
6998 
6999    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
7000    retval = AsnGenericUserSeqOfAsnWrite(ptr , (AsnWriteFunc) PCRPrimerAsnWrite, aip, atp, PCRPRIMERSET_E);
7001    retval = TRUE;
7002 
7003 erret:
7004    AsnUnlinkType(orig);       /* unlink local tree */
7005    return retval;
7006 }
7007 
7008 /**************************************************
7009 *
7010 *    PCRReactionNew()
7011 *
7012 **************************************************/
7013 NLM_EXTERN 
7014 PCRReactionPtr LIBCALL
7015 PCRReactionNew(void)
7016 {
7017    PCRReactionPtr ptr = MemNew((size_t) sizeof(PCRReaction));
7018 
7019    return ptr;
7020 
7021 }
7022 
7023 /**************************************************
7024 *
7025 *    PCRReactionFree()
7026 *
7027 **************************************************/
7028 NLM_EXTERN 
7029 PCRReactionPtr LIBCALL
7030 PCRReactionFree(PCRReactionPtr ptr)
7031 {
7032 
7033    if(ptr == NULL) {
7034       return NULL;
7035    }
7036    PCRPrimerSetFree(ptr -> forward);
7037    PCRPrimerSetFree(ptr -> reverse);
7038    return MemFree(ptr);
7039 }
7040 
7041 /**************************************************
7042 *
7043 *    PCRReactionAsnRead()
7044 *
7045 **************************************************/
7046 NLM_EXTERN 
7047 PCRReactionPtr LIBCALL
7048 PCRReactionAsnRead(AsnIoPtr aip, AsnTypePtr orig)
7049 {
7050    DataVal av;
7051    AsnTypePtr atp;
7052    AsnReadFunc func;
7053    PCRReactionPtr ptr;
7054 
7055     if (! loaded)
7056     {
7057         if (! SeqFeatAsnLoad())
7058             return (PCRReactionPtr)NULL;
7059     }
7060 
7061    if (aip == NULL) {
7062       return NULL;
7063    }
7064 
7065    if (orig == NULL) {         /* PCRReaction ::= (self contained) */
7066       atp = AsnReadId(aip, amp, PCRREACTION);
7067    } else {
7068       atp = AsnLinkType(orig, PCRREACTION);
7069    }
7070    /* link in local tree */
7071    if (atp == NULL) {
7072       return NULL;
7073    }
7074 
7075    ptr = PCRReactionNew();
7076    if (ptr == NULL) {
7077       goto erret;
7078    }
7079    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
7080       goto erret;
7081    }
7082 
7083    atp = AsnReadId(aip,amp, atp);
7084    func = NULL;
7085 
7086    if (atp == PCRREACTION_forward) {
7087       ptr -> forward = PCRPrimerSetAsnRead(aip, atp);
7088       if (aip -> io_failure) {
7089          goto erret;
7090       }
7091       atp = AsnReadId(aip,amp, atp);
7092    }
7093    if (atp == PCRREACTION_reverse) {
7094       ptr -> reverse = PCRPrimerSetAsnRead(aip, atp);
7095       if (aip -> io_failure) {
7096          goto erret;
7097       }
7098       atp = AsnReadId(aip,amp, atp);
7099    }
7100 
7101    if (AsnReadVal(aip, atp, &av) <= 0) {
7102       goto erret;
7103    }
7104    /* end struct */
7105 
7106 ret:
7107    AsnUnlinkType(orig);       /* unlink local tree */
7108    return ptr;
7109 
7110 erret:
7111    aip -> io_failure = TRUE;
7112    ptr = PCRReactionFree(ptr);
7113    goto ret;
7114 }
7115 
7116 /**************************************************
7117 *
7118 *    PCRReactionAsnWrite()
7119 *
7120 **************************************************/
7121 NLM_EXTERN Boolean LIBCALL 
7122 PCRReactionAsnWrite(PCRReactionPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
7123 {
7124    AsnTypePtr atp;
7125    Boolean retval = FALSE;
7126 
7127     if (! loaded)
7128     {
7129         if (! SeqFeatAsnLoad())
7130             return FALSE;
7131     }
7132 
7133    if (aip == NULL) {
7134       return FALSE;
7135    }
7136 
7137    atp = AsnLinkType(orig, PCRREACTION);   /* link local tree */
7138    if (atp == NULL) {
7139       return FALSE;
7140    }
7141 
7142    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
7143    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
7144       goto erret;
7145    }
7146 
7147    if (ptr -> forward != NULL) {
7148       if ( ! PCRPrimerSetAsnWrite(ptr -> forward, aip, PCRREACTION_forward)) {
7149          goto erret;
7150       }
7151    }
7152    if (ptr -> reverse != NULL) {
7153       if ( ! PCRPrimerSetAsnWrite(ptr -> reverse, aip, PCRREACTION_reverse)) {
7154          goto erret;
7155       }
7156    }
7157    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
7158       goto erret;
7159    }
7160    retval = TRUE;
7161 
7162 erret:
7163    AsnUnlinkType(orig);       /* unlink local tree */
7164    return retval;
7165 }
7166 
7167 /**************************************************
7168 *
7169 *    PCRReactionSetFree()
7170 *
7171 **************************************************/
7172 NLM_EXTERN 
7173 PCRReactionSetPtr LIBCALL
7174 PCRReactionSetFree(PCRReactionSetPtr ptr)
7175 {
7176 
7177    if(ptr == NULL) {
7178       return NULL;
7179    }
7180    AsnGenericUserSeqOfFree(ptr,  (AsnOptFreeFunc) PCRReactionFree);
7181    return NULL;
7182 }
7183 
7184 /**************************************************
7185 *
7186 *    PCRReactionSetAsnRead()
7187 *
7188 **************************************************/
7189 NLM_EXTERN 
7190 PCRReactionSetPtr LIBCALL
7191 PCRReactionSetAsnRead(AsnIoPtr aip, AsnTypePtr orig)
7192 {
7193    AsnTypePtr atp;
7194    Boolean isError = FALSE;
7195    AsnReadFunc func;
7196    PCRReactionSetPtr ptr;
7197 
7198     if (! loaded)
7199     {
7200         if (! SeqFeatAsnLoad())
7201             return (PCRReactionSetPtr)NULL;
7202     }
7203 
7204    if (aip == NULL) {
7205       return NULL;
7206    }
7207 
7208    if (orig == NULL) {         /* PCRReactionSet ::= (self contained) */
7209       atp = AsnReadId(aip, amp, PCRREACTIONSET);
7210    } else {
7211       atp = AsnLinkType(orig, PCRREACTIONSET);
7212    }
7213    /* link in local tree */
7214    if (atp == NULL) {
7215       return NULL;
7216    }
7217 
7218    func = NULL;
7219 
7220    ptr  = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) PCRReactionAsnRead, (AsnOptFreeFunc) PCRReactionFree);
7221    if (isError && ptr  == NULL) {
7222       goto erret;
7223    }
7224 
7225 
7226 
7227 ret:
7228    AsnUnlinkType(orig);       /* unlink local tree */
7229    return ptr;
7230 
7231 erret:
7232    aip -> io_failure = TRUE;
7233    ptr = PCRReactionSetFree(ptr);
7234    goto ret;
7235 }
7236 
7237 /**************************************************
7238 *
7239 *    PCRReactionSetAsnWrite()
7240 *
7241 **************************************************/
7242 NLM_EXTERN Boolean LIBCALL 
7243 PCRReactionSetAsnWrite(PCRReactionSetPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
7244 {
7245    AsnTypePtr atp;
7246    Boolean retval = FALSE;
7247 
7248     if (! loaded)
7249     {
7250         if (! SeqFeatAsnLoad())
7251             return FALSE;
7252     }
7253 
7254    if (aip == NULL) {
7255       return FALSE;
7256    }
7257 
7258    atp = AsnLinkType(orig, PCRREACTIONSET);   /* link local tree */
7259    if (atp == NULL) {
7260       return FALSE;
7261    }
7262 
7263    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
7264    retval = AsnGenericUserSeqOfAsnWrite(ptr , (AsnWriteFunc) PCRReactionAsnWrite, aip, atp, PCRREACTIONSET_E);
7265    retval = TRUE;
7266 
7267 erret:
7268    AsnUnlinkType(orig);       /* unlink local tree */
7269    return retval;
7270 }
7271 
7272 
7273 /**************************************************
7274 *
7275 *    CloneRefNew()
7276 *
7277 **************************************************/
7278 NLM_EXTERN 
7279 CloneRefPtr LIBCALL
7280 CloneRefNew(void)
7281 {
7282    CloneRefPtr ptr = MemNew((size_t) sizeof(CloneRef));
7283 
7284    ptr -> concordant = 0;
7285    ptr -> unique = 0;
7286    return ptr;
7287 
7288 }
7289 
7290 
7291 /**************************************************
7292 *
7293 *    CloneRefFree()
7294 *
7295 **************************************************/
7296 NLM_EXTERN 
7297 CloneRefPtr LIBCALL
7298 CloneRefFree(CloneRefPtr ptr)
7299 {
7300 
7301    if(ptr == NULL) {
7302       return NULL;
7303    }
7304    MemFree(ptr -> name);
7305    MemFree(ptr -> library);
7306    CloneSeqSetFree(ptr -> clone_seq);
7307    return MemFree(ptr);
7308 }
7309 
7310 
7311 /**************************************************
7312 *
7313 *    CloneRefAsnRead()
7314 *
7315 **************************************************/
7316 NLM_EXTERN 
7317 CloneRefPtr LIBCALL
7318 CloneRefAsnRead(AsnIoPtr aip, AsnTypePtr orig)
7319 {
7320    DataVal av;
7321    AsnTypePtr atp;
7322    AsnReadFunc func;
7323    CloneRefPtr ptr;
7324 
7325    if (! loaded)
7326    {
7327       if (! SeqFeatAsnLoad()) {
7328          return NULL;
7329       }
7330    }
7331 
7332    if (aip == NULL) {
7333       return NULL;
7334    }
7335 
7336    if (orig == NULL) {         /* CloneRef ::= (self contained) */
7337       atp = AsnReadId(aip, amp, CLONE_REF);
7338    } else {
7339       atp = AsnLinkType(orig, CLONE_REF);
7340    }
7341    /* link in local tree */
7342    if (atp == NULL) {
7343       return NULL;
7344    }
7345 
7346    ptr = CloneRefNew();
7347    if (ptr == NULL) {
7348       goto erret;
7349    }
7350    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
7351       goto erret;
7352    }
7353 
7354    atp = AsnReadId(aip,amp, atp);
7355    func = NULL;
7356 
7357    if (atp == CLONE_REF_name) {
7358       if ( AsnReadVal(aip, atp, &av) <= 0) {
7359          goto erret;
7360       }
7361       ptr -> name = av.ptrvalue;
7362       atp = AsnReadId(aip,amp, atp);
7363    }
7364    if (atp == CLONE_REF_library) {
7365       if ( AsnReadVal(aip, atp, &av) <= 0) {
7366          goto erret;
7367       }
7368       ptr -> library = av.ptrvalue;
7369       atp = AsnReadId(aip,amp, atp);
7370    }
7371    if (atp == CLONE_REF_concordant) {
7372       if ( AsnReadVal(aip, atp, &av) <= 0) {
7373          goto erret;
7374       }
7375       ptr -> concordant = av.boolvalue;
7376       atp = AsnReadId(aip,amp, atp);
7377    }
7378    if (atp == CLONE_REF_unique) {
7379       if ( AsnReadVal(aip, atp, &av) <= 0) {
7380          goto erret;
7381       }
7382       ptr -> unique = av.boolvalue;
7383       atp = AsnReadId(aip,amp, atp);
7384    }
7385    if (atp == CLONE_REF_placement_method) {
7386       if ( AsnReadVal(aip, atp, &av) <= 0) {
7387          goto erret;
7388       }
7389       ptr -> placement_method = av.intvalue;
7390       ptr -> OBbits__ |= 1<<0;
7391       atp = AsnReadId(aip,amp, atp);
7392    }
7393    if (atp == CLONE_REF_clone_seq) {
7394       ptr -> clone_seq = CloneSeqSetAsnRead(aip, atp);
7395       if (aip -> io_failure) {
7396          goto erret;
7397       }
7398       atp = AsnReadId(aip,amp, atp);
7399    }
7400 
7401    if (AsnReadVal(aip, atp, &av) <= 0) {
7402       goto erret;
7403    }
7404    /* end struct */
7405 
7406 ret:
7407    AsnUnlinkType(orig);       /* unlink local tree */
7408    return ptr;
7409 
7410 erret:
7411    aip -> io_failure = TRUE;
7412    ptr = CloneRefFree(ptr);
7413    goto ret;
7414 }
7415 
7416 
7417 
7418 /**************************************************
7419 *
7420 *    CloneRefAsnWrite()
7421 *
7422 **************************************************/
7423 NLM_EXTERN Boolean LIBCALL 
7424 CloneRefAsnWrite(CloneRefPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
7425 {
7426    DataVal av;
7427    AsnTypePtr atp;
7428    Boolean retval = FALSE;
7429 
7430    if (! loaded)
7431    {
7432       if (! SeqFeatAsnLoad()) {
7433          return FALSE;
7434       }
7435    }
7436 
7437    if (aip == NULL) {
7438       return FALSE;
7439    }
7440 
7441    atp = AsnLinkType(orig, CLONE_REF);   /* link local tree */
7442    if (atp == NULL) {
7443       return FALSE;
7444    }
7445 
7446    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
7447    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
7448       goto erret;
7449    }
7450 
7451    if (ptr -> name != NULL) {
7452       av.ptrvalue = ptr -> name;
7453       retval = AsnWrite(aip, CLONE_REF_name,  &av);
7454    }
7455    if (ptr -> library != NULL) {
7456       av.ptrvalue = ptr -> library;
7457       retval = AsnWrite(aip, CLONE_REF_library,  &av);
7458    }
7459    av.boolvalue = ptr -> concordant;
7460    retval = AsnWrite(aip, CLONE_REF_concordant,  &av);
7461    av.boolvalue = ptr -> unique;
7462    retval = AsnWrite(aip, CLONE_REF_unique,  &av);
7463    if (ptr -> placement_method || (ptr -> OBbits__ & (1<<0) )){   av.intvalue = ptr -> placement_method;
7464       retval = AsnWrite(aip, CLONE_REF_placement_method,  &av);
7465    }
7466    if (ptr -> clone_seq != NULL) {
7467       if ( ! CloneSeqSetAsnWrite(ptr -> clone_seq, aip, CLONE_REF_clone_seq)) {
7468          goto erret;
7469       }
7470    }
7471    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
7472       goto erret;
7473    }
7474    retval = TRUE;
7475 
7476 erret:
7477    AsnUnlinkType(orig);       /* unlink local tree */
7478    return retval;
7479 }
7480 
7481 
7482 
7483 /**************************************************
7484 *
7485 *    CloneSeqSetFree()
7486 *
7487 **************************************************/
7488 NLM_EXTERN 
7489 CloneSeqSetPtr LIBCALL
7490 CloneSeqSetFree(CloneSeqSetPtr ptr)
7491 {
7492 
7493    if(ptr == NULL) {
7494       return NULL;
7495    }
7496    AsnGenericUserSeqOfFree(ptr,  (AsnOptFreeFunc) CloneSeqFree);
7497    return NULL;
7498 }
7499 
7500 
7501 /**************************************************
7502 *
7503 *    CloneSeqSetAsnRead()
7504 *
7505 **************************************************/
7506 NLM_EXTERN 
7507 CloneSeqSetPtr LIBCALL
7508 CloneSeqSetAsnRead(AsnIoPtr aip, AsnTypePtr orig)
7509 {
7510    AsnTypePtr atp;
7511    Boolean isError = FALSE;
7512    AsnReadFunc func;
7513    CloneSeqSetPtr ptr;
7514 
7515    if (! loaded)
7516    {
7517       if (! SeqFeatAsnLoad()) {
7518          return NULL;
7519       }
7520    }
7521 
7522    if (aip == NULL) {
7523       return NULL;
7524    }
7525 
7526    if (orig == NULL) {         /* CloneSeqSet ::= (self contained) */
7527       atp = AsnReadId(aip, amp, CLONE_SEQ_SET);
7528    } else {
7529       atp = AsnLinkType(orig, CLONE_SEQ_SET);
7530    }
7531    /* link in local tree */
7532    if (atp == NULL) {
7533       return NULL;
7534    }
7535 
7536    func = NULL;
7537 
7538    ptr  = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) CloneSeqAsnRead, (AsnOptFreeFunc) CloneSeqFree);
7539    if (isError && ptr  == NULL) {
7540       goto erret;
7541    }
7542 
7543 
7544 
7545 ret:
7546    AsnUnlinkType(orig);       /* unlink local tree */
7547    return ptr;
7548 
7549 erret:
7550    aip -> io_failure = TRUE;
7551    ptr = CloneSeqSetFree(ptr);
7552    goto ret;
7553 }
7554 
7555 
7556 
7557 /**************************************************
7558 *
7559 *    CloneSeqSetAsnWrite()
7560 *
7561 **************************************************/
7562 NLM_EXTERN Boolean LIBCALL 
7563 CloneSeqSetAsnWrite(CloneSeqSetPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
7564 {
7565    AsnTypePtr atp;
7566    Boolean retval = FALSE;
7567 
7568    if (! loaded)
7569    {
7570       if (! SeqFeatAsnLoad()) {
7571          return FALSE;
7572       }
7573    }
7574 
7575    if (aip == NULL) {
7576       return FALSE;
7577    }
7578 
7579    atp = AsnLinkType(orig, CLONE_SEQ_SET);   /* link local tree */
7580    if (atp == NULL) {
7581       return FALSE;
7582    }
7583 
7584    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
7585    retval = AsnGenericUserSeqOfAsnWrite(ptr , (AsnWriteFunc) CloneSeqAsnWrite, aip, atp, CLONE_SEQ_SET_E);
7586    retval = TRUE;
7587 
7588 erret:
7589    AsnUnlinkType(orig);       /* unlink local tree */
7590    return retval;
7591 }
7592 
7593 
7594 
7595 /**************************************************
7596 *
7597 *    CloneSeqNew()
7598 *
7599 **************************************************/
7600 NLM_EXTERN 
7601 CloneSeqPtr LIBCALL
7602 CloneSeqNew(void)
7603 {
7604    CloneSeqPtr ptr = MemNew((size_t) sizeof(CloneSeq));
7605 
7606    return ptr;
7607 
7608 }
7609 
7610 
7611 /**************************************************
7612 *
7613 *    CloneSeqFree()
7614 *
7615 **************************************************/
7616 NLM_EXTERN 
7617 CloneSeqPtr LIBCALL
7618 CloneSeqFree(CloneSeqPtr ptr)
7619 {
7620 
7621    if(ptr == NULL) {
7622       return NULL;
7623    }
7624    SeqLocFree(ptr -> location);
7625    SeqLocFree(ptr -> seq);
7626    DbtagFree(ptr -> align_id);
7627    return MemFree(ptr);
7628 }
7629 
7630 
7631 /**************************************************
7632 *
7633 *    CloneSeqAsnRead()
7634 *
7635 **************************************************/
7636 NLM_EXTERN 
7637 CloneSeqPtr LIBCALL
7638 CloneSeqAsnRead(AsnIoPtr aip, AsnTypePtr orig)
7639 {
7640    DataVal av;
7641    AsnTypePtr atp;
7642    AsnReadFunc func;
7643    CloneSeqPtr ptr;
7644 
7645    if (! loaded)
7646    {
7647       if (! SeqFeatAsnLoad()) {
7648          return NULL;
7649       }
7650    }
7651 
7652    if (aip == NULL) {
7653       return NULL;
7654    }
7655 
7656    if (orig == NULL) {         /* CloneSeq ::= (self contained) */
7657       atp = AsnReadId(aip, amp, CLONE_SEQ);
7658    } else {
7659       atp = AsnLinkType(orig, CLONE_SEQ);
7660    }
7661    /* link in local tree */
7662    if (atp == NULL) {
7663       return NULL;
7664    }
7665 
7666    ptr = CloneSeqNew();
7667    if (ptr == NULL) {
7668       goto erret;
7669    }
7670    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
7671       goto erret;
7672    }
7673 
7674    atp = AsnReadId(aip,amp, atp);
7675    func = NULL;
7676 
7677    if (atp == CLONE_SEQ_type) {
7678       if ( AsnReadVal(aip, atp, &av) <= 0) {
7679          goto erret;
7680       }
7681       ptr -> type = av.intvalue;
7682       atp = AsnReadId(aip,amp, atp);
7683    }
7684    if (atp == CLONE_SEQ_confidence) {
7685       if ( AsnReadVal(aip, atp, &av) <= 0) {
7686          goto erret;
7687       }
7688       ptr -> confidence = av.intvalue;
7689       ptr -> OBbits__ |= 1<<0;
7690       atp = AsnReadId(aip,amp, atp);
7691    }
7692    if (atp == CLONE_SEQ_location) {
7693       ptr -> location = SeqLocAsnRead(aip, atp);
7694       if (aip -> io_failure) {
7695          goto erret;
7696       }
7697       atp = AsnReadId(aip,amp, atp);
7698    }
7699    if (atp == CLONE_SEQ_seq) {
7700       ptr -> seq = SeqLocAsnRead(aip, atp);
7701       if (aip -> io_failure) {
7702          goto erret;
7703       }
7704       atp = AsnReadId(aip,amp, atp);
7705    }
7706    if (atp == CLONE_SEQ_align_id) {
7707       ptr -> align_id = DbtagAsnRead(aip, atp);
7708       if (aip -> io_failure) {
7709          goto erret;
7710       }
7711       atp = AsnReadId(aip,amp, atp);
7712    }
7713 
7714    if (AsnReadVal(aip, atp, &av) <= 0) {
7715       goto erret;
7716    }
7717    /* end struct */
7718 
7719 ret:
7720    AsnUnlinkType(orig);       /* unlink local tree */
7721    return ptr;
7722 
7723 erret:
7724    aip -> io_failure = TRUE;
7725    ptr = CloneSeqFree(ptr);
7726    goto ret;
7727 }
7728 
7729 
7730 
7731 /**************************************************
7732 *
7733 *    CloneSeqAsnWrite()
7734 *
7735 **************************************************/
7736 NLM_EXTERN Boolean LIBCALL 
7737 CloneSeqAsnWrite(CloneSeqPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
7738 {
7739    DataVal av;
7740    AsnTypePtr atp;
7741    Boolean retval = FALSE;
7742 
7743    if (! loaded)
7744    {
7745       if (! SeqFeatAsnLoad()) {
7746          return FALSE;
7747       }
7748    }
7749 
7750    if (aip == NULL) {
7751       return FALSE;
7752    }
7753 
7754    atp = AsnLinkType(orig, CLONE_SEQ);   /* link local tree */
7755    if (atp == NULL) {
7756       return FALSE;
7757    }
7758 
7759    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
7760    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
7761       goto erret;
7762    }
7763 
7764    av.intvalue = ptr -> type;
7765    retval = AsnWrite(aip, CLONE_SEQ_type,  &av);
7766    if (ptr -> confidence || (ptr -> OBbits__ & (1<<0) )){   av.intvalue = ptr -> confidence;
7767       retval = AsnWrite(aip, CLONE_SEQ_confidence,  &av);
7768    }
7769    if (ptr -> location != NULL) {
7770       if ( ! SeqLocAsnWrite(ptr -> location, aip, CLONE_SEQ_location)) {
7771          goto erret;
7772       }
7773    }
7774    if (ptr -> seq != NULL) {
7775       if ( ! SeqLocAsnWrite(ptr -> seq, aip, CLONE_SEQ_seq)) {
7776          goto erret;
7777       }
7778    }
7779    if (ptr -> align_id != NULL) {
7780       if ( ! DbtagAsnWrite(ptr -> align_id, aip, CLONE_SEQ_align_id)) {
7781          goto erret;
7782       }
7783    }
7784    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
7785       goto erret;
7786    }
7787    retval = TRUE;
7788 
7789 erret:
7790    AsnUnlinkType(orig);       /* unlink local tree */
7791    return retval;
7792 }
7793 
7794 

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.