analyze_sequence_composition
Analyze protein sequence properties like amino acid composition and hydrophobicity using a UniProt accession number to understand structural characteristics.
Instructions
Amino acid composition, hydrophobicity, and other sequence properties
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accession | Yes | UniProt accession number |
Implementation Reference
- src/index.ts:1303-1358 (handler)Main handler function that implements the tool logic: fetches protein sequence from UniProtKB API, calculates amino acid counts, frequencies, and categorizes residues (hydrophobic, charged, polar).private async handleAnalyzeSequenceComposition(args: any) { if (!isValidProteinInfoArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid sequence composition arguments'); } try { const response = await this.apiClient.get(`/uniprotkb/${args.accession}`, { params: { format: 'json' }, }); const protein = response.data; const sequence = protein.sequence?.value || ''; // Calculate amino acid composition const aaCount: { [key: string]: number } = {}; const aaFreq: { [key: string]: number } = {}; for (const aa of sequence) { aaCount[aa] = (aaCount[aa] || 0) + 1; } for (const aa in aaCount) { aaFreq[aa] = aaCount[aa] / sequence.length; } const composition = { accession: protein.primaryAccession, sequenceLength: sequence.length, molecularWeight: protein.sequence?.molWeight, aminoAcidComposition: aaCount, aminoAcidFrequency: aaFreq, hydrophobicResidues: ['A', 'I', 'L', 'M', 'F', 'W', 'Y', 'V'].reduce((sum, aa) => sum + (aaCount[aa] || 0), 0), chargedResidues: ['R', 'H', 'K', 'D', 'E'].reduce((sum, aa) => sum + (aaCount[aa] || 0), 0), polarResidues: ['S', 'T', 'N', 'Q'].reduce((sum, aa) => sum + (aaCount[aa] || 0), 0), }; return { content: [ { type: 'text', text: JSON.stringify(composition, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error analyzing sequence composition: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } }
- src/index.ts:549-555 (schema)Input schema for the tool defining the required 'accession' parameter.inputSchema: { type: 'object', properties: { accession: { type: 'string', description: 'UniProt accession number' }, }, required: ['accession'], },
- src/index.ts:754-755 (registration)Registration and dispatch of the tool handler in the CallToolRequestSchema switch statement.case 'analyze_sequence_composition': return this.handleAnalyzeSequenceComposition(args);
- src/index.ts:547-556 (registration)Tool registration in the ListToolsRequestSchema response, including name, description, and schema.name: 'analyze_sequence_composition', description: 'Amino acid composition, hydrophobicity, and other sequence properties', inputSchema: { type: 'object', properties: { accession: { type: 'string', description: 'UniProt accession number' }, }, required: ['accession'], }, },
- src/index.ts:79-89 (helper)Shared validation function for accession-based arguments, used in the handler for input validation.const isValidProteinInfoArgs = ( args: any ): args is { accession: string; format?: string } => { return ( typeof args === 'object' && args !== null && typeof args.accession === 'string' && args.accession.length > 0 && (args.format === undefined || ['json', 'tsv', 'fasta', 'xml'].includes(args.format)) ); };