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
54 changes: 38 additions & 16 deletions apps/macos/Sources/RoveApp/Analysis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct MatrixReport: Decodable, Sendable {
let unobservedCharacters: [Int]?
let observationExamples: [ObservationExample]?
let stateLabels: [[String]]?
var dataType: String? = nil
var inputFormat: String? = nil
var isDNA: Bool { dataType == "dna" }
var allTaxa: [String] { taxonNames ?? taxa }

var missingPercent: Double {
Expand All @@ -33,7 +36,8 @@ struct MatrixReport: Decodable, Sendable {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let value = try decoder.decode(Self.self, from: data)
guard value.schemaVersion == 1, value.taxonCount > 0, value.characterCount > 0,
guard value.schemaVersion == 1, ["standard", "dna"].contains(value.dataType ?? "standard"),
value.taxonCount > 0, value.characterCount > 0,
value.cells.count == value.taxa.count, !value.cells.isEmpty,
value.cells.allSatisfy({ $0.count == value.characterLabels.count })
else {
Expand Down Expand Up @@ -245,6 +249,7 @@ enum ProposalSchedule {
}

struct AnalysisSettings: Codable, Equatable, Sendable {
var dataType = "standard"
var dating = DatingSettings()
var treePrior = "birth-death"
var birthRateUpper = "1000"
Expand Down Expand Up @@ -285,7 +290,8 @@ struct AnalysisSettings: Codable, Equatable, Sendable {
}

private enum CodingKeys: String, CodingKey {
case dating, treePrior, birthRateUpper, clock, clockSigmaShape, clockSigmaScale, conditioning,
case dataType, dating, treePrior, birthRateUpper, clock, clockSigmaShape, clockSigmaScale,
conditioning,
partitioning, steps,
sampleEvery, seed, gapsAsMissing, chains, comparisonBurnin, backend, printEvery,
stopWhenConverged, sampleFromPrior, minESS, maxRhat, checkEvery, checkpointEvery, tuning,
Expand All @@ -294,6 +300,7 @@ struct AnalysisSettings: Codable, Equatable, Sendable {

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
dataType = try values.decodeIfPresent(String.self, forKey: .dataType) ?? "standard"
dating = try values.decodeIfPresent(DatingSettings.self, forKey: .dating) ?? DatingSettings()
treePrior = try values.decodeIfPresent(String.self, forKey: .treePrior) ?? "birth-death"
birthRateUpper = try values.decodeIfPresent(String.self, forKey: .birthRateUpper) ?? "1000"
Expand Down Expand Up @@ -367,14 +374,26 @@ struct AnalysisSettings: Codable, Equatable, Sendable {
return value
}

var characterModelLabel: String {
if dataType == "dna" { return "DNA · JC69" }
return conditioning == "variable"
? "Mkv · variable characters"
: conditioning == "informative" ? "Mkparsinf · informative characters" : "Mk · all characters"
}

var validationError: String? {
guard ["birth-death", "yule"].contains(treePrior),
guard ["standard", "dna"].contains(dataType),
["birth-death", "yule"].contains(treePrior),
["strict", "reference"].contains(clock),
["variable", "informative", "none"].contains(conditioning),
["observed", "declared", "labels"].contains(partitioning)
else {
return "This setup uses an unsupported model."
}
if dataType == "dna" && (conditioning != "none" || partitioning != "declared") {
return
"DNA JC69 keeps all four A/C/G/T states and all aligned sites, including constant sites."
}
if treePrior == "yule" {
if dating.enabled {
return "Yule requires contemporaneous tips without fossil dating or calibrations."
Expand Down Expand Up @@ -509,18 +528,20 @@ struct AnalysisDraft: Codable, Sendable {
monophyly: [[String]] = [], outgroup: String? = nil
) {
formatVersion =
settings.treePrior == "yule"
? 10
: settings.usesJointExchange
? 9
: settings.partitioning == "labels"
? 8
: settings.usesExecutionOptions
? 7
: settings.usesCustomSigmaPrior
? 6
: (settings.usesAdvancedOptions
? 5 : (settings.dating.estimatesProcess ? 4 : (settings.dating.enabled ? 3 : 2)))
settings.dataType == "dna"
? 11
: settings.treePrior == "yule"
? 10
: settings.usesJointExchange
? 9
: settings.partitioning == "labels"
? 8
: settings.usesExecutionOptions
? 7
: settings.usesCustomSigmaPrior
? 6
: (settings.usesAdvancedOptions
? 5 : (settings.dating.estimatesProcess ? 4 : (settings.dating.enabled ? 3 : 2)))
createdAt = Date()
matrixPath = matrix.path
matrixSHA256 = report.inputSha256
Expand All @@ -544,7 +565,8 @@ struct AnalysisDraft: Codable, Sendable {
}

func validate() throws {
guard (1...10).contains(formatVersion),
guard (1...11).contains(formatVersion),
formatVersion >= 11 || settings.dataType != "dna",
formatVersion >= 10 || settings.treePrior != "yule",
formatVersion >= 9 || !settings.usesJointExchange,
formatVersion >= 8 || settings.partitioning != "labels",
Expand Down
6 changes: 3 additions & 3 deletions apps/macos/Sources/RoveApp/CommandLineImport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ enum CommandLineImport {
}
guard let steps = Int(exactly: record.settings.steps),
let interval = Int(exactly: record.settings.sampleEvery),
let conditioning = EngineRecord.Model.conditioningDescriptions.first(where: {
$0.value == record.model.conditioning
})?.key
let conditioning = record.model.conditioningKind
?? option("--conditioning")
else { throw RunFailure.invalidCompletion }
var value = AnalysisSettings()
value.dataType = record.model.resolvedDataType
guard record.model.dataModelMatches(value) else { throw RunFailure.invalidCompletion }
value.treePrior = record.model.treePriorKind ?? "birth-death"
if value.treePrior == "yule" {
guard let prior = record.model.birthRatePriorParameters, prior.valid else {
Expand Down
5 changes: 1 addition & 4 deletions apps/macos/Sources/RoveApp/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ private struct HistoryDetail: View {
field(
"Character model",
strings(
draft.settings.conditioning == "variable"
? "Mkv · variable characters"
: draft.settings.conditioning == "informative"
? "Mkparsinf · informative characters" : "Mk · all characters"))
draft.settings.characterModelLabel))
field(
"State partitions",
strings(
Expand Down
4 changes: 2 additions & 2 deletions apps/macos/Sources/RoveApp/MarginalLikelihood.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ struct SavedEstimate: Identifiable, Sendable {
return record.input.sha256 == draft.matrixSHA256
&& record.input.gaps == (settings.gapsAsMissing ? "missing" : "reject")
&& record.model.monophyly == draft.constraints && record.model.preset == settings.clock
&& record.model.conditioning
== EngineRecord.Model.conditioningDescriptions[settings.conditioning]
&& record.model.conditioningKind == settings.conditioning
&& record.model.dataModelMatches(settings)
&& (record.model.partitioning ?? "declared") == settings.partitioning
&& record.model.dating == dating && record.model.treePriorMatches(settings)
&& (settings.clock != "reference"
Expand Down
75 changes: 44 additions & 31 deletions apps/macos/Sources/RoveApp/MatrixView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ struct MatrixView: View {
HStack(spacing: 0) {
metric(
"TERMINALS", value: strings.number(report.taxonCount), note: "The taxa in your study")
metric("CHARACTERS", value: strings.number(report.characterCount), note: "Observed traits")
metric(
report.isDNA ? "SITES" : "CHARACTERS", value: strings.number(report.characterCount),
note: report.isDNA ? "Aligned positions" : "Observed traits")
metric(
"PATTERNS", value: report.patternCount.map(strings.number) ?? "—",
note: "Distinct patterns within partitions")
Expand All @@ -43,37 +45,42 @@ struct MatrixView: View {
.background(Lab.surface, in: RoundedRectangle(cornerRadius: 15))
.overlay(RoundedRectangle(cornerRadius: 15).strokeBorder(Lab.border.opacity(0.7)))

LabPanel {
VStack(alignment: .leading, spacing: 12) {
HStack {
Text(strings("State partitions")).font(.system(size: 13, weight: .semibold))
Spacer()
Picker(strings("State partitions"), selection: $workspace.settings.partitioning) {
Text(strings("By observed states")).tag("observed")
Text(strings("Declared alphabet")).tag("declared")
Text(strings("Complete state labels")).tag("labels")
}.labelsHidden().frame(width: 260)
.disabled(workspace.loading)
.onChange(of: workspace.settings.partitioning) { workspace.reloadGapPolicy() }
}
Text(
strings(
workspace.settings.partitioning == "observed"
? "Characters are grouped by state count and ordering. Ordered characters keep intermediate states; binary alphabets keep both states."
: workspace.settings.partitioning == "labels"
? "Use each state-label list as the complete possible alphabet, in SYMBOLS order. Choose this only if every character lists all its possible states."
: "Every character uses all states declared in SYMBOLS. Choose this only if they are possible for every character."
if report.isDNA {
NucleotideModelSection(strings: strings)
} else {
LabPanel {
VStack(alignment: .leading, spacing: 12) {
HStack {
Text(strings("State partitions")).font(.system(size: 13, weight: .semibold))
Spacer()
Picker(strings("State partitions"), selection: $workspace.settings.partitioning) {
Text(strings("By observed states")).tag("observed")
Text(strings("Declared alphabet")).tag("declared")
Text(strings("Complete state labels")).tag("labels")
}.labelsHidden().frame(width: 260)
.disabled(workspace.loading)
.onChange(of: workspace.settings.partitioning) { workspace.reloadGapPolicy() }
}
Text(
strings(
workspace.settings.partitioning == "observed"
? "Characters are grouped by state count and ordering. Ordered characters keep intermediate states; binary alphabets keep both states."
: workspace.settings.partitioning == "labels"
? "Use each state-label list as the complete possible alphabet, in SYMBOLS order. Choose this only if every character lists all its possible states."
: "Every character uses all states declared in SYMBOLS. Choose this only if they are possible for every character."
)
)
)
.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) }
VStack(alignment: .leading, spacing: 8) { partitionCounts(partitions) }
.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) }
VStack(alignment: .leading, spacing: 8) { partitionCounts(partitions) }
}
}
}
}

}

if let constant = report.constantCharacters, !constant.isEmpty {
Expand All @@ -85,7 +92,9 @@ struct MatrixView: View {
.font(.system(size: 11, design: .monospaced)).textSelection(.enabled)
Text(
strings(
"These characters remain in the matrix. Variable-only (Mkv) coding cannot include them. Review how characters were selected before choosing All characters (Mk)."
report.isDNA
? "Constant sites are retained and contribute to the JC69 likelihood."
: "These characters remain in the matrix. Variable-only (Mkv) coding cannot include them. Review how characters were selected before choosing All characters (Mk)."
)
)
.font(.system(size: 11)).foregroundStyle(Lab.secondary)
Expand Down Expand Up @@ -151,14 +160,18 @@ struct MatrixView: View {
.font(.system(size: 11, weight: .medium))
Text(
strings(
"Braces such as {01} mean state 0 OR 1. Parentheses such as (01) mean both states are present. Rove preserves this distinction; its current observation model cannot analyze true polymorphism."
report.isDNA
? "IUPAC codes and braces specify possible bases: R means A or G, and N permits all four. These observations contribute to inference without being recoded as extra states."
: "Braces such as {01} mean state 0 OR 1. Parentheses such as (01) mean both states are present. Rove preserves this distinction; its current observation model cannot analyze true polymorphism."
)
)
.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."
report.isDNA
? "Predictive checks currently require single bases or missing cells. Ambiguous observations need an explicit observation model for simulation."
: "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)
Expand Down
27 changes: 27 additions & 0 deletions apps/macos/Sources/RoveApp/NucleotideModelView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import SwiftUI

struct NucleotideModelSection: View {
let strings: AppStrings

var body: some View {
LabPanel {
VStack(alignment: .leading, spacing: 12) {
Text(strings("Aligned DNA · JC69")).font(.system(size: 13, weight: .semibold))
Text(
strings(
"JC69 treats A, C, G and T equally. All four states remain possible at every site, and constant sites stay in the alignment."
)
)
.font(.system(size: 12)).foregroundStyle(Lab.secondary)
.fixedSize(horizontal: false, vertical: true)
Text(
strings(
"Import sequences that are already aligned. Ambiguous IUPAC bases represent possible states, not extra nucleotides. Choose a gap policy in the matrix preview."
)
)
.font(.system(size: 11)).foregroundStyle(Lab.secondary)
.fixedSize(horizontal: false, vertical: true)
}
}
}
}
21 changes: 21 additions & 0 deletions apps/macos/Sources/RoveApp/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1174,3 +1174,24 @@
"Birth-difference and relative-death moves require the birth-death prior." = "Birth-difference and relative-death moves require the birth-death prior.";
"The birth-rate move requires Yule without fossil dating." = "The birth-rate move requires Yule without fossil dating.";
"Speciation rate under Yule, per source tree-height unit." = "Speciation rate under Yule, per source tree-height unit.";

// Aligned DNA
"DNA · JC69" = "DNA · JC69";
"Aligned DNA · JC69" = "Aligned DNA · JC69";
"JC69 treats A, C, G and T equally. All four states remain possible at every site, and constant sites stay in the alignment." = "JC69 treats A, C, G and T equally. All four states remain possible at every site, and constant sites stay in the alignment.";
"Import sequences that are already aligned. Ambiguous IUPAC bases represent possible states, not extra nucleotides. Choose a gap policy in the matrix preview." = "Import sequences that are already aligned. Ambiguous IUPAC bases represent possible states, not extra nucleotides. Choose a gap policy in the matrix preview.";
"DNA JC69 keeps all four A/C/G/T states and all aligned sites, including constant sites." = "DNA JC69 keeps all four A/C/G/T states and all aligned sites, including constant sites.";
"The saved data type does not match the input." = "The saved data type does not match the input.";
"SITES" = "SITES";
"Aligned positions" = "Aligned positions";
"Constant sites are retained and contribute to the JC69 likelihood." = "Constant sites are retained and contribute to the JC69 likelihood.";
"IUPAC codes and braces specify possible bases: R means A or G, and N permits all four. These observations contribute to inference without being recoded as extra states." = "IUPAC codes and braces specify possible bases: R means A or G, and N permits all four. These observations contribute to inference without being recoded as extra states.";
"Predictive checks currently require single bases or missing cells. Ambiguous observations need an explicit observation model for simulation." = "Predictive checks currently require single bases or missing cells. Ambiguous observations need an explicit observation model for simulation.";
"Open a NEXUS matrix or aligned DNA in FASTA. Your data stays on this Mac." = "Open a NEXUS matrix or aligned DNA in FASTA. Your data stays on this Mac.";
"Choose a local NEXUS or aligned FASTA file from your Mac." = "Choose a local NEXUS or aligned FASTA file from your Mac.";
"Choose a NEXUS or aligned FASTA file, rather than a folder." = "Choose a NEXUS or aligned FASTA file, rather than a folder.";
"Drop a NEXUS or aligned FASTA file here, or browse your Mac." = "Drop a NEXUS or aligned FASTA file here, or browse your Mac.";
"Open or drop a NEXUS matrix, tree file or aligned DNA in FASTA" = "Open or drop a NEXUS matrix, tree file or aligned DNA in FASTA";
"Import a morphological NEXUS matrix or aligned DNA in NEXUS or FASTA. Inspect the observations and review the model before starting an analysis." = "Import a morphological NEXUS matrix or aligned DNA in NEXUS or FASTA. Inspect the observations and review the model before starting an analysis.";
"Declared states: %@ · DNA" = "Declared states: %@ · DNA";
"Choose a matrix or DNA alignment" = "Choose a matrix or DNA alignment";
Loading
Loading