diff --git a/src/app/store/Run.ts b/src/app/store/Run.ts index e80b5d03..9a232252 100644 --- a/src/app/store/Run.ts +++ b/src/app/store/Run.ts @@ -7,10 +7,8 @@ import FinalAlignment from './FinalAlignment'; import AstralTree from './AstralTree'; import StoreBase, { runEvents } from './StoreBase'; import { host } from './host'; -import { commandText, settingsText } from './command'; +import { commandArgs, commandText, settingsText } from './command'; import type { CmdArg } from './command'; -import { astralArgs } from './command/astral'; -import { modeltestNgArgs } from './command/modeltestNg'; import { binaries, analysisOptions, @@ -41,8 +39,7 @@ import { } from './RunOptions'; import type { AnalysisChoice } from './RunOptions'; import type { DataType } from '../../common/typecheckAlignment'; -import { basename, join, quote } from '../paths'; -import remove from 'lodash/remove'; +import { basename, join } from '../paths'; import UserFixError from '../../common/errors'; import type { ErrorObject } from 'serialize-error'; import type { AstralSuccessPayload } from '../../main/astral'; @@ -485,16 +482,7 @@ class Run extends StoreBase { }; get args(): CmdArg[][] { - if ( this.usesAstral ) { - return astralArgs( this, { windows } ); - } - if ( this.usesModeltestNg ) { - return modeltestNgArgs( this, { windows } ); - } - if ( this.usesRaxmlNg ) { - return this.raxmlNgArgs(); - } - return this.raxmlArgs(); + return commandArgs( this, { windows } ); } get ngSubstitutionModelCmd(): string { @@ -572,701 +560,6 @@ class Run extends StoreBase { return model; } - raxmlNgArgs = (): CmdArg[][] => { - const first: CmdArg[] = []; - const second: CmdArg[] = []; - const third: CmdArg[] = []; - const cmdArgs = [first, second, third]; // Possibly empty ones removed in the end - switch ( this.analysis.value ) { - case 'SC': - // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#preparing-the-alignment - first.push( '--check' ); - if ( this.havePartitionFile ) { - first.push( '--model', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '--model', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } else { - first.push( '--model', this.ngSubstitutionModelCmd ); - } - first.push( - '--prefix', - quote( join( this.outputDir, this.outputNameSafe ), { windows } ), - ); - first.push( '--msa', quote( this.finalAlignment.path, { windows } ) ); - if ( this.backboneConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.backboneConstraint.filePath, { windows } ), - ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.multifurcatingConstraint.filePath, { windows } ), - ); - } - break; - case 'CC': - // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#preparing-the-alignment - first.push( '--parse' ); - if ( this.havePartitionFile ) { - first.push( '--model', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '--model', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } else { - first.push( '--model', this.ngSubstitutionModelCmd ); - } - first.push( - '--prefix', - quote( join( this.outputDir, this.outputNameSafe ), { windows } ), - ); - first.push( '--msa', quote( this.finalAlignment.path, { windows } ) ); - if ( this.backboneConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.backboneConstraint.filePath, { windows } ), - ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.multifurcatingConstraint.filePath, { windows } ), - ); - } - break; - case 'TI': - // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#tree-inference - first.push( '--msa', quote( this.finalAlignment.path, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '--model', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '--model', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } else { - first.push( '--model', this.ngSubstitutionModelCmd ); - } - first.push( - '--prefix', - quote( join( this.outputDir, this.outputNameSafe ), { windows } ), - ); - if ( !this.numThreads.notAvailable ) { - first.push( '--threads', this.numThreads.value ); - } - first.push( '--seed', this.seedParsimony ); - if ( this.outGroup.cmdValue ) { - first.push( '--outgroup', this.outGroup.cmdValue ); - } - first.push( '--tree', `rand{${this.numRuns.value}}` ); - if ( this.backboneConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.backboneConstraint.filePath, { windows } ), - ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.multifurcatingConstraint.filePath, { windows } ), - ); - } - break; - case 'ML+tBS+con': - // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#bootstrapping - // raxml-ng --all --msa prim.phy --model GTR+G --prefix T15 --seed 2 --threads 2 --bs-metric fbp,tbe - first.push( '--all' ); - first.push( '--msa', quote( this.finalAlignment.path, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '--model', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '--model', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } else { - first.push( '--model', this.ngSubstitutionModelCmd ); - } - first.push( - '--prefix', - quote( join( this.outputDir, this.outputNameSafe ), { windows } ), - ); - first.push( '--seed', this.seedParsimony ); - if ( !this.numThreads.notAvailable ) { - first.push( '--threads', this.numThreads.value ); - } - if ( this.outGroup.cmdValue ) { - first.push( '--outgroup', this.outGroup.cmdValue ); - } - first.push( '--bs-metric', 'fbp' ); - first.push( '--tree', `rand{${this.numRuns.value}}` ); - first.push( '--bs-trees', this.numRepetitionsNg.value ); - if ( this.backboneConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.backboneConstraint.filePath, { windows } ), - ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.multifurcatingConstraint.filePath, { windows } ), - ); - } - break; - case 'ML+TBE+con': - // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#bootstrapping - // raxml-ng --all --msa prim.phy --model GTR+G --prefix T15 --seed 2 --threads 2 --bs-metric fbp,tbe - first.push( '--all' ); - first.push( '--msa', quote( this.finalAlignment.path, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '--model', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '--model', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } else { - first.push( '--model', this.ngSubstitutionModelCmd ); - } - first.push( - '--prefix', - quote( join( this.outputDir, this.outputNameSafe ), { windows } ), - ); - first.push( '--seed', this.seedParsimony ); - if ( !this.numThreads.notAvailable ) { - first.push( '--threads', this.numThreads.value ); - } - if ( this.outGroup.cmdValue ) { - first.push( '--outgroup', this.outGroup.cmdValue ); - } - first.push( '--bs-metric', 'tbe' ); - first.push( '--tree', `rand{${this.numRuns.value}}` ); - first.push( '--bs-trees', this.numRepetitionsNg.value ); - if ( this.backboneConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.backboneConstraint.filePath, { windows } ), - ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( - '--tree-constraint', - quote( this.multifurcatingConstraint.filePath, { windows } ), - ); - } - break; - case 'AS': - // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#bootstrapping - // raxml-ng --all --msa prim.phy --model GTR+G --prefix T15 --seed 2 --threads 2 --bs-metric fbp,tbe - first.push( '--ancestral' ); - first.push( '--msa', quote( this.finalAlignment.path, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '--model', quote( this.partitionFile, { windows } ) ); - } else if ( this.alignments.length > 1 ) { - first.push( '--model', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } else { - first.push( '--model', this.ngSubstitutionModelCmd ); - } - first.push( - '--prefix', - quote( join( this.outputDir, this.outputNameSafe ), { windows } ), - ); - first.push( '--tree', quote( this.tree.filePath, { windows } ) ); - break; - default: - } - // Remove items that are only empty strings - cmdArgs.forEach( ( args ) => remove( args, ( n ) => n === '' ) ); - return cmdArgs.filter( ( args ) => args.length > 0 ); - }; - - raxmlArgs = (): CmdArg[][] => { - const first: CmdArg[] = []; - const second: CmdArg[] = []; - const third: CmdArg[] = []; - const cmdArgs = [first, second, third]; // Possibly empty ones removed in the end - - switch ( this.analysis.value ) { - case 'FT': // Fast tree search - // params: [params.brL, params.SHlike, params.outGroup], - // cmd= """cd %s %s &&%s %s -f E -p %s %s -n %s -s %s -O -w %s %s %s %s %s""" \ - // % (winD, raxml_path, K[0], pro, seed_1, mod, out_file, seq_file, path_dir, part_f, cmd_temp1,cmd_temp2, winEx) - //TODO: Where is outGroup? From line 1436 in original code, -o is unchecked - if ( !this.numThreads.notAvailable ) { - first.push( '-T', this.numThreads.value ); - } - first.push( '-f', 'E' ); - first.push( '-p', this.seedParsimony ); - first.push( '-m', this.raxmlSubstitutionModelCmd ); - first.push( this.substitutionMatrix.extraCmdValue ); - first.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - first.push( '-K', this.multistateModel.value ); - } - if ( this.disableCheckUndeterminedSequence ) { - first.push( '-O' ); - } - if ( this.outGroup.cmdValue ) { - first.push( '-o', this.outGroup.cmdValue ); - } - first.push( '-n', this.outputFilenameSafe ); - first.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - first.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - if ( this.branchLength.value ) { - const treeFile1 = join( - this.outputDir, - `RAxML_fastTree.${this.outputFilenameSafe}`, - ); - const next: CmdArg[] = []; - if ( !this.numThreads.notAvailable ) { - next.push( '-T', this.numThreads.value ); - } - next.push( '-f', 'e' ); - next.push( '-m', this.raxmlSubstitutionModelCmd ); - next.push( this.substitutionMatrix.extraCmdValue ); - next.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - next.push( '-K', this.multistateModel.value ); - } - next.push( '-t', quote( treeFile1, { windows } ) ); - next.push( '-n', `brL.${this.outputFilenameSafe}` ); - next.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - next.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - next.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - next.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - cmdArgs.push( next ); - } - if ( this.sHlike.value ) { - const treeFile2 = this.branchLength.value - ? join( - this.outputDir, - `RAxML_result.brL.${this.outputFilenameSafe}`, - ) - : join( this.outputDir, `RAxML_fastTree.${this.outputFilenameSafe}` ); - const next: CmdArg[] = []; - if ( !this.numThreads.notAvailable ) { - next.push( '-T', this.numThreads.value ); - } - next.push( '-f', 'e' ); - next.push( '-m', this.raxmlSubstitutionModelCmd ); - next.push( this.substitutionMatrix.extraCmdValue ); - next.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - next.push( '-K', this.multistateModel.value ); - } - next.push( '-t', quote( treeFile2, { windows } ) ); - next.push( '-n', `sh.${this.outputFilenameSafe}` ); - next.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - next.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - next.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - next.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - cmdArgs.push( next ); - } - break; - case 'ML': // ML search - // params: [params.SHlike, params.combinedOutput, params.outGroup], - // cmd= """cd %s %s&&%s %s -f d %s -N %s -O -p %s %s -s %s -n %s %s -w %s %s %s %s %s %s""" \ - // % (winD, raxml_path, K[0], pro, mod, BSrep2.get(), random.randrange(1, 1000, 1), o, seq_file, out_file, part_f, path_dir, const_f, result2, cmd_temp2, combine_trees, winEx) - //TODO: Check conf_f (from line 754 in original source) - if ( !this.numThreads.notAvailable ) { - first.push( '-T', this.numThreads.value ); - } - first.push( '-f', 'd' ); - first.push( '-m', this.raxmlSubstitutionModelCmd ); - first.push( this.substitutionMatrix.extraCmdValue ); - first.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - first.push( '-K', this.multistateModel.value ); - } - first.push( '-N', this.numRuns.value ); - if ( this.disableCheckUndeterminedSequence ) { - first.push( '-O' ); - } - first.push( '-p', this.seedParsimony ); - first.push( '-n', this.outputFilenameSafe ); - if ( this.outGroup.cmdValue ) { - first.push( '-o', this.outGroup.cmdValue ); - } - first.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - first.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - if ( this.backboneConstraint.isSet ) { - first.push( '-r', quote( this.backboneConstraint.filePath, { windows } ) ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( '-g', quote( this.multifurcatingConstraint.filePath, { windows } ) ); - } - if ( this.sHlike.value ) { - const treeFile = join( - this.outputDir, - `RAxML_bestTree.${this.outputFilenameSafe}`, - ); - const next: CmdArg[] = []; - if ( !this.numThreads.notAvailable ) { - next.push( '-T', this.numThreads.value ); - } - next.push( '-f', 'e' ); - next.push( '-m', this.raxmlSubstitutionModelCmd ); - next.push( this.substitutionMatrix.extraCmdValue ); - next.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - next.push( '-K', this.multistateModel.value ); - } - next.push( '-t', quote( treeFile, { windows } ) ); - next.push( '-n', `sh.${this.outputFilenameSafe}` ); - next.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - next.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - next.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - next.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - cmdArgs.push( next ); - } - break; - case 'ML+rBS': // ML + rapid bootstrap - // params: [params.reps, params.brL, params.outGroup], - // cmd= """cd %s %s&& %s %s %s -f a -x %s %s %s -p %s -N %s %s -s %s -n %s %s -O -w %s %s %s %s""" \ - // % (winD, raxml_path, runWin, K[0], pro, seed_1, save_brL.get(),mod, seed_2, BSrep.get(), o, seq_file, out_file, \ - // part_f, path_dir, const_f, result, winEx) - if ( !this.numThreads.notAvailable ) { - first.push( '-T', this.numThreads.value ); - } - first.push( '-f', 'a' ); - first.push( '-x', this.seedRapidBootstrap ); - first.push( '-p', this.seedParsimony ); - first.push( '-N', this.numRepetitions.value ); - first.push( '-m', this.raxmlSubstitutionModelCmd ); - first.push( this.substitutionMatrix.extraCmdValue ); - first.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - first.push( '-K', this.multistateModel.value ); - } - if ( this.branchLength.value ) { - first.push( '-k' ); - } - if ( this.disableCheckUndeterminedSequence ) { - first.push( '-O' ); - } - if ( this.outGroup.cmdValue ) { - first.push( '-o', this.outGroup.cmdValue ); - } - first.push( '-n', this.outputFilenameSafe ); - first.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - first.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - if ( this.backboneConstraint.isSet ) { - first.push( '-r', quote( this.backboneConstraint.filePath, { windows } ) ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( '-g', quote( this.multifurcatingConstraint.filePath, { windows } ) ); - } - break; - case 'ML+tBS': { // ML + thorough bootstrap - // params: [params.runs, params.reps, params.brL, params.outGroup], - // cmd= """cd %s %s \ - // &&%s %s -b %s %s %s -p %s -N %s %s -s %s -n %s %s -w %s %s -O && cd %s \ - // &&%s %s -f d %s %s -s %s -N %s -n %s %s -w %s %s -p %s -O && cd %s \ - // &&%s %s -f b -t %s -z %s %s -s %s -n %s -w %s %s -O %s""" \ - // % (winD, raxml_path, K[0], pro, seed_1, mod, save_brL.get(),seed_2, BSrep.get(), o, seq_file, out_file1, part_f, path_dir, const_f,\ - // raxml_path, K[0], pro, mod, o, seq_file, BSrep2.get(), out_file2, part_f, path_dir, const_f,random.randrange(1, 1000, 1), \ - // raxml_path, K[0], pro, MLtreeR, trees, mod, seq_file, out_file, path_dir, result, winEx) - // try: - // remove="RAxML_info.%s.tre" % (only_name) - // ... - const outputFilenameSafe1 = `${this.outputNameSafe}R.tre`; - const outputFilenameSafe2 = `${this.outputNameSafe}B.tre`; - const treeFile = join( - this.outputDir, - `RAxML_bestTree.${outputFilenameSafe2}`, - ); // MLtreeR - const treesFile = join( - this.outputDir, - `RAxML_bootstrap.${outputFilenameSafe1}`, - ); // trees - // first wrote RAxML_bootstrap.binary_8R.tre - // second wrote RAxML_bootstrap.binary_8B.tre - - if ( !this.numThreads.notAvailable ) { - first.push( '-T', this.numThreads.value ); - } - first.push( '-b', this.seedBootstrap ); - first.push( '-m', this.raxmlSubstitutionModelCmd ); - first.push( this.substitutionMatrix.extraCmdValue ); - first.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - first.push( '-K', this.multistateModel.value ); - } - if ( this.branchLength.value ) { - first.push( '-k' ); - } - first.push( '-p', this.seedParsimony ); - first.push( '-N', this.numRepetitions.value ); - if ( this.disableCheckUndeterminedSequence ) { - first.push( '-O' ); - } - if ( this.outGroup.cmdValue ) { - first.push( '-o', this.outGroup.cmdValue ); - } - first.push( '-n', outputFilenameSafe1 ); - first.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - first.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - if ( this.backboneConstraint.isSet ) { - first.push( '-r', quote( this.backboneConstraint.filePath, { windows } ) ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( '-g', quote( this.multifurcatingConstraint.filePath, { windows } ) ); - } - - if ( !this.numThreads.notAvailable ) { - second.push( '-T', this.numThreads.value ); - } - second.push( '-f', 'd' ); - second.push( '-m', this.raxmlSubstitutionModelCmd ); - second.push( this.substitutionMatrix.extraCmdValue ); - second.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - second.push( '-K', this.multistateModel.value ); - } - second.push( '-p', this.seedParsimony ); - second.push( '-N', this.numRuns.value ); - if ( this.disableCheckUndeterminedSequence ) { - second.push( '-O' ); - } - if ( this.outGroup.cmdValue ) { - second.push( '-o', this.outGroup.cmdValue ); - } - second.push( '-n', outputFilenameSafe2 ); - second.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - second.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - second.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - second.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - if ( this.backboneConstraint.isSet ) { - second.push( '-r', quote( this.backboneConstraint.filePath, { windows } ) ); - } - if ( this.multifurcatingConstraint.isSet ) { - second.push( '-g', quote( this.multifurcatingConstraint.filePath, { windows } ) ); - } - - if ( !this.numThreads.notAvailable ) { - third.push( '-T', this.numThreads.value ); - } - third.push( '-f', 'b' ); - third.push( '-t', quote( treeFile, { windows } ) ); - third.push( '-z', quote( treesFile, { windows } ) ); - third.push( '-m', this.raxmlSubstitutionModelCmd ); - third.push( this.substitutionMatrix.extraCmdValue ); - third.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - third.push( '-K', this.multistateModel.value ); - } - if ( this.disableCheckUndeterminedSequence ) { - third.push( '-O' ); - } - third.push( '-n', this.outputFilenameSafe ); - third.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - third.push( '-w', quote( this.outputDir, { windows } ) ); - - break; - } - case 'BS+con': { // Bootstrap + consensus - // params: [params.reps, params.brL, params.outGroup], - // BStrees_file= """ "%sRAxML_bootstrap.%s" """ % (path_dirsimple, out_file) - // cmd= """cd %s %s \ - // && %s %s %s %s -n %s -s %s %s -x %s -N %s -w %s %s %s -p %s -O && cd %s\ - // && %s %s %s -n con.%s -J MR -z %s -w %s %s - // """ \ - // % (winD, raxml_path, \ - // K[0], pro, mod, save_brL.get(), out_file, seq_file, o, seed_1, BSrep.get(), path_dir, part_f, const_f, random.randrange(1, 1000, 1), raxml_path, \ - // K[0], pro, mod, out_file, BStrees_file, path_dir, winEx) - - const bsTreeFile = join( - this.outputDir, - `RAxML_bootstrap.${this.outputFilenameSafe}`, - ); - const consensusOutput = `consensus.${this.outputFilenameSafe}`; - - if ( !this.numThreads.notAvailable ) { - first.push( '-T', this.numThreads.value ); - } - if ( this.branchLength.value ) { - first.push( '-k' ); - } - first.push( '-x', this.seedRapidBootstrap ); - first.push( '-p', this.seedParsimony ); - first.push( '-N', this.numRepetitions.value ); - first.push( '-m', this.raxmlSubstitutionModelCmd ); - first.push( this.substitutionMatrix.extraCmdValue ); - first.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - first.push( '-K', this.multistateModel.value ); - } - if ( this.disableCheckUndeterminedSequence ) { - first.push( '-O' ); - } - if ( this.outGroup.cmdValue ) { - first.push( '-o', this.outGroup.cmdValue ); - } - first.push( '-n', this.outputFilenameSafe ); - first.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - first.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - if ( this.backboneConstraint.isSet ) { - first.push( '-r', quote( this.backboneConstraint.filePath, { windows } ) ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( '-g', quote( this.multifurcatingConstraint.filePath, { windows } ) ); - } - - if ( !this.numThreads.notAvailable ) { - second.push( '-T', this.numThreads.value ); - } - second.push( '-m', this.raxmlSubstitutionModelCmd ); - second.push( this.substitutionMatrix.extraCmdValue ); - second.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - second.push( '-K', this.multistateModel.value ); - } - second.push( '-J', 'MR' ); - second.push( '-w', quote( this.outputDir, { windows } ) ); - second.push( '-z', quote( bsTreeFile, { windows } ) ); - second.push( '-n', consensusOutput ); - if ( this.backboneConstraint.isSet ) { - second.push( '-r', quote( this.backboneConstraint.filePath, { windows } ) ); - } - if ( this.multifurcatingConstraint.isSet ) { - second.push( '-g', quote( this.multifurcatingConstraint.filePath, { windows } ) ); - } - break; - } - case 'AS': // Ancestral states - // params: [params.tree], - // cmd = """cd %s %s &&%s %s -f A -t "%s" -s %s %s -n %s -O -w %s %s %s""" \ - // % (winD, raxml_path, K[0], pro, rooted_tree, seq_file, mod, out_file, path_dir, part_f, winEx) - if ( !this.numThreads.notAvailable ) { - first.push( '-T', this.numThreads.value ); - } - first.push( '-f', 'A' ); - first.push( '-t', quote( this.tree.filePath, { windows } ) ); - first.push( '-m', this.raxmlSubstitutionModelCmd ); - first.push( this.substitutionMatrix.extraCmdValue ); - first.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - first.push( '-K', this.multistateModel.value ); - } - first.push( '-n', this.outputFilenameSafe ); - first.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - first.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - break; - case 'PD': // Pairwise distances - // params: [params.startingTree], - // # "./raxmlHPC -f x -m GTRGAMMA[I] -n NAME -s INPUT -p RANDOMNR [-q PARTFILE -o OUTGROUP]" - // cmd = """cd %s %s &&%s %s -f x -p %s %s -s %s %s -n %s %s -O -w %s %s %s""" \ - // % (winD, raxml_path, K[0], pro, seed_1, const_f, seq_file, mod, out_file, o, path_dir, part_f, winEx) - if ( !this.numThreads.notAvailable ) { - first.push( '-T', this.numThreads.value ); - } - first.push( '-f', 'x' ); - first.push( '-p', this.seedParsimony ); - first.push( '-m', this.raxmlSubstitutionModelCmd ); - first.push( this.substitutionMatrix.extraCmdValue ); - first.push( this.substitutionAscertainment.extraCmdValue ); - if ( !this.multistateModel.notAvailable ) { - first.push( '-K', this.multistateModel.value ); - } - if ( this.disableCheckUndeterminedSequence ) { - first.push( '-O' ); - } - if ( !this.tree.notAvailable ) { - first.push( '-t', quote( this.tree.filePath, { windows } ) ); - } - first.push( '-n', this.outputFilenameSafe ); - first.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - first.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - break; - case 'RBS': // Rell bootstraps - // params: [params.reps, params.brL, params.outGroup], - // # "./raxmlHPC -f x -m GTRGAMMA[I] -n NAME -s INPUT -p RANDOMNR [-q PARTFILE -o OUTGROUP]" - // cmd = """cd %s %s &&%s %s -f D -p %s %s -s %s %s -n %s %s -O -w %s %s %s""" \ - // % (winD, raxml_path, K[0], pro, seed_1, const_f, seq_file, mod, out_file, o, path_dir, part_f, winEx) - if ( !this.numThreads.notAvailable ) { - first.push( '-T', this.numThreads.value ); - } - first.push( '-f', 'D' ); - first.push( '-p', this.seedParsimony ); - first.push( '-m', this.raxmlSubstitutionModelCmd ); - first.push( this.substitutionMatrix.extraCmdValue ); - first.push( this.substitutionAscertainment.extraCmdValue ); - if ( this.branchLength.value ) { - first.push( '-k' ); - } - if ( this.outGroup.cmdValue ) { - first.push( '-o', this.outGroup.cmdValue ); - } - if ( !this.multistateModel.notAvailable ) { - first.push( '-K', this.multistateModel.value ); - } - if ( this.disableCheckUndeterminedSequence ) { - first.push( '-O' ); - } - first.push( '-n', this.outputFilenameSafe ); - first.push( '-s', quote( this.finalAlignment.path, { windows } ) ); - // if (!this.tree.notAvailable) { - // first.push('-t', this.tree.filePath); - // } - first.push( '-w', quote( this.outputDir, { windows } ) ); - if ( this.havePartitionFile ) { - first.push( '-q', quote( this.partitionFile, { windows } ) ); - } else if ( !this.finalAlignment.partition.isDefault ) { - first.push( '-q', quote( this.finalAlignment.partitionFilePath, { windows } ) ); - } - if ( this.backboneConstraint.isSet ) { - first.push( '-r', quote( this.backboneConstraint.filePath, { windows } ) ); - } - if ( this.multifurcatingConstraint.isSet ) { - first.push( '-g', quote( this.multifurcatingConstraint.filePath, { windows } ) ); - } - break; - default: - } - // Remove items that are only empty strings - cmdArgs.forEach( ( args ) => remove( args, ( n ) => n === '' ) ); - return cmdArgs.filter( ( args ) => args.length > 0 ); - }; - get command(): string { return commandText( this.binary.value, this.args, this.usesAstral ); } diff --git a/src/app/store/command/index.ts b/src/app/store/command/index.ts index 40e960af..295a9fb2 100644 --- a/src/app/store/command/index.ts +++ b/src/app/store/command/index.ts @@ -1,3 +1,12 @@ +import { astralArgs } from './astral'; +import type { AstralInput } from './astral'; +import { modeltestNgArgs } from './modeltestNg'; +import type { ModeltestNgInput } from './modeltestNg'; +import { raxmlArgs } from './raxml'; +import type { RaxmlInput } from './raxml'; +import { raxmlNgArgs } from './raxmlNg'; +import type { RaxmlNgInput } from './raxmlNg'; + // A CLI argument: seeds and thread counts are pushed as numbers. export type CmdArg = string | number; @@ -6,6 +15,43 @@ export interface Platform { windows: boolean; } +// The partition choice, read by both RAxML builders. +export interface PartitionInput { + havePartitionFile: boolean; + partitionFile: string; + finalAlignment: { + path: string; + partitionFilePath: string; + partition: { isDefault: boolean }; + }; +} + +// The two constraint trees, read by both RAxML builders. +export interface ConstraintInput { + backboneConstraint: { isSet: boolean; filePath: string }; + multifurcatingConstraint: { isSet: boolean; filePath: string }; +} + +// An intersection, not `extends`: the builders read different parts of `tree`. +export type CommandInput = AstralInput & ModeltestNgInput & RaxmlNgInput & RaxmlInput & { + usesAstral: boolean; + usesModeltestNg: boolean; + usesRaxmlNg: boolean; +}; + +export const commandArgs = ( run: CommandInput, platform: Platform ): CmdArg[][] => { + if ( run.usesAstral ) { + return astralArgs( run, platform ); + } + if ( run.usesModeltestNg ) { + return modeltestNgArgs( run, platform ); + } + if ( run.usesRaxmlNg ) { + return raxmlNgArgs( run, platform ); + } + return raxmlArgs( run, platform ); +}; + export const commandText = ( binary: string, args: CmdArg[][], usesAstral: boolean ): string => { if ( usesAstral ) { return args diff --git a/src/app/store/command/raxml.test.ts b/src/app/store/command/raxml.test.ts new file mode 100644 index 00000000..440766a4 --- /dev/null +++ b/src/app/store/command/raxml.test.ts @@ -0,0 +1,96 @@ +import { expect, it } from 'vitest'; + +import { raxmlArgs } from './raxml'; + +const base = { + analysis: { value: 'PD' }, + outputNameSafe: 'run1', + outputFilenameSafe: 'run1.tre', + raxmlSubstitutionModelCmd: 'GTRGAMMA', + numThreads: { notAvailable: false, value: 2 }, + seedParsimony: 123, + seedRapidBootstrap: 456, + seedBootstrap: 789, + // Empty extra values are dropped from the command + substitutionMatrix: { extraCmdValue: '' }, + substitutionAscertainment: { extraCmdValue: '' }, + multistateModel: { notAvailable: true, value: '' }, + disableCheckUndeterminedSequence: true, + outGroup: { cmdValue: '' }, + branchLength: { value: false }, + sHlike: { value: false }, + numRuns: { value: 1 }, + numRepetitions: { value: 100 }, + backboneConstraint: { isSet: false, filePath: '' }, + multifurcatingConstraint: { isSet: false, filePath: '' }, +}; + +it( 'raxmlArgs quotes paths on Windows', () => { + const run = { + ...base, + havePartitionFile: true, + partitionFile: 'C:\\in\\my.part', + finalAlignment: { + path: 'C:\\in\\aln.phy', + partitionFilePath: 'C:\\in\\aln.part', + partition: { isDefault: true }, + }, + outputDir: 'C:\\out', + tree: { notAvailable: false, filePath: 'C:\\in\\start.tre' }, + }; + expect( raxmlArgs( run, { windows: true } ) ).toEqual( [[ + '-T', + 2, + '-f', + 'x', + '-p', + 123, + '-m', + 'GTRGAMMA', + '-O', + '-t', + '"C:\\in\\start.tre"', + '-n', + 'run1.tre', + '-s', + '"C:\\in\\aln.phy"', + '-w', + '"C:\\out"', + '-q', + '"C:\\in\\my.part"', + ]] ); +} ); + +it( 'raxmlArgs leaves paths bare off Windows', () => { + const run = { + ...base, + havePartitionFile: false, + partitionFile: '', + finalAlignment: { + path: '/in/aln.phy', + partitionFilePath: '/in/aln.part', + partition: { isDefault: false }, + }, + outputDir: '/out', + tree: { notAvailable: true, filePath: '' }, + }; + expect( raxmlArgs( run, { windows: false } ) ).toEqual( [[ + '-T', + 2, + '-f', + 'x', + '-p', + 123, + '-m', + 'GTRGAMMA', + '-O', + '-n', + 'run1.tre', + '-s', + '/in/aln.phy', + '-w', + '/out', + '-q', + '/in/aln.part', + ]] ); +} ); diff --git a/src/app/store/command/raxml.ts b/src/app/store/command/raxml.ts new file mode 100644 index 00000000..3d85896b --- /dev/null +++ b/src/app/store/command/raxml.ts @@ -0,0 +1,521 @@ +import remove from 'lodash/remove'; + +import { join, quote } from '../../paths'; +import type { CmdArg, ConstraintInput, PartitionInput, Platform } from './index'; + +export interface RaxmlInput extends PartitionInput, ConstraintInput { + outputDir: string; + outputNameSafe: string; + analysis: { value: string }; + outputFilenameSafe: string; + raxmlSubstitutionModelCmd: string; + numThreads: { notAvailable: boolean; value: number }; + seedParsimony: number; + seedRapidBootstrap: number; + seedBootstrap: number; + substitutionMatrix: { extraCmdValue: string }; + substitutionAscertainment: { extraCmdValue: string }; + multistateModel: { notAvailable: boolean; value: string }; + disableCheckUndeterminedSequence: boolean; + outGroup: { cmdValue: string }; + branchLength: { value: boolean }; + sHlike: { value: boolean }; + numRuns: { value: number }; + numRepetitions: { value: number | string }; + tree: { notAvailable: boolean; filePath: string }; +} + +export const raxmlArgs = ( run: RaxmlInput, { windows }: Platform ): CmdArg[][] => { + const first: CmdArg[] = []; + const second: CmdArg[] = []; + const third: CmdArg[] = []; + const cmdArgs = [first, second, third]; // Possibly empty ones removed in the end + + switch ( run.analysis.value ) { + case 'FT': // Fast tree search + // params: [params.brL, params.SHlike, params.outGroup], + // cmd= """cd %s %s &&%s %s -f E -p %s %s -n %s -s %s -O -w %s %s %s %s %s""" \ + // % (winD, raxml_path, K[0], pro, seed_1, mod, out_file, seq_file, path_dir, part_f, cmd_temp1,cmd_temp2, winEx) + //TODO: Where is outGroup? From line 1436 in original code, -o is unchecked + if ( !run.numThreads.notAvailable ) { + first.push( '-T', run.numThreads.value ); + } + first.push( '-f', 'E' ); + first.push( '-p', run.seedParsimony ); + first.push( '-m', run.raxmlSubstitutionModelCmd ); + first.push( run.substitutionMatrix.extraCmdValue ); + first.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + first.push( '-K', run.multistateModel.value ); + } + if ( run.disableCheckUndeterminedSequence ) { + first.push( '-O' ); + } + if ( run.outGroup.cmdValue ) { + first.push( '-o', run.outGroup.cmdValue ); + } + first.push( '-n', run.outputFilenameSafe ); + first.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + first.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + if ( run.branchLength.value ) { + const treeFile1 = join( + run.outputDir, + `RAxML_fastTree.${run.outputFilenameSafe}`, + ); + const next: CmdArg[] = []; + if ( !run.numThreads.notAvailable ) { + next.push( '-T', run.numThreads.value ); + } + next.push( '-f', 'e' ); + next.push( '-m', run.raxmlSubstitutionModelCmd ); + next.push( run.substitutionMatrix.extraCmdValue ); + next.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + next.push( '-K', run.multistateModel.value ); + } + next.push( '-t', quote( treeFile1, { windows } ) ); + next.push( '-n', `brL.${run.outputFilenameSafe}` ); + next.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + next.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + next.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + next.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + cmdArgs.push( next ); + } + if ( run.sHlike.value ) { + const treeFile2 = run.branchLength.value + ? join( + run.outputDir, + `RAxML_result.brL.${run.outputFilenameSafe}`, + ) + : join( run.outputDir, `RAxML_fastTree.${run.outputFilenameSafe}` ); + const next: CmdArg[] = []; + if ( !run.numThreads.notAvailable ) { + next.push( '-T', run.numThreads.value ); + } + next.push( '-f', 'e' ); + next.push( '-m', run.raxmlSubstitutionModelCmd ); + next.push( run.substitutionMatrix.extraCmdValue ); + next.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + next.push( '-K', run.multistateModel.value ); + } + next.push( '-t', quote( treeFile2, { windows } ) ); + next.push( '-n', `sh.${run.outputFilenameSafe}` ); + next.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + next.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + next.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + next.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + cmdArgs.push( next ); + } + break; + case 'ML': // ML search + // params: [params.SHlike, params.combinedOutput, params.outGroup], + // cmd= """cd %s %s&&%s %s -f d %s -N %s -O -p %s %s -s %s -n %s %s -w %s %s %s %s %s %s""" \ + // % (winD, raxml_path, K[0], pro, mod, BSrep2.get(), random.randrange(1, 1000, 1), o, seq_file, out_file, part_f, path_dir, const_f, result2, cmd_temp2, combine_trees, winEx) + //TODO: Check conf_f (from line 754 in original source) + if ( !run.numThreads.notAvailable ) { + first.push( '-T', run.numThreads.value ); + } + first.push( '-f', 'd' ); + first.push( '-m', run.raxmlSubstitutionModelCmd ); + first.push( run.substitutionMatrix.extraCmdValue ); + first.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + first.push( '-K', run.multistateModel.value ); + } + first.push( '-N', run.numRuns.value ); + if ( run.disableCheckUndeterminedSequence ) { + first.push( '-O' ); + } + first.push( '-p', run.seedParsimony ); + first.push( '-n', run.outputFilenameSafe ); + if ( run.outGroup.cmdValue ) { + first.push( '-o', run.outGroup.cmdValue ); + } + first.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + first.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + if ( run.backboneConstraint.isSet ) { + first.push( '-r', quote( run.backboneConstraint.filePath, { windows } ) ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( '-g', quote( run.multifurcatingConstraint.filePath, { windows } ) ); + } + if ( run.sHlike.value ) { + const treeFile = join( + run.outputDir, + `RAxML_bestTree.${run.outputFilenameSafe}`, + ); + const next: CmdArg[] = []; + if ( !run.numThreads.notAvailable ) { + next.push( '-T', run.numThreads.value ); + } + next.push( '-f', 'e' ); + next.push( '-m', run.raxmlSubstitutionModelCmd ); + next.push( run.substitutionMatrix.extraCmdValue ); + next.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + next.push( '-K', run.multistateModel.value ); + } + next.push( '-t', quote( treeFile, { windows } ) ); + next.push( '-n', `sh.${run.outputFilenameSafe}` ); + next.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + next.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + next.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + next.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + cmdArgs.push( next ); + } + break; + case 'ML+rBS': // ML + rapid bootstrap + // params: [params.reps, params.brL, params.outGroup], + // cmd= """cd %s %s&& %s %s %s -f a -x %s %s %s -p %s -N %s %s -s %s -n %s %s -O -w %s %s %s %s""" \ + // % (winD, raxml_path, runWin, K[0], pro, seed_1, save_brL.get(),mod, seed_2, BSrep.get(), o, seq_file, out_file, \ + // part_f, path_dir, const_f, result, winEx) + if ( !run.numThreads.notAvailable ) { + first.push( '-T', run.numThreads.value ); + } + first.push( '-f', 'a' ); + first.push( '-x', run.seedRapidBootstrap ); + first.push( '-p', run.seedParsimony ); + first.push( '-N', run.numRepetitions.value ); + first.push( '-m', run.raxmlSubstitutionModelCmd ); + first.push( run.substitutionMatrix.extraCmdValue ); + first.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + first.push( '-K', run.multistateModel.value ); + } + if ( run.branchLength.value ) { + first.push( '-k' ); + } + if ( run.disableCheckUndeterminedSequence ) { + first.push( '-O' ); + } + if ( run.outGroup.cmdValue ) { + first.push( '-o', run.outGroup.cmdValue ); + } + first.push( '-n', run.outputFilenameSafe ); + first.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + first.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + if ( run.backboneConstraint.isSet ) { + first.push( '-r', quote( run.backboneConstraint.filePath, { windows } ) ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( '-g', quote( run.multifurcatingConstraint.filePath, { windows } ) ); + } + break; + case 'ML+tBS': { // ML + thorough bootstrap + // params: [params.runs, params.reps, params.brL, params.outGroup], + // cmd= """cd %s %s \ + // &&%s %s -b %s %s %s -p %s -N %s %s -s %s -n %s %s -w %s %s -O && cd %s \ + // &&%s %s -f d %s %s -s %s -N %s -n %s %s -w %s %s -p %s -O && cd %s \ + // &&%s %s -f b -t %s -z %s %s -s %s -n %s -w %s %s -O %s""" \ + // % (winD, raxml_path, K[0], pro, seed_1, mod, save_brL.get(),seed_2, BSrep.get(), o, seq_file, out_file1, part_f, path_dir, const_f,\ + // raxml_path, K[0], pro, mod, o, seq_file, BSrep2.get(), out_file2, part_f, path_dir, const_f,random.randrange(1, 1000, 1), \ + // raxml_path, K[0], pro, MLtreeR, trees, mod, seq_file, out_file, path_dir, result, winEx) + // try: + // remove="RAxML_info.%s.tre" % (only_name) + // ... + const outputFilenameSafe1 = `${run.outputNameSafe}R.tre`; + const outputFilenameSafe2 = `${run.outputNameSafe}B.tre`; + const treeFile = join( + run.outputDir, + `RAxML_bestTree.${outputFilenameSafe2}`, + ); // MLtreeR + const treesFile = join( + run.outputDir, + `RAxML_bootstrap.${outputFilenameSafe1}`, + ); // trees + // first wrote RAxML_bootstrap.binary_8R.tre + // second wrote RAxML_bootstrap.binary_8B.tre + + if ( !run.numThreads.notAvailable ) { + first.push( '-T', run.numThreads.value ); + } + first.push( '-b', run.seedBootstrap ); + first.push( '-m', run.raxmlSubstitutionModelCmd ); + first.push( run.substitutionMatrix.extraCmdValue ); + first.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + first.push( '-K', run.multistateModel.value ); + } + if ( run.branchLength.value ) { + first.push( '-k' ); + } + first.push( '-p', run.seedParsimony ); + first.push( '-N', run.numRepetitions.value ); + if ( run.disableCheckUndeterminedSequence ) { + first.push( '-O' ); + } + if ( run.outGroup.cmdValue ) { + first.push( '-o', run.outGroup.cmdValue ); + } + first.push( '-n', outputFilenameSafe1 ); + first.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + first.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + if ( run.backboneConstraint.isSet ) { + first.push( '-r', quote( run.backboneConstraint.filePath, { windows } ) ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( '-g', quote( run.multifurcatingConstraint.filePath, { windows } ) ); + } + + if ( !run.numThreads.notAvailable ) { + second.push( '-T', run.numThreads.value ); + } + second.push( '-f', 'd' ); + second.push( '-m', run.raxmlSubstitutionModelCmd ); + second.push( run.substitutionMatrix.extraCmdValue ); + second.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + second.push( '-K', run.multistateModel.value ); + } + second.push( '-p', run.seedParsimony ); + second.push( '-N', run.numRuns.value ); + if ( run.disableCheckUndeterminedSequence ) { + second.push( '-O' ); + } + if ( run.outGroup.cmdValue ) { + second.push( '-o', run.outGroup.cmdValue ); + } + second.push( '-n', outputFilenameSafe2 ); + second.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + second.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + second.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + second.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + if ( run.backboneConstraint.isSet ) { + second.push( '-r', quote( run.backboneConstraint.filePath, { windows } ) ); + } + if ( run.multifurcatingConstraint.isSet ) { + second.push( '-g', quote( run.multifurcatingConstraint.filePath, { windows } ) ); + } + + if ( !run.numThreads.notAvailable ) { + third.push( '-T', run.numThreads.value ); + } + third.push( '-f', 'b' ); + third.push( '-t', quote( treeFile, { windows } ) ); + third.push( '-z', quote( treesFile, { windows } ) ); + third.push( '-m', run.raxmlSubstitutionModelCmd ); + third.push( run.substitutionMatrix.extraCmdValue ); + third.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + third.push( '-K', run.multistateModel.value ); + } + if ( run.disableCheckUndeterminedSequence ) { + third.push( '-O' ); + } + third.push( '-n', run.outputFilenameSafe ); + third.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + third.push( '-w', quote( run.outputDir, { windows } ) ); + + break; + } + case 'BS+con': { // Bootstrap + consensus + // params: [params.reps, params.brL, params.outGroup], + // BStrees_file= """ "%sRAxML_bootstrap.%s" """ % (path_dirsimple, out_file) + // cmd= """cd %s %s \ + // && %s %s %s %s -n %s -s %s %s -x %s -N %s -w %s %s %s -p %s -O && cd %s\ + // && %s %s %s -n con.%s -J MR -z %s -w %s %s + // """ \ + // % (winD, raxml_path, \ + // K[0], pro, mod, save_brL.get(), out_file, seq_file, o, seed_1, BSrep.get(), path_dir, part_f, const_f, random.randrange(1, 1000, 1), raxml_path, \ + // K[0], pro, mod, out_file, BStrees_file, path_dir, winEx) + + const bsTreeFile = join( + run.outputDir, + `RAxML_bootstrap.${run.outputFilenameSafe}`, + ); + const consensusOutput = `consensus.${run.outputFilenameSafe}`; + + if ( !run.numThreads.notAvailable ) { + first.push( '-T', run.numThreads.value ); + } + if ( run.branchLength.value ) { + first.push( '-k' ); + } + first.push( '-x', run.seedRapidBootstrap ); + first.push( '-p', run.seedParsimony ); + first.push( '-N', run.numRepetitions.value ); + first.push( '-m', run.raxmlSubstitutionModelCmd ); + first.push( run.substitutionMatrix.extraCmdValue ); + first.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + first.push( '-K', run.multistateModel.value ); + } + if ( run.disableCheckUndeterminedSequence ) { + first.push( '-O' ); + } + if ( run.outGroup.cmdValue ) { + first.push( '-o', run.outGroup.cmdValue ); + } + first.push( '-n', run.outputFilenameSafe ); + first.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + first.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + if ( run.backboneConstraint.isSet ) { + first.push( '-r', quote( run.backboneConstraint.filePath, { windows } ) ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( '-g', quote( run.multifurcatingConstraint.filePath, { windows } ) ); + } + + if ( !run.numThreads.notAvailable ) { + second.push( '-T', run.numThreads.value ); + } + second.push( '-m', run.raxmlSubstitutionModelCmd ); + second.push( run.substitutionMatrix.extraCmdValue ); + second.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + second.push( '-K', run.multistateModel.value ); + } + second.push( '-J', 'MR' ); + second.push( '-w', quote( run.outputDir, { windows } ) ); + second.push( '-z', quote( bsTreeFile, { windows } ) ); + second.push( '-n', consensusOutput ); + if ( run.backboneConstraint.isSet ) { + second.push( '-r', quote( run.backboneConstraint.filePath, { windows } ) ); + } + if ( run.multifurcatingConstraint.isSet ) { + second.push( '-g', quote( run.multifurcatingConstraint.filePath, { windows } ) ); + } + break; + } + case 'AS': // Ancestral states + // params: [params.tree], + // cmd = """cd %s %s &&%s %s -f A -t "%s" -s %s %s -n %s -O -w %s %s %s""" \ + // % (winD, raxml_path, K[0], pro, rooted_tree, seq_file, mod, out_file, path_dir, part_f, winEx) + if ( !run.numThreads.notAvailable ) { + first.push( '-T', run.numThreads.value ); + } + first.push( '-f', 'A' ); + first.push( '-t', quote( run.tree.filePath, { windows } ) ); + first.push( '-m', run.raxmlSubstitutionModelCmd ); + first.push( run.substitutionMatrix.extraCmdValue ); + first.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + first.push( '-K', run.multistateModel.value ); + } + first.push( '-n', run.outputFilenameSafe ); + first.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + first.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + break; + case 'PD': // Pairwise distances + // params: [params.startingTree], + // # "./raxmlHPC -f x -m GTRGAMMA[I] -n NAME -s INPUT -p RANDOMNR [-q PARTFILE -o OUTGROUP]" + // cmd = """cd %s %s &&%s %s -f x -p %s %s -s %s %s -n %s %s -O -w %s %s %s""" \ + // % (winD, raxml_path, K[0], pro, seed_1, const_f, seq_file, mod, out_file, o, path_dir, part_f, winEx) + if ( !run.numThreads.notAvailable ) { + first.push( '-T', run.numThreads.value ); + } + first.push( '-f', 'x' ); + first.push( '-p', run.seedParsimony ); + first.push( '-m', run.raxmlSubstitutionModelCmd ); + first.push( run.substitutionMatrix.extraCmdValue ); + first.push( run.substitutionAscertainment.extraCmdValue ); + if ( !run.multistateModel.notAvailable ) { + first.push( '-K', run.multistateModel.value ); + } + if ( run.disableCheckUndeterminedSequence ) { + first.push( '-O' ); + } + if ( !run.tree.notAvailable ) { + first.push( '-t', quote( run.tree.filePath, { windows } ) ); + } + first.push( '-n', run.outputFilenameSafe ); + first.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + first.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + break; + case 'RBS': // Rell bootstraps + // params: [params.reps, params.brL, params.outGroup], + // # "./raxmlHPC -f x -m GTRGAMMA[I] -n NAME -s INPUT -p RANDOMNR [-q PARTFILE -o OUTGROUP]" + // cmd = """cd %s %s &&%s %s -f D -p %s %s -s %s %s -n %s %s -O -w %s %s %s""" \ + // % (winD, raxml_path, K[0], pro, seed_1, const_f, seq_file, mod, out_file, o, path_dir, part_f, winEx) + if ( !run.numThreads.notAvailable ) { + first.push( '-T', run.numThreads.value ); + } + first.push( '-f', 'D' ); + first.push( '-p', run.seedParsimony ); + first.push( '-m', run.raxmlSubstitutionModelCmd ); + first.push( run.substitutionMatrix.extraCmdValue ); + first.push( run.substitutionAscertainment.extraCmdValue ); + if ( run.branchLength.value ) { + first.push( '-k' ); + } + if ( run.outGroup.cmdValue ) { + first.push( '-o', run.outGroup.cmdValue ); + } + if ( !run.multistateModel.notAvailable ) { + first.push( '-K', run.multistateModel.value ); + } + if ( run.disableCheckUndeterminedSequence ) { + first.push( '-O' ); + } + first.push( '-n', run.outputFilenameSafe ); + first.push( '-s', quote( run.finalAlignment.path, { windows } ) ); + // if (!run.tree.notAvailable) { + // first.push('-t', run.tree.filePath); + // } + first.push( '-w', quote( run.outputDir, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '-q', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '-q', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } + if ( run.backboneConstraint.isSet ) { + first.push( '-r', quote( run.backboneConstraint.filePath, { windows } ) ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( '-g', quote( run.multifurcatingConstraint.filePath, { windows } ) ); + } + break; + default: + } + // Remove items that are only empty strings + cmdArgs.forEach( ( args ) => remove( args, ( n ) => n === '' ) ); + return cmdArgs.filter( ( args ) => args.length > 0 ); +}; diff --git a/src/app/store/command/raxmlNg.test.ts b/src/app/store/command/raxmlNg.test.ts new file mode 100644 index 00000000..96fbdec7 --- /dev/null +++ b/src/app/store/command/raxmlNg.test.ts @@ -0,0 +1,60 @@ +import { expect, it } from 'vitest'; + +import { raxmlNgArgs } from './raxmlNg'; + +const base = { + analysis: { value: 'SC' }, + havePartitionFile: false, + partitionFile: '', + ngSubstitutionModelCmd: 'GTR+G', + numThreads: { notAvailable: false, value: 2 }, + seedParsimony: 123, + outGroup: { cmdValue: '' }, + numRuns: { value: 1 }, + numRepetitionsNg: { value: 100 }, + alignments: { length: 1 }, + tree: { filePath: '' }, + multifurcatingConstraint: { isSet: false, filePath: '' }, +}; + +it( 'raxmlNgArgs quotes paths on Windows', () => { + const run = { + ...base, + finalAlignment: { + path: 'C:\\in\\aln.phy', + partitionFilePath: 'C:\\in\\aln.part', + partition: { isDefault: true }, + }, + outputDir: 'C:\\out', + outputNameSafe: 'run1', + backboneConstraint: { isSet: true, filePath: 'C:\\in\\backbone.tre' }, + }; + expect( raxmlNgArgs( run, { windows: true } ) ).toEqual( [[ + '--check', + '--model', + 'GTR+G', + '--prefix', + '"C:\\out\\run1"', + '--msa', + '"C:\\in\\aln.phy"', + '--tree-constraint', + '"C:\\in\\backbone.tre"', + ]] ); +} ); + +it( 'raxmlNgArgs leaves paths bare off Windows', () => { + const run = { + ...base, + finalAlignment: { + path: '/in/aln.phy', + partitionFilePath: '/in/aln.part', + partition: { isDefault: false }, + }, + outputDir: '/out', + outputNameSafe: 'run1', + backboneConstraint: { isSet: false, filePath: '' }, + }; + expect( raxmlNgArgs( run, { windows: false } ) ).toEqual( [ + ['--check', '--model', '/in/aln.part', '--prefix', '/out/run1', '--msa', '/in/aln.phy'], + ] ); +} ); diff --git a/src/app/store/command/raxmlNg.ts b/src/app/store/command/raxmlNg.ts new file mode 100644 index 00000000..6025fd62 --- /dev/null +++ b/src/app/store/command/raxmlNg.ts @@ -0,0 +1,218 @@ +import remove from 'lodash/remove'; + +import { join, quote } from '../../paths'; +import type { CmdArg, ConstraintInput, PartitionInput, Platform } from './index'; + +export interface RaxmlNgInput extends PartitionInput, ConstraintInput { + outputDir: string; + outputNameSafe: string; + analysis: { value: string }; + ngSubstitutionModelCmd: string; + numThreads: { notAvailable: boolean; value: number }; + seedParsimony: number; + outGroup: { cmdValue: string }; + numRuns: { value: number }; + numRepetitionsNg: { value: number | string }; + alignments: { length: number }; + tree: { filePath: string }; +} + +export const raxmlNgArgs = ( run: RaxmlNgInput, { windows }: Platform ): CmdArg[][] => { + const first: CmdArg[] = []; + const second: CmdArg[] = []; + const third: CmdArg[] = []; + const cmdArgs = [first, second, third]; // Possibly empty ones removed in the end + switch ( run.analysis.value ) { + case 'SC': + // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#preparing-the-alignment + first.push( '--check' ); + if ( run.havePartitionFile ) { + first.push( '--model', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '--model', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } else { + first.push( '--model', run.ngSubstitutionModelCmd ); + } + first.push( + '--prefix', + quote( join( run.outputDir, run.outputNameSafe ), { windows } ), + ); + first.push( '--msa', quote( run.finalAlignment.path, { windows } ) ); + if ( run.backboneConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.backboneConstraint.filePath, { windows } ), + ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.multifurcatingConstraint.filePath, { windows } ), + ); + } + break; + case 'CC': + // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#preparing-the-alignment + first.push( '--parse' ); + if ( run.havePartitionFile ) { + first.push( '--model', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '--model', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } else { + first.push( '--model', run.ngSubstitutionModelCmd ); + } + first.push( + '--prefix', + quote( join( run.outputDir, run.outputNameSafe ), { windows } ), + ); + first.push( '--msa', quote( run.finalAlignment.path, { windows } ) ); + if ( run.backboneConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.backboneConstraint.filePath, { windows } ), + ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.multifurcatingConstraint.filePath, { windows } ), + ); + } + break; + case 'TI': + // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#tree-inference + first.push( '--msa', quote( run.finalAlignment.path, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '--model', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '--model', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } else { + first.push( '--model', run.ngSubstitutionModelCmd ); + } + first.push( + '--prefix', + quote( join( run.outputDir, run.outputNameSafe ), { windows } ), + ); + if ( !run.numThreads.notAvailable ) { + first.push( '--threads', run.numThreads.value ); + } + first.push( '--seed', run.seedParsimony ); + if ( run.outGroup.cmdValue ) { + first.push( '--outgroup', run.outGroup.cmdValue ); + } + first.push( '--tree', `rand{${run.numRuns.value}}` ); + if ( run.backboneConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.backboneConstraint.filePath, { windows } ), + ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.multifurcatingConstraint.filePath, { windows } ), + ); + } + break; + case 'ML+tBS+con': + // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#bootstrapping + // raxml-ng --all --msa prim.phy --model GTR+G --prefix T15 --seed 2 --threads 2 --bs-metric fbp,tbe + first.push( '--all' ); + first.push( '--msa', quote( run.finalAlignment.path, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '--model', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '--model', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } else { + first.push( '--model', run.ngSubstitutionModelCmd ); + } + first.push( + '--prefix', + quote( join( run.outputDir, run.outputNameSafe ), { windows } ), + ); + first.push( '--seed', run.seedParsimony ); + if ( !run.numThreads.notAvailable ) { + first.push( '--threads', run.numThreads.value ); + } + if ( run.outGroup.cmdValue ) { + first.push( '--outgroup', run.outGroup.cmdValue ); + } + first.push( '--bs-metric', 'fbp' ); + first.push( '--tree', `rand{${run.numRuns.value}}` ); + first.push( '--bs-trees', run.numRepetitionsNg.value ); + if ( run.backboneConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.backboneConstraint.filePath, { windows } ), + ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.multifurcatingConstraint.filePath, { windows } ), + ); + } + break; + case 'ML+TBE+con': + // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#bootstrapping + // raxml-ng --all --msa prim.phy --model GTR+G --prefix T15 --seed 2 --threads 2 --bs-metric fbp,tbe + first.push( '--all' ); + first.push( '--msa', quote( run.finalAlignment.path, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '--model', quote( run.partitionFile, { windows } ) ); + } else if ( !run.finalAlignment.partition.isDefault ) { + first.push( '--model', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } else { + first.push( '--model', run.ngSubstitutionModelCmd ); + } + first.push( + '--prefix', + quote( join( run.outputDir, run.outputNameSafe ), { windows } ), + ); + first.push( '--seed', run.seedParsimony ); + if ( !run.numThreads.notAvailable ) { + first.push( '--threads', run.numThreads.value ); + } + if ( run.outGroup.cmdValue ) { + first.push( '--outgroup', run.outGroup.cmdValue ); + } + first.push( '--bs-metric', 'tbe' ); + first.push( '--tree', `rand{${run.numRuns.value}}` ); + first.push( '--bs-trees', run.numRepetitionsNg.value ); + if ( run.backboneConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.backboneConstraint.filePath, { windows } ), + ); + } + if ( run.multifurcatingConstraint.isSet ) { + first.push( + '--tree-constraint', + quote( run.multifurcatingConstraint.filePath, { windows } ), + ); + } + break; + case 'AS': + // https://github.com/amkozlov/raxml-ng/wiki/Tutorial#bootstrapping + // raxml-ng --all --msa prim.phy --model GTR+G --prefix T15 --seed 2 --threads 2 --bs-metric fbp,tbe + first.push( '--ancestral' ); + first.push( '--msa', quote( run.finalAlignment.path, { windows } ) ); + if ( run.havePartitionFile ) { + first.push( '--model', quote( run.partitionFile, { windows } ) ); + } else if ( run.alignments.length > 1 ) { + first.push( '--model', quote( run.finalAlignment.partitionFilePath, { windows } ) ); + } else { + first.push( '--model', run.ngSubstitutionModelCmd ); + } + first.push( + '--prefix', + quote( join( run.outputDir, run.outputNameSafe ), { windows } ), + ); + first.push( '--tree', quote( run.tree.filePath, { windows } ) ); + break; + default: + } + // Remove items that are only empty strings + cmdArgs.forEach( ( args ) => remove( args, ( n ) => n === '' ) ); + return cmdArgs.filter( ( args ) => args.length > 0 ); +};