1 /* @source ajtranslate ********************************************************
2 **
3 ** AJAX translate functions
4 **
5 ** These functions control all aspects of sequence translation
6 **
7 ** These functions do not translate to the 'ambiguity' residues
8 ** 'B' (Asn or Asp) and 'Z' (Glu or Gln). So the codons:
9 ** RAC, RAT, RAY, RAU which could code for 'B' return 'X'
10 ** and SAA, SAG, SAR which could code for 'Z' return 'X'.
11 **
12 ** This translation table doesn't have the doubly ambiguous
13 ** codons set up:
14 ** YTR - L
15 ** MGR - R
16 ** YUR - L
17 **
18 ** This should be attended to at some time.
19 **
20 ** @author Copyright (C) 1999 Gary Williams
21 ** @version $Revision: 1.49 $
22 ** @modified Feb 15 1999 GWW First version
23 ** @modified April 19 1999 GWW Second version using NCBI's GC tables
24 ** @modified April 18 2000 GWW Reorganised many of the routines
25 ** @modified 2001-2011 Peter Rice
26 ** @modified $Date: 2013/02/07 10:32:50 $ by $Author: rice $
27 ** @@
28 **
29 ** This library is free software; you can redistribute it and/or
30 ** modify it under the terms of the GNU Lesser General Public
31 ** License as published by the Free Software Foundation; either
32 ** version 2.1 of the License, or (at your option) any later version.
33 **
34 ** This library is distributed in the hope that it will be useful,
35 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
37 ** Lesser General Public License for more details.
38 **
39 ** You should have received a copy of the GNU Lesser General Public
40 ** License along with this library; if not, write to the Free Software
41 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42 ** MA  02110-1301,  USA.
43 **
44 *******************************************************************************
45 **
46 ** Example of typical usage (code fragment):
47 **
48 **
49 ** trnTable = ajTrnNewI(table_number);
50 ** while(ajSeqallNext(seqall, &seq))
51 ** {
52 **     protein_seq = ajTrnSeqFramePep(trnObj, seq, frame)
53 **     write out protein_seq
54 **     ajSeqDel(&protein_seq);
55 ** }
56 ** ajTrnDel(&trnTable);
57 **
58 ** or
59 **
60 ** trnTable = ajTrnNewI(table_number);
61 ** ajTrnStr(trnTable, seq, &protein_str)
62 ** ajFmtPrintF(outfile, "protein=%S\n", protein_str);
63 ** ajTrnDel(&trnTable);
64 **
65 **
66 **
67 ** Example of typical ACD file list for getting the translation frame:
68 **
69 **   list: frame [
70 **         opt: Y
71 **         default: "1"
72 **         min: 1
73 **         max: 1
74 **         header: "Translation frames"
75 **         values:
76 **                 "1:1,
77 **                 2:2,
78 **                 3:3,
79 **                 F:Forward three frames,
80 **                 -1:-1,
81 **                 -2:-2,
82 **                 -3:-3,
83 **                 R:Reverse three frames,
84 **                 6:All six frames"
85 **         delim: ","
86 **         codedelim: ":"
87 **         prompt: "Frame(s) to translate"
88 **   ]
89 **
90 **
91 ** Example of typical ACD file list for getting the genetic code table number:
92 **
93 ** list: table [
94 **        opt: Y
95 **        default: "0"
96 **        min: 1
97 **        max: 1
98 **        header: "Genetic codes"
99 **        values:
100 **                "0:Standard;
101 **                1:Standard (with alternative initiation codons);
102 **                2:Vertebrate Mitochondrial;
103 **                3:Yeast Mitochondrial;
104 **                4:Mold, Protozoan, Coelenterate Mitochondrial
105 **                  and Mycoplasma/Spiroplasma;
106 **                5:Invertebrate Mitochondrial;
107 **                6:Ciliate Macronuclear and Dasycladacean;
108 **                9:Echinoderm Mitochondrial;
109 **                10:Euplotid Nuclear;
110 **                11:Bacterial;
111 **                12:Alternative Yeast Nuclear;
112 **                13:Ascidian Mitochondrial;
113 **                14:Flatworm Mitochondrial;
114 **                15:Blepharisma Macronuclear;
115 **                16:Chlorophycean Mitochondrial;
116 **                21:Trematode Mitochondrial"
117 **        delim: ";"
118 **        codedelim: ":"
119 **        prompt: "Code to use"
120 **  ]
121 **
122 **
123 **
124 ******************************************************************************/
125 
126 #include "ajlib.h"
127 
128 #include "ajtranslate.h"
129 #include "ajtable.h"
130 #include "ajfileio.h"
131 #include "ajfiledata.h"
132 #include "ajseqtype.h"
133 
134 #include <string.h>
135 #include <stddef.h>
136 #include <stdarg.h>
137 #include <float.h>
138 #include <limits.h>
139 
140 
141 
142 
143 #define TGCFILE "EGC.0"
144 #define TGC "EGC."
145 
146 static AjPTable trnCodes = NULL;
147 
148 
149 /* table to convert character of base to translation array element value */
150 static ajint trnconv[] =
151 {
152     /* characters less than 64 */
153     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
154     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
155 
156   /*' '  !   "   #   $   %   &   '   (   )   *   +   ,   -   .   / */
157     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
158 
159   /* 0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ? */
160     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
161 
162   /* @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O */
163     14,  0, 13,  1, 12, 14, 14,  2, 11, 14, 14,  9, 14,  4, 14, 14,
164 
165   /* P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _ */
166     14, 14,  5,  7,  3,  3, 10,  6, 14,  8, 14, 14, 14, 14, 14, 14,
167 
168   /* `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o */
169     14,  0, 13,  1, 12, 14, 14,  2, 11, 14, 14,  9, 14,  4, 14, 14,
170 
171   /* p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~   del */
172     14, 14,  5,  7,  3,  3, 10,  6, 14,  8, 14, 14, 14, 14, 14, 14
173 };
174 
175 
176 /*
177  ** table to convert character of COMPLEMENT of base to translation array
178  ** element value
179  */
180 
181 static ajint trncomp[] =
182 {
183     /* characters less than 64 */
184     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
185     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
186 
187   /*' '  !   "   #   $   %   &   '   (   )   *   +   ,   -   .   / */
188     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
189 
190   /* 0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ? */
191     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
192 
193   /* @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O*/
194     14,  3, 10,  2, 11, 14, 14,  1, 12, 14, 14,  4, 14,  9, 14, 14,
195 
196   /* P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _ */
197     14, 14,  8,  7,  0,  0, 13,  6, 14,  5, 14, 14, 14, 14, 14, 14,
198 
199   /* `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o */
200     14,  3, 10,  2, 11, 14, 14,  1, 12, 14, 14,  4, 14,  9, 14, 14,
201 
202   /* p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~   del */
203     14, 14,  8,  7,  0,  0, 13,  6, 14,  5, 14, 14, 14, 14, 14, 14
204 };
205 
206 
207 static AjPStr trnResidueStr = NULL;
208 
209 static void trnNoComment(AjPStr* text);
210 
211 static AjBool trnComplete(AjPTrn thys);
212 
213 
214 
215 
216 /* @func ajTrnDel *************************************************************
217 **
218 ** Deletes a translation table object
219 **
220 ** @param [d] pthis [AjPTrn*] Address of translation table object
221 ** @return [void]
222 ** @category delete [AjPTrn] Default destructor
223 **
224 ** @release 1.0.0
225 ** @@
226 ******************************************************************************/
227 
ajTrnDel(AjPTrn * pthis)228 void ajTrnDel(AjPTrn* pthis)
229 {
230     AjPTrn thys;
231 
232     if(!pthis)
233         return;
234 
235     thys = *pthis;
236 
237     if(!thys)
238         return;
239 
240     ajStrDel(&thys->FileName);
241     ajStrDel(&thys->Title);
242 
243     AJFREE(*pthis);
244 
245     return;
246 }
247 
248 
249 
250 
251 /* @func ajTrnNewC ************************************************************
252 **
253 ** Initialises translation. Reads a translation data file.
254 **
255 ** @param [r] filename [const char*] translation table file name
256 ** @return [AjPTrn] Translation object
257 ** @category new [AjPTrn] Default constructor
258 **
259 ** @release 1.0.0
260 ** @@
261 ******************************************************************************/
262 
ajTrnNewC(const char * filename)263 AjPTrn ajTrnNewC(const char * filename)
264 {
265     AjPStr trnFileName = NULL;
266 
267     trnFileName = ajStrNewC(filename);
268 
269     return ajTrnNew(trnFileName);
270 
271 }
272 
273 
274 
275 
276 /* @func ajTrnNewI ************************************************************
277 **
278 ** Initialises translation. Reads a translation data file called 'EGC.x'
279 ** where 'x' is supplied as an ajint parameter.
280 ** The filename must exist somewhere in the data path.
281 ** ajTrnDel should be called when translation has ceased.
282 **
283 ** @param [r] trnFileNameInt [ajint] translation table file name number
284 ** @return [AjPTrn] Translation object
285 ** @category new [AjPTrn] Default constructor
286 **
287 ** @release 1.0.0
288 ** @@
289 ******************************************************************************/
290 
ajTrnNewI(ajint trnFileNameInt)291 AjPTrn ajTrnNewI(ajint trnFileNameInt)
292 {
293     AjPStr trnFileName = NULL;
294     AjPStr value       = NULL;
295     AjPTrn ret = NULL;
296 
297     value       = ajStrNew();
298     trnFileName = ajStrNewC(TGC);
299 
300     ajStrFromInt(&value, trnFileNameInt);
301     ajStrAppendS(&trnFileName, value);
302 
303     ret = ajTrnNew(trnFileName);
304 
305     ajStrDel(&value);
306     ajStrDel(&trnFileName);
307 
308     return ret;
309 }
310 
311 
312 
313 
314 /* @func ajTrnNew *************************************************************
315 **
316 ** Initialises translation. Reads a translation data file
317 ** ajTrnDel should be called when translation has ceased.
318 **
319 ** @param [r] trnFileName [const AjPStr] translation table file name
320 ** @return [AjPTrn] Translation object
321 ** @category new [AjPTrn] Default constructor
322 **
323 ** @release 1.0.0
324 ** @@
325 ******************************************************************************/
326 
ajTrnNew(const AjPStr trnFileName)327 AjPTrn ajTrnNew(const AjPStr trnFileName)
328 {
329     AjPFile trnFile = NULL;
330     AjPTrn pthis;
331     ajint i;
332     ajint j;
333     ajint k;
334 
335     /* open the translation table file */
336 
337     /* if the file is not specified, use the standard table file */
338     if(!ajStrGetLen(trnFileName))
339 	trnFileName = ajStrNewC(TGCFILE);
340 
341 
342     trnFile = ajDatafileNewInNameS(trnFileName);
343 
344     if(trnFile==NULL)
345 	ajFatal("Translation table file '%S' not found\n", trnFileName);
346 
347     /* create and initialise the translation object */
348     AJNEW0(pthis);
349     pthis->FileName = ajStrNew();
350     pthis->Title    = ajStrNew();
351 
352     /* initialise the GC and Starts tables */
353     for(i=0; i<16; i++)
354 	for(j=0; j<16; j++)
355 	    for(k=0; k<16; k++)
356 	    {
357 		pthis->GC[i][j][k] = 'X';
358 		pthis->Starts[i][j][k] = '-';
359 	    }
360 
361     ajStrAssignS(&(pthis->FileName), trnFileName);
362     ajTrnReadFile(pthis, trnFile);
363 
364     ajFileClose(&trnFile);
365 
366     return pthis;
367 }
368 
369 
370 
371 
372 /* @func ajTrnReadFile ********************************************************
373 **
374 ** Reads a translation data file
375 **
376 ** The destructor ajTrnDel should be called when translation has ceased.
377 **
378 ** @param [w] trnObj [AjPTrn] translation table object
379 ** @param [u] trnFile [AjPFile] translation table file handle
380 ** @return [void]
381 ** @category input [AjPTrn] Reads a Genetic Code file
382 **
383 ** @release 1.0.0
384 ** @@
385 ******************************************************************************/
386 
ajTrnReadFile(AjPTrn trnObj,AjPFile trnFile)387 void ajTrnReadFile(AjPTrn trnObj, AjPFile trnFile)
388 {
389     AjPStr trnLine    = NULL;
390     AjPStr trnText    = NULL;
391     AjPStr tmpstr     = NULL;
392     AjPStr aaline     = NULL;
393     AjPStr startsline = NULL;
394     AjPStr base1line  = NULL;
395     AjPStr base2line  = NULL;
396     AjPStr base3line  = NULL;
397 
398     AjPStrTok tokenhandle;
399 
400     const char *aa;
401     const char *starts;
402     const char *base1;
403     const char *base2;
404     const char *base3;
405     ajint dlen;
406     ajint i;
407 
408 
409     /* positions of first use of a residue in the aa line */
410     /* ajint firstaa[256]; Now unused */
411 
412     /*
413     ** NB '-' and '*' are valid characters,
414     ** don't skip over them when parsing tokens
415     */
416     char white[] = " \t\n\r!@#$%^&()_+=|\\~`{[}]:;\"'<,>.?/";
417 
418     ajDebug("ajTrnReadFile %F\n", trnFile);
419 
420     while(ajReadlineTrim(trnFile, &trnLine))
421     {
422 	trnNoComment(&trnLine);
423 
424 	if(ajStrGetLen(trnLine))
425 	{
426 	    if(ajStrFindC(trnLine, "Genetic Code") == -1)
427 		ajFatal("The file '%S' is not a valid Genetic Code file.\n"
428 			"The 'Genetic Code' line was not found.",
429 			trnObj->FileName);
430 	    else
431 		break;
432 	}
433     }
434 
435     /* title */
436     while(ajReadlineTrim(trnFile, &trnLine))
437     {
438 	trnNoComment(&trnLine);
439 
440 	if(ajStrGetLen(trnLine))
441 	{
442 	    ajStrAssignS(&(trnObj->Title), trnLine);
443 	    break;
444 	}
445     }
446 
447     /* rest */
448     while(ajReadlineTrim(trnFile, &trnLine))
449     {
450 	trnNoComment(&trnLine);
451 
452 	if(ajStrGetLen(trnLine))
453 	{
454 	    ajStrAppendS(&trnText, trnLine);
455 	    ajStrAppendC(&trnText, " ");
456 	}
457     }
458 
459     /* data */
460     tokenhandle = ajStrTokenNewC(trnText, white);
461 
462     ajStrTokenNextParse(tokenhandle, &tmpstr);
463 
464     if(ajStrCmpC(tmpstr, "AAs") == -1)
465 	ajFatal("The file '%S' is not a valid Genetic Code file.\n"
466 		"The 'AAs' line was not found.", trnObj->FileName);
467 
468     ajStrTokenNextParse(tokenhandle, &aaline);
469     aa = ajStrGetPtr(aaline);
470 
471     ajStrTokenNextParse(tokenhandle, &tmpstr);
472 
473     if(ajStrCmpC(tmpstr, "Starts") == -1)
474 	ajFatal("The file '%S' is not a valid Genetic Code file.\n"
475 		"The 'Starts' line was not found.", trnObj->FileName);
476 
477     ajStrTokenNextParse(tokenhandle, &startsline);
478     starts = ajStrGetPtr(startsline);
479 
480     ajStrTokenNextParse(tokenhandle, &tmpstr);
481 
482     if(ajStrCmpC(tmpstr, "Base1") == -1)
483 	ajFatal("The file '%S' is not a valid Genetic Code file.\n"
484 		"The 'Base1' line was not found.", trnObj->FileName);
485 
486     ajStrTokenNextParse(tokenhandle, &base1line);
487     base1 = ajStrGetPtr(base1line);
488 
489     ajStrTokenNextParse(tokenhandle, &tmpstr);
490 
491     if(ajStrCmpC(tmpstr, "Base2") == -1)
492 	ajFatal("The file '%S' is not a valid Genetic Code file.\n"
493 		"The 'Base2' line was not found.", trnObj->FileName);
494 
495     ajStrTokenNextParse(tokenhandle, &base2line);
496     base2 = ajStrGetPtr(base2line);
497 
498     ajStrTokenNextParse(tokenhandle, &tmpstr);
499 
500     if(ajStrCmpC(tmpstr, "Base3") == -1)
501 	ajFatal("The file '%S' is not a valid Genetic Code file.\n"
502 		"The 'Base3' line was not found.", trnObj->FileName);
503 
504     ajStrTokenNextParse(tokenhandle, &base3line);
505     base3 = ajStrGetPtr(base3line);
506 
507 
508     ajStrTokenDel(&tokenhandle);
509     ajStrDel(&tmpstr);
510 
511     /* populate the Starts(Initiation sites) table */
512     dlen = ajStrGetLen(startsline);
513 
514     for(i=0; i<dlen; i++)
515 	trnObj->Starts[trnconv[(ajint)base1[i]]]
516 	              [trnconv[(ajint)base2[i]]]
517 		      [trnconv[(ajint)base3[i]]]
518 		    = starts[i];
519 
520     /* populate the GC (Genetic code) table */
521     dlen = ajStrGetLen(aaline);
522 
523     /* initialise first use of aa array */
524     /* Now unused
525     for(i=0; i<256; i++)
526 	firstaa[i] = -1;
527     */
528 
529     for(i=0; i<dlen; i++)
530     {
531 	/*
532 	** put the residue in the table using the unambiguous codon
533 	*/
534 	trnObj->GC[trnconv[(ajint)base1[i]]]
535 	          [trnconv[(ajint)base2[i]]]
536                   [trnconv[(ajint)base3[i]]]
537 		    = aa[i];
538     }
539 
540     /*
541     ** Check we have defined every codon
542     ** Calculate wobble in base3 and populate
543     ** For each amino acid (just once) calculate most ambiguous and populate
544     */
545 
546     trnComplete(trnObj);
547 
548     ajStrDel(&trnText);
549     ajStrDel(&startsline);
550     ajStrDel(&base1line);
551     ajStrDel(&base2line);
552     ajStrDel(&base3line);
553     ajStrDel(&aaline);
554     ajStrDel(&trnLine);
555 
556     return;
557 }
558 
559 
560 
561 
562 /* @funcstatic trnNoComment ***************************************************
563 **
564 ** Strips comments from a character string (a line from a trn file).
565 ** Comments are blank lines or any text following a "#" character.
566 ** Whitespace characters can be included in a blank line.
567 **
568 ** @param [u] text [AjPStr*] Line of text from input file
569 ** @return [void]
570 **
571 ** @release 1.0.0
572 ** @@
573 ******************************************************************************/
574 
trnNoComment(AjPStr * text)575 static void trnNoComment(AjPStr* text)
576 {
577     ajint i;
578     char *cp;
579 
580     ajStrTrimWhite(text);
581     i = ajStrGetLen(*text);
582 
583     if(!i)
584 	return;
585 
586     cp = strchr(ajStrGetuniquePtr(text), '#');
587 
588     if(cp)
589     {
590 	/* comment found */
591 	*cp = '\0';
592 	ajStrSetValid(text);
593     }
594 
595     return;
596 }
597 
598 
599 
600 
601 /* @func ajTrnNewPep **********************************************************
602 **
603 ** Creates a new AjPSeq set up with an appropriate name and description
604 **
605 ** It:
606 **  Creates a AjPSeq object
607 **  Sets it to be a protein.
608 **  Sets the description as being the same as that description of the nucleic
609 **    acid sequence it was translated from.
610 **  Gives it the same name as the nucleic acid sequence it is translated from.
611 **
612 ** If the frame is not specified as being '0' it will then append a '_'
613 ** and the number of the frame to form a unique name for the protein
614 ** sequence in the event of many frames being translated.  If the frame
615 ** number is negative, it will use a number in the range 4, 5, 6, this is
616 ** because ID names with '-' in them were causing problems in the sequence
617 ** reading routines.
618 **
619 ** Frame 4 is the same as frame -1, 5 is -2, 6 is -3.
620 **
621 ** You will have to set the sequence of this object with something like:
622 **  ajSeqAssignSeqS(trnPeptide, seqstr);
623 **
624 **
625 ** @param [r] nucleicSeq [const AjPSeq] nucleic sequence being translated
626 ** @param [r] frame [ajint] frame of translation (-3,-2,-1,0,1,2,3,4,5,6)
627 ** @return [AjPSeq] New peptide object
628 ** @category new [AjPSeq] Peptide object constructor
629 **
630 ** @release 1.0.0
631 ** @@
632 ******************************************************************************/
633 
ajTrnNewPep(const AjPSeq nucleicSeq,ajint frame)634 AjPSeq ajTrnNewPep(const AjPSeq nucleicSeq, ajint frame)
635 {
636 
637     AjPSeq trnPeptide = NULL;
638     AjPStr name       = NULL;		/* name of the translation */
639     AjPStr value      = NULL;  /* value of frame of the translation */
640 
641     trnPeptide = ajSeqNew();
642     ajSeqSetProt(trnPeptide);
643 
644     name  = ajStrNew();
645     value = ajStrNew();
646 
647     /* name for the subsequence */
648     ajStrAssignS(&name, ajSeqGetNameS(nucleicSeq));
649 
650     /*
651     ** if the frame is not 0 then append the frame number to the name to
652     **make it unique
653     */
654     if(frame != 0)
655     {
656 	if(frame < -3)
657             frame = frame + 3;
658 
659 	if(frame < 0)
660             frame = -frame + 3;
661 
662 	ajStrAppendC(&name, "_");
663 
664 	ajStrFromInt(&value, frame);
665 	ajStrAppendS(&name, value);
666     }
667 
668     ajSeqAssignNameS(trnPeptide, name);
669 
670     ajSeqAssignDescS(trnPeptide, ajSeqGetDescS(nucleicSeq));
671 
672     ajStrDel(&name);
673     ajStrDel(&value);
674 
675     return trnPeptide;
676 }
677 
678 
679 
680 
681 /* @func ajTrnCodonS **********************************************************
682 **
683 ** Translates a codon
684 **
685 ** @param [r] trnObj [const AjPTrn] Translation tables
686 ** @param [r] codon [const AjPStr] codon to translate
687 ** @return [char] Amino acid translation
688 ** @category use [AjPTrn] Translating a codon from an AjPStr
689 **
690 ** @release 6.2.0
691 ** @@
692 ******************************************************************************/
693 
ajTrnCodonS(const AjPTrn trnObj,const AjPStr codon)694 char ajTrnCodonS(const AjPTrn trnObj, const AjPStr codon)
695 {
696     const char * res;
697 
698     res = ajStrGetPtr(codon);
699     return trnObj->GC[trnconv[(ajint)res[0]]]
700 	             [trnconv[(ajint)res[1]]]
701 	             [trnconv[(ajint)res[2]]];
702 
703 }
704 
705 
706 
707 
708 /* @func ajTrnCodonRevS *******************************************************
709 **
710 ** Translates the reverse complement of a codon
711 **
712 ** @param [r] trnObj [const AjPTrn] Translation tables
713 ** @param [r] codon [const AjPStr] codon to translate
714 ** @return [char] Amino acid translation
715 ** @category use [AjPTrn] Reverse complement translating a codon
716 **                from an AjPStr
717 **
718 ** @release 6.2.0
719 ** @@
720 ******************************************************************************/
721 
ajTrnCodonRevS(const AjPTrn trnObj,const AjPStr codon)722 char ajTrnCodonRevS(const AjPTrn trnObj, const AjPStr codon)
723 {
724     const char * res;
725 
726     res = ajStrGetPtr(codon);
727     return trnObj->GC[trncomp[(ajint)res[2]]]
728 	             [trncomp[(ajint)res[1]]]
729 	             [trncomp[(ajint)res[0]]];
730 }
731 
732 
733 
734 
735 /* @func ajTrnCodonC **********************************************************
736 **
737 ** Translates a const char * codon
738 **
739 ** @param [r] trnObj [const AjPTrn] Translation tables
740 ** @param [r] codon [const char *] codon to translate
741 **                           (these 3 characters need not be NULL-terminated)
742 ** @return [char] Amino acid translation
743 ** @category use [AjPTrn] Translating a codon from a char* text
744 **
745 ** @release 1.0.0
746 ** @@
747 ******************************************************************************/
748 
ajTrnCodonC(const AjPTrn trnObj,const char * codon)749 char ajTrnCodonC(const AjPTrn trnObj, const char *codon)
750 {
751     return trnObj->GC[trnconv[(ajint)codon[0]]]
752 	             [trnconv[(ajint)codon[1]]]
753 	             [trnconv[(ajint)codon[2]]];
754 }
755 
756 
757 
758 
759 /* @func ajTrnCodonRevC *******************************************************
760 **
761 ** Translates the reverse complement of a const char * codon
762 **
763 ** @param [r] trnObj [const AjPTrn] Translation tables
764 ** @param [r] codon [const char *] codon to translate
765 **                           (these 3 characters need not be NULL-terminated)
766 ** @return [char] Amino acid translation
767 ** @category use [AjPTrn] Translating a codon from a char* text
768 **
769 ** @release 6.2.0
770 ** @@
771 ******************************************************************************/
772 
ajTrnCodonRevC(const AjPTrn trnObj,const char * codon)773 char ajTrnCodonRevC(const AjPTrn trnObj, const char *codon)
774 {
775     return trnObj->GC[trncomp[(ajint)codon[2]]]
776                      [trncomp[(ajint)codon[1]]]
777                      [trncomp[(ajint)codon[0]]];
778 }
779 
780 
781 
782 
783 /* @func ajTrnCodonK **********************************************************
784 **
785 ** Translates a const char * codon to a char
786 **
787 ** @param [r] trnObj [const AjPTrn] Translation tables
788 ** @param [r] codon [const char *] codon to translate
789 **                           (these 3 characters need not be NULL-terminated)
790 ** @return [char] Amino acid translation
791 ** @category use [AjPTrn] Translating a codon from a char* to a
792 **                char
793 **
794 ** @release 1.0.0
795 ** @@
796 ******************************************************************************/
797 
ajTrnCodonK(const AjPTrn trnObj,const char * codon)798 char ajTrnCodonK(const AjPTrn trnObj, const char *codon)
799 {
800     return trnObj->GC[trnconv[(ajint)codon[0]]]
801 	             [trnconv[(ajint)codon[1]]]
802 	             [trnconv[(ajint)codon[2]]];
803 }
804 
805 
806 
807 
808 /* @func ajTrnRevCodonK *******************************************************
809 **
810 ** Translates a the reverse complement of a const char * codon to a char
811 **
812 ** @param [r] trnObj [const AjPTrn] Translation tables
813 ** @param [r] codon [const char *] codon to translate
814 **                           (these 3 characters need not be NULL-terminated)
815 ** @return [char] Amino acid translation
816 ** @category use [AjPTrn] Reverse complement translating a codon
817 **                from a char* to a char
818 **
819 ** @release 1.0.0
820 ** @@
821 ******************************************************************************/
822 
ajTrnRevCodonK(const AjPTrn trnObj,const char * codon)823 char ajTrnRevCodonK(const AjPTrn trnObj, const char *codon)
824 {
825 
826     return trnObj->GC[trncomp[(ajint)codon[2]]]
827 	             [trncomp[(ajint)codon[1]]]
828 	             [trncomp[(ajint)codon[0]]];
829 
830 }
831 
832 
833 
834 
835 /* @func ajTrnSeqC ************************************************************
836 **
837 ** Translates a sequence in a char *
838 **
839 ** This routine translates in frame 1 (from the first base) to the last full
840 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the end, they are
841 ** ignored)
842 **
843 **
844 ** @param [r] trnObj [const AjPTrn] Translation tables
845 ** @param [r] str [const char *] sequence string to translate
846 ** @param [r] len [ajint] length of sequence string to translate
847 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
848 **
849 ** @return [void]
850 ** @category use [AjPTrn] Translating a sequence from a char* text
851 **
852 ** @release 6.2.0
853 ** @@
854 ******************************************************************************/
855 
ajTrnSeqC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)856 void ajTrnSeqC(const AjPTrn trnObj, const char *str, ajint len, AjPStr *pep)
857 {
858     ajint i;
859     ajint lenmod3;
860     const char *cp = str;
861     AjPStr transtr = NULL;
862     char *cq;
863     ajint trnlen;
864 
865     lenmod3 = len - (len % 3);
866     trnlen = lenmod3/3;
867 
868     transtr = ajStrNewRes(trnlen+1);
869     cq = ajStrGetuniquePtr(&transtr);
870 
871     for(i=0; i < lenmod3; i+=3)
872     {
873         *cq++ =  trnObj->GC[trnconv[(ajint)*cp]]
874 	                   [trnconv[(ajint)*(cp+1)]]
875 	                   [trnconv[(ajint)*(cp+2)]];
876 	cp+=3;
877     }
878     ajStrSetValidLen(&transtr, trnlen);
879     ajStrAppendS(pep, transtr);
880     ajStrDel(&transtr);
881 
882     return;
883 }
884 
885 
886 
887 
888 
889 /* @func ajTrnSeqInitC ********************************************************
890 **
891 ** Translates a sequence in a char *
892 **
893 ** This routine translates in frame 1 (from the first base) to the last full
894 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the end, they are
895 ** ignored)
896 **
897 **
898 ** @param [r] trnObj [const AjPTrn] Translation tables
899 ** @param [r] str [const char *] sequence string to translate
900 ** @param [r] len [ajint] length of sequence string to translate
901 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
902 **
903 ** @return [void]
904 ** @category use [AjPTrn] Translating a sequence from a char* text
905 **
906 ** @release 6.2.0
907 ** @@
908 ******************************************************************************/
909 
ajTrnSeqInitC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)910 void ajTrnSeqInitC(const AjPTrn trnObj, const char *str, ajint len, AjPStr *pep)
911 {
912     ajint i;
913     ajint lenmod3;
914     const char *cp = str;
915     AjPStr transtr = NULL;
916     char *cq;
917     ajint trnlen;
918     ajuint istart = 0;
919 
920     lenmod3 = len - (len % 3);
921     trnlen = lenmod3/3;
922 
923     transtr = ajStrNewRes(trnlen+1);
924     cq = ajStrGetuniquePtr(&transtr);
925 
926     if(lenmod3 > 2)
927     {
928         if('M' == trnObj->Starts[trnconv[(ajint)*cp]]
929                                 [trnconv[(ajint)*(cp+1)]]
930                                 [trnconv[(ajint)*(cp+2)]])
931         {
932             cp += 3;
933             istart += 3;
934             *cq++ = 'M';
935         }
936     }
937 
938     for(i=istart; i < lenmod3; i+=3)
939     {
940         *cq++ =  trnObj->GC[trnconv[(ajint)*cp]]
941 	                   [trnconv[(ajint)*(cp+1)]]
942 	                   [trnconv[(ajint)*(cp+2)]];
943 	cp+=3;
944     }
945     ajStrSetValidLen(&transtr, trnlen);
946     ajStrAppendS(pep, transtr);
947     ajStrDel(&transtr);
948 
949     return;
950 }
951 
952 
953 
954 
955 
956 /* @func ajTrnSeqRevC *********************************************************
957 **
958 ** Translates the reverse complement of a sequence in a char *.
959 **
960 ** This routine translates in frame -1 (using the frame '1' codons)
961 ** to the first full triplet codon,
962 ** (i.e. if there are 1 or 2 bases extra at the start, they are ignored)
963 **
964 **
965 ** @param [r] trnObj [const AjPTrn] Translation tables
966 ** @param [r] str [const char *] sequence string to translate
967 ** @param [r] len [ajint] length of sequence string to translate
968 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
969 **
970 ** @return [void]
971 ** @category use [AjPTrn] Reverse complement translating a sequence
972 **                from a char* text
973 **
974 ** @release 6.2.0
975 ** @@
976 ******************************************************************************/
977 
ajTrnSeqRevC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)978 void ajTrnSeqRevC(const AjPTrn trnObj, const char *str, ajint len, AjPStr *pep)
979 {
980     ajint i;
981     ajint end;
982     const char *cp;
983     AjPStr transtr = NULL;
984     char *cq;
985     ajint trnlen;
986 
987     end = (len/3)*3-1;
988     trnlen = (end+1)/3;
989     cp = &str[end];
990     transtr = ajStrNewRes(trnlen+1);
991     cq = ajStrGetuniquePtr(&transtr);
992 
993     for(i=end; i>1; i-=3)
994     {
995 	*cq++ = trnObj->GC[trncomp[(ajint)*cp]]
996 	                  [trncomp[(ajint)*(cp-1)]]
997 	                  [trncomp[(ajint)*(cp-2)]];
998 	cp-=3;
999     }
1000 
1001     ajStrSetValidLen(&transtr, trnlen);
1002     ajStrAppendS(pep, transtr);
1003     ajStrDel(&transtr);
1004 
1005     return;
1006 }
1007 
1008 
1009 
1010 
1011 
1012 /* @func ajTrnSeqRevinitC *****************************************************
1013 **
1014 ** Translates the reverse complement of a sequence in a char *.
1015 ** If the sequence begins with a defined alternative start codon,
1016 ** the residue is replaced with Methionine.
1017 **
1018 ** This routine translates in frame -1 (using the frame '1' codons)
1019 ** to the first full triplet codon,
1020 ** (i.e. if there are 1 or 2 bases extra at the start, they are ignored)
1021 **
1022 **
1023 ** @param [r] trnObj [const AjPTrn] Translation tables
1024 ** @param [r] str [const char *] sequence string to translate
1025 ** @param [r] len [ajint] length of sequence string to translate
1026 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1027 **
1028 ** @return [void]
1029 ** @category use [AjPTrn] Reverse complement translating a sequence
1030 **                from a char* text
1031 **
1032 ** @release 6.2.0
1033 ** @@
1034 ******************************************************************************/
1035 
ajTrnSeqRevinitC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)1036 void ajTrnSeqRevinitC(const AjPTrn trnObj, const char *str, ajint len,
1037                       AjPStr *pep)
1038 {
1039     ajint i;
1040     ajint end;
1041     const char *cp;
1042     AjPStr transtr = NULL;
1043     char *cq;
1044     ajint trnlen;
1045     ajuint iend;
1046 
1047     end = (len/3)*3-1;
1048     trnlen = (end+1)/3;
1049     cp = &str[end];
1050     transtr = ajStrNewRes(trnlen+1);
1051     cq = ajStrGetuniquePtr(&transtr);
1052 
1053     iend = end;
1054 
1055     if(iend > 2)
1056     {
1057         if('M' == trnObj->Starts[trncomp[(ajint)*cp]]
1058                                 [trncomp[(ajint)*(cp-1)]]
1059                                 [trncomp[(ajint)*(cp-2)]])
1060         {
1061             cp -= 3;
1062             iend -= 3;
1063             *cq++ = 'M';
1064         }
1065     }
1066 
1067     for(i=iend; i>1; i-=3)
1068     {
1069 	*cq++ = trnObj->GC[trncomp[(ajint)*cp]]
1070 	                  [trncomp[(ajint)*(cp-1)]]
1071 	                  [trncomp[(ajint)*(cp-2)]];
1072 	cp-=3;
1073     }
1074 
1075     ajStrSetValidLen(&transtr, trnlen);
1076     ajStrAppendS(pep, transtr);
1077     ajStrDel(&transtr);
1078 
1079     return;
1080 }
1081 
1082 
1083 
1084 
1085 
1086 /* @func ajTrnSeqAltRevC ******************************************************
1087 **
1088 ** Translates the reverse complement of a sequence in a char *.
1089 **
1090 ** This routine translates in frame -4 (from the last base) to the first full
1091 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the start, they are
1092 ** ignored).
1093 ** This routine is for those people who define frame '-1' as being the
1094 ** frame starting from the first base of a reverse-complemented sequence.
1095 **
1096 **
1097 ** @param [r] trnObj [const AjPTrn] Translation tables
1098 ** @param [r] str [const char *] sequence string to translate
1099 ** @param [r] len [ajint] length of sequence string to translate
1100 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1101 **
1102 ** @return [void]
1103 ** @category use [AjPTrn] (Alt) Reverse complement translating a
1104 **                sequence from a char* text
1105 **
1106 ** @release 6.2.0
1107 ** @@
1108 ******************************************************************************/
1109 
ajTrnSeqAltRevC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)1110 void ajTrnSeqAltRevC(const AjPTrn trnObj, const char *str, ajint len,
1111                      AjPStr *pep)
1112 {
1113     ajint i;
1114 
1115     for(i=len-1; i>1; i-=3)
1116 	ajStrAppendK(pep, trnObj->GC[trncomp[(ajint)str[i]]]
1117 		                    [trncomp[(ajint)str[i-1]]]
1118 		                    [trncomp[(ajint)str[i-2]]]);
1119 
1120     return;
1121 }
1122 
1123 
1124 
1125 
1126 /* @func ajTrnSeqAltRevinitC **************************************************
1127 **
1128 ** Translates the reverse complement of a sequence in a char *.
1129 ** If the sequence begins with a defined alternative start codon,
1130 ** the residue is replaced with Methionine.
1131 **
1132 ** This routine translates in frame -4 (from the last base) to the first full
1133 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the start, they are
1134 ** ignored).
1135 ** This routine is for those people who define frame '-1' as being the
1136 ** frame starting from the first base of a reverse-complemented sequence.
1137 **
1138 **
1139 ** @param [r] trnObj [const AjPTrn] Translation tables
1140 ** @param [r] str [const char *] sequence string to translate
1141 ** @param [r] len [ajint] length of sequence string to translate
1142 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1143 **
1144 ** @return [void]
1145 ** @category use [AjPTrn] (Alt) Reverse complement translating a
1146 **                sequence from a char* text
1147 **
1148 ** @release 6.2.0
1149 ** @@
1150 ******************************************************************************/
1151 
ajTrnSeqAltRevinitC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)1152 void ajTrnSeqAltRevinitC(const AjPTrn trnObj, const char *str, ajint len,
1153                          AjPStr *pep)
1154 {
1155     ajint i;
1156     ajint iend;
1157 
1158     iend = len-1;
1159 
1160     if(iend > 1)
1161     {
1162         if('M' == trnObj->Starts[trncomp[(ajint)str[iend]]]
1163                                 [trncomp[(ajint)str[iend-1]]]
1164                                 [trncomp[(ajint)str[iend-2]]])
1165         {
1166             iend -= 3;
1167             ajStrAppendK(pep, 'M');
1168         }
1169     }
1170 
1171 
1172     for(i=iend; i>1; i-=3)
1173 	ajStrAppendK(pep, trnObj->GC[trncomp[(ajint)str[i]]]
1174 		                    [trncomp[(ajint)str[i-1]]]
1175 		                    [trncomp[(ajint)str[i-2]]]);
1176 
1177     return;
1178 }
1179 
1180 
1181 
1182 
1183 /* @func ajTrnSeqS ************************************************************
1184 **
1185 ** Translates a sequence in a AjPStr.
1186 **
1187 ** This routine translates in frame 1 (from the first base) to the last full
1188 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the end, they are
1189 ** ignored)
1190 **
1191 **
1192 ** @param [r] trnObj [const AjPTrn] Translation tables
1193 ** @param [r] str [const AjPStr] sequence string to translate
1194 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1195 **
1196 ** @return [void]
1197 ** @category use [AjPTrn] Translating a sequence from a
1198 **                AjPStr
1199 **
1200 ** @release 6.2.0
1201 ** @@
1202 ******************************************************************************/
1203 
ajTrnSeqS(const AjPTrn trnObj,const AjPStr str,AjPStr * pep)1204 void ajTrnSeqS(const AjPTrn trnObj, const AjPStr str, AjPStr *pep)
1205 {
1206     ajTrnSeqC(trnObj, ajStrGetPtr(str), ajStrGetLen(str), pep);
1207 
1208     return;
1209 }
1210 
1211 
1212 
1213 
1214 /* @func ajTrnRevStr **********************************************************
1215 **
1216 ** Translates the reverse complement of a sequence in a AjPStr.
1217 **
1218 ** This routine translates in frame -1 (from the first base) to the last full
1219 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the end, they are
1220 ** ignored)
1221 **
1222 **
1223 ** @param [r] trnObj [const AjPTrn] Translation tables
1224 ** @param [r] str [const AjPStr] sequence string to translate
1225 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1226 **
1227 ** @return [void]
1228 ** @category use [AjPTrn] Reverse complement translating a sequence
1229 **                from a AjPStr
1230 **
1231 ** @release 1.0.0
1232 ** @@
1233 ******************************************************************************/
1234 
ajTrnRevStr(const AjPTrn trnObj,const AjPStr str,AjPStr * pep)1235 void ajTrnRevStr(const AjPTrn trnObj, const AjPStr str, AjPStr *pep)
1236 {
1237     ajTrnSeqRevC(trnObj, ajStrGetPtr(str), ajStrGetLen(str), pep);
1238 
1239     return;
1240 }
1241 
1242 
1243 
1244 
1245 /* @func ajTrnSeqAltRevS ******************************************************
1246 **
1247 ** Translates the reverse complement of a sequence in a AjPStr.
1248 **
1249 ** This routine translates in frame -4 (from the last base) to the first full
1250 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the start, they are
1251 ** ignored).
1252 ** This routine is for those people who define frame '-1' as being the
1253 ** frame starting from the first base of a reverse-complemented sequence.
1254 **
1255 **
1256 ** @param [r] trnObj [const AjPTrn] Translation tables
1257 ** @param [r] str [const AjPStr] sequence string to translate
1258 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1259 **
1260 ** @return [void]
1261 ** @category use [AjPTrn] (Alt) Reverse complement translating a
1262 **                sequence from a AjPStr
1263 **
1264 ** @release 6.2.0
1265 ** @@
1266 ******************************************************************************/
1267 
ajTrnSeqAltRevS(const AjPTrn trnObj,const AjPStr str,AjPStr * pep)1268 void ajTrnSeqAltRevS(const AjPTrn trnObj, const AjPStr str, AjPStr *pep)
1269 {
1270     ajTrnSeqAltRevC(trnObj, ajStrGetPtr(str), ajStrGetLen(str), pep);
1271 
1272     return;
1273 }
1274 
1275 
1276 
1277 
1278 /* @func ajTrnSeqSeq **********************************************************
1279 **
1280 ** Translates a sequence in a AjPSeq
1281 **
1282 ** This routine translates in frame 1 (from the first base) to the last full
1283 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the end, they are
1284 ** ignored)
1285 **
1286 **
1287 ** @param [r] trnObj [const AjPTrn] Translation tables
1288 ** @param [r] seq [const AjPSeq] sequence to translate
1289 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1290 **
1291 ** @return [void]
1292 ** @category use [AjPTrn] Translating a sequence from a
1293 **                AjPSeq
1294 **
1295 ** @release 6.2.0
1296 ** @@
1297 ******************************************************************************/
1298 
ajTrnSeqSeq(const AjPTrn trnObj,const AjPSeq seq,AjPStr * pep)1299 void ajTrnSeqSeq(const AjPTrn trnObj, const AjPSeq seq, AjPStr *pep)
1300 {
1301     ajTrnSeqC(trnObj, ajSeqGetSeqC(seq), ajSeqGetLen(seq), pep);
1302 
1303     return;
1304 }
1305 
1306 
1307 
1308 
1309 /* @func ajTrnSeqRevSeq *******************************************************
1310 **
1311 ** Translates the reverse complement of a sequence in a AjPSeq
1312 ** The translation is APPENDED to the input peptide.
1313 **
1314 ** This routine translates in frame 1 (from the first base) to the last full
1315 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the end, they are
1316 ** ignored)
1317 **
1318 **
1319 ** @param [r] trnObj [const AjPTrn] Translation tables
1320 ** @param [r] seq [const AjPSeq] sequence to translate
1321 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1322 **
1323 ** @return [void]
1324 ** @category use [AjPTrn] Reverse complement translating a sequence
1325 **                from a AjPSeq
1326 **
1327 ** @release 6.2.0
1328 ** @@
1329 ******************************************************************************/
1330 
ajTrnSeqRevSeq(const AjPTrn trnObj,const AjPSeq seq,AjPStr * pep)1331 void ajTrnSeqRevSeq(const AjPTrn trnObj, const AjPSeq seq, AjPStr *pep)
1332 {
1333     ajTrnSeqRevC(trnObj, ajSeqGetSeqC(seq), ajSeqGetLen(seq), pep);
1334 
1335     return;
1336 }
1337 
1338 
1339 
1340 
1341 /* @func ajTrnSeqAltRevSeq ****************************************************
1342 **
1343 ** Translates the reverse complement of a sequence in a AjPSeq
1344 ** The translation is APPENDED to the input peptide.
1345 **
1346 ** This routine translates in frame -4 (from the last base) to the first full
1347 ** triplet codon, (i.e. if there are 1 or 2 bases extra at the start, they are
1348 ** ignored).
1349 ** This routine is for those people who define frame '-1' as being the
1350 ** frame starting from the first base of a reverse-complemented sequence.
1351 **
1352 **
1353 **
1354 ** @param [r] trnObj [const AjPTrn] Translation tables
1355 ** @param [r] seq [const AjPSeq] sequence to translate
1356 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1357 **
1358 ** @return [void]
1359 ** @category use [AjPTrn] Reverse complement translating a sequence
1360 **                from a AjPSeq
1361 **
1362 ** @release 6.2.0
1363 ** @@
1364 ******************************************************************************/
1365 
ajTrnSeqAltRevSeq(const AjPTrn trnObj,const AjPSeq seq,AjPStr * pep)1366 void ajTrnSeqAltRevSeq(const AjPTrn trnObj, const AjPSeq seq, AjPStr *pep)
1367 {
1368     ajTrnSeqAltRevC(trnObj, ajSeqGetSeqC(seq), ajSeqGetLen(seq), pep);
1369 
1370     return;
1371 }
1372 
1373 
1374 
1375 
1376 /* @func ajTrnSeqFrameC *******************************************************
1377 **
1378 ** Translates a sequence in a char * in the specified frame.
1379 ** The translation is APPENDED to the input peptide.
1380 **
1381 ** This routine translates in the specified frame (one of:
1382 ** 1,2,3,-1,-2,-3,4,5,6,-4,-5,-6) to the last full triplet codon,
1383 ** (i.e.  if there are 1 or 2 bases extra at the end, they are ignored).
1384 **
1385 ** Frame -1 is defined as the translation of the reverse complement
1386 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1387 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1388 ** is the reverse complement of ACG (i.e.  CGT).
1389 **
1390 ** Frame -4 is defined as the translation from the last base to the first full
1391 ** triplet codon.
1392 ** This routine is for those people who define frame '-1' as being the
1393 ** frame starting from the first base of a reverse-complemented sequence.
1394 ** This is also known as the 'alternative frame -1'.
1395 ** Frame -5 starts on the penultimate base. (Alternative frame -2)
1396 ** Frame -6 starts on the ante-penultimate base. (Alternative frame -3)
1397 **
1398 ** Frame 4 is the same as frame -1, 5 is -2, 6 is -3.
1399 **
1400 ** @param [r] trnObj [const AjPTrn] Translation tables
1401 ** @param [r] seq [const char *] sequence string to translate
1402 ** @param [r] len [ajint] length of sequence string to translate
1403 ** @param [r] frame [ajint] frame to translate in
1404 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1405 **
1406 ** @return [void]
1407 ** @category use [AjPTrn] Translating a sequence from a char* in a
1408 **                frame
1409 **
1410 ** @release 6.2.0
1411 ** @@
1412 ******************************************************************************/
1413 
ajTrnSeqFrameC(const AjPTrn trnObj,const char * seq,ajint len,ajint frame,AjPStr * pep)1414 void ajTrnSeqFrameC(const AjPTrn trnObj,
1415                     const char *seq, ajint len,
1416                     ajint frame, AjPStr *pep)
1417 {
1418 
1419     if(frame > 3)
1420         frame = -frame + 3;
1421 
1422     if(frame >= 1 && frame <= 3)
1423     {
1424 	/* len = REAL length passed over */
1425 	ajTrnSeqC(trnObj, &seq[frame-1], len-frame+1, pep);
1426     }
1427     else if(frame >= -3 && frame <= -1)
1428     {
1429 	/* len = REAL length passed over */
1430 	ajTrnSeqRevC(trnObj, &seq[-frame-1], len+frame+1, pep);
1431     }
1432     else if(frame >= -6 && frame <= -4)
1433 	ajTrnSeqAltRevC(trnObj, seq, len+frame+4 , pep);
1434     else
1435 	ajFatal("Invalid frame '%d' in ajTrnSeqFrameC()\n", frame);
1436 
1437     return;
1438 }
1439 
1440 
1441 
1442 
1443 /* @func ajTrnSeqFrameS *******************************************************
1444 **
1445 ** Translates a sequence in a AjStr in the specified frame.
1446 ** The translation is APPENDED to the input peptide.
1447 **
1448 ** This routine translates in the specified frame (one of:
1449 ** 1,2,3,-1,-2,-3,4,5,6,-4,-5,-6) to the last full triplet codon,
1450 ** (i.e.  if there are 1 or 2 bases extra at the end, they are ignored).
1451 **
1452 ** Frame -1 is defined as the translation of the reverse complement
1453 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1454 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1455 ** is the reverse complement of ACG (i.e.  CGT).
1456 **
1457 ** Frame -4 is defined as the translation from the last base to the first full
1458 ** triplet codon.
1459 ** This routine is for those people who define frame '-1' as being the
1460 ** frame starting from the first base of a reverse-complemented sequence.
1461 ** This is also known as the 'alternative frame -1'.
1462 ** Frame -5 starts on the penultimate base. (Alternative frame -2)
1463 ** Frame -6 starts on the ante-penultimate base. (Alternative frame -3)
1464 **
1465 ** Frame 4 is the same as frame -1, 5 is -2, 6 is -3.
1466 **
1467 ** @param [r] trnObj [const AjPTrn] Translation tables
1468 ** @param [r] seq [const AjPStr] sequence string to translate
1469 ** @param [r] frame [ajint] frame to translate in
1470 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1471 **
1472 ** @return [void]
1473 ** @category use [AjPTrn] Translating a sequence from a AjPStr in a
1474 **                frame
1475 **
1476 ** @release 6.2.0
1477 ** @@
1478 ******************************************************************************/
1479 
ajTrnSeqFrameS(const AjPTrn trnObj,const AjPStr seq,ajint frame,AjPStr * pep)1480 void ajTrnSeqFrameS(const AjPTrn trnObj, const AjPStr seq, ajint frame,
1481                     AjPStr *pep)
1482 {
1483     ajTrnSeqFrameC(trnObj, ajStrGetPtr(seq), ajStrGetLen(seq), frame, pep);
1484 
1485     return;
1486 }
1487 
1488 
1489 
1490 
1491 /* @func ajTrnSeqFrameInitC ***************************************************
1492 **
1493 ** Translates a sequence in a char * in the specified frame.
1494 ** The translation is APPENDED to the input peptide.
1495 ** If the sequence begins with a defined alternative start codon,
1496 ** the residue is replaced with Methionine.
1497 **
1498 ** This routine translates in the specified frame (one of:
1499 ** 1,2,3,-1,-2,-3,4,5,6,-4,-5,-6) to the last full triplet codon,
1500 ** (i.e.  if there are 1 or 2 bases extra at the end, they are ignored).
1501 **
1502 ** Frame -1 is defined as the translation of the reverse complement
1503 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1504 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1505 ** is the reverse complement of ACG (i.e.  CGT).
1506 **
1507 ** Frame -4 is defined as the translation from the last base to the first full
1508 ** triplet codon.
1509 ** This routine is for those people who define frame '-1' as being the
1510 ** frame starting from the first base of a reverse-complemented sequence.
1511 ** This is also known as the 'alternative frame -1'.
1512 ** Frame -5 starts on the penultimate base. (Alternative frame -2)
1513 ** Frame -6 starts on the ante-penultimate base. (Alternative frame -3)
1514 **
1515 ** Frame 4 is the same as frame -1, 5 is -2, 6 is -3.
1516 **
1517 ** @param [r] trnObj [const AjPTrn] Translation tables
1518 ** @param [r] seq [const char *] sequence string to translate
1519 ** @param [r] len [ajint] length of sequence string to translate
1520 ** @param [r] frame [ajint] frame to translate in
1521 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1522 **
1523 ** @return [void]
1524 ** @category use [AjPTrn] Translating a sequence from a char* in a
1525 **                frame
1526 **
1527 ** @release 6.2.0
1528 ** @@
1529 ******************************************************************************/
1530 
ajTrnSeqFrameInitC(const AjPTrn trnObj,const char * seq,ajint len,ajint frame,AjPStr * pep)1531 void ajTrnSeqFrameInitC(const AjPTrn trnObj,
1532                         const char *seq, ajint len,
1533                         ajint frame, AjPStr *pep)
1534 {
1535 
1536     if(frame > 3)
1537         frame = -frame + 3;
1538 
1539     if(frame >= 1 && frame <= 3)
1540     {
1541 	/* len = REAL length passed over */
1542 	ajTrnSeqInitC(trnObj, &seq[frame-1], len-frame+1, pep);
1543     }
1544     else if(frame >= -3 && frame <= -1)
1545     {
1546 	/* len = REAL length passed over */
1547 	ajTrnSeqRevinitC(trnObj, &seq[-frame-1], len+frame+1, pep);
1548     }
1549     else if(frame >= -6 && frame <= -4)
1550 	ajTrnSeqAltRevinitC(trnObj, seq, len+frame+4 , pep);
1551     else
1552 	ajFatal("Invalid frame '%d' in ajTrnSeqFrameC()\n", frame);
1553 
1554     return;
1555 }
1556 
1557 
1558 
1559 
1560 /* @func ajTrnSeqFrameInitS ***************************************************
1561 **
1562 ** Translates a sequence in a AjStr in the specified frame.
1563 ** The translation is APPENDED to the input peptide.
1564 ** If the sequence begins with a defined alternative start codon,
1565 ** the residue is replaced with Methionine.
1566 **
1567 ** This routine translates in the specified frame (one of:
1568 ** 1,2,3,-1,-2,-3,4,5,6,-4,-5,-6) to the last full triplet codon,
1569 ** (i.e.  if there are 1 or 2 bases extra at the end, they are ignored).
1570 **
1571 ** Frame -1 is defined as the translation of the reverse complement
1572 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1573 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1574 ** is the reverse complement of ACG (i.e.  CGT).
1575 **
1576 ** Frame -4 is defined as the translation from the last base to the first full
1577 ** triplet codon.
1578 ** This routine is for those people who define frame '-1' as being the
1579 ** frame starting from the first base of a reverse-complemented sequence.
1580 ** This is also known as the 'alternative frame -1'.
1581 ** Frame -5 starts on the penultimate base. (Alternative frame -2)
1582 ** Frame -6 starts on the ante-penultimate base. (Alternative frame -3)
1583 **
1584 ** Frame 4 is the same as frame -1, 5 is -2, 6 is -3.
1585 **
1586 ** @param [r] trnObj [const AjPTrn] Translation tables
1587 ** @param [r] seq [const AjPStr] sequence string to translate
1588 ** @param [r] frame [ajint] frame to translate in
1589 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1590 **
1591 ** @return [void]
1592 ** @category use [AjPTrn] Translating a sequence from a AjPStr in a
1593 **                frame
1594 **
1595 ** @release 6.2.0
1596 ** @@
1597 ******************************************************************************/
1598 
ajTrnSeqFrameInitS(const AjPTrn trnObj,const AjPStr seq,ajint frame,AjPStr * pep)1599 void ajTrnSeqFrameInitS(const AjPTrn trnObj, const AjPStr seq, ajint frame,
1600                         AjPStr *pep)
1601 {
1602     ajTrnSeqFrameInitC(trnObj, ajStrGetPtr(seq), ajStrGetLen(seq), frame, pep);
1603 
1604     return;
1605 }
1606 
1607 
1608 
1609 
1610 /* @func ajTrnSeqFrameSeq *****************************************************
1611 **
1612 ** Translates a sequence in an AjPSeq in the specified frame.
1613 ** The translation is APPENDED to the input peptide.
1614 **
1615 ** This routine translates in the specified frame (one of:
1616 ** 1,2,3,-1,-2,-3,4,5,6,-4,-5,-6) to the last full triplet codon,
1617 ** (i.e.  if there are 1 or 2 bases extra at the end, they are ignored).
1618 **
1619 ** Frame -1 is defined as the translation of the reverse complement
1620 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1621 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1622 ** is the reverse complement of ACG (i.e.  CGT).
1623 **
1624 ** Frame -4 is defined as the translation from the last base to the first full
1625 ** triplet codon.
1626 ** This routine is for those people who define frame '-1' as being the
1627 ** frame starting from the first base of a reverse-complemented sequence.
1628 ** This is also known as the 'alternative frame -1'.
1629 ** Frame -5 starts on the penultimate base. (Alternative frame -2)
1630 ** Frame -6 starts on the ante-penultimate base. (Alternative frame -3)
1631 **
1632 ** Frame 4 is the same as frame -1, 5 is -2, 6 is -3.
1633 **
1634 **
1635 ** @param [r] trnObj [const AjPTrn] Translation tables
1636 ** @param [r] seq [const AjPSeq] sequence string to translate
1637 ** @param [r] frame [ajint] frame to translate in
1638 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1639 **
1640 ** @return [void]
1641 ** @category use [AjPTrn] Translating a sequence from a AjPSeq in a
1642 **                frame
1643 **
1644 ** @release 6.2.0
1645 ** @@
1646 ******************************************************************************/
1647 
ajTrnSeqFrameSeq(const AjPTrn trnObj,const AjPSeq seq,ajint frame,AjPStr * pep)1648 void ajTrnSeqFrameSeq(const AjPTrn trnObj, const AjPSeq seq, ajint frame,
1649                       AjPStr *pep)
1650 {
1651     ajTrnSeqFrameC(trnObj, ajSeqGetSeqC(seq), ajSeqGetLen(seq), frame, pep);
1652 
1653     return;
1654 }
1655 
1656 
1657 
1658 
1659 /* @func ajTrnSeqFrameSeqInit *************************************************
1660 **
1661 ** Translates a sequence in an AjPSeq in the specified frame.
1662 ** The translation is APPENDED to the input peptide.
1663 ** If the sequence begins with a defined alternative start codon,
1664 ** the residue is replaced with Methionine.
1665 **
1666 ** This routine translates in the specified frame (one of:
1667 ** 1,2,3,-1,-2,-3,4,5,6,-4,-5,-6) to the last full triplet codon,
1668 ** (i.e.  if there are 1 or 2 bases extra at the end, they are ignored).
1669 **
1670 ** Frame -1 is defined as the translation of the reverse complement
1671 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1672 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1673 ** is the reverse complement of ACG (i.e.  CGT).
1674 **
1675 ** Frame -4 is defined as the translation from the last base to the first full
1676 ** triplet codon.
1677 ** This routine is for those people who define frame '-1' as being the
1678 ** frame starting from the first base of a reverse-complemented sequence.
1679 ** This is also known as the 'alternative frame -1'.
1680 ** Frame -5 starts on the penultimate base. (Alternative frame -2)
1681 ** Frame -6 starts on the ante-penultimate base. (Alternative frame -3)
1682 **
1683 ** Frame 4 is the same as frame -1, 5 is -2, 6 is -3.
1684 **
1685 **
1686 ** @param [r] trnObj [const AjPTrn] Translation tables
1687 ** @param [r] seq [const AjPSeq] sequence string to translate
1688 ** @param [r] frame [ajint] frame to translate in
1689 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1690 **
1691 ** @return [void]
1692 ** @category use [AjPTrn] Translating a sequence from a AjPSeq in a
1693 **                frame
1694 **
1695 ** @release 6.2.0
1696 ** @@
1697 ******************************************************************************/
1698 
ajTrnSeqFrameSeqInit(const AjPTrn trnObj,const AjPSeq seq,ajint frame,AjPStr * pep)1699 void ajTrnSeqFrameSeqInit(const AjPTrn trnObj, const AjPSeq seq, ajint frame,
1700                           AjPStr *pep)
1701 {
1702     ajTrnSeqFrameInitC(trnObj, ajSeqGetSeqC(seq), ajSeqGetLen(seq),
1703                        frame, pep);
1704 
1705     return;
1706 }
1707 
1708 
1709 
1710 
1711 /* @func ajTrnSeqFramePep *****************************************************
1712 **
1713 ** Translates a sequence in a AjSeq in the specified frame and returns a
1714 ** new peptide.
1715 **
1716 ** This routine translates in the specified frame (one of:
1717 ** 1,2,3,-1,-2,-3,4,5,6,-4,-5,-6) to the last full triplet codon,
1718 ** (i.e.  if there are 1 or 2 bases extra at the end, they are ignored).
1719 **
1720 ** Frame -1 is defined as the translation of the reverse complement
1721 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1722 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1723 ** is the reverse complement of ACG (i.e.  CGT).
1724 **
1725 ** Frame -4 is defined as the translation from the last base to the first full
1726 ** triplet codon.
1727 ** This routine is for those people who define frame '-1' as being the
1728 ** frame starting from the first base of a reverse-complemented sequence.
1729 ** This is also known as the 'alternative frame -1'.
1730 ** Frame -5 starts on the penultimate base. (Alternative frame -2)
1731 ** Frame -6 starts on the ante-penultimate base. (Alternative frame -3)
1732 **
1733 ** Frame 4 is the same as frame -1, 5 is -2, 6 is -3.
1734 **
1735 ** NB.  that the naming of the output sequence is always to take
1736 ** the name of the input sequence (e.g.  ECARGS) and to append an underscore
1737 ** character and the frame number 1 to 3 for forward frames and 4 to 6 for
1738 ** reverse frames regardless of the final orientation of the reverse
1739 ** frames.  (i.e.  frame -1 = ECARGS_4, frame -2 = ECARGS_5, -3 = ECARGS_6, 4 =
1740 ** ECARGS_4, 5 = ECARGS_5 6 = ECARGS_6)
1741 **
1742 ** @param [r] trnObj [const AjPTrn] Translation tables
1743 ** @param [r] seq [const AjPSeq] sequence string to translate
1744 ** @param [r] frame [ajint] frame to translate in
1745 **
1746 ** @return [AjPSeq] returned peptide translation
1747 ** @category use [AjPTrn] Translating a sequence from a AjPSeq in a
1748 **                frame and returns a new peptide
1749 **
1750 ** @release 2.0.0
1751 ** @@
1752 ******************************************************************************/
1753 
ajTrnSeqFramePep(const AjPTrn trnObj,const AjPSeq seq,ajint frame)1754 AjPSeq ajTrnSeqFramePep(const AjPTrn trnObj, const AjPSeq seq, ajint frame)
1755 {
1756     AjPSeq pep = NULL;
1757     AjPStr trn = NULL;
1758 
1759     pep = ajTrnNewPep(seq, frame);
1760     trn = ajStrNew();
1761 
1762     ajTrnSeqFrameSeq(trnObj, seq, frame, &trn);
1763     ajSeqAssignSeqS(pep, trn);
1764 
1765     ajStrDel(&trn);
1766 
1767     return pep;
1768 }
1769 
1770 
1771 
1772 
1773 /* @func ajTrnSeqDangleC ******************************************************
1774 **
1775 ** Translates the last 1 or two bases of a sequence in a char *
1776 ** that would not be translated if just translating complete codons
1777 ** in the specified frame.
1778 ** The translation is APPENDED to the input peptide.
1779 **
1780 ** @param [r] trnObj [const AjPTrn] Translation tables
1781 ** @param [r] seq [const char *] sequence string to translate
1782 ** @param [r] frame [ajint] frame to translate in
1783 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1784 **
1785 ** @return [ajint] Number of dangling bases (0,1 or 2)
1786 ** @category use [AjPTrn] Translates the last 1 or two bases of a
1787 **                sequence in a char* text
1788 **
1789 ** @release 6.2.0
1790 ** @@
1791 ******************************************************************************/
1792 
ajTrnSeqDangleC(const AjPTrn trnObj,const char * seq,ajint frame,AjPStr * pep)1793 ajint ajTrnSeqDangleC(const AjPTrn trnObj, const char *seq,
1794                       ajint frame, AjPStr *pep)
1795 {
1796     ajint end = 0; 	          /* end base of last complete forward codon */
1797     ajint dangle;		  /* number of bases at the end              */
1798     ajuint len = strlen(seq);
1799 
1800     if(frame > 3)			/* convert frames 4,5,6 to -1,-2,-3 */
1801 	frame = -frame + 3;
1802 
1803     if(frame > 0)
1804     {					/* forward 3 frames */
1805 	end = frame + ((len-frame+1)/3)*3 - 1;
1806 	dangle = len - end;
1807     }
1808     else if(frame <= -4)		/* alternative reverse frames */
1809 	dangle = (len+frame+4)%3;
1810     else				/* standard reverse frames */
1811 	dangle = -frame-1;
1812 
1813     /* translate any dangling pair of bases at the end */
1814     if(dangle == 2)
1815     {
1816 	if(frame >= 1 && frame <= 3)
1817 	    ajStrAppendK(pep, trnObj->GC[trnconv[(ajint)seq[end]]]
1818 		                        [trnconv[(ajint)seq[end+1]]]
1819 		                        [trnconv[0]]);
1820 	else	/* reverse sense */
1821 	    ajStrAppendK(pep, trnObj->GC[trncomp[(ajint)seq[1]]]
1822 		                        [trncomp[(ajint)seq[0]]]
1823 		                        [trncomp[0]]);
1824     }
1825     else if(dangle == 1) /* Make up single base translation */
1826 	ajStrAppendK(pep, 'X');
1827 
1828     return dangle;
1829 }
1830 
1831 
1832 
1833 
1834 
1835 /* @func ajTrnSeqDangleS ******************************************************
1836 **
1837 ** Translates the last 1 or two bases of a sequence in a AjStr
1838 ** that would not be translated if just translating complete codons
1839 ** in the specified frame.
1840 ** The translation is APPENDED to the input peptide.
1841 **
1842 ** @param [r] trnObj [const AjPTrn] Translation tables
1843 ** @param [r] seq [const AjPStr] sequence string to translate
1844 ** @param [r] frame [ajint] frame to translate in
1845 ** @param [u] pep [AjPStr *] returned peptide translation (APPENDED TO INPUT)
1846 **
1847 ** @return [ajint] Number of dangling bases (0,1 or 2)
1848 **	dangle = len - end;
1849 ** @category use [AjPTrn] Translates the last 1 or two bases of a
1850 **                sequence in a AjStr
1851 **
1852 ** @release 6.2.0
1853 ** @@
1854 ******************************************************************************/
1855 
ajTrnSeqDangleS(const AjPTrn trnObj,const AjPStr seq,ajint frame,AjPStr * pep)1856 ajint ajTrnSeqDangleS(const AjPTrn trnObj, const AjPStr seq, ajint frame,
1857                       AjPStr *pep)
1858 {
1859     ajint end = 0; 	          /* end base of last complete forward codon */
1860     ajint dangle;		  /* number of bases at the end              */
1861     ajuint len = ajStrGetLen(seq);
1862     const char* cp = ajStrGetPtr(seq);
1863 
1864     if(frame > 3)			/* convert frames 4,5,6 to -1,-2,-3 */
1865 	frame = -frame + 3;
1866 
1867     if(frame > 0)
1868     {					/* forward 3 frames */
1869 	end = frame + ((len-frame+1)/3)*3 - 1;
1870 	dangle = len - end;
1871     }
1872     else if(frame <= -4)		/* alternative reverse frames */
1873 	dangle = (len+frame+4)%3;
1874     else				/* standard reverse frames */
1875 	dangle = -frame-1;
1876 
1877     /* translate any dangling pair of bases at the end */
1878     if(dangle == 2)
1879     {
1880 	if(frame >= 1 && frame <= 3)
1881 	    ajStrAppendK(pep, trnObj->GC[trnconv[(ajint)cp[end]]]
1882 		                        [trnconv[(ajint)cp[end+1]]]
1883 		                        [trnconv[0]]);
1884 	else	/* reverse sense */
1885 	    ajStrAppendK(pep, trnObj->GC[trncomp[(ajint)cp[1]]]
1886 		                        [trncomp[(ajint)cp[0]]]
1887 		                        [trncomp[0]]);
1888     }
1889     else if(dangle == 1) /* Make up single base translation */
1890 	ajStrAppendK(pep, 'X');
1891 
1892     return dangle;
1893 }
1894 
1895 
1896 
1897 
1898 /* @func ajTrnSeqInit *********************************************************
1899 **
1900 ** Translates a sequence, correcting first residue to methionine if it is a
1901 ** defined start codon in the translation table.
1902 **
1903 ** The frame to translate is in the range -3 to 6.
1904 ** Frames 1 to 3 give normal forward translations.
1905 **
1906 ** Frames -3 to -1 give translations in the reverse sense.
1907 ** Frame -1 is defined as the translation of the reverse complement
1908 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1909 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1910 ** is the reverse complement of ACG (i.e.  CGT).
1911 **
1912 ** Frames -4 to -6 give translations in the reverse sense.
1913 ** Frame -4 is defined as the translation of the reverse complement,
1914 ** starting the translation in the first codon of the reversed sequence.
1915 ** i.e.  in the sequence ACGT, the last codon is CGT and so frame -4
1916 ** translates from the reverse complement of CGT (i.e.  ACG) - this is
1917 ** for those people who define frame -1 as using the first codon when the
1918 ** sequence is reverse-complemented.
1919 **
1920 ** Frames 4 to 6 rev-comp the DNA sequence then reverse the peptide sequence
1921 **
1922 ** Frames 4 to 6 are therefore a reversed protein sequence useful mainly for
1923 **  displaying beneath the original DNA sequence.
1924 **
1925 ** NB.  that the naming of the output sequence is always to take
1926 ** the name of the input sequence (e.g.  ECARGS) and to append an underscore
1927 ** character and the frame number 1 to 3 for forward frames and 4 to 6 for
1928 ** reverse frames regardless of the final orientation of the reverse
1929 ** frames.  (i.e.  frame -1 = ECARGS_4, frame -2 = ECARGS_5, -3 = ECARGS_6, 4 =
1930 ** ECARGS_4, 5 = ECARGS_5 6 = ECARGS_6)
1931 **
1932 ** @param [r] trnObj [const AjPTrn] Translation tables
1933 ** @param [r] seq [const AjPSeq] sequence to translate
1934 ** @param [r] frame [ajint] frame to translate in (-6 to 6)
1935 **
1936 ** @return [AjPSeq] Peptide translation
1937 ** @category use [AjPTrn] Translating a sequence
1938 ** @category new [AjPSeq] Translating a sequence
1939 **
1940 ** @release 1.0.0
1941 ** @@
1942 ******************************************************************************/
1943 
ajTrnSeqInit(const AjPTrn trnObj,const AjPSeq seq,ajint frame)1944 AjPSeq ajTrnSeqInit(const AjPTrn trnObj, const AjPSeq seq, ajint frame)
1945 {
1946     AjPSeq pep = NULL;
1947     AjPStr trn = NULL;
1948 
1949     pep = ajTrnNewPep(seq, frame);
1950     trn = ajStrNew();
1951 
1952     ajTrnSeqFrameSeqInit(trnObj, seq, frame, &trn);
1953 
1954     /*
1955     ** if there are any dangling bases, then attempt to
1956     ** translate them
1957     */
1958     ajTrnSeqDangleS(trnObj, ajSeqGetSeqS(seq), frame, &trn);
1959 
1960     /*
1961     ** if frame is 4, 5 or 6 then reverse the peptide for displaying beneath
1962     ** the original DNA sequence
1963     */
1964     if(frame > 3)
1965 	ajStrReverse(&trn);
1966 
1967     ajSeqAssignSeqS(pep, trn);
1968 
1969     ajStrDel(&trn);
1970 
1971     return pep;
1972 }
1973 
1974 
1975 
1976 
1977 /* @func ajTrnSeqOrig *********************************************************
1978 **
1979 ** Translates a sequence.
1980 **
1981 ** The frame to translate is in the range -3 to 6.
1982 ** Frames 1 to 3 give normal forward translations.
1983 **
1984 ** Frames -3 to -1 give translations in the reverse sense.
1985 ** Frame -1 is defined as the translation of the reverse complement
1986 ** sequence which matches the codons used in frame 1.  i.e.  in the sequence
1987 ** ACGT, the first codon of frame 1 is ACG and the last codon of frame -1
1988 ** is the reverse complement of ACG (i.e.  CGT).
1989 **
1990 ** Frames -4 to -6 give translations in the reverse sense.
1991 ** Frame -4 is defined as the translation of the reverse complement,
1992 ** starting the translation in the first codon of the reversed sequence.
1993 ** i.e.  in the sequence ACGT, the last codon is CGT and so frame -4
1994 ** translates from the reverse complement of CGT (i.e.  ACG) - this is
1995 ** for those people who define frame -1 as using the first codon when the
1996 ** sequence is reverse-complemented.
1997 **
1998 ** Frames 4 to 6 rev-comp the DNA sequence then reverse the peptide sequence
1999 **
2000 ** Frames 4 to 6 are therefore a reversed protein sequence useful mainly for
2001 **  displaying beneath the original DNA sequence.
2002 **
2003 ** NB.  that the naming of the output sequence is always to take
2004 ** the name of the input sequence (e.g.  ECARGS) and to append an underscore
2005 ** character and the frame number 1 to 3 for forward frames and 4 to 6 for
2006 ** reverse frames regardless of the final orientation of the reverse
2007 ** frames.  (i.e.  frame -1 = ECARGS_4, frame -2 = ECARGS_5, -3 = ECARGS_6, 4 =
2008 ** ECARGS_4, 5 = ECARGS_5 6 = ECARGS_6)
2009 **
2010 ** @param [r] trnObj [const AjPTrn] Translation tables
2011 ** @param [r] seq [const AjPSeq] sequence to translate
2012 ** @param [r] frame [ajint] frame to translate in (-6 to 6)
2013 **
2014 ** @return [AjPSeq] Peptide translation
2015 ** @category use [AjPTrn] Translating a sequence
2016 ** @category new [AjPSeq] Translating a sequence
2017 **
2018 ** @release 1.0.0
2019 ** @@
2020 ******************************************************************************/
2021 
ajTrnSeqOrig(const AjPTrn trnObj,const AjPSeq seq,ajint frame)2022 AjPSeq ajTrnSeqOrig(const AjPTrn trnObj, const AjPSeq seq, ajint frame)
2023 {
2024     AjPSeq pep = NULL;
2025     AjPStr trn = NULL;
2026 
2027     pep = ajTrnNewPep(seq, frame);
2028     trn = ajStrNew();
2029 
2030     ajTrnSeqFrameSeq(trnObj, seq, frame, &trn);
2031 
2032     /*
2033     ** if there are any dangling bases, then attempt to
2034     ** translate them
2035     */
2036     ajTrnSeqDangleS(trnObj, ajSeqGetSeqS(seq), frame, &trn);
2037 
2038     /*
2039     ** if frame is 4, 5 or 6 then reverse the peptide for displaying beneath
2040     ** the original DNA sequence
2041     */
2042     if(frame > 3)
2043 	ajStrReverse(&trn);
2044 
2045     ajSeqAssignSeqS(pep, trn);
2046 
2047     ajStrDel(&trn);
2048 
2049     return pep;
2050 }
2051 
2052 
2053 
2054 
2055 /* @func ajTrnCodonstrTypeC ***************************************************
2056 **
2057 ** Checks whether a const char * codon is a Start codon, a Stop codon or
2058 ** something else
2059 **
2060 ** @param [r] trnObj [const AjPTrn] Translation tables
2061 ** @param [r] codon [const char *] codon to translate
2062 **                           (these 3 characters need not be NULL-terminated)
2063 ** @param [w] aa [char *] returned translated amino acid
2064 **                        (not a NULL-terminated array of char)
2065 ** @return [ajint] 1 if it is a start codon, -1 if it is a stop codon, else 0
2066 ** @category use [AjPTrn] Checks whether a const char* codon is a
2067 **                Start codon, a Stop codon or something else
2068 **
2069 ** @release 6.2.0
2070 ** @@
2071 ******************************************************************************/
2072 
ajTrnCodonstrTypeC(const AjPTrn trnObj,const char * codon,char * aa)2073 ajint ajTrnCodonstrTypeC(const AjPTrn trnObj, const char *codon, char *aa)
2074 {
2075     ajint tc1;
2076     ajint tc2;
2077     ajint tc3;
2078 
2079     tc1 = trnconv[(ajint)codon[0]];
2080     tc2 = trnconv[(ajint)codon[1]];
2081     tc3 = trnconv[(ajint)codon[2]];
2082 
2083 
2084     *aa = trnObj->GC[tc1][tc2][tc3];
2085 
2086     if(trnObj->Starts[tc1][tc2][tc3] == 'M')
2087 	return 1;
2088 
2089     if(*aa == '*')
2090 	return -1;
2091 
2092     return 0;
2093 }
2094 
2095 
2096 
2097 
2098 /* @func ajTrnCodonstrTypeS ***************************************************
2099 **
2100 ** Checks whether the input codon is a Start codon, a Stop codon or
2101 ** something else
2102 **
2103 ** @param [r] trnObj [const AjPTrn] Translation tables
2104 ** @param [r] codon [const AjPStr] codon to check
2105 ** @param [w] aa [char *] returned translated amino acid
2106 **                        (not a NULL-terminated array of char)
2107 ** @return [ajint] 1 if it is a start codon, -1 if it is a stop codon, else 0
2108 ** @category use [AjPTrn] Checks whether the input codon is a Start
2109 **                codon, a Stop codon or something else
2110 **
2111 ** @release 6.2.0
2112 ** @@
2113 ******************************************************************************/
2114 
ajTrnCodonstrTypeS(const AjPTrn trnObj,const AjPStr codon,char * aa)2115 ajint ajTrnCodonstrTypeS(const AjPTrn trnObj, const AjPStr codon, char *aa)
2116 {
2117     const char *res;
2118 
2119     ajint tc1;
2120     ajint tc2;
2121     ajint tc3;
2122 
2123     res = ajStrGetPtr(codon);
2124 
2125     tc1 = trnconv[(ajint)res[0]];
2126     tc2 = trnconv[(ajint)res[1]];
2127     tc3 = trnconv[(ajint)res[2]];
2128 
2129     *aa = trnObj->GC[tc1][tc2][tc3];
2130 
2131     if(trnObj->Starts[tc1][tc2][tc3] == 'M')
2132 	return 1;
2133 
2134     if(*aa == '*')
2135 	return -1;
2136 
2137     return 0;
2138 }
2139 
2140 
2141 
2142 
2143 /* @func ajTrnGetTitle ********************************************************
2144 **
2145 ** Returns the translation table description.
2146 ** Because this is a pointer to the real internal string
2147 ** the caller must take care not to change the character string in any way.
2148 ** If the string is to be changed (case for example) then it must first
2149 ** be copied.
2150 **
2151 ** @param [r] thys [const AjPTrn] Translation object.
2152 ** @return [AjPStr] Description as a string.
2153 ** @category cast [AjPTrn] Returns description of the translation
2154 **                table
2155 **
2156 ** @release 1.0.0
2157 ** @@
2158 ******************************************************************************/
2159 
ajTrnGetTitle(const AjPTrn thys)2160 AjPStr ajTrnGetTitle(const AjPTrn thys)
2161 {
2162   return thys->Title;
2163 }
2164 
2165 
2166 
2167 
2168 /* @func ajTrnGetFilename *****************************************************
2169 **
2170 ** Returns the file that the translation table was read from.
2171 ** Because this is a pointer to the real internal string
2172 ** the caller must take care not to change the character string in any way.
2173 ** If the string is to be changed (case for example) then it must first
2174 ** be copied.
2175 **
2176 ** @param [r] thys [const AjPTrn] Translation object.
2177 ** @return [AjPStr] File name as a string.
2178 ** @category cast [AjPTrn] Returns file name the translation table
2179 **                was read from
2180 **
2181 ** @release 6.2.0
2182 ** @@
2183 ******************************************************************************/
2184 
ajTrnGetFilename(const AjPTrn thys)2185 AjPStr ajTrnGetFilename(const AjPTrn thys)
2186 {
2187   return thys->FileName;
2188 }
2189 
2190 
2191 
2192 
2193 /* @func ajTrnName ************************************************************
2194 **
2195 ** Checks whether a const char * codon is a Start codon, a Stop codon or
2196 ** something else
2197 **
2198 ** @param [r] trnFileNameInt [ajint] translation table file name number
2199 ** @return [const AjPStr] Genetic code description
2200 **
2201 ** @release 3.0.0
2202 ** @@
2203 ******************************************************************************/
2204 
ajTrnName(ajint trnFileNameInt)2205 const AjPStr ajTrnName(ajint trnFileNameInt)
2206 {
2207     const AjPStr ret = NULL;
2208     static AjPStr unknown = NULL;
2209     AjPFile indexf = NULL;
2210     AjPStr indexfname = NULL;
2211     AjPStr line = NULL;
2212     AjPStr tmpstr = NULL;
2213     AjPStr tok1 = NULL;
2214     AjPStr tok2 = NULL;
2215     AjPStrTok handle = NULL;
2216 
2217     if(!trnCodes)
2218     {
2219 	if(!indexfname)
2220 	    indexfname = ajStrNewC("EGC.index");
2221 
2222 	trnCodes = ajTablestrNew(20);
2223 
2224 	indexf = ajDatafileNewInNameS(indexfname);
2225 
2226 	if(!indexf)
2227 	    return unknown;
2228 
2229 	while(ajReadlineTrim(indexf, &line))
2230 	{
2231 	    ajStrTrimWhite(&line);
2232 
2233 	    if(ajStrGetCharFirst(line) == '#')
2234 		continue;
2235 
2236 	    ajStrTokenAssignC(&handle, line, " ");
2237 	    ajStrTokenNextParse(handle, &tok1);
2238 	    ajStrTokenRestParse(handle, &tok2);
2239 	    ajTablePut(trnCodes, tok1, tok2);
2240 	    tok1 = NULL;
2241 	    tok2 = NULL;
2242 	}
2243 
2244 	ajFileClose(&indexf);
2245     }
2246 
2247     ajFmtPrintS(&tmpstr, "%d", trnFileNameInt);
2248     ret = ajTableFetchS(trnCodes, tmpstr);
2249 
2250     ajStrDel(&indexfname);
2251     ajStrDel(&tok1);
2252     ajStrDel(&tok2);
2253     ajStrDel(&line);
2254     ajStrDel(&tmpstr);
2255     ajStrTokenDel(&handle);
2256 
2257     if(ret)
2258 	return ret;
2259 
2260     if(!unknown)
2261 	unknown = ajStrNewC("unknown");
2262 
2263     return unknown;
2264 }
2265 
2266 
2267 
2268 
2269 /* @funcstatic trnComplete ****************************************************
2270 **
2271 ** Completes a translation table.
2272 **
2273 ** Checks all basic codons are defined
2274 **
2275 ** Sets third base wobble ambiguity codes
2276 **
2277 ** Sets most ambiguous codon for each amino acid
2278 **
2279 ** @param [u] thys [AjPTrn] Translation table
2280 ** @return [AjBool] ajTrue if table was valid and could be set
2281 **
2282 ** @release 4.0.0
2283 ******************************************************************************/
2284 
trnComplete(AjPTrn thys)2285 static AjBool trnComplete(AjPTrn thys)
2286 {
2287     ajint i;
2288     ajint j;
2289     ajint k;
2290     ajint jj;
2291     ajint kk;
2292     ajint ifirst = 0;
2293     ajint jfirst = 0;
2294     ajint kfirst = 0;
2295     ajint newkfirst;
2296     const char* bases = "ACGT";
2297     char newaa[] = "X";
2298     ajint codonval[4];
2299     char aa;
2300     ajint code[4] = {1, 2, 4, 8};
2301     ajint ambigcodes[] = { 1,  2,  4,  8,  3,  5,  6,  9,
2302 			  10, 12,  7, 11, 13, 14, 15};
2303     ajint trncodes[] = {14,  0,  1,  4,  2,  5,  7, 10,
2304 			 3,  6,  8, 11,  9, 12, 13, 14};
2305     char aalist[65] = "";
2306 
2307     for(i=0;i<4;i++)
2308     {
2309 	for(j=0;j<4;j++)
2310 	{
2311 	    for(k=0;k<4;k++)
2312 	    {
2313 		if(!thys->GC[i][j][k])
2314 		{
2315 		    ajWarn("Incomplete genetic code definition: "
2316 			   "no codon for '%c%c%c",
2317 			   bases[i], bases[j], bases[k]);
2318 
2319 		    return ajFalse;
2320 		}
2321 	    }
2322 
2323 	    kfirst = 0;
2324 
2325 	    while(kfirst < 4)
2326 	    {
2327 		codonval[2] = 0;
2328 		aa = thys->GC[i][j][kfirst];
2329 		newkfirst = 4;
2330 
2331 		for(k=kfirst;k<4;k++)
2332 		{
2333 		    if(thys->GC[i][j][k] == aa)
2334 		    {
2335 			codonval[2] |= code[k];
2336 		    }
2337 		    else
2338 		    {
2339 			if(newkfirst == 4)
2340 			    newkfirst = k;
2341 		    }
2342 		}
2343 
2344 		for(k=4;k<15;k++)
2345 		{
2346 		    kk = ambigcodes[k];
2347 
2348 		    if(((kk|codonval[2]) == codonval[2]) &&
2349 		       (kk & codonval[2]))
2350 			thys->GC[i][j][k] = aa;
2351 		}
2352 
2353 		kfirst = newkfirst;
2354 	    }
2355 	}
2356     }
2357 
2358     newaa[0] = 'X';
2359     ifirst = jfirst = kfirst = 0;
2360     jj = kk = 0;
2361 
2362     while(newaa[0])
2363     {
2364 	newaa[0] = '\0';
2365 	aa = thys->GC[ifirst][jfirst][kfirst];
2366 	codonval[0] = codonval[1] = codonval[2] = 0;
2367 
2368 	for(i=ifirst;i<4;i++)
2369 	{
2370 	    for(j=jfirst;j<4;j++)
2371 	    {
2372 		for(k=kfirst;k<4;k++)
2373 		{
2374 		    if(thys->GC[i][j][k] == aa)
2375 		    {
2376 			codonval[0] |= code[i];
2377 			codonval[1] |= code[j];
2378 			codonval[2] |= code[k];
2379 		    }
2380 		    else
2381 		    {
2382 			if(!newaa[0])
2383 			{
2384 			    if(!strchr(aalist, thys->GC[i][j][k]))
2385 			    {
2386 				newaa[0] = thys->GC[i][j][k];
2387 				ifirst = i;
2388 				jj = j;
2389 				kk = k;
2390 				strcat(aalist, newaa);
2391 			    }
2392 			}
2393 		    }
2394 		}
2395 
2396 		kfirst = 0;
2397 	    }
2398 
2399 	    jfirst = 0;
2400 	}
2401 
2402 	jfirst = jj;
2403 	kfirst = kk;
2404 	thys->GC[trncodes[codonval[0]]]
2405 	    [trncodes[codonval[1]]]
2406 		[trncodes[codonval[2]]] = aa;
2407     }
2408 
2409     return ajTrue;
2410 }
2411 
2412 
2413 
2414 
2415 /* @func ajTrnExit ************************************************************
2416 **
2417 ** Cleans up translation processing internal memory
2418 **
2419 ** @return [void]
2420 **
2421 ** @release 4.0.0
2422 ** @@
2423 ******************************************************************************/
2424 
ajTrnExit(void)2425 void ajTrnExit(void)
2426 {
2427     ajStrDel(&trnResidueStr);
2428     ajTablestrFree(&trnCodes);
2429 
2430     return;
2431 }
2432 
2433 
2434 
2435 
2436 #ifdef AJ_COMPILE_DEPRECATED_BOOK
2437 #endif /* AJ_COMPILE_DEPRECATED_BOOK */
2438 
2439 
2440 
2441 
2442 #ifdef AJ_COMPILE_DEPRECATED
2443 /* @obsolete ajTrnCodon
2444 ** @remove Use ajTrnCodonS
2445 */
2446 
ajTrnCodon(const AjPTrn trnObj,const AjPStr codon)2447 __deprecated const AjPStr ajTrnCodon(const AjPTrn trnObj, const AjPStr codon)
2448 {
2449     static AjPStr trnResidue = NULL;
2450     const char * res;
2451     char store[2];
2452 
2453     store[1] = '\0';			/* end the char * of store */
2454 
2455     res = ajStrGetPtr(codon);
2456     store[0] = trnObj->GC[trnconv[(ajint)res[0]]]
2457 	                 [trnconv[(ajint)res[1]]]
2458 	                 [trnconv[(ajint)res[2]]];
2459 
2460     ajStrAssignC(&trnResidue, store);
2461 
2462     return trnResidue;
2463 }
2464 
2465 
2466 
2467 
2468 /* @obsolete ajTrnRevCodon
2469 ** @remove Use ajTrnCodonRevS
2470 */
2471 
ajTrnRevCodon(const AjPTrn trnObj,const AjPStr codon)2472 __deprecated const AjPStr ajTrnRevCodon(const AjPTrn trnObj, const AjPStr codon)
2473 {
2474     const char * res;
2475     char store[2];
2476 
2477     store[1] = '\0';			/* end the char * of store */
2478 
2479     res = ajStrGetPtr(codon);
2480     store[0] = trnObj->GC[trncomp[(ajint)res[2]]]
2481 	                 [trncomp[(ajint)res[1]]]
2482 	                 [trncomp[(ajint)res[0]]];
2483 
2484     ajStrAssignC(&trnResidueStr, store);
2485 
2486     return trnResidueStr;
2487 }
2488 
2489 
2490 
2491 
2492 /* @obsolete ajTrnC
2493 ** @rename ajTrnSeqC
2494 */
2495 
ajTrnC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)2496 __deprecated void ajTrnC(const AjPTrn trnObj, const char *str, ajint len,
2497                          AjPStr *pep)
2498 {
2499     ajTrnSeqC(trnObj, str, len, pep);
2500     return;
2501 }
2502 
2503 
2504 
2505 
2506 /* @obsolete ajTrnRevC
2507 ** @rename ajTrnSeqRevC
2508 */
2509 
ajTrnRevC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)2510 __deprecated void ajTrnRevC(const AjPTrn trnObj, const char *str,
2511                             ajint len, AjPStr *pep)
2512 {
2513     ajTrnSeqRevC(trnObj, str, len, pep);
2514 }
2515 
2516 
2517 
2518 
2519 /* @obsolete ajTrnAltRevC
2520 ** @rename ajTrnSeqAltRevC
2521 */
2522 
ajTrnAltRevC(const AjPTrn trnObj,const char * str,ajint len,AjPStr * pep)2523 __deprecated void ajTrnAltRevC(const AjPTrn trnObj, const char *str, ajint len,
2524                                AjPStr *pep)
2525 {
2526     ajTrnSeqAltRevC(trnObj, str, len, pep);
2527     return;
2528 }
2529 
2530 
2531 
2532 
2533 /* @obsolete ajTrnStr
2534 ** @rename ajTrnSeqS
2535 */
2536 
ajTrnStr(const AjPTrn trnObj,const AjPStr str,AjPStr * pep)2537 __deprecated void ajTrnStr(const AjPTrn trnObj, const AjPStr str, AjPStr *pep)
2538 {
2539     ajTrnSeqS(trnObj, str, pep);
2540     return;
2541 }
2542 
2543 
2544 
2545 
2546 /* @obsolete ajTrnAltRevStr
2547 ** @rename ajTrnSeqAltRevStr
2548 */
2549 
ajTrnAltRevStr(const AjPTrn trnObj,const AjPStr str,AjPStr * pep)2550 __deprecated void ajTrnAltRevStr(const AjPTrn trnObj,
2551                                  const AjPStr str, AjPStr *pep)
2552 {
2553     ajTrnSeqAltRevS(trnObj, str, pep);
2554     return;
2555 }
2556 
2557 
2558 
2559 
2560 /* @obsolete ajTrnSeq
2561 ** @rename ajTrnSeqSeq
2562 */
2563 
ajTrnSeq(const AjPTrn trnObj,const AjPSeq seq,AjPStr * pep)2564 __deprecated void ajTrnSeq(const AjPTrn trnObj, const AjPSeq seq, AjPStr *pep)
2565 {
2566     ajTrnSeqSeq(trnObj, seq, pep);
2567     return;
2568 }
2569 
2570 
2571 
2572 
2573 /* @obsolete ajTrnRevSeq
2574 ** @rename ajTrnSeqRevSeq
2575 */
2576 
ajTrnRevSeq(const AjPTrn trnObj,const AjPSeq seq,AjPStr * pep)2577 __deprecated void ajTrnRevSeq(const AjPTrn trnObj,
2578                               const AjPSeq seq, AjPStr *pep)
2579 {
2580     ajTrnSeqRevSeq(trnObj, seq, pep);
2581 }
2582 
2583 
2584 
2585 
2586 /* @obsolete ajTrnAltRevSeq
2587 ** @rename ajTrnSeqAltRevSeq
2588 */
2589 
ajTrnAltRevSeq(const AjPTrn trnObj,const AjPSeq seq,AjPStr * pep)2590 __deprecated void ajTrnAltRevSeq(const AjPTrn trnObj, const AjPSeq seq,
2591                                  AjPStr *pep)
2592 {
2593     ajTrnSeqAltRevSeq(trnObj, seq, pep);
2594     return;
2595 }
2596 
2597 
2598 
2599 
2600 /* @obsolete ajTrnCFrame
2601 ** @rename ajTrnSeqFrameC
2602 */
2603 
ajTrnCFrame(const AjPTrn trnObj,const char * seq,ajint len,ajint frame,AjPStr * pep)2604 __deprecated void ajTrnCFrame(const AjPTrn trnObj, const char *seq,
2605                               ajint len, ajint frame,
2606                               AjPStr *pep)
2607 
2608 {
2609 
2610     ajTrnSeqFrameC(trnObj, seq, len, frame, pep);
2611     return;
2612 }
2613 
2614 
2615 
2616 
2617 /* @obsolete ajTrnStrFrame
2618 ** @rename ajTrnSeqFrameS
2619 */
2620 
ajTrnStrFrame(const AjPTrn trnObj,const AjPStr seq,ajint frame,AjPStr * pep)2621 __deprecated void ajTrnStrFrame(const AjPTrn trnObj,
2622                                 const AjPStr seq, ajint frame,
2623                                 AjPStr *pep)
2624 {
2625     ajTrnSeqFrameS(trnObj, seq, frame, pep);
2626     return;
2627 }
2628 
2629 
2630 
2631 
2632 
2633 /* @obsolete ajTrnSeqFrame
2634 ** @rename ajTrnSeqFrameSeq
2635 */
2636 
ajTrnSeqFrame(const AjPTrn trnObj,const AjPSeq seq,ajint frame,AjPStr * pep)2637 __deprecated void ajTrnSeqFrame(const AjPTrn trnObj, const AjPSeq seq,
2638                                 ajint frame, AjPStr *pep)
2639 {
2640     ajTrnSeqFrameSeq(trnObj, seq, frame, pep);
2641     return;
2642 }
2643 
2644 
2645 
2646 
2647 /* @obsolete ajTrnCDangle
2648 ** @rename ajTrnSeqDangleC
2649 */
2650 
ajTrnCDangle(const AjPTrn trnObj,const char * seq,ajint len,ajint frame,AjPStr * pep)2651 __deprecated ajint ajTrnCDangle(const AjPTrn trnObj,
2652                                 const char *seq, ajint len,
2653                                 ajint frame, AjPStr *pep)
2654 {
2655     (void) len;
2656     return ajTrnSeqDangleC(trnObj,seq,frame,pep);
2657 }
2658 
2659 
2660 
2661 
2662 /* @obsolete ajTrnStrDangle
2663 ** @rename ajTrnDangleS
2664 */
2665 
ajTrnStrDangle(const AjPTrn trnObj,const AjPStr seq,ajint frame,AjPStr * pep)2666 __deprecated ajint ajTrnStrDangle(const AjPTrn trnObj, const AjPStr seq,
2667                                   ajint frame, AjPStr *pep)
2668 {
2669     return ajTrnSeqDangleS(trnObj, seq, frame, pep);
2670 }
2671 
2672 
2673 
2674 
2675 /* @obsolete ajTrnStartStopC
2676 ** @rename ajTrnCodonstrTypeC
2677 */
ajTrnStartStopC(const AjPTrn trnObj,const char * codon,char * aa)2678 __deprecated ajint ajTrnStartStopC(const AjPTrn trnObj,
2679                                   const char* codon, char *aa)
2680 {
2681     return ajTrnCodonstrTypeC(trnObj, codon, aa);
2682 }
2683 
2684 
2685 
2686 
2687 /* @obsolete ajTrnStartStop
2688 ** @rename ajTrnCodonstrTypeS
2689 */
ajTrnStartStop(const AjPTrn trnObj,const AjPStr codon,char * aa)2690 __deprecated ajint ajTrnStartStop(const AjPTrn trnObj,
2691                                   const AjPStr codon, char *aa)
2692 {
2693     return ajTrnCodonstrTypeS(trnObj, codon, aa);
2694 }
2695 
2696 
2697 
2698 
2699 /* @obsolete ajTrnGetFileName
2700 ** @rename ajTrnGetFilename
2701 */
2702 
ajTrnGetFileName(const AjPTrn thys)2703 __deprecated AjPStr ajTrnGetFileName(const AjPTrn thys)
2704 {
2705   return thys->FileName;
2706 }
2707 
2708 #endif /* AJ_COMPILE_DEPRECATED */
2709