archaeopteryx 3.22.0 → 3.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,7 +24,7 @@ nothing is uploaded. Its **Expert options** panel exercises every launch
24
24
  config key live and shows the exact config JSON to copy into your own
25
25
  `launch()` call.
26
26
 
27
- * [Auspice / Nextstrain JSON](https://cmzmasek.github.io/archaeopteryx-js/demo.html?tree=auspice)
27
+ * [Auspice / Nextstrain JSON (Time | Div, Clock plot)](https://cmzmasek.github.io/archaeopteryx-js/demo.html?tree=auspice)
28
28
  * [Swine H1 HA1 + alignment (Nexus)](https://cmzmasek.github.io/archaeopteryx-js/demo.html?tree=swh1)
29
29
  * [BEAST annotations (Nexus)](https://cmzmasek.github.io/archaeopteryx-js/demo.html?tree=beast)
30
30
  * [Flavivirus mature peptides (10 trees)](https://cmzmasek.github.io/archaeopteryx-js/demo.html?tree=flavivirus)
@@ -886,6 +886,59 @@ branches show divergence, and the Scale Axis measures distance instead. Each lay
886
886
  Div is on screen says so and opens again showing divergence. All of this is
887
887
  shared with the desktop.
888
888
 
889
+ ### Clock plot
890
+
891
+ Beside the switch, a **Clock plot** button opens a panel that plots each
892
+ tip's **date** against its **divergence** from the root, with a straight
893
+ line through the tips — the root-to-tip plot of TempEst and TreeTime, and
894
+ Auspice's clock view. Under the plot:
895
+
896
+ - **Rate** — the slope of the line: substitutions per site per year (per
897
+ unit of the tree's dates where they are not calendar years). Negative
898
+ where the tips' divergence falls with time.
899
+ - **Root date, by the line** — the date at which the line comes down to the
900
+ root's divergence — over **Root date, in the tree**, the one the tree
901
+ states. How far apart they are is the point of showing both.
902
+ - **R²** and the number of **Tips** in the fit.
903
+
904
+ The line is ordinary least squares over the **tips only**: a tip's date is
905
+ an observation, an ancestor's was inferred (usually with a clock), and
906
+ counting it would have the estimate confirm itself. It is not forced through
907
+ the root. Tips share ancestry, so R² describes the fit and is no
908
+ significance test. On a BEAST clock-model tree the divergence *is* each
909
+ branch's time × its clock rate, so there the plot shows the model's rates,
910
+ not a measurement of its own (a strict clock is a perfect line), and the
911
+ panel says so.
912
+
913
+ The panel is **linked to the tree** and stays open while you work in it
914
+ (drag it by its title):
915
+
916
+ - a point wears its node's colour in the tree — the Color visualization,
917
+ search hits, the selection;
918
+ - pointing at a point lights its node in the tree (the collapsed clade
919
+ holding it, if it is hidden in one), and pointing at a node in the tree
920
+ rings its point;
921
+ - **clicking** a point selects or deselects its node, and **dragging** a box
922
+ selects the tips in it — the tree's own selection, so an outlier found on
923
+ the plot is found in the tree. **Deselect all** clears it;
924
+ - tips with one date and one divergence — identical sequences sampled on one
925
+ day — are drawn on one spot, and that dot answers for all of them: the
926
+ readout says how many tips are there and names the first five, all of them
927
+ light up in the tree, and a click selects them all (or deselects them all,
928
+ where all were selected);
929
+ - in a subtree view the plot is the clade's, with the clade's own line.
930
+
931
+ **Regression line** shows and hides the line. **Internal nodes** adds the
932
+ ancestors' points, each at its own date and divergence; the panel opens
933
+ without them, since the line is the tips' and a deep root would crowd them
934
+ into a corner.
935
+
936
+ The button is offered on a tree that has **Time | Div** and whose line can
937
+ be drawn: three tips or more, not all on one date. A tree sampled at one
938
+ moment has no slope to estimate. (A tree whose branch lengths are divergence
939
+ and whose tips alone are dated — the tree a root-to-tip plot is run on
940
+ *before* dating — has no plot yet.)
941
+
889
942
  # forester.js
890
943
  forester.js is a general suite for dealing with phylogenetic trees.
891
944
 
@@ -1096,7 +1149,10 @@ pick them up. Both metrics are retained, and
1096
1149
  `forester.applyTimeBranchLengths(phy)` /
1097
1150
  `forester.applyDivergenceBranchLengths(phy)` /
1098
1151
  `forester.hasTimeAndDivergence(phy)` are the plumbing behind the
1099
- **Time | Div** switch. The two `apply` functions answer `true` when they
1152
+ **Time | Div** switch (and `forester.clockPlotKind(phy)` /
1153
+ `forester.clockPlotData(phy, view)` / `forester.clockRegression(xs, ys)`
1154
+ behind the **Clock plot**: which trees have one, its points and its
1155
+ least-squares line). The two `apply` functions answer `true` when they
1100
1156
  laid the tree out, and `false` — leaving every branch length as it was —
1101
1157
  when their layout cannot state every branch.
1102
1158
 
@@ -2540,6 +2596,46 @@ figure never carries an artefact of where the view happened to be scrolled.
2540
2596
  (The desktop pins its axes to the viewport bottom always; sticky is a
2541
2597
  deliberate difference.)
2542
2598
 
2599
+ ### The clock plot
2600
+
2601
+ **Model** (`forester.js`, pure). `forester.clockPlotKind(phy)` answers
2602
+ `'divergence'` or `null`: the tree has Time and Div
2603
+ (`forester.hasTimeAndDivergence`) and three tips or more, not all on one
2604
+ date. It is asked of the **tree**, never of the view. A second kind,
2605
+ `'root-to-tip'` — divergence branch lengths, dated tips, no dated ancestors —
2606
+ is described beside the function and not built. `forester.clockPlotData(phy,
2607
+ view)` returns `{kind, forward, unit, fromRates, points, root, fit}`: a point
2608
+ `{node, date, div, tip}` per node of the view (a tip also carries its
2609
+ `residual`), `forward` false where the dates are ages, `fromRates` true where
2610
+ the divergence is time × clock rate, and `fit` =
2611
+ `forester.clockRegression(dates, divergences)` over the tips — ordinary least
2612
+ squares about the means, `{n, slope, intercept, r2}` — plus `rate` (the slope
2613
+ in the direction time runs) and `rootDate` (where the line reaches the view
2614
+ root's divergence; `null` unless the rate is positive). `fit` is `null` for a
2615
+ view with fewer than three tips or one date. `forester.calendarTickMonths`
2616
+ gives month ticks for a span too short for whole years.
2617
+
2618
+ **Panel** (`archaeopteryx.js`, the "Clock plot" section). A modeless
2619
+ `makeDialogShell` dialog, dragged by its title, placed in the tree area's top
2620
+ right corner and below anything the host page keeps there. The drawing is one
2621
+ SVG in the panel's own `--p-*` inks. `renderClockPlot` runs at the end of
2622
+ every `update()`: it works the points out and lays them down again only when
2623
+ the top of the view or its node count changed, or a checkbox did; otherwise
2624
+ it only goes over the points' colours. A point's colour is its node's in the
2625
+ tree (found, selected, the Color visualization, the file's styles).
2626
+
2627
+ **The link.** Pointer events on the SVG: the nearest point within 7 px, and
2628
+ with it every point of its kind within 1 px of it — one dot for tips that
2629
+ share a date and a divergence. The dot's nodes are lit through
2630
+ `showHoverGlow(node, also)` (each as the tree shows it: a tip hidden in a
2631
+ collapsed clade lights the clade); a click toggles them in `_selectedNodes`,
2632
+ a dragged box adds the tips inside it; `mouseover` on a tree node rings its
2633
+ point. Closing is synchronous: nothing waits for the dialog's `close` event.
2634
+
2635
+ There is no config key and no view key for the panel yet, and it is not part
2636
+ of any download. The numbers are pinned in `test/clock_test.js` (computed by
2637
+ hand), the panel in `test/browser/clock_plot.html`.
2638
+
2543
2639
  ## Node selection
2544
2640
 
2545
2641
  With `enableManualNodeSelection` on, the node menu gains **Select/Deselect Node**
@@ -2553,7 +2649,12 @@ var selected = archaeopteryx.getSelectedNodes(); // array of node objects
2553
2649
  Selected nodes are drawn in the selection colour, which is fixed so that it
2554
2650
  stays distinguishable from the two search colours.
2555
2651
 
2556
- There is no push mechanism (no button or event that announces "the user is done
2557
- selecting") — the embedding application reads the selection whenever it wants,
2558
- typically from its own button. (Versions before 3.0 carried a dormant,
2559
- never-rendered "Submit Selected" button in the source; it was removed.)
2652
+ The **Clock plot** selects too, whatever this setting says: a click on a
2653
+ point, or a box dragged over tips, changes the same selection.
2654
+
2655
+ Every change of the selection — from the node menu or from the clock plot —
2656
+ dispatches a `selected_nodes_changed_event` on `document`, so the embedding
2657
+ application can read the selection then, or whenever it wants from its own
2658
+ button. Nothing announces "the user is done selecting". (Versions before 3.0
2659
+ carried a dormant, never-rendered "Submit Selected" button in the source; it
2660
+ was removed.)