Skip to main content
Glama

calculate_expression_correlation

Analyze gene expression correlations across tissues using GTEx data to identify co-expression patterns and functional relationships between genes.

Instructions

Calculate expression correlation between genes across tissues

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
gencodeIdsYesArray of GENCODE gene IDs to compare
datasetIdNoGTEx dataset ID (default: gtex_v8)gtex_v8

Implementation Reference

  • Main handler function that fetches median gene expression data for multiple genes and computes pairwise Pearson correlations across common tissues, returning formatted correlation results.
    async calculateExpressionCorrelation(args: any) {
      if (!args.geneIds || !Array.isArray(args.geneIds) || args.geneIds.length < 2) {
        throw new Error('geneIds parameter is required and must contain at least 2 gene IDs for correlation analysis');
      }
    
      if (args.geneIds.length > 10) {
        return {
          content: [{
            type: "text",
            text: "Maximum 10 genes can be processed for correlation analysis."
          }]
        };
      }
    
      // Get median expression for all genes
      const result = await this.apiClient.getMedianGeneExpression(
        args.geneIds,
        args.datasetId || 'gtex_v8'
      );
    
      if (result.error) {
        return {
          content: [{
            type: "text",
            text: `Error calculating expression correlation: ${result.error}`
          }],
          isError: true
        };
      }
    
      const expressions = result.data || [];
      if (expressions.length === 0) {
        return {
          content: [{
            type: "text",
            text: "No expression data found for correlation analysis."
          }]
        };
      }
    
      // Organize by gene and tissue
      const geneData: { [gene: string]: { [tissue: string]: number } } = {};
      const geneNames: { [gene: string]: string } = {};
      
      expressions.forEach(expr => {
        const geneKey = expr.gencodeId;
        geneNames[geneKey] = expr.geneSymbol;
        if (!geneData[geneKey]) {
          geneData[geneKey] = {};
        }
        geneData[geneKey][expr.tissueSiteDetailId] = expr.median;
      });
    
      // Find common tissues
      const genes = Object.keys(geneData);
      const commonTissues = Object.keys(geneData[genes[0]] || {});
      
      // Calculate pairwise correlations
      let output = `**Gene Expression Correlation Analysis**\n`;
      output += `Genes: ${genes.length}\n`;
      output += `Common tissues: ${commonTissues.length}\n`;
      output += `Dataset: ${expressions[0]?.datasetId}\n\n`;
    
      if (commonTissues.length < 5) {
        output += `⚠️ **Warning**: Only ${commonTissues.length} common tissues found. Correlation analysis requires more data points for reliability.\n\n`;
      }
    
      output += `**Pairwise Correlations:**\n`;
      
      for (let i = 0; i < genes.length; i++) {
        for (let j = i + 1; j < genes.length; j++) {
          const gene1 = genes[i];
          const gene2 = genes[j];
          
          // Calculate Pearson correlation
          const values1 = commonTissues.map(t => geneData[gene1][t]).filter(v => v !== undefined);
          const values2 = commonTissues.map(t => geneData[gene2][t]).filter(v => v !== undefined);
          
          if (values1.length !== values2.length || values1.length < 3) {
            output += `• **${geneNames[gene1]}** vs **${geneNames[gene2]}**: Insufficient data\n`;
            continue;
          }
          
          const correlation = this.calculatePearsonCorrelation(values1, values2);
          const strength = Math.abs(correlation) > 0.7 ? "Strong" : 
                          Math.abs(correlation) > 0.4 ? "Moderate" : "Weak";
          
          output += `• **${geneNames[gene1]}** vs **${geneNames[gene2]}**: r = ${correlation.toFixed(3)} (${strength})\n`;
        }
      }
    
      output += `\n**Analysis Notes:**\n`;
      output += `- Correlations calculated using median expression across tissues\n`;
      output += `- |r| > 0.7: Strong correlation, |r| > 0.4: Moderate correlation\n`;
      output += `- Based on ${commonTissues.length} tissue samples\n`;
    
      return {
        content: [{
          type: "text",
          text: output
        }]
      };
    }
  • Input schema defining the parameters for the calculate_expression_correlation tool: array of GENCODE gene IDs (required) and optional datasetId.
    inputSchema: {
      type: "object",
      properties: {
        gencodeIds: {
          type: "array", 
          items: { type: "string" },
          description: "Array of GENCODE gene IDs to compare"
        },
        datasetId: {
          type: "string",
          description: "GTEx dataset ID (default: gtex_v8)",
          default: "gtex_v8"
        }
      },
      required: ["gencodeIds"]
    }
  • src/index.ts:172-191 (registration)
    Tool registration in the listTools response, including name, description, and input schema.
    {
      name: "calculate_expression_correlation",
      description: "Calculate expression correlation between genes across tissues",
      inputSchema: {
        type: "object",
        properties: {
          gencodeIds: {
            type: "array", 
            items: { type: "string" },
            description: "Array of GENCODE gene IDs to compare"
          },
          datasetId: {
            type: "string",
            description: "GTEx dataset ID (default: gtex_v8)",
            default: "gtex_v8"
          }
        },
        required: ["gencodeIds"]
      }
    },
  • src/index.ts:657-662 (registration)
    Dispatch logic in CallToolRequest handler that routes calls to the expressionHandlers.calculateExpressionCorrelation method.
    if (name === "calculate_expression_correlation") {
      return await expressionHandlers.calculateExpressionCorrelation({
        geneIds: args?.gencodeIds || [],
        datasetId: args?.datasetId
      });
    }
  • Private helper method that computes the Pearson correlation coefficient between two arrays of expression values.
    private calculatePearsonCorrelation(x: number[], y: number[]): number {
      const n = x.length;
      if (n !== y.length || n === 0) return 0;
      
      const sumX = x.reduce((sum, val) => sum + val, 0);
      const sumY = y.reduce((sum, val) => sum + val, 0);
      const sumXY = x.reduce((sum, val, i) => sum + val * y[i], 0);
      const sumX2 = x.reduce((sum, val) => sum + val * val, 0);
      const sumY2 = y.reduce((sum, val) => sum + val * val, 0);
      
      const numerator = n * sumXY - sumX * sumY;
      const denominator = Math.sqrt((n * sumX2 - sumX * sumX) * (n * sumY2 - sumY * sumY));
      
      return denominator === 0 ? 0 : numerator / denominator;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool calculates correlation but omits critical details such as the correlation method (e.g., Pearson, Spearman), output format, performance characteristics (e.g., computational intensity, rate limits), or any side effects. This is inadequate for a tool with no annotation support.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any fluff or redundancy. It is appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of gene expression correlation analysis, no annotations, and no output schema, the description is insufficient. It lacks details on behavior, output format, and usage context, which are critical for an agent to effectively invoke this tool. More information is needed to compensate for the missing structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both parameters clearly documented in the schema (gencodeIds as gene IDs to compare, datasetId as GTEx dataset ID with default). The description adds no additional meaning beyond the schema, such as explaining what 'expression correlation' entails or constraints on gene IDs. Baseline 3 is appropriate given high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('calculate expression correlation') and the target ('between genes across tissues'), which is specific and informative. However, it does not explicitly differentiate this tool from its many siblings (e.g., get_gene_expression, get_clustered_expression, get_tissue_specific_genes), which would require more detail about scope or methodology to achieve a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With numerous sibling tools related to gene expression, correlation, and tissue analysis, there is no mention of context, prerequisites, or comparisons (e.g., use this for cross-tissue correlation, not for single-tissue expression). This leaves the agent without clear direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Augmented-Nature/GTEx-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server