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
12 changes: 6 additions & 6 deletions src/app/AlignmentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface CardModelExtra {
value: string;
onChange: ( value: string ) => void;
notAvailable: boolean;
hoverInfo: string;
hoverInfo?: string;
error: unknown;
}

Expand All @@ -44,12 +44,12 @@ interface CardAlignment {
loading: boolean;
showPartition: boolean;
partition: { isComplete: boolean };
substitutionModel: OptionSelectOptionLike;
substitutionModel: OptionSelectOptionLike<string>;
multistateNumber: OptionTextFieldOptionLike;
ngStationaryFrequencies: OptionSelectOptionLike;
ngInvariantSites: OptionSelectOptionLike;
ngRateHeterogeneity: OptionSelectOptionLike;
ngAscertainmentBias: OptionSelectOptionLike;
ngStationaryFrequencies: OptionSelectOptionLike<string>;
ngInvariantSites: OptionSelectOptionLike<string>;
ngRateHeterogeneity: OptionSelectOptionLike<string>;
ngAscertainmentBias: OptionSelectOptionLike<string>;
modelExtra: CardModelExtra | null;
modelTestCanRun: boolean;
modeltestLoading: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/app/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type InputRun = PartitionFileCardProps['run'] & {
inputIsAlignment: boolean;
alignments: ( AlignmentCardProps['alignment'] & { path: string } )[];
inputIsTree: boolean;
astralTree: AstralTreeCardProps['astralTree'];
astralTree: AstralTreeCardProps['astralTree'] | null | undefined;
canLoadAlignment: boolean;
haveAlignments: boolean;
canLoadPartitionFile: boolean;
Expand All @@ -60,7 +60,7 @@ function droppedPath( file: File ): string {
}

const Input = ( { run }: InputProps ): React.JSX.Element => {
// run.hasAstralTree is the condition on which to show an astral tree card
// run.astralTree (hasAstralTree) is the condition on which to show an astral tree card
// For some reason when changed in the mobx store a rerender is not triggered with this boolean with the conditional below alone
// With this if the component rerenders as should be
if ( run.hasAstralTree ) {
Expand Down Expand Up @@ -143,7 +143,7 @@ const Input = ( { run }: InputProps ): React.JSX.Element => {
/>
) )
: null}
{run.inputIsTree && run.hasAstralTree
{run.inputIsTree && run.astralTree
? (
<AstralTreeCard astralTree={run.astralTree} />
)
Expand Down
24 changes: 12 additions & 12 deletions src/app/Model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ import type { OptionCheckOptionLike } from './components/OptionCheck';
interface ModelRun {
usesModeltestNg: boolean;
usesAstral: boolean;
analysis: OptionSelectOptionLike;
numRuns: OptionSelectOptionLike;
numRepetitions: OptionSelectOptionLike;
numRepetitionsNg: OptionSelectOptionLike;
analysis: OptionSelectOptionLike<string>;
numRuns: OptionSelectOptionLike<number>;
numRepetitions: OptionSelectOptionLike<number | string>;
numRepetitionsNg: OptionSelectOptionLike<number | string>;
branchLength: OptionCheckOptionLike;
sHlike: OptionCheckOptionLike;
combinedOutput: OptionCheckOptionLike;
startingTree: OptionSelectOptionLike;
outGroup: OptionSelectOptionLike;
startingTree: OptionSelectOptionLike<string>;
outGroup: OptionSelectOptionLike<string[]>;
haveRandomSeed: boolean;
randomSeed: number;
setRandomSeed: ( value: string ) => void;
substitutionMatrix: OptionSelectOptionLike;
substitutionRate: OptionSelectOptionLike;
substitutionI: OptionSelectOptionLike;
substitutionAscertainment: OptionSelectOptionLike;
multistateModel: OptionSelectOptionLike;
substitutionMatrix: OptionSelectOptionLike<string>;
substitutionRate: OptionSelectOptionLike<string>;
substitutionI: OptionSelectOptionLike<string>;
substitutionAscertainment: OptionSelectOptionLike<string>;
multistateModel: OptionSelectOptionLike<string>;
estimatedFrequencies: OptionCheckOptionLike;
baseFrequencies: OptionSelectOptionLike;
baseFrequencies: OptionSelectOptionLike<string>;
}

export interface ModelProps {
Expand Down
6 changes: 3 additions & 3 deletions src/app/PartitionEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ interface PartPositionOption extends Omit<OptionTextFieldOptionLike, 'setValue'>

interface EditorPartition {
partToAdd: {
type: OptionSelectOptionLike;
aaType: OptionSelectOptionLike;
type: OptionSelectOptionLike<string>;
aaType: OptionSelectOptionLike<string>;
name: OptionTextFieldOptionLike;
start: PartPositionOption;
end: PartPositionOption;
codon: OptionSelectOptionLike;
codon: OptionSelectOptionLike<string>;
};
progress: number;
currentEndValue: number;
Expand Down
4 changes: 2 additions & 2 deletions src/app/Raxml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { FormHelperText } from '@mui/material';

interface RaxmlRun {
command: string;
binary: OptionSelectOptionLike;
numThreads: OptionSelectOptionLike;
binary: OptionSelectOptionLike<string>;
numThreads: OptionSelectOptionLike<number>;
modelTestIsRunningOnAlignment: boolean;
cancelModeltestOnAlignment: () => void;
running: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/app/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function initDev( exampleFiles: ExampleFilesPayload ): void {
].map( ( filename ) => ( {
path: join( exampleFilesDir, 'phylip', filename ),
} ) );
const useFiles = [].concat( useFastaFiles, usePhylipFiles );
const useFiles = [ ...useFastaFiles, ...usePhylipFiles ];
store.activeRun.addAlignments( useFiles );
store.activeRun.setOutputDir( exampleFiles.outdir );
setTimeout( () => {
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/ErrorDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it( 'the reload action reloads the window', () => {
} );

const button = Array.from( document.body.querySelectorAll( 'button' ) )
.find( ( item ) => item.textContent === 'Ignore and reload' );
.find( ( item ) => item.textContent === 'Ignore and reload' )!;
act( () => {
button.click();
} );
Expand Down Expand Up @@ -55,7 +55,7 @@ function renderDialog( error: Error ) {
div,
button( label: string ) {
return Array.from( document.body.querySelectorAll<HTMLElement>( 'button, a' ) )
.find( ( item ) => item.textContent === label );
.find( ( item ) => item.textContent === label )!;
},
};
}
Expand Down Expand Up @@ -94,7 +94,7 @@ Locale: en-US`;
const url = new URL( openExternal.mock.calls[0][0] );
expect( `${url.origin}${url.pathname}` ).toBe( 'https://github.com/AntonelliLab/raxmlGUI/issues/new' );
expect( url.searchParams.get( 'title' ) ).toBe( 'Error: boom' );
const body = url.searchParams.get( 'body' );
const body = url.searchParams.get( 'body' )!;
expect( body.startsWith( 'Autogenerated report:' ) ).toBe( true );
expect( body ).toContain( 'boom' );
expect( body ).toContain( 'raxml -s primates.fasta' );
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/OptionCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface OptionCheckOptionLike {
value: boolean;
setValue: ( value: boolean ) => void;
notAvailable: boolean;
hoverInfo: string;
hoverInfo?: string;
}

export interface OptionCheckProps {
Expand Down
23 changes: 12 additions & 11 deletions src/app/components/OptionSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ export interface OptionSelectChoice {
title: string | number;
}

export interface OptionSelectOptionLike {
export interface OptionSelectOptionLike<Value extends string | number | readonly string[]> {
notAvailable?: boolean;
title: string;
hoverInfo: string;
hoverInfo?: string;
options: readonly OptionSelectChoice[];
value: string | number | readonly string[];
setValue: ( value: unknown ) => void;
value: Value;
setValue: ( value: Value ) => void;
multiple?: boolean;
error: unknown;
placeholder?: string;
}

export interface OptionSelectProps {
option: OptionSelectOptionLike;
export interface OptionSelectProps<Value extends string | number | readonly string[]> {
option: OptionSelectOptionLike<Value>;
sx?: SxProps<Theme>;
}

const OptionSelect = observer( function OptionSelect( {
function OptionSelect<Value extends string | number | readonly string[]>( {
option,
sx,
}: OptionSelectProps ) {
}: OptionSelectProps<Value> ) {
if ( option.notAvailable || option.options.length === 0 ) {
return null;
}
Expand Down Expand Up @@ -59,7 +59,8 @@ const OptionSelect = observer( function OptionSelect( {
<FormControl variant="standard" sx={sx} title={option.hoverInfo}>
<Select
value={option.value}
onChange={( e ) => option.setValue( e.target.value )}
// MUI's change event types the value as `Value | string`.
onChange={( e ) => option.setValue( e.target.value as Value )}
inputProps={{
name: option.title,
id: option.title,
Expand All @@ -76,6 +77,6 @@ const OptionSelect = observer( function OptionSelect( {
<FormHelperText>{option.title}</FormHelperText>
</FormControl>
);
} );
}

export default OptionSelect;
export default observer<typeof OptionSelect>( OptionSelect );
2 changes: 1 addition & 1 deletion src/app/components/OptionTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface OptionTextFieldOptionLike {
value: string | number | boolean;
setValue: ( value: string ) => void;
notAvailable: boolean;
hoverInfo: string;
hoverInfo?: string;
haveError: boolean;
disabled?: boolean;
placeholder?: string;
Expand Down
10 changes: 5 additions & 5 deletions src/app/droppedFile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ function mountInput( run: object ) {
}

function button( div: HTMLElement, text: string ) {
return Array.from( div.querySelectorAll( 'button' ) ).find( ( node ) => node.textContent.trim() === text );
return Array.from( div.querySelectorAll( 'button' ) ).find( ( node ) => node.textContent.trim() === text )!;
}

async function drop( target: Element, name: string ) {
const input = target.closest( '[role="presentation"]' ).querySelector( 'input[type="file"]' );
const input = target.closest( '[role="presentation"]' )!.querySelector( 'input[type="file"]' )!;
const file = new File( ['x'], name );
Object.defineProperty( input, 'files', {
configurable: true,
Expand All @@ -79,7 +79,7 @@ it( 'each drop target keeps the dropped file path', async () => {
'cats.fasta': '/tmp/drop-6',
'dogs.fasta': '/tmp/drop-7',
'genes.part': '/tmp/drop-8',
}[file.name];
}[file.name]!;
},
} );

Expand Down Expand Up @@ -109,7 +109,7 @@ it( 'each drop target keeps the dropped file path', async () => {
} );
const secondView = mountInput( second );
await drop(
secondView.div.querySelector( 'button[title="Concatenate new alignments and create partition"]' ),
secondView.div.querySelector( 'button[title="Concatenate new alignments and create partition"]' )!,
'cats.fasta',
);
expect( second.addAlignments ).toHaveBeenCalledWith( [{ path: '/tmp/drop-6' }] );
Expand All @@ -122,7 +122,7 @@ it( 'each drop target keeps the dropped file path', async () => {
} );
const thirdView = mountInput( third );
await drop(
thirdView.div.querySelector( 'button[title="Concatenate new alignments and automatically generate a partition"]' ),
thirdView.div.querySelector( 'button[title="Concatenate new alignments and automatically generate a partition"]' )!,
'dogs.fasta',
);
await drop( button( thirdView.div, 'Load partition' ), 'genes.part' );
Expand Down
3 changes: 2 additions & 1 deletion src/app/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const stemOf = ( baseName: string ): string => {
const parsed = ( filePath: string ): { base: string; name: string; dir: string } => {
const sep = sepOf( filePath );
const chunks = filePath.split( /[/\\]/ );
const baseName = chunks.pop();
// split() always returns at least one chunk, so pop() never yields undefined.
const baseName = chunks.pop() ?? '';
let directory = '';
if ( chunks.length === 1 && chunks[0] === '' ) {
directory = sep;
Expand Down
49 changes: 31 additions & 18 deletions src/app/store/Alignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface AlignmentOwner {
substitutionRate: SettableOption<string>;
substitutionMatrix: SettableOption<string>;
alignments: Alignment[];
dataType: string;
dataType: string | undefined;
error: unknown;
afterRun: () => void;
removeAlignment: ( alignment: Alignment ) => void;
Expand Down Expand Up @@ -215,7 +215,8 @@ class Alignment extends InputFile<AlignmentOwner> {
case 'multistate':
return 'MULTI';
default:
return this.dataType;
// '' until the alignment is parsed.
return this.dataType ?? '';
}
}

Expand Down Expand Up @@ -292,15 +293,24 @@ class Alignment extends InputFile<AlignmentOwner> {
);
return;
}
const { dataType } = this;
// dataType check narrows for the compiler; modelTestCanRun already excludes undefined.
if ( !this.modelTestCanRun || dataType === undefined ) {
return;
}
const binaryName = this.run.modeltestName;
if ( binaryName === undefined ) {
throw new Error( 'No modeltest binary in the binaries list' );
}
this.modeltestLoading = true;
const { rendererBridge } = window;
await rendererBridge.startModelSelection( {
id: this.id,
filePath: this.path,
outputDir: this.run.outputDir,
dataType: this.dataType,
dataType,
numThreads: this.run.numThreads.value,
binaryName: this.run.modeltestName,
binaryName,
} );
};

Expand All @@ -320,14 +330,17 @@ class Alignment extends InputFile<AlignmentOwner> {
model = model.replace( 'TrN', 'TN93' );
model = model.replace( 'TPM1', 'K81' );
this.substitutionModel.setValue( model );
if ( /\+F[O|E]?/.test( raxmlNG ) ) {
this.ngStationaryFrequencies.setValue( /\+F[O|E]?/.exec( raxmlNG )[0] );
const frequencies = raxmlNG.match( /\+F[O|E]?/ );
if ( frequencies ) {
this.ngStationaryFrequencies.setValue( frequencies[0] );
}
if ( /\+IC?/.test( raxmlNG ) ) {
this.ngInvariantSites.setValue( /\+IC?/.exec( raxmlNG )[0] );
const invariantSites = raxmlNG.match( /\+IC?/ );
if ( invariantSites ) {
this.ngInvariantSites.setValue( invariantSites[0] );
}
if ( /\+GA?/.test( raxmlNG ) ) {
this.ngRateHeterogeneity.setValue( /\+GA?/.exec( raxmlNG )[0] );
const rateHeterogeneity = raxmlNG.match( /\+GA?/ );
if ( rateHeterogeneity ) {
this.ngRateHeterogeneity.setValue( rateHeterogeneity[0] );
}
if ( /\+ASC_LEWIS/.test( raxmlNG ) ) {
this.ngAscertainmentBias.setValue( '+ASC_LEWIS' );
Expand All @@ -350,7 +363,8 @@ class Alignment extends InputFile<AlignmentOwner> {
console.log( 'parsing matrix name...' );
const { options } = raxmlSettings.aminoAcidSubstitutionMatrixOptions;
const re = new RegExp( `(${options.join( '|' )})$` );
const matrixName = re.exec( model )[1];
// Null on an unlisted matrix throws a TypeError, as before; #403 owns that case.
const matrixName = re.exec( model )![1];
this.aaMatrixName = matrixName;
model = model.replace( re, '' );
}
Expand Down Expand Up @@ -396,11 +410,10 @@ class Alignment extends InputFile<AlignmentOwner> {
try {
const parsed = await rendererBridge.parseAlignment( this.id, this.path );
const { alignment, change } = parsed;
const newDataType = getFinalDataType(
this.run.alignments
.map( ( { dataType } ) => dataType )
.concat( alignment.dataType ),
);
const newDataType = getFinalDataType( [
...this.run.alignments.map( ( { dataType } ) => dataType ),
alignment.dataType,
] );
runInAction( () => {
if ( this.run.dataType !== newDataType ) {
this.run.substitutionMatrix.value =
Expand All @@ -422,8 +435,8 @@ class Alignment extends InputFile<AlignmentOwner> {
if ( change ) {
this.path = change.newFilePath;
this.convertedFrom = change.format;
this.converted = change.converted;
this.modified = change.modified;
this.converted = change.converted ?? false;
this.modified = change.modified ?? false;
this.modificationMessages = change.modificationMessages;
if ( change.modificationMessages.length > 0 ) {
this.showModifiedDialog = true;
Expand Down
2 changes: 1 addition & 1 deletion src/app/store/AlignmentOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function useOtherBinary( run: Run ) {
runInAction( () => {
run.binary.value = run.binary.options.find(
( o ) => !o.value.includes( 'raxml-ng' ),
).value;
)!.value;
} );
}

Expand Down
Loading
Loading