1 /* @source ensgene ************************************************************
2 **
3 ** Ensembl Gene functions
4 **
5 ** @author Copyright (C) 1999 Ensembl Developers
6 ** @author Copyright (C) 2006 Michael K. Schuster
7 ** @version $Revision: 1.74 $
8 ** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core
9 ** @modified $Date: 2013/02/17 13:06:02 $ 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 "ensdatabaseentry.h"
35 #include "ensexon.h"
36 #include "ensexternaldatabase.h"
37 #include "ensgene.h"
38 #include "ensprojectionsegment.h"
39 #include "enstable.h"
40 #include "enstranscript.h"
41 
42 
43 
44 
45 /* ========================================================================= */
46 /* =============================== constants =============================== */
47 /* ========================================================================= */
48 
49 
50 
51 
52 /* ========================================================================= */
53 /* =========================== global variables ============================ */
54 /* ========================================================================= */
55 
56 
57 
58 
59 /* ========================================================================= */
60 /* ============================= private data ============================== */
61 /* ========================================================================= */
62 
63 
64 
65 
66 /* ========================================================================= */
67 /* =========================== private constants =========================== */
68 /* ========================================================================= */
69 
70 /* @conststatic geneKStatus ***************************************************
71 **
72 ** The Ensembl Gene status member is enumerated in both, the SQL table
73 ** definition and the data structure. The following strings are used for
74 ** conversion in database operations and correspond to EnsEGeneStatus.
75 **
76 ******************************************************************************/
77 
78 static const char *const geneKStatus[] =
79 {
80     "",
81     "KNOWN",
82     "NOVEL",
83     "PUTATIVE",
84     "PREDICTED",
85     "KNOWN_BY_PROJECTION",
86     "UNKNOWN",
87     (const char *) NULL
88 };
89 
90 
91 
92 
93 /* @conststatic geneadaptorKTablenames ****************************************
94 **
95 ** Array of Ensembl Gene Adaptor SQL table names
96 **
97 ******************************************************************************/
98 
99 static const char *const geneadaptorKTablenames[] =
100 {
101     "gene",
102     "xref",
103     (const char *) NULL
104 };
105 
106 
107 
108 
109 /* @conststatic geneadaptorKColumnnames ***************************************
110 **
111 ** Array of Ensembl Gene Adaptor SQL column names
112 **
113 ******************************************************************************/
114 
115 static const char *const geneadaptorKColumnnames[] =
116 {
117     "gene.gene_id",
118     "gene.seq_region_id",
119     "gene.seq_region_start",
120     "gene.seq_region_end",
121     "gene.seq_region_strand",
122     "gene.analysis_id",
123     "gene.display_xref_id",
124     "gene.description",
125     "gene.source",
126     "gene.biotype",
127     "gene.status",
128     "gene.is_current",
129     "gene.canonical_transcript_id",
130     "gene.canonical_annotation",
131     "gene.stable_id",
132     "gene.version",
133     "gene.created_date",
134     "gene.modified_date",
135     "xref.external_db_id",
136     "xref.dbprimary_acc",
137     "xref.display_label",
138     "xref.version",
139     "xref.description",
140     "xref.info_type",
141     "xref.info_text",
142     (const char *) NULL
143 };
144 
145 
146 
147 
148 /* @conststatic geneadaptorKLeftjoins *****************************************
149 **
150 ** Array of Ensembl Gene Adaptor SQL LEFT JOIN conditions
151 **
152 ******************************************************************************/
153 
154 static const EnsOBaseadaptorLeftjoin geneadaptorKLeftjoins[] =
155 {
156     {"xref", "gene.display_xref_id = xref.xref_id"},
157     {(const char *) NULL, (const char *) NULL}
158 };
159 
160 
161 
162 
163 /* ========================================================================= */
164 /* =========================== private variables =========================== */
165 /* ========================================================================= */
166 
167 
168 
169 
170 /* ========================================================================= */
171 /* =========================== private functions =========================== */
172 /* ========================================================================= */
173 
174 static EnsPGene geneNewCpyFeatures(EnsPGene gene);
175 
176 static int listExonCompareAddressAscending(
177     const void *item1,
178     const void *item2);
179 
180 static void listExonDelete(void **Pitem, void *cl);
181 
182 static int listGeneCompareEndAscending(
183     const void *item1,
184     const void *item2);
185 
186 static int listGeneCompareEndDescending(
187     const void *item1,
188     const void *item2);
189 
190 static int listGeneCompareIdentifierAscending(
191     const void *item1,
192     const void *item2);
193 
194 static int listGeneCompareStartAscending(
195     const void *item1,
196     const void *item2);
197 
198 static int listGeneCompareStartDescending(
199     const void *item1,
200     const void *item2);
201 
202 static AjBool geneadaptorFetchAllbyStatement(
203     EnsPBaseadaptor ba,
204     const AjPStr statement,
205     EnsPAssemblymapper am,
206     EnsPSlice slice,
207     AjPList genes);
208 
209 
210 
211 
212 /* ========================================================================= */
213 /* ======================= All functions by section ======================== */
214 /* ========================================================================= */
215 
216 
217 
218 
219 /* @filesection ensgene *******************************************************
220 **
221 ** @nam1rule ens Function belongs to the Ensembl library
222 **
223 ******************************************************************************/
224 
225 
226 
227 
228 /* @datasection [EnsPGene] Ensembl Gene ***************************************
229 **
230 ** @nam2rule Gene Functions for manipulating Ensembl Gene objects
231 **
232 ** @cc Bio::EnsEMBL::Gene
233 ** @cc CVS Revision: 1.180
234 ** @cc CVS Tag: branch-ensembl-68
235 **
236 ******************************************************************************/
237 
238 
239 
240 
241 /* @section constructors ******************************************************
242 **
243 ** All constructors return a new Ensembl Gene by pointer.
244 ** It is the responsibility of the user to first destroy any previous
245 ** Gene. The target pointer does not need to be initialised to
246 ** NULL, but it is good programming practice to do so anyway.
247 **
248 ** @fdata [EnsPGene]
249 **
250 ** @nam3rule New Constructor
251 ** @nam4rule Cpy Constructor with existing object
252 ** @nam4rule Ini Constructor with initial values
253 ** @nam4rule Ref Constructor by incrementing the reference counter
254 **
255 ** @argrule Cpy gene [const EnsPGene] Ensembl Gene
256 ** @argrule Ini ga [EnsPGeneadaptor] Ensembl Gene Adaptor
257 ** @argrule Ini identifier [ajuint] SQL database-internal identifier
258 ** @argrule Ini feature [EnsPFeature] Ensembl Feature
259 ** @argrule Ini displaydbe [EnsPDatabaseentry] Ensembl display Database Entry
260 ** @argrule Ini description [AjPStr] Description
261 ** @argrule Ini source [AjPStr] Source
262 ** @argrule Ini biotype [AjPStr] Biotype
263 ** @argrule Ini status [EnsEGeneStatus] Status
264 ** @argrule Ini current [AjBool] Current attribute
265 ** @argrule Ini cantrcid [ajuint] Canonical Ensembl Transcript identifier
266 ** @argrule Ini canann [AjPStr] Canonical annotation
267 ** @argrule Ini stableid [AjPStr] Stable identifier
268 ** @argrule Ini version [ajuint] Version
269 ** @argrule Ini cdate [AjPStr] Creation date
270 ** @argrule Ini mdate [AjPStr] Modification date
271 ** @argrule Ini transcripts [AjPList] AJAX List of Ensembl Transcript objects
272 ** @argrule Ref gene [EnsPGene] Ensembl Gene
273 **
274 ** @valrule * [EnsPGene] Ensembl Gene or NULL
275 **
276 ** @fcategory new
277 ******************************************************************************/
278 
279 
280 
281 
282 /* @func ensGeneNewCpy ********************************************************
283 **
284 ** Object-based constructor function, which returns an independent object.
285 **
286 ** @param [r] gene [const EnsPGene] Ensembl Gene
287 **
288 ** @return [EnsPGene] Ensembl Gene or NULL
289 **
290 ** @release 6.4.0
291 ** @@
292 ******************************************************************************/
293 
ensGeneNewCpy(const EnsPGene gene)294 EnsPGene ensGeneNewCpy(const EnsPGene gene)
295 {
296     AjIList iter = NULL;
297 
298     EnsPAttribute attribute = NULL;
299 
300     EnsPDatabaseentry dbe = NULL;
301 
302     EnsPGene pthis = NULL;
303 
304     EnsPTranscript transcript = NULL;
305 
306     if (!gene)
307         return NULL;
308 
309     AJNEW0(pthis);
310 
311     pthis->Use        = 1U;
312     pthis->Identifier = gene->Identifier;
313     pthis->Adaptor    = gene->Adaptor;
314     pthis->Feature    = ensFeatureNewRef(gene->Feature);
315 
316     pthis->Displayreference = ensDatabaseentryNewRef(gene->Displayreference);
317 
318     if (gene->Description)
319         pthis->Description = ajStrNewRef(gene->Description);
320 
321     if (gene->Source)
322         pthis->Source = ajStrNewRef(gene->Source);
323 
324     if (gene->Biotype)
325         pthis->Biotype = ajStrNewRef(gene->Biotype);
326 
327     pthis->Status  = gene->Status;
328     pthis->Current = gene->Current;
329 
330     if (gene->Canonicalannotation)
331         pthis->Canonicalannotation = ajStrNewRef(gene->Canonicalannotation);
332 
333     pthis->Canonicaltranscriptidentifier =
334         gene->Canonicaltranscriptidentifier;
335 
336     pthis->Version = gene->Version;
337 
338     if (gene->Stableidentifier)
339         pthis->Stableidentifier = ajStrNewRef(gene->Stableidentifier);
340 
341     if (gene->DateCreation)
342         pthis->DateCreation = ajStrNewRef(gene->DateCreation);
343 
344     if (gene->DateModification)
345         pthis->DateModification = ajStrNewRef(gene->DateModification);
346 
347     /* NOTE: Copy the AJAX List of Ensembl Attribute objects. */
348 
349     if (gene->Attributes && ajListGetLength(gene->Attributes))
350     {
351         pthis->Attributes = ajListNew();
352 
353         iter = ajListIterNew(gene->Attributes);
354 
355         while (!ajListIterDone(iter))
356         {
357             attribute = (EnsPAttribute) ajListIterGet(iter);
358 
359             ajListPushAppend(pthis->Attributes,
360                              (void *) ensAttributeNewRef(attribute));
361         }
362 
363         ajListIterDel(&iter);
364     }
365     else
366         pthis->Attributes = NULL;
367 
368     /* NOTE: Copy the AJAX List of Ensembl Database Entry objects. */
369 
370     if (gene->Databaseentries && ajListGetLength(gene->Databaseentries))
371     {
372         pthis->Databaseentries = ajListNew();
373 
374         iter = ajListIterNew(gene->Databaseentries);
375 
376         while (!ajListIterDone(iter))
377         {
378             dbe = (EnsPDatabaseentry) ajListIterGet(iter);
379 
380             ajListPushAppend(pthis->Databaseentries,
381                              (void *) ensDatabaseentryNewRef(dbe));
382         }
383 
384         ajListIterDel(&iter);
385     }
386     else
387         pthis->Databaseentries = NULL;
388 
389     /* NOTE: Copy the AJAX List of Ensembl Transcript objects. */
390 
391     if (gene->Transcripts && ajListGetLength(gene->Transcripts))
392     {
393         pthis->Transcripts = ajListNew();
394 
395         iter = ajListIterNew(gene->Transcripts);
396 
397         while (!ajListIterDone(iter))
398         {
399             transcript = (EnsPTranscript) ajListIterGet(iter);
400 
401             ajListPushAppend(pthis->Transcripts,
402                              (void *) ensTranscriptNewRef(transcript));
403         }
404 
405         ajListIterDel(&iter);
406     }
407     else
408         pthis->Transcripts = NULL;
409 
410     return pthis;
411 }
412 
413 
414 
415 
416 /* @func ensGeneNewIni ********************************************************
417 **
418 ** Constructor of an Ensembl Gene with initial values.
419 **
420 ** @cc Bio::EnsEMBL::Storable::new
421 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
422 ** @param [r] identifier [ajuint] SQL database-internal identifier
423 ** @cc Bio::EnsEMBL::Feature::new
424 ** @param [u] feature [EnsPFeature] Ensembl Feature
425 ** @cc Bio::EnsEMBL::Gene::new
426 ** @param [u] displaydbe [EnsPDatabaseentry] Ensembl display Database Entry
427 ** @param [u] description [AjPStr] Description
428 ** @param [u] source [AjPStr] Source
429 ** @param [u] biotype [AjPStr] Biotype
430 ** @param [u] status [EnsEGeneStatus] Status
431 ** @param [r] current [AjBool] Current attribute
432 ** @param [r] cantrcid [ajuint] Canonical Ensembl Transcript identifier
433 ** @param [u] canann [AjPStr] Canonical annotation
434 ** @param [u] stableid [AjPStr] Stable identifier
435 ** @param [r] version [ajuint] Version
436 ** @param [u] cdate [AjPStr] Creation date
437 ** @param [u] mdate [AjPStr] Modification date
438 ** @param [u] transcripts [AjPList] AJAX List of Ensembl Transcript objects
439 **
440 ** @return [EnsPGene] Ensembl Gene or NULL
441 **
442 ** @release 6.4.0
443 ** @@
444 ******************************************************************************/
445 
ensGeneNewIni(EnsPGeneadaptor ga,ajuint identifier,EnsPFeature feature,EnsPDatabaseentry displaydbe,AjPStr description,AjPStr source,AjPStr biotype,EnsEGeneStatus status,AjBool current,ajuint cantrcid,AjPStr canann,AjPStr stableid,ajuint version,AjPStr cdate,AjPStr mdate,AjPList transcripts)446 EnsPGene ensGeneNewIni(EnsPGeneadaptor ga,
447                        ajuint identifier,
448                        EnsPFeature feature,
449                        EnsPDatabaseentry displaydbe,
450                        AjPStr description,
451                        AjPStr source,
452                        AjPStr biotype,
453                        EnsEGeneStatus status,
454                        AjBool current,
455                        ajuint cantrcid,
456                        AjPStr canann,
457                        AjPStr stableid,
458                        ajuint version,
459                        AjPStr cdate,
460                        AjPStr mdate,
461                        AjPList transcripts)
462 {
463     AjIList iter = NULL;
464 
465     EnsPGene gene = NULL;
466 
467     EnsPTranscript transcript = NULL;
468 
469     if (ajDebugTest("ensGeneNew"))
470     {
471         ajDebug("ensGeneNew\n"
472                 "  ga %p\n"
473                 "  identifier %u\n"
474                 "  feature %p\n"
475                 "  displaydbe %p\n"
476                 "  description '%S'\n"
477                 "  source '%S'\n"
478                 "  biotype '%S'\n"
479                 "  status %d\n"
480                 "  current %b\n"
481                 "  cantrcid %u\n"
482                 "  canann '%S'\n"
483                 "  stableid '%S'\n"
484                 "  version %u\n"
485                 "  cdate '%S'\n"
486                 "  mdate '%S'\n"
487                 "  transcripts %p\n",
488                 ga,
489                 identifier,
490                 feature,
491                 displaydbe,
492                 description,
493                 source,
494                 biotype,
495                 status,
496                 current,
497                 cantrcid,
498                 canann,
499                 stableid,
500                 version,
501                 cdate,
502                 mdate,
503                 transcripts);
504 
505         ensFeatureTrace(feature, 1);
506 
507         ensDatabaseentryTrace(displaydbe, 1);
508     }
509 
510     if (!feature)
511         return NULL;
512 
513     AJNEW0(gene);
514 
515     gene->Use        = 1U;
516     gene->Identifier = identifier;
517     gene->Adaptor    = ga;
518     gene->Feature    = ensFeatureNewRef(feature);
519 
520     gene->Displayreference = ensDatabaseentryNewRef(displaydbe);
521 
522     if (description)
523         gene->Description = ajStrNewRef(description);
524 
525     if (source)
526         gene->Source = ajStrNewRef(source);
527 
528     if (biotype)
529         gene->Biotype = ajStrNewRef(biotype);
530 
531     gene->Status  = status;
532     gene->Current = current;
533 
534     if (canann)
535         gene->Canonicalannotation = ajStrNewRef(canann);
536 
537     gene->Canonicaltranscriptidentifier = cantrcid;
538     gene->Version = version;
539 
540     if (stableid)
541         gene->Stableidentifier = ajStrNewRef(stableid);
542 
543     if (cdate)
544         gene->DateCreation = ajStrNewRef(cdate);
545 
546     if (mdate)
547         gene->DateModification = ajStrNewRef(mdate);
548 
549     gene->Attributes = NULL;
550 
551     gene->Databaseentries = NULL;
552 
553     /* NOTE: Copy the AJAX List of Ensembl Transcript objects. */
554 
555     if (transcripts && ajListGetLength(transcripts))
556     {
557         gene->Transcripts = ajListNew();
558 
559         iter = ajListIterNew(transcripts);
560 
561         while (!ajListIterDone(iter))
562         {
563             transcript = (EnsPTranscript) ajListIterGet(iter);
564 
565             ajListPushAppend(gene->Transcripts,
566                              (void *) ensTranscriptNewRef(transcript));
567         }
568 
569         ajListIterDel(&iter);
570     }
571     else
572         gene->Transcripts = NULL;
573 
574     return gene;
575 }
576 
577 
578 
579 
580 /* @func ensGeneNewRef ********************************************************
581 **
582 ** Ensembl Object referencing function, which returns a pointer to the
583 ** Ensembl Object passed in and increases its reference count.
584 **
585 ** @param [u] gene [EnsPGene] Ensembl Gene
586 **
587 ** @return [EnsPGene] Ensembl Gene or NULL
588 **
589 ** @release 6.2.0
590 ** @@
591 ******************************************************************************/
592 
ensGeneNewRef(EnsPGene gene)593 EnsPGene ensGeneNewRef(EnsPGene gene)
594 {
595     if (!gene)
596         return NULL;
597 
598     gene->Use++;
599 
600     return gene;
601 }
602 
603 
604 
605 
606 /* @funcstatic geneNewCpyFeatures *********************************************
607 **
608 ** Returns a new copy of an Ensembl Gene, but in addition to the shallow
609 ** copy provided by ensGeneNewCpy, also copies all Ensembl Gene-
610 ** internal Ensembl Objects based on the Ensembl Feature class. This is useful
611 ** in preparation of ensGeneTransform and ensGeneTransfer, which
612 ** return an independent Ensembl Gene object and therefore, require
613 ** independent mapping of all internal Feature objects to the new
614 ** Ensembl Coordinate System or Ensembl Slice.
615 **
616 ** @param [u] gene [EnsPGene] Ensembl Gene
617 **
618 ** @return [EnsPGene] Ensembl Gene or NULL
619 **
620 ** @release 6.4.0
621 ** @@
622 ******************************************************************************/
623 
geneNewCpyFeatures(EnsPGene gene)624 static EnsPGene geneNewCpyFeatures(EnsPGene gene)
625 {
626     AjIList iter = NULL;
627 
628     EnsPGene newgene = NULL;
629 
630     EnsPTranscript newtranscript = NULL;
631     EnsPTranscript oldtranscript = NULL;
632 
633     if (!gene)
634         return NULL;
635 
636     newgene = ensGeneNewCpy(gene);
637 
638     if (!newgene)
639         return NULL;
640 
641     /* Copy the AJAX List of Ensembl Transcript objects. */
642 
643     if (newgene->Transcripts)
644     {
645         iter = ajListIterNew(newgene->Transcripts);
646 
647         while (!ajListIterDone(iter))
648         {
649             oldtranscript = (EnsPTranscript) ajListIterGet(iter);
650 
651             ajListIterRemove(iter);
652 
653             newtranscript = ensTranscriptNewCpy(oldtranscript);
654 
655             ajListIterInsert(iter, (void *) newtranscript);
656 
657             /* Advance the AJAX List Iterator after the insert. */
658 
659             (void) ajListIterGet(iter);
660 
661             ensTranscriptDel(&oldtranscript);
662         }
663 
664         ajListIterDel(&iter);
665     }
666 
667     return newgene;
668 }
669 
670 
671 
672 
673 /* @section destructors *******************************************************
674 **
675 ** Destruction destroys all internal data structures and frees the memory
676 ** allocated for an Ensembl Gene object.
677 **
678 ** @fdata [EnsPGene]
679 **
680 ** @nam3rule Del Destroy (free) an Ensembl Gene
681 **
682 ** @argrule * Pgene [EnsPGene*] Ensembl Gene address
683 **
684 ** @valrule * [void]
685 **
686 ** @fcategory delete
687 ******************************************************************************/
688 
689 
690 
691 
692 /* @func ensGeneDel ***********************************************************
693 **
694 ** Default destructor for an Ensembl Gene.
695 **
696 ** @param [d] Pgene [EnsPGene*] Ensembl Gene address
697 **
698 ** @return [void]
699 **
700 ** @release 6.2.0
701 ** @@
702 ******************************************************************************/
703 
ensGeneDel(EnsPGene * Pgene)704 void ensGeneDel(EnsPGene *Pgene)
705 {
706     EnsPAttribute attribute = NULL;
707 
708     EnsPDatabaseentry dbe = NULL;
709 
710     EnsPTranscript transcript = NULL;
711 
712     EnsPGene pthis = NULL;
713 
714     if (!Pgene)
715         return;
716 
717 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
718     if (ajDebugTest("ensGeneDel"))
719     {
720         ajDebug("ensGeneDel\n"
721                 "  *Pgene %p\n",
722                 *Pgene);
723 
724         ensGeneTrace(*Pgene, 1);
725     }
726 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
727 
728     if (!(pthis = *Pgene) || --pthis->Use)
729     {
730         *Pgene = NULL;
731 
732         return;
733     }
734 
735     ensFeatureDel(&pthis->Feature);
736 
737     ensDatabaseentryDel(&pthis->Displayreference);
738 
739     ajStrDel(&pthis->Description);
740     ajStrDel(&pthis->Source);
741     ajStrDel(&pthis->Biotype);
742     ajStrDel(&pthis->Canonicalannotation);
743     ajStrDel(&pthis->Stableidentifier);
744     ajStrDel(&pthis->DateCreation);
745     ajStrDel(&pthis->DateModification);
746 
747     /* Clear and delete the AJAX List of Ensembl Attribute objects. */
748 
749     while (ajListPop(pthis->Attributes, (void **) &attribute))
750         ensAttributeDel(&attribute);
751 
752     ajListFree(&pthis->Databaseentries);
753 
754     /* Clear and delete the AJAX List of Ensembl Database Entry objects. */
755 
756     while (ajListPop(pthis->Databaseentries, (void **) &dbe))
757         ensDatabaseentryDel(&dbe);
758 
759     ajListFree(&pthis->Databaseentries);
760 
761     /* Clear and delete the AJAX List of Ensembl Transcript objects. */
762 
763     while (ajListPop(pthis->Transcripts, (void **) &transcript))
764         ensTranscriptDel(&transcript);
765 
766     ajListFree(&pthis->Transcripts);
767 
768     ajMemFree((void **) Pgene);
769 
770     return;
771 }
772 
773 
774 
775 
776 /* @section member retrieval **************************************************
777 **
778 ** Functions for returning members of an Ensembl Gene object.
779 **
780 ** @fdata [EnsPGene]
781 **
782 ** @nam3rule Get Return Gene attribute(s)
783 ** @nam4rule Adaptor Return the Ensembl Gene Adaptor
784 ** @nam4rule Biotype Return the biological type
785 ** @nam4rule Canonicalannotation Return the canonical annotation
786 ** @nam4rule Canonicaltranscriptidentifier
787 ** Return the canonical Ensembl Transcript identifier
788 ** @nam4rule Current Return the current attribute
789 ** @nam4rule Date Return a date
790 ** @nam5rule DateCreation Return the creation date
791 ** @nam5rule DateModification Return the modification date
792 ** @nam4rule Description Return the description
793 ** @nam4rule Displayreference Return the display External Reference
794 ** @nam4rule Feature Return the Ensembl Feature
795 ** @nam4rule Identifier Return the SQL database-internal identifier
796 ** @nam4rule Source Return the source
797 ** @nam4rule Stableidentifier Return the stable identifier
798 ** @nam4rule Status Return the status
799 ** @nam4rule Version Return the version
800 ** @nam4rule Attributes Return all Ensembl Attribute objects
801 ** @nam4rule Databaseentries Return all Ensembl Database Entry objects
802 ** @nam4rule Transcripts Return all Ensembl Transcript objects
803 **
804 ** @argrule * gene [const EnsPGene] Gene
805 **
806 ** @valrule Adaptor [EnsPGeneadaptor] Ensembl Gene Adaptor or NULL
807 ** @valrule Biotype [AjPStr] Biological type or NULL
808 ** @valrule Canonicaltranscriptidentifier [ajuint]
809 ** Canonical Ensembl Transcript identifier or 0U
810 ** @valrule Canonicalannotation [AjPStr] Canonical annotation or NULL
811 ** @valrule Current [AjBool] Current flag or ajFalse
812 ** @valrule DateCreation [AjPStr] Creation date or NULL
813 ** @valrule DateModification [AjPStr] Modification date or NULL
814 ** @valrule Description [AjPStr] Description or NULL
815 ** @valrule Displayreference [EnsPDatabaseentry] Ensembl Database Entry or NULL
816 ** @valrule Feature [EnsPFeature] Ensembl Feature or NULL
817 ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U
818 ** @valrule Source [AjPStr] Source or NULL
819 ** @valrule Stableidentifier [AjPStr] Stable identifier or NULL
820 ** @valrule Status [EnsEGeneStatus] Status or ensEGeneStatusNULL
821 ** @valrule Version [ajuint] Version or 0U
822 ** @valrule Attributes [const AjPList]
823 ** AJAX List of Ensembl Attribute objects or NULL
824 ** @valrule Databaseentries [const AjPList]
825 ** AJAX List of Ensembl Database Entry objects or NULL
826 ** @valrule Transcripts [const AjPList]
827 ** AJAX List of Ensembl Transcript objects or NULL
828 **
829 ** @fcategory use
830 ******************************************************************************/
831 
832 
833 
834 
835 /* @func ensGeneGetAdaptor ****************************************************
836 **
837 ** Get the Ensembl Gene Adaptor member of an Ensembl Gene.
838 **
839 ** @cc Bio::EnsEMBL::Storable::adaptor
840 ** @param [r] gene [const EnsPGene] Ensembl Gene
841 **
842 ** @return [EnsPGeneadaptor] Ensembl Gene Adaptor or NULL
843 **
844 ** @release 6.2.0
845 ** @@
846 ******************************************************************************/
847 
ensGeneGetAdaptor(const EnsPGene gene)848 EnsPGeneadaptor ensGeneGetAdaptor(const EnsPGene gene)
849 {
850     return (gene) ? gene->Adaptor : NULL;
851 }
852 
853 
854 
855 
856 /* @func ensGeneGetBiotype ****************************************************
857 **
858 ** Get the biological type member of an Ensembl Gene.
859 **
860 ** @cc Bio::EnsEMBL::Gene::biotype
861 ** @param [r] gene [const EnsPGene] Ensembl Gene
862 **
863 ** @return [AjPStr] Biological type or NULL
864 **
865 ** @release 6.4.0
866 ** @@
867 ******************************************************************************/
868 
ensGeneGetBiotype(const EnsPGene gene)869 AjPStr ensGeneGetBiotype(const EnsPGene gene)
870 {
871     return (gene) ? gene->Biotype : NULL;
872 }
873 
874 
875 
876 
877 /* @func ensGeneGetCanonicalannotation ****************************************
878 **
879 ** Get the canonical annotation member of an Ensembl Gene.
880 **
881 ** @cc Bio::EnsEMBL::Gene::canonical_annotation
882 ** @param [r] gene [const EnsPGene] Ensembl Gene
883 **
884 ** @return [AjPStr] Canonical annotation or NULL
885 **
886 ** @release 6.4.0
887 ** @@
888 ******************************************************************************/
889 
ensGeneGetCanonicalannotation(const EnsPGene gene)890 AjPStr ensGeneGetCanonicalannotation(const EnsPGene gene)
891 {
892     return (gene) ? gene->Canonicalannotation : NULL;
893 }
894 
895 
896 
897 
898 /* @func ensGeneGetCanonicaltranscriptidentifier ******************************
899 **
900 ** Get the canonical Ensembl Transcript identifier member of an Ensembl Gene.
901 **
902 ** @cc Bio::EnsEMBL::Gene::canonical_transcript
903 ** @param [r] gene [const EnsPGene] Ensembl Gene
904 **
905 ** @return [ajuint] Canonical Ensembl Transcript identifier or 0U
906 **
907 ** @release 6.4.0
908 ** @@
909 ******************************************************************************/
910 
ensGeneGetCanonicaltranscriptidentifier(const EnsPGene gene)911 ajuint ensGeneGetCanonicaltranscriptidentifier(const EnsPGene gene)
912 {
913     return (gene) ? gene->Canonicaltranscriptidentifier : 0U;
914 }
915 
916 
917 
918 
919 /* @func ensGeneGetCurrent ****************************************************
920 **
921 ** Get the current attribute of an Ensembl Gene.
922 **
923 ** @cc Bio::EnsEMBL::Gene::is_current
924 ** @param [r] gene [const EnsPGene] Ensembl Gene
925 **
926 ** @return [AjBool] Current attribute or ajFalse
927 **
928 ** @release 6.2.0
929 ** @@
930 ******************************************************************************/
931 
ensGeneGetCurrent(const EnsPGene gene)932 AjBool ensGeneGetCurrent(const EnsPGene gene)
933 {
934     return (gene) ? gene->Current : ajFalse;
935 }
936 
937 
938 
939 
940 /* @func ensGeneGetDateCreation ***********************************************
941 **
942 ** Get the creation date member of an Ensembl Gene.
943 **
944 ** @cc Bio::EnsEMBL::Gene::created_date
945 ** @param [r] gene [const EnsPGene] Ensembl Gene
946 **
947 ** @return [AjPStr] Creation date or NULL
948 **
949 ** @release 6.4.0
950 ** @@
951 ******************************************************************************/
952 
ensGeneGetDateCreation(const EnsPGene gene)953 AjPStr ensGeneGetDateCreation(const EnsPGene gene)
954 {
955     return (gene) ? gene->DateCreation : NULL;
956 }
957 
958 
959 
960 
961 /* @func ensGeneGetDateModification *******************************************
962 **
963 ** Get the modification date member of an Ensembl Gene.
964 **
965 ** @cc Bio::EnsEMBL::Gene::modified_date
966 ** @param [r] gene [const EnsPGene] Ensembl Gene
967 **
968 ** @return [AjPStr] Modification date or NULL
969 **
970 ** @release 6.4.0
971 ** @@
972 ******************************************************************************/
973 
ensGeneGetDateModification(const EnsPGene gene)974 AjPStr ensGeneGetDateModification(const EnsPGene gene)
975 {
976     return (gene) ? gene->DateModification : NULL;
977 }
978 
979 
980 
981 
982 /* @func ensGeneGetDescription ************************************************
983 **
984 ** Get the description member of an Ensembl Gene.
985 **
986 ** @cc Bio::EnsEMBL::Gene::description
987 ** @param [r] gene [const EnsPGene] Ensembl Gene
988 **
989 ** @return [AjPStr] Description or NULL
990 **
991 ** @release 6.2.0
992 ** @@
993 ******************************************************************************/
994 
ensGeneGetDescription(const EnsPGene gene)995 AjPStr ensGeneGetDescription(const EnsPGene gene)
996 {
997     return (gene) ? gene->Description : NULL;
998 }
999 
1000 
1001 
1002 
1003 /* @func ensGeneGetDisplayreference *******************************************
1004 **
1005 ** Get the display reference member of an Ensembl Gene.
1006 **
1007 ** @cc Bio::EnsEMBL::Gene::display_xref
1008 ** @param [r] gene [const EnsPGene] Ensembl Gene
1009 **
1010 ** @return [EnsPDatabaseentry] Ensembl Database Entry or NULL
1011 **
1012 ** @release 6.4.0
1013 ** @@
1014 ******************************************************************************/
1015 
ensGeneGetDisplayreference(const EnsPGene gene)1016 EnsPDatabaseentry ensGeneGetDisplayreference(const EnsPGene gene)
1017 {
1018     return (gene) ? gene->Displayreference : NULL;
1019 }
1020 
1021 
1022 
1023 
1024 /* @func ensGeneGetFeature ****************************************************
1025 **
1026 ** Get the Ensembl Feature member of an Ensembl Gene.
1027 **
1028 ** @param [r] gene [const EnsPGene] Ensembl Gene
1029 **
1030 ** @return [EnsPFeature] Ensembl Feature or NULL
1031 **
1032 ** @release 6.2.0
1033 ** @@
1034 ******************************************************************************/
1035 
ensGeneGetFeature(const EnsPGene gene)1036 EnsPFeature ensGeneGetFeature(const EnsPGene gene)
1037 {
1038     return (gene) ? gene->Feature : NULL;
1039 }
1040 
1041 
1042 
1043 
1044 /* @func ensGeneGetIdentifier *************************************************
1045 **
1046 ** Get the SQL database-internal identifier member of an Ensembl Gene.
1047 **
1048 ** @cc Bio::EnsEMBL::Storable::dbID
1049 ** @param [r] gene [const EnsPGene] Ensembl Gene
1050 **
1051 ** @return [ajuint] SQL database-internal identifier or 0U
1052 **
1053 ** @release 6.2.0
1054 ** @@
1055 ******************************************************************************/
1056 
ensGeneGetIdentifier(const EnsPGene gene)1057 ajuint ensGeneGetIdentifier(const EnsPGene gene)
1058 {
1059     return (gene) ? gene->Identifier : 0U;
1060 }
1061 
1062 
1063 
1064 
1065 /* @func ensGeneGetSource *****************************************************
1066 **
1067 ** Get the source member of an Ensembl Gene.
1068 **
1069 ** @cc Bio::EnsEMBL::Gene::source
1070 ** @param [r] gene [const EnsPGene] Ensembl Gene
1071 **
1072 ** @return [AjPStr] Source or NULL
1073 **
1074 ** @release 6.2.0
1075 ** @@
1076 ******************************************************************************/
1077 
ensGeneGetSource(const EnsPGene gene)1078 AjPStr ensGeneGetSource(const EnsPGene gene)
1079 {
1080     return (gene) ? gene->Source : NULL;
1081 }
1082 
1083 
1084 
1085 
1086 /* @func ensGeneGetStableidentifier *******************************************
1087 **
1088 ** Get the stable identifier member of an Ensembl Gene.
1089 **
1090 ** @cc Bio::EnsEMBL::Gene::stable_id
1091 ** @param [r] gene [const EnsPGene] Ensembl Gene
1092 **
1093 ** @return [AjPStr] Stable identifier or NULL
1094 **
1095 ** @release 6.4.0
1096 ** @@
1097 ******************************************************************************/
1098 
ensGeneGetStableidentifier(const EnsPGene gene)1099 AjPStr ensGeneGetStableidentifier(const EnsPGene gene)
1100 {
1101     return (gene) ? gene->Stableidentifier : NULL;
1102 }
1103 
1104 
1105 
1106 
1107 /* @func ensGeneGetStatus *****************************************************
1108 **
1109 ** Get the status member of an Ensembl Gene.
1110 **
1111 ** @cc Bio::EnsEMBL::Gene::status
1112 ** @param [r] gene [const EnsPGene] Ensembl Gene
1113 **
1114 ** @return [EnsEGeneStatus] Status or ensEGeneStatusNULL
1115 **
1116 ** @release 6.2.0
1117 ** @@
1118 ******************************************************************************/
1119 
ensGeneGetStatus(const EnsPGene gene)1120 EnsEGeneStatus ensGeneGetStatus(const EnsPGene gene)
1121 {
1122     return (gene) ? gene->Status : ensEGeneStatusNULL;
1123 }
1124 
1125 
1126 
1127 
1128 /* @func ensGeneGetVersion ****************************************************
1129 **
1130 ** Get the version member of an Ensembl Gene.
1131 **
1132 ** @cc Bio::EnsEMBL::Gene::version
1133 ** @param [r] gene [const EnsPGene] Ensembl Gene
1134 **
1135 ** @return [ajuint] Version or 0U
1136 **
1137 ** @release 6.2.0
1138 ** @@
1139 ******************************************************************************/
1140 
ensGeneGetVersion(const EnsPGene gene)1141 ajuint ensGeneGetVersion(const EnsPGene gene)
1142 {
1143     return (gene) ? gene->Version : 0U;
1144 }
1145 
1146 
1147 
1148 
1149 /* @section load on demand ****************************************************
1150 **
1151 ** Functions for returning members of an Ensembl Gene object,
1152 ** which may need loading from an Ensembl SQL database on demand.
1153 **
1154 ** @fdata [EnsPGene]
1155 **
1156 ** @nam3rule Load Return Ensembl Gene attribute(s) loaded on demand
1157 ** @nam4rule Attributes Return all Ensembl Attribute objects
1158 ** @nam4rule Databaseentries Return all Ensembl Database Entry objects
1159 ** @nam4rule Transcripts Return all Ensembl Transcript objects
1160 **
1161 ** @argrule * gene [EnsPGene] Ensembl Gene
1162 **
1163 ** @valrule Attributes [const AjPList]
1164 ** AJAX List of Ensembl Attribute objects or NULL
1165 ** @valrule Databaseentries [const AjPList]
1166 ** AJAX List of Ensembl Database Entry objects or NULL
1167 ** @valrule Transcripts [const AjPList]
1168 ** AJAX List of Ensembl Transcript objects or NULL
1169 **
1170 ** @fcategory use
1171 ******************************************************************************/
1172 
1173 
1174 
1175 
1176 /* @func ensGeneLoadAttributes ************************************************
1177 **
1178 ** Load all Ensembl Attribute objects of an Ensembl Gene.
1179 **
1180 ** This is not a simple accessor function, it will fetch
1181 ** Ensembl Attribute objects from an Ensembl SQL database in case the
1182 ** AJAX List is not defined.
1183 **
1184 ** @cc Bio::EnsEMBL::Gene::get_all_Attributes
1185 ** @param [u] gene [EnsPGene] Ensembl Gene
1186 **
1187 ** @return [const AjPList] AJAX List of Ensembl Attribute objects or NULL
1188 **
1189 ** @release 6.4.0
1190 ** @@
1191 ******************************************************************************/
1192 
ensGeneLoadAttributes(EnsPGene gene)1193 const AjPList ensGeneLoadAttributes(EnsPGene gene)
1194 {
1195     EnsPDatabaseadaptor dba = NULL;
1196 
1197     if (!gene)
1198         return NULL;
1199 
1200     if (gene->Attributes)
1201         return gene->Attributes;
1202 
1203     if (!gene->Adaptor)
1204     {
1205         ajDebug("ensGeneLoadAttributes cannot fetch "
1206                 "Ensembl Attribute objects for an "
1207                 "Ensembl Gene without an "
1208                 "Ensembl Gene Adaptor.\n");
1209 
1210         return NULL;
1211     }
1212 
1213     dba = ensGeneadaptorGetDatabaseadaptor(gene->Adaptor);
1214 
1215     if (!dba)
1216     {
1217         ajDebug("ensGeneLoadAttributes cannot fetch "
1218                 "Ensembl Attribute objects for an "
1219                 "Ensembl Gene without an "
1220                 "Ensembl Database Adaptor set in the "
1221                 "Ensembl Gene Adaptor.\n");
1222 
1223         return NULL;
1224     }
1225 
1226     gene->Attributes = ajListNew();
1227 
1228     ensAttributeadaptorFetchAllbyGene(
1229         ensRegistryGetAttributeadaptor(dba),
1230         gene,
1231         (AjPStr) NULL,
1232         gene->Attributes);
1233 
1234     return gene->Attributes;
1235 }
1236 
1237 
1238 
1239 
1240 /* @func ensGeneLoadDatabaseentries *******************************************
1241 **
1242 ** Load all Ensembl Database Entry objects of an Ensembl Gene.
1243 **
1244 ** This is not a simple accessor function, it will fetch
1245 ** Ensembl Database Entry objects from an Ensembl SQL database in case the
1246 ** AJAX List is not defined.
1247 **
1248 ** @cc Bio::EnsEMBL::Gene::get_all_DBEntries
1249 ** @param [u] gene [EnsPGene] Ensembl Gene
1250 **
1251 ** @return [const AjPList] AJAX List of Ensembl Database Entry objects or NULL
1252 **
1253 ** @release 6.4.0
1254 ** @@
1255 ******************************************************************************/
1256 
ensGeneLoadDatabaseentries(EnsPGene gene)1257 const AjPList ensGeneLoadDatabaseentries(EnsPGene gene)
1258 {
1259     AjPStr objtype = NULL;
1260 
1261     EnsPDatabaseadaptor dba = NULL;
1262 
1263     if (!gene)
1264         return NULL;
1265 
1266     if (gene->Databaseentries)
1267         return gene->Databaseentries;
1268 
1269     if (!gene->Adaptor)
1270     {
1271         ajDebug("ensGeneLoadDatabaseentries cannot fetch "
1272                 "Ensembl Database Entry objects for an Ensembl Gene without "
1273                 "an Ensembl Gene Adaptor.\n");
1274 
1275         return NULL;
1276     }
1277 
1278     dba = ensGeneadaptorGetDatabaseadaptor(gene->Adaptor);
1279 
1280     if (!dba)
1281     {
1282         ajDebug("ensGeneLoadDatabaseentries cannot fetch "
1283                 "Ensembl Database Entry objects for an Ensembl Gene without "
1284                 "an Ensembl Database Adaptor set in the "
1285                 "Ensembl Gene Adaptor.\n");
1286 
1287         return NULL;
1288     }
1289 
1290     objtype = ajStrNewC("Gene");
1291 
1292     gene->Databaseentries = ajListNew();
1293 
1294     ensDatabaseentryadaptorFetchAllbyObject(
1295         ensRegistryGetDatabaseentryadaptor(dba),
1296         gene->Identifier,
1297         objtype,
1298         (AjPStr) NULL,
1299         ensEExternaldatabaseTypeNULL,
1300         gene->Databaseentries);
1301 
1302     ajStrDel(&objtype);
1303 
1304     return gene->Databaseentries;
1305 }
1306 
1307 
1308 
1309 
1310 /* @func ensGeneLoadTranscripts ***********************************************
1311 **
1312 ** Load all Ensembl Transcript objects of an Ensembl Gene.
1313 **
1314 ** This is not a simple accessor function, it will fetch
1315 ** Ensembl Transcript objects from an Ensembl SQL database in case the
1316 ** AJAX List is not defined.
1317 **
1318 ** @cc Bio::EnsEMBL::Gene::get_all_Transcripts
1319 ** @param [u] gene [EnsPGene] Ensembl Gene
1320 **
1321 ** @return [const AjPList] AJAX List of Ensembl Transcript objects or NULL
1322 **
1323 ** @release 6.4.0
1324 ** @@
1325 ******************************************************************************/
1326 
ensGeneLoadTranscripts(EnsPGene gene)1327 const AjPList ensGeneLoadTranscripts(EnsPGene gene)
1328 {
1329     EnsPDatabaseadaptor dba = NULL;
1330 
1331     if (!gene)
1332         return NULL;
1333 
1334     if (gene->Transcripts)
1335         return gene->Transcripts;
1336 
1337     if (!gene->Adaptor)
1338     {
1339         ajDebug("ensGeneLoadTranscripts cannot fetch "
1340                 "Ensembl Transcript objects for an Ensembl Gene without an "
1341                 "Ensembl Gene Adaptor.\n");
1342 
1343         return NULL;
1344     }
1345 
1346     dba = ensGeneadaptorGetDatabaseadaptor(gene->Adaptor);
1347 
1348     gene->Transcripts = ajListNew();
1349 
1350     ensTranscriptadaptorFetchAllbyGene(
1351         ensRegistryGetTranscriptadaptor(dba),
1352         gene,
1353         gene->Transcripts);
1354 
1355     return gene->Transcripts;
1356 }
1357 
1358 
1359 
1360 
1361 /* @section member assignment *************************************************
1362 **
1363 ** Functions for assigning members of an Ensembl Gene object.
1364 **
1365 ** @fdata [EnsPGene]
1366 **
1367 ** @nam3rule Set Set one member of a Gene
1368 ** @nam4rule Adaptor Set the Ensembl Gene Adaptor
1369 ** @nam4rule Biotype Set the biological type
1370 ** @nam4rule Canonicalannotation Set the canonical annotation
1371 ** @nam4rule Canonicaltranscriptidentifier
1372 ** Set the canonical Ensembl Transcript identifier
1373 ** @nam4rule Current Set the current attribute
1374 ** @nam4rule Date Set a date
1375 ** @nam5rule DateCreation Set the creation date
1376 ** @nam5rule DateModification Set the modification date
1377 ** @nam4rule Description Set the description
1378 ** @nam4rule Displayreference Set the Ensembl Database Entry
1379 ** @nam4rule Feature Set the Ensembl Feature
1380 ** @nam4rule Identifier Set the SQL database-internal identifier
1381 ** @nam4rule Source Set the source
1382 ** @nam4rule Stableidentifier Set the stable identifier
1383 ** @nam4rule Status Set the status
1384 ** @nam4rule Version Set the version
1385 **
1386 ** @argrule * gene [EnsPGene] Ensembl Gene object
1387 ** @argrule Adaptor ga [EnsPGeneadaptor] Ensembl Gene Adaptor
1388 ** @argrule Biotype biotype [AjPStr] Biological type
1389 ** @argrule Canonicalannotation canann [AjPStr] Canonical annotation
1390 ** @argrule Canonicaltranscriptidentifier cantrcid [ajuint]
1391 ** Canonical Ensembl Transcript identifier
1392 ** @argrule Current current [AjBool] Current attribute
1393 ** @argrule DateCreation cdate [AjPStr] Creation date
1394 ** @argrule DateModification mdate [AjPStr] Modification date
1395 ** @argrule Description description [AjPStr] Description
1396 ** @argrule Displayreference dbe [EnsPDatabaseentry] Ensembl Database Entry
1397 ** @argrule Feature feature [EnsPFeature] Ensembl Feature
1398 ** @argrule Identifier identifier [ajuint] SQL database-internal identifier
1399 ** @argrule Source source [AjPStr] Source
1400 ** @argrule Stableidentifier stableid [AjPStr] Stable identifier
1401 ** @argrule Status status [EnsEGeneStatus] Status
1402 ** @argrule Version version [ajuint] Version
1403 **
1404 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1405 **
1406 ** @fcategory modify
1407 ******************************************************************************/
1408 
1409 
1410 
1411 
1412 /* @func ensGeneSetAdaptor ****************************************************
1413 **
1414 ** Set the Ensembl Gene Adaptor member of an Ensembl Gene.
1415 **
1416 ** @cc Bio::EnsEMBL::Storable::adaptor
1417 ** @param [u] gene [EnsPGene] Ensembl Gene
1418 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
1419 **
1420 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1421 **
1422 ** @release 6.2.0
1423 ** @@
1424 ******************************************************************************/
1425 
ensGeneSetAdaptor(EnsPGene gene,EnsPGeneadaptor ga)1426 AjBool ensGeneSetAdaptor(EnsPGene gene, EnsPGeneadaptor ga)
1427 {
1428     if (!gene)
1429         return ajFalse;
1430 
1431     gene->Adaptor = ga;
1432 
1433     return ajTrue;
1434 }
1435 
1436 
1437 
1438 
1439 /* @func ensGeneSetBiotype ****************************************************
1440 **
1441 ** Set the biological type member of an Ensembl Gene.
1442 **
1443 ** @cc Bio::EnsEMBL::Gene::biotype
1444 ** @param [u] gene [EnsPGene] Ensembl Gene
1445 ** @param [u] biotype [AjPStr] Biological type
1446 **
1447 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1448 **
1449 ** @release 6.4.0
1450 ** @@
1451 ******************************************************************************/
1452 
ensGeneSetBiotype(EnsPGene gene,AjPStr biotype)1453 AjBool ensGeneSetBiotype(EnsPGene gene, AjPStr biotype)
1454 {
1455     if (!gene)
1456         return ajFalse;
1457 
1458     ajStrDel(&gene->Biotype);
1459 
1460     gene->Biotype = ajStrNewRef(biotype);
1461 
1462     return ajTrue;
1463 }
1464 
1465 
1466 
1467 
1468 /* @func ensGeneSetCanonicalannotation ****************************************
1469 **
1470 ** Set the canonical annotation member of an Ensembl Gene.
1471 **
1472 ** @cc Bio::EnsEMBL::Gene::canonical_annotation
1473 ** @param [u] gene [EnsPGene] Ensembl Gene
1474 ** @param [u] canann [AjPStr] Canonical annotation
1475 **
1476 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1477 **
1478 ** @release 6.4.0
1479 ** @@
1480 ******************************************************************************/
1481 
ensGeneSetCanonicalannotation(EnsPGene gene,AjPStr canann)1482 AjBool ensGeneSetCanonicalannotation(EnsPGene gene, AjPStr canann)
1483 {
1484     if (!gene)
1485         return ajFalse;
1486 
1487     ajStrDel(&gene->Canonicalannotation);
1488 
1489     gene->Canonicalannotation = ajStrNewRef(canann);
1490 
1491     return ajTrue;
1492 }
1493 
1494 
1495 
1496 
1497 /* @func ensGeneSetCanonicaltranscriptidentifier ******************************
1498 **
1499 ** Set the canonical Ensembl Transcript identifier member of an Ensembl Gene.
1500 **
1501 ** @cc Bio::EnsEMBL::Gene::canonical_transcript
1502 ** @param [u] gene [EnsPGene] Ensembl Gene
1503 ** @param [r] cantrcid [ajuint] Canonical Ensembl Transcript identifier
1504 **
1505 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1506 **
1507 ** @release 6.4.0
1508 ** @@
1509 ** NOTE: In this implementation, the Ensembl Gene only holds the identifier
1510 ** for the canonical Ensembl Transcript and not the object itself.
1511 ******************************************************************************/
1512 
ensGeneSetCanonicaltranscriptidentifier(EnsPGene gene,ajuint cantrcid)1513 AjBool ensGeneSetCanonicaltranscriptidentifier(EnsPGene gene, ajuint cantrcid)
1514 {
1515     AjBool match = AJFALSE;
1516 
1517     AjIList iter = NULL;
1518 
1519     EnsPTranscript transcript = NULL;
1520 
1521     if (!gene)
1522         return ajFalse;
1523 
1524     /*
1525     ** If Ensembl Transcript objects are available, check if the
1526     ** identifier matches one. The ensGeneLoadTranscripts function
1527     ** is no longer called explicitly.
1528     */
1529 
1530     if (gene->Transcripts)
1531     {
1532         iter = ajListIterNewread(gene->Transcripts);
1533 
1534         while (!ajListIterDone(iter))
1535         {
1536             transcript = (EnsPTranscript) ajListIterGet(iter);
1537 
1538             if (ensTranscriptGetIdentifier(transcript) ==
1539                 gene->Canonicaltranscriptidentifier)
1540                 ensTranscriptSetCanonical(transcript, ajFalse);
1541 
1542             if (ensTranscriptGetIdentifier(transcript) == cantrcid)
1543             {
1544                 ensTranscriptSetCanonical(transcript, ajTrue);
1545                 match = ajTrue;
1546                 break;
1547             }
1548         }
1549 
1550         ajListIterDel(&iter);
1551     }
1552 
1553     if (cantrcid == 0U)
1554         match = ajTrue;
1555 
1556     if (match == ajTrue)
1557         gene->Canonicaltranscriptidentifier = cantrcid;
1558 
1559     return match;
1560 }
1561 
1562 
1563 
1564 
1565 /* @func ensGeneSetCurrent ****************************************************
1566 **
1567 ** Set the current attribute of an Ensembl Gene.
1568 **
1569 ** @cc Bio::EnsEMBL::Gene::is_current
1570 ** @param [u] gene [EnsPGene] Ensembl Gene
1571 ** @param [r] current [AjBool] Current attribute
1572 **
1573 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1574 **
1575 ** @release 6.2.0
1576 ** @@
1577 ******************************************************************************/
1578 
ensGeneSetCurrent(EnsPGene gene,AjBool current)1579 AjBool ensGeneSetCurrent(EnsPGene gene, AjBool current)
1580 {
1581     if (!gene)
1582         return ajFalse;
1583 
1584     gene->Current = current;
1585 
1586     return ajTrue;
1587 }
1588 
1589 
1590 
1591 
1592 /* @func ensGeneSetDateCreation ***********************************************
1593 **
1594 ** Set the creation date member of an Ensembl Gene.
1595 **
1596 ** @cc Bio::EnsEMBL::Gene::created_date
1597 ** @param [u] gene [EnsPGene] Ensembl Gene
1598 ** @param [u] cdate [AjPStr] Creation date
1599 **
1600 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1601 **
1602 ** @release 6.4.0
1603 ** @@
1604 ******************************************************************************/
1605 
ensGeneSetDateCreation(EnsPGene gene,AjPStr cdate)1606 AjBool ensGeneSetDateCreation(EnsPGene gene, AjPStr cdate)
1607 {
1608     if (!gene)
1609         return ajFalse;
1610 
1611     ajStrDel(&gene->DateCreation);
1612 
1613     gene->DateCreation = ajStrNewRef(cdate);
1614 
1615     return ajTrue;
1616 }
1617 
1618 
1619 
1620 
1621 /* @func ensGeneSetDateModification *******************************************
1622 **
1623 ** Set the modification date member of an Ensembl Gene.
1624 **
1625 ** @cc Bio::EnsEMBL::Gene::modified_date
1626 ** @param [u] gene [EnsPGene] Ensembl Gene
1627 ** @param [u] mdate [AjPStr] Modification date
1628 **
1629 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1630 **
1631 ** @release 6.4.0
1632 ** @@
1633 ******************************************************************************/
1634 
ensGeneSetDateModification(EnsPGene gene,AjPStr mdate)1635 AjBool ensGeneSetDateModification(EnsPGene gene, AjPStr mdate)
1636 {
1637     if (!gene)
1638         return ajFalse;
1639 
1640     ajStrDel(&gene->DateModification);
1641 
1642     gene->DateModification = ajStrNewRef(mdate);
1643 
1644     return ajTrue;
1645 }
1646 
1647 
1648 
1649 
1650 /* @func ensGeneSetDescription ************************************************
1651 **
1652 ** Set the description member of an Ensembl Gene.
1653 **
1654 ** @cc Bio::EnsEMBL::Gene::description
1655 ** @param [u] gene [EnsPGene] Ensembl Gene
1656 ** @param [u] description [AjPStr] Description
1657 **
1658 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1659 **
1660 ** @release 6.2.0
1661 ** @@
1662 ******************************************************************************/
1663 
ensGeneSetDescription(EnsPGene gene,AjPStr description)1664 AjBool ensGeneSetDescription(EnsPGene gene, AjPStr description)
1665 {
1666     if (!gene)
1667         return ajFalse;
1668 
1669     ajStrDel(&gene->Description);
1670 
1671     gene->Description = ajStrNewRef(description);
1672 
1673     return ajTrue;
1674 }
1675 
1676 
1677 
1678 
1679 /* @func ensGeneSetDisplayreference *******************************************
1680 **
1681 ** Set the Ensembl Database Entry member of an Ensembl Gene.
1682 **
1683 ** @cc Bio::EnsEMBL::Gene::display_xref
1684 ** @param [u] gene [EnsPGene] Ensembl Gene
1685 ** @param [u] dbe [EnsPDatabaseentry] Ensembl Database Entry
1686 **
1687 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1688 **
1689 ** @release 6.4.0
1690 ** @@
1691 ******************************************************************************/
1692 
ensGeneSetDisplayreference(EnsPGene gene,EnsPDatabaseentry dbe)1693 AjBool ensGeneSetDisplayreference(EnsPGene gene, EnsPDatabaseentry dbe)
1694 {
1695     if (!gene)
1696         return ajFalse;
1697 
1698     ensDatabaseentryDel(&gene->Displayreference);
1699 
1700     gene->Displayreference = ensDatabaseentryNewRef(dbe);
1701 
1702     return ajTrue;
1703 }
1704 
1705 
1706 
1707 
1708 /* @func ensGeneSetFeature ****************************************************
1709 **
1710 ** Set the Ensembl Feature member of an Ensembl Gene.
1711 **
1712 ** @param [u] gene [EnsPGene] Ensembl Gene
1713 ** @param [u] feature [EnsPFeature] Ensembl Feature
1714 **
1715 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1716 **
1717 ** @release 6.2.0
1718 ** @@
1719 ******************************************************************************/
1720 
ensGeneSetFeature(EnsPGene gene,EnsPFeature feature)1721 AjBool ensGeneSetFeature(EnsPGene gene, EnsPFeature feature)
1722 {
1723     AjIList iter = NULL;
1724 
1725     EnsPSlice slice = NULL;
1726 
1727     EnsPTranscript oldtranscript = NULL;
1728     EnsPTranscript newtranscript = NULL;
1729 
1730     if (ajDebugTest("ensGeneSetFeature"))
1731         ajDebug("ensGeneSetFeature\n"
1732                 "  gene %p\n"
1733                 "  feature %p\n",
1734                 gene,
1735                 feature);
1736 
1737     if (!gene)
1738         return ajFalse;
1739 
1740     if (!feature)
1741         return ajFalse;
1742 
1743     /* Replace the current Feature. */
1744 
1745     ensFeatureDel(&gene->Feature);
1746 
1747     gene->Feature = ensFeatureNewRef(feature);
1748 
1749     slice = ensFeatureGetSlice(gene->Feature);
1750 
1751     /* Transfer the Ensembl Transcript objects onto the new Ensembl Slice. */
1752 
1753     iter = ajListIterNew(gene->Transcripts);
1754 
1755     while (!ajListIterDone(iter))
1756     {
1757         oldtranscript = (EnsPTranscript) ajListIterGet(iter);
1758 
1759         ajListIterRemove(iter);
1760 
1761         newtranscript = ensTranscriptTransfer(oldtranscript, slice);
1762 
1763         if (!newtranscript)
1764         {
1765             ajDebug("ensGeneSetFeature could not transfer "
1766                     "Transcript onto new Ensembl Feature Slice.");
1767 
1768             ensTranscriptTrace(oldtranscript, 1);
1769         }
1770 
1771         ajListIterInsert(iter, (void *) newtranscript);
1772 
1773         /* Advance the AJAX List Iterator after the insert. */
1774 
1775         (void) ajListIterGet(iter);
1776 
1777         ensTranscriptDel(&oldtranscript);
1778     }
1779 
1780     ajListIterDel(&iter);
1781 
1782     return ajTrue;
1783 }
1784 
1785 
1786 
1787 
1788 /* @func ensGeneSetIdentifier *************************************************
1789 **
1790 ** Set the SQL database-internal identifier member of an Ensembl Gene.
1791 **
1792 ** @cc Bio::EnsEMBL::Storable::dbID
1793 ** @param [u] gene [EnsPGene] Ensembl Gene
1794 ** @param [r] identifier [ajuint] SQL database-internal identifier
1795 **
1796 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1797 **
1798 ** @release 6.2.0
1799 ** @@
1800 ******************************************************************************/
1801 
ensGeneSetIdentifier(EnsPGene gene,ajuint identifier)1802 AjBool ensGeneSetIdentifier(EnsPGene gene, ajuint identifier)
1803 {
1804     if (!gene)
1805         return ajFalse;
1806 
1807     gene->Identifier = identifier;
1808 
1809     return ajTrue;
1810 }
1811 
1812 
1813 
1814 
1815 /* @func ensGeneSetSource *****************************************************
1816 **
1817 ** Set the source member of an Ensembl Gene.
1818 **
1819 ** @cc Bio::EnsEMBL::Gene::source
1820 ** @param [u] gene [EnsPGene] Ensembl Gene
1821 ** @param [u] source [AjPStr] Source
1822 **
1823 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1824 **
1825 ** @release 6.2.0
1826 ** @@
1827 ******************************************************************************/
1828 
ensGeneSetSource(EnsPGene gene,AjPStr source)1829 AjBool ensGeneSetSource(EnsPGene gene, AjPStr source)
1830 {
1831     if (!gene)
1832         return ajFalse;
1833 
1834     ajStrDel(&gene->Source);
1835 
1836     gene->Source = ajStrNewRef(source);
1837 
1838     return ajTrue;
1839 }
1840 
1841 
1842 
1843 
1844 /* @func ensGeneSetStableidentifier *******************************************
1845 **
1846 ** Set the stable identifier member of an Ensembl Gene.
1847 **
1848 ** @cc Bio::EnsEMBL::Gene::stable_id
1849 ** @param [u] gene [EnsPGene] Ensembl Gene
1850 ** @param [u] stableid [AjPStr] Stable identifier
1851 **
1852 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1853 **
1854 ** @release 6.4.0
1855 ** @@
1856 ******************************************************************************/
1857 
ensGeneSetStableidentifier(EnsPGene gene,AjPStr stableid)1858 AjBool ensGeneSetStableidentifier(EnsPGene gene, AjPStr stableid)
1859 {
1860     if (!gene)
1861         return ajFalse;
1862 
1863     ajStrDel(&gene->Stableidentifier);
1864 
1865     gene->Stableidentifier = ajStrNewRef(stableid);
1866 
1867     return ajTrue;
1868 }
1869 
1870 
1871 
1872 
1873 /* @func ensGeneSetStatus *****************************************************
1874 **
1875 ** Set the status member of an Ensembl Gene.
1876 **
1877 ** @cc Bio::EnsEMBL::Gene::status
1878 ** @param [u] gene [EnsPGene] Ensembl Gene
1879 ** @param [u] status [EnsEGeneStatus] Status
1880 **
1881 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1882 **
1883 ** @release 6.2.0
1884 ** @@
1885 ******************************************************************************/
1886 
ensGeneSetStatus(EnsPGene gene,EnsEGeneStatus status)1887 AjBool ensGeneSetStatus(EnsPGene gene, EnsEGeneStatus status)
1888 {
1889     if (!gene)
1890         return ajFalse;
1891 
1892     gene->Status = status;
1893 
1894     return ajTrue;
1895 }
1896 
1897 
1898 
1899 
1900 /* @func ensGeneSetVersion ****************************************************
1901 **
1902 ** Set the version member of an Ensembl Gene.
1903 **
1904 ** @cc Bio::EnsEMBL::Gene::version
1905 ** @param [u] gene [EnsPGene] Ensembl Gene
1906 ** @param [r] version [ajuint] Version
1907 **
1908 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1909 **
1910 ** @release 6.2.0
1911 ** @@
1912 ******************************************************************************/
1913 
ensGeneSetVersion(EnsPGene gene,ajuint version)1914 AjBool ensGeneSetVersion(EnsPGene gene, ajuint version)
1915 {
1916     if (!gene)
1917         return ajFalse;
1918 
1919     gene->Version = version;
1920 
1921     return ajTrue;
1922 }
1923 
1924 
1925 
1926 
1927 /* @section member addition ***************************************************
1928 **
1929 ** Functions for adding members to an Ensembl Gene object.
1930 **
1931 ** @fdata [EnsPGene]
1932 **
1933 ** @nam3rule Add Add one object to an Ensembl Gene
1934 ** @nam4rule Attribute Add an Ensembl Attribute
1935 ** @nam4rule Databaseentry Add an Ensembl Database Entry
1936 ** @nam4rule Transcript Add an Ensembl Transcript
1937 **
1938 ** @argrule * gene [EnsPGene] Ensembl Gene object
1939 ** @argrule Attribute attribute [EnsPAttribute] Ensembl Attribute
1940 ** @argrule Databaseentry dbe [EnsPDatabaseentry] Ensembl Database Entry
1941 ** @argrule Transcript transcript [EnsPTranscript] Ensembl Transcript
1942 **
1943 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1944 **
1945 ** @fcategory modify
1946 ******************************************************************************/
1947 
1948 
1949 
1950 
1951 /* @func ensGeneAddAttribute **************************************************
1952 **
1953 ** Add an Ensembl Attribute to an Ensembl Gene.
1954 **
1955 ** @cc Bio::EnsEMBL::Gene::add_Attributes
1956 ** @param [u] gene [EnsPGene] Ensembl Gene
1957 ** @param [u] attribute [EnsPAttribute] Ensembl Attribute
1958 **
1959 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1960 **
1961 ** @release 6.2.0
1962 ** @@
1963 ******************************************************************************/
1964 
ensGeneAddAttribute(EnsPGene gene,EnsPAttribute attribute)1965 AjBool ensGeneAddAttribute(EnsPGene gene, EnsPAttribute attribute)
1966 {
1967     if (!gene)
1968         return ajFalse;
1969 
1970     if (!attribute)
1971         return ajFalse;
1972 
1973     if (!gene->Attributes)
1974         gene->Attributes = ajListNew();
1975 
1976     ajListPushAppend(gene->Attributes, (void *) ensAttributeNewRef(attribute));
1977 
1978     return ajTrue;
1979 }
1980 
1981 
1982 
1983 
1984 /* @func ensGeneAddDatabaseentry **********************************************
1985 **
1986 ** Add an Ensembl Database Entry to an Ensembl Gene.
1987 **
1988 ** @cc Bio::EnsEMBL::Gene::add_DBEntry
1989 ** @param [u] gene [EnsPGene] Ensembl Gene
1990 ** @param [u] dbe [EnsPDatabaseentry] Ensembl Database Entry
1991 **
1992 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1993 **
1994 ** @release 6.2.0
1995 ** @@
1996 ******************************************************************************/
1997 
ensGeneAddDatabaseentry(EnsPGene gene,EnsPDatabaseentry dbe)1998 AjBool ensGeneAddDatabaseentry(EnsPGene gene, EnsPDatabaseentry dbe)
1999 {
2000     if (!gene)
2001         return ajFalse;
2002 
2003     if (!dbe)
2004         return ajFalse;
2005 
2006     if (!gene->Databaseentries)
2007         gene->Databaseentries = ajListNew();
2008 
2009     ajListPushAppend(gene->Databaseentries,
2010                      (void *) ensDatabaseentryNewRef(dbe));
2011 
2012     return ajTrue;
2013 }
2014 
2015 
2016 
2017 
2018 /* @func ensGeneAddTranscript *************************************************
2019 **
2020 ** Add an Ensembl Transcript to an Ensembl Gene.
2021 ** This will also re-calculate gene coordinates.
2022 **
2023 ** @cc Bio::EnsEMBL::Gene::add_Transcript
2024 ** @param [u] gene [EnsPGene] Ensembl Gene
2025 ** @param [u] transcript [EnsPTranscript] Ensembl Transcript
2026 **
2027 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2028 **
2029 ** @release 6.2.0
2030 ** @@
2031 ******************************************************************************/
2032 
ensGeneAddTranscript(EnsPGene gene,EnsPTranscript transcript)2033 AjBool ensGeneAddTranscript(EnsPGene gene, EnsPTranscript transcript)
2034 {
2035     if (!gene)
2036         return ajFalse;
2037 
2038     if (!transcript)
2039         return ajFalse;
2040 
2041     if (!gene->Transcripts)
2042         gene->Transcripts = ajListNew();
2043 
2044     ajListPushAppend(gene->Transcripts,
2045                      (void *) ensTranscriptNewRef(transcript));
2046 
2047     ensGeneCalculateCoordinates(gene);
2048 
2049     return ajTrue;
2050 }
2051 
2052 
2053 
2054 
2055 /* @section debugging *********************************************************
2056 **
2057 ** Functions for reporting of an Ensembl Gene object.
2058 **
2059 ** @fdata [EnsPGene]
2060 **
2061 ** @nam3rule Trace Report Ensembl Gene members to debug file
2062 **
2063 ** @argrule Trace gene [const EnsPGene] Ensembl Gene
2064 ** @argrule Trace level [ajuint] Indentation level
2065 **
2066 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2067 **
2068 ** @fcategory misc
2069 ******************************************************************************/
2070 
2071 
2072 
2073 
2074 /* @func ensGeneTrace *********************************************************
2075 **
2076 ** Trace an Ensembl Gene.
2077 **
2078 ** @param [r] gene [const EnsPGene] Ensembl Gene
2079 ** @param [r] level [ajuint] Indentation level
2080 **
2081 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2082 **
2083 ** @release 6.2.0
2084 ** @@
2085 ******************************************************************************/
2086 
ensGeneTrace(const EnsPGene gene,ajuint level)2087 AjBool ensGeneTrace(const EnsPGene gene, ajuint level)
2088 {
2089     AjIList iter = NULL;
2090 
2091     AjPStr indent = NULL;
2092 
2093     EnsPAttribute attribute = NULL;
2094 
2095     EnsPDatabaseentry dbe = NULL;
2096 
2097     EnsPTranscript transcript = NULL;
2098 
2099     if (!gene)
2100         return ajFalse;
2101 
2102     indent = ajStrNew();
2103 
2104     ajStrAppendCountK(&indent, ' ', level * 2);
2105 
2106     ajDebug("%SensGeneTrace %p\n"
2107             "%S  Use %u\n"
2108             "%S  Identifier %u\n"
2109             "%S  Adaptor %p\n"
2110             "%S  Feature %p\n"
2111             "%S  Displayreference %p\n"
2112             "%S  Description '%S'\n"
2113             "%S  Source '%S'\n"
2114             "%S  Biotype '%S'\n"
2115             "%S  Status '%s'\n"
2116             "%S  Current '%B'\n"
2117             "%S  Canonicalannotation '%S'\n"
2118             "%S  Canonicaltranscriptidentifier %u\n"
2119             "%S  Stableidentifier '%S'\n"
2120             "%S  DateCreation '%S'\n"
2121             "%S  DateModification '%S'\n"
2122             "%S  Version %u\n"
2123             "%S  Attributes %p\n"
2124             "%S  Databaseentries %p\n"
2125             "%S  Transcripts %p\n",
2126             indent, gene,
2127             indent, gene->Use,
2128             indent, gene->Identifier,
2129             indent, gene->Adaptor,
2130             indent, gene->Feature,
2131             indent, gene->Displayreference,
2132             indent, gene->Description,
2133             indent, gene->Source,
2134             indent, gene->Biotype,
2135             indent, ensGeneStatusToChar(gene->Status),
2136             indent, gene->Current,
2137             indent, gene->Canonicalannotation,
2138             indent, gene->Canonicaltranscriptidentifier,
2139             indent, gene->Stableidentifier,
2140             indent, gene->DateCreation,
2141             indent, gene->DateModification,
2142             indent, gene->Version,
2143             indent, gene->Attributes,
2144             indent, gene->Databaseentries,
2145             indent, gene->Transcripts);
2146 
2147     ensFeatureTrace(gene->Feature, level + 1);
2148 
2149     ensDatabaseentryTrace(gene->Displayreference, level + 1);
2150 
2151     /* Trace the AJAX List of Ensembl Attribute objects. */
2152 
2153     if (gene->Attributes)
2154     {
2155         ajDebug("%S    AJAX List %p of Ensembl Attribute objects\n",
2156                 indent, gene->Attributes);
2157 
2158         iter = ajListIterNewread(gene->Attributes);
2159 
2160         while (!ajListIterDone(iter))
2161         {
2162             attribute = (EnsPAttribute) ajListIterGet(iter);
2163 
2164             ensAttributeTrace(attribute, level + 2);
2165         }
2166 
2167         ajListIterDel(&iter);
2168     }
2169 
2170     /* Trace the AJAX List of Ensembl Database Entry objects. */
2171 
2172     if (gene->Databaseentries)
2173     {
2174         ajDebug("%S    AJAX List %p of Ensembl Database Entry objects\n",
2175                 indent, gene->Databaseentries);
2176 
2177         iter = ajListIterNewread(gene->Databaseentries);
2178 
2179         while (!ajListIterDone(iter))
2180         {
2181             dbe = (EnsPDatabaseentry) ajListIterGet(iter);
2182 
2183             ensDatabaseentryTrace(dbe, level + 2);
2184         }
2185 
2186         ajListIterDel(&iter);
2187     }
2188 
2189     /* Trace the AJAX List of Ensembl Transcript objects. */
2190 
2191     if (gene->Transcripts)
2192     {
2193         ajDebug("%S    AJAX List %p of Ensembl Transcript objects\n",
2194                 indent, gene->Transcripts);
2195 
2196         iter = ajListIterNewread(gene->Transcripts);
2197 
2198         while (!ajListIterDone(iter))
2199         {
2200             transcript = (EnsPTranscript) ajListIterGet(iter);
2201 
2202             ensTranscriptTrace(transcript, level + 2);
2203         }
2204 
2205         ajListIterDel(&iter);
2206     }
2207 
2208     ajStrDel(&indent);
2209 
2210     return ajTrue;
2211 }
2212 
2213 
2214 
2215 
2216 /* @section calculate *********************************************************
2217 **
2218 ** Functions for calculating information from an Ensembl Gene object.
2219 **
2220 ** @fdata [EnsPGene]
2221 **
2222 ** @nam3rule Calculate Calculate Ensembl Gene information
2223 ** @nam4rule Coordinates Calculate coordinates
2224 ** @nam4rule Memsize Calculate the memory size in bytes
2225 **
2226 ** @argrule Coordinates gene [EnsPGene] Ensembl Gene
2227 ** @argrule Memsize gene [const EnsPGene] Ensembl Gene
2228 **
2229 ** @valrule Coordinates [AjBool] ajTrue upon success, ajFalse otherwise
2230 ** @valrule Memsize [size_t] Memory size in bytes or 0
2231 **
2232 ** @fcategory misc
2233 ******************************************************************************/
2234 
2235 
2236 
2237 
2238 /* @func ensGeneCalculateCoordinates ******************************************
2239 **
2240 ** Calculate coordinates of an Ensembl Gene.
2241 ** This function should be called, whenever a Transcript of this Gene has
2242 ** been changed.
2243 **
2244 ** @cc Bio::EnsEMBL::Gene::recalculate_coordinates
2245 ** @param [u] gene [EnsPGene] Ensembl Gene
2246 **
2247 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2248 **
2249 ** @release 6.2.0
2250 ** @@
2251 ******************************************************************************/
2252 
ensGeneCalculateCoordinates(EnsPGene gene)2253 AjBool ensGeneCalculateCoordinates(EnsPGene gene)
2254 {
2255     ajint start = 0;
2256     ajint end = 0;
2257     ajint strand = 0;
2258 
2259     AjBool transsplicing = AJFALSE;
2260 
2261     AjIList iter = NULL;
2262     const AjPList list = NULL;
2263 
2264     EnsPFeature gfeature = NULL;
2265     EnsPFeature tfeature = NULL;
2266 
2267     EnsPSlice slice = NULL;
2268 
2269     EnsPTranscript transcript = NULL;
2270 
2271     if (!gene)
2272         return ajFalse;
2273 
2274     list = ensGeneLoadTranscripts(gene);
2275 
2276     if (!ajListGetLength(list))
2277         return ajTrue;
2278 
2279     /* Get the first Transcript with coordinates. */
2280 
2281     iter = ajListIterNewread(list);
2282 
2283     while (!ajListIterDone(iter))
2284     {
2285         transcript = (EnsPTranscript) ajListIterGet(iter);
2286 
2287         /* Skip missing Ensembl Transcript objects. */
2288 
2289         if (!transcript)
2290             continue;
2291 
2292         tfeature = ensTranscriptGetFeature(transcript);
2293 
2294         /* Skip un-mapped Ensembl Transcript objects. */
2295 
2296         if (!ensFeatureGetStart(tfeature))
2297             continue;
2298 
2299         slice = ensFeatureGetSlice(tfeature);
2300 
2301         start = ensFeatureGetStart(tfeature);
2302 
2303         end = ensFeatureGetEnd(tfeature);
2304 
2305         strand = ensFeatureGetStrand(tfeature);
2306 
2307         break;
2308     }
2309 
2310     ajListIterDel(&iter);
2311 
2312     /* Start loop after the first Transcript with coordinates. */
2313 
2314     iter = ajListIterNewread(list);
2315 
2316     while (!ajListIterDone(iter))
2317     {
2318         transcript = (EnsPTranscript) ajListIterGet(iter);
2319 
2320         /* Skip missing Ensembl Transcript objects. */
2321 
2322         if (!transcript)
2323             continue;
2324 
2325         tfeature = ensTranscriptGetFeature(transcript);
2326 
2327         /* Skip un-mapped Ensembl Transcript objects. */
2328 
2329         if (!ensFeatureGetStart(tfeature))
2330             continue;
2331 
2332         if (!ensSliceMatch(ensFeatureGetSlice(tfeature), slice))
2333             ajFatal("ensGeneCalculateCoordinates got "
2334                     "Ensembl Transcript objects of one Ensembl Gene on "
2335                     "different Ensembl Slice objects.\n");
2336 
2337         start = (ensFeatureGetStart(tfeature) < start) ?
2338             ensFeatureGetStart(tfeature) :
2339             start;
2340 
2341         end = (ensFeatureGetEnd(tfeature) > end) ?
2342             ensFeatureGetEnd(tfeature) :
2343             end;
2344 
2345         if (ensFeatureGetStrand(tfeature) != strand)
2346             transsplicing = ajTrue;
2347     }
2348 
2349     ajListIterDel(&iter);
2350 
2351     if (transsplicing)
2352         ajWarn("ensGeneCalculateCoordinates got an Ensembl Gene suggesting "
2353                "a trans-splicing event.\n");
2354 
2355     gfeature = ensGeneGetFeature(gene);
2356 
2357     ensFeatureSetStart(gfeature, start);
2358 
2359     ensFeatureSetEnd(gfeature, end);
2360 
2361     ensFeatureSetStrand(gfeature, strand);
2362 
2363     ensFeatureSetSlice(gfeature, slice);
2364 
2365     /* Clear internal members that depend on Transcript coordinates. None! */
2366 
2367     return ajTrue;
2368 }
2369 
2370 
2371 
2372 
2373 /* @func ensGeneCalculateMemsize **********************************************
2374 **
2375 ** Calculate the memory size in bytes of an Ensembl Gene.
2376 **
2377 ** @param [r] gene [const EnsPGene] Ensembl Gene
2378 **
2379 ** @return [size_t] Memory size in bytes or 0
2380 **
2381 ** @release 6.4.0
2382 ** @@
2383 ******************************************************************************/
2384 
ensGeneCalculateMemsize(const EnsPGene gene)2385 size_t ensGeneCalculateMemsize(const EnsPGene gene)
2386 {
2387     size_t size = 0;
2388 
2389     AjIList iter = NULL;
2390 
2391     EnsPAttribute attribute = NULL;
2392 
2393     EnsPDatabaseentry dbe = NULL;
2394 
2395     EnsPTranscript transcript = NULL;
2396 
2397     if (!gene)
2398         return 0;
2399 
2400     size += sizeof (EnsOGene);
2401 
2402     size += ensFeatureCalculateMemsize(gene->Feature);
2403 
2404     size += ensDatabaseentryCalculateMemsize(gene->Displayreference);
2405 
2406     if (gene->Description)
2407     {
2408         size += sizeof (AjOStr);
2409 
2410         size += ajStrGetRes(gene->Description);
2411     }
2412 
2413     if (gene->Source)
2414     {
2415         size += sizeof (AjOStr);
2416 
2417         size += ajStrGetRes(gene->Source);
2418     }
2419 
2420     if (gene->Biotype)
2421     {
2422         size += sizeof (AjOStr);
2423 
2424         size += ajStrGetRes(gene->Biotype);
2425     }
2426 
2427     if (gene->Canonicalannotation)
2428     {
2429         size += sizeof (AjOStr);
2430 
2431         size += ajStrGetRes(gene->Canonicalannotation);
2432     }
2433 
2434     if (gene->Stableidentifier)
2435     {
2436         size += sizeof (AjOStr);
2437 
2438         size += ajStrGetRes(gene->Stableidentifier);
2439     }
2440 
2441     if (gene->DateCreation)
2442     {
2443         size += sizeof (AjOStr);
2444 
2445         size += ajStrGetRes(gene->DateCreation);
2446     }
2447 
2448     if (gene->DateModification)
2449     {
2450         size += sizeof (AjOStr);
2451 
2452         size += ajStrGetRes(gene->DateModification);
2453     }
2454 
2455     /* Summarise the AJAX List of Ensembl Attribute objects. */
2456 
2457     if (gene->Attributes)
2458     {
2459         size += sizeof (AjOList);
2460 
2461         iter = ajListIterNewread(gene->Attributes);
2462 
2463         while (!ajListIterDone(iter))
2464         {
2465             attribute = (EnsPAttribute) ajListIterGet(iter);
2466 
2467             size += ensAttributeCalculateMemsize(attribute);
2468         }
2469 
2470         ajListIterDel(&iter);
2471     }
2472 
2473     /* Summarise the AJAX List of Ensembl Database Entry objects. */
2474 
2475     if (gene->Databaseentries)
2476     {
2477         size += sizeof (AjOList);
2478 
2479         iter = ajListIterNewread(gene->Databaseentries);
2480 
2481         while (!ajListIterDone(iter))
2482         {
2483             dbe = (EnsPDatabaseentry) ajListIterGet(iter);
2484 
2485             size += ensDatabaseentryCalculateMemsize(dbe);
2486         }
2487 
2488         ajListIterDel(&iter);
2489     }
2490 
2491     /* Summarise the AJAX List of Ensembl Transcript objects. */
2492 
2493     if (gene->Transcripts)
2494     {
2495         size += sizeof (AjOList);
2496 
2497         iter = ajListIterNewread(gene->Transcripts);
2498 
2499         while (!ajListIterDone(iter))
2500         {
2501             transcript = (EnsPTranscript) ajListIterGet(iter);
2502 
2503             size += ensTranscriptCalculateMemsize(transcript);
2504         }
2505 
2506         ajListIterDel(&iter);
2507     }
2508 
2509     return size;
2510 }
2511 
2512 
2513 
2514 
2515 /* @section fetch *************************************************************
2516 **
2517 ** Functions for fetching information from an Ensembl Gene object.
2518 **
2519 ** @fdata [EnsPGene]
2520 **
2521 ** @nam3rule Fetch Fetch Ensembl Gene information
2522 ** @nam4rule All Fetch all objects
2523 ** @nam5rule Attributes Fetch all Ensembl Attribute objects
2524 ** @nam5rule Databaseentries Fetch all Ensembl Database Entry objects
2525 ** @nam5rule Exons Fetch all Ensembl Exon objects
2526 ** @nam4rule Canonicaltranscript Fetch the canonical Ensembl Transcript
2527 ** @nam4rule Displayidentifier Fetch the display identifier
2528 **
2529 ** @argrule AllAttributes gene [EnsPGene] Ensembl Gene
2530 ** @argrule AllAttributes code [const AjPStr] Ensembl Attribute code
2531 ** @argrule AllAttributes attributes [AjPList]
2532 ** AJAX List of Ensembl Attribute objects
2533 ** @argrule AllDatabaseentries gene [EnsPGene] Ensembl Gene
2534 ** @argrule AllDatabaseentries name [const AjPStr]
2535 ** Ensembl External Database name
2536 ** @argrule AllDatabaseentries type [EnsEExternaldatabaseType]
2537 ** Ensembl External Database type
2538 ** @argrule AllDatabaseentries dbes [AjPList]
2539 ** AJAX List of Ensembl Database Entry objects
2540 ** @argrule AllExons gene [EnsPGene] Ensembl Gene
2541 ** @argrule AllExons exons [AjPList] AJAX List of Ensembl Exon objects
2542 ** @argrule Canonicaltranscript gene [EnsPGene] Ensembl Gene
2543 ** @argrule Canonicaltranscript Ptranscript [EnsPTranscript*]
2544 ** Ensembl Transcript address
2545 ** @argrule Displayidentifier gene [const EnsPGene] Ensembl Gene
2546 ** @argrule Displayidentifier Pidentifier [AjPStr*] AJAX String address
2547 **
2548 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2549 **
2550 ** @fcategory misc
2551 ******************************************************************************/
2552 
2553 
2554 
2555 
2556 /* @func ensGeneFetchAllAttributes ********************************************
2557 **
2558 ** Fetch all Ensembl Attribute objects of an Ensembl Gene.
2559 **
2560 ** @cc Bio::EnsEMBL::Gene::get_all_Attributes
2561 ** @param [u] gene [EnsPGene] Ensembl Gene
2562 ** @param [r] code [const AjPStr] Ensembl Attribute code
2563 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
2564 **
2565 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2566 **
2567 ** @release 6.2.0
2568 ** @@
2569 ******************************************************************************/
2570 
ensGeneFetchAllAttributes(EnsPGene gene,const AjPStr code,AjPList attributes)2571 AjBool ensGeneFetchAllAttributes(EnsPGene gene,
2572                                  const AjPStr code,
2573                                  AjPList attributes)
2574 {
2575     AjBool match = AJFALSE;
2576 
2577     const AjPList list = NULL;
2578     AjIList iter = NULL;
2579 
2580     EnsPAttribute attribute = NULL;
2581 
2582     if (!gene)
2583         return ajFalse;
2584 
2585     if (!attributes)
2586         return ajFalse;
2587 
2588     list = ensGeneLoadAttributes(gene);
2589 
2590     iter = ajListIterNewread(list);
2591 
2592     while (!ajListIterDone(iter))
2593     {
2594         attribute = (EnsPAttribute) ajListIterGet(iter);
2595 
2596         if (code)
2597         {
2598             if (ajStrMatchCaseS(code, ensAttributeGetCode(attribute)))
2599                 match = ajTrue;
2600             else
2601                 match = ajFalse;
2602         }
2603         else
2604             match = ajTrue;
2605 
2606         if (match)
2607             ajListPushAppend(attributes,
2608                              (void *) ensAttributeNewRef(attribute));
2609     }
2610 
2611     ajListIterDel(&iter);
2612 
2613     return ajTrue;
2614 }
2615 
2616 
2617 
2618 
2619 /* @func ensGeneFetchAllDatabaseentries ***************************************
2620 **
2621 ** Fetch all Ensembl Database Entry objects of an Ensembl Gene.
2622 **
2623 ** @cc Bio::EnsEMBL::Gene::get_all_DBEntries
2624 ** @param [u] gene [EnsPGene] Ensembl Gene
2625 ** @param [r] name [const AjPStr] Ensembl External Database name
2626 ** @param [u] type [EnsEExternaldatabaseType] Ensembl External Database type
2627 ** @param [u] dbes [AjPList] AJAX List of Ensembl Database Entry objects
2628 **
2629 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2630 **
2631 ** @release 6.4.0
2632 ** @@
2633 ******************************************************************************/
2634 
ensGeneFetchAllDatabaseentries(EnsPGene gene,const AjPStr name,EnsEExternaldatabaseType type,AjPList dbes)2635 AjBool ensGeneFetchAllDatabaseentries(EnsPGene gene,
2636                                       const AjPStr name,
2637                                       EnsEExternaldatabaseType type,
2638                                       AjPList dbes)
2639 {
2640     AjBool namematch = AJFALSE;
2641     AjBool typematch = AJFALSE;
2642 
2643     const AjPList list = NULL;
2644     AjIList iter       = NULL;
2645 
2646     EnsPDatabaseentry dbe = NULL;
2647 
2648     if (!gene)
2649         return ajFalse;
2650 
2651     if (!dbes)
2652         return ajFalse;
2653 
2654     list = ensGeneLoadDatabaseentries(gene);
2655 
2656     iter = ajListIterNewread(list);
2657 
2658     while (!ajListIterDone(iter))
2659     {
2660         dbe = (EnsPDatabaseentry) ajListIterGet(iter);
2661 
2662         if (name)
2663         {
2664             if (ajStrMatchCaseS(name, ensDatabaseentryGetDbName(dbe)))
2665                 namematch = ajTrue;
2666             else
2667                 namematch = ajFalse;
2668         }
2669         else
2670             namematch = ajTrue;
2671 
2672         if (type)
2673         {
2674             if (type == ensDatabaseentryGetType(dbe))
2675                 typematch = ajTrue;
2676             else
2677                 typematch = ajFalse;
2678         }
2679         else
2680             typematch = ajTrue;
2681 
2682         if (namematch && typematch)
2683             ajListPushAppend(dbes, (void *) ensDatabaseentryNewRef(dbe));
2684     }
2685 
2686     ajListIterDel(&iter);
2687 
2688     return ajTrue;
2689 }
2690 
2691 
2692 
2693 
2694 /* @funcstatic listExonCompareAddressAscending ********************************
2695 **
2696 ** Comparison function to sort Ensembl Exon objects via their address in
2697 ** ascending order. For identical Exon objects at separate addresses, which are
2698 ** matched via ensExonMatch 0 is returned.
2699 **
2700 ** @param [r] item1 [const void*] Ensembl Exon 1
2701 ** @param [r] item2 [const void*] Ensembl Exon 2
2702 ** @see ajListSortUnique
2703 **
2704 ** @return [int] The comparison function returns an integer less than,
2705 **               equal to, or greater than zero if the first argument is
2706 **               considered to be respectively less than, equal to, or
2707 **               greater than the second.
2708 **
2709 ** @release 6.2.0
2710 ** @@
2711 ******************************************************************************/
2712 
listExonCompareAddressAscending(const void * item1,const void * item2)2713 static int listExonCompareAddressAscending(
2714     const void *item1,
2715     const void *item2)
2716 {
2717     int result = 0;
2718 
2719     EnsPExon exon1 = *(EnsOExon *const *) item1;
2720     EnsPExon exon2 = *(EnsOExon *const *) item2;
2721 
2722 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
2723     if (ajDebugTest("listExonCompareAddressAscending"))
2724         ajDebug("listExonCompareAddressAscending\n"
2725                 "  exon1 %p\n"
2726                 "  exon2 %p\n",
2727                 exon1,
2728                 exon2);
2729 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
2730 
2731     if (ensExonSimilarity(exon1, exon2) == ajTrue)
2732         return 0;
2733 
2734     if (exon1 < exon2)
2735         result = -1;
2736 
2737     if (exon1 > exon2)
2738         result = +1;
2739 
2740     return result;
2741 }
2742 
2743 
2744 
2745 
2746 /* @funcstatic listExonDelete *************************************************
2747 **
2748 ** ajListSortUnique "itemdel" function to delete Ensembl Exon objects that
2749 ** are redundant.
2750 **
2751 ** @param [r] Pitem [void**] Ensembl Exon address
2752 ** @param [r] cl [void*] Standard, passed in from ajListSortUnique
2753 ** @see ajListSortUnique
2754 **
2755 ** @return [void]
2756 **
2757 ** @release 6.2.0
2758 ** @@
2759 ******************************************************************************/
2760 
listExonDelete(void ** Pitem,void * cl)2761 static void listExonDelete(void **Pitem, void *cl)
2762 {
2763     if (!Pitem)
2764         return;
2765 
2766     (void) cl;
2767 
2768     ensExonDel((EnsPExon *) Pitem);
2769 
2770     return;
2771 }
2772 
2773 
2774 
2775 
2776 /* @func ensGeneFetchAllExons *************************************************
2777 **
2778 ** Fetch all Ensembl Exon objects of an Ensembl Gene.
2779 **
2780 ** @cc Bio::EnsEMBL::Gene::get_all_Exons
2781 ** @param [u] gene [EnsPGene] Ensembl Gene
2782 ** @param [u] exons [AjPList] AJAX List of Ensembl Exon objects
2783 **
2784 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2785 **
2786 ** @release 6.2.0
2787 ** @@
2788 ******************************************************************************/
2789 
ensGeneFetchAllExons(EnsPGene gene,AjPList exons)2790 AjBool ensGeneFetchAllExons(EnsPGene gene, AjPList exons)
2791 {
2792     const AjPList elist = NULL;
2793     const AjPList tlist = NULL;
2794 
2795     AjIList eiter = NULL;
2796     AjIList titer = NULL;
2797 
2798     EnsPExon exon = NULL;
2799 
2800     EnsPTranscript transcript = NULL;
2801 
2802     if (!gene)
2803         return ajFalse;
2804 
2805     if (!exons)
2806         return ajFalse;
2807 
2808     tlist = ensGeneLoadTranscripts(gene);
2809 
2810     titer = ajListIterNewread(tlist);
2811 
2812     while (!ajListIterDone(titer))
2813     {
2814         transcript = (EnsPTranscript) ajListIterGet(titer);
2815 
2816         elist = ensTranscriptLoadExons(transcript);
2817 
2818         eiter = ajListIterNewread(elist);
2819 
2820         while (!ajListIterDone(eiter))
2821         {
2822             exon = (EnsPExon) ajListIterGet(eiter);
2823 
2824             ajListPushAppend(exons, (void *) ensExonNewRef(exon));
2825         }
2826 
2827         ajListIterDel(&eiter);
2828     }
2829 
2830     ajListIterDel(&titer);
2831 
2832     ajListSortUnique(exons, &listExonCompareAddressAscending, &listExonDelete);
2833 
2834     return ajTrue;
2835 }
2836 
2837 
2838 
2839 
2840 /* @func ensGeneFetchCanonicaltranscript **************************************
2841 **
2842 ** Fetch the canonical Ensembl Transcript of an Ensembl Gene.
2843 **
2844 ** The caller is repsonsible for deleting the Ensembl Transcript.
2845 **
2846 ** @cc Bio::EnsEMBL::Gene::canonical_transcript
2847 ** @param [u] gene [EnsPGene] Ensembl Gene
2848 ** @param [wP] Ptranscript [EnsPTranscript*] Ensembl Transcript address
2849 **
2850 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2851 **
2852 ** @release 6.4.0
2853 ** @@
2854 ******************************************************************************/
2855 
ensGeneFetchCanonicaltranscript(EnsPGene gene,EnsPTranscript * Ptranscript)2856 AjBool ensGeneFetchCanonicaltranscript(EnsPGene gene,
2857                                        EnsPTranscript *Ptranscript)
2858 {
2859     if (!gene)
2860         return ajFalse;
2861 
2862     if (!Ptranscript)
2863         return ajFalse;
2864 
2865     return ensTranscriptadaptorFetchByIdentifier(
2866         ensRegistryGetTranscriptadaptor(
2867             ensGeneadaptorGetDatabaseadaptor(gene->Adaptor)),
2868         gene->Canonicaltranscriptidentifier,
2869         Ptranscript);
2870 }
2871 
2872 
2873 
2874 
2875 /* @func ensGeneFetchDisplayidentifier ****************************************
2876 **
2877 ** Fetch the display identifier of an Ensembl Gene.
2878 ** This will return the stable identifier, the SQL database-internal identifier
2879 ** or the Gene memory address in this descending priority.
2880 ** The caller is responsible for deleting the AJAX String.
2881 **
2882 ** @cc Bio::EnsEMBL::Gene::display_id
2883 ** @param [r] gene [const EnsPGene] Ensembl Gene
2884 ** @param [wP] Pidentifier [AjPStr*] AJAX String address
2885 **
2886 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2887 **
2888 ** @release 6.5.0
2889 ** @@
2890 ******************************************************************************/
2891 
ensGeneFetchDisplayidentifier(const EnsPGene gene,AjPStr * Pidentifier)2892 AjBool ensGeneFetchDisplayidentifier(const EnsPGene gene,
2893                                      AjPStr *Pidentifier)
2894 {
2895     if (!gene)
2896         return ajFalse;
2897 
2898     if (!Pidentifier)
2899         return ajFalse;
2900 
2901     if (gene->Stableidentifier &&
2902         ajStrGetLen(gene->Stableidentifier))
2903     {
2904         if (*Pidentifier)
2905             ajStrAssignS(Pidentifier, gene->Stableidentifier);
2906         else
2907             *Pidentifier = ajStrNewS(gene->Stableidentifier);
2908     }
2909     else if (gene->Identifier)
2910     {
2911         if (*Pidentifier)
2912             *Pidentifier = ajFmtPrintS(Pidentifier, "%u", gene->Identifier);
2913         else
2914             *Pidentifier = ajFmtStr("%u", gene->Identifier);
2915     }
2916     else
2917     {
2918         if (*Pidentifier)
2919             *Pidentifier = ajFmtPrintS(Pidentifier, "%p", gene);
2920         else
2921             *Pidentifier = ajFmtStr("%p", gene);
2922     }
2923 
2924     return ajTrue;
2925 }
2926 
2927 
2928 
2929 
2930 /* @section matching **********************************************************
2931 **
2932 ** Functions for matching Ensembl Gene objects
2933 **
2934 ** @fdata [EnsPGene]
2935 **
2936 ** @nam3rule Match      Test Ensembl Gene objects for identity
2937 ** @nam3rule Overlap    Test Ensembl Gene objects for overlap
2938 ** @nam3rule Similarity Test Ensembl Gene objects for similarity
2939 **
2940 ** @argrule * gene1 [EnsPGene] Ensembl Gene
2941 ** @argrule * gene2 [EnsPGene] Ensembl Gene
2942 **
2943 ** @valrule * [AjBool] True on success
2944 **
2945 ** @fcategory use
2946 ******************************************************************************/
2947 
2948 
2949 
2950 
2951 /* @func ensGeneSimilarity ****************************************************
2952 **
2953 ** Test Ensembl Gene objects for similarity.
2954 **
2955 ** @cc Bio::EnsEMBL::Gene::equals
2956 ** @param [u] gene1 [EnsPGene] Ensembl Gene
2957 ** @param [u] gene2 [EnsPGene] Ensembl Gene
2958 **
2959 ** @return [AjBool] ajTrue if the Ensembl Gene objects are similar
2960 **
2961 ** @release 6.4.0
2962 ** @@
2963 ** NOTE: This function is similar to Bio::EnsEMBL::Gene::equals, but not
2964 ** completely identical. The Bio::EnsEMBL::Transcript objects are not sorted
2965 ** before comparison, as this would interfere with the internal AJAX List and
2966 ** their order in the Ensembl Gene.
2967 ******************************************************************************/
2968 
ensGeneSimilarity(EnsPGene gene1,EnsPGene gene2)2969 AjBool ensGeneSimilarity(EnsPGene gene1, EnsPGene gene2)
2970 {
2971     AjBool mismatch = AJFALSE;
2972     AjBool similarity = AJFALSE;
2973 
2974     AjIList iter1 = NULL;
2975     AjIList iter2 = NULL;
2976 
2977     const AjPList transcripts1 = NULL;
2978     const AjPList transcripts2 = NULL;
2979 
2980     EnsPTranscript transcript1 = NULL;
2981     EnsPTranscript transcript2 = NULL;
2982 
2983     if (!gene1)
2984         return ajFalse;
2985 
2986     if (!gene2)
2987         return ajFalse;
2988 
2989     if (gene1 == gene2)
2990         return ajTrue;
2991 
2992     if (!ensFeatureSimilarity(gene1->Feature, gene2->Feature))
2993         return ajFalse;
2994 
2995     if (!ajStrMatchCaseS(gene1->Biotype, gene2->Biotype))
2996         return ajFalse;
2997 
2998     if ((gene1->Stableidentifier && gene2->Stableidentifier) &&
2999         (!ajStrMatchCaseS(gene1->Stableidentifier,
3000                           gene2->Stableidentifier)))
3001         return ajFalse;
3002 
3003     transcripts1 = ensGeneLoadTranscripts(gene1);
3004     transcripts2 = ensGeneLoadTranscripts(gene2);
3005 
3006     if (ajListGetLength(transcripts1) != ajListGetLength(transcripts2))
3007         return ajFalse;
3008 
3009     iter1 = ajListIterNewread(transcripts1);
3010     iter2 = ajListIterNewread(transcripts2);
3011 
3012     while (!ajListIterDone(iter1))
3013     {
3014         transcript1 = (EnsPTranscript) ajListIterGet(iter1);
3015 
3016         ajListIterRewind(iter2);
3017 
3018         similarity = ajFalse;
3019 
3020         while (!ajListIterDone(iter2))
3021         {
3022             transcript2 = (EnsPTranscript) ajListIterGet(iter2);
3023 
3024             if (ensTranscriptSimilarity(transcript1, transcript2))
3025             {
3026                 similarity = ajTrue;
3027                 break;
3028             }
3029         }
3030 
3031         if (similarity == ajFalse)
3032         {
3033             mismatch = ajTrue;
3034             break;
3035         }
3036     }
3037 
3038     ajListIterDel(&iter1);
3039     ajListIterDel(&iter2);
3040 
3041     if (mismatch == ajTrue)
3042         return ajFalse;
3043 
3044     return ajTrue;
3045 }
3046 
3047 
3048 
3049 
3050 /* @section map ***************************************************************
3051 **
3052 ** Functions for mapping Ensembl Gene objects between
3053 ** Ensembl Coordinate System objects.
3054 **
3055 ** @fdata [EnsPGene]
3056 **
3057 ** @nam3rule Transfer Transfer an Ensembl Gene
3058 ** @nam3rule Transform Transform an Ensembl Gene
3059 **
3060 ** @argrule * gene [EnsPGene] Ensembl Gene
3061 ** @argrule Transfer slice [EnsPSlice] Ensembl Slice
3062 ** @argrule Transform csname [const AjPStr] Ensembl Coordinate System name
3063 ** @argrule Transform csversion [const AjPStr] Ensembl Coordinate System
3064 **                                             version
3065 **
3066 ** @valrule * [EnsPGene] Ensembl Gene or NULL
3067 **
3068 ** @fcategory misc
3069 ******************************************************************************/
3070 
3071 
3072 
3073 
3074 /* @func ensGeneTransfer ******************************************************
3075 **
3076 ** Transfer an Ensembl Gene onto another Ensembl Slice.
3077 **
3078 ** @cc Bio::EnsEMBL::Gene::transfer
3079 ** @param [u] gene [EnsPGene] Ensembl Gene
3080 ** @param [u] slice [EnsPSlice] Ensembl Slice
3081 ** @see ensFeatureTransfer
3082 **
3083 ** @return [EnsPGene] Ensembl Gene or NULL
3084 **
3085 ** @release 6.2.0
3086 ** @@
3087 ******************************************************************************/
3088 
ensGeneTransfer(EnsPGene gene,EnsPSlice slice)3089 EnsPGene ensGeneTransfer(EnsPGene gene, EnsPSlice slice)
3090 {
3091     EnsPFeature newfeature = NULL;
3092 
3093     EnsPGene newgene = NULL;
3094 
3095     if (ajDebugTest("ensGeneTransfer"))
3096         ajDebug("ensGeneTransfer\n"
3097                 "  gene %p\n"
3098                 "  slice %p\n",
3099                 gene,
3100                 slice);
3101 
3102     if (!gene)
3103         return NULL;
3104 
3105     if (!slice)
3106         return NULL;
3107 
3108     newfeature = ensFeatureTransfer(gene->Feature, slice);
3109 
3110     if (!newfeature)
3111     {
3112         ajDebug("ensGeneTransfer could not transfer the Ensembl Feature %p "
3113                 "onto the new Ensembl Slice %p.\n", gene->Feature, slice);
3114 
3115         ensFeatureTrace(gene->Feature, 1);
3116 
3117         ensSliceTrace(slice, 1);
3118 
3119         return NULL;
3120     }
3121 
3122     newgene = geneNewCpyFeatures(gene);
3123 
3124     ensGeneSetFeature(newgene, newfeature);
3125 
3126     ensFeatureDel(&newfeature);
3127 
3128     return newgene;
3129 }
3130 
3131 
3132 
3133 
3134 /* @func ensGeneTransform *****************************************************
3135 **
3136 ** Transform an Ensembl Gene into another Ensembl Coordinate System.
3137 **
3138 ** @cc Bio::EnsEMBL::Gene::transform
3139 ** @param [u] gene [EnsPGene] Ensembl Gene
3140 ** @param [r] csname [const AjPStr] Ensembl Coordinate System name
3141 ** @param [r] csversion [const AjPStr] Ensembl Coordinate System version
3142 ** @see ensFeatureTransform
3143 **
3144 ** @return [EnsPGene] Ensembl Gene or NULL
3145 **
3146 ** @release 6.2.0
3147 ** @@
3148 ******************************************************************************/
3149 
ensGeneTransform(EnsPGene gene,const AjPStr csname,const AjPStr csversion)3150 EnsPGene ensGeneTransform(EnsPGene gene,
3151                           const AjPStr csname,
3152                           const AjPStr csversion)
3153 {
3154     ajint failures = 0;
3155     ajint minstart = INT_MAX;
3156     ajint maxend   = INT_MIN;
3157 
3158     ajuint psslength = 0U;
3159 
3160     AjIList iter = NULL;
3161     AjPList pss  = NULL;
3162 
3163     const AjPList transcripts = NULL;
3164 
3165     EnsPFeature newgf = NULL;
3166     EnsPFeature newtf = NULL;
3167 
3168     EnsPGene newgene = NULL;
3169 
3170     EnsPProjectionsegment ps = NULL;
3171 
3172     EnsPTranscript newtranscript = NULL;
3173     EnsPTranscript oldtranscript = NULL;
3174 
3175     if (!gene)
3176         return NULL;
3177 
3178     if (!csname)
3179         return NULL;
3180 
3181     if (ajStrGetLen(csname) == 0U)
3182         return NULL;
3183 
3184     newgf = ensFeatureTransform(gene->Feature,
3185                                 csname,
3186                                 csversion,
3187                                 (EnsPSlice) NULL);
3188 
3189     if (!newgf)
3190     {
3191         /*
3192         ** Check if this Gene projects at all to the requested
3193         ** Coordinate System.
3194         */
3195 
3196         pss = ajListNew();
3197 
3198         ensFeatureProject(gene->Feature, csname, csversion, pss);
3199 
3200         psslength = (ajuint) ajListGetLength(pss);
3201 
3202         while (ajListPop(pss, (void **) &ps))
3203             ensProjectionsegmentDel(&ps);
3204 
3205         ajListFree(&pss);
3206 
3207         if (psslength == 0U)
3208             return NULL;
3209     }
3210 
3211     /* All Ensembl Transcript and Ensembl Exon objects need to be loaded. */
3212 
3213     transcripts = ensGeneLoadTranscripts(gene);
3214 
3215     iter = ajListIterNewread(transcripts);
3216 
3217     while (!ajListIterDone(iter))
3218     {
3219         oldtranscript = (EnsPTranscript) ajListIterGet(iter);
3220 
3221         ensTranscriptLoadExons(oldtranscript);
3222     }
3223 
3224     ajListIterDel(&iter);
3225 
3226     /*
3227     ** Copy the Ensembl Gene object and also its internal
3228     ** Ensembl Feature class-based members.
3229     */
3230 
3231     newgene = geneNewCpyFeatures(gene);
3232 
3233     if (newgene->Transcripts)
3234     {
3235         iter = ajListIterNew(newgene->Transcripts);
3236 
3237         while (!ajListIterDone(iter))
3238         {
3239             oldtranscript = (EnsPTranscript) ajListIterGet(iter);
3240 
3241             ajListIterRemove(iter);
3242 
3243             newtranscript = ensTranscriptTransform(oldtranscript,
3244                                                    csname,
3245                                                    csversion);
3246 
3247             if (newtranscript)
3248             {
3249                 ajListIterInsert(iter, (void *) newtranscript);
3250 
3251                 /* Advance the AJAX List Iterator after the insert. */
3252 
3253                 (void) ajListIterGet(iter);
3254             }
3255             else
3256             {
3257                 failures++;
3258 
3259                 continue;
3260             }
3261 
3262             if (!newgf)
3263             {
3264                 newtf = ensTranscriptGetFeature(newtranscript);
3265 
3266                 minstart = (ensFeatureGetStart(newtf) < minstart)
3267                     ? ensFeatureGetStart(newtf) : minstart;
3268 
3269                 maxend   = (ensFeatureGetEnd(newtf) > maxend)
3270                     ? ensFeatureGetEnd(newtf) : maxend;
3271             }
3272 
3273             ensTranscriptDel(&oldtranscript);
3274         }
3275 
3276         ajListIterDel(&iter);
3277     }
3278 
3279     if (failures)
3280     {
3281         ensFeatureDel(&newgf);
3282 
3283         ensGeneDel(&newgene);
3284 
3285         return NULL;
3286     }
3287 
3288     if (!newgf)
3289     {
3290         ajListPeekFirst(newgene->Transcripts, (void **) &newtranscript);
3291 
3292         newtf = ensTranscriptGetFeature(newtranscript);
3293 
3294         newgf = ensFeatureNewIniS(ensFeatureGetAnalysis(gene->Feature),
3295                                   ensFeatureGetSlice(newtf),
3296                                   minstart,
3297                                   maxend,
3298                                   ensFeatureGetStrand(newtf));
3299     }
3300 
3301     /*
3302     ** Set the Feature directly, since ensGeneSetFeature transfers all
3303     ** internal Ensembl Objects based on the Feature class onto the new
3304     ** Ensembl Feature Slice, which duplicates the work already done here.
3305     */
3306 
3307     ensFeatureDel(&newgene->Feature);
3308 
3309     newgene->Feature = newgf;
3310 
3311     /* Clear internal members that depend on Transcript coordinates. */
3312 
3313     return newgene;
3314 }
3315 
3316 
3317 
3318 
3319 /* @section check *************************************************************
3320 **
3321 ** Check Ensembl Gene objects.
3322 **
3323 ** @fdata [EnsPGene]
3324 **
3325 ** @nam3rule Check Check Ensembl Gene object(s)
3326 ** @nam4rule Reference Check whether an Ensembl Gene object is the reference
3327 **
3328 ** @argrule * gene [const EnsPGene] Ensembl Gene
3329 ** @argrule Reference Presult [AjBool*] Result
3330 **
3331 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
3332 **
3333 ** @fcategory use
3334 ******************************************************************************/
3335 
3336 
3337 
3338 
3339 /* @func ensGeneCheckReference ************************************************
3340 **
3341 ** Check, whether an Ensembl Gene is a reference or alternative allele.
3342 **
3343 ** @cc Bio::EnsEMBL::Gene::is_reference
3344 ** @param [r] gene [const EnsPGene] Ensembl Gene
3345 ** @param [u] Presult [AjBool*] Result
3346 **
3347 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3348 **
3349 ** @release 6.4.0
3350 ** @@
3351 ******************************************************************************/
3352 
ensGeneCheckReference(const EnsPGene gene,AjBool * Presult)3353 AjBool ensGeneCheckReference(const EnsPGene gene, AjBool *Presult)
3354 {
3355     if (!gene)
3356         return ajFalse;
3357 
3358     if (!gene->Adaptor)
3359         return ajFalse;
3360 
3361     return ensGeneadaptorCheckReference(gene->Adaptor, gene, Presult);
3362 }
3363 
3364 
3365 
3366 
3367 /* @datasection [EnsEGeneStatus] Ensembl Gene Status **************************
3368 **
3369 ** @nam2rule Gene Functions for manipulating
3370 ** Ensembl Gene objects
3371 ** @nam3rule GeneStatus Functions for manipulating
3372 ** Ensembl Gene Status enumerations
3373 **
3374 ******************************************************************************/
3375 
3376 
3377 
3378 
3379 /* @section Misc **************************************************************
3380 **
3381 ** Functions for returning an Ensembl Gene Status enumeration.
3382 **
3383 ** @fdata [EnsEGeneStatus]
3384 **
3385 ** @nam4rule From Ensembl Gene Status query
3386 ** @nam5rule Str  AJAX String object query
3387 **
3388 ** @argrule  Str  status  [const AjPStr] Status string
3389 **
3390 ** @valrule * [EnsEGeneStatus] Ensembl Gene Status enumeration or
3391 **                             ensEGeneStatusNULL
3392 **
3393 ** @fcategory misc
3394 ******************************************************************************/
3395 
3396 
3397 
3398 
3399 /* @func ensGeneStatusFromStr *************************************************
3400 **
3401 ** Convert an AJAX String into an Ensembl Gene Status enumeration.
3402 **
3403 ** @param [r] status [const AjPStr] Status string
3404 **
3405 ** @return [EnsEGeneStatus] Ensembl Gene Status enumeration or
3406 **                          ensEGeneStatusNULL
3407 **
3408 ** @release 6.2.0
3409 ** @@
3410 ******************************************************************************/
3411 
ensGeneStatusFromStr(const AjPStr status)3412 EnsEGeneStatus ensGeneStatusFromStr(const AjPStr status)
3413 {
3414     register EnsEGeneStatus i = ensEGeneStatusNULL;
3415 
3416     EnsEGeneStatus estatus = ensEGeneStatusNULL;
3417 
3418     for (i = ensEGeneStatusNULL;
3419          geneKStatus[i];
3420          i++)
3421         if (ajStrMatchC(status, geneKStatus[i]))
3422             estatus = i;
3423 
3424     if (!estatus)
3425         ajDebug("ensGeneStatusFromStr encountered "
3426                 "unexpected string '%S'.\n", status);
3427 
3428     return estatus;
3429 }
3430 
3431 
3432 
3433 
3434 /* @section Cast **************************************************************
3435 **
3436 ** Functions for returning attributes of an
3437 ** Ensembl Gene Status enumeration.
3438 **
3439 ** @fdata [EnsEGeneStatus]
3440 **
3441 ** @nam4rule To   Return Ensembl Gene Status enumeration
3442 ** @nam5rule Char Return C character string value
3443 **
3444 ** @argrule To status [EnsEGeneStatus] Ensembl Gene Status enumeration
3445 **
3446 ** @valrule Char [const char*] Ensembl Gene Status C-type (char *) string
3447 **
3448 ** @fcategory cast
3449 ******************************************************************************/
3450 
3451 
3452 
3453 
3454 /* @func ensGeneStatusToChar **************************************************
3455 **
3456 ** Convert an Ensembl Gene Status enumeration into a C-type (char *) string.
3457 **
3458 ** @param [u] status [EnsEGeneStatus] Ensembl Gene Status enumeration
3459 **
3460 ** @return [const char*] Ensembl Gene Status C-type (char *) string
3461 **
3462 ** @release 6.2.0
3463 ** @@
3464 ******************************************************************************/
3465 
ensGeneStatusToChar(EnsEGeneStatus status)3466 const char* ensGeneStatusToChar(EnsEGeneStatus status)
3467 {
3468     register EnsEGeneStatus i = ensEGeneStatusNULL;
3469 
3470     for (i = ensEGeneStatusNULL;
3471          geneKStatus[i] && (i < status);
3472          i++);
3473 
3474     if (!geneKStatus[i])
3475         ajDebug("ensGeneStatusToChar "
3476                 "encountered an out of boundary error on "
3477                 "Ensembl Gene Status "
3478                 "enumeration %d.\n",
3479                 status);
3480 
3481     return geneKStatus[i];
3482 }
3483 
3484 
3485 
3486 
3487 /* @datasection [AjPList] AJAX List *******************************************
3488 **
3489 ** @nam2rule List Functions for manipulating AJAX List objects
3490 **
3491 ******************************************************************************/
3492 
3493 
3494 
3495 
3496 /* @funcstatic listGeneCompareEndAscending ************************************
3497 **
3498 ** AJAX List of Ensembl Gene objects comparison function to sort by
3499 ** Ensembl Feature end member in ascending order.
3500 **
3501 ** @param [r] item1 [const void*] Ensembl Gene address 1
3502 ** @param [r] item2 [const void*] Ensembl Gene address 2
3503 ** @see ajListSort
3504 **
3505 ** @return [int] The comparison function returns an integer less than,
3506 **               equal to, or greater than zero if the first argument is
3507 **               considered to be respectively less than, equal to, or
3508 **               greater than the second.
3509 **
3510 ** @release 6.4.0
3511 ** @@
3512 ******************************************************************************/
3513 
listGeneCompareEndAscending(const void * item1,const void * item2)3514 static int listGeneCompareEndAscending(
3515     const void *item1,
3516     const void *item2)
3517 {
3518     EnsPGene gene1 = *(EnsOGene *const *) item1;
3519     EnsPGene gene2 = *(EnsOGene *const *) item2;
3520 
3521 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3522     if (ajDebugTest("listGeneCompareEndAscending"))
3523         ajDebug("listGeneCompareEndAscending\n"
3524                 "  gene1 %p\n"
3525                 "  gene2 %p\n",
3526                 gene1,
3527                 gene2);
3528 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3529 
3530     /* Sort empty values towards the end of the AJAX List. */
3531 
3532     if (gene1 && (!gene2))
3533         return -1;
3534 
3535     if ((!gene1) && (!gene2))
3536         return 0;
3537 
3538     if ((!gene1) && gene2)
3539         return +1;
3540 
3541     return ensFeatureCompareEndAscending(gene1->Feature, gene2->Feature);
3542 }
3543 
3544 
3545 
3546 
3547 /* @funcstatic listGeneCompareEndDescending ***********************************
3548 **
3549 ** AJAX List of Ensembl Gene objects comparison function to sort by
3550 ** Ensembl Feature end member in descending order.
3551 **
3552 ** @param [r] item1 [const void*] Ensembl Gene address 1
3553 ** @param [r] item2 [const void*] Ensembl Gene address 2
3554 ** @see ajListSort
3555 **
3556 ** @return [int] The comparison function returns an integer less than,
3557 **               equal to, or greater than zero if the first argument is
3558 **               considered to be respectively less than, equal to, or
3559 **               greater than the second.
3560 **
3561 ** @release 6.4.0
3562 ** @@
3563 ******************************************************************************/
3564 
listGeneCompareEndDescending(const void * item1,const void * item2)3565 static int listGeneCompareEndDescending(
3566     const void *item1,
3567     const void *item2)
3568 {
3569     EnsPGene gene1 = *(EnsOGene *const *) item1;
3570     EnsPGene gene2 = *(EnsOGene *const *) item2;
3571 
3572 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3573     if (ajDebugTest("listGeneCompareEndDescending"))
3574         ajDebug("listGeneCompareEndDescending\n"
3575                 "  gene1 %p\n"
3576                 "  gene2 %p\n",
3577                 gene1,
3578                 gene2);
3579 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3580 
3581     /* Sort empty values towards the end of the AJAX List. */
3582 
3583     if (gene1 && (!gene2))
3584         return -1;
3585 
3586     if ((!gene1) && (!gene2))
3587         return 0;
3588 
3589     if ((!gene1) && gene2)
3590         return +1;
3591 
3592     return ensFeatureCompareEndDescending(gene1->Feature, gene2->Feature);
3593 }
3594 
3595 
3596 
3597 
3598 /* @funcstatic listGeneCompareIdentifierAscending *****************************
3599 **
3600 ** AJAX List of Ensembl Gene objects comparison function to sort by
3601 ** identifier member in ascending order.
3602 **
3603 ** @param [r] item1 [const void*] Ensembl Gene address 1
3604 ** @param [r] item2 [const void*] Ensembl Gene address 2
3605 ** @see ajListSort
3606 **
3607 ** @return [int] The comparison function returns an integer less than,
3608 **               equal to, or greater than zero if the first argument is
3609 **               considered to be respectively less than, equal to, or
3610 **               greater than the second.
3611 **
3612 ** @release 6.4.0
3613 ** @@
3614 ******************************************************************************/
3615 
listGeneCompareIdentifierAscending(const void * item1,const void * item2)3616 static int listGeneCompareIdentifierAscending(
3617     const void *item1,
3618     const void *item2)
3619 {
3620     EnsPGene gene1 = *(EnsOGene *const *) item1;
3621     EnsPGene gene2 = *(EnsOGene *const *) item2;
3622 
3623 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3624     if (ajDebugTest("listGeneCompareIdentifierAscending"))
3625         ajDebug("listGeneCompareIdentifierAscending\n"
3626                 "  gene1 %p\n"
3627                 "  gene2 %p\n",
3628                 gene1,
3629                 gene2);
3630 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3631 
3632     /* Sort empty values towards the end of the AJAX List. */
3633 
3634     if (gene1 && (!gene2))
3635         return -1;
3636 
3637     if ((!gene1) && (!gene2))
3638         return 0;
3639 
3640     if ((!gene1) && gene2)
3641         return +1;
3642 
3643     if (gene1->Identifier < gene2->Identifier)
3644         return -1;
3645 
3646     if (gene1->Identifier > gene2->Identifier)
3647         return +1;
3648 
3649     return 0;
3650 }
3651 
3652 
3653 
3654 
3655 /* @funcstatic listGeneCompareStartAscending **********************************
3656 **
3657 ** AJAX List of Ensembl Gene objects comparison function to sort by
3658 ** Ensembl Feature start member in ascending order.
3659 **
3660 ** @param [r] item1 [const void*] Ensembl Gene address 1
3661 ** @param [r] item2 [const void*] Ensembl Gene address 2
3662 ** @see ajListSort
3663 **
3664 ** @return [int] The comparison function returns an integer less than,
3665 **               equal to, or greater than zero if the first argument is
3666 **               considered to be respectively less than, equal to, or
3667 **               greater than the second.
3668 **
3669 ** @release 6.4.0
3670 ** @@
3671 ******************************************************************************/
3672 
listGeneCompareStartAscending(const void * item1,const void * item2)3673 static int listGeneCompareStartAscending(
3674     const void *item1,
3675     const void *item2)
3676 {
3677     EnsPGene gene1 = *(EnsOGene *const *) item1;
3678     EnsPGene gene2 = *(EnsOGene *const *) item2;
3679 
3680 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3681     if (ajDebugTest("listGeneCompareStartAscending"))
3682         ajDebug("listGeneCompareStartAscending\n"
3683                 "  gene1 %p\n"
3684                 "  gene2 %p\n",
3685                 gene1,
3686                 gene2);
3687 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3688 
3689     /* Sort empty values towards the end of the AJAX List. */
3690 
3691     if (gene1 && (!gene2))
3692         return -1;
3693 
3694     if ((!gene1) && (!gene2))
3695         return 0;
3696 
3697     if ((!gene1) && gene2)
3698         return +1;
3699 
3700     return ensFeatureCompareStartAscending(gene1->Feature, gene2->Feature);
3701 }
3702 
3703 
3704 
3705 
3706 /* @funcstatic listGeneCompareStartDescending *********************************
3707 **
3708 ** AJAX List of Ensembl Gene objects comparison function to sort by
3709 ** Ensembl Feature start member in descending order.
3710 **
3711 ** @param [r] item1 [const void*] Ensembl Gene address 1
3712 ** @param [r] item2 [const void*] Ensembl Gene address 2
3713 ** @see ajListSort
3714 **
3715 ** @return [int] The comparison function returns an integer less than,
3716 **               equal to, or greater than zero if the first argument is
3717 **               considered to be respectively less than, equal to, or
3718 **               greater than the second.
3719 **
3720 ** @release 6.4.0
3721 ** @@
3722 ******************************************************************************/
3723 
listGeneCompareStartDescending(const void * item1,const void * item2)3724 static int listGeneCompareStartDescending(
3725     const void *item1,
3726     const void *item2)
3727 {
3728     EnsPGene gene1 = *(EnsOGene *const *) item1;
3729     EnsPGene gene2 = *(EnsOGene *const *) item2;
3730 
3731 #if defined(AJ_DEBUG) && AJ_DEBUG >= 2
3732     if (ajDebugTest("listGeneCompareStartDescending"))
3733         ajDebug("listGeneCompareStartDescending\n"
3734                 "  gene1 %p\n"
3735                 "  gene2 %p\n",
3736                 gene1,
3737                 gene2);
3738 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */
3739 
3740     /* Sort empty values towards the end of the AJAX List. */
3741 
3742     if (gene1 && (!gene2))
3743         return -1;
3744 
3745     if ((!gene1) && (!gene2))
3746         return 0;
3747 
3748     if ((!gene1) && gene2)
3749         return +1;
3750 
3751     return ensFeatureCompareStartDescending(gene1->Feature, gene2->Feature);
3752 }
3753 
3754 
3755 
3756 
3757 /* @section list **************************************************************
3758 **
3759 ** Functions for manipulating AJAX List objects.
3760 **
3761 ** @fdata [AjPList]
3762 **
3763 ** @nam3rule Gene Functions for manipulating AJAX List objects of
3764 ** Ensembl Gene objects
3765 ** @nam4rule Sort       Sort functions
3766 ** @nam5rule End        Sort by Ensembl Feature end member
3767 ** @nam5rule Identifier Sort by identifier member
3768 ** @nam5rule Start      Sort by Ensembl Feature start member
3769 ** @nam6rule Ascending  Sort in ascending order
3770 ** @nam6rule Descending Sort in descending order
3771 **
3772 ** @argrule * genes [AjPList] AJAX List of Ensembl Gene objects
3773 **
3774 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
3775 **
3776 ** @fcategory misc
3777 ******************************************************************************/
3778 
3779 
3780 
3781 
3782 /* @func ensListGeneSortEndAscending ******************************************
3783 **
3784 ** Sort an AJAX List of Ensembl Gene objects by their
3785 ** Ensembl Feature end member in ascending order.
3786 **
3787 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
3788 **
3789 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3790 **
3791 ** @release 6.4.0
3792 ** @@
3793 ******************************************************************************/
3794 
ensListGeneSortEndAscending(AjPList genes)3795 AjBool ensListGeneSortEndAscending(AjPList genes)
3796 {
3797     if (!genes)
3798         return ajFalse;
3799 
3800     ajListSortTwoThree(genes,
3801                        &listGeneCompareEndAscending,
3802                        &listGeneCompareStartAscending,
3803                        &listGeneCompareIdentifierAscending);
3804 
3805     return ajTrue;
3806 }
3807 
3808 
3809 
3810 
3811 /* @func ensListGeneSortEndDescending *****************************************
3812 **
3813 ** Sort an AJAX List of Ensembl Gene objects by their
3814 ** Ensembl Feature end member in descending order.
3815 **
3816 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
3817 **
3818 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3819 **
3820 ** @release 6.4.0
3821 ** @@
3822 ******************************************************************************/
3823 
ensListGeneSortEndDescending(AjPList genes)3824 AjBool ensListGeneSortEndDescending(AjPList genes)
3825 {
3826     if (!genes)
3827         return ajFalse;
3828 
3829     ajListSortTwoThree(genes,
3830                        &listGeneCompareEndDescending,
3831                        &listGeneCompareStartDescending,
3832                        &listGeneCompareIdentifierAscending);
3833 
3834     return ajTrue;
3835 }
3836 
3837 
3838 
3839 
3840 /* @func ensListGeneSortIdentifierAscending ***********************************
3841 **
3842 ** Sort an AJAX List of Ensembl Gene objects by their
3843 ** identifier member in ascending order.
3844 **
3845 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
3846 **
3847 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3848 **
3849 ** @release 6.4.0
3850 ** @@
3851 ******************************************************************************/
3852 
ensListGeneSortIdentifierAscending(AjPList genes)3853 AjBool ensListGeneSortIdentifierAscending(AjPList genes)
3854 {
3855     if (!genes)
3856         return ajFalse;
3857 
3858     ajListSort(genes, &listGeneCompareIdentifierAscending);
3859 
3860     return ajTrue;
3861 }
3862 
3863 
3864 
3865 
3866 /* @func ensListGeneSortStartAscending ****************************************
3867 **
3868 ** Sort an AJAX List of Ensembl Gene objects by their
3869 ** Ensembl Feature start member in ascending order.
3870 **
3871 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
3872 **
3873 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3874 **
3875 ** @release 6.4.0
3876 ** @@
3877 ******************************************************************************/
3878 
ensListGeneSortStartAscending(AjPList genes)3879 AjBool ensListGeneSortStartAscending(AjPList genes)
3880 {
3881     if (!genes)
3882         return ajFalse;
3883 
3884     ajListSortTwoThree(genes,
3885                        &listGeneCompareStartAscending,
3886                        &listGeneCompareEndAscending,
3887                        &listGeneCompareIdentifierAscending);
3888 
3889     return ajTrue;
3890 }
3891 
3892 
3893 
3894 
3895 /* @func ensListGeneSortStartDescending ***************************************
3896 **
3897 ** Sort an AJAX List of Ensembl Gene objects by their
3898 ** Ensembl Feature start member in descending order.
3899 **
3900 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
3901 **
3902 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3903 **
3904 ** @release 6.4.0
3905 ** @@
3906 ******************************************************************************/
3907 
ensListGeneSortStartDescending(AjPList genes)3908 AjBool ensListGeneSortStartDescending(AjPList genes)
3909 {
3910     if (!genes)
3911         return ajFalse;
3912 
3913     ajListSortTwoThree(genes,
3914                        &listGeneCompareStartDescending,
3915                        &listGeneCompareEndDescending,
3916                        &listGeneCompareIdentifierAscending);
3917 
3918     return ajTrue;
3919 }
3920 
3921 
3922 
3923 
3924 /* @datasection [AjPSeq] AJAX Sequence ****************************************
3925 **
3926 ** @nam2rule Sequence Functions for manipulating AJAX Sequence objects
3927 **
3928 ******************************************************************************/
3929 
3930 
3931 
3932 
3933 /* @section add ***************************************************************
3934 **
3935 ** Functions for manipulating AJAX Sequence objects.
3936 **
3937 ** @fdata [AjPSeq]
3938 **
3939 ** @nam3rule Add Add to an AJAX Sequence
3940 ** @nam4rule Feature Add an AJAX Feature
3941 ** @nam5rule Gene Convert an Ensembl Gene into an AJAX Feature
3942 **
3943 ** @argrule * seq [AjPSeq] AJAX Sequence
3944 ** @argrule Gene gene [EnsPGene] Ensembl Gene
3945 ** @argrule Gene Pfeature [AjPFeature*] AJAX Feature address
3946 **
3947 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
3948 **
3949 ** @fcategory misc
3950 ******************************************************************************/
3951 
3952 
3953 
3954 
3955 /* @func ensSequenceAddFeatureGene ********************************************
3956 **
3957 ** Convert an Ensembl Gene into an AJAX Feature and add it to the
3958 ** AJAX Feature Table of an AJAX Sequence. Also recursively convert and add
3959 ** all Ensembl Transcript and Ensembl Exon objects.
3960 **
3961 ** @param [u] seq [AjPSeq] AJAX Sequence
3962 ** @param [u] gene [EnsPGene] Ensembl Gene
3963 ** @param [wP] Pfeature [AjPFeature*] AJAX Feature address
3964 **
3965 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
3966 **
3967 ** @release 6.5.0
3968 ** @@
3969 ******************************************************************************/
3970 
ensSequenceAddFeatureGene(AjPSeq seq,EnsPGene gene,AjPFeature * Pfeature)3971 AjBool ensSequenceAddFeatureGene(AjPSeq seq,
3972                                  EnsPGene gene,
3973                                  AjPFeature *Pfeature)
3974 {
3975     AjPFeature feature = NULL;
3976 
3977     AjIList iter = NULL;
3978     const AjPList transcripts = NULL;
3979 
3980     AjPStr label = NULL;
3981     AjPStr type  = NULL;
3982 
3983     EnsPDatabaseadaptor dba = NULL;
3984 
3985     EnsPDatabaseentry dbe = NULL;
3986 
3987     EnsPGene newgene = NULL;
3988 
3989     EnsPSlice slice      = NULL;
3990     EnsPSliceadaptor sla = NULL;
3991 
3992     EnsPTranscript transcript = NULL;
3993 
3994     if (!seq)
3995         return ajFalse;
3996 
3997     if (!gene)
3998         return ajFalse;
3999 
4000     if (!Pfeature)
4001         return ajFalse;
4002 
4003     *Pfeature = NULL;
4004 
4005     /*
4006     ** NOTE: An AJAX Sequence accessor function returning the
4007     ** AJAX Feature Table in modifiable form is missing.
4008     */
4009 
4010     if (!seq->Fttable)
4011         return ajFalse;
4012 
4013     /*
4014     ** Get the Ensembl Slice covering the AJAX Sequence object and transfer
4015     ** the Ensembl Gene object onto it.
4016     */
4017 
4018     dba = ensGeneadaptorGetDatabaseadaptor(gene->Adaptor);
4019 
4020     sla = ensRegistryGetSliceadaptor(dba);
4021 
4022     ensSliceadaptorFetchByName(sla, ajSeqGetNameS(seq), &slice);
4023 
4024     if (!slice)
4025     {
4026         ajDebug("ensSequenceAddFeatureGene could not fetch an "
4027                 "Ensembl Slice for AJAX Sequence name '%S'.\n",
4028                 ajSeqGetNameS(seq));
4029 
4030         return ajFalse;
4031     }
4032 
4033     newgene = ensGeneTransfer(gene, slice);
4034 
4035     if (!newgene)
4036     {
4037         ajDebug("ensSequenceAddFeatureGene could not transfer "
4038                 "Ensembl Gene %p onto "
4039                 "Ensembl Slice %p.\n", gene, slice);
4040 
4041         ensGeneTrace(gene, 1);
4042         ensSliceTrace(slice, 1);
4043 
4044         ensSliceDel(&slice);
4045 
4046         return ajFalse;
4047     }
4048 
4049     /* Convert the Ensembl Gene into a parent AJAX Feature. */
4050 
4051     type = ajStrNewC("gene");
4052 
4053     *Pfeature = ajFeatNewNucFlags(
4054         seq->Fttable,
4055         ensAnalysisGetName(ensFeatureGetAnalysis(newgene->Feature)),
4056         type,
4057         ensFeatureGetStart(newgene->Feature),
4058         ensFeatureGetEnd(newgene->Feature),
4059         0.0F,
4060         ensFeatureCalculateStrand(newgene->Feature),
4061         0, /* Frame */
4062         0, /* Exon number */
4063         0, /* Start 2 */
4064         0, /* End 2 */
4065         (AjPStr) NULL, /* Remote Identifier */
4066         (AjPStr) NULL, /* Label */
4067         0);
4068 
4069     ensGeneFetchDisplayidentifier(gene, &label);
4070 
4071     ajFeatTagAddCS(*Pfeature, "standard_name", label);
4072 
4073     dbe = ensGeneGetDisplayreference(gene);
4074 
4075     if (dbe)
4076         ajFeatTagAddCS(*Pfeature,
4077                        "gene",
4078                        ensDatabaseentryGetDisplayidentifier(dbe));
4079 
4080     /* Add Ensembl Transcript objects as sub-AJAX Feature objects. */
4081 
4082     transcripts = ensGeneLoadTranscripts(newgene);
4083 
4084     iter = ajListIterNewread(transcripts);
4085 
4086     while (!ajListIterDone(iter))
4087     {
4088         transcript = (EnsPTranscript) ajListIterGet(iter);
4089 
4090         ensSequenceAddFeatureTranscript(seq, transcript, &feature);
4091     }
4092 
4093     ajListIterDel(&iter);
4094 
4095     ajStrDel(&label);
4096     ajStrDel(&type);
4097 
4098     ensGeneDel(&newgene);
4099 
4100     ensSliceDel(&slice);
4101 
4102     return ajTrue;
4103 }
4104 
4105 
4106 
4107 
4108 /* @datasection [EnsPGeneadaptor] Ensembl Gene Adaptor ************************
4109 **
4110 ** @nam2rule Geneadaptor Functions for manipulating
4111 ** Ensembl Gene Adaptor objects
4112 **
4113 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor
4114 ** @cc CVS Revision: 1.207
4115 ** @cc CVS Tag: branch-ensembl-68
4116 **
4117 ******************************************************************************/
4118 
4119 
4120 
4121 
4122 /* @funcstatic geneadaptorFetchAllbyStatement *********************************
4123 **
4124 ** Fetch all Ensembl Gene objects via an SQL statement.
4125 **
4126 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::_objs_from_sth
4127 ** @param [u] ba [EnsPBaseadaptor] Ensembl Base Adaptor
4128 ** @param [r] statement [const AjPStr] SQL statement
4129 ** @param [uN] am [EnsPAssemblymapper] Ensembl Assembly Mapper
4130 ** @param [uN] slice [EnsPSlice] Ensembl Slice
4131 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
4132 **
4133 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4134 **
4135 ** @release 6.4.0
4136 ** @@
4137 ** NOTE: In this implementation, the Ensembl Gene Adaptor does not LEFT JOIN
4138 ** the external_db table. Due to the rather small number of Ensembl External
4139 ** Database objects, potentially linked to a large number of Ensembl External
4140 ** Reference objects, all External Database objects are cached in the adaptor.
4141 ******************************************************************************/
4142 
geneadaptorFetchAllbyStatement(EnsPBaseadaptor ba,const AjPStr statement,EnsPAssemblymapper am,EnsPSlice slice,AjPList genes)4143 static AjBool geneadaptorFetchAllbyStatement(
4144     EnsPBaseadaptor ba,
4145     const AjPStr statement,
4146     EnsPAssemblymapper am,
4147     EnsPSlice slice,
4148     AjPList genes)
4149 {
4150     ajuint identifier = 0U;
4151     ajuint analysisid = 0U;
4152     ajuint erid       = 0U;
4153     ajuint edbid      = 0U;
4154 
4155     ajuint srid     = 0U;
4156     ajuint srstart  = 0U;
4157     ajuint srend    = 0U;
4158     ajint  srstrand = 0;
4159 
4160     ajuint cantrcid = 0U;
4161     ajuint version  = 0U;
4162 
4163     AjBool current = AJFALSE;
4164 
4165     EnsEGeneStatus estatus = ensEGeneStatusNULL;
4166 
4167     EnsEExternalreferenceInfotype erit = ensEExternalreferenceInfotypeNULL;
4168 
4169     AjPSqlstatement sqls = NULL;
4170     AjISqlrow sqli       = NULL;
4171     AjPSqlrow sqlr       = NULL;
4172 
4173     AjPStr description   = NULL;
4174     AjPStr source        = NULL;
4175     AjPStr biotype       = NULL;
4176     AjPStr status        = NULL;
4177     AjPStr canann        = NULL;
4178     AjPStr stableid      = NULL;
4179     AjPStr cdate         = NULL;
4180     AjPStr mdate         = NULL;
4181     AjPStr erprimaryid   = NULL;
4182     AjPStr erdisplayid   = NULL;
4183     AjPStr erversion     = NULL;
4184     AjPStr erdescription = NULL;
4185     AjPStr erinfotype    = NULL;
4186     AjPStr erinfotext    = NULL;
4187 
4188     EnsPDatabaseadaptor dba = NULL;
4189 
4190     EnsPDatabaseentry dbe = NULL;
4191 
4192     EnsPExternaldatabase edb         = NULL;
4193     EnsPExternaldatabaseadaptor edba = NULL;
4194 
4195     EnsPFeature feature = NULL;
4196 
4197     EnsPGene gene      = NULL;
4198     EnsPGeneadaptor ga = NULL;
4199 
4200     if (ajDebugTest("geneadaptorFetchAllbyStatement"))
4201         ajDebug("geneadaptorFetchAllbyStatement\n"
4202                 "  ba %p\n"
4203                 "  statement %p\n"
4204                 "  am %p\n"
4205                 "  slice %p\n"
4206                 "  genes %p\n",
4207                 ba,
4208                 statement,
4209                 am,
4210                 slice,
4211                 genes);
4212 
4213     if (!ba)
4214         return ajFalse;
4215 
4216     if (!statement)
4217         return ajFalse;
4218 
4219     if (!genes)
4220         return ajFalse;
4221 
4222     dba = ensBaseadaptorGetDatabaseadaptor(ba);
4223 
4224     edba = ensRegistryGetExternaldatabaseadaptor(dba);
4225     ga   = ensRegistryGetGeneadaptor(dba);
4226 
4227     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
4228 
4229     sqli = ajSqlrowiterNew(sqls);
4230 
4231     while (!ajSqlrowiterDone(sqli))
4232     {
4233         identifier    = 0U;
4234         srid          = 0U;
4235         srstart       = 0U;
4236         srend         = 0U;
4237         srstrand      = 0;
4238         analysisid    = 0U;
4239         erid          = 0U;
4240         description   = ajStrNew();
4241         source        = ajStrNew();
4242         biotype       = ajStrNew();
4243         status        = ajStrNew();
4244         current       = ajFalse;
4245         cantrcid      = 0U;
4246         canann        = ajStrNew();
4247         stableid      = ajStrNew();
4248         version       = 0U;
4249         cdate         = ajStrNew();
4250         mdate         = ajStrNew();
4251         edbid         = 0U;
4252         erprimaryid   = ajStrNew();
4253         erdisplayid   = ajStrNew();
4254         erversion     = ajStrNew();
4255         erdescription = ajStrNew();
4256         erinfotype    = ajStrNew();
4257         erinfotext    = ajStrNew();
4258 
4259         estatus = ensEGeneStatusNULL;
4260         erit    = ensEExternalreferenceInfotypeNULL;
4261 
4262         sqlr = ajSqlrowiterGet(sqli);
4263 
4264         ajSqlcolumnToUint(sqlr, &identifier);
4265         ajSqlcolumnToUint(sqlr, &srid);
4266         ajSqlcolumnToUint(sqlr, &srstart);
4267         ajSqlcolumnToUint(sqlr, &srend);
4268         ajSqlcolumnToInt(sqlr, &srstrand);
4269         ajSqlcolumnToUint(sqlr, &analysisid);
4270         ajSqlcolumnToUint(sqlr, &erid);
4271         ajSqlcolumnToStr(sqlr, &description);
4272         ajSqlcolumnToStr(sqlr, &source);
4273         ajSqlcolumnToStr(sqlr, &biotype);
4274         ajSqlcolumnToStr(sqlr, &status);
4275         ajSqlcolumnToBool(sqlr, &current);
4276         ajSqlcolumnToUint(sqlr, &cantrcid);
4277         ajSqlcolumnToStr(sqlr, &canann);
4278         ajSqlcolumnToStr(sqlr, &stableid);
4279         ajSqlcolumnToUint(sqlr, &version);
4280         ajSqlcolumnToStr(sqlr, &cdate);
4281         ajSqlcolumnToStr(sqlr, &mdate);
4282         ajSqlcolumnToUint(sqlr, &edbid);
4283         ajSqlcolumnToStr(sqlr, &erprimaryid);
4284         ajSqlcolumnToStr(sqlr, &erdisplayid);
4285         ajSqlcolumnToStr(sqlr, &erversion);
4286         ajSqlcolumnToStr(sqlr, &erdescription);
4287         ajSqlcolumnToStr(sqlr, &erinfotype);
4288         ajSqlcolumnToStr(sqlr, &erinfotext);
4289 
4290         ensBaseadaptorRetrieveFeature(ba,
4291                                       analysisid,
4292                                       srid,
4293                                       srstart,
4294                                       srend,
4295                                       srstrand,
4296                                       am,
4297                                       slice,
4298                                       &feature);
4299 
4300         if (!feature)
4301         {
4302             ajStrDel(&description);
4303             ajStrDel(&source);
4304             ajStrDel(&biotype);
4305             ajStrDel(&status);
4306             ajStrDel(&canann);
4307             ajStrDel(&stableid);
4308             ajStrDel(&cdate);
4309             ajStrDel(&mdate);
4310             ajStrDel(&erprimaryid);
4311             ajStrDel(&erdisplayid);
4312             ajStrDel(&erversion);
4313             ajStrDel(&erdescription);
4314             ajStrDel(&erinfotype);
4315             ajStrDel(&erinfotext);
4316 
4317             continue;
4318         }
4319 
4320         if (erid)
4321         {
4322             ensExternaldatabaseadaptorFetchByIdentifier(edba, edbid, &edb);
4323 
4324             erit = ensExternalreferenceInfotypeFromStr(erinfotype);
4325 
4326             if (!erit)
4327                 ajDebug("geneadaptorFetchAllbyStatement encountered "
4328                         "unexpected string '%S' in the "
4329                         "'xref.infotype' field.\n", erinfotype);
4330 
4331             dbe = ensDatabaseentryNewIni((EnsPDatabaseentryadaptor) NULL,
4332                                          erid,
4333                                          (EnsPAnalysis) NULL,
4334                                          edb,
4335                                          erprimaryid,
4336                                          erdisplayid,
4337                                          erversion,
4338                                          erdescription,
4339                                          (AjPStr) NULL,
4340                                          erinfotext,
4341                                          erit,
4342                                          ensEExternalreferenceObjecttypeGene,
4343                                          identifier);
4344 
4345             ensExternaldatabaseDel(&edb);
4346         }
4347 
4348         /* Set the Gene status. */
4349 
4350         estatus = ensGeneStatusFromStr(status);
4351 
4352         if (!estatus)
4353             ajDebug("geneadaptorFetchAllbyStatement encountered "
4354                     "unexpected string '%S' in the "
4355                     "'gene.status' field.\n", status);
4356 
4357         /* Finally, create a new Ensembl Gene. */
4358 
4359         gene = ensGeneNewIni(ga,
4360                              identifier,
4361                              feature,
4362                              dbe,
4363                              description,
4364                              source,
4365                              biotype,
4366                              estatus,
4367                              current,
4368                              cantrcid,
4369                              canann,
4370                              stableid,
4371                              version,
4372                              cdate,
4373                              mdate,
4374                              (AjPList) NULL);
4375 
4376         ajListPushAppend(genes, (void *) gene);
4377 
4378         ensDatabaseentryDel(&dbe);
4379 
4380         ensFeatureDel(&feature);
4381 
4382         ajStrDel(&description);
4383         ajStrDel(&source);
4384         ajStrDel(&biotype);
4385         ajStrDel(&status);
4386         ajStrDel(&canann);
4387         ajStrDel(&stableid);
4388         ajStrDel(&cdate);
4389         ajStrDel(&mdate);
4390         ajStrDel(&erprimaryid);
4391         ajStrDel(&erdisplayid);
4392         ajStrDel(&erversion);
4393         ajStrDel(&erdescription);
4394         ajStrDel(&erinfotype);
4395         ajStrDel(&erinfotext);
4396     }
4397 
4398     ajSqlrowiterDel(&sqli);
4399 
4400     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
4401 
4402     return ajTrue;
4403 }
4404 
4405 
4406 
4407 
4408 /* @section constructors ******************************************************
4409 **
4410 ** All constructors return a new Ensembl Gene Adaptor by pointer.
4411 ** It is the responsibility of the user to first destroy any previous
4412 ** Gene Adaptor. The target pointer does not need to be initialised to
4413 ** NULL, but it is good programming practice to do so anyway.
4414 **
4415 ** @fdata [EnsPGeneadaptor]
4416 **
4417 ** @nam3rule New Constructor
4418 **
4419 ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
4420 **
4421 ** @valrule * [EnsPGeneadaptor] Ensembl Gene Adaptor or NULL
4422 **
4423 ** @fcategory new
4424 ******************************************************************************/
4425 
4426 
4427 
4428 
4429 /* @func ensGeneadaptorNew ****************************************************
4430 **
4431 ** Default constructor for an Ensembl Gene Adaptor.
4432 **
4433 ** Ensembl Object Adaptors are singleton objects in the sense that a single
4434 ** instance of an Ensembl Object Adaptor connected to a particular database is
4435 ** sufficient to instantiate any number of Ensembl Objects from the database.
4436 ** Each Ensembl Object will have a weak reference to the Object Adaptor that
4437 ** instantiated it. Therefore, Ensembl Object Adaptors should not be
4438 ** instantiated directly, but rather obtained from the Ensembl Registry,
4439 ** which will in turn call this function if neccessary.
4440 **
4441 ** @see ensRegistryGetDatabaseadaptor
4442 ** @see ensRegistryGetGeneadaptor
4443 **
4444 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::new
4445 ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
4446 **
4447 ** @return [EnsPGeneadaptor] Ensembl Gene Adaptor or NULL
4448 **
4449 ** @release 6.2.0
4450 ** @@
4451 ******************************************************************************/
4452 
ensGeneadaptorNew(EnsPDatabaseadaptor dba)4453 EnsPGeneadaptor ensGeneadaptorNew(
4454     EnsPDatabaseadaptor dba)
4455 {
4456     return ensFeatureadaptorNew(
4457         dba,
4458         geneadaptorKTablenames,
4459         geneadaptorKColumnnames,
4460         geneadaptorKLeftjoins,
4461         (const char *) NULL,
4462         (const char *) NULL,
4463         &geneadaptorFetchAllbyStatement,
4464         (void *(*)(const void *)) NULL,
4465         (void *(*)(void *)) &ensGeneNewRef,
4466         (AjBool (*)(const void *)) NULL,
4467         (void (*)(void **)) &ensGeneDel,
4468         (size_t (*)(const void *)) &ensGeneCalculateMemsize,
4469         (EnsPFeature (*)(const void *)) &ensGeneGetFeature,
4470         "Gene");
4471 }
4472 
4473 
4474 
4475 
4476 /* @section destructors *******************************************************
4477 **
4478 ** Destruction destroys all internal data structures and frees the memory
4479 ** allocated for an Ensembl Gene Adaptor object.
4480 **
4481 ** @fdata [EnsPGeneadaptor]
4482 **
4483 ** @nam3rule Del Destroy (free) an Ensembl Gene Adaptor
4484 **
4485 ** @argrule * Pga [EnsPGeneadaptor*] Ensembl Gene Adaptor address
4486 **
4487 ** @valrule * [void]
4488 **
4489 ** @fcategory delete
4490 ******************************************************************************/
4491 
4492 
4493 
4494 
4495 /* @func ensGeneadaptorDel ****************************************************
4496 **
4497 ** Default destructor for an Ensembl Gene Adaptor.
4498 **
4499 ** Ensembl Object Adaptors are singleton objects that are registered in the
4500 ** Ensembl Registry and weakly referenced by Ensembl Objects that have been
4501 ** instantiated by it. Therefore, Ensembl Object Adaptors should never be
4502 ** destroyed directly. Upon exit, the Ensembl Registry will call this function
4503 ** if required.
4504 **
4505 ** @param [d] Pga [EnsPGeneadaptor*] Ensembl Gene Adaptor address
4506 **
4507 ** @return [void]
4508 **
4509 ** @release 6.2.0
4510 ** @@
4511 ******************************************************************************/
4512 
ensGeneadaptorDel(EnsPGeneadaptor * Pga)4513 void ensGeneadaptorDel(EnsPGeneadaptor *Pga)
4514 {
4515     ensFeatureadaptorDel(Pga);
4516 
4517     return;
4518 }
4519 
4520 
4521 
4522 
4523 /* @section member retrieval **************************************************
4524 **
4525 ** Functions for returning members of an Ensembl Gene Adaptor object.
4526 **
4527 ** @fdata [EnsPGeneadaptor]
4528 **
4529 ** @nam3rule Get Return Ensembl Gene Adaptor attribute(s)
4530 ** @nam4rule Baseadaptor Return the Ensembl Base Adaptor
4531 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
4532 ** @nam4rule Featureadaptor Return the Ensembl Feature Adaptor
4533 **
4534 ** @argrule * ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4535 **
4536 ** @valrule Baseadaptor [EnsPBaseadaptor]
4537 ** Ensembl Base Adaptor or NULL
4538 ** @valrule Databaseadaptor [EnsPDatabaseadaptor]
4539 ** Ensembl Database Adaptor or NULL
4540 ** @valrule Featureadaptor [EnsPFeatureadaptor]
4541 ** Ensembl Feature Adaptor or NULL
4542 **
4543 ** @fcategory use
4544 ******************************************************************************/
4545 
4546 
4547 
4548 
4549 /* @func ensGeneadaptorGetBaseadaptor *****************************************
4550 **
4551 ** Get the Ensembl Base Adaptor member of the
4552 ** Ensembl Feature Adaptor member of an Ensembl Gene Adaptor.
4553 **
4554 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4555 **
4556 ** @return [EnsPBaseadaptor] Ensembl Base Adaptor or NULL
4557 **
4558 ** @release 6.2.0
4559 ** @@
4560 ******************************************************************************/
4561 
ensGeneadaptorGetBaseadaptor(EnsPGeneadaptor ga)4562 EnsPBaseadaptor ensGeneadaptorGetBaseadaptor(
4563     EnsPGeneadaptor ga)
4564 {
4565     return ensFeatureadaptorGetBaseadaptor(
4566         ensGeneadaptorGetFeatureadaptor(ga));
4567 }
4568 
4569 
4570 
4571 
4572 /* @func ensGeneadaptorGetDatabaseadaptor *************************************
4573 **
4574 ** Get the Ensembl Database Adaptor member of the
4575 ** Ensembl Feature Adaptor member of an Ensembl Gene Adaptor.
4576 **
4577 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4578 **
4579 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
4580 **
4581 ** @release 6.2.0
4582 ** @@
4583 ******************************************************************************/
4584 
ensGeneadaptorGetDatabaseadaptor(EnsPGeneadaptor ga)4585 EnsPDatabaseadaptor ensGeneadaptorGetDatabaseadaptor(
4586     EnsPGeneadaptor ga)
4587 {
4588     return ensFeatureadaptorGetDatabaseadaptor(
4589         ensGeneadaptorGetFeatureadaptor(ga));
4590 }
4591 
4592 
4593 
4594 
4595 /* @func ensGeneadaptorGetFeatureadaptor **************************************
4596 **
4597 ** Get the Ensembl Feature Adaptor member of an Ensembl Gene Adaptor.
4598 **
4599 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4600 **
4601 ** @return [EnsPFeatureadaptor] Ensembl Feature Adaptor or NULL
4602 **
4603 ** @release 6.2.0
4604 ** @@
4605 ******************************************************************************/
4606 
ensGeneadaptorGetFeatureadaptor(EnsPGeneadaptor ga)4607 EnsPFeatureadaptor ensGeneadaptorGetFeatureadaptor(
4608     EnsPGeneadaptor ga)
4609 {
4610     return ga;
4611 }
4612 
4613 
4614 
4615 
4616 /* @section object retrieval **************************************************
4617 **
4618 ** Functions for fetching Ensembl Gene objects from an
4619 ** Ensembl SQL database.
4620 **
4621 ** @fdata [EnsPGeneadaptor]
4622 **
4623 ** @nam3rule Fetch Fetch Ensembl Gene object(s)
4624 ** @nam4rule All Fetch all Ensembl Gene objects
4625 ** @nam4rule Allby Fetch all Ensembl Gene objects matching a criterion
4626 ** @nam5rule Biotype Fetch all by biological type
4627 ** @nam5rule Displaylabel Fetch all by display label
4628 ** @nam5rule Externalname Fetch all by an external name
4629 ** @nam5rule Identifiers Fetch all by an AJAX Table
4630 ** @nam5rule Slice   Fetch all by an Ensembl Slice
4631 ** @nam5rule Stableidentifier Fetch all by an Ensembl Gene stable identifier
4632 ** @nam4rule By Fetch one Ensembl Gene object matching a criterion
4633 ** @nam5rule Displaylabel
4634 ** Fetch by a display label
4635 ** @nam5rule Exonidentifier
4636 ** Fetch by an Ensembl Exon identifier
4637 ** @nam5rule Exonstableidentifier
4638 ** Fetch by an Ensembl Exon stable identifier
4639 ** @nam5rule Externaldatabasename
4640 ** Fetch by an Ensembl External Database name
4641 ** @nam5rule Externalname
4642 ** Fetch by an Ensembl Database Entry name
4643 ** @nam5rule Identifier
4644 ** Fetch by SQL database-internal identifier
4645 ** @nam5rule Stableidentifier
4646 ** Fetch by an Ensembl Gene stable identifier
4647 ** @nam5rule Transcriptidentifier
4648 ** Fetch by an Ensembl Transcript identifier
4649 ** @nam5rule Transcriptstableidentifier
4650 ** Fetch by an Ensembl Transcript stable identifier
4651 ** @nam5rule Translationidentifier
4652 ** Fetch by an Ensembl Translation identifier
4653 ** @nam5rule Translationstableidentifier
4654 ** Fetch by an Ensembl Translation stable identifier
4655 **
4656 ** @argrule * ga [EnsPGeneadaptor]
4657 ** Ensembl Gene Adaptor
4658 ** @argrule All genes [AjPList]
4659 ** AJAX List of Ensembl Gene objects
4660 ** @argrule AllbyBiotype biotype [const AjPStr]
4661 ** Biotype
4662 ** @argrule AllbyBiotype genes [AjPList]
4663 ** AJAX List of Ensembl Gene objects
4664 ** @argrule AllbyDisplaylabel label [const AjPStr]
4665 ** Display label
4666 ** @argrule AllbyDisplaylabel genes [AjPList]
4667 ** AJAX List of Ensembl Gene objects
4668 ** @argrule AllbyExternaldatabasename dbname [const AjPStr]
4669 ** Ensembl External Database name
4670 ** @argrule AllbyExternaldatabasename genes [AjPList]
4671 ** AJAX List of Ensembl Gene objects
4672 ** @argrule AllbyExternalname name [const AjPStr]
4673 ** Ensembl Database Entry name
4674 ** @argrule AllbyExternalname dbname [const AjPStr]
4675 ** Ensembl External Database name
4676 ** @argrule AllbyExternalname override [AjBool]
4677 ** Override optimisation of '_' SQL any
4678 ** @argrule AllbyExternalname genes [AjPList]
4679 ** AJAX List of Ensembl Gene objects
4680 ** @argrule AllbyIdentifiers genes [AjPTable]
4681 ** AJAX Table of Ensembl Gene objects
4682 ** @argrule AllbySlice slice [EnsPSlice]
4683 ** Ensembl Slice
4684 ** @argrule AllbySlice anname [const AjPStr]
4685 ** Ensembl Analysis name
4686 ** @argrule AllbySlice source [const AjPStr]
4687 ** Source name
4688 ** @argrule AllbySlice biotype [const AjPStr]
4689 ** Biotype name
4690 ** @argrule AllbySlice loadtranscripts [AjBool]
4691 ** Load Ensembl Transcript objects
4692 ** @argrule AllbySlice genes [AjPList]
4693 ** AJAX List of Ensembl Gene objects
4694 ** @argrule AllbyStableidentifier stableid [const AjPStr]
4695 ** Ensembl Gene stable identifier
4696 ** @argrule AllbyStableidentifier genes [AjPList]
4697 ** AJAX List of Ensembl Gene objects
4698 ** @argrule ByDisplaylabel label [const AjPStr] Display label
4699 ** @argrule ByExonidentifier identifier [ajuint]
4700 ** Ensembl Exon identifier
4701 ** @argrule ByExonstableidentifier stableid [const AjPStr]
4702 ** Ensembl Exon stable identifier
4703 ** @argrule ByIdentifier identifier [ajuint]
4704 ** SQL database-internal identifier
4705 ** @argrule ByStableidentifier stableid [const AjPStr]
4706 ** Ensembl Gene stable identifier
4707 ** @argrule ByStableidentifier version [ajuint]
4708 ** Version
4709 ** @argrule ByTranscriptidentifier identifier [ajuint]
4710 ** Ensembl Transcript identifier
4711 ** @argrule ByTranscriptstableidentifier stableid [const AjPStr]
4712 ** Ensembl Transcript stable identifier
4713 ** @argrule ByTranslationidentifier identifier [ajuint]
4714 ** Ensembl Translation identifier
4715 ** @argrule ByTranslationstableidentifier stableid [const AjPStr]
4716 ** Ensembl Translation stable identifier
4717 ** @argrule By Pgene [EnsPGene*] Ensembl Gene address
4718 **
4719 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
4720 **
4721 ** @fcategory use
4722 ******************************************************************************/
4723 
4724 
4725 
4726 
4727 /* @func ensGeneadaptorFetchAll ***********************************************
4728 **
4729 ** Fetch all Ensembl Gene objects.
4730 **
4731 ** The caller is responsible for deleting the Ensembl Gene objects
4732 ** before deleting the AJAX List.
4733 **
4734 ** @cc Bio::EnsEMBL::DBSQL::BaseAdaptor::fetch_all
4735 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4736 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
4737 **
4738 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4739 **
4740 ** @release 6.2.0
4741 ** @@
4742 ******************************************************************************/
4743 
ensGeneadaptorFetchAll(EnsPGeneadaptor ga,AjPList genes)4744 AjBool ensGeneadaptorFetchAll(
4745     EnsPGeneadaptor ga,
4746     AjPList genes)
4747 {
4748     AjBool result = AJFALSE;
4749 
4750     AjPStr constraint = NULL;
4751 
4752     if (!ga)
4753         return ajFalse;
4754 
4755     if (!genes)
4756         return ajFalse;
4757 
4758     constraint = ajStrNewC(
4759         "gene.biotype != 'LRG_gene' "
4760         "AND "
4761         "gene.is_current = 1");
4762 
4763     result = ensBaseadaptorFetchAllbyConstraint(
4764         ensGeneadaptorGetBaseadaptor(ga),
4765         constraint,
4766         (EnsPAssemblymapper) NULL,
4767         (EnsPSlice) NULL,
4768         genes);
4769 
4770     ajStrDel(&constraint);
4771 
4772     return result;
4773 }
4774 
4775 
4776 
4777 
4778 /* @func ensGeneadaptorFetchAllbyBiotype **************************************
4779 **
4780 ** Fetch all Ensembl Gene objects via a biotype.
4781 **
4782 ** The caller is responsible for deleting the Ensembl Gene objects
4783 ** before deleting the AJAX List.
4784 **
4785 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_all_by_biotype
4786 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4787 ** @param [r] biotype [const AjPStr] Biotype
4788 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
4789 **
4790 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4791 **
4792 ** @release 6.4.0
4793 ** @@
4794 ******************************************************************************/
4795 
ensGeneadaptorFetchAllbyBiotype(EnsPGeneadaptor ga,const AjPStr biotype,AjPList genes)4796 AjBool ensGeneadaptorFetchAllbyBiotype(
4797     EnsPGeneadaptor ga,
4798     const AjPStr biotype,
4799     AjPList genes)
4800 {
4801     char *txtbiotype = NULL;
4802 
4803     AjBool result = AJFALSE;
4804 
4805     AjPStr constraint = NULL;
4806 
4807     EnsPBaseadaptor ba = NULL;
4808 
4809     if (!ga)
4810         return ajFalse;
4811 
4812     if (!biotype)
4813         return ajFalse;
4814 
4815     if (!genes)
4816         return ajFalse;
4817 
4818     ba = ensGeneadaptorGetBaseadaptor(ga);
4819 
4820     ensBaseadaptorEscapeC(ba, &txtbiotype, biotype);
4821 
4822     constraint = ajFmtStr(
4823         "gene.is_current = 1 "
4824         "AND "
4825         "gene.biotype = '%s'",
4826         txtbiotype);
4827 
4828     ajCharDel(&txtbiotype);
4829 
4830     result = ensBaseadaptorFetchAllbyConstraint(
4831         ba,
4832         constraint,
4833         (EnsPAssemblymapper) NULL,
4834         (EnsPSlice) NULL,
4835         genes);
4836 
4837     ajStrDel(&constraint);
4838 
4839     return result;
4840 }
4841 
4842 
4843 
4844 
4845 /* @func ensGeneadaptorFetchAllbyDisplaylabel *********************************
4846 **
4847 ** Fetch all Ensembl Gene objects via a display label.
4848 **
4849 ** The caller is responsible for deleting the Ensembl Gene objects
4850 ** before deleting the AJAX List.
4851 **
4852 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_all_by_display_label
4853 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4854 ** @param [r] label [const AjPStr] Display label
4855 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
4856 **
4857 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4858 **
4859 ** @release 6.5.0
4860 ** @@
4861 ******************************************************************************/
4862 
ensGeneadaptorFetchAllbyDisplaylabel(EnsPGeneadaptor ga,const AjPStr label,AjPList genes)4863 AjBool ensGeneadaptorFetchAllbyDisplaylabel(
4864     EnsPGeneadaptor ga,
4865     const AjPStr label,
4866     AjPList genes)
4867 {
4868     char *txtlabel = NULL;
4869 
4870     AjBool result = AJFALSE;
4871 
4872     AjPStr constraint = NULL;
4873 
4874     EnsPBaseadaptor ba = NULL;
4875 
4876     if (!ga)
4877         return ajFalse;
4878 
4879     if (!label)
4880         return ajFalse;
4881 
4882     if (!genes)
4883         return ajFalse;
4884 
4885     ba = ensGeneadaptorGetBaseadaptor(ga);
4886 
4887     ensBaseadaptorEscapeC(ba, &txtlabel, label);
4888 
4889     constraint = ajFmtStr(
4890         "gene.is_current = 1 "
4891         "AND "
4892         "xref.display_label = '%s'",
4893         txtlabel);
4894 
4895     ajCharDel(&txtlabel);
4896 
4897     result = ensBaseadaptorFetchAllbyConstraint(
4898         ba,
4899         constraint,
4900         (EnsPAssemblymapper) NULL,
4901         (EnsPSlice) NULL,
4902         genes);
4903 
4904     ajStrDel(&constraint);
4905 
4906     return result;
4907 }
4908 
4909 
4910 
4911 
4912 /* @func ensGeneadaptorFetchAllbyExternaldatabasename *************************
4913 **
4914 ** Fetch all Ensembl Gene objects via an Ensembl External Database name.
4915 **
4916 ** The caller is responsible for deleting the Ensembl Gene objects
4917 ** before deleting the AJAX List.
4918 **
4919 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4920 ** @param [r] dbname [const AjPStr] Ensembl External Database name
4921 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
4922 **
4923 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4924 **
4925 ** @release 6.6.0
4926 ** @@
4927 ******************************************************************************/
4928 
ensGeneadaptorFetchAllbyExternaldatabasename(EnsPGeneadaptor ga,const AjPStr dbname,AjPList genes)4929 AjBool ensGeneadaptorFetchAllbyExternaldatabasename(
4930     EnsPGeneadaptor ga,
4931     const AjPStr dbname,
4932     AjPList genes)
4933 {
4934     AjBool result = AJFALSE;
4935 
4936     AjPTable table = NULL;
4937 
4938     if (!ga)
4939         return ajFalse;
4940 
4941     if (!dbname)
4942         return ajFalse;
4943 
4944     if (!genes)
4945         return ajFalse;
4946 
4947     table = ajTableuintNew(0U);
4948 
4949     ajTableSetDestroyvalue(table, (void (*)(void **)) &ensGeneDel);
4950 
4951     result = ensDatabaseentryadaptorRetrieveAllGeneidentifiersByExternaldatabasename(
4952         ensRegistryGetDatabaseentryadaptor(
4953             ensGeneadaptorGetDatabaseadaptor(ga)),
4954         dbname,
4955         table);
4956 
4957     result = ensGeneadaptorFetchAllbyIdentifiers(ga, table);
4958 
4959     ensTableuintToList(table, genes);
4960 
4961     ajTableFree(&table);
4962 
4963     return result;
4964 }
4965 
4966 
4967 
4968 
4969 /* @func ensGeneadaptorFetchAllbyExternalname *********************************
4970 **
4971 ** Fetch all Ensembl Gene objects via an Ensembl Database Entry name and
4972 ** Ensembl External Database name.
4973 **
4974 ** The caller is responsible for deleting the Ensembl Gene objects
4975 ** before deleting the AJAX List.
4976 **
4977 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_all_by_external_name
4978 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
4979 ** @param [r] name [const AjPStr] Ensembl Database Entry name
4980 ** @param [rN] dbname [const AjPStr] Ensembl External Database name
4981 ** @param [r] override [AjBool] Override optimisation of '_' SQL any
4982 ** @param [u] genes [AjPList] AJAX List of Ensembl Gene objects
4983 **
4984 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
4985 **
4986 ** @release 6.6.0
4987 ** @@
4988 ******************************************************************************/
4989 
ensGeneadaptorFetchAllbyExternalname(EnsPGeneadaptor ga,const AjPStr name,const AjPStr dbname,AjBool override,AjPList genes)4990 AjBool ensGeneadaptorFetchAllbyExternalname(
4991     EnsPGeneadaptor ga,
4992     const AjPStr name,
4993     const AjPStr dbname,
4994     AjBool override,
4995     AjPList genes)
4996 {
4997     AjBool result = AJFALSE;
4998 
4999     AjPTable table = NULL;
5000 
5001     if (!ga)
5002         return ajFalse;
5003 
5004     if (!name)
5005         return ajFalse;
5006 
5007     if (!genes)
5008         return ajFalse;
5009 
5010     table = ajTableuintNew(0U);
5011 
5012     ajTableSetDestroyvalue(table, (void (*)(void **)) &ensGeneDel);
5013 
5014     result = ensDatabaseentryadaptorRetrieveAllGeneidentifiersByExternalname(
5015         ensRegistryGetDatabaseentryadaptor(
5016             ensGeneadaptorGetDatabaseadaptor(ga)),
5017         name,
5018         dbname,
5019         override,
5020         table);
5021 
5022     result = ensGeneadaptorFetchAllbyIdentifiers(ga, table);
5023 
5024     ensTableuintToList(table, genes);
5025 
5026     ajTableFree(&table);
5027 
5028     return result;
5029 }
5030 
5031 
5032 
5033 
5034 /* @func ensGeneadaptorFetchAllbyIdentifiers **********************************
5035 **
5036 ** Fetch all Ensembl Gene objects by an AJAX Table of
5037 ** AJAX unsigned integer key data and assign them as value data.
5038 **
5039 ** The caller is responsible for deleting the AJAX unsigned integer key and
5040 ** Ensembl Gene value data before deleting the AJAX Table.
5041 **
5042 ** @cc Bio::EnsEMBL::DBSQL::BaseAdaptor::fetch_all_by_dbID_list
5043 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5044 ** @param [u] genes [AjPTable]
5045 ** AJAX Table of
5046 ** AJAX unsigned integer key data and
5047 ** Ensembl Gene value data
5048 **
5049 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5050 **
5051 ** @release 6.4.0
5052 ** @@
5053 ******************************************************************************/
5054 
ensGeneadaptorFetchAllbyIdentifiers(EnsPGeneadaptor ga,AjPTable genes)5055 AjBool ensGeneadaptorFetchAllbyIdentifiers(
5056     EnsPGeneadaptor ga,
5057     AjPTable genes)
5058 {
5059     return ensBaseadaptorFetchAllbyIdentifiers(
5060         ensGeneadaptorGetBaseadaptor(ga),
5061         (EnsPSlice) NULL,
5062         (ajuint (*)(const void *)) &ensGeneGetIdentifier,
5063         genes);
5064 }
5065 
5066 
5067 
5068 
5069 /* @func ensGeneadaptorFetchAllbySlice ****************************************
5070 **
5071 ** Fetch all Ensembl Genes via an Ensembl Slice.
5072 **
5073 ** The caller is responsible for deleting the Ensembl Genes before
5074 ** deleting the AJAX List.
5075 **
5076 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_all_by_Slice
5077 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5078 ** @param [u] slice [EnsPSlice] Ensembl Slice
5079 ** @param [r] anname [const AjPStr] Ensembl Analysis name
5080 ** @param [r] source [const AjPStr] Source name
5081 ** @param [r] biotype [const AjPStr] Biotype name
5082 ** @param [r] loadtranscripts [AjBool] Load Ensembl Transcript objects
5083 ** @param [u] genes [AjPList] AJAX List of Ensembl Genes
5084 **
5085 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5086 **
5087 ** @release 6.4.0
5088 ** @@
5089 ******************************************************************************/
5090 
ensGeneadaptorFetchAllbySlice(EnsPGeneadaptor ga,EnsPSlice slice,const AjPStr anname,const AjPStr source,const AjPStr biotype,AjBool loadtranscripts,AjPList genes)5091 AjBool ensGeneadaptorFetchAllbySlice(
5092     EnsPGeneadaptor ga,
5093     EnsPSlice slice,
5094     const AjPStr anname,
5095     const AjPStr source,
5096     const AjPStr biotype,
5097     AjBool loadtranscripts,
5098     AjPList genes)
5099 {
5100     void **keyarray = NULL;
5101 
5102     char *txtsource  = NULL;
5103     char *txtbiotype = NULL;
5104 
5105     ajint start = INT_MAX;
5106     ajint end   = INT_MIN;
5107 
5108     register ajuint i = 0U;
5109 
5110     ajuint gnid = 0U;
5111     ajuint trid = 0U;
5112 
5113     ajuint *Pidentifier = NULL;
5114 
5115     AjIList iter        = NULL;
5116     AjPList transcripts = NULL;
5117 
5118     AjPSqlstatement sqls = NULL;
5119     AjISqlrow sqli       = NULL;
5120     AjPSqlrow sqlr       = NULL;
5121 
5122     AjPStr constraint = NULL;
5123     AjPStr csv        = NULL;
5124     AjPStr statement  = NULL;
5125 
5126     AjPTable gntable = NULL;
5127     AjPTable trtable = NULL;
5128 
5129     EnsPDatabaseadaptor dba = NULL;
5130 
5131     EnsPFeature feature = NULL;
5132 
5133     EnsPGene gene = NULL;
5134 
5135     EnsPSlice newslice   = NULL;
5136     EnsPSliceadaptor sla = NULL;
5137 
5138     EnsPTranscript oldtranscript = NULL;
5139     EnsPTranscript newtranscript = NULL;
5140     EnsPTranscriptadaptor tca    = NULL;
5141 
5142     if (!ga)
5143         return ajFalse;
5144 
5145     if (!slice)
5146         return ajFalse;
5147 
5148     if (!genes)
5149         return ajFalse;
5150 
5151     dba = ensGeneadaptorGetDatabaseadaptor(ga);
5152 
5153     constraint = ajStrNewC("gene.is_current = 1");
5154 
5155     if (source && ajStrGetLen(source))
5156     {
5157         ensDatabaseadaptorEscapeC(dba, &txtsource, source);
5158 
5159         ajFmtPrintAppS(&constraint, " AND gene.source = '%s'", txtsource);
5160 
5161         ajCharDel(&txtsource);
5162     }
5163 
5164     if (biotype && ajStrGetLen(biotype))
5165     {
5166         ensDatabaseadaptorEscapeC(dba, &txtbiotype, biotype);
5167 
5168         ajFmtPrintAppS(&constraint, " AND gene.biotype = '%s'", txtbiotype);
5169 
5170         ajCharDel(&txtbiotype);
5171     }
5172 
5173     ensFeatureadaptorFetchAllbySlice(
5174         ensGeneadaptorGetFeatureadaptor(ga),
5175         slice,
5176         constraint,
5177         anname,
5178         genes);
5179 
5180     ajStrDel(&constraint);
5181 
5182     /* If there are less than two genes, still do lazy-loading. */
5183 
5184     if ((!loadtranscripts) || (ajListGetLength(genes) == 0U))
5185         return ajTrue;
5186 
5187     /*
5188     ** Preload all Ensembl Transcript objects now, instead of lazy loading
5189     ** later, which is faster than one query per Ensembl Transcript.
5190     ** First check if Ensembl Transcript objects are already preloaded.
5191     ** TODO: This should check all Ensembl Transcript objects.
5192     */
5193 
5194     ajListPeekFirst(genes, (void **) &gene);
5195 
5196     if (gene->Transcripts)
5197         return ajTrue;
5198 
5199     tca = ensRegistryGetTranscriptadaptor(dba);
5200 
5201     sla = ensRegistryGetSliceadaptor(dba);
5202 
5203     /* Get the extent of the region spanned by Ensembl Transcript objects. */
5204 
5205     csv = ajStrNew();
5206 
5207     gntable = ajTableuintNew(ajListGetLength(genes));
5208     trtable = ajTableuintNew(ajListGetLength(genes));
5209 
5210     ajTableSetDestroyvalue(gntable, (void (*)(void **)) &ensGeneDel);
5211     ajTableSetDestroyvalue(trtable, (void (*)(void **)) &ensGeneDel);
5212 
5213     iter = ajListIterNew(genes);
5214 
5215     while (!ajListIterDone(iter))
5216     {
5217         gene = (EnsPGene) ajListIterGet(iter);
5218 
5219         gnid = ensGeneGetIdentifier(gene);
5220 
5221         feature = ensGeneGetFeature(gene);
5222 
5223         start = (ensFeatureGetSeqregionStart(feature) < start) ?
5224             ensFeatureGetSeqregionStart(feature) : start;
5225 
5226         end = (ensFeatureGetSeqregionEnd(feature) > end) ?
5227             ensFeatureGetSeqregionEnd(feature) : end;
5228 
5229         ajFmtPrintAppS(&csv, "%u, ", gnid);
5230 
5231         /*
5232         ** Put all Ensembl Genes into an AJAX Table indexed by their
5233         ** identifier.
5234         */
5235 
5236         if (ajTableMatchV(gntable, (const void *) &gnid))
5237             ajDebug("ensGeneadaptorFetchAllbySlice got duplicate "
5238                     "Ensembl Gene objects with identifier %u.\n", gnid);
5239         else
5240         {
5241             AJNEW0(Pidentifier);
5242 
5243             *Pidentifier = gnid;
5244 
5245             ajTablePut(gntable,
5246                        (void *) Pidentifier,
5247                        (void *) ensGeneNewRef(gene));
5248         }
5249     }
5250 
5251     ajListIterDel(&iter);
5252 
5253     /* Remove the last comma and space from the comma-separated values. */
5254 
5255     ajStrCutEnd(&csv, 2);
5256 
5257     if ((start >= ensSliceGetStart(slice)) && (end <= ensSliceGetEnd(slice)))
5258         newslice = ensSliceNewRef(slice);
5259     else
5260         ensSliceadaptorFetchBySlice(sla,
5261                                     slice,
5262                                     start,
5263                                     end,
5264                                     ensSliceGetStrand(slice),
5265                                     &newslice);
5266 
5267     /* Associate Ensembl Transcript identifiers with Ensembl Genes. */
5268 
5269     statement = ajFmtStr(
5270         "SELECT "
5271         "transcript.transcript_id, "
5272         "transcript.gene_id "
5273         "FROM "
5274         "transcript "
5275         "WHERE "
5276         "transcript.gene_id IN (%S)",
5277         csv);
5278 
5279     ajStrAssignClear(&csv);
5280 
5281     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
5282 
5283     sqli = ajSqlrowiterNew(sqls);
5284 
5285     while (!ajSqlrowiterDone(sqli))
5286     {
5287         trid = 0U;
5288         gnid = 0U;
5289 
5290         sqlr = ajSqlrowiterGet(sqli);
5291 
5292         ajSqlcolumnToUint(sqlr, &trid);
5293         ajSqlcolumnToUint(sqlr, &gnid);
5294 
5295         if (ajTableMatchV(trtable, (const void *) &trid))
5296         {
5297             ajDebug("ensGeneadaptorFetchAllbySlice got duplicate "
5298                     "Ensembl Transcript objects with identifier %u "
5299                     "for Ensembl Gene with identifier %u.\n",
5300                     trid, gnid);
5301 
5302             continue;
5303         }
5304 
5305         gene = (EnsPGene) ajTableFetchmodV(gntable, (const void *) &gnid);
5306 
5307         if (gene)
5308         {
5309             AJNEW0(Pidentifier);
5310 
5311             *Pidentifier = trid;
5312 
5313             ajTablePut(trtable,
5314                        (void *) Pidentifier,
5315                        (void *) ensGeneNewRef(gene));
5316         }
5317         else
5318             ajDebug("ensGeneadaptorFetchAllbySlice could not fetch "
5319                     "Ensembl Gene with identifier %u for "
5320                     "Ensembl Transcript with identifier %u.\n",
5321                     gnid, trid);
5322     }
5323 
5324     ajSqlrowiterDel(&sqli);
5325 
5326     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
5327 
5328     ajStrDel(&statement);
5329 
5330     /* Get all Ensembl Transcript identifiers as comma-separated values. */
5331 
5332     ajTableToarrayKeys(trtable, &keyarray);
5333 
5334     for (i = 0U; keyarray[i]; i++)
5335         ajFmtPrintAppS(&csv, "%u, ", *((ajuint *) keyarray[i]));
5336 
5337     AJFREE(keyarray);
5338 
5339     /* Remove the last comma and space from the comma-separated values. */
5340 
5341     ajStrCutEnd(&csv, 2);
5342 
5343     constraint = ajFmtStr("transcript.transcript_id IN (%S)", csv);
5344 
5345     ajStrDel(&csv);
5346 
5347     transcripts = ajListNew();
5348 
5349     ensTranscriptadaptorFetchAllbySlice(tca,
5350                                         newslice,
5351                                         anname,
5352                                         constraint,
5353                                         ajTrue,
5354                                         transcripts);
5355 
5356     ajStrDel(&constraint);
5357 
5358     /*
5359     ** Transfer Ensembl Transcript objects onto the Gene Slice, and add them
5360     ** to Gene objects.
5361     */
5362 
5363     while (ajListPop(transcripts, (void **) &oldtranscript))
5364     {
5365         newtranscript = ensTranscriptTransfer(oldtranscript, newslice);
5366 
5367         if (!newtranscript)
5368             ajFatal("ensGeneAdaptorFetchAllbySlice could not transfer "
5369                     "Transcript onto new Slice.\n");
5370 
5371         trid = ensTranscriptGetIdentifier(newtranscript);
5372 
5373         gene = (EnsPGene) ajTableFetchmodV(trtable, (const void *) &trid);
5374 
5375         ensGeneAddTranscript(gene, newtranscript);
5376 
5377         ensTranscriptDel(&newtranscript);
5378         ensTranscriptDel(&oldtranscript);
5379     }
5380 
5381     ajListFree(&transcripts);
5382 
5383     /*
5384     ** Clear and delete the AJAX Table objects of
5385     ** AJAX unsigned integer key (Gene and Transcript identifier) and
5386     ** Ensembl Gene value data.
5387     */
5388 
5389     ajTableDel(&gntable);
5390     ajTableDel(&trtable);
5391 
5392     ensSliceDel(&newslice);
5393 
5394     return ajTrue;
5395 }
5396 
5397 
5398 
5399 
5400 /* @func ensGeneadaptorFetchAllbyStableidentifier *****************************
5401 **
5402 ** Fetch all Ensembl Genes of all version via an
5403 ** Ensembl Gene stable identifier.
5404 **
5405 ** The caller is responsible for deleting the Ensembl Genes before deleting
5406 ** the AJAX List.
5407 **
5408 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_all_versions_by_stable_id
5409 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5410 ** @param [r] stableid [const AjPStr] Ensembl Gene stable identifier
5411 ** @param [u] genes [AjPList] AJAX List of Ensembl Genes
5412 **
5413 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5414 **
5415 ** @release 6.4.0
5416 ** @@
5417 ******************************************************************************/
5418 
ensGeneadaptorFetchAllbyStableidentifier(EnsPGeneadaptor ga,const AjPStr stableid,AjPList genes)5419 AjBool ensGeneadaptorFetchAllbyStableidentifier(
5420     EnsPGeneadaptor ga,
5421     const AjPStr stableid,
5422     AjPList genes)
5423 {
5424     char *txtstableid = NULL;
5425 
5426     AjBool result = AJFALSE;
5427 
5428     AjPStr constraint = NULL;
5429 
5430     EnsPBaseadaptor ba = NULL;
5431 
5432     if (!ga)
5433         return ajFalse;
5434 
5435     if (!stableid)
5436         return ajFalse;
5437 
5438     if (!genes)
5439         return ajFalse;
5440 
5441     ba = ensGeneadaptorGetBaseadaptor(ga);
5442 
5443     ensBaseadaptorEscapeC(ba, &txtstableid, stableid);
5444 
5445     constraint = ajFmtStr("gene.stable_id = '%s'", txtstableid);
5446 
5447     ajCharDel(&txtstableid);
5448 
5449     result = ensBaseadaptorFetchAllbyConstraint(
5450         ba,
5451         constraint,
5452         (EnsPAssemblymapper) NULL,
5453         (EnsPSlice) NULL,
5454         genes);
5455 
5456     ajStrDel(&constraint);
5457 
5458     return result;
5459 }
5460 
5461 
5462 
5463 
5464 /* @func ensGeneadaptorFetchByDisplaylabel ************************************
5465 **
5466 ** Fetch an Ensembl Gene via its display label.
5467 **
5468 ** The caller is responsible for deleting the Ensembl Gene.
5469 **
5470 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_by_display_label
5471 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5472 ** @param [r] label [const AjPStr] Display label
5473 ** @param [wP] Pgene [EnsPGene*] Ensembl Gene address
5474 **
5475 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5476 **
5477 ** @release 6.4.0
5478 ** @@
5479 ******************************************************************************/
5480 
ensGeneadaptorFetchByDisplaylabel(EnsPGeneadaptor ga,const AjPStr label,EnsPGene * Pgene)5481 AjBool ensGeneadaptorFetchByDisplaylabel(
5482     EnsPGeneadaptor ga,
5483     const AjPStr label,
5484     EnsPGene *Pgene)
5485 {
5486     char *txtlabel = NULL;
5487 
5488     AjBool nonref = AJFALSE;
5489     AjBool result = AJFALSE;
5490 
5491     AjIList iter = NULL;
5492 
5493     AjPList genes = NULL;
5494 
5495     AjPStr constraint = NULL;
5496 
5497     EnsPBaseadaptor ba = NULL;
5498 
5499     EnsPGene gene = NULL;
5500 
5501     if (!ga)
5502         return ajFalse;
5503 
5504     if (!label)
5505         return ajFalse;
5506 
5507     if (!Pgene)
5508         return ajFalse;
5509 
5510     *Pgene = NULL;
5511 
5512     ba = ensGeneadaptorGetBaseadaptor(ga);
5513 
5514     ensBaseadaptorEscapeC(ba, &txtlabel, label);
5515 
5516     constraint = ajFmtStr(
5517         "gene.is_current = 1 "
5518         "AND "
5519         "xref.display_label = '%s'",
5520         txtlabel);
5521 
5522     ajCharDel(&txtlabel);
5523 
5524     genes = ajListNew();
5525 
5526     result = ensBaseadaptorFetchAllbyConstraint(
5527         ba,
5528         constraint,
5529         (EnsPAssemblymapper) NULL,
5530         (EnsPSlice) NULL,
5531         genes);
5532 
5533     if (ajListGetLength(genes) > 1)
5534         ajDebug("ensGeneadaptorFetchByDisplaylabel got more than one "
5535                 "Ensembl Gene objects for display label '%S'.\n", label);
5536 
5537     /*
5538     ** Since more than one Ensembl Gene object may be obtained,
5539     ** find the one linked to a reference Ensembl Slice object
5540     ** (or not linked to a non-refrence Ensembl Slice object).
5541     */
5542 
5543     iter = ajListIterNew(genes);
5544 
5545     while (!ajListIterDone(iter))
5546     {
5547         gene = (EnsPGene) ajListIterGet(iter);
5548 
5549         ensSliceIsNonreference(ensFeatureGetSlice(ensGeneGetFeature(gene)),
5550                                &nonref);
5551 
5552         if (nonref == ajFalse)
5553             *Pgene = ensGeneNewRef(gene);
5554     }
5555 
5556     ajListIterDel(&iter);
5557 
5558     if (!*Pgene)
5559     {
5560         ajListPeekFirst(genes, (void **) Pgene);
5561 
5562         ensGeneNewRef(*Pgene);
5563     }
5564 
5565     /* Clear the remaining AJAX List of Ensembl Gene objects. */
5566 
5567     ajListPop(genes, (void **) Pgene);
5568 
5569     while (ajListPop(genes, (void **) &gene))
5570         ensGeneDel(&gene);
5571 
5572     ajListFree(&genes);
5573 
5574     ajStrDel(&constraint);
5575 
5576     return result;
5577 }
5578 
5579 
5580 
5581 
5582 /* @func ensGeneadaptorFetchByExonidentifier **********************************
5583 **
5584 ** Fetch an Ensembl Gene via an Ensembl Exon identifier.
5585 ** The caller is responsible for deleting the Ensembl Gene.
5586 **
5587 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_by_exon_id
5588 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5589 ** @param [r] identifier [ajuint] Ensembl Exon identifier
5590 ** @param [wP] Pgene [EnsPGene*] Ensembl Gene address
5591 **
5592 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5593 **
5594 ** @release 6.4.0
5595 ** @@
5596 ******************************************************************************/
5597 
ensGeneadaptorFetchByExonidentifier(EnsPGeneadaptor ga,ajuint identifier,EnsPGene * Pgene)5598 AjBool ensGeneadaptorFetchByExonidentifier(
5599     EnsPGeneadaptor ga,
5600     ajuint identifier,
5601     EnsPGene *Pgene)
5602 {
5603     ajuint gid = 0U;
5604 
5605     AjPSqlstatement sqls = NULL;
5606     AjISqlrow sqli       = NULL;
5607     AjPSqlrow sqlr       = NULL;
5608 
5609     AjPStr statement = NULL;
5610 
5611     EnsPDatabaseadaptor dba = NULL;
5612 
5613     if (!ga)
5614         return ajFalse;
5615 
5616     if (!identifier)
5617         return ajFalse;
5618 
5619     if (!Pgene)
5620         return ajFalse;
5621 
5622     *Pgene = NULL;
5623 
5624     dba = ensGeneadaptorGetDatabaseadaptor(ga);
5625 
5626     statement = ajFmtStr(
5627         "SELECT "
5628         "transcript.gene_id "
5629         "FROM "
5630         "transcript, "
5631         "exon_transcript, "
5632         "exon "
5633         "WHERE "
5634         "transcript.transcript_id = exon_transcript.transcript_id "
5635         "AND "
5636         "exon_transcript.exon_id = exon.exon_id "
5637         "AND "
5638         "exon.exon_id = %u "
5639         "AND "
5640         "exon.is_current = 1",
5641         identifier);
5642 
5643     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
5644 
5645     sqli = ajSqlrowiterNew(sqls);
5646 
5647     while (!ajSqlrowiterDone(sqli))
5648     {
5649         gid = 0U;
5650 
5651         sqlr = ajSqlrowiterGet(sqli);
5652 
5653         ajSqlcolumnToUint(sqlr, &gid);
5654     }
5655 
5656     ajSqlrowiterDel(&sqli);
5657 
5658     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
5659 
5660     ajStrDel(&statement);
5661 
5662     if (!gid)
5663     {
5664         ajDebug("ensGeneadaptorFetchByExonidentifier "
5665                 "could not get an "
5666                 "Ensembl Gene identifier for "
5667                 "Ensembl Exon identifier %u.\n",
5668                 identifier);
5669 
5670         return ajFalse;
5671     }
5672 
5673     return ensBaseadaptorFetchByIdentifier(
5674         ensGeneadaptorGetBaseadaptor(ga),
5675         gid,
5676         (void **) Pgene);
5677 }
5678 
5679 
5680 
5681 
5682 /* @func ensGeneadaptorFetchByExonstableidentifier ****************************
5683 **
5684 ** Fetch an Ensembl Gene via an Ensembl Exon stable identifier.
5685 ** The caller is responsible for deleting the Ensembl Gene.
5686 **
5687 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_by_exon_stable_id
5688 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5689 ** @param [r] stableid [const AjPStr] Ensembl Exon stable identifier
5690 ** @param [wP] Pgene [EnsPGene*] Ensembl Gene address
5691 **
5692 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5693 **
5694 ** @release 6.4.0
5695 ** @@
5696 ******************************************************************************/
5697 
ensGeneadaptorFetchByExonstableidentifier(EnsPGeneadaptor ga,const AjPStr stableid,EnsPGene * Pgene)5698 AjBool ensGeneadaptorFetchByExonstableidentifier(
5699     EnsPGeneadaptor ga,
5700     const AjPStr stableid,
5701     EnsPGene *Pgene)
5702 {
5703     char *txtstableid = NULL;
5704 
5705     ajuint gid = 0U;
5706 
5707     AjPSqlstatement sqls = NULL;
5708     AjISqlrow sqli       = NULL;
5709     AjPSqlrow sqlr       = NULL;
5710 
5711     AjPStr statement = NULL;
5712 
5713     EnsPDatabaseadaptor dba = NULL;
5714 
5715     if (!ga)
5716         return ajFalse;
5717 
5718     if (!stableid && !ajStrGetLen(stableid))
5719         return ajFalse;
5720 
5721     if (!Pgene)
5722         return ajFalse;
5723 
5724     *Pgene = NULL;
5725 
5726     dba = ensGeneadaptorGetDatabaseadaptor(ga);
5727 
5728     ensDatabaseadaptorEscapeC(dba, &txtstableid, stableid);
5729 
5730     statement = ajFmtStr(
5731         "SELECT "
5732         "transcript.gene_id "
5733         "FROM "
5734         "transcript, "
5735         "exon_transcript, "
5736         "exon "
5737         "WHERE "
5738         "transcript.transcript_id = exon_transcript.transcript_id "
5739         "AND "
5740         "exon_transcript.exon_id = exon.exon_id "
5741         "AND "
5742         "exon.stable_id = '%s' "
5743         "AND "
5744         "exon.is_current = 1",
5745         txtstableid);
5746 
5747     ajCharDel(&txtstableid);
5748 
5749     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
5750 
5751     sqli = ajSqlrowiterNew(sqls);
5752 
5753     while (!ajSqlrowiterDone(sqli))
5754     {
5755         gid = 0U;
5756 
5757         sqlr = ajSqlrowiterGet(sqli);
5758 
5759         ajSqlcolumnToUint(sqlr, &gid);
5760     }
5761 
5762     ajSqlrowiterDel(&sqli);
5763 
5764     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
5765 
5766     ajStrDel(&statement);
5767 
5768     if (!gid)
5769     {
5770         ajDebug("ensGeneadaptorFetchByExonstableidentifier "
5771                 "could not get an "
5772                 "Ensembl Gene identifier for "
5773                 "Ensembl Exon stable identifier '%S'.\n",
5774                 stableid);
5775 
5776         return ajFalse;
5777     }
5778 
5779     return ensBaseadaptorFetchByIdentifier(
5780         ensGeneadaptorGetBaseadaptor(ga),
5781         gid,
5782         (void **) Pgene);
5783 }
5784 
5785 
5786 
5787 
5788 /* @func ensGeneadaptorFetchByIdentifier **************************************
5789 **
5790 ** Fetch an Ensembl Gene via its SQL database-internal identifier.
5791 ** The caller is responsible for deleting the Ensembl Gene.
5792 **
5793 ** @cc Bio::EnsEMBL::DBSQL::BaseAdaptor::fetch_by_dbID
5794 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5795 ** @param [r] identifier [ajuint] SQL database-internal identifier
5796 ** @param [wP] Pgene [EnsPGene*] Ensembl Gene address
5797 **
5798 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5799 **
5800 ** @release 6.2.0
5801 ** @@
5802 ******************************************************************************/
5803 
ensGeneadaptorFetchByIdentifier(EnsPGeneadaptor ga,ajuint identifier,EnsPGene * Pgene)5804 AjBool ensGeneadaptorFetchByIdentifier(
5805     EnsPGeneadaptor ga,
5806     ajuint identifier,
5807     EnsPGene *Pgene)
5808 {
5809     AjBool result = AJFALSE;
5810 
5811     EnsPCache cache = NULL;
5812 
5813     if (!ga)
5814         return ajFalse;
5815 
5816     if (!identifier)
5817         return ajFalse;
5818 
5819     if (!Pgene)
5820         return ajFalse;
5821 
5822     *Pgene = NULL;
5823 
5824     cache = ensFeatureadaptorGetCache(ga);
5825 
5826     ensCacheFetch(cache, (void *) &identifier, (void **) Pgene);
5827 
5828     if (*Pgene)
5829         return ajTrue;
5830 
5831     result = ensBaseadaptorFetchByIdentifier(
5832         ensGeneadaptorGetBaseadaptor(ga),
5833         identifier,
5834         (void **) Pgene);
5835 
5836     ensCacheStore(cache, (void *) &identifier, (void **) Pgene);
5837 
5838     return result;
5839 }
5840 
5841 
5842 
5843 
5844 /* @func ensGeneadaptorFetchByStableidentifier ********************************
5845 **
5846 ** Fetch an Ensembl Gene via its stable identifier and version.
5847 ** In case a particular version is not specified,
5848 ** the current Ensembl Gene will be returned.
5849 ** The caller is responsible for deleting the Ensembl Gene.
5850 **
5851 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_by_stable_id
5852 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5853 ** @param [r] stableid [const AjPStr] Stable identifier
5854 ** @param [r] version [ajuint] Version
5855 ** @param [wP] Pgene [EnsPGene*] Ensembl Gene address
5856 **
5857 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5858 **
5859 ** @release 6.4.0
5860 ** @@
5861 ******************************************************************************/
5862 
ensGeneadaptorFetchByStableidentifier(EnsPGeneadaptor ga,const AjPStr stableid,ajuint version,EnsPGene * Pgene)5863 AjBool ensGeneadaptorFetchByStableidentifier(
5864     EnsPGeneadaptor ga,
5865     const AjPStr stableid,
5866     ajuint version,
5867     EnsPGene *Pgene)
5868 {
5869     char *txtstableid = NULL;
5870 
5871     AjBool result = AJFALSE;
5872 
5873     AjPList genes = NULL;
5874 
5875     AjPStr constraint = NULL;
5876 
5877     EnsPBaseadaptor ba = NULL;
5878 
5879     EnsPGene gene = NULL;
5880 
5881     if (!ga)
5882         return ajFalse;
5883 
5884     if (!stableid)
5885         return ajFalse;
5886 
5887     if (!Pgene)
5888         return ajFalse;
5889 
5890     *Pgene = NULL;
5891 
5892     ba = ensGeneadaptorGetBaseadaptor(ga);
5893 
5894     ensBaseadaptorEscapeC(ba, &txtstableid, stableid);
5895 
5896     if (version)
5897         constraint = ajFmtStr(
5898             "gene.stable_id = '%s' "
5899             "AND "
5900             "gene.version = %u",
5901             txtstableid,
5902             version);
5903     else
5904         constraint = ajFmtStr(
5905             "gene.stable_id = '%s' "
5906             "AND "
5907             "gene.is_current = 1",
5908             txtstableid);
5909 
5910     ajCharDel(&txtstableid);
5911 
5912     genes = ajListNew();
5913 
5914     result = ensBaseadaptorFetchAllbyConstraint(
5915         ba,
5916         constraint,
5917         (EnsPAssemblymapper) NULL,
5918         (EnsPSlice) NULL,
5919         genes);
5920 
5921     if (ajListGetLength(genes) > 1)
5922         ajDebug("ensGeneadaptorFetchByStableidentifier got more than one "
5923                 "Ensembl Gene for stable identifier '%S' and version %u.\n",
5924                 stableid,
5925                 version);
5926 
5927     ajListPop(genes, (void **) Pgene);
5928 
5929     while (ajListPop(genes, (void **) &gene))
5930         ensGeneDel(&gene);
5931 
5932     ajListFree(&genes);
5933 
5934     ajStrDel(&constraint);
5935 
5936     return result;
5937 }
5938 
5939 
5940 
5941 
5942 /* @func ensGeneadaptorFetchByTranscriptidentifier ****************************
5943 **
5944 ** Fetch an Ensembl Gene via an Ensembl Transcript identifier.
5945 ** The caller is responsible for deleting the Ensembl Gene.
5946 **
5947 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_by_transcript_id
5948 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
5949 ** @param [r] identifier [ajuint] Ensembl Transcript identifier
5950 ** @param [wP] Pgene [EnsPGene*] Ensembl Gene address
5951 **
5952 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
5953 **
5954 ** @release 6.4.0
5955 ** @@
5956 ******************************************************************************/
5957 
ensGeneadaptorFetchByTranscriptidentifier(EnsPGeneadaptor ga,ajuint identifier,EnsPGene * Pgene)5958 AjBool ensGeneadaptorFetchByTranscriptidentifier(
5959     EnsPGeneadaptor ga,
5960     ajuint identifier,
5961     EnsPGene *Pgene)
5962 {
5963     ajuint gid = 0U;
5964 
5965     AjPSqlstatement sqls = NULL;
5966     AjISqlrow sqli       = NULL;
5967     AjPSqlrow sqlr       = NULL;
5968 
5969     AjPStr statement = NULL;
5970 
5971     EnsPDatabaseadaptor dba = NULL;
5972 
5973     if (!ga)
5974         return ajFalse;
5975 
5976     if (!identifier)
5977         return ajFalse;
5978 
5979     if (!Pgene)
5980         return ajFalse;
5981 
5982     *Pgene = NULL;
5983 
5984     dba = ensGeneadaptorGetDatabaseadaptor(ga);
5985 
5986     statement = ajFmtStr(
5987         "SELECT "
5988         "transcript.gene_id "
5989         "FROM "
5990         "transcript "
5991         "WHERE "
5992         "transcript.transcript_id = %u",
5993         identifier);
5994 
5995     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
5996 
5997     sqli = ajSqlrowiterNew(sqls);
5998 
5999     while (!ajSqlrowiterDone(sqli))
6000     {
6001         gid = 0U;
6002 
6003         sqlr = ajSqlrowiterGet(sqli);
6004 
6005         ajSqlcolumnToUint(sqlr, &gid);
6006     }
6007 
6008     ajSqlrowiterDel(&sqli);
6009 
6010     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
6011 
6012     ajStrDel(&statement);
6013 
6014     if (!gid)
6015     {
6016         ajDebug("ensGeneadaptorFetchByTranscriptidentifier "
6017                 "could not get an "
6018                 "Ensembl Gene identifier for "
6019                 "Ensembl Transcript identifier %u.\n",
6020                 identifier);
6021 
6022         return ajFalse;
6023     }
6024 
6025     return ensBaseadaptorFetchByIdentifier(
6026         ensGeneadaptorGetBaseadaptor(ga),
6027         gid,
6028         (void **) Pgene);
6029 }
6030 
6031 
6032 
6033 
6034 /* @func ensGeneadaptorFetchByTranscriptstableidentifier **********************
6035 **
6036 ** Fetch an Ensembl Gene via an Ensembl Transcript stable identifier.
6037 ** The caller is responsible for deleting the Ensembl Gene.
6038 **
6039 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_by_transcript_stable_id
6040 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
6041 ** @param [r] stableid [const AjPStr] Ensembl Transcript stable identifier
6042 ** @param [wP] Pgene [EnsPGene*] Ensembl Gene address
6043 **
6044 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
6045 **
6046 ** @release 6.4.0
6047 ** @@
6048 ******************************************************************************/
6049 
ensGeneadaptorFetchByTranscriptstableidentifier(EnsPGeneadaptor ga,const AjPStr stableid,EnsPGene * Pgene)6050 AjBool ensGeneadaptorFetchByTranscriptstableidentifier(
6051     EnsPGeneadaptor ga,
6052     const AjPStr stableid,
6053     EnsPGene *Pgene)
6054 {
6055     char *txtstableid = NULL;
6056 
6057     ajuint gid = 0U;
6058 
6059     AjPSqlstatement sqls = NULL;
6060     AjISqlrow sqli       = NULL;
6061     AjPSqlrow sqlr       = NULL;
6062 
6063     AjPStr statement = NULL;
6064 
6065     EnsPDatabaseadaptor dba = NULL;
6066 
6067     if (!ga)
6068         return ajFalse;
6069 
6070     if (!stableid && !ajStrGetLen(stableid))
6071         return ajFalse;
6072 
6073     if (!Pgene)
6074         return ajFalse;
6075 
6076     *Pgene = NULL;
6077 
6078     dba = ensGeneadaptorGetDatabaseadaptor(ga);
6079 
6080     ensDatabaseadaptorEscapeC(dba, &txtstableid, stableid);
6081 
6082     statement = ajFmtStr(
6083         "SELECT "
6084         "transcript.gene_id "
6085         "FROM"
6086         "transcript "
6087         "WHERE "
6088         "transcript.stable_id = '%s' "
6089         "AND "
6090         "transcript.is_current = 1",
6091         txtstableid);
6092 
6093     ajCharDel(&txtstableid);
6094 
6095     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
6096 
6097     sqli = ajSqlrowiterNew(sqls);
6098 
6099     while (!ajSqlrowiterDone(sqli))
6100     {
6101         gid = 0U;
6102 
6103         sqlr = ajSqlrowiterGet(sqli);
6104 
6105         ajSqlcolumnToUint(sqlr, &gid);
6106     }
6107 
6108     ajSqlrowiterDel(&sqli);
6109 
6110     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
6111 
6112     ajStrDel(&statement);
6113 
6114     if (!gid)
6115     {
6116         ajDebug("ensGeneadaptorFetchByTranscriptstableidentifier "
6117                 "could not get an "
6118                 "Ensembl Gene identifier for "
6119                 "Ensembl Transcript stable identifier '%S'.\n",
6120                 stableid);
6121 
6122         return ajFalse;
6123     }
6124 
6125     return ensBaseadaptorFetchByIdentifier(
6126         ensGeneadaptorGetBaseadaptor(ga),
6127         gid,
6128         (void **) Pgene);
6129 }
6130 
6131 
6132 
6133 
6134 /* @func ensGeneadaptorFetchByTranslationstableidentifier *********************
6135 **
6136 ** Fetch an Ensembl Gene via an Ensembl Translation stable identifier.
6137 ** The caller is responsible for deleting the Ensembl Gene.
6138 **
6139 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::fetch_by_translation_stable_id
6140 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
6141 ** @param [r] stableid [const AjPStr] Ensembl Translation stable identifier
6142 ** @param [wP] Pgene [EnsPGene*] Ensembl Gene address
6143 **
6144 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
6145 **
6146 ** @release 6.4.0
6147 ** @@
6148 ******************************************************************************/
6149 
ensGeneadaptorFetchByTranslationstableidentifier(EnsPGeneadaptor ga,const AjPStr stableid,EnsPGene * Pgene)6150 AjBool ensGeneadaptorFetchByTranslationstableidentifier(
6151     EnsPGeneadaptor ga,
6152     const AjPStr stableid,
6153     EnsPGene *Pgene)
6154 {
6155     char *txtstableid = NULL;
6156 
6157     ajuint gid = 0U;
6158 
6159     AjPSqlstatement sqls = NULL;
6160     AjISqlrow sqli       = NULL;
6161     AjPSqlrow sqlr       = NULL;
6162 
6163     AjPStr statement = NULL;
6164 
6165     EnsPDatabaseadaptor dba = NULL;
6166 
6167     if (!ga)
6168         return ajFalse;
6169 
6170     if (!stableid && !ajStrGetLen(stableid))
6171         return ajFalse;
6172 
6173     if (!Pgene)
6174         return ajFalse;
6175 
6176     *Pgene = NULL;
6177 
6178     dba = ensGeneadaptorGetDatabaseadaptor(ga);
6179 
6180     ensDatabaseadaptorEscapeC(dba, &txtstableid, stableid);
6181 
6182     statement = ajFmtStr(
6183         "SELECT "
6184         "transcript.gene_id "
6185         "FROM "
6186         "transcript, "
6187         "translation"
6188         "WHERE "
6189         "translation.stable_id = '%s' "
6190         "AND "
6191         "transcript.transcript_id = translation.transcript_id "
6192         "AND "
6193         "transcript.is_current = 1",
6194         txtstableid);
6195 
6196     ajCharDel(&txtstableid);
6197 
6198     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
6199 
6200     sqli = ajSqlrowiterNew(sqls);
6201 
6202     while (!ajSqlrowiterDone(sqli))
6203     {
6204         gid = 0U;
6205 
6206         sqlr = ajSqlrowiterGet(sqli);
6207 
6208         ajSqlcolumnToUint(sqlr, &gid);
6209     }
6210 
6211     ajSqlrowiterDel(&sqli);
6212 
6213     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
6214 
6215     ajStrDel(&statement);
6216 
6217     if (!gid)
6218     {
6219         ajDebug("ensGeneadaptorFetchByTranslationstableidentifier "
6220                 "could not get an "
6221                 "Ensembl Gene identifier for "
6222                 "Ensembl Translation stable identifier '%S'.\n",
6223                 stableid);
6224 
6225         return ajFalse;
6226     }
6227 
6228     return ensBaseadaptorFetchByIdentifier(
6229         ensGeneadaptorGetBaseadaptor(ga),
6230         gid,
6231         (void **) Pgene);
6232 }
6233 
6234 
6235 
6236 
6237 /* @section accessory object retrieval ****************************************
6238 **
6239 ** Functions for retrieving objects releated to Ensembl Gene objects from an
6240 ** Ensembl SQL database.
6241 **
6242 ** @fdata [EnsPGeneadaptor]
6243 **
6244 ** @nam3rule Retrieve Retrieve Ensembl Gene-releated object(s)
6245 ** @nam4rule All Retrieve all Ensembl Gene-releated objects
6246 ** @nam5rule Identifiers Retrieve all SQL database-internal identifier objects
6247 ** @nam5rule Stableidentifiers Retrieve all stable identifier objects
6248 **
6249 ** @argrule * ga [EnsPGeneadaptor] Ensembl Gene Adaptor
6250 ** @argrule AllIdentifiers identifiers [AjPList]
6251 ** AJAX List of AJAX unsigned integer (Ensembl Gene identifier) objects
6252 ** @argrule AllStableidentifiers stableids [AjPList]
6253 ** AJAX List of AJAX String (Ensembl Gene stable identifier) objects
6254 **
6255 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
6256 **
6257 ** @fcategory use
6258 ******************************************************************************/
6259 
6260 
6261 
6262 
6263 /* @func ensGeneadaptorRetrieveAllIdentifiers *********************************
6264 **
6265 ** Retrieve all SQL database-internal identifier objects of Ensembl Genes.
6266 **
6267 ** The caller is responsible for deleting the AJAX unsigned integer objects
6268 ** before deleting the AJAX List.
6269 **
6270 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::list_dbIDs
6271 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
6272 ** @param [u] identifiers [AjPList]
6273 ** AJAX List of AJAX unsigned integer (Ensembl Gene identifier) objects
6274 **
6275 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
6276 **
6277 ** @release 6.4.0
6278 ** @@
6279 ******************************************************************************/
6280 
ensGeneadaptorRetrieveAllIdentifiers(EnsPGeneadaptor ga,AjPList identifiers)6281 AjBool ensGeneadaptorRetrieveAllIdentifiers(
6282     EnsPGeneadaptor ga,
6283     AjPList identifiers)
6284 {
6285     AjBool result = AJFALSE;
6286 
6287     AjPStr table = NULL;
6288 
6289     if (!ga)
6290         return ajFalse;
6291 
6292     if (!identifiers)
6293         return ajFalse;
6294 
6295     table = ajStrNewC("gene");
6296 
6297     result = ensBaseadaptorRetrieveAllIdentifiers(
6298         ensGeneadaptorGetBaseadaptor(ga),
6299         table,
6300         (AjPStr) NULL,
6301         identifiers);
6302 
6303     ajStrDel(&table);
6304 
6305     return result;
6306 }
6307 
6308 
6309 
6310 
6311 /* @func ensGeneadaptorRetrieveAllStableidentifiers ***************************
6312 **
6313 ** Retrieve all stable identifier objects of Ensembl Genes.
6314 **
6315 ** The caller is responsible for deleting the AJAX String objects before
6316 ** deleting the AJAX List.
6317 **
6318 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::list_stable_ids
6319 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
6320 ** @param [u] stableids [AjPList]
6321 ** AJAX List of AJAX String (Ensembl Gene stable identifier) objects
6322 **
6323 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
6324 **
6325 ** @release 6.4.0
6326 ** @@
6327 ******************************************************************************/
6328 
ensGeneadaptorRetrieveAllStableidentifiers(EnsPGeneadaptor ga,AjPList stableids)6329 AjBool ensGeneadaptorRetrieveAllStableidentifiers(
6330     EnsPGeneadaptor ga,
6331     AjPList stableids)
6332 {
6333     AjBool result = AJFALSE;
6334 
6335     AjPStr primary = NULL;
6336     AjPStr table   = NULL;
6337 
6338     if (!ga)
6339         return ajFalse;
6340 
6341     if (!stableids)
6342         return ajFalse;
6343 
6344     table   = ajStrNewC("gene");
6345     primary = ajStrNewC("stable_id");
6346 
6347     result = ensBaseadaptorRetrieveAllStrings(
6348         ensGeneadaptorGetBaseadaptor(ga),
6349         table,
6350         primary,
6351         stableids);
6352 
6353     ajStrDel(&table);
6354     ajStrDel(&primary);
6355 
6356     return result;
6357 }
6358 
6359 
6360 
6361 
6362 /* @section check *************************************************************
6363 **
6364 ** Check Ensembl Gene objects.
6365 **
6366 ** @fdata [EnsPGeneadaptor]
6367 **
6368 ** @nam3rule Check Check Ensembl Gene object(s)
6369 ** @nam4rule Reference Check whether an Ensembl Gene object is the reference
6370 **
6371 ** @argrule * ga [EnsPGeneadaptor] Ensembl Gene Adaptor
6372 ** @argrule * gene [const EnsPGene] Ensembl Gene
6373 ** @argrule Reference Presult [AjBool*] Result
6374 **
6375 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
6376 **
6377 ** @fcategory use
6378 ******************************************************************************/
6379 
6380 
6381 
6382 
6383 /* @func ensGeneadaptorCheckReference *****************************************
6384 **
6385 ** Check, whether an Ensembl Gene is a reference or alternative allele.
6386 **
6387 ** @cc Bio::EnsEMBL::DBSQL::GeneAdaptor::is_ref
6388 ** @param [u] ga [EnsPGeneadaptor] Ensembl Gene Adaptor
6389 ** @param [r] gene [const EnsPGene] Ensembl Gene
6390 ** @param [u] Presult [AjBool*] Result
6391 **
6392 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
6393 **
6394 ** @release 6.4.0
6395 ** @@
6396 ******************************************************************************/
6397 
ensGeneadaptorCheckReference(EnsPGeneadaptor ga,const EnsPGene gene,AjBool * Presult)6398 AjBool ensGeneadaptorCheckReference(
6399     EnsPGeneadaptor ga,
6400     const EnsPGene gene,
6401     AjBool *Presult)
6402 {
6403     ajuint count = 0U;
6404 
6405     AjPSqlstatement sqls = NULL;
6406     AjISqlrow sqli       = NULL;
6407     AjPSqlrow sqlr       = NULL;
6408 
6409     AjPStr statement = NULL;
6410 
6411     EnsPDatabaseadaptor dba = NULL;
6412 
6413     if (!ga)
6414         return ajFalse;
6415 
6416     if (!gene)
6417         return ajFalse;
6418 
6419     if (!Presult)
6420         return ajFalse;
6421 
6422     *Presult = ajTrue;
6423 
6424     dba = ensGeneadaptorGetDatabaseadaptor(ga);
6425 
6426     statement = ajFmtStr(
6427         "SELECT "
6428         "COUNT(1) "
6429         "FROM "
6430         "alt_allele "
6431         "WHERE "
6432         "alt_allele.gene_id = %u "
6433         "AND "
6434         "alt_allele.is_ref = 0",
6435         ensGeneGetIdentifier(gene));
6436 
6437     sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
6438 
6439     sqli = ajSqlrowiterNew(sqls);
6440 
6441     while (!ajSqlrowiterDone(sqli))
6442     {
6443         count = 0U;
6444 
6445         sqlr = ajSqlrowiterGet(sqli);
6446 
6447         ajSqlcolumnToUint(sqlr, &count);
6448 
6449         if (count == 1)
6450             *Presult = ajFalse;
6451     }
6452 
6453     ajSqlrowiterDel(&sqli);
6454 
6455     ensDatabaseadaptorSqlstatementDel(dba, &sqls);
6456 
6457     ajStrDel(&statement);
6458 
6459     return ajTrue;
6460 }
6461