translate_sequence
Convert DNA sequences into protein sequences using genetic code tables for biological analysis and research applications.
Instructions
Translate DNA sequence to protein sequence
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sequence": "<sequence>"
},
"name": "translate_sequence"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sequence | Yes | DNA sequence to translate | |
| genetic_code | No | Genetic code table (default: 1 for standard) |
Implementation Reference
- src/index.ts:1114-1165 (handler)The handler function that executes the translate_sequence tool. It cleans the input DNA sequence, translates it to protein using the standard genetic code codon table (ignoring non-ATCG characters, using X for unknown codons), and returns the result in JSON format.
private async handleTranslateSequence(args: any) { try { const geneticCode = args.genetic_code || 1; // Simple translation implementation const codonTable: { [key: string]: string } = { 'TTT': 'F', 'TTC': 'F', 'TTA': 'L', 'TTG': 'L', 'TCT': 'S', 'TCC': 'S', 'TCA': 'S', 'TCG': 'S', 'TAT': 'Y', 'TAC': 'Y', 'TAA': '*', 'TAG': '*', 'TGT': 'C', 'TGC': 'C', 'TGA': '*', 'TGG': 'W', 'CTT': 'L', 'CTC': 'L', 'CTA': 'L', 'CTG': 'L', 'CCT': 'P', 'CCC': 'P', 'CCA': 'P', 'CCG': 'P', 'CAT': 'H', 'CAC': 'H', 'CAA': 'Q', 'CAG': 'Q', 'CGT': 'R', 'CGC': 'R', 'CGA': 'R', 'CGG': 'R', 'ATT': 'I', 'ATC': 'I', 'ATA': 'I', 'ATG': 'M', 'ACT': 'T', 'ACC': 'T', 'ACA': 'T', 'ACG': 'T', 'AAT': 'N', 'AAC': 'N', 'AAA': 'K', 'AAG': 'K', 'AGT': 'S', 'AGC': 'S', 'AGA': 'R', 'AGG': 'R', 'GTT': 'V', 'GTC': 'V', 'GTA': 'V', 'GTG': 'V', 'GCT': 'A', 'GCC': 'A', 'GCA': 'A', 'GCG': 'A', 'GAT': 'D', 'GAC': 'D', 'GAA': 'E', 'GAG': 'E', 'GGT': 'G', 'GGC': 'G', 'GGA': 'G', 'GGG': 'G', }; const sequence = args.sequence.toUpperCase().replace(/[^ATCG]/g, ''); let protein = ''; for (let i = 0; i < sequence.length - 2; i += 3) { const codon = sequence.substr(i, 3); if (codon.length === 3) { protein += codonTable[codon] || 'X'; } } return { content: [ { type: 'text', text: JSON.stringify({ input_sequence: args.sequence, cleaned_sequence: sequence, protein_sequence: protein, genetic_code: geneticCode, length: protein.length, }, null, 2), }, ], }; } catch (error) { return this.handleError(error, 'translating sequence'); } } - src/index.ts:641-651 (schema)Input schema definition for the translate_sequence tool, specifying the required 'sequence' parameter and optional 'genetic_code'.
name: 'translate_sequence', description: 'Translate DNA sequence to protein sequence', inputSchema: { type: 'object', properties: { sequence: { type: 'string', description: 'DNA sequence to translate' }, genetic_code: { type: 'number', description: 'Genetic code table (default: 1 for standard)', minimum: 1, maximum: 31 }, }, required: ['sequence'], }, }, - src/index.ts:846-847 (registration)Registration of the translate_sequence tool handler in the switch statement for CallToolRequestSchema.
case 'translate_sequence': return this.handleTranslateSequence(args); - src/index.ts:336-346 (schema)Type guard function for validating input arguments to the translate_sequence tool (defined but not used in the handler).
const isValidTranslateArgs = ( args: any ): args is { sequence: string; genetic_code?: number } => { return ( typeof args === 'object' && args !== null && typeof args.sequence === 'string' && args.sequence.length > 0 && (args.genetic_code === undefined || (typeof args.genetic_code === 'number' && args.genetic_code >= 1 && args.genetic_code <= 31)) ); };