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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ This is an [Electron](https://electronjs.org/) app. The shell is built with elec

`yarn test:e2e` builds the shell, then [Playwright](https://playwright.dev/) launches `out/main/index.js`. There is no dev server. Specs in `e2e/` check the UI and output files:

- `modeltest-then-raxml-ng.spec.js` — ModelTest, then a full raxml-ng analysis
- `raxmlHPC.spec.js` — classic raxmlHPC (ML search), including copying the command and the citation
- `modeltest-outcome.spec.js` — ModelTest, then a raxml-ng tree inference and a serial raxmlHPC ML search with the model it picked, each checked against a per-host fixture in `e2e/fixtures/`. The raxmlHPC test also copies the command and the citation

Download binaries once, then run:

Expand Down
28 changes: 28 additions & 0 deletions e2e/fixtures/darwin-arm64/modeltest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"settings": {
"seed": 12345,
"runs": 1,
"analysis": "modeltest",
"criterion": "AICc",
"binary": "modeltest-ng-ARM64",
"binaryVersions": {
"modeltest-ng": "0.1.7"
}
},
"outcome": {
"criteria": {
"BIC": {
"model": "TPM2uf+I",
"score": 2639.0324
},
"AIC": {
"model": "TVM+I",
"score": 2460.0698
},
"AICc": {
"model": "TVM+I",
"score": 2465.0698
}
}
}
}
16 changes: 16 additions & 0 deletions e2e/fixtures/darwin-arm64/raxml-ng.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"settings": {
"seed": 12345,
"runs": 1,
"analysis": "TI",
"binary": "raxml-ng",
"binaryVersions": {
"raxml-ng": "1.2.2"
}
},
"outcome": {
"model": "TVM+FO+I",
"logLikelihood": -1184.201009,
"bestTree": "(TAXON_1:0.011965,((((TAXON_5:0.004875,(TAXON_11:0.000001,TAXON_13:0.000001):0.003275):0.001605,TAXON_10:0.001653):0.001599,(((((TAXON_9:0.003212,(((TAXON_15:0.001593,(TAXON_2:0.010048,TAXON_4:0.003299):0.000001):0.001582,TAXON_7:0.001567):0.000001,TAXON_3:0.003190):0.000001):0.001632,TAXON_6:0.003863):0.003130,(TAXON_8:0.004816,TAXON_14:0.000001):0.001588):0.000001,TAXON_16:0.000001):0.001871,TAXON_17:0.000001):0.000001):0.001503,TAXON_18:0.000328):0.001611,TAXON_19:0.002346);"
}
}
16 changes: 16 additions & 0 deletions e2e/fixtures/darwin-arm64/raxmlHPC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"settings": {
"seed": 12345,
"runs": 1,
"analysis": "ML",
"binary": "raxmlHPC",
"binaryVersions": {
"raxmlHPC": "8.2.12"
}
},
"outcome": {
"model": "GTRCATIX",
"score": -1183.120275,
"bestTree": "(TAXON_19:0.00244607530621962976,(((TAXON_10:0.00165460077468338688,(TAXON_5:0.00490169990410668430,(TAXON_11:0.00000100000050002909,TAXON_13:0.00000100000050002909):0.00326460786816565492):0.00159662967916767979):0.00159732624854270924,(TAXON_17:0.00000100000050002909,(((((((TAXON_15:0.00161828822768687029,(TAXON_2:0.01023582658137301565,TAXON_4:0.00340503013899453926):0.00000100000050002909):0.00158288002901413468,TAXON_7:0.00160944904780967483):0.00000100000050002909,TAXON_3:0.00326681961445571571):0.00002345716699163092,TAXON_9:0.00327614007924441385):0.00149308198240371724,TAXON_6:0.00422084577883892823):0.00327631431077851643,TAXON_16:0.00000100000050002909):0.00000100000050002909,(TAXON_14:0.00000100000050002909,TAXON_8:0.00490291155260013604):0.00160702621607535195):0.00191993844272083020):0.00000100000050002909):0.00013743433944014784,TAXON_18:0.00153047559521670459):0.00168622373656522064,TAXON_1:0.01197460871080295412):0.0;"
}
}
28 changes: 28 additions & 0 deletions e2e/fixtures/linux-x64/modeltest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"settings": {
"seed": 12345,
"runs": 1,
"analysis": "modeltest",
"criterion": "AICc",
"binary": "modeltest-ng",
"binaryVersions": {
"modeltest-ng": "x.y.z"
}
},
"outcome": {
"criteria": {
"BIC": {
"model": "TPM2uf+I",
"score": 2638.9532
},
"AIC": {
"model": "TVM+I",
"score": 2460.0397
},
"AICc": {
"model": "TVM+I",
"score": 2465.0397
}
}
}
}
16 changes: 16 additions & 0 deletions e2e/fixtures/linux-x64/raxml-ng.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"settings": {
"seed": 12345,
"runs": 1,
"analysis": "TI",
"binary": "raxml-ng",
"binaryVersions": {
"raxml-ng": "1.2.2-master"
}
},
"outcome": {
"model": "TVM+FO+I",
"logLikelihood": -1184.201361,
"bestTree": "(TAXON_7:0.001567,((TAXON_2:0.010036,TAXON_4:0.003295):0.000001,TAXON_15:0.001591):0.001580,((TAXON_9:0.003208,(TAXON_6:0.003858,((TAXON_14:0.000001,TAXON_8:0.004812):0.001587,(TAXON_16:0.000001,(((((TAXON_11:0.000001,TAXON_13:0.000001):0.003272,TAXON_5:0.004870):0.001604,TAXON_10:0.001652):0.001598,((TAXON_1:0.011966,TAXON_19:0.002344):0.001603,TAXON_18:0.000332):0.001502):0.000001,TAXON_17:0.000001):0.001876):0.000001):0.003137):0.001589):0.000044,TAXON_3:0.003188):0.000001);"
}
}
16 changes: 16 additions & 0 deletions e2e/fixtures/linux-x64/raxmlHPC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"settings": {
"seed": 12345,
"runs": 1,
"analysis": "ML",
"binary": "raxmlHPC",
"binaryVersions": {
"raxmlHPC": "8.2.12"
}
},
"outcome": {
"model": "GTRCATIX",
"score": -1183.120275,
"bestTree": "(TAXON_19:0.00244607530473719102,(((TAXON_10:0.00165460077670411400,(TAXON_5:0.00490169990999902820,(TAXON_11:0.00000100000050002909,TAXON_13:0.00000100000050002909):0.00326460787716503342):0.00159662968071902674):0.00159732625053941239,(TAXON_17:0.00000100000050002909,(((((((TAXON_15:0.00161828823041654875,(TAXON_2:0.01023582659058935168,TAXON_4:0.00340503014194076066):0.00000100000050002909):0.00158288003065052709,TAXON_7:0.00160944905088082754):0.00000100000050002909,TAXON_3:0.00326681961677442951):0.00002345717677958670,TAXON_9:0.00327614008220529279):0.00149308199646746675,TAXON_6:0.00422084576034152930):0.00327631430549322035,TAXON_16:0.00000100000050002909):0.00000100000050002909,(TAXON_14:0.00000100000050002909,TAXON_8:0.00490291155601087995):0.00160702621743578325):0.00191993844408858399):0.00000100000050002909):0.00013743440375832238,TAXON_18:0.00153047555790677883):0.00168622372143269867,TAXON_1:0.01197460875703067369):0.0;"
}
}
28 changes: 28 additions & 0 deletions e2e/fixtures/win32-x64/modeltest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"settings": {
"seed": 12345,
"runs": 1,
"analysis": "modeltest",
"criterion": "AICc",
"binary": "modeltest-ng.exe",
"binaryVersions": {
"modeltest-ng": "0.1.7"
}
},
"outcome": {
"criteria": {
"BIC": {
"model": "TPM2uf+I",
"score": 2639.0324
},
"AIC": {
"model": "TVM+I",
"score": 2460.0698
},
"AICc": {
"model": "TVM+I",
"score": 2465.0698
}
}
}
}
16 changes: 16 additions & 0 deletions e2e/fixtures/win32-x64/raxmlHPC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"settings": {
"seed": 12345,
"runs": 1,
"analysis": "ML",
"binary": "raxmlHPC.exe",
"binaryVersions": {
"raxmlHPC": "8.2.12"
}
},
"outcome": {
"model": "GTRCATIX",
"score": -1183.120275,
"bestTree": "(TAXON_19:0.00244607532222351374,(((TAXON_10:0.00165460077416372054,(TAXON_5:0.00490169990266712489,(TAXON_11:0.00000100000050002909,TAXON_13:0.00000100000050002909):0.00326460786435126384):0.00159662967851137904):0.00159732624784359616,(TAXON_17:0.00000100000050002909,(((((((TAXON_15:0.00161828822701187355,(TAXON_2:0.01023582658714253593,TAXON_4:0.00340503014127669940):0.00000100000050002909):0.00158288002917348161,TAXON_7:0.00160944904689838144):0.00000100000050002909,TAXON_3:0.00326681961657928179):0.00002345716191679346,TAXON_9:0.00327614007965075201):0.00149308197811563324,TAXON_6:0.00422084580040837411):0.00327631431276509703,TAXON_16:0.00000100000050002909):0.00000100000050002909,(TAXON_14:0.00000100000050002909,TAXON_8:0.00490291155409224542):0.00160702621604032355):0.00191993844179090024):0.00000100000050002909):0.00013743422052569246,TAXON_18:0.00153047566661464640):0.00168622376581414207,TAXON_1:0.01197460869009258147):0.0;"
}
}
203 changes: 203 additions & 0 deletions e2e/helpers/fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
const fs = require('fs');
const path = require('path');
const { parseNewick, edges, compareTopologies } = require('./newick');

const RTOL = 1e-4;
const TREE_RTOL = 1e-3;
const REGENERATE = 'yarn test:e2e:update-fixtures';

/** @param {unknown} value */
const show = (value) =>
typeof value === 'string' ? value : JSON.stringify(value);

/** @param {Record<string, any>} obj @param {string} [prefix] */
function flatten(obj, prefix = '') {
/** @type {Record<string, unknown>} */
const out = {};
for (const [key, value] of Object.entries(obj)) {
const name = prefix ? `${prefix}.${key}` : key;
if (value && typeof value === 'object') {
Object.assign(out, flatten(value, name));
} else {
out[name] = value;
}
}
return out;
}

/**
* Differences between two Newick trees: topology exact (RF distance 0), then
* each branch length within TREE_RTOL relative to the larger length.
* @param {string} expected
* @param {string} actual
* @returns {{ field: string, expected: unknown, actual: unknown, delta: unknown, tolerance: string }[]}
*/
function compareTrees(expected, actual) {
const topology = compareTopologies(expected, actual);
if ('taxaMismatch' in topology) {
const { onlyInA, onlyInB } = topology.taxaMismatch;
return [
{
field: 'bestTree taxa',
expected: `unique to fixture: ${onlyInA.join(' ') || 'none'}`,
actual: `unique to actual: ${onlyInB.join(' ') || 'none'}`,
delta: 'n/a',
tolerance: 'exact',
},
];
}
if (topology.rf) {
return [
{
field: 'bestTree topology',
expected: 'RF distance 0',
actual: `RF distance ${topology.rf}\n splits unique to fixture: ${topology.uniqueA.join(' | ') || 'none'}\n splits unique to actual: ${topology.uniqueB.join(' | ') || 'none'}`,
delta: topology.rf,
tolerance: 'exact',
},
];
}
const ea = edges(parseNewick(expected));
const eb = edges(parseNewick(actual));
/** @type {ReturnType<typeof compareTrees>} */
const diffs = [];
for (const [key, x] of ea) {
const y = eb.get(key);
if (typeof x !== 'number' || typeof y !== 'number') continue;
const delta = Number((y - x).toPrecision(6));
if (Math.abs(delta) > TREE_RTOL * Math.max(Math.abs(x), Math.abs(y))) {
diffs.push({
field: `bestTree branch ${key}`,
expected: x,
actual: y,
delta,
tolerance: `${TREE_RTOL} relative`,
});
}
}
return diffs;
}

/**
* Differing fields, binary versions first. Numbers agree within RTOL
* relative to the larger magnitude; everything else must be equal. A
* `bestTree` field is compared as a tree.
* @param {Record<string, any>} expected
* @param {Record<string, any>} actual
*/
function compareOutcome(expected, actual) {
const { bestTree: expectedTree, ...expectedRest } = expected;
const { bestTree: actualTree, ...actualRest } = actual;
const e = flatten(expectedRest);
const a = flatten(actualRest);
/** @type {{ field: string, expected: unknown, actual: unknown, delta: unknown, tolerance: string }[]} */
const diffs = [];
if (expectedTree !== undefined || actualTree !== undefined) {
if (typeof expectedTree === 'string' && typeof actualTree === 'string') {
diffs.push(...compareTrees(expectedTree, actualTree));
} else {
diffs.push({
field: 'bestTree',
expected: expectedTree,
actual: actualTree,
delta: 'n/a',
tolerance: 'exact',
});
}
}
for (const field of new Set([...Object.keys(e), ...Object.keys(a)])) {
const x = e[field];
const y = a[field];
if (typeof x === 'number' && typeof y === 'number') {
const delta = Number((y - x).toPrecision(6));
if (Math.abs(delta) > RTOL * Math.max(Math.abs(x), Math.abs(y))) {
diffs.push({
field,
expected: x,
actual: y,
delta,
tolerance: `${RTOL} relative`,
});
}
} else if (x !== y) {
diffs.push({
field,
expected: x,
actual: y,
delta: 'n/a',
tolerance: 'exact',
});
}
}
const isVersion = (/** @type {{ field: string }} */ d) =>
d.field.startsWith('binaryVersions');
return [...diffs.filter(isVersion), ...diffs.filter((d) => !isVersion(d))];
}

/**
* @param {ReturnType<typeof compareOutcome>} diffs
* @param {string} fixturePath
*/
function formatReport(diffs, fixturePath) {
const blocks = diffs.map(
(d) =>
`${d.field}\n expected: ${show(d.expected)}\n actual: ${show(d.actual)}\n delta: ${show(d.delta)}\n tolerance: ${d.tolerance}`,
);
return `${blocks.join('\n\n')}\n\nFixture: ${fixturePath}\nRegenerate: ${REGENERATE}`;
}

/**
* The one entry point per run. Compares the outcome with this host's fixture,
* or writes the fixture when RAXMLGUI_UPDATE_FIXTURES is set.
* @param {string} name fixture file name without extension
* @param {Record<string, any> & { binaryVersions: Record<string, string> }} settings what the spec ran with
* @param {Record<string, any> & { binaryVersions: Record<string, string> }} actual parsed outcome
* @returns {{ ok: boolean, message: string }}
*/
function checkFixture(name, settings, actual) {
const host = `${process.platform}-${process.arch}`;
const fixturePath = path.join(__dirname, '..', 'fixtures', host, `${name}.json`);
const { binaryVersions, ...outcome } = actual;

if (process.env.RAXMLGUI_UPDATE_FIXTURES === '1') {
// A fixture must not record a binary the spec does not declare
const diffs = compareOutcome(
{ binaryVersions: settings.binaryVersions },
{ binaryVersions },
);
if (diffs.length) return { ok: false, message: formatReport(diffs, fixturePath) };
fs.mkdirSync(path.dirname(fixturePath), { recursive: true });
fs.writeFileSync(
fixturePath,
`${JSON.stringify({ settings, outcome }, null, 2)}\n`,
);
return { ok: true, message: `Wrote ${fixturePath}` };
}

if (!fs.existsSync(fixturePath)) {
return {
ok: false,
message: `No fixture for ${host}: ${fixturePath}\nRegenerate: ${REGENERATE}`,
};
}
const fixture = JSON.parse(fs.readFileSync(fixturePath, 'utf8'));
const drift = Object.keys({ ...fixture.settings, ...settings }).filter(
(key) =>
JSON.stringify(fixture.settings[key]) !== JSON.stringify(settings[key]),
);
if (drift.length) {
return {
ok: false,
message: `Settings differ from the fixture: ${drift.join(', ')}\nFixture: ${fixturePath}\nRegenerate: ${REGENERATE}`,
};
}
const diffs = compareOutcome(
{ binaryVersions: fixture.settings.binaryVersions, ...fixture.outcome },
actual,
);
return diffs.length
? { ok: false, message: formatReport(diffs, fixturePath) }
: { ok: true, message: '' };
}

module.exports = { checkFixture, compareOutcome, formatReport };
Loading
Loading