1 /* @source ensmiscellaneous ***************************************************
2 **
3 ** Ensembl Miscellaneous functions
4 **
5 ** @author Copyright (C) 1999 Ensembl Developers
6 ** @author Copyright (C) 2006 Michael K. Schuster
7 ** @version $Revision: 1.63 $
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 "ensmiscellaneous.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 miscellaneoussetadaptorKTablenames ****************************
65 **
66 ** Array of Ensembl Miscellaneous Set Adaptor SQL table names
67 **
68 ******************************************************************************/
69 
70 static const char *const miscellaneoussetadaptorKTablenames[] =
71 {
72     "misc_set",
73     (const char *) NULL
74 };
75 
76 
77 
78 
79 /* @conststatic miscellaneoussetadaptorKColumnnames ***************************
80 **
81 ** Array of Ensembl Miscellaneous Set Adaptor SQL column names
82 **
83 ******************************************************************************/
84 
85 static const char *const miscellaneoussetadaptorKColumnnames[] =
86 {
87     "misc_set.misc_set_id",
88     "misc_set.code",
89     "misc_set.name",
90     "misc_set.description",
91     "misc_set.max_length",
92     (const char *) NULL
93 };
94 
95 
96 
97 
98 /* @conststatic miscellaneousfeatureadaptorKTablenames ************************
99 **
100 ** Array of Ensembl Miscellaneous Feature Adaptor SQL table names
101 **
102 ******************************************************************************/
103 
104 static const char *const miscellaneousfeatureadaptorKTablenames[] =
105 {
106     "misc_feature",
107     "misc_feature_misc_set",
108     "misc_attrib",
109     (const char *) NULL
110 };
111 
112 
113 
114 
115 /* @conststatic miscellaneousfeatureadaptorKColumnnames ***********************
116 **
117 ** Array of Ensembl Miscellaneous Feature Adaptor SQL column names
118 **
119 ******************************************************************************/
120 
121 static const char *const miscellaneousfeatureadaptorKColumnnames[] =
122 {
123     "misc_feature.misc_feature_id",
124     "misc_feature.seq_region_id",
125     "misc_feature.seq_region_start",
126     "misc_feature.seq_region_end",
127     "misc_feature.seq_region_strand",
128     "misc_attrib.attrib_type_id",
129     "misc_attrib.value",
130     "misc_feature_misc_set.misc_set_id",
131     (const char *) NULL
132 };
133 
134 
135 
136 
137 /* @conststatic miscellaneousfeatureadaptorKLeftjoins *************************
138 **
139 ** Array of Ensembl Miscellaneous Feature Adaptor SQL LEFT JOIN conditions
140 **
141 ******************************************************************************/
142 
143 static const EnsOBaseadaptorLeftjoin miscellaneousfeatureadaptorKLeftjoins[] =
144 {
145     {
146         "misc_feature_misc_set",
147         "misc_feature.misc_feature_id = misc_feature_misc_set.misc_feature_id"
148     },
149     {
150         "misc_attrib",
151         "misc_feature.misc_feature_id = misc_attrib.misc_feature_id"
152     },
153     {(const char *) NULL, (const char *) NULL}
154 };
155 
156 
157 
158 
159 /* @conststatic miscellaneousfeatureadaptorKFinalcondition ********************
160 **
161 ** Ensembl Miscellaneous Feature Adaptor SQL SELECT final condition
162 **
163 ******************************************************************************/
164 
165 static const char *miscellaneousfeatureadaptorKFinalcondition =
166     " ORDER BY misc_feature.misc_feature_id";
167 
168 
169 
170 
171 /* ========================================================================= */
172 /* =========================== private variables =========================== */
173 /* ========================================================================= */
174 
175 
176 
177 
178 /* ========================================================================= */
179 /* =========================== private functions =========================== */
180 /* ========================================================================= */
181 
182 static int listMiscellaneoussetCompareIdentifierAscending(
183     const void *item1,
184     const void *item2);
185 
186 static int listMiscellaneoussetCompareIdentifierDescending(
187     const void *item1,
188     const void *item2);
189 
190 static AjBool miscellaneoussetadaptorFetchAllbyStatement(
191     EnsPBaseadaptor ba,
192     const AjPStr statement,
193     EnsPAssemblymapper am,
194     EnsPSlice slice,
195     AjPList mss);
196 
197 static AjBool miscellaneoussetadaptorCacheInit(
198     EnsPMiscellaneoussetadaptor msa);
199 
200 static AjBool miscellaneoussetadaptorCacheInsert(
201     EnsPMiscellaneoussetadaptor msa,
202     EnsPMiscellaneousset *Pms);
203 
204 #if AJFALSE
205 static AjBool miscellaneoussetadaptorCacheRemove(
206     EnsPMiscellaneoussetadaptor msa,
207     EnsPMiscellaneousset ms);
208 #endif /* AJFALSE */
209 
210 static void miscellaneoussetadaptorFetchAll(const void *key,
211                                             void **Pvalue,
212                                             void *cl);
213 
214 static int listMiscellaneousfeatureCompareEndAscending(
215     const void *item1,
216     const void *item2);
217 
218 static int listMiscellaneousfeatureCompareEndDescending(
219     const void *item1,
220     const void *item2);
221 
222 static int listMiscellaneousfeatureCompareIdentifierAscending(
223     const void *item1,
224     const void *item2);
225 
226 static int listMiscellaneousfeatureCompareStartAscending(
227     const void *item1,
228     const void *item2);
229 
230 static int listMiscellaneousfeatureCompareStartDescending(
231     const void *item1,
232     const void *item2);
233 
234 static AjBool miscellaneousfeatureadaptorHasAttribute(AjPTable attributes,
235                                                       ajuint atid,
236                                                       const AjPStr value);
237 
238 static AjBool miscellaneousfeatureadaptorHasMiscellaneousset(AjPTable sets,
239                                                              ajuint msid);
240 
241 static AjBool miscellaneousfeatureadaptorFetchAllbyStatement(
242     EnsPBaseadaptor ba,
243     const AjPStr statement,
244     EnsPAssemblymapper am,
245     EnsPSlice slice,
246     AjPList mfs);
247 
248 
249 
250 
251 /* ========================================================================= */
252 /* ======================= All functions by section ======================== */
253 /* ========================================================================= */
254 
255 
256 
257 
258 /* @filesection ensmiscellaneous **********************************************
259 **
260 ** @nam1rule ens Function belongs to the Ensembl library
261 **
262 ******************************************************************************/
263 
264 
265 
266 
267 /* @datasection [EnsPMiscellaneousset] Ensembl Miscellaneous Set **************
268 **
269 ** @nam2rule Miscellaneousset Functions for manipulating
270 ** Ensembl Miscellaneous Set objects
271 **
272 ** @cc Bio::EnsEMBL::MiscSet
273 ** @cc CVS Revision: 1.10
274 ** @cc CVS Tag: branch-ensembl-68
275 **
276 ******************************************************************************/
277 
278 
279 
280 
281 /* @section constructors ******************************************************
282 **
283 ** All constructors return a new Ensembl Miscellaneous Set by pointer.
284 ** It is the responsibility of the user to first destroy any previous
285 ** Miscellaneous Set. The target pointer does not need to be initialised to
286 ** NULL, but it is good programming practice to do so anyway.
287 **
288 ** @fdata [EnsPMiscellaneousset]
289 **
290 ** @nam3rule New Constructor
291 ** @nam4rule Cpy Constructor with existing object
292 ** @nam4rule Ini Constructor with initial values
293 ** @nam4rule Ref Constructor by incrementing the reference counter
294 **
295 ** @argrule Cpy ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
296 ** @argrule Ini msa [EnsPMiscellaneoussetadaptor] Ensembl Miscellaneous
297 ** @argrule Ini identifier [ajuint] SQL database-internal identifier
298 ** @argrule Ini code [AjPStr] Code
299 ** @argrule Ini name [AjPStr] Name
300 ** @argrule Ini description [AjPStr] Description
301 ** @argrule Ini maxlen [ajuint] Maximum length
302 ** @argrule Ref ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
303 **
304 ** @valrule * [EnsPMiscellaneousset] Ensembl Miscellaneous Set or NULL
305 **
306 ** @fcategory new
307 ******************************************************************************/
308 
309 
310 
311 
312 /* @func ensMiscellaneoussetNewCpy ********************************************
313 **
314 ** Object-based constructor function, which returns an independent object.
315 **
316 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
317 **
318 ** @return [EnsPMiscellaneousset] Ensembl Miscellaneous Set or NULL
319 **
320 ** @release 6.4.0
321 ** @@
322 ******************************************************************************/
323 
ensMiscellaneoussetNewCpy(const EnsPMiscellaneousset ms)324 EnsPMiscellaneousset ensMiscellaneoussetNewCpy(
325     const EnsPMiscellaneousset ms)
326 {
327     EnsPMiscellaneousset pthis = NULL;
328 
329     if (!ms)
330         return NULL;
331 
332     AJNEW0(pthis);
333 
334     pthis->Use        = 1U;
335     pthis->Identifier = ms->Identifier;
336     pthis->Adaptor    = ms->Adaptor;
337 
338     if (ms->Code)
339         pthis->Code = ajStrNewRef(ms->Code);
340 
341     if (ms->Name)
342         pthis->Name = ajStrNewRef(ms->Name);
343 
344     if (ms->Description)
345         pthis->Description = ajStrNewRef(ms->Description);
346 
347     pthis->MaximumLength = ms->MaximumLength;
348 
349     return pthis;
350 }
351 
352 
353 
354 
355 /* @func ensMiscellaneoussetNewIni ********************************************
356 **
357 ** Constructor for an Ensembl Miscellaneous Set with initial values.
358 **
359 ** @cc Bio::EnsEMBL::Storable::new
360 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
361 ** Ensembl Miscellaneous Set Adaptor
362 ** @param [r] identifier [ajuint] SQL database-internal identifier
363 ** @cc Bio::EnsEMBL::MiscSet::new
364 ** @param [u] code [AjPStr] Code
365 ** @param [u] name [AjPStr] Name
366 ** @param [u] description [AjPStr] Description
367 ** @param [r] maxlen [ajuint] Maximum length
368 **
369 ** @return [EnsPMiscellaneousset] Ensembl Miscellaneous Set or NULL
370 **
371 ** @release 6.4.0
372 ** @@
373 ******************************************************************************/
374 
ensMiscellaneoussetNewIni(EnsPMiscellaneoussetadaptor msa,ajuint identifier,AjPStr code,AjPStr name,AjPStr description,ajuint maxlen)375 EnsPMiscellaneousset ensMiscellaneoussetNewIni(
376     EnsPMiscellaneoussetadaptor msa,
377     ajuint identifier,
378     AjPStr code,
379     AjPStr name,
380     AjPStr description,
381     ajuint maxlen)
382 {
383     EnsPMiscellaneousset ms = NULL;
384 
385     AJNEW0(ms);
386 
387     ms->Use        = 1U;
388     ms->Identifier = identifier;
389     ms->Adaptor    = msa;
390 
391     if (code)
392         ms->Code = ajStrNewRef(code);
393 
394     if (name)
395         ms->Name = ajStrNewRef(name);
396 
397     if (description)
398         ms->Description = ajStrNewRef(description);
399 
400     ms->MaximumLength = maxlen;
401 
402     return ms;
403 }
404 
405 
406 
407 
408 /* @func ensMiscellaneoussetNewRef ********************************************
409 **
410 ** Ensembl Object referencing function, which returns a pointer to the
411 ** Ensembl Object passed in and increases its reference count.
412 **
413 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
414 **
415 ** @return [EnsPMiscellaneousset] Ensembl Miscellaneous Set or NULL
416 **
417 ** @release 6.2.0
418 ** @@
419 ******************************************************************************/
420 
ensMiscellaneoussetNewRef(EnsPMiscellaneousset ms)421 EnsPMiscellaneousset ensMiscellaneoussetNewRef(EnsPMiscellaneousset ms)
422 {
423     if (!ms)
424         return NULL;
425 
426     ms->Use++;
427 
428     return ms;
429 }
430 
431 
432 
433 
434 /* @section destructors *******************************************************
435 **
436 ** Destruction destroys all internal data structures and frees the memory
437 ** allocated for an Ensembl Miscellaneous Set object.
438 **
439 ** @fdata [EnsPMiscellaneousset]
440 **
441 ** @nam3rule Del Destroy (free) an Ensembl Miscellaneous Set
442 **
443 ** @argrule * Pms [EnsPMiscellaneousset*] Ensembl Miscellaneous Set address
444 **
445 ** @valrule * [void]
446 **
447 ** @fcategory delete
448 ******************************************************************************/
449 
450 
451 
452 
453 /* @func ensMiscellaneoussetDel ***********************************************
454 **
455 ** Default destructor for an Ensembl Miscellaneous Set.
456 **
457 ** @param [d] Pms [EnsPMiscellaneousset*] Ensembl Miscellaneous Set address
458 **
459 ** @return [void]
460 **
461 ** @release 6.2.0
462 ** @@
463 ******************************************************************************/
464 
ensMiscellaneoussetDel(EnsPMiscellaneousset * Pms)465 void ensMiscellaneoussetDel(EnsPMiscellaneousset *Pms)
466 {
467     EnsPMiscellaneousset pthis = NULL;
468 
469     if (!Pms)
470         return;
471 
472 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
473     if (ajDebugTest("ensMiscellaneoussetDel"))
474     {
475         ajDebug("ensMiscellaneoussetDel\n"
476                 "  *Pms %p\n",
477                 *Pms);
478 
479         ensMiscellaneoussetTrace(*Pms, 1);
480     }
481 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
482 
483     if (!(pthis = *Pms) || --pthis->Use)
484     {
485         *Pms = NULL;
486 
487         return;
488     }
489 
490     ajStrDel(&pthis->Code);
491     ajStrDel(&pthis->Name);
492     ajStrDel(&pthis->Description);
493 
494     ajMemFree((void **) Pms);
495 
496     return;
497 }
498 
499 
500 
501 
502 /* @section member retrieval **************************************************
503 **
504 ** Functions for returning members of an Ensembl Miscellaneous Set object.
505 **
506 ** @fdata [EnsPMiscellaneousset]
507 **
508 ** @nam3rule Get Return Ensembl Miscellaneous Set attribute(s)
509 ** @nam4rule Adaptor Return the Ensembl Miscellaneous Set Adaptor
510 ** @nam4rule Code Return the code
511 ** @nam4rule Description Return the description
512 ** @nam4rule Identifier Return the SQL database-internal identifier
513 ** @nam4rule Maximumlength Return the maximum length
514 ** @nam4rule Name Return the name
515 **
516 ** @argrule * ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
517 **
518 ** @valrule Adaptor [EnsPMiscellaneoussetadaptor]
519 ** Ensembl Miscellaneous Set Adaptor or NULL
520 ** @valrule Code [AjPStr] Code or NULL
521 ** @valrule Description [AjPStr] Description or NULL
522 ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U
523 ** @valrule Maximumlength [ajuint] Maximum length or 0U
524 ** @valrule Name [AjPStr] Name or NULL
525 **
526 ** @fcategory use
527 ******************************************************************************/
528 
529 
530 
531 
532 /* @func ensMiscellaneoussetGetAdaptor ****************************************
533 **
534 ** Get the Ensembl Miscellaneous Set Adaptor member of an
535 ** Ensembl Miscellaneous Set.
536 **
537 ** @cc Bio::EnsEMBL::Storable::adaptor
538 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
539 **
540 ** @return [EnsPMiscellaneoussetadaptor] Ensembl Miscellaneous Set Adaptor
541 ** or NULL
542 **
543 ** @release 6.2.0
544 ** @@
545 ******************************************************************************/
546 
ensMiscellaneoussetGetAdaptor(const EnsPMiscellaneousset ms)547 EnsPMiscellaneoussetadaptor ensMiscellaneoussetGetAdaptor(
548     const EnsPMiscellaneousset ms)
549 {
550     return (ms) ? ms->Adaptor : NULL;
551 }
552 
553 
554 
555 
556 /* @func ensMiscellaneoussetGetCode *******************************************
557 **
558 ** Get the code member of an Ensembl Miscellaneous Set.
559 **
560 ** @cc Bio::EnsEMBL::MiscSet::code
561 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
562 **
563 ** @return [AjPStr] Code or NULL
564 **
565 ** @release 6.2.0
566 ** @@
567 ******************************************************************************/
568 
ensMiscellaneoussetGetCode(const EnsPMiscellaneousset ms)569 AjPStr ensMiscellaneoussetGetCode(const EnsPMiscellaneousset ms)
570 {
571     return (ms) ? ms->Code : NULL;
572 }
573 
574 
575 
576 
577 /* @func ensMiscellaneoussetGetDescription ************************************
578 **
579 ** Get the description member of an Ensembl Miscellaneous Set.
580 **
581 ** @cc Bio::EnsEMBL::MiscSet::description
582 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
583 **
584 ** @return [AjPStr] Description or NULL
585 **
586 ** @release 6.2.0
587 ** @@
588 ******************************************************************************/
589 
ensMiscellaneoussetGetDescription(const EnsPMiscellaneousset ms)590 AjPStr ensMiscellaneoussetGetDescription(const EnsPMiscellaneousset ms)
591 {
592     return (ms) ? ms->Description : NULL;
593 }
594 
595 
596 
597 
598 /* @func ensMiscellaneoussetGetIdentifier *************************************
599 **
600 ** Get the SQL database-internal identifier member of an
601 ** Ensembl Miscellaneous Set.
602 **
603 ** @cc Bio::EnsEMBL::Storable::dbID
604 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
605 **
606 ** @return [ajuint] SQL database-internal identifier or 0U
607 **
608 ** @release 6.2.0
609 ** @@
610 ******************************************************************************/
611 
ensMiscellaneoussetGetIdentifier(const EnsPMiscellaneousset ms)612 ajuint ensMiscellaneoussetGetIdentifier(const EnsPMiscellaneousset ms)
613 {
614     return (ms) ? ms->Identifier : 0U;
615 }
616 
617 
618 
619 
620 /* @func ensMiscellaneoussetGetMaximumlength **********************************
621 **
622 ** Get the maximum length member of an Ensembl Miscellaneous Set.
623 **
624 ** @cc Bio::EnsEMBL::MiscSet::longest_feature
625 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
626 **
627 ** @return [ajuint] Maximum length or 0U
628 **
629 ** @release 6.3.0
630 ** @@
631 ******************************************************************************/
632 
ensMiscellaneoussetGetMaximumlength(const EnsPMiscellaneousset ms)633 ajuint ensMiscellaneoussetGetMaximumlength(const EnsPMiscellaneousset ms)
634 {
635     return (ms) ? ms->MaximumLength : 0U;
636 }
637 
638 
639 
640 
641 /* @func ensMiscellaneoussetGetName *******************************************
642 **
643 ** Get the name member of an Ensembl Miscellaneous Set.
644 **
645 ** @cc Bio::EnsEMBL::MiscSet::name
646 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
647 **
648 ** @return [AjPStr] Name or NULL
649 **
650 ** @release 6.2.0
651 ** @@
652 ******************************************************************************/
653 
ensMiscellaneoussetGetName(const EnsPMiscellaneousset ms)654 AjPStr ensMiscellaneoussetGetName(const EnsPMiscellaneousset ms)
655 {
656     return (ms) ? ms->Name : NULL;
657 }
658 
659 
660 
661 
662 /* @section modifiers *********************************************************
663 **
664 ** Functions for assigning members of an Ensembl Miscellaneous Set object.
665 **
666 ** @fdata [EnsPMiscellaneousset]
667 **
668 ** @nam3rule Set Set one member of an Ensembl Miscellaneous Set
669 ** @nam4rule Adaptor Set the Ensembl Miscellaneous Set Adaptor
670 ** @nam4rule Code Set the code
671 ** @nam4rule Description Set the description
672 ** @nam4rule Identifier Set the SQL database-internal identifier
673 ** @nam4rule Maximumlength Set the maximum length
674 ** @nam4rule Name Set the name
675 **
676 ** @argrule * ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set object
677 ** @argrule Adaptor msa [EnsPMiscellaneoussetadaptor] Ensembl Miscellaneous
678 **                                                    Set Adaptor
679 ** @argrule Code code [AjPStr] Code
680 ** @argrule Description description [AjPStr] Description
681 ** @argrule Identifier identifier [ajuint] SQL database-internal identifier
682 ** @argrule Maximumlength maxlen [ajuint] Maximum length
683 ** @argrule Name name [AjPStr] Name
684 **
685 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
686 **
687 ** @fcategory modify
688 ******************************************************************************/
689 
690 
691 
692 
693 /* @func ensMiscellaneoussetSetAdaptor ****************************************
694 **
695 ** Set the Ensembl Miscellaneous Set Adaptor member of an
696 ** Ensembl Miscellaneous Set.
697 **
698 ** @cc Bio::EnsEMBL::Storable::adaptor
699 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
700 ** @param [u] msa [EnsPMiscellaneoussetadaptor] Ensembl Miscellaneous
701 **                                              Set Adaptor
702 **
703 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
704 **
705 ** @release 6.2.0
706 ** @@
707 ******************************************************************************/
708 
ensMiscellaneoussetSetAdaptor(EnsPMiscellaneousset ms,EnsPMiscellaneoussetadaptor msa)709 AjBool ensMiscellaneoussetSetAdaptor(EnsPMiscellaneousset ms,
710                                      EnsPMiscellaneoussetadaptor msa)
711 {
712     if (!ms)
713         return ajFalse;
714 
715     ms->Adaptor = msa;
716 
717     return ajTrue;
718 }
719 
720 
721 
722 
723 /* @func ensMiscellaneoussetSetCode *******************************************
724 **
725 ** Set the code member of an Ensembl Miscellaneous Set.
726 **
727 ** @cc Bio::EnsEMBL::MiscSet::code
728 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
729 ** @param [u] code [AjPStr] Code
730 **
731 ** @return [AjBool] ajTrue upon success, ajFalse otherwise.
732 **
733 ** @release 6.2.0
734 ** @@
735 ******************************************************************************/
736 
ensMiscellaneoussetSetCode(EnsPMiscellaneousset ms,AjPStr code)737 AjBool ensMiscellaneoussetSetCode(EnsPMiscellaneousset ms, AjPStr code)
738 {
739     if (!ms)
740         return ajFalse;
741 
742     ajStrDel(&ms->Code);
743 
744     ms->Code = ajStrNewRef(code);
745 
746     return ajTrue;
747 }
748 
749 
750 
751 
752 /* @func ensMiscellaneoussetSetDescription ************************************
753 **
754 ** Set the description member of an Ensembl Miscellaneous Set.
755 **
756 ** @cc Bio::EnsEMBL::MiscSet::description
757 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
758 ** @param [u] description [AjPStr] Description
759 **
760 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
761 **
762 ** @release 6.2.0
763 ** @@
764 ******************************************************************************/
765 
ensMiscellaneoussetSetDescription(EnsPMiscellaneousset ms,AjPStr description)766 AjBool ensMiscellaneoussetSetDescription(EnsPMiscellaneousset ms,
767                                          AjPStr description)
768 {
769     if (!ms)
770         return ajFalse;
771 
772     ajStrDel(&ms->Description);
773 
774     ms->Description = ajStrNewRef(description);
775 
776     return ajTrue;
777 }
778 
779 
780 
781 
782 /* @func ensMiscellaneoussetSetIdentifier *************************************
783 **
784 ** Set the SQL database-internal identifier member of an
785 ** Ensembl Miscellaneous Set.
786 **
787 ** @cc Bio::EnsEMBL::Storable::dbID
788 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
789 ** @param [r] identifier [ajuint] SQL database-internal identifier
790 **
791 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
792 **
793 ** @release 6.2.0
794 ** @@
795 ******************************************************************************/
796 
ensMiscellaneoussetSetIdentifier(EnsPMiscellaneousset ms,ajuint identifier)797 AjBool ensMiscellaneoussetSetIdentifier(EnsPMiscellaneousset ms,
798                                         ajuint identifier)
799 {
800     if (!ms)
801         return ajFalse;
802 
803     ms->Identifier = identifier;
804 
805     return ajTrue;
806 }
807 
808 
809 
810 
811 /* @func ensMiscellaneoussetSetMaximumlength **********************************
812 **
813 ** Set the maximum length member of an Ensembl Miscellaneous Set.
814 **
815 ** @cc Bio::EnsEMBL::MiscSet::longest_feature
816 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
817 ** @param [r] maxlen [ajuint] Maximum length
818 **
819 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
820 **
821 ** @release 6.3.0
822 ** @@
823 ******************************************************************************/
824 
ensMiscellaneoussetSetMaximumlength(EnsPMiscellaneousset ms,ajuint maxlen)825 AjBool ensMiscellaneoussetSetMaximumlength(EnsPMiscellaneousset ms,
826                                            ajuint maxlen)
827 {
828     if (!ms)
829         return ajFalse;
830 
831     ms->MaximumLength = maxlen;
832 
833     return ajTrue;
834 }
835 
836 
837 
838 
839 /* @func ensMiscellaneoussetSetName *******************************************
840 **
841 ** Set the name member of an Ensembl Miscellaneous Set.
842 **
843 ** @cc Bio::EnsEMBL::MiscSet::name
844 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
845 ** @param [u] name [AjPStr] Name
846 **
847 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
848 **
849 ** @release 6.2.0
850 ** @@
851 ******************************************************************************/
852 
ensMiscellaneoussetSetName(EnsPMiscellaneousset ms,AjPStr name)853 AjBool ensMiscellaneoussetSetName(EnsPMiscellaneousset ms, AjPStr name)
854 {
855     if (!ms)
856         return ajFalse;
857 
858     ajStrDel(&ms->Name);
859 
860     ms->Name = ajStrNewRef(name);
861 
862     return ajTrue;
863 }
864 
865 
866 
867 
868 /* @section debugging *********************************************************
869 **
870 ** Functions for reporting of an Ensembl Miscellaneous Set object.
871 **
872 ** @fdata [EnsPMiscellaneousset]
873 **
874 ** @nam3rule Trace Report Ensembl Miscellaneous Set members to debug file
875 **
876 ** @argrule Trace ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
877 ** @argrule Trace level [ajuint] Indentation level
878 **
879 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
880 **
881 ** @fcategory misc
882 ******************************************************************************/
883 
884 
885 
886 
887 /* @func ensMiscellaneoussetTrace *********************************************
888 **
889 ** Trace an Ensembl Miscellaneous Set.
890 **
891 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
892 ** @param [r] level [ajuint] Indentation level
893 **
894 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
895 **
896 ** @release 6.2.0
897 ** @@
898 ******************************************************************************/
899 
ensMiscellaneoussetTrace(const EnsPMiscellaneousset ms,ajuint level)900 AjBool ensMiscellaneoussetTrace(const EnsPMiscellaneousset ms, ajuint level)
901 {
902     AjPStr indent = NULL;
903 
904     if (!ms)
905         return ajFalse;
906 
907     indent = ajStrNew();
908 
909     ajStrAppendCountK(&indent, ' ', level * 2);
910 
911     ajDebug("%SensMiscellaneoussetTrace %p\n"
912             "%S  Use %u\n"
913             "%S  Identifier %u\n"
914             "%S  Adaptor %p\n"
915             "%S  Code '%S'\n"
916             "%S  Name '%S'\n"
917             "%S  Description '%S'\n"
918             "%S  MaximumLength %u\n",
919             indent, ms,
920             indent, ms->Use,
921             indent, ms->Identifier,
922             indent, ms->Adaptor,
923             indent, ms->Code,
924             indent, ms->Name,
925             indent, ms->Description,
926             indent, ms->MaximumLength);
927 
928     ajStrDel(&indent);
929 
930     return ajTrue;
931 }
932 
933 
934 
935 
936 /* @section calculate *********************************************************
937 **
938 ** Functions for calculating information from an
939 ** Ensembl Miscellaneous Set object.
940 **
941 ** @fdata [EnsPMiscellaneousset]
942 **
943 ** @nam3rule Calculate Calculate Ensembl Miscellaneous Set information
944 ** @nam4rule Memsize Calculate the memory size in bytes
945 **
946 ** @argrule * ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
947 **
948 ** @valrule Memsize [size_t] Memory size in bytes or 0
949 **
950 ** @fcategory misc
951 ******************************************************************************/
952 
953 
954 
955 
956 /* @func ensMiscellaneoussetCalculateMemsize **********************************
957 **
958 ** Calculate the memory size in bytes of an Ensembl Miscellaneous Set.
959 **
960 ** @param [r] ms [const EnsPMiscellaneousset] Ensembl Miscellaneous Set
961 **
962 ** @return [size_t] Memory size in bytes or 0
963 **
964 ** @release 6.4.0
965 ** @@
966 ******************************************************************************/
967 
ensMiscellaneoussetCalculateMemsize(const EnsPMiscellaneousset ms)968 size_t ensMiscellaneoussetCalculateMemsize(const EnsPMiscellaneousset ms)
969 {
970     size_t size = 0;
971 
972     if (!ms)
973         return 0;
974 
975     size += sizeof (EnsOMiscellaneousset);
976 
977     if (ms->Code)
978     {
979         size += sizeof (AjOStr);
980 
981         size += ajStrGetRes(ms->Code);
982     }
983 
984     if (ms->Name)
985     {
986         size += sizeof (AjOStr);
987 
988         size += ajStrGetRes(ms->Name);
989     }
990 
991     if (ms->Description)
992     {
993         size += sizeof (AjOStr);
994 
995         size += ajStrGetRes(ms->Description);
996     }
997 
998     return size;
999 }
1000 
1001 
1002 
1003 
1004 /* @datasection [AjPList] AJAX List *******************************************
1005 **
1006 ** @nam2rule List Functions for manipulating AJAX List objects
1007 **
1008 ******************************************************************************/
1009 
1010 
1011 
1012 
1013 /* @funcstatic listMiscellaneoussetCompareIdentifierAscending *****************
1014 **
1015 ** AJAX List of Ensembl Miscellaneous Set objects comparison function to sort
1016 ** by Ensembl Miscellaneous Set identifier in ascending order.
1017 **
1018 ** @param [r] item1 [const void*] Ensembl Miscellaneous Set address 1
1019 ** @param [r] item2 [const void*] Ensembl Miscellaneous Set address 2
1020 ** @see ajListSort
1021 **
1022 ** @return [int] The comparison function returns an integer less than,
1023 **               equal to, or greater than zero if the first argument is
1024 **               considered to be respectively less than, equal to, or
1025 **               greater than the second.
1026 **
1027 ** @release 6.4.0
1028 ** @@
1029 ******************************************************************************/
1030 
listMiscellaneoussetCompareIdentifierAscending(const void * item1,const void * item2)1031 static int listMiscellaneoussetCompareIdentifierAscending(
1032     const void *item1,
1033     const void *item2)
1034 {
1035     EnsPMiscellaneousset ms1 = *(EnsOMiscellaneousset *const *) item1;
1036     EnsPMiscellaneousset ms2 = *(EnsOMiscellaneousset *const *) item2;
1037 
1038 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
1039     if (ajDebugTest("listMiscellaneoussetCompareIdentifierAscending"))
1040         ajDebug("listMiscellaneoussetCompareIdentifierAscending\n"
1041                 "  ms1 %p\n"
1042                 "  ms2 %p\n",
1043                 ms1,
1044                 ms2);
1045 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
1046 
1047     /* Sort empty values towards the end of the AJAX List. */
1048 
1049     if (ms1 && (!ms2))
1050         return -1;
1051 
1052     if ((!ms1) && (!ms2))
1053         return 0;
1054 
1055     if ((!ms1) && ms2)
1056         return +1;
1057 
1058     if (ms1->Identifier < ms2->Identifier)
1059         return -1;
1060 
1061     if (ms1->Identifier > ms2->Identifier)
1062         return +1;
1063 
1064     return 0;
1065 }
1066 
1067 
1068 
1069 
1070 /* @funcstatic listMiscellaneoussetCompareIdentifierDescending ****************
1071 **
1072 ** AJAX List of Ensembl Miscellaneous Set objects comparison function to sort
1073 ** by Ensembl Miscellaneous Set identifier in descending order.
1074 **
1075 ** @param [r] item1 [const void*] Ensembl Miscellaneous Set address 1
1076 ** @param [r] item2 [const void*] Ensembl Miscellaneous Set address 2
1077 ** @see ajListSort
1078 **
1079 ** @return [int] The comparison function returns an integer less than,
1080 **               equal to, or greater than zero if the first argument is
1081 **               considered to be respectively less than, equal to, or
1082 **               greater than the second.
1083 **
1084 ** @release 6.4.0
1085 ** @@
1086 ******************************************************************************/
1087 
listMiscellaneoussetCompareIdentifierDescending(const void * item1,const void * item2)1088 static int listMiscellaneoussetCompareIdentifierDescending(
1089     const void *item1,
1090     const void *item2)
1091 {
1092     EnsPMiscellaneousset ms1 = *(EnsOMiscellaneousset *const *) item1;
1093     EnsPMiscellaneousset ms2 = *(EnsOMiscellaneousset *const *) item2;
1094 
1095 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
1096     if (ajDebugTest("listMiscellaneoussetCompareIdentifierDescending"))
1097         ajDebug("listMiscellaneoussetCompareIdentifierDescending\n"
1098                 "  ms1 %p\n"
1099                 "  ms2 %p\n",
1100                 ms1,
1101                 ms2);
1102 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
1103 
1104     /* Sort empty values towards the end of the AJAX List. */
1105 
1106     if (ms1 && (!ms2))
1107         return -1;
1108 
1109     if ((!ms1) && (!ms2))
1110         return 0;
1111 
1112     if ((!ms1) && ms2)
1113         return +1;
1114 
1115     if (ms1->Identifier > ms2->Identifier)
1116         return -1;
1117 
1118     if (ms1->Identifier < ms2->Identifier)
1119         return +1;
1120 
1121     return 0;
1122 }
1123 
1124 
1125 
1126 
1127 /* @section list **************************************************************
1128 **
1129 ** Functions for manipulating AJAX List objects.
1130 **
1131 ** @fdata [AjPList]
1132 **
1133 ** @nam3rule Miscellaneousset Functions for manipulating AJAX List objects of
1134 ** Ensembl Miscellaneous Set objects
1135 ** @nam4rule Sort Sort functions
1136 ** @nam5rule Identifier Sort by Ensembl Miscellaneous Set identifier member
1137 ** @nam5rule Name Sort by Ensembl Miscellaneous Set name member
1138 ** @nam6rule Ascending  Sort in ascending order
1139 ** @nam6rule Descending Sort in descending order
1140 **
1141 ** @argrule Sort mss [AjPList] AJAX List of Ensembl Miscellaneous Set objects
1142 **
1143 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1144 **
1145 ** @fcategory misc
1146 ******************************************************************************/
1147 
1148 
1149 
1150 
1151 /* @func ensListMiscellaneoussetSortIdentifierAscending ***********************
1152 **
1153 ** Sort an AJAX List of Ensembl Miscellaneous Set objects by their
1154 ** Ensembl Miscellaneous Set identifier in ascending order.
1155 **
1156 ** @param [u] mss [AjPList] AJAX List of Ensembl Miscellaneous Set objects
1157 **
1158 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1159 **
1160 ** @release 6.4.0
1161 ** @@
1162 ******************************************************************************/
1163 
ensListMiscellaneoussetSortIdentifierAscending(AjPList mss)1164 AjBool ensListMiscellaneoussetSortIdentifierAscending(AjPList mss)
1165 {
1166     if (!mss)
1167         return ajFalse;
1168 
1169     ajListSort(mss, &listMiscellaneoussetCompareIdentifierAscending);
1170 
1171     return ajTrue;
1172 }
1173 
1174 
1175 
1176 
1177 /* @func ensListMiscellaneoussetSortIdentifierDescending **********************
1178 **
1179 ** Sort an AJAX List of Ensembl Miscellaneous Set objects by their
1180 ** Ensembl Miscellaneous Set identifier in descending order.
1181 **
1182 ** @param [u] mss [AjPList] AJAX List of Ensembl Miscellaneous Set objects
1183 **
1184 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1185 **
1186 ** @release 6.4.0
1187 ** @@
1188 ******************************************************************************/
1189 
ensListMiscellaneoussetSortIdentifierDescending(AjPList mss)1190 AjBool ensListMiscellaneoussetSortIdentifierDescending(AjPList mss)
1191 {
1192     if (!mss)
1193         return ajFalse;
1194 
1195     ajListSort(mss, &listMiscellaneoussetCompareIdentifierDescending);
1196 
1197     return ajTrue;
1198 }
1199 
1200 
1201 
1202 
1203 /* @datasection [EnsPMiscellaneoussetadaptor] Ensembl Miscellaneous Set Adaptor
1204 **
1205 ** @nam2rule Miscellaneoussetadaptor Functions for manipulating
1206 ** Ensembl Miscellaneous Set Adaptor objects
1207 **
1208 ** @cc Bio::EnsEMBL::DBSQL::MiscSetAdaptor
1209 ** @cc CVS Revision: 1.16
1210 ** @cc CVS Tag: branch-ensembl-68
1211 **
1212 ******************************************************************************/
1213 
1214 
1215 
1216 
1217 /* @funcstatic miscellaneoussetadaptorFetchAllbyStatement *********************
1218 **
1219 ** Run a SQL statement against an Ensembl Database Adaptor and consolidate the
1220 ** results into an AJAX List of Ensembl Miscellaneous Set objects.
1221 **
1222 ** @param [u] ba [EnsPBaseadaptor] Ensembl Base Adaptor
1223 ** @param [r] statement [const AjPStr] SQL statement
1224 ** @param [uN] am [EnsPAssemblymapper] Ensembl Assembly Mapper
1225 ** @param [uN] slice [EnsPSlice] Ensembl Slice
1226 ** @param [u] mss [AjPList] AJAX List of Ensembl Miscellaneous Sets
1227 **
1228 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1229 **
1230 ** @release 6.4.0
1231 ** @@
1232 ******************************************************************************/
1233 
miscellaneoussetadaptorFetchAllbyStatement(EnsPBaseadaptor ba,const AjPStr statement,EnsPAssemblymapper am,EnsPSlice slice,AjPList mss)1234 static AjBool miscellaneoussetadaptorFetchAllbyStatement(
1235     EnsPBaseadaptor ba,
1236     const AjPStr statement,
1237     EnsPAssemblymapper am,
1238     EnsPSlice slice,
1239     AjPList mss)
1240 {
1241     ajuint identifier = 0U;
1242     ajuint maxlen     = 0U;
1243 
1244     AjPSqlstatement sqls = NULL;
1245     AjISqlrow sqli       = NULL;
1246     AjPSqlrow sqlr       = NULL;
1247 
1248     AjPStr code        = NULL;
1249     AjPStr name        = NULL;
1250     AjPStr description = NULL;
1251 
1252     EnsPDatabaseadaptor dba = NULL;
1253 
1254     EnsPMiscellaneousset        ms  = NULL;
1255     EnsPMiscellaneoussetadaptor msa = NULL;
1256 
1257     if (ajDebugTest("miscellaneoussetadaptorFetchAllbyStatement"))
1258         ajDebug("miscellaneoussetadaptorFetchAllbyStatement\n"
1259                 "  ba %p\n"
1260                 "  statement %p\n"
1261                 "  am %p\n"
1262                 "  slice %p\n"
1263                 "  mss %p\n",
1264                 ba,
1265                 statement,
1266                 am,
1267                 slice,
1268                 mss);
1269 
1270     if (!ba)
1271         return ajFalse;
1272 
1273     if (!statement)
1274         return ajFalse;
1275 
1276     if (!mss)
1277         return ajFalse;
1278 
1279     dba = ensBaseadaptorGetDatabaseadaptor(ba);
1280 
1281     msa = ensRegistryGetMiscellaneoussetadaptor(dba);
1282 
1283     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
1284 
1285     sqli = ajSqlrowiterNew(sqls);
1286 
1287     while (!ajSqlrowiterDone(sqli))
1288     {
1289         identifier  = 0;
1290         code        = ajStrNew();
1291         name        = ajStrNew();
1292         description = ajStrNew();
1293         maxlen      = 0;
1294 
1295         sqlr = ajSqlrowiterGet(sqli);
1296 
1297         ajSqlcolumnToUint(sqlr, &identifier);
1298         ajSqlcolumnToStr(sqlr, &code);
1299         ajSqlcolumnToStr(sqlr, &name);
1300         ajSqlcolumnToStr(sqlr, &description);
1301         ajSqlcolumnToUint(sqlr, &maxlen);
1302 
1303         ms = ensMiscellaneoussetNewIni(msa,
1304                                        identifier,
1305                                        code,
1306                                        name,
1307                                        description,
1308                                        maxlen);
1309 
1310         ajListPushAppend(mss, (void *) ms);
1311 
1312         ajStrDel(&code);
1313         ajStrDel(&name);
1314         ajStrDel(&description);
1315     }
1316 
1317     ajSqlrowiterDel(&sqli);
1318 
1319     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
1320 
1321     return ajTrue;
1322 }
1323 
1324 
1325 
1326 
1327 /* @section constructors ******************************************************
1328 **
1329 ** All constructors return a new Ensembl Miscellaneous Set Adaptor by pointer.
1330 ** It is the responsibility of the user to first destroy any previous
1331 ** Miscellaneous Set Adaptor. The target pointer does not need to be
1332 ** initialised to NULL, but it is good programming practice to do so anyway.
1333 **
1334 ** @fdata [EnsPMiscellaneoussetadaptor]
1335 **
1336 ** @nam3rule New Constructor
1337 **
1338 ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
1339 **
1340 ** @valrule * [EnsPMiscellaneoussetadaptor]
1341 ** Ensembl Miscellaneous Set Adaptor or NULL
1342 **
1343 ** @fcategory new
1344 ******************************************************************************/
1345 
1346 
1347 
1348 
1349 /* @func ensMiscellaneoussetadaptorNew ****************************************
1350 **
1351 ** Default constructor for an Ensembl Miscellaneous Set Adaptor.
1352 **
1353 ** Ensembl Object Adaptors are singleton objects in the sense that a single
1354 ** instance of an Ensembl Object Adaptor connected to a particular database is
1355 ** sufficient to instantiate any number of Ensembl Objects from the database.
1356 ** Each Ensembl Object will have a weak reference to the Object Adaptor that
1357 ** instantiated it. Therefore, Ensembl Object Adaptors should not be
1358 ** instantiated directly, but rather obtained from the Ensembl Registry,
1359 ** which will in turn call this function if neccessary.
1360 **
1361 ** @see ensRegistryGetDatabaseadaptor
1362 ** @see ensRegistryGetMiscellaneoussetadaptor
1363 **
1364 ** @cc Bio::EnsEMBL::DBSQL::MiscSetAdaptor::new
1365 ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
1366 **
1367 ** @return [EnsPMiscellaneoussetadaptor]
1368 ** Ensembl Miscellaneous Set Adaptor or NULL
1369 **
1370 ** @release 6.2.0
1371 ** @@
1372 ******************************************************************************/
1373 
ensMiscellaneoussetadaptorNew(EnsPDatabaseadaptor dba)1374 EnsPMiscellaneoussetadaptor ensMiscellaneoussetadaptorNew(
1375     EnsPDatabaseadaptor dba)
1376 {
1377     EnsPMiscellaneoussetadaptor msa = NULL;
1378 
1379     if (!dba)
1380         return NULL;
1381 
1382     AJNEW0(msa);
1383 
1384     msa->Adaptor = ensBaseadaptorNew(
1385         dba,
1386         miscellaneoussetadaptorKTablenames,
1387         miscellaneoussetadaptorKColumnnames,
1388         (const EnsPBaseadaptorLeftjoin) NULL,
1389         (const char *) NULL,
1390         (const char *) NULL,
1391         &miscellaneoussetadaptorFetchAllbyStatement);
1392 
1393     /*
1394     ** NOTE: The cache cannot be initialised here because the
1395     ** miscellaneoussetadaptorCacheInit function calls
1396     ** ensBaseadaptorFetchAllbyConstraint, which calls
1397     ** miscellaneoussetadaptorFetchAllbyStatement, which calls
1398     ** ensRegistryGetMiscellaneoussetadaptor. At that point, however, the
1399     ** Miscellaneous Set Adaptor has not been stored in the Registry.
1400     ** Therefore, each ensMiscellaneoussetadaptorFetch function has to test
1401     ** the presence of the adaptor-internal cache and eventually initialise
1402     ** before accessing it.
1403     **
1404     miscellaneoussetadaptorCacheInit(msa);
1405     */
1406 
1407     return msa;
1408 }
1409 
1410 
1411 
1412 
1413 /* @section cache *************************************************************
1414 **
1415 ** Functions for maintaining the Ensembl Miscellaneous Set Adaptor-internal
1416 ** cache of Ensembl Miscellaneous Set objects.
1417 **
1418 ** @fdata [EnsPMiscellaneoussetadaptor]
1419 **
1420 ** @nam3rule Cache Process an Ensembl Miscellaneous Set Adaptor-internal cache
1421 ** @nam4rule Clear Clear the Ensembl Miscellaneous Set Adaptor-internal cache
1422 **
1423 ** @argrule * msa [EnsPMiscellaneoussetadaptor]
1424 ** Ensembl Miscellaneous Set Adaptor
1425 **
1426 ** @valrule * [AjBool] True on success, ajFalse otherwise
1427 **
1428 ** @fcategory use
1429 ******************************************************************************/
1430 
1431 
1432 
1433 
1434 /* @funcstatic miscellaneoussetadaptorCacheInit *******************************
1435 **
1436 ** Initialise the internal Miscellaneous Set cache of an
1437 ** Ensembl Miscellaneous Set Adaptor.
1438 **
1439 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
1440 ** Ensembl Miscellaneous Set Adaptor
1441 **
1442 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1443 **
1444 ** @release 6.3.0
1445 ** @@
1446 ******************************************************************************/
1447 
miscellaneoussetadaptorCacheInit(EnsPMiscellaneoussetadaptor msa)1448 static AjBool miscellaneoussetadaptorCacheInit(
1449     EnsPMiscellaneoussetadaptor msa)
1450 {
1451     AjPList mss      = NULL;
1452 
1453     EnsPMiscellaneousset ms = NULL;
1454 
1455     if (!msa)
1456         return ajFalse;
1457 
1458     if (msa->CacheByIdentifier)
1459         return ajFalse;
1460     else
1461     {
1462         msa->CacheByIdentifier = ajTableuintNew(0U);
1463 
1464         ajTableSetDestroyvalue(
1465             msa->CacheByIdentifier,
1466             (void (*)(void **)) &ensMiscellaneoussetDel);
1467     }
1468 
1469     if (msa->CacheByCode)
1470         return ajFalse;
1471     else
1472     {
1473         msa->CacheByCode = ajTablestrNew(0U);
1474 
1475         ajTableSetDestroyvalue(
1476             msa->CacheByCode,
1477             (void (*)(void **)) &ensMiscellaneoussetDel);
1478     }
1479 
1480     mss = ajListNew();
1481 
1482     ensBaseadaptorFetchAllbyConstraint(
1483         ensMiscellaneoussetadaptorGetBaseadaptor(msa),
1484         (const AjPStr) NULL,
1485         (EnsPAssemblymapper) NULL,
1486         (EnsPSlice) NULL,
1487         mss);
1488 
1489     while (ajListPop(mss, (void **) &ms))
1490     {
1491         miscellaneoussetadaptorCacheInsert(msa, &ms);
1492 
1493         /*
1494         ** Both caches hold internal references to the
1495         ** Miscellaneous Set objects.
1496         */
1497 
1498         ensMiscellaneoussetDel(&ms);
1499     }
1500 
1501     ajListFree(&mss);
1502 
1503     return ajTrue;
1504 }
1505 
1506 
1507 
1508 
1509 /* @funcstatic miscellaneoussetadaptorCacheInsert *****************************
1510 **
1511 ** Insert an Ensembl Miscellaneous Set into the
1512 ** Miscellaneous Set Adaptor-internal cache.
1513 ** If a Miscellaneous Set with the same code member is already present in the
1514 ** adaptor cache, the Miscellaneous Set is deleted and a pointer to the cached
1515 ** Miscellaneous Set is returned.
1516 **
1517 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
1518 ** Ensembl Miscellaneous Set Adaptor
1519 ** @param [u] Pms [EnsPMiscellaneousset*] Ensembl Miscellaneous Set address
1520 **
1521 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1522 **
1523 ** @release 6.3.0
1524 ** @@
1525 ******************************************************************************/
1526 
miscellaneoussetadaptorCacheInsert(EnsPMiscellaneoussetadaptor msa,EnsPMiscellaneousset * Pms)1527 static AjBool miscellaneoussetadaptorCacheInsert(
1528     EnsPMiscellaneoussetadaptor msa,
1529     EnsPMiscellaneousset *Pms)
1530 {
1531     ajuint *Pidentifier = NULL;
1532 
1533     EnsPMiscellaneousset ms1 = NULL;
1534     EnsPMiscellaneousset ms2 = NULL;
1535 
1536     if (!msa)
1537         return ajFalse;
1538 
1539     if (!msa->CacheByIdentifier)
1540         return ajFalse;
1541 
1542     if (!msa->CacheByCode)
1543         return ajFalse;
1544 
1545     if (!Pms)
1546         return ajFalse;
1547 
1548     if (!*Pms)
1549         return ajFalse;
1550 
1551     /* Search the identifer cache. */
1552 
1553     ms1 = (EnsPMiscellaneousset) ajTableFetchmodV(
1554         msa->CacheByIdentifier,
1555         (const void *) &((*Pms)->Identifier));
1556 
1557     /* Search the code cache. */
1558 
1559     ms2 = (EnsPMiscellaneousset) ajTableFetchmodS(
1560         msa->CacheByCode,
1561         (*Pms)->Code);
1562 
1563     if ((!ms1) && (!ms2))
1564     {
1565         /* Insert into the identifier cache. */
1566 
1567         AJNEW0(Pidentifier);
1568 
1569         *Pidentifier = (*Pms)->Identifier;
1570 
1571         ajTablePut(msa->CacheByIdentifier,
1572                    (void *) Pidentifier,
1573                    (void *) ensMiscellaneoussetNewRef(*Pms));
1574 
1575         /* Insert into the code cache. */
1576 
1577         ajTablePut(msa->CacheByCode,
1578                    (void *) ajStrNewS((*Pms)->Code),
1579                    (void *) ensMiscellaneoussetNewRef(*Pms));
1580     }
1581 
1582     if (ms1 && ms2 && (ms1 == ms2))
1583     {
1584         ajDebug("miscellaneoussetadaptorCacheInsert replaced "
1585                 "Miscellaneous Set %p with one already cached %p.\n",
1586                 *Pms, ms1);
1587 
1588         ensMiscellaneoussetDel(Pms);
1589 
1590         Pms = &ms1;
1591     }
1592 
1593     if (ms1 && ms2 && (ms1 != ms2))
1594         ajDebug("miscellaneoussetadaptorCacheInsert detected "
1595                 "Miscellaneous Sets in the identifier and code cache with "
1596                 "identical codes ('%S' and '%S') but different addresses "
1597                 "(%p and %p).\n",
1598                 ms1->Code, ms2->Code, ms1, ms2);
1599 
1600     if (ms1 && (!ms2))
1601         ajDebug("miscellaneoussetadaptorCacheInsert detected an "
1602                 "Ensembl Miscellaneous Set "
1603                 "in the identifier, but not in the code cache.\n");
1604 
1605     if ((!ms1) && ms2)
1606         ajDebug("miscellaneoussetadaptorCacheInsert detected an "
1607                 "Ensembl Miscellaneous Set "
1608                 "in the code, but not in the identifier cache.\n");
1609 
1610     return ajTrue;
1611 }
1612 
1613 
1614 
1615 
1616 #if AJFALSE
1617 /* @funcstatic miscellaneoussetadaptorCacheRemove *****************************
1618 **
1619 ** Remove an Ensembl Miscellaneous Set from the
1620 ** Miscellaneous Set Adaptor-internal cache.
1621 **
1622 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
1623 ** Ensembl Miscellaneous Set Adaptor
1624 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
1625 **
1626 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1627 **
1628 ** @release 6.3.0
1629 ** @@
1630 ******************************************************************************/
1631 
miscellaneoussetadaptorCacheRemove(EnsPMiscellaneoussetadaptor msa,EnsPMiscellaneousset ms)1632 static AjBool miscellaneoussetadaptorCacheRemove(
1633     EnsPMiscellaneoussetadaptor msa,
1634     EnsPMiscellaneousset ms)
1635 {
1636     EnsPMiscellaneousset ms1 = NULL;
1637     EnsPMiscellaneousset ms2 = NULL;
1638 
1639     if (!msa)
1640         return ajFalse;
1641 
1642     if (!ms)
1643         return ajFalse;
1644 
1645     ms1 = (EnsPMiscellaneousset) ajTableRemove(
1646         msa->CacheByIdentifier,
1647         (const void *) &ms->Identifier);
1648 
1649     ms2 = (EnsPMiscellaneousset) ajTableRemove(
1650         msa->CacheByCode,
1651         (const void *) ms->Code);
1652 
1653     if (ms1 && (!ms2))
1654         ajWarn("miscellaneoussetadaptorCacheRemove could remove "
1655                "Miscellaneous Set '%S' (%u) "
1656                "only from the identifier cache.\n",
1657                ms->Code, ms->Identifier);
1658 
1659     if ((!ms1) && ms2)
1660         ajWarn("miscellaneoussetadaptorCacheRemove could remove "
1661                "Miscellaneous Set '%S' (%u) "
1662                "only from the code cache.\n",
1663                ms->Code, ms->Identifier);
1664 
1665     ensMiscellaneoussetDel(&ms1);
1666     ensMiscellaneoussetDel(&ms2);
1667 
1668     return ajTrue;
1669 }
1670 
1671 #endif /* AJFALSE */
1672 
1673 
1674 
1675 
1676 /* @func ensMiscellaneoussetadaptorCacheClear *********************************
1677 **
1678 ** Clear the Ensembl Miscellaneous Set Adaptor-internal cache of
1679 ** Ensembl Miscellaneous Set objects.
1680 **
1681 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
1682 ** Ensembl Miscellaneous Set Adaptor
1683 **
1684 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1685 **
1686 ** @release 6.4.0
1687 ** @@
1688 ******************************************************************************/
1689 
ensMiscellaneoussetadaptorCacheClear(EnsPMiscellaneoussetadaptor msa)1690 AjBool ensMiscellaneoussetadaptorCacheClear(
1691     EnsPMiscellaneoussetadaptor msa)
1692 {
1693     if (!msa)
1694         return ajFalse;
1695 
1696     ajTableDel(&msa->CacheByIdentifier);
1697     ajTableDel(&msa->CacheByCode);
1698 
1699     return ajTrue;
1700 }
1701 
1702 
1703 
1704 
1705 /* @section destructors *******************************************************
1706 **
1707 ** Destruction destroys all internal data structures and frees the memory
1708 ** allocated for an Ensembl Miscellaneous Set Adaptor object.
1709 **
1710 ** @fdata [EnsPMiscellaneoussetadaptor]
1711 **
1712 ** @nam3rule Del Destroy (free) an Ensembl Miscellaneous Set Adaptor
1713 **
1714 ** @argrule * Pmsa [EnsPMiscellaneoussetadaptor*]
1715 ** Ensembl Miscellaneous Set Adaptor address
1716 **
1717 ** @valrule * [void]
1718 **
1719 ** @fcategory delete
1720 ******************************************************************************/
1721 
1722 
1723 
1724 
1725 /* @func ensMiscellaneoussetadaptorDel ****************************************
1726 **
1727 ** Default destructor for an Ensembl Miscellaneous Set Adaptor.
1728 **
1729 ** This function also clears the internal caches.
1730 **
1731 ** Ensembl Object Adaptors are singleton objects that are registered in the
1732 ** Ensembl Registry and weakly referenced by Ensembl Objects that have been
1733 ** instantiated by it. Therefore, Ensembl Object Adaptors should never be
1734 ** destroyed directly. Upon exit, the Ensembl Registry will call this function
1735 ** if required.
1736 **
1737 ** @param [d] Pmsa [EnsPMiscellaneoussetadaptor*]
1738 ** Ensembl Miscellaneous Set Adaptor address
1739 **
1740 ** @return [void]
1741 **
1742 ** @release 6.2.0
1743 ** @@
1744 ******************************************************************************/
1745 
ensMiscellaneoussetadaptorDel(EnsPMiscellaneoussetadaptor * Pmsa)1746 void ensMiscellaneoussetadaptorDel(EnsPMiscellaneoussetadaptor *Pmsa)
1747 {
1748     EnsPMiscellaneoussetadaptor pthis = NULL;
1749 
1750     if (!Pmsa)
1751         return;
1752 
1753 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
1754     if (ajDebugTest("ensMiscellaneoussetadaptorDel"))
1755         ajDebug("ensMiscellaneoussetadaptorDel\n"
1756                 "  *Pmsa %p\n",
1757                 *Pmsa);
1758 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
1759 
1760     if (!(pthis = *Pmsa))
1761         return;
1762 
1763     ensMiscellaneoussetadaptorCacheClear(pthis);
1764 
1765     ensBaseadaptorDel(&pthis->Adaptor);
1766 
1767     ajMemFree((void **) Pmsa);
1768 
1769     return;
1770 }
1771 
1772 
1773 
1774 
1775 /* @section member retrieval **************************************************
1776 **
1777 ** Functions for returning members of an
1778 ** Ensembl Miscellaneous Set Adaptor object.
1779 **
1780 ** @fdata [EnsPMiscellaneoussetadaptor]
1781 **
1782 ** @nam3rule Get Return Ensembl Miscellaneous Set Adaptor attribute(s)
1783 ** @nam4rule Baseadaptor     Return the Ensembl Base Adaptor
1784 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
1785 **
1786 ** @argrule * msa [EnsPMiscellaneoussetadaptor]
1787 ** Ensembl Miscellaneous Set Adaptor
1788 **
1789 ** @valrule Baseadaptor [EnsPBaseadaptor]
1790 ** Ensembl Base Adaptor or NULL
1791 ** @valrule Databaseadaptor [EnsPDatabaseadaptor]
1792 ** Ensembl Database Adaptor or NULL
1793 **
1794 ** @fcategory use
1795 ******************************************************************************/
1796 
1797 
1798 
1799 
1800 /* @func ensMiscellaneoussetadaptorGetBaseadaptor *****************************
1801 **
1802 ** Get the Ensembl Base Adaptor member of an
1803 ** Ensembl Miscellaneous Set Adaptor.
1804 **
1805 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
1806 ** Ensembl Miscellaneous Set Adaptor
1807 **
1808 ** @return [EnsPBaseadaptor] Ensembl Base Adaptor or NULL
1809 **
1810 ** @release 6.4.0
1811 ** @@
1812 ******************************************************************************/
1813 
ensMiscellaneoussetadaptorGetBaseadaptor(EnsPMiscellaneoussetadaptor msa)1814 EnsPBaseadaptor ensMiscellaneoussetadaptorGetBaseadaptor(
1815     EnsPMiscellaneoussetadaptor msa)
1816 {
1817     return (msa) ? msa->Adaptor : NULL;
1818 }
1819 
1820 
1821 
1822 
1823 /* @func ensMiscellaneoussetadaptorGetDatabaseadaptor *************************
1824 **
1825 ** Get the Ensembl Database Adaptor member of an
1826 ** Ensembl Miscellaneous Set Adaptor.
1827 **
1828 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
1829 ** Ensembl Miscellaneous Set Adaptor
1830 **
1831 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
1832 **
1833 ** @release 6.2.0
1834 ** @@
1835 ******************************************************************************/
1836 
ensMiscellaneoussetadaptorGetDatabaseadaptor(EnsPMiscellaneoussetadaptor msa)1837 EnsPDatabaseadaptor ensMiscellaneoussetadaptorGetDatabaseadaptor(
1838     EnsPMiscellaneoussetadaptor msa)
1839 {
1840     return ensBaseadaptorGetDatabaseadaptor(
1841         ensMiscellaneoussetadaptorGetBaseadaptor(msa));
1842 }
1843 
1844 
1845 
1846 
1847 /* @section object fetching ***************************************************
1848 **
1849 ** Functions for fetching Ensembl Miscellaneous Set objects from an
1850 ** Ensembl SQL database.
1851 **
1852 ** @fdata [EnsPMiscellaneoussetadaptor]
1853 **
1854 ** @nam3rule Fetch   Fetch Ensembl Miscellaneous Set object(s)
1855 ** @nam4rule All     Fetch all Ensembl Miscellaneous Set objects
1856 ** @nam5rule Allby   Fetch all Ensembl Miscellaneous Set objects
1857 **                   matching a criterion
1858 ** @nam4rule FetchBy Fetch one Ensembl Miscellaneous Set object
1859 **                   matching a criterion
1860 ** @nam5rule Code    Fetch by code
1861 ** @nam5rule Identifier Fetch by an SQL database-internal identifier
1862 **
1863 ** @argrule * msa [EnsPMiscellaneoussetadaptor]
1864 ** Ensembl Miscellaneous Set Adaptor
1865 ** @argrule All mss [AjPList] AJAX List of Ensembl Miscellaneous Set objects
1866 ** @argrule ByCode code [const AjPStr] Ensembl Miscellaneous Set code
1867 ** @argrule ByIdentifier identifier [ajuint] SQL database-internal identifier
1868 ** @argrule By Pms [EnsPMiscellaneousset*] Ensembl Miscellaneous Set address
1869 **
1870 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1871 **
1872 ** @fcategory use
1873 ******************************************************************************/
1874 
1875 
1876 
1877 
1878 /* @funcstatic miscellaneoussetadaptorFetchAll ********************************
1879 **
1880 ** An ajTableMap "apply" function to return all Miscellaneous Set objects
1881 ** from the Ensembl Miscellaneous Set Adaptor-internal cache.
1882 **
1883 ** @param [u] key [const void*] AJAX unsigned integer key data address
1884 ** @param [u] Pvalue [void**] Ensembl Miscellaneous Set value data address
1885 ** @param [u] cl [void*] AJAX List of Ensembl Miscellaneous Set objects,
1886 **                       passed in via ajTableMap
1887 ** @see ajTableMap
1888 **
1889 ** @return [void]
1890 **
1891 ** @release 6.3.0
1892 ** @@
1893 ******************************************************************************/
1894 
miscellaneoussetadaptorFetchAll(const void * key,void ** Pvalue,void * cl)1895 static void miscellaneoussetadaptorFetchAll(const void *key,
1896                                             void **Pvalue,
1897                                             void *cl)
1898 {
1899     if (!key)
1900         return;
1901 
1902     if (!Pvalue)
1903         return;
1904 
1905     if (!*Pvalue)
1906         return;
1907 
1908     if (!cl)
1909         return;
1910 
1911     ajListPushAppend(
1912         (AjPList) cl,
1913         (void *) ensMiscellaneoussetNewRef(
1914             *((EnsPMiscellaneousset *) Pvalue)));
1915 
1916     return;
1917 }
1918 
1919 
1920 
1921 
1922 /* @func ensMiscellaneoussetadaptorFetchAll ***********************************
1923 **
1924 ** Fetch all Ensembl Miscellaneous Sets.
1925 **
1926 ** @cc Bio::EnsEMBL::DBSQL::MiscSetAdaptor::fetch_all
1927 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
1928 ** Ensembl Miscellaneous Set Adaptor
1929 ** @param [u] mss [AjPList] AJAX List of Ensembl Miscellaneous Set objects
1930 **
1931 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1932 **
1933 ** @release 6.2.0
1934 ** @@
1935 ******************************************************************************/
1936 
ensMiscellaneoussetadaptorFetchAll(EnsPMiscellaneoussetadaptor msa,AjPList mss)1937 AjBool ensMiscellaneoussetadaptorFetchAll(
1938     EnsPMiscellaneoussetadaptor msa,
1939     AjPList mss)
1940 {
1941     if (!msa)
1942         return ajFalse;
1943 
1944     if (!mss)
1945         return ajFalse;
1946 
1947     if (!msa->CacheByIdentifier)
1948         miscellaneoussetadaptorCacheInit(msa);
1949 
1950     ajTableMap(msa->CacheByIdentifier,
1951                &miscellaneoussetadaptorFetchAll,
1952                (void *) mss);
1953 
1954     return ajTrue;
1955 }
1956 
1957 
1958 
1959 
1960 /* @func ensMiscellaneoussetadaptorFetchByCode ********************************
1961 **
1962 ** Fetch an Ensembl Miscellaneous Set by its code.
1963 **
1964 ** @cc Bio::EnsEMBL::DBSQL::MiscSetAdaptor::fetch_by_code
1965 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
1966 ** Ensembl Miscellaneous Set Adaptor
1967 ** @param [r] code [const AjPStr] Ensembl Miscellaneous Set code
1968 ** @param [wP] Pms [EnsPMiscellaneousset*] Ensembl Miscellaneous Set address
1969 **
1970 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1971 **
1972 ** @release 6.2.0
1973 ** @@
1974 ******************************************************************************/
1975 
ensMiscellaneoussetadaptorFetchByCode(EnsPMiscellaneoussetadaptor msa,const AjPStr code,EnsPMiscellaneousset * Pms)1976 AjBool ensMiscellaneoussetadaptorFetchByCode(
1977     EnsPMiscellaneoussetadaptor msa,
1978     const AjPStr code,
1979     EnsPMiscellaneousset *Pms)
1980 {
1981     char *txtcode = NULL;
1982 
1983     AjPList mss = NULL;
1984 
1985     AjPStr constraint = NULL;
1986 
1987     EnsPDatabaseadaptor dba = NULL;
1988 
1989     EnsPMiscellaneousset ms = NULL;
1990 
1991     if (!msa)
1992         return ajFalse;
1993 
1994     if ((!code) && (!ajStrGetLen(code)))
1995         return ajFalse;
1996 
1997     if (!Pms)
1998         return ajFalse;
1999 
2000     *Pms = NULL;
2001 
2002     /*
2003     ** Initially, search the code cache.
2004     ** For any object returned by the AJAX Table the reference counter needs
2005     ** to be incremented manually.
2006     */
2007 
2008     if (!msa->CacheByCode)
2009         miscellaneoussetadaptorCacheInit(msa);
2010 
2011     *Pms = (EnsPMiscellaneousset) ajTableFetchmodS(msa->CacheByCode, code);
2012 
2013     if (*Pms)
2014     {
2015         ensMiscellaneoussetNewRef(*Pms);
2016 
2017         return ajTrue;
2018     }
2019 
2020     /* In case of a cache miss, query the database. */
2021 
2022     dba = ensMiscellaneoussetadaptorGetDatabaseadaptor(msa);
2023 
2024     ensDatabaseadaptorEscapeC(dba, &txtcode, code);
2025 
2026     constraint = ajFmtStr("misc_set.code = '%s'", txtcode);
2027 
2028     ajCharDel(&txtcode);
2029 
2030     mss = ajListNew();
2031 
2032     ensBaseadaptorFetchAllbyConstraint(
2033         ensMiscellaneoussetadaptorGetBaseadaptor(msa),
2034         constraint,
2035         (EnsPAssemblymapper) NULL,
2036         (EnsPSlice) NULL,
2037         mss);
2038 
2039     if (ajListGetLength(mss) > 1)
2040         ajWarn("ensMiscellaneoussetadaptorFetchByCode got more than one "
2041                "Ensembl Miscellaneous Sets for (UNIQUE) code '%S'.\n",
2042                code);
2043 
2044     ajListPop(mss, (void **) Pms);
2045 
2046     miscellaneoussetadaptorCacheInsert(msa, Pms);
2047 
2048     while (ajListPop(mss, (void **) &ms))
2049     {
2050         miscellaneoussetadaptorCacheInsert(msa, &ms);
2051 
2052         ensMiscellaneoussetDel(&ms);
2053     }
2054 
2055     ajListFree(&mss);
2056 
2057     ajStrDel(&constraint);
2058 
2059     return ajTrue;
2060 }
2061 
2062 
2063 
2064 
2065 /* @func ensMiscellaneoussetadaptorFetchByIdentifier **************************
2066 **
2067 ** Fetch an Ensembl Miscellaneous Set by its SQL database-internal identifier.
2068 **
2069 ** @cc Bio::EnsEMBL::DBSQL::MiscSetAdaptor::fetch_by_dbID
2070 ** @param [u] msa [EnsPMiscellaneoussetadaptor]
2071 ** Ensembl Miscellaneous Set Adaptor
2072 ** @param [r] identifier [ajuint] SQL database-internal identifier
2073 ** @param [wP] Pms [EnsPMiscellaneousset*] Ensembl Miscellaneous Set address
2074 **
2075 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2076 **
2077 ** @release 6.2.0
2078 ** @@
2079 ******************************************************************************/
2080 
ensMiscellaneoussetadaptorFetchByIdentifier(EnsPMiscellaneoussetadaptor msa,ajuint identifier,EnsPMiscellaneousset * Pms)2081 AjBool ensMiscellaneoussetadaptorFetchByIdentifier(
2082     EnsPMiscellaneoussetadaptor msa,
2083     ajuint identifier,
2084     EnsPMiscellaneousset *Pms)
2085 {
2086     AjBool result = AJFALSE;
2087 
2088     if (!msa)
2089         return ajFalse;
2090 
2091     if (!identifier)
2092         return ajFalse;
2093 
2094     if (!Pms)
2095         return ajFalse;
2096 
2097     *Pms = NULL;
2098 
2099     /*
2100     ** Initially, search the identifier cache.
2101     ** For any object returned by the AJAX Table the reference counter needs
2102     ** to be incremented manually.
2103     */
2104 
2105     if (!msa->CacheByIdentifier)
2106         miscellaneoussetadaptorCacheInit(msa);
2107 
2108     *Pms = (EnsPMiscellaneousset) ajTableFetchmodV(msa->CacheByIdentifier,
2109                                                    (const void *) &identifier);
2110 
2111     if (*Pms)
2112     {
2113         ensMiscellaneoussetNewRef(*Pms);
2114 
2115         return ajTrue;
2116     }
2117 
2118     /* For a cache miss query the database. */
2119 
2120     result = ensBaseadaptorFetchByIdentifier(
2121         ensMiscellaneoussetadaptorGetBaseadaptor(msa),
2122         identifier,
2123         (void **) Pms);
2124 
2125     miscellaneoussetadaptorCacheInsert(msa, Pms);
2126 
2127     return result;
2128 }
2129 
2130 
2131 
2132 
2133 /* @datasection [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature ******
2134 **
2135 ** @nam2rule Miscellaneousfeature Functions for manipulating
2136 ** Ensembl Miscellaneous Feature objects
2137 **
2138 ** @cc Bio::EnsEMBL::MiscFeature
2139 ** @cc CVS Revision: 1.19
2140 ** @cc CVS Tag: branch-ensembl-68
2141 **
2142 ******************************************************************************/
2143 
2144 
2145 
2146 
2147 /* @section constructors ******************************************************
2148 **
2149 ** All constructors return a new Ensembl Miscellaneous Feature by pointer.
2150 ** It is the responsibility of the user to first destroy any previous
2151 ** Miscellaneous Feature. The target pointer does not need to be initialised
2152 ** to NULL, but it is good programming practice to do so anyway.
2153 **
2154 ** @fdata [EnsPMiscellaneousfeature]
2155 **
2156 ** @nam3rule New Constructor
2157 ** @nam4rule Cpy Constructor with existing object
2158 ** @nam4rule Ini Constructor with initial value
2159 ** @nam4rule Ref Constructor by incrementing the reference counter
2160 **
2161 ** @argrule Cpy mf [const EnsPMiscellaneousfeature]
2162 ** Ensembl Miscellaneous Feature
2163 ** @argrule Ini mfa [EnsPMiscellaneousfeatureadaptor]
2164 ** Ensembl Miscellaneous Feature Adaptor
2165 ** @argrule Ini identifier [ajuint] SQL database-internal identifier
2166 ** @argrule Ini feature [EnsPFeature] Ensembl Feature
2167 ** @argrule Ref mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2168 **
2169 ** @valrule * [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature or NULL
2170 **
2171 ** @fcategory new
2172 ******************************************************************************/
2173 
2174 
2175 
2176 
2177 /* @func ensMiscellaneousfeatureNewCpy ****************************************
2178 **
2179 ** Object-based constructor function, which returns an independent object.
2180 **
2181 ** @param [r] mf [const EnsPMiscellaneousfeature]
2182 ** Ensembl Miscellaneous Feature
2183 **
2184 ** @return [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature or NULL
2185 **
2186 ** @release 6.4.0
2187 ** @@
2188 ******************************************************************************/
2189 
ensMiscellaneousfeatureNewCpy(const EnsPMiscellaneousfeature mf)2190 EnsPMiscellaneousfeature ensMiscellaneousfeatureNewCpy(
2191     const EnsPMiscellaneousfeature mf)
2192 {
2193     AjIList iter = NULL;
2194 
2195     EnsPAttribute attribute = NULL;
2196 
2197     EnsPMiscellaneousfeature pthis = NULL;
2198 
2199     EnsPMiscellaneousset ms = NULL;
2200 
2201     if (!mf)
2202         return NULL;
2203 
2204     AJNEW0(pthis);
2205 
2206     pthis->Use        = 1U;
2207     pthis->Identifier = mf->Identifier;
2208     pthis->Adaptor    = mf->Adaptor;
2209     pthis->Feature    = ensFeatureNewRef(mf->Feature);
2210 
2211     /* NOTE: Copy the AJAX List of Ensembl Attribute objects. */
2212 
2213     if (mf->Attributes && ajListGetLength(mf->Attributes))
2214     {
2215         pthis->Attributes = ajListNew();
2216 
2217         iter = ajListIterNew(mf->Attributes);
2218 
2219         while (!ajListIterDone(iter))
2220         {
2221             attribute = (EnsPAttribute) ajListIterGet(iter);
2222 
2223             ajListPushAppend(pthis->Attributes,
2224                              (void *) ensAttributeNewRef(attribute));
2225         }
2226 
2227         ajListIterDel(&iter);
2228     }
2229     else
2230         pthis->Attributes = NULL;
2231 
2232     /* NOTE: Copy the AJAX List of Ensembl Miscellaneous Set objects. */
2233 
2234     if (mf->Miscellaneoussets && ajListGetLength(mf->Miscellaneoussets))
2235     {
2236         pthis->Miscellaneoussets = ajListNew();
2237 
2238         iter = ajListIterNew(mf->Miscellaneoussets);
2239 
2240         while (!ajListIterDone(iter))
2241         {
2242             ms = (EnsPMiscellaneousset) ajListIterGet(iter);
2243 
2244             ajListPushAppend(pthis->Miscellaneoussets,
2245                              (void *) ensMiscellaneoussetNewRef(ms));
2246         }
2247 
2248         ajListIterDel(&iter);
2249     }
2250     else
2251         pthis->Miscellaneoussets = NULL;
2252 
2253     return pthis;
2254 }
2255 
2256 
2257 
2258 
2259 /* @func ensMiscellaneousfeatureNewIni ****************************************
2260 **
2261 ** Constructor for an Ensembl Miscellaneous Feature with initial values.
2262 **
2263 ** @cc Bio::EnsEMBL::Storable::new
2264 ** @param [u] mfa [EnsPMiscellaneousfeatureadaptor]
2265 ** Ensembl Miscellaneous Feature Adaptor
2266 ** @param [r] identifier [ajuint] SQL database-internal identifier
2267 ** @cc Bio::EnsEMBL::Feature::new
2268 ** @param [u] feature [EnsPFeature] Ensembl Feature
2269 ** @cc Bio::EnsEMBL::MiscFeature::new
2270 **
2271 ** @return [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature or NULL
2272 **
2273 ** @release 6.4.0
2274 ** @@
2275 ******************************************************************************/
2276 
ensMiscellaneousfeatureNewIni(EnsPMiscellaneousfeatureadaptor mfa,ajuint identifier,EnsPFeature feature)2277 EnsPMiscellaneousfeature ensMiscellaneousfeatureNewIni(
2278     EnsPMiscellaneousfeatureadaptor mfa,
2279     ajuint identifier,
2280     EnsPFeature feature)
2281 {
2282     EnsPMiscellaneousfeature mf = NULL;
2283 
2284     if (!feature)
2285         return NULL;
2286 
2287     AJNEW0(mf);
2288 
2289     mf->Use               = 1U;
2290     mf->Identifier        = identifier;
2291     mf->Adaptor           = mfa;
2292     mf->Feature           = ensFeatureNewRef(feature);
2293     mf->Attributes        = NULL;
2294     mf->Miscellaneoussets = NULL;
2295 
2296     return mf;
2297 }
2298 
2299 
2300 
2301 
2302 /* @func ensMiscellaneousfeatureNewRef ****************************************
2303 **
2304 ** Ensembl Object referencing function, which returns a pointer to the
2305 ** Ensembl Object passed in and increases its reference count.
2306 **
2307 ** @param [u] mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2308 **
2309 ** @return [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature or NULL
2310 **
2311 ** @release 6.2.0
2312 ** @@
2313 ******************************************************************************/
2314 
ensMiscellaneousfeatureNewRef(EnsPMiscellaneousfeature mf)2315 EnsPMiscellaneousfeature ensMiscellaneousfeatureNewRef(
2316     EnsPMiscellaneousfeature mf)
2317 {
2318     if (!mf)
2319         return NULL;
2320 
2321     mf->Use++;
2322 
2323     return mf;
2324 }
2325 
2326 
2327 
2328 
2329 /* @section destructors *******************************************************
2330 **
2331 ** Destruction destroys all internal data structures and frees the memory
2332 ** allocated for an Ensembl Miscellaneous Feature object.
2333 **
2334 ** @fdata [EnsPMiscellaneousfeature]
2335 **
2336 ** @nam3rule Del Destroy (free) an Ensembl Miscellaneous Feature
2337 **
2338 ** @argrule * Pmf [EnsPMiscellaneousfeature*]
2339 ** Ensembl Miscellaneous Feature address
2340 **
2341 ** @valrule * [void]
2342 **
2343 ** @fcategory delete
2344 ******************************************************************************/
2345 
2346 
2347 
2348 
2349 /* @func ensMiscellaneousfeatureDel *******************************************
2350 **
2351 ** Default destructor for an Ensembl Miscellaneous Feature.
2352 **
2353 ** @param [d] Pmf [EnsPMiscellaneousfeature*]
2354 ** Ensembl Miscellaneous Feature address
2355 **
2356 ** @return [void]
2357 **
2358 ** @release 6.2.0
2359 ** @@
2360 ******************************************************************************/
2361 
ensMiscellaneousfeatureDel(EnsPMiscellaneousfeature * Pmf)2362 void ensMiscellaneousfeatureDel(EnsPMiscellaneousfeature *Pmf)
2363 {
2364     EnsPAttribute attribute = NULL;
2365 
2366     EnsPMiscellaneousset ms = NULL;
2367 
2368     EnsPMiscellaneousfeature pthis = NULL;
2369 
2370 
2371     if (!Pmf)
2372         return;
2373 
2374 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
2375     if (ajDebugTest("ensMiscellaneousfeatureDel"))
2376     {
2377         ajDebug("ensMiscellaneousfeatureDel\n"
2378                 "  *Pmf %p\n",
2379                 *Pmf);
2380 
2381         ensMiscellaneousfeatureTrace(*Pmf, 1);
2382     }
2383 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
2384 
2385     if (!(pthis = *Pmf) || --pthis->Use)
2386     {
2387         *Pmf = NULL;
2388 
2389         return;
2390     }
2391 
2392     ensFeatureDel(&pthis->Feature);
2393 
2394     /* Clear and free the AJAX List of Ensembl Attribute objects. */
2395 
2396     while (ajListPop(pthis->Attributes, (void **) &attribute))
2397         ensAttributeDel(&attribute);
2398 
2399     ajListFree(&pthis->Attributes);
2400 
2401     /* Clear and free the AJAX List of Ensembl Miscellaneous Set objects. */
2402 
2403     while (ajListPop(pthis->Miscellaneoussets, (void **) &ms))
2404         ensMiscellaneoussetDel(&ms);
2405 
2406     ajListFree(&pthis->Miscellaneoussets);
2407 
2408     ajMemFree((void **) Pmf);
2409 
2410     return;
2411 }
2412 
2413 
2414 
2415 
2416 /* @section member retrieval **************************************************
2417 **
2418 ** Functions for returning members of an Ensembl Miscellaneous Feature object.
2419 **
2420 ** @fdata [EnsPMiscellaneousfeature]
2421 **
2422 ** @nam3rule Get Return Miscellaneous Feature attribute(s)
2423 ** @nam4rule Adaptor Return the Ensembl Miscellaneous Feature Adaptor
2424 ** @nam4rule Attributes Return all Ensembl Attribute objects
2425 ** @nam4rule Feature Return the Ensembl Feature
2426 ** @nam4rule Identifier Return the SQL database-internal identifier
2427 ** @nam4rule Miscellaneoussets Return all Ensembl Miscellaneous Set objects
2428 **
2429 ** @argrule * mf [const EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2430 **
2431 ** @valrule Adaptor [EnsPMiscellaneousfeatureadaptor]
2432 ** Ensembl Miscellaneous Feature Adaptor or NULL
2433 ** @valrule Attributes [const AjPList]
2434 ** AJAX List of Ensembl Attribute objects or NULL
2435 ** @valrule Feature [EnsPFeature] Ensembl Feature or NULL
2436 ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U
2437 ** @valrule Miscellaneoussets [const AjPList]
2438 ** AJAX List of Ensembl Miscellaneous Set objects or NULL
2439 **
2440 ** @fcategory use
2441 ******************************************************************************/
2442 
2443 
2444 
2445 
2446 /* @func ensMiscellaneousfeatureGetAdaptor ************************************
2447 **
2448 ** Get the Ensembl Miscellaneous Feature Adaptor member of an
2449 ** Ensembl Miscellaneous Feature.
2450 **
2451 ** @cc Bio::EnsEMBL::Storable::adaptor
2452 ** @param [r] mf [const EnsPMiscellaneousfeature]
2453 ** Ensembl Miscellaneous Feature
2454 **
2455 ** @return [EnsPMiscellaneousfeatureadaptor]
2456 ** Ensembl Miscellaneous Feature Adaptor or NULL
2457 **
2458 ** @release 6.2.0
2459 ** @@
2460 ******************************************************************************/
2461 
ensMiscellaneousfeatureGetAdaptor(const EnsPMiscellaneousfeature mf)2462 EnsPMiscellaneousfeatureadaptor ensMiscellaneousfeatureGetAdaptor(
2463     const EnsPMiscellaneousfeature mf)
2464 {
2465     return (mf) ? mf->Adaptor : NULL;
2466 }
2467 
2468 
2469 
2470 
2471 /* @func ensMiscellaneousfeatureGetAttributes *********************************
2472 **
2473 ** Get all Ensembl Attribute objects of an Ensembl Miscellaneous Feature.
2474 **
2475 ** @cc Bio::EnsEMBL::MiscFeature::get_all_Attributes
2476 ** @param [r] mf [const EnsPMiscellaneousfeature]
2477 ** Ensembl Miscellaneous Feature
2478 **
2479 ** @return [const AjPList] AJAX List of Ensembl Attribute objects or NULL
2480 **
2481 ** @release 6.2.0
2482 ** @@
2483 ******************************************************************************/
2484 
ensMiscellaneousfeatureGetAttributes(const EnsPMiscellaneousfeature mf)2485 const AjPList ensMiscellaneousfeatureGetAttributes(
2486     const EnsPMiscellaneousfeature mf)
2487 {
2488     return (mf) ? mf->Attributes : NULL;
2489 }
2490 
2491 
2492 
2493 
2494 /* @func ensMiscellaneousfeatureGetFeature ************************************
2495 **
2496 ** Get the Ensembl Feature member of an Ensembl Miscellaneous Feature.
2497 **
2498 ** @param [r] mf [const EnsPMiscellaneousfeature]
2499 ** Ensembl Miscellaneous Feature
2500 **
2501 ** @return [EnsPFeature] Ensembl Feature or NULL
2502 **
2503 ** @release 6.2.0
2504 ** @@
2505 ******************************************************************************/
2506 
ensMiscellaneousfeatureGetFeature(const EnsPMiscellaneousfeature mf)2507 EnsPFeature ensMiscellaneousfeatureGetFeature(
2508     const EnsPMiscellaneousfeature mf)
2509 {
2510     return (mf) ? mf->Feature : NULL;
2511 }
2512 
2513 
2514 
2515 
2516 /* @func ensMiscellaneousfeatureGetIdentifier *********************************
2517 **
2518 ** Get the SQL database-internal identifier member of an
2519 ** Ensembl Miscellaneous Feature.
2520 **
2521 ** @cc Bio::EnsEMBL::Storable::dbID
2522 ** @param [r] mf [const EnsPMiscellaneousfeature]
2523 ** Ensembl Miscellaneous Feature
2524 **
2525 ** @return [ajuint] SQL database-internal identifier or 0U
2526 **
2527 ** @release 6.2.0
2528 ** @@
2529 ******************************************************************************/
2530 
ensMiscellaneousfeatureGetIdentifier(const EnsPMiscellaneousfeature mf)2531 ajuint ensMiscellaneousfeatureGetIdentifier(
2532     const EnsPMiscellaneousfeature mf)
2533 {
2534     return (mf) ? mf->Identifier : 0U;
2535 }
2536 
2537 
2538 
2539 
2540 /* @func ensMiscellaneousfeatureGetMiscellaneoussets **************************
2541 **
2542 ** Get all Ensembl Miscellaneous Sets of an Ensembl Miscellaneous Feature.
2543 **
2544 ** @cc Bio::EnsEMBL::MiscFeature::get_all_MiscSets
2545 ** @param [r] mf [const EnsPMiscellaneousfeature]
2546 ** Ensembl Miscellaneous Feature
2547 **
2548 ** @return [const AjPList] AJAX List of Ensembl Miscellaneous Sets or NULL
2549 **
2550 ** @release 6.2.0
2551 ** @@
2552 ******************************************************************************/
2553 
ensMiscellaneousfeatureGetMiscellaneoussets(const EnsPMiscellaneousfeature mf)2554 const AjPList ensMiscellaneousfeatureGetMiscellaneoussets(
2555     const EnsPMiscellaneousfeature mf)
2556 {
2557     return (mf) ? mf->Miscellaneoussets : NULL;
2558 }
2559 
2560 
2561 
2562 
2563 /* @section modifiers *********************************************************
2564 **
2565 ** Functions for assigning members of an Ensembl Miscellaneous Feature object.
2566 **
2567 ** @fdata [EnsPMiscellaneousfeature]
2568 **
2569 ** @nam3rule Set Set one member of a Miscellaneous Feature
2570 ** @nam4rule Adaptor Set the Ensembl Miscellaneous Feature Adaptor
2571 ** @nam4rule Identifier Set the SQL database-internal identifier
2572 ** @nam4rule Feature Set the Ensembl Feature
2573 **
2574 ** @argrule * mf [EnsPMiscellaneousfeature]
2575 ** Ensembl Miscellaneous Feature object
2576 ** @argrule Adaptor mfa [EnsPMiscellaneousfeatureadaptor]
2577 ** Ensembl Miscellaneous Feature Adaptor
2578 ** @argrule Feature feature [EnsPFeature] Ensembl Feature
2579 ** @argrule Identifier identifier [ajuint] SQL database-internal identifier
2580 **
2581 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2582 **
2583 ** @fcategory modify
2584 ******************************************************************************/
2585 
2586 
2587 
2588 
2589 /* @func ensMiscellaneousfeatureSetAdaptor ************************************
2590 **
2591 ** Set the Ensembl Miscellaneous Feature Adaptor member of an
2592 ** Ensembl Miscellaneous Feature.
2593 **
2594 ** @cc Bio::EnsEMBL::Storable::adaptor
2595 ** @param [u] mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2596 ** @param [u] mfa [EnsPMiscellaneousfeatureadaptor]
2597 ** Ensembl Miscellaneous Feature Adaptor
2598 **
2599 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2600 **
2601 ** @release 6.2.0
2602 ** @@
2603 ******************************************************************************/
2604 
ensMiscellaneousfeatureSetAdaptor(EnsPMiscellaneousfeature mf,EnsPMiscellaneousfeatureadaptor mfa)2605 AjBool ensMiscellaneousfeatureSetAdaptor(
2606     EnsPMiscellaneousfeature mf,
2607     EnsPMiscellaneousfeatureadaptor mfa)
2608 {
2609     if (!mf)
2610         return ajFalse;
2611 
2612     mf->Adaptor = mfa;
2613 
2614     return ajTrue;
2615 }
2616 
2617 
2618 
2619 
2620 /* @func ensMiscellaneousfeatureSetFeature ************************************
2621 **
2622 ** Set the Ensembl Feature member of an Ensembl Miscellaneous Feature.
2623 **
2624 ** @param [u] mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2625 ** @param [u] feature [EnsPFeature] Ensembl Feature
2626 **
2627 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2628 **
2629 ** @release 6.2.0
2630 ** @@
2631 ******************************************************************************/
2632 
ensMiscellaneousfeatureSetFeature(EnsPMiscellaneousfeature mf,EnsPFeature feature)2633 AjBool ensMiscellaneousfeatureSetFeature(
2634     EnsPMiscellaneousfeature mf,
2635     EnsPFeature feature)
2636 {
2637     if (!mf)
2638         return ajFalse;
2639 
2640     ensFeatureDel(&mf->Feature);
2641 
2642     mf->Feature = ensFeatureNewRef(feature);
2643 
2644     return ajTrue;
2645 }
2646 
2647 
2648 
2649 
2650 /* @func ensMiscellaneousfeatureSetIdentifier *********************************
2651 **
2652 ** Set the SQL database-internal identifier member of an
2653 ** Ensembl Miscellaneous Feature.
2654 **
2655 ** @cc Bio::EnsEMBL::Storable::dbID
2656 ** @param [u] mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2657 ** @param [r] identifier [ajuint] SQL database-internal identifier
2658 **
2659 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2660 **
2661 ** @release 6.2.0
2662 ** @@
2663 ******************************************************************************/
2664 
ensMiscellaneousfeatureSetIdentifier(EnsPMiscellaneousfeature mf,ajuint identifier)2665 AjBool ensMiscellaneousfeatureSetIdentifier(
2666     EnsPMiscellaneousfeature mf,
2667     ajuint identifier)
2668 {
2669     if (!mf)
2670         return ajFalse;
2671 
2672     mf->Identifier = identifier;
2673 
2674     return ajTrue;
2675 }
2676 
2677 
2678 
2679 
2680 /* @section member addition ***************************************************
2681 **
2682 ** Functions for adding members to an Ensembl Miscellaneous Feature object.
2683 **
2684 ** @fdata [EnsPMiscellaneousfeature]
2685 **
2686 ** @nam3rule Add Add one object to an Ensembl Miscellaneous Feature
2687 ** @nam4rule Attribute Add an Ensembl Attribute
2688 ** @nam4rule Miscellaneousset Add an Ensembl Miscellaneous Set
2689 **
2690 ** @argrule * mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2691 ** @argrule Attribute attribute [EnsPAttribute] Ensembl Attribute
2692 ** @argrule Miscellaneousset ms [EnsPMiscellaneousset]
2693 ** Ensembl Miscellaneous Set
2694 **
2695 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2696 **
2697 ** @fcategory modify
2698 ******************************************************************************/
2699 
2700 
2701 
2702 
2703 /* @func ensMiscellaneousfeatureAddAttribute **********************************
2704 **
2705 ** Add an Ensembl Attribute to an Ensembl Miscellaneous Feature.
2706 **
2707 ** @cc Bio::EnsEMBL::MiscFeature::add_Attribute
2708 ** @param [u] mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2709 ** @param [u] attribute [EnsPAttribute] Ensembl Attribute
2710 **
2711 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2712 **
2713 ** @release 6.2.0
2714 ** @@
2715 ******************************************************************************/
2716 
ensMiscellaneousfeatureAddAttribute(EnsPMiscellaneousfeature mf,EnsPAttribute attribute)2717 AjBool ensMiscellaneousfeatureAddAttribute(
2718     EnsPMiscellaneousfeature mf,
2719     EnsPAttribute attribute)
2720 {
2721     if (!mf)
2722         return ajFalse;
2723 
2724     if (!attribute)
2725         return ajFalse;
2726 
2727     if (!mf->Attributes)
2728         mf->Attributes = ajListNew();
2729 
2730     ajListPushAppend(mf->Attributes, (void *) ensAttributeNewRef(attribute));
2731 
2732     return ajTrue;
2733 }
2734 
2735 
2736 
2737 
2738 /* @func ensMiscellaneousfeatureAddMiscellaneousset ***************************
2739 **
2740 ** Add an Ensembl Miscellaneous Set to an Ensembl Miscellaneous Feature.
2741 **
2742 ** @cc Bio::EnsEMBL::MiscFeature::add_MiscSet
2743 ** @param [u] mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2744 ** @param [u] ms [EnsPMiscellaneousset] Ensembl Miscellaneous Set
2745 **
2746 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2747 **
2748 ** @release 6.2.0
2749 ** @@
2750 ******************************************************************************/
2751 
ensMiscellaneousfeatureAddMiscellaneousset(EnsPMiscellaneousfeature mf,EnsPMiscellaneousset ms)2752 AjBool ensMiscellaneousfeatureAddMiscellaneousset(
2753     EnsPMiscellaneousfeature mf,
2754     EnsPMiscellaneousset ms)
2755 {
2756     if (!mf)
2757         return ajFalse;
2758 
2759     if (!ms)
2760         return ajFalse;
2761 
2762     if (!mf->Miscellaneoussets)
2763         mf->Miscellaneoussets = ajListNew();
2764 
2765     ajListPushAppend(mf->Miscellaneoussets,
2766                      (void *) ensMiscellaneoussetNewRef(ms));
2767 
2768     return ajTrue;
2769 }
2770 
2771 
2772 
2773 
2774 /* @section debugging *********************************************************
2775 **
2776 ** Functions for reporting of an Ensembl Miscellaneous Feature object.
2777 **
2778 ** @fdata [EnsPMiscellaneousfeature]
2779 **
2780 ** @nam3rule Trace Report Ensembl Miscellaneous Feature members to debug file
2781 **
2782 ** @argrule Trace mf [const EnsPMiscellaneousfeature]
2783 ** Ensembl Miscellaneous Feature
2784 ** @argrule Trace level [ajuint] Indentation level
2785 **
2786 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2787 **
2788 ** @fcategory misc
2789 ******************************************************************************/
2790 
2791 
2792 
2793 
2794 /* @func ensMiscellaneousfeatureTrace *****************************************
2795 **
2796 ** Trace an Ensembl Miscellaneous Feature.
2797 **
2798 ** @param [r] mf [const EnsPMiscellaneousfeature]
2799 ** Ensembl Miscellaneous Feature
2800 ** @param [r] level [ajuint] Indentation level
2801 **
2802 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2803 **
2804 ** @release 6.2.0
2805 ** @@
2806 ******************************************************************************/
2807 
ensMiscellaneousfeatureTrace(const EnsPMiscellaneousfeature mf,ajuint level)2808 AjBool ensMiscellaneousfeatureTrace(const EnsPMiscellaneousfeature mf,
2809                                     ajuint level)
2810 {
2811     AjPStr indent = NULL;
2812 
2813     if (!mf)
2814         return ajFalse;
2815 
2816     indent = ajStrNew();
2817 
2818     ajStrAppendCountK(&indent, ' ', level * 2);
2819 
2820     ajDebug("%SensMiscellaneousfeatureTrace %p\n"
2821             "%S  Use %u\n"
2822             "%S  Identifier %u\n"
2823             "%S  Adaptor %p\n"
2824             "%S  Feature %p\n"
2825             "%S  Attributes %p\n"
2826             "%S  Miscellaneoussets %p\n",
2827             indent, mf,
2828             indent, mf->Use,
2829             indent, mf->Identifier,
2830             indent, mf->Adaptor,
2831             indent, mf->Feature,
2832             indent, mf->Attributes,
2833             indent, mf->Miscellaneoussets);
2834 
2835     ensFeatureTrace(mf->Feature, level + 1);
2836 
2837     ajStrDel(&indent);
2838 
2839     return ajTrue;
2840 }
2841 
2842 
2843 
2844 
2845 /* @section calculate *********************************************************
2846 **
2847 ** Functions for calculating information from an
2848 ** Ensembl Miscellaneous Feature object.
2849 **
2850 ** @fdata [EnsPMiscellaneousfeature]
2851 **
2852 ** @nam3rule Calculate Calculate Ensembl Miscellaneous Feature information
2853 ** @nam4rule Memsize Calculate the memory size in bytes
2854 **
2855 ** @argrule * mf [const EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2856 **
2857 ** @valrule Memsize [size_t] Memory size in bytes or 0
2858 **
2859 ** @fcategory misc
2860 ******************************************************************************/
2861 
2862 
2863 
2864 
2865 /* @func ensMiscellaneousfeatureCalculateMemsize ******************************
2866 **
2867 ** Calculate the memory size in bytes of an Ensembl Miscellaneous Feature.
2868 **
2869 ** @param [r] mf [const EnsPMiscellaneousfeature]
2870 ** Ensembl Miscellaneous Feature
2871 **
2872 ** @return [size_t] Memory size in bytes or 0
2873 **
2874 ** @release 6.4.0
2875 ** @@
2876 ******************************************************************************/
2877 
ensMiscellaneousfeatureCalculateMemsize(const EnsPMiscellaneousfeature mf)2878 size_t ensMiscellaneousfeatureCalculateMemsize(
2879     const EnsPMiscellaneousfeature mf)
2880 {
2881     size_t size = 0;
2882 
2883     AjIList iter = NULL;
2884 
2885     EnsPAttribute attribute = NULL;
2886 
2887     EnsPMiscellaneousset ms = NULL;
2888 
2889     if (!mf)
2890         return 0;
2891 
2892     size += sizeof (EnsOMiscellaneousfeature);
2893 
2894     size += ensFeatureCalculateMemsize(mf->Feature);
2895 
2896     if (mf->Attributes)
2897     {
2898         iter = ajListIterNewread(mf->Attributes);
2899 
2900         while (!ajListIterDone(iter))
2901         {
2902             attribute = (EnsPAttribute) ajListIterGet(iter);
2903 
2904             size += ensAttributeCalculateMemsize(attribute);
2905         }
2906 
2907         ajListIterDel(&iter);
2908     }
2909 
2910     if (mf->Miscellaneoussets)
2911     {
2912         iter = ajListIterNewread(mf->Miscellaneoussets);
2913 
2914         while (!ajListIterDone(iter))
2915         {
2916             ms = (EnsPMiscellaneousset) ajListIterGet(iter);
2917 
2918             size += ensMiscellaneoussetCalculateMemsize(ms);
2919         }
2920 
2921         ajListIterDel(&iter);
2922     }
2923 
2924     return size;
2925 }
2926 
2927 
2928 
2929 
2930 /* @section fetch *************************************************************
2931 **
2932 ** Functions for fetching values of an Ensembl Miscellaneous Feature object.
2933 **
2934 ** @fdata [EnsPMiscellaneousfeature]
2935 **
2936 ** @nam3rule Fetch Fetch Ensembl Miscellaneous Feature values
2937 ** @nam4rule All Fetch all objects
2938 ** @nam5rule Attributes Fetch all Ensembl Attribute objects
2939 ** @nam5rule Miscellaneoussets Fetch all Ensembl Miscellaneous Set objects
2940 **
2941 ** @argrule AllAttributes mf [EnsPMiscellaneousfeature]
2942 ** Ensembl Miscellaneous Feature
2943 ** @argrule AllAttributes code [const AjPStr]
2944 ** Ensembl Attribute code
2945 ** @argrule AllAttributes attributes [AjPList]
2946 ** AJAX List of Ensembl Attribute objects
2947 ** @argrule AllMiscellaneoussets mf [EnsPMiscellaneousfeature]
2948 ** Ensembl Miscellaneous Feature
2949 ** @argrule AllMiscellaneoussets code [const AjPStr]
2950 ** Ensembl Miscellaneous Set code
2951 ** @argrule AllMiscellaneoussets mss [AjPList]
2952 ** AJAX List of Ensembl Miscellaneous Set objects
2953 **
2954 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2955 **
2956 ** @fcategory misc
2957 ******************************************************************************/
2958 
2959 
2960 
2961 
2962 /* @func ensMiscellaneousfeatureFetchAllAttributes ****************************
2963 **
2964 ** Fetch all Ensembl Attribute objects of an Ensembl Miscellaneous Feature.
2965 **
2966 ** The caller is responsible for deleting the Ensembl Attribute objects
2967 ** before deleting the AJAX List.
2968 **
2969 ** @cc Bio::EnsEMBL::MiscFeature::get_all_Attributes
2970 ** @param [u] mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
2971 ** @param [rN] code [const AjPStr] Ensembl Attribute code
2972 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
2973 **
2974 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2975 **
2976 ** @release 6.2.0
2977 ** @@
2978 ******************************************************************************/
2979 
ensMiscellaneousfeatureFetchAllAttributes(EnsPMiscellaneousfeature mf,const AjPStr code,AjPList attributes)2980 AjBool ensMiscellaneousfeatureFetchAllAttributes(
2981     EnsPMiscellaneousfeature mf,
2982     const AjPStr code,
2983     AjPList attributes)
2984 {
2985     AjIList iter = NULL;
2986 
2987     EnsPAttribute attribute = NULL;
2988 
2989     if (!mf)
2990         return ajFalse;
2991 
2992     if (!attributes)
2993         return ajFalse;
2994 
2995     iter = ajListIterNewread(mf->Attributes);
2996 
2997     while (!ajListIterDone(iter))
2998     {
2999         attribute = (EnsPAttribute) ajListIterGet(iter);
3000 
3001         if (code && ajStrGetLen(code))
3002         {
3003             if (ajStrMatchCaseS(code, ensAttributeGetCode(attribute)))
3004                 ajListPushAppend(attributes,
3005                                  (void *) ensAttributeNewRef(attribute));
3006         }
3007         else
3008             ajListPushAppend(attributes,
3009                              (void *) ensAttributeNewRef(attribute));
3010     }
3011 
3012     ajListIterDel(&iter);
3013 
3014     return ajTrue;
3015 }
3016 
3017 
3018 
3019 
3020 /* @func ensMiscellaneousfeatureFetchAllMiscellaneoussets *********************
3021 **
3022 ** Fetch all Ensembl Miscellaneous Set objects of an
3023 ** Ensembl Miscellaneous Feature.
3024 **
3025 ** The caller is responsible for deleting the Ensembl Miscellaneous Set objects
3026 ** before deleting the AJAX List.
3027 **
3028 ** @cc Bio::EnsEMBL::MiscFeature::get_all_MiscSets
3029 ** @param [u] mf [EnsPMiscellaneousfeature] Ensembl Miscellaneous Feature
3030 ** @param [rN] code [const AjPStr] Ensembl Miscellaneous Set code
3031 ** @param [u] mss [AjPList] AJAX List of Ensembl Miscellanaeous Set objects
3032 **
3033 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3034 **
3035 ** @release 6.2.0
3036 ** @@
3037 ******************************************************************************/
3038 
ensMiscellaneousfeatureFetchAllMiscellaneoussets(EnsPMiscellaneousfeature mf,const AjPStr code,AjPList mss)3039 AjBool ensMiscellaneousfeatureFetchAllMiscellaneoussets(
3040     EnsPMiscellaneousfeature mf,
3041     const AjPStr code,
3042     AjPList mss)
3043 {
3044     AjIList iter = NULL;
3045 
3046     EnsPMiscellaneousset ms = NULL;
3047 
3048     if (!mf)
3049         return ajFalse;
3050 
3051     if (!mss)
3052         return ajFalse;
3053 
3054     iter = ajListIterNewread(mf->Miscellaneoussets);
3055 
3056     while (!ajListIterDone(iter))
3057     {
3058         ms = (EnsPMiscellaneousset) ajListIterGet(iter);
3059 
3060         if (code && ajStrGetLen(code))
3061         {
3062             if (ajStrMatchCaseS(code, ensMiscellaneoussetGetCode(ms)))
3063                 ajListPushAppend(mss,
3064                                  (void *) ensMiscellaneoussetNewRef(ms));
3065         }
3066         else
3067             ajListPushAppend(mss, (void *) ensMiscellaneoussetNewRef(ms));
3068     }
3069 
3070     ajListIterDel(&iter);
3071 
3072     return ajTrue;
3073 }
3074 
3075 
3076 
3077 
3078 /* @datasection [AjPList] AJAX List *******************************************
3079 **
3080 ** @nam2rule List Functions for manipulating AJAX List objects
3081 **
3082 ******************************************************************************/
3083 
3084 
3085 
3086 
3087 /* @funcstatic listMiscellaneousfeatureCompareEndAscending ********************
3088 **
3089 ** AJAX List of Ensembl Miscellaneous Feature objects comparison function to
3090 ** sort by Ensembl Feature end coordinate in ascending order.
3091 **
3092 ** @param [r] item1 [const void*] Ensembl Miscellaneous Feature address 1
3093 ** @param [r] item2 [const void*] Ensembl Miscellaneous Feature address 2
3094 ** @see ajListSort
3095 **
3096 ** @return [int] The comparison function returns an integer less than,
3097 **               equal to, or greater than zero if the first argument is
3098 **               considered to be respectively less than, equal to, or
3099 **               greater than the second.
3100 **
3101 ** @release 6.4.0
3102 ** @@
3103 ******************************************************************************/
3104 
listMiscellaneousfeatureCompareEndAscending(const void * item1,const void * item2)3105 static int listMiscellaneousfeatureCompareEndAscending(
3106     const void *item1,
3107     const void *item2)
3108 {
3109     EnsPMiscellaneousfeature mf1 = *(EnsOMiscellaneousfeature *const *) item1;
3110     EnsPMiscellaneousfeature mf2 = *(EnsOMiscellaneousfeature *const *) item2;
3111 
3112 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3113     if (ajDebugTest("listMiscellaneousfeatureCompareEndAscending"))
3114         ajDebug("listMiscellaneousfeatureCompareEndAscending\n"
3115                 "  mf1 %p\n"
3116                 "  mf2 %p\n",
3117                 mf1,
3118                 mf2);
3119 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3120 
3121     /* Sort empty values towards the end of the AJAX List. */
3122 
3123     if (mf1 && (!mf2))
3124         return -1;
3125 
3126     if ((!mf1) && (!mf2))
3127         return 0;
3128 
3129     if ((!mf1) && mf2)
3130         return +1;
3131 
3132     return ensFeatureCompareEndAscending(mf1->Feature, mf2->Feature);
3133 }
3134 
3135 
3136 
3137 
3138 /* @funcstatic listMiscellaneousfeatureCompareEndDescending *******************
3139 **
3140 ** AJAX List of Ensembl Miscellaneous Feature objects comparison function to
3141 ** sort by Ensembl Feature end coordinate in descending order.
3142 **
3143 ** @param [r] item1 [const void*] Ensembl Miscellaneous Feature address 1
3144 ** @param [r] item2 [const void*] Ensembl Miscellaneous Feature address 2
3145 ** @see ajListSort
3146 **
3147 ** @return [int] The comparison function returns an integer less than,
3148 **               equal to, or greater than zero if the first argument is
3149 **               considered to be respectively less than, equal to, or
3150 **               greater than the second.
3151 **
3152 ** @release 6.4.0
3153 ** @@
3154 ******************************************************************************/
3155 
listMiscellaneousfeatureCompareEndDescending(const void * item1,const void * item2)3156 static int listMiscellaneousfeatureCompareEndDescending(
3157     const void *item1,
3158     const void *item2)
3159 {
3160     EnsPMiscellaneousfeature mf1 = *(EnsOMiscellaneousfeature *const *) item1;
3161     EnsPMiscellaneousfeature mf2 = *(EnsOMiscellaneousfeature *const *) item2;
3162 
3163 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3164     if (ajDebugTest("listMiscellaneousfeatureCompareEndDescending"))
3165         ajDebug("listMiscellaneousfeatureCompareEndDescending\n"
3166                 "  mf1 %p\n"
3167                 "  mf2 %p\n",
3168                 mf1,
3169                 mf2);
3170 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3171 
3172     /* Sort empty values towards the end of the AJAX List. */
3173 
3174     if (mf1 && (!mf2))
3175         return -1;
3176 
3177     if ((!mf1) && (!mf2))
3178         return 0;
3179 
3180     if ((!mf1) && mf2)
3181         return +1;
3182 
3183     return ensFeatureCompareEndDescending(mf1->Feature, mf2->Feature);
3184 }
3185 
3186 
3187 
3188 
3189 /* @funcstatic listMiscellaneousfeatureCompareIdentifierAscending *************
3190 **
3191 ** AJAX List of Ensembl Miscellaneous Feature objects comparison function to
3192 ** sort by identifier member in ascending order.
3193 **
3194 ** @param [r] item1 [const void*] Ensembl Miscellaneous Feature address 1
3195 ** @param [r] item2 [const void*] Ensembl Miscellaneous Feature address 2
3196 ** @see ajListSort
3197 **
3198 ** @return [int] The comparison function returns an integer less than,
3199 **               equal to, or greater than zero if the first argument is
3200 **               considered to be respectively less than, equal to, or
3201 **               greater than the second.
3202 **
3203 ** @release 6.4.0
3204 ** @@
3205 ******************************************************************************/
3206 
listMiscellaneousfeatureCompareIdentifierAscending(const void * item1,const void * item2)3207 static int listMiscellaneousfeatureCompareIdentifierAscending(
3208     const void *item1,
3209     const void *item2)
3210 {
3211     EnsPMiscellaneousfeature mf1 = *(EnsOMiscellaneousfeature *const *) item1;
3212     EnsPMiscellaneousfeature mf2 = *(EnsOMiscellaneousfeature *const *) item2;
3213 
3214 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3215     if (ajDebugTest("listMiscellaneousfeatureCompareIdentifierAscending"))
3216         ajDebug("listMiscellaneousfeatureCompareIdentifierAscending\n"
3217                 "  mf1 %p\n"
3218                 "  mf2 %p\n",
3219                 mf1,
3220                 mf2);
3221 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3222 
3223     /* Sort empty values towards the end of the AJAX List. */
3224 
3225     if (mf1 && (!mf2))
3226         return -1;
3227 
3228     if ((!mf1) && (!mf2))
3229         return 0;
3230 
3231     if ((!mf1) && mf2)
3232         return +1;
3233 
3234     if (mf1->Identifier < mf2->Identifier)
3235         return -1;
3236 
3237     if (mf1->Identifier > mf2->Identifier)
3238         return +1;
3239 
3240     return 0;
3241 }
3242 
3243 
3244 
3245 
3246 /* @funcstatic listMiscellaneousfeatureCompareStartAscending ******************
3247 **
3248 ** AJAX List of Ensembl Miscellaneous Feature objects comparison function to
3249 ** sort by Ensembl Feature start coordinate in ascending order.
3250 **
3251 ** @param [r] item1 [const void*] Ensembl Miscellaneous Feature address 1
3252 ** @param [r] item2 [const void*] Ensembl Miscellaneous Feature address 2
3253 ** @see ajListSort
3254 **
3255 ** @return [int] The comparison function returns an integer less than,
3256 **               equal to, or greater than zero if the first argument is
3257 **               considered to be respectively less than, equal to, or
3258 **               greater than the second.
3259 **
3260 ** @release 6.4.0
3261 ** @@
3262 ******************************************************************************/
3263 
listMiscellaneousfeatureCompareStartAscending(const void * item1,const void * item2)3264 static int listMiscellaneousfeatureCompareStartAscending(
3265     const void *item1,
3266     const void *item2)
3267 {
3268     EnsPMiscellaneousfeature mf1 = *(EnsOMiscellaneousfeature *const *) item1;
3269     EnsPMiscellaneousfeature mf2 = *(EnsOMiscellaneousfeature *const *) item2;
3270 
3271 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3272     if (ajDebugTest("listMiscellaneousfeatureCompareStartAscending"))
3273         ajDebug("listMiscellaneousfeatureCompareStartAscending\n"
3274                 "  mf1 %p\n"
3275                 "  mf2 %p\n",
3276                 mf1,
3277                 mf2);
3278 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3279 
3280     /* Sort empty values towards the end of the AJAX List. */
3281 
3282     if (mf1 && (!mf2))
3283         return -1;
3284 
3285     if ((!mf1) && (!mf2))
3286         return 0;
3287 
3288     if ((!mf1) && mf2)
3289         return +1;
3290 
3291     return ensFeatureCompareStartAscending(mf1->Feature, mf2->Feature);
3292 }
3293 
3294 
3295 
3296 
3297 /* @funcstatic listMiscellaneousfeatureCompareStartDescending *****************
3298 **
3299 ** AJAX List of Ensembl Miscellaneous Feature objects comparison function to
3300 ** sort by Ensembl Feature start coordinate in descending order.
3301 **
3302 ** @param [r] item1 [const void*] Ensembl Miscellaneous Feature address 1
3303 ** @param [r] item2 [const void*] Ensembl Miscellaneous Feature address 2
3304 ** @see ajListSort
3305 **
3306 ** @return [int] The comparison function returns an integer less than,
3307 **               equal to, or greater than zero if the first argument is
3308 **               considered to be respectively less than, equal to, or
3309 **               greater than the second.
3310 **
3311 ** @release 6.4.0
3312 ** @@
3313 ******************************************************************************/
3314 
listMiscellaneousfeatureCompareStartDescending(const void * item1,const void * item2)3315 static int listMiscellaneousfeatureCompareStartDescending(
3316     const void *item1,
3317     const void *item2)
3318 {
3319     EnsPMiscellaneousfeature mf1 = *(EnsOMiscellaneousfeature *const *) item1;
3320     EnsPMiscellaneousfeature mf2 = *(EnsOMiscellaneousfeature *const *) item2;
3321 
3322 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3323     if (ajDebugTest("listMiscellaneousfeatureCompareStartDescending"))
3324         ajDebug("listMiscellaneousfeatureCompareStartDescending\n"
3325                 "  mf1 %p\n"
3326                 "  mf2 %p\n",
3327                 mf1,
3328                 mf2);
3329 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3330 
3331     /* Sort empty values towards the end of the AJAX List. */
3332 
3333     if (mf1 && (!mf2))
3334         return -1;
3335 
3336     if ((!mf1) && (!mf2))
3337         return 0;
3338 
3339     if ((!mf1) && mf2)
3340         return +1;
3341 
3342     return ensFeatureCompareStartDescending(mf1->Feature, mf2->Feature);
3343 }
3344 
3345 
3346 
3347 
3348 /* @section list **************************************************************
3349 **
3350 ** Functions for manipulating AJAX List objects.
3351 **
3352 ** @fdata [AjPList]
3353 **
3354 ** @nam3rule Miscellaneousfeature Functions for manipulating AJAX List objects
3355 ** of Ensembl Miscellaneous Feature objects
3356 ** @nam4rule Sort       Sort functions
3357 ** @nam5rule End        Sort by Ensembl Feature end member
3358 ** @nam5rule Identifier Sort by identifier member
3359 ** @nam5rule Start      Sort by Ensembl Feature start member
3360 ** @nam6rule Ascending  Sort in ascending order
3361 ** @nam6rule Descending Sort in descending order
3362 **
3363 ** @argrule * mfs [AjPList]
3364 ** AJAX List of Ensembl Miscellaneous Feature objects
3365 **
3366 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
3367 **
3368 ** @fcategory misc
3369 ******************************************************************************/
3370 
3371 
3372 
3373 
3374 /* @func ensListMiscellaneousfeatureSortEndAscending **************************
3375 **
3376 ** Sort an AJAX List of Ensembl Miscellaneous Feature objects by their
3377 ** Ensembl Feature end coordinate in ascending order.
3378 **
3379 ** @param [u] mfs [AjPList] AJAX List of Ensembl Miscellaneous Feature objects
3380 **
3381 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3382 **
3383 ** @release 6.4.0
3384 ** @@
3385 ******************************************************************************/
3386 
ensListMiscellaneousfeatureSortEndAscending(AjPList mfs)3387 AjBool ensListMiscellaneousfeatureSortEndAscending(AjPList mfs)
3388 {
3389     if (!mfs)
3390         return ajFalse;
3391 
3392     ajListSortTwoThree(mfs,
3393                        &listMiscellaneousfeatureCompareEndAscending,
3394                        &listMiscellaneousfeatureCompareStartAscending,
3395                        &listMiscellaneousfeatureCompareIdentifierAscending);
3396 
3397     return ajTrue;
3398 }
3399 
3400 
3401 
3402 
3403 /* @func ensListMiscellaneousfeatureSortEndDescending *************************
3404 **
3405 ** Sort an AJAX List of Ensembl Miscellaneous Feature objects by their
3406 ** Ensembl Feature end coordinate in descending order.
3407 **
3408 ** @param [u] mfs [AjPList] AJAX List of Ensembl Miscellaneous Feature objects
3409 **
3410 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3411 **
3412 ** @release 6.4.0
3413 ** @@
3414 ******************************************************************************/
3415 
ensListMiscellaneousfeatureSortEndDescending(AjPList mfs)3416 AjBool ensListMiscellaneousfeatureSortEndDescending(AjPList mfs)
3417 {
3418     if (!mfs)
3419         return ajFalse;
3420 
3421     ajListSortTwoThree(mfs,
3422                        &listMiscellaneousfeatureCompareEndDescending,
3423                        &listMiscellaneousfeatureCompareStartDescending,
3424                        &listMiscellaneousfeatureCompareIdentifierAscending);
3425 
3426     return ajTrue;
3427 }
3428 
3429 
3430 
3431 
3432 /* @func ensListMiscellaneousfeatureSortIdentifierAscending *******************
3433 **
3434 ** Sort an AJAX List of Ensembl Miscellaneous Feature objects by their
3435 ** identifier member in ascending order.
3436 **
3437 ** @param [u] mfs [AjPList] AJAX List of Ensembl Miscellaneous Feature objects
3438 **
3439 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3440 **
3441 ** @release 6.4.0
3442 ** @@
3443 ******************************************************************************/
3444 
ensListMiscellaneousfeatureSortIdentifierAscending(AjPList mfs)3445 AjBool ensListMiscellaneousfeatureSortIdentifierAscending(AjPList mfs)
3446 {
3447     if (!mfs)
3448         return ajFalse;
3449 
3450     ajListSort(mfs, &listMiscellaneousfeatureCompareIdentifierAscending);
3451 
3452     return ajTrue;
3453 }
3454 
3455 
3456 
3457 
3458 /* @func ensListMiscellaneousfeatureSortStartAscending ************************
3459 **
3460 ** Sort an AJAX List of Ensembl Miscellaneous Feature objects by their
3461 ** Ensembl Feature start coordinate in ascending order.
3462 **
3463 ** @param [u] mfs [AjPList] AJAX List of Ensembl Miscellaneous Feature objects
3464 **
3465 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3466 **
3467 ** @release 6.4.0
3468 ** @@
3469 ******************************************************************************/
3470 
ensListMiscellaneousfeatureSortStartAscending(AjPList mfs)3471 AjBool ensListMiscellaneousfeatureSortStartAscending(AjPList mfs)
3472 {
3473     if (!mfs)
3474         return ajFalse;
3475 
3476     ajListSortTwoThree(mfs,
3477                        &listMiscellaneousfeatureCompareStartAscending,
3478                        &listMiscellaneousfeatureCompareEndAscending,
3479                        &listMiscellaneousfeatureCompareIdentifierAscending);
3480 
3481     return ajTrue;
3482 }
3483 
3484 
3485 
3486 
3487 /* @func ensListMiscellaneousfeatureSortStartDescending ***********************
3488 **
3489 ** Sort an AJAX List of Ensembl Miscellaneous Feature objects by their
3490 ** Ensembl Feature start coordinate in descending order.
3491 **
3492 ** @param [u] mfs [AjPList] AJAX List of Ensembl Miscellaneous Feature objects
3493 **
3494 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3495 **
3496 ** @release 6.4.0
3497 ** @@
3498 ******************************************************************************/
3499 
ensListMiscellaneousfeatureSortStartDescending(AjPList mfs)3500 AjBool ensListMiscellaneousfeatureSortStartDescending(AjPList mfs)
3501 {
3502     if (!mfs)
3503         return ajFalse;
3504 
3505     ajListSortTwoThree(mfs,
3506                        &listMiscellaneousfeatureCompareStartDescending,
3507                        &listMiscellaneousfeatureCompareEndDescending,
3508                        &listMiscellaneousfeatureCompareIdentifierAscending);
3509 
3510     return ajTrue;
3511 }
3512 
3513 
3514 
3515 
3516 /* @datasection [EnsPMiscellaneousfeatureadaptor] Ensembl Miscellaneous Feature
3517 ** Adaptor
3518 **
3519 ** @nam2rule Miscellaneousfeatureadaptor Functions for manipulating
3520 ** Ensembl Miscellaneous Feature Adaptor objects
3521 **
3522 ** @cc Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor
3523 ** @cc CVS Revision: 1.27
3524 ** @cc CVS Tag: branch-ensembl-68
3525 **
3526 ******************************************************************************/
3527 
3528 
3529 
3530 
3531 /* @funcstatic miscellaneousfeatureadaptorHasAttribute ************************
3532 **
3533 ** Check whether an Ensembl Attribute has already been indexed for a particular
3534 ** Ensembl Miscellaneous Feature.
3535 **
3536 ** @param [u] attributes [AjPTable] AJAX Table of AJAX String key data
3537 ** (code:value pairs) and AJAX Boolean value data
3538 ** @param [r] atid [ajuint] Ensembl Attribute Type identifier
3539 ** @param [r] value [const AjPStr] Ensembl Attribute value
3540 **
3541 ** @return [AjBool] ajTrue: A particular code:value String has already
3542 **                          been indexed.
3543 **                  ajFalse: A particular code:value String has not been
3544 **                           indexed before, but has been added now.
3545 **
3546 ** @release 6.3.0
3547 ** @@
3548 ** This function keeps an AJAX Table of Attribute code:value String key
3549 ** data and AjBool value data.
3550 ******************************************************************************/
3551 
miscellaneousfeatureadaptorHasAttribute(AjPTable attributes,ajuint atid,const AjPStr value)3552 static AjBool miscellaneousfeatureadaptorHasAttribute(AjPTable attributes,
3553                                                       ajuint atid,
3554                                                       const AjPStr value)
3555 {
3556     AjBool *Pbool = NULL;
3557 
3558     AjPStr key = NULL;
3559 
3560     key = ajFmtStr("%u:%S", atid, value);
3561 
3562     if (ajTableMatchS(attributes, key))
3563     {
3564         ajStrDel(&key);
3565 
3566         return ajTrue;
3567     }
3568     else
3569     {
3570         AJNEW0(Pbool);
3571 
3572         *Pbool = ajTrue;
3573 
3574         ajTablePut(attributes, (void *) key, (void *) Pbool);
3575 
3576         return ajFalse;
3577     }
3578 }
3579 
3580 
3581 
3582 
3583 /* @funcstatic miscellaneousfeatureadaptorHasMiscellaneousset *****************
3584 **
3585 ** Check whether an Ensembl Miscellaneous Set has already been indexed for a
3586 ** particular Ensembl Miscellaneous Feature.
3587 **
3588 ** @param [u] sets [AjPTable] AJAX Table of AJAX unsigned integer
3589 ** (Ensembl Miscellaneous Set identifier) objects
3590 ** @param [r] msid [ajuint] Ensembl Miscellaneous Set identifier
3591 **
3592 ** @return [AjBool] ajTrue: A particular Ensembl Miscellaneous Set identifier
3593 **                          has already been indexed.
3594 **                  ajFalse: A particular Ensembl Miscellaneous Set identifier
3595 **                           has not been indexed before, but has been added
3596 **                           now.
3597 **
3598 ** @release 6.3.0
3599 ** @@
3600 ** This function keeps an AJAX Table of AJAX unsigned integer
3601 ** (Ensembl Miscellaneous Set identifier) object key data and
3602 ** AJAX Boolean object value data.
3603 ******************************************************************************/
3604 
miscellaneousfeatureadaptorHasMiscellaneousset(AjPTable sets,ajuint msid)3605 static AjBool miscellaneousfeatureadaptorHasMiscellaneousset(AjPTable sets,
3606                                                              ajuint msid)
3607 {
3608     AjBool *Pbool = NULL;
3609 
3610     ajuint *Pidentifier = NULL;
3611 
3612     if (ajTableMatchV(sets, (const void *) &msid))
3613         return ajTrue;
3614 
3615     AJNEW0(Pidentifier);
3616 
3617     *Pidentifier = msid;
3618 
3619     AJNEW0(Pbool);
3620 
3621     *Pbool = ajTrue;
3622 
3623     ajTablePut(sets, (void *) Pidentifier, (void *) Pbool);
3624 
3625     return ajFalse;
3626 }
3627 
3628 
3629 
3630 
3631 /* @funcstatic miscellaneousfeatureadaptorFetchAllbyStatement *****************
3632 **
3633 ** Fetch all Ensembl Miscellaneous Feature objects via an SQL statement.
3634 **
3635 ** @cc Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor::_objs_from_sth
3636 ** @param [u] ba [EnsPBaseadaptor] Ensembl Base Adaptor
3637 ** @param [r] statement [const AjPStr] SQL statement
3638 ** @param [uN] am [EnsPAssemblymapper] Ensembl Assembly Mapper
3639 ** @param [uN] slice [EnsPSlice] Ensembl Slice
3640 ** @param [u] mfs [AjPList] AJAX List of Ensembl Miscellaneous Feature objects
3641 **
3642 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3643 **
3644 ** @release 6.4.0
3645 ** @@
3646 ******************************************************************************/
3647 
miscellaneousfeatureadaptorFetchAllbyStatement(EnsPBaseadaptor ba,const AjPStr statement,EnsPAssemblymapper am,EnsPSlice slice,AjPList mfs)3648 static AjBool miscellaneousfeatureadaptorFetchAllbyStatement(
3649     EnsPBaseadaptor ba,
3650     const AjPStr statement,
3651     EnsPAssemblymapper am,
3652     EnsPSlice slice,
3653     AjPList mfs)
3654 {
3655     ajuint identifier = 0U;
3656     ajuint atid       = 0U;
3657     ajuint msid       = 0U;
3658 
3659     ajuint srid     = 0U;
3660     ajuint srstart  = 0U;
3661     ajuint srend    = 0U;
3662     ajint  srstrand = 0;
3663 
3664     ajuint current = 0U;
3665     ajuint throw = 0U;
3666 
3667     AjPSqlstatement sqls = NULL;
3668     AjISqlrow sqli       = NULL;
3669     AjPSqlrow sqlr       = NULL;
3670 
3671     AjPStr avalue = NULL;
3672 
3673     AjPTable attributes = NULL;
3674     AjPTable sets       = NULL;
3675 
3676     EnsPAttribute attribute = NULL;
3677 
3678     EnsPAttributetype        at  = NULL;
3679     EnsPAttributetypeadaptor ata = NULL;
3680 
3681     EnsPDatabaseadaptor dba = NULL;
3682 
3683     EnsPFeature feature = NULL;
3684 
3685     EnsPMiscellaneousfeature mf         = NULL;
3686     EnsPMiscellaneousfeatureadaptor mfa = NULL;
3687 
3688     EnsPMiscellaneousset ms         = NULL;
3689     EnsPMiscellaneoussetadaptor msa = NULL;
3690 
3691     if (ajDebugTest("miscellaneousfeatureadaptorFetchAllbyStatement"))
3692         ajDebug("miscellaneousfeatureadaptorFetchAllbyStatement\n"
3693                 "  ba %p\n"
3694                 "  statement %p\n"
3695                 "  am %p\n"
3696                 "  slice %p\n"
3697                 "  mfs %p\n",
3698                 ba,
3699                 statement,
3700                 am,
3701                 slice,
3702                 mfs);
3703 
3704     if (!ba)
3705         return ajFalse;
3706 
3707     if (!statement)
3708         return ajFalse;
3709 
3710     if (!mfs)
3711         return ajFalse;
3712 
3713     dba = ensBaseadaptorGetDatabaseadaptor(ba);
3714 
3715     ata = ensRegistryGetAttributetypeadaptor(dba);
3716     mfa = ensRegistryGetMiscellaneousfeatureadaptor(dba);
3717     msa = ensRegistryGetMiscellaneoussetadaptor(dba);
3718 
3719     attributes = ajTablestrNew(0U);
3720 
3721     ajTableSetDestroyvalue(attributes, &ajMemFree);
3722 
3723     sets = ajTableuintNew(0U);
3724 
3725     ajTableSetDestroyvalue(sets, &ajMemFree);
3726 
3727     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
3728 
3729     sqli = ajSqlrowiterNew(sqls);
3730 
3731     while (!ajSqlrowiterDone(sqli))
3732     {
3733         identifier = 0U;
3734         srid       = 0U;
3735         srstart    = 0U;
3736         srend      = 0U;
3737         srstrand   = 0;
3738         atid       = 0U;
3739         avalue     = ajStrNew();
3740         msid       = 0U;
3741 
3742         sqlr = ajSqlrowiterGet(sqli);
3743 
3744         ajSqlcolumnToUint(sqlr, &identifier);
3745         ajSqlcolumnToUint(sqlr, &srid);
3746         ajSqlcolumnToUint(sqlr, &srstart);
3747         ajSqlcolumnToUint(sqlr, &srend);
3748         ajSqlcolumnToInt(sqlr, &srstrand);
3749         ajSqlcolumnToUint(sqlr, &atid);
3750         ajSqlcolumnToStr(sqlr, &avalue);
3751         ajSqlcolumnToUint(sqlr, &msid);
3752 
3753         if (identifier == throw)
3754         {
3755             /*
3756             ** This Miscellanous Feature is already known to map into a gap,
3757             ** therefore throw it away immediately.
3758             */
3759 
3760             ajStrDel(&avalue);
3761 
3762             continue;
3763         }
3764 
3765         if (identifier != current)
3766         {
3767             /*
3768             ** This is a new Miscellaneous Feature, therefore clear all
3769             ** internal caches.
3770             */
3771 
3772             ajTableClearDelete(attributes);
3773             ajTableClearDelete(sets);
3774 
3775             mf      = NULL;
3776             current = identifier;
3777             throw   = 0U;
3778 
3779             ensBaseadaptorRetrieveFeature(ba,
3780                                           0U,
3781                                           srid,
3782                                           srstart,
3783                                           srend,
3784                                           srstrand,
3785                                           am,
3786                                           slice,
3787                                           &feature);
3788 
3789             if (!feature)
3790             {
3791                 throw = identifier;
3792 
3793                 ajStrDel(&avalue);
3794 
3795                 continue;
3796             }
3797 
3798             /* Finally, create a new Ensembl Miscellaneous Feature. */
3799 
3800             mf = ensMiscellaneousfeatureNewIni(mfa, identifier, feature);
3801 
3802             ensFeatureDel(&feature);
3803 
3804             ajListPushAppend(mfs, (void *) mf);
3805         }
3806 
3807         /* Add an Ensembl Attribute if one was defined. */
3808 
3809         if ((atid > 0) &&
3810             (ajStrGetLen(avalue) > 0) &&
3811             !miscellaneousfeatureadaptorHasAttribute(attributes, atid, avalue))
3812         {
3813             ensAttributetypeadaptorFetchByIdentifier(ata, atid, &at);
3814 
3815             attribute = ensAttributeNewIni(at, avalue);
3816 
3817             ensAttributetypeDel(&at);
3818 
3819             ensMiscellaneousfeatureAddAttribute(mf, attribute);
3820 
3821             ensAttributeDel(&attribute);
3822         }
3823 
3824         /* Add an Ensembl Miscellaneous Set if one was defined. */
3825 
3826         if ((msid > 0) &&
3827             !miscellaneousfeatureadaptorHasMiscellaneousset(sets, msid))
3828         {
3829             ensMiscellaneoussetadaptorFetchByIdentifier(msa, msid, &ms);
3830 
3831             ensMiscellaneousfeatureAddMiscellaneousset(mf, ms);
3832 
3833             ensMiscellaneoussetDel(&ms);
3834         }
3835 
3836         ajStrDel(&avalue);
3837     }
3838 
3839     ajSqlrowiterDel(&sqli);
3840 
3841     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
3842 
3843     ajTableDel(&attributes);
3844     ajTableDel(&sets);
3845 
3846     return ajTrue;
3847 }
3848 
3849 
3850 
3851 
3852 /* @section constructors ******************************************************
3853 **
3854 ** All constructors return a new Ensembl Miscellaneous Feature Adaptor by
3855 ** pointer.
3856 ** It is the responsibility of the user to first destroy any previous
3857 ** Miscellaneous Feature Adaptor. The target pointer does not need to be
3858 ** initialised to NULL, but it is good programming practice to do so anyway.
3859 **
3860 ** @fdata [EnsPMiscellaneousfeatureadaptor]
3861 **
3862 ** @nam3rule New Constructor
3863 **
3864 ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
3865 **
3866 ** @valrule * [EnsPMiscellaneousfeatureadaptor]
3867 ** Ensembl Miscellaneous Feature Adaptor or NULL
3868 **
3869 ** @fcategory new
3870 ******************************************************************************/
3871 
3872 
3873 
3874 
3875 /* @func ensMiscellaneousfeatureadaptorNew ************************************
3876 **
3877 ** Default constructor for an Ensembl Miscellaneous Feature Adaptor.
3878 **
3879 ** Ensembl Object Adaptors are singleton objects in the sense that a single
3880 ** instance of an Ensembl Object Adaptor connected to a particular database is
3881 ** sufficient to instantiate any number of Ensembl Objects from the database.
3882 ** Each Ensembl Object will have a weak reference to the Object Adaptor that
3883 ** instantiated it. Therefore, Ensembl Object Adaptors should not be
3884 ** instantiated directly, but rather obtained from the Ensembl Registry,
3885 ** which will in turn call this function if neccessary.
3886 **
3887 ** @see ensRegistryGetDatabaseadaptor
3888 ** @see ensRegistryGetMiscellaneousfeatureadaptor
3889 **
3890 ** @cc Bio::EnsEMBL::DBSQL::MiscSetAdaptor::new
3891 ** @cc Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor::new
3892 ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
3893 **
3894 ** @return [EnsPMiscellaneousfeatureadaptor]
3895 ** Ensembl Miscellaneous Feature Adaptor or NULL
3896 **
3897 ** @release 6.2.0
3898 ** @@
3899 ******************************************************************************/
3900 
ensMiscellaneousfeatureadaptorNew(EnsPDatabaseadaptor dba)3901 EnsPMiscellaneousfeatureadaptor ensMiscellaneousfeatureadaptorNew(
3902     EnsPDatabaseadaptor dba)
3903 {
3904     return ensFeatureadaptorNew(
3905         dba,
3906         miscellaneousfeatureadaptorKTablenames,
3907         miscellaneousfeatureadaptorKColumnnames,
3908         miscellaneousfeatureadaptorKLeftjoins,
3909         (const char *) NULL,
3910         miscellaneousfeatureadaptorKFinalcondition,
3911         &miscellaneousfeatureadaptorFetchAllbyStatement,
3912         (void *(*)(const void *)) NULL,
3913         (void *(*)(void *)) &ensMiscellaneousfeatureNewRef,
3914         (AjBool (*)(const void *)) NULL,
3915         (void (*)(void **)) &ensMiscellaneousfeatureDel,
3916         (size_t (*)(const void *)) &ensMiscellaneousfeatureCalculateMemsize,
3917         (EnsPFeature (*)(const void *)) &ensMiscellaneousfeatureGetFeature,
3918         "Miscellaneous Feature");
3919 }
3920 
3921 
3922 
3923 
3924 /* @section destructors *******************************************************
3925 **
3926 ** Destruction destroys all internal data structures and frees the memory
3927 ** allocated for an Ensembl Miscellaneous Set Adaptor object.
3928 **
3929 ** @fdata [EnsPMiscellaneousfeatureadaptor]
3930 **
3931 ** @nam3rule Del Destroy (free) an Ensembl Miscellaneous Feature Adaptor
3932 **
3933 ** @argrule * Pmfa [EnsPMiscellaneousfeatureadaptor*]
3934 ** Ensembl Miscellaneous Feature Adaptor address
3935 **
3936 ** @valrule * [void]
3937 **
3938 ** @fcategory delete
3939 ******************************************************************************/
3940 
3941 
3942 
3943 
3944 /* @func ensMiscellaneousfeatureadaptorDel ************************************
3945 **
3946 ** Default destructor for an Ensembl Miscellaneous Feature Adaptor.
3947 **
3948 ** Ensembl Object Adaptors are singleton objects that are registered in the
3949 ** Ensembl Registry and weakly referenced by Ensembl Objects that have been
3950 ** instantiated by it. Therefore, Ensembl Object Adaptors should never be
3951 ** destroyed directly. Upon exit, the Ensembl Registry will call this function
3952 ** if required.
3953 **
3954 ** @param [d] Pmfa [EnsPMiscellaneousfeatureadaptor*]
3955 ** Ensembl Miscellaneous Feature Adaptor address
3956 **
3957 ** @return [void]
3958 **
3959 ** @release 6.2.0
3960 ** @@
3961 ******************************************************************************/
3962 
ensMiscellaneousfeatureadaptorDel(EnsPMiscellaneousfeatureadaptor * Pmfa)3963 void ensMiscellaneousfeatureadaptorDel(
3964     EnsPMiscellaneousfeatureadaptor *Pmfa)
3965 {
3966     ensFeatureadaptorDel(Pmfa);
3967 
3968     return;
3969 }
3970 
3971 
3972 
3973 
3974 /* @section member retrieval **************************************************
3975 **
3976 ** Functions for returning members of an
3977 ** Ensembl Miscellaneous Feature Adaptor object.
3978 **
3979 ** @fdata [EnsPMiscellaneousfeatureadaptor]
3980 **
3981 ** @nam3rule Get Return Ensembl Miscellaneous Feature Adaptor attribute(s)
3982 ** @nam4rule Baseadaptor Return the Ensembl Base Adaptor
3983 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
3984 ** @nam4rule Featureadaptor Return the Ensembl Feature Adaptor
3985 **
3986 ** @argrule * mfa [EnsPMiscellaneousfeatureadaptor]
3987 ** Ensembl Miscellaneous Feature Adaptor
3988 **
3989 ** @valrule Baseadaptor [EnsPBaseadaptor]
3990 ** Ensembl Base Adaptor or NULL
3991 ** @valrule Databaseadaptor [EnsPDatabaseadaptor]
3992 ** Ensembl Database Adaptor or NULL
3993 ** @valrule Featureadaptor [EnsPFeatureadaptor]
3994 ** Ensembl Feature Adaptor or NULL
3995 **
3996 ** @fcategory use
3997 ******************************************************************************/
3998 
3999 
4000 
4001 
4002 /* @func ensMiscellaneousfeatureadaptorGetBaseadaptor *************************
4003 **
4004 ** Get the Ensembl Base Adaptor member of an
4005 ** Ensembl Miscellaneous Feature Adaptor.
4006 **
4007 ** @param [u] mfa [EnsPMiscellaneousfeatureadaptor]
4008 ** Ensembl Miscellaneous Feature Adaptor
4009 **
4010 ** @return [EnsPBaseadaptor] Ensembl Base Adaptor or NULL
4011 **
4012 ** @release 6.5.0
4013 ** @@
4014 ******************************************************************************/
4015 
ensMiscellaneousfeatureadaptorGetBaseadaptor(EnsPMiscellaneousfeatureadaptor mfa)4016 EnsPBaseadaptor ensMiscellaneousfeatureadaptorGetBaseadaptor(
4017     EnsPMiscellaneousfeatureadaptor mfa)
4018 {
4019     return ensFeatureadaptorGetBaseadaptor(
4020         ensMiscellaneousfeatureadaptorGetFeatureadaptor(mfa));
4021 }
4022 
4023 
4024 
4025 
4026 /* @func ensMiscellaneousfeatureadaptorGetDatabaseadaptor *********************
4027 **
4028 ** Get the Ensembl Database Adaptor member of an
4029 ** Ensembl Miscellaneous Feature Adaptor.
4030 **
4031 ** @param [u] mfa [EnsPMiscellaneousfeatureadaptor]
4032 ** Ensembl Miscellaneous Feature Adaptor
4033 **
4034 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
4035 **
4036 ** @release 6.4.0
4037 ** @@
4038 ******************************************************************************/
4039 
ensMiscellaneousfeatureadaptorGetDatabaseadaptor(EnsPMiscellaneousfeatureadaptor mfa)4040 EnsPDatabaseadaptor ensMiscellaneousfeatureadaptorGetDatabaseadaptor(
4041     EnsPMiscellaneousfeatureadaptor mfa)
4042 {
4043     return ensFeatureadaptorGetDatabaseadaptor(
4044         ensMiscellaneousfeatureadaptorGetFeatureadaptor(mfa));
4045 }
4046 
4047 
4048 
4049 
4050 /* @func ensMiscellaneousfeatureadaptorGetFeatureadaptor **********************
4051 **
4052 ** Get the Ensembl Feature Adaptor member of an
4053 ** Ensembl Miscellaneous Feature Adaptor.
4054 **
4055 ** @param [u] mfa [EnsPMiscellaneousfeatureadaptor]
4056 ** Ensembl Miscellaneous Feature Adaptor
4057 **
4058 ** @return [EnsPFeatureadaptor] Ensembl Feature Adaptor or NULL
4059 **
4060 ** @release 6.5.1
4061 ** @@
4062 ******************************************************************************/
4063 
ensMiscellaneousfeatureadaptorGetFeatureadaptor(EnsPMiscellaneousfeatureadaptor mfa)4064 EnsPFeatureadaptor ensMiscellaneousfeatureadaptorGetFeatureadaptor(
4065     EnsPMiscellaneousfeatureadaptor mfa)
4066 {
4067     return mfa;
4068 }
4069 
4070 
4071 
4072 
4073 /* @section object fetching ***************************************************
4074 **
4075 ** Functions for fetching Ensembl Miscellaneous Feature objects from an
4076 ** Ensembl Core database.
4077 **
4078 ** @fdata [EnsPMiscellaneousfeatureadaptor]
4079 **
4080 ** @nam3rule Fetch Fetch Ensembl Miscellaneous Feature object(s)
4081 ** @nam4rule All   Fetch all Ensembl Miscellaneous Feature objects
4082 ** @nam4rule Allby Fetch all Ensembl Miscellaneous Feature objects
4083 **                 matching a criterion
4084 ** @nam5rule Attributecodevalue Fetch all by Ensembl Attribute code and value
4085 ** @nam5rule Slicecodes Fetch all by an Ensembl Slice and an AJAX List of AJAX
4086 ** String (Ensembl Miscelleaneous Set codes)
4087 ** @nam4rule By    Fetch one Ensembl Miscellaneous Feature object
4088 **                 matching a criterion
4089 **
4090 ** @argrule * mfa [EnsPMiscellaneousfeatureadaptor]
4091 ** Ensembl Miscellaneous Feature Adaptor
4092 ** @argrule FetchAll mfs [AjPList]
4093 ** AJAX List of Ensembl Miscellaneous Feature objects
4094 ** @argrule AllbyAttributecodevalue code [const AjPStr]
4095 ** Ensembl Attribute code
4096 ** @argrule AllbyAttributecodevalue value [const AjPStr]
4097 ** Ensembl Attribute value
4098 ** @argrule AllbyAttributecodevalue mfs [AjPList]
4099 ** AJAX List of Ensembl Miscellaneous Feature objects
4100 ** @argrule AllbySlicecodes slice [EnsPSlice] Ensembl Slice
4101 ** @argrule AllbySlicecodes codes [const AjPList]
4102 ** AJAX List of AJAX String objects
4103 ** @argrule AllbySlicecodes mfs [AjPList]
4104 ** AJAX List of Ensembl Miscellaneous Feature objects
4105 **
4106 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
4107 **
4108 ** @fcategory use
4109 ******************************************************************************/
4110 
4111 
4112 
4113 
4114 /* @func ensMiscellaneousfeatureadaptorFetchAllbyAttributecodevalue ***********
4115 **
4116 ** Fetch all Ensembl Miscellaneous Feature objects by an Ensembl Slice and
4117 ** an Ensembl Attribute code and value.
4118 **
4119 ** @cc Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor::
4120 **     fetch_all_by_attribute_type_value
4121 ** @param [u] mfa [EnsPMiscellaneousfeatureadaptor]
4122 ** Ensembl Miscellaneous Feature Adaptor
4123 ** @param [r] code [const AjPStr] Ensembl Attribute code
4124 ** @param [r] value [const AjPStr] Ensembl Attribute value
4125 ** @param [u] mfs [AjPList] AJAX List of Ensembl Miscellaneous Feature objects
4126 **
4127 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4128 **
4129 ** @release 6.4.0
4130 ** @@
4131 ******************************************************************************/
4132 
ensMiscellaneousfeatureadaptorFetchAllbyAttributecodevalue(EnsPMiscellaneousfeatureadaptor mfa,const AjPStr code,const AjPStr value,AjPList mfs)4133 AjBool ensMiscellaneousfeatureadaptorFetchAllbyAttributecodevalue(
4134     EnsPMiscellaneousfeatureadaptor mfa,
4135     const AjPStr code,
4136     const AjPStr value,
4137     AjPList mfs)
4138 {
4139     register ajuint i = 0U;
4140 
4141     ajuint mfid = 0U;
4142 
4143     char *txtvalue = NULL;
4144 
4145     const char *template = "misc_feature.misc_feature_id in (%S)";
4146 
4147     AjPSqlstatement sqls = NULL;
4148     AjISqlrow sqli       = NULL;
4149     AjPSqlrow sqlr       = NULL;
4150 
4151     AjPStr csv        = NULL;
4152     AjPStr constraint = NULL;
4153     AjPStr statement  = NULL;
4154 
4155     EnsPAttributetype at = NULL;
4156 
4157     EnsPBaseadaptor ba = NULL;
4158 
4159     EnsPDatabaseadaptor dba = NULL;
4160 
4161     if (!mfa)
4162         return ajFalse;
4163 
4164     if (!code)
4165         ajFatal("ensMiscellaneousfeatureadaptorFetchAllbyAttributecodevalue "
4166                 "requires an Ensembl Attribute code.\n");
4167 
4168     ba  = ensMiscellaneousfeatureadaptorGetBaseadaptor(mfa);
4169 
4170     dba = ensBaseadaptorGetDatabaseadaptor(ba);
4171 
4172     ensAttributetypeadaptorFetchByCode(
4173         ensRegistryGetAttributetypeadaptor(dba),
4174         code,
4175         &at);
4176 
4177     if (!at)
4178         return ajTrue;
4179 
4180     /*
4181     ** Need to do two queries so that all of the identifiers come back with
4182     ** the Ensembl Feature objects. The problem with adding attribute
4183     ** constraints to filter the misc_features, which come back is that not
4184     ** all of the Ensembl Attribute objects will come back
4185     */
4186 
4187     statement = ajFmtStr(
4188         "SELECT DISTINCT "
4189         "misc_attrib.misc_feature_id "
4190         "FROM "
4191         "misc_attrib, "
4192         "misc_feature, "
4193         "seq_region, "
4194         "coord_system "
4195         "WHERE "
4196         "misc_attrib.attrib_type_id = %u "
4197         "AND "
4198         "misc_attrib.misc_feature_id = misc_feature.misc_feature_id "
4199         "AND "
4200         "misc_feature.seq_region_id = seq_region.seq_region_id "
4201         "AND "
4202         "seq_region.coord_system_id = coord_system.coord_system_id "
4203         "AND "
4204         "coord_system.species_id = %u",
4205         ensAttributetypeGetIdentifier(at),
4206         ensDatabaseadaptorGetIdentifier(dba));
4207 
4208     if (value)
4209     {
4210         ensDatabaseadaptorEscapeC(dba, &txtvalue, value);
4211 
4212         ajFmtPrintAppS(&statement, " AND misc_attrib.value = '%s'", txtvalue);
4213 
4214         ajCharDel(&txtvalue);
4215     }
4216 
4217     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
4218 
4219     sqli = ajSqlrowiterNew(sqls);
4220 
4221     csv = ajStrNew();
4222 
4223     /*
4224     ** Large queries are split into smaller ones on the basis of the maximum
4225     ** number of identifier instances configured in the
4226     ** Ensembl Base Adaptor module.
4227     ** This ensures that MySQL is faster and the maximum query size is not
4228     ** exceeded.
4229     */
4230 
4231     while (!ajSqlrowiterDone(sqli))
4232     {
4233         mfid = 0;
4234 
4235         sqlr = ajSqlrowiterGet(sqli);
4236 
4237         ajSqlcolumnToUint(sqlr, &mfid);
4238 
4239         ajFmtPrintAppS(&csv, "%u, ", mfid);
4240 
4241         /*
4242         ** Run the statement if the maximum chunk size is exceed or
4243         ** if there are no more AJAX List elements to process.
4244         */
4245 
4246         if ((((i + 1U) % ensKBaseadaptorMaximumIdentifiers) == 0) ||
4247             ajSqlrowiterDone(sqli))
4248         {
4249             /*
4250             ** Remove the last comma and space from the
4251             ** comma-separated values.
4252             */
4253 
4254             ajStrCutEnd(&csv, 2);
4255 
4256             if (ajStrGetLen(csv))
4257             {
4258                 constraint = ajFmtStr(template, csv);
4259 
4260                 ensBaseadaptorFetchAllbyConstraint(
4261                     ba,
4262                     constraint,
4263                     (EnsPAssemblymapper) NULL,
4264                     (EnsPSlice) NULL,
4265                     mfs);
4266 
4267                 ajStrDel(&constraint);
4268             }
4269 
4270             ajStrSetClear(&csv);
4271         }
4272 
4273         i++;
4274     }
4275 
4276     ajSqlrowiterDel(&sqli);
4277 
4278     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
4279 
4280     ajStrDel(&statement);
4281 
4282     ajStrDel(&csv);
4283 
4284     return ajTrue;
4285 }
4286 
4287 
4288 
4289 
4290 /* @func ensMiscellaneousfeatureadaptorFetchAllbySlicecodes *******************
4291 **
4292 ** Fetch all Ensembl Miscellaneous Feature objects by an Ensembl Slice and
4293 ** Ensembl Miscellaneous Set codes.
4294 **
4295 ** @cc Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor::
4296 **     fetch_all_by_Slice_and_set_code
4297 ** @param [u] mfa [EnsPMiscellaneousfeatureadaptor]
4298 ** Ensembl Miscellaneous Feature Adaptor
4299 ** @param [u] slice [EnsPSlice] Ensembl Slice
4300 ** @param [r] codes [const AjPList] AJAX List of AJAX String
4301 ** (Ensembl Miscellaneous Set code) objects
4302 ** @param [u] mfs [AjPList] AJAX List of Ensembl Miscellaneous Feature objects
4303 **
4304 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4305 **
4306 ** @release 6.4.0
4307 ** @@
4308 ******************************************************************************/
4309 
ensMiscellaneousfeatureadaptorFetchAllbySlicecodes(EnsPMiscellaneousfeatureadaptor mfa,EnsPSlice slice,const AjPList codes,AjPList mfs)4310 AjBool ensMiscellaneousfeatureadaptorFetchAllbySlicecodes(
4311     EnsPMiscellaneousfeatureadaptor mfa,
4312     EnsPSlice slice,
4313     const AjPList codes,
4314     AjPList mfs)
4315 {
4316     ajuint maxlen = 0U;
4317 
4318     AjIList iter = NULL;
4319 
4320     AjPStr code       = NULL;
4321     AjPStr constraint = NULL;
4322     AjPStr csv        = NULL;
4323 
4324     EnsPDatabaseadaptor dba = NULL;
4325 
4326     EnsPMiscellaneousset ms         = NULL;
4327     EnsPMiscellaneoussetadaptor msa = NULL;
4328 
4329     if (!mfa)
4330         return ajFalse;
4331 
4332     if (!slice)
4333         return ajFalse;
4334 
4335     if (!codes)
4336         return ajFalse;
4337 
4338     if (!mfs)
4339         return ajFalse;
4340 
4341     dba = ensMiscellaneousfeatureadaptorGetDatabaseadaptor(mfa);
4342 
4343     msa = ensRegistryGetMiscellaneoussetadaptor(dba);
4344 
4345     csv = ajStrNew();
4346 
4347     iter = ajListIterNewread(codes);
4348 
4349     while (!ajListIterDone(iter))
4350     {
4351         code = (AjPStr) ajListIterGet(iter);
4352 
4353         ensMiscellaneoussetadaptorFetchByCode(msa, code, &ms);
4354 
4355         if (ms)
4356         {
4357             maxlen = (ensMiscellaneoussetGetMaximumlength(ms) > maxlen) ?
4358                 ensMiscellaneoussetGetMaximumlength(ms) : maxlen;
4359 
4360             ajFmtPrintAppS(&csv, "%u, ", ensMiscellaneoussetGetIdentifier(ms));
4361 
4362             ensMiscellaneoussetDel(&ms);
4363         }
4364         else
4365             ajWarn("ensMiscellaneousfeatureadaptorFetchAllbySlicecodes "
4366                    "no Miscellaneous Set with code '%S'.\n", code);
4367     }
4368 
4369     ajListIterDel(&iter);
4370 
4371     /* Remove the last comma and space from the comma-separated values. */
4372 
4373     ajStrCutEnd(&csv, 2);
4374 
4375     if (ajStrGetLen(csv) > 0)
4376     {
4377         constraint = ajFmtStr("misc_feature_misc_set.misc_set_id IN (%S)",
4378                               csv);
4379 
4380         ensFeatureadaptorSetMaximumlength(mfa, maxlen);
4381 
4382         ensFeatureadaptorFetchAllbySlice(mfa,
4383                                          slice,
4384                                          constraint,
4385                                          (const AjPStr) NULL,
4386                                          mfs);
4387 
4388         ensFeatureadaptorSetMaximumlength(mfa, 0);
4389 
4390         ajStrDel(&constraint);
4391     }
4392 
4393     ajStrDel(&csv);
4394 
4395     return ajTrue;
4396 }
4397 
4398 
4399 
4400 
4401 /* @section accessory object retrieval ****************************************
4402 **
4403 ** Functions for retrieving objects releated to Ensembl Miscellaneous Feature
4404 ** objects from an Ensembl SQL database.
4405 **
4406 ** @fdata [EnsPMiscellaneousfeatureadaptor]
4407 **
4408 ** @nam3rule Retrieve Retrieve Ensembl Miscellaneous Feature-releated object(s)
4409 ** @nam4rule All Retrieve all Ensembl Miscellaneous Feature-releated objects
4410 ** @nam5rule Identifiers Retrieve all SQL database-internal identifier objects
4411 **
4412 ** @argrule * mfa [EnsPMiscellaneousfeatureadaptor]
4413 ** Ensembl Miscellaneous Feature Adaptor
4414 ** @argrule AllIdentifiers identifiers [AjPList]
4415 ** AJAX List of AJAX unsigned integer
4416 ** (Ensembl Miscellaneous Feature identifier) objects
4417 **
4418 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
4419 **
4420 ** @fcategory use
4421 ******************************************************************************/
4422 
4423 
4424 
4425 
4426 /* @func ensMiscellaneousfeatureadaptorRetrieveAllIdentifiers *****************
4427 **
4428 ** Retrieve all SQL database-internal identifier objects of
4429 ** Ensembl Miscellaneous Feature objects.
4430 **
4431 ** The caller is responsible for deleting the AJAX unsigned integer objects
4432 ** before deleting the AJAX List.
4433 **
4434 ** @cc Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor::list_dbIDs
4435 ** @param [u] mfa [EnsPMiscellaneousfeatureadaptor]
4436 ** Ensembl Miscellaneous Feature Adaptor
4437 ** @param [u] identifiers [AjPList]
4438 ** AJAX List of AJAX unsigned integer
4439 ** (Ensembl Miscellaneous Feature identifier) objects
4440 **
4441 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4442 **
4443 ** @release 6.4.0
4444 ** @@
4445 ******************************************************************************/
4446 
ensMiscellaneousfeatureadaptorRetrieveAllIdentifiers(EnsPMiscellaneousfeatureadaptor mfa,AjPList identifiers)4447 AjBool ensMiscellaneousfeatureadaptorRetrieveAllIdentifiers(
4448     EnsPMiscellaneousfeatureadaptor mfa,
4449     AjPList identifiers)
4450 {
4451     AjBool result = AJFALSE;
4452 
4453     AjPStr table = NULL;
4454 
4455     if (!mfa)
4456         return ajFalse;
4457 
4458     if (!identifiers)
4459         return ajFalse;
4460 
4461     table = ajStrNewC("misc_feature");
4462 
4463     result = ensBaseadaptorRetrieveAllIdentifiers(
4464         ensMiscellaneousfeatureadaptorGetBaseadaptor(mfa),
4465         table,
4466         (AjPStr) NULL,
4467         identifiers);
4468 
4469     ajStrDel(&table);
4470 
4471     return result;
4472 }
4473