|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/object/objalign.c |
source navigation diff markup identifier search freetext search file search |
1 /* objalign.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name: objalign.c
27 *
28 * Author: James Ostell
29 *
30 * Version Creation Date: 4/1/91
31 *
32 * $Revision: 6.17 $
33 *
34 * File Description: Object manager for module NCBI-Seqalign
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 * 05-13-93 Schuler All public functions are now declared LIBCALL.
41 *
42 * $Log: objalign.c,v
43 * Revision 4.1 1995/09/21 02:26:14 ostel
44 * added ProgMon call
45 *
46 * Revision 4.0 1995/07/26 13:48:06 ostell
47 * force revision to 4.0
48 *
49 * Revision 3.10 1995/07/25 01:00:07 ostell
50 * added checks to strip asn1 spec 4.0 objects on demand
51 *
52 * Revision 3.9 1995/07/22 21:59:13 ostell
53 * added support for ASN.1 spec 4.0
54 *
55 * Revision 3.8 1995/06/27 17:35:03 epstein
56 * add missing return values to new Seq-align-set functions
57 *
58 * Revision 3.7 95/06/21 17:17:46 epstein
59 * add Seq-align-set
60 *
61 * Revision 3.6 95/05/15 21:22:00 ostell
62 * added Log line
63 *
64 *
65 *
66 *
67 * ==========================================================================
68 */
69 #include <objalign.h> /* the align interface */
70 #include <asnalign.h> /* the AsnTool header */
71 #include <objmgr.h> /* object manager interface */
72 #include <sequtil.h>
73
74 static Boolean loaded = FALSE;
75 static CharPtr seqaligntypelabel = "SeqAlign",
76 seqhistaligntypelabel = "SeqHistAlign";
77
78 static ScorePtr InternalScoreSetAsnRead (AsnIoPtr aip, AsnTypePtr settype, AsnTypePtr elementtype);
79 static Boolean InternalScoreSetAsnWrite (ScorePtr sp, AsnIoPtr aip, AsnTypePtr settype, AsnTypePtr elementtype);
80 /* this is really an internal type at the moment */
81 NLM_EXTERN Int2 LIBCALL SeqHistAlignLabel PROTO((SeqAlignPtr sap, CharPtr buffer, Int2 buflen, Uint1 content));
82
83 /*****************************************************************************
84 *
85 * SeqAlign ObjMgr Routines
86 *
87 *****************************************************************************/
88 static Int2 NEAR SeqAlignLabelContent (SeqAlignPtr sap, CharPtr buf, Int2 buflen, Uint1 labeltype, CharPtr typelabel)
89
90 {
91 Char label [90];
92 Char str [40];
93 Int2 j;
94 DenseDiagPtr ddp;
95 DenseSegPtr dsp;
96 StdSegPtr ssp;
97 SeqIdPtr sip;
98 SeqLocPtr slp;
99
100 if (sap == NULL) return 0;
101
102 label [0] = '\0';
103 switch (sap->segtype) {
104 case 1 :
105 ddp = (DenseDiagPtr) sap->segs;
106 if (ddp != NULL) {
107 for (sip = ddp->id, j = 0; sip != NULL && j < 2; sip = sip->next, j++) {
108 SeqIdWrite (sip, str, PRINTID_FASTA_SHORT, sizeof (str));
109 if (j > 0) {
110 StringCat (label, ",");
111 }
112 StringCat (label, str);
113 }
114 if (sip != NULL) {
115 StringCat (label, ",...");
116 }
117 }
118 break;
119 case 2 :
120 dsp = (DenseSegPtr) sap->segs;
121 if (dsp != NULL) {
122 for (sip = dsp->ids, j = 0; sip != NULL && j < 2; sip = sip->next, j++) {
123 SeqIdWrite (sip, str, PRINTID_FASTA_SHORT, sizeof (str));
124 if (j > 0) {
125 StringCat (label, ",");
126 }
127 StringCat (label, str);
128 }
129 if (sip != NULL) {
130 StringCat (label, ",...");
131 }
132 }
133 break;
134 case 3 :
135 ssp = (StdSegPtr) sap->segs;
136 if (ssp != NULL && ssp->loc != NULL) {
137 for (slp = ssp->loc, j = 0; slp != NULL && j < 2; slp = slp->next, j++) {
138 sip = SeqLocId (slp);
139 SeqIdWrite (sip, str, PRINTID_FASTA_SHORT, sizeof (str));
140 if (j > 0) {
141 StringCat (label, ",");
142 }
143 StringCat (label, str);
144 }
145 if (slp != NULL) {
146 StringCat (label, ",...");
147 }
148 }
149 break;
150 default :
151 break;
152 }
153
154 return LabelCopyExtra (buf, label, buflen, NULL, NULL);
155 }
156
157 static Int2 NEAR CommonSeqAlignLabelFunc (SeqAlignPtr sap, CharPtr buf, Int2 buflen, Uint1 labeltype, CharPtr prefix)
158
159 {
160 Int2 len, diff;
161 CharPtr curr, typelabel, tmp;
162 Char tbuf[40];
163 CharPtr suffix = NULL;
164
165 if ((sap == NULL) || (buf == NULL) || (buflen < 1))
166 return 0;
167
168 buf[0] = '\0';
169 curr = buf;
170 len = buflen;
171
172 tmp = StringMove(tbuf, prefix);
173 typelabel = tbuf;
174
175 if ((labeltype == OM_LABEL_TYPE) || (labeltype == OM_LABEL_BOTH))
176 {
177 if (labeltype == OM_LABEL_BOTH)
178 suffix = ": ";
179 else
180 suffix = NULL;
181
182 diff = LabelCopyExtra(curr, typelabel, buflen, NULL, suffix);
183 curr += diff;
184 buflen -= diff;
185 }
186
187 if ((labeltype == OM_LABEL_TYPE) || (! buflen))
188 return (len - buflen);
189
190 diff = SeqAlignLabelContent (sap, curr, buflen, labeltype, typelabel);
191 buflen -= diff;
192
193 if ((! diff) && (labeltype == OM_LABEL_CONTENT))
194 {
195 buflen -= LabelCopy(curr, typelabel, buflen);
196 }
197
198 return (len - buflen);
199 }
200
201 static Pointer LIBCALLBACK SeqAlignNewFunc (void)
202 {
203 return (Pointer) SeqAlignNew();
204 }
205
206 static Pointer LIBCALLBACK SeqAlignFreeFunc (Pointer data)
207 {
208 return (Pointer) SeqAlignFree ((SeqAlignPtr) data);
209 }
210
211 static Boolean LIBCALLBACK SeqAlignAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
212 {
213 return SeqAlignAsnWrite((SeqAlignPtr)data, aip, atp);
214 }
215
216 static Pointer LIBCALLBACK SeqAlignAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
217 {
218 return (Pointer) SeqAlignAsnRead (aip, atp);
219 }
220
221 static Int2 LIBCALLBACK SeqAlignLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
222 {
223 return SeqAlignLabel((SeqAlignPtr)data, buffer, buflen, content);
224 }
225
226 NLM_EXTERN Int2 LIBCALL SeqAlignLabel (SeqAlignPtr sap, CharPtr buffer, Int2 buflen, Uint1 content)
227 {
228 return CommonSeqAlignLabelFunc (sap, buffer, buflen, content, seqaligntypelabel);
229 }
230
231
232 static Int2 LIBCALLBACK SeqHistAlignLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
233 {
234 return SeqHistAlignLabel((SeqAlignPtr)data, buffer, buflen, content);
235 }
236
237 NLM_EXTERN Int2 LIBCALL SeqHistAlignLabel (SeqAlignPtr sap, CharPtr buffer, Int2 buflen, Uint1 content)
238 {
239 return CommonSeqAlignLabelFunc (sap, buffer, buflen, content, seqhistaligntypelabel);
240 }
241
242 static Uint2 LIBCALLBACK SeqAlignSubTypeFunc (Pointer ptr)
243 {
244 if (ptr == NULL)
245 return 0;
246 return (Uint2)((SeqAlignPtr)ptr)->type;
247 }
248
249 /*****************************************************************************
250 *
251 * SeqAlignAsnLoad()
252 *
253 *****************************************************************************/
254 NLM_EXTERN Boolean LIBCALL SeqAlignAsnLoad (void)
255 {
256 if (loaded)
257 return TRUE;
258 loaded = TRUE;
259
260 if (! GeneralAsnLoad())
261 {
262 loaded = FALSE;
263 return FALSE;
264 }
265 if (! SeqLocAsnLoad())
266 {
267 loaded = FALSE;
268 return FALSE;
269 }
270 if (! AsnLoad())
271 {
272 loaded = FALSE;
273 return FALSE;
274 }
275
276 ObjMgrTypeLoad(OBJ_SEQALIGN, "Seq-align", seqaligntypelabel, "Sequence Alignment",
277 SEQ_ALIGN, SeqAlignNewFunc, SeqAlignAsnReadFunc, SeqAlignAsnWriteFunc,
278 SeqAlignFreeFunc, SeqAlignLabelFunc, SeqAlignSubTypeFunc);
279
280
281 ObjMgrTypeLoad(OBJ_SEQHIST_ALIGN, "Seq-align", seqhistaligntypelabel, "Sequence History Alignment",
282 SEQ_ALIGN, SeqAlignNewFunc, SeqAlignAsnReadFunc, SeqAlignAsnWriteFunc,
283 SeqAlignFreeFunc, SeqHistAlignLabelFunc, SeqAlignSubTypeFunc);
284
285 return TRUE;
286 }
287
288 /*****************************************************************************
289 *
290 * SeqAlign Routines
291 *
292 *****************************************************************************/
293 NLM_EXTERN SeqAlignIndexPtr LIBCALL SeqAlignIndexFree (SeqAlignIndexPtr saip)
294 {
295 Boolean retval;
296 VoidPtr ptr;
297 SeqAlignIndexPtr tmp = NULL;
298
299 if (saip == NULL)
300 return saip;
301
302 if (saip->freefunc != NULL)
303 {
304 ptr = (VoidPtr)(saip);
305 retval = (*(saip->freefunc))(ptr);
306 if (! retval)
307 ErrPostEx(SEV_ERROR,0,0,"SeqAlignFreeFunc: saip->freefunc returned FALSE");
308 return tmp;
309 }
310
311 ErrPostEx(SEV_ERROR,0,0,"SeqAlignIndexFree: saip lacking a freefunc");
312
313 return tmp;
314 }
315
316 /*****************************************************************************
317 *
318 * SeqAlignNew()
319 *
320 *****************************************************************************/
321 NLM_EXTERN SeqAlignPtr LIBCALL SeqAlignNew (void)
322 {
323 return (SeqAlignPtr)MemNew(sizeof(SeqAlign));
324 }
325 /*****************************************************************************
326 *
327 * SeqAlignFree(sap)
328 * Frees one SeqAlign and associated data
329 *
330 *****************************************************************************/
331 NLM_EXTERN SeqAlignPtr LIBCALL SeqAlignFree (SeqAlignPtr sap)
332 {
333 DenseDiagPtr ddp, ddpnext;
334 StdSegPtr ssp, sspnext;
335 ValNodePtr anp, next;
336 UserObjectPtr uopa, uopb;
337
338 if (sap == NULL)
339 return (SeqAlignPtr)NULL;
340
341 sap->saip = SeqAlignIndexFree (sap->saip); /* free index elements */
342
343 switch (sap->segtype)
344 {
345 case 1: /* dendiag */
346 ddpnext = NULL;
347 for (ddp = (DenseDiagPtr)(sap->segs); ddp != NULL; ddp = ddpnext)
348 {
349 ddpnext = ddp->next;
350 DenseDiagFree(ddp);
351 }
352 break;
353 case 2: /* denseg */
354 DenseSegFree((DenseSegPtr)sap->segs);
355 break;
356 case 3: /* std-seg */
357 sspnext = NULL;
358 for (ssp = (StdSegPtr)(sap->segs); ssp !=NULL; ssp = sspnext)
359 {
360 sspnext = ssp->next;
361 StdSegFree(ssp);
362 }
363 break;
364 case 4: /* packseg */
365 PackSegFree((PackSegPtr)sap->segs);
366 break;
367 case 5: /* disc */
368 SeqAlignSetFree((SeqAlignPtr)sap->segs);
369 break;
370 case 6: /* spliced */
371 SplicedSegFree((SplicedSegPtr)sap->segs);
372 break;
373 case 7: /* sparse */
374 SparseSegFree((SparseSegPtr)sap->segs);
375 break;
376 }
377 ScoreSetFree(sap->score);
378 anp = sap->id;
379 while (anp != NULL) {
380 next = anp->next;
381 ObjectIdFree((ObjectIdPtr)anp->data.ptrvalue);
382 MemFree(anp);
383 anp = next;
384 }
385 /*
386 AsnGenericChoiceSeqOfFree(sap -> id, (AsnOptFreeFunc) ObjectIdFree);
387 */
388 uopa = (UserObjectPtr) sap->ext;
389 while (uopa != NULL) {
390 uopb = uopa->next;
391 uopa->next = NULL;
392 UserObjectFree (uopa);
393 uopa = uopb;
394 }
395 /*
396 AsnGenericUserSeqOfFree(sap -> ext, (AsnOptFreeFunc) UserObjectFree);
397 */
398 SeqLocSetFree(sap->bounds);
399 SeqIdFree(sap->master);
400
401 ObjMgrDelete(OBJ_SEQALIGN, (Pointer)sap);
402
403 return (SeqAlignPtr)MemFree(sap);
404 }
405
406 /*****************************************************************************
407 *
408 * SeqAlignAsnWrite(sap, aip, atp)
409 * atp is the current type (if identifier of a parent struct)
410 * if atp == NULL, then assumes it stands alone (SeqAlign ::=)
411 *
412 *****************************************************************************/
413 NLM_EXTERN Boolean LIBCALL SeqAlignAsnWrite (SeqAlignPtr sap, AsnIoPtr aip, AsnTypePtr orig)
414 {
415 DataVal av;
416 AsnTypePtr atp;
417 DenseDiagPtr ddp;
418 StdSegPtr ssp;
419 Boolean retval = FALSE;
420 ValNodePtr anp;
421 UserObjectPtr uop;
422
423 if (! loaded)
424 {
425 if (! SeqAlignAsnLoad())
426 return FALSE;
427 }
428
429 if (aip == NULL)
430 return FALSE;
431
432 if ((aip->spec_version == 3) && /* ASN3 strip new value */
433 (sap != NULL) && (sap->segtype > 3))
434 {
435 ErrPostEx(SEV_ERROR,0,0,"ASN3: SeqAlign.segs > 3 stripped");
436 return TRUE;
437 }
438
439 atp = AsnLinkType(orig, SEQ_ALIGN); /* link local tree */
440 if (atp == NULL)
441 return FALSE;
442
443 if (sap == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
444
445 if (! AsnOpenStruct(aip, atp, (Pointer)sap))
446 goto erret;
447
448 av.intvalue = sap->type;
449 if (! AsnWrite(aip, SEQ_ALIGN_type, &av)) /* write the type */
450 goto erret;
451
452 if (sap->dim) /* default global dimensionality? */
453 {
454 av.intvalue = sap->dim;
455 if (! AsnWrite(aip, SEQ_ALIGN_dim, &av)) goto erret;
456 }
457
458 if (sap->score != NULL)
459 {
460 if (! InternalScoreSetAsnWrite(sap->score, aip, SEQ_ALIGN_score, SEQ_ALIGN_score_E))
461 goto erret;
462 }
463
464 av.ptrvalue = (Pointer)sap->segs;
465 if (! AsnWriteChoice(aip, SEQ_ALIGN_segs, (Int2)sap->segtype, &av)) goto erret;
466
467 switch (sap->segtype) /* which CHOICE */
468 {
469 case 1: /* dendiag */
470 if (! AsnOpenStruct(aip, SEQ_ALIGN_segs_dendiag, (Pointer)sap->segs))
471 goto erret;
472 ddp = (DenseDiagPtr) sap->segs;
473 while (ddp != NULL)
474 {
475 if (! DenseDiagAsnWrite(ddp, aip, SEQ_ALIGN_segs_dendiag_E))
476 goto erret;
477 ddp = ddp->next;
478 }
479 if (! AsnCloseStruct(aip, SEQ_ALIGN_segs_dendiag, (Pointer)sap->segs))
480 goto erret;
481 break;
482 case 2: /* denseg */
483 if (! DenseSegAsnWrite((DenseSegPtr)sap->segs, aip, SEQ_ALIGN_segs_denseg))
484 goto erret;
485 break;
486 case 3: /* std-seg */
487 if (! AsnOpenStruct(aip, SEQ_ALIGN_segs_std, (Pointer)sap->segs))
488 goto erret;
489 ssp = (StdSegPtr) sap->segs;
490 while (ssp != NULL)
491 {
492 if (! StdSegAsnWrite(ssp, aip, SEQ_ALIGN_segs_std_E))
493 goto erret;
494 ssp = ssp->next;
495 }
496 if (! AsnCloseStruct(aip, SEQ_ALIGN_segs_std, (Pointer)sap->segs))
497 goto erret;
498 break;
499 case 4: /* packseg */
500 if (! PackSegAsnWrite((PackSegPtr)sap->segs, aip, SEQ_ALIGN_segs_packed))
501 goto erret;
502 break;
503 case 5: /* disc */
504 if (! SpecialSeqAlignSetAsnWrite((SeqAlignPtr)sap->segs, aip, SEQ_ALIGN_segs_disc))
505 goto erret;
506 break;
507 case 6: /* spliced */
508 if (! SplicedSegAsnWrite((SplicedSegPtr)sap->segs, aip, SEQ_ALIGN_segs_spliced))
509 goto erret;
510 break;
511 case 7: /* sparse */
512 if (! SparseSegAsnWrite((SparseSegPtr)sap->segs, aip, SEQ_ALIGN_segs_sparse))
513 goto erret;
514 break;
515 }
516
517 if (sap->bounds != NULL)
518 {
519 if (aip->spec_version == 3) /* ASN3 strip new value */
520 {
521 ErrPostEx(SEV_ERROR,0,0,"ASN3: SeqAlign.bounds stripped");
522 }
523 else
524 if (! SeqLocSetAsnWrite(sap->bounds, aip, SEQ_ALIGN_bounds, SEQ_ALIGN_bounds_E))
525 goto erret;
526 }
527
528 if (sap->id != NULL)
529 {
530 if (aip->spec_version == 3) /* ASN3 strip new value */
531 {
532 ErrPostEx(SEV_ERROR,0,0,"ASN3: SeqAlign.id stripped");
533 }
534 else {
535 if (! AsnOpenStruct(aip, SEQ_ALIGN_id, (Pointer)sap->id)) goto erret;
536 anp = sap->id;
537 while (anp != NULL) {
538 if (! ObjectIdAsnWrite((ObjectIdPtr)anp->data.ptrvalue, aip, SEQ_ALIGN_id_E)) goto erret;
539 anp = anp->next;
540 }
541 if (! AsnCloseStruct(aip, SEQ_ALIGN_id, (Pointer)sap->id)) goto erret;
542 /*
543 AsnGenericChoiceSeqOfAsnWrite(sap -> id, (AsnWriteFunc) ObjectIdAsnWrite, aip, SEQ_ALIGN_id, SEQ_ALIGN_id_E);
544 */
545 }
546 }
547
548 if (sap->ext != NULL)
549 {
550 if (aip->spec_version == 3) /* ASN3 strip new value */
551 {
552 ErrPostEx(SEV_ERROR,0,0,"ASN3: SeqAlign.ext stripped");
553 }
554 else {
555 uop = (UserObjectPtr) sap->ext;
556 if (! AsnOpenStruct(aip, SEQ_ALIGN_ext, sap->ext)) goto erret;
557 while (uop != NULL)
558 {
559 if (! UserObjectAsnWrite(uop, aip, SEQ_ALIGN_ext_E)) goto erret;
560 uop = uop->next;
561 }
562 if (! AsnCloseStruct(aip, SEQ_ALIGN_ext, sap->ext)) goto erret;
563 }
564 /*
565 AsnGenericUserSeqOfAsnWrite(sap -> ext, (AsnWriteFunc) UserObjectAsnWrite, aip, SEQ_ALIGN_ext, SEQ_ALIGN_ext_E);
566 */
567 }
568
569 if (! AsnCloseStruct(aip, atp, (Pointer)sap))
570 goto erret;
571 retval = TRUE;
572 erret:
573 AsnUnlinkType(orig); /* unlink local tree */
574 return retval;
575 }
576
577 /*****************************************************************************
578 *
579 * SeqAlignAsnRead(aip, atp)
580 * atp is the current type (if identifier of a parent struct)
581 * assumption is readIdent has occurred
582 * if atp == NULL, then assumes it stands alone and read ident
583 * has not occurred.
584 *
585 *****************************************************************************/
586 NLM_EXTERN SeqAlignPtr LIBCALL SeqAlignAsnRead (AsnIoPtr aip, AsnTypePtr orig)
587 {
588 DataVal av;
589 AsnTypePtr atp, oldtype;
590 SeqAlignPtr sap=NULL;
591 DenseDiagPtr currddp = NULL, ddp;
592 StdSegPtr currssp = NULL, ssp;
593 Boolean isError = FALSE;
594 ValNodePtr anp, prev = NULL;
595 ObjectIdPtr oip;
596
597 if (! loaded)
598 {
599 if (! SeqAlignAsnLoad())
600 return sap;
601 }
602
603 if (aip == NULL)
604 return sap;
605
606 if (orig == NULL) /* SeqAlign ::= (self contained) */
607 atp = AsnReadId(aip, amp, SEQ_ALIGN);
608 else
609 atp = AsnLinkType(orig, SEQ_ALIGN); /* link in local tree */
610 oldtype = atp;
611 if (atp == NULL)
612 return sap;
613
614 sap = SeqAlignNew();
615 if (sap == NULL)
616 goto erret;
617
618 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
619 atp = AsnReadId(aip, amp, atp); /* read the type */
620 if (atp == NULL)
621 goto erret;
622 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
623 sap->type = (Uint1) av.intvalue;
624 while ((atp = AsnReadId(aip, amp, atp)) != oldtype)
625 {
626 if (atp == NULL)
627 goto erret;
628 if (atp == SEQ_ALIGN_dim)
629 {
630 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
631 sap->dim = (Int2) av.intvalue;
632 }
633 else if (atp == SEQ_ALIGN_score)
634 {
635 sap->score = InternalScoreSetAsnRead(aip, SEQ_ALIGN_score, SEQ_ALIGN_score_E);
636 if (sap->score == NULL)
637 goto erret;
638 }
639 else if (atp == SEQ_ALIGN_bounds)
640 {
641 sap->bounds = SeqLocSetAsnRead(aip, SEQ_ALIGN_bounds, SEQ_ALIGN_bounds_E);
642 if (sap->bounds == NULL)
643 goto erret;
644 if (aip->spec_version == 3) /* ASN3 strip new value */
645 {
646 ErrPostEx(SEV_ERROR,0,0,"ASN3: SeqAlign.bounds stripped");
647 sap->bounds = SeqLocSetFree(sap->bounds);
648 }
649 }
650 else if (atp == SEQ_ALIGN_segs_dendiag_E)
651 {
652 sap->segtype = 1;
653 ddp = DenseDiagAsnRead(aip, atp);
654 if (ddp == NULL)
655 goto erret;
656 if (sap->segs == NULL)
657 sap->segs = (Pointer)ddp;
658 else
659 currddp->next = ddp;
660 currddp = ddp;
661 }
662 else if (atp == SEQ_ALIGN_segs_denseg)
663 {
664 sap->segtype = 2;
665 sap->segs = (Pointer) DenseSegAsnRead(aip, SEQ_ALIGN_segs_denseg);
666 if (sap->segs == NULL)
667 goto erret;
668 }
669 else if (atp == SEQ_ALIGN_segs_std_E)
670 {
671 sap->segtype = 3;
672 ssp = StdSegAsnRead(aip, atp);
673 if (ssp == NULL)
674 goto erret;
675 if (sap->segs == NULL)
676 sap->segs = (Pointer) ssp;
677 else
678 currssp->next = ssp;
679 currssp = ssp;
680 }
681 else if (atp == SEQ_ALIGN_segs_packed)
682 {
683 sap->segtype = 4;
684 sap->segs = (Pointer) PackSegAsnRead(aip, atp);
685 if (sap->segs == NULL)
686 goto erret;
687 }
688 else if (atp == SEQ_ALIGN_segs_disc)
689 {
690 sap->segtype = 5;
691 sap->segs = (Pointer) SpecialSeqAlignSetAsnRead(aip, atp);
692 if (sap->segs == NULL)
693 goto erret;
694 }
695 else if (atp == SEQ_ALIGN_segs_spliced)
696 {
697 sap->segtype = 6;
698 sap->segs = (Pointer) SplicedSegAsnRead(aip, atp);
699 if (sap->segs == NULL)
700 goto erret;
701 }
702 else if (atp == SEQ_ALIGN_segs_sparse)
703 {
704 sap->segtype = 7;
705 sap->segs = (Pointer) SparseSegAsnRead(aip, atp);
706 if (sap->segs == NULL)
707 goto erret;
708 }
709 else if (atp == SEQ_ALIGN_bounds)
710 {
711 sap->bounds = AsnGenericChoiceSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) SeqLocAsnRead, (AsnOptFreeFunc) SeqLocFree);
712 if (sap->bounds == NULL)
713 goto erret;
714 }
715 else if (atp == SEQ_ALIGN_id)
716 {
717 if (AsnReadVal (aip, atp, &av) <= 0) goto erret; /* START_STRUCT */
718 while ((atp = AsnReadId(aip, amp, atp)) == SEQ_ALIGN_id_E) {
719 oip = ObjectIdAsnRead (aip, atp);
720 if (oip == NULL) goto erret;
721 anp = ValNodeNew (NULL);
722 if (anp == NULL) goto erret;
723 anp->data.ptrvalue = (Pointer) oip;
724 if (sap->id == NULL) {
725 sap->id = anp;
726 }
727 if (prev != NULL) {
728 prev->next = anp;
729 }
730 prev = anp;
731 }
732 if (AsnReadVal (aip, atp, &av) <= 0) goto erret; /* END_STRUCT */
733 /*
734 sap->id = AsnGenericChoiceSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) ObjectIdAsnRead, (AsnOptFreeFunc) ObjectIdFree);
735 */
736 if (sap->id == NULL)
737 goto erret;
738 }
739 else if (atp == SEQ_ALIGN_ext)
740 {
741 sap->ext = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) UserObjectAsnRead, (AsnOptFreeFunc) UserObjectFree);
742 if (sap->ext == NULL)
743 goto erret;
744 }
745 else
746 {
747 if (AsnReadVal(aip, atp, NULL) <= 0)
748 goto erret;
749 }
750 }
751 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
752 if ((aip->spec_version == 3) && /* ASN3 strip new value */
753 (sap->segtype > 3))
754 {
755 ErrPostEx(SEV_ERROR,0,0,"ASN3: SeqAlign.segs > 3 stripped");
756 sap = SeqAlignFree(sap);
757 }
758 ret:
759 AsnUnlinkType(orig); /* unlink local tree */
760 return sap;
761 erret:
762 aip->io_failure = TRUE;
763 sap = SeqAlignFree(sap);
764 goto ret;
765 }
766
767 /*****************************************************************************
768 *
769 * ScoreNew()
770 *
771 *****************************************************************************/
772 NLM_EXTERN ScorePtr LIBCALL ScoreNew (void)
773 {
774 return (ScorePtr)MemNew(sizeof(Score));
775 }
776
777 /*****************************************************************************
778 *
779 * ScoreSetFree(sp)
780 * Frees a complete CHAIN of scores
781 *
782 *****************************************************************************/
783 NLM_EXTERN ScorePtr LIBCALL ScoreSetFree (ScorePtr sp)
784 {
785 ScorePtr next;
786
787 while (sp != NULL)
788 {
789 next = sp->next;
790 ObjectIdFree(sp->id);
791 MemFree(sp);
792 sp = next;
793 }
794
795 return (ScorePtr)NULL;
796 }
797
798 NLM_EXTERN Boolean LIBCALL ScoreSetAsnWrite (ScorePtr sp, AsnIoPtr aip, AsnTypePtr settype)
799 {
800 Boolean retval;
801 AsnTypePtr atp;
802
803 if (settype == NULL)
804 atp = AsnLinkType(settype, SCORE_SET);
805 else
806 atp = settype;
807 retval = InternalScoreSetAsnWrite(sp, aip, atp, SCORE_SET_E);
808 if (settype == NULL)
809 AsnUnlinkType(settype);
810
811 return retval;
812 }
813
814 /*****************************************************************************
815 *
816 * InternalScoreSetAsnWrite(sp, aip, settype, elementtype)
817 * ===== NOTE: Reads a complete CHAIN of scores ===================
818 * Score never stands alone
819 *
820 *****************************************************************************/
821 static Boolean InternalScoreSetAsnWrite (ScorePtr sp, AsnIoPtr aip, AsnTypePtr settype, AsnTypePtr elementtype)
822 {
823 ScorePtr oldsp;
824 Boolean retval = FALSE;
825
826 if (! loaded)
827 {
828 if (! SeqAlignAsnLoad())
829 return FALSE;
830 }
831
832 if (aip == NULL)
833 return FALSE;
834
835 if (sp == NULL) { AsnNullValueMsg(aip, settype); goto erret; }
836
837 /* score is local - no link to tree */
838 oldsp = sp;
839 if (! AsnOpenStruct(aip, settype, (Pointer)sp))
840 goto erret;
841 while (sp != NULL) /* write scores */
842 {
843 if (! AsnOpenStruct(aip, elementtype, (Pointer)sp))
844 goto erret;
845 if (sp->id != NULL)
846 {
847 if (! ObjectIdAsnWrite(sp->id, aip, SCORE_id))
848 goto erret;
849 }
850 if (! AsnWriteChoice(aip, SCORE_value, (Int2)sp->choice, &sp->value))
851 goto erret;
852 switch (sp->choice)
853 {
854 case 1: /* int */
855 if (! AsnWrite(aip, SCORE_value_int, &sp->value))
856 goto erret;
857 break;
858 case 2: /* real */
859 if (! AsnWrite(aip, SCORE_value_real, &sp->value))
860 goto erret;
861 break;
862 }
863 if (! AsnCloseStruct(aip, elementtype, (Pointer)sp))
864 goto erret;
865 sp = sp->next;
866 }
867 /* score is local -- no link to tree */
868 if (! AsnCloseStruct(aip, settype, oldsp))
869 goto erret;
870 retval = TRUE;
871 erret:
872 return retval;
873 }
874
875 NLM_EXTERN ScorePtr LIBCALL ScoreSetAsnRead (AsnIoPtr aip, AsnTypePtr settype)
876 {
877 ScorePtr retval;
878 AsnTypePtr atp;
879
880 if (settype == NULL) {
881 atp = AsnReadId(aip, amp, SCORE_SET);
882 } else {
883 atp = AsnLinkType(settype, SCORE_SET);
884 }
885
886 retval = InternalScoreSetAsnRead(aip, atp, SCORE_SET_E);
887
888 AsnUnlinkType (settype);
889
890 return retval;
891 }
892
893 /*****************************************************************************
894 *
895 * InternalScoreSetAsnRead(aip, settype, elementtype)
896 * assumes first settype has been read
897 * score never stands alone
898 * reads a CHAIN of scores
899 * An empty chain is treated as an error even though it is syntactically
900 * correct
901 *
902 *****************************************************************************/
903 static ScorePtr InternalScoreSetAsnRead (AsnIoPtr aip, AsnTypePtr settype, AsnTypePtr elementtype)
904 {
905 DataVal av;
906 AsnTypePtr atp;
907 ScorePtr sp=NULL, curr = NULL, first = NULL;
908
909 if (! loaded)
910 {
911 if (! SeqAlignAsnLoad())
912 return sp;
913 }
914
915 if (aip == NULL)
916 return sp;
917
918 atp = settype;
919
920 if (AsnReadVal(aip, settype, &av) <= 0) goto erret; /* start set/seq */
921
922 while ((atp = AsnReadId(aip, amp, atp)) != settype)
923 {
924 if (atp == NULL)
925 goto erret;
926 if (atp == SCORE_id)
927 {
928 sp->id = ObjectIdAsnRead(aip, atp);
929 if (sp->id == NULL)
930 goto erret;
931 }
932 else
933 {
934 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the value */
935 if ((atp == elementtype) && (av.intvalue == START_STRUCT))
936 {
937 sp = ScoreNew();
938 if (sp == NULL)
939 goto erret;
940 if (first == NULL)
941 first = sp;
942 else
943 curr->next = sp;
944 curr = sp;
945 }
946 else if (atp == SCORE_value_int)
947 {
948 sp->choice = 1;
949 sp->value.intvalue = av.intvalue;
950 }
951 else if (atp == SCORE_value_real)
952 {
953 sp->choice = 2;
954 sp->value.realvalue = av.realvalue;
955 }
956 }
957 }
958 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end set/seq , no unlink */
959 if (first == NULL) /* empty set of scores, treat as error */
960 ErrPost(CTX_NCBIOBJ, 1, "Empty SET OF Score. line %ld", aip->linenumber);
961 ret:
962 return first;
963 erret:
964 first = ScoreSetFree(first);
965 goto ret;
966 }
967
968 /*****************************************************************************
969 *
970 * DenseDiagNew()
971 *
972 *****************************************************************************/
973 NLM_EXTERN DenseDiagPtr LIBCALL DenseDiagNew (void)
974 {
975 return (DenseDiagPtr)MemNew(sizeof(DenseDiag));
976 }
977
978 /*****************************************************************************
979 *
980 * DenseDiagFree(ddp)
981 * Frees one DenseDiag and associated data
982 *
983 *****************************************************************************/
984 NLM_EXTERN DenseDiagPtr LIBCALL DenseDiagFree (DenseDiagPtr ddp)
985 {
986 if (ddp == NULL)
987 return ddp;
988
989 SeqIdSetFree(ddp->id); /* frees chain */
990 MemFree(ddp->starts);
991 MemFree(ddp->strands);
992 ScoreSetFree(ddp->scores); /* frees chain */
993 return (DenseDiagPtr)MemFree(ddp);
994 }
995
996 /*****************************************************************************
997 *
998 * DenseDiagAsnWrite(ddp, aip, atp)
999 * atp is the current type (if identifier of a parent struct)
1000 * if atp == NULL, then assumes it stands alone (DenseDiag ::=)
1001 *
1002 *****************************************************************************/
1003 NLM_EXTERN Boolean LIBCALL DenseDiagAsnWrite (DenseDiagPtr ddp, AsnIoPtr aip, AsnTypePtr orig)
1004 {
1005 DataVal av;
1006 AsnTypePtr atp;
1007 Int2 dim = 0, i; /* global dimensionality */
1008 Boolean retval = FALSE;
1009
1010 if (! loaded)
1011 {
1012 if (! SeqAlignAsnLoad())
1013 return FALSE;
1014 }
1015
1016 if (aip == NULL)
1017 return FALSE;
1018
1019 atp = AsnLinkType(orig, DENSE_DIAG); /* link local tree */
1020 if (atp == NULL)
1021 return FALSE;
1022
1023 if (ddp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1024
1025 if (! AsnOpenStruct(aip, atp, (Pointer)ddp))
1026 goto erret;
1027
1028 if (ddp->dim) /* default global dimensionality? */
1029 {
1030 dim = ddp->dim;
1031 av.intvalue = ddp->dim;
1032 if (! AsnWrite(aip, DENSE_DIAG_dim, &av)) goto erret;
1033 }
1034 else
1035 dim = 2; /* default value */
1036 /* write the SeqIds */
1037 if (! SeqIdSetAsnWrite(ddp->id, aip, DENSE_DIAG_ids, DENSE_DIAG_ids_E))
1038 goto erret;
1039
1040 if (! AsnOpenStruct(aip, DENSE_DIAG_starts, (Pointer)ddp->starts))
1041 goto erret;
1042 for (i = 0; i < dim; i++)
1043 {
1044 av.intvalue = ddp->starts[i];
1045 if (! AsnWrite(aip, DENSE_DIAG_starts_E, &av)) goto erret;
1046 }
1047 if (! AsnCloseStruct(aip, DENSE_DIAG_starts, (Pointer)ddp->starts))
1048 goto erret;
1049
1050 av.intvalue = ddp->len;
1051 if (! AsnWrite(aip, DENSE_DIAG_len, &av)) goto erret;
1052
1053 if (ddp->strands != NULL)
1054 {
1055 if (! AsnOpenStruct(aip, DENSE_DIAG_strands, (Pointer)ddp->strands))
1056 goto erret;
1057 for (i = 0; i < dim; i++)
1058 {
1059 av.intvalue = ddp->strands[i];
1060 if (! AsnWrite(aip, DENSE_DIAG_strands_E, &av)) goto erret;
1061 }
1062 if (! AsnCloseStruct(aip, DENSE_DIAG_strands, (Pointer)ddp->strands))
1063 goto erret;
1064 }
1065
1066 if (ddp->scores != NULL)
1067 {
1068 if (! InternalScoreSetAsnWrite(ddp->scores, aip, DENSE_DIAG_scores, DENSE_DIAG_scores_E))
1069 goto erret;
1070 }
1071
1072 if (! AsnCloseStruct(aip, atp, (Pointer)ddp))
1073 goto erret;
1074 retval = TRUE;
1075 erret:
1076 AsnUnlinkType(orig); /* unlink local tree */
1077 return retval;
1078 }
1079
1080 /*****************************************************************************
1081 *
1082 * DenseDiagAsnRead(aip, atp)
1083 * atp is the current type (if identifier of a parent struct)
1084 * assumption is readIdent has occurred
1085 * if atp == NULL, then assumes it stands alone and read ident
1086 * has not occurred.
1087 *
1088 *****************************************************************************/
1089 NLM_EXTERN DenseDiagPtr LIBCALL DenseDiagAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1090 {
1091 DataVal av;
1092 AsnTypePtr atp, oldtype;
1093 DenseDiagPtr ddp=NULL;
1094 Int2 dim, i;
1095
1096 if (! loaded)
1097 {
1098 if (! SeqAlignAsnLoad())
1099 return ddp;
1100 }
1101
1102 if (aip == NULL)
1103 return ddp;
1104
1105 if (orig == NULL) /* DenseDiag ::= (self contained) */
1106 atp = AsnReadId(aip, amp, DENSE_DIAG);
1107 else
1108 atp = AsnLinkType(orig, DENSE_DIAG); /* link in local tree */
1109 oldtype = atp;
1110 if (atp == NULL)
1111 return ddp;
1112
1113 ddp = DenseDiagNew();
1114 if (ddp == NULL)
1115 goto erret;
1116
1117 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
1118 atp = AsnReadId(aip, amp, atp); /* read the dim or ids */
1119 if (atp == NULL)
1120 goto erret;
1121 if (atp == DENSE_DIAG_dim)
1122 {
1123 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1124 ddp->dim = (Int2)av.intvalue;
1125 dim = ddp->dim;
1126 atp = AsnReadId(aip, amp, atp); /* ids */
1127 if (atp == NULL)
1128 goto erret;
1129 }
1130 else
1131 dim = 2; /* default */
1132
1133 ddp->id = SeqIdSetAsnRead(aip, DENSE_DIAG_ids, DENSE_DIAG_ids_E);
1134 if (ddp->id == NULL)
1135 goto erret;
1136
1137 ddp->starts = (Int4Ptr) MemNew(sizeof(Int4) * dim);
1138 if (ddp->starts == NULL)
1139 goto erret;
1140 atp = AsnReadId(aip, amp, atp); /* SEQ OF INTEGER */
1141 if (atp == NULL)
1142 goto erret;
1143 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1144 for (i = 0; i < dim; i++)
1145 {
1146 atp = AsnReadId(aip, amp, atp);
1147 if (atp == NULL)
1148 goto erret;
1149 if (atp != DENSE_DIAG_starts_E)
1150 {
1151 ErrPost(CTX_NCBIOBJ, 1, "Too few starts in Dense-diag");
1152 goto erret;
1153 }
1154 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1155 ddp->starts[i] = av.intvalue;
1156 }
1157 atp = AsnReadId(aip, amp, atp);
1158 if (atp != DENSE_DIAG_starts)
1159 {
1160 ErrPost(CTX_NCBIOBJ, 1, "Too many starts in Dense-diag");
1161 goto erret;
1162 }
1163 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF INTEGER */
1164
1165 atp = AsnReadId(aip, amp, atp); /* len */
1166 if (atp == NULL)
1167 goto erret;
1168 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1169 ddp->len = av.intvalue;
1170
1171 while ((atp = AsnReadId(aip, amp, atp)) != oldtype)
1172 {
1173 if (atp == NULL)
1174 goto erret;
1175 if (atp == DENSE_DIAG_strands)
1176 {
1177 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* start SEQ OF */
1178 ddp->strands = (Uint1Ptr) MemNew(sizeof(Uint1) * dim);
1179 if (ddp->strands == NULL)
1180 goto erret;
1181 for (i = 0; i < dim; i++)
1182 {
1183 atp = AsnReadId(aip, amp, atp);
1184 if (atp == NULL)
1185 goto erret;
1186 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1187 ddp->strands[i] = (Uint1)av.intvalue;
1188 }
1189 atp = AsnReadId(aip, amp, atp);
1190 if (atp == NULL)
1191 goto erret;
1192 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF */
1193 }
1194 else if (atp == DENSE_DIAG_scores)
1195 {
1196 ddp->scores = InternalScoreSetAsnRead(aip, DENSE_DIAG_scores, DENSE_DIAG_scores_E);
1197 if (ddp->scores == NULL)
1198 goto erret;
1199 }
1200 }
1201
1202 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
1203 ret:
1204 AsnUnlinkType(orig); /* unlink local tree */
1205 return ddp;
1206 erret:
1207 ddp = DenseDiagFree(ddp);
1208 goto ret;
1209 }
1210
1211 /*****************************************************************************
1212 *
1213 * DenseSegNew()
1214 *
1215 *****************************************************************************/
1216 NLM_EXTERN DenseSegPtr LIBCALL DenseSegNew (void)
1217 {
1218 return (DenseSegPtr)MemNew(sizeof(DenseSeg));
1219 }
1220
1221 /*****************************************************************************
1222 *
1223 * DenseSegFree(dsp)
1224 * Frees one DenseSeg and associated data
1225 *
1226 *****************************************************************************/
1227 NLM_EXTERN DenseSegPtr LIBCALL DenseSegFree (DenseSegPtr dsp)
1228 {
1229 if (dsp == NULL)
1230 return dsp;
1231
1232 SeqIdSetFree(dsp->ids); /* frees chain */
1233 MemFree(dsp->starts);
1234 MemFree(dsp->lens);
1235 MemFree(dsp->strands);
1236 ScoreSetFree(dsp->scores); /* frees chain */
1237 return (DenseSegPtr)MemFree(dsp);
1238 }
1239
1240 /*****************************************************************************
1241 *
1242 * DenseSegAsnWrite(dsp, aip, atp)
1243 * atp is the current type (if identifier of a parent struct)
1244 * if atp == NULL, then assumes it stands alone (DenseSeg ::=)
1245 *
1246 *****************************************************************************/
1247 NLM_EXTERN Boolean LIBCALL DenseSegAsnWrite (DenseSegPtr dsp, AsnIoPtr aip, AsnTypePtr orig)
1248 {
1249 DataVal av;
1250 AsnTypePtr atp;
1251 Int2 dim = 0, i, /* global dimensionality */
1252 numseg = 0; /* number of segments represented */
1253 Int4 total, j;
1254 Boolean retval = FALSE;
1255
1256 if (! loaded)
1257 {
1258 if (! SeqAlignAsnLoad())
1259 return FALSE;
1260 }
1261
1262 if (aip == NULL)
1263 return FALSE;
1264
1265 atp = AsnLinkType(orig, DENSE_SEG); /* link local tree */
1266 if (atp == NULL)
1267 return FALSE;
1268
1269 if (dsp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1270
1271 if (! AsnOpenStruct(aip, atp, (Pointer)dsp))
1272 goto erret;
1273
1274 if (dsp->dim) /* default global dimensionality? */
1275 {
1276 dim = dsp->dim;
1277 av.intvalue = dsp->dim;
1278 if (! AsnWrite(aip, DENSE_SEG_dim, &av)) goto erret;
1279 }
1280 else
1281 dim = 2; /* default value */
1282
1283 numseg = dsp->numseg;
1284 av.intvalue = numseg;
1285 if (! AsnWrite(aip, DENSE_SEG_numseg, &av)) goto erret;
1286
1287 total = numseg * dim;
1288 /* write the SeqIds */
1289 if (! SeqIdSetAsnWrite(dsp->ids, aip, DENSE_SEG_ids, DENSE_SEG_ids_E))
1290 goto erret;
1291
1292 if (! AsnOpenStruct(aip, DENSE_SEG_starts, (Pointer)dsp->starts))
1293 goto erret;
1294 for (j = 0; j < total; j++)
1295 {
1296 av.intvalue = dsp->starts[j];
1297 if (! AsnWrite(aip, DENSE_SEG_starts_E, &av)) goto erret;
1298 }
1299 if (! AsnCloseStruct(aip, DENSE_SEG_starts, (Pointer)dsp->starts))
1300 goto erret;
1301
1302 if (! AsnOpenStruct(aip, DENSE_SEG_lens, (Pointer)dsp->lens))
1303 goto erret;
1304 for (i = 0; i < numseg; i++)
1305 {
1306 av.intvalue = dsp->lens[i];
1307 if (! AsnWrite(aip, DENSE_SEG_lens_E, &av)) goto erret;
1308 }
1309 if (! AsnCloseStruct(aip, DENSE_SEG_lens, (Pointer)dsp->lens))
1310 goto erret;
1311
1312 if (dsp->strands != NULL)
1313 {
1314 if (! AsnOpenStruct(aip, DENSE_SEG_strands, (Pointer)dsp->strands))
1315 goto erret;
1316 for (j = 0; j < total; j++)
1317 {
1318 av.intvalue = dsp->strands[j];
1319 if (! AsnWrite(aip, DENSE_SEG_strands_E, &av)) goto erret;
1320 }
1321 if (! AsnCloseStruct(aip, DENSE_SEG_strands, (Pointer)dsp->strands))
1322 goto erret;
1323 }
1324
1325 if (dsp->scores != NULL)
1326 {
1327 if (! InternalScoreSetAsnWrite(dsp->scores, aip, DENSE_SEG_scores, DENSE_SEG_scores_E))
1328 goto erret;
1329 }
1330
1331 if (! AsnCloseStruct(aip, atp, (Pointer)dsp))
1332 goto erret;
1333 retval = TRUE;
1334 erret:
1335 AsnUnlinkType(orig); /* unlink local tree */
1336 return retval;
1337 }
1338
1339 /*****************************************************************************
1340 *
1341 * DenseSegAsnRead(aip, atp)
1342 * atp is the current type (if identifier of a parent struct)
1343 * assumption is readIdent has occurred
1344 * if atp == NULL, then assumes it stands alone and read ident
1345 * has not occurred.
1346 *
1347 *****************************************************************************/
1348 NLM_EXTERN DenseSegPtr LIBCALL DenseSegAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1349 {
1350 DataVal av;
1351 AsnTypePtr atp, oldtype;
1352 DenseSegPtr dsp=NULL;
1353 Int2 dim, i, numseg;
1354 Int4 j, total;
1355
1356 if (! loaded)
1357 {
1358 if (! SeqAlignAsnLoad())
1359 return dsp;
1360 }
1361
1362 if (aip == NULL)
1363 return dsp;
1364
1365 if (orig == NULL) /* DenseSeg ::= (self contained) */
1366 atp = AsnReadId(aip, amp, DENSE_SEG);
1367 else
1368 atp = AsnLinkType(orig, DENSE_SEG); /* link in local tree */
1369 oldtype = atp;
1370 if (atp == NULL)
1371 return dsp;
1372
1373 dsp = DenseSegNew();
1374 if (dsp == NULL)
1375 goto erret;
1376
1377 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
1378 atp = AsnReadId(aip, amp, atp); /* read the dim or numseg */
1379 if (atp == NULL)
1380 goto erret;
1381 if (atp == DENSE_SEG_dim)
1382 {
1383 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1384 dsp->dim = (Int2)av.intvalue;
1385 dim = dsp->dim;
1386 if (dim == 0) {
1387 ErrPostEx(SEV_ERROR,0,0,"DenseSegAsnRead: dim = 0");
1388 goto erret;
1389 }
1390 atp = AsnReadId(aip, amp, atp); /* ids */
1391 if (atp == NULL)
1392 goto erret;
1393 }
1394 else
1395 dim = 2; /* default */
1396
1397 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* numseg */
1398 dsp->numseg = (Int2)av.intvalue;
1399 numseg = dsp->numseg;
1400 if (numseg == 0) {
1401 ErrPostEx(SEV_ERROR,0,0,"DenseSegAsnRead: numseg = 0");
1402 goto erret;
1403 }
1404 total = numseg * dim;
1405
1406 atp = AsnReadId(aip, amp, atp);
1407 if (atp == NULL)
1408 goto erret;
1409 dsp->ids = SeqIdSetAsnRead(aip, atp, DENSE_SEG_ids_E);
1410 if (dsp->ids == NULL)
1411 goto erret;
1412
1413 dsp->starts = (Int4Ptr) MemNew(sizeof(Int4) * total);
1414 if (dsp->starts == NULL)
1415 goto erret;
1416 atp = AsnReadId(aip, amp, atp); /* SEQ OF INTEGER */
1417 if (atp == NULL)
1418 goto erret;
1419 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1420 for (j = 0; j < total; j++)
1421 {
1422 atp = AsnReadId(aip, amp, atp);
1423 if (atp != DENSE_SEG_starts_E)
1424 {
1425 ErrPost(CTX_NCBIOBJ, 1, "Too few starts in Dense-seg");
1426 goto erret;
1427 }
1428 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1429 dsp->starts[j] = av.intvalue;
1430 }
1431 atp = AsnReadId(aip, amp, atp);
1432 if (atp != DENSE_SEG_starts)
1433 {
1434 ErrPost(CTX_NCBIOBJ, 1, "Too many starts in Dense-seg");
1435 goto erret;
1436 }
1437 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF INTEGER */
1438
1439 dsp->lens = (Int4Ptr) MemNew(sizeof(Int4) * numseg);
1440 if (dsp->lens == NULL)
1441 goto erret;
1442 atp = AsnReadId(aip, amp, atp); /* SEQ OF INTEGER */
1443 if (atp == NULL)
1444 goto erret;
1445 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1446 for (i = 0; i < numseg; i++)
1447 {
1448 atp = AsnReadId(aip, amp, atp);
1449 if (atp != DENSE_SEG_lens_E)
1450 {
1451 ErrPost(CTX_NCBIOBJ, 1, "Too few lens in Dense-seg");
1452 goto erret;
1453 }
1454 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1455 dsp->lens[i] = av.intvalue;
1456 }
1457 atp = AsnReadId(aip, amp, atp);
1458 if (atp != DENSE_SEG_lens)
1459 {
1460 ErrPost(CTX_NCBIOBJ, 1, "Too many lens in Dense-seg");
1461 goto erret;
1462 }
1463 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF INTEGER */
1464
1465 while ((atp = AsnReadId(aip, amp, atp)) != oldtype)
1466 {
1467 if (atp == NULL)
1468 goto erret;
1469 if (atp == DENSE_SEG_strands)
1470 {
1471 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* start SEQ OF */
1472 dsp->strands = (Uint1Ptr) MemNew(sizeof(Uint1) * total);
1473 if (dsp->strands == NULL)
1474 goto erret;
1475 for (j = 0; j < total; j++)
1476 {
1477 atp = AsnReadId(aip, amp, atp);
1478 if (atp == NULL)
1479 goto erret;
1480 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1481 dsp->strands[j] = (Uint1)av.intvalue;
1482 }
1483 atp = AsnReadId(aip, amp, atp);
1484 if (atp == NULL)
1485 goto erret;
1486 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF */
1487 }
1488 else if (atp == DENSE_SEG_scores)
1489 {
1490 dsp->scores = InternalScoreSetAsnRead(aip, DENSE_SEG_scores, DENSE_SEG_scores_E);
1491 if (dsp->scores == NULL)
1492 goto erret;
1493 }
1494 }
1495
1496 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
1497 ret:
1498 AsnUnlinkType(orig); /* unlink local tree */
1499 return dsp;
1500 erret:
1501 dsp = DenseSegFree(dsp);
1502 goto ret;
1503 }
1504
1505 /*****************************************************************************
1506 *
1507 * StdSegNew()
1508 *
1509 *****************************************************************************/
1510 NLM_EXTERN StdSegPtr LIBCALL StdSegNew (void)
1511 {
1512 return (StdSegPtr)MemNew(sizeof(StdSeg));
1513 }
1514 /*****************************************************************************
1515 *
1516 * StdSegFree(ddp)
1517 * Frees one StdSeg and associated data
1518 *
1519 *****************************************************************************/
1520 NLM_EXTERN StdSegPtr LIBCALL StdSegFree (StdSegPtr ssp)
1521
1522 {
1523 if (ssp == NULL)
1524 return ssp;
1525
1526 SeqIdSetFree(ssp->ids); /* frees chain */
1527 SeqLocSetFree(ssp->loc); /* frees chain */
1528 ScoreSetFree(ssp->scores); /* frees chain */
1529 return (StdSegPtr)MemFree(ssp);
1530 }
1531
1532 /*****************************************************************************
1533 *
1534 * StdSegAsnWrite(ssp, aip, atp)
1535 * atp is the current type (if identifier of a parent struct)
1536 * if atp == NULL, then assumes it stands alone (StdSeg ::=)
1537 *
1538 *****************************************************************************/
1539 NLM_EXTERN Boolean LIBCALL StdSegAsnWrite (StdSegPtr ssp, AsnIoPtr aip, AsnTypePtr orig)
1540 {
1541 DataVal av;
1542 AsnTypePtr atp;
1543 Boolean retval = FALSE;
1544
1545 if (! loaded)
1546 {
1547 if (! SeqAlignAsnLoad())
1548 return FALSE;
1549 }
1550
1551 if (aip == NULL)
1552 return FALSE;
1553
1554 atp = AsnLinkType(orig, STD_SEG); /* link local tree */
1555 if (atp == NULL)
1556 return FALSE;
1557
1558 if (ssp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1559
1560 if (! AsnOpenStruct(aip, atp, (Pointer)ssp))
1561 goto erret;
1562
1563 if (ssp->dim) /* default global dimensionality? */
1564 {
1565 av.intvalue = ssp->dim;
1566 if (! AsnWrite(aip, STD_SEG_dim, &av)) goto erret;
1567 }
1568 /* write the SeqIds */
1569 if (ssp->ids != NULL)
1570 {
1571 if (! SeqIdSetAsnWrite(ssp->ids, aip, STD_SEG_ids, STD_SEG_ids_E))
1572 goto erret;
1573 }
1574 /* write the SeqLocs */
1575 if (! SeqLocSetAsnWrite(ssp->loc, aip, STD_SEG_loc, STD_SEG_loc_E))
1576 goto erret;
1577 /* write the Scores */
1578 if (ssp->scores != NULL)
1579 {
1580 if (! InternalScoreSetAsnWrite(ssp->scores, aip, STD_SEG_scores, STD_SEG_scores_E))
1581 goto erret;
1582 }
1583
1584 if (! AsnCloseStruct(aip, atp, (Pointer)ssp))
1585 goto erret;
1586 retval = TRUE;
1587 erret:
1588 AsnUnlinkType(orig); /* unlink local tree */
1589 return retval;
1590 }
1591 /*****************************************************************************
1592 *
1593 * StdSegAsnRead(aip, atp)
1594 * atp is the current type (if identifier of a parent struct)
1595 * assumption is readIdent has occurred
1596 * if atp == NULL, then assumes it stands alone and read ident
1597 * has not occurred.
1598 *
1599 *****************************************************************************/
1600
1601 NLM_EXTERN StdSegPtr LIBCALL StdSegAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1602 {
1603 DataVal av;
1604 AsnTypePtr atp;
1605 StdSegPtr ssp=NULL;
1606
1607 if (! loaded)
1608 {
1609 if (! SeqAlignAsnLoad())
1610 return ssp;
1611 }
1612
1613 if (aip == NULL)
1614 return ssp;
1615
1616 if (orig == NULL) /* StdSeg ::= (self contained) */
1617 atp = AsnReadId(aip, amp, STD_SEG);
1618 else
1619 atp = AsnLinkType(orig, STD_SEG); /* link in local tree */
1620 if (atp == NULL)
1621 return ssp;
1622
1623 ssp = StdSegNew();
1624 if (ssp == NULL)
1625 goto erret;
1626
1627 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
1628 atp = AsnReadId(aip, amp, atp); /* read the dim or ids */
1629 if (atp == NULL)
1630 goto erret;
1631 if (atp == STD_SEG_dim)
1632 {
1633 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1634 ssp->dim = (Int2)av.intvalue;
1635 atp = AsnReadId(aip, amp, atp); /* ids */
1636 if (atp == NULL)
1637 goto erret;
1638 }
1639
1640 if (atp == STD_SEG_ids)
1641 {
1642 ssp->ids = SeqIdSetAsnRead(aip, atp, STD_SEG_ids_E);
1643 if (ssp->ids == NULL)
1644 goto erret;
1645 atp = AsnReadId(aip, amp, atp); /* ids */
1646 if (atp == NULL)
1647 goto erret;
1648 }
1649
1650 ssp->loc = SeqLocSetAsnRead(aip, STD_SEG_loc, STD_SEG_loc_E);
1651 if (ssp->loc == NULL)
1652 goto erret;
1653
1654 atp = AsnReadId(aip, amp, atp);
1655 if (atp == NULL)
1656 goto erret;
1657 if (atp == STD_SEG_scores)
1658 {
1659 ssp->scores = InternalScoreSetAsnRead(aip, STD_SEG_scores, STD_SEG_scores_E);
1660 if (ssp->scores == NULL)
1661 goto erret;
1662 atp = AsnReadId(aip, amp, atp);
1663 if (atp == NULL)
1664 goto erret;
1665 }
1666
1667 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
1668 ret:
1669 AsnUnlinkType(orig); /* unlink local tree */
1670 return ssp;
1671 erret:
1672 ssp = StdSegFree(ssp);
1673 goto ret;
1674 }
1675
1676 /*****************************************************************************
1677 *
1678 * SeqAlignSetAsnWrite(sap, aip, set, element)
1679 *
1680 *****************************************************************************/
1681 NLM_EXTERN Boolean LIBCALL SeqAlignSetAsnWrite (SeqAlignPtr sap, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
1682 {
1683 AsnTypePtr atp;
1684 SeqAlignPtr oldsap;
1685 Boolean retval = FALSE;
1686 Int2 ctr = 0;
1687
1688 if (! loaded)
1689 {
1690 if (! SeqAlignAsnLoad())
1691 return FALSE;
1692 }
1693
1694 if (aip == NULL)
1695 return FALSE;
1696
1697 atp = AsnLinkType(element, SEQ_ALIGN); /* link local tree */
1698 if (atp == NULL)
1699 return FALSE;
1700
1701
1702 oldsap = sap;
1703 if (! AsnOpenStruct(aip, set, (Pointer)oldsap))
1704 goto erret;
1705
1706 while (sap != NULL)
1707 {
1708 if (! SeqAlignAsnWrite(sap, aip, atp))
1709 goto erret;
1710 sap = sap->next;
1711 ctr++;
1712 if (ctr == 10)
1713 {
1714 if (! ProgMon("Write SeqAlign"))
1715 goto erret;
1716 ctr = 0;
1717 }
1718 }
1719
1720 if (! AsnCloseStruct(aip, set, (Pointer)oldsap))
1721 goto erret;
1722 retval = TRUE;
1723 erret:
1724 AsnUnlinkType(element); /* unlink local tree */
1725 return retval;
1726 }
1727 /*****************************************************************************
1728 *
1729 * SeqAlignSetAsnRead(aip, set, element)
1730 *
1731 *****************************************************************************/
1732 NLM_EXTERN SeqAlignPtr LIBCALL SeqAlignSetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
1733 {
1734 DataVal av;
1735 AsnTypePtr atp;
1736 SeqAlignPtr sap=NULL, curr = NULL, first = NULL;
1737 Int2 ctr = 0;
1738
1739 if (! loaded)
1740 {
1741 if (! SeqAlignAsnLoad())
1742 return sap;
1743 }
1744
1745 if (aip == NULL)
1746 return sap;
1747
1748
1749 if (set == NULL) /* SeqAlignSet ::= (self contained) */
1750 atp = AsnReadId(aip, amp, SEQ_ALIGN_SET);
1751 else
1752 atp = AsnLinkType(set, SEQ_ALIGN_SET); /* link in local tree */
1753
1754 if (atp == NULL)
1755 return sap;
1756
1757 AsnLinkType(element, SEQ_ALIGN); /* link in local tree */
1758
1759 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
1760 while ((atp = AsnReadId(aip, amp, atp)) == element) /* read the type */
1761 {
1762 sap = SeqAlignAsnRead(aip, atp);
1763 if (sap == NULL)
1764 goto erret;
1765 if (first == NULL)
1766 first = sap;
1767 else
1768 curr->next = sap;
1769 curr = sap;
1770 ctr++;
1771 if (ctr == 10)
1772 {
1773 if (! ProgMon("Read SeqAlign"))
1774 goto erret;
1775 ctr = 0;
1776 }
1777 }
1778 if (atp == NULL)
1779 goto erret;
1780 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
1781 ret:
1782 AsnUnlinkType(element); /* unlink local tree */
1783 return first;
1784 erret:
1785 while (first != NULL)
1786 {
1787 curr = first;
1788 first = first->next;
1789 SeqAlignFree(curr);
1790 }
1791 goto ret;
1792 }
1793
1794
1795 /* free a set of Seq-aligns */
1796 NLM_EXTERN SeqAlignPtr LIBCALL SeqAlignSetFree (SeqAlignPtr sap)
1797 {
1798 SeqAlignPtr next;
1799
1800 while (sap != NULL)
1801 {
1802 next = sap->next;
1803 SeqAlignFree(sap);
1804 sap = next;
1805 }
1806
1807 return NULL;
1808 }
1809
1810 NLM_EXTERN SeqAlignPtr LIBCALL SeqAlignSetNew (void)
1811 {
1812 return SeqAlignNew();
1813 }
1814
1815 NLM_EXTERN SeqAlignPtr LIBCALL SpecialSeqAlignSetAsnRead (AsnIoPtr aip, AsnTypePtr set)
1816 {
1817 return SeqAlignSetAsnRead(aip, set, SEQ_ALIGN_SET_E);
1818 }
1819
1820 NLM_EXTERN Boolean LIBCALL SpecialSeqAlignSetAsnWrite (SeqAlignPtr sap, AsnIoPtr aip, AsnTypePtr set)
1821 {
1822 return SeqAlignSetAsnWrite(sap, aip, set, SEQ_ALIGN_SET_E);
1823 }
1824
1825 NLM_EXTERN Boolean LIBCALL GenericSeqAlignSetAsnWrite (SeqAlignPtr sap, AsnIoPtr aip)
1826 {
1827 return SeqAlignSetAsnWrite(sap, aip, SEQ_ALIGN_SET, SEQ_ALIGN_SET_E);
1828 }
1829
1830
1831 /*****************************************************************************
1832 *
1833 * PackSegNew()
1834 *
1835 *****************************************************************************/
1836 NLM_EXTERN PackSegPtr LIBCALL PackSegNew (void)
1837 {
1838 return (PackSegPtr)MemNew(sizeof(PackSeg));
1839 }
1840
1841 /*****************************************************************************
1842 *
1843 * PackSegFree(psp)
1844 * Frees one PackSeg and associated data
1845 *
1846 *****************************************************************************/
1847 NLM_EXTERN PackSegPtr LIBCALL PackSegFree (PackSegPtr psp)
1848 {
1849 if (psp == NULL)
1850 return psp;
1851
1852 SeqIdSetFree(psp->ids); /* frees chain */
1853 MemFree(psp->starts);
1854 BSFree(psp->present);
1855 MemFree(psp->lens);
1856 MemFree(psp->strands);
1857 ScoreSetFree(psp->scores); /* frees chain */
1858 return (PackSegPtr)MemFree(psp);
1859 }
1860
1861 /*****************************************************************************
1862 *
1863 * PackSegAsnWrite(psp, aip, atp)
1864 * atp is the current type (if identifier of a parent struct)
1865 * if atp == NULL, then assumes it stands alone (PackSeg ::=)
1866 *
1867 *****************************************************************************/
1868 NLM_EXTERN Boolean LIBCALL PackSegAsnWrite (PackSegPtr psp, AsnIoPtr aip, AsnTypePtr orig)
1869 {
1870 DataVal av;
1871 AsnTypePtr atp;
1872 Int2 dim = 0, i, /* global dimensionality */
1873 numseg = 0; /* number of segments represented */
1874 Boolean retval = FALSE;
1875
1876 if (! loaded)
1877 {
1878 if (! SeqAlignAsnLoad())
1879 return FALSE;
1880 }
1881
1882 if (aip == NULL)
1883 return FALSE;
1884
1885 atp = AsnLinkType(orig, PACKED_SEG); /* link local tree */
1886 if (atp == NULL)
1887 return FALSE;
1888
1889 if (psp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1890
1891 if (! AsnOpenStruct(aip, atp, (Pointer)psp))
1892 goto erret;
1893
1894 if (psp->dim) /* default global dimensionality? */
1895 {
1896 dim = psp->dim;
1897 av.intvalue = psp->dim;
1898 if (! AsnWrite(aip, PACKED_SEG_dim, &av)) goto erret;
1899 }
1900 else
1901 dim = 2; /* default value */
1902
1903 numseg = psp->numseg;
1904 av.intvalue = numseg;
1905 if (! AsnWrite(aip, PACKED_SEG_numseg, &av)) goto erret;
1906
1907 /* write the SeqIds */
1908 if (! SeqIdSetAsnWrite(psp->ids, aip, PACKED_SEG_ids, PACKED_SEG_ids_E))
1909 goto erret;
1910
1911 if (! AsnOpenStruct(aip, PACKED_SEG_starts, (Pointer)psp->starts))
1912 goto erret;
1913 for (i = 0; i < dim; i++)
1914 {
1915 av.intvalue = psp->starts[i];
1916 if (! AsnWrite(aip, PACKED_SEG_starts_E, &av)) goto erret;
1917 }
1918 if (! AsnCloseStruct(aip, PACKED_SEG_starts, (Pointer)psp->starts))
1919 goto erret;
1920
1921 av.ptrvalue = psp->present;
1922 if (! AsnWrite(aip, PACKED_SEG_present, &av)) goto erret;
1923
1924 if (! AsnOpenStruct(aip, PACKED_SEG_lens, (Pointer)psp->lens))
1925 goto erret;
1926 for (i = 0; i < numseg; i++)
1927 {
1928 av.intvalue = psp->lens[i];
1929 if (! AsnWrite(aip, PACKED_SEG_lens_E, &av)) goto erret;
1930 }
1931 if (! AsnCloseStruct(aip, PACKED_SEG_lens, (Pointer)psp->lens))
1932 goto erret;
1933
1934 if (psp->strands != NULL)
1935 {
1936 if (! AsnOpenStruct(aip, PACKED_SEG_strands, (Pointer)psp->strands))
1937 goto erret;
1938 for (i = 0; i < dim; i++)
1939 {
1940 av.intvalue = psp->strands[i];
1941 if (! AsnWrite(aip, PACKED_SEG_strands_E, &av)) goto erret;
1942 }
1943 if (! AsnCloseStruct(aip, PACKED_SEG_strands, (Pointer)psp->strands))
1944 goto erret;
1945 }
1946
1947 if (psp->scores != NULL)
1948 {
1949 if (! InternalScoreSetAsnWrite(psp->scores, aip, PACKED_SEG_scores, PACKED_SEG_scores_E))
1950 goto erret;
1951 }
1952
1953 if (! AsnCloseStruct(aip, atp, (Pointer)psp))
1954 goto erret;
1955 retval = TRUE;
1956 erret:
1957 AsnUnlinkType(orig); /* unlink local tree */
1958 return retval;
1959 }
1960
1961 /*****************************************************************************
1962 *
1963 * PackSegAsnRead(aip, atp)
1964 * atp is the current type (if identifier of a parent struct)
1965 * assumption is readIdent has occurred
1966 * if atp == NULL, then assumes it stands alone and read ident
1967 * has not occurred.
1968 *
1969 *****************************************************************************/
1970 NLM_EXTERN PackSegPtr LIBCALL PackSegAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1971 {
1972 DataVal av;
1973 AsnTypePtr atp, oldtype;
1974 PackSegPtr psp=NULL;
1975 Int2 dim, i, numseg;
1976
1977 if (! loaded)
1978 {
1979 if (! SeqAlignAsnLoad())
1980 return psp;
1981 }
1982
1983 if (aip == NULL)
1984 return psp;
1985
1986 if (orig == NULL) /* PackSeg ::= (self contained) */
1987 atp = AsnReadId(aip, amp, PACKED_SEG);
1988 else
1989 atp = AsnLinkType(orig, PACKED_SEG); /* link in local tree */
1990 oldtype = atp;
1991 if (atp == NULL)
1992 return psp;
1993
1994 psp = PackSegNew();
1995 if (psp == NULL)
1996 goto erret;
1997
1998 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
1999 atp = AsnReadId(aip, amp, atp); /* read the dim or numseg */
2000 if (atp == NULL)
2001 goto erret;
2002 if (atp == PACKED_SEG_dim)
2003 {
2004 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2005 psp->dim = (Int2)av.intvalue;
2006 dim = psp->dim;
2007 atp = AsnReadId(aip, amp, atp); /* ids */
2008 if (atp == NULL)
2009 goto erret;
2010 }
2011 else
2012 dim = 2; /* default */
2013
2014 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* numseg */
2015 psp->numseg = (Int2)av.intvalue;
2016 numseg = psp->numseg;
2017
2018 atp = AsnReadId(aip, amp, atp);
2019 if (atp == NULL)
2020 goto erret;
2021 psp->ids = SeqIdSetAsnRead(aip, atp, PACKED_SEG_ids_E);
2022 if (psp->ids == NULL)
2023 goto erret;
2024
2025 psp->starts = (Int4Ptr) MemNew(sizeof(Int4) * dim);
2026 if (psp->starts == NULL)
2027 goto erret;
2028 atp = AsnReadId(aip, amp, atp); /* SEQ OF INTEGER */
2029 if (atp == NULL)
2030 goto erret;
2031 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2032 for (i = 0; i < dim; i++)
2033 {
2034 atp = AsnReadId(aip, amp, atp);
2035 if (atp != PACKED_SEG_starts_E)
2036 {
2037 ErrPost(CTX_NCBIOBJ, 1, "Too few starts in Dense-seg");
2038 goto erret;
2039 }
2040 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2041 psp->starts[i] = av.intvalue;
2042 }
2043 atp = AsnReadId(aip, amp, atp);
2044 if (atp != PACKED_SEG_starts)
2045 {
2046 ErrPost(CTX_NCBIOBJ, 1, "Too many starts in Dense-seg");
2047 goto erret;
2048 }
2049 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF INTEGER */
2050
2051 atp = AsnReadId(aip, amp, atp); /* Packed-seg.present */
2052 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2053 psp->present = (ByteStorePtr)(av.ptrvalue);
2054
2055 psp->lens = (Int4Ptr) MemNew(sizeof(Int4) * numseg);
2056 if (psp->lens == NULL)
2057 goto erret;
2058 atp = AsnReadId(aip, amp, atp); /* SEQ OF INTEGER */
2059 if (atp == NULL)
2060 goto erret;
2061 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2062 for (i = 0; i < numseg; i++)
2063 {
2064 atp = AsnReadId(aip, amp, atp);
2065 if (atp != PACKED_SEG_lens_E)
2066 {
2067 ErrPost(CTX_NCBIOBJ, 1, "Too few lens in Dense-seg");
2068 goto erret;
2069 }
2070 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2071 psp->lens[i] = av.intvalue;
2072 }
2073 atp = AsnReadId(aip, amp, atp);
2074 if (atp != PACKED_SEG_lens)
2075 {
2076 ErrPost(CTX_NCBIOBJ, 1, "Too many lens in Dense-seg");
2077 goto erret;
2078 }
2079 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF INTEGER */
2080
2081 while ((atp = AsnReadId(aip, amp, atp)) != oldtype)
2082 {
2083 if (atp == NULL)
2084 goto erret;
2085 if (atp == PACKED_SEG_strands)
2086 {
2087 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* start SEQ OF */
2088 psp->strands = (Uint1Ptr) MemNew(sizeof(Uint1) * dim);
2089 if (psp->strands == NULL)
2090 goto erret;
2091 for (i = 0; i < dim; i++)
2092 {
2093 atp = AsnReadId(aip, amp, atp);
2094 if (atp == NULL)
2095 goto erret;
2096 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2097 psp->strands[i] = (Uint1)av.intvalue;
2098 }
2099 atp = AsnReadId(aip, amp, atp);
2100 if (atp == NULL)
2101 goto erret;
2102 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF */
2103 }
2104 else if (atp == PACKED_SEG_scores)
2105 {
2106 psp->scores = InternalScoreSetAsnRead(aip, PACKED_SEG_scores, PACKED_SEG_scores_E);
2107 if (psp->scores == NULL)
2108 goto erret;
2109 }
2110 }
2111
2112 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
2113 ret:
2114 AsnUnlinkType(orig); /* unlink local tree */
2115 return psp;
2116 erret:
2117 psp = PackSegFree(psp);
2118 goto ret;
2119 }
2120
2121
2122 /**************************************************
2123 *
2124 * SplicedSegNew()
2125 *
2126 **************************************************/
2127 NLM_EXTERN
2128 SplicedSegPtr LIBCALL
2129 SplicedSegNew(void)
2130 {
2131 SplicedSegPtr ptr = MemNew((size_t) sizeof(SplicedSeg));
2132
2133 return ptr;
2134
2135 }
2136
2137
2138 /**************************************************
2139 *
2140 * SplicedSegFree()
2141 *
2142 **************************************************/
2143 NLM_EXTERN
2144 SplicedSegPtr LIBCALL
2145 SplicedSegFree(SplicedSegPtr ptr)
2146 {
2147
2148 if(ptr == NULL) {
2149 return NULL;
2150 }
2151 SeqIdFree(ptr -> product_id);
2152 SeqIdFree(ptr -> genomic_id);
2153 AsnGenericUserSeqOfFree(ptr -> exons, (AsnOptFreeFunc) SplicedExonFree);
2154 AsnGenericChoiceSeqOfFree(ptr -> modifiers, (AsnOptFreeFunc) SplicedSegModifierFree);
2155 return MemFree(ptr);
2156 }
2157
2158
2159 /**************************************************
2160 *
2161 * SplicedSegAsnRead()
2162 *
2163 **************************************************/
2164 NLM_EXTERN
2165 SplicedSegPtr LIBCALL
2166 SplicedSegAsnRead(AsnIoPtr aip, AsnTypePtr orig)
2167 {
2168 DataVal av;
2169 AsnTypePtr atp;
2170 Boolean isError = FALSE;
2171 AsnReadFunc func;
2172 SplicedSegPtr ptr;
2173
2174 if (! loaded)
2175 {
2176 if (! SeqAlignAsnLoad()) {
2177 return NULL;
2178 }
2179 }
2180
2181 if (aip == NULL) {
2182 return NULL;
2183 }
2184
2185 if (orig == NULL) { /* SplicedSeg ::= (self contained) */
2186 atp = AsnReadId(aip, amp, SPLICED_SEG);
2187 } else {
2188 atp = AsnLinkType(orig, SPLICED_SEG);
2189 }
2190 /* link in local tree */
2191 if (atp == NULL) {
2192 return NULL;
2193 }
2194
2195 ptr = SplicedSegNew();
2196 if (ptr == NULL) {
2197 goto erret;
2198 }
2199 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
2200 goto erret;
2201 }
2202
2203 atp = AsnReadId(aip,amp, atp);
2204 func = NULL;
2205
2206 if (atp == SPLICED_SEG_product_id) {
2207 ptr -> product_id = SeqIdAsnRead(aip, atp);
2208 if (aip -> io_failure) {
2209 goto erret;
2210 }
2211 atp = AsnReadId(aip,amp, atp);
2212 }
2213 if (atp == SPLICED_SEG_genomic_id) {
2214 ptr -> genomic_id = SeqIdAsnRead(aip, atp);
2215 if (aip -> io_failure) {
2216 goto erret;
2217 }
2218 atp = AsnReadId(aip,amp, atp);
2219 }
2220 if (atp == SPLICED_SEG_product_strand) {
2221 if ( AsnReadVal(aip, atp, &av) <= 0) {
2222 goto erret;
2223 }
2224 ptr -> product_strand = av.intvalue;
2225 ptr -> OBbits__ |= 1<<0;
2226 atp = AsnReadId(aip,amp, atp);
2227 }
2228 if (atp == SPLICED_SEG_genomic_strand) {
2229 if ( AsnReadVal(aip, atp, &av) <= 0) {
2230 goto erret;
2231 }
2232 ptr -> genomic_strand = av.intvalue;
2233 ptr -> OBbits__ |= 1<<1;
2234 atp = AsnReadId(aip,amp, atp);
2235 }
2236 if (atp == SPLICED_SEG_product_type) {
2237 if ( AsnReadVal(aip, atp, &av) <= 0) {
2238 goto erret;
2239 }
2240 ptr -> product_type = av.intvalue;
2241 atp = AsnReadId(aip,amp, atp);
2242 }
2243 if (atp == SPLICED_SEG_exons) {
2244 ptr -> exons = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) SplicedExonAsnRead, (AsnOptFreeFunc) SplicedExonFree);
2245 if (isError && ptr -> exons == NULL) {
2246 goto erret;
2247 }
2248 atp = AsnReadId(aip,amp, atp);
2249 }
2250 if (atp == SPLICED_SEG_poly_a) {
2251 if ( AsnReadVal(aip, atp, &av) <= 0) {
2252 goto erret;
2253 }
2254 ptr -> poly_a = av.intvalue;
2255 ptr -> OBbits__ |= 1<<2;
2256 atp = AsnReadId(aip,amp, atp);
2257 }
2258 if (atp == SPLICED_SEG_product_length) {
2259 if ( AsnReadVal(aip, atp, &av) <= 0) {
2260 goto erret;
2261 }
2262 ptr -> product_length = av.intvalue;
2263 ptr -> OBbits__ |= 1<<3;
2264 atp = AsnReadId(aip,amp, atp);
2265 }
2266 if (atp == SPLICED_SEG_modifiers) {
2267 ptr -> modifiers = AsnGenericChoiceSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) SplicedSegModifierAsnRead, (AsnOptFreeFunc) SplicedSegModifierFree);
2268 if (isError && ptr -> modifiers == NULL) {
2269 goto erret;
2270 }
2271 atp = AsnReadId(aip,amp, atp);
2272 }
2273
2274 if (AsnReadVal(aip, atp, &av) <= 0) {
2275 goto erret;
2276 }
2277 /* end struct */
2278
2279 ret:
2280 AsnUnlinkType(orig); /* unlink local tree */
2281 return ptr;
2282
2283 erret:
2284 aip -> io_failure = TRUE;
2285 ptr = SplicedSegFree(ptr);
2286 goto ret;
2287 }
2288
2289
2290
2291 /**************************************************
2292 *
2293 * SplicedSegAsnWrite()
2294 *
2295 **************************************************/
2296 NLM_EXTERN Boolean LIBCALL
2297 SplicedSegAsnWrite(SplicedSegPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
2298 {
2299 DataVal av;
2300 AsnTypePtr atp;
2301 Boolean retval = FALSE;
2302
2303 if (! loaded)
2304 {
2305 if (! SeqAlignAsnLoad()) {
2306 return FALSE;
2307 }
2308 }
2309
2310 if (aip == NULL) {
2311 return FALSE;
2312 }
2313
2314 atp = AsnLinkType(orig, SPLICED_SEG); /* link local tree */
2315 if (atp == NULL) {
2316 return FALSE;
2317 }
2318
2319 if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2320 if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
2321 goto erret;
2322 }
2323
2324 if (ptr -> product_id != NULL) {
2325 if ( ! SeqIdAsnWrite(ptr -> product_id, aip, SPLICED_SEG_product_id)) {
2326 goto erret;
2327 }
2328 }
2329 if (ptr -> genomic_id != NULL) {
2330 if ( ! SeqIdAsnWrite(ptr -> genomic_id, aip, SPLICED_SEG_genomic_id)) {
2331 goto erret;
2332 }
2333 }
2334 if (ptr -> product_strand || (ptr -> OBbits__ & (1<<0) )){ av.intvalue = ptr -> product_strand;
2335 retval = AsnWrite(aip, SPLICED_SEG_product_strand, &av);
2336 }
2337 if (ptr -> genomic_strand || (ptr -> OBbits__ & (1<<1) )){ av.intvalue = ptr -> genomic_strand;
2338 retval = AsnWrite(aip, SPLICED_SEG_genomic_strand, &av);
2339 }
2340 av.intvalue = ptr -> product_type;
2341 retval = AsnWrite(aip, SPLICED_SEG_product_type, &av);
2342 AsnGenericUserSeqOfAsnWrite(ptr -> exons, (AsnWriteFunc) SplicedExonAsnWrite, aip, SPLICED_SEG_exons, SPLICED_SEG_exons_E);
2343 if (ptr -> poly_a || (ptr -> OBbits__ & (1<<2) )){ av.intvalue = ptr -> poly_a;
2344 retval = AsnWrite(aip, SPLICED_SEG_poly_a, &av);
2345 }
2346 if (ptr -> product_length || (ptr -> OBbits__ & (1<<3) )){ av.intvalue = ptr -> product_length;
2347 retval = AsnWrite(aip, SPLICED_SEG_product_length, &av);
2348 }
2349 AsnGenericChoiceSeqOfAsnWrite(ptr -> modifiers, (AsnWriteFunc) SplicedSegModifierAsnWrite, aip, SPLICED_SEG_modifiers, SPLICED_SEG_modifiers_E);
2350 if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
2351 goto erret;
2352 }
2353 retval = TRUE;
2354
2355 erret:
2356 AsnUnlinkType(orig); /* unlink local tree */
2357 return retval;
2358 }
2359
2360
2361
2362 /**************************************************
2363 *
2364 * SparseSegNew()
2365 *
2366 **************************************************/
2367 NLM_EXTERN
2368 SparseSegPtr LIBCALL
2369 SparseSegNew(void)
2370 {
2371 SparseSegPtr ptr = MemNew((size_t) sizeof(SparseSeg));
2372
2373 return ptr;
2374
2375 }
2376
2377
2378 /**************************************************
2379 *
2380 * SparseSegFree()
2381 *
2382 **************************************************/
2383 NLM_EXTERN
2384 SparseSegPtr LIBCALL
2385 SparseSegFree(SparseSegPtr ptr)
2386 {
2387
2388 if(ptr == NULL) {
2389 return NULL;
2390 }
2391 SeqIdFree(ptr -> master_id);
2392 AsnGenericUserSeqOfFree(ptr -> rows, (AsnOptFreeFunc) SparseAlignFree);
2393 ScoreSetFree((ScorePtr) ptr -> row_scores);
2394 AsnGenericUserSeqOfFree(ptr -> ext, (AsnOptFreeFunc) SparseSegExtFree);
2395 return MemFree(ptr);
2396 }
2397
2398
2399 /**************************************************
2400 *
2401 * SparseSegAsnRead()
2402 *
2403 **************************************************/
2404 NLM_EXTERN
2405 SparseSegPtr LIBCALL
2406 SparseSegAsnRead(AsnIoPtr aip, AsnTypePtr orig)
2407 {
2408 DataVal av;
2409 AsnTypePtr atp;
2410 Boolean isError = FALSE;
2411 AsnReadFunc func;
2412 SparseSegPtr ptr;
2413
2414 if (! loaded)
2415 {
2416 if (! SeqAlignAsnLoad()) {
2417 return NULL;
2418 }
2419 }
2420
2421 if (aip == NULL) {
2422 return NULL;
2423 }
2424
2425 if (orig == NULL) { /* SparseSeg ::= (self contained) */
2426 atp = AsnReadId(aip, amp, SPARSE_SEG);
2427 } else {
2428 atp = AsnLinkType(orig, SPARSE_SEG);
2429 }
2430 /* link in local tree */
2431 if (atp == NULL) {
2432 return NULL;
2433 }
2434
2435 ptr = SparseSegNew();
2436 if (ptr == NULL) {
2437 goto erret;
2438 }
2439 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
2440 goto erret;
2441 }
2442
2443 atp = AsnReadId(aip,amp, atp);
2444 func = NULL;
2445
2446 if (atp == SPARSE_SEG_master_id) {
2447 ptr -> master_id = SeqIdAsnRead(aip, atp);
2448 if (aip -> io_failure) {
2449 goto erret;
2450 }
2451 atp = AsnReadId(aip,amp, atp);
2452 }
2453 if (atp == SPARSE_SEG_rows) {
2454 ptr -> rows = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) SparseAlignAsnRead, (AsnOptFreeFunc) SparseAlignFree);
2455 if (isError && ptr -> rows == NULL) {
2456 goto erret;
2457 }
2458 atp = AsnReadId(aip,amp, atp);
2459 }
2460 if (atp == SPARSE_SEG_row_scores) {
2461 ptr -> row_scores = InternalScoreSetAsnRead(aip, SPARSE_SEG_row_scores, SPARSE_SEG_row_scores_E);
2462 if (isError && ptr -> row_scores == NULL) {
2463 goto erret;
2464 }
2465 atp = AsnReadId(aip,amp, atp);
2466 }
2467 if (atp == SPARSE_SEG_ext) {
2468 ptr -> ext = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) SparseSegExtAsnRead, (AsnOptFreeFunc) SparseSegExtFree);
2469 if (isError && ptr -> ext == NULL) {
2470 goto erret;
2471 }
2472 atp = AsnReadId(aip,amp, atp);
2473 }
2474
2475 if (AsnReadVal(aip, atp, &av) <= 0) {
2476 goto erret;
2477 }
2478 /* end struct */
2479
2480 ret:
2481 AsnUnlinkType(orig); /* unlink local tree */
2482 return ptr;
2483
2484 erret:
2485 aip -> io_failure = TRUE;
2486 ptr = SparseSegFree(ptr);
2487 goto ret;
2488 }
2489
2490
2491
2492 /**************************************************
2493 *
2494 * SparseSegAsnWrite()
2495 *
2496 **************************************************/
2497 NLM_EXTERN Boolean LIBCALL
2498 SparseSegAsnWrite(SparseSegPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
2499 {
2500 AsnTypePtr atp;
2501 Boolean retval = FALSE;
2502
2503 if (! loaded)
2504 {
2505 if (! SeqAlignAsnLoad()) {
2506 return FALSE;
2507 }
2508 }
2509
2510 if (aip == NULL) {
2511 return FALSE;
2512 }
2513
2514 atp = AsnLinkType(orig, SPARSE_SEG); /* link local tree */
2515 if (atp == NULL) {
2516 return FALSE;
2517 }
2518
2519 if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2520 if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
2521 goto erret;
2522 }
2523
2524 if (ptr -> master_id != NULL) {
2525 if ( ! SeqIdAsnWrite(ptr -> master_id, aip, SPARSE_SEG_master_id)) {
2526 goto erret;
2527 }
2528 }
2529 AsnGenericUserSeqOfAsnWrite(ptr -> rows, (AsnWriteFunc) SparseAlignAsnWrite, aip, SPARSE_SEG_rows, SPARSE_SEG_rows_E);
2530 if (ptr->row_scores != NULL)
2531 {
2532 if (! InternalScoreSetAsnWrite(ptr->row_scores, aip, SPARSE_SEG_row_scores, SPARSE_SEG_row_scores_E))
2533 goto erret;
2534 }
2535 AsnGenericUserSeqOfAsnWrite(ptr -> ext, (AsnWriteFunc) SparseSegExtAsnWrite, aip, SPARSE_SEG_ext, SPARSE_SEG_ext_E);
2536 if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
2537 goto erret;
2538 }
2539 retval = TRUE;
2540
2541 erret:
2542 AsnUnlinkType(orig); /* unlink local tree */
2543 return retval;
2544 }
2545
2546
2547
2548 /**************************************************
2549 *
2550 * SplicedExonNew()
2551 *
2552 **************************************************/
2553 NLM_EXTERN
2554 SplicedExonPtr LIBCALL
2555 SplicedExonNew(void)
2556 {
2557 SplicedExonPtr ptr = MemNew((size_t) sizeof(SplicedExon));
2558
2559 return ptr;
2560
2561 }
2562
2563
2564 /**************************************************
2565 *
2566 * SplicedExonFree()
2567 *
2568 **************************************************/
2569 NLM_EXTERN
2570 SplicedExonPtr LIBCALL
2571 SplicedExonFree(SplicedExonPtr ptr)
2572 {
2573
2574 if(ptr == NULL) {
2575 return NULL;
2576 }
2577 ProductPosFree(ptr -> product_start);
2578 ProductPosFree(ptr -> product_end);
2579 SeqIdFree(ptr -> product_id);
2580 SeqIdFree(ptr -> genomic_id);
2581 AsnGenericChoiceSeqOfFree(ptr -> parts, (AsnOptFreeFunc) SplicedExonChunkFree);
2582 ScoreSetFree((ScorePtr) ptr -> scores);
2583 SpliceSiteFree(ptr -> acceptor_before_exon);
2584 SpliceSiteFree(ptr -> donor_after_exon);
2585 AsnGenericUserSeqOfFree(ptr -> ext, (AsnOptFreeFunc) UserObjectFree);
2586 return MemFree(ptr);
2587 }
2588
2589
2590 /**************************************************
2591 *
2592 * SplicedExonAsnRead()
2593 *
2594 **************************************************/
2595 NLM_EXTERN
2596 SplicedExonPtr LIBCALL
2597 SplicedExonAsnRead(AsnIoPtr aip, AsnTypePtr orig)
2598 {
2599 DataVal av;
2600 AsnTypePtr atp;
2601 Boolean isError = FALSE;
2602 AsnReadFunc func;
2603 SplicedExonPtr ptr;
2604
2605 if (! loaded)
2606 {
2607 if (! SeqAlignAsnLoad()) {
2608 return NULL;
2609 }
2610 }
2611
2612 if (aip == NULL) {
2613 return NULL;
2614 }
2615
2616 if (orig == NULL) { /* SplicedExon ::= (self contained) */
2617 atp = AsnReadId(aip, amp, SPLICED_EXON);
2618 } else {
2619 atp = AsnLinkType(orig, SPLICED_EXON);
2620 }
2621 /* link in local tree */
2622 if (atp == NULL) {
2623 return NULL;
2624 }
2625
2626 ptr = SplicedExonNew();
2627 if (ptr == NULL) {
2628 goto erret;
2629 }
2630 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
2631 goto erret;
2632 }
2633
2634 atp = AsnReadId(aip,amp, atp);
2635 func = NULL;
2636
2637 if (atp == SPLICED_EXON_product_start) {
2638 ptr -> product_start = ProductPosAsnRead(aip, atp);
2639 if (aip -> io_failure) {
2640 goto erret;
2641 }
2642 atp = AsnReadId(aip,amp, atp);
2643 }
2644 if (atp == SPLICED_EXON_product_end) {
2645 ptr -> product_end = ProductPosAsnRead(aip, atp);
2646 if (aip -> io_failure) {
2647 goto erret;
2648 }
2649 atp = AsnReadId(aip,amp, atp);
2650 }
2651 if (atp == SPLICED_EXON_genomic_start) {
2652 if ( AsnReadVal(aip, atp, &av) <= 0) {
2653 goto erret;
2654 }
2655 ptr -> genomic_start = av.intvalue;
2656 atp = AsnReadId(aip,amp, atp);
2657 }
2658 if (atp == SPLICED_EXON_genomic_end) {
2659 if ( AsnReadVal(aip, atp, &av) <= 0) {
2660 goto erret;
2661 }
2662 ptr -> genomic_end = av.intvalue;
2663 atp = AsnReadId(aip,amp, atp);
2664 }
2665 if (atp == SPLICED_EXON_product_id) {
2666 ptr -> product_id = SeqIdAsnRead(aip, atp);
2667 if (aip -> io_failure) {
2668 goto erret;
2669 }
2670 atp = AsnReadId(aip,amp, atp);
2671 }
2672 if (atp == SPLICED_EXON_genomic_id) {
2673 ptr -> genomic_id = SeqIdAsnRead(aip, atp);
2674 if (aip -> io_failure) {
2675 goto erret;
2676 }
2677 atp = AsnReadId(aip,amp, atp);
2678 }
2679 if (atp == SPLICED_EXON_product_strand) {
2680 if ( AsnReadVal(aip, atp, &av) <= 0) {
2681 goto erret;
2682 }
2683 ptr -> product_strand = av.intvalue;
2684 atp = AsnReadId(aip,amp, atp);
2685 }
2686 if (atp == SPLICED_EXON_genomic_strand) {
2687 if ( AsnReadVal(aip, atp, &av) <= 0) {
2688 goto erret;
2689 }
2690 ptr -> genomic_strand = av.intvalue;
2691 atp = AsnReadId(aip,amp, atp);
2692 }
2693 if (atp == SPLICED_EXON_parts) {
2694 ptr -> parts = AsnGenericChoiceSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) SplicedExonChunkAsnRead, (AsnOptFreeFunc) SplicedExonChunkFree);
2695 if (isError && ptr -> parts == NULL) {
2696 goto erret;
2697 }
2698 atp = AsnReadId(aip,amp, atp);
2699 }
2700 if (atp == SPLICED_EXON_scores) {
2701 ptr -> scores = ScoreSetAsnRead(aip, atp);
2702 if (aip -> io_failure) {
2703 goto erret;
2704 }
2705 atp = AsnReadId(aip,amp, atp);
2706 }
2707 if (atp == EXON_acceptor_before_exon) {
2708 ptr -> acceptor_before_exon = SpliceSiteAsnRead(aip, atp);
2709 if (aip -> io_failure) {
2710 goto erret;
2711 }
2712 atp = AsnReadId(aip,amp, atp);
2713 }
2714 if (atp == SPLICED_EXON_donor_after_exon) {
2715 ptr -> donor_after_exon = SpliceSiteAsnRead(aip, atp);
2716 if (aip -> io_failure) {
2717 goto erret;
2718 }
2719 atp = AsnReadId(aip,amp, atp);
2720 }
2721 if (atp == SPLICED_EXON_partial) {
2722 if ( AsnReadVal(aip, atp, &av) <= 0) {
2723 goto erret;
2724 }
2725 ptr -> partial = av.boolvalue;
2726 atp = AsnReadId(aip,amp, atp);
2727 }
2728 if (atp == SPLICED_EXON_ext) {
2729 ptr -> ext = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, (AsnReadFunc) UserObjectAsnRead, (AsnOptFreeFunc) UserObjectFree);
2730 if (isError && ptr -> ext == NULL) {
2731 goto erret;
2732 }
2733 atp = AsnReadId(aip,amp, atp);
2734 }
2735
2736 if (AsnReadVal(aip, atp, &av) <= 0) {
2737 goto erret;
2738 }
2739 /* end struct */
2740
2741 ret:
2742 AsnUnlinkType(orig); /* unlink local tree */
2743 return ptr;
2744
2745 erret:
2746 aip -> io_failure = TRUE;
2747 ptr = SplicedExonFree(ptr);
2748 goto ret;
2749 }
2750
2751
2752
2753 /**************************************************
2754 *
2755 * SplicedExonAsnWrite()
2756 *
2757 **************************************************/
2758 NLM_EXTERN Boolean LIBCALL
2759 SplicedExonAsnWrite(SplicedExonPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
2760 {
2761 DataVal av;
2762 AsnTypePtr atp;
2763 Boolean retval = FALSE;
2764
2765 if (! loaded)
2766 {
2767 if (! SeqAlignAsnLoad()) {
2768 return FALSE;
2769 }
2770 }
2771
2772 if (aip == NULL) {
2773 return FALSE;
2774 }
2775
2776 atp = AsnLinkType(orig, SPLICED_EXON); /* link local tree */
2777 if (atp == NULL) {
2778 return FALSE;
2779 }
2780
2781 if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2782 if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
2783 goto erret;
2784 }
2785
2786 if (ptr -> product_start != NULL) {
2787 if ( ! ProductPosAsnWrite(ptr -> product_start, aip, SPLICED_EXON_product_start)) {
2788 goto erret;
2789 }
2790 }
2791 if (ptr -> product_end != NULL) {
2792 if ( ! ProductPosAsnWrite(ptr -> product_end, aip, SPLICED_EXON_product_end)) {
2793 goto erret;
2794 }
2795 }
2796 av.intvalue = ptr -> genomic_start;
2797 retval = AsnWrite(aip, SPLICED_EXON_genomic_start, &av);
2798 av.intvalue = ptr -> genomic_end;
2799 retval = AsnWrite(aip, SPLICED_EXON_genomic_end, &av);
2800 if (ptr -> product_id != NULL) {
2801 if ( ! SeqIdAsnWrite(ptr -> product_id, aip, SPLICED_EXON_product_id)) {
2802 goto erret;
2803 }
2804 }
2805 if (ptr -> genomic_id != NULL) {
2806 if ( ! SeqIdAsnWrite(ptr -> genomic_id, aip, SPLICED_EXON_genomic_id)) {
2807 goto erret;
2808 }
2809 }
2810 if (ptr -> product_strand > 0) {
2811 av.intvalue = ptr -> product_strand;
2812 retval = AsnWrite(aip, SPLICED_EXON_product_strand, &av);
2813 }
2814 if (ptr -> genomic_strand > 0) {
2815 av.intvalue = ptr -> genomic_strand;
2816 retval = AsnWrite(aip, SPLICED_EXON_genomic_strand, &av);
2817 }
2818 AsnGenericChoiceSeqOfAsnWrite(ptr -> parts, (AsnWriteFunc) SplicedExonChunkAsnWrite, aip, SPLICED_EXON_parts, SPLICED_EXON_parts_E);
2819 if (ptr -> scores != NULL) {
2820 if ( ! ScoreSetAsnWrite((ScorePtr) ptr -> scores, aip, SPLICED_EXON_scores)) {
2821 goto erret;
2822 }
2823 }
2824 if (ptr -> acceptor_before_exon != NULL) {
2825 if ( ! SpliceSiteAsnWrite(ptr -> acceptor_before_exon, aip, EXON_acceptor_before_exon)) {
2826 goto erret;
2827 }
2828 }
2829 if (ptr -> donor_after_exon != NULL) {
2830 if ( ! SpliceSiteAsnWrite(ptr -> donor_after_exon, aip, SPLICED_EXON_donor_after_exon)) {
2831 goto erret;
2832 }
2833 }
2834 if (ptr -> partial) {
2835 av.boolvalue = ptr -> partial;
2836 retval = AsnWrite(aip, SPLICED_EXON_partial, &av);
2837 }
2838 AsnGenericUserSeqOfAsnWrite(ptr -> ext, (AsnWriteFunc) UserObjectAsnWrite, aip, SPLICED_EXON_ext, SPLICED_EXON_ext_E);
2839 if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
2840 goto erret;
2841 }
2842 retval = TRUE;
2843
2844 erret:
2845 AsnUnlinkType(orig); /* unlink local tree */
2846 return retval;
2847 }
2848
2849
2850
2851 /**************************************************
2852 *
2853 * SplicedSegModifierFree()
2854 *
2855 **************************************************/
2856 NLM_EXTERN
2857 SplicedSegModifierPtr LIBCALL
2858 SplicedSegModifierFree(ValNodePtr anp)
2859 {
2860 Pointer pnt;
2861
2862 if (anp == NULL) {
2863 return NULL;
2864 }
2865
2866 pnt = anp->data.ptrvalue;
2867 switch (anp->choice)
2868 {
2869 default:
2870 break;
2871 }
2872 return MemFree(anp);
2873 }
2874
2875
2876 /**************************************************
2877 *
2878 * SplicedSegModifierAsnRead()
2879 *
2880 **************************************************/
2881 NLM_EXTERN
2882 SplicedSegModifierPtr LIBCALL
2883 SplicedSegModifierAsnRead(AsnIoPtr aip, AsnTypePtr orig)
2884 {
2885 DataVal av;
2886 AsnTypePtr atp;
2887 ValNodePtr anp;
2888 Uint1 choice;
2889 Boolean nullIsError = FALSE;
2890 AsnReadFunc func;
2891
2892 if (! loaded)
2893 {
2894 if (! SeqAlignAsnLoad()) {
2895 return NULL;
2896 }
2897 }
2898
2899 if (aip == NULL) {
2900 return NULL;
2901 }
2902
2903 if (orig == NULL) { /* SplicedSegModifier ::= (self contained) */
2904 atp = AsnReadId(aip, amp, SPLICED_SEG_MODIFIER);
2905 } else {
2906 atp = AsnLinkType(orig, SPLICED_SEG_MODIFIER); /* link in local tree */
2907 }
2908 if (atp == NULL) {
2909 return NULL;
2910 }
2911
2912 anp = ValNodeNew(NULL);
2913 if (anp == NULL) {
2914 goto erret;
2915 }
2916 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the CHOICE or OpenStruct value (nothing) */
2917 goto erret;
2918 }
2919
2920 func = NULL;
2921
2922 atp = AsnReadId(aip, amp, atp); /* find the choice */
2923 if (atp == NULL) {
2924 goto erret;
2925 }
2926 if (atp == SEG_MODIFIER_start_codon_found) {
2927 choice = SplicedSegModifier_start_codon_found;
2928 if (AsnReadVal(aip, atp, &av) <= 0) {
2929 goto erret;
2930 }
2931 anp->data.boolvalue = av.boolvalue;
2932 }
2933 else if (atp == SEG_MODIFIER_stop_codon_found) {
2934 choice = SplicedSegModifier_stop_codon_found;
2935 if (AsnReadVal(aip, atp, &av) <= 0) {
2936 goto erret;
2937 }
2938 anp->data.boolvalue = av.boolvalue;
2939 }
2940 anp->choice = choice;
2941 if (func != NULL)
2942 {
2943 anp->data.ptrvalue = (* func)(aip, atp);
2944 if (aip -> io_failure) goto erret;
2945
2946 if (nullIsError && anp->data.ptrvalue == NULL) {
2947 goto erret;
2948 }
2949 }
2950
2951 ret:
2952 AsnUnlinkType(orig); /* unlink local tree */
2953 return anp;
2954
2955 erret:
2956 anp = MemFree(anp);
2957 aip -> io_failure = TRUE;
2958 goto ret;
2959 }
2960
2961
2962 /**************************************************
2963 *
2964 * SplicedSegModifierAsnWrite()
2965 *
2966 **************************************************/
2967 NLM_EXTERN Boolean LIBCALL
2968 SplicedSegModifierAsnWrite(SplicedSegModifierPtr anp, AsnIoPtr aip, AsnTypePtr orig)
2969
2970 {
2971 DataVal av;
2972 AsnTypePtr atp, writetype = NULL;
2973 Pointer pnt;
2974 AsnWriteFunc func = NULL;
2975 Boolean retval = FALSE;
2976
2977 if (! loaded)
2978 {
2979 if (! SeqAlignAsnLoad())
2980 return FALSE;
2981 }
2982
2983 if (aip == NULL)
2984 return FALSE;
2985
2986 atp = AsnLinkType(orig, SPLICED_SEG_MODIFIER); /* link local tree */
2987 if (atp == NULL) {
2988 return FALSE;
2989 }
2990
2991 if (anp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2992
2993 av.ptrvalue = (Pointer)anp;
2994 if (! AsnWriteChoice(aip, atp, (Int2)anp->choice, &av)) {
2995 goto erret;
2996 }
2997
2998 pnt = anp->data.ptrvalue;
2999 switch (anp->choice)
3000 {
3001 case SplicedSegModifier_start_codon_found:
3002 av.boolvalue = anp->data.boolvalue;
3003 retval = AsnWrite(aip, SEG_MODIFIER_start_codon_found, &av);
3004 break;
3005 case SplicedSegModifier_stop_codon_found:
3006 av.boolvalue = anp->data.boolvalue;
3007 retval = AsnWrite(aip, SEG_MODIFIER_stop_codon_found, &av);
3008 break;
3009 }
3010 if (writetype != NULL) {
3011 retval = (* func)(pnt, aip, writetype); /* write it out */
3012 }
3013 if (!retval) {
3014 goto erret;
3015 }
3016 retval = TRUE;
3017
3018 erret:
3019 AsnUnlinkType(orig); /* unlink local tree */
3020 return retval;
3021 }
3022
3023
3024 /**************************************************
3025 *
3026 * ProductPosFree()
3027 *
3028 **************************************************/
3029 NLM_EXTERN
3030 ProductPosPtr LIBCALL
3031 ProductPosFree(ValNodePtr anp)
3032 {
3033 Pointer pnt;
3034
3035 if (anp == NULL) {
3036 return NULL;
3037 }
3038
3039 pnt = anp->data.ptrvalue;
3040 switch (anp->choice)
3041 {
3042 default:
3043 break;
3044 case ProductPos_protpos:
3045 ProtPosFree(anp -> data.ptrvalue);
3046 break;
3047 }
3048 return MemFree(anp);
3049 }
3050
3051
3052 /**************************************************
3053 *
3054 * ProductPosAsnRead()
3055 *
3056 **************************************************/
3057 NLM_EXTERN
3058 ProductPosPtr LIBCALL
3059 ProductPosAsnRead(AsnIoPtr aip, AsnTypePtr orig)
3060 {
3061 DataVal av;
3062 AsnTypePtr atp;
3063 ValNodePtr anp;
3064 Uint1 choice;
3065 Boolean nullIsError = FALSE;
3066 AsnReadFunc func;
3067
3068 if (! loaded)
3069 {
3070 if (! SeqAlignAsnLoad()) {
3071 return NULL;
3072 }
3073 }
3074
3075 if (aip == NULL) {
3076 return NULL;
3077 }
3078
3079 if (orig == NULL) { /* ProductPos ::= (self contained) */
3080 atp = AsnReadId(aip, amp, PRODUCT_POS);
3081 } else {
3082 atp = AsnLinkType(orig, PRODUCT_POS); /* link in local tree */
3083 }
3084 if (atp == NULL) {
3085 return NULL;
3086 }
3087
3088 anp = ValNodeNew(NULL);
3089 if (anp == NULL) {
3090 goto erret;
3091 }
3092 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the CHOICE or OpenStruct value (nothing) */
3093 goto erret;
3094 }
3095
3096 func = NULL;
3097
3098 atp = AsnReadId(aip, amp, atp); /* find the choice */
3099 if (atp == NULL) {
3100 goto erret;
3101 }
3102 if (atp == PRODUCT_POS_nucpos) {
3103 choice = ProductPos_nucpos;
3104 if (AsnReadVal(aip, atp, &av) <= 0) {
3105 goto erret;
3106 }
3107 anp->data.intvalue = av.intvalue;
3108 }
3109 else if (atp == PRODUCT_POS_protpos) {
3110 choice = ProductPos_protpos;
3111 func = (AsnReadFunc) ProtPosAsnRead;
3112 }
3113 anp->choice = choice;
3114 if (func != NULL)
3115 {
3116 anp->data.ptrvalue = (* func)(aip, atp);
3117 if (aip -> io_failure) goto erret;
3118
3119 if (nullIsError && anp->data.ptrvalue == NULL) {
3120 goto erret;
3121 }
3122 }
3123
3124 ret:
3125 AsnUnlinkType(orig); /* unlink local tree */
3126 return anp;
3127
3128 erret:
3129 anp = MemFree(anp);
3130 aip -> io_failure = TRUE;
3131 goto ret;
3132 }
3133
3134
3135 /**************************************************
3136 *
3137 * ProductPosAsnWrite()
3138 *
3139 **************************************************/
3140 NLM_EXTERN Boolean LIBCALL
3141 ProductPosAsnWrite(ProductPosPtr anp, AsnIoPtr aip, AsnTypePtr orig)
3142
3143 {
3144 DataVal av;
3145 AsnTypePtr atp, writetype = NULL;
3146 Pointer pnt;
3147 AsnWriteFunc func = NULL;
3148 Boolean retval = FALSE;
3149
3150 if (! loaded)
3151 {
3152 if (! SeqAlignAsnLoad())
3153 return FALSE;
3154 }
3155
3156 if (aip == NULL)
3157 return FALSE;
3158
3159 atp = AsnLinkType(orig, PRODUCT_POS); /* link local tree */
3160 if (atp == NULL) {
3161 return FALSE;
3162 }
3163
3164 if (anp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3165
3166 av.ptrvalue = (Pointer)anp;
3167 if (! AsnWriteChoice(aip, atp, (Int2)anp->choice, &av)) {
3168 goto erret;
3169 }
3170
3171 pnt = anp->data.ptrvalue;
3172 switch (anp->choice)
3173 {
3174 case ProductPos_nucpos:
3175 av.intvalue = anp->data.intvalue;
3176 retval = AsnWrite(aip, PRODUCT_POS_nucpos, &av);
3177 break;
3178 case ProductPos_protpos:
3179 writetype = PRODUCT_POS_protpos;
3180 func = (AsnWriteFunc) ProtPosAsnWrite;
3181 break;
3182 }
3183 if (writetype != NULL) {
3184 retval = (* func)(pnt, aip, writetype); /* write it out */
3185 }
3186 if (!retval) {
3187 goto erret;
3188 }
3189 retval = TRUE;
3190
3191 erret:
3192 AsnUnlinkType(orig); /* unlink local tree */
3193 return retval;
3194 }
3195
3196
3197 /**************************************************
3198 *
3199 * SplicedExonChunkFree()
3200 *
3201 **************************************************/
3202 NLM_EXTERN
3203 SplicedExonChunkPtr LIBCALL
3204 SplicedExonChunkFree(ValNodePtr anp)
3205 {
3206 Pointer pnt;
3207
3208 if (anp == NULL) {
3209 return NULL;
3210 }
3211
3212 pnt = anp->data.ptrvalue;
3213 switch (anp->choice)
3214 {
3215 default:
3216 break;
3217 }
3218 return MemFree(anp);
3219 }
3220
3221
3222 /**************************************************
3223 *
3224 * SplicedExonChunkAsnRead()
3225 *
3226 **************************************************/
3227 NLM_EXTERN
3228 SplicedExonChunkPtr LIBCALL
3229 SplicedExonChunkAsnRead(AsnIoPtr aip, AsnTypePtr orig)
3230 {
3231 DataVal av;
3232 AsnTypePtr atp;
3233 ValNodePtr anp;
3234 Uint1 choice;
3235 Boolean nullIsError = FALSE;
3236 AsnReadFunc func;
3237
3238 if (! loaded)
3239 {
3240 if (! SeqAlignAsnLoad()) {
3241 return NULL;
3242 }
3243 }
3244
3245 if (aip == NULL) {
3246 return NULL;
3247 }
3248
3249 if (orig == NULL) { /* SplicedExonChunk ::= (self contained) */
3250 atp = AsnReadId(aip, amp, SPLICED_EXON_CHUNK);
3251 } else {
3252 atp = AsnLinkType(orig, SPLICED_EXON_CHUNK); /* link in local tree */
3253 }
3254 if (atp == NULL) {
3255 return NULL;
3256 }
3257
3258 anp = ValNodeNew(NULL);
3259 if (anp == NULL) {
3260 goto erret;
3261 }
3262 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the CHOICE or OpenStruct value (nothing) */
3263 goto erret;
3264 }
3265
3266 func = NULL;
3267
3268 atp = AsnReadId(aip, amp, atp); /* find the choice */
3269 if (atp == NULL) {
3270 goto erret;
3271 }
3272 if (atp == SPLICED_EXON_CHUNK_match) {
3273 choice = SplicedExonChunk_match;
3274 if (AsnReadVal(aip, atp, &av) <= 0) {
3275 goto erret;
3276 }
3277 anp->data.intvalue = av.intvalue;
3278 }
3279 else if (atp == SPLICED_EXON_CHUNK_mismatch) {
3280 choice = SplicedExonChunk_mismatch;
3281 if (AsnReadVal(aip, atp, &av) <= 0) {
3282 goto erret;
3283 }
3284 anp->data.intvalue = av.intvalue;
3285 }
3286 else if (atp == SPLICED_EXON_CHUNK_diag) {
3287 choice = SplicedExonChunk_diag;
3288 if (AsnReadVal(aip, atp, &av) <= 0) {
3289 goto erret;
3290 }
3291 anp->data.intvalue = av.intvalue;
3292 }
3293 else if (atp == SPLICED_EXON_CHUNK_product_ins) {
3294 choice = SplicedExonChunk_product_ins;
3295 if (AsnReadVal(aip, atp, &av) <= 0) {
3296 goto erret;
3297 }
3298 anp->data.intvalue = av.intvalue;
3299 }
3300 else if (atp == SPLICED_EXON_CHUNK_genomic_ins) {
3301 choice = SplicedExonChunk_genomic_ins;
3302 if (AsnReadVal(aip, atp, &av) <= 0) {
3303 goto erret;
3304 }
3305 anp->data.intvalue = av.intvalue;
3306 }
3307 anp->choice = choice;
3308 if (func != NULL)
3309 {
3310 anp->data.ptrvalue = (* func)(aip, atp);
3311 if (aip -> io_failure) goto erret;
3312
3313 if (nullIsError && anp->data.ptrvalue == NULL) {
3314 goto erret;
3315 }
3316 }
3317
3318 ret:
3319 AsnUnlinkType(orig); /* unlink local tree */
3320 return anp;
3321
3322 erret:
3323 anp = MemFree(anp);
3324 aip -> io_failure = TRUE;
3325 goto ret;
3326 }
3327
3328
3329 /**************************************************
3330 *
3331 * SplicedExonChunkAsnWrite()
3332 *
3333 **************************************************/
3334 NLM_EXTERN Boolean LIBCALL
3335 SplicedExonChunkAsnWrite(SplicedExonChunkPtr anp, AsnIoPtr aip, AsnTypePtr orig)
3336
3337 {
3338 DataVal av;
3339 AsnTypePtr atp, writetype = NULL;
3340 Pointer pnt;
3341 AsnWriteFunc func = NULL;
3342 Boolean retval = FALSE;
3343
3344 if (! loaded)
3345 {
3346 if (! SeqAlignAsnLoad())
3347 return FALSE;
3348 }
3349
3350 if (aip == NULL)
3351 return FALSE;
3352
3353 atp = AsnLinkType(orig, SPLICED_EXON_CHUNK); /* link local tree */
3354 if (atp == NULL) {
3355 return FALSE;
3356 }
3357
3358 if (anp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3359
3360 av.ptrvalue = (Pointer)anp;
3361 if (! AsnWriteChoice(aip, atp, (Int2)anp->choice, &av)) {
3362 goto erret;
3363 }
3364
3365 pnt = anp->data.ptrvalue;
3366 switch (anp->choice)
3367 {
3368 case SplicedExonChunk_match:
3369 av.intvalue = anp->data.intvalue;
3370 retval = AsnWrite(aip, SPLICED_EXON_CHUNK_match, &av);
3371 break;
3372 case SplicedExonChunk_mismatch:
3373 av.intvalue = anp->data.intvalue;
3374 retval = AsnWrite(aip, SPLICED_EXON_CHUNK_mismatch, &av);
3375 break;
3376 case SplicedExonChunk_diag:
3377 av.intvalue = anp->data.intvalue;
3378 retval = AsnWrite(aip, SPLICED_EXON_CHUNK_diag, &av);
3379 break;
3380 case SplicedExonChunk_product_ins:
3381 av.intvalue = anp->data.intvalue;
3382 retval = AsnWrite(aip, SPLICED_EXON_CHUNK_product_ins, &av);
3383 break;
3384 case SplicedExonChunk_genomic_ins:
3385 av.intvalue = anp->data.intvalue;
3386 retval = AsnWrite(aip, SPLICED_EXON_CHUNK_genomic_ins, &av);
3387 break;
3388 }
3389 if (writetype != NULL) {
3390 retval = (* func)(pnt, aip, writetype); /* write it out */
3391 }
3392 if (!retval) {
3393 goto erret;
3394 }
3395 retval = TRUE;
3396
3397 erret:
3398 AsnUnlinkType(orig); /* unlink local tree */
3399 return retval;
3400 }
3401
3402
3403 /**************************************************
3404 *
3405 * SpliceSiteNew()
3406 *
3407 **************************************************/
3408 NLM_EXTERN
3409 SpliceSitePtr LIBCALL
3410 SpliceSiteNew(void)
3411 {
3412 SpliceSitePtr ptr = MemNew((size_t) sizeof(SpliceSite));
3413
3414 return ptr;
3415
3416 }
3417
3418
3419 /**************************************************
3420 *
3421 * SpliceSiteFree()
3422 *
3423 **************************************************/
3424 NLM_EXTERN
3425 SpliceSitePtr LIBCALL
3426 SpliceSiteFree(SpliceSitePtr ptr)
3427 {
3428
3429 if(ptr == NULL) {
3430 return NULL;
3431 }
3432 MemFree(ptr -> bases);
3433 return MemFree(ptr);
3434 }
3435
3436
3437 /**************************************************
3438 *
3439 * SpliceSiteAsnRead()
3440 *
3441 **************************************************/
3442 NLM_EXTERN
3443 SpliceSitePtr LIBCALL
3444 SpliceSiteAsnRead(AsnIoPtr aip, AsnTypePtr orig)
3445 {
3446 DataVal av;
3447 AsnTypePtr atp;
3448 AsnReadFunc func;
3449 SpliceSitePtr ptr;
3450
3451 if (! loaded)
3452 {
3453 if (! SeqAlignAsnLoad()) {
3454 return NULL;
3455 }
3456 }
3457
3458 if (aip == NULL) {
3459 return NULL;
3460 }
3461
3462 if (orig == NULL) { /* SpliceSite ::= (self contained) */
3463 atp = AsnReadId(aip, amp, SPLICE_SITE);
3464 } else {
3465 atp = AsnLinkType(orig, SPLICE_SITE);
3466 }
3467 /* link in local tree */
3468 if (atp == NULL) {
3469 return NULL;
3470 }
3471
3472 ptr = SpliceSiteNew();
3473 if (ptr == NULL) {
3474 goto erret;
3475 }
3476 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
3477 goto erret;
3478 }
3479
3480 atp = AsnReadId(aip,amp, atp);
3481 func = NULL;
3482
3483 if (atp == SPLICE_SITE_bases) {
3484 if ( AsnReadVal(aip, atp, &av) <= 0) {
3485 goto erret;
3486 }
3487 ptr -> bases = av.ptrvalue;
3488 atp = AsnReadId(aip,amp, atp);
3489 }
3490
3491 if (AsnReadVal(aip, atp, &av) <= 0) {
3492 goto erret;
3493 }
3494 /* end struct */
3495
3496 ret:
3497 AsnUnlinkType(orig); /* unlink local tree */
3498 return ptr;
3499
3500 erret:
3501 aip -> io_failure = TRUE;
3502 ptr = SpliceSiteFree(ptr);
3503 goto ret;
3504 }
3505
3506
3507
3508 /**************************************************
3509 *
3510 * SpliceSiteAsnWrite()
3511 *
3512 **************************************************/
3513 NLM_EXTERN Boolean LIBCALL
3514 SpliceSiteAsnWrite(SpliceSitePtr ptr, AsnIoPtr aip, AsnTypePtr orig)
3515 {
3516 DataVal av;
3517 AsnTypePtr atp;
3518 Boolean retval = FALSE;
3519
3520 if (! loaded)
3521 {
3522 if (! SeqAlignAsnLoad()) {
3523 return FALSE;
3524 }
3525 }
3526
3527 if (aip == NULL) {
3528 return FALSE;
3529 }
3530
3531 atp = AsnLinkType(orig, SPLICE_SITE); /* link local tree */
3532 if (atp == NULL) {
3533 return FALSE;
3534 }
3535
3536 if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3537 if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
3538 goto erret;
3539 }
3540
3541 if (ptr -> bases != NULL) {
3542 av.ptrvalue = ptr -> bases;
3543 retval = AsnWrite(aip, SPLICE_SITE_bases, &av);
3544 }
3545 if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
3546 goto erret;
3547 }
3548 retval = TRUE;
3549
3550 erret:
3551 AsnUnlinkType(orig); /* unlink local tree */
3552 return retval;
3553 }
3554
3555
3556
3557 /**************************************************
3558 *
3559 * ProtPosNew()
3560 *
3561 **************************************************/
3562 NLM_EXTERN
3563 ProtPosPtr LIBCALL
3564 ProtPosNew(void)
3565 {
3566 ProtPosPtr ptr = MemNew((size_t) sizeof(ProtPos));
3567
3568 ptr -> frame = 0;
3569 return ptr;
3570
3571 }
3572
3573
3574 /**************************************************
3575 *
3576 * ProtPosFree()
3577 *
3578 **************************************************/
3579 NLM_EXTERN
3580 ProtPosPtr LIBCALL
3581 ProtPosFree(ProtPosPtr ptr)
3582 {
3583
3584 if(ptr == NULL) {
3585 return NULL;
3586 }
3587 return MemFree(ptr);
3588 }
3589
3590
3591 /**************************************************
3592 *
3593 * ProtPosAsnRead()
3594 *
3595 **************************************************/
3596 NLM_EXTERN
3597 ProtPosPtr LIBCALL
3598 ProtPosAsnRead(AsnIoPtr aip, AsnTypePtr orig)
3599 {
3600 DataVal av;
3601 AsnTypePtr atp;
3602 AsnReadFunc func;
3603 ProtPosPtr ptr;
3604
3605 if (! loaded)
3606 {
3607 if (! SeqAlignAsnLoad()) {
3608 return NULL;
3609 }
3610 }
3611
3612 if (aip == NULL) {
3613 return NULL;
3614 }
3615
3616 if (orig == NULL) { /* ProtPos ::= (self contained) */
3617 atp = AsnReadId(aip, amp, PROT_POS);
3618 } else {
3619 atp = AsnLinkType(orig, PROT_POS);
3620 }
3621 /* link in local tree */
3622 if (atp == NULL) {
3623 return NULL;
3624 }
3625
3626 ptr = ProtPosNew();
3627 if (ptr == NULL) {
3628 goto erret;
3629 }
3630 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
3631 goto erret;
3632 }
3633
3634 atp = AsnReadId(aip,amp, atp);
3635 func = NULL;
3636
3637 if (atp == PROT_POS_amin) {
3638 if ( AsnReadVal(aip, atp, &av) <= 0) {
3639 goto erret;
3640 }
3641 ptr -> amin = av.intvalue;
3642 atp = AsnReadId(aip,amp, atp);
3643 }
3644 if (atp == PROT_POS_frame) {
3645 if ( AsnReadVal(aip, atp, &av) <= 0) {
3646 goto erret;
3647 }
3648 ptr -> frame = av.intvalue;
3649 atp = AsnReadId(aip,amp, atp);
3650 }
3651
3652 if (AsnReadVal(aip, atp, &av) <= 0) {
3653 goto erret;
3654 }
3655 /* end struct */
3656
3657 ret:
3658 AsnUnlinkType(orig); /* unlink local tree */
3659 return ptr;
3660
3661 erret:
3662 aip -> io_failure = TRUE;
3663 ptr = ProtPosFree(ptr);
3664 goto ret;
3665 }
3666
3667
3668
3669 /**************************************************
3670 *
3671 * ProtPosAsnWrite()
3672 *
3673 **************************************************/
3674 NLM_EXTERN Boolean LIBCALL
3675 ProtPosAsnWrite(ProtPosPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
3676 {
3677 DataVal av;
3678 AsnTypePtr atp;
3679 Boolean retval = FALSE;
3680
3681 if (! loaded)
3682 {
3683 if (! SeqAlignAsnLoad()) {
3684 return FALSE;
3685 }
3686 }
3687
3688 if (aip == NULL) {
3689 return FALSE;
3690 }
3691
3692 atp = AsnLinkType(orig, PROT_POS); /* link local tree */
3693 if (atp == NULL) {
3694 return FALSE;
3695 }
3696
3697 if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3698 if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
3699 goto erret;
3700 }
3701
3702 av.intvalue = ptr -> amin;
3703 retval = AsnWrite(aip, PROT_POS_amin, &av);
3704 av.intvalue = ptr -> frame;
3705 retval = AsnWrite(aip, PROT_POS_frame, &av);
3706 if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
3707 goto erret;
3708 }
3709 retval = TRUE;
3710
3711 erret:
3712 AsnUnlinkType(orig); /* unlink local tree */
3713 return retval;
3714 }
3715
3716
3717
3718
3719 /**************************************************
3720 *
3721 * SparseAlignNew()
3722 *
3723 **************************************************/
3724 NLM_EXTERN
3725 SparseAlignPtr LIBCALL
3726 SparseAlignNew(void)
3727 {
3728 SparseAlignPtr ptr = MemNew((size_t) sizeof(SparseAlign));
3729
3730 return ptr;
3731
3732 }
3733
3734
3735 /**************************************************
3736 *
3737 * SparseAlignFree()
3738 *
3739 **************************************************/
3740 NLM_EXTERN
3741 SparseAlignPtr LIBCALL
3742 SparseAlignFree(SparseAlignPtr ptr)
3743 {
3744
3745 if(ptr == NULL) {
3746 return NULL;
3747 }
3748 SeqIdFree(ptr -> first_id);
3749 SeqIdFree(ptr -> second_id);
3750 AsnGenericBaseSeqOfFree(ptr -> first_starts ,ASNCODE_INTVAL_SLOT);
3751 AsnGenericBaseSeqOfFree(ptr -> second_starts ,ASNCODE_INTVAL_SLOT);
3752 AsnGenericBaseSeqOfFree(ptr -> lens ,ASNCODE_INTVAL_SLOT);
3753 AsnGenericBaseSeqOfFree(ptr -> second_strands ,ASNCODE_INTVAL_SLOT);
3754 ScoreSetFree(ptr -> seg_scores);
3755 return MemFree(ptr);
3756 }
3757
3758
3759 /**************************************************
3760 *
3761 * SparseAlignAsnRead()
3762 *
3763 **************************************************/
3764 NLM_EXTERN
3765 SparseAlignPtr LIBCALL
3766 SparseAlignAsnRead(AsnIoPtr aip, AsnTypePtr orig)
3767 {
3768 DataVal av;
3769 AsnTypePtr atp;
3770 Boolean isError = FALSE;
3771 AsnReadFunc func;
3772 SparseAlignPtr ptr;
3773
3774 if (! loaded)
3775 {
3776 if (! SeqAlignAsnLoad()) {
3777 return NULL;
3778 }
3779 }
3780
3781 if (aip == NULL) {
3782 return NULL;
3783 }
3784
3785 if (orig == NULL) { /* SparseAlign ::= (self contained) */
3786 atp = AsnReadId(aip, amp, SPARSE_ALIGN);
3787 } else {
3788 atp = AsnLinkType(orig, SPARSE_ALIGN);
3789 }
3790 /* link in local tree */
3791 if (atp == NULL) {
3792 return NULL;
3793 }
3794
3795 ptr = SparseAlignNew();
3796 if (ptr == NULL) {
3797 goto erret;
3798 }
3799 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
3800 goto erret;
3801 }
3802
3803 atp = AsnReadId(aip,amp, atp);
3804 func = NULL;
3805
3806 if (atp == SPARSE_ALIGN_first_id) {
3807 ptr -> first_id = SeqIdAsnRead(aip, atp);
3808 if (aip -> io_failure) {
3809 goto erret;
3810 }
3811 atp = AsnReadId(aip,amp, atp);
3812 }
3813 if (atp == SPARSE_ALIGN_second_id) {
3814 ptr -> second_id = SeqIdAsnRead(aip, atp);
3815 if (aip -> io_failure) {
3816 goto erret;
3817 }
3818 atp = AsnReadId(aip,amp, atp);
3819 }
3820 if (atp == SPARSE_ALIGN_numseg) {
3821 if ( AsnReadVal(aip, atp, &av) <= 0) {
3822 goto erret;
3823 }
3824 ptr -> numseg = av.intvalue;
3825 atp = AsnReadId(aip,amp, atp);
3826 }
3827 if (atp == SPARSE_ALIGN_first_starts) {
3828 ptr -> first_starts = AsnGenericBaseSeqOfAsnRead(aip, amp, atp, ASNCODE_INTVAL_SLOT, &isError);
3829 if (isError && ptr -> first_starts == NULL) {
3830 goto erret;
3831 }
3832 atp = AsnReadId(aip,amp, atp);
3833 }
3834 if (atp == SPARSE_ALIGN_second_starts) {
3835 ptr -> second_starts = AsnGenericBaseSeqOfAsnRead(aip, amp, atp, ASNCODE_INTVAL_SLOT, &isError);
3836 if (isError && ptr -> second_starts == NULL) {
3837 goto erret;
3838 }
3839 atp = AsnReadId(aip,amp, atp);
3840 }
3841 if (atp == SPARSE_ALIGN_lens) {
3842 ptr -> lens = AsnGenericBaseSeqOfAsnRead(aip, amp, atp, ASNCODE_INTVAL_SLOT, &isError);
3843 if (isError && ptr -> lens == NULL) {
3844 goto erret;
3845 }
3846 atp = AsnReadId(aip,amp, atp);
3847 }
3848 if (atp == SPARSE_ALIGN_second_strands) {
3849 ptr -> second_strands = AsnGenericBaseSeqOfAsnRead(aip, amp, atp, ASNCODE_INTVAL_SLOT, &isError);
3850 if (isError && ptr -> second_strands == NULL) {
3851 goto erret;
3852 }
3853 atp = AsnReadId(aip,amp, atp);
3854 }
3855 if (atp == SPARSE_ALIGN_seg_scores) {
3856 ptr -> seg_scores = InternalScoreSetAsnRead(aip, SPARSE_ALIGN_seg_scores, SPARSE_ALIGN_seg_scores_E);
3857 if (isError && ptr -> seg_scores == NULL) {
3858 goto erret;
3859 }
3860 atp = AsnReadId(aip,amp, atp);
3861 }
3862
3863 if (AsnReadVal(aip, atp, &av) <= 0) {
3864 goto erret;
3865 }
3866 /* end struct */
3867
3868 ret:
3869 AsnUnlinkType(orig); /* unlink local tree */
3870 return ptr;
3871
3872 erret:
3873 aip -> io_failure = TRUE;
3874 ptr = SparseAlignFree(ptr);
3875 goto ret;
3876 }
3877
3878
3879
3880 /**************************************************
3881 *
3882 * SparseAlignAsnWrite()
3883 *
3884 **************************************************/
3885 NLM_EXTERN Boolean LIBCALL
3886 SparseAlignAsnWrite(SparseAlignPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
3887 {
3888 DataVal av;
3889 AsnTypePtr atp;
3890 Boolean retval = FALSE;
3891
3892 if (! loaded)
3893 {
3894 if (! SeqAlignAsnLoad()) {
3895 return FALSE;
3896 }
3897 }
3898
3899 if (aip == NULL) {
3900 return FALSE;
3901 }
3902
3903 atp = AsnLinkType(orig, SPARSE_ALIGN); /* link local tree */
3904 if (atp == NULL) {
3905 return FALSE;
3906 }
3907
3908 if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3909 if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
3910 goto erret;
3911 }
3912
3913 if (ptr -> first_id != NULL) {
3914 if ( ! SeqIdAsnWrite(ptr -> first_id, aip, SPARSE_ALIGN_first_id)) {
3915 goto erret;
3916 }
3917 }
3918 if (ptr -> second_id != NULL) {
3919 if ( ! SeqIdAsnWrite(ptr -> second_id, aip, SPARSE_ALIGN_second_id)) {
3920 goto erret;
3921 }
3922 }
3923 av.intvalue = ptr -> numseg;
3924 retval = AsnWrite(aip, SPARSE_ALIGN_numseg, &av);
3925 retval = AsnGenericBaseSeqOfAsnWrite(ptr -> first_starts ,ASNCODE_INTVAL_SLOT, aip, SPARSE_ALIGN_first_starts, SPARSE_ALIGN_first_starts_E);
3926 retval = AsnGenericBaseSeqOfAsnWrite(ptr -> second_starts ,ASNCODE_INTVAL_SLOT, aip, SPARSE_ALIGN_second_starts, SPARSE_ALIGN_second_starts_E);
3927 retval = AsnGenericBaseSeqOfAsnWrite(ptr -> lens ,ASNCODE_INTVAL_SLOT, aip, SPARSE_ALIGN_lens, SPARSE_ALIGN_lens_E);
3928 retval = AsnGenericBaseSeqOfAsnWrite(ptr -> second_strands ,ASNCODE_INTVAL_SLOT, aip, SPARSE_ALIGN_second_strands, SPARSE_ALIGN_second_strands_E);
3929 if (ptr->seg_scores != NULL)
3930 {
3931 if (! InternalScoreSetAsnWrite(ptr->seg_scores, aip, SPARSE_ALIGN_seg_scores, SPARSE_ALIGN_seg_scores_E))
3932 goto erret;
3933 }
3934 if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
3935 goto erret;
3936 }
3937 retval = TRUE;
3938
3939 erret:
3940 AsnUnlinkType(orig); /* unlink local tree */
3941 return retval;
3942 }
3943
3944
3945
3946 /**************************************************
3947 *
3948 * SparseSegExtNew()
3949 *
3950 **************************************************/
3951 NLM_EXTERN
3952 SparseSegExtPtr LIBCALL
3953 SparseSegExtNew(void)
3954 {
3955 SparseSegExtPtr ptr = MemNew((size_t) sizeof(SparseSegExt));
3956
3957 return ptr;
3958
3959 }
3960
3961
3962 /**************************************************
3963 *
3964 * SparseSegExtFree()
3965 *
3966 **************************************************/
3967 NLM_EXTERN
3968 SparseSegExtPtr LIBCALL
3969 SparseSegExtFree(SparseSegExtPtr ptr)
3970 {
3971
3972 if(ptr == NULL) {
3973 return NULL;
3974 }
3975 return MemFree(ptr);
3976 }
3977
3978
3979 /**************************************************
3980 *
3981 * SparseSegExtAsnRead()
3982 *
3983 **************************************************/
3984 NLM_EXTERN
3985 SparseSegExtPtr LIBCALL
3986 SparseSegExtAsnRead(AsnIoPtr aip, AsnTypePtr orig)
3987 {
3988 DataVal av;
3989 AsnTypePtr atp;
3990 AsnReadFunc func;
3991 SparseSegExtPtr ptr;
3992
3993 if (! loaded)
3994 {
3995 if (! SeqAlignAsnLoad()) {
3996 return NULL;
3997 }
3998 }
3999
4000 if (aip == NULL) {
4001 return NULL;
4002 }
4003
4004 if (orig == NULL) { /* SparseSegExt ::= (self contained) */
4005 atp = AsnReadId(aip, amp, SPARSE_SEG_EXT);
4006 } else {
4007 atp = AsnLinkType(orig, SPARSE_SEG_EXT);
4008 }
4009 /* link in local tree */
4010 if (atp == NULL) {
4011 return NULL;
4012 }
4013
4014 ptr = SparseSegExtNew();
4015 if (ptr == NULL) {
4016 goto erret;
4017 }
4018 if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
4019 goto erret;
4020 }
4021
4022 atp = AsnReadId(aip,amp, atp);
4023 func = NULL;
4024
4025 if (atp == SPARSE_SEG_EXT_index) {
4026 if ( AsnReadVal(aip, atp, &av) <= 0) {
4027 goto erret;
4028 }
4029 ptr -> index = av.intvalue;
4030 atp = AsnReadId(aip,amp, atp);
4031 }
4032
4033 if (AsnReadVal(aip, atp, &av) <= 0) {
4034 goto erret;
4035 }
4036 /* end struct */
4037
4038 ret:
4039 AsnUnlinkType(orig); /* unlink local tree */
4040 return ptr;
4041
4042 erret:
4043 aip -> io_failure = TRUE;
4044 ptr = SparseSegExtFree(ptr);
4045 goto ret;
4046 }
4047
4048
4049
4050 /**************************************************
4051 *
4052 * SparseSegExtAsnWrite()
4053 *
4054 **************************************************/
4055 NLM_EXTERN Boolean LIBCALL
4056 SparseSegExtAsnWrite(SparseSegExtPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
4057 {
4058 DataVal av;
4059 AsnTypePtr atp;
4060 Boolean retval = FALSE;
4061
4062 if (! loaded)
4063 {
4064 if (! SeqAlignAsnLoad()) {
4065 return FALSE;
4066 }
4067 }
4068
4069 if (aip == NULL) {
4070 return FALSE;
4071 }
4072
4073 atp = AsnLinkType(orig, SPARSE_SEG_EXT); /* link local tree */
4074 if (atp == NULL) {
4075 return FALSE;
4076 }
4077
4078 if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
4079 if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
4080 goto erret;
4081 }
4082
4083 av.intvalue = ptr -> index;
4084 retval = AsnWrite(aip, SPARSE_SEG_EXT_index, &av);
4085 if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
4086 goto erret;
4087 }
4088 retval = TRUE;
4089
4090 erret:
4091 AsnUnlinkType(orig); /* unlink local tree */
4092 return retval;
4093 }
4094
4095 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |