Notebook Views¶
SurveyView shows one gene of a survey in a notebook: the chart with its
elites, the trace of a niche, and the tree of a niche. It works in Jupyter,
JupyterLab, VS Code and marimo. These are the same views as on the page
Try It in Your Browser.
A live run¶
Show the view in one cell. In the next cell, give it as the monitor of a run. The chart fills while the second cell runs.
from hifuku.widgets import SurveyView
view = SurveyView(run, gene="geneB", chart=0) # run is a SurveyRun
view
The view shows only the tasks of its gene and chart, so one monitor can watch a loop over all the tasks of a run. A new task of the gene starts the view again.
A stored survey¶
When the survey holds more than one chain of records for the gene, for
example replicate runs, name one with run=, a run id or label.
What the views show¶
- Hover over a niche to see the trace of its best log-likelihood and the tree of its elite. A live run adds a trace point when the niche is new or its log-likelihood changes, and a point at the last checkpoint. A stored survey has a point for each segment of the chain of records of the gene. A survey that ran in one segment has one point for each niche.
- Before any niche is hovered, the trace of a stored survey shows the best log-likelihood of the survey at each checkpoint.
- Click a niche to keep it: the trace and the tree follow it until you click it again, click where there is no niche, or press Escape with the chart in focus. During a live run, a tree can be read after the run ends.
The view sends the page only what changes. It sets the full trace rows and
trees on its widgets at the last checkpoint of a run and when it is
displayed. After a run that stops early, for example at an interrupt, call
view.sync() so that a new display of the widgets is complete.
view.chart, view.trace and view.tree are the widgets themselves, so
that you can put them in a layout of your own. The widgets of one view
share hover and select events in the page, so a hover gets an answer while
the kernel is busy.
The widgets are in widgets/ at the root of the repository, and they know
nothing of surveys. hifuku.widgets.generic holds their Python classes.
SurveyView
¶
The chart, the trace and the tree of one gene on one chart.
source is a :class:~hifuku.survey_io.SurveyRun for a live run, or
a :class:~hifuku.survey_io.Survey for a stored one. For a live run,
show the view in one cell and give it as the monitor in the next::
view = SurveyView(run, gene="geneB")
view
run.execute(task, monitor=view)
The view shows only the tasks of its gene and chart. A new task of the gene starts the view again.
A hover on the chart shows the niche's trace, and a click shows its
tree. A live run adds a trace point when a niche is new or its
log-likelihood changes, and a point at the last checkpoint. A stored
survey has a trace point for each segment of its chain of records, and
the survey-level rows of its history at each checkpoint. When the
survey holds more than one chain for the gene (replicate runs), run
names the run id or the label of the run whose chain to show.
Source code in src/hifuku/widgets/survey_view.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
sync
¶
Set the trace rows and the trees that the view keeps on its widgets, so that a display of the widgets holds all of them.
The view does this at the last checkpoint of a run and when it is displayed. Call it after a run that stopped before its last checkpoint, for example after an interrupt.
Source code in src/hifuku/widgets/survey_view.py
display
¶
Return the three widgets, laid out as the browser page lays them out: the chart on the left, and the trace above the tree on the right. The widgets hold every trace point and tree that the view keeps, so a view displayed again during a run is complete.
Source code in src/hifuku/widgets/survey_view.py
Simplex
¶
Bases: AnyWidget
Values on a triangular grid in barycentric coordinates.
geometry holds the three vertices, the grid origin, the cell side
and a label for each vertex. The key of cell (i, j) is the string
"i,j". selected is the key of the cell that the user clicked
last.
Source code in src/hifuku/widgets/generic.py
set_cells
¶
Show values in the cells ij.
ij is an integer array of shape (n, 2), and values has
one value for each cell. A NaN value is not drawn.
Source code in src/hifuku/widgets/generic.py
Trace
¶
Bases: AnyWidget
A line plot of the row of the hovered key.
series maps a key to a row {"x": [...], "y": [...]} with an
optional "title". fallback is the key of the row to show when
the hovered key has no row.
Source code in src/hifuku/widgets/generic.py
add
¶
Add each (key, x, y) point to the row of its key, and return
the points as lists. Nothing goes to the page until :meth:sync.
Source code in src/hifuku/widgets/generic.py
extend
¶
Add each (key, x, y) point to the row of its key, and send
the points to the page.
The page adds the points to the rows that it shows. series does
not change until :meth:sync, so the rows are not all sent again.
Source code in src/hifuku/widgets/generic.py
last_x
¶
clear
¶
set_row
¶
Replace the row of key. :meth:sync sends it.
sync
¶
Set series from the rows that this widget keeps, so that a new
display of the widget shows all of them.
Tree
¶
Bases: AnyWidget
An unrooted tree, from Newick, for the selected key.
When the page has no tree for the selected key, it sets requested
to the key. The code that feeds the widget then calls :meth:add.
Source code in src/hifuku/widgets/generic.py
add
¶
Send the page the tree of key, with a caption, and keep it.
Only this tree goes to the page. trees does not change until
:meth:sync, so the other trees are not sent again.
Source code in src/hifuku/widgets/generic.py
entry
¶
sync
¶
Set trees from the trees that this widget keeps, so that a new
display of the widget has all of them.