xtract
Quick Start
- Command:
xtract - Local executable:
/home/vimalinx/miniforge3/envs/bio/bin/xtract - Full reference: See
references/help.mdfor complete argument list and examples
When To Use This Tool
- Convert Entrez XML into tab-delimited tables.
- Extract selected elements or nested values from
efetch,esummary, orelinkXML output. - Filter records conditionally while flattening XML into rows.
- Use this after you already know the XML structure you are parsing.
Common Patterns
# 1) Turn document summaries into a simple two-column table
esearch -db assembly -query 'GCF_000001405.40[accn]' | \
efetch -format docsum | \
xtract -pattern DocumentSummary -element Id AssemblyAccession
# 2) Extract PubMed summary IDs and titles
esearch -db pubmed -query 'ebola virus[Title/Abstract]' | \
efetch -format docsum | \
xtract -pattern DocumentSummary -element Id Title
# 3) Conditional extraction from linked records
elink -db pubmed -id 20210808 -cmd score | \
xtract -pattern LinkSet -max Link/Score
Recommended Workflow
- Feed XML from stdin or
-input;xtractis not useful without structured input. - Define rows first with
-pattern. - Add
-elementfields incrementally before reaching for-group,-block, or-if. - Save the exact extraction command alongside the analysis so XML-to-table logic remains reproducible.
Guardrails
xtractrequires XML input from stdin or-input; otherwise it errors immediately.-patterndefines row boundaries; choosing the wrong pattern is the fastest way to get nonsense tables.- Start with a minimal extraction and expand, rather than writing a huge one-liner blind.
- Use
-strictwhen embedded HTML or MathML is polluting the text you want to extract.