generate_dna_sequence
Generate random DNA sequences with customizable length, GC content, and generation models for bioinformatics research and testing.
Instructions
Generate random DNA sequences with specified parameters
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": {
"length": "<length>"
},
"name": "generate_dna_sequence"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| length | Yes | Length of the DNA sequence to generate | |
| gcContent | No | GC content (0-1), default is 0.5 | |
| count | No | Number of sequences to generate, default is 1 | |
| seed | No | Random seed for reproducible results (optional) | |
| model | No | Generation model: 'random', 'markov', or 'codon-biased' | |
| outputFormat | No | Output format: 'fasta' or 'plain' |
Implementation Reference
- src/tools/generateDNA.ts:44-117 (handler)Main handler function that executes the generate_dna_sequence tool logic. Accepts parameters for length, GC content, count, seed, model (random/markov/codon-biased), and output format (fasta/plain). Uses SequenceGenerator utility and supports three different generation models.
async handler({ length, gcContent = 0.5, count = 1, seed, model = "random", outputFormat = "fasta" }: { length: number; gcContent?: number; count?: number; seed?: number; model?: string; outputFormat?: string; }) { const generator = new SequenceGenerator(seed); const sequences = []; for (let i = 0; i < count; i++) { let sequence: string; switch (model) { case "random": sequence = generator.generateRandomDNA(length, gcContent); break; case "markov": sequence = generateMarkovDNA(length, gcContent, generator); break; case "codon-biased": sequence = generateCodonBiasedDNA(length, generator); break; default: sequence = generator.generateRandomDNA(length, gcContent); } const actualGC = (sequence.match(/[GC]/g) || []).length / sequence.length; sequences.push({ id: `sim_dna_${i + 1}`, sequence, length: sequence.length, gcContent: Math.round(actualGC * 10000) / 100, model }); } let output = ''; if (outputFormat === 'fasta') { output = sequences.map(seq => `>${seq.id} length=${seq.length} gc=${seq.gcContent}% model=${seq.model}\n${seq.sequence}` ).join('\n\n'); } else { output = sequences.map(seq => seq.sequence).join('\n'); } const stats = { totalSequences: sequences.length, averageLength: Math.round(sequences.reduce((sum, seq) => sum + seq.length, 0) / sequences.length), averageGC: Math.round(sequences.reduce((sum, seq) => sum + seq.gcContent, 0) / sequences.length * 100) / 100, model, seed: seed || "random" }; return { content: [{ type: "text", text: JSON.stringify({ statistics: stats, sequences: outputFormat === 'fasta' ? output : sequences, rawOutput: outputFormat === 'plain' ? output : undefined }, null, 2) }] }; } - src/tools/generateDNA.ts:4-43 (schema)Tool definition and input schema for generate_dna_sequence. Defines the tool name, description, and JSON Schema validation for all input parameters including length (required), gcContent, count, seed, model, and outputFormat.
export const generateDNA = { definition: { name: "generate_dna_sequence", description: "Generate random DNA sequences with specified parameters", inputSchema: { type: "object", properties: { length: { type: "number", description: "Length of the DNA sequence to generate" }, gcContent: { type: "number", description: "GC content (0-1), default is 0.5", minimum: 0, maximum: 1 }, count: { type: "number", description: "Number of sequences to generate, default is 1", minimum: 1 }, seed: { type: "number", description: "Random seed for reproducible results (optional)" }, model: { type: "string", description: "Generation model: 'random', 'markov', or 'codon-biased'", enum: ["random", "markov", "codon-biased"] }, outputFormat: { type: "string", description: "Output format: 'fasta' or 'plain'", enum: ["fasta", "plain"] } }, required: ["length"] }, }, - src/server.ts:47-55 (registration)Registration of the generate_dna_sequence tool handler in the MCP server's CallToolRequestSchema request handler. Maps the tool name to the generateDNA.handler function with proper TypeScript type annotations.
case "generate_dna_sequence": return await generateDNA.handler(args as { length: number; gcContent?: number; count?: number; seed?: number; model?: string; outputFormat?: string; }); - src/utils/sequenceUtils.ts:48-81 (helper)SequenceGenerator utility class with seedable RNG and the generateRandomDNA method used by the handler. Supports generating random DNA sequences with specified GC content bias.
export class SequenceGenerator { public rng: () => number; constructor(seed?: number) { if (seed !== undefined) { let s = seed; this.rng = () => { s = Math.sin(s) * 10000; return s - Math.floor(s); }; } else { this.rng = Math.random; } } generateRandomDNA(length: number, gcContent: number = 0.5): string { const gcProb = gcContent / 2; const atProb = (1 - gcContent) / 2; let sequence = ''; for (let i = 0; i < length; i++) { const rand = this.rng(); if (rand < atProb) { sequence += 'A'; } else if (rand < atProb * 2) { sequence += 'T'; } else if (rand < atProb * 2 + gcProb) { sequence += 'G'; } else { sequence += 'C'; } } return sequence; } - src/tools/generateDNA.ts:120-172 (helper)Helper functions for alternative DNA generation models: generateMarkovDNA (uses Markov chain transitions) and generateCodonBiasedDNA (uses codon usage tables). These are called by the main handler when model parameter is set to 'markov' or 'codon-biased'.
function generateMarkovDNA(length: number, gcContent: number, generator: SequenceGenerator): string { const transitions = { 'A': { 'A': 0.3, 'T': 0.3, 'G': 0.2, 'C': 0.2 }, 'T': { 'A': 0.3, 'T': 0.3, 'G': 0.2, 'C': 0.2 }, 'G': { 'A': 0.2, 'T': 0.2, 'G': 0.3, 'C': 0.3 }, 'C': { 'A': 0.2, 'T': 0.2, 'G': 0.3, 'C': 0.3 } }; let sequence = generator.generateRandomDNA(1, gcContent); for (let i = 1; i < length; i++) { const lastBase = sequence[i - 1] as keyof typeof transitions; const probs = transitions[lastBase]; const rand = Math.random(); let cumProb = 0; for (const [base, prob] of Object.entries(probs)) { cumProb += prob; if (rand < cumProb) { sequence += base; break; } } } return sequence; } function generateCodonBiasedDNA(length: number, generator: SequenceGenerator): string { const codonUsage = { 'F': ['TTT', 'TTC'], 'L': ['TTA', 'TTG', 'CTT', 'CTC', 'CTA', 'CTG'], 'S': ['TCT', 'TCC', 'TCA', 'TCG', 'AGT', 'AGC'], 'Y': ['TAT', 'TAC'], 'C': ['TGT', 'TGC'], 'W': ['TGG'], 'P': ['CCT', 'CCC', 'CCA', 'CCG'], 'H': ['CAT', 'CAC'], 'Q': ['CAA', 'CAG'], 'R': ['CGT', 'CGC', 'CGA', 'CGG', 'AGA', 'AGG'], 'I': ['ATT', 'ATC', 'ATA'], 'M': ['ATG'], 'T': ['ACT', 'ACC', 'ACA', 'ACG'], 'N': ['AAT', 'AAC'], 'K': ['AAA', 'AAG'], 'V': ['GTT', 'GTC', 'GTA', 'GTG'], 'A': ['GCT', 'GCC', 'GCA', 'GCG'], 'D': ['GAT', 'GAC'], 'E': ['GAA', 'GAG'], 'G': ['GGT', 'GGC', 'GGA', 'GGG'], '*': ['TAA', 'TAG', 'TGA'] }; const aminoAcids = Object.keys(codonUsage).filter(aa => aa !== '*'); let sequence = ''; const targetCodons = Math.floor(length / 3); for (let i = 0; i < targetCodons; i++) { const aa = aminoAcids[Math.floor(Math.random() * aminoAcids.length)]; const codons = codonUsage[aa as keyof typeof codonUsage]; const codon = codons[Math.floor(Math.random() * codons.length)]; sequence += codon; } return sequence.substring(0, length); }