bio-batch-downloads
Download large datasets from NCBI efficiently using EPost, history server, batching, rate limiting, and retry logic. Use when bulk-fetching tens of thousands of sequences, pulling all results of a large ESearch, designing reproducible pipelines, comparing E-utilities to NCBI Datasets v2 CLI, or implementing checksum-validated downloads. Encodes WebEnv TTL (~8h), EPost 200-ID limit, retmax caps, parallelization design, and integrity verification.
What this skill does
## Version Compatibility Reference examples tested with: BioPython 1.83+, NCBI Datasets CLI 16.0+, Entrez Direct 21.0+ Before using code patterns, verify installed versions match. If versions differ: - Python: `pip show biopython` then `help(Bio.Entrez.efetch)` to check signatures - CLI: `datasets --version` and `efetch -version` If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying. # Batch Downloads **"Download N thousand records from NCBI without getting blocked"** -> The right answer is rarely "parallelize requests". For >5000 records the answer is the **history server**: search once, fetch in chunks server-side. For >100,000 records or whole genomes, the modern answer is **NCBI Datasets v2 CLI** -- the E-utilities are not optimized for bulk genome/gene data anymore. This skill encodes (a) when to use each retrieval strategy, (b) the precise rate-limit math, (c) WebEnv lifecycle for long-running jobs, (d) how to design retry/resume, and (e) when to defect to Datasets CLI instead. - Python: `Entrez.esearch(usehistory='y')` + chunked `Entrez.efetch()` (BioPython) - CLI: `datasets download genome accession ...` (NCBI Datasets v2 -- preferred for genome/gene bulk) - CLI: `epost | efetch -mode webenv` (Entrez Direct) ## Required Setup ```python from Bio import Entrez import time Entrez.email = '[email protected]' Entrez.api_key = 'YOUR_KEY' # 3 -> 10 req/sec; mandatory for bulk Entrez.tool = 'project-name' ``` ## Decision matrix: which retrieval strategy? | Record count | Source | Strategy | Why | |---|---|---|---| | < 200 known IDs | Any db | EFetch with comma-joined `id=` | Single round-trip; trivial | | 200-5,000 known IDs | Any db | EPost (chunked at 200) -> history -> chunked EFetch | URL length limit + chunked retrieval | | 5,000-100,000 from a query | Any db | ESearch with `usehistory='y'` -> chunked EFetch | Push to server once; pull in batches | | > 100,000 sequences | nucleotide/protein | Consider FTP mirror or Datasets CLI; chunk if E-utils still | NCBI throttles bulk; offline mirror is faster | | Whole genome assemblies | Assembly/Datasets | `datasets download genome accession ...` | Datasets v2 is the modern bulk endpoint | | All RefSeq for a species | Datasets | `datasets download genome taxon ...` | Replaces assembly_summary.txt scraping | | All gene records for a list | Datasets | `datasets download gene gene-id ...` | Cleaner output than EFetch gene XML | | Raw sequencing reads | SRA | `prefetch` + `fasterq-dump` (or ENA mirror) | See `sra-data` skill | The Datasets CLI is the right answer for any genome- or gene-centric bulk workflow as of 2023+. The E-utilities remain right for PubMed, ESummary metadata, custom queries, and anything not in the Datasets API. See `ncbi-datasets-cli` skill. ## Rate-limit math (precise) | Auth | req/sec | Sleep between calls | Bulk-friendly notes | |---|---|---|---| | Email only | 3 | 0.34 s | Single-threaded only; parallelism violates ToS | | Email + API key | 10 | 0.10 s | Modest parallelism (max ~4 workers) safe | | Institutional bulk | Negotiated | Email `[email protected]` | For >100K queries; courtesy expected | NCBI's terms ask that heavy automated downloads run **outside US weekday business hours (9 AM-5 PM ET)**. Cron the job for nights/weekends; pipelines that ignore this get IP-throttled. **Critical**: parallelizing API calls is the WRONG bulk strategy. One stream with history server + larger batches is faster AND more polite than N parallel streams. The bottleneck is rarely NCBI's throughput at small N -- it's the round-trip count. ## History server lifecycle (the long-running-job trap) | Property | Value | Failure mode | |---|---|---| | TTL | 8 hours absolute (per NCBI E-utils help) | Job started Friday evening dies Saturday morning | | Idle eviction | ~15 min empirically under load | A worker that stalls loses its WebEnv | | Per-session isolation | One WebEnv string per session | Don't share across processes if isolation matters | | Expired session behavior | HTTP 200 with `<ERROR>WebEnv not found</ERROR>` | Won't surface as HTTP error -- must parse body | | Recovery | Re-run ESearch; resume at `retstart` | Need to checkpoint progress to disk | Production pattern: checkpoint the `retstart` cursor after each successful chunk to disk; on restart, re-run ESearch (cheap), pick up `retstart` from checkpoint, continue. ## EPost specifics EPost pushes a list of UIDs to the history server so downstream EFetch can pull by WebEnv/QueryKey instead of by ID. Two constraints: - **200 IDs per EPost call** is the hard limit. - **Chained posts share a WebEnv**: pass the WebEnv from the first call into subsequent calls to accumulate IDs under one session; a new QueryKey is issued per call. To intersect: `term=#{key1} AND #{key2}` against the WebEnv produces a new key. ## Batch size guidelines per rettype | Database | rettype | Optimal batch | Per-record payload | |---|---|---|---| | nucleotide | fasta | 500-1000 | ~1 KB | | nucleotide | gb | 100-200 | ~10-50 KB | | protein | fasta | 500-1000 | ~0.5 KB | | protein | gp | 100-200 | ~5-30 KB | | pubmed | medline | 1000-2000 | ~2 KB | | pubmed | xml | 200-500 | ~10-30 KB | | any | esummary (docsum) | 500 per call | ~1 KB | Smaller batches for GenBank/XML because per-record payload is larger; larger batches for FASTA because the per-call HTTP overhead dominates. ## Code patterns ### Production batch fetch (history server + retry + checkpoint) **Goal:** Download all records matching a query, robust to mid-job failures and session expiry. **Approach:** ESearch with history; checkpoint cursor to disk; on error, retry the chunk; on session expiry, re-run ESearch and resume from checkpoint. **Reference (BioPython 1.83+):** ```python import json import time from pathlib import Path from urllib.error import HTTPError from Bio import Entrez def checkpointed_batch_download(db, term, out_path, ckpt_path, rettype='fasta', retmode='text', batch_size=500, max_retries=3): '''Download all matching records with disk checkpoint for resumability.''' delay = 0.1 if Entrez.api_key else 0.34 ckpt = Path(ckpt_path) start = json.loads(ckpt.read_text())['start'] if ckpt.exists() else 0 h = Entrez.esearch(db=db, term=term, usehistory='y', retmax=0) s = Entrez.read(h); h.close() webenv, query_key, total = s['WebEnv'], s['QueryKey'], int(s['Count']) print(f'{total:,} records matched; resuming at {start:,}') mode = 'a' if start else 'w' with open(out_path, mode) as out: while start < total: for attempt in range(max_retries): try: h = Entrez.efetch(db=db, rettype=rettype, retmode=retmode, retstart=start, retmax=batch_size, webenv=webenv, query_key=query_key) body = h.read(); h.close() if isinstance(body, bytes): body = body.decode('utf-8', errors='replace') if '<ERROR>' in body[:500]: raise RuntimeError(f'Server error in body: {body[:200]}') out.write(body) break except HTTPError as e: if e.code == 429: wait = 10 * (attempt + 1) print(f' Rate-limited; sleeping {wait}s') time.sleep(wait) elif attempt == max_retries - 1: raise else: time.sleep(5 * (attempt + 1)) except RuntimeError as e: # Likely WebEnv expired; re-run ESearch print(f' {e}; refreshing WebEnv') h = Entrez.esearch(db=db, term=term, usehistory='y', retmax
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.