1 /* @source ensrepeat **********************************************************
2 **
3 ** Ensembl Repeat functions
4 **
5 ** @author Copyright (C) 1999 Ensembl Developers
6 ** @author Copyright (C) 2006 Michael K. Schuster
7 ** @version $Revision: 1.59 $
8 ** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core
9 ** @modified $Date: 2013/02/17 13:02:11 $ 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 "ensrepeat.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 repeatconsensusadaptorKTablenames *****************************
65 **
66 ** Array of Ensembl Repeat Consensus Adaptor SQL table names
67 **
68 ******************************************************************************/
69 
70 static const char *repeatconsensusadaptorKTablenames[] =
71 {
72     "repeat_consensus",
73     (const char *) NULL
74 };
75 
76 
77 
78 
79 /* @conststatic repeatconsensusadaptorKColumnnames ****************************
80 **
81 ** Array of Ensembl Repeat Consensus Adaptor SQL column names
82 **
83 ******************************************************************************/
84 
85 static const char *repeatconsensusadaptorKColumnnames[] =
86 {
87     "repeat_consensus.repeat_consensus_id",
88     "repeat_consensus.repeat_name",
89     "repeat_consensus.repeat_class",
90     "repeat_consensus.repeat_type",
91     "repeat_consensus.repeat_consensus",
92     (const char *) NULL
93 };
94 
95 
96 
97 
98 /* @conststatic repeatfeatureadaptorKTablenames *******************************
99 **
100 ** Array of Ensembl Repeat Feature Adaptor SQL table names
101 **
102 ******************************************************************************/
103 
104 static const char *repeatfeatureadaptorKTablenames[] =
105 {
106     "repeat_feature",
107     "repeat_consensus",
108     (const char *) NULL
109 };
110 
111 
112 
113 
114 /* @conststatic repeatfeatureadaptorKColumnnames ******************************
115 **
116 ** Array of Ensembl Repeat Feature Adaptor SQL column names
117 **
118 ******************************************************************************/
119 
120 static const char *repeatfeatureadaptorKColumnnames[] =
121 {
122     "repeat_feature.repeat_feature_id",
123     "repeat_feature.seq_region_id",
124     "repeat_feature.seq_region_start",
125     "repeat_feature.seq_region_end",
126     "repeat_feature.seq_region_strand",
127     "repeat_feature.repeat_consensus_id",
128     "repeat_feature.repeat_start",
129     "repeat_feature.repeat_end",
130     "repeat_feature.analysis_id",
131     "repeat_feature.score",
132     (const char *) NULL
133 };
134 
135 
136 
137 
138 /* @conststatic repeatfeatureadaptorKDefaultcondition *************************
139 **
140 ** Ensembl Repeat Feature Adaptor SQL SELECT default condition
141 **
142 ******************************************************************************/
143 
144 static const char *repeatfeatureadaptorKDefaultcondition =
145     "repeat_feature.repeat_consensus_id = "
146     "repeat_consensus.repeat_consensus_id";
147 
148 
149 
150 
151 /* ========================================================================= */
152 /* =========================== private variables =========================== */
153 /* ========================================================================= */
154 
155 
156 
157 
158 /* ========================================================================= */
159 /* =========================== private functions =========================== */
160 /* ========================================================================= */
161 
162 static AjBool repeatconsensusadaptorFetchAllbyStatement(
163     EnsPBaseadaptor ba,
164     const AjPStr statement,
165     EnsPAssemblymapper am,
166     EnsPSlice slice,
167     AjPList rci);
168 
169 static int listRepeatfeatureCompareEndAscending(
170     const void *item1,
171     const void *item2);
172 
173 static int listRepeatfeatureCompareEndDescending(
174     const void *item1,
175     const void *item2);
176 
177 static int listRepeatfeatureCompareIdentifierAscending(
178     const void *item1,
179     const void *item2);
180 
181 static int listRepeatfeatureCompareStartAscending(
182     const void *item1,
183     const void *item2);
184 
185 static int listRepeatfeatureCompareStartDescending(
186     const void *item1,
187     const void *item2);
188 
189 static void repeatfeatureadaptorLinkRepeatconsensus(void **Pkey,
190                                                     void **Pvalue,
191                                                     void *cl);
192 
193 static AjBool repeatfeatureadaptorFetchAllbyStatement(
194     EnsPBaseadaptor ba,
195     const AjPStr statement,
196     EnsPAssemblymapper am,
197     EnsPSlice slice,
198     AjPList rfs);
199 
200 
201 
202 
203 /* ========================================================================= */
204 /* ======================= All functions by section ======================== */
205 /* ========================================================================= */
206 
207 
208 
209 
210 /* @filesection ensrepeat *****************************************************
211 **
212 ** @nam1rule ens Function belongs to the Ensembl library
213 **
214 ******************************************************************************/
215 
216 
217 
218 
219 /* @datasection [EnsPRepeatconsensus] Ensembl Repeat Consensus ****************
220 **
221 ** @nam2rule Repeatconsensus Functions for manipulating
222 ** Ensembl Repeat Consensus objects
223 **
224 ** @cc Bio::EnsEMBL::RepeatConsensus
225 ** @cc CVS Revision: 1.14
226 ** @cc CVS Tag: branch-ensembl-68
227 **
228 ******************************************************************************/
229 
230 
231 
232 
233 /* @section constructors ******************************************************
234 **
235 ** All constructors return a new Ensembl Repeat Consensus by pointer.
236 ** It is the responsibility of the user to first destroy any previous
237 ** Repeat Consensus. The target pointer does not need to be initialised to
238 ** NULL, but it is good programming practice to do so anyway.
239 **
240 ** @fdata [EnsPRepeatconsensus]
241 **
242 ** @nam3rule New Constructor
243 ** @nam4rule Cpy Constructor with existing object
244 ** @nam4rule Ini Constructor with initial values
245 ** @nam4rule Ref Constructor by incrementing the reference counter
246 **
247 ** @argrule Cpy rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
248 ** @argrule Ini rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus
249 ** Adaptor
250 ** @argrule Ini identifier [ajuint] SQL database-internal identifier
251 ** @argrule Ini name [AjPStr] Repeat Consensus name
252 ** @argrule Ini class [AjPStr] Repeat Consensus class
253 ** @argrule Ini type [AjPStr] Repeat Consensus type
254 ** @argrule Ini consensus [AjPStr] Repeat Consensus sequence
255 ** @argrule Ini length [ajuint] Repeat Consensus sequence length
256 ** @argrule Ref rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
257 **
258 ** @valrule * [EnsPRepeatconsensus] Ensembl Repeat Consensus or NULL
259 **
260 ** @fcategory new
261 ******************************************************************************/
262 
263 
264 
265 
266 /* @func ensRepeatconsensusNewCpy *********************************************
267 **
268 ** Object-based constructor function, which returns an independent object.
269 **
270 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
271 **
272 ** @return [EnsPRepeatconsensus] Ensembl Repeat Consensus or NULL
273 **
274 ** @release 6.4.0
275 ** @@
276 ******************************************************************************/
277 
ensRepeatconsensusNewCpy(const EnsPRepeatconsensus rc)278 EnsPRepeatconsensus ensRepeatconsensusNewCpy(const EnsPRepeatconsensus rc)
279 {
280     EnsPRepeatconsensus pthis = NULL;
281 
282     if (!rc)
283         return NULL;
284 
285     AJNEW0(pthis);
286 
287     pthis->Adaptor = rc->Adaptor;
288 
289     pthis->Identifier = rc->Identifier;
290 
291     if (rc->Name)
292         pthis->Name = ajStrNewRef(rc->Name);
293 
294     if (rc->Class)
295         pthis->Class = ajStrNewRef(rc->Class);
296 
297     if (rc->Type)
298         pthis->Type = ajStrNewRef(rc->Type);
299 
300     if (rc->Consensus)
301         pthis->Consensus = ajStrNewRef(rc->Consensus);
302 
303     pthis->Length = rc->Length;
304 
305     pthis->Use = 1U;
306 
307     return pthis;
308 }
309 
310 
311 
312 
313 /* @func ensRepeatconsensusNewIni *********************************************
314 **
315 ** Constructor for an Ensembl Repeat Consensus with initial values.
316 **
317 ** @cc Bio::EnsEMBL::RepeatConsensus::new
318 ** @param [u] rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
319 ** @param [r] identifier [ajuint] SQL database-internal identifier
320 ** @param [u] name [AjPStr] Repeat Consensus name
321 ** @param [u] class [AjPStr] Repeat Consensus class
322 ** @param [u] type [AjPStr] Repeat Consensus type
323 ** @param [u] consensus [AjPStr] Repeat Consensus sequence
324 ** @param [r] length [ajuint] Repeat Consensus sequence length
325 **
326 ** @return [EnsPRepeatconsensus] Ensembl Repeat Consensus or NULL
327 **
328 ** @release 6.4.0
329 ** @@
330 ******************************************************************************/
331 
ensRepeatconsensusNewIni(EnsPRepeatconsensusadaptor rca,ajuint identifier,AjPStr name,AjPStr class,AjPStr type,AjPStr consensus,ajuint length)332 EnsPRepeatconsensus ensRepeatconsensusNewIni(EnsPRepeatconsensusadaptor rca,
333                                              ajuint identifier,
334                                              AjPStr name,
335                                              AjPStr class,
336                                              AjPStr type,
337                                              AjPStr consensus,
338                                              ajuint length)
339 {
340     EnsPRepeatconsensus rc = NULL;
341 
342     AJNEW0(rc);
343 
344     rc->Adaptor    = rca;
345     rc->Identifier = identifier;
346 
347     if (name)
348         rc->Name = ajStrNewRef(name);
349 
350     if (class)
351         rc->Class = ajStrNewRef(class);
352 
353     if (type)
354         rc->Type = ajStrNewRef(type);
355 
356     if (consensus)
357         rc->Consensus = ajStrNewRef(consensus);
358 
359     rc->Length = length;
360 
361     rc->Use = 1U;
362 
363     return rc;
364 }
365 
366 
367 
368 
369 /* @func ensRepeatconsensusNewRef *********************************************
370 **
371 ** Ensembl Object referencing function, which returns a pointer to the
372 ** Ensembl Object passed in and increases its reference count.
373 **
374 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
375 **
376 ** @return [EnsPRepeatconsensus] Ensembl Repeat Consensus or NULL
377 **
378 ** @release 6.2.0
379 ** @@
380 ******************************************************************************/
381 
ensRepeatconsensusNewRef(EnsPRepeatconsensus rc)382 EnsPRepeatconsensus ensRepeatconsensusNewRef(EnsPRepeatconsensus rc)
383 {
384     if (!rc)
385         return NULL;
386 
387     rc->Use++;
388 
389     return rc;
390 }
391 
392 
393 
394 
395 /* @section destructors *******************************************************
396 **
397 ** Destruction destroys all internal data structures and frees the memory
398 ** allocated for an Ensembl Repeat Consensus object.
399 **
400 ** @fdata [EnsPRepeatconsensus]
401 **
402 ** @nam3rule Del Destroy (free) an Ensembl Repeat Consensus
403 **
404 ** @argrule * Prc [EnsPRepeatconsensus*] Ensembl Repeat Consensus address
405 **
406 ** @valrule * [void]
407 **
408 ** @fcategory delete
409 ******************************************************************************/
410 
411 
412 
413 
414 /* @func ensRepeatconsensusDel ************************************************
415 **
416 ** Default destructor for an Ensembl Repeat Consensus.
417 **
418 ** @param [d] Prc [EnsPRepeatconsensus*] Ensembl Repeat Consensus address
419 **
420 ** @return [void]
421 **
422 ** @release 6.2.0
423 ** @@
424 ******************************************************************************/
425 
ensRepeatconsensusDel(EnsPRepeatconsensus * Prc)426 void ensRepeatconsensusDel(EnsPRepeatconsensus *Prc)
427 {
428     EnsPRepeatconsensus pthis = NULL;
429 
430     if (!Prc)
431         return;
432 
433 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
434     if (ajDebugTest("ensRepeatconsensusDel"))
435     {
436         ajDebug("ensRepeatconsensusDel\n"
437                 "  *Prc %p\n",
438                 *Prc);
439 
440         ensRepeatconsensusTrace(*Prc, 1);
441     }
442 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
443 
444     if (!(pthis = *Prc) || --pthis->Use)
445     {
446         *Prc = NULL;
447 
448         return;
449     }
450 
451     ajStrDel(&pthis->Name);
452     ajStrDel(&pthis->Class);
453     ajStrDel(&pthis->Type);
454     ajStrDel(&pthis->Consensus);
455 
456     ajMemFree((void **) Prc);
457 
458     return;
459 }
460 
461 
462 
463 
464 /* @section member retrieval **************************************************
465 **
466 ** Functions for returning members of an Ensembl Repeat Consensus object.
467 **
468 ** @fdata [EnsPRepeatconsensus]
469 **
470 ** @nam3rule Get Return Repeat Consensus attribute(s)
471 ** @nam4rule Adaptor Return the Ensembl Repeat Consensus Adaptor
472 ** @nam4rule Class Return the class
473 ** @nam4rule Consensus Return the consensus sequence
474 ** @nam4rule Identifier Return the SQL database-internal identifier
475 ** @nam4rule Length Return the length
476 ** @nam4rule Name Return the name
477 ** @nam4rule Type Return the type
478 **
479 ** @argrule * rc [const EnsPRepeatconsensus] Repeat Consensus
480 **
481 ** @valrule Adaptor [EnsPRepeatconsensusadaptor]
482 ** Ensembl Repeat Consensus Adaptor or NULL
483 ** @valrule Class [AjPStr] Class or NULL
484 ** @valrule Consensus [AjPStr] Consensus sequence or NULL
485 ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U
486 ** @valrule Length [ajuint] Length or 0U
487 ** @valrule Name [AjPStr] Name or NULL
488 ** @valrule Type [AjPStr] Type or NULL
489 **
490 ** @fcategory use
491 ******************************************************************************/
492 
493 
494 
495 
496 /* @func ensRepeatconsensusGetAdaptor *****************************************
497 **
498 ** Get the Ensembl Repeat Consensus Adaptor member of an
499 ** Ensembl Repeat Consensus.
500 **
501 ** @cc Bio::EnsEMBL::Storable::adaptor
502 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
503 **
504 ** @return [EnsPRepeatconsensusadaptor]
505 ** Ensembl Repeat Consensus Adaptor or NULL
506 **
507 ** @release 6.2.0
508 ** @@
509 ******************************************************************************/
510 
ensRepeatconsensusGetAdaptor(const EnsPRepeatconsensus rc)511 EnsPRepeatconsensusadaptor ensRepeatconsensusGetAdaptor(
512     const EnsPRepeatconsensus rc)
513 {
514     return (rc) ? rc->Adaptor : NULL;
515 }
516 
517 
518 
519 
520 /* @func ensRepeatconsensusGetClass *******************************************
521 **
522 ** Get the class member of an Ensembl Repeat Consensus.
523 **
524 ** @cc Bio::EnsEMBL::RepeatConsensus::repeat_class
525 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
526 **
527 ** @return [AjPStr] Class or NULL
528 **
529 ** @release 6.2.0
530 ** @@
531 ******************************************************************************/
532 
ensRepeatconsensusGetClass(const EnsPRepeatconsensus rc)533 AjPStr ensRepeatconsensusGetClass(const EnsPRepeatconsensus rc)
534 {
535     return (rc) ? rc->Class : NULL;
536 }
537 
538 
539 
540 
541 /* @func ensRepeatconsensusGetConsensus ***************************************
542 **
543 ** Get the consensus sequence member of an Ensembl Repeat Consensus.
544 **
545 ** @cc Bio::EnsEMBL::RepeatConsensus::repeat_consensus
546 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
547 **
548 ** @return [AjPStr] Consensus sequence or NULL
549 **
550 ** @release 6.2.0
551 ** @@
552 ******************************************************************************/
553 
ensRepeatconsensusGetConsensus(const EnsPRepeatconsensus rc)554 AjPStr ensRepeatconsensusGetConsensus(const EnsPRepeatconsensus rc)
555 {
556     return (rc) ? rc->Consensus : NULL;
557 }
558 
559 
560 
561 
562 /* @func ensRepeatconsensusGetIdentifier **************************************
563 **
564 ** Get the SQL database-internal identifier member of an
565 ** Ensembl Repeat Consensus.
566 **
567 ** @cc Bio::EnsEMBL::Storable::dbID
568 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
569 **
570 ** @return [ajuint] SQL database-internal identifier or 0U
571 **
572 ** @release 6.2.0
573 ** @@
574 ******************************************************************************/
575 
ensRepeatconsensusGetIdentifier(const EnsPRepeatconsensus rc)576 ajuint ensRepeatconsensusGetIdentifier(const EnsPRepeatconsensus rc)
577 {
578     return (rc) ? rc->Identifier : 0U;
579 }
580 
581 
582 
583 
584 /* @func ensRepeatconsensusGetLength ******************************************
585 **
586 ** Get the length member of an Ensembl Repeat Consensus.
587 **
588 ** @cc Bio::EnsEMBL::RepeatConsensus::length
589 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
590 **
591 ** @return [ajuint] Length or 0U
592 **
593 ** @release 6.2.0
594 ** @@
595 ******************************************************************************/
596 
ensRepeatconsensusGetLength(const EnsPRepeatconsensus rc)597 ajuint ensRepeatconsensusGetLength(const EnsPRepeatconsensus rc)
598 {
599     return (rc) ? rc->Length : 0U;
600 }
601 
602 
603 
604 
605 /* @func ensRepeatconsensusGetName ********************************************
606 **
607 ** Get the name member of an Ensembl Repeat Consensus.
608 **
609 ** @cc Bio::EnsEMBL::RepeatConsensus::name
610 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
611 **
612 ** @return [AjPStr] Name or NULL
613 **
614 ** @release 6.2.0
615 ** @@
616 ******************************************************************************/
617 
ensRepeatconsensusGetName(const EnsPRepeatconsensus rc)618 AjPStr ensRepeatconsensusGetName(const EnsPRepeatconsensus rc)
619 {
620     return (rc) ? rc->Name : NULL;
621 }
622 
623 
624 
625 
626 /* @func ensRepeatconsensusGetType ********************************************
627 **
628 ** Get the type member of an Ensembl Repeat Consensus.
629 **
630 ** @cc Bio::EnsEMBL::RepeatConsensus::repeat_type
631 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
632 **
633 ** @return [AjPStr] Type or NULL
634 **
635 ** @release 6.2.0
636 ** @@
637 ******************************************************************************/
638 
ensRepeatconsensusGetType(const EnsPRepeatconsensus rc)639 AjPStr ensRepeatconsensusGetType(const EnsPRepeatconsensus rc)
640 {
641     return (rc) ? rc->Type : NULL;
642 }
643 
644 
645 
646 
647 /* @section modifiers *********************************************************
648 **
649 ** Functions for assigning members of an Ensembl Repeat Consensus object.
650 **
651 ** @fdata [EnsPRepeatconsensus]
652 **
653 ** @nam3rule Set Set one member of a Repeat Consensus
654 ** @nam4rule Adaptor Set the Ensembl Repeat Consensus Adaptor
655 ** @nam4rule Class Set the class
656 ** @nam4rule Consensus Set the consensus sequence
657 ** @nam4rule Identifier Set the SQL database-internal identifier
658 ** @nam4rule Length Set the length
659 ** @nam4rule Name Set the name
660 ** @nam4rule Type Set the type
661 **
662 ** @argrule * rc [EnsPRepeatconsensus] Ensembl Repeat Consensus object
663 ** @argrule Adaptor rca [EnsPRepeatconsensusadaptor] Ensembl Repeat
664 **                                                   Consensus Adaptor
665 ** @argrule Class class [AjPStr] Class
666 ** @argrule Consensus consensus [AjPStr] Consensus sequence
667 ** @argrule Identifier identifier [ajuint] SQL database-internal identifier
668 ** @argrule Length length [ajuint] Length
669 ** @argrule Name name [AjPStr] Name
670 ** @argrule Type type [AjPStr] Type
671 **
672 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
673 **
674 ** @fcategory modify
675 ******************************************************************************/
676 
677 
678 
679 
680 /* @func ensRepeatconsensusSetAdaptor *****************************************
681 **
682 ** Set the Ensembl Repeat Consensus Adaptor member of an
683 ** Ensembl Repeat Consensus.
684 **
685 ** @cc Bio::EnsEMBL::Storable::adaptor
686 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
687 ** @param [u] rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
688 **
689 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
690 **
691 ** @release 6.2.0
692 ** @@
693 ******************************************************************************/
694 
ensRepeatconsensusSetAdaptor(EnsPRepeatconsensus rc,EnsPRepeatconsensusadaptor rca)695 AjBool ensRepeatconsensusSetAdaptor(EnsPRepeatconsensus rc,
696                                     EnsPRepeatconsensusadaptor rca)
697 {
698     if (!rc)
699         return ajFalse;
700 
701     rc->Adaptor = rca;
702 
703     return ajTrue;
704 }
705 
706 
707 
708 
709 /* @func ensRepeatconsensusSetClass *******************************************
710 **
711 ** Set the class member of an Ensembl Repeat Consensus.
712 **
713 ** @cc Bio::EnsEMBL::RepeatConsensus::repeat_class
714 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
715 ** @param [u] class [AjPStr] Class
716 **
717 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
718 **
719 ** @release 6.2.0
720 ** @@
721 ******************************************************************************/
722 
ensRepeatconsensusSetClass(EnsPRepeatconsensus rc,AjPStr class)723 AjBool ensRepeatconsensusSetClass(EnsPRepeatconsensus rc,
724                                   AjPStr class)
725 {
726     if (!rc)
727         return ajFalse;
728 
729     ajStrDel(&rc->Class);
730 
731     if (class)
732         rc->Class = ajStrNewRef(class);
733 
734     return ajTrue;
735 }
736 
737 
738 
739 
740 /* @func ensRepeatconsensusSetConsensus ***************************************
741 **
742 ** Set the consensus sequence member of an Ensembl Repeat Consensus.
743 **
744 ** @cc Bio::EnsEMBL::RepeatConsensus::repeat_consensus
745 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
746 ** @param [u] consensus [AjPStr] Consensus sequence
747 **
748 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
749 **
750 ** @release 6.2.0
751 ** @@
752 ******************************************************************************/
753 
ensRepeatconsensusSetConsensus(EnsPRepeatconsensus rc,AjPStr consensus)754 AjBool ensRepeatconsensusSetConsensus(EnsPRepeatconsensus rc,
755                                       AjPStr consensus)
756 {
757     if (!rc)
758         return ajFalse;
759 
760     ajStrDel(&rc->Consensus);
761 
762     if (consensus)
763         rc->Consensus = ajStrNewRef(consensus);
764 
765     return ajTrue;
766 }
767 
768 
769 
770 
771 /* @func ensRepeatconsensusSetIdentifier **************************************
772 **
773 ** Set the SQL database-internal identifier member of an
774 ** Ensembl Repeat Consensus.
775 **
776 ** @cc Bio::EnsEMBL::Storable::dbID
777 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
778 ** @param [r] identifier [ajuint] SQL database-internal identifier
779 **
780 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
781 **
782 ** @release 6.2.0
783 ** @@
784 ******************************************************************************/
785 
ensRepeatconsensusSetIdentifier(EnsPRepeatconsensus rc,ajuint identifier)786 AjBool ensRepeatconsensusSetIdentifier(EnsPRepeatconsensus rc,
787                                        ajuint identifier)
788 {
789     if (!rc)
790         return ajFalse;
791 
792     rc->Identifier = identifier;
793 
794     return ajTrue;
795 }
796 
797 
798 
799 
800 /* @func ensRepeatconsensusSetLength ******************************************
801 **
802 ** Set the length member of an Ensembl Repeat Consensus.
803 **
804 ** @cc Bio::EnsEMBL::RepeatConsensus::length
805 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
806 ** @param [r] length [ajuint] Length
807 **
808 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
809 **
810 ** @release 6.2.0
811 ** @@
812 ******************************************************************************/
813 
ensRepeatconsensusSetLength(EnsPRepeatconsensus rc,ajuint length)814 AjBool ensRepeatconsensusSetLength(EnsPRepeatconsensus rc,
815                                    ajuint length)
816 {
817     if (!rc)
818         return ajFalse;
819 
820     rc->Length = length;
821 
822     return ajTrue;
823 }
824 
825 
826 
827 
828 /* @func ensRepeatconsensusSetName ********************************************
829 **
830 ** Set the name member of an Ensembl Repeat Consensus.
831 **
832 ** @cc Bio::EnsEMBL::RepeatConsensus::name
833 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
834 ** @param [u] name [AjPStr] Name
835 **
836 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
837 **
838 ** @release 6.2.0
839 ** @@
840 ******************************************************************************/
841 
ensRepeatconsensusSetName(EnsPRepeatconsensus rc,AjPStr name)842 AjBool ensRepeatconsensusSetName(EnsPRepeatconsensus rc,
843                                  AjPStr name)
844 {
845     if (!rc)
846         return ajFalse;
847 
848     ajStrDel(&rc->Name);
849 
850     if (name)
851         rc->Name = ajStrNewRef(name);
852 
853     return ajTrue;
854 }
855 
856 
857 
858 
859 /* @func ensRepeatconsensusSetType ********************************************
860 **
861 ** Set the type member of an Ensembl Repeat Consensus.
862 **
863 ** @cc Bio::EnsEMBL::RepeatConsensus::repeat_type
864 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
865 ** @param [u] type [AjPStr] Type
866 **
867 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
868 **
869 ** @release 6.2.0
870 ** @@
871 ******************************************************************************/
872 
ensRepeatconsensusSetType(EnsPRepeatconsensus rc,AjPStr type)873 AjBool ensRepeatconsensusSetType(EnsPRepeatconsensus rc,
874                                  AjPStr type)
875 {
876     if (!rc)
877         return ajFalse;
878 
879     ajStrDel(&rc->Type);
880 
881     if (type)
882         rc->Type = ajStrNewRef(type);
883 
884     return ajTrue;
885 }
886 
887 
888 
889 
890 /* @section debugging *********************************************************
891 **
892 ** Functions for reporting of an Ensembl Repeat Consensus object.
893 **
894 ** @fdata [EnsPRepeatconsensus]
895 **
896 ** @nam3rule Trace Report Ensembl Repeat Consensus members to debug file
897 **
898 ** @argrule Trace rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
899 ** @argrule Trace level [ajuint] Indentation level
900 **
901 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
902 **
903 ** @fcategory misc
904 ******************************************************************************/
905 
906 
907 
908 
909 /* @func ensRepeatconsensusTrace **********************************************
910 **
911 ** Trace an Ensembl Repeat Consensus.
912 **
913 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
914 ** @param [r] level [ajuint] Indentation level
915 **
916 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
917 **
918 ** @release 6.2.0
919 ** @@
920 ******************************************************************************/
921 
ensRepeatconsensusTrace(const EnsPRepeatconsensus rc,ajuint level)922 AjBool ensRepeatconsensusTrace(const EnsPRepeatconsensus rc, ajuint level)
923 {
924     AjPStr indent = NULL;
925 
926     if (!rc)
927         return ajFalse;
928 
929     indent = ajStrNew();
930 
931     ajStrAppendCountK(&indent, ' ', level * 2);
932 
933     ajDebug("%SensRepeatconsensusTrace %p\n"
934             "%S  Adaptor %p\n"
935             "%S  Identifier %u\n"
936             "%S  Name '%S'\n"
937             "%S  Class '%S'\n"
938             "%S  Type '%S'\n"
939             "%S  Consensus '%S'\n"
940             "%S  Length %u\n"
941             "%S  Use %u\n",
942             indent, rc,
943             indent, rc->Adaptor,
944             indent, rc->Identifier,
945             indent, rc->Name,
946             indent, rc->Class,
947             indent, rc->Type,
948             indent, rc->Consensus,
949             indent, rc->Length,
950             indent, rc->Use);
951 
952     ajStrDel(&indent);
953 
954     return ajTrue;
955 }
956 
957 
958 
959 
960 /* @section calculate *********************************************************
961 **
962 ** Functions for calculating information from an
963 ** Ensembl Repeat Consensus object.
964 **
965 ** @fdata [EnsPRepeatconsensus]
966 **
967 ** @nam3rule Calculate Calculate Ensembl Repeat Consensus information
968 ** @nam4rule Memsize Calculate the memory size in bytes
969 **
970 ** @argrule * rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
971 **
972 ** @valrule Memsize [size_t] Memory size in bytes or 0
973 **
974 ** @fcategory misc
975 ******************************************************************************/
976 
977 
978 
979 
980 /* @func ensRepeatconsensusCalculateMemsize ***********************************
981 **
982 ** Calculate the memory size in bytes of an Ensembl Repeat Consensus.
983 **
984 ** @param [r] rc [const EnsPRepeatconsensus] Ensembl Repeat Consensus
985 **
986 ** @return [size_t] Memory size in bytes or 0
987 **
988 ** @release 6.4.0
989 ** @@
990 ******************************************************************************/
991 
ensRepeatconsensusCalculateMemsize(const EnsPRepeatconsensus rc)992 size_t ensRepeatconsensusCalculateMemsize(const EnsPRepeatconsensus rc)
993 {
994     size_t size = 0;
995 
996     if (!rc)
997         return 0;
998 
999     size += sizeof (EnsORepeatconsensus);
1000 
1001     if (rc->Name)
1002     {
1003         size += sizeof (AjOStr);
1004 
1005         size += ajStrGetRes(rc->Name);
1006     }
1007 
1008     if (rc->Class)
1009     {
1010         size += sizeof (AjOStr);
1011 
1012         size += ajStrGetRes(rc->Class);
1013     }
1014 
1015     if (rc->Type)
1016     {
1017         size += sizeof (AjOStr);
1018 
1019         size += ajStrGetRes(rc->Type);
1020     }
1021 
1022     if (rc->Consensus)
1023     {
1024         size += sizeof (AjOStr);
1025 
1026         size += ajStrGetRes(rc->Consensus);
1027     }
1028 
1029     return size;
1030 }
1031 
1032 
1033 
1034 
1035 /* @datasection [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
1036 **
1037 ** @nam2rule Repeatconsensusadaptor Functions for manipulating
1038 ** Ensembl Repeat Consensus Adaptor objects
1039 **
1040 ** @cc Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor
1041 ** @cc CVS Revision: 1.25
1042 ** @cc CVS Tag: branch-ensembl-68
1043 **
1044 ******************************************************************************/
1045 
1046 
1047 
1048 
1049 /* @funcstatic repeatconsensusadaptorFetchAllbyStatement **********************
1050 **
1051 ** Run a SQL statement against an Ensembl Database Adaptor and consolidate the
1052 ** results into an AJAX List of Ensembl Repeat Consensus objects.
1053 ** The caller is responsible for deleting the Ensembl Repeat Consensi before
1054 ** deleting the AJAX List.
1055 **
1056 ** @cc Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::_generic_fetch
1057 ** @param [u] ba [EnsPBaseadaptor] Ensembl Base Adaptor
1058 ** @param [r] statement [const AjPStr] SQL statement
1059 ** @param [uN] am [EnsPAssemblymapper] Ensembl Assembly Mapper
1060 ** @param [uN] slice [EnsPSlice] Ensembl Slice
1061 ** @param [u] rci [AjPList] AJAX List of Ensembl Repeat Consensi
1062 **
1063 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1064 **
1065 ** @release 6.4.0
1066 ** @@
1067 ******************************************************************************/
1068 
repeatconsensusadaptorFetchAllbyStatement(EnsPBaseadaptor ba,const AjPStr statement,EnsPAssemblymapper am,EnsPSlice slice,AjPList rci)1069 static AjBool repeatconsensusadaptorFetchAllbyStatement(
1070     EnsPBaseadaptor ba,
1071     const AjPStr statement,
1072     EnsPAssemblymapper am,
1073     EnsPSlice slice,
1074     AjPList rci)
1075 {
1076     const char *Ptr = NULL;
1077 
1078     register ajuint i = 0U;
1079 
1080     ajuint identifier = 0U;
1081     ajuint length     = 0U;
1082 
1083     AjPRegexp rp = NULL;
1084 
1085     AjPSqlstatement sqls = NULL;
1086     AjISqlrow sqli       = NULL;
1087     AjPSqlrow sqlr       = NULL;
1088 
1089     AjPStr name      = NULL;
1090     AjPStr class     = NULL;
1091     AjPStr type      = NULL;
1092     AjPStr consensus = NULL;
1093     AjPStr number    = NULL;
1094 
1095     EnsPDatabaseadaptor dba = NULL;
1096 
1097     EnsPRepeatconsensus rc         = NULL;
1098     EnsPRepeatconsensusadaptor rca = NULL;
1099 
1100     if (ajDebugTest("repeatconsensusadaptorFetchAllbyStatement"))
1101         ajDebug("repeatconsensusadaptorFetchAllbyStatement\n"
1102                 "  ba %p\n"
1103                 "  statement %p\n"
1104                 "  am %p\n"
1105                 "  slice %p\n"
1106                 "  rci %p\n",
1107                 ba,
1108                 statement,
1109                 am,
1110                 slice,
1111                 rci);
1112 
1113     if (!ba)
1114         return ajFalse;
1115 
1116     if (!statement)
1117         return ajFalse;
1118 
1119     if (!rci)
1120         return ajFalse;
1121 
1122     rp = ajRegCompC("^(\\d+)\\(N\\)$");
1123 
1124     number = ajStrNew();
1125 
1126     dba = ensBaseadaptorGetDatabaseadaptor(ba);
1127 
1128     rca = ensRegistryGetRepeatconsensusadaptor(dba);
1129 
1130     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
1131 
1132     sqli = ajSqlrowiterNew(sqls);
1133 
1134     while (!ajSqlrowiterDone(sqli))
1135     {
1136         identifier = 0U;
1137         name       = ajStrNew();
1138         class      = ajStrNew();
1139         type       = ajStrNew();
1140         consensus  = ajStrNew();
1141         length     = 0U;
1142 
1143         sqlr = ajSqlrowiterGet(sqli);
1144 
1145         ajSqlcolumnToUint(sqlr, &identifier);
1146         ajSqlcolumnToStr(sqlr, &name);
1147         ajSqlcolumnToStr(sqlr, &class);
1148         ajSqlcolumnToStr(sqlr, &type);
1149         ajSqlcolumnToStr(sqlr, &consensus);
1150 
1151         /*
1152         ** Check the Ensembl Repeat consus whether it obeys the ^\\d+\\(N\\)$
1153         ** format or alternatively, use the string length, which should
1154         ** conveniently fit into an unsigned integer.
1155         */
1156 
1157         if (ajRegExec(rp, consensus))
1158         {
1159             ajRegSubI(rp, 1, &number);
1160 
1161             if (!ajStrToUint(number, &length))
1162                 ajWarn("Could not convert repeat consensus '%S', which obeys "
1163                        "the \\d+\\(N\\) format, into an unsigned integer.\n",
1164                        consensus);
1165         }
1166         else
1167         {
1168             /*
1169             ** NOTE: Since ajStrGetLen returns size_t, which exceeds ajuint,
1170             ** the length of the consensus sequence needs to be determined
1171             ** here.
1172             **
1173             ** length = (ajuint) ajStrGetLen(consensus);
1174             */
1175 
1176             for (i = 0U, Ptr = ajStrGetPtr(consensus);
1177                  (Ptr && *Ptr);
1178                  i++, Ptr++)
1179                 if (i == UINT_MAX)
1180                     ajFatal("repeatconsensusadaptorFetchAllbyStatement got a "
1181                             "consensus, which length exeeded UINT_MAX.");
1182 
1183             length = i;
1184         }
1185 
1186         rc = ensRepeatconsensusNewIni(rca,
1187                                       identifier,
1188                                       name,
1189                                       class,
1190                                       type,
1191                                       consensus,
1192                                       length);
1193 
1194         ajListPushAppend(rci, (void *) rc);
1195 
1196         ajStrDel(&name);
1197         ajStrDel(&class);
1198         ajStrDel(&type);
1199         ajStrDel(&consensus);
1200     }
1201 
1202     ajSqlrowiterDel(&sqli);
1203 
1204     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
1205 
1206     ajRegFree(&rp);
1207 
1208     ajStrDel(&number);
1209 
1210     return ajTrue;
1211 }
1212 
1213 
1214 
1215 
1216 /* @section constructors ******************************************************
1217 **
1218 ** All constructors return a new Ensembl Repeat Consensus Adaptor by pointer.
1219 ** It is the responsibility of the user to first destroy any previous
1220 ** Repeat Consensus Adaptor. The target pointer does not need to be
1221 ** initialised to NULL, but it is good programming practice to do so anyway.
1222 **
1223 ** @fdata [EnsPRepeatconsensusadaptor]
1224 **
1225 ** @nam3rule New Constructor
1226 **
1227 ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
1228 **
1229 ** @valrule * [EnsPRepeatconsensusadaptor]
1230 ** Ensembl Repeat Consensus Adaptor or NULL
1231 **
1232 ** @fcategory new
1233 ******************************************************************************/
1234 
1235 
1236 
1237 
1238 /* @func ensRepeatconsensusadaptorNew *****************************************
1239 **
1240 ** Default constructor for an Ensembl Repeat Consensus Adaptor.
1241 **
1242 ** Ensembl Object Adaptors are singleton objects in the sense that a single
1243 ** instance of an Ensembl Object Adaptor connected to a particular database is
1244 ** sufficient to instantiate any number of Ensembl Objects from the database.
1245 ** Each Ensembl Object will have a weak reference to the Object Adaptor that
1246 ** instantiated it. Therefore, Ensembl Object Adaptors should not be
1247 ** instantiated directly, but rather obtained from the Ensembl Registry,
1248 ** which will in turn call this function if neccessary.
1249 **
1250 ** @see ensRegistryGetDatabaseadaptor
1251 ** @see ensRegistryGetRepeatconsensusadaptor
1252 **
1253 ** @cc Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::new
1254 ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
1255 **
1256 ** @return [EnsPRepeatconsensusadaptor]
1257 ** Ensembl Repat Consensus Adaptor or NULL
1258 **
1259 ** @release 6.4.0
1260 ** @@
1261 ******************************************************************************/
1262 
ensRepeatconsensusadaptorNew(EnsPDatabaseadaptor dba)1263 EnsPRepeatconsensusadaptor ensRepeatconsensusadaptorNew(
1264     EnsPDatabaseadaptor dba)
1265 {
1266     return ensBaseadaptorNew(
1267         dba,
1268         repeatconsensusadaptorKTablenames,
1269         repeatconsensusadaptorKColumnnames,
1270         (const EnsPBaseadaptorLeftjoin) NULL,
1271         (const char *) NULL,
1272         (const char *) NULL,
1273         &repeatconsensusadaptorFetchAllbyStatement);
1274 }
1275 
1276 
1277 
1278 
1279 /* @section destructors *******************************************************
1280 **
1281 ** Destruction destroys all internal data structures and frees the memory
1282 ** allocated for an Ensembl Repeat Consensus Adaptor object.
1283 **
1284 ** @fdata [EnsPRepeatconsensusadaptor]
1285 **
1286 ** @nam3rule Del Destroy (free) an Ensembl Repeat Consensus Adaptor
1287 **
1288 ** @argrule * Prca [EnsPRepeatconsensusadaptor*]
1289 ** Ensembl Repeat Consensus Adaptor address
1290 **
1291 ** @valrule * [void]
1292 **
1293 ** @fcategory delete
1294 ******************************************************************************/
1295 
1296 
1297 
1298 
1299 /* @func ensRepeatconsensusadaptorDel *****************************************
1300 **
1301 ** Default destructor for an Ensembl Repeat Consensus Adaptor.
1302 **
1303 ** This function also clears the internal caches.
1304 **
1305 ** Ensembl Object Adaptors are singleton objects that are registered in the
1306 ** Ensembl Registry and weakly referenced by Ensembl Objects that have been
1307 ** instantiated by it. Therefore, Ensembl Object Adaptors should never be
1308 ** destroyed directly. Upon exit, the Ensembl Registry will call this function
1309 ** if required.
1310 **
1311 ** @param [d] Prca [EnsPRepeatconsensusadaptor*]
1312 ** Ensembl Repeat Consensus Adaptor address
1313 **
1314 ** @return [void]
1315 **
1316 ** @release 6.4.0
1317 ** @@
1318 ******************************************************************************/
1319 
ensRepeatconsensusadaptorDel(EnsPRepeatconsensusadaptor * Prca)1320 void ensRepeatconsensusadaptorDel(EnsPRepeatconsensusadaptor *Prca)
1321 {
1322     ensBaseadaptorDel(Prca);
1323 
1324     return;
1325 }
1326 
1327 
1328 
1329 
1330 /* @section member retrieval **************************************************
1331 **
1332 ** Functions for returning members of an Ensembl Repeat Consensus Adaptor
1333 ** object.
1334 **
1335 ** @fdata [EnsPRepeatconsensusadaptor]
1336 **
1337 ** @nam3rule Get Return Repeat Consensus Adaptor attribute(s)
1338 ** @nam4rule Baseadaptor Return the Ensembl Base Adaptor
1339 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
1340 **
1341 ** @argrule * rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
1342 **
1343 ** @valrule Baseadaptor [EnsPBaseadaptor]
1344 ** Ensembl Base Adaptor or NULL
1345 ** @valrule Databaseadaptor [EnsPDatabaseadaptor]
1346 ** Ensembl Database Adaptor or NULL
1347 **
1348 ** @fcategory use
1349 ******************************************************************************/
1350 
1351 
1352 
1353 
1354 /* @func ensRepeatconsensusadaptorGetBaseadaptor ******************************
1355 **
1356 ** Get the Ensembl Base Adaptor member of an
1357 ** Ensembl Repeat Consensus Adaptor.
1358 **
1359 ** @param [u] rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
1360 **
1361 ** @return [EnsPBaseadaptor] Ensembl Base Adaptor or NULL
1362 **
1363 ** @release 6.5.0
1364 ** @@
1365 ******************************************************************************/
1366 
ensRepeatconsensusadaptorGetBaseadaptor(EnsPRepeatconsensusadaptor rca)1367 EnsPBaseadaptor ensRepeatconsensusadaptorGetBaseadaptor(
1368     EnsPRepeatconsensusadaptor rca)
1369 {
1370     return rca;
1371 }
1372 
1373 
1374 
1375 
1376 /* @func ensRepeatconsensusadaptorGetDatabaseadaptor **************************
1377 **
1378 ** Get the Ensembl Database Adaptor member of an
1379 ** Ensembl Repeat Consensus Adaptor.
1380 **
1381 ** @param [u] rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
1382 **
1383 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
1384 **
1385 ** @release 6.4.0
1386 ** @@
1387 ******************************************************************************/
1388 
ensRepeatconsensusadaptorGetDatabaseadaptor(EnsPRepeatconsensusadaptor rca)1389 EnsPDatabaseadaptor ensRepeatconsensusadaptorGetDatabaseadaptor(
1390     EnsPRepeatconsensusadaptor rca)
1391 {
1392     return ensBaseadaptorGetDatabaseadaptor(
1393         ensRepeatconsensusadaptorGetBaseadaptor(rca));
1394 }
1395 
1396 
1397 
1398 
1399 /* @section object retrieval **************************************************
1400 **
1401 ** Functions for fetching Ensembl Repeat Consensus objects from an
1402 ** Ensembl SQL database.
1403 **
1404 ** @fdata [EnsPRepeatconsensusadaptor]
1405 **
1406 ** @nam3rule Fetch Fetch Ensembl Repeat Consensus object(s)
1407 ** @nam4rule All Fetch all Ensembl Repeat Consensus objects
1408 ** @nam4rule Allby Fetch all Ensembl Repeat Consensus objects
1409 **                 matching a criterion
1410 ** @nam5rule Classconsensus Fetch all by class and consensus sequence
1411 ** @nam5rule Identifiers Fetch all by an AJAX Table
1412 ** @nam4rule By Fetch one Ensembl Repeat Consensus object
1413 **              matching a criterion
1414 ** @nam5rule Identifier Fetch by a SQL database-internal identifier
1415 ** @nam5rule Name Fetch by name and class
1416 **
1417 ** @argrule * rca [EnsPRepeatconsensusadaptor]
1418 ** Ensembl Repeat Consensus Adaptor
1419 ** @argrule AllbyClassconsensus class [const AjPStr]
1420 ** Class
1421 ** @argrule AllbyClassconsensus consensus [const AjPStr]
1422 ** Consensus sequence
1423 ** @argrule AllbyClassconsensus rci [AjPList]
1424 ** AJAX List of Ensembl Repeat Consensus objects
1425 ** @argrule AllbyIdentifiers rcit [AjPTable]
1426 ** AJAX Table of Ensembl Repeat Consensus objects
1427 ** @argrule ByIdentifier identifier [ajuint]
1428 ** SQL database-internal identifier
1429 ** @argrule ByIdentifier Prc [EnsPRepeatconsensus*]
1430 ** Ensembl Repeat Consensus address
1431 ** @argrule ByName name [const AjPStr]
1432 ** Name
1433 ** @argrule ByName class [const AjPStr]
1434 ** Class
1435 ** @argrule ByName Prc [EnsPRepeatconsensus*]
1436 ** Ensembl Repeat Consensus address
1437 **
1438 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1439 **
1440 ** @fcategory use
1441 ******************************************************************************/
1442 
1443 
1444 
1445 
1446 /* @func ensRepeatconsensusadaptorFetchAllbyClassconsensus ********************
1447 **
1448 ** Fetch all Ensembl Repeat Consensus objects by a class and
1449 ** consensus sequence.
1450 **
1451 ** The caller is responsible for deleting the Ensembl Repeat Consensus objects
1452 ** before deleting the AJAX List.
1453 **
1454 ** @cc Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::fetch_all_by_class_seq
1455 ** @param [u] rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
1456 ** @param [r] class [const AjPStr] Class
1457 ** @param [r] consensus [const AjPStr] Consensus sequence
1458 ** @param [u] rci [AjPList] AJAX List of Ensembl Repeat Consensi
1459 **
1460 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1461 **
1462 ** @release 6.4.0
1463 ** @@
1464 ******************************************************************************/
1465 
ensRepeatconsensusadaptorFetchAllbyClassconsensus(EnsPRepeatconsensusadaptor rca,const AjPStr class,const AjPStr consensus,AjPList rci)1466 AjBool ensRepeatconsensusadaptorFetchAllbyClassconsensus(
1467     EnsPRepeatconsensusadaptor rca,
1468     const AjPStr class,
1469     const AjPStr consensus,
1470     AjPList rci)
1471 {
1472     char *txtclass     = NULL;
1473     char *txtconsensus = NULL;
1474 
1475     AjBool result = AJFALSE;
1476 
1477     AjPStr constraint = NULL;
1478 
1479     EnsPBaseadaptor ba = NULL;
1480 
1481     if (!rca)
1482         return ajFalse;
1483 
1484     if (!class)
1485         return ajFalse;
1486 
1487     if (!consensus)
1488         return ajFalse;
1489 
1490     if (!rci)
1491         return ajFalse;
1492 
1493     ba = ensRepeatconsensusadaptorGetBaseadaptor(rca);
1494 
1495     ensBaseadaptorEscapeC(ba, &txtclass, class);
1496     ensBaseadaptorEscapeC(ba, &txtconsensus, consensus);
1497 
1498     constraint = ajFmtStr(
1499         "repeat_consensus.repeat_class = '%s' "
1500         "AND "
1501         "repeat_consensus.repeat_consensus = '%s'",
1502         txtclass,
1503         txtconsensus);
1504 
1505     ajCharDel(&txtclass);
1506     ajCharDel(&txtconsensus);
1507 
1508     result = ensBaseadaptorFetchAllbyConstraint(
1509         ba,
1510         constraint,
1511         (EnsPAssemblymapper) NULL,
1512         (EnsPSlice) NULL,
1513         rci);
1514 
1515     ajStrDel(&constraint);
1516 
1517     return result;
1518 }
1519 
1520 
1521 
1522 
1523 /* @func ensRepeatconsensusadaptorFetchAllbyIdentifiers ***********************
1524 **
1525 ** Fetch all Ensembl Repeat Consensus objects by an AJAX Table of
1526 ** AJAX unsigned integer key data and assign them as value data.
1527 **
1528 ** The caller is responsible for deleting the AJAX unsigned integer key and
1529 ** Ensembl Repeat Consensus value data before deleting the AJAX Table.
1530 **
1531 ** @cc Bio::EnsEMBL::DBSQL::BaseAdaptor::fetch_all_by_dbID_list
1532 ** @param [u] rca [EnsPRepeatconsensusadaptor]
1533 ** Ensembl Repeat Consensus Adaptor
1534 ** @param [u] rcit [AjPTable]
1535 ** AJAX Table of
1536 ** AJAX unsigned integer (identifier) key data and
1537 ** Ensembl Repeat Consensus value data
1538 **
1539 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1540 **
1541 ** @release 6.4.0
1542 ** @@
1543 ******************************************************************************/
1544 
ensRepeatconsensusadaptorFetchAllbyIdentifiers(EnsPRepeatconsensusadaptor rca,AjPTable rcit)1545 AjBool ensRepeatconsensusadaptorFetchAllbyIdentifiers(
1546     EnsPRepeatconsensusadaptor rca,
1547     AjPTable rcit)
1548 {
1549     return ensBaseadaptorFetchAllbyIdentifiers(
1550         ensRepeatconsensusadaptorGetBaseadaptor(rca),
1551         (EnsPSlice) NULL,
1552         (ajuint (*)(const void *)) &ensRepeatconsensusGetIdentifier,
1553         rcit);
1554 }
1555 
1556 
1557 
1558 
1559 /* @func ensRepeatconsensusadaptorFetchByIdentifier ***************************
1560 **
1561 ** Fetch an Ensembl Repeat Consensus by its SQL database-internal identifier.
1562 ** The caller is responsible for deleting the Ensembl Repeat Consensus.
1563 **
1564 ** @cc Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::fetch_by_dbID
1565 ** @param [u] rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
1566 ** @param [r] identifier [ajuint] SQL database-internal identifier
1567 ** @param [u] Prc [EnsPRepeatconsensus*] Ensembl Repeat Consensus address
1568 **
1569 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1570 **
1571 ** @release 6.2.0
1572 ** @@
1573 ******************************************************************************/
1574 
ensRepeatconsensusadaptorFetchByIdentifier(EnsPRepeatconsensusadaptor rca,ajuint identifier,EnsPRepeatconsensus * Prc)1575 AjBool ensRepeatconsensusadaptorFetchByIdentifier(
1576     EnsPRepeatconsensusadaptor rca,
1577     ajuint identifier,
1578     EnsPRepeatconsensus *Prc)
1579 {
1580     return ensBaseadaptorFetchByIdentifier(
1581         ensRepeatconsensusadaptorGetBaseadaptor(rca),
1582         identifier,
1583         (void **) Prc);
1584 }
1585 
1586 
1587 
1588 
1589 /* @func ensRepeatconsensusadaptorFetchByName *********************************
1590 **
1591 ** Fetch an Ensembl Repeat Consensus by its name and optionally class.
1592 **
1593 ** The caller is responsible for deleting the Ensembl Repeat Consensus.
1594 **
1595 ** @cc Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::fetch_by_name
1596 ** @cc Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::fetch_by_name_class
1597 ** @param [u] rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
1598 ** @param [r] name [const AjPStr] Name
1599 ** @param [rN] class [const AjPStr] Class
1600 ** @param [u] Prc [EnsPRepeatconsensus*] Ensembl Repeat Consensus address
1601 **
1602 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1603 **
1604 ** @release 6.2.0
1605 ** @@
1606 ******************************************************************************/
1607 
ensRepeatconsensusadaptorFetchByName(EnsPRepeatconsensusadaptor rca,const AjPStr name,const AjPStr class,EnsPRepeatconsensus * Prc)1608 AjBool ensRepeatconsensusadaptorFetchByName(
1609     EnsPRepeatconsensusadaptor rca,
1610     const AjPStr name,
1611     const AjPStr class,
1612     EnsPRepeatconsensus *Prc)
1613 {
1614     char *txtname  = NULL;
1615     char *txtclass = NULL;
1616 
1617     AjBool result = AJFALSE;
1618 
1619     AjPList rci = NULL;
1620 
1621     AjPStr constraint = NULL;
1622 
1623     EnsPBaseadaptor ba = NULL;
1624 
1625     EnsPRepeatconsensus rc = NULL;
1626 
1627     if (!rca)
1628         return ajFalse;
1629 
1630     if (!name)
1631         return ajFalse;
1632 
1633     if (!Prc)
1634         return ajFalse;
1635 
1636     ba = ensRepeatconsensusadaptorGetBaseadaptor(rca);
1637 
1638     ensBaseadaptorEscapeC(ba, &txtname, name);
1639 
1640     constraint = ajFmtStr("repeat_consensus.repeat_name = '%s'", txtname);
1641 
1642     ajCharDel(&txtname);
1643 
1644     if (class && ajStrGetLen(class))
1645     {
1646         ensBaseadaptorEscapeC(ba, &txtclass, class);
1647 
1648         ajFmtPrintAppS(&constraint,
1649                        " AND repeat_consensus.repeat_class = '%s'",
1650                        txtclass);
1651 
1652         ajCharDel(&txtclass);
1653     }
1654 
1655     rci = ajListNew();
1656 
1657     result = ensBaseadaptorFetchAllbyConstraint(
1658         ba,
1659         constraint,
1660         (EnsPAssemblymapper) NULL,
1661         (EnsPSlice) NULL,
1662         rci);
1663 
1664     if (ajListGetLength(rci) > 1)
1665         ajFatal("ensRepeatconsensusadaptorFetchByName got more than one "
1666                 "Repeat Consensus from the database for name '%S' and "
1667                 "class '%S'.\n", name, class);
1668 
1669     ajListPop(rci, (void **) Prc);
1670 
1671     while (ajListPop(rci, (void **) &rc))
1672         ensRepeatconsensusDel(&rc);
1673 
1674     ajListFree(&rci);
1675 
1676     ajStrDel(&constraint);
1677 
1678     return result;
1679 }
1680 
1681 
1682 
1683 
1684 /* @section accessory object retrieval ****************************************
1685 **
1686 ** Functions for retrieving objects releated to
1687 ** Ensembl Repeat Consensus objects from an Ensembl SQL database.
1688 **
1689 ** @fdata [EnsPRepeatconsensusadaptor]
1690 **
1691 ** @nam3rule Retrieve Retrieve Ensembl Repeat Consensus-releated object(s)
1692 ** @nam4rule All Retrieve all Ensembl Repeat Consensus-releated objects
1693 ** @nam5rule Identifiers Retrieve all SQL database-internal identifier objects
1694 ** @nam5rule Types Retrieve all Ensembl Repeat Consensus types
1695 **
1696 ** @argrule * rca [EnsPRepeatconsensusadaptor]
1697 ** Ensembl Repeat Consensus Adaptor
1698 ** @argrule AllIdentifiers identifiers [AjPList]
1699 ** AJAX List of AJAX unsigned integer objects
1700 ** @argrule AllTypes types [AjPList]
1701 ** AJAX List of AJAX String (Ensembl Repeat Consensus type) objects
1702 **
1703 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1704 **
1705 ** @fcategory use
1706 ******************************************************************************/
1707 
1708 
1709 
1710 
1711 /* @func ensRepeatconsensusadaptorRetrieveAllTypes ****************************
1712 **
1713 ** Retrieve all Ensembl Repeat Consensus types of
1714 ** Ensembl Repeat Consensus objects.
1715 **
1716 ** The caller is responsible for deleting the AJAX String objects before
1717 ** deleting the AJAX List.
1718 **
1719 ** @cc Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::fetch_all_repeat_types
1720 ** @param [u] rca [EnsPRepeatconsensusadaptor] Ensembl Repeat Consensus Adaptor
1721 ** @param [u] types [AjPList]
1722 ** AJAX List of AJAX String (Ensembl Repeat Consensus type) objects
1723 **
1724 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1725 **
1726 ** @release 6.5.0
1727 ** @@
1728 ******************************************************************************/
1729 
ensRepeatconsensusadaptorRetrieveAllTypes(EnsPRepeatconsensusadaptor rca,AjPList types)1730 AjBool ensRepeatconsensusadaptorRetrieveAllTypes(
1731     EnsPRepeatconsensusadaptor rca,
1732     AjPList types)
1733 {
1734     AjPSqlstatement sqls = NULL;
1735     AjISqlrow sqli       = NULL;
1736     AjPSqlrow sqlr       = NULL;
1737 
1738     AjPStr statement = NULL;
1739     AjPStr type      = NULL;
1740 
1741     EnsPDatabaseadaptor dba = NULL;
1742 
1743     if (!rca)
1744         return ajFalse;
1745 
1746     if (!types)
1747         return ajFalse;
1748 
1749     dba = ensRepeatconsensusadaptorGetDatabaseadaptor(rca);
1750 
1751     statement = ajStrNewC(
1752         "SELECT "
1753         "DISTINCT "
1754         "repeat_consensus.repeat_type "
1755         "FROM "
1756         "repeat_consensus");
1757 
1758     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
1759 
1760     sqli = ajSqlrowiterNew(sqls);
1761 
1762     while (!ajSqlrowiterDone(sqli))
1763     {
1764         type = ajStrNew();
1765 
1766         sqlr = ajSqlrowiterGet(sqli);
1767 
1768         ajSqlcolumnToStr(sqlr, &type);
1769 
1770         ajListstrPushAppend(types, type);
1771     }
1772 
1773     ajSqlrowiterDel(&sqli);
1774 
1775     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
1776 
1777     ajStrDel(&statement);
1778 
1779     return ajTrue;
1780 }
1781 
1782 
1783 
1784 
1785 /* @datasection [EnsPRepeatfeature] Ensembl Repeat Feature ********************
1786 **
1787 ** @nam2rule Repeatfeature Functions for manipulating
1788 ** Ensembl Repeat Feature objects
1789 **
1790 ** @cc Bio::EnsEMBL::RepeatFeature
1791 ** @cc CVS Revision: 1.29
1792 ** @cc CVS Tag: branch-ensembl-68
1793 **
1794 ******************************************************************************/
1795 
1796 
1797 
1798 
1799 /* @section constructors ******************************************************
1800 **
1801 ** All constructors return a new Ensembl Repeat Feature by pointer.
1802 ** It is the responsibility of the user to first destroy any previous
1803 ** Repeat Feature. The target pointer does not need to be initialised to
1804 ** NULL, but it is good programming practice to do so anyway.
1805 **
1806 ** @fdata [EnsPRepeatfeature]
1807 **
1808 ** @nam3rule New Constructor
1809 ** @nam4rule Cpy Constructor with existing object
1810 ** @nam4rule Ini Constructor with initial values
1811 ** @nam4rule Ref Constructor by incrementing the reference counter
1812 **
1813 ** @argrule Cpy rf [const EnsPRepeatfeature] Ensembl Repeat Feature
1814 ** @argrule Ini rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
1815 ** @argrule Ini identifier [ajuint] SQL database-internal identifier
1816 ** @argrule Ini feature [EnsPFeature] Ensembl Feature
1817 ** @argrule Ini rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
1818 ** @argrule Ini hstart [ajint] Repeat Consensus hit start
1819 ** @argrule Ini hend [ajint] Repeat Consensus hit end
1820 ** @argrule Ini score [double] Repeat Consensus score
1821 ** @argrule Ref rf [EnsPRepeatfeature] Ensembl Repeat Feature
1822 **
1823 ** @valrule * [EnsPRepeatfeature] Ensembl Repeat Feature or NULL
1824 **
1825 ** @fcategory new
1826 ******************************************************************************/
1827 
1828 
1829 
1830 
1831 /* @func ensRepeatfeatureNewCpy ***********************************************
1832 **
1833 ** Object-based constructor function, which returns an independent object.
1834 **
1835 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
1836 **
1837 ** @return [EnsPRepeatfeature] Ensembl Repeat Feature or NULL
1838 **
1839 ** @release 6.4.0
1840 ** @@
1841 ******************************************************************************/
1842 
ensRepeatfeatureNewCpy(const EnsPRepeatfeature rf)1843 EnsPRepeatfeature ensRepeatfeatureNewCpy(const EnsPRepeatfeature rf)
1844 {
1845     EnsPRepeatfeature pthis = NULL;
1846 
1847     if (!rf)
1848         return NULL;
1849 
1850     AJNEW0(pthis);
1851 
1852     pthis->Adaptor = rf->Adaptor;
1853 
1854     pthis->Identifier = rf->Identifier;
1855 
1856     pthis->Feature = ensFeatureNewRef(rf->Feature);
1857 
1858     pthis->Repeatconsensus = ensRepeatconsensusNewRef(rf->Repeatconsensus);
1859 
1860     pthis->HitStart = rf->HitStart;
1861 
1862     pthis->HitEnd = rf->HitEnd;
1863 
1864     pthis->Score = rf->Score;
1865 
1866     pthis->Use = 1U;
1867 
1868     return pthis;
1869 }
1870 
1871 
1872 
1873 
1874 /* @func ensRepeatfeatureNewIni ***********************************************
1875 **
1876 ** Constructor for an Ensembl Repeat Feature with initial values.
1877 **
1878 ** @cc Bio::EnsEMBL::RepeatFeature::new
1879 ** @param [u] rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
1880 ** @param [r] identifier [ajuint] SQL database-internal identifier
1881 ** @param [u] feature [EnsPFeature] Ensembl Feature
1882 ** @param [uN] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
1883 ** @param [r] hstart [ajint] Repeat Consensus hit start
1884 ** @param [r] hend [ajint] Repeat Consensus hit end
1885 ** @param [r] score [double] Repeat Consensus score
1886 **
1887 ** @return [EnsPRepeatfeature] Ensembl Repeat Feature or NULL
1888 **
1889 ** @release 6.4.0
1890 ** @@
1891 ******************************************************************************/
1892 
ensRepeatfeatureNewIni(EnsPRepeatfeatureadaptor rfa,ajuint identifier,EnsPFeature feature,EnsPRepeatconsensus rc,ajint hstart,ajint hend,double score)1893 EnsPRepeatfeature ensRepeatfeatureNewIni(EnsPRepeatfeatureadaptor rfa,
1894                                          ajuint identifier,
1895                                          EnsPFeature feature,
1896                                          EnsPRepeatconsensus rc,
1897                                          ajint hstart,
1898                                          ajint hend,
1899                                          double score)
1900 {
1901     EnsPRepeatfeature rf = NULL;
1902 
1903     if (!feature)
1904         return NULL;
1905 
1906     AJNEW0(rf);
1907 
1908     rf->Adaptor = rfa;
1909 
1910     rf->Identifier = identifier;
1911 
1912     rf->Feature = ensFeatureNewRef(feature);
1913 
1914     rf->Repeatconsensus = ensRepeatconsensusNewRef(rc);
1915 
1916     rf->HitStart = hstart;
1917 
1918     rf->HitEnd = hend;
1919 
1920     rf->Score = score;
1921 
1922     rf->Use = 1U;
1923 
1924     return rf;
1925 }
1926 
1927 
1928 
1929 
1930 /* @func ensRepeatfeatureNewRef ***********************************************
1931 **
1932 ** Ensembl Object referencing function, which returns a pointer to the
1933 ** Ensembl Object passed in and increases its reference count.
1934 **
1935 ** @param [u] rf [EnsPRepeatfeature] Ensembl Repeat Feature
1936 **
1937 ** @return [EnsPRepeatfeature] Ensembl Repeat Feature or NULL
1938 **
1939 ** @release 6.2.0
1940 ** @@
1941 ******************************************************************************/
1942 
ensRepeatfeatureNewRef(EnsPRepeatfeature rf)1943 EnsPRepeatfeature ensRepeatfeatureNewRef(EnsPRepeatfeature rf)
1944 {
1945     if (!rf)
1946         return NULL;
1947 
1948     rf->Use++;
1949 
1950     return rf;
1951 }
1952 
1953 
1954 
1955 
1956 /* @section destructors *******************************************************
1957 **
1958 ** Destruction destroys all internal data structures and frees the memory
1959 ** allocated for an Ensembl Repeat Feature object.
1960 **
1961 ** @fdata [EnsPRepeatfeature]
1962 **
1963 ** @nam3rule Del Destroy (free) an Ensembl Repeat Feature
1964 **
1965 ** @argrule * Prf [EnsPRepeatfeature*] Ensembl Repeat Feature address
1966 **
1967 ** @valrule * [void]
1968 **
1969 ** @fcategory delete
1970 ******************************************************************************/
1971 
1972 
1973 
1974 
1975 /* @func ensRepeatfeatureDel **************************************************
1976 **
1977 ** Default destructor for an Ensembl Repeat Feature.
1978 **
1979 ** @param [d] Prf [EnsPRepeatfeature*] Ensembl Repeat Feature address
1980 **
1981 ** @return [void]
1982 **
1983 ** @release 6.2.0
1984 ** @@
1985 ******************************************************************************/
1986 
ensRepeatfeatureDel(EnsPRepeatfeature * Prf)1987 void ensRepeatfeatureDel(EnsPRepeatfeature *Prf)
1988 {
1989     EnsPRepeatfeature pthis = NULL;
1990 
1991     if (!Prf)
1992         return;
1993 
1994 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
1995     if (ajDebugTest("ensRepeatfeatureDel"))
1996     {
1997         ajDebug("ensRepeatfeatureDel\n"
1998                 "  *Prf %p\n",
1999                 *Prf);
2000 
2001         ensRepeatfeatureTrace(*Prf, 1);
2002     }
2003 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
2004 
2005     if (!(pthis = *Prf) || --pthis->Use)
2006     {
2007         *Prf = NULL;
2008 
2009         return;
2010     }
2011 
2012     ensFeatureDel(&pthis->Feature);
2013 
2014     ensRepeatconsensusDel(&pthis->Repeatconsensus);
2015 
2016     ajMemFree((void **) Prf);
2017 
2018     return;
2019 }
2020 
2021 
2022 
2023 
2024 /* @section member retrieval **************************************************
2025 **
2026 ** Functions for returning members of an Ensembl Repeat Feature object.
2027 **
2028 ** @fdata [EnsPRepeatfeature]
2029 **
2030 ** @nam3rule Get Return Repeat Feature attribute(s)
2031 ** @nam4rule Adaptor Return the Ensembl Repeat Feature Adaptor
2032 ** @nam4rule Feature Return the Ensembl Feature
2033 ** @nam4rule Identifier Return the SQL database-internal identifier
2034 ** @nam4rule Hit Return hit members
2035 ** @nam5rule Start Return the hit start
2036 ** @nam5rule End Return the hit end
2037 ** @nam5rule Strand Return the hit strand
2038 ** @nam4rule Repeatconsensus Return the Ensembl Repeat Consensus
2039 ** @nam4rule Score Return the score
2040 **
2041 ** @argrule * rf [const EnsPRepeatfeature] Repeat Feature
2042 **
2043 ** @valrule Adaptor [EnsPRepeatfeatureadaptor]
2044 ** Ensembl Repeat Feature Adaptor or NULL
2045 ** @valrule Feature [EnsPFeature] Ensembl Feature or NULL
2046 ** @valrule HitEnd [ajint] Hit end or 0
2047 ** @valrule HitStart [ajint] Hit start or 0
2048 ** @valrule HitStrand [ajint] Hit strand or 0
2049 ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U
2050 ** @valrule Repeatconsensus [EnsPRepeatconsensus]
2051 ** Ensembl Repeat Consensus or NULL
2052 ** @valrule Score [double] Score or 0.0
2053 **
2054 ** @fcategory use
2055 ******************************************************************************/
2056 
2057 
2058 
2059 
2060 /* @func ensRepeatfeatureGetAdaptor *******************************************
2061 **
2062 ** Get the Object Adaptor member of an Ensembl Repeat Feature.
2063 **
2064 ** @cc Bio::EnsEMBL::Storable::adaptor
2065 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2066 **
2067 ** @return [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor or NULL
2068 **
2069 ** @release 6.2.0
2070 ** @@
2071 ******************************************************************************/
2072 
ensRepeatfeatureGetAdaptor(const EnsPRepeatfeature rf)2073 EnsPRepeatfeatureadaptor ensRepeatfeatureGetAdaptor(
2074     const EnsPRepeatfeature rf)
2075 {
2076     return (rf) ? rf->Adaptor : NULL;
2077 }
2078 
2079 
2080 
2081 
2082 /* @func ensRepeatfeatureGetFeature *******************************************
2083 **
2084 ** Get the Ensembl Feature member of an Ensembl Repeat Feature.
2085 **
2086 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2087 **
2088 ** @return [EnsPFeature] Ensembl Feature or NULL
2089 **
2090 ** @release 6.2.0
2091 ** @@
2092 ******************************************************************************/
2093 
ensRepeatfeatureGetFeature(const EnsPRepeatfeature rf)2094 EnsPFeature ensRepeatfeatureGetFeature(
2095     const EnsPRepeatfeature rf)
2096 {
2097     return (rf) ? rf->Feature : NULL;
2098 }
2099 
2100 
2101 
2102 
2103 /* @func ensRepeatfeatureGetHitEnd ********************************************
2104 **
2105 ** Get the hit end member of an Ensembl Repeat Feature.
2106 **
2107 ** @cc Bio::EnsEMBL::RepeatFeature::hend
2108 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2109 **
2110 ** @return [ajint] Hit end coordinate or 0
2111 **
2112 ** @release 6.2.0
2113 ** @@
2114 ******************************************************************************/
2115 
ensRepeatfeatureGetHitEnd(const EnsPRepeatfeature rf)2116 ajint ensRepeatfeatureGetHitEnd(
2117     const EnsPRepeatfeature rf)
2118 {
2119     return (rf) ? rf->HitEnd : 0;
2120 }
2121 
2122 
2123 
2124 
2125 /* @func ensRepeatfeatureGetHitStart ******************************************
2126 **
2127 ** Get the hit start member of an Ensembl Repeat Feature.
2128 **
2129 ** @cc Bio::EnsEMBL::RepeatFeature::hstart
2130 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2131 **
2132 ** @return [ajint] Hit start coordinate or 0
2133 **
2134 ** @release 6.2.0
2135 ** @@
2136 ******************************************************************************/
2137 
ensRepeatfeatureGetHitStart(const EnsPRepeatfeature rf)2138 ajint ensRepeatfeatureGetHitStart(
2139     const EnsPRepeatfeature rf)
2140 {
2141     return (rf) ? rf->HitStart : 0;
2142 }
2143 
2144 
2145 
2146 
2147 /* @func ensRepeatfeatureGetHitStrand *****************************************
2148 **
2149 ** Get the hit strand member of an Ensembl Repeat Feature.
2150 **
2151 ** @cc Bio::EnsEMBL::RepeatFeature::hstrand
2152 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2153 **
2154 ** @return [ajint] Hit strand or 0
2155 **
2156 ** @release 6.2.0
2157 ** @@
2158 ******************************************************************************/
2159 
ensRepeatfeatureGetHitStrand(const EnsPRepeatfeature rf)2160 ajint ensRepeatfeatureGetHitStrand(
2161     const EnsPRepeatfeature rf)
2162 {
2163     return (rf) ? 1 : 0;
2164 }
2165 
2166 
2167 
2168 
2169 /* @func ensRepeatfeatureGetIdentifier ****************************************
2170 **
2171 ** Get the SQL database-internal identifier member of an
2172 ** Ensembl Repeat Feature.
2173 **
2174 ** @cc Bio::EnsEMBL::Storable::dbID
2175 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2176 **
2177 ** @return [ajuint] SQL database-internal identifier or 0U
2178 **
2179 ** @release 6.2.0
2180 ** @@
2181 ******************************************************************************/
2182 
ensRepeatfeatureGetIdentifier(const EnsPRepeatfeature rf)2183 ajuint ensRepeatfeatureGetIdentifier(
2184     const EnsPRepeatfeature rf)
2185 {
2186     return (rf) ? rf->Identifier : 0U;
2187 }
2188 
2189 
2190 
2191 
2192 /* @func ensRepeatfeatureGetRepeatconsensus ***********************************
2193 **
2194 ** Get the Ensembl Repeat Consensus member of an Ensembl Repeat Feature.
2195 **
2196 ** @cc Bio::EnsEMBL::RepeatFeature::repeat_consensus
2197 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2198 **
2199 ** @return [EnsPRepeatconsensus] Ensembl Repeat Consensus or NULL
2200 **
2201 ** @release 6.2.0
2202 ** @@
2203 ******************************************************************************/
2204 
ensRepeatfeatureGetRepeatconsensus(const EnsPRepeatfeature rf)2205 EnsPRepeatconsensus ensRepeatfeatureGetRepeatconsensus(
2206     const EnsPRepeatfeature rf)
2207 {
2208     return (rf) ? rf->Repeatconsensus : NULL;
2209 }
2210 
2211 
2212 
2213 
2214 /* @func ensRepeatfeatureGetScore *********************************************
2215 **
2216 ** Get the score member of an Ensembl Repeat Feature.
2217 **
2218 ** @cc Bio::EnsEMBL::RepeatFeature::score
2219 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2220 **
2221 ** @return [double] Score or 0.0
2222 **
2223 ** @release 6.2.0
2224 ** @@
2225 ******************************************************************************/
2226 
ensRepeatfeatureGetScore(const EnsPRepeatfeature rf)2227 double ensRepeatfeatureGetScore(
2228     const EnsPRepeatfeature rf)
2229 {
2230     return (rf) ? rf->Score : 0.0;
2231 }
2232 
2233 
2234 
2235 
2236 /* @section modifiers *********************************************************
2237 **
2238 ** Functions for assigning members of an Ensembl Repeat Feature object.
2239 **
2240 ** @fdata [EnsPRepeatfeature]
2241 **
2242 ** @nam3rule Set Set one member of a Repeat Feature
2243 ** @nam4rule Adaptor Set the Ensembl Repeat Feature Adaptor
2244 ** @nam4rule Feature Set the Ensembl Feature
2245 ** @nam4rule Hit Set hit members
2246 ** @nam5rule End Set the hit end
2247 ** @nam5rule Start Set the hit start
2248 ** @nam4rule Identifier Set the SQL database-internal identifier
2249 ** @nam4rule Repeatconsensus Set the Ensembl Repeat Consensus
2250 ** @nam4rule Score Set the score
2251 **
2252 ** @argrule * rf [EnsPRepeatfeature] Ensembl Repeat Feature object
2253 ** @argrule Adaptor rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat
2254 **                                                 Feature Adaptor
2255 ** @argrule Feature feature [EnsPFeature] Ensembl Feature
2256 ** @argrule HitEnd hend [ajuint] Hit end
2257 ** @argrule HitStart hstart [ajuint] Hit start
2258 ** @argrule Identifier identifier [ajuint] SQL database-internal identifier
2259 ** @argrule Repeatconsensus rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
2260 ** @argrule Score score [double] Score
2261 **
2262 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2263 **
2264 ** @fcategory modify
2265 ******************************************************************************/
2266 
2267 
2268 
2269 
2270 /* @func ensRepeatfeatureSetAdaptor *******************************************
2271 **
2272 ** Set the Ensembl Database Adaptor member of an Ensembl Repeat Feature.
2273 **
2274 ** @cc Bio::EnsEMBL::Storable::adaptor
2275 ** @param [u] rf [EnsPRepeatfeature] Ensembl Repeat Feature
2276 ** @param [u] rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
2277 **
2278 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2279 **
2280 ** @release 6.2.0
2281 ** @@
2282 ******************************************************************************/
2283 
ensRepeatfeatureSetAdaptor(EnsPRepeatfeature rf,EnsPRepeatfeatureadaptor rfa)2284 AjBool ensRepeatfeatureSetAdaptor(EnsPRepeatfeature rf,
2285                                   EnsPRepeatfeatureadaptor rfa)
2286 {
2287     if (!rf)
2288         return ajFalse;
2289 
2290     rf->Adaptor = rfa;
2291 
2292     return ajTrue;
2293 }
2294 
2295 
2296 
2297 
2298 /* @func ensRepeatfeatureSetFeature *******************************************
2299 **
2300 ** Set the Ensembl Feature member of an Ensembl Repeat Feature.
2301 **
2302 ** @param [u] rf [EnsPRepeatfeature] Ensembl Repeat Feature
2303 ** @param [u] feature [EnsPFeature] Ensembl Feature
2304 **
2305 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2306 **
2307 ** @release 6.2.0
2308 ** @@
2309 ******************************************************************************/
2310 
ensRepeatfeatureSetFeature(EnsPRepeatfeature rf,EnsPFeature feature)2311 AjBool ensRepeatfeatureSetFeature(EnsPRepeatfeature rf,
2312                                   EnsPFeature feature)
2313 {
2314     if (!rf)
2315         return ajFalse;
2316 
2317     ensFeatureDel(&rf->Feature);
2318 
2319     rf->Feature = ensFeatureNewRef(feature);
2320 
2321     return ajTrue;
2322 }
2323 
2324 
2325 
2326 
2327 /* @func ensRepeatfeatureSetHitEnd ********************************************
2328 **
2329 ** Set the hit end member of an Ensembl Repeat Feature.
2330 **
2331 ** @cc Bio::EnsEMBL::RepeatFeature::hend
2332 ** @param [u] rf [EnsPRepeatfeature] Ensembl Repeat Feature
2333 ** @param [r] hend [ajuint] Hit end
2334 **
2335 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2336 **
2337 ** @release 6.2.0
2338 ** @@
2339 ******************************************************************************/
2340 
ensRepeatfeatureSetHitEnd(EnsPRepeatfeature rf,ajuint hend)2341 AjBool ensRepeatfeatureSetHitEnd(EnsPRepeatfeature rf,
2342                                  ajuint hend)
2343 {
2344     if (!rf)
2345         return ajFalse;
2346 
2347     rf->HitEnd = hend;
2348 
2349     return ajTrue;
2350 }
2351 
2352 
2353 
2354 
2355 /* @func ensRepeatfeatureSetHitStart ******************************************
2356 **
2357 ** Set the hit start member of an Ensembl Repeat Feature.
2358 **
2359 ** @cc Bio::EnsEMBL::RepeatFeature::hstart
2360 ** @param [u] rf [EnsPRepeatfeature] Ensembl Repeat Feature
2361 ** @param [r] hstart [ajuint] Hit start
2362 **
2363 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2364 **
2365 ** @release 6.2.0
2366 ** @@
2367 ******************************************************************************/
2368 
ensRepeatfeatureSetHitStart(EnsPRepeatfeature rf,ajuint hstart)2369 AjBool ensRepeatfeatureSetHitStart(EnsPRepeatfeature rf,
2370                                    ajuint hstart)
2371 {
2372     if (!rf)
2373         return ajFalse;
2374 
2375     rf->HitStart = hstart;
2376 
2377     return ajTrue;
2378 }
2379 
2380 
2381 
2382 
2383 /* @func ensRepeatfeatureSetIdentifier ****************************************
2384 **
2385 ** Set the SQL database-internal identifier member of an
2386 ** Ensembl Repeat Feature.
2387 **
2388 ** @cc Bio::EnsEMBL::Storable::dbID
2389 ** @param [u] rf [EnsPRepeatfeature] Ensembl Repeat Feature
2390 ** @param [r] identifier [ajuint] SQL database-internal identifier
2391 **
2392 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2393 **
2394 ** @release 6.2.0
2395 ** @@
2396 ******************************************************************************/
2397 
ensRepeatfeatureSetIdentifier(EnsPRepeatfeature rf,ajuint identifier)2398 AjBool ensRepeatfeatureSetIdentifier(EnsPRepeatfeature rf,
2399                                      ajuint identifier)
2400 {
2401     if (!rf)
2402         return ajFalse;
2403 
2404     rf->Identifier = identifier;
2405 
2406     return ajTrue;
2407 }
2408 
2409 
2410 
2411 
2412 /* @func ensRepeatfeatureSetRepeatconsensus ***********************************
2413 **
2414 ** Set the Ensembl Repeat Consensus member of an Ensembl Repeat Feature.
2415 **
2416 ** @cc Bio::EnsEMBL::RepeatFeature::repeat_consensus
2417 ** @param [u] rf [EnsPRepeatfeature] Ensembl Repeat Feature
2418 ** @param [u] rc [EnsPRepeatconsensus] Ensembl Repeat Consensus
2419 **
2420 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2421 **
2422 ** @release 6.2.0
2423 ** @@
2424 ******************************************************************************/
2425 
ensRepeatfeatureSetRepeatconsensus(EnsPRepeatfeature rf,EnsPRepeatconsensus rc)2426 AjBool ensRepeatfeatureSetRepeatconsensus(EnsPRepeatfeature rf,
2427                                           EnsPRepeatconsensus rc)
2428 {
2429     if (!rf)
2430         return ajFalse;
2431 
2432     ensRepeatconsensusDel(&rf->Repeatconsensus);
2433 
2434     rf->Repeatconsensus = ensRepeatconsensusNewRef(rc);
2435 
2436     return ajTrue;
2437 }
2438 
2439 
2440 
2441 
2442 /* @func ensRepeatfeatureSetScore *********************************************
2443 **
2444 ** Set the score member of an Ensembl Repeat Feature.
2445 **
2446 ** @cc Bio::EnsEMBL::RepeatFeature::score
2447 ** @param [u] rf [EnsPRepeatfeature] Ensembl Repeat Feature
2448 ** @param [r] score [double] Score
2449 **
2450 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2451 **
2452 ** @release 6.2.0
2453 ** @@
2454 ******************************************************************************/
2455 
ensRepeatfeatureSetScore(EnsPRepeatfeature rf,double score)2456 AjBool ensRepeatfeatureSetScore(EnsPRepeatfeature rf,
2457                                 double score)
2458 {
2459     if (!rf)
2460         return ajFalse;
2461 
2462     rf->Score = score;
2463 
2464     return ajTrue;
2465 }
2466 
2467 
2468 
2469 
2470 /* @section debugging *********************************************************
2471 **
2472 ** Functions for reporting of an Ensembl Repeat Feature object.
2473 **
2474 ** @fdata [EnsPRepeatfeature]
2475 **
2476 ** @nam3rule Trace Report Ensembl Repeat Feature members to debug file
2477 **
2478 ** @argrule Trace rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2479 ** @argrule Trace level [ajuint] Indentation level
2480 **
2481 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2482 **
2483 ** @fcategory misc
2484 ******************************************************************************/
2485 
2486 
2487 
2488 
2489 /* @func ensRepeatfeatureTrace ************************************************
2490 **
2491 ** Trace an Ensembl Repeat Feature.
2492 **
2493 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2494 ** @param [r] level [ajuint] Indentation level
2495 **
2496 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2497 **
2498 ** @release 6.2.0
2499 ** @@
2500 ******************************************************************************/
2501 
ensRepeatfeatureTrace(const EnsPRepeatfeature rf,ajuint level)2502 AjBool ensRepeatfeatureTrace(const EnsPRepeatfeature rf, ajuint level)
2503 {
2504     AjPStr indent = NULL;
2505 
2506     if (!rf)
2507         return ajFalse;
2508 
2509     indent = ajStrNew();
2510 
2511     ajStrAppendCountK(&indent, ' ', level * 2);
2512 
2513     ajDebug("%SensRepeatfeatureTrace %p\n"
2514             "%S  Adaptor %p\n"
2515             "%S  Identifier %u\n"
2516             "%S  Feature %p\n"
2517             "%S  Repeatconsensus %p\n"
2518             "%S  HitStart %d\n"
2519             "%S  HitEnd %d\n"
2520             "%S  Score %f\n"
2521             "%S  Use %u\n",
2522             indent, rf,
2523             indent, rf->Adaptor,
2524             indent, rf->Identifier,
2525             indent, rf->Feature,
2526             indent, rf->Repeatconsensus,
2527             indent, rf->HitStart,
2528             indent, rf->HitEnd,
2529             indent, rf->Score,
2530             indent, rf->Use);
2531 
2532     ensFeatureTrace(rf->Feature, level + 1);
2533 
2534     ensRepeatconsensusTrace(rf->Repeatconsensus, level + 1);
2535 
2536     ajStrDel(&indent);
2537 
2538     return ajTrue;
2539 }
2540 
2541 
2542 
2543 
2544 /* @section calculate *********************************************************
2545 **
2546 ** Functions for calculating information from an Ensembl Repeat Feature object.
2547 **
2548 ** @fdata [EnsPRepeatfeature]
2549 **
2550 ** @nam3rule Calculate Calculate Ensembl Repeat Feature information
2551 ** @nam4rule Memsize Calculate the memory size in bytes
2552 **
2553 ** @argrule * rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2554 **
2555 ** @valrule Memsize [size_t] Memory size in bytes or 0
2556 **
2557 ** @fcategory misc
2558 ******************************************************************************/
2559 
2560 
2561 
2562 
2563 /* @func ensRepeatfeatureCalculateMemsize *************************************
2564 **
2565 ** Calculate the memory size in bytes of an Ensembl Repeat Feature.
2566 **
2567 ** @param [r] rf [const EnsPRepeatfeature] Ensembl Repeat Feature
2568 **
2569 ** @return [size_t] Memory size in bytes or 0
2570 **
2571 ** @release 6.4.0
2572 ** @@
2573 ******************************************************************************/
2574 
ensRepeatfeatureCalculateMemsize(const EnsPRepeatfeature rf)2575 size_t ensRepeatfeatureCalculateMemsize(const EnsPRepeatfeature rf)
2576 {
2577     size_t size = 0;
2578 
2579     if (!rf)
2580         return 0;
2581 
2582     size += sizeof (EnsORepeatfeature);
2583 
2584     size += ensFeatureCalculateMemsize(rf->Feature);
2585 
2586     size += ensRepeatconsensusCalculateMemsize(rf->Repeatconsensus);
2587 
2588     return size;
2589 }
2590 
2591 
2592 
2593 
2594 /* @datasection [AjPList] AJAX List *******************************************
2595 **
2596 ** @nam2rule List Functions for manipulating AJAX List objects
2597 **
2598 ******************************************************************************/
2599 
2600 
2601 
2602 
2603 /* @funcstatic listRepeatfeatureCompareEndAscending ***************************
2604 **
2605 ** AJAX List of Ensembl Repeat Feature objects comparison function to sort by
2606 ** Ensembl Feature end member in ascending order.
2607 **
2608 ** @param [r] item1 [const void*] Ensembl Repeat Feature address 1
2609 ** @param [r] item2 [const void*] Ensembl Repeat Feature address 2
2610 ** @see ajListSort
2611 **
2612 ** @return [int] The comparison function returns an integer less than,
2613 **               equal to, or greater than zero if the first argument is
2614 **               considered to be respectively less than, equal to, or
2615 **               greater than the second.
2616 **
2617 ** @release 6.4.0
2618 ** @@
2619 ******************************************************************************/
2620 
listRepeatfeatureCompareEndAscending(const void * item1,const void * item2)2621 static int listRepeatfeatureCompareEndAscending(
2622     const void *item1,
2623     const void *item2)
2624 {
2625     EnsPRepeatfeature rf1 = *(EnsORepeatfeature *const *) item1;
2626     EnsPRepeatfeature rf2 = *(EnsORepeatfeature *const *) item2;
2627 
2628 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
2629     if (ajDebugTest("listRepeatfeatureCompareEndAscending"))
2630         ajDebug("listRepeatfeatureCompareEndAscending\n"
2631                 "  rf1 %p\n"
2632                 "  rf2 %p\n",
2633                 rf1,
2634                 rf2);
2635 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
2636 
2637     /* Sort empty values towards the end of the AJAX List. */
2638 
2639     if (rf1 && (!rf2))
2640         return -1;
2641 
2642     if ((!rf1) && (!rf2))
2643         return 0;
2644 
2645     if ((!rf1) && rf2)
2646         return +1;
2647 
2648     return ensFeatureCompareEndAscending(rf1->Feature, rf2->Feature);
2649 }
2650 
2651 
2652 
2653 
2654 /* @funcstatic listRepeatfeatureCompareEndDescending **************************
2655 **
2656 ** AJAX List of Ensembl Repeat Feature objects comparison function to sort by
2657 ** Ensembl Feature end member in descending order.
2658 **
2659 ** @param [r] item1 [const void*] Ensembl Repeat Feature address 1
2660 ** @param [r] item2 [const void*] Ensembl Repeat Feature address 2
2661 ** @see ajListSort
2662 **
2663 ** @return [int] The comparison function returns an integer less than,
2664 **               equal to, or greater than zero if the first argument is
2665 **               considered to be respectively less than, equal to, or
2666 **               greater than the second.
2667 **
2668 ** @release 6.4.0
2669 ** @@
2670 ******************************************************************************/
2671 
listRepeatfeatureCompareEndDescending(const void * item1,const void * item2)2672 static int listRepeatfeatureCompareEndDescending(
2673     const void *item1,
2674     const void *item2)
2675 {
2676     EnsPRepeatfeature rf1 = *(EnsORepeatfeature *const *) item1;
2677     EnsPRepeatfeature rf2 = *(EnsORepeatfeature *const *) item2;
2678 
2679 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
2680     if (ajDebugTest("listRepeatfeatureCompareEndDescending"))
2681         ajDebug("listRepeatfeatureCompareEndDescending\n"
2682                 "  rf1 %p\n"
2683                 "  rf2 %p\n",
2684                 rf1,
2685                 rf2);
2686 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
2687 
2688     /* Sort empty values towards the end of the AJAX List. */
2689 
2690     if (rf1 && (!rf2))
2691         return -1;
2692 
2693     if ((!rf1) && (!rf2))
2694         return 0;
2695 
2696     if ((!rf1) && rf2)
2697         return +1;
2698 
2699     return ensFeatureCompareEndDescending(rf1->Feature, rf2->Feature);
2700 }
2701 
2702 
2703 
2704 
2705 /* @funcstatic listRepeatfeatureCompareIdentifierAscending ********************
2706 **
2707 ** AJAX List of Ensembl Repeat Feature objects comparison function to sort by
2708 ** identifier member in ascending order.
2709 **
2710 ** @param [r] item1 [const void*] Ensembl Repeat Feature address 1
2711 ** @param [r] item2 [const void*] Ensembl Repeat Feature address 2
2712 ** @see ajListSort
2713 **
2714 ** @return [int] The comparison function returns an integer less than,
2715 **               equal to, or greater than zero if the first argument is
2716 **               considered to be respectively less than, equal to, or
2717 **               greater than the second.
2718 **
2719 ** @release 6.4.0
2720 ** @@
2721 ******************************************************************************/
2722 
listRepeatfeatureCompareIdentifierAscending(const void * item1,const void * item2)2723 static int listRepeatfeatureCompareIdentifierAscending(
2724     const void *item1,
2725     const void *item2)
2726 {
2727     EnsPRepeatfeature rf1 = *(EnsORepeatfeature *const *) item1;
2728     EnsPRepeatfeature rf2 = *(EnsORepeatfeature *const *) item2;
2729 
2730 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
2731     if (ajDebugTest("listRepeatfeatureCompareIdentifierAscending"))
2732         ajDebug("listRepeatfeatureCompareIdentifierAscending\n"
2733                 "  rf1 %p\n"
2734                 "  rf2 %p\n",
2735                 rf1,
2736                 rf2);
2737 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
2738 
2739     /* Sort empty values towards the end of the AJAX List. */
2740 
2741     if (rf1 && (!rf2))
2742         return -1;
2743 
2744     if ((!rf1) && (!rf2))
2745         return 0;
2746 
2747     if ((!rf1) && rf2)
2748         return +1;
2749 
2750     if (rf1->Identifier < rf2->Identifier)
2751         return -1;
2752 
2753     if (rf1->Identifier > rf2->Identifier)
2754         return +1;
2755 
2756     return 0;
2757 }
2758 
2759 
2760 
2761 
2762 /* @funcstatic listRepeatfeatureCompareStartAscending *************************
2763 **
2764 ** AJAX List of Ensembl Repeat Feature objects comparison function to sort by
2765 ** Ensembl Feature start member in ascending order.
2766 **
2767 ** @param [r] item1 [const void*] Ensembl Repeat Feature address 1
2768 ** @param [r] item2 [const void*] Ensembl Repeat Feature address 2
2769 ** @see ajListSort
2770 **
2771 ** @return [int] The comparison function returns an integer less than,
2772 **               equal to, or greater than zero if the first argument is
2773 **               considered to be respectively less than, equal to, or
2774 **               greater than the second.
2775 **
2776 ** @release 6.4.0
2777 ** @@
2778 ******************************************************************************/
2779 
listRepeatfeatureCompareStartAscending(const void * item1,const void * item2)2780 static int listRepeatfeatureCompareStartAscending(
2781     const void *item1,
2782     const void *item2)
2783 {
2784     EnsPRepeatfeature rf1 = *(EnsORepeatfeature *const *) item1;
2785     EnsPRepeatfeature rf2 = *(EnsORepeatfeature *const *) item2;
2786 
2787 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
2788     if (ajDebugTest("listRepeatfeatureCompareStartAscending"))
2789         ajDebug("listRepeatfeatureCompareStartAscending\n"
2790                 "  rf1 %p\n"
2791                 "  rf2 %p\n",
2792                 rf1,
2793                 rf2);
2794 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
2795 
2796     /* Sort empty values towards the end of the AJAX List. */
2797 
2798     if (rf1 && (!rf2))
2799         return -1;
2800 
2801     if ((!rf1) && (!rf2))
2802         return 0;
2803 
2804     if ((!rf1) && rf2)
2805         return +1;
2806 
2807     return ensFeatureCompareStartAscending(rf1->Feature, rf2->Feature);
2808 }
2809 
2810 
2811 
2812 
2813 /* @funcstatic listRepeatfeatureCompareStartDescending ************************
2814 **
2815 ** AJAX List of Ensembl Repeat Feature objects comparison function to sort by
2816 ** Ensembl Feature start member in descending order.
2817 **
2818 ** @param [r] item1 [const void*] Ensembl Repeat Feature address 1
2819 ** @param [r] item2 [const void*] Ensembl Repeat Feature address 2
2820 ** @see ajListSort
2821 **
2822 ** @return [int] The comparison function returns an integer less than,
2823 **               equal to, or greater than zero if the first argument is
2824 **               considered to be respectively less than, equal to, or
2825 **               greater than the second.
2826 **
2827 ** @release 6.4.0
2828 ** @@
2829 ******************************************************************************/
2830 
listRepeatfeatureCompareStartDescending(const void * item1,const void * item2)2831 static int listRepeatfeatureCompareStartDescending(
2832     const void *item1,
2833     const void *item2)
2834 {
2835     EnsPRepeatfeature rf1 = *(EnsORepeatfeature *const *) item1;
2836     EnsPRepeatfeature rf2 = *(EnsORepeatfeature *const *) item2;
2837 
2838 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
2839     if (ajDebugTest("listRepeatfeatureCompareStartDescending"))
2840         ajDebug("listRepeatfeatureCompareStartDescending\n"
2841                 "  rf1 %p\n"
2842                 "  rf2 %p\n",
2843                 rf1,
2844                 rf2);
2845 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
2846 
2847     /* Sort empty values towards the end of the AJAX List. */
2848 
2849     if (rf1 && (!rf2))
2850         return -1;
2851 
2852     if ((!rf1) && (!rf2))
2853         return 0;
2854 
2855     if ((!rf1) && rf2)
2856         return +1;
2857 
2858     return ensFeatureCompareStartDescending(rf1->Feature, rf2->Feature);
2859 }
2860 
2861 
2862 
2863 
2864 /* @section list **************************************************************
2865 **
2866 ** Functions for manipulating AJAX List objects.
2867 **
2868 ** @fdata [AjPList]
2869 **
2870 ** @nam3rule Repeatfeature Functions for manipulating AJAX List objects of
2871 ** Ensembl Repeat Feature objects
2872 ** @nam4rule            Sort Sort functions
2873 ** @nam5rule End        Sort by Ensembl Feature end member
2874 ** @nam5rule Identifier Sort by identifier member
2875 ** @nam5rule Start      Sort by Ensembl Feature start member
2876 ** @nam6rule Ascending  Sort in ascending order
2877 ** @nam6rule Descending Sort in descending order
2878 **
2879 ** @argrule * rfs [AjPList]
2880 ** AJAX List of Ensembl Repeat Feature objects
2881 **
2882 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2883 **
2884 ** @fcategory misc
2885 ******************************************************************************/
2886 
2887 
2888 
2889 
2890 /* @func ensListRepeatfeatureSortEndAscending *********************************
2891 **
2892 ** Sort an AJAX List of Ensembl Repeat Feature objects by their
2893 ** Ensembl Feature end member in ascending order.
2894 **
2895 ** @param [u] rfs [AjPList] AJAX List of Ensembl Repeat Feature objects
2896 **
2897 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2898 **
2899 ** @release 6.4.0
2900 ** @@
2901 ******************************************************************************/
2902 
ensListRepeatfeatureSortEndAscending(AjPList rfs)2903 AjBool ensListRepeatfeatureSortEndAscending(AjPList rfs)
2904 {
2905     if (!rfs)
2906         return ajFalse;
2907 
2908     ajListSortTwoThree(rfs,
2909                        &listRepeatfeatureCompareEndAscending,
2910                        &listRepeatfeatureCompareStartAscending,
2911                        &listRepeatfeatureCompareIdentifierAscending);
2912 
2913     return ajTrue;
2914 }
2915 
2916 
2917 
2918 
2919 /* @func ensListRepeatfeatureSortEndDescending ********************************
2920 **
2921 ** Sort an AJAX List of Ensembl Repeat Feature objects by their
2922 ** Ensembl Feature end member in descending order.
2923 **
2924 ** @param [u] rfs [AjPList] AJAX List of Ensembl Repeat Feature objects
2925 **
2926 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2927 **
2928 ** @release 6.4.0
2929 ** @@
2930 ******************************************************************************/
2931 
ensListRepeatfeatureSortEndDescending(AjPList rfs)2932 AjBool ensListRepeatfeatureSortEndDescending(AjPList rfs)
2933 {
2934     if (!rfs)
2935         return ajFalse;
2936 
2937     ajListSortTwoThree(rfs,
2938                        &listRepeatfeatureCompareEndDescending,
2939                        &listRepeatfeatureCompareStartDescending,
2940                        &listRepeatfeatureCompareIdentifierAscending);
2941 
2942     return ajTrue;
2943 }
2944 
2945 
2946 
2947 
2948 /* @func ensListRepeatfeatureSortIdentifierAscending **************************
2949 **
2950 ** Sort an AJAX List of Ensembl Repeat Feature objects by their
2951 ** identifier member in ascending order.
2952 **
2953 ** @param [u] rfs [AjPList] AJAX List of Ensembl Repeat Feature objects
2954 **
2955 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2956 **
2957 ** @release 6.4.0
2958 ** @@
2959 ******************************************************************************/
2960 
ensListRepeatfeatureSortIdentifierAscending(AjPList rfs)2961 AjBool ensListRepeatfeatureSortIdentifierAscending(AjPList rfs)
2962 {
2963     if (!rfs)
2964         return ajFalse;
2965 
2966     ajListSort(rfs, &listRepeatfeatureCompareIdentifierAscending);
2967 
2968     return ajTrue;
2969 }
2970 
2971 
2972 
2973 
2974 /* @func ensListRepeatfeatureSortStartAscending *******************************
2975 **
2976 ** Sort an AJAX List of Ensembl Repeat Feature objects by their
2977 ** Ensembl Feature start member in ascending order.
2978 **
2979 ** @param [u] rfs [AjPList] AJAX List of Ensembl Repeat Feature objects
2980 **
2981 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2982 **
2983 ** @release 6.4.0
2984 ** @@
2985 ******************************************************************************/
2986 
ensListRepeatfeatureSortStartAscending(AjPList rfs)2987 AjBool ensListRepeatfeatureSortStartAscending(AjPList rfs)
2988 {
2989     if (!rfs)
2990         return ajFalse;
2991 
2992     ajListSortTwoThree(rfs,
2993                        &listRepeatfeatureCompareStartAscending,
2994                        &listRepeatfeatureCompareEndAscending,
2995                        &listRepeatfeatureCompareIdentifierAscending);
2996 
2997     return ajTrue;
2998 }
2999 
3000 
3001 
3002 
3003 /* @func ensListRepeatfeatureSortStartDescending ******************************
3004 **
3005 ** Sort an AJAX List of Ensembl Repeat Feature objects by their
3006 ** Ensembl Feature start member in descending order.
3007 **
3008 ** @param [u] rfs [AjPList] AJAX List of Ensembl Repeat Feature objects
3009 **
3010 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3011 **
3012 ** @release 6.4.0
3013 ** @@
3014 ******************************************************************************/
3015 
ensListRepeatfeatureSortStartDescending(AjPList rfs)3016 AjBool ensListRepeatfeatureSortStartDescending(AjPList rfs)
3017 {
3018     if (!rfs)
3019         return ajFalse;
3020 
3021     ajListSortTwoThree(rfs,
3022                        &listRepeatfeatureCompareStartDescending,
3023                        &listRepeatfeatureCompareEndDescending,
3024                        &listRepeatfeatureCompareIdentifierAscending);
3025 
3026     return ajTrue;
3027 }
3028 
3029 
3030 
3031 
3032 /* @datasection [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor *****
3033 **
3034 ** @nam2rule Repeatfeatureadaptor Functions for manipulating
3035 ** Ensembl Repeat Feature Adaptor objects
3036 **
3037 ** @cc Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptor
3038 ** @cc CVS Revision: 1.63
3039 ** @cc CVS Tag: branch-ensembl-68
3040 **
3041 ******************************************************************************/
3042 
3043 
3044 
3045 
3046 /* @funcstatic repeatfeatureadaptorLinkRepeatconsensus ************************
3047 **
3048 ** An ajTableMapDel "apply" function to link Ensembl Repeat Feature objects to
3049 ** Ensembl Repeat Consensus objects.
3050 ** This function also deletes the AJAX unsigned integer identifier key and the
3051 ** AJAX List objects of Ensembl Repeat Feature objects after association.
3052 **
3053 ** @param [d] Pkey [void**] AJAX unsigned integer key data address
3054 ** @param [d] Pvalue [void**] AJAX List of Ensembl Repeat Feature objects
3055 ** @param [u] cl [void*] AJAX Table of Ensembl Repeat Consensus objects,
3056 **                       passed in from ajTableMapDel
3057 ** @see ajTableMapDel
3058 **
3059 ** @return [void]
3060 **
3061 ** @release 6.4.0
3062 ** @@
3063 ******************************************************************************/
3064 
repeatfeatureadaptorLinkRepeatconsensus(void ** Pkey,void ** Pvalue,void * cl)3065 static void repeatfeatureadaptorLinkRepeatconsensus(void **Pkey,
3066                                                     void **Pvalue,
3067                                                     void *cl)
3068 {
3069     EnsPRepeatconsensus rc = NULL;
3070 
3071     EnsPRepeatfeature rf = NULL;
3072 
3073     if (!Pkey)
3074         return;
3075 
3076     if (!*Pkey)
3077         return;
3078 
3079     if (!Pvalue)
3080         return;
3081 
3082     if (!*Pvalue)
3083         return;
3084 
3085     if (!cl)
3086         return;
3087 
3088     rc = (EnsPRepeatconsensus) ajTableFetchmodV(cl, *Pkey);
3089 
3090     /*
3091     ** The Ensembl Repeat Feature objects can be deleted after associating
3092     ** them with Ensembl Repeat Consensus objects, because this AJAX Table
3093     ** holds independent references for these objects.
3094     */
3095 
3096     while (ajListPop(*((AjPList *) Pvalue), (void **) &rf))
3097     {
3098         ensRepeatfeatureSetRepeatconsensus(rf, rc);
3099 
3100         ensRepeatfeatureDel(&rf);
3101     }
3102 
3103     ajMemFree(Pkey);
3104 
3105     ajListFree((AjPList *) Pvalue);
3106 
3107     return;
3108 }
3109 
3110 
3111 
3112 
3113 /* @funcstatic repeatfeatureadaptorFetchAllbyStatement ************************
3114 **
3115 ** Run a SQL statement against an Ensembl Database Adaptor and consolidate the
3116 ** results into an AJAX List of Ensembl Repeat Features.
3117 ** The caller is responsible for deleting the Ensembl Repeat Feature objects
3118 ** before deleting the AJAX List.
3119 **
3120 ** @cc Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptor::_objs_from_sth
3121 ** @param [u] ba [EnsPBaseadaptor] Ensembl Base Adaptor
3122 ** @param [r] statement [const AjPStr] SQL statement
3123 ** @param [uN] am [EnsPAssemblymapper] Ensembl Assembly Mapper
3124 ** @param [uN] slice [EnsPSlice] Ensembl Slice
3125 ** @param [u] rfs [AjPList] AJAX List of Ensembl Repeat Feature objects
3126 **
3127 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3128 **
3129 ** @release 6.4.0
3130 ** @@
3131 ******************************************************************************/
3132 
repeatfeatureadaptorFetchAllbyStatement(EnsPBaseadaptor ba,const AjPStr statement,EnsPAssemblymapper am,EnsPSlice slice,AjPList rfs)3133 static AjBool repeatfeatureadaptorFetchAllbyStatement(
3134     EnsPBaseadaptor ba,
3135     const AjPStr statement,
3136     EnsPAssemblymapper am,
3137     EnsPSlice slice,
3138     AjPList rfs)
3139 {
3140     ajuint *Pidentifier = NULL;
3141 
3142     ajuint anid  = 0U;
3143     ajuint rcid  = 0U;
3144     ajuint rfid  = 0U;
3145     ajuint srid  = 0U;
3146 
3147     ajuint rpstart = 0U;
3148     ajuint rpend   = 0U;
3149 
3150     ajuint srstart  = 0U;
3151     ajuint srend    = 0U;
3152     ajint  srstrand = 0;
3153 
3154     double score = 0;
3155 
3156     AjBool debug = AJFALSE;
3157 
3158     AjPList list = NULL;
3159 
3160     AjPSqlstatement sqls = NULL;
3161     AjISqlrow sqli       = NULL;
3162     AjPSqlrow sqlr       = NULL;
3163 
3164     AjPTable rci     = NULL;
3165     AjPTable rcitorf = NULL;
3166 
3167     EnsPDatabaseadaptor dba = NULL;
3168 
3169     EnsPFeature feature = NULL;
3170 
3171     EnsPRepeatconsensusadaptor rca = NULL;
3172 
3173     EnsPRepeatfeature        rf  = NULL;
3174     EnsPRepeatfeatureadaptor rfa = NULL;
3175 
3176     debug = ajDebugTest("repeatfeatureadaptorFetchAllbyStatement");
3177 
3178     if (debug)
3179         ajDebug("repeatfeatureadaptorFetchAllbyStatement\n"
3180                 "  ba %p\n"
3181                 "  statement %p\n"
3182                 "  am %p\n"
3183                 "  slice %p\n"
3184                 "  rfs %p\n",
3185                 ba,
3186                 statement,
3187                 am,
3188                 slice,
3189                 rfs);
3190 
3191     if (!ba)
3192         return ajFalse;
3193 
3194     if (!statement)
3195         return ajFalse;
3196 
3197     if (!rfs)
3198         return ajFalse;
3199 
3200     dba = ensBaseadaptorGetDatabaseadaptor(ba);
3201 
3202     rca = ensRegistryGetRepeatconsensusadaptor(dba);
3203     rfa = ensRegistryGetRepeatfeatureadaptor(dba);
3204 
3205     rci     = ajTableuintNew(0U);
3206     rcitorf = ajTableuintNew(0U);
3207 
3208     ajTableSetDestroyvalue(rci, (void (*)(void **)) &ensRepeatconsensusDel);
3209 
3210     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
3211 
3212     sqli = ajSqlrowiterNew(sqls);
3213 
3214     while (!ajSqlrowiterDone(sqli))
3215     {
3216         rfid     = 0;
3217         srid     = 0;
3218         srstart  = 0;
3219         srend    = 0;
3220         srstrand = 0;
3221         rcid     = 0;
3222         rpstart  = 0;
3223         rpend    = 0;
3224         anid     = 0;
3225         score    = 0;
3226 
3227         sqlr = ajSqlrowiterGet(sqli);
3228 
3229         ajSqlcolumnToUint(sqlr, &rfid);
3230         ajSqlcolumnToUint(sqlr, &srid);
3231         ajSqlcolumnToUint(sqlr, &srstart);
3232         ajSqlcolumnToUint(sqlr, &srend);
3233         ajSqlcolumnToInt(sqlr, &srstrand);
3234         ajSqlcolumnToUint(sqlr, &rcid);
3235         ajSqlcolumnToUint(sqlr, &rpstart);
3236         ajSqlcolumnToUint(sqlr, &rpend);
3237         ajSqlcolumnToUint(sqlr, &anid);
3238         ajSqlcolumnToDouble(sqlr, &score);
3239 
3240         ensBaseadaptorRetrieveFeature(ba,
3241                                       anid,
3242                                       srid,
3243                                       srstart,
3244                                       srend,
3245                                       srstrand,
3246                                       am,
3247                                       slice,
3248                                       &feature);
3249 
3250         if (!feature)
3251             continue;
3252 
3253         /* Finally, create a new Ensembl Repeat Feature. */
3254 
3255         rf = ensRepeatfeatureNewIni(rfa,
3256                                     rfid,
3257                                     feature,
3258                                     (EnsPRepeatconsensus) NULL,
3259                                     rpstart,
3260                                     rpend,
3261                                     score);
3262 
3263         ajListPushAppend(rfs, (void *) rf);
3264 
3265         /*
3266         ** Populate two AJAX Table objects to fetch Ensembl Repeat Consensus
3267         ** objects from the database and associate them with
3268         ** Ensembl Repeat Feature objects.
3269         **
3270         ** rci
3271         **   key data:   AJAX unsigned integer
3272         **               (Ensembl Repeat Consensus identifier) objects
3273         **   value data: Ensembl Repeat Consensus objects fetched by
3274         **               ensRepeatconsensusadaptorFetchAllbyIdentifiers
3275         **
3276         ** rcitorf
3277         **   key data:   AJAX unsigned integer
3278         **               (Ensembl Repeat Consensus identifier) objects
3279         **   value data: AJAX List objects of Ensembl Repeat Feature objects
3280         **               that need to be associated with Ensembl Repeat
3281         **               Consensus objects once they have been fetched
3282         **               from the database
3283         */
3284 
3285         if (!ajTableMatchV(rci, (const void *) &rcid))
3286         {
3287             AJNEW0(Pidentifier);
3288 
3289             *Pidentifier = rcid;
3290 
3291             ajTablePut(rci, (void *) Pidentifier, NULL);
3292         }
3293 
3294         list = (AjPList) ajTableFetchmodV(rcitorf, (const void *) &rcid);
3295 
3296         if (!list)
3297         {
3298             AJNEW0(Pidentifier);
3299 
3300             *Pidentifier = rcid;
3301 
3302             list = ajListNew();
3303 
3304             ajTablePut(rcitorf, (void *) Pidentifier, (void *) list);
3305         }
3306 
3307         ajListPushAppend(list, (void *) ensRepeatfeatureNewRef(rf));
3308 
3309         ensFeatureDel(&feature);
3310     }
3311 
3312     ajSqlrowiterDel(&sqli);
3313 
3314     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
3315 
3316     ensRepeatconsensusadaptorFetchAllbyIdentifiers(rca, rci);
3317 
3318     /*
3319     ** Link
3320     ** Ensembl Repeat Consensus objects to
3321     ** Ensembl Repeat Feature objects.
3322     */
3323 
3324     ajTableMapDel(rcitorf,
3325                   &repeatfeatureadaptorLinkRepeatconsensus,
3326                   (void *) rci);
3327 
3328     ajTableFree(&rcitorf);
3329 
3330     /* Delete the utility AJAX Table. */
3331 
3332     ajTableDel(&rci);
3333 
3334     return ajTrue;
3335 }
3336 
3337 
3338 
3339 
3340 /* @section constructors ******************************************************
3341 **
3342 ** All constructors return a new Ensembl Repeat Feature Adaptor by pointer.
3343 ** It is the responsibility of the user to first destroy any previous
3344 ** Repeat Feature Adaptor. The target pointer does not need to be
3345 ** initialised to NULL, but it is good programming practice to do so anyway.
3346 **
3347 ** @fdata [EnsPRepeatfeatureadaptor]
3348 **
3349 ** @nam3rule New Constructor
3350 **
3351 ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
3352 **
3353 ** @valrule * [EnsPRepeatfeatureadaptor]
3354 ** Ensembl Repeat Feature Adaptor or NULL
3355 **
3356 ** @fcategory new
3357 ******************************************************************************/
3358 
3359 
3360 
3361 
3362 /* @func ensRepeatfeatureadaptorNew *******************************************
3363 **
3364 ** Default constructor for an Ensembl Repeat Feature Adaptor.
3365 **
3366 ** Ensembl Object Adaptors are singleton objects in the sense that a single
3367 ** instance of an Ensembl Object Adaptor connected to a particular database is
3368 ** sufficient to instantiate any number of Ensembl Objects from the database.
3369 ** Each Ensembl Object will have a weak reference to the Object Adaptor that
3370 ** instantiated it. Therefore, Ensembl Object Adaptors should not be
3371 ** instantiated directly, but rather obtained from the Ensembl Registry,
3372 ** which will in turn call this function if neccessary.
3373 **
3374 ** @see ensRegistryGetDatabaseadaptor
3375 ** @see ensRegistryGetRepeatfeatureadaptor
3376 **
3377 ** @cc Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptor::new
3378 ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
3379 **
3380 ** @return [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor or NULL
3381 **
3382 ** @release 6.2.0
3383 ** @@
3384 ******************************************************************************/
3385 
ensRepeatfeatureadaptorNew(EnsPDatabaseadaptor dba)3386 EnsPRepeatfeatureadaptor ensRepeatfeatureadaptorNew(
3387     EnsPDatabaseadaptor dba)
3388 {
3389     return ensFeatureadaptorNew(
3390         dba,
3391         repeatfeatureadaptorKTablenames,
3392         repeatfeatureadaptorKColumnnames,
3393         (const EnsPBaseadaptorLeftjoin) NULL,
3394         repeatfeatureadaptorKDefaultcondition,
3395         (const char *) NULL,
3396         &repeatfeatureadaptorFetchAllbyStatement,
3397         (void *(*)(const void *)) NULL,
3398         (void *(*)(void *)) &ensRepeatfeatureNewRef,
3399         (AjBool (*)(const void *)) NULL,
3400         (void (*)(void **)) &ensRepeatfeatureDel,
3401         (size_t (*)(const void *)) &ensRepeatfeatureCalculateMemsize,
3402         (EnsPFeature (*)(const void *)) &ensRepeatfeatureGetFeature,
3403         "Repeatfeature");
3404 }
3405 
3406 
3407 
3408 
3409 /* @section destructors *******************************************************
3410 **
3411 ** Destruction destroys all internal data structures and frees the memory
3412 ** allocated for an Ensembl Repeat Feature Adaptor object.
3413 **
3414 ** @fdata [EnsPRepeatfeatureadaptor]
3415 **
3416 ** @nam3rule Del Destroy (free) an Ensembl Repeat Feature Adaptor
3417 **
3418 ** @argrule * Prfa [EnsPRepeatfeatureadaptor*]
3419 ** Ensembl Repeat Feature Adaptor address
3420 **
3421 ** @valrule * [void]
3422 **
3423 ** @fcategory delete
3424 ******************************************************************************/
3425 
3426 
3427 
3428 
3429 /* @func ensRepeatfeatureadaptorDel *******************************************
3430 **
3431 ** Default destructor for an Ensembl Repeat Feature Adaptor.
3432 **
3433 ** Ensembl Object Adaptors are singleton objects that are registered in the
3434 ** Ensembl Registry and weakly referenced by Ensembl Objects that have been
3435 ** instantiated by it. Therefore, Ensembl Object Adaptors should never be
3436 ** destroyed directly. Upon exit, the Ensembl Registry will call this function
3437 ** if required.
3438 **
3439 ** @param [d] Prfa [EnsPRepeatfeatureadaptor*]
3440 ** Ensembl Repeat Feature Adaptor address
3441 **
3442 ** @return [void]
3443 **
3444 ** @release 6.2.0
3445 ** @@
3446 ******************************************************************************/
3447 
ensRepeatfeatureadaptorDel(EnsPRepeatfeatureadaptor * Prfa)3448 void ensRepeatfeatureadaptorDel(EnsPRepeatfeatureadaptor *Prfa)
3449 {
3450     ensFeatureadaptorDel(Prfa);
3451 
3452     return;
3453 }
3454 
3455 
3456 
3457 
3458 /* @section member retrieval **************************************************
3459 **
3460 ** Functions for returning members of an Ensembl Repeat Feature Adaptor
3461 ** object.
3462 **
3463 ** @fdata [EnsPRepeatfeatureadaptor]
3464 **
3465 ** @nam3rule Get Return Repeat Feature Adaptor attribute(s)
3466 ** @nam4rule Baseadaptor Return the Ensembl Base Adaptor
3467 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
3468 ** @nam4rule Featureadaptor Return the Ensembl Feature Adaptor
3469 **
3470 ** @argrule * rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
3471 **
3472 ** @valrule Baseadaptor [EnsPBaseadaptor]
3473 ** Ensembl Base Adaptor or NULL
3474 ** @valrule Databaseadaptor [EnsPDatabaseadaptor]
3475 ** Ensembl Database Adaptor or NULL
3476 ** @valrule Featureadaptor [EnsPFeatureadaptor]
3477 ** Ensembl Feature Adaptor or NULL
3478 **
3479 ** @fcategory use
3480 ******************************************************************************/
3481 
3482 
3483 
3484 
3485 /* @func ensRepeatfeatureadaptorGetBaseadaptor ********************************
3486 **
3487 ** Get the Ensembl Base Adaptor member of an
3488 ** Ensembl Repeat Feature Adaptor.
3489 **
3490 ** @param [u] rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
3491 **
3492 ** @return [EnsPBaseadaptor] Ensembl Base Adaptor or NULL
3493 **
3494 ** @release 6.5.0
3495 ** @@
3496 ******************************************************************************/
3497 
ensRepeatfeatureadaptorGetBaseadaptor(EnsPRepeatfeatureadaptor rfa)3498 EnsPBaseadaptor ensRepeatfeatureadaptorGetBaseadaptor(
3499     EnsPRepeatfeatureadaptor rfa)
3500 {
3501     return ensFeatureadaptorGetBaseadaptor(
3502         ensRepeatfeatureadaptorGetFeatureadaptor(rfa));
3503 }
3504 
3505 
3506 
3507 
3508 /* @func ensRepeatfeatureadaptorGetDatabaseadaptor ****************************
3509 **
3510 ** Get the Ensembl Database Adaptor member of an
3511 ** Ensembl Repeat Feature Adaptor.
3512 **
3513 ** @param [u] rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
3514 **
3515 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
3516 **
3517 ** @release 6.4.0
3518 ** @@
3519 ******************************************************************************/
3520 
ensRepeatfeatureadaptorGetDatabaseadaptor(EnsPRepeatfeatureadaptor rfa)3521 EnsPDatabaseadaptor ensRepeatfeatureadaptorGetDatabaseadaptor(
3522     EnsPRepeatfeatureadaptor rfa)
3523 {
3524     return ensFeatureadaptorGetDatabaseadaptor(
3525         ensRepeatfeatureadaptorGetFeatureadaptor(rfa));
3526 }
3527 
3528 
3529 
3530 
3531 /* @func ensRepeatfeatureadaptorGetFeatureadaptor *****************************
3532 **
3533 ** Get the Ensembl Feature Adaptor member of an
3534 ** Ensembl Repeat Feature Adaptor.
3535 **
3536 ** @param [u] rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
3537 **
3538 ** @return [EnsPFeatureadaptor] Ensembl Feature Adaptor or NULL
3539 **
3540 ** @release 6.5.0
3541 ** @@
3542 ******************************************************************************/
3543 
ensRepeatfeatureadaptorGetFeatureadaptor(EnsPRepeatfeatureadaptor rfa)3544 EnsPFeatureadaptor ensRepeatfeatureadaptorGetFeatureadaptor(
3545     EnsPRepeatfeatureadaptor rfa)
3546 {
3547     return rfa;
3548 }
3549 
3550 
3551 
3552 
3553 /* @section object retrieval **************************************************
3554 **
3555 ** Functions for fetching Ensembl Repeat Feature objects from an
3556 ** Ensembl SQL database.
3557 **
3558 ** @fdata [EnsPRepeatfeatureadaptor]
3559 **
3560 ** @nam3rule Fetch Fetch Ensembl Repeat Feature object(s)
3561 ** @nam4rule All Fetch all Ensembl Repeat Feature objects
3562 ** @nam4rule Allby Fetch all Ensembl Repeat Feature objects
3563 **                 matching a criterion
3564 ** @nam5rule Slice Fetch all by an Ensembl Slice
3565 ** @nam4rule By Fetch one Ensembl Repeat Feature object
3566 **              matching a criterion
3567 **
3568 ** @argrule * rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
3569 ** @argrule AllbySlice slice [EnsPSlice] Ensembl Slice
3570 ** @argrule AllbySlice anname [const AjPStr] Ensembl Analysis name
3571 ** @argrule AllbySlice rctype [const AjPStr] Ensembl Repeat Consensus type
3572 ** @argrule AllbySlice rcclass [const AjPStr] Ensembl Repeat Consensus class
3573 ** @argrule AllbySlice rcname [const AjPStr] Ensembl Repeat Consensus name
3574 ** @argrule AllbySlice rfs [AjPList]
3575 ** AJAX List of Ensembl Repeat Feature objects
3576 **
3577 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
3578 **
3579 ** @fcategory use
3580 ******************************************************************************/
3581 
3582 
3583 
3584 
3585 /* @func ensRepeatfeatureadaptorFetchAllbySlice *******************************
3586 **
3587 ** Fetch all Ensembl Repeat Feature objects on an Ensembl Slice.
3588 ** The caller is responsible for deleting the Ensembl Repeat Feature objects
3589 ** before deleting the AJAX List.
3590 **
3591 ** @cc Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptor::fetch_all_by_Slice
3592 ** @param [u] rfa [EnsPRepeatfeatureadaptor] Ensembl Repeat Feature Adaptor
3593 ** @param [u] slice [EnsPSlice] Ensembl Slice
3594 ** @param [rN] anname [const AjPStr] Ensembl Analysis name
3595 ** @param [rN] rctype [const AjPStr] Ensembl Repeat Consensus type
3596 ** @param [rN] rcclass [const AjPStr] Ensembl Repeat Consensus class
3597 ** @param [rN] rcname [const AjPStr] Ensembl Repeat Consensus name
3598 ** @param [u] rfs [AjPList] AJAX List of Ensembl Repeat Feature objects
3599 **
3600 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3601 **
3602 ** @release 6.4.0
3603 ** @@
3604 ******************************************************************************/
3605 
ensRepeatfeatureadaptorFetchAllbySlice(EnsPRepeatfeatureadaptor rfa,EnsPSlice slice,const AjPStr anname,const AjPStr rctype,const AjPStr rcclass,const AjPStr rcname,AjPList rfs)3606 AjBool ensRepeatfeatureadaptorFetchAllbySlice(
3607     EnsPRepeatfeatureadaptor rfa,
3608     EnsPSlice slice,
3609     const AjPStr anname,
3610     const AjPStr rctype,
3611     const AjPStr rcclass,
3612     const AjPStr rcname,
3613     AjPList rfs)
3614 {
3615     char *txtrcclass = NULL;
3616     char *txtrcname = NULL;
3617     char *txtrctype = NULL;
3618 
3619     AjBool result = AJFALSE;
3620 
3621     AjPStr constraint = NULL;
3622 
3623     EnsPFeatureadaptor fa = NULL;
3624 
3625     if (ajDebugTest("ensRepeatfeatureadaptorFetchAllbySlice"))
3626         ajDebug("ensRepeatfeatureadaptorFetchAllbySlice\n"
3627                 "  rfa %p\n"
3628                 "  slice %p\n"
3629                 "  anname '%S'\n"
3630                 "  rctype '%S'\n"
3631                 "  rcclass '%S'\n"
3632                 "  rcname '%S'\n"
3633                 "  rfs %p\n",
3634                 rfa,
3635                 slice,
3636                 anname,
3637                 rctype,
3638                 rcclass,
3639                 rcname,
3640                 rfs);
3641 
3642     if (!rfa)
3643         return ajFalse;
3644 
3645     if (!slice)
3646         return ajFalse;
3647 
3648     if (!rfs)
3649         return ajFalse;
3650 
3651     fa = ensRepeatfeatureadaptorGetFeatureadaptor(rfa);
3652 
3653     if (rctype && ajStrGetLen(rctype))
3654     {
3655         ensFeatureadaptorEscapeC(fa, &txtrctype, rctype);
3656 
3657         constraint = ajFmtStr("repeat_consensus.repeat_type = '%s'",
3658                               txtrctype);
3659 
3660         ajCharDel(&txtrctype);
3661     }
3662 
3663     if (rcclass && ajStrGetLen(rcclass))
3664     {
3665         ensFeatureadaptorEscapeC(fa, &txtrcclass, rcclass);
3666 
3667         if (constraint)
3668             ajFmtPrintAppS(&constraint,
3669                            " AND repeat_consensus.repeat_class = '%s'",
3670                            txtrcclass);
3671         else
3672             constraint = ajFmtStr("repeat_consensus.repeat_class = '%s'",
3673                                   txtrcclass);
3674 
3675         ajCharDel(&txtrcclass);
3676     }
3677 
3678     if (rcname && ajStrGetLen(rcname))
3679     {
3680         ensFeatureadaptorEscapeC(fa, &txtrcname, rcname);
3681 
3682         if (constraint)
3683             ajFmtPrintAppS(&constraint,
3684                            " AND repeat_consensus.repeat_name = '%s'",
3685                            txtrcname);
3686         else
3687             constraint = ajFmtStr("repeat_consensus.repeat_name = '%s'",
3688                                   txtrcname);
3689 
3690         ajCharDel(&txtrcname);
3691     }
3692 
3693     result = ensFeatureadaptorFetchAllbySlice(
3694         fa,
3695         slice,
3696         constraint,
3697         anname,
3698         rfs);
3699 
3700     ajStrDel(&constraint);
3701 
3702     return result;
3703 }
3704