[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EBKWMHFC29YP2MDMEDE929":3,"skill-same:01M7EBKWMHFC29YP2MDMEDE929":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":14,"repositoryHtmlUrl":33,"repositoryHomepageUrl":33,"ownerHtmlUrl":34,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":35,"install":36,"resources":49},"01M7EBKWMHFC29YP2MDMEDE929","bio-biomart-queries",null,"Bulk-query Ensembl BioMart (and other BioMart instances) for cross-database ID mapping, gene\u002Ftranscript\u002Fexon coordinates, and ortholog tables. Use when batch-converting Ensembl IDs to other namespaces (HGNC, RefSeq, UniProt, Entrez), pulling gene coordinate tables for thousands of genes, building ortholog wide-tables across species, or replacing slow Ensembl REST loops with one-shot bulk export. Encodes BioMart's XML query format, R biomaRt vs Python pybiomart trade-off, mart-vs-dataset hierarchy, and the URL endpoint that's BioMart-specific (separate from rest.ensembl.org).","Mr-Nobody-Anonymous\u002FAll-skills","Mr-Nobody-Anonymous","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184253119?v=4","01M7AEXFJHKTYQW5R0ZCQQTWFV","anonymous","01M7C00M3GQR4QKP9GZA42GFAK",0,"MIT","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-biomart-queries\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: bio-biomart-queries\ndescription: Bulk-query Ensembl BioMart (and other BioMart instances) for cross-database ID mapping, gene\u002Ftranscript\u002Fexon coordinates, and ortholog tables. Use when batch-converting Ensembl IDs to other namespaces (HGNC, RefSeq, UniProt, Entrez), pulling gene coordinate tables for thousands of genes, building ortholog wide-tables across species, or replacing slow Ensembl REST loops with one-shot bulk export. Encodes BioMart's XML query format, R biomaRt vs Python pybiomart trade-off, mart-vs-dataset hierarchy, and the URL endpoint that's BioMart-specific (separate from rest.ensembl.org).\ntool_type: mixed\nprimary_tool: pybiomart\nsource: \"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills\"\nsource_repository: \"GPTomics\u002FbioSkills\"\nsource_path: \"database-access\u002Fbiomart-queries\u002FSKILL.md\"\nlicense: \"MIT\"\nimported_at: \"2026-09-20\"\n---\n\n## Version Compatibility\n\nReference examples tested with: pybiomart 0.9+, R biomaRt 2.58+ (Bioconductor); Ensembl BioMart (release 110+)\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show pybiomart`\n- R: `packageVersion('biomaRt')`\n\nThe BioMart XML query format is stable across Ensembl releases; the underlying mart names and attribute IDs can change between Ensembl releases. For published work, pin the Ensembl release via `useEnsembl(version=110)`.\n\n# BioMart Queries\n\n**\"Bulk-convert IDs \u002F pull coordinate tables \u002F extract ortholog wide tables\"** -> BioMart is the right answer for any Ensembl-rooted query producing >5,000 rows. It is a separate service from the Ensembl REST API, with separate rate behavior and a different query model (XML-based, batch-oriented). For one-off lookups (\u003C100 records), Ensembl REST is more convenient; for bulk anything, BioMart wins.\n\nThe single most important fact: **BioMart returns a flat table from a single query**. There is no per-record loop, no rate-limit cascade, no async polling. One XML query in; one TSV out.\n\n- Python: `pybiomart` (https:\u002F\u002Fgithub.com\u002Fjrderuiter\u002Fpybiomart) is the lightest client\n- R: `biomaRt` Bioconductor (Durinck et al. 2009 *Nat Protoc* 4:1184) is the canonical client\n- CLI: `curl` against the XML endpoint works but is rarely used directly\n- Web: `https:\u002F\u002Fwww.ensembl.org\u002Fbiomart\u002Fmartview` for interactive query design\n\n## Installation\n\n```bash\npip install pybiomart pandas\n# R:\n# BiocManager::install('biomaRt')\n```\n\n## BioMart hierarchy\n\n| Level | Examples |\n|---|---|\n| Mart | `ENSEMBL_MART_ENSEMBL` (genes), `ENSEMBL_MART_SNP` (variants), `ENSEMBL_MART_MOUSE` (mouse-specific) |\n| Dataset | `hsapiens_gene_ensembl`, `mmusculus_gene_ensembl`, etc. (per species) |\n| Attribute | Fields to return: `ensembl_gene_id`, `external_gene_name`, `chromosome_name`, etc. |\n| Filter | Constraints on the query: `chromosome_name = 17`, `biotype = protein_coding`, etc. |\n\nA query is: pick a mart, pick a dataset, list attributes to return, list filters to constrain. BioMart returns a single TSV.\n\nDiscovery:\n```python\nfrom pybiomart import Server\nserver = Server(host='http:\u002F\u002Fwww.ensembl.org')\nprint(server.marts)                                          # list marts\nmart = server['ENSEMBL_MART_ENSEMBL']\nprint(mart.datasets)                                         # list datasets (species)\nds = mart['hsapiens_gene_ensembl']\nprint(ds.attributes)                                         # list attributes\nprint(ds.filters)                                            # list filters\n```\n\n## Decision matrix: BioMart vs Ensembl REST\n\n| Question | BioMart | Ensembl REST |\n|---|---|---|\n| Bulk ID mapping (>5000 IDs) | yes (1 query) | rate-limited cascade |\n| Single-gene lookup | overkill | yes |\n| Coordinate tables for thousands of genes | yes | rate-limited |\n| Ortholog wide-table across species | yes (multi-species mart) | per-gene loop |\n| VEP variant annotation | no | yes (or local VEP) |\n| Sequence retrieval | partial | yes |\n| Real-time | no (batch) | yes (per-record) |\n| Reproducibility (version pin) | `useEnsembl(version=110)` | archive URL `e110.rest.ensembl.org` |\n\nFor >5K rows, BioMart is the right tool. For real-time per-record lookups, REST.\n\n## Common attribute selectors\n\n| Attribute | Returns |\n|---|---|\n| `ensembl_gene_id` | Stable Ensembl Gene ID |\n| `ensembl_gene_id_version` | With `.N` version suffix |\n| `external_gene_name` | HGNC symbol (or species-equivalent) |\n| `hgnc_id`, `hgnc_symbol` | HGNC permanent ID and symbol |\n| `entrezgene_id` | NCBI Gene ID |\n| `refseq_mrna`, `refseq_peptide` | RefSeq accessions |\n| `uniprotswissprot`, `uniprotsptrembl` | UniProt accessions |\n| `chromosome_name`, `start_position`, `end_position`, `strand` | Gene coordinates |\n| `transcript_count`, `exon_count` | Counts |\n| `biotype` | protein_coding, lncRNA, miRNA, etc. |\n| `description` | Free-text gene description |\n| `go_id`, `name_1006`, `namespace_1003` | GO term ID, name, namespace |\n\n## Common filter selectors\n\n| Filter | Constraint |\n|---|---|\n| `ensembl_gene_id` | List of Gene IDs |\n| `external_gene_name` | List of symbols |\n| `entrezgene_id` | List of NCBI Gene IDs |\n| `chromosome_name` | One or more chromosomes |\n| `start` \u002F `end` | Coordinate range |\n| `biotype` | One or more biotypes |\n| `with_\u003Csource>` | Boolean: has cross-ref to `\u003Csource>` (e.g. `with_hpa` = has Human Protein Atlas) |\n\n## Code patterns\n\n### Bulk ID mapping: Ensembl Gene -> HGNC + RefSeq + UniProt\n\n**Goal:** Convert 5,000 Ensembl Gene IDs to HGNC symbols, RefSeq mRNA accessions, and UniProt accessions in one query.\n\n**Approach:** pybiomart query with three attributes; ID list as a filter; returns one TSV.\n\n**Reference (pybiomart 0.9+, Ensembl release 110+):**\n```python\nfrom pybiomart import Server\nimport pandas as pd\n\nserver = Server(host='http:\u002F\u002Fwww.ensembl.org')\nmart = server['ENSEMBL_MART_ENSEMBL']\nds = mart['hsapiens_gene_ensembl']\n\nensembl_ids = ['ENSG00000139618', 'ENSG00000141510', 'ENSG00000171862']  # ...up to 5K+\n\ndf = ds.query(\n    attributes=['ensembl_gene_id', 'external_gene_name', 'hgnc_id',\n                'refseq_mrna', 'uniprotswissprot'],\n    filters={'ensembl_gene_id': ensembl_ids},\n)\nprint(df.head())\n# One row per (gene, cross-ref) pair; genes with multiple RefSeq mRNAs get multiple rows.\n```\n\n### Pull gene coordinate table for a chromosome\n\n```python\ndf = ds.query(\n    attributes=['ensembl_gene_id', 'external_gene_name', 'chromosome_name',\n                'start_position', 'end_position', 'strand', 'biotype'],\n    filters={'chromosome_name': '17', 'biotype': 'protein_coding'},\n)\nprint(f'{len(df)} protein-coding genes on chr17')\n```\n\n### Bulk ortholog wide-table (human \u003C-> mouse \u003C-> zebrafish)\n\n**Goal:** One TSV with human Ensembl ID, mouse ortholog Ensembl ID, zebrafish ortholog Ensembl ID per row.\n\n**Approach:** Ortholog attributes from the human mart query both species' orthologs.\n\n```python\ndf = ds.query(\n    attributes=['ensembl_gene_id', 'external_gene_name',\n                'mmusculus_homolog_ensembl_gene', 'mmusculus_homolog_orthology_type',\n                'drerio_homolog_ensembl_gene', 'drerio_homolog_orthology_type'],\n    filters={'chromosome_name': '17'},\n)\n# pybiomart columns use the mart display names, which can vary across releases.\n# Resolve column names defensively rather than hardcoding strings:\nmouse_type_col = next(c for c in df.columns if 'Mouse' in c and 'type' in c)\nzebra_type_col = next(c for c in df.columns if 'Zebrafish' in c and 'type' in c)\ndf_one2one = df[(df[mouse_type_col] == 'ortholog_one2one') &\n                (df[zebra_type_col] == 'ortholog_one2one')]\nprint(f'{len(df_one2one)} 1:1 orthologs across all three species on chr17')\n```\n\n### GO term annotation for a gene set\n\n```python\ndf = ds.query(\n    attributes=['ensembl_gene_id', 'external_gene_name',\n                'go_id', 'name_1006', 'namespace_1003'],\n    filters={'external_gene_name': ['TP53', 'BRCA1', 'MYC', 'EGFR']},\n)\n# Long format: one row per (gene, GO term) pair\n```\n\n### Version-pinned query (R biomaRt)\n\n```r\n# Reference: Bioconductor biomaRt 2.58+ | Verify API if version differs\nlibrary(biomaRt)\n\n# Pin to release 110 for reproducibility\nensembl \u003C- useEnsembl(biomart='genes', dataset='hsapiens_gene_ensembl', version=110)\n\n# Or via host URL (for older or specific assemblies)\n# ensembl \u003C- useMart('ENSEMBL_MART_ENSEMBL',\n#                     dataset='hsapiens_gene_ensembl',\n#                     host='https:\u002F\u002Fnov2020.archive.ensembl.org')\n\ndf \u003C- getBM(\n    attributes = c('ensembl_gene_id', 'external_gene_name', 'entrezgene_id',\n                   'uniprotswissprot', 'refseq_mrna'),\n    filters = 'ensembl_gene_id',\n    values = c('ENSG00000139618', 'ENSG00000141510'),\n    mart = ensembl\n)\nhead(df)\n```\n\n### Discover attributes \u002F filters programmatically\n\n```python\n# What attributes are available?\nattrs = ds.attributes\northo_attrs = [a for a in attrs if 'homolog' in a]\nprint(f'{len(ortho_attrs)} ortholog attributes; first 5: {ortho_attrs[:5]}')\n\n# What filters?\nfilts = ds.filters\nchrom_filts = [f for f in filts if 'chrom' in f]\n```\n\n## Failure modes\n\n### Trying to pull >100K rows in one query\n- **Trigger:** Query without any filter (e.g. all attributes for the whole human genome).\n- **Mechanism:** BioMart times out or truncates on very large queries.\n- **Symptom:** Empty or partial result.\n- **Fix:** Chunk by chromosome; combine results client-side.\n\n### No version pinning\n- **Trigger:** `useMart('ensembl', ...)` without `version=`.\n- **Mechanism:** Defaults to current release; gene model versions change quarterly.\n- **Symptom:** Re-running a year later produces different rows.\n- **Fix:** Pin with `useEnsembl(version=110)` or archive host URL.\n\n### Multiple cross-refs balloon row count\n- **Trigger:** Query for `ensembl_gene_id, refseq_mrna`; a gene with 10 RefSeq mRNAs produces 10 rows.\n- **Mechanism:** BioMart joins on cross-refs; many-to-many produces row multiplication.\n- **Symptom:** \"Why do I have 50K rows for 5K input IDs?\"\n- **Fix:** Filter to one isoform per gene downstream; or use `ensembl_canonical` filter where available.\n\n### Symbol-based filter misses HGNC renames\n- **Trigger:** `filters={'external_gene_name': ['MARCH1']}` post-2020.\n- **Mechanism:** HGNC renamed to MARCHF1; BioMart mirrors the new symbol.\n- **Symptom:** Empty result for that gene.\n- **Fix:** Filter by `ensembl_gene_id` or `hgnc_id`; these are stable.\n\n### Multi-species mart query slow\n- **Trigger:** Querying `mmusculus_homolog_ensembl_gene` for 30K human genes.\n- **Mechanism:** Ortholog attributes are heavy; large queries take minutes.\n- **Symptom:** Timeout or slow.\n- **Fix:** Chunk by chromosome; or use Ensembl Compara REST for targeted lookups.\n\n### REST loops where BioMart belongs\n- **Trigger:** Loop of 5,000 Ensembl REST `\u002Flookup\u002Fsymbol` calls.\n- **Mechanism:** Rate-limit cascade; 5,000 * 0.07s = 6 minutes just for the rate gate, plus HTTP overhead.\n- **Symptom:** Slow; 429 errors.\n- **Fix:** Switch to one BioMart query.\n\n### Wrong mart for the question\n- **Trigger:** Querying gene info from `ENSEMBL_MART_SNP`.\n- **Mechanism:** SNP mart has variant attributes, not gene attributes.\n- **Symptom:** Empty result or wrong fields.\n- **Fix:** Discover marts with `server.marts`; pick `ENSEMBL_MART_ENSEMBL` for genes.\n\n## Common errors\n\n| Error \u002F symptom | Cause | Solution |\n|---|---|---|\n| Empty result | Wrong attribute \u002F filter name | List with `ds.attributes` and `ds.filters` |\n| Timeout on big query | No filter, too many rows | Chunk by chromosome |\n| Drift between re-runs | No version pinning | `useEnsembl(version=110)` |\n| Row count > expected | Many-to-many cross-ref joins | Filter to canonical isoform |\n| Symbol filter returns nothing | HGNC rename | Filter by Ensembl ID or HGNC ID |\n| Slow on ortholog wide-table | Multi-species join expensive | Chunk by chromosome |\n\n## References\n\n- Durinck S, Spellman PT, Birney E, Huber W. (2009) Mapping identifiers for the integration of genomic datasets with the R\u002FBioconductor package biomaRt. *Nat Protoc* 4:1184-1191.\n- Kinsella RJ, Kahari A, Haider S, et al. (2011) Ensembl BioMarts: a hub for data retrieval across taxonomic space. *Database* 2011:bar030.\n- Smedley D, Haider S, Durinck S, et al. (2015) The BioMart community portal: an innovative alternative to large, centralized data repositories. *Nucleic Acids Res* 43:W589-W598.\n- pybiomart documentation: https:\u002F\u002Fgithub.com\u002Fjrderuiter\u002Fpybiomart\n\n## Related Skills\n\n- ensembl-rest - Per-record Ensembl queries (BioMart's complement)\n- ortholog-inference - Compara ortholog calls with confidence semantics\n- uniprot-access - UniProt ID mapping (preferred for UniProt-rooted lookups and obsolete-accession resolution; BioMart is preferred for Ensembl-rooted batches >5K)\n- ncbi-datasets-cli - NCBI-side bulk path for genome \u002F gene data\n- entrez-search - NCBI alternative for non-Ensembl queries\n","## Version Compatibility\n\nReference examples tested with: pybiomart 0.9+, R biomaRt 2.58+ (Bioconductor); Ensembl BioMart (release 110+)\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show pybiomart`\n- R: `packageVersion('biomaRt')`\n\nThe BioMart XML query format is stable across Ensembl releases; the underlying mart names and attribute IDs can change between Ensembl releases. For published work, pin the Ensembl release via `useEnsembl(version=110)`.\n\n# BioMart Queries\n\n**\"Bulk-convert IDs \u002F pull coordinate tables \u002F extract ortholog wide tables\"** -> BioMart is the right answer for any Ensembl-rooted query producing >5,000 rows. It is a separate service from the Ensembl REST API, with separate rate behavior and a different query model (XML-based, batch-oriented). For one-off lookups (\u003C100 records), Ensembl REST is more convenient; for bulk anything, BioMart wins.\n\nThe single most important fact: **BioMart returns a flat table from a single query**. There is no per-record loop, no rate-limit cascade, no async polling. One XML query in; one TSV out.\n\n- Python: `pybiomart` (https:\u002F\u002Fgithub.com\u002Fjrderuiter\u002Fpybiomart) is the lightest client\n- R: `biomaRt` Bioconductor (Durinck et al. 2009 *Nat Protoc* 4:1184) is the canonical client\n- CLI: `curl` against the XML endpoint works but is rarely used directly\n- Web: `https:\u002F\u002Fwww.ensembl.org\u002Fbiomart\u002Fmartview` for interactive query design\n\n## Installation\n\n```bash\npip install pybiomart pandas\n# R:\n# BiocManager::install('biomaRt')\n```\n\n## BioMart hierarchy\n\n| Level | Examples |\n|---|---|\n| Mart | `ENSEMBL_MART_ENSEMBL` (genes), `ENSEMBL_MART_SNP` (variants), `ENSEMBL_MART_MOUSE` (mouse-specific) |\n| Dataset | `hsapiens_gene_ensembl`, `mmusculus_gene_ensembl`, etc. (per species) |\n| Attribute | Fields to return: `ensembl_gene_id`, `external_gene_name`, `chromosome_name`, etc. |\n| Filter | Constraints on the query: `chromosome_name = 17`, `biotype = protein_coding`, etc. |\n\nA query is: pick a mart, pick a dataset, list attributes to return, list filters to constrain. BioMart returns a single TSV.\n\nDiscovery:\n```python\nfrom pybiomart import Server\nserver = Server(host='http:\u002F\u002Fwww.ensembl.org')\nprint(server.marts)                                          # list marts\nmart = server['ENSEMBL_MART_ENSEMBL']\nprint(mart.datasets)                                         # list datasets (species)\nds = mart['hsapiens_gene_ensembl']\nprint(ds.attributes)                                         # list attributes\nprint(ds.filters)                                            # list filters\n```\n\n## Decision matrix: BioMart vs Ensembl REST\n\n| Question | BioMart | Ensembl REST |\n|---|---|---|\n| Bulk ID mapping (>5000 IDs) | yes (1 query) | rate-limited cascade |\n| Single-gene lookup | overkill | yes |\n| Coordinate tables for thousands of genes | yes | rate-limited |\n| Ortholog wide-table across species | yes (multi-species mart) | per-gene loop |\n| VEP variant annotation | no | yes (or local VEP) |\n| Sequence retrieval | partial | yes |\n| Real-time | no (batch) | yes (per-record) |\n| Reproducibility (version pin) | `useEnsembl(version=110)` | archive URL `e110.rest.ensembl.org` |\n\nFor >5K rows, BioMart is the right tool. For real-time per-record lookups, REST.\n\n## Common attribute selectors\n\n| Attribute | Returns |\n|---|---|\n| `ensembl_gene_id` | Stable Ensembl Gene ID |\n| `ensembl_gene_id_version` | With `.N` version suffix |\n| `external_gene_name` | HGNC symbol (or species-equivalent) |\n| `hgnc_id`, `hgnc_symbol` | HGNC permanent ID and symbol |\n| `entrezgene_id` | NCBI Gene ID |\n| `refseq_mrna`, `refseq_peptide` | RefSeq accessions |\n| `uniprotswissprot`, `uniprotsptrembl` | UniProt accessions |\n| `chromosome_name`, `start_position`, `end_position`, `strand` | Gene coordinates |\n| `transcript_count`, `exon_count` | Counts |\n| `biotype` | protein_coding, lncRNA, miRNA, etc. |\n| `description` | Free-text gene description |\n| `go_id`, `name_1006`, `namespace_1003` | GO term ID, name, namespace |\n\n## Common filter selectors\n\n| Filter | Constraint |\n|---|---|\n| `ensembl_gene_id` | List of Gene IDs |\n| `external_gene_name` | List of symbols |\n| `entrezgene_id` | List of NCBI Gene IDs |\n| `chromosome_name` | One or more chromosomes |\n| `start` \u002F `end` | Coordinate range |\n| `biotype` | One or more biotypes |\n| `with_\u003Csource>` | Boolean: has cross-ref to `\u003Csource>` (e.g. `with_hpa` = has Human Protein Atlas) |\n\n## Code patterns\n\n### Bulk ID mapping: Ensembl Gene -> HGNC + RefSeq + UniProt\n\n**Goal:** Convert 5,000 Ensembl Gene IDs to HGNC symbols, RefSeq mRNA accessions, and UniProt accessions in one query.\n\n**Approach:** pybiomart query with three attributes; ID list as a filter; returns one TSV.\n\n**Reference (pybiomart 0.9+, Ensembl release 110+):**\n```python\nfrom pybiomart import Server\nimport pandas as pd\n\nserver = Server(host='http:\u002F\u002Fwww.ensembl.org')\nmart = server['ENSEMBL_MART_ENSEMBL']\nds = mart['hsapiens_gene_ensembl']\n\nensembl_ids = ['ENSG00000139618', 'ENSG00000141510', 'ENSG00000171862']  # ...up to 5K+\n\ndf = ds.query(\n    attributes=['ensembl_gene_id', 'external_gene_name', 'hgnc_id',\n                'refseq_mrna', 'uniprotswissprot'],\n    filters={'ensembl_gene_id': ensembl_ids},\n)\nprint(df.head())\n# One row per (gene, cross-ref) pair; genes with multiple RefSeq mRNAs get multiple rows.\n```\n\n### Pull gene coordinate table for a chromosome\n\n```python\ndf = ds.query(\n    attributes=['ensembl_gene_id', 'external_gene_name', 'chromosome_name',\n                'start_position', 'end_position', 'strand', 'biotype'],\n    filters={'chromosome_name': '17', 'biotype': 'protein_coding'},\n)\nprint(f'{len(df)} protein-coding genes on chr17')\n```\n\n### Bulk ortholog wide-table (human \u003C-> mouse \u003C-> zebrafish)\n\n**Goal:** One TSV with human Ensembl ID, mouse ortholog Ensembl ID, zebrafish ortholog Ensembl ID per row.\n\n**Approach:** Ortholog attributes from the human mart query both species' orthologs.\n\n```python\ndf = ds.query(\n    attributes=['ensembl_gene_id', 'external_gene_name',\n                'mmusculus_homolog_ensembl_gene', 'mmusculus_homolog_orthology_type',\n                'drerio_homolog_ensembl_gene', 'drerio_homolog_orthology_type'],\n    filters={'chromosome_name': '17'},\n)\n# pybiomart columns use the mart display names, which can vary across releases.\n# Resolve column names defensively rather than hardcoding strings:\nmouse_type_col = next(c for c in df.columns if 'Mouse' in c and 'type' in c)\nzebra_type_col = next(c for c in df.columns if 'Zebrafish' in c and 'type' in c)\ndf_one2one = df[(df[mouse_type_col] == 'ortholog_one2one') &\n                (df[zebra_type_col] == 'ortholog_one2one')]\nprint(f'{len(df_one2one)} 1:1 orthologs across all three species on chr17')\n```\n\n### GO term annotation for a gene set\n\n```python\ndf = ds.query(\n    attributes=['ensembl_gene_id', 'external_gene_name',\n                'go_id', 'name_1006', 'namespace_1003'],\n    filters={'external_gene_name': ['TP53', 'BRCA1', 'MYC', 'EGFR']},\n)\n# Long format: one row per (gene, GO term) pair\n```\n\n### Version-pinned query (R biomaRt)\n\n```r\n# Reference: Bioconductor biomaRt 2.58+ | Verify API if version differs\nlibrary(biomaRt)\n\n# Pin to release 110 for reproducibility\nensembl \u003C- useEnsembl(biomart='genes', dataset='hsapiens_gene_ensembl', version=110)\n\n# Or via host URL (for older or specific assemblies)\n# ensembl \u003C- useMart('ENSEMBL_MART_ENSEMBL',\n#                     dataset='hsapiens_gene_ensembl',\n#                     host='https:\u002F\u002Fnov2020.archive.ensembl.org')\n\ndf \u003C- getBM(\n    attributes = c('ensembl_gene_id', 'external_gene_name', 'entrezgene_id',\n                   'uniprotswissprot', 'refseq_mrna'),\n    filters = 'ensembl_gene_id',\n    values = c('ENSG00000139618', 'ENSG00000141510'),\n    mart = ensembl\n)\nhead(df)\n```\n\n### Discover attributes \u002F filters programmatically\n\n```python\n# What attributes are available?\nattrs = ds.attributes\northo_attrs = [a for a in attrs if 'homolog' in a]\nprint(f'{len(ortho_attrs)} ortholog attributes; first 5: {ortho_attrs[:5]}')\n\n# What filters?\nfilts = ds.filters\nchrom_filts = [f for f in filts if 'chrom' in f]\n```\n\n## Failure modes\n\n### Trying to pull >100K rows in one query\n- **Trigger:** Query without any filter (e.g. all attributes for the whole human genome).\n- **Mechanism:** BioMart times out or truncates on very large queries.\n- **Symptom:** Empty or partial result.\n- **Fix:** Chunk by chromosome; combine results client-side.\n\n### No version pinning\n- **Trigger:** `useMart('ensembl', ...)` without `version=`.\n- **Mechanism:** Defaults to current release; gene model versions change quarterly.\n- **Symptom:** Re-running a year later produces different rows.\n- **Fix:** Pin with `useEnsembl(version=110)` or archive host URL.\n\n### Multiple cross-refs balloon row count\n- **Trigger:** Query for `ensembl_gene_id, refseq_mrna`; a gene with 10 RefSeq mRNAs produces 10 rows.\n- **Mechanism:** BioMart joins on cross-refs; many-to-many produces row multiplication.\n- **Symptom:** \"Why do I have 50K rows for 5K input IDs?\"\n- **Fix:** Filter to one isoform per gene downstream; or use `ensembl_canonical` filter where available.\n\n### Symbol-based filter misses HGNC renames\n- **Trigger:** `filters={'external_gene_name': ['MARCH1']}` post-2020.\n- **Mechanism:** HGNC renamed to MARCHF1; BioMart mirrors the new symbol.\n- **Symptom:** Empty result for that gene.\n- **Fix:** Filter by `ensembl_gene_id` or `hgnc_id`; these are stable.\n\n### Multi-species mart query slow\n- **Trigger:** Querying `mmusculus_homolog_ensembl_gene` for 30K human genes.\n- **Mechanism:** Ortholog attributes are heavy; large queries take minutes.\n- **Symptom:** Timeout or slow.\n- **Fix:** Chunk by chromosome; or use Ensembl Compara REST for targeted lookups.\n\n### REST loops where BioMart belongs\n- **Trigger:** Loop of 5,000 Ensembl REST `\u002Flookup\u002Fsymbol` calls.\n- **Mechanism:** Rate-limit cascade; 5,000 * 0.07s = 6 minutes just for the rate gate, plus HTTP overhead.\n- **Symptom:** Slow; 429 errors.\n- **Fix:** Switch to one BioMart query.\n\n### Wrong mart for the question\n- **Trigger:** Querying gene info from `ENSEMBL_MART_SNP`.\n- **Mechanism:** SNP mart has variant attributes, not gene attributes.\n- **Symptom:** Empty result or wrong fields.\n- **Fix:** Discover marts with `server.marts`; pick `ENSEMBL_MART_ENSEMBL` for genes.\n\n## Common errors\n\n| Error \u002F symptom | Cause | Solution |\n|---|---|---|\n| Empty result | Wrong attribute \u002F filter name | List with `ds.attributes` and `ds.filters` |\n| Timeout on big query | No filter, too many rows | Chunk by chromosome |\n| Drift between re-runs | No version pinning | `useEnsembl(version=110)` |\n| Row count > expected | Many-to-many cross-ref joins | Filter to canonical isoform |\n| Symbol filter returns nothing | HGNC rename | Filter by Ensembl ID or HGNC ID |\n| Slow on ortholog wide-table | Multi-species join expensive | Chunk by chromosome |\n\n## References\n\n- Durinck S, Spellman PT, Birney E, Huber W. (2009) Mapping identifiers for the integration of genomic datasets with the R\u002FBioconductor package biomaRt. *Nat Protoc* 4:1184-1191.\n- Kinsella RJ, Kahari A, Haider S, et al. (2011) Ensembl BioMarts: a hub for data retrieval across taxonomic space. *Database* 2011:bar030.\n- Smedley D, Haider S, Durinck S, et al. (2015) The BioMart community portal: an innovative alternative to large, centralized data repositories. *Nucleic Acids Res* 43:W589-W598.\n- pybiomart documentation: https:\u002F\u002Fgithub.com\u002Fjrderuiter\u002Fpybiomart\n\n## Related Skills\n\n- ensembl-rest - Per-record Ensembl queries (BioMart's complement)\n- ortholog-inference - Compara ortholog calls with confidence semantics\n- uniprot-access - UniProt ID mapping (preferred for UniProt-rooted lookups and obsolete-accession resolution; BioMart is preferred for Ensembl-rooted batches >5K)\n- ncbi-datasets-cli - NCBI-side bulk path for genome \u002F gene data\n- entrez-search - NCBI alternative for non-Ensembl queries\n",{"name":5,"source":24,"license":15,"tool_type":25,"description":7,"imported_at":26,"source_path":27,"primary_tool":28,"source_repository":29},"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills","mixed","2026-09-20","database-access\u002Fbiomart-queries\u002FSKILL.md","pybiomart","GPTomics\u002FbioSkills","main","2d1750717747097b602acf30bd09a7cbd4b4c6ea","awesome_skills\u002Fbiology\u002Fbio-biomart-queries","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous","2026-11-09 11:45:36",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-biomart-queries",{"tool":42,"command":43},"bunx","bunx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-biomart-queries",{"tool":45,"command":46},"pnpm","pnpm dlx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-biomart-queries","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-biomart-queries\u002FSKILL.md",true,[50,56,60,64],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"examples\u002Fbulk_id_mapping.py","SCRIPT","脚本",1692,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-biomart-queries\u002Fexamples\u002Fbulk_id_mapping.py",{"path":57,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":58,"sourceHtmlUrl":59},"examples\u002Fcoordinate_table.sh",1699,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-biomart-queries\u002Fexamples\u002Fcoordinate_table.sh",{"path":61,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":62,"sourceHtmlUrl":63},"examples\u002Fortholog_table.py",1658,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-biomart-queries\u002Fexamples\u002Fortholog_table.py",{"path":65,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":68,"sourceHtmlUrl":69},"usage-guide.md","REFERENCE","参考文档",4151,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-biomart-queries\u002Fusage-guide.md",[71,79,86,93,100,107],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":78},"01M7FFFZPC2025JQQHPHDX154J","dei-assessment","Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-assessment\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":78},"01M7FFFWN8H4WA7A6Y398QKB6J","dei-action-plan","Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-action-plan\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":78},"01M7FFFSHTM0QZRVZ2NRJTJ0PY","culture-fit-assessment","Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fculture-fit-assessment\u002FSKILL.md",[],[],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":78},"01M7FFFMA12RKEQA38KHJSXXPS","cowork-to-code-bridge","Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcowork-to-code-bridge\u002FSKILL.md",[],[],{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":78},"01M7FFFH1F6M8YRGW5V487GH1K","counter-offer-response","Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcounter-offer-response\u002FSKILL.md",[],[],{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":78},"01M7FFFDGEHV8Y7J9N40HZXW52","continuous-feedback-system","Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcontinuous-feedback-system\u002FSKILL.md",[],[]]