convert_coordinates
Convert genomic coordinates between hg19 and hg38 genome builds for accurate positioning across different genomic reference standards.
Instructions
Convert between different genomic coordinate systems
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chr | Yes | Chromosome (e.g., chr1, chr2, chrX) | |
| fromBuild | No | Source genome build (default: hg38) | hg38 |
| position | Yes | Genomic position to convert | |
| toBuild | No | Target genome build (default: hg19) | hg19 |
Implementation Reference
- Main handler function that performs approximate genomic coordinate conversion between hg19 and hg38 builds using helper offset functions.async convertCoordinates(args: any) { if (!args.chr || !args.position) { throw new Error('chr and position parameters are required'); } if (typeof args.position !== 'number') { throw new Error('position parameter must be a number'); } const fromBuild = args.fromBuild || 'hg38'; const toBuild = args.toBuild || 'hg19'; // Validate genome builds const validBuilds = ['hg19', 'hg38']; if (!validBuilds.includes(fromBuild) || !validBuilds.includes(toBuild)) { throw new Error('Genome builds must be either "hg19" or "hg38"'); } if (fromBuild === toBuild) { return { content: [{ type: "text", text: `No conversion needed: ${args.chr}:${args.position.toLocaleString()} (${fromBuild} → ${toBuild})` }] }; } let output = `**Genomic Coordinate Conversion**\n`; output += `Input: ${args.chr}:${args.position.toLocaleString()} (${fromBuild})\n`; output += `Target: ${toBuild}\n\n`; // Note: This is a simplified coordinate conversion // Real coordinate conversion requires liftOver tools or chain files // Provide approximate conversion based on known differences let convertedPosition = args.position; let conversionNote = ''; if (fromBuild === 'hg19' && toBuild === 'hg38') { // Very rough approximation - real conversion needs liftOver // Most positions shift by small amounts, some by larger amounts const roughOffset = this.getApproximateHg19ToHg38Offset(args.chr, args.position); convertedPosition = args.position + roughOffset; conversionNote = 'hg19 to hg38 conversion (approximate)'; } else if (fromBuild === 'hg38' && toBuild === 'hg19') { // Reverse conversion const roughOffset = this.getApproximateHg38ToHg19Offset(args.chr, args.position); convertedPosition = args.position + roughOffset; conversionNote = 'hg38 to hg19 conversion (approximate)'; } output += `**Converted Coordinates:**\n`; output += `• **${toBuild}**: ${args.chr}:${convertedPosition.toLocaleString()}\n`; output += `• **Offset**: ${(convertedPosition - args.position).toLocaleString()} bp\n\n`; output += `**Conversion Details:**\n`; output += `• Method: ${conversionNote}\n`; output += `• Chromosome: ${args.chr}\n`; output += `• Region type: ${this.getRegionType(args.chr, args.position)}\n\n`; output += `**⚠️ Important Limitations:**\n`; output += `• This is an APPROXIMATE conversion for demonstration purposes\n`; output += `• Real coordinate conversion requires UCSC liftOver tools\n`; output += `• Some positions may not have direct equivalents between builds\n`; output += `• Insertions/deletions between builds can affect accuracy\n\n`; output += `**Recommended Tools for Accurate Conversion:**\n`; output += `• UCSC Genome Browser LiftOver: https://genome.ucsc.edu/cgi-bin/hgLiftOver\n`; output += `• Ensembl Assembly Converter: https://www.ensembl.org/Homo_sapiens/Tools/AssemblyConverter\n`; output += `• NCBI Remap: https://www.ncbi.nlm.nih.gov/genome/tools/remap\n`; return { content: [{ type: "text", text: output }] }; }
- src/index.ts:584-612 (schema)Input schema definition for the convert_coordinates tool, specifying required parameters chr and position, and optional fromBuild/toBuild.name: "convert_coordinates", description: "Convert between different genomic coordinate systems", inputSchema: { type: "object", properties: { chr: { type: "string", description: "Chromosome (e.g., chr1, chr2, chrX)" }, position: { type: "integer", description: "Genomic position to convert" }, fromBuild: { type: "string", description: "Source genome build (default: hg38)", enum: ["hg19", "hg38"], default: "hg38" }, toBuild: { type: "string", description: "Target genome build (default: hg19)", enum: ["hg19", "hg38"], default: "hg19" } }, required: ["chr", "position"] } }
- src/index.ts:779-786 (registration)Tool dispatch/registration in the main CallToolRequestSchema handler, mapping convert_coordinates calls to referenceHandlers.convertCoordinates.if (name === "convert_coordinates") { return await referenceHandlers.convertCoordinates({ chr: args?.chr, position: args?.position, fromBuild: args?.fromBuild, toBuild: args?.toBuild }); }
- Private helper method providing approximate offset calculations for hg19 to hg38 coordinate conversion based on chromosome-specific adjustments.private getApproximateHg19ToHg38Offset(chr: string, position: number): number { // This is a very simplified approximation // Real conversion requires comprehensive chain files // Most positions have small positive offsets in hg38 // This is just for demonstration purposes const baseOffset = Math.floor(position * 0.0001); // Very rough approximation // Some chromosomes have different patterns switch (chr.toLowerCase()) { case 'chr1': return baseOffset + 100; case 'chr2': return baseOffset - 50; case 'chrx': return baseOffset + 200; case 'chry': return baseOffset - 100; default: return baseOffset; } }