1 /*****************************************************************
2 * HMMER - Biological sequence analysis with profile HMMs
3 * Copyright (C) 1992-1999 Washington University School of Medicine
6 * This source code is distributed under the terms of the
7 * GNU General Public License. See the files COPYING and LICENSE
9 *****************************************************************/
12 * translate.c - functions for translating nucleic acid sequence
13 * created Tue Jan 12 11:27:29 1993, SRE
15 * RCS $Id: translate.c,v 1.1.1.1 2005/03/22 08:34:31 cmzmasek Exp $
29 /* Function: Translate(char *seq, char **code)
31 * Given a ptr to the start of a nucleic acid sequence,
32 * and a genetic code, translate the sequence into
33 * amino acid sequence.
35 * code is an array of 65 strings, representing
36 * the translations of the 64 codons, arranged
37 * in order AAA, AAC, AAG, AAU, ..., UUA, UUC, UUG, UUU.
38 * '*' or '***' is used to represent termination
39 * codons, usually. The final string, code[64],
40 * is the code for an ambiguous amino acid.
42 * Because of the way space is allocated for the amino
43 * acid sequence, the amino acid strings cannot be
44 * longer than 3 letters each. (I don't foresee using
45 * anything but the single- and triple- letter codes.)
47 * Returns a ptr to the translation string on success,
51 Translate(char *seq, char **code)
53 int codon; /* index for codon */
54 char *aaseq; /* RETURN: the translation */
55 char *aaptr; /* ptr into aaseq */
59 { squid_errno = SQERR_NODATA; return NULL; }
60 if ((aaseq = (char *) calloc (strlen(seq) + 1, sizeof(char))) == NULL)
64 for (; *seq != '\0' && *(seq+1) != '\0' && *(seq+2) != '\0'; seq += 3)
66 /* calculate the lookup value for
69 for (i = 0; i < 3; i++)
73 case 'A': case 'a': break;
74 case 'C': case 'c': codon += 1; break;
75 case 'G': case 'g': codon += 2; break;
76 case 'T': case 't': codon += 3; break;
77 case 'U': case 'u': codon += 3; break;
78 default: codon = 64; break;
80 if (codon == 64) break;
83 strcpy(aaptr, code[codon]);
84 aaptr += strlen(code[codon]);