Commit 7f53552
add color_tree_by parameter for Auspice-style tree coloring (#2)
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>1 parent ef5b46c commit 7f53552
8 files changed
Lines changed: 1560 additions & 42 deletions
File tree
- docs
- scripts
- src/tree_annotated_plot
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
19 | 33 | | |
20 | 34 | | |
21 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| |||
131 | 136 | | |
132 | 137 | | |
133 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
134 | 173 | | |
135 | 174 | | |
136 | 175 | | |
| |||
145 | 184 | | |
146 | 185 | | |
147 | 186 | | |
| 187 | + | |
148 | 188 | | |
149 | 189 | | |
150 | 190 | | |
| |||
162 | 202 | | |
163 | 203 | | |
164 | 204 | | |
| 205 | + | |
165 | 206 | | |
166 | 207 | | |
167 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 113 | + | |
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
121 | 119 | | |
122 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
123 | 131 | | |
124 | 132 | | |
125 | 133 | | |
| |||
146 | 154 | | |
147 | 155 | | |
148 | 156 | | |
| 157 | + | |
149 | 158 | | |
150 | 159 | | |
151 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
152 | 186 | | |
153 | 187 | | |
154 | 188 | | |
| |||
0 commit comments