Skip to main content
Glama

batch_translate

Translate multiple biological identifiers in a batch operation using specified source and target attributes. Returns successful translations, missing IDs, and counts for efficient processing in Biomart MCP.

Instructions

Translates multiple identifiers in a single batch operation.

This function is more efficient than multiple calls to get_translation when
you need to translate many identifiers at once.

Args:
    mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL")
    dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl")
    from_attr (str): The source attribute name (e.g., "hgnc_symbol")
    to_attr (str): The target attribute name (e.g., "ensembl_gene_id")
    targets (list[str]): List of identifier values to translate (e.g., ["TP53", "BRCA1", "BRCA2"])

Returns:
    dict: A dictionary containing:
        - translations: Dictionary mapping input IDs to translated IDs
        - not_found: List of IDs that could not be translated
        - found_count: Number of successfully translated IDs
        - not_found_count: Number of IDs that could not be translated

Example:
    batch_translate("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", "hgnc_symbol", "ensembl_gene_id", ["TP53", "BRCA1", "BRCA2"])
    >>> {"translations": {"TP53": "ENSG00000141510", "BRCA1": "ENSG00000012048"}, "not_found": ["BRCA2"], "found_count": 2, "not_found_count": 1}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
datasetYes
from_attrYes
martYes
targetsYes
to_attrYes

Implementation Reference

  • The main handler function for the batch_translate tool, decorated with @mcp.tool() for registration. It uses a cached translation dictionary to map multiple input identifiers to their corresponding targets efficiently.
    def batch_translate(mart: str, dataset: str, from_attr: str, to_attr: str, targets: list[str]):
        """
        Translates multiple identifiers in a single batch operation.
    
        This function is more efficient than multiple calls to get_translation when
        you need to translate many identifiers at once.
    
        Args:
            mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL")
            dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl")
            from_attr (str): The source attribute name (e.g., "hgnc_symbol")
            to_attr (str): The target attribute name (e.g., "ensembl_gene_id")
            targets (list[str]): List of identifier values to translate (e.g., ["TP53", "BRCA1", "BRCA2"])
    
        Returns:
            dict: A dictionary containing:
                - translations: Dictionary mapping input IDs to translated IDs
                - not_found: List of IDs that could not be translated
                - found_count: Number of successfully translated IDs
                - not_found_count: Number of IDs that could not be translated
    
        Example:
            batch_translate("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", "hgnc_symbol", "ensembl_gene_id", ["TP53", "BRCA1", "BRCA2"])
            >>> {"translations": {"TP53": "ENSG00000141510", "BRCA1": "ENSG00000012048"}, "not_found": ["BRCA2"], "found_count": 2, "not_found_count": 1}
        """
        # Use the cached helper function to get the translation dictionary
        result_dict = _get_translation_dict(mart, dataset, from_attr, to_attr)
    
        translations = {}
        not_found = []
    
        for target in targets:
            if target in result_dict:
                translations[target] = result_dict[target]
            else:
                not_found.append(target)
    
        if not_found:
            print(
                f"The following targets were not found: {', '.join(not_found)}",
                file=sys.stderr,
            )
    
        return {
            "translations": translations,
            "not_found": not_found,
            "found_count": len(translations),
            "not_found_count": len(not_found),
        }
  • Cached helper function that queries Biomart to build a translation dictionary from from_attr to to_attr, used by both get_translation and batch_translate tools.
    def _get_translation_dict(mart: str, dataset: str, from_attr: str, to_attr: str):
        """
        Helper function to get and cache a translation dictionary.
        """
        try:
            server = get_server()
            dataset_obj = server[mart][dataset]
            df = dataset_obj.query(attributes=[from_attr, to_attr])
            return dict(zip(df.iloc[:, 0], df.iloc[:, 1]))
        except Exception as e:
            print(f"Error getting translation dictionary: {str(e)}", file=sys.stderr)
            return {}
Behavior4/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. It effectively describes the tool's behavior: it's a batch translation operation that returns translations, not-found items, and counts. However, it lacks details on error handling, rate limits, or authentication needs, which would be valuable for a tool with no annotations.

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 well-structured and appropriately sized. It starts with a clear purpose statement, follows with usage guidelines, details parameters with examples, specifies return values, and provides a practical example. Every sentence adds value without redundancy.

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

Completeness5/5

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

Given the complexity (5 parameters, no annotations, no output schema), the description is highly complete. It covers purpose, usage, parameter semantics, return structure, and includes an example. This provides all necessary context for an agent to understand and invoke the tool correctly.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate. It provides detailed parameter semantics in the 'Args' section, including names, types, descriptions, and examples for all 5 parameters (e.g., 'mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL")'). This fully explains parameter meanings beyond the bare schema.

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

Purpose5/5

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

The description clearly states the tool's purpose: 'Translates multiple identifiers in a single batch operation.' It specifies the verb ('translates'), resource ('identifiers'), and scope ('batch operation'), and distinguishes it from sibling 'get_translation' by emphasizing efficiency for many identifiers.

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

Usage Guidelines5/5

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

The description explicitly provides usage guidance: 'This function is more efficient than multiple calls to get_translation when you need to translate many identifiers at once.' It names the alternative tool ('get_translation') and specifies when to use this tool ('when you need to translate many identifiers at once').

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

Related 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/jzinno/biomart-mcp'

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