NCBI C Toolkit Cross Reference

C/object/objloc.c


  1 /*  objloc.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 loclic 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:  objloc.c
 27 *
 28 * Author:  James Ostell
 29 *   
 30 * Version Creation Date: 4/1/91
 31 *
 32 * $Revision: 6.12 $
 33 *
 34 * File Description:  Object manager for module NCBI-Seqloc
 35 *
 36 * Modifications:  
 37 * --------------------------------------------------------------------------
 38 * Date     Name        Description of modification
 39 * -------  ----------  -----------------------------------------------------
 40 *
 41 * ==========================================================================
 42 */
 43 #include <objloc.h>                /* the loc interface */
 44 #include <asnloc.h>        /* the AsnTool header */
 45 #include <objmgr.h>
 46 #include <sequtil.h>       /* for label routines */
 47 
 48 /*****************************************************************************
 49 *
 50 *   SeqLoc ObjMgr Routines
 51 *
 52 *****************************************************************************/
 53 static CharPtr seqlocname = "SeqLoc";
 54 
 55 static Pointer LIBCALLBACK SeqLocNewFunc (void)
 56 {
 57         return (Pointer) ValNodeNew(NULL);
 58 }
 59 
 60 static Pointer LIBCALLBACK SeqLocFreeFunc (Pointer data)
 61 {
 62         return (Pointer) SeqLocFree ((SeqLocPtr) data);
 63 }
 64 
 65 static Boolean LIBCALLBACK SeqLocAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
 66 {
 67         return SeqLocAsnWrite((SeqLocPtr)data, aip, atp);
 68 }
 69 
 70 static Pointer LIBCALLBACK SeqLocAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
 71 {
 72         return (Pointer) SeqLocAsnRead (aip, atp);
 73 }
 74 
 75 static Int2 LIBCALLBACK SeqLocLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
 76 {
 77         return SeqLocLabel((SeqLocPtr)data, buffer, buflen, content);
 78 }
 79 
 80 NLM_EXTERN Int2 LIBCALL SeqLocLabel (SeqLocPtr slp, CharPtr buffer, Int2 buflen, Uint1 content)
 81 {
 82         CharPtr label;
 83         Int2 diff, len;
 84 
 85         len = buflen;
 86         switch (content)
 87         {
 88                 case OM_LABEL_BOTH:
 89                         diff = LabelCopyExtra(buffer, seqlocname, buflen, NULL, ": ");
 90                         buflen -= diff;
 91                 case OM_LABEL_CONTENT:
 92                 case OM_LABEL_SUMMARY:
 93                         label = SeqLocPrint(slp);
 94                         diff = LabelCopy(buffer, label, buflen);
 95                         buflen -= diff;
 96                         MemFree(label);
 97                         return len - buflen;
 98                 case OM_LABEL_TYPE:
 99                 default:
100                         return LabelCopy(buffer, seqlocname, buflen);
101         }
102 }
103 
104 static Uint2 LIBCALLBACK SeqLocSubTypeFunc (Pointer ptr)
105 {
106         if (ptr == NULL)
107                 return 0;
108         return (Uint2)((SeqLocPtr)ptr)->choice;
109 }
110 
111 /*****************************************************************************
112 *
113 *   SeqId ObjMgr Routines
114 *
115 *****************************************************************************/
116 static CharPtr seqidname = "SeqID";
117 
118 static Pointer LIBCALLBACK SeqIdNewFunc (void)
119 {
120         return (Pointer) ValNodeNew(NULL);
121 }
122 
123 static Pointer LIBCALLBACK SeqIdFreeFunc (Pointer data)
124 {
125         return (Pointer) SeqIdFree ((SeqIdPtr) data);
126 }
127 
128 static Boolean LIBCALLBACK SeqIdAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
129 {
130         return SeqIdAsnWrite((SeqIdPtr)data, aip, atp);
131 }
132 
133 static Pointer LIBCALLBACK SeqIdAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
134 {
135         return (Pointer) SeqIdAsnRead (aip, atp);
136 }
137 
138 static Int2 LIBCALLBACK SeqIdLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
139 {
140         return SeqIdLabel ((SeqIdPtr)data, buffer, buflen, content);
141 }
142 
143 NLM_EXTERN Int2 LIBCALL SeqIdLabel ( SeqIdPtr sip, CharPtr buffer, Int2 buflen, Uint1 content)
144 {
145         Char label[40];
146         Int2 diff, len;
147         Int2 rsult = 0;
148 
149         if ((sip == NULL) || (buflen < 1))
150                 return 0;
151 
152         len = buflen;
153         switch (content)
154         {
155                 case OM_LABEL_BOTH:
156                         diff = LabelCopyExtra(buffer, seqidname, buflen, NULL, ": ");
157                         buflen -= diff;
158                 case OM_LABEL_CONTENT:
159                 case OM_LABEL_SUMMARY:
160                         label[0] = '\0';
161                         SeqIdWrite(sip, label, PRINTID_FASTA_SHORT, 39);
162                         diff = LabelCopy(buffer, label, buflen);
163                         buflen -= diff;
164                         return len - buflen;
165                 case OM_LABEL_TYPE:
166                 default:
167                         rsult = LabelCopy(buffer, seqidname, buflen);
168         }
169         return rsult;
170 }
171 
172 static Uint2 LIBCALLBACK SeqIdSubTypeFunc (Pointer ptr)
173 {
174         if (ptr == NULL)
175                 return 0;
176         return (Uint2)((SeqIdPtr)ptr)->choice;
177 }
178 
179 
180 static Boolean loaded = FALSE;
181 
182 /*****************************************************************************
183 *
184 *   Seqloc Routines
185 *
186 *****************************************************************************/
187 
188 /*****************************************************************************
189 *
190 *   Seqloc loader
191 *
192 *****************************************************************************/
193 NLM_EXTERN Boolean LIBCALL SeqLocAsnLoad (void)
194 {
195     if (loaded)
196         return TRUE;
197     loaded = TRUE;
198 
199     if (! GeneralAsnLoad())
200     {
201         loaded = FALSE;
202         return FALSE;
203     }
204     if (! BiblioAsnLoad())
205     {
206         loaded = FALSE;
207         return FALSE;
208     }
209     if (! SeqFeatAsnLoad())
210     {
211         loaded = FALSE;
212         return FALSE;
213     }
214     if (! AsnLoad())
215     {
216         loaded = FALSE;
217         return FALSE;
218     }
219 
220         ObjMgrTypeLoad(OBJ_SEQLOC, "Seq-loc", seqlocname, "Sequence Location",
221                 SEQ_LOC, SeqLocNewFunc, SeqLocAsnReadFunc, SeqLocAsnWriteFunc,
222                 SeqLocFreeFunc, SeqLocLabelFunc, SeqLocSubTypeFunc);
223 
224         ObjMgrTypeLoad(OBJ_SEQID, "Seq-align", seqidname, "Sequence ID",
225                 SEQ_ID, SeqIdNewFunc, SeqIdAsnReadFunc, SeqIdAsnWriteFunc,
226                 SeqIdFreeFunc, SeqIdLabelFunc, SeqIdSubTypeFunc);
227 
228     return TRUE;
229 }
230 
231 /*****************************************************************************
232 *
233 *   SeqIdFree(anp)
234 *       Frees one SeqId and associated data
235 *
236 *****************************************************************************/
237 NLM_EXTERN SeqIdPtr LIBCALL SeqIdFree (SeqIdPtr anp)
238 {
239     Pointer pnt;
240 
241     if (anp == NULL)
242         return anp;
243     
244     pnt = anp->data.ptrvalue;
245     switch (anp->choice)
246     {
247         case SEQID_LOCAL:      /* local */
248             ObjectIdFree((ObjectIdPtr)pnt);
249             break;
250         case SEQID_GIBBSQ:      /* gibbseq */
251         case SEQID_GIBBMT:      /* gibbmt */
252             break;
253         case SEQID_GIIM:      /* giimid */
254             GiimFree((GiimPtr)pnt);
255             break;
256         case SEQID_GENBANK:      /* genbank */
257         case SEQID_EMBL:      /* embl */
258         case SEQID_PIR:      /* pir   */
259         case SEQID_SWISSPROT:      /* swissprot */
260         case SEQID_OTHER:     /* other */
261         case SEQID_DDBJ:
262                 case SEQID_PRF:
263         case SEQID_TPG:
264             case SEQID_TPE:
265             case SEQID_TPD:
266         case SEQID_GPIPE:
267         case SEQID_NAMED_ANNOT_TRACK:
268             TextSeqIdFree((TextSeqIdPtr)pnt);
269             break;
270         case SEQID_PATENT:      /* patent seq id */
271             PatentSeqIdFree((PatentSeqIdPtr)pnt);
272             break;
273         case SEQID_GENERAL:     /* general */
274             DbtagFree((DbtagPtr)pnt);
275             break;
276         case SEQID_GI:     /* gi */
277             break;
278                 case SEQID_PDB:
279                         PDBSeqIdFree((PDBSeqIdPtr)pnt);
280                         break;
281     }
282 
283         ObjMgrDelete(OBJ_SEQID, (Pointer)anp);
284 
285         return (SeqIdPtr)MemFree(anp);
286 }
287 
288 /*****************************************************************************
289 *
290 *   SeqIdAsnWrite(anp, aip, atp)
291 *       atp is the current type (if identifier of a parent struct)
292 *       if atp == NULL, then assumes it stands alone (SeqId ::=)
293 *
294 *****************************************************************************/
295 NLM_EXTERN Boolean LIBCALL SeqIdAsnWrite (SeqIdPtr anp, AsnIoPtr aip, AsnTypePtr orig)
296 {
297         DataVal av;
298         AsnTypePtr atp, writetype = NULL;
299     Pointer pnt;
300     AsnWriteFunc func = NULL;
301     Boolean retval = FALSE;
302 
303         if (! loaded)
304         {
305                 if (! SeqLocAsnLoad())
306                         return retval;
307         }
308 
309         if (aip == NULL)
310                 return retval;
311 
312         atp = AsnLinkType(orig, SEQ_ID);   /* link local tree */
313     if (atp == NULL)
314         return retval;
315 
316         if (anp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
317 
318         av.ptrvalue = (Pointer)anp;
319     if (! AsnWriteChoice(aip, atp, (Int2)anp->choice, &av))
320         goto erret;
321 
322     pnt = anp->data.ptrvalue;
323     av.intvalue = anp->data.intvalue;
324     switch (anp->choice)
325     {
326         case SEQID_LOCAL:      /* local */
327             writetype = SEQ_ID_local;
328             func = (AsnWriteFunc) ObjectIdAsnWrite;
329             break;
330         case SEQID_GIBBSQ:      /* gibbseq */
331             retval = AsnWrite(aip, SEQ_ID_gibbsq, &av);
332             break;
333         case SEQID_GIBBMT:      /* gibbmt */
334             retval = AsnWrite(aip, SEQ_ID_gibbmt, &av);
335             break;
336         case SEQID_GIIM:      /* giimid */
337             writetype = SEQ_ID_giim;
338             func = (AsnWriteFunc) GiimAsnWrite;
339             break;
340         case SEQID_GENBANK:      /* genbank */
341             writetype = SEQ_ID_genbank;
342             func = (AsnWriteFunc) TextSeqIdAsnWrite;
343             break;
344         case SEQID_EMBL:      /* embl */
345             writetype = SEQ_ID_embl;
346             func = (AsnWriteFunc) TextSeqIdAsnWrite;
347             break;
348         case SEQID_PIR:      /* pir   */
349             writetype = SEQ_ID_pir;
350             func = (AsnWriteFunc) TextSeqIdAsnWrite;
351             break;
352         case SEQID_SWISSPROT:      /* swissprot */
353             writetype = SEQ_ID_swissprot;
354             func = (AsnWriteFunc) TextSeqIdAsnWrite;
355             break;
356         case SEQID_OTHER:     /* other */
357             writetype = SEQ_ID_other;
358             func = (AsnWriteFunc) TextSeqIdAsnWrite;
359             break;
360         case SEQID_PATENT:      /* patent seq id */
361             writetype = SEQ_ID_patent;
362             func = (AsnWriteFunc) PatentSeqIdAsnWrite;
363             break;
364         case SEQID_GENERAL:     /* general */
365             writetype = SEQ_ID_general;
366             func = (AsnWriteFunc) DbtagAsnWrite;
367             break;
368         case SEQID_GI:     /* gi */
369             retval = AsnWrite(aip, SEQ_ID_gi, &av);
370             break;
371         case SEQID_DDBJ:      /* ddbj */
372             writetype = SEQ_ID_ddbj;
373             func = (AsnWriteFunc) TextSeqIdAsnWrite;
374             break;
375         case SEQID_PRF:      /* prf   */
376             writetype = SEQ_ID_prf;
377             func = (AsnWriteFunc) TextSeqIdAsnWrite;
378             break;
379         case SEQID_PDB:      /* pdb   */
380             writetype = SEQ_ID_pdb;
381             func = (AsnWriteFunc) PDBSeqIdAsnWrite;
382             break;
383         case SEQID_TPG:      /* tpg   */
384             writetype = SEQ_ID_tpg;
385             func = (AsnWriteFunc) TextSeqIdAsnWrite;
386             break;
387         case SEQID_TPE:      /* tpe   */
388             writetype = SEQ_ID_tpe;
389             func = (AsnWriteFunc) TextSeqIdAsnWrite;
390             break;
391         case SEQID_TPD:      /* tpd   */
392             writetype = SEQ_ID_tpd;
393             func = (AsnWriteFunc) TextSeqIdAsnWrite;
394             break;
395         case SEQID_GPIPE:
396             writetype = SEQ_ID_gpipe;
397             func = (AsnWriteFunc) TextSeqIdAsnWrite;
398             break;
399         case SEQID_NAMED_ANNOT_TRACK:
400             writetype = SEQ_ID_named_annot_track;
401             func = (AsnWriteFunc) TextSeqIdAsnWrite;
402             break;
403     }
404     if (writetype != NULL)
405         retval = (* func)(pnt, aip, writetype);   /* write it out */
406 erret:
407         AsnUnlinkType(orig);       /* unlink local tree */
408         return retval;
409 }
410 
411 /*****************************************************************************
412 *
413 *   SeqIdAsnRead(aip, atp)
414 *       atp is the current type (if identifier of a parent struct)
415 *            assumption is readIdent has occurred
416 *       if atp == NULL, then assumes it stands alone and read ident
417 *            has not occurred.
418 *
419 *****************************************************************************/
420 NLM_EXTERN SeqIdPtr LIBCALL SeqIdAsnRead (AsnIoPtr aip, AsnTypePtr orig)
421 {
422         DataVal av;
423         AsnTypePtr atp;
424     SeqIdPtr anp=NULL;
425     Uint1 choice;
426     AsnReadFunc func;
427 
428         if (! loaded)
429         {
430                 if (! SeqLocAsnLoad())
431                         return anp;
432         }
433 
434         if (aip == NULL)
435                 return anp;
436 
437         if (orig == NULL)           /* SeqId ::= (self contained) */
438                 atp = AsnReadId(aip, amp, SEQ_ID);
439         else
440                 atp = AsnLinkType(orig, SEQ_ID);    /* link in local tree */
441     if (atp == NULL)
442         return anp;
443 
444         anp = ValNodeNew(NULL);
445     if (anp == NULL)
446         goto erret;
447 
448     if ( AsnReadVal(aip, atp, &av) <= 0)
449         goto erret;    /* read the CHOICE value (nothing) */
450     if ((atp = AsnReadId(aip, amp, atp)) == NULL)
451         goto erret;  /* find the choice */
452 
453     func = NULL;
454 
455         if (atp == SEQ_ID_local)
456     {
457         choice = SEQID_LOCAL;
458         func = (AsnReadFunc) ObjectIdAsnRead;
459     }
460     else if (atp == SEQ_ID_gibbsq)
461     {
462         choice = SEQID_GIBBSQ;
463         AsnReadVal(aip, atp, &av);
464         anp->data.intvalue = av.intvalue;
465     }
466     else if (atp == SEQ_ID_gibbmt)
467     {
468         choice = SEQID_GIBBMT;
469         AsnReadVal(aip, atp, &av);
470         anp->data.intvalue = av.intvalue;
471     }
472     else if (atp == SEQ_ID_giim)
473     {
474         choice = SEQID_GIIM;
475         func = (AsnReadFunc) GiimAsnRead;
476     }
477     else if (atp == SEQ_ID_genbank)
478     {
479         choice = SEQID_GENBANK;
480         func = (AsnReadFunc) TextSeqIdAsnRead;
481     }
482     else if (atp == SEQ_ID_embl)
483     {
484         choice = SEQID_EMBL;
485         func = (AsnReadFunc) TextSeqIdAsnRead;
486     }
487     else if (atp == SEQ_ID_pir)
488     {
489         choice = SEQID_PIR;
490         func = (AsnReadFunc) TextSeqIdAsnRead;
491     }
492     else if (atp == SEQ_ID_swissprot)
493     {
494         choice = SEQID_SWISSPROT;
495         func = (AsnReadFunc) TextSeqIdAsnRead;
496     }
497     else if (atp == SEQ_ID_patent)
498     {
499         choice = SEQID_PATENT;
500         func = (AsnReadFunc) PatentSeqIdAsnRead;
501     }
502     else if (atp == SEQ_ID_other)
503     {
504         choice = SEQID_OTHER;
505         func = (AsnReadFunc) TextSeqIdAsnRead;
506     }
507     else if (atp == SEQ_ID_general)
508     {
509         choice = SEQID_GENERAL;
510         func = (AsnReadFunc) DbtagAsnRead;
511     }
512     else if (atp == SEQ_ID_gi)
513     {
514         choice = SEQID_GI;
515         AsnReadVal(aip, atp, &av);
516         anp->data.intvalue = av.intvalue;
517     }
518     else if (atp == SEQ_ID_ddbj)
519     {
520         choice = SEQID_DDBJ;
521         func = (AsnReadFunc) TextSeqIdAsnRead;
522     }
523     else if (atp == SEQ_ID_prf)
524     {
525         choice = SEQID_PRF;
526         func = (AsnReadFunc) TextSeqIdAsnRead;
527     }
528     else if (atp == SEQ_ID_pdb)
529     {
530         choice = SEQID_PDB;
531         func = (AsnReadFunc) PDBSeqIdAsnRead;
532     }
533     else if (atp == SEQ_ID_tpg)
534     {
535         choice = SEQID_TPG;
536         func = (AsnReadFunc) TextSeqIdAsnRead;
537     }
538     else if (atp == SEQ_ID_tpe)
539     {
540         choice = SEQID_TPE;
541         func = (AsnReadFunc) TextSeqIdAsnRead;
542     }
543     else if (atp == SEQ_ID_tpd)
544     {
545         choice = SEQID_TPD;
546         func = (AsnReadFunc) TextSeqIdAsnRead;
547     }
548     else if (atp == SEQ_ID_gpipe)
549     {
550         choice = SEQID_GPIPE;
551         func = (AsnReadFunc) TextSeqIdAsnRead;
552     }
553     else if (atp == SEQ_ID_named_annot_track)
554     {
555         choice = SEQID_NAMED_ANNOT_TRACK;
556         func = (AsnReadFunc) TextSeqIdAsnRead;
557     }
558     else
559         goto erret;
560 
561     anp->choice = choice;
562     if (func != NULL)
563         anp->data.ptrvalue = (* func)(aip, atp);
564 ret:
565         AsnUnlinkType(orig);       /* unlink local tree */
566         return anp;
567 erret:
568     anp = SeqIdFree(anp);
569     goto ret;
570 }
571 
572 /*****************************************************************************
573 *
574 *   SeqIdPtr SeqIdDup(oldid)
575 *
576 *****************************************************************************/
577 NLM_EXTERN SeqIdPtr LIBCALL SeqIdDup (SeqIdPtr oldid)
578 {
579     TextSeqIdPtr at, bt;
580         GiimPtr ga, gb;
581         PatentSeqIdPtr psa, psb;
582         PDBSeqIdPtr pdba, pdbb;
583         SeqIdPtr newid = NULL;
584 
585     if (oldid == NULL)
586         return oldid;
587 
588         newid = ValNodeNew(NULL);
589         if (newid == NULL) return newid;
590         MemCopy(newid, oldid, sizeof(ValNode));
591         newid->next = NULL;    /* not in chain */
592     switch (oldid->choice)
593     {
594         case SEQID_NOT_SET:
595             break;
596         case SEQID_LOCAL:
597                         newid->data.ptrvalue = ObjectIdDup((ObjectIdPtr)oldid->data.ptrvalue);
598                         break;
599                                          /* integer types */
600         case SEQID_GIBBSQ:   /* gibbsq */
601         case SEQID_GIBBMT:   /* gibbmt */
602         case SEQID_GI:  /* gi */
603             break;
604 
605         case SEQID_GIIM:   /* giim */
606                         ga = (GiimPtr) oldid->data.ptrvalue;
607                         gb = GiimNew();
608                         if (gb == NULL) return NULL;
609                         gb->id = ga->id;
610                         gb->db = StringSave(ga->db);
611                         gb->release = StringSave(ga->release);
612                         newid->data.ptrvalue = gb;
613                         break;
614         case SEQID_PATENT:   /* patent seq */
615                         psa = (PatentSeqIdPtr)oldid->data.ptrvalue;
616                         psb = PatentSeqIdNew();
617                         if (psb == NULL) return NULL;
618                         psb->seqid = psa->seqid;
619                         psb->cit = IdPatNew();
620                         psb->cit->country = StringSave(psa->cit->country);
621                         psb->cit->number = StringSave(psa->cit->number);
622                         psb->cit->app_number = StringSave(psa->cit->app_number);
623                         newid->data.ptrvalue = psb;
624                         break;
625                                                         /* TextSeqId Types */
626                 case SEQID_GENBANK:
627                 case SEQID_EMBL:
628                 case SEQID_PIR:
629                 case SEQID_SWISSPROT:
630                 case SEQID_OTHER:
631                 case SEQID_DDBJ:
632                 case SEQID_PRF:
633                 case SEQID_TPG:
634                 case SEQID_TPE:
635                 case SEQID_TPD:
636         case SEQID_GPIPE:
637                         at = (TextSeqIdPtr)oldid->data.ptrvalue;
638             bt = TextSeqIdNew();
639                         if (bt == NULL) return NULL;
640                         bt->name = StringSave(at->name);
641                         bt->accession = StringSave(at->accession);
642                         bt->release = StringSave(at->release);
643                         bt->version = at->version;
644                         newid->data.ptrvalue = bt;
645                         break;
646                 case SEQID_GENERAL:
647                         newid->data.ptrvalue = DbtagDup((DbtagPtr)oldid->data.ptrvalue);
648                         break;
649                 case SEQID_PDB:
650                         pdba = (PDBSeqIdPtr)oldid->data.ptrvalue;
651             pdbb = PDBSeqIdNew();
652                         if (pdbb == NULL) return NULL;
653                         newid->data.ptrvalue = pdbb;
654                         pdbb->mol = StringSave(pdba->mol);
655                         pdbb->chain = pdba->chain;
656                         pdbb->rel = DateDup(pdba->rel);
657                         break;
658      }
659         return newid;
660 }
661 
662 /*****************************************************************************
663 *
664 *   SeqIdPtr SeqIdSetDup(oldid)
665 *       duplicates a chain of SeqId's
666 *
667 *****************************************************************************/
668 NLM_EXTERN SeqIdPtr LIBCALL 
669 SeqIdSetDup(SeqIdPtr seqid)
670 {
671    SeqIdPtr sid_head, sid, seqid_var;
672 
673    if (seqid == NULL)
674       return seqid;
675    else {
676       seqid_var = seqid;
677       sid_head = sid = SeqIdDup(seqid);
678    }
679 
680    while ((seqid_var = seqid_var->next) != NULL) {
681       sid->next = SeqIdDup(seqid_var);
682       sid = sid->next;
683    }
684 
685    return sid_head;
686 }
687 
688 
689 /*****************************************************************************
690 *
691 *   SeqIdSetFree()
692 *       frees a chain of SeqId's
693 *
694 *****************************************************************************/
695 NLM_EXTERN SeqIdPtr LIBCALL SeqIdSetFree (SeqIdPtr sip)
696 {
697     SeqIdPtr next;
698 
699     while (sip != NULL)
700     {
701         next = sip->next;
702         SeqIdFree(sip);
703         sip = next;
704     }
705     return sip;
706 }
707 
708 /*****************************************************************************
709 *
710 *   SeqIdSetAsnRead(aip, settype, elementtype)
711 *       read a set/seq of SeqId's
712 *
713 *****************************************************************************/
714 NLM_EXTERN SeqIdPtr LIBCALL SeqIdSetAsnRead (AsnIoPtr aip, AsnTypePtr settype, AsnTypePtr elementtype)
715 {
716     DataVal av;
717     AsnTypePtr atp, atp2;
718     SeqIdPtr first = NULL, curr = NULL, anp;
719 
720         if (! loaded)
721         {
722                 if (! SeqLocAsnLoad())
723                         return first;
724         }
725 
726     atp2 = AsnLinkType(elementtype, SEQ_ID);
727     if (atp2 == NULL)
728         return first;
729 
730     if (AsnReadVal(aip, settype, &av) <= 0)   /* start struct */
731         goto erret;
732 
733     atp = settype;
734     while ((atp = AsnReadId(aip, amp, atp)) != settype)
735     {
736         if (atp == NULL)
737             goto erret;
738         anp = SeqIdAsnRead(aip, atp2);
739         if (anp == NULL)
740             goto erret;
741 
742         if (first == NULL)
743             first = anp;
744         else
745             curr->next = anp;
746         curr = anp;
747     }
748     if (AsnReadVal(aip, atp, &av) <= 0)    /* end struct */
749         goto erret;
750         if (first == NULL)
751                 ErrPost(CTX_NCBIOBJ, 1, "Empty SET OF Seq-id. line %ld", aip->linenumber);
752 ret:
753     AsnUnlinkType(elementtype);
754     return first;
755 erret:
756     aip->io_failure = TRUE;
757     first = SeqIdSetFree(first);
758     goto ret;
759 }
760 
761 /*****************************************************************************
762 *
763 *   SeqIdSetAsnWrite(anp, aip, settype, elementtype)
764 *
765 *****************************************************************************/
766 NLM_EXTERN Boolean LIBCALL SeqIdSetAsnWrite (SeqIdPtr anp, AsnIoPtr aip, AsnTypePtr settype, AsnTypePtr elementtype)
767 {
768     AsnTypePtr atp2;
769         SeqIdPtr oldanp;
770     Boolean retval = FALSE;
771 
772         if (! loaded)
773         {
774                 if (! SeqLocAsnLoad())
775                         return retval;
776         }
777 
778     if (aip == NULL)
779         return retval;
780 
781     atp2 = AsnLinkType(elementtype, SEQ_ID);
782     if (atp2 == NULL)
783         return retval;
784 
785         if (anp == NULL) { AsnNullValueMsg(aip, settype); goto erret; }
786 
787         oldanp = anp;
788     if (! AsnOpenStruct(aip, settype, (Pointer)oldanp))
789         goto erret;
790     while (anp != NULL)
791     {
792         if (! SeqIdAsnWrite(anp, aip, atp2))
793             goto erret;
794         anp = anp->next;
795     }
796     if (! AsnCloseStruct(aip, settype, (Pointer)oldanp))
797         goto erret;
798     retval = TRUE;
799 erret:
800     AsnUnlinkType(elementtype);
801     return retval;
802 }
803 
804 /*****************************************************************************
805 *
806 *   TextSeqIdNew()
807 *
808 *****************************************************************************/
809 NLM_EXTERN TextSeqIdPtr LIBCALL TextSeqIdNew (void)
810 {
811         TextSeqIdPtr tsip;
812 
813     tsip = (TextSeqIdPtr)MemNew(sizeof(TextSeqId));
814         if (tsip == NULL) return tsip;
815 
816         tsip->version = INT2_MIN;
817         return tsip;
818 }
819 
820 /*****************************************************************************
821 *
822 *   TextSeqIdFree(anp)
823 *       Frees one TextSeqId
824 *
825 *****************************************************************************/
826 NLM_EXTERN TextSeqIdPtr LIBCALL TextSeqIdFree (TextSeqIdPtr tsip)
827 {
828     if (tsip == NULL)
829         return tsip;
830     
831     MemFree(tsip->name);
832     MemFree(tsip->accession);
833     MemFree(tsip->release);
834         return (TextSeqIdPtr)MemFree(tsip);
835 }
836 
837 /*****************************************************************************
838 *
839 *   TextSeqIdAsnWrite(tsip, aip, atp)
840 *       atp is the current type (if identifier of a parent struct)
841 *       if atp == NULL, then assumes it stands alone (TextSeqId ::=)
842 *
843 *****************************************************************************/
844 NLM_EXTERN Boolean LIBCALL TextSeqIdAsnWrite (TextSeqIdPtr tsip, AsnIoPtr aip, AsnTypePtr orig)
845 {
846         DataVal av;
847         AsnTypePtr atp;
848     Boolean retval = FALSE;
849 
850         if (! loaded)
851         {
852                 if (! SeqLocAsnLoad())
853                         return retval;
854         }
855 
856         if (aip == NULL)
857                 return retval;
858 
859         atp = AsnLinkType(orig, TEXTSEQ_ID);   /* link local tree */
860     if (atp == NULL)
861         return retval;
862 
863         if (tsip == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
864 
865     if (! AsnOpenStruct(aip, atp, (Pointer)tsip))
866         goto erret;
867     if (tsip->name != NULL)
868     {
869         av.ptrvalue = tsip->name;
870         if (! AsnWrite(aip, TEXTSEQ_ID_name, &av))
871             goto erret;
872     }
873     if (tsip->accession != NULL)
874     {
875         av.ptrvalue = tsip->accession;
876         if (! AsnWrite(aip, TEXTSEQ_ID_accession, &av))
877             goto erret;
878     }
879     if (tsip->release != NULL)
880     {
881         av.ptrvalue = tsip->release;
882         if (! AsnWrite(aip, TEXTSEQ_ID_release, &av))
883             goto erret;
884     }
885         if (tsip->version != INT2_MIN)
886         {
887                 av.intvalue = (Int4) tsip->version;
888                 if (! AsnWrite(aip, TEXTSEQ_ID_version, &av))
889             goto erret;
890         }
891     if (! AsnCloseStruct(aip, atp, (Pointer)tsip))
892         goto erret;
893     retval = TRUE;
894 erret:
895         AsnUnlinkType(orig);       /* unlink local tree */
896         return retval;
897 }
898 
899 /*****************************************************************************
900 *
901 *   TextSeqIdAsnRead(aip, atp)
902 *       atp is the current type (if identifier of a parent struct)
903 *            assumption is readIdent has occurred
904 *       if atp == NULL, then assumes it stands alone and read ident
905 *            has not occurred.
906 *
907 *****************************************************************************/
908 NLM_EXTERN TextSeqIdPtr LIBCALL TextSeqIdAsnRead (AsnIoPtr aip, AsnTypePtr orig)
909 {
910         DataVal av;
911         AsnTypePtr atp, oldtype;
912     TextSeqIdPtr tsip=NULL;
913 
914         if (! loaded)
915         {
916                 if (! SeqLocAsnLoad())
917                         return tsip;
918         }
919 
920         if (aip == NULL)
921                 return tsip;
922 
923         if (orig == NULL)           /* TextSeqId ::= (self contained) */
924                 atp = AsnReadId(aip, amp, TEXTSEQ_ID);
925         else
926                 atp = AsnLinkType(orig, TEXTSEQ_ID);    /* link in local tree */
927     oldtype = atp;
928     if (atp == NULL)
929         return tsip;
930 
931         tsip = TextSeqIdNew();
932     if (tsip == NULL)
933         goto erret;
934 
935         if ((AsnReadVal(aip, oldtype, &av)) <= 0)    /* read the START_STRUCT */
936         goto erret;
937     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)
938     {
939         if (atp == NULL)
940             goto erret;
941         if ((AsnReadVal(aip, atp, &av)) <= 0)
942             goto erret;
943         if (atp == TEXTSEQ_ID_name)
944             tsip->name = (CharPtr)av.ptrvalue;
945         else if (atp == TEXTSEQ_ID_accession)
946             tsip->accession = (CharPtr)av.ptrvalue;
947         else if (atp == TEXTSEQ_ID_release)
948             tsip->release = (CharPtr)av.ptrvalue;
949                 else if (atp == TEXTSEQ_ID_version)
950                         tsip->version = (Int2)av.intvalue;
951         else
952             goto erret;
953     }
954     if ((AsnReadVal(aip, atp, &av)) <= 0)      /* read END_STRUCT */
955         goto erret;
956 ret:
957         AsnUnlinkType(orig);       /* unlink local tree */
958         return tsip;
959 erret:
960     tsip = TextSeqIdFree(tsip);
961     goto ret;
962 }
963 
964 /*****************************************************************************
965 *
966 *   PatentSeqIdNew()
967 *
968 *****************************************************************************/
969 NLM_EXTERN PatentSeqIdPtr LIBCALL PatentSeqIdNew (void)
970 {
971     return (PatentSeqIdPtr)MemNew(sizeof(PatentSeqId));
972 }
973 
974 /*****************************************************************************
975 *
976 *   PatentSeqIdFree(anp)
977 *       Frees one PatentSeqId
978 *
979 *****************************************************************************/
980 NLM_EXTERN PatentSeqIdPtr LIBCALL PatentSeqIdFree (PatentSeqIdPtr psip)
981 {
982     if (psip == NULL)
983         return psip;
984     
985     IdPatFree(psip->cit);
986         return (PatentSeqIdPtr)MemFree(psip);
987 }
988 
989 /*****************************************************************************
990 *
991 *   PatentSeqIdAsnWrite(psip, aip, atp)
992 *       atp is the current type (if identifier of a parent struct)
993 *       if atp == NULL, then assumes it stands alone (PatentSeqId ::=)
994 *
995 *****************************************************************************/
996 NLM_EXTERN Boolean LIBCALL PatentSeqIdAsnWrite (PatentSeqIdPtr psip, AsnIoPtr aip, AsnTypePtr orig)
997 {
998         DataVal av;
999         AsnTypePtr atp;
1000     Boolean retval = FALSE;
1001 
1002         if (! loaded)
1003         {
1004                 if (! SeqLocAsnLoad())
1005                         return FALSE;
1006         }
1007 
1008         if (aip == NULL)
1009                 return FALSE;
1010 
1011         atp = AsnLinkType(orig, PATENT_SEQ_ID);   /* link local tree */
1012     if (atp == NULL)
1013         return FALSE;
1014 
1015         if (psip == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1016 
1017     if (! AsnOpenStruct(aip, atp, (Pointer)psip))
1018         goto erret;
1019     av.intvalue = psip->seqid;
1020     if (! AsnWrite(aip, PATENT_SEQ_ID_seqid, &av))
1021         goto erret;
1022     if (! IdPatAsnWrite(psip->cit, aip, PATENT_SEQ_ID_cit))
1023         goto erret;
1024     if (! AsnCloseStruct(aip, atp, (Pointer)psip))
1025         goto erret;
1026     retval = TRUE;
1027 erret:
1028         AsnUnlinkType(orig);       /* unlink local tree */
1029         return retval;
1030 }
1031 
1032 /*****************************************************************************
1033 *
1034 *   PatentSeqIdAsnRead(aip, atp)
1035 *       atp is the current type (if identifier of a parent struct)
1036 *            assumption is readIdent has occurred
1037 *       if atp == NULL, then assumes it stands alone and read ident
1038 *            has not occurred.
1039 *
1040 *****************************************************************************/
1041 NLM_EXTERN PatentSeqIdPtr LIBCALL PatentSeqIdAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1042 {
1043         DataVal av;
1044         AsnTypePtr atp;
1045     PatentSeqIdPtr psip=NULL;
1046 
1047         if (! loaded)
1048         {
1049                 if (! SeqLocAsnLoad())
1050                         return psip;
1051         }
1052 
1053         if (aip == NULL)
1054                 return psip;
1055 
1056         if (orig == NULL)           /* PatentSeqId ::= (self contained) */
1057                 atp = AsnReadId(aip, amp, PATENT_SEQ_ID);
1058         else
1059                 atp = AsnLinkType(orig, PATENT_SEQ_ID);    /* link in local tree */
1060     if (atp == NULL)
1061         return psip;
1062 
1063         psip = PatentSeqIdNew();
1064     if (psip == NULL)
1065         goto erret;
1066 
1067         if (AsnReadVal(aip, atp, &av) <= 0)    /* read the START_STRUCT */
1068         goto erret;
1069     atp = AsnReadId(aip, amp, atp);   /* read the seqid */
1070     if (atp == NULL)
1071         goto erret;
1072     if (AsnReadVal(aip, atp, &av) <= 0)
1073         goto erret;
1074     psip->seqid = av.intvalue;
1075     atp = AsnReadId(aip, amp, atp);   /* read the cit */
1076     if (atp == NULL)
1077         goto erret;
1078     psip->cit = IdPatAsnRead(aip, atp);
1079     if (psip->cit == NULL)
1080         goto erret;
1081     atp = AsnReadId(aip, amp, atp);
1082     if (atp == NULL)
1083         goto erret;
1084     if (AsnReadVal(aip, atp, &av) <= 0)      /* read END_STRUCT */
1085         goto erret;
1086 ret:
1087         AsnUnlinkType(orig);       /* unlink local tree */
1088         return psip;
1089 erret:
1090     psip = PatentSeqIdFree(psip);
1091     goto ret;
1092 }
1093 
1094 /*****************************************************************************
1095 *
1096 *   GiimNew()
1097 *
1098 *****************************************************************************/
1099 NLM_EXTERN GiimPtr LIBCALL GiimNew (void)
1100 {
1101     return (GiimPtr)MemNew(sizeof(Giim));
1102 }
1103 
1104 /*****************************************************************************
1105 *
1106 *   GiimFree(anp)
1107 *       Frees one Giim
1108 *
1109 *****************************************************************************/
1110 NLM_EXTERN GiimPtr LIBCALL GiimFree (GiimPtr gip)
1111 {
1112     if (gip == NULL)
1113         return gip;
1114     
1115     MemFree(gip->db);
1116     MemFree(gip->release);
1117         return (GiimPtr)MemFree(gip);
1118 }
1119 
1120 /*****************************************************************************
1121 *
1122 *   GiimAsnWrite(gip, aip, atp)
1123 *       atp is the current type (if identifier of a parent struct)
1124 *       if atp == NULL, then assumes it stands alone (Giim ::=)
1125 *
1126 *****************************************************************************/
1127 NLM_EXTERN Boolean LIBCALL GiimAsnWrite (GiimPtr gip, AsnIoPtr aip, AsnTypePtr orig)
1128 {
1129         DataVal av;
1130         AsnTypePtr atp;
1131     Boolean retval = FALSE;
1132 
1133         if (! loaded)
1134         {
1135                 if (! SeqLocAsnLoad())
1136                         return FALSE;
1137         }
1138 
1139         if (aip == NULL)
1140                 return FALSE;
1141 
1142         atp = AsnLinkType(orig, GIIMPORT_ID);   /* link local tree */
1143     if (atp == NULL)
1144         return FALSE;
1145 
1146         if (gip == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1147 
1148     if (! AsnOpenStruct(aip, atp, (Pointer)gip))
1149         goto erret;
1150     av.intvalue = gip->id;
1151     if (! AsnWrite(aip, GIIMPORT_ID_id, &av))
1152         goto erret;
1153     if (gip->db != NULL)
1154     {
1155         av.ptrvalue = gip->db;
1156         if (! AsnWrite(aip, GIIMPORT_ID_db, &av))
1157             goto erret;
1158     }
1159     if (gip->release != NULL)
1160     {
1161         av.ptrvalue = gip->release;
1162         if (! AsnWrite(aip, GIIMPORT_ID_release, &av))
1163             goto erret;
1164     }
1165     if (! AsnCloseStruct(aip, atp, (Pointer)gip))
1166         goto erret;
1167     retval = TRUE;
1168 erret:
1169         AsnUnlinkType(orig);       /* unlink local tree */
1170         return retval;
1171 }
1172 
1173 /*****************************************************************************
1174 *
1175 *   GiimAsnRead(aip, atp)
1176 *       atp is the current type (if identifier of a parent struct)
1177 *            assumption is readIdent has occurred
1178 *       if atp == NULL, then assumes it stands alone and read ident
1179 *            has not occurred.
1180 *
1181 *****************************************************************************/
1182 NLM_EXTERN GiimPtr LIBCALL GiimAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1183 {
1184         DataVal av;
1185         AsnTypePtr atp, oldtype;
1186     GiimPtr gip=NULL;
1187 
1188         if (! loaded)
1189         {
1190                 if (! SeqLocAsnLoad())
1191                         return gip;
1192         }
1193 
1194         if (aip == NULL)
1195                 return gip;
1196 
1197         if (orig == NULL)           /* Giim ::= (self contained) */
1198                 atp = AsnReadId(aip, amp, GIIMPORT_ID);
1199         else
1200                 atp = AsnLinkType(orig, GIIMPORT_ID);    /* link in local tree */
1201     if (atp == NULL)
1202         return gip;
1203     oldtype = atp;
1204 
1205         gip = GiimNew();
1206     if (gip == NULL)
1207         goto erret;
1208 
1209         if (AsnReadVal(aip, oldtype, &av) <= 0)    /* read the START_STRUCT */
1210         goto erret;
1211     atp = AsnReadId(aip, amp, atp);   /* read the seqid */
1212     if (atp == NULL)
1213         goto erret;
1214     if (AsnReadVal(aip, atp, &av) <= 0)
1215         goto erret;
1216     gip->id = av.intvalue;
1217     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)
1218     {
1219         if (atp == NULL)
1220             goto erret;
1221         if (AsnReadVal(aip, atp, &av) <= 0)
1222             goto erret;
1223         if (atp == GIIMPORT_ID_db)
1224             gip->db = (CharPtr)av.ptrvalue;
1225         else if (atp == GIIMPORT_ID_release)
1226             gip->release = (CharPtr)av.ptrvalue;
1227         else
1228             goto erret;
1229     }
1230     if (AsnReadVal(aip, atp, &av) <= 0)      /* read END_STRUCT */
1231         goto erret;
1232 ret:
1233         AsnUnlinkType(orig);       /* unlink local tree */
1234         return gip;
1235 erret:
1236     gip = GiimFree(gip);
1237     goto ret;
1238 }
1239 
1240 /*****************************************************************************
1241 *
1242 *   PDBSeqIdNew()
1243 *
1244 *****************************************************************************/
1245 NLM_EXTERN PDBSeqIdPtr LIBCALL PDBSeqIdNew (void)
1246 {
1247         PDBSeqIdPtr pdbsip;
1248 
1249     pdbsip = (PDBSeqIdPtr)MemNew(sizeof(PDBSeqId));
1250         if (pdbsip == NULL) return pdbsip;
1251         pdbsip->chain = (Uint1)32;
1252         return pdbsip;
1253 }
1254 
1255 /*****************************************************************************
1256 *
1257 *   PDBSeqIdFree(anp)
1258 *       Frees one PDBSeqId
1259 *
1260 *****************************************************************************/
1261 NLM_EXTERN PDBSeqIdPtr LIBCALL PDBSeqIdFree (PDBSeqIdPtr pdbsip)
1262 {
1263     if (pdbsip == NULL)
1264         return pdbsip;
1265     
1266     MemFree(pdbsip->mol);
1267         DateFree(pdbsip->rel);
1268         return (PDBSeqIdPtr)MemFree(pdbsip);
1269 }
1270 
1271 /*****************************************************************************
1272 *
1273 *   PDBSeqIdAsnWrite(pdbsip, aip, atp)
1274 *       atp is the current type (if identifier of a parent struct)
1275 *       if atp == NULL, then assumes it stands alone (PDBSeqId ::=)
1276 *
1277 *****************************************************************************/
1278 NLM_EXTERN Boolean LIBCALL PDBSeqIdAsnWrite (PDBSeqIdPtr pdbsip, AsnIoPtr aip, AsnTypePtr orig)
1279 {
1280         DataVal av;
1281         AsnTypePtr atp;
1282     Boolean retval = FALSE;
1283 
1284         if (! loaded)
1285         {
1286                 if (! SeqLocAsnLoad())
1287                         return retval;
1288         }
1289 
1290         if (aip == NULL)
1291                 return retval;
1292 
1293         atp = AsnLinkType(orig, PDB_SEQ_ID);   /* link local tree */
1294     if (atp == NULL)
1295         return retval;
1296 
1297         if (pdbsip == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1298 
1299     if (! AsnOpenStruct(aip, atp, (Pointer)pdbsip))
1300         goto erret;
1301     if (pdbsip->mol != NULL)
1302     {
1303         av.ptrvalue = pdbsip->mol;
1304         if (! AsnWrite(aip, PDB_SEQ_ID_mol, &av))
1305             goto erret;
1306     }
1307     if (pdbsip->chain != (Uint1)32)
1308     {
1309         av.intvalue = (Int4) pdbsip->chain;
1310         if (! AsnWrite(aip, PDB_SEQ_ID_chain, &av))
1311             goto erret;
1312     }
1313     if (pdbsip->rel != NULL)
1314     {
1315         if (! DateAsnWrite(pdbsip->rel, aip, PDB_SEQ_ID_rel))
1316             goto erret;
1317     }
1318     if (! AsnCloseStruct(aip, atp, (Pointer)pdbsip))
1319         goto erret;
1320     retval = TRUE;
1321 erret:
1322         AsnUnlinkType(orig);       /* unlink local tree */
1323         return retval;
1324 }
1325 
1326 /*****************************************************************************
1327 *
1328 *   PDBSeqIdAsnRead(aip, atp)
1329 *       atp is the current type (if identifier of a parent struct)
1330 *            assumption is readIdent has occurred
1331 *       if atp == NULL, then assumes it stands alone and read ident
1332 *            has not occurred.
1333 *
1334 *****************************************************************************/
1335 NLM_EXTERN PDBSeqIdPtr LIBCALL PDBSeqIdAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1336 {
1337         DataVal av;
1338         AsnTypePtr atp, oldtype;
1339     PDBSeqIdPtr pdbsip=NULL;
1340 
1341         if (! loaded)
1342         {
1343                 if (! SeqLocAsnLoad())
1344                         return pdbsip;
1345         }
1346 
1347         if (aip == NULL)
1348                 return pdbsip;
1349 
1350         if (orig == NULL)           /* PDBSeqId ::= (self contained) */
1351                 atp = AsnReadId(aip, amp, PDB_SEQ_ID);
1352         else
1353                 atp = AsnLinkType(orig, PDB_SEQ_ID);    /* link in local tree */
1354     oldtype = atp;
1355     if (atp == NULL)
1356         return pdbsip;
1357 
1358         pdbsip = PDBSeqIdNew();
1359     if (pdbsip == NULL)
1360         goto erret;
1361 
1362         if ((AsnReadVal(aip, oldtype, &av)) <= 0)    /* read the START_STRUCT */
1363         goto erret;
1364     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)
1365     {
1366         if (atp == NULL)
1367             goto erret;
1368         if (atp == PDB_SEQ_ID_rel)
1369                 {
1370             pdbsip->rel = DateAsnRead(aip, atp);
1371                         if (pdbsip->rel == NULL)
1372                                 goto erret;
1373                 }
1374                 else
1375                 {
1376                 if ((AsnReadVal(aip, atp, &av)) <= 0)
1377                 goto erret;
1378                 if (atp == PDB_SEQ_ID_mol)
1379                 pdbsip->mol = (CharPtr)av.ptrvalue;
1380                 else if (atp == PDB_SEQ_ID_chain)
1381                 pdbsip->chain = (Uint1)av.intvalue;
1382                 else
1383                 goto erret;
1384                 }
1385     }
1386     if ((AsnReadVal(aip, atp, &av)) <= 0)      /* read END_STRUCT */
1387         goto erret;
1388 ret:
1389         AsnUnlinkType(orig);       /* unlink local tree */
1390         return pdbsip;
1391 erret:
1392     pdbsip = PDBSeqIdFree(pdbsip);
1393     goto ret;
1394 }
1395 
1396 /*****************************************************************************
1397 *
1398 *   SeqLoc
1399 *   SeqLoc is a choice using an ValNode, most types in data.ptrvalue
1400 *      except integers, in data.intvalue
1401 *   choice:
1402     1 = null NULL ,           -- not placed
1403     2 = empty Seq-id ,        -- to NULL one Seq-id in a collection
1404     3 = whole Seq-id ,        -- whole sequence
1405     4 = int Seq-interval ,    -- from to
1406     5 = packed-int Packed-seqint ,
1407     6 = pnt Seq-point ,
1408     7 = packed-pnt Packed-seqpnt ,
1409     8 = mix SEQUENCE OF Seq-loc ,
1410     9 = equiv SET OF Seq-loc ,  -- equivalent sets of locations
1411     10 = bond Seq-bond
1412     11 = feat Feat-id
1413 *
1414 *****************************************************************************/
1415 /*****************************************************************************
1416 *
1417 *   SeqLocFree(anp)
1418 *       Frees one SeqLoc and associated data
1419 *
1420 *****************************************************************************/
1421 NLM_EXTERN SeqLocPtr LIBCALL SeqLocFree (SeqLocPtr anp)
1422 {
1423     Pointer pnt;
1424 
1425     if (anp == NULL)
1426         return anp;
1427     
1428     pnt = anp->data.ptrvalue;
1429     switch (anp->choice)
1430     {
1431         case SEQLOC_NULL:      /* null */
1432             break;
1433         case SEQLOC_EMPTY:      /* empty */
1434         case SEQLOC_WHOLE:      /* whole */
1435             SeqIdFree((SeqIdPtr)pnt);
1436             break;
1437         case SEQLOC_INT:      /* int */
1438             SeqIntFree((SeqIntPtr)pnt);
1439             break;
1440         case SEQLOC_PNT:      /* pnt */
1441             SeqPntFree((SeqPntPtr)pnt);
1442             break;
1443         case SEQLOC_PACKED_PNT:      /* packed-pnt   */
1444             PackSeqPntFree((PackSeqPntPtr)pnt);
1445             break;
1446         case SEQLOC_MIX:      /* mix */
1447         case SEQLOC_EQUIV:     /* equiv */
1448         case SEQLOC_PACKED_INT:      /* packed seqint */
1449             SeqLocSetFree((SeqLocPtr)pnt);
1450             break;
1451         case SEQLOC_BOND:      /* bond */
1452             SeqBondFree((SeqBondPtr)pnt);
1453             break;
1454         case SEQLOC_FEAT:
1455             SeqFeatIdFree((ChoicePtr)pnt);
1456             MemFree(pnt);    /* get rid of Choice too */
1457             break;
1458     }
1459 
1460         ObjMgrDelete(OBJ_SEQLOC, (Pointer)anp);
1461 
1462         return (SeqLocPtr)MemFree(anp);
1463 }
1464 
1465 /*****************************************************************************
1466 *
1467 *   SeqLocCopy(anp)
1468 *       Convenience function to duplicate SeqLoc
1469 *
1470 *****************************************************************************/
1471 NLM_EXTERN SeqLocPtr LIBCALL SeqLocCopy (SeqLocPtr anp)
1472 
1473 {
1474     if (anp == NULL)
1475         return anp;
1476     
1477     return (SeqLocPtr) AsnIoMemCopy ((Pointer) anp,
1478                                      (AsnReadFunc) SeqLocAsnRead,
1479                                      (AsnWriteFunc) SeqLocAsnWrite);
1480 }
1481 
1482 /*****************************************************************************
1483 *
1484 *   SeqLocAsnWrite(anp, aip, atp)
1485 *       atp is the current type (if identifier of a parent struct)
1486 *       if atp == NULL, then assumes it stands alone (SeqLoc ::=)
1487 *
1488 *****************************************************************************/
1489 NLM_EXTERN Boolean LIBCALL SeqLocAsnWrite (SeqLocPtr anp, AsnIoPtr aip, AsnTypePtr orig)
1490 {
1491         DataVal av;
1492         AsnTypePtr atp, writetype = NULL;
1493     Pointer pnt;
1494     AsnWriteFunc func = NULL;
1495     Boolean retval = FALSE;
1496 
1497         if (! loaded)
1498         {
1499                 if (! SeqLocAsnLoad())
1500                         return FALSE;
1501         }
1502 
1503         if (aip == NULL)
1504                 return FALSE;
1505 
1506         atp = AsnLinkType(orig, SEQ_LOC);   /* link local tree */
1507     if (atp == NULL)
1508         return FALSE;
1509 
1510         if (anp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1511 
1512         av.ptrvalue = (Pointer)anp;
1513         if (! AsnWriteChoice(aip, atp, (Int2)anp->choice, &av))
1514         goto erret;
1515 
1516     pnt = anp->data.ptrvalue;
1517     av.intvalue = anp->data.intvalue;
1518     switch (anp->choice)
1519     {
1520         case SEQLOC_NULL:      /* null */
1521             retval = AsnWrite(aip, SEQ_LOC_null, &av);
1522             break;
1523         case SEQLOC_EMPTY:      /* empty */
1524             writetype = SEQ_LOC_empty;
1525             func = (AsnWriteFunc) SeqIdAsnWrite;
1526             break;
1527         case SEQLOC_WHOLE:      /* whole */
1528             writetype = SEQ_LOC_whole;
1529             func = (AsnWriteFunc) SeqIdAsnWrite;
1530             break;
1531         case SEQLOC_INT:      /* int */
1532             writetype = SEQ_LOC_int;
1533             func = (AsnWriteFunc) SeqIntAsnWrite;
1534             break;
1535         case SEQLOC_PACKED_INT:      /* packed-int */
1536             writetype = SEQ_LOC_packed_int;
1537             func = (AsnWriteFunc) PackSeqIntAsnWrite;
1538             break;
1539         case SEQLOC_PNT:      /* pnt */
1540             writetype = SEQ_LOC_pnt;
1541             func = (AsnWriteFunc) SeqPntAsnWrite;
1542             break;
1543         case SEQLOC_PACKED_PNT:      /* packed-pnt */
1544             writetype = SEQ_LOC_packed_pnt;
1545             func = (AsnWriteFunc) PackSeqPntAsnWrite;
1546             break;
1547         case SEQLOC_MIX:      /* mix */
1548             writetype = SEQ_LOC_mix;
1549             func = (AsnWriteFunc) SeqLocMixAsnWrite;
1550             break;
1551         case SEQLOC_EQUIV:     /* equiv */
1552             writetype = SEQ_LOC_equiv;
1553             func = (AsnWriteFunc) SeqLocEquivAsnWrite;
1554             break;
1555         case SEQLOC_BOND:      /* bond */
1556             writetype = SEQ_LOC_bond;
1557             func = (AsnWriteFunc) SeqBondAsnWrite;
1558             break;
1559         case SEQLOC_FEAT:      /* Feat-id */
1560             writetype = SEQ_LOC_feat;
1561             func = (AsnWriteFunc) SeqFeatIdAsnWrite;
1562             break;
1563     }
1564     if (writetype != NULL)
1565         retval = (* func)(pnt, aip, writetype);   /* write it out */
1566 erret:
1567         AsnUnlinkType(orig);       /* unlink local tree */
1568         return retval;
1569 }
1570 
1571 /*****************************************************************************
1572 *
1573 *   SeqLocAsnRead(aip, atp)
1574 *       atp is the current type (if identifier of a parent struct)
1575 *            assumption is readIdent has occurred
1576 *       if atp == NULL, then assumes it stands alone and read ident
1577 *            has not occurred.
1578 *
1579 *****************************************************************************/
1580 NLM_EXTERN SeqLocPtr LIBCALL SeqLocAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1581 {
1582         DataVal av;
1583         AsnTypePtr atp;
1584     SeqLocPtr anp=NULL;
1585     Uint1 choice;
1586     AsnReadFunc func;
1587 
1588         if (! loaded)
1589         {
1590                 if (! SeqLocAsnLoad())
1591                         return anp;
1592         }
1593 
1594         if (aip == NULL)
1595                 return anp;
1596 
1597         if (orig == NULL)           /* SeqLoc ::= (self contained) */
1598                 atp = AsnReadId(aip, amp, SEQ_LOC);
1599         else
1600                 atp = AsnLinkType(orig, SEQ_LOC);    /* link in local tree */
1601     if (atp == NULL)
1602         return anp;
1603 
1604         anp = ValNodeNew(NULL);
1605     if (anp == NULL)
1606         goto erret;
1607 
1608         if (AsnReadVal(aip, atp, &av) <= 0)  /* read the CHOICE value (nothing) */
1609         goto erret;
1610         atp = AsnReadId(aip, amp, atp);  /* find the choice */
1611     if (atp == NULL)
1612         goto erret;
1613 
1614     func = NULL;
1615 
1616         if (atp == SEQ_LOC_null)
1617     {
1618         choice = SEQLOC_NULL;
1619         if (AsnReadVal(aip, atp, &av) <= 0)
1620             goto erret;
1621     }
1622     else if (atp == SEQ_LOC_empty)
1623     {
1624         choice = SEQLOC_EMPTY;
1625         func = (AsnReadFunc) SeqIdAsnRead;
1626     }
1627     else if (atp == SEQ_LOC_whole)
1628     {
1629         choice = SEQLOC_WHOLE;
1630         func = (AsnReadFunc) SeqIdAsnRead;
1631     }
1632     else if (atp == SEQ_LOC_int)
1633     {
1634         choice = SEQLOC_INT;
1635         func = (AsnReadFunc) SeqIntAsnRead;
1636     }
1637     else if (atp == SEQ_LOC_packed_int)
1638     {
1639         choice = SEQLOC_PACKED_INT;
1640         func = (AsnReadFunc) PackSeqIntAsnRead;
1641     }
1642     else if (atp == SEQ_LOC_pnt)
1643     {
1644         choice = SEQLOC_PNT;
1645         func = (AsnReadFunc) SeqPntAsnRead;
1646     }
1647     else if (atp == SEQ_LOC_packed_pnt)
1648     {
1649         choice = SEQLOC_PACKED_PNT;
1650         func = (AsnReadFunc) PackSeqPntAsnRead;
1651     }
1652     else if (atp == SEQ_LOC_mix)
1653     {
1654         choice = SEQLOC_MIX;
1655         func = (AsnReadFunc) SeqLocMixAsnRead;
1656     }
1657     else if (atp == SEQ_LOC_equiv)
1658     {
1659         choice = SEQLOC_EQUIV;
1660         func = (AsnReadFunc) SeqLocEquivAsnRead;
1661     }
1662     else if (atp == SEQ_LOC_bond)
1663     {
1664         choice = SEQLOC_BOND;
1665         func = (AsnReadFunc) SeqBondAsnRead;
1666     }
1667     else if (atp == SEQ_LOC_feat)
1668     {
1669         choice = SEQLOC_FEAT;
1670         anp->data.ptrvalue = MemNew(sizeof(Choice));
1671         if (anp->data.ptrvalue == NULL)
1672             goto erret;
1673         if (! SeqFeatIdAsnRead(aip, atp, (ChoicePtr)anp->data.ptrvalue))
1674             goto erret;
1675     } else
1676         goto erret;
1677 
1678     anp->choice = choice;
1679     if (func != NULL)
1680     {
1681         anp->data.ptrvalue = (* func)(aip, atp);
1682         if (anp->data.ptrvalue == NULL)
1683             goto erret;
1684     }
1685 ret:
1686         AsnUnlinkType(orig);       /* unlink local tree */
1687         return anp;
1688 erret:
1689     anp = SeqLocFree(anp);
1690     goto ret;
1691 }
1692 
1693 /*****************************************************************************
1694 *
1695 *   SeqLocMixAsnWrite(anp, aip, atp)
1696 *       atp is the current type (if identifier of a parent struct)
1697 *       if atp == NULL, then assumes it stands alone (SeqLocMix ::=)
1698 *
1699 *****************************************************************************/
1700 NLM_EXTERN Boolean LIBCALL SeqLocMixAsnWrite (SeqLocPtr anp, AsnIoPtr aip, AsnTypePtr orig)
1701 {
1702         AsnTypePtr atp;
1703     Boolean retval = FALSE;
1704 
1705         if (! loaded)
1706         {
1707                 if (! SeqLocAsnLoad())
1708                         return FALSE;
1709         }
1710 
1711         if (aip == NULL)
1712                 return FALSE;
1713 
1714         atp = AsnLinkType(orig, SEQ_LOC_MIX);   /* link local tree */
1715     if (atp == NULL)
1716         return FALSE;
1717 
1718         if (anp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1719 
1720     retval = SeqLocSetAsnWrite(anp, aip, atp, SEQ_LOC_MIX_E);
1721 erret:
1722     AsnUnlinkType(orig);
1723     return retval;
1724 }
1725 
1726 /*****************************************************************************
1727 *
1728 *   SeqLocMixAsnRead(aip, atp)
1729 *       atp is the current type (if identifier of a parent struct)
1730 *            assumption is readIdent has occurred
1731 *       if atp == NULL, then assumes it stands alone and read ident
1732 *            has not occurred.
1733 *
1734 *****************************************************************************/
1735 NLM_EXTERN SeqLocPtr LIBCALL SeqLocMixAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1736 {
1737         AsnTypePtr atp;
1738     SeqLocPtr anp=NULL;
1739 
1740         if (! loaded)
1741         {
1742                 if (! SeqLocAsnLoad())
1743                         return anp;
1744         }
1745 
1746         if (aip == NULL)
1747                 return anp;
1748 
1749         if (orig == NULL)           /* Seq-loc-mix ::= (self contained) */
1750                 atp = AsnReadId(aip, amp, SEQ_LOC_MIX);
1751         else
1752                 atp = AsnLinkType(orig, SEQ_LOC_MIX);    /* link in local tree */
1753     if (atp == NULL)
1754         return anp;
1755     anp = SeqLocSetAsnRead(aip, atp, SEQ_LOC_MIX_E);
1756     AsnUnlinkType(orig);
1757     return anp;
1758 }
1759 
1760 /*****************************************************************************
1761 *
1762 *   SeqLocEquivAsnWrite(anp, aip, atp)
1763 *       atp is the current type (if identifier of a parent struct)
1764 *       if atp == NULL, then assumes it stands alone (SeqLocEquiv ::=)
1765 *
1766 *****************************************************************************/
1767 NLM_EXTERN Boolean LIBCALL SeqLocEquivAsnWrite (SeqLocPtr anp, AsnIoPtr aip, AsnTypePtr orig)
1768 {
1769         AsnTypePtr atp;
1770     Boolean retval = FALSE;
1771 
1772         if (! loaded)
1773         {
1774                 if (! SeqLocAsnLoad())
1775                         return FALSE;
1776         }
1777 
1778         if (aip == NULL)
1779                 return FALSE;
1780 
1781         atp = AsnLinkType(orig, SEQ_LOC_EQUIV);   /* link local tree */
1782     if (atp == NULL)
1783         return FALSE;
1784 
1785         if (anp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1786 
1787     retval = SeqLocSetAsnWrite(anp, aip, atp, SEQ_LOC_EQUIV_E);
1788 erret:
1789     AsnUnlinkType(orig);
1790     return retval;
1791 }
1792 
1793 /*****************************************************************************
1794 *
1795 *   SeqLocEquivAsnRead(aip, atp)
1796 *       atp is the current type (if identifier of a parent struct)
1797 *            assumption is readIdent has occurred
1798 *       if atp == NULL, then assumes it stands alone and read ident
1799 *            has not occurred.
1800 *
1801 *****************************************************************************/
1802 NLM_EXTERN SeqLocPtr LIBCALL SeqLocEquivAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1803 {
1804         AsnTypePtr atp;
1805     SeqLocPtr anp=NULL;
1806 
1807         if (! loaded)
1808         {
1809                 if (! SeqLocAsnLoad())
1810                         return anp;
1811         }
1812 
1813         if (aip == NULL)
1814                 return anp;
1815 
1816         if (orig == NULL)           /* Seq-loc-equiv ::= (self contained) */
1817                 atp = AsnReadId(aip, amp, SEQ_LOC_EQUIV);
1818         else
1819                 atp = AsnLinkType(orig, SEQ_LOC_EQUIV);    /* link in local tree */
1820     if (atp == NULL)
1821         return anp;
1822     anp = SeqLocSetAsnRead(aip, atp, SEQ_LOC_EQUIV_E);
1823     AsnUnlinkType(orig);
1824     return anp;
1825 }
1826 
1827 /*****************************************************************************
1828 *
1829 *   SeqLocSetAsnWrite(anp, aip, atp, set, element)
1830 *       atp is the current type (if identifier of a parent struct)
1831 *       if atp == NULL, then assumes it stands alone (SeqLocSet ::=)
1832 *
1833 *****************************************************************************/
1834 NLM_EXTERN Boolean LIBCALL SeqLocSetAsnWrite (SeqLocPtr anp, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
1835 {
1836     AsnTypePtr atp2;
1837         SeqLocPtr oldanp;
1838     Boolean retval = FALSE;
1839 
1840         if (! loaded)
1841         {
1842                 if (! SeqLocAsnLoad())
1843                         return FALSE;
1844         }
1845 
1846         if (aip == NULL)
1847                 return FALSE;
1848 
1849     atp2 = AsnLinkType(element, SEQ_LOC);
1850     if (atp2 == NULL)
1851         return FALSE;
1852 
1853         if (anp == NULL) { AsnNullValueMsg(aip, set); goto erret; }
1854 
1855         oldanp = anp;
1856     if (! AsnOpenStruct(aip, set, (Pointer)oldanp))
1857         goto erret;
1858     while (anp != NULL)
1859     {
1860         if (! SeqLocAsnWrite(anp, aip, atp2))
1861             goto erret;
1862         anp = anp->next;
1863     }
1864     if (! AsnCloseStruct(aip, set, (Pointer)oldanp))
1865         goto erret;
1866     retval = TRUE;
1867 erret:
1868     AsnUnlinkType(element);
1869         return retval;
1870 }
1871 
1872 /*****************************************************************************
1873 *
1874 *   SeqLocSetAsnRead(aip, atp, set, element)
1875 *       atp is the current type (if identifier of a parent struct)
1876 *            assumption is readIdent has occurred
1877 *       if atp == NULL, then assumes it stands alone and read ident
1878 *            has not occurred.
1879 *
1880 *****************************************************************************/
1881 NLM_EXTERN SeqLocPtr LIBCALL SeqLocSetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
1882 {
1883         DataVal av;
1884         AsnTypePtr atp, atp2;
1885     SeqLocPtr anp, first=NULL, prev;
1886 
1887         if (! loaded)
1888         {
1889                 if (! SeqLocAsnLoad())
1890                         return first;
1891         }
1892 
1893         if (aip == NULL)
1894                 return first;
1895 
1896     prev = NULL;
1897 
1898     atp2 = AsnLinkType(element, SEQ_LOC);
1899     if (atp2 == NULL)
1900         return first;
1901     atp = set;
1902         if (AsnReadVal(aip, atp, &av) <= 0)    /* read the START_STRUCT */
1903         goto erret;
1904     while ((atp = AsnReadId(aip, amp, atp)) != set)
1905     {
1906         if (atp == NULL)
1907             goto erret;
1908         anp = SeqLocAsnRead(aip, atp2);
1909         if (anp == NULL)
1910             goto erret;
1911         if (first == NULL)
1912             first = anp;
1913         else
1914             prev->next = anp;
1915         prev = anp;
1916     }
1917     if (AsnReadVal(aip, atp, &av) <= 0)      /* read END_STRUCT */
1918         goto erret;
1919         if (first == NULL)
1920                 ErrPost(CTX_NCBIOBJ, 1, "Empty SET OF Seq-loc.  line %ld", aip->linenumber);
1921 ret:
1922     AsnUnlinkType(element);
1923         return first;
1924 erret:
1925     aip->io_failure = TRUE;
1926     first = SeqLocSetFree(first);
1927     goto ret;
1928 }
1929 
1930 /*****************************************************************************
1931 *
1932 *   SeqLocSetFree(anp)
1933 *
1934 *****************************************************************************/
1935 NLM_EXTERN SeqLocPtr LIBCALL SeqLocSetFree (SeqLocPtr anp)
1936 {
1937     SeqLocPtr next;
1938 
1939     while (anp != NULL)
1940     {
1941         next = anp->next;
1942         SeqLocFree(anp);
1943         anp = next;
1944     }
1945     return anp;
1946 }
1947 
1948 /*****************************************************************************
1949 *
1950 *   SeqIntNew()
1951 *
1952 *****************************************************************************/
1953 NLM_EXTERN SeqIntPtr LIBCALL SeqIntNew (void)
1954 {
1955     return (SeqIntPtr)MemNew(sizeof(SeqInt));
1956 }
1957 
1958 /*****************************************************************************
1959 *
1960 *   SeqIntFree(sip)
1961 *       Frees one SeqInt if next == NULL
1962 *       or PackSeqInt if next != NULL
1963 *
1964 *****************************************************************************/
1965 NLM_EXTERN SeqIntPtr LIBCALL SeqIntFree (SeqIntPtr sip)
1966 {
1967     if (sip == NULL)
1968         return sip;
1969 
1970     IntFuzzFree(sip->if_from);
1971     IntFuzzFree(sip->if_to);
1972     SeqIdFree(sip->id);
1973     return (SeqIntPtr)MemFree(sip);
1974 }
1975 
1976 /*****************************************************************************
1977 *
1978 *   SeqIntAsnWrite(sip, aip, atp)
1979 *       atp is the current type (if identifier of a parent struct)
1980 *       if atp == NULL, then assumes it stands alone (SeqInt ::=)
1981 *
1982 *****************************************************************************/
1983 NLM_EXTERN Boolean LIBCALL SeqIntAsnWrite (SeqIntPtr sip, AsnIoPtr aip, AsnTypePtr orig)
1984 {
1985         DataVal av;
1986         AsnTypePtr atp;
1987     Boolean retval = FALSE;
1988 
1989         if (! loaded)
1990         {
1991                 if (! SeqLocAsnLoad())
1992                         return FALSE;
1993         }
1994 
1995         if (aip == NULL)
1996                 return FALSE;
1997 
1998         atp = AsnLinkType(orig, SEQ_INTERVAL);   /* link local tree */
1999     if (atp == NULL)
2000         goto erret;
2001 
2002         if (sip == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2003 
2004     if (! AsnOpenStruct(aip, atp, (Pointer)sip))
2005         goto erret;
2006     av.intvalue = sip->from;
2007     if (! AsnWrite(aip, SEQ_INTERVAL_from, &av))
2008         goto erret;
2009     av.intvalue = sip->to;
2010     if (! AsnWrite(aip, SEQ_INTERVAL_to, &av))
2011         goto erret;
2012     if (sip->strand)
2013     {
2014         av.intvalue = sip->strand;
2015         if (! AsnWrite(aip, SEQ_INTERVAL_strand, &av))
2016             goto erret;
2017     }
2018     if (sip->id != NULL)
2019     {
2020         if (! SeqIdAsnWrite(sip->id, aip, SEQ_INTERVAL_id))
2021             goto erret;
2022     }
2023     if (sip->if_from != NULL)
2024     {
2025         if (! IntFuzzAsnWrite(sip->if_from, aip, SEQ_INTERVAL_fuzz_from))
2026             goto erret;
2027     }
2028     if (sip->if_to != NULL)
2029     {
2030         if (! IntFuzzAsnWrite(sip->if_to, aip, SEQ_INTERVAL_fuzz_to))
2031             goto erret;
2032     }
2033     if (! AsnCloseStruct(aip, atp, (Pointer)sip))
2034         goto erret;
2035     retval = TRUE;
2036 erret:
2037         AsnUnlinkType(orig);       /* unlink local tree */
2038         return retval;
2039 }
2040 
2041 /*****************************************************************************
2042 *
2043 *   SeqIntAsnRead(aip, atp)
2044 *       atp is the current type (if identifier of a parent struct)
2045 *            assumption is readIdent has occurred
2046 *       if atp == NULL, then assumes it stands alone and read ident
2047 *            has not occurred.
2048 *
2049 *****************************************************************************/
2050 NLM_EXTERN SeqIntPtr LIBCALL SeqIntAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2051 {
2052         DataVal av;
2053         AsnTypePtr atp, oldtype;
2054     SeqIntPtr sip=NULL;
2055 
2056         if (! loaded)
2057         {
2058                 if (! SeqLocAsnLoad())
2059                         return sip;
2060         }
2061 
2062         if (aip == NULL)
2063                 return sip;
2064 
2065         if (orig == NULL)           /* SeqInt ::= (self contained) */
2066                 atp = AsnReadId(aip, amp, SEQ_INTERVAL);
2067         else
2068                 atp = AsnLinkType(orig, SEQ_INTERVAL);    /* link in local tree */
2069     oldtype = atp;
2070     if (atp == NULL)
2071         return sip;
2072 
2073         sip = SeqIntNew();
2074     if (sip == NULL)
2075         goto erret;
2076 
2077         if (AsnReadVal(aip, oldtype, &av) <= 0)    /* read the START_STRUCT */
2078         goto erret;
2079     atp = AsnReadId(aip, amp, atp);   /* read the from */
2080     if (atp == NULL)
2081         goto erret;
2082     if (AsnReadVal(aip, atp, &av) <= 0)
2083         goto erret;
2084     sip->from = av.intvalue;
2085     atp = AsnReadId(aip, amp, atp);   /* read the to */
2086     if (atp == NULL)
2087         goto erret;
2088     if (AsnReadVal(aip, atp, &av) <= 0)
2089         goto erret;
2090     sip->to = av.intvalue;
2091     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)  /* get options */
2092     {
2093         if (atp == NULL)
2094             goto erret;
2095         if (atp == SEQ_INTERVAL_strand)
2096         {
2097             if (AsnReadVal(aip, atp, &av) <= 0)
2098                 goto erret;
2099             sip->strand = (Uint1)av.intvalue;
2100         }
2101         else if (atp == SEQ_INTERVAL_id)
2102         {
2103             sip->id = SeqIdAsnRead(aip, atp);
2104             if (sip->id == NULL)
2105                 goto erret;
2106         }
2107         else if (atp == SEQ_INTERVAL_fuzz_from)
2108         {
2109             sip->if_from = IntFuzzAsnRead(aip, atp);
2110             if (sip->if_from == NULL)
2111                 goto erret;
2112         }
2113         else if (atp == SEQ_INTERVAL_fuzz_to)
2114         {
2115             sip->if_to = IntFuzzAsnRead(aip, atp);
2116             if (sip->if_to == NULL)
2117                 goto erret;
2118         }
2119     }
2120     if (AsnReadVal(aip, atp, &av) <= 0)      /* read END_STRUCT */
2121         goto erret;
2122 
2123 ret:
2124         AsnUnlinkType(orig);       /* unlink local tree */
2125         return sip;
2126 erret:
2127     sip = SeqIntFree(sip);
2128     goto ret;
2129 }
2130 
2131 /*****************************************************************************
2132 *
2133 *   PackSeqIntAsnWrite(sip, aip, atp)
2134 *       atp is the current type (if identifier of a parent struct)
2135 *       if atp == NULL, then assumes it stands alone (SeqInt ::=)
2136 *
2137 *****************************************************************************/
2138 NLM_EXTERN Boolean LIBCALL PackSeqIntAsnWrite (SeqLocPtr sip, AsnIoPtr aip, AsnTypePtr orig)
2139 {
2140         AsnTypePtr atp;
2141         SeqLocPtr oldsip;
2142     Boolean retval = FALSE;
2143 
2144         if (! loaded)
2145         {
2146                 if (! SeqLocAsnLoad())
2147                         return FALSE;
2148         }
2149 
2150         if (aip == NULL)
2151                 return FALSE;
2152 
2153         atp = AsnLinkType(orig, PACKED_SEQINT);   /* link local tree */
2154     if (atp == NULL)
2155         return FALSE;
2156         oldsip = sip;
2157 
2158         if (sip == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2159 
2160     if (! AsnOpenStruct(aip, atp, (Pointer)oldsip))
2161         goto erret;
2162         for ( ;sip != NULL; sip = sip->next)
2163         {
2164         if (! SeqIntAsnWrite((SeqIntPtr)sip->data.ptrvalue, aip,
2165                 PACKED_SEQINT_E))
2166             goto erret;
2167     }
2168     if (! AsnCloseStruct(aip, atp, (Pointer)oldsip))
2169         goto erret;
2170     retval = TRUE;
2171 erret:
2172         AsnUnlinkType(orig);       /* unlink local tree */
2173         return retval;
2174 }
2175 
2176 /*****************************************************************************
2177 *
2178 *   PackSeqIntAsnRead(aip, atp)
2179 *       atp is the current type (if identifier of a parent struct)
2180 *            assumption is readIdent has occurred
2181 *       if atp == NULL, then assumes it stands alone and read ident
2182 *            has not occurred.
2183 *
2184 *****************************************************************************/
2185 NLM_EXTERN SeqLocPtr LIBCALL PackSeqIntAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2186 {
2187         DataVal av;
2188         AsnTypePtr atp, oldtype;
2189         SeqLocPtr head = NULL, now = NULL;
2190 
2191         if (! loaded)
2192         {
2193                 if (! SeqLocAsnLoad())
2194                         return head;
2195         }
2196 
2197         if (aip == NULL)
2198                 return head;
2199 
2200         if (orig == NULL)           /* SeqInt ::= (self contained) */
2201                 atp = AsnReadId(aip, amp, PACKED_SEQINT);
2202         else
2203                 atp = AsnLinkType(orig, PACKED_SEQINT);    /* link in local tree */
2204     oldtype = atp;
2205     if (atp == NULL)
2206         return head;
2207         
2208     if (AsnReadVal(aip, oldtype, &av) <= 0)    /* read the START_STRUCT */
2209         goto erret;
2210     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)  /* get options */
2211     {
2212             if (atp == NULL)
2213                 goto erret;
2214                         now = ValNodeNew(now);
2215             if (now == NULL)
2216                 goto erret;
2217                         if ( ! head)
2218                                 head = now;
2219                         now -> choice = 4;
2220                         now -> data.ptrvalue =  SeqIntAsnRead(aip, atp);
2221             if (now->data.ptrvalue == NULL)
2222                 goto erret;
2223     }
2224     if (AsnReadVal(aip, atp, &av) <= 0)      /* read END_STRUCT */
2225         goto erret;
2226 ret:
2227         AsnUnlinkType(orig);       /* unlink local tree */
2228         return head;
2229 erret:
2230     head = SeqLocFree(head);
2231     goto ret;
2232 }
2233 
2234 /*****************************************************************************
2235 *
2236 *   SeqPntNew()
2237 *
2238 *****************************************************************************/
2239 NLM_EXTERN SeqPntPtr LIBCALL SeqPntNew (void)
2240 {
2241     return (SeqPntPtr)MemNew(sizeof(SeqPnt));
2242 }
2243 
2244 /*****************************************************************************
2245 *
2246 *   SeqPntFree(spp)
2247 *       Frees one SeqPnt if next == NULL
2248 *       or PackSeqPnt if next != NULL
2249 *
2250 *****************************************************************************/
2251 NLM_EXTERN SeqPntPtr LIBCALL SeqPntFree (SeqPntPtr spp)
2252 {
2253     if (spp == NULL)
2254         return spp;
2255 
2256     IntFuzzFree(spp->fuzz);
2257     SeqIdFree(spp->id);
2258     return (SeqPntPtr)MemFree(spp);
2259 }
2260 
2261 /*****************************************************************************
2262 *
2263 *   SeqPntAsnWrite(spp, aip, atp)
2264 *       atp is the current type (if identifier of a parent struct)
2265 *       if atp == NULL, then assumes it stands alone (SeqPnt ::=)
2266 *
2267 *****************************************************************************/
2268 NLM_EXTERN Boolean LIBCALL SeqPntAsnWrite (SeqPntPtr spp, AsnIoPtr aip, AsnTypePtr orig)
2269 {
2270         DataVal av;
2271         AsnTypePtr atp;
2272     Boolean retval = FALSE;
2273 
2274         if (! loaded)
2275         {
2276                 if (! SeqLocAsnLoad())
2277                         return FALSE;
2278         }
2279 
2280         if (aip == NULL)
2281                 return FALSE;
2282 
2283         atp = AsnLinkType(orig, SEQ_POINT);   /* link local tree */
2284     if (atp == NULL)
2285         goto erret;
2286 
2287         if (spp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2288 
2289     if (! AsnOpenStruct(aip, atp, (Pointer)spp))
2290         goto erret;
2291     av.intvalue = spp->point;
2292     if (! AsnWrite(aip, SEQ_POINT_point, &av))
2293         goto erret;
2294     if (spp->strand)
2295     {
2296         av.intvalue = spp->strand;
2297         if (! AsnWrite(aip, SEQ_POINT_strand, &av))
2298             goto erret;
2299     }
2300     if (spp->id != NULL)
2301     {
2302         if (! SeqIdAsnWrite(spp->id, aip, SEQ_POINT_id))
2303             goto erret;
2304     }
2305     if (spp->fuzz != NULL)
2306     {
2307         if (! IntFuzzAsnWrite(spp->fuzz, aip, SEQ_POINT_fuzz))
2308             goto erret;
2309     }
2310     if (! AsnCloseStruct(aip, atp, (Pointer)spp))
2311         goto erret;
2312     retval = TRUE;
2313 erret:
2314         AsnUnlinkType(orig);       /* unlink local tree */
2315         return retval;
2316 }
2317 
2318 /*****************************************************************************
2319 *
2320 *   SeqPntAsnRead(aip, atp)
2321 *       atp is the current type (if identifier of a parent struct)
2322 *            assumption is readIdent has occurred
2323 *       if atp == NULL, then assumes it stands alone and read ident
2324 *            has not occurred.
2325 *
2326 *****************************************************************************/
2327 NLM_EXTERN SeqPntPtr LIBCALL SeqPntAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2328 {
2329         DataVal av;
2330         AsnTypePtr atp, oldtype;
2331     SeqPntPtr spp=NULL;
2332 
2333         if (! loaded)
2334         {
2335                 if (! SeqLocAsnLoad())
2336                         return spp;
2337         }
2338 
2339         if (aip == NULL)
2340                 return spp;
2341 
2342         if (orig == NULL)           /* SeqPnt ::= (self contained) */
2343                 atp = AsnReadId(aip, amp, SEQ_POINT);
2344         else
2345                 atp = AsnLinkType(orig, SEQ_POINT);    /* link in local tree */
2346     oldtype = atp;
2347     if (atp == NULL)
2348         return spp;
2349 
2350         spp = SeqPntNew();
2351     if (spp == NULL)
2352         goto erret;
2353 
2354         if (AsnReadVal(aip, oldtype, &av) <= 0)    /* read the START_STRUCT */
2355         goto erret;
2356     atp = AsnReadId(aip, amp, atp);   /* read the point */
2357     if (atp == NULL)
2358         goto erret;
2359     if (AsnReadVal(aip, atp, &av) <= 0)
2360         goto erret;
2361     spp->point = av.intvalue;
2362     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)  /* get options */
2363     {
2364         if (atp == NULL)
2365             goto erret;
2366         if (atp == SEQ_POINT_strand)
2367         {
2368             if (AsnReadVal(aip, atp, &av) <= 0)
2369                 goto erret;
2370             spp->strand = (Uint1)av.intvalue;
2371         }
2372         else if (atp == SEQ_POINT_id)
2373         {
2374             spp->id = SeqIdAsnRead(aip, atp);
2375             if (spp->id == NULL)
2376                 goto erret;
2377         }
2378         else if (atp == SEQ_POINT_fuzz)
2379         {
2380             spp->fuzz = IntFuzzAsnRead(aip, atp);
2381             if (spp->fuzz == NULL)
2382                 goto erret;
2383         }
2384     }
2385     if (AsnReadVal(aip, atp, &av) <= 0)      /* read END_STRUCT */
2386         goto erret;
2387 
2388 ret:
2389         AsnUnlinkType(orig);       /* unlink local tree */
2390         return spp;
2391 erret:
2392     spp = SeqPntFree(spp);
2393     goto ret;
2394 }
2395 
2396 /*****************************************************************************
2397 *
2398 *   PackSeqPntNew()
2399 *
2400 *****************************************************************************/
2401 NLM_EXTERN PackSeqPntPtr LIBCALL PackSeqPntNew (void)
2402 {
2403     return (PackSeqPntPtr)MemNew(sizeof(PackSeqPnt));
2404 }
2405 
2406 /*****************************************************************************
2407 *
2408 *   PackSeqPntFree(pspp)
2409 *       Frees one PackSeqPnt if next == NULL
2410 *       or PackPackSeqPnt if next != NULL
2411 *
2412 *****************************************************************************/
2413 NLM_EXTERN PackSeqPntPtr LIBCALL PackSeqPntFree (PackSeqPntPtr pspp)
2414 {
2415     PackSeqPntPtr next;
2416 
2417     while (pspp != NULL)
2418     {
2419         next = pspp->next;
2420         IntFuzzFree(pspp->fuzz);
2421         SeqIdFree(pspp->id);
2422         MemFree(pspp);
2423         pspp = next;
2424     }
2425     return pspp;
2426 }
2427 
2428 /*****************************************************************************
2429 *
2430 *   PackSeqPntAsnWrite(pspp, aip, atp)
2431 *       atp is the current type (if identifier of a parent struct)
2432 *       if atp == NULL, then assumes it stands alone (PackSeqPnt ::=)
2433 *
2434 *****************************************************************************/
2435 NLM_EXTERN Boolean LIBCALL PackSeqPntAsnWrite (PackSeqPntPtr pspp, AsnIoPtr aip, AsnTypePtr orig)
2436 {
2437         DataVal av;
2438         AsnTypePtr atp;
2439     Int4 num, index;
2440     Boolean retval = FALSE;
2441 
2442         if (! loaded)
2443         {
2444                 if (! SeqLocAsnLoad())
2445                         return FALSE;
2446         }
2447 
2448         if (aip == NULL)
2449                 return FALSE;
2450 
2451         atp = AsnLinkType(orig, PACKED_SEQPNT);   /* link local tree */
2452     if (atp == NULL)
2453         return FALSE;
2454 
2455         if (pspp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2456 
2457     if (! AsnOpenStruct(aip, atp, (Pointer)pspp))
2458         goto erret;
2459     if (pspp->strand)
2460     {
2461         av.intvalue = pspp->strand;
2462         if (! AsnWrite(aip, PACKED_SEQPNT_strand, &av))
2463             goto erret;
2464     }
2465     if (pspp->id != NULL)
2466     {
2467         if (! SeqIdAsnWrite(pspp->id, aip, PACKED_SEQPNT_id))
2468             goto erret;
2469     }
2470     if (pspp->fuzz != NULL)
2471     {
2472         if (! IntFuzzAsnWrite(pspp->fuzz, aip, PACKED_SEQPNT_fuzz))
2473             goto erret;
2474     }
2475     if (! AsnOpenStruct(aip, PACKED_SEQPNT_points, (Pointer)pspp))
2476         goto erret;
2477     num = PackSeqPntNum(pspp);   /* total number of points */
2478     for (index = 0; index < num; index++)
2479     {
2480         av.intvalue = PackSeqPntGet(pspp, index);
2481 
2482         if (! AsnWrite(aip, PACKED_SEQPNT_points_E, &av))
2483             goto erret;
2484     }
2485     if (! AsnCloseStruct(aip, PACKED_SEQPNT_points, (Pointer)pspp))
2486         goto erret;
2487     if (! AsnCloseStruct(aip, atp, (Pointer)pspp))
2488         goto erret;
2489     retval = TRUE;
2490 erret:
2491         AsnUnlinkType(orig);       /* unlink local tree */
2492         return retval;
2493 }
2494 
2495 /*****************************************************************************
2496 *
2497 *   PackSeqPntAsnRead(aip, atp)
2498 *       atp is the current type (if identifier of a parent struct)
2499 *            assumption is readIdent has occurred
2500 *       if atp == NULL, then assumes it stands alone and read ident
2501 *            has not occurred.
2502 *
2503 *****************************************************************************/
2504 NLM_EXTERN PackSeqPntPtr LIBCALL PackSeqPntAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2505 {
2506         DataVal av;
2507         AsnTypePtr atp, oldtype;
2508     PackSeqPntPtr pspp=NULL;
2509 
2510         if (! loaded)
2511         {
2512                 if (! SeqLocAsnLoad())
2513                         return pspp;
2514         }
2515 
2516         if (aip == NULL)
2517                 return pspp;
2518 
2519         if (orig == NULL)           /* PackSeqPnt ::= (self contained) */
2520                 atp = AsnReadId(aip, amp, PACKED_SEQPNT);
2521         else
2522                 atp = AsnLinkType(orig, PACKED_SEQPNT);    /* link in local tree */
2523     oldtype = atp;
2524     if (atp == NULL)
2525         return pspp;
2526 
2527         pspp = PackSeqPntNew();
2528     if (pspp == NULL)
2529         goto erret;
2530 
2531         if (AsnReadVal(aip, oldtype, &av) <= 0)    /* read the START_STRUCT */
2532         goto erret;
2533     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)  /* get options */
2534     {
2535         if (atp == NULL)
2536             goto erret;
2537         if (atp == PACKED_SEQPNT_strand)
2538         {
2539             if (AsnReadVal(aip, atp, &av) <= 0)
2540                 goto erret;
2541             pspp->strand = (Uint1)av.intvalue;
2542         }
2543         else if (atp == PACKED_SEQPNT_id)
2544         {
2545             pspp->id = SeqIdAsnRead(aip, atp);
2546             if (pspp->id == NULL)
2547                 goto erret;
2548         }
2549         else if (atp == PACKED_SEQPNT_fuzz)
2550         {
2551             pspp->fuzz = IntFuzzAsnRead(aip, atp);
2552             if (pspp->fuzz == NULL)
2553                 goto erret;
2554         }
2555         else if (atp == PACKED_SEQPNT_points)
2556         {
2557             if (AsnReadVal(aip, atp, &av) <= 0)   /* start struct */
2558                 goto erret;
2559             while ((atp = AsnReadId(aip, amp, atp)) == PACKED_SEQPNT_points_E)
2560             {
2561                 if (AsnReadVal(aip, atp, &av) <= 0)
2562                     goto erret;
2563 
2564                 if (! PackSeqPntPut(pspp, av.intvalue))
2565                     goto erret;
2566             }
2567             if (atp == NULL)
2568                  goto erret;
2569             if (AsnReadVal(aip, atp, &av) <= 0)   /* end struct */
2570                 goto erret;
2571         }
2572     }
2573     if (AsnReadVal(aip, atp, &av) <= 0)      /* read END_STRUCT */
2574         goto erret;
2575 ret:
2576         AsnUnlinkType(orig);       /* unlink local tree */
2577         return pspp;
2578 erret:
2579     pspp = PackSeqPntFree(pspp);
2580     goto ret;
2581 }
2582 
2583 /*****************************************************************************
2584 *
2585 *   PackSeqPntNum(pspp)
2586 *
2587 *****************************************************************************/
2588 NLM_EXTERN Int4 LIBCALL PackSeqPntNum (PackSeqPntPtr pspp)
2589 {
2590     Int4 num = 0;
2591     while (pspp != NULL)
2592     {
2593         num += pspp->used;
2594         pspp = pspp->next;
2595     }
2596     return num;
2597 }
2598 
2599 /*****************************************************************************
2600 *
2601 *   PackSeqPntGet(pspp, index)
2602 *       returns point at index, or -1 if index out of range
2603 *
2604 *****************************************************************************/
2605 NLM_EXTERN Int4 LIBCALL PackSeqPntGet (PackSeqPntPtr pspp, Int4 index)
2606 {
2607     Int4 num = 0;
2608     if (index < 0)
2609         return -1;
2610 
2611     while (pspp != NULL)
2612     {
2613         if (index < (Int4) (num + (pspp->used)))
2614             return pspp->pnts[index - num];
2615         num += pspp->used;
2616         pspp = pspp->next;
2617     }
2618     return -1;
2619 }
2620 
2621 /*****************************************************************************
2622 *
2623 *   PackSeqPntPut(pspp, point)
2624 *       adds to end of list
2625 *
2626 *****************************************************************************/
2627 NLM_EXTERN Boolean LIBCALL PackSeqPntPut (PackSeqPntPtr pspp, Int4 point)
2628 {
2629     if ((pspp == NULL) || (point < 0))
2630         return FALSE;
2631 
2632     while (pspp->next != NULL)
2633         pspp = pspp->next;
2634 
2635     if (pspp->used == PACK_PNT_NUM)   /* full */
2636     {
2637         pspp->next = PackSeqPntNew();
2638         if (pspp->next == NULL)
2639             return FALSE;
2640         pspp = pspp->next;
2641     }
2642     pspp->pnts[pspp->used] = point;
2643     pspp->used++;
2644     return TRUE;
2645 }
2646 
2647 /*****************************************************************************
2648 *
2649 *   SeqBondNew()
2650 *
2651 *****************************************************************************/
2652 NLM_EXTERN SeqBondPtr LIBCALL SeqBondNew (void)
2653 {
2654     return (SeqBondPtr)MemNew(sizeof(SeqBond));
2655 }
2656 
2657 /*****************************************************************************
2658 *
2659 *   SeqBondFree(sbp)
2660 *       Frees one SeqBond
2661 *
2662 *****************************************************************************/
2663 NLM_EXTERN SeqBondPtr LIBCALL SeqBondFree (SeqBondPtr sbp)
2664 {
2665     if (sbp == NULL)
2666         return sbp;
2667     
2668     SeqPntFree(sbp->a);
2669     SeqPntFree(sbp->b);
2670     return (SeqBondPtr)MemFree(sbp);
2671 }
2672 
2673 /*****************************************************************************
2674 *
2675 *   SeqBondAsnWrite(sbp, aip, atp)
2676 *       atp is the current type (if identifier of a parent struct)
2677 *       if atp == NULL, then assumes it stands alone (SeqBond ::=)
2678 *
2679 *****************************************************************************/
2680 NLM_EXTERN Boolean LIBCALL SeqBondAsnWrite (SeqBondPtr sbp, AsnIoPtr aip, AsnTypePtr orig)
2681 {
2682         AsnTypePtr atp;
2683     Boolean retval = FALSE;
2684 
2685         if (! loaded)
2686         {
2687                 if (! SeqLocAsnLoad())
2688                         return FALSE;
2689         }
2690 
2691         if (aip == NULL)
2692                 return FALSE;
2693 
2694         atp = AsnLinkType(orig, SEQ_BOND);   /* link local tree */
2695     if (atp == NULL)
2696         return FALSE;
2697 
2698         if (sbp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2699 
2700     if (! AsnOpenStruct(aip, atp, (Pointer)sbp))
2701         goto erret;
2702     if (! SeqPntAsnWrite(sbp->a, aip, SEQ_BOND_a))
2703         goto erret;
2704     if (sbp->b != NULL)
2705     {
2706         if (! SeqPntAsnWrite(sbp->b, aip, SEQ_BOND_b))
2707             goto erret;
2708     }
2709     if (! AsnCloseStruct(aip, atp, (Pointer)sbp))
2710         goto erret;
2711     retval = TRUE;
2712 erret:
2713         AsnUnlinkType(orig);       /* unlink local tree */
2714         return retval;
2715 }
2716 
2717 /*****************************************************************************
2718 *
2719 *   SeqBondAsnRead(aip, atp)
2720 *       atp is the current type (if identifier of a parent struct)
2721 *            assumption is readIdent has occurred
2722 *       if atp == NULL, then assumes it stands alone and read ident
2723 *            has not occurred.
2724 *
2725 *****************************************************************************/
2726 NLM_EXTERN SeqBondPtr LIBCALL SeqBondAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2727 {
2728         DataVal av;
2729         AsnTypePtr atp, oldtype;
2730     SeqBondPtr sbp=NULL;
2731     SeqPntPtr tmp;
2732 
2733         if (! loaded)
2734         {
2735                 if (! SeqLocAsnLoad())
2736                         return sbp;
2737         }
2738 
2739         if (aip == NULL)
2740                 return sbp;
2741 
2742         if (orig == NULL)           /* SeqBond ::= (self contained) */
2743                 atp = AsnReadId(aip, amp, SEQ_BOND);
2744         else
2745                 atp = AsnLinkType(orig, SEQ_BOND);    /* link in local tree */
2746     oldtype = atp;
2747     if (atp == NULL)
2748         return sbp;
2749 
2750         sbp = SeqBondNew();
2751     if (sbp == NULL)
2752         goto erret;
2753 
2754         if (AsnReadVal(aip, oldtype, &av) <= 0)    /* read the START_STRUCT */
2755         goto erret;
2756     while ((atp = AsnReadId(aip, amp, atp)) != oldtype)  /* get options */
2757     {
2758         if (atp == NULL)
2759             goto erret;
2760         tmp = SeqPntAsnRead(aip, atp);
2761         if (tmp == NULL)
2762             goto erret;
2763         if (atp == SEQ_BOND_a)
2764             sbp->a = tmp;
2765         else
2766             sbp->b = tmp;
2767     }
2768     if (AsnReadVal(aip, atp, &av) <= 0)      /* read END_STRUCT */
2769         goto erret;
2770 ret:
2771         AsnUnlinkType(orig);       /* unlink local tree */
2772         return sbp;
2773 erret:
2774     sbp = SeqBondFree(sbp);
2775     goto ret;
2776 }
2777 
2778 

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.