Alterlab gene db

From AlterLab-IEU/AlterLab-Academic-Skills · View interactive version

Alterlab gene db is an AI agent skill from the GitHub repository AlterLab-IEU/AlterLab-Academic-Skills. Query NCBI Gene via the E-utilities and Datasets APIs, searching by gene symbol or Gene ID and retrieving gene information (RefSeqs, GO terms, genomic locations, associated phenotypes) including batch lookups. Use when resolving gene symbols to IDs, annotating gene lists, or pulling functional and p

How to use this skill

Skill file

Gene Database

Overview

NCBI Gene is a comprehensive database integrating gene information from diverse species. It provides nomenclature, reference sequences (RefSeqs), chromosomal maps, biological pathways, genetic variations, phenotypes, and cross-references to global genomic resources.

When to Use This Skill

This skill should be used when working with gene data including searching by gene symbol or ID, retrieving gene sequences and metadata, analyzing gene functions and pathways, or performing batch gene lookups.

Does NOT Trigger

| Scenario | Use Instead |

|----------|-------------|

| Ensembl IDs, VEP consequences, orthologs, or GRCh37↔GRCh38 mapping | alterlab-ensembl |

| Protein-level function, domains, PTMs, or UniProt ID mapping | alterlab-uniprot |

| Variant clinical significance | alterlab-clinvar |

| Pathway membership / enrichment for a gene list | alterlab-reactome |

| Quick one-off gene lookups from a CLI across databases | alterlab-gget |

Hand-off rule. When the request matches a row above, open your answer by naming that skill by its exact id (for example alterlab-ensembl) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.

Quick Start

NCBI provides two main APIs for gene data access:

  1. E-utilities (Traditional): Full-featured API for all Entrez databases with flexible querying
  2. NCBI Datasets API (Newer): Optimized for gene data retrieval with simplified workflows

Choose E-utilities for complex queries and cross-database searches. Choose the Datasets API for straightforward gene metadata retrieval (one gene report per request; transcript/protein RefSeq accessions come from the separate product_report endpoint).

Common Workflows

Search Genes by Symbol or Name

To search for genes by symbol or name across organisms:

  1. Use the scripts/query_gene.py script with E-utilities ESearch
  2. Specify the gene symbol and organism (e.g., "BRCA1 in human")
  3. The script returns matching Gene IDs

Example query patterns (tags checked against einfo.fcgi?db=gene; an unknown tag such

as [disease], [phenotype], or [pathway] is silently rewritten to [All Fields] —

always read querytranslation in the ESearch response):

insulin[gene name] finds nothing — use insulin[Gene Full Name] for names)

([chromosome] holds chromosome numbers only, e.g. 17[chromosome])

Retrieve Gene Information by ID

To fetch detailed information for known Gene IDs:

  1. Use scripts/fetch_gene_data.py with the Datasets API for comprehensive data
  2. Alternatively, use scripts/query_gene.py with E-utilities EFetch for specific formats
  3. Specify desired output format (JSON, XML, or text)

The Datasets API gene report returns:

For the individual transcript/protein RefSeq accessions, request the

product_report endpoint (GET /gene/id/{id}/product_report) — the base

gene report carries the counts, not the accessions.

Batch Gene Lookups

For multiple genes simultaneously:

  1. Use scripts/batch_gene_lookup.py for efficient batch processing
  2. Provide a list of gene symbols or IDs
  3. Specify the organism for symbol-based queries
  4. The script handles rate limiting automatically (10 requests/second with API key) and

retries HTTP 429/5xx

  1. Each symbol is matched as the official symbol ([pref]) first, then as an alias or

previous symbol ([gene]); the matched_by field says which. Report renamed genes

(MRE11A → MRE11, FAM175A → ABRAXAS1). A bare [gene] search can return the wrong

gene: POLQ[gene] ranks POLK (alias "POLQ") above POLQ (Gene ID 10721)

This workflow is useful for:

Search by Biological Context

To find genes associated with specific biological functions or phenotypes:

  1. Use E-utilities with Gene Ontology (GO) terms or phenotype keywords
  2. Query by pathway names or disease associations
  3. Filter by organism, chromosome, or other attributes

Example searches:

("insulin receptor signaling pathway"[Gene Ontology]) or a pathway database

(alterlab-reactome, alterlab-kegg)

API Access Patterns

Rate Limits:

Authentication:

Register for a free NCBI API key at https://www.ncbi.nlm.nih.gov/account/ to increase rate limits.

Error Handling:

Both APIs return standard HTTP status codes. Common errors include:

Retry failed requests with exponential backoff.

Script Usage

query_gene.py

Query NCBI Gene using E-utilities (ESearch, ESummary, EFetch).

python scripts/query_gene.py --search "BRCA1" --organism "human"
python scripts/query_gene.py --id 672 --format json
python scripts/query_gene.py --search "INS[sym] AND diabetes[Disease/Phenotype]" --organism human

fetch_gene_data.py

Fetch comprehensive gene data using NCBI Datasets API.

python scripts/fetch_gene_data.py --gene-id 672
python scripts/fetch_gene_data.py --symbol BRCA1 --taxon human
python scripts/fetch_gene_data.py --symbol TP53 --taxon "Homo sapiens" --output json

batch_gene_lookup.py

Process multiple gene queries efficiently.

python scripts/batch_gene_lookup.py --file gene_list.txt --organism human
python scripts/batch_gene_lookup.py --ids 672,7157,5594 --output results.json

API References

For detailed API documentation including endpoints, parameters, response formats, and examples, refer to:

Search these references when needing specific API endpoint details, parameter options, or response structure information.

Data Formats

NCBI Gene data can be retrieved in multiple formats:

Choose JSON for modern applications, XML for legacy systems requiring detailed metadata, and FASTA for sequence analysis workflows.

Best Practices

  1. Always specify organism when searching by gene symbol to avoid ambiguity
  2. Use Gene IDs for precise lookups when available
  3. Batch requests when working with multiple genes to minimize API calls
  4. Cache results locally to reduce redundant queries
  5. Include API key in scripts for higher rate limits
  6. Handle errors gracefully with retry logic for transient failures
  7. Validate gene symbols before batch processing to catch typos

Resources

This skill includes:

scripts/

references/

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.