Skip to content

add color_tree_by parameter for Auspice-style tree coloring#2

Merged
jbloom merged 1 commit intomainfrom
color-tree-by
May 5, 2026
Merged

add color_tree_by parameter for Auspice-style tree coloring#2
jbloom merged 1 commit intomainfrom
color-tree-by

Conversation

@jbloom
Copy link
Copy Markdown
Member

@jbloom jbloom commented May 5, 2026

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[].value on each node.
  • "genotype::" — colored by the inferred amino-acid (or nucleotide) state at the site, computed from branch_attrs.mutations walked from the root.
  • "genotype::,,..." — 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 "" category.

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:

  • 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.

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>
@jbloom jbloom merged commit 7f53552 into main May 5, 2026
3 checks passed
@jbloom jbloom deleted the color-tree-by branch May 5, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant