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