Debian Codegraph @

ajax/ensembl/ensgvallele.c

raw symbols SCIP
1 /* @source ensgvallele ********************************************************
2 **
3 ** Ensembl Genetic Variation Allele functions
4 **
5 ** @author Copyright (C) 1999 Ensembl Developers
6 ** @author Copyright (C) 2006 Michael K. Schuster
7 ** @version $Revision: 1.23 $
8 ** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core
9 ** @modified $Date: 2013/02/17 13:02:10 $ by $Author: mks $
10 ** @@
11 **
12 ** This library is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU Lesser General Public
14 ** License as published by the Free Software Foundation; either
15 ** version 2.1 of the License, or (at your option) any later version.
16 **
17 ** This library is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** Lesser General Public License for more details.
21 **
22 ** You should have received a copy of the GNU Lesser General Public
23 ** License along with this library; if not, write to the Free Software
24 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 ** MA 02110-1301, USA.
26 **
27 ******************************************************************************/
28
29 /* ========================================================================= */
30 /* ============================= include files ============================= */
31 /* ========================================================================= */
32
33 #include "ensgvallele.h"
34 #include "ensgvbaseadaptor.h"
35 #include "ensgvdatabaseadaptor.h"
36 #include "ensgvpopulation.h"
37 #include "ensgvvariation.h"
38
39
40
41
42 /* ========================================================================= */
43 /* =============================== constants =============================== */
44 /* ========================================================================= */
45
46
47
48
49 /* ========================================================================= */
50 /* =========================== global variables ============================ */
51 /* ========================================================================= */
52
53
54
55
56 /* ========================================================================= */
57 /* ============================= private data ============================== */
58 /* ========================================================================= */
59
60
61
62
63 /* ========================================================================= */
64 /* =========================== private constants =========================== */
65 /* ========================================================================= */
66
67 /* @conststatic gvalleleadaptorKTablenames ************************************
68 **
69 ** Array of Ensembl Genetic Variation Allele Adaptor SQL table names
70 **
71 ******************************************************************************/
72
73 static const char *gvalleleadaptorKTablenames[] =
74 {
75 "allele",
76 "allele_code",
77 (const char *) NULL
78 };
79
80
81
82
83 /* @conststatic gvalleleadaptorKColumnnames ***********************************
84 **
85 ** Array of Ensembl Genetic Variation Allele Adaptor SQL column names
86 **
87 ******************************************************************************/
88
89 static const char *gvalleleadaptorKColumnnames[] =
90 {
91 "allele.allele_id",
92 "allele.variation_id",
93 "allele.subsnp_id",
94 "allele_code.allele",
95 "allele.frequency",
96 "allele.sample_id",
97 "allele.count",
98 (const char *) NULL
99 };
100
101
102
103
104 /* @conststatic gvalleleadaptorKLeftjoins *************************************
105 **
106 ** Array of Ensembl Genetic Variation Allele Adaptor SQL LEFT JOIN conditions
107 **
108 ******************************************************************************/
109
110 static const EnsOBaseadaptorLeftjoin gvalleleadaptorKLeftjoins[] =
111 {
112 {"failed_allele", "allele.allele_id = failed_allele.allele_id"},
113 {(const char *) NULL, (const char *) NULL}
114 };
115
116
117
118
119 /* @conststatic gvalleleadaptorKDefaultcondition ******************************
120 **
121 ** Ensembl Genetic Variation Allele Adaptor SQL SELECT default condition
122 **
123 ******************************************************************************/
124
125 static const char *gvalleleadaptorKDefaultcondition =
126 "allele.allele_code_id = allele_code.allele_code_id";
127
128
129
130
131 /* @conststatic gvalleleadaptorfailedvariationKTablenames *********************
132 **
133 ** Array of Ensembl Genetic Variation Allele Adaptor SQL table names
134 **
135 ******************************************************************************/
136
137 static const char *gvalleleadaptorfailedvariationKTablenames[] =
138 {
139 "allele",
140 "allele_code",
141 "failed_allele",
142 (const char *) NULL
143 };
144
145
146
147
148 /* ========================================================================= */
149 /* =========================== private variables =========================== */
150 /* ========================================================================= */
151
152
153
154
155 /* ========================================================================= */
156 /* =========================== private functions =========================== */
157 /* ========================================================================= */
158
159 static AjBool gvalleleadaptorFetchAllbyStatement(
160 EnsPBaseadaptor ba,
161 const AjPStr statement,
162 EnsPAssemblymapper am,
163 EnsPSlice slice,
164 AjPList gvas);
165
166
167
168
169 /* ========================================================================= */
170 /* ======================= All functions by section ======================== */
171 /* ========================================================================= */
172
173
174
175
176 /* @filesection ensgvallele ***************************************************
177 **
178 ** @nam1rule ens Function belongs to the Ensembl library
179 **
180 ******************************************************************************/
181
182
183
184
185 /* @datasection [EnsPGvallele] Ensembl Genetic Variation Allele ***************
186 **
187 ** @nam2rule Gvallele Functions for manipulating
188 ** Ensembl Genetic Variation Allele objects
189 **
190 ** @cc Bio::EnsEMBL::Variation::Allele
191 ** @cc CVS Revision: 1.20
192 ** @cc CVS Tag: branch-ensembl-68
193 **
194 ** @cc Bio::EnsEMBL::Variation::Failable
195 ** @cc CVS Revision: 1.2
196 ** @cc CVS Tag: branch-ensembl-68
197 **
198 ** TODO: Lazy loading of Ensembl Genetic Variation Population objects and
199 ** Ensembl Genetic Variation Variation objects is not implemented yet.
200 ** In the Perl implementation Variation objects have references to Allele
201 ** objects and vice versa so to avoid circular references, the Allele object
202 ** weakens its link to the Variation object.
203 ******************************************************************************/
204
205
206
207
208 /* @section constructors ******************************************************
209 **
210 ** All constructors return a new Ensembl Genetic Variation Allele by pointer.
211 ** It is the responsibility of the user to first destroy any previous
212 ** Genetic Variation Allele. The target pointer does not need to be
213 ** initialised to NULL, but it is good programming practice to do so anyway.
214 **
215 ** @fdata [EnsPGvallele]
216 **
217 ** @nam3rule New Constructor
218 ** @nam4rule Cpy Constructor with existing object
219 ** @nam4rule Ini Constructor with initial values
220 ** @nam4rule Ref Constructor by incrementing the reference counter
221 **
222 ** @argrule Cpy gva [const EnsPGvallele] Ensembl Genetic Variation Allele
223 ** @argrule Ini gvaa [EnsPGvalleleadaptor] Ensembl Genetic Variation
224 ** @argrule Ini identifier [ajuint] SQL database-internal identifier
225 ** @argrule Ini gvp [EnsPGvpopulation] Ensembl Genetic Variation Population
226 ** @argrule Ini allele [AjPStr] Allele
227 ** @argrule Ini frequency [float] Frequency
228 ** @argrule Ini subidentifier [ajuint] Subidentifier
229 ** @argrule Ini counter [ajuint] Counter
230 ** @argrule Ini gvvid [ajuint] Ensembl Genetic Variation Variation identifier
231 ** @argrule Ref gva [EnsPGvallele] Ensembl Genetic Variation Allele
232 **
233 ** @valrule * [EnsPGvallele] Ensembl Genetic Variation Allele or NULL
234 **
235 ** @fcategory new
236 ******************************************************************************/
237
238
239
240
241 /* @func ensGvalleleNewCpy ****************************************************
242 **
243 ** Object-based constructor function, which returns an independent object.
244 **
245 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
246 **
247 ** @return [EnsPGvallele] Ensembl Genetic Variation Allele or NULL
248 **
249 ** @release 6.4.0
250 ** @@
251 ******************************************************************************/
252
253 EnsPGvallele ensGvalleleNewCpy(const EnsPGvallele gva)
254 {
255 AjIList iter = NULL;
256
257 AjPStr description = NULL;
258
259 EnsPGvallele pthis = NULL;
260
261 if (!gva)
262 return NULL;
263
264 AJNEW0(pthis);
265
266 pthis->Use = 1U;
267
268 pthis->Identifier = gva->Identifier;
269
270 pthis->Adaptor = gva->Adaptor;
271
272 pthis->Gvpopulation = ensGvpopulationNewRef(gva->Gvpopulation);
273
274 if (gva->Allele)
275 pthis->Allele = ajStrNewRef(gva->Allele);
276
277 if (gva->Subhandle)
278 pthis->Subhandle = ajStrNewRef(gva->Subhandle);
279
280 /* NOTE: Copy the AJAX List of AJAX String (failed description) objects. */
281
282 if (gva->Faileddescriptions)
283 {
284 pthis->Faileddescriptions = ajListstrNew();
285
286 iter = ajListIterNew(gva->Faileddescriptions);
287
288 while (!ajListIterDone(iter))
289 {
290 description = ajListstrIterGet(iter);
291
292 if (description)
293 ajListstrPushAppend(pthis->Faileddescriptions,
294 ajStrNewS(description));
295 }
296
297 ajListIterDel(&iter);
298 }
299
300 pthis->Counter = gva->Counter;
301
302 pthis->Gvvariationidentifier = gva->Gvvariationidentifier;
303
304 pthis->Subidentifier = gva->Subidentifier;
305
306 pthis->Frequency = gva->Frequency;
307
308 return pthis;
309 }
310
311
312
313
314 /* @func ensGvalleleNewIni ****************************************************
315 **
316 ** Constructor for an Ensembl Genetic Variation Allele with initial values.
317 **
318 ** @cc Bio::EnsEMBL::Storable::new
319 ** @param [u] gvaa [EnsPGvalleleadaptor] Ensembl Genetic Variation
320 ** Allele Adaptor
321 ** @param [r] identifier [ajuint] SQL database-internal identifier
322 ** @cc Bio::EnsEMBL::Variation::Allele::new
323 ** @param [u] gvp [EnsPGvpopulation] Ensembl Genetic Variation Population
324 ** @param [u] allele [AjPStr] Allele
325 ** @param [r] frequency [float] Frequency
326 ** @param [r] subidentifier [ajuint] Subidentifier
327 ** @param [r] counter [ajuint] Counter
328 ** @param [r] gvvid [ajuint] Ensembl Genetic Variation Variation identifier
329 **
330 ** @return [EnsPGvallele] Ensembl Genetic Variation Allele or NULL
331 **
332 ** @release 6.4.0
333 ** @@
334 ******************************************************************************/
335
336 EnsPGvallele ensGvalleleNewIni(EnsPGvalleleadaptor gvaa,
337 ajuint identifier,
338 EnsPGvpopulation gvp,
339 AjPStr allele,
340 float frequency,
341 ajuint subidentifier,
342 ajuint counter,
343 ajuint gvvid)
344 {
345 EnsPGvallele gva = NULL;
346
347 if (!gvp)
348 return NULL;
349
350 if (!allele)
351 return NULL;
352
353 AJNEW0(gva);
354
355 gva->Use = 1U;
356
357 gva->Identifier = identifier;
358
359 gva->Adaptor = gvaa;
360
361 gva->Gvpopulation = ensGvpopulationNewRef(gvp);
362
363 if (allele)
364 gva->Allele = ajStrNewS(allele);
365
366 gva->Subidentifier = subidentifier;
367
368 gva->Counter = counter;
369
370 gva->Gvvariationidentifier = gvvid;
371
372 gva->Frequency = frequency;
373
374 return gva;
375 }
376
377
378
379
380 /* @func ensGvalleleNewRef ****************************************************
381 **
382 ** Ensembl Object referencing function, which returns a pointer to the
383 ** Ensembl Object passed in and increases its reference count.
384 **
385 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
386 **
387 ** @return [EnsPGvallele] Ensembl Genetic Variation Allele or NULL
388 **
389 ** @release 6.2.0
390 ** @@
391 ******************************************************************************/
392
393 EnsPGvallele ensGvalleleNewRef(EnsPGvallele gva)
394 {
395 if (!gva)
396 return NULL;
397
398 gva->Use++;
399
400 return gva;
401 }
402
403
404
405
406 /* @section destructors *******************************************************
407 **
408 ** Destruction destroys all internal data structures and frees the memory
409 ** allocated for an Ensembl Genetic Variation Allele object.
410 **
411 ** @fdata [EnsPGvallele]
412 **
413 ** @nam3rule Del Destroy (free) an Ensembl Genetic Variation Allele
414 **
415 ** @argrule * Pgva [EnsPGvallele*] Ensembl Genetic Variation Allele address
416 **
417 ** @valrule * [void]
418 **
419 ** @fcategory delete
420 ******************************************************************************/
421
422
423
424
425 /* @func ensGvalleleDel *******************************************************
426 **
427 ** Default destructor for an Ensembl Genetic Variation Allele.
428 **
429 ** @param [d] Pgva [EnsPGvallele*] Ensembl Genetic Variation Allele address
430 **
431 ** @return [void]
432 **
433 ** @release 6.2.0
434 ** @@
435 ******************************************************************************/
436
437 void ensGvalleleDel(EnsPGvallele *Pgva)
438 {
439 EnsPGvallele pthis = NULL;
440
441 if (!Pgva)
442 return;
443
444 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
445 if (ajDebugTest("ensGvalleleDel"))
446 {
447 ajDebug("ensGvalleleDel\n"
448 " *Pgva %p\n",
449 *Pgva);
450
451 ensGvalleleTrace(*Pgva, 1);
452 }
453 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
454
455 if (!(pthis = *Pgva) || --pthis->Use)
456 {
457 *Pgva = NULL;
458
459 return;
460 }
461
462 ensGvpopulationDel(&pthis->Gvpopulation);
463
464 ajStrDel(&pthis->Allele);
465
466 ajStrDel(&pthis->Subhandle);
467
468 ajListstrFreeData(&pthis->Faileddescriptions);
469
470 ajMemFree((void **) Pgva);
471
472 return;
473 }
474
475
476
477
478 /* @section member retrieval **************************************************
479 **
480 ** Functions for returning members of an
481 ** Ensembl Genetic Variation Allele object.
482 **
483 ** @fdata [EnsPGvallele]
484 **
485 ** @nam3rule Get Return Genetic Variation Allele attribute(s)
486 ** @nam4rule Adaptor Return the Ensembl Genetic Variation Allele Adaptor
487 ** @nam4rule Allele Return the allele
488 ** @nam4rule Counter Return the counter
489 ** @nam4rule Frequency Return the frequency
490 ** @nam4rule Gvpopulation Return the Ensembl Genetic Variation Population
491 ** @nam4rule Gvvariationidentifier
492 ** Return the Ensembl Genetic Variation Variation identifier
493 ** @nam4rule Identifier Return the SQL database-internal identifier
494 ** @nam4rule Subidentifier Return the subidentifier
495 **
496 ** @argrule * gva [const EnsPGvallele] Genetic Variation Allele
497 **
498 ** @valrule Adaptor [EnsPGvalleleadaptor] Ensembl Genetic Variation
499 ** Allele Adaptor or NULL
500 ** @valrule Allele [AjPStr] Allele or NULL
501 ** @valrule Counter [ajuint] Counter or 0U
502 ** @valrule Frequency [float] Frequency or 0.0F
503 ** @valrule Gvpopulation [EnsPGvpopulation]
504 ** Ensembl Genetic Variation Population or NULL
505 ** @valrule Gvvariationidentifier [ajuint]
506 ** Ensembl Genetic Variation Variation identifier or 0U
507 ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U
508 ** @valrule Subidentifier [ajuint] Subidentifier or 0U
509 **
510 ** @fcategory use
511 ******************************************************************************/
512
513
514
515
516 /* @func ensGvalleleGetAdaptor ************************************************
517 **
518 ** Get the Ensembl Genetic Variation Allele Adaptor member of an
519 ** Ensembl Genetic Variation Allele.
520 **
521 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
522 **
523 ** @return [EnsPGvalleleadaptor] Ensembl Genetic Variation Allele Adaptor
524 ** or NULL
525 **
526 ** @release 6.2.0
527 ** @@
528 ******************************************************************************/
529
530 EnsPGvalleleadaptor ensGvalleleGetAdaptor(const EnsPGvallele gva)
531 {
532 return (gva) ? gva->Adaptor : NULL;
533 }
534
535
536
537
538 /* @func ensGvalleleGetAllele *************************************************
539 **
540 ** Get the allele member of an Ensembl Genetic Variation Allele.
541 **
542 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
543 **
544 ** @return [AjPStr] Allele or NULL
545 **
546 ** @release 6.2.0
547 ** @@
548 ******************************************************************************/
549
550 AjPStr ensGvalleleGetAllele(const EnsPGvallele gva)
551 {
552 return (gva) ? gva->Allele : NULL;
553 }
554
555
556
557
558 /* @func ensGvalleleGetCounter ************************************************
559 **
560 ** Get the counter member of an Ensembl Genetic Variation Allele.
561 **
562 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
563 **
564 ** @return [ajuint] Counter or 0U
565 **
566 ** @release 6.4.0
567 ** @@
568 ******************************************************************************/
569
570 ajuint ensGvalleleGetCounter(const EnsPGvallele gva)
571 {
572 return (gva) ? gva->Counter : 0U;
573 }
574
575
576
577
578 /* @func ensGvalleleGetFrequency **********************************************
579 **
580 ** Get the frequency member of an Ensembl Genetic Variation Allele.
581 **
582 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
583 **
584 ** @return [float] Frequency or 0.0F
585 **
586 ** @release 6.2.0
587 ** @@
588 ******************************************************************************/
589
590 float ensGvalleleGetFrequency(const EnsPGvallele gva)
591 {
592 return (gva) ? gva->Frequency : 0.0F;
593 }
594
595
596
597
598 /* @func ensGvalleleGetGvpopulation *******************************************
599 **
600 ** Get the Ensembl Genetic Variation Population member of an
601 ** Ensembl Genetic Variation Allele.
602 **
603 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
604 **
605 ** @return [EnsPGvpopulation] Ensembl Genetic Variation Population or NULL
606 **
607 ** @release 6.4.0
608 ** @@
609 ******************************************************************************/
610
611 EnsPGvpopulation ensGvalleleGetGvpopulation(const EnsPGvallele gva)
612 {
613 return (gva) ? gva->Gvpopulation : NULL;
614 }
615
616
617
618
619 /* @func ensGvalleleGetGvvariationidentifier **********************************
620 **
621 ** Get the Ensembl Genetic Variation Variation identifier member of an
622 ** Ensembl Genetic Variation Allele.
623 **
624 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
625 **
626 ** @return [ajuint] Ensembl Genetic Variation Variation identifier or 0U
627 **
628 ** @release 6.4.0
629 ** @@
630 ******************************************************************************/
631
632 ajuint ensGvalleleGetGvvariationidentifier(const EnsPGvallele gva)
633 {
634 return (gva) ? gva->Gvvariationidentifier : 0U;
635 }
636
637
638
639
640 /* @func ensGvalleleGetIdentifier *********************************************
641 **
642 ** Get the SQL database-internal identifier member of an
643 ** Ensembl Genetic Variation Allele.
644 **
645 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
646 **
647 ** @return [ajuint] SQL database-internal identifier or 0U
648 **
649 ** @release 6.2.0
650 ** @@
651 ******************************************************************************/
652
653 ajuint ensGvalleleGetIdentifier(const EnsPGvallele gva)
654 {
655 return (gva) ? gva->Identifier : 0U;
656 }
657
658
659
660
661 /* @func ensGvalleleGetSubidentifier ******************************************
662 **
663 ** Get the subidentifier member of an Ensembl Genetic Variation Allele.
664 **
665 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
666 **
667 ** @return [ajuint] Subidentifier or 0U
668 **
669 ** @release 6.4.0
670 ** @@
671 ******************************************************************************/
672
673 ajuint ensGvalleleGetSubidentifier(const EnsPGvallele gva)
674 {
675 return (gva) ? gva->Subidentifier : 0U;
676 }
677
678
679
680
681 /* @section load on demand ****************************************************
682 **
683 ** Functions for returning members of an Ensembl Genetic Variation Allele
684 ** object, which may need loading from an Ensembl SQL database on demand.
685 **
686 ** @fdata [EnsPGvallele]
687 **
688 ** @nam3rule Load Return Ensembl Genetic Variation Allele attribute(s)
689 ** loaded on demand
690 ** @nam4rule All Return all Ensembl Genetic Variation Allele attribute(s)
691 ** loaded on demand
692 ** @nam5rule Faileddescriptions Load all failed descriptions
693 ** @nam4rule Subhandle Return the subhandle
694 **
695 ** @argrule * gva [EnsPGvallele] Ensembl Genetic Variation Allele
696 **
697 ** @valrule Faileddescriptions [const AjPList]
698 ** AJAX List of AJAX String (failed description) objects or NULL
699 ** @valrule Subhandle [AjPStr] Subhandle or NULL
700 **
701 ** @fcategory use
702 ******************************************************************************/
703
704
705
706
707 /* @func ensGvalleleLoadAllFaileddescriptions *********************************
708 **
709 ** Load all failed descriptions of an Ensembl Genetic Variation Allele.
710 **
711 ** This is not a simple accessor function, it will fetch the Ensembl Genetic
712 ** Variation Allele failed descriptions from the Ensembl Genetic Variation
713 ** database in case the AJAX List is not defined.
714 **
715 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
716 **
717 ** @return [const AjPList]
718 ** AJAX List of AJAX String (failed description) objects or NULL
719 **
720 ** @release 6.4.0
721 ** @@
722 ******************************************************************************/
723
724 const AjPList ensGvalleleLoadAllFaileddescriptions(EnsPGvallele gva)
725 {
726 if (!gva)
727 return NULL;
728
729 if (gva->Faileddescriptions)
730 return gva->Faileddescriptions;
731
732 if (!gva->Adaptor)
733 {
734 ajDebug("ensGvalleleLoadAllFaileddescriptions cannot retrieve "
735 "AJAX String (failed description) objects for an "
736 "Ensembl Genetic Variation Allele whithout an "
737 "Ensembl Genetic Variation Allele Adaptor.\n");
738
739 return NULL;
740 }
741
742 gva->Faileddescriptions = ajListstrNew();
743
744 ensGvalleleadaptorRetrieveAllFaileddescriptions(
745 gva->Adaptor,
746 gva,
747 gva->Faileddescriptions);
748
749 return gva->Faileddescriptions;
750 }
751
752
753
754
755 /* @func ensGvalleleLoadSubhandle *********************************************
756 **
757 ** Get the subhandle member of an Ensembl Genetic Variation Allele.
758 **
759 ** This is not a simple accessor function, it will fetch the Ensembl Genetic
760 ** Variation Allele subhandle from the Ensembl Genetic Variation database
761 ** in case the AJAX String is not defined.
762 **
763 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
764 **
765 ** @return [AjPStr] Subhandle or NULL
766 **
767 ** @release 6.4.0
768 ** @@
769 ******************************************************************************/
770
771 AjPStr ensGvalleleLoadSubhandle(EnsPGvallele gva)
772 {
773 if (!gva)
774 return NULL;
775
776 if (gva->Subhandle)
777 return gva->Subhandle;
778
779 if (!gva->Adaptor)
780 {
781 ajDebug("ensGvalleleLoadSubhandle cannot fetch a subhandle "
782 "from the database for an Ensembl Genetic Variation Allele "
783 "whithout an Ensembl Genetic Variation Allele Adaptor.\n");
784
785 return gva->Subhandle;
786 }
787
788 gva->Subhandle = ajStrNew();
789
790 ensGvalleleadaptorRetrieveSubhandle(
791 gva->Adaptor,
792 gva,
793 &gva->Subhandle);
794
795 return gva->Subhandle;
796 }
797
798
799
800
801 /* @section member assignment *************************************************
802 **
803 ** Functions for assigning members of an
804 ** Ensembl Genetic Variation Allele object.
805 **
806 ** @fdata [EnsPGvallele]
807 **
808 ** @nam3rule Set Set one member of a Genetic Variation Allele
809 ** @nam4rule Adaptor Set the Ensembl Genetic Variation Allele Adaptor
810 ** @nam4rule Allele Set the allele
811 ** @nam4rule Counter Set the counter
812 ** @nam4rule Frequency Set the frequency
813 ** @nam4rule Gvpopulation Set the Ensembl Genetic Variation Population
814 ** @nam4rule Gvvariationidentifier
815 ** Set the Ensembl Genetic Variation Variation identifier
816 ** @nam4rule Identifier Set the SQL database-internal identifier
817 ** @nam4rule Subhandle Set the subhandle
818 ** @nam4rule Subidentifier Set the subidentifier
819 **
820 ** @argrule * gva [EnsPGvallele] Ensembl Genetic Variation Allele object
821 **
822 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
823 ** @argrule Adaptor gvaa [EnsPGvalleleadaptor] Ensembl Genetic Variation
824 ** @argrule Allele allele [AjPStr] Allele
825 ** @argrule Counter counter [ajuint] Counter
826 ** @argrule Frequency frequency [float] Frequency
827 ** @argrule Gvpopulation gvp [EnsPGvpopulation]
828 ** Ensembl Genetic Variation Population
829 ** @argrule Gvvariationidentifier gvvid [ajuint]
830 ** Ensembl Genetic Variation Variation identifier
831 ** @argrule Identifier identifier [ajuint] SQL database-internal identifier
832 ** @argrule Subhandle subhandle [AjPStr] Subhandle
833 ** @argrule Subidentifier subidentifier [ajuint] Subidentifier
834 **
835 ** @fcategory modify
836 ******************************************************************************/
837
838
839
840
841 /* @func ensGvalleleSetAdaptor ************************************************
842 **
843 ** Set the Ensembl Genetic Variation Allele Adaptor member of an
844 ** Ensembl Genetic Variation Allele.
845 **
846 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
847 ** @param [u] gvaa [EnsPGvalleleadaptor] Ensembl Genetic Variation
848 ** Allele Adaptor
849 **
850 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
851 **
852 ** @release 6.2.0
853 ** @@
854 ******************************************************************************/
855
856 AjBool ensGvalleleSetAdaptor(EnsPGvallele gva, EnsPGvalleleadaptor gvaa)
857 {
858 if (!gva)
859 return ajFalse;
860
861 gva->Adaptor = gvaa;
862
863 return ajTrue;
864 }
865
866
867
868
869 /* @func ensGvalleleSetAllele *************************************************
870 **
871 ** Set the allele member of an Ensembl Genetic Variation Allele.
872 **
873 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
874 ** @param [u] allele [AjPStr] Allele
875 **
876 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
877 **
878 ** @release 6.2.0
879 ** @@
880 ******************************************************************************/
881
882 AjBool ensGvalleleSetAllele(EnsPGvallele gva, AjPStr allele)
883 {
884 if (!gva)
885 return ajFalse;
886
887 ajStrDel(&gva->Allele);
888
889 if (allele)
890 gva->Allele = ajStrNewRef(allele);
891
892 return ajTrue;
893 }
894
895
896
897
898 /* @func ensGvalleleSetCounter ************************************************
899 **
900 ** Set the counter member of an Ensembl Genetic Variation Allele.
901 **
902 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
903 ** @param [r] counter [ajuint] Counter
904 **
905 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
906 **
907 ** @release 6.4.0
908 ** @@
909 ******************************************************************************/
910
911 AjBool ensGvalleleSetCounter(EnsPGvallele gva, ajuint counter)
912 {
913 if (!gva)
914 return ajFalse;
915
916 gva->Counter = counter;
917
918 return ajTrue;
919 }
920
921
922
923
924 /* @func ensGvalleleSetFrequency **********************************************
925 **
926 ** Set the frequency member of an Ensembl Genetic Variation Allele.
927 **
928 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
929 ** @param [r] frequency [float] Frequency
930 **
931 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
932 **
933 ** @release 6.2.0
934 ** @@
935 ******************************************************************************/
936
937 AjBool ensGvalleleSetFrequency(EnsPGvallele gva, float frequency)
938 {
939 if (!gva)
940 return ajFalse;
941
942 gva->Frequency = frequency;
943
944 return ajTrue;
945 }
946
947
948
949
950 /* @func ensGvalleleSetGvpopulation *******************************************
951 **
952 ** Set the Ensembl Genetic Variation Population member of an
953 ** Ensembl Genetic Variation Allele.
954 **
955 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
956 ** @param [u] gvp [EnsPGvpopulation] Ensembl Genetic Variation Population
957 **
958 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
959 **
960 ** @release 6.4.0
961 ** @@
962 ******************************************************************************/
963
964 AjBool ensGvalleleSetGvpopulation(EnsPGvallele gva, EnsPGvpopulation gvp)
965 {
966 if (!gva)
967 return ajFalse;
968
969 ensGvpopulationDel(&gva->Gvpopulation);
970
971 gva->Gvpopulation = ensGvpopulationNewRef(gvp);
972
973 return ajTrue;
974 }
975
976
977
978
979 /* @func ensGvalleleSetGvvariationidentifier **********************************
980 **
981 ** Set the Ensembl Genetic Variation Variation identifier member of an
982 ** Ensembl Genetic Variation Allele.
983 **
984 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
985 ** @param [r] gvvid [ajuint] Ensembl Genetic Variation Variation identifier
986 **
987 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
988 **
989 ** @release 6.4.0
990 ** @@
991 ******************************************************************************/
992
993 AjBool ensGvalleleSetGvvariationidentifier(EnsPGvallele gva, ajuint gvvid)
994 {
995 if (!gva)
996 return ajFalse;
997
998 gva->Gvvariationidentifier = gvvid;
999
1000 return ajTrue;
1001 }
1002
1003
1004
1005
1006 /* @func ensGvalleleSetIdentifier *********************************************
1007 **
1008 ** Set the SQL database-internal identifier member of an
1009 ** Ensembl Genetic Variation Allele.
1010 **
1011 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
1012 ** @param [r] identifier [ajuint] SQL database-internal identifier
1013 **
1014 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1015 **
1016 ** @release 6.2.0
1017 ** @@
1018 ******************************************************************************/
1019
1020 AjBool ensGvalleleSetIdentifier(EnsPGvallele gva, ajuint identifier)
1021 {
1022 if (!gva)
1023 return ajFalse;
1024
1025 gva->Identifier = identifier;
1026
1027 return ajTrue;
1028 }
1029
1030
1031
1032
1033 /* @func ensGvalleleSetSubhandle **********************************************
1034 **
1035 ** Set the subhandle member of an Ensembl Genetic Variation Allele.
1036 **
1037 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
1038 ** @param [u] subhandle [AjPStr] Subhandle
1039 **
1040 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1041 **
1042 ** @release 6.4.0
1043 ** @@
1044 ******************************************************************************/
1045
1046 AjBool ensGvalleleSetSubhandle(EnsPGvallele gva, AjPStr subhandle)
1047 {
1048 if (!gva)
1049 return ajFalse;
1050
1051 ajStrDel(&gva->Subhandle);
1052
1053 if (subhandle)
1054 gva->Subhandle = ajStrNewRef(subhandle);
1055
1056 return ajTrue;
1057 }
1058
1059
1060
1061
1062 /* @func ensGvalleleSetSubidentifier ******************************************
1063 **
1064 ** Set the subidentifier member of an Ensembl Genetic Variation Allele.
1065 **
1066 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
1067 ** @param [r] subidentifier [ajuint] Subidentifier
1068 **
1069 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1070 **
1071 ** @release 6.4.0
1072 ** @@
1073 ******************************************************************************/
1074
1075 AjBool ensGvalleleSetSubidentifier(EnsPGvallele gva, ajuint subidentifier)
1076 {
1077 if (!gva)
1078 return ajFalse;
1079
1080 gva->Subidentifier = subidentifier;
1081
1082 return ajTrue;
1083 }
1084
1085
1086
1087
1088 /* @section debugging *********************************************************
1089 **
1090 ** Functions for reporting of an Ensembl Genetic Variation Allele object.
1091 **
1092 ** @fdata [EnsPGvallele]
1093 **
1094 ** @nam3rule Trace Report Ensembl Genetic Variation Allele members to
1095 ** debug file
1096 **
1097 ** @argrule Trace gva [const EnsPGvallele] Ensembl Genetic Variation Allele
1098 ** @argrule Trace level [ajuint] Indentation level
1099 **
1100 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1101 **
1102 ** @fcategory misc
1103 ******************************************************************************/
1104
1105
1106
1107
1108 /* @func ensGvalleleTrace *****************************************************
1109 **
1110 ** Trace an Ensembl Genetic Variation Allele.
1111 **
1112 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
1113 ** @param [r] level [ajuint] Indentation level
1114 **
1115 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1116 **
1117 ** @release 6.2.0
1118 ** @@
1119 ******************************************************************************/
1120
1121 AjBool ensGvalleleTrace(const EnsPGvallele gva, ajuint level)
1122 {
1123 AjIList iter = NULL;
1124
1125 AjPStr description = NULL;
1126 AjPStr indent = NULL;
1127
1128 if (!gva)
1129 return ajFalse;
1130
1131 indent = ajStrNew();
1132
1133 ajStrAppendCountK(&indent, ' ', level * 2);
1134
1135 ajDebug("%SensGvalleleTrace %p\n"
1136 "%S Use %u\n"
1137 "%S Identifier %u\n"
1138 "%S Adaptor %p\n"
1139 "%S Population %p\n"
1140 "%S Allele '%S'\n"
1141 "%S Subhandle '%S'\n"
1142 "%S Faileddescriptions %p\n"
1143 "%S Counter %u\n"
1144 "%S Gvvariationidentifier %u\n"
1145 "%S Subidentifier %u\n"
1146 "%S Frequency %f\n",
1147 indent, gva,
1148 indent, gva->Use,
1149 indent, gva->Identifier,
1150 indent, gva->Adaptor,
1151 indent, gva->Gvpopulation,
1152 indent, gva->Allele,
1153 indent, gva->Subhandle,
1154 indent, gva->Faileddescriptions,
1155 indent, gva->Counter,
1156 indent, gva->Gvvariationidentifier,
1157 indent, gva->Subidentifier,
1158 indent, gva->Frequency);
1159
1160 ensGvpopulationTrace(gva->Gvpopulation, level + 1);
1161
1162 /* Trace the AJAX List of AJAX String (failed description) objects. */
1163
1164 if (gva->Faileddescriptions)
1165 {
1166 ajDebug("%S AJAX List %p of AJAX String (failed description) "
1167 "objects:\n",
1168 indent, gva->Faileddescriptions);
1169
1170 iter = ajListIterNewread(gva->Faileddescriptions);
1171
1172 while (!ajListIterDone(iter))
1173 {
1174 description = ajListstrIterGet(iter);
1175
1176 ajDebug("%S %S\n", description);
1177 }
1178 }
1179
1180 ajListIterDel(&iter);
1181
1182 ajStrDel(&indent);
1183
1184 return ajTrue;
1185 }
1186
1187
1188
1189
1190 /* @section calculate *********************************************************
1191 **
1192 ** Functions for calculating information from an
1193 ** Ensembl Genetic Variation Allele object.
1194 **
1195 ** @fdata [EnsPGvallele]
1196 **
1197 ** @nam3rule Calculate Calculate Ensembl Genetic Variation Allele information
1198 ** @nam4rule Memsize Calculate the memory size in bytes
1199 **
1200 ** @argrule * gva [const EnsPGvallele] Ensembl Genetic Variation Allele
1201 **
1202 ** @valrule Memsize [size_t] Memory size in bytes or 0
1203 **
1204 ** @fcategory misc
1205 ******************************************************************************/
1206
1207
1208
1209
1210 /* @func ensGvalleleCalculateMemsize ******************************************
1211 **
1212 ** Get the memory size in bytes of an Ensembl Genetic Variation Allele.
1213 **
1214 ** @param [r] gva [const EnsPGvallele] Ensembl Genetic Variation Allele
1215 **
1216 ** @return [size_t] Memory size in bytes or 0
1217 **
1218 ** @release 6.4.0
1219 ** @@
1220 ******************************************************************************/
1221
1222 size_t ensGvalleleCalculateMemsize(const EnsPGvallele gva)
1223 {
1224 size_t size = 0;
1225
1226 if (!gva)
1227 return 0;
1228
1229 size += sizeof (EnsOGvallele);
1230
1231 size += ensGvpopulationCalculateMemsize(gva->Gvpopulation);
1232
1233 if (gva->Allele)
1234 {
1235 size += sizeof (AjOStr);
1236
1237 size += ajStrGetRes(gva->Allele);
1238 }
1239
1240 if (gva->Subhandle)
1241 {
1242 size += sizeof (AjOStr);
1243
1244 size += ajStrGetRes(gva->Subhandle);
1245 }
1246
1247 return size;
1248 }
1249
1250
1251
1252
1253 /* @section query *************************************************************
1254 **
1255 ** Functions for querying the properties of an
1256 ** Ensembl Genetic Variation Allele.
1257 **
1258 ** @fdata [EnsPGvallele]
1259 **
1260 ** @nam3rule Is Check whether an Ensembl Genetic Variation Allele represents a
1261 ** certain property
1262 ** @nam4rule Failed Check for failed
1263 **
1264 ** @argrule Failed gva [EnsPGvallele] Ensembl Genetic Variation Allele
1265 ** @argrule Failed Presult [AjBool*] Boolean result
1266 **
1267 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1268 **
1269 ** @fcategory use
1270 ******************************************************************************/
1271
1272
1273
1274
1275 /* @func ensGvalleleIsFailed **************************************************
1276 **
1277 ** Check if an Ensembl Genetic Variation Allele has been failed.
1278 ** This function calls ensGvalleleLoadAllFaileddescriptions to find out if
1279 ** failed descriptiosn are available.
1280 **
1281 ** @param [u] gva [EnsPGvallele] Ensembl Genetic Variation Allele
1282 ** @param [u] Presult [AjBool*] ajTrue, if an Ensembl Genetic Variation Allele
1283 ** has been failed
1284 **
1285 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1286 **
1287 ** @release 6.4.0
1288 ** @@
1289 ******************************************************************************/
1290
1291 AjBool ensGvalleleIsFailed(EnsPGvallele gva, AjBool *Presult)
1292 {
1293 const AjPList descriptions = NULL;
1294
1295 if (!gva)
1296 return ajFalse;
1297
1298 if (!Presult)
1299 return ajFalse;
1300
1301 descriptions = ensGvalleleLoadAllFaileddescriptions(gva);
1302
1303 if (ajListGetLength(descriptions) > 0)
1304 *Presult = ajTrue;
1305 else
1306 *Presult = ajFalse;
1307
1308 return ajTrue;
1309 }
1310
1311
1312
1313
1314 /* @datasection [EnsPGvalleleadaptor] Ensembl Genetic Variation Allele Adaptor
1315 **
1316 ** @nam2rule Gvalleleadaptor Functions for manipulating
1317 ** Ensembl Genetic Variation Allele Adaptor objects
1318 **
1319 ** @cc Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor
1320 ** @cc CVS Revision: 1.12
1321 ** @cc CVS Tag: branch-ensembl-68
1322 **
1323 ******************************************************************************/
1324
1325
1326
1327
1328 /* @funcstatic gvalleleadaptorFetchAllbyStatement *****************************
1329 **
1330 ** Fetch all Ensembl Genetic Variation Allele objects via an SQL statement.
1331 **
1332 ** @param [u] ba [EnsPBaseadaptor] Ensembl Base Adaptor
1333 ** @param [r] statement [const AjPStr] SQL statement
1334 ** @param [uN] am [EnsPAssemblymapper] Ensembl Assembly Mapper
1335 ** @param [uN] slice [EnsPSlice] Ensembl Slice
1336 ** @param [u] gvas [AjPList]
1337 ** AJAX List of Ensembl Genetic Variation Allele objects
1338 **
1339 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1340 **
1341 ** @release 6.4.0
1342 ** @@
1343 ******************************************************************************/
1344
1345 static AjBool gvalleleadaptorFetchAllbyStatement(
1346 EnsPBaseadaptor ba,
1347 const AjPStr statement,
1348 EnsPAssemblymapper am,
1349 EnsPSlice slice,
1350 AjPList gvas)
1351 {
1352 float frequency = 0.0F;
1353
1354 ajuint counter = 0U;
1355 ajuint identifier = 0U;
1356 ajuint gvpid = 0U;
1357 ajuint gvvid = 0U;
1358 ajuint lastid = 0U;
1359 ajuint subid = 0U;
1360
1361 AjPSqlstatement sqls = NULL;
1362 AjISqlrow sqli = NULL;
1363 AjPSqlrow sqlr = NULL;
1364
1365 AjPStr allele = NULL;
1366
1367 EnsPDatabaseadaptor dba = NULL;
1368
1369 EnsPGvallele gva = NULL;
1370 EnsPGvalleleadaptor gvaa = NULL;
1371
1372 EnsPGvpopulation gvp = NULL;
1373 EnsPGvpopulationadaptor gvpa = NULL;
1374
1375 if (ajDebugTest("gvalleleadaptorFetchAllbyStatement"))
1376 ajDebug("gvalleleadaptorFetchAllbyStatement\n"
1377 " ba %p\n"
1378 " statement %p\n"
1379 " am %p\n"
1380 " slice %p\n"
1381 " gvas %p\n",
1382 ba,
1383 statement,
1384 am,
1385 slice,
1386 gvas);
1387
1388 if (!ba)
1389 return ajFalse;
1390
1391 if (!statement)
1392 return ajFalse;
1393
1394 if (!gvas)
1395 return ajFalse;
1396
1397 dba = ensBaseadaptorGetDatabaseadaptor(ba);
1398
1399 gvaa = ensRegistryGetGvalleleadaptor(dba);
1400 gvpa = ensRegistryGetGvpopulationadaptor(dba);
1401
1402 sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
1403
1404 sqli = ajSqlrowiterNew(sqls);
1405
1406 while (!ajSqlrowiterDone(sqli))
1407 {
1408 identifier = 0U;
1409 gvvid = 0U;
1410 subid = 0U;
1411 allele = ajStrNew();
1412 frequency = 0.0F;
1413 gvpid = 0U;
1414 counter = 0U;
1415
1416 sqlr = ajSqlrowiterGet(sqli);
1417
1418 ajSqlcolumnToUint(sqlr, &identifier);
1419 ajSqlcolumnToUint(sqlr, &gvvid);
1420 ajSqlcolumnToUint(sqlr, &subid);
1421 ajSqlcolumnToStr(sqlr, &allele);
1422 ajSqlcolumnToFloat(sqlr, &frequency);
1423 ajSqlcolumnToUint(sqlr, &gvpid);
1424 ajSqlcolumnToUint(sqlr, &counter);
1425
1426 if (identifier != lastid)
1427 {
1428 ensGvpopulationadaptorFetchByIdentifier(gvpa, gvpid, &gvp);
1429
1430 gva = ensGvalleleNewIni(gvaa,
1431 identifier,
1432 gvp,
1433 allele,
1434 frequency,
1435 subid,
1436 counter,
1437 gvvid);
1438
1439 ajListPushAppend(gvas, (void *) gva);
1440
1441 ensGvpopulationDel(&gvp);
1442 }
1443
1444 ajStrDel(&allele);
1445
1446 lastid = identifier;
1447 }
1448
1449 ajSqlrowiterDel(&sqli);
1450
1451 ensDatabaseadaptorSqlstatementDel(dba, &sqls);
1452
1453 return ajTrue;
1454 }
1455
1456
1457
1458
1459 /* @section constructors ******************************************************
1460 **
1461 ** All constructors return a new Ensembl Genetic Variation Allele Adaptor
1462 ** by pointer.
1463 ** It is the responsibility of the user to first destroy any previous
1464 ** Ensembl Genetic Variation Allele Adaptor. The target pointer does not
1465 ** need to be initialised to NULL, but it is good programming practice to do
1466 ** so anyway.
1467 **
1468 ** @fdata [EnsPGvalleleadaptor]
1469 **
1470 ** @nam3rule New Constructor
1471 **
1472 ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
1473 **
1474 ** @valrule * [EnsPGvalleleadaptor]
1475 ** Ensembl Genetic Variation Allele Adaptor or NULL
1476 **
1477 ** @fcategory new
1478 ******************************************************************************/
1479
1480
1481
1482
1483 /* @func ensGvalleleadaptorNew ************************************************
1484 **
1485 ** Default constructor for an Ensembl Genetic Variation Allele Adaptor.
1486 **
1487 ** Ensembl Object Adaptors are singleton objects in the sense that a single
1488 ** instance of an Ensembl Object Adaptor connected to a particular database is
1489 ** sufficient to instantiate any number of Ensembl Objects from the database.
1490 ** Each Ensembl Object will have a weak reference to the Object Adaptor that
1491 ** instantiated it. Therefore, Ensembl Object Adaptors should not be
1492 ** instantiated directly, but rather obtained from the Ensembl Registry,
1493 ** which will in turn call this function if neccessary.
1494 **
1495 ** @see ensRegistryGetDatabaseadaptor
1496 ** @see ensRegistryGetGvalleleadaptor
1497 **
1498 ** @cc Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor::new
1499 ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
1500 **
1501 ** @return [EnsPGvalleleadaptor]
1502 ** Ensembl Genetic Variation Allele Adaptor or NULL
1503 **
1504 ** @release 6.4.0
1505 ** @@
1506 ******************************************************************************/
1507
1508 EnsPGvalleleadaptor ensGvalleleadaptorNew(
1509 EnsPDatabaseadaptor dba)
1510 {
1511 EnsPGvalleleadaptor gvaa = NULL;
1512
1513 EnsPGvdatabaseadaptor gvdba = NULL;
1514
1515 if (!dba)
1516 return NULL;
1517
1518 gvdba = ensRegistryGetGvdatabaseadaptor(dba);
1519
1520 if (!gvdba)
1521 return NULL;
1522
1523 AJNEW0(gvaa);
1524
1525 gvaa->Excludeadaptor = ensGvbaseadaptorNew(
1526 gvdba,
1527 gvalleleadaptorKTablenames,
1528 gvalleleadaptorKColumnnames,
1529 gvalleleadaptorKLeftjoins,
1530 gvalleleadaptorKDefaultcondition,
1531 (const char *) NULL,
1532 &gvalleleadaptorFetchAllbyStatement);
1533
1534 /*
1535 ** If failed Variation objects are included, add the "failed_variation"
1536 ** SQL table name, but skip the SQL LEFT JOIN.
1537 */
1538
1539 gvaa->Includeadaptor = ensGvbaseadaptorNew(
1540 gvdba,
1541 gvalleleadaptorfailedvariationKTablenames,
1542 gvalleleadaptorKColumnnames,
1543 (const EnsPBaseadaptorLeftjoin) NULL,
1544 gvalleleadaptorKDefaultcondition,
1545 (const char *) NULL,
1546 &gvalleleadaptorFetchAllbyStatement);
1547
1548 return gvaa;
1549 }
1550
1551
1552
1553
1554 /* @section destructors *******************************************************
1555 **
1556 ** Destruction destroys all internal data structures and frees the memory
1557 ** allocated for an Ensembl Genetic Variation Allele Adaptor object.
1558 **
1559 ** @fdata [EnsPGvalleleadaptor]
1560 **
1561 ** @nam3rule Del Destroy (free) an
1562 ** Ensembl Genetic Variation Allele Adaptor
1563 **
1564 ** @argrule * Pgvaa [EnsPGvalleleadaptor*]
1565 ** Ensembl Genetic Variation Allele Adaptor address
1566 **
1567 ** @valrule * [void]
1568 **
1569 ** @fcategory delete
1570 ******************************************************************************/
1571
1572
1573
1574
1575 /* @func ensGvalleleadaptorDel ************************************************
1576 **
1577 ** Default destructor for an Ensembl Genetic Variation Allele Adaptor.
1578 **
1579 ** Ensembl Object Adaptors are singleton objects that are registered in the
1580 ** Ensembl Registry and weakly referenced by Ensembl Objects that have been
1581 ** instantiated by it. Therefore, Ensembl Object Adaptors should never be
1582 ** destroyed directly. Upon exit, the Ensembl Registry will call this function
1583 ** if required.
1584 **
1585 ** @param [d] Pgvaa [EnsPGvalleleadaptor*]
1586 ** Ensembl Genetic Variation Allele Adaptor address
1587 **
1588 ** @return [void]
1589 **
1590 ** @release 6.4.0
1591 ** @@
1592 ******************************************************************************/
1593
1594 void ensGvalleleadaptorDel(EnsPGvalleleadaptor *Pgvaa)
1595 {
1596 EnsPGvalleleadaptor pthis = NULL;
1597
1598 if (!Pgvaa)
1599 return;
1600
1601 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
1602 if (ajDebugTest("ensGvalleleadaptorDel"))
1603 ajDebug("ensGvalleleadaptorDel\n"
1604 " *Pgvaa %p\n",
1605 *Pgvaa);
1606 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
1607
1608 if (!(pthis = *Pgvaa))
1609 return;
1610
1611 ensGvbaseadaptorDel(&pthis->Excludeadaptor);
1612 ensGvbaseadaptorDel(&pthis->Includeadaptor);
1613
1614 ajMemFree((void **) Pgvaa);
1615
1616 return;
1617 }
1618
1619
1620
1621
1622 /* @section member retrieval **************************************************
1623 **
1624 ** Functions for returning members of an
1625 ** Ensembl Genetic Variation Allele Adaptor object.
1626 **
1627 ** @fdata [EnsPGvalleleadaptor]
1628 **
1629 ** @nam3rule Get Return Ensembl Genetic Variation Allele Adaptor attribute(s)
1630 ** @nam4rule Baseadaptor Return the Ensembl Base Adaptor
1631 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
1632 ** @nam4rule Gvdatabaseadaptor
1633 ** Return the Ensembl Genetic Variation Database Adaptor
1634 **
1635 ** @argrule * gvaa [const EnsPGvalleleadaptor]
1636 ** Ensembl Genetic Variation Allele Adaptor
1637 **
1638 ** @valrule Baseadaptor [EnsPBaseadaptor] Ensembl Base Adaptor or NULL
1639 ** @valrule Databaseadaptor [EnsPDatabaseadaptor]
1640 ** Ensembl Database Adaptor or NULL
1641 ** @valrule Gvdatabaseadaptor [EnsPGvdatabaseadaptor]
1642 ** Ensembl Genetic Variation Database Adaptor
1643 **
1644 ** @fcategory use
1645 ******************************************************************************/
1646
1647
1648
1649
1650 /* @func ensGvalleleadaptorGetDatabaseadaptor *********************************
1651 **
1652 ** Get the Ensembl Database Adaptor member of an
1653 ** Ensembl Genetic Variation Allele Adaptor.
1654 **
1655 ** @param [r] gvaa [const EnsPGvalleleadaptor]
1656 ** Ensembl Genetic Variation Allele Adaptor
1657 **
1658 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
1659 **
1660 ** @release 6.4.0
1661 ** @@
1662 ******************************************************************************/
1663
1664 EnsPDatabaseadaptor ensGvalleleadaptorGetDatabaseadaptor(
1665 const EnsPGvalleleadaptor gvaa)
1666 {
1667 if (!gvaa)
1668 return NULL;
1669
1670 /*
1671 ** It does not matter from which Ensembl Genetic Variation Base Adaptor
1672 ** the Ensembl Genetic Variation Database Adaptor is taken, they both
1673 ** link to the same object.
1674 */
1675
1676 return ensGvdatabaseadaptorGetDatabaseadaptor(
1677 ensGvbaseadaptorGetGvdatabaseadaptor(gvaa->Excludeadaptor));
1678 }
1679
1680
1681
1682
1683 /* @func ensGvalleleadaptorGetGvdatabaseadaptor *******************************
1684 **
1685 ** Get the Ensembl Genetic Variation Database Adaptor member of an
1686 ** Ensembl Genetic Variation Allele Adaptor.
1687 **
1688 ** @param [r] gvaa [const EnsPGvalleleadaptor]
1689 ** Ensembl Genetic Variation Allele Adaptor
1690 **
1691 ** @return [EnsPGvdatabaseadaptor]
1692 ** Ensembl Genetic Variation Database Adaptor or NULL
1693 **
1694 ** @release 6.4.0
1695 ** @@
1696 ******************************************************************************/
1697
1698 EnsPGvdatabaseadaptor ensGvalleleadaptorGetGvdatabaseadaptor(
1699 const EnsPGvalleleadaptor gvaa)
1700 {
1701 /*
1702 ** It does not matter from which Ensembl Genetic Variation Base Adaptor
1703 ** the Ensembl Genetic Variation Database Adaptor is taken, they both
1704 ** link to the same object.
1705 */
1706
1707 return (gvaa) ?
1708 ensGvbaseadaptorGetGvdatabaseadaptor(gvaa->Excludeadaptor) : NULL;
1709 }
1710
1711
1712
1713
1714 /* @section object retrieval **************************************************
1715 **
1716 ** Functions for fetching Ensembl Genetic Variation Allele objects from an
1717 ** Ensembl SQL database.
1718 **
1719 ** @fdata [EnsPGvalleleadaptor]
1720 **
1721 ** @nam3rule Fetch Fetch Ensembl Genetic Variation Allele object(s)
1722 ** @nam4rule All Fetch all Ensembl Genetic Variation Allele objects
1723 ** @nam4rule Allby Fetch all Ensembl Genetic Variation Allele objects
1724 ** matching a criterion
1725 ** @nam5rule Gvvariation Fetch all by an Ensembl Genetic Variation Variation
1726 ** @nam5rule Subidentifier
1727 ** @nam4rule By Fetch one Ensembl Genetic Variation Allele object
1728 ** matching a criterion
1729 ** @nam5rule Identifier Fetch by a SQL database-internal identifier
1730 **
1731 ** @argrule * gvaa [EnsPGvalleleadaptor]
1732 ** Ensembl Genetic Variation Allele Adaptor
1733 ** @argrule Gvvariation gvv [const EnsPGvvariation]
1734 ** Ensembl Genetic Variation Variation
1735 ** @argrule Gvvariation gvp [const EnsPGvpopulation]
1736 ** Ensembl Genetic Variation Population
1737 ** @argrule Subidentifier subidentifier [ajuint] Subidentifier
1738 ** @argrule All gvas [AjPList] AJAX List of
1739 ** Ensembl Genetic Variation Allele objects
1740 ** @argrule Allby gvas [AjPList] AJAX List of
1741 ** Ensembl Genetic Variation Allele objects
1742 ** @argrule ByIdentifier identifier [ajuint] SQL database-internal identifier
1743 ** @argrule By Pgva [EnsPGvallele*]
1744 ** Ensembl Genetic Variation Allele object address
1745 **
1746 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1747 **
1748 ** @fcategory use
1749 ******************************************************************************/
1750
1751
1752
1753
1754 /* @func ensGvalleleadaptorFetchAllbyGvvariation ******************************
1755 **
1756 ** Fetch all Ensembl Genetic Variation Allele objects by an
1757 ** Ensembl Genetic Variation Variation.
1758 **
1759 ** @cc Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor::fetch_all_by_Variation
1760 ** @param [u] gvaa [EnsPGvalleleadaptor]
1761 ** Ensembl Genetic Variation Allele Adaptor
1762 ** @param [r] gvv [const EnsPGvvariation]
1763 ** Ensembl Genetic Variation Variation
1764 ** @param [rN] gvp [const EnsPGvpopulation]
1765 ** Ensembl Genetic Variation Population
1766 ** @param [u] gvas [AjPList] AJAX List of
1767 ** Ensembl Genetic Variation Allele objects
1768 **
1769 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1770 **
1771 ** @release 6.4.0
1772 ** @@
1773 ******************************************************************************/
1774
1775 AjBool ensGvalleleadaptorFetchAllbyGvvariation(
1776 EnsPGvalleleadaptor gvaa,
1777 const EnsPGvvariation gvv,
1778 const EnsPGvpopulation gvp,
1779 AjPList gvas)
1780 {
1781 AjBool result = AJFALSE;
1782
1783 AjPStr constraint = NULL;
1784 AjPStr fvsconstraint = NULL;
1785
1786 EnsPBaseadaptor ba = NULL;
1787
1788 EnsPGvdatabaseadaptor gvdba = NULL;
1789
1790 if (!gvaa)
1791 return ajFalse;
1792
1793 if (!gvv)
1794 return ajFalse;
1795
1796 if (!gvas)
1797 return ajFalse;
1798
1799 /*
1800 ** It does not matter from which Ensembl Genetic Variation Base Adaptor
1801 ** the Ensembl Genetic Variation Database Adaptor is taken, they both
1802 ** link to the same object. It does, however, matter, which
1803 ** Ensembl Genetic Variation Base Adaptor gets used.
1804 */
1805
1806 gvdba = ensGvbaseadaptorGetGvdatabaseadaptor(gvaa->Excludeadaptor);
1807
1808 if (ensGvdatabaseadaptorGetFailedvariations(gvdba))
1809 ba = ensGvbaseadaptorGetBaseadaptor(gvaa->Includeadaptor);
1810 else
1811 ba = ensGvbaseadaptorGetBaseadaptor(gvaa->Excludeadaptor);
1812
1813 constraint = ajFmtStr("allele.variation_id = %u",
1814 ensGvvariationGetIdentifier(gvv));
1815
1816 if (gvp)
1817 ajFmtPrintAppS(&constraint, " AND allele.sample_id = %u",
1818 ensGvpopulationGetIdentifier(gvp));
1819
1820 ensGvdatabaseadaptorFailedvariationsconstraint(
1821 gvdba,
1822 (const AjPStr) NULL,
1823 &fvsconstraint);
1824
1825 ajStrAppendC(&constraint, " AND ");
1826 ajStrAppendS(&constraint, fvsconstraint);
1827
1828 ajStrDel(&fvsconstraint);
1829
1830 result = ensBaseadaptorFetchAllbyConstraint(
1831 ba,
1832 constraint,
1833 (EnsPAssemblymapper) NULL,
1834 (EnsPSlice) NULL,
1835 gvas);
1836
1837 /*
1838 ** NOTE: The Perl API iterates over the Ensembl Genetic Variation Allele
1839 ** objects and adds the Ensembl Genetic Variation Variation object to each
1840 ** one of them. This will also add the Ensembl Genetic Variation Allele
1841 ** object to the Ensembl Genetic Variation Variation object and weaken
1842 ** the Variation object's link back to the Allele object.
1843 ** If an Ensembl Genetic Variation Population object was specified, the
1844 ** Perl API adds this object to the Allele as well.
1845 */
1846
1847 ajStrDel(&constraint);
1848
1849 return result;
1850 }
1851
1852
1853
1854
1855 /* @func ensGvalleleadaptorFetchAllbySubidentifier ****************************
1856 **
1857 ** Fetch all Ensembl Genetic Variation Allele objects by a Subidentifier.
1858 **
1859 ** @cc Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor::fetch_all_by_subsnp_id
1860 ** @param [u] gvaa [EnsPGvalleleadaptor]
1861 ** Ensembl Genetic Variation Allele Adaptor
1862 ** @param [r] subidentifier [ajuint] Subidentifier
1863 ** @param [u] gvas [AjPList] AJAX List of
1864 ** Ensembl Genetic Variation Allele objects
1865 **
1866 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1867 **
1868 ** @release 6.4.0
1869 ** @@
1870 ******************************************************************************/
1871
1872 AjBool ensGvalleleadaptorFetchAllbySubidentifier(
1873 EnsPGvalleleadaptor gvaa,
1874 ajuint subidentifier,
1875 AjPList gvas)
1876 {
1877 AjBool result = AJFALSE;
1878
1879 AjPStr constraint = NULL;
1880
1881 EnsPBaseadaptor ba = NULL;
1882
1883 EnsPGvdatabaseadaptor gvdba = NULL;
1884
1885 if (!gvaa)
1886 return ajFalse;
1887
1888 if (!subidentifier)
1889 return ajFalse;
1890
1891 if (!gvas)
1892 return ajFalse;
1893
1894 gvdba = ensGvbaseadaptorGetGvdatabaseadaptor(gvaa->Excludeadaptor);
1895
1896 if (ensGvdatabaseadaptorGetFailedvariations(gvdba))
1897 ba = ensGvbaseadaptorGetBaseadaptor(gvaa->Includeadaptor);
1898 else
1899 ba = ensGvbaseadaptorGetBaseadaptor(gvaa->Excludeadaptor);
1900
1901 constraint = ajFmtStr("allele.subsnp_id = %u", subidentifier);
1902
1903 result = ensBaseadaptorFetchAllbyConstraint(
1904 ba,
1905 constraint,
1906 (EnsPAssemblymapper) NULL,
1907 (EnsPSlice) NULL,
1908 gvas);
1909
1910 ajStrDel(&constraint);
1911
1912 return result;
1913 }
1914
1915
1916
1917
1918 /* @section accessory object retrieval ****************************************
1919 **
1920 ** Functions for retrieving objects releated to
1921 ** Ensembl Genetic Variation Allele
1922 ** objects from an Ensembl SQL database.
1923 **
1924 ** @fdata [EnsPGvalleleadaptor]
1925 **
1926 ** @nam3rule Retrieve
1927 ** Retrieve Ensembl Genetic Variation Allele-releated object(s)
1928 ** @nam4rule All
1929 ** Retrieve all Ensembl Genetic Variation Allele-releated objects
1930 ** @nam5rule Identifiers Retrieve all SQL database-internal identifier objects
1931 ** @nam5rule Faileddescriptions Retrieve all failed descriptions
1932 ** @nam4rule Subhandle Retrieve the Subhandle
1933 **
1934 ** @argrule * gvaa [EnsPGvalleleadaptor]
1935 ** Ensembl Genetic Variation Allele Adaptor
1936 ** @argrule AllIdentifiers identifiers [AjPList]
1937 ** AJAX List of AJAX unsigned integer objects
1938 ** @argrule AllFaileddescriptions gva [const EnsPGvallele]
1939 ** Ensembl Genetic Variation Allele
1940 ** @argrule AllFaileddescriptions descriptions [AjPList]
1941 ** AJAX List of AJAX String (failed description) objects
1942 ** @argrule Subhandle gva [const EnsPGvallele]
1943 ** Ensembl Genetic Variation Allele
1944 ** @argrule Subhandle Psubhandle [AjPStr*] Subhandle
1945 **
1946 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1947 **
1948 ** @fcategory use
1949 ******************************************************************************/
1950
1951
1952
1953
1954 /* @func ensGvalleleadaptorRetrieveAllFaileddescriptions **********************
1955 **
1956 ** Retrieve all failed descriptions of an
1957 ** Ensembl Genetic Variation Allele object.
1958 **
1959 ** @cc Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor::
1960 ** get_all_failed_descriptions
1961 ** @cc Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor::
1962 ** _internal_get_failed_descriptions
1963 ** @param [u] gvaa [EnsPGvalleleadaptor]
1964 ** Ensembl Genetic Variation Allele Adaptor
1965 ** @param [r] gva [const EnsPGvallele]
1966 ** Ensembl Genetic Variation Allele
1967 ** @param [u] descriptions [AjPList] AJAX List of
1968 ** AJAX String (description) objects
1969 **
1970 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1971 **
1972 ** @release 6.4.0
1973 ** @@
1974 ******************************************************************************/
1975
1976 AjBool ensGvalleleadaptorRetrieveAllFaileddescriptions(
1977 EnsPGvalleleadaptor gvaa,
1978 const EnsPGvallele gva,
1979 AjPList descriptions)
1980 {
1981 AjPSqlstatement sqls = NULL;
1982 AjISqlrow sqli = NULL;
1983 AjPSqlrow sqlr = NULL;
1984
1985 AjPStr description = NULL;
1986 AjPStr statement = NULL;
1987
1988 EnsPDatabaseadaptor dba = NULL;
1989
1990 if (!gvaa)
1991 return ajFalse;
1992
1993 if (!gva)
1994 return ajFalse;
1995
1996 if (!descriptions)
1997 return ajFalse;
1998
1999 dba = ensGvalleleadaptorGetDatabaseadaptor(gvaa);
2000
2001 statement = ajFmtStr(
2002 "SELECT "
2003 "DISTINCT "
2004 "failed_description.description "
2005 "FROM "
2006 "failed_allele "
2007 "JOIN "
2008 "failed_description "
2009 "ON "
2010 "("
2011 "failed_description.failed_description_id = "
2012 "failed_allele.failed_description_id"
2013 ") "
2014 "WHERE "
2015 "failed_allele.allele_id = %u",
2016 gva->Identifier);
2017
2018 sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
2019
2020 sqli = ajSqlrowiterNew(sqls);
2021
2022 while (!ajSqlrowiterDone(sqli))
2023 {
2024 description = ajStrNew();
2025
2026 sqlr = ajSqlrowiterGet(sqli);
2027
2028 ajSqlcolumnToStr(sqlr, &description);
2029
2030 ajListstrPushAppend(descriptions, description);
2031 }
2032
2033 ajSqlrowiterDel(&sqli);
2034
2035 ensDatabaseadaptorSqlstatementDel(dba, &sqls);
2036
2037 ajStrDel(&statement);
2038
2039 return ajTrue;
2040 }
2041
2042
2043
2044
2045 /* @func ensGvalleleadaptorRetrieveSubhandle **********************************
2046 **
2047 ** Retrieve the Subhandle of an
2048 ** Ensembl Genetic Variation Allele object.
2049 **
2050 ** @cc Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor::get_subsnp_handle
2051 ** @param [u] gvaa [EnsPGvalleleadaptor]
2052 ** Ensembl Genetic Variation Allele Adaptor
2053 ** @param [r] gva [const EnsPGvallele]
2054 ** Ensembl Genetic Variation Allele
2055 ** @param [u] Psubhandle [AjPStr*] AJAX String (Subhandle) address
2056 **
2057 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2058 **
2059 ** @release 6.4.0
2060 ** @@
2061 ******************************************************************************/
2062
2063 AjBool ensGvalleleadaptorRetrieveSubhandle(
2064 EnsPGvalleleadaptor gvaa,
2065 const EnsPGvallele gva,
2066 AjPStr *Psubhandle)
2067 {
2068 AjPSqlstatement sqls = NULL;
2069 AjISqlrow sqli = NULL;
2070 AjPSqlrow sqlr = NULL;
2071
2072 AjPStr handle = NULL;
2073 AjPStr statement = NULL;
2074
2075 EnsPDatabaseadaptor dba = NULL;
2076
2077 if (!gvaa)
2078 return ajFalse;
2079
2080 if (!gva)
2081 return ajFalse;
2082
2083 dba = ensGvalleleadaptorGetDatabaseadaptor(gvaa);
2084
2085 statement = ajFmtStr(
2086 "SELECT "
2087 "subsnp_handle.handle "
2088 "FROM "
2089 "subsnp_handle "
2090 "WHERE "
2091 "subsnp_handle.subsnp_id = %u "
2092 /* NOTE: LIMIT 1 is MySQL-specific. */
2093 "LIMIT 1",
2094 gva->Subidentifier);
2095
2096 sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
2097
2098 sqli = ajSqlrowiterNew(sqls);
2099
2100 while (!ajSqlrowiterDone(sqli))
2101 {
2102 handle = ajStrNew();
2103
2104 sqlr = ajSqlrowiterGet(sqli);
2105
2106 ajSqlcolumnToStr(sqlr, &handle);
2107
2108 ajStrAssignS(Psubhandle, handle);
2109
2110 ajStrDel(&handle);
2111 }
2112
2113 ajSqlrowiterDel(&sqli);
2114
2115 ensDatabaseadaptorSqlstatementDel(dba, &sqls);
2116
2117 ajStrDel(&statement);
2118
2119 return ajTrue;
2120 }