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