[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CVN39EN5W9R00AYW877FNQ":3,"skill-same:01M7CVN39EN5W9R00AYW877FNQ":67},{"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":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":6,"ownerHtmlUrl":31,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":32,"install":33,"resources":46},"01M7CVN39EN5W9R00AYW877FNQ","bio-phylo-tree-io",null,"Read, write, and convert phylogenetic tree files with Biopython Bio.Phylo, and choose an annotation-preserving parser (treeio, DendroPy) when metadata matters. Covers why a tree file is a lossy serialization, why format conversion silently drops BEAST\u002FMrBayes node annotations (posteriors, HPD intervals, rates), the Newick support-vs-label ambiguity that mislabels bootstrap values, and the Nexus TRANSLATE and rooted\u002Funrooted traps. Use when parsing Newick, Nexus, NHX, phyloXML, or NeXML, converting between formats, handling posterior tree sets, or moving annotated BEAST trees without losing the credible intervals. Routes annotation-critical reads to DendroPy or treeio and orthology\u002Falignment context to sibling skills.","mrsonord2240\u002Fopenscience-specialists","mrsonord2240","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F76487430?v=4","01M7CTEM40S43GSJZ9A3YCCXZK","Samuel Nord","01M7CTEM4K69JD1GBYNHVJ9ZP4",2,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fmolecular-phylogenetics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-phylo-tree-io\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: bio-phylo-tree-io\ndescription: Read, write, and convert phylogenetic tree files with Biopython Bio.Phylo, and choose an annotation-preserving parser (treeio, DendroPy) when metadata matters. Covers why a tree file is a lossy serialization, why format conversion silently drops BEAST\u002FMrBayes node annotations (posteriors, HPD intervals, rates), the Newick support-vs-label ambiguity that mislabels bootstrap values, and the Nexus TRANSLATE and rooted\u002Funrooted traps. Use when parsing Newick, Nexus, NHX, phyloXML, or NeXML, converting between formats, handling posterior tree sets, or moving annotated BEAST trees without losing the credible intervals. Routes annotation-critical reads to DendroPy or treeio and orthology\u002Falignment context to sibling skills.\ntool_type: python\nprimary_tool: Bio.Phylo\n---\n\n## Version Compatibility\n\nReference examples tested with: BioPython 1.83+. Annotation-preserving alternatives: DendroPy 5+ (Python), treeio 1.26+ \u002F ape 5.8+ (R).\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show biopython` then `help(module.function)` to check signatures\n- R: `packageVersion('treeio')` then `?read.beast` to verify parameters\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed\npackage and adapt the example to match the actual API rather than retrying.\n\nBio.Phylo stores a Newick `[&...]` bracket as opaque `.comment` text and does NOT parse BEAST key-values; DendroPy `extract_comment_metadata=True` and treeio `read.beast` do.\n\n# Tree I\u002FO -- A Tree File Is a Lossy Serialization\n\n**\"Read and convert my tree files\"** -> Parse a tree into an in-memory object and re-serialize it, knowing which annotations each format and parser preserves.\n- Python: `Phylo.read('tree.nwk', 'newick')`, `Phylo.convert(...)` (Bio.Phylo)\n- Annotation-critical: `dendropy.Tree.get(..., extract_comment_metadata=True)` or treeio `read.beast()`\n\nScope: reading, writing, converting, and inspecting tree files, and selecting a parser that keeps the annotations the analysis needs. Rooting, pruning, collapsing -> tree-manipulation. Plotting and mapping annotations onto branches -> tree-visualization. Producing BEAST\u002FMrBayes annotated trees -> bayesian-inference, divergence-dating. Taxon-name sanitization shares the whitespace traps in sequence-io\u002Fread-sequences.\n\n## The Single Most Important Modern Insight\n\nA tree file is a lossy serialization of a richer in-memory object. The biologist cares about the topology plus its annotations -- branch supports, posterior probabilities, 95% HPD intervals on node heights, per-branch rates, divergence dates, taxon metadata -- and formats differ enormously in which of these they can hold, while parsers differ in which they actually read back. Three load-bearing facts:\n\n1. **Conversion is a silent data-destroying operation.** Reading a BEAST MCC tree and writing plain Newick produces a topologically identical tree that plots fine, but the HPD intervals, clade posteriors, and per-branch rates are gone and unrecoverable without re-running a multi-day MCMC. The loss is invisible until a reviewer asks where the credible intervals went.\n2. **The tool, not the format string, decides whether `[&...]` metadata survives.** In Python the naive default (Bio.Phylo) does not parse BEAST key-values and corrupts them on Newick write; in R the naive default (`ape::read.nexus`) drops them; the tools built to preserve them are DendroPy (`extract_comment_metadata=True`) and treeio (`read.beast`). Route annotated trees through those.\n3. **In plain Newick a bare number has no fixed meaning.** In `(A,B)95:0.3` the `95` could be a bootstrap, a posterior, an internal clade name, or a second branch length. Only the tool that wrote the file knows; a parser that guesses wrong turns supports into names silently. IQ-TREE overloads the slot further, writing `SH-aLRT\u002FUFBoot` (e.g. `87.5\u002F98`), which a single-value parser truncates or chokes on.\n\n## Tool Taxonomy\n\n| Tool (lang) | BEAST `[&...]` | NHX | phyloXML richness | When |\n|-------------|----------------|-----|-------------------|------|\n| treeio (R) | YES, structured (`read.beast`\u002F`read.mrbayes`\u002F`read.iqtree`) | YES | via tidytree\u002Fggtree | the default whenever annotations matter; feeds ggtree |\n| DendroPy (Py) | YES, structured (`.annotations`) | YES | no | Python work needing metadata, posterior sets, tree distances, conversion with annotations |\n| ETE3\u002FETE4 (Py) | partial (custom features) | YES, native | no | reconciliation, NHX round-trips, programmatic node features |\n| Bio.Phylo (Py) | NO key-value parse (opaque `.comment`) | no | YES, richest | general pipelines, conversion among its 5 formats, phyloXML annotation |\n| ape (R) | NO (drops `[&...]`) | no | no | fast topology\u002Fbranch-length analysis; pair with treeio for annotated files |\n\nReferences: Bio.Phylo Talevich 2012; DendroPy Sukumaran 2010; ETE3 Huerta-Cepas 2016; ape Paradis 2019; treeio Wang 2020.\n\nOne-line decision rule: if the file came from BEAST, MrBayes, or RevBayes or carries `[&...]`\u002F`&&NHX` that matters, read it with treeio (R) or DendroPy (Py); otherwise Bio.Phylo (Py) or ape (R) is fine. Never route a BEAST MCC tree through `Bio.Phylo` or `ape::read.nexus` when the HPDs are needed.\n\n## Format Capability (What Each Format Can Hold)\n\n| Capability | Newick | NHX | Nexus (BEAST-annotated) | phyloXML | NeXML |\n|------------|--------|-----|-------------------------|----------|-------|\n| Topology + branch lengths | yes | yes | yes | yes | yes |\n| One support value | ambiguous slot | `B=` tag | comment key | typed `\u003Cconfidence>` | typed meta |\n| Multiple supports per node | no (single slot) | tags | comment keys | yes (n elements) | yes |\n| Posterior \u002F HPD intervals | no | no | yes (`_95%_HPD={}`) | via property | via meta |\n| Per-branch rates \u002F dates | no | tags | yes | yes | yes |\n| Taxonomy (NCBI id\u002Frank) | no | `S=`\u002F`T=` | no | yes, typed | yes |\n| Schema-validated | no | no | loose | yes (XSD) | yes (XSD) |\n\nNewick\u002FNHX are compact and grep-able; phyloXML\u002FNeXML are verbose XML (often 5-20x larger) but typed and validatable -- prefer XML for archiving\u002Fexchange where machine-checkable semantics matter, Newick\u002FNexus for pipeline interchange. BEAST\u002FFigTree metadata rides inside a Nexus (or Newick) `[&...]` comment, so \"it is a Nexus file\" says nothing about whether annotations survive -- only the parser does.\n\n## Reading, Writing, and Converting (Bio.Phylo)\n\n**Goal:** Move trees between formats and inspect them without assuming a single tree or losing annotations.\n\n**Approach:** Use `Phylo.read` for exactly one tree and `Phylo.parse` for many (posterior sets); use `Phylo.convert` only among formats of equal or greater capability; check `.confidence` vs `.name` to confirm support was read into the right slot.\n\n```python\nfrom Bio import Phylo\n\ntree = Phylo.read('tree.nwk', 'newick')          # exactly one tree; raises if 0 or >1\nposterior = list(Phylo.parse('run.trees', 'nexus'))   # many trees: posterior\u002Fbootstrap set\nPhylo.write(tree, 'tree.xml', 'phyloxml')        # phyloXML is Bio.Phylo's richest format\n\nPhylo.convert('tree.nex', 'nexus', 'tree.nwk', 'newick')   # WARNING: [&...] is written as an escaped [\\[&...\\]] comment that DendroPy\u002Ftreeio cannot parse -- annotations are effectively corrupted\n\nfor clade in tree.get_nonterminals():\n    print(clade.confidence, clade.name)          # confirm the support landed in .confidence, not .name\n    if clade.confidence is None and clade.name and '\u002F' in clade.name:   # IQ-TREE -B + --alrt: '98.5\u002F100' stays in .name\n        sh_alrt, ufboot = (float(v) for v in clade.name.split('\u002F')[-2:])   # last field = UFBoot\n```\n\nSupported format strings: `newick`, `nexus`, `phyloxml`, `nexml`, `cdao` (`cdao` raises `KeyError` unless `pip install rdflib`, and does not keep confidences). Colors and branch widths persist only in phyloXML.\n\nEncoding: on Windows, path-based `Phylo.read`\u002F`Phylo.write` (and DendroPy `path=`) use the locale codec (cp1252), garbling non-ASCII tip names. Pass explicit handles for both directions: `with open(p, encoding='utf-8') as fh: Phylo.read(fh, 'newick')`, and the same with `'w'` for writing.\n\n## Preserve BEAST\u002FMrBayes Annotations Before Down-Converting\n\n**Goal:** Keep posteriors, HPD intervals, and rates when a downstream tool wants plain Newick.\n\n**Approach:** Read with an annotation-aware parser, extract the numbers into a side table that travels with the analysis, and only then write a stripped topology -- never down-convert first.\n\n```python\nimport dendropy\n\ntree = dendropy.Tree.get(path='mcc.tree', schema='nexus', extract_comment_metadata=True)\nfor node in tree:\n    if node.annotations.get_value('posterior') is not None:\n        post = float(node.annotations.get_value('posterior'))   # DendroPy returns strings; cast\n        hpd = [float(v) for v in node.annotations.get_value('height_95%_HPD')]   # raw BEAST key; treeio typically exposes it as height_0.95_HPD (exact name varies by source program and version -- introspect the columns)\n        # persist post\u002Fhpd to a side table keyed by the clade before any conversion\ntree.write(path='topology.nwk', schema='newick', suppress_annotations=True, suppress_rooting=True)   # intentional, after extraction; suppress_rooting drops the leading [&R]\n```\n\nIn R the equivalent is treeio `read.beast('mcc.tree')` then `get.data()` \u002F `as_tibble()`, feeding ggtree (tree-visualization); `write.beast()` re-serializes with annotations intact.\n\n## Per-Method Failure Modes\n\n### BEAST\u002FMrBayes MCC to Plain Newick Erases the Credible Intervals\n**Trigger:** `Phylo.convert`, `ape::read.nexus` + `write.tree`, or any \"just give me the topology\" step on an annotated tree.\n**Mechanism:** The HPDs, posteriors, and rates live only in the `[&...]` comments; stripping parsers (`ape::read.nexus`) discard them, and Bio.Phylo writes them as escaped `[\\[&...\\]]` comments that DendroPy and treeio no longer parse.\n**Symptom:** The output plots fine but the credible intervals are gone, irrecoverable without re-running the MCMC.\n**Fix:** Read with treeio `read.beast` or DendroPy `extract_comment_metadata=True`; extract the numbers to a side table; keep the original `.tree` as the source of truth.\n\n### Support Value Read as a Node Name (or Truncated)\n**Trigger:** Parsing a tree whose internal-node slot holds a bootstrap, a posterior, a clade name, or IQ-TREE's `SH-aLRT\u002FUFBoot` dual value.\n**Mechanism:** The Newick grammar gives one slot for all of these; the parser must be told which it is. Bio.Phylo keeps a non-numeric label such as `98.5\u002F100` whole in `.name` and leaves `.confidence` None.\n**Symptom:** Supports appear as `.name` strings, and any code reading `.confidence` silently gets None.\n**Fix:** Know what wrote the file; in Bio.Phylo inspect `.confidence` vs `.name` and split `name.split('\u002F')` (SH-aLRT, UFBoot last) as in the snippet above; in treeio use `read.iqtree`\u002F`read.raxml`, which split dual support correctly.\n\n### Whitespace, Underscore, or Non-ASCII Taxon Names\n**Trigger:** Tip names with spaces, parentheses, commas, or accented characters; reliance on the Newick underscore-space convention.\n**Mechanism:** Naive CLI tools split unquoted spaces, and underscore-to-space auto-conversion silently desyncs tip labels from a metadata join key.\n**Symptom:** Downstream tools error or a metadata merge matches nothing.\n**Fix:** Read and write through UTF-8 handles; sanitize to `[A-Za-z0-9_.]` before ape or ete3 ever see the file (ape reads `'O''Brien isolate 7'` as `NA`; ete3 raises on quoted names), keep a label map, and round-trip-test the labels against the metadata table before any join.\n\n### Nexus TRANSLATE-Table Desync and Rooted\u002FUnrooted Confusion\n**Trigger:** Hand-editing or merging Nexus tree blocks; assuming topology shape implies rootedness.\n**Mechanism:** The integer-to-name TRANSLATE map can decouple from the tree and silently relabel tips; Newick does not flag rootedness (a basal trifurcation conventionally signals unrooted, but tools disagree), while Nexus carries an explicit `[&R]`\u002F`[&U]`.\n**Symptom:** Tips are mislabeled after a merge, or a rooting-sensitive analysis runs on the wrong assumption without erroring.\n**Fix:** Parse with a translate-aware reader (treeio\u002FDendroPy\u002Fape apply it); verify tip-label sets match across merged trees; set rootedness explicitly rather than trusting topology shape.\n\n## Quantitative and Practical Notes\n\n| Item | Guidance | Why |\n|------|----------|-----|\n| Support-value scales | bootstrap\u002FUFBoot in [0,100], posterior in [0,1], SH-aLRT in [0,100] | a number is meaningless without knowing which test produced it; preserve provenance, not just the value |\n| Multi-tree files | use `Phylo.parse` \u002F DendroPy `TreeList` \u002F treeio `read.beast`; check object length | a single-tree reader on a `.trees` posterior returns only the first or errors |\n| Round-trip test | read -> write -> read and diff the annotations, not just the topology | topology almost always survives and gives false confidence |\n| Posterior set vs MCC | `.trees` is the full posterior; `.tree`\u002F`.mcc` is the single annotated summary | `read.beast` on a full posterior is huge; usually the MCC is wanted |\n\n## Common Errors\n\n| Error \u002F symptom | Cause | Solution |\n|-----------------|-------|----------|\n| HPD bars missing after conversion | converted a BEAST tree to Newick | extract annotations with treeio\u002FDendroPy first |\n| `Phylo.read` raises on a `.trees` file | multiple trees in the file | use `Phylo.parse` and iterate |\n| Bootstrap values show up as taxon names | node-label slot read as `.name` | set\u002Finspect confidence parsing; use a software-specific reader |\n| Metadata join matches nothing | underscore\u002Fspace relabeling of tips | sanitize and round-trip-test labels before joining |\n| Parser errors on `[` | strict parser chokes on FigTree comment | strip comments only after extracting needed metadata |\n| `AssertionError: Two string taxonomies?` from `Phylo.read` on a MrBayes `.con.tre` | Bio.Phylo cannot parse MrBayes' annotated consensus layout | read with DendroPy (`extract_comment_metadata=True`) or treeio `read.mrbayes` |\n| NeXML tips named `d7`, `d8`... | Bio.Phylo's NeXML reader names tips by otu id, not label | check tip names; read NeXML from other tools with DendroPy |\n| Non-ASCII tip garbled (`CercopithÃ¨que`) | path-based read\u002Fwrite used the Windows locale codec | open files with `encoding='utf-8'` for read and write |\n\n## References\n\nCock PJA, Antao T, Chang JT, et al. 2009. Biopython: freely available Python tools for computational molecular biology and bioinformatics. *Bioinformatics* 25(11):1422-1423.\nTalevich E, Invergo BM, Cock PJA, Chapman BA. 2012. Bio.Phylo: a unified toolkit for processing, analyzing and visualizing phylogenetic trees in Biopython. *BMC Bioinformatics* 13:209.\nSukumaran J, Holder MT. 2010. DendroPy: a Python library for phylogenetic computing. *Bioinformatics* 26(12):1569-1571.\nHuerta-Cepas J, Serra F, Bork P. 2016. ETE 3: reconstruction, analysis, and visualization of phylogenomic data. *Molecular Biology and Evolution* 33(6):1635-1638.\nParadis E, Schliep K. 2019. ape 5.0: an environment for modern phylogenetics and evolutionary analyses in R. *Bioinformatics* 35(3):526-528.\nWang L-G, Lam TT-Y, Xu S, et al. 2020. Treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. *Molecular Biology and Evolution* 37(2):599-603.\nMaddison DR, Swofford DL, Maddison WP. 1997. NEXUS: an extensible file format for systematic information. *Systematic Biology* 46(4):590-621.\nHan MV, Zmasek CM. 2009. phyloXML: XML for evolutionary biology and comparative genomics. *BMC Bioinformatics* 10:356.\nVos RA, Balhoff JP, Caravas JA, et al. 2012. NeXML: rich, extensible, and verifiable representation of comparative data and metadata. *Systematic Biology* 61(4):675-689.\n\n## Related Skills\n\n- tree-manipulation - rooting, pruning, and collapsing where rooted\u002Funrooted and polytomy choices bite\n- tree-visualization - ggtree and ETE consume the annotations preserved here\n- bayesian-inference - produces the BEAST\u002FMrBayes annotated trees whose metadata must survive\n- divergence-dating - produces MCC trees with HPD intervals on node ages\n- sequence-io\u002Fread-sequences - taxon-name sanitization shares the whitespace and non-ASCII traps\n","## Version Compatibility\n\nReference examples tested with: BioPython 1.83+. Annotation-preserving alternatives: DendroPy 5+ (Python), treeio 1.26+ \u002F ape 5.8+ (R).\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show biopython` then `help(module.function)` to check signatures\n- R: `packageVersion('treeio')` then `?read.beast` to verify parameters\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed\npackage and adapt the example to match the actual API rather than retrying.\n\nBio.Phylo stores a Newick `[&...]` bracket as opaque `.comment` text and does NOT parse BEAST key-values; DendroPy `extract_comment_metadata=True` and treeio `read.beast` do.\n\n# Tree I\u002FO -- A Tree File Is a Lossy Serialization\n\n**\"Read and convert my tree files\"** -> Parse a tree into an in-memory object and re-serialize it, knowing which annotations each format and parser preserves.\n- Python: `Phylo.read('tree.nwk', 'newick')`, `Phylo.convert(...)` (Bio.Phylo)\n- Annotation-critical: `dendropy.Tree.get(..., extract_comment_metadata=True)` or treeio `read.beast()`\n\nScope: reading, writing, converting, and inspecting tree files, and selecting a parser that keeps the annotations the analysis needs. Rooting, pruning, collapsing -> tree-manipulation. Plotting and mapping annotations onto branches -> tree-visualization. Producing BEAST\u002FMrBayes annotated trees -> bayesian-inference, divergence-dating. Taxon-name sanitization shares the whitespace traps in sequence-io\u002Fread-sequences.\n\n## The Single Most Important Modern Insight\n\nA tree file is a lossy serialization of a richer in-memory object. The biologist cares about the topology plus its annotations -- branch supports, posterior probabilities, 95% HPD intervals on node heights, per-branch rates, divergence dates, taxon metadata -- and formats differ enormously in which of these they can hold, while parsers differ in which they actually read back. Three load-bearing facts:\n\n1. **Conversion is a silent data-destroying operation.** Reading a BEAST MCC tree and writing plain Newick produces a topologically identical tree that plots fine, but the HPD intervals, clade posteriors, and per-branch rates are gone and unrecoverable without re-running a multi-day MCMC. The loss is invisible until a reviewer asks where the credible intervals went.\n2. **The tool, not the format string, decides whether `[&...]` metadata survives.** In Python the naive default (Bio.Phylo) does not parse BEAST key-values and corrupts them on Newick write; in R the naive default (`ape::read.nexus`) drops them; the tools built to preserve them are DendroPy (`extract_comment_metadata=True`) and treeio (`read.beast`). Route annotated trees through those.\n3. **In plain Newick a bare number has no fixed meaning.** In `(A,B)95:0.3` the `95` could be a bootstrap, a posterior, an internal clade name, or a second branch length. Only the tool that wrote the file knows; a parser that guesses wrong turns supports into names silently. IQ-TREE overloads the slot further, writing `SH-aLRT\u002FUFBoot` (e.g. `87.5\u002F98`), which a single-value parser truncates or chokes on.\n\n## Tool Taxonomy\n\n| Tool (lang) | BEAST `[&...]` | NHX | phyloXML richness | When |\n|-------------|----------------|-----|-------------------|------|\n| treeio (R) | YES, structured (`read.beast`\u002F`read.mrbayes`\u002F`read.iqtree`) | YES | via tidytree\u002Fggtree | the default whenever annotations matter; feeds ggtree |\n| DendroPy (Py) | YES, structured (`.annotations`) | YES | no | Python work needing metadata, posterior sets, tree distances, conversion with annotations |\n| ETE3\u002FETE4 (Py) | partial (custom features) | YES, native | no | reconciliation, NHX round-trips, programmatic node features |\n| Bio.Phylo (Py) | NO key-value parse (opaque `.comment`) | no | YES, richest | general pipelines, conversion among its 5 formats, phyloXML annotation |\n| ape (R) | NO (drops `[&...]`) | no | no | fast topology\u002Fbranch-length analysis; pair with treeio for annotated files |\n\nReferences: Bio.Phylo Talevich 2012; DendroPy Sukumaran 2010; ETE3 Huerta-Cepas 2016; ape Paradis 2019; treeio Wang 2020.\n\nOne-line decision rule: if the file came from BEAST, MrBayes, or RevBayes or carries `[&...]`\u002F`&&NHX` that matters, read it with treeio (R) or DendroPy (Py); otherwise Bio.Phylo (Py) or ape (R) is fine. Never route a BEAST MCC tree through `Bio.Phylo` or `ape::read.nexus` when the HPDs are needed.\n\n## Format Capability (What Each Format Can Hold)\n\n| Capability | Newick | NHX | Nexus (BEAST-annotated) | phyloXML | NeXML |\n|------------|--------|-----|-------------------------|----------|-------|\n| Topology + branch lengths | yes | yes | yes | yes | yes |\n| One support value | ambiguous slot | `B=` tag | comment key | typed `\u003Cconfidence>` | typed meta |\n| Multiple supports per node | no (single slot) | tags | comment keys | yes (n elements) | yes |\n| Posterior \u002F HPD intervals | no | no | yes (`_95%_HPD={}`) | via property | via meta |\n| Per-branch rates \u002F dates | no | tags | yes | yes | yes |\n| Taxonomy (NCBI id\u002Frank) | no | `S=`\u002F`T=` | no | yes, typed | yes |\n| Schema-validated | no | no | loose | yes (XSD) | yes (XSD) |\n\nNewick\u002FNHX are compact and grep-able; phyloXML\u002FNeXML are verbose XML (often 5-20x larger) but typed and validatable -- prefer XML for archiving\u002Fexchange where machine-checkable semantics matter, Newick\u002FNexus for pipeline interchange. BEAST\u002FFigTree metadata rides inside a Nexus (or Newick) `[&...]` comment, so \"it is a Nexus file\" says nothing about whether annotations survive -- only the parser does.\n\n## Reading, Writing, and Converting (Bio.Phylo)\n\n**Goal:** Move trees between formats and inspect them without assuming a single tree or losing annotations.\n\n**Approach:** Use `Phylo.read` for exactly one tree and `Phylo.parse` for many (posterior sets); use `Phylo.convert` only among formats of equal or greater capability; check `.confidence` vs `.name` to confirm support was read into the right slot.\n\n```python\nfrom Bio import Phylo\n\ntree = Phylo.read('tree.nwk', 'newick')          # exactly one tree; raises if 0 or >1\nposterior = list(Phylo.parse('run.trees', 'nexus'))   # many trees: posterior\u002Fbootstrap set\nPhylo.write(tree, 'tree.xml', 'phyloxml')        # phyloXML is Bio.Phylo's richest format\n\nPhylo.convert('tree.nex', 'nexus', 'tree.nwk', 'newick')   # WARNING: [&...] is written as an escaped [\\[&...\\]] comment that DendroPy\u002Ftreeio cannot parse -- annotations are effectively corrupted\n\nfor clade in tree.get_nonterminals():\n    print(clade.confidence, clade.name)          # confirm the support landed in .confidence, not .name\n    if clade.confidence is None and clade.name and '\u002F' in clade.name:   # IQ-TREE -B + --alrt: '98.5\u002F100' stays in .name\n        sh_alrt, ufboot = (float(v) for v in clade.name.split('\u002F')[-2:])   # last field = UFBoot\n```\n\nSupported format strings: `newick`, `nexus`, `phyloxml`, `nexml`, `cdao` (`cdao` raises `KeyError` unless `pip install rdflib`, and does not keep confidences). Colors and branch widths persist only in phyloXML.\n\nEncoding: on Windows, path-based `Phylo.read`\u002F`Phylo.write` (and DendroPy `path=`) use the locale codec (cp1252), garbling non-ASCII tip names. Pass explicit handles for both directions: `with open(p, encoding='utf-8') as fh: Phylo.read(fh, 'newick')`, and the same with `'w'` for writing.\n\n## Preserve BEAST\u002FMrBayes Annotations Before Down-Converting\n\n**Goal:** Keep posteriors, HPD intervals, and rates when a downstream tool wants plain Newick.\n\n**Approach:** Read with an annotation-aware parser, extract the numbers into a side table that travels with the analysis, and only then write a stripped topology -- never down-convert first.\n\n```python\nimport dendropy\n\ntree = dendropy.Tree.get(path='mcc.tree', schema='nexus', extract_comment_metadata=True)\nfor node in tree:\n    if node.annotations.get_value('posterior') is not None:\n        post = float(node.annotations.get_value('posterior'))   # DendroPy returns strings; cast\n        hpd = [float(v) for v in node.annotations.get_value('height_95%_HPD')]   # raw BEAST key; treeio typically exposes it as height_0.95_HPD (exact name varies by source program and version -- introspect the columns)\n        # persist post\u002Fhpd to a side table keyed by the clade before any conversion\ntree.write(path='topology.nwk', schema='newick', suppress_annotations=True, suppress_rooting=True)   # intentional, after extraction; suppress_rooting drops the leading [&R]\n```\n\nIn R the equivalent is treeio `read.beast('mcc.tree')` then `get.data()` \u002F `as_tibble()`, feeding ggtree (tree-visualization); `write.beast()` re-serializes with annotations intact.\n\n## Per-Method Failure Modes\n\n### BEAST\u002FMrBayes MCC to Plain Newick Erases the Credible Intervals\n**Trigger:** `Phylo.convert`, `ape::read.nexus` + `write.tree`, or any \"just give me the topology\" step on an annotated tree.\n**Mechanism:** The HPDs, posteriors, and rates live only in the `[&...]` comments; stripping parsers (`ape::read.nexus`) discard them, and Bio.Phylo writes them as escaped `[\\[&...\\]]` comments that DendroPy and treeio no longer parse.\n**Symptom:** The output plots fine but the credible intervals are gone, irrecoverable without re-running the MCMC.\n**Fix:** Read with treeio `read.beast` or DendroPy `extract_comment_metadata=True`; extract the numbers to a side table; keep the original `.tree` as the source of truth.\n\n### Support Value Read as a Node Name (or Truncated)\n**Trigger:** Parsing a tree whose internal-node slot holds a bootstrap, a posterior, a clade name, or IQ-TREE's `SH-aLRT\u002FUFBoot` dual value.\n**Mechanism:** The Newick grammar gives one slot for all of these; the parser must be told which it is. Bio.Phylo keeps a non-numeric label such as `98.5\u002F100` whole in `.name` and leaves `.confidence` None.\n**Symptom:** Supports appear as `.name` strings, and any code reading `.confidence` silently gets None.\n**Fix:** Know what wrote the file; in Bio.Phylo inspect `.confidence` vs `.name` and split `name.split('\u002F')` (SH-aLRT, UFBoot last) as in the snippet above; in treeio use `read.iqtree`\u002F`read.raxml`, which split dual support correctly.\n\n### Whitespace, Underscore, or Non-ASCII Taxon Names\n**Trigger:** Tip names with spaces, parentheses, commas, or accented characters; reliance on the Newick underscore-space convention.\n**Mechanism:** Naive CLI tools split unquoted spaces, and underscore-to-space auto-conversion silently desyncs tip labels from a metadata join key.\n**Symptom:** Downstream tools error or a metadata merge matches nothing.\n**Fix:** Read and write through UTF-8 handles; sanitize to `[A-Za-z0-9_.]` before ape or ete3 ever see the file (ape reads `'O''Brien isolate 7'` as `NA`; ete3 raises on quoted names), keep a label map, and round-trip-test the labels against the metadata table before any join.\n\n### Nexus TRANSLATE-Table Desync and Rooted\u002FUnrooted Confusion\n**Trigger:** Hand-editing or merging Nexus tree blocks; assuming topology shape implies rootedness.\n**Mechanism:** The integer-to-name TRANSLATE map can decouple from the tree and silently relabel tips; Newick does not flag rootedness (a basal trifurcation conventionally signals unrooted, but tools disagree), while Nexus carries an explicit `[&R]`\u002F`[&U]`.\n**Symptom:** Tips are mislabeled after a merge, or a rooting-sensitive analysis runs on the wrong assumption without erroring.\n**Fix:** Parse with a translate-aware reader (treeio\u002FDendroPy\u002Fape apply it); verify tip-label sets match across merged trees; set rootedness explicitly rather than trusting topology shape.\n\n## Quantitative and Practical Notes\n\n| Item | Guidance | Why |\n|------|----------|-----|\n| Support-value scales | bootstrap\u002FUFBoot in [0,100], posterior in [0,1], SH-aLRT in [0,100] | a number is meaningless without knowing which test produced it; preserve provenance, not just the value |\n| Multi-tree files | use `Phylo.parse` \u002F DendroPy `TreeList` \u002F treeio `read.beast`; check object length | a single-tree reader on a `.trees` posterior returns only the first or errors |\n| Round-trip test | read -> write -> read and diff the annotations, not just the topology | topology almost always survives and gives false confidence |\n| Posterior set vs MCC | `.trees` is the full posterior; `.tree`\u002F`.mcc` is the single annotated summary | `read.beast` on a full posterior is huge; usually the MCC is wanted |\n\n## Common Errors\n\n| Error \u002F symptom | Cause | Solution |\n|-----------------|-------|----------|\n| HPD bars missing after conversion | converted a BEAST tree to Newick | extract annotations with treeio\u002FDendroPy first |\n| `Phylo.read` raises on a `.trees` file | multiple trees in the file | use `Phylo.parse` and iterate |\n| Bootstrap values show up as taxon names | node-label slot read as `.name` | set\u002Finspect confidence parsing; use a software-specific reader |\n| Metadata join matches nothing | underscore\u002Fspace relabeling of tips | sanitize and round-trip-test labels before joining |\n| Parser errors on `[` | strict parser chokes on FigTree comment | strip comments only after extracting needed metadata |\n| `AssertionError: Two string taxonomies?` from `Phylo.read` on a MrBayes `.con.tre` | Bio.Phylo cannot parse MrBayes' annotated consensus layout | read with DendroPy (`extract_comment_metadata=True`) or treeio `read.mrbayes` |\n| NeXML tips named `d7`, `d8`... | Bio.Phylo's NeXML reader names tips by otu id, not label | check tip names; read NeXML from other tools with DendroPy |\n| Non-ASCII tip garbled (`CercopithÃ¨que`) | path-based read\u002Fwrite used the Windows locale codec | open files with `encoding='utf-8'` for read and write |\n\n## References\n\nCock PJA, Antao T, Chang JT, et al. 2009. Biopython: freely available Python tools for computational molecular biology and bioinformatics. *Bioinformatics* 25(11):1422-1423.\nTalevich E, Invergo BM, Cock PJA, Chapman BA. 2012. Bio.Phylo: a unified toolkit for processing, analyzing and visualizing phylogenetic trees in Biopython. *BMC Bioinformatics* 13:209.\nSukumaran J, Holder MT. 2010. DendroPy: a Python library for phylogenetic computing. *Bioinformatics* 26(12):1569-1571.\nHuerta-Cepas J, Serra F, Bork P. 2016. ETE 3: reconstruction, analysis, and visualization of phylogenomic data. *Molecular Biology and Evolution* 33(6):1635-1638.\nParadis E, Schliep K. 2019. ape 5.0: an environment for modern phylogenetics and evolutionary analyses in R. *Bioinformatics* 35(3):526-528.\nWang L-G, Lam TT-Y, Xu S, et al. 2020. Treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. *Molecular Biology and Evolution* 37(2):599-603.\nMaddison DR, Swofford DL, Maddison WP. 1997. NEXUS: an extensible file format for systematic information. *Systematic Biology* 46(4):590-621.\nHan MV, Zmasek CM. 2009. phyloXML: XML for evolutionary biology and comparative genomics. *BMC Bioinformatics* 10:356.\nVos RA, Balhoff JP, Caravas JA, et al. 2012. NeXML: rich, extensible, and verifiable representation of comparative data and metadata. *Systematic Biology* 61(4):675-689.\n\n## Related Skills\n\n- tree-manipulation - rooting, pruning, and collapsing where rooted\u002Funrooted and polytomy choices bite\n- tree-visualization - ggtree and ETE consume the annotations preserved here\n- bayesian-inference - produces the BEAST\u002FMrBayes annotated trees whose metadata must survive\n- divergence-dating - produces MCC trees with HPD intervals on node ages\n- sequence-io\u002Fread-sequences - taxon-name sanitization shares the whitespace and non-ASCII traps\n",{"name":5,"tool_type":24,"description":7,"primary_tool":25},"python","Bio.Phylo","main","e0956dc9606356ab78468936b502e55a365282e2","specialists\u002Fmolecular-phylogenetics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-phylo-tree-io",0,"https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists","https:\u002F\u002Fgithub.com\u002Fmrsonord2240","2026-10-12 03:19:04",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add mrsonord2240\u002Fopenscience-specialists --skill bio-phylo-tree-io",{"tool":39,"command":40},"bunx","bunx skills add mrsonord2240\u002Fopenscience-specialists --skill bio-phylo-tree-io",{"tool":42,"command":43},"pnpm","pnpm dlx skills add mrsonord2240\u002Fopenscience-specialists --skill bio-phylo-tree-io","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fmolecular-phylogenetics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-phylo-tree-io\u002FSKILL.md",true,[47,53,57,61],{"path":48,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":51,"sourceHtmlUrl":52},"examples\u002Fconvert_formats.py","SCRIPT","脚本",1430,"https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fmolecular-phylogenetics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-phylo-tree-io\u002Fexamples\u002Fconvert_formats.py",{"path":54,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":55,"sourceHtmlUrl":56},"examples\u002Fparse_multiple_trees.py",457,"https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fmolecular-phylogenetics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-phylo-tree-io\u002Fexamples\u002Fparse_multiple_trees.py",{"path":58,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":59,"sourceHtmlUrl":60},"examples\u002Fread_newick.py",518,"https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fmolecular-phylogenetics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-phylo-tree-io\u002Fexamples\u002Fread_newick.py",{"path":62,"resourceType":63,"resourceTypeDesc":64,"sizeBytes":65,"sourceHtmlUrl":66},"usage-guide.md","REFERENCE","参考文档",4299,"https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fmolecular-phylogenetics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-phylo-tree-io\u002Fusage-guide.md",[68,75,82,89,96,103],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M7CW36A6QAGWFE2C008M1XPG","bio-workflows-metabolomics-pipeline","Orchestrates the untargeted LC-MS metabolomics pipeline end-to-end (xcms 4.x feature extraction, QC\u002Fdrift\u002Fnormalization, confidence-stratified annotation, permutation-validated statistics, background-aware pathway mapping), naming what each stage decides and where it silently fails. Use when running a full LC-MS metabolomics study from raw mzML to enriched pathways and needing the honest handoffs between stages. Each stage defers to its component skill for parameters and traps; for stable-isotope flux (a separate branch, not this untargeted flow) see metabolomics\u002Fisotope-tracing.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-workflows-metabolomics-pipeline\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7CW2Y18623NA2S1Y30FRQW1","bio-metabolomics-xcms-preprocessing","Programmatic untargeted LC-MS feature extraction in R with the modern xcms 4.x MsExperiment\u002FXcmsExperiment API, taking raw mzML to a feature table via CentWave peak detection, retention-time alignment, peak-density correspondence, gap-filling, CAMERA redundancy collapse, and built-in QC feature filtering. Use when converting centroided LC-MS runs into a features-by-samples matrix and deciding centWave\u002Fgrouping\u002Falignment parameters. For drift correction and QC\u002FCV filtering execution see metabolomics\u002Fnormalization-qc; for metabolite identification see metabolomics\u002Fmetabolite-annotation; for the MS-DIAL GUI alternative with MS2Dec deconvolution see metabolomics\u002Fmsdial-preprocessing; for downstream statistics see metabolomics\u002Fstatistical-analysis.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-xcms-preprocessing\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7CW2M364HVWPNQEKE2WP4PP","bio-metabolomics-statistical-analysis","Decision-grade statistical analysis for metabolomics intensity tables. Covers transformation and scaling (Pareto vs unit-variance as a hidden hypothesis), unsupervised structure (PCA\u002FHCA for QC), permutation-validated PLS-DA\u002FOPLS-DA (R2 vs Q2, double CV, VIP as heuristic), univariate testing (Welch\u002FMann-Whitney\u002FANOVA\u002FLMM with covariate adjustment), and dependence-aware multiple testing. Use when testing which metabolites differ, building or validating a discriminant model, choosing a scaling, or correcting many correlated tests. For sample-wise normalization\u002Fdrift correction see metabolomics\u002Fnormalization-qc; for ML classifiers and selection-inside-CV leakage see machine-learning\u002Fbiomarker-discovery and machine-learning\u002Fmodel-validation; for pathway interpretation see metabolomics\u002Fpathway-mapping; for design\u002Fpower\u002Fmultiplicity regime see experimental-design\u002Fmultiple-testing.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-statistical-analysis\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":19},"01M7CW2BCBF851WYE03Z8XPEDQ","bio-metabolomics-pathway-mapping","Maps metabolomics results to biological pathways via over-representation (ORA), metabolite-set enrichment (MSEA\u002FQEA), mummichog\u002FPSEA on raw m\u002Fz peaks, and network-diffusion enrichment (FELLA), with correct background-set construction and honest interpretive ceilings. Use when interpreting differential metabolites or an untargeted LC-MS feature table in pathway context, choosing ORA vs MSEA vs mummichog vs topology, or setting the reference\u002Fbackground set. For annotation confidence levels feeding ORA see metabolomics\u002Fmetabolite-annotation; for gene-set concepts see pathway-analysis\u002Fgo-enrichment and pathway-analysis\u002Fgsea; for joint gene+metabolite pathways see multi-omics-integration\u002Fmofa-integration.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-pathway-mapping\u002FSKILL.md",[],[],{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":19},"01M7CW21NSZMCPMF7D9CHJM718","bio-metabolomics-normalization-qc","Designs QC, corrects signal drift, removes batch effects, filters features, normalizes samples, and imputes missing values for untargeted LC-MS\u002FGC-MS metabolomics, framing each step as a measurement model that can create or erase biological signal. Use when processing a peak\u002Ffeature table before statistical analysis, choosing a drift-correction or sample-normalization method, deciding QC RSD vs D-ratio filtering, or handling left-censored missing values. The feature table is produced by metabolomics\u002Fxcms-preprocessing or metabolomics\u002Fmsdial-preprocessing; transformation\u002Fscaling for modeling defers to metabolomics\u002Fstatistical-analysis; cross-study design issues link to experimental-design\u002Fbatch-design.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-normalization-qc\u002FSKILL.md",[],[],{"skillNo":104,"name":105,"nameZh":6,"description":106,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":19},"01M7CW1SWVM0NYHVE6Q7MA3G7R","bio-metabolomics-msdial-preprocessing","Runs the MS-DIAL preprocessing workflow (peak picking, MS2Dec spectral deconvolution, alignment, gap-filling) and imports the alignment-result table into R or Python with honest filtering. Use when preprocessing LC-MS DDA\u002FDIA (SWATH) or GC-MS raw data with MS-DIAL, deciding MS-DIAL vs XCMS, configuring the MSDIALCUI console run, or parsing an MS-DIAL export into a clean feature matrix. For programmatic R peak detection and the feature-table-as-artifact framing see metabolomics\u002Fxcms-preprocessing; for lipid annotation mode see metabolomics\u002Flipidomics; for MSI-level confidence honesty see metabolomics\u002Fmetabolite-annotation; for drift correction and QC see metabolomics\u002Fnormalization-qc.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-msdial-preprocessing\u002FSKILL.md",[],[]]