1 /* @source ensmetainformation *************************************************
2 **
3 ** Ensembl Meta-Information functions
4 **
5 ** @author Copyright (C) 1999 Ensembl Developers
6 ** @author Copyright (C) 2006 Michael K. Schuster
7 ** @version $Revision: 1.42 $
8 ** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core
9 ** @modified $Date: 2013/02/17 13:02:40 $ 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 "ensmetainformation.h"
34 #include "enstable.h"
35
36
37
38
39 /* ========================================================================= */
40 /* =============================== constants =============================== */
41 /* ========================================================================= */
42
43
44
45
46 /* ========================================================================= */
47 /* =========================== global variables ============================ */
48 /* ========================================================================= */
49
50
51
52
53 /* ========================================================================= */
54 /* ============================= private data ============================== */
55 /* ========================================================================= */
56
57
58
59
60 /* ========================================================================= */
61 /* =========================== private constants =========================== */
62 /* ========================================================================= */
63
64 /* @conststatic metainformationKNonSpeciesKeys ********************************
65 **
66 ** The following Ensembl Meta-Information keys are not species-specific,
67 ** i.e. they are not linked to a species identifier.
68 **
69 ******************************************************************************/
70
71 static const char *metainformationKNonSpeciesKeys[] =
72 {
73 "patch",
74 "schema_version",
75 "schema_type",
76 (const char *) NULL
77 };
78
79
80
81
82 /* ========================================================================= */
83 /* =========================== private variables =========================== */
84 /* ========================================================================= */
85
86
87
88
89 /* ========================================================================= */
90 /* =========================== private functions =========================== */
91 /* ========================================================================= */
92
93 static int listMetainformationCompareIdentifierAscending(
94 const void *item1,
95 const void *item2);
96
97 static int listMetainformationCompareIdentifierDescending(
98 const void *item1,
99 const void *item2);
100
101 static AjBool metainformationkeyIsSpecieskey(const AjPStr key);
102
103 static AjBool metainformationadaptorFetchAllbyStatement(
104 EnsPMetainformationadaptor mia,
105 const AjPStr statement,
106 AjPList mis);
107
108 static AjBool metainformationadaptorCacheInit(
109 EnsPMetainformationadaptor mia);
110
111 static void metainformationadaptorCacheByKeyValdel(void **Pvalue);
112
113
114
115
116 /* ========================================================================= */
117 /* ======================= All functions by section ======================== */
118 /* ========================================================================= */
119
120
121
122
123 /* @filesection ensmetainformation ********************************************
124 **
125 ** @nam1rule ens Function belongs to the Ensembl library
126 **
127 ******************************************************************************/
128
129
130
131
132 /* @datasection [EnsPMetainformation] Ensembl Meta-Information ****************
133 **
134 ** @nam2rule Metainformation Functions for manipulating
135 ** Ensembl Meta-Information objects
136 **
137 ******************************************************************************/
138
139
140
141
142 /* @section constructors ******************************************************
143 **
144 ** All constructors return a new Ensembl Meta-Information by pointer.
145 ** It is the responsibility of the user to first destroy any previous
146 ** Meta-Information. The target pointer does not need to be initialised to
147 ** NULL, but it is good programming practice to do so anyway.
148 **
149 ** @fdata [EnsPMetainformation]
150 **
151 ** @nam3rule New Constructor
152 ** @nam4rule Cpy Constructor with existing object
153 ** @nam4rule Ini Constructor with initial values
154 ** @nam4rule Ref Constructor by incrementing the reference counter
155 **
156 ** @argrule Cpy mi [const EnsPMetainformation] Ensembl Meta-Information
157 ** @argrule Ini mia [EnsPMetainformationadaptor]
158 ** Ensembl Meta-Information Adaptor
159 ** @argrule Ini identifier [ajuint] SQL database-internal identifier
160 ** @argrule Ini species [ajuint] Species identififer
161 ** @argrule Ini key [AjPStr] Key
162 ** @argrule Ini value [AjPStr] Value
163 ** @argrule Ref mi [EnsPMetainformation] Ensembl Meta-Information
164 **
165 ** @valrule * [EnsPMetainformation] Ensembl Meta-Information or NULL
166 **
167 ** @fcategory new
168 ******************************************************************************/
169
170
171
172
173 /* @func ensMetainformationNewCpy *********************************************
174 **
175 ** Object-based constructor function, which returns an independent object.
176 **
177 ** @param [r] mi [const EnsPMetainformation] Ensembl Meta-Information
178 **
179 ** @return [EnsPMetainformation] Ensembl Meta-Information or NULL
180 **
181 ** @release 6.4.0
182 ** @@
183 ******************************************************************************/
184
ensMetainformationNewCpy(const EnsPMetainformation mi)185 EnsPMetainformation ensMetainformationNewCpy(const EnsPMetainformation mi)
186 {
187 EnsPMetainformation pthis = NULL;
188
189 if (!mi)
190 return NULL;
191
192 AJNEW0(pthis);
193
194 pthis->Use = 1U;
195 pthis->Identifier = mi->Identifier;
196 pthis->Adaptor = mi->Adaptor;
197
198 if (mi->Key)
199 pthis->Key = ajStrNewRef(mi->Key);
200
201 if (mi->Value)
202 pthis->Value = ajStrNewRef(mi->Value);
203
204 pthis->Species = (mi->Species) ? mi->Species : 1;
205
206 return pthis;
207 }
208
209
210
211
212 /* @func ensMetainformationNewIni *********************************************
213 **
214 ** Constructor for an Ensembl Meta-Information object with initial values.
215 **
216 ** @cc Bio::EnsEMBL::Storable
217 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
218 ** @param [r] identifier [ajuint] SQL database-internal identifier
219 ** @cc Bio::EnsEMBL::MetaContainer
220 ** @param [r] species [ajuint] Species identififer
221 ** @param [u] key [AjPStr] Key
222 ** @param [u] value [AjPStr] Value
223 **
224 ** @return [EnsPMetainformation] Ensembl Meta-Information or NULL
225 **
226 ** @release 6.4.0
227 ** @@
228 ******************************************************************************/
229
ensMetainformationNewIni(EnsPMetainformationadaptor mia,ajuint identifier,ajuint species,AjPStr key,AjPStr value)230 EnsPMetainformation ensMetainformationNewIni(EnsPMetainformationadaptor mia,
231 ajuint identifier,
232 ajuint species,
233 AjPStr key,
234 AjPStr value)
235 {
236 EnsPMetainformation mi = NULL;
237
238 AJNEW0(mi);
239
240 mi->Use = 1U;
241 mi->Identifier = identifier;
242 mi->Adaptor = mia;
243
244 if (key)
245 mi->Key = ajStrNewRef(key);
246
247 if (value)
248 mi->Value = ajStrNewRef(value);
249
250 mi->Species = (species) ? species : 1;
251
252 return mi;
253 }
254
255
256
257
258 /* @func ensMetainformationNewRef *********************************************
259 **
260 ** Ensembl Object referencing function, which returns a pointer to the
261 ** Ensembl Object passed in and increases its reference count.
262 **
263 ** @param [u] mi [EnsPMetainformation] Ensembl Meta-Information
264 **
265 ** @return [EnsPMetainformation] Ensembl Meta-Information or NULL
266 **
267 ** @release 6.2.0
268 ** @@
269 ******************************************************************************/
270
ensMetainformationNewRef(EnsPMetainformation mi)271 EnsPMetainformation ensMetainformationNewRef(EnsPMetainformation mi)
272 {
273 if (!mi)
274 return NULL;
275
276 mi->Use++;
277
278 return mi;
279 }
280
281
282
283
284 /* @section destructors *******************************************************
285 **
286 ** Destruction destroys all internal data structures and frees the memory
287 ** allocated for an Ensembl Meta-Information object.
288 **
289 ** @fdata [EnsPMetainformation]
290 **
291 ** @nam3rule Del Destroy (free) an Ensembl Meta-Information
292 **
293 ** @argrule * Pmi [EnsPMetainformation*] Ensembl Meta-Information address
294 **
295 ** @valrule * [void]
296 **
297 ** @fcategory delete
298 ******************************************************************************/
299
300
301
302
303 /* @func ensMetainformationDel ************************************************
304 **
305 ** Default destructor for an Ensembl Meta-Information object.
306 **
307 ** @param [d] Pmi [EnsPMetainformation*] Ensembl Meta-Information address
308 **
309 ** @return [void]
310 **
311 ** @release 6.2.0
312 ** @@
313 ******************************************************************************/
314
ensMetainformationDel(EnsPMetainformation * Pmi)315 void ensMetainformationDel(EnsPMetainformation *Pmi)
316 {
317 EnsPMetainformation pthis = NULL;
318
319 if (!Pmi)
320 return;
321
322 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
323 if (ajDebugTest("ensMetainformationDel"))
324 {
325 ajDebug("ensMetainformationDel\n"
326 " *Pmi %p\n",
327 *Pmi);
328
329 ensMetainformationTrace(*Pmi, 1);
330 }
331 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
332
333 if (!(pthis = *Pmi) || --pthis->Use)
334 {
335 *Pmi = NULL;
336
337 return;
338 }
339
340 ajStrDel(&pthis->Key);
341 ajStrDel(&pthis->Value);
342
343 ajMemFree((void **) Pmi);
344
345 return;
346 }
347
348
349
350
351 /* @section member retrieval **************************************************
352 **
353 ** Functions for returning members of an Ensembl Meta-Information object.
354 **
355 ** @fdata [EnsPMetainformation]
356 **
357 ** @nam3rule Get Return Meta-Information attribute(s)
358 ** @nam4rule Adaptor Return the Ensembl Meta-Information Adaptor
359 ** @nam4rule Identifier Return the SQL database-internal identifier
360 ** @nam4rule Key Return the key
361 ** @nam4rule Species Return the species identifier
362 ** @nam4rule Value Return the value
363 **
364 ** @argrule * mi [const EnsPMetainformation] Ensembl Meta-Information
365 **
366 ** @valrule Adaptor [EnsPMetainformationadaptor] Ensembl Meta-Information
367 ** Adaptor or NULL
368 ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U
369 ** @valrule Key [AjPStr] Key or NULL
370 ** @valrule Species [ajuint] Species identifier or 0U
371 ** @valrule Value [AjPStr] Value or NULL
372 **
373 ** @fcategory use
374 ******************************************************************************/
375
376
377
378
379 /* @func ensMetainformationGetAdaptor *****************************************
380 **
381 ** Get the Ensembl Meta-Information Adaptor member of an
382 ** Ensembl Meta-Information.
383 **
384 ** @param [r] mi [const EnsPMetainformation] Ensembl Meta-Information
385 **
386 ** @return [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
387 ** or NULL
388 **
389 ** @release 6.2.0
390 ** @@
391 ******************************************************************************/
392
ensMetainformationGetAdaptor(const EnsPMetainformation mi)393 EnsPMetainformationadaptor ensMetainformationGetAdaptor(
394 const EnsPMetainformation mi)
395 {
396 return (mi) ? mi->Adaptor : NULL;
397 }
398
399
400
401
402 /* @func ensMetainformationGetIdentifier **************************************
403 **
404 ** Get the SQL database-internal identifier member of an
405 ** Ensembl Meta-Information.
406 **
407 ** @param [r] mi [const EnsPMetainformation] Ensembl Meta-Information
408 **
409 ** @return [ajuint] SQL database-internal identifier or 0U
410 **
411 ** @release 6.2.0
412 ** @@
413 ******************************************************************************/
414
ensMetainformationGetIdentifier(const EnsPMetainformation mi)415 ajuint ensMetainformationGetIdentifier(const EnsPMetainformation mi)
416 {
417 return (mi) ? mi->Identifier : 0U;
418 }
419
420
421
422
423 /* @func ensMetainformationGetKey *********************************************
424 **
425 ** Get the key member of an Ensembl Meta-Information.
426 **
427 ** @param [r] mi [const EnsPMetainformation] Ensembl Meta-Information
428 **
429 ** @return [AjPStr] Key or NULL
430 **
431 ** @release 6.2.0
432 ** @@
433 ******************************************************************************/
434
ensMetainformationGetKey(const EnsPMetainformation mi)435 AjPStr ensMetainformationGetKey(const EnsPMetainformation mi)
436 {
437 return (mi) ? mi->Key : NULL;
438 }
439
440
441
442
443 /* @func ensMetainformationGetSpecies *****************************************
444 **
445 ** Get the species identifier member of an Ensembl Meta-Information object.
446 **
447 ** @param [r] mi [const EnsPMetainformation] Ensembl Meta-Information
448 **
449 ** @return [ajuint] Species identifier or 0U
450 **
451 ** @release 6.2.0
452 ** @@
453 ******************************************************************************/
454
ensMetainformationGetSpecies(const EnsPMetainformation mi)455 ajuint ensMetainformationGetSpecies(const EnsPMetainformation mi)
456 {
457 return (mi) ? mi->Species : 0U;
458 }
459
460
461
462
463 /* @func ensMetainformationGetValue *******************************************
464 **
465 ** Get the value member of an Ensembl Meta-Information.
466 **
467 ** @param [r] mi [const EnsPMetainformation] Ensembl Meta-Information
468 **
469 ** @return [AjPStr] Value or NULL
470 **
471 ** @release 6.2.0
472 ** @@
473 ******************************************************************************/
474
ensMetainformationGetValue(const EnsPMetainformation mi)475 AjPStr ensMetainformationGetValue(const EnsPMetainformation mi)
476 {
477 return (mi) ? mi->Value : NULL;
478 }
479
480
481
482
483 /* @section modifiers *********************************************************
484 **
485 ** Functions for assigning members of an Ensembl Meta-Information object.
486 **
487 ** @fdata [EnsPMetainformation]
488 **
489 ** @nam3rule Set Set one member of a Meta-Information
490 ** @nam4rule Adaptor Set the Ensembl Meta-Information Adaptor
491 ** @nam4rule Identifier Set the SQL database-internal identifier
492 ** @nam4rule Key Set the key
493 ** @nam4rule Species Set the species identifier
494 ** @nam4rule Value Set the value
495 **
496 ** @argrule * mi [EnsPMetainformation] Ensembl Meta-Information object
497 ** @argrule Adaptor mia [EnsPMetainformationadaptor] Ensembl Meta-Information
498 ** Adaptor
499 ** @argrule Identifier identifier [ajuint] SQL database-internal identifier
500 ** @argrule Key key [AjPStr] Key
501 ** @argrule Species species [ajuint] Species identifier
502 ** @argrule Value value [AjPStr] Value
503 **
504 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
505 **
506 ** @fcategory modify
507 ******************************************************************************/
508
509
510
511
512 /* @func ensMetainformationSetAdaptor *****************************************
513 **
514 ** Set the Ensembl Meta-Information Adaptor member of an
515 ** Ensembl Meta-Information.
516 **
517 ** @param [u] mi [EnsPMetainformation] Ensembl Meta-Information
518 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
519 **
520 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
521 **
522 ** @release 6.2.0
523 ** @@
524 ******************************************************************************/
525
ensMetainformationSetAdaptor(EnsPMetainformation mi,EnsPMetainformationadaptor mia)526 AjBool ensMetainformationSetAdaptor(EnsPMetainformation mi,
527 EnsPMetainformationadaptor mia)
528 {
529 if (!mi)
530 return ajFalse;
531
532 mi->Adaptor = mia;
533
534 return ajTrue;
535 }
536
537
538
539
540 /* @func ensMetainformationSetIdentifier **************************************
541 **
542 ** Set the SQL database-internal identifier member of an
543 ** Ensembl Meta-Information.
544 **
545 ** @param [u] mi [EnsPMetainformation] Ensembl Meta-Information
546 ** @param [r] identifier [ajuint] SQL database-internal identifier
547 **
548 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
549 **
550 ** @release 6.2.0
551 ** @@
552 ******************************************************************************/
553
ensMetainformationSetIdentifier(EnsPMetainformation mi,ajuint identifier)554 AjBool ensMetainformationSetIdentifier(EnsPMetainformation mi,
555 ajuint identifier)
556 {
557 if (!mi)
558 return ajFalse;
559
560 mi->Identifier = identifier;
561
562 return ajTrue;
563 }
564
565
566
567
568 /* @func ensMetainformationSetKey *********************************************
569 **
570 ** Set the key member of an Ensembl Meta-Information.
571 **
572 ** @param [u] mi [EnsPMetainformation] Ensembl Meta-Information
573 ** @param [u] key [AjPStr] Key
574 **
575 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
576 **
577 ** @release 6.2.0
578 ** @@
579 ******************************************************************************/
580
ensMetainformationSetKey(EnsPMetainformation mi,AjPStr key)581 AjBool ensMetainformationSetKey(EnsPMetainformation mi, AjPStr key)
582 {
583 if (!mi)
584 return ajFalse;
585
586 ajStrDel(&mi->Key);
587
588 if (key)
589 mi->Key = ajStrNewRef(key);
590
591 return ajTrue;
592 }
593
594
595
596
597 /* @func ensMetainformationSetSpecies *****************************************
598 **
599 ** Set the species identifier member of an Ensembl Meta-Information.
600 **
601 ** @param [u] mi [EnsPMetainformation] Ensembl Meta-Information
602 ** @param [r] species [ajuint] Species identifier
603 **
604 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
605 **
606 ** @release 6.2.0
607 ** @@
608 ******************************************************************************/
609
ensMetainformationSetSpecies(EnsPMetainformation mi,ajuint species)610 AjBool ensMetainformationSetSpecies(EnsPMetainformation mi, ajuint species)
611 {
612 if (!mi)
613 return ajFalse;
614
615 mi->Species = species;
616
617 return ajTrue;
618 }
619
620
621
622
623 /* @func ensMetainformationSetValue *******************************************
624 **
625 ** Set the value member of an Ensembl Meta-Information.
626 **
627 ** @param [u] mi [EnsPMetainformation] Ensembl Meta-Information
628 ** @param [u] value [AjPStr] Value
629 **
630 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
631 **
632 ** @release 6.2.0
633 ** @@
634 ******************************************************************************/
635
ensMetainformationSetValue(EnsPMetainformation mi,AjPStr value)636 AjBool ensMetainformationSetValue(EnsPMetainformation mi, AjPStr value)
637 {
638 if (!mi)
639 return ajFalse;
640
641 ajStrDel(&mi->Value);
642
643 if (value)
644 mi->Value = ajStrNewRef(value);
645
646 return ajTrue;
647 }
648
649
650
651
652 /* @section debugging *********************************************************
653 **
654 ** Functions for reporting of an Ensembl Meta-Information.
655 **
656 ** @fdata [EnsPMetainformation]
657 **
658 ** @nam3rule Trace Report Ensembl Meta-Information members to debug file
659 **
660 ** @argrule Trace mi [const EnsPMetainformation] Ensembl Meta-Information
661 ** @argrule Trace level [ajuint] Indentation level
662 **
663 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
664 **
665 ** @fcategory misc
666 ******************************************************************************/
667
668
669
670
671 /* @func ensMetainformationTrace **********************************************
672 **
673 ** Trace an Ensembl Meta-Information.
674 **
675 ** @param [r] mi [const EnsPMetainformation] Ensembl Meta-Information
676 ** @param [r] level [ajuint] Indentation level
677 **
678 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
679 **
680 ** @release 6.2.0
681 ** @@
682 ******************************************************************************/
683
ensMetainformationTrace(const EnsPMetainformation mi,ajuint level)684 AjBool ensMetainformationTrace(const EnsPMetainformation mi, ajuint level)
685 {
686 AjPStr indent = NULL;
687
688 if (!mi)
689 return ajFalse;
690
691 indent = ajStrNew();
692
693 ajStrAppendCountK(&indent, ' ', level * 2);
694
695 ajDebug("%SensMetainformationTrace %p\n"
696 "%S Use %u\n"
697 "%S Identifier %u\n"
698 "%S Adaptor %p\n"
699 "%S Key '%S'\n"
700 "%S Value '%S'\n"
701 "%S Species %u\n",
702 indent, mi,
703 indent, mi->Use,
704 indent, mi->Identifier,
705 indent, mi->Adaptor,
706 indent, mi->Key,
707 indent, mi->Value,
708 indent, mi->Species);
709
710 ajStrDel(&indent);
711
712 return ajTrue;
713 }
714
715
716
717
718 /* @section calculate *********************************************************
719 **
720 ** Functions for calculating information from an
721 ** Ensembl Meta-Information object.
722 **
723 ** @fdata [EnsPMetainformation]
724 **
725 ** @nam3rule Calculate Calculate Ensembl Meta-Information information
726 ** @nam4rule Memsize Calculate the memory size in bytes
727 **
728 ** @argrule * mi [const EnsPMetainformation] Ensembl Meta-Information
729 **
730 ** @valrule Memsize [size_t] Memory size in bytes or 0
731 **
732 ** @fcategory misc
733 ******************************************************************************/
734
735
736
737
738 /* @func ensMetainformationCalculateMemsize ***********************************
739 **
740 ** Get the memory size in bytes of an Ensembl Meta-Information.
741 **
742 ** @param [r] mi [const EnsPMetainformation] Ensembl Meta-Information
743 **
744 ** @return [size_t] Memory size in bytes or 0
745 **
746 ** @release 6.4.0
747 ** @@
748 ******************************************************************************/
749
ensMetainformationCalculateMemsize(const EnsPMetainformation mi)750 size_t ensMetainformationCalculateMemsize(const EnsPMetainformation mi)
751 {
752 size_t size = 0;
753
754 if (!mi)
755 return 0;
756
757 size += sizeof (EnsOMetainformation);
758
759 if (mi->Key)
760 {
761 size += sizeof (AjOStr);
762
763 size += ajStrGetRes(mi->Key);
764 }
765
766 if (mi->Value)
767 {
768 size += sizeof (AjOStr);
769
770 size += ajStrGetRes(mi->Value);
771 }
772
773 return size;
774 }
775
776
777
778
779 /* @datasection [AjPList] AJAX List *******************************************
780 **
781 ** @nam2rule List Functions for manipulating AJAX List objects
782 **
783 ******************************************************************************/
784
785
786
787
788 /* @funcstatic listMetainformationCompareIdentifierAscending ******************
789 **
790 ** AJAX List of Ensembl Meta-Information objects comparison function
791 ** to sort by Ensembl Meta-Information identifier in ascending order.
792 **
793 ** @param [r] item1 [const void*] Ensembl Meta-Information address 1
794 ** @param [r] item2 [const void*] Ensembl Meta-Information address 2
795 ** @see ajListSort
796 **
797 ** @return [int] The comparison function returns an integer less than,
798 ** equal to, or greater than zero if the first argument is
799 ** considered to be respectively less than, equal to, or
800 ** greater than the second.
801 **
802 ** @release 6.4.0
803 ** @@
804 ******************************************************************************/
805
listMetainformationCompareIdentifierAscending(const void * item1,const void * item2)806 static int listMetainformationCompareIdentifierAscending(
807 const void *item1,
808 const void *item2)
809 {
810 EnsPMetainformation mi1 = *(EnsOMetainformation *const *) item1;
811 EnsPMetainformation mi2 = *(EnsOMetainformation *const *) item2;
812
813 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
814 if (ajDebugTest("listMetainformationCompareIdentifierAscending"))
815 ajDebug("listMetainformationCompareIdentifierAscending\n"
816 " mi1 %p\n"
817 " mi2 %p\n",
818 mi1,
819 mi2);
820 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
821
822 /* Sort empty values towards the end of the AJAX List. */
823
824 if (mi1 && (!mi2))
825 return -1;
826
827 if ((!mi1) && (!mi2))
828 return 0;
829
830 if ((!mi1) && mi2)
831 return +1;
832
833 if (mi1->Identifier < mi2->Identifier)
834 return -1;
835
836 if (mi1->Identifier > mi2->Identifier)
837 return +1;
838
839 return 0;
840 }
841
842
843
844
845 /* @funcstatic listMetainformationCompareIdentifierDescending *****************
846 **
847 ** AJAX List of Ensembl Meta-Information objects comparison function
848 ** to sort by Ensembl Meta-Information identifier in descending order.
849 **
850 ** @param [r] item1 [const void*] Ensembl Meta-Information address 1
851 ** @param [r] item2 [const void*] Ensembl Meta-Information address 2
852 ** @see ajListSort
853 **
854 ** @return [int] The comparison function returns an integer less than,
855 ** equal to, or greater than zero if the first argument is
856 ** considered to be respectively less than, equal to, or
857 ** greater than the second.
858 **
859 ** @release 6.4.0
860 ** @@
861 ******************************************************************************/
862
listMetainformationCompareIdentifierDescending(const void * item1,const void * item2)863 static int listMetainformationCompareIdentifierDescending(
864 const void *item1,
865 const void *item2)
866 {
867 EnsPMetainformation mi1 = *(EnsOMetainformation *const *) item1;
868 EnsPMetainformation mi2 = *(EnsOMetainformation *const *) item2;
869
870 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
871 if (ajDebugTest("listMetainformationCompareIdentifierDescending"))
872 ajDebug("listMetainformationCompareIdentifierDescending\n"
873 " mi1 %p\n"
874 " mi2 %p\n",
875 mi1,
876 mi2);
877 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
878
879 /* Sort empty values towards the end of the AJAX List. */
880
881 if (mi1 && (!mi2))
882 return -1;
883
884 if ((!mi1) && (!mi2))
885 return 0;
886
887 if ((!mi1) && mi2)
888 return +1;
889
890 if (mi1->Identifier > mi2->Identifier)
891 return -1;
892
893 if (mi1->Identifier < mi2->Identifier)
894 return +1;
895
896 return 0;
897 }
898
899
900
901
902 /* @section list **************************************************************
903 **
904 ** Functions for manipulating AJAX List objects.
905 **
906 ** @fdata [AjPList]
907 **
908 ** @nam3rule Metainformation Functions for manipulating AJAX List objects of
909 ** Ensembl Meta-Information objects
910 ** @nam4rule Sort Sort functions
911 ** @nam5rule Identifier Sort by Ensembl Meta-Information identifier member
912 ** @nam6rule Ascending Sort in ascending order
913 ** @nam6rule Descending Sort in descending order
914 **
915 ** @argrule Sort mis [AjPList] AJAX List of Ensembl Meta-Information objects
916 **
917 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
918 **
919 ** @fcategory misc
920 ******************************************************************************/
921
922
923
924
925 /* @func ensListMetainformationSortIdentifierAscending ************************
926 **
927 ** Sort an AJAX List of Ensembl Meta-Information objects by their
928 ** Ensembl Meta-Information identifier in ascending order.
929 **
930 ** @param [u] mis [AjPList] AJAX List of Ensembl Meta-Information objects
931 **
932 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
933 **
934 ** @release 6.4.0
935 ** @@
936 ******************************************************************************/
937
ensListMetainformationSortIdentifierAscending(AjPList mis)938 AjBool ensListMetainformationSortIdentifierAscending(AjPList mis)
939 {
940 if (!mis)
941 return ajFalse;
942
943 ajListSort(mis, &listMetainformationCompareIdentifierAscending);
944
945 return ajTrue;
946 }
947
948
949
950
951 /* @func ensListMetainformationSortIdentifierDescending ***********************
952 **
953 ** Sort an AJAX List of Ensembl Meta-Information objects by their
954 ** Ensembl Meta-Information identifier in descending order.
955 **
956 ** @param [u] mis [AjPList] AJAX List of Ensembl Meta-Information objects
957 **
958 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
959 **
960 ** @release 6.4.0
961 ** @@
962 ******************************************************************************/
963
ensListMetainformationSortIdentifierDescending(AjPList mis)964 AjBool ensListMetainformationSortIdentifierDescending(AjPList mis)
965 {
966 if (!mis)
967 return ajFalse;
968
969 ajListSort(mis, &listMetainformationCompareIdentifierDescending);
970
971 return ajTrue;
972 }
973
974
975
976
977 /* @funcstatic metainformationkeyIsSpecieskey *********************************
978 **
979 ** Check whether a Meta-Information key is species-specific.
980 **
981 ** @param [r] key [const AjPStr] Key
982 **
983 ** @return [AjBool] ajTrue for species-specific keys,
984 ** ajFalse for unspecific keys
985 **
986 ** @release 6.3.0
987 ** @@
988 ******************************************************************************/
989
metainformationkeyIsSpecieskey(const AjPStr key)990 static AjBool metainformationkeyIsSpecieskey(const AjPStr key)
991 {
992 register ajuint i = 0U;
993
994 AjBool result = AJTRUE;
995
996 if (!key)
997 return ajFalse;
998
999 for (i = 0U; metainformationKNonSpeciesKeys[i]; i++)
1000 if (ajStrMatchCaseC(key, metainformationKNonSpeciesKeys[i]))
1001 {
1002 result = AJFALSE;
1003
1004 break;
1005 }
1006
1007 return result;
1008 }
1009
1010
1011
1012
1013 /* @datasection [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1014 **
1015 ** @nam2rule Metainformationadaptor Functions for manipulating
1016 ** Ensembl Meta-Information Adaptor objects
1017 **
1018 ** @cc Bio::EnsEMBL::DBSQL::BaseMetaContainer
1019 ** @cc CVS Revision: 1.23
1020 ** @cc CVS Tag: branch-ensembl-68
1021 **
1022 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer
1023 ** @cc CVS Revision: 1.43
1024 ** @cc CVS Tag: branch-ensembl-68
1025 **
1026 ******************************************************************************/
1027
1028
1029
1030
1031 /* @funcstatic metainformationadaptorFetchAllbyStatement **********************
1032 **
1033 ** Run a SQL statement against an Ensembl Database Adaptor and consolidate the
1034 ** results into an AJAX List of Ensembl Meta-Information objects.
1035 **
1036 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1037 ** @param [r] statement [const AjPStr] SQL statement
1038 ** @param [u] mis [AjPList] AJAX List of Ensembl Meta-Information objects
1039 **
1040 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1041 **
1042 ** @release 6.4.0
1043 ** @@
1044 ******************************************************************************/
1045
metainformationadaptorFetchAllbyStatement(EnsPMetainformationadaptor mia,const AjPStr statement,AjPList mis)1046 static AjBool metainformationadaptorFetchAllbyStatement(
1047 EnsPMetainformationadaptor mia,
1048 const AjPStr statement,
1049 AjPList mis)
1050 {
1051 ajuint identifier = 0U;
1052 ajuint species = 0U;
1053
1054 AjPSqlstatement sqls = NULL;
1055 AjISqlrow sqli = NULL;
1056 AjPSqlrow sqlr = NULL;
1057
1058 AjPStr key = NULL;
1059 AjPStr value = NULL;
1060
1061 EnsPDatabaseadaptor dba = NULL;
1062
1063 EnsPMetainformation mi = NULL;
1064
1065 if (ajDebugTest("metainformationadaptorFetchAllbyStatement"))
1066 ajDebug("metainformationadaptorFetchAllbyStatement\n"
1067 " mia %p\n"
1068 " statement %p\n"
1069 " mis %p\n",
1070 mia,
1071 statement,
1072 mis);
1073
1074 if (!mia)
1075 return ajFalse;
1076
1077 if (!statement)
1078 return ajFalse;
1079
1080 if (!mis)
1081 return ajFalse;
1082
1083 dba = ensMetainformationadaptorGetDatabaseadaptor(mia);
1084
1085 sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
1086
1087 sqli = ajSqlrowiterNew(sqls);
1088
1089 while (!ajSqlrowiterDone(sqli))
1090 {
1091 identifier = 0;
1092 species = 0;
1093
1094 key = ajStrNew();
1095 value = ajStrNew();
1096
1097 sqlr = ajSqlrowiterGet(sqli);
1098
1099 ajSqlcolumnToUint(sqlr, &identifier);
1100 ajSqlcolumnToUint(sqlr, &species);
1101 ajSqlcolumnToStr(sqlr, &key);
1102 ajSqlcolumnToStr(sqlr, &value);
1103
1104 mi = ensMetainformationNewIni(mia, identifier, species, key, value);
1105
1106 ajListPushAppend(mis, (void *) mi);
1107
1108 ajStrDel(&key);
1109 ajStrDel(&value);
1110 }
1111
1112 ajSqlrowiterDel(&sqli);
1113
1114 ensDatabaseadaptorSqlstatementDel(dba, &sqls);
1115
1116 return ajTrue;
1117 }
1118
1119
1120
1121
1122 /* @funcstatic metainformationadaptorCacheInit ********************************
1123 **
1124 ** Initialise the Ensembl Meta-Information Adaptor-internal
1125 ** Meta-Information cache.
1126 **
1127 ** The cache contains all Meta-Information objects irrespective of their
1128 ** species identifier. Standard object retrieval functions accessing the cache
1129 ** are expected to select species-specific Meta-Information objects via the
1130 ** species identifier in the corresponding Ensembl Database Adaptor, as well
1131 ** non species-specific objects. Specialist functions can still select objects
1132 ** for all species identifiers.
1133 **
1134 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1135 **
1136 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1137 **
1138 ** @release 6.3.0
1139 ** @@
1140 ******************************************************************************/
1141
metainformationadaptorCacheInit(EnsPMetainformationadaptor mia)1142 static AjBool metainformationadaptorCacheInit(
1143 EnsPMetainformationadaptor mia)
1144 {
1145 ajuint *Pidentifier = NULL;
1146
1147 AjPList mis = NULL;
1148 AjPList list = NULL;
1149 AjPStr statement = NULL;
1150
1151 EnsPMetainformation mi = NULL;
1152 EnsPMetainformation temp = NULL;
1153
1154 if (ajDebugTest("metainformationadaptorCacheInit"))
1155 ajDebug("metainformationadaptorCacheInit\n"
1156 " mia %p\n",
1157 mia);
1158
1159 if (!mia)
1160 return ajFalse;
1161
1162 statement = ajStrNewC(
1163 "SELECT "
1164 "meta.meta_id, "
1165 "meta.species_id, "
1166 "meta.meta_key, "
1167 "meta.meta_value "
1168 "FROM "
1169 "meta");
1170
1171 mis = ajListNew();
1172
1173 metainformationadaptorFetchAllbyStatement(mia, statement, mis);
1174
1175 /*
1176 ** Sorting by identifier here, should lead to sorted AJAX List objects
1177 ** throughout the cache.
1178 */
1179
1180 ensListMetainformationSortIdentifierAscending(mis);
1181
1182 while (ajListPop(mis, (void **) &mi))
1183 {
1184 /* Insert into the identifier cache. */
1185
1186 AJNEW0(Pidentifier);
1187
1188 *Pidentifier = mi->Identifier;
1189
1190 temp = (EnsPMetainformation) ajTablePut(mia->CacheByIdentifier,
1191 (void *) Pidentifier,
1192 (void *) mi);
1193
1194 if (temp)
1195 {
1196 ajWarn("metainformationCacheInit got more than one "
1197 "Ensembl Meta-Information with identifier %u.\n",
1198 temp->Identifier);
1199
1200 ensMetainformationDel(&temp);
1201 }
1202
1203 /* Insert into the key cache. */
1204
1205 list = (AjPList) ajTableFetchmodV(mia->CacheByKey,
1206 (const void *) mi->Key);
1207
1208 if (!list)
1209 {
1210 list = ajListNew();
1211
1212 ajTablePut(mia->CacheByKey,
1213 (void *) ajStrNewS(mi->Key),
1214 (void *) list);
1215 }
1216
1217 ajListPushAppend(list, (void *) ensMetainformationNewRef(mi));
1218 }
1219
1220 ajListFree(&mis);
1221
1222 ajStrDel(&statement);
1223
1224 return ajTrue;
1225 }
1226
1227
1228
1229
1230 /* @section constructors ******************************************************
1231 **
1232 ** All constructors return a new Ensembl Meta-Information Adaptor by pointer.
1233 ** It is the responsibility of the user to first destroy any previous
1234 ** Meta-Information Adaptor. The target pointer does not need to be initialised
1235 ** to NULL, but it is good programming practice to do so anyway.
1236 **
1237 ** @fdata [EnsPMetainformationadaptor]
1238 **
1239 ** @nam3rule New Constructor
1240 **
1241 ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
1242 **
1243 ** @valrule * [EnsPMetainformationadaptor]
1244 ** Ensembl Meta-Information Adaptor or NULL
1245 **
1246 ** @fcategory new
1247 ******************************************************************************/
1248
1249
1250
1251
1252 /* @func ensMetainformationadaptorNew *****************************************
1253 **
1254 ** Default constructor for an Ensembl Meta-Information Adaptor.
1255 **
1256 ** Ensembl Object Adaptors are singleton objects in the sense that a single
1257 ** instance of an Ensembl Object Adaptor connected to a particular database is
1258 ** sufficient to instantiate any number of Ensembl Objects from the database.
1259 ** Each Ensembl Object will have a weak reference to the Object Adaptor that
1260 ** instantiated it. Therefore, Ensembl Object Adaptors should not be
1261 ** instantiated directly, but rather obtained from the Ensembl Registry,
1262 ** which will in turn call this function if neccessary.
1263 **
1264 ** @see ensRegistryGetDatabaseadaptor
1265 ** @see ensRegistryGetMetainformationadaptor
1266 **
1267 ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
1268 **
1269 ** @return [EnsPMetainformationadaptor]
1270 ** Ensembl Meta-Information Adaptor or NULL
1271 **
1272 ** @release 6.2.0
1273 ** @@
1274 ******************************************************************************/
1275
ensMetainformationadaptorNew(EnsPDatabaseadaptor dba)1276 EnsPMetainformationadaptor ensMetainformationadaptorNew(
1277 EnsPDatabaseadaptor dba)
1278 {
1279 EnsPMetainformationadaptor mia = NULL;
1280
1281 if (ajDebugTest("ensMetainformationadaptorNew"))
1282 ajDebug("ensMetainformationadaptorNew\n"
1283 " dba %p\n",
1284 dba);
1285
1286 if (!dba)
1287 return NULL;
1288
1289 AJNEW0(mia);
1290
1291 mia->Adaptor = dba;
1292
1293 mia->CacheByIdentifier = ajTableuintNew(0U);
1294
1295 ajTableSetDestroyvalue(
1296 mia->CacheByIdentifier,
1297 (void (*)(void **)) &ensMetainformationDel);
1298
1299 mia->CacheByKey = ajTablestrNew(0U);
1300
1301 ajTableSetDestroyvalue(
1302 mia->CacheByKey,
1303 (void (*)(void **)) &metainformationadaptorCacheByKeyValdel);
1304
1305 metainformationadaptorCacheInit(mia);
1306
1307 return mia;
1308 }
1309
1310
1311
1312
1313 /* @funcstatic metainformationadaptorCacheByKeyValdel *************************
1314 **
1315 ** An ajTableSetDestroyvalue "valdel" function to clear AJAX Table value data.
1316 ** This function removes and deletes Ensembl Meta-Information objects
1317 ** from an AJAX List object, before deleting the AJAX List object.
1318 **
1319 ** @param [d] Pvalue [void**] AJAX List address
1320 ** @see ajTableSetDestroyvalue
1321 **
1322 ** @return [void]
1323 **
1324 ** @release 6.3.0
1325 ** @@
1326 ******************************************************************************/
1327
metainformationadaptorCacheByKeyValdel(void ** Pvalue)1328 static void metainformationadaptorCacheByKeyValdel(void **Pvalue)
1329 {
1330 EnsPMetainformation mi = NULL;
1331
1332 if (!Pvalue)
1333 return;
1334
1335 if (!*Pvalue)
1336 return;
1337
1338 while (ajListPop(*((AjPList *) Pvalue), (void **) &mi))
1339 ensMetainformationDel(&mi);
1340
1341 ajListFree((AjPList *) Pvalue);
1342
1343 return;
1344 }
1345
1346
1347
1348
1349 /* @section destructors *******************************************************
1350 **
1351 ** Destruction destroys all internal data structures and frees the memory
1352 ** allocated for an Ensembl Meta-Information Adaptor object.
1353 **
1354 ** @fdata [EnsPMetainformationadaptor]
1355 **
1356 ** @nam3rule Del Destroy (free) an Ensembl Meta-Information Adaptor
1357 **
1358 ** @argrule * Pmia [EnsPMetainformationadaptor*]
1359 ** Ensembl Meta-Information Adaptor address
1360 **
1361 ** @valrule * [void]
1362 **
1363 ** @fcategory delete
1364 ******************************************************************************/
1365
1366
1367
1368
1369 /* @func ensMetainformationadaptorDel *****************************************
1370 **
1371 ** Default destructor for an Ensembl Meta-Information Adaptor.
1372 **
1373 ** This function also clears the internal caches.
1374 **
1375 ** Ensembl Object Adaptors are singleton objects that are registered in the
1376 ** Ensembl Registry and weakly referenced by Ensembl Objects that have been
1377 ** instantiated by it. Therefore, Ensembl Object Adaptors should never be
1378 ** destroyed directly. Upon exit, the Ensembl Registry will call this function
1379 ** if required.
1380 **
1381 ** @param [d] Pmia [EnsPMetainformationadaptor*]
1382 ** Ensembl Meta-Information Adaptor address
1383 **
1384 ** @return [void]
1385 **
1386 ** @release 6.2.0
1387 ** @@
1388 ******************************************************************************/
1389
ensMetainformationadaptorDel(EnsPMetainformationadaptor * Pmia)1390 void ensMetainformationadaptorDel(EnsPMetainformationadaptor *Pmia)
1391 {
1392 EnsPMetainformationadaptor pthis = NULL;
1393
1394 if (!Pmia)
1395 return;
1396
1397 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
1398 if (ajDebugTest("ensMetainformationadaptorDel"))
1399 ajDebug("ensMetainformationadaptorDel\n"
1400 " *Pmia %p\n",
1401 *Pmia);
1402 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
1403
1404 if (!(pthis = *Pmia))
1405 return;
1406
1407 ajTableDel(&pthis->CacheByIdentifier);
1408 ajTableDel(&pthis->CacheByKey);
1409
1410 ajMemFree((void **) Pmia);
1411
1412 return;
1413 }
1414
1415
1416
1417
1418 /* @section member retrieval **************************************************
1419 **
1420 ** Functions for returning members of an
1421 ** Ensembl Meta-Information Adaptor object.
1422 **
1423 ** @fdata [EnsPMetainformationadaptor]
1424 **
1425 ** @nam3rule Get Return Ensembl Meta-Information Adaptor attribute(s)
1426 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
1427 **
1428 ** @argrule * mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1429 **
1430 ** @valrule Databaseadaptor [EnsPDatabaseadaptor]
1431 ** Ensembl Database Adaptor or NULL
1432 **
1433 ** @fcategory use
1434 ******************************************************************************/
1435
1436
1437
1438
1439 /* @func ensMetainformationadaptorGetDatabaseadaptor **************************
1440 **
1441 ** Get the Ensembl Database Adaptor of an Ensembl Meta-Information Adaptor.
1442 **
1443 ** @param [u] mia [EnsPMetainformationadaptor]
1444 ** Ensembl Meta-Information Adaptor
1445 **
1446 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
1447 **
1448 ** @release 6.5.0
1449 ** @@
1450 ******************************************************************************/
1451
ensMetainformationadaptorGetDatabaseadaptor(EnsPMetainformationadaptor mia)1452 EnsPDatabaseadaptor ensMetainformationadaptorGetDatabaseadaptor(
1453 EnsPMetainformationadaptor mia)
1454 {
1455 return (mia) ? mia->Adaptor : NULL;
1456 }
1457
1458
1459
1460
1461 /* @section canonical object retrieval ****************************************
1462 **
1463 ** Functions for fetching Ensembl Meta-Information objects from an
1464 ** Ensembl SQL database.
1465 **
1466 ** @fdata [EnsPMetainformationadaptor]
1467 **
1468 ** @nam3rule Fetch Fetch Ensembl Meta-Information object(s)
1469 ** @nam4rule All Fetch all Ensembl Meta-Information objects
1470 ** @nam4rule Allby Fetch all Ensembl Meta-Information objects matching a
1471 ** criterion
1472 ** @nam5rule Key Fetch all by an Ensembl Meta-Information key
1473 ** @nam4rule By Fetch one Ensembl Meta-Information object matching a criterion
1474 ** @nam5rule Identifier Fetch by an SQL database internal identifier
1475 **
1476 ** @argrule * mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1477 ** @argrule All mis [AjPList] AJAX List of Ensembl Meta-Information objects
1478 ** @argrule AllbyKey key [const AjPStr] Key
1479 ** @argrule Allby mis [AjPList] AJAX List of Ensembl Meta-Information objects
1480 ** @argrule ByIdentifier identifier [ajuint] SQL database-internal identifier
1481 ** @argrule ByIdentifier Pmi [EnsPMetainformation*] Ensembl Meta-Information
1482 ** address
1483 **
1484 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1485 **
1486 ** @fcategory use
1487 ******************************************************************************/
1488
1489
1490
1491
1492 /* @func ensMetainformationadaptorFetchAllbyKey *******************************
1493 **
1494 ** Fetch all Ensembl Meta-Information objects by a key.
1495 **
1496 ** This function returns only non species-specific or species-specific
1497 ** Meta-Information objects, which species identifier matches the one of the
1498 ** underlying Ensembl Database Adaptor.
1499 **
1500 ** The caller is responsible for deleting the Ensembl Meta-Information objects
1501 ** before deleting the AJAX List.
1502 **
1503 ** @cc Bio::EnsEMBL::DBSQL::BaseMetaContainer::list_value_by_key
1504 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1505 ** @param [r] key [const AjPStr] Key
1506 ** @param [u] mis [AjPList] AJAX List of Ensembl Meta-Information objects
1507 **
1508 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1509 **
1510 ** @release 6.4.0
1511 ** @@
1512 ******************************************************************************/
1513
ensMetainformationadaptorFetchAllbyKey(EnsPMetainformationadaptor mia,const AjPStr key,AjPList mis)1514 AjBool ensMetainformationadaptorFetchAllbyKey(
1515 EnsPMetainformationadaptor mia,
1516 const AjPStr key,
1517 AjPList mis)
1518 {
1519 ajuint identifer = 0U;
1520
1521 AjBool specieskey = AJFALSE;
1522
1523 AjIList iter = NULL;
1524 AjPList list = NULL;
1525
1526 EnsPMetainformation mi = NULL;
1527
1528 if (!mia)
1529 return ajFalse;
1530
1531 if (!key)
1532 return ajFalse;
1533
1534 if (!mis)
1535 return ajFalse;
1536
1537 list = (AjPList) ajTableFetchmodV(mia->CacheByKey, (const void *) key);
1538
1539 if (!list)
1540 return ajTrue;
1541
1542 identifer = ensDatabaseadaptorGetIdentifier(
1543 ensMetainformationadaptorGetDatabaseadaptor(mia));
1544
1545 specieskey = metainformationkeyIsSpecieskey(key);
1546
1547 iter = ajListIterNew(list);
1548
1549 while (!ajListIterDone(iter))
1550 {
1551 mi = (EnsPMetainformation) ajListIterGet(iter);
1552
1553 if (!mi)
1554 continue;
1555
1556 /*
1557 ** For species-specific Ensembl Meta-Information keys, the species
1558 ** identifier in the Ensembl Meta-Information object and in the
1559 ** Ensembl Database Adaptor have to match.
1560 */
1561
1562 if ((specieskey == ajTrue) && (mi->Species != identifer))
1563 continue;
1564
1565 ajListPushAppend(mis, (void **) ensMetainformationNewRef(mi));
1566 }
1567
1568 ajListIterDel(&iter);
1569
1570 return ajTrue;
1571 }
1572
1573
1574
1575
1576 /* @section accessory object retrieval ****************************************
1577 **
1578 ** Functions for retrieving objects releated to Ensembl Meta-Information objects
1579 ** from an Ensembl SQL database.
1580 **
1581 ** @fdata [EnsPMetainformationadaptor]
1582 **
1583 ** @nam3rule Retrieve Retrieve Ensembl Meta-Information-releated object(s)
1584 ** @nam4rule All Retrieve all Ensembl Meta-Information-releated objects
1585 ** @nam5rule Speciesclassifications Retrieve the species classification
1586 ** @nam5rule Speciesnames Retrieve all species names of multi-species databases
1587 ** @nam4rule Genebuildversion Retrieve the genebuild version
1588 ** @nam4rule Species Retrieve species information
1589 ** @nam5rule Commonname Retrieve the common name
1590 ** @nam5rule Division Retrieve the species division
1591 ** @nam5rule Productionname Retrieve the prodiuction name
1592 ** @nam5rule Scientificname Retrieve the scientific name
1593 ** @nam5rule Shortname Retrieve the short name
1594 ** @nam4rule Schemaversion Retrieve the Ensembl database schema version
1595 ** @nam4rule Taxonomyidentifier Retrieve the NCBI Taxonomy identifier
1596 ** @nam4rule Value Retrieve an Ensembl Meta-Information value
1597 **
1598 ** @argrule * mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1599 ** @argrule AllSpeciesclassifications values [AjPList]
1600 ** AJAX List of AJAX String (taxonomy name) objects
1601 ** @argrule AllSpeciesnames values [AjPList]
1602 ** AJAX List of AJAX String (species name) objects
1603 ** @argrule Genebuildversion Pvalue [AjPStr*] Value address
1604 ** @argrule Schemaversion Pvalue [AjPStr*] Value address
1605 ** @argrule Species Pvalue [AjPStr*] Value address
1606 ** @argrule Taxonomyidentifier Pvalue [AjPStr*] Value address
1607 ** @argrule Value key [const AjPStr] Key
1608 ** @argrule Value Pvalue [AjPStr*] Value address
1609 **
1610 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1611 **
1612 ** @fcategory use
1613 ******************************************************************************/
1614
1615
1616
1617
1618 /* @func ensMetainformationadaptorRetrieveAllSpeciesclassifications ***********
1619 **
1620 ** Retrieve the species classification.
1621 **
1622 ** The caller is responsible for deleting the AJAX String objects
1623 ** before deleting the AJAX List.
1624 **
1625 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer::get_classification
1626 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1627 ** @param [u] values [AjPList] AJAX List of AJAX String (taxonomy names)
1628 **
1629 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1630 **
1631 ** @release 6.5.0
1632 ** @@
1633 ******************************************************************************/
1634
ensMetainformationadaptorRetrieveAllSpeciesclassifications(EnsPMetainformationadaptor mia,AjPList values)1635 AjBool ensMetainformationadaptorRetrieveAllSpeciesclassifications(
1636 EnsPMetainformationadaptor mia,
1637 AjPList values)
1638 {
1639 AjIList iter = NULL;
1640 AjPList list = NULL;
1641
1642 AjPStr key = NULL;
1643 AjPStr value = NULL;
1644
1645 EnsPMetainformation mi = NULL;
1646
1647 if (!mia)
1648 return ajFalse;
1649
1650 if (!values)
1651 return ajFalse;
1652
1653 key = ajStrNewC("species.classication");
1654
1655 list = (AjPList) ajTableFetchmodV(mia->CacheByKey, (const void *) key);
1656
1657 iter = ajListIterNew(list);
1658
1659 while (!ajListIterDone(iter))
1660 {
1661 mi = (EnsPMetainformation) ajListIterGet(iter);
1662
1663 ajListstrPushAppend(values, ajStrNewS(mi->Value));
1664 }
1665
1666 ajListIterDel(&iter);
1667
1668 ajStrDel(&key);
1669
1670 /*
1671 ** Remove the last taxonomy level e.g. "Homo sapiens" or
1672 ** "Canis lupus familiaris".
1673 */
1674
1675 ajListstrPop(values, &value);
1676 ajStrDel(&value);
1677
1678 return ajTrue;
1679 }
1680
1681
1682
1683
1684 /* @func ensMetainformationadaptorRetrieveAllSpeciesnames *********************
1685 **
1686 ** Retrieve all species names of multi-species databases.
1687 **
1688 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1689 ** @param [u] values [AjPList] AJAX List of AJAX String (species name) objects
1690 **
1691 ** @return [AjBool] ajTrue if the Meta Information exists, ajFalse otherwise
1692 **
1693 ** @release 6.4.0
1694 ** @@
1695 ******************************************************************************/
1696
ensMetainformationadaptorRetrieveAllSpeciesnames(EnsPMetainformationadaptor mia,AjPList values)1697 AjBool ensMetainformationadaptorRetrieveAllSpeciesnames(
1698 EnsPMetainformationadaptor mia,
1699 AjPList values)
1700 {
1701 AjIList iter = NULL;
1702 AjPList list = NULL;
1703
1704 AjPStr key = NULL;
1705
1706 EnsPMetainformation mi = NULL;
1707
1708 if (!mia)
1709 return ajFalse;
1710
1711 if (!values)
1712 return ajFalse;
1713
1714 key = ajStrNewC("species.db_name");
1715
1716 list = (AjPList) ajTableFetchmodV(mia->CacheByKey, (const void *) key);
1717
1718 iter = ajListIterNew(list);
1719
1720 while (!ajListIterDone(iter))
1721 {
1722 mi = (EnsPMetainformation) ajListIterGet(iter);
1723
1724 ajListstrPushAppend(values, ajStrNewS(mi->Value));
1725 }
1726
1727 ajListIterDel(&iter);
1728
1729 ajStrDel(&key);
1730
1731 return ajTrue;
1732 }
1733
1734
1735
1736
1737 /* @func ensMetainformationadaptorRetrieveGenebuildversion ********************
1738 **
1739 ** Retrieve the genebuild version.
1740 **
1741 ** The caller is responsible for deleting the AJAX String.
1742 **
1743 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer::get_genebuild
1744 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1745 ** @param [wP] Pvalue [AjPStr*] Value address
1746 **
1747 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1748 **
1749 ** @release 6.4.0
1750 ** @@
1751 ******************************************************************************/
1752
ensMetainformationadaptorRetrieveGenebuildversion(EnsPMetainformationadaptor mia,AjPStr * Pvalue)1753 AjBool ensMetainformationadaptorRetrieveGenebuildversion(
1754 EnsPMetainformationadaptor mia,
1755 AjPStr *Pvalue)
1756 {
1757 ajint errors = 0;
1758
1759 AjPStr key = NULL;
1760
1761 if (!mia)
1762 return ajFalse;
1763
1764 if (!Pvalue)
1765 return ajFalse;
1766
1767 if (*Pvalue)
1768 ajStrAssignClear(Pvalue);
1769 else
1770 *Pvalue = ajStrNew();
1771
1772 key = ajStrNewC("genebuild.start_date");
1773
1774 if (!ensMetainformationadaptorRetrieveValue(mia, key, Pvalue))
1775 errors++;
1776
1777 ajStrDel(&key);
1778
1779 if (errors)
1780 return ajFalse;
1781
1782 return ajTrue;
1783 }
1784
1785
1786
1787
1788 /* @func ensMetainformationadaptorRetrieveSchemaversion ***********************
1789 **
1790 ** Retrieve the Ensembl database schema version.
1791 **
1792 ** The caller is responsible for deleting the AJAX String.
1793 **
1794 ** @cc Bio::EnsEMBL::DBSQL::BaseMetaContainer::get_schema_version
1795 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1796 ** @param [wP] Pvalue [AjPStr*] Value String address
1797 **
1798 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1799 **
1800 ** @release 6.4.0
1801 ** @@
1802 ******************************************************************************/
1803
ensMetainformationadaptorRetrieveSchemaversion(EnsPMetainformationadaptor mia,AjPStr * Pvalue)1804 AjBool ensMetainformationadaptorRetrieveSchemaversion(
1805 EnsPMetainformationadaptor mia,
1806 AjPStr *Pvalue)
1807 {
1808 ajint errors = 0;
1809
1810 AjPStr key = NULL;
1811
1812 if (!mia)
1813 return ajFalse;
1814
1815 if (!Pvalue)
1816 return ajFalse;
1817
1818 if (*Pvalue)
1819 ajStrAssignClear(Pvalue);
1820 else
1821 *Pvalue = ajStrNew();
1822
1823 key = ajStrNewC("schema_version");
1824
1825 if (!ensMetainformationadaptorRetrieveValue(mia, key, Pvalue))
1826 errors++;
1827
1828 ajStrDel(&key);
1829
1830 if (errors)
1831 return ajFalse;
1832
1833 return ajTrue;
1834 }
1835
1836
1837
1838
1839 /* @func ensMetainformationadaptorRetrieveSpeciesCommonname *******************
1840 **
1841 ** Retrieve the common name for the species.
1842 **
1843 ** The caller is responsible for deleting the AJAX String.
1844 **
1845 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer::get_common_name
1846 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1847 ** @param [wP] Pvalue [AjPStr*] Value address
1848 **
1849 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1850 **
1851 ** @release 6.4.0
1852 ** @@
1853 ******************************************************************************/
1854
ensMetainformationadaptorRetrieveSpeciesCommonname(EnsPMetainformationadaptor mia,AjPStr * Pvalue)1855 AjBool ensMetainformationadaptorRetrieveSpeciesCommonname(
1856 EnsPMetainformationadaptor mia,
1857 AjPStr *Pvalue)
1858 {
1859 ajint errors = 0;
1860
1861 AjPStr key = NULL;
1862
1863 if (!mia)
1864 return ajFalse;
1865
1866 if (!Pvalue)
1867 return ajFalse;
1868
1869 if (*Pvalue)
1870 ajStrAssignClear(Pvalue);
1871 else
1872 *Pvalue = ajStrNew();
1873
1874 key = ajStrNewC("species.common_name");
1875
1876 if (!ensMetainformationadaptorRetrieveValue(mia, key, Pvalue))
1877 errors++;
1878
1879 ajStrDel(&key);
1880
1881 if (errors)
1882 return ajFalse;
1883
1884 return ajTrue;
1885 }
1886
1887
1888
1889
1890 /* @func ensMetainformationadaptorRetrieveSpeciesDivision *********************
1891 **
1892 ** Retrieve the division for the species.
1893 **
1894 ** The caller is responsible for deleting the AJAX String.
1895 **
1896 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer::get_division
1897 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1898 ** @param [wP] Pvalue [AjPStr*] Value address
1899 **
1900 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1901 **
1902 ** @release 6.5.0
1903 ** @@
1904 ******************************************************************************/
1905
ensMetainformationadaptorRetrieveSpeciesDivision(EnsPMetainformationadaptor mia,AjPStr * Pvalue)1906 AjBool ensMetainformationadaptorRetrieveSpeciesDivision(
1907 EnsPMetainformationadaptor mia,
1908 AjPStr *Pvalue)
1909 {
1910 ajint errors = 0;
1911
1912 AjPStr key = NULL;
1913
1914 if (!mia)
1915 return ajFalse;
1916
1917 if (!Pvalue)
1918 return ajFalse;
1919
1920 if (*Pvalue)
1921 ajStrAssignClear(Pvalue);
1922 else
1923 *Pvalue = ajStrNew();
1924
1925 key = ajStrNewC("species.division");
1926
1927 if (!ensMetainformationadaptorRetrieveValue(mia, key, Pvalue))
1928 errors++;
1929
1930 ajStrDel(&key);
1931
1932 if (errors)
1933 return ajFalse;
1934
1935 return ajTrue;
1936 }
1937
1938
1939
1940
1941 /* @func ensMetainformationadaptorRetrieveSpeciesProductionname ***************
1942 **
1943 ** Retrieve the production name for the species.
1944 **
1945 ** The caller is responsible for deleting the AJAX String.
1946 **
1947 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer::get_production_name
1948 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
1949 ** @param [wP] Pvalue [AjPStr*] Value address
1950 **
1951 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1952 **
1953 ** @release 6.4.0
1954 ** @@
1955 ******************************************************************************/
1956
ensMetainformationadaptorRetrieveSpeciesProductionname(EnsPMetainformationadaptor mia,AjPStr * Pvalue)1957 AjBool ensMetainformationadaptorRetrieveSpeciesProductionname(
1958 EnsPMetainformationadaptor mia,
1959 AjPStr *Pvalue)
1960 {
1961 ajint errors = 0;
1962
1963 AjPStr key = NULL;
1964
1965 if (!mia)
1966 return ajFalse;
1967
1968 if (!Pvalue)
1969 return ajFalse;
1970
1971 if (*Pvalue)
1972 ajStrAssignClear(Pvalue);
1973 else
1974 *Pvalue = ajStrNew();
1975
1976 key = ajStrNewC("species.production_name");
1977
1978 if (!ensMetainformationadaptorRetrieveValue(mia, key, Pvalue))
1979 errors++;
1980
1981 ajStrDel(&key);
1982
1983 if (errors)
1984 return ajFalse;
1985
1986 return ajTrue;
1987 }
1988
1989
1990
1991
1992 /* @func ensMetainformationadaptorRetrieveSpeciesScientificname ***************
1993 **
1994 ** Retrieve the scientific name for the species.
1995 **
1996 ** The caller is responsible for deleting the AJAX String.
1997 **
1998 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer::get_scientific_name
1999 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
2000 ** @param [wP] Pvalue [AjPStr*] Value address
2001 **
2002 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2003 **
2004 ** @release 6.4.0
2005 ** @@
2006 ******************************************************************************/
2007
ensMetainformationadaptorRetrieveSpeciesScientificname(EnsPMetainformationadaptor mia,AjPStr * Pvalue)2008 AjBool ensMetainformationadaptorRetrieveSpeciesScientificname(
2009 EnsPMetainformationadaptor mia,
2010 AjPStr *Pvalue)
2011 {
2012 ajint errors = 0;
2013
2014 AjPStr key = NULL;
2015
2016 if (!mia)
2017 return ajFalse;
2018
2019 if (!Pvalue)
2020 return ajFalse;
2021
2022 if (*Pvalue)
2023 ajStrAssignClear(Pvalue);
2024 else
2025 *Pvalue = ajStrNew();
2026
2027 key = ajStrNewC("species.scientific_name");
2028
2029 if (!ensMetainformationadaptorRetrieveValue(mia, key, Pvalue))
2030 errors++;
2031
2032 ajStrDel(&key);
2033
2034 if (errors)
2035 return ajFalse;
2036
2037 return ajTrue;
2038 }
2039
2040
2041
2042
2043 /* @func ensMetainformationadaptorRetrieveSpeciesShortname ********************
2044 **
2045 ** Retrieve the short name for the species.
2046 **
2047 ** The caller is responsible for deleting the AJAX String.
2048 **
2049 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer::get_short_name
2050 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
2051 ** @param [wP] Pvalue [AjPStr*] Value address
2052 **
2053 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2054 **
2055 ** @release 6.4.0
2056 ** @@
2057 ******************************************************************************/
2058
ensMetainformationadaptorRetrieveSpeciesShortname(EnsPMetainformationadaptor mia,AjPStr * Pvalue)2059 AjBool ensMetainformationadaptorRetrieveSpeciesShortname(
2060 EnsPMetainformationadaptor mia,
2061 AjPStr *Pvalue)
2062 {
2063 ajint errors = 0;
2064
2065 AjPStr key = NULL;
2066
2067 if (!mia)
2068 return ajFalse;
2069
2070 if (!Pvalue)
2071 return ajFalse;
2072
2073 if (*Pvalue)
2074 ajStrAssignClear(Pvalue);
2075 else
2076 *Pvalue = ajStrNew();
2077
2078 key = ajStrNewC("species.short_name");
2079
2080 if (!ensMetainformationadaptorRetrieveValue(mia, key, Pvalue))
2081 errors++;
2082
2083 ajStrDel(&key);
2084
2085 if (errors)
2086 return ajFalse;
2087
2088 return ajTrue;
2089 }
2090
2091
2092
2093
2094 /* @func ensMetainformationadaptorRetrieveTaxonomyidentifier ******************
2095 **
2096 ** Retrieve the NCBI Taxonomy identifier.
2097 **
2098 ** The caller is responsible for deleting the AJAX String.
2099 **
2100 ** @cc Bio::EnsEMBL::DBSQL::MetaContainer::get_taxonomy_id
2101 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
2102 ** @param [wP] Pvalue [AjPStr*] Value String address
2103 **
2104 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2105 **
2106 ** @release 6.4.0
2107 ** @@
2108 ******************************************************************************/
2109
ensMetainformationadaptorRetrieveTaxonomyidentifier(EnsPMetainformationadaptor mia,AjPStr * Pvalue)2110 AjBool ensMetainformationadaptorRetrieveTaxonomyidentifier(
2111 EnsPMetainformationadaptor mia,
2112 AjPStr *Pvalue)
2113 {
2114 ajint errors = 0;
2115
2116 AjPStr key = NULL;
2117
2118 if (!mia)
2119 return ajFalse;
2120
2121 if (!Pvalue)
2122 return ajFalse;
2123
2124 if (*Pvalue)
2125 ajStrAssignClear(Pvalue);
2126 else
2127 *Pvalue = ajStrNew();
2128
2129 key = ajStrNewC("species.taxonomy_id");
2130
2131 if (!ensMetainformationadaptorRetrieveValue(mia, key, Pvalue))
2132 errors++;
2133
2134 ajStrDel(&key);
2135
2136 if (errors)
2137 return ajFalse;
2138
2139 return ajTrue;
2140 }
2141
2142
2143
2144
2145 /* @func ensMetainformationadaptorRetrieveValue *******************************
2146 **
2147 ** Retrieve a single Ensembl Meta-Information value by a key.
2148 **
2149 ** The function warns in case there is more than one Meta-Information value to
2150 ** a particular key and will return the first value returned by the database
2151 ** engine.
2152 **
2153 ** The caller is responsible for deleting the AJAX String.
2154 **
2155 ** @cc Bio::EnsEMBL::DBSQL::BaseMetaContainer::single_value_by_key
2156 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
2157 ** @param [r] key [const AjPStr] Key
2158 ** @param [wP] Pvalue [AjPStr*] Value address
2159 **
2160 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2161 **
2162 ** @release 6.4.0
2163 ** @@
2164 ******************************************************************************/
2165
ensMetainformationadaptorRetrieveValue(EnsPMetainformationadaptor mia,const AjPStr key,AjPStr * Pvalue)2166 AjBool ensMetainformationadaptorRetrieveValue(
2167 EnsPMetainformationadaptor mia,
2168 const AjPStr key,
2169 AjPStr *Pvalue)
2170 {
2171 ajint errors = 0;
2172
2173 AjPList mis = NULL;
2174
2175 EnsPMetainformation mi = NULL;
2176
2177 if (!mia)
2178 return ajFalse;
2179
2180 if (!key)
2181 return ajFalse;
2182
2183 if (!Pvalue)
2184 return ajFalse;
2185
2186 if (*Pvalue)
2187 ajStrAssignClear(Pvalue);
2188 else
2189 *Pvalue = ajStrNew();
2190
2191 mis = ajListNew();
2192
2193 ensMetainformationadaptorFetchAllbyKey(mia, key, mis);
2194
2195 if (ajListGetLength(mis) > 1)
2196 {
2197 errors++;
2198
2199 ajWarn("ensMetainformationadaptorRetrieveValue matched %d "
2200 "'meta.meta_value' rows via 'meta.meta_key' '%S', "
2201 "but only the first value was returned.\n",
2202 ajListGetLength(mis), key);
2203 }
2204
2205 ajListPeekFirst(mis, (void **) &mi);
2206
2207 ajStrAssignS(Pvalue, ensMetainformationGetValue(mi));
2208
2209 while (ajListPop(mis, (void **) &mi))
2210 ensMetainformationDel(&mi);
2211
2212 ajListFree(&mis);
2213
2214 if (errors)
2215 return ajFalse;
2216
2217 return ajTrue;
2218 }
2219
2220
2221
2222
2223 /* @section check *************************************************************
2224 **
2225 ** Check Ensembl Meta-Information objects.
2226 **
2227 ** @fdata [EnsPMetainformationadaptor]
2228 **
2229 ** @nam3rule Check Check Ensembl Meta-Information objects
2230 ** @nam4rule Exists Check whether an Ensembl Meta-Information object exists
2231 **
2232 ** @argrule * mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
2233 ** @argrule Exists key [const AjPStr] Key string
2234 ** @argrule Exists value [const AjPStr] Value string
2235 ** @argrule Exists Presult [AjBool*] Result
2236 **
2237 ** @valrule * [AjBool] ajTrue if the Meta-Information exists, ajFalse otherwise
2238 **
2239 ** @fcategory use
2240 ******************************************************************************/
2241
2242
2243
2244
2245 /* @func ensMetainformationadaptorCheckExists *********************************
2246 **
2247 ** Check whether an Ensembl Meta-Information object with a particular
2248 ** key and value pair has already been stored in the database.
2249 **
2250 ** @cc Bio::EnsEMBL::DBSQL::BaseMetaContainer::key_value_exists
2251 ** @param [u] mia [EnsPMetainformationadaptor] Ensembl Meta-Information Adaptor
2252 ** @param [r] key [const AjPStr] Key
2253 ** @param [r] value [const AjPStr] Value
2254 ** @param [u] Presult [AjBool*] Result
2255 **
2256 ** @return [AjBool] ajTrue if the Meta-Information exists, ajFalse otherwise
2257 **
2258 ** @release 6.4.0
2259 ** @@
2260 ******************************************************************************/
2261
ensMetainformationadaptorCheckExists(EnsPMetainformationadaptor mia,const AjPStr key,const AjPStr value,AjBool * Presult)2262 AjBool ensMetainformationadaptorCheckExists(
2263 EnsPMetainformationadaptor mia,
2264 const AjPStr key,
2265 const AjPStr value,
2266 AjBool *Presult)
2267 {
2268 ajuint identifier = 0U;
2269
2270 AjBool specieskey = AJFALSE;
2271
2272 AjIList iter = NULL;
2273 AjPList list = NULL;
2274
2275 EnsPMetainformation mi = NULL;
2276
2277 if (!mia)
2278 return ajFalse;
2279
2280 if (!key)
2281 return ajFalse;
2282
2283 if (!value)
2284 return ajFalse;
2285
2286 list = (AjPList) ajTableFetchmodV(mia->CacheByKey, (const void *) key);
2287
2288 if (!list)
2289 {
2290 *Presult = ajFalse;
2291
2292 return ajTrue;
2293 }
2294
2295 identifier = ensDatabaseadaptorGetIdentifier(
2296 ensMetainformationadaptorGetDatabaseadaptor(mia));
2297
2298 specieskey = metainformationkeyIsSpecieskey(key);
2299
2300 iter = ajListIterNew(list);
2301
2302 while (!ajListIterDone(iter))
2303 {
2304 mi = (EnsPMetainformation) ajListIterGet(iter);
2305
2306 if (!mi)
2307 continue;
2308
2309 /*
2310 ** For species-specific Ensembl Meta-Information keys the species
2311 ** identifier in the Ensembl Meta-Information object and in the
2312 ** Ensembl Database Adaptor have to match.
2313 */
2314
2315 if ((specieskey == ajTrue) && (mi->Species != identifier))
2316 continue;
2317
2318 if (ajStrMatchS(mi->Value, value))
2319 {
2320 *Presult = ajTrue;
2321
2322 break;
2323 }
2324 }
2325
2326 ajListIterDel(&iter);
2327
2328 return ajTrue;
2329 }
2330