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