Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/macos/Sources/RoveApp/Analysis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ enum GroupConstraints {
static func validate(_ groups: [[String]], taxa: [String], outgroup: String? = nil) -> String? {
let known = Set(taxa)
if let outgroup, !known.contains(outgroup) || known.count < 3 {
return "Choose one outgroup from a matrix with at least three terminals."
return "Choose one rooting taxon from a matrix with at least three terminals."
}
var previous: [Set<String>] = []
for group in groups {
Expand Down
107 changes: 107 additions & 0 deletions apps/macos/Sources/RoveApp/ClockSigmaPrior.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Charts
import SwiftUI

struct ClockSigmaPrior: Codable, Equatable, Sendable {
Expand All @@ -8,6 +9,109 @@ struct ClockSigmaPrior: Codable, Equatable, Sendable {
func description(strings: AppStrings) -> String {
strings("Gamma · shape %@ · scale %@", String(shape), String(scale))
}

var mean: Double { shape * scale }
var standardDeviation: Double { sqrt(shape) * scale }

/// Shape/scale Gamma density; evaluate in scaled coordinates to avoid
/// subtracting the separate, large shape * log(scale) terms.
func logDensity(at sigma: Double) -> Double? {
guard shape.isFinite, scale.isFinite, shape > 0, scale > 0,
sigma.isFinite, sigma >= 0, lgamma(shape).isFinite
else { return nil }
if sigma == 0 {
if shape < 1 { return .infinity }
return shape == 1 ? -log(scale) : -.infinity
}
let value = sigma / scale
guard value.isFinite, value > 0 else { return nil }
let density = (shape - 1) * log(value) - value - lgamma(shape) - log(scale)
return density.isNaN ? nil : density
}

struct Curve: Sendable {
struct Point: Identifiable, Sendable {
let id: Int
let sigma: Double
let density: Double
}
let points: [Point]
let upperBound: Double
}

var curve: Curve? {
let upper = mean + 5 * standardDeviation
// The numerical prior may be valid at scales where a linear display
// cannot draw meaningful axes. Keep that limitation in the preview only.
guard upper.isFinite, upper >= 1e-12, upper <= 1e12,
mean.isFinite, mean > 0, shape > 0, scale > 0
else { return nil }
let first = shape < 1 ? 1 : 0
var points: [Curve.Point] = []
for index in first...240 {
let sigma = upper * Double(index) / 240
guard let logValue = logDensity(at: sigma) else { return nil }
let value = exp(logValue)
guard value.isFinite, value <= 1e12 else { return nil }
points.append(.init(id: index, sigma: sigma, density: value))
}
guard points.contains(where: { $0.density > 0 }) else { return nil }
return Curve(points: points, upperBound: upper)
}
}

struct ClockSigmaPriorChart: View {
let prior: ClockSigmaPrior
let strings: AppStrings

var body: some View {
VStack(alignment: .leading, spacing: 10) {
if let curve = prior.curve {
Chart {
ForEach(curve.points) { point in
LineMark(
x: .value("Sigma", point.sigma),
y: .value(strings("Prior density"), point.density)
)
.foregroundStyle(Lab.lilac).lineStyle(StrokeStyle(lineWidth: 2))
}
RuleMark(x: .value(strings("Expected sigma"), prior.mean))
.foregroundStyle(Lab.accent).lineStyle(StrokeStyle(lineWidth: 1, dash: [4, 3]))
}
.chartXScale(domain: 0...curve.upperBound)
.chartXAxisLabel("Sigma")
.chartYAxisLabel(strings("Prior density"))
.frame(height: 170)
.accessibilityLabel(
strings("Gamma prior for clock sigma; the dashed line marks its expectation."))
} else {
Text(strings("The density preview is unavailable at this numerical scale."))
.font(.system(size: 11)).foregroundStyle(Lab.secondary)
}
if prior.mean.isFinite, prior.standardDeviation.isFinite {
Text(
strings(
"Expected sigma: %@ · standard deviation: %@",
number(prior.mean), number(prior.standardDeviation))
)
.font(.system(size: 11, weight: .medium)).foregroundStyle(Lab.accent)
}
if prior.shape < 1 {
Text(strings("The density grows without bound near zero; the curve starts above zero."))
.font(.system(size: 10)).foregroundStyle(Lab.secondary)
}
Text(
strings(
"This is a prior preview, before seeing the data. The displayed range is not a credible interval."
)
)
.font(.system(size: 10)).foregroundStyle(Lab.muted)
}
}

private func number(_ value: Double) -> String {
value.formatted(.number.precision(.significantDigits(1...5)).locale(strings.locale))
}
}

struct ClockSigmaPriorSection: View {
Expand Down Expand Up @@ -39,6 +143,9 @@ struct ClockSigmaPriorSection: View {
)
)
.font(.system(size: 11)).foregroundStyle(Lab.secondary).lineSpacing(3)
if let prior = workspace.settings.clockSigmaPrior {
ClockSigmaPriorChart(prior: prior, strings: strings)
}
if workspace.settings.clockSigmaPrior == nil {
Text(strings("Use positive, finite shape and scale values for the clock sigma prior."))
.font(.system(size: 12)).foregroundStyle(Lab.accent)
Expand Down
2 changes: 1 addition & 1 deletion apps/macos/Sources/RoveApp/LaunchExperience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct RoveRelease: Identifiable {
id: "morphology", symbol: "square.grid.3x3", title: "Bring all the little differences.",
summary: "Morphological matrices, with two, three or more states.",
detail:
"Import a NEXUS matrix, review its state partitions and choose the outgroup explicitly. The bundled 20 × 50 example is a good place to start.",
"Import a NEXUS matrix, review its state partitions and choose the taxon used for rooting explicitly. The bundled 20 × 50 example is a good place to start.",
action: "Try the example", destination: .example),
ReleaseHighlight(
id: "history", symbol: "clock.arrow.circlepath",
Expand Down
21 changes: 17 additions & 4 deletions apps/macos/Sources/RoveApp/MatrixView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct MatrixView: View {
Text(strings("By observed states")).tag("observed")
Text(strings("Declared alphabet")).tag("declared")
Text(strings("Complete state labels")).tag("labels")
}.labelsHidden().frame(width: 210)
}.labelsHidden().frame(width: 260)
.disabled(workspace.loading)
.onChange(of: workspace.settings.partitioning) { workspace.reloadGapPolicy() }
}
Expand All @@ -66,6 +66,7 @@ struct MatrixView: View {
)
)
.font(.system(size: 11)).foregroundStyle(Lab.secondary).lineSpacing(3)
.fixedSize(horizontal: false, vertical: true)
if let partitions = report.partitions {
ViewThatFits(in: .horizontal) {
HStack(spacing: 16) { partitionCounts(partitions) }
Expand All @@ -88,6 +89,7 @@ struct MatrixView: View {
)
)
.font(.system(size: 11)).foregroundStyle(Lab.secondary)
.fixedSize(horizontal: false, vertical: true)
}
}
}
Expand Down Expand Up @@ -153,12 +155,14 @@ struct MatrixView: View {
)
)
.font(.system(size: 11)).foregroundStyle(Lab.secondary)
.fixedSize(horizontal: false, vertical: true)
Text(
strings(
"If your exporter uses braces for polymorphism, confirm the meaning before running. Reading the file does not resolve that scientific choice."
)
)
.font(.system(size: 11)).foregroundStyle(Lab.secondary)
.fixedSize(horizontal: false, vertical: true)
if let examples = report.observationExamples, !examples.isEmpty {
DisclosureGroup(strings("Inspect ambiguous observations")) {
ForEach(Array(examples.enumerated()), id: \.offset) { _, example in
Expand Down Expand Up @@ -275,9 +279,18 @@ private struct MatrixGrid: View {
let name =
report.characterLabels[selected.column]
?? strings("Character %@", strings.number(selected.column + 1))
Text(
"\(report.taxa[selected.row]) · \(name) · \(report.cells[selected.row][selected.column])"
)
VStack(alignment: .leading, spacing: 4) {
Text(
"\(report.taxa[selected.row]) · \(name) · \(report.cells[selected.row][selected.column])"
)
if let labels = report.stateLabels, labels.indices.contains(selected.column) {
Text(
zip(report.symbols, labels[selected.column])
.map { "\($0.0) = \($0.1)" }.joined(separator: " · ")
)
.fixedSize(horizontal: false, vertical: true)
}
}
} else {
Text(strings("Click a cell to inspect it. Scroll to explore."))
}
Expand Down
4 changes: 2 additions & 2 deletions apps/macos/Sources/RoveApp/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct OnboardingView: View {
private let descriptions = [
"Rove explores evolutionary relationships from morphological data. A native workspace, a Rust engine, and a curious little companion.",
"Rows are taxa. Columns are characters. Bring a NEXUS matrix and Rove will help you inspect the states and missing observations before you run anything.",
"Review the model and choose your outgroup explicitly. It gives your analysis a rooting constraint; Rove never guesses one for you.",
"Review the model and choose a taxon for rooting explicitly. It constrains the root split; Rove never guesses that choice for you.",
"Follow the run, inspect its traces and explore the trees. History keeps your work together, with checkpoints for picking up a paused analysis.",
]

Expand Down Expand Up @@ -179,7 +179,7 @@ struct OnboardingView: View {
VStack(alignment: .leading, spacing: 10) {
Label(strings("For the bundled example"), systemImage: "lightbulb")
.font(.system(size: 12, weight: .medium)).foregroundStyle(Lab.ice)
Text(strings("Choose T20 as the outgroup. Check the remaining settings before starting."))
Text(strings("Choose T20 as the taxon used for rooting. Check the remaining settings before starting."))
.font(.system(size: 12)).foregroundStyle(Lab.secondary).lineSpacing(4)
}
}.padding(22).background(Lab.background.opacity(0.6), in: RoundedRectangle(cornerRadius: 15))
Expand Down
21 changes: 16 additions & 5 deletions apps/macos/Sources/RoveApp/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
"%@ on one side of the root; the other %@ terminals together on the other." = "%@ on one side of the root; the other %@ terminals together on the other.";
"The outgroup is a terminal, not the ancestor at the root. This choice constrains the ingroup; its support is imposed by the setup." = "The outgroup is a terminal, not the ancestor at the root. This choice constrains the ingroup; its support is imposed by the setup.";
"No outgroup selected. Any applied groups below still constrain the tree." = "No outgroup selected. Any applied groups below still constrain the tree.";
"Choose one outgroup from a matrix with at least three terminals." = "Choose one outgroup from a matrix with at least three terminals.";
"Choose one rooting taxon from a matrix with at least three terminals." = "Choose one rooting taxon from a matrix with at least three terminals.";
"No groups applied. Root placement is unconstrained by groups." = "No groups applied. Root placement is unconstrained by groups.";
"Applied groups" = "Applied groups";
"Support for an imposed group is not independent evidence from the characters." = "Support for an imposed group is not independent evidence from the characters.";
Expand Down Expand Up @@ -618,7 +618,7 @@
"Your research.\nRoom to explore." = "Your research.\nRoom to explore.";
"Rove explores evolutionary relationships from morphological data. A native workspace, a Rust engine, and a curious little companion." = "Rove explores evolutionary relationships from morphological data. A native workspace, a Rust engine, and a curious little companion.";
"Rows are taxa. Columns are characters. Bring a NEXUS matrix and Rove will help you inspect the states and missing observations before you run anything." = "Rows are taxa. Columns are characters. Bring a NEXUS matrix and Rove will help you inspect the states and missing observations before you run anything.";
"Review the model and choose your outgroup explicitly. It gives your analysis a rooting constraint; Rove never guesses one for you." = "Review the model and choose your outgroup explicitly. It gives your analysis a rooting constraint; Rove never guesses one for you.";
"Review the model and choose a taxon for rooting explicitly. It constrains the root split; Rove never guesses that choice for you." = "Review the model and choose a taxon for rooting explicitly. It constrains the root split; Rove never guesses that choice for you.";
"Follow the run, inspect its traces and explore the trees. History keeps your work together, with checkpoints for picking up a paused analysis." = "Follow the run, inspect its traces and explore the trees. History keeps your work together, with checkpoints for picking up a paused analysis.";
"YOUR FIRST FIELD TRIP" = "YOUR FIRST FIELD TRIP";
"A SMALL INTRODUCTION" = "A SMALL INTRODUCTION";
Expand All @@ -637,7 +637,7 @@
"Illustration of a morphological matrix" = "Illustration of a morphological matrix";
"? means an unknown observation." = "? means an unknown observation.";
"For the bundled example" = "For the bundled example";
"Choose T20 as the outgroup. Check the remaining settings before starting." = "Choose T20 as the outgroup. Check the remaining settings before starting.";
"Choose T20 as the taxon used for rooting. Check the remaining settings before starting." = "Choose T20 as the taxon used for rooting. Check the remaining settings before starting.";
"Check the sampling" = "Check the sampling";
"Useful samples matter more than step counts." = "Useful samples matter more than step counts.";
"Explore the trees" = "Explore the trees";
Expand All @@ -655,7 +655,7 @@
"A small beginning, with room for big questions. Meet the tools already inside this beta." = "A small beginning, with room for big questions. Meet the tools already inside this beta.";
"Bring all the little differences." = "Bring all the little differences.";
"Morphological matrices, with two, three or more states." = "Morphological matrices, with two, three or more states.";
"Import a NEXUS matrix, review its state partitions and choose the outgroup explicitly. The bundled 20 × 50 example is a good place to start." = "Import a NEXUS matrix, review its state partitions and choose the outgroup explicitly. The bundled 20 × 50 example is a good place to start.";
"Import a NEXUS matrix, review its state partitions and choose the taxon used for rooting explicitly. The bundled 20 × 50 example is a good place to start." = "Import a NEXUS matrix, review its state partitions and choose the taxon used for rooting explicitly. The bundled 20 × 50 example is a good place to start.";
"Good work deserves a save point." = "Good work deserves a save point.";
"Find past runs. Pause a long analysis. Pick up where you left off." = "Find past runs. Pause a long analysis. Pick up where you left off.";
"History keeps the run configuration and output paths together. Checkpoints preserve the sampler state; resuming requires the same engine and original input." = "History keeps the run configuration and output paths together. Checkpoints preserve the sampler state; resuming requires the same engine and original input.";
Expand Down Expand Up @@ -950,7 +950,7 @@
"The tree file could not be opened." = "The tree file could not be opened.";
"The tree file is no longer at its recorded path." = "The tree file is no longer at its recorded path.";
"Trees from another program" = "Trees from another program";
"Rove did not run this sample here, so no outgroup is known. A summary and high node support do not establish convergence." = "Rove did not run this sample here, so no outgroup is known. A summary and high node support do not establish convergence.";
"Rove did not run this sample here, so its rooting choice is unknown. A summary and high node support do not establish convergence." = "Rove did not run this sample here, so its rooting choice is unknown. A summary and high node support do not establish convergence.";
"The tree file is no longer at its recorded path. Saved summaries stay available." = "The tree file is no longer at its recorded path. Saved summaries stay available.";
"Summaries" = "Summaries";
"No summary yet. Summarize the file to build an annotated MCC tree." = "No summary yet. Summarize the file to build an annotated MCC tree.";
Expand Down Expand Up @@ -1105,3 +1105,14 @@
"Inspect ambiguous observations" = "Inspect ambiguous observations";
"Up to 100 observations are listed; the counts include the full matrix." = "Up to 100 observations are listed; the counts include the full matrix.";
"Alphabet choice" = "Alphabet choice";

// Visual model guidance.
"Prior density" = "Prior density";
"Expected sigma" = "Expected sigma";
"Gamma prior for clock sigma; the dashed line marks its expectation." = "Gamma prior for clock sigma; the dashed line marks its expectation.";
"The density preview is unavailable at this numerical scale." = "The density preview is unavailable at this numerical scale.";
"Expected sigma: %@ · standard deviation: %@" = "Expected sigma: %@ · standard deviation: %@";
"The density grows without bound near zero; the curve starts above zero." = "The density grows without bound near zero; the curve starts above zero.";
"This is a prior preview, before seeing the data. The displayed range is not a credible interval." = "This is a prior preview, before seeing the data. The displayed range is not a credible interval.";
"Other %@ terminals" = "Other %@ terminals";
"Constraint diagram. Branch lengths and relationships within the collapsed group are not estimated here." = "Constraint diagram. Branch lengths and relationships within the collapsed group are not estimated here.";
Loading
Loading