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
78 changes: 14 additions & 64 deletions src/app/store/Run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import FinalAlignment from './FinalAlignment';
import AstralTree from './AstralTree';
import StoreBase, { runEvents } from './StoreBase';
import { host } from './host';
import { commandText, settingsText } from './command';
import type { CmdArg } from './command';
import { astralArgs } from './command/astral';
import { modeltestNgArgs } from './command/modeltestNg';
import {
binaries,
analysisOptions,
Expand Down Expand Up @@ -56,8 +60,6 @@ interface RunParent {
interface FilePathEntry {
path: string;
}
// A CLI argument: seeds and thread counts are pushed as numbers.
type CmdArg = string | number;

class Run extends StoreBase {
parent: RunParent;
Expand Down Expand Up @@ -484,10 +486,10 @@ class Run extends StoreBase {

get args(): CmdArg[][] {
if ( this.usesAstral ) {
return this.astralArgs();
return astralArgs( this, { windows } );
}
if ( this.usesModeltestNg ) {
return this.modeltestNgArgs();
return modeltestNgArgs( this, { windows } );
}
if ( this.usesRaxmlNg ) {
return this.raxmlNgArgs();
Expand Down Expand Up @@ -570,43 +572,6 @@ class Run extends StoreBase {
return model;
}

astralArgs = (): string[][] => {
const first: string[] = [];
if ( this.astralTree ) {
first.push( '-i', quote( this.astralTree.path, { windows } ) );
}
first.push(
'-o',
quote( join( this.outputDir, `ASTRAL_${this.outputNameSafe}.tre` ), { windows } ),
);
return [first];
};

modeltestNgArgs = (): CmdArg[][] => {
const first: CmdArg[] = [];
// data type
if ( this.dataType === 'nucleotide' ) {
first.push( '-d', 'nt' );
} else if ( this.dataType === 'protein' ) {
first.push( '-d', 'aa' );
}
// alignment file
first.push( '-i', quote( this.finalAlignment.path, { windows } ) );
// output file, modeltest errors if this file already exists
first.push(
'-o',
quote( join( this.outputDir, `RAxML_GUI_ModelTest_${this.outputNameSafe}` ), { windows } ),
);
// modeltest throws errors if the output file already exists
first.push( '--force' );
// Number of processors
first.push( '-p', this.numThreads.value );
// TODO: in able to support partitioned modeltest we need to change the partition file text
// https://github.com/ddarriba/modeltest/wiki/Input-Data#partition-files
// partition scheme
return [first];
};

raxmlNgArgs = (): CmdArg[][] => {
const first: CmdArg[] = [];
const second: CmdArg[] = [];
Expand Down Expand Up @@ -1303,32 +1268,17 @@ class Run extends StoreBase {
};

get command(): string {
if ( this.usesAstral ) {
return this.args
.map( ( cmdArgs ) => `java -jar ${this.binary.value} ${cmdArgs.join( ' ' )}` )
.join( ' &&\\\n' );
}
return this.args
.map( ( cmdArgs ) => `${this.binary.value} ${cmdArgs.join( ' ' )}` )
.join( ' &&\\\n' );
return commandText( this.binary.value, this.args, this.usesAstral );
}

get settingsFileContent(): string {
let text = `The analysis was run using raxmlGUI 2.0 (version ${this.version}) as follows:
Analysis: ${this.analysisOption.title}
Binary: ${this.binary.value} version ${this.binary.version}
Results saved to: ${this.outputDir}
`;
let argumentext = 'RAxML was called with these arguments:\n';
this.args.map(
( arg, index ) => ( argumentext += `${index + 1}.) ${arg.join( ' ' )}\n` ),
);
text += argumentext;
// TODO: should we be more precise about what the single params mean?
// text += `To repeat the analysis use the following seeds:
// Bootstrap seed: ${this.seedBootstrap}
// Parsimony seed: ${this.seedParsimony}`;
return text;
return settingsText( {
appVersion: this.version,
analysisTitle: this.analysisOption.title,
binary: this.binary,
outputDir: this.outputDir,
args: this.args,
} );
}

get settingsFilePath(): string {
Expand Down
17 changes: 17 additions & 0 deletions src/app/store/command/astral.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, it } from 'vitest';

import { astralArgs } from './astral';

it( 'astralArgs quotes paths on Windows', () => {
const run = { astralTree: { path: 'C:\\in\\genes.tre' }, outputDir: 'C:\\out', outputNameSafe: 'run1' };
expect( astralArgs( run, { windows: true } ) ).toEqual( [
['-i', '"C:\\in\\genes.tre"', '-o', '"C:\\out\\ASTRAL_run1.tre"'],
] );
} );

it( 'astralArgs leaves paths bare off Windows', () => {
const run = { astralTree: { path: '/in/genes.tre' }, outputDir: '/out', outputNameSafe: 'run1' };
expect( astralArgs( run, { windows: false } ) ).toEqual( [
['-i', '/in/genes.tre', '-o', '/out/ASTRAL_run1.tre'],
] );
} );
20 changes: 20 additions & 0 deletions src/app/store/command/astral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { join, quote } from '../../paths';
import type { Platform } from './index';

export interface AstralInput {
outputDir: string;
outputNameSafe: string;
astralTree: { path: string } | null | undefined;
}

export const astralArgs = ( run: AstralInput, { windows }: Platform ): string[][] => {
const first: string[] = [];
if ( run.astralTree ) {
first.push( '-i', quote( run.astralTree.path, { windows } ) );
}
first.push(
'-o',
quote( join( run.outputDir, `ASTRAL_${run.outputNameSafe}.tre` ), { windows } ),
);
return [first];
};
42 changes: 42 additions & 0 deletions src/app/store/command/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// A CLI argument: seeds and thread counts are pushed as numbers.
export type CmdArg = string | number;

// Shaped like the second argument `quote` takes.
export interface Platform {
windows: boolean;
}

export const commandText = ( binary: string, args: CmdArg[][], usesAstral: boolean ): string => {
if ( usesAstral ) {
return args
.map( ( cmdArgs ) => `java -jar ${binary} ${cmdArgs.join( ' ' )}` )
.join( ' &&\\\n' );
}
return args
.map( ( cmdArgs ) => `${binary} ${cmdArgs.join( ' ' )}` )
.join( ' &&\\\n' );
};

export const settingsText = ( { appVersion, analysisTitle, binary, outputDir, args }: {
appVersion: string | undefined;
analysisTitle: string;
binary: { value: string; version: string | undefined };
outputDir: string;
args: CmdArg[][];
} ): string => {
let text = `The analysis was run using raxmlGUI 2.0 (version ${appVersion}) as follows:
Analysis: ${analysisTitle}
Binary: ${binary.value} version ${binary.version}
Results saved to: ${outputDir}
`;
let argumentext = 'RAxML was called with these arguments:\n';
args.map(
( arg, index ) => ( argumentext += `${index + 1}.) ${arg.join( ' ' )}\n` ),
);
text += argumentext;
// TODO: should we be more precise about what the single params mean?
// text += `To repeat the analysis use the following seeds:
// Bootstrap seed: ${this.seedBootstrap}
// Parsimony seed: ${this.seedParsimony}`;
return text;
};
29 changes: 29 additions & 0 deletions src/app/store/command/modeltestNg.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, it } from 'vitest';

import { modeltestNgArgs } from './modeltestNg';

it( 'modeltestNgArgs quotes paths on Windows', () => {
const run = {
dataType: 'protein',
finalAlignment: { path: 'C:\\in\\aln.phy' },
outputDir: 'C:\\out',
outputNameSafe: 'run1',
numThreads: { value: 4 },
};
expect( modeltestNgArgs( run, { windows: true } ) ).toEqual( [
['-d', 'aa', '-i', '"C:\\in\\aln.phy"', '-o', '"C:\\out\\RAxML_GUI_ModelTest_run1"', '--force', '-p', 4],
] );
} );

it( 'modeltestNgArgs leaves paths bare off Windows', () => {
const run = {
dataType: 'nucleotide',
finalAlignment: { path: '/in/aln.phy' },
outputDir: '/out',
outputNameSafe: 'run1',
numThreads: { value: 2 },
};
expect( modeltestNgArgs( run, { windows: false } ) ).toEqual( [
['-d', 'nt', '-i', '/in/aln.phy', '-o', '/out/RAxML_GUI_ModelTest_run1', '--force', '-p', 2],
] );
} );
35 changes: 35 additions & 0 deletions src/app/store/command/modeltestNg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { join, quote } from '../../paths';
import type { CmdArg, Platform } from './index';

export interface ModeltestNgInput {
outputDir: string;
outputNameSafe: string;
dataType: string | undefined;
finalAlignment: { path: string };
numThreads: { value: number };
}

export const modeltestNgArgs = ( run: ModeltestNgInput, { windows }: Platform ): CmdArg[][] => {
const first: CmdArg[] = [];
// data type
if ( run.dataType === 'nucleotide' ) {
first.push( '-d', 'nt' );
} else if ( run.dataType === 'protein' ) {
first.push( '-d', 'aa' );
}
// alignment file
first.push( '-i', quote( run.finalAlignment.path, { windows } ) );
// output file, modeltest errors if this file already exists
first.push(
'-o',
quote( join( run.outputDir, `RAxML_GUI_ModelTest_${run.outputNameSafe}` ), { windows } ),
);
// modeltest throws errors if the output file already exists
first.push( '--force' );
// Number of processors
first.push( '-p', run.numThreads.value );
// TODO: in able to support partitioned modeltest we need to change the partition file text
// https://github.com/ddarriba/modeltest/wiki/Input-Data#partition-files
// partition scheme
return [first];
};
Loading