add color_tree_by parameter for Auspice-style tree coloring#2
Merged
Conversation
Introduces a color_tree_by parameter that colors the tree's branches and tip circles by: - A node_attrs key like "subclade" — colored by node_attrs[<key>].value on each node. - "genotype:<GENE>:<SITE>" — colored by the inferred amino-acid (or nucleotide) state at the site, computed from branch_attrs.mutations walked from the root. - "genotype:<GENE>:<SITE1>,<SITE2>,..." — same but for a haplotype across sites; sites that don't vary in the tree drop out of the label; if every requested site is invariant, every node gets a single "<no variation>" category. Color and ordering are chosen to match Nextstrain views for the same tree: when the Auspice JSON defines meta.colorings[<key>].scale that palette is used; otherwise the same per-N palette Auspice's frontend uses (reproduced in _color.py with attribution to AGPL-licensed Auspice) fills in. Categories are sorted by descending frequency (ties broken alphabetically), matching Auspice's sortedDomain. The "unknown" category renders in gray and is hidden from the legend when only internal nodes lack the attribute. Other changes bundled in: - TreeNode now carries node_attrs and branch_attrs for downstream consumers; load_auspice_with_meta sibling helper exposes the JSON's top-level meta dict alongside the parsed root. - Default tree_line_width bumped from 1.5 to 2 and tree_node_size from 28 to 45 with explicit opacity=1, since the prior defaults were tuned for unicolor black trees and read poorly when colored. - New "Color the tree" subsection in docs/examples.md with a second H3N2 example colored by genotype HA1:158. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a color_tree_by parameter that colors the tree's branches and tip circles by:
Color and ordering are chosen to match Nextstrain views for the same tree: when the Auspice JSON defines meta.colorings[].scale that palette is used; otherwise the same per-N palette Auspice's frontend uses (reproduced in _color.py with attribution to AGPL-licensed Auspice) fills in. Categories are sorted by descending frequency (ties broken alphabetically), matching Auspice's sortedDomain. The "unknown" category renders in gray and is hidden from the legend when only internal nodes lack the attribute.
Other changes bundled in: