import React, { Component } from 'react'; // Component for the advanced params input field. export class Options extends Component { constructor(props) { super(props); this.state = { textValue: '', objectValue: this.defaultObjectValue(), paramsMode: 'advanced' }; this.onTextValueChanged = this.onTextValueChanged.bind(this); this.optionsPresetsJSX = this.optionsPresetsJSX.bind(this); this.advancedParamsJSX = this.advancedParamsJSX.bind(this); this.showAdvancedOptionsHelp = this.showAdvancedOptionsHelp.bind(this); } defaultObjectValue() { return { max_target_seqs: '', evalue: '', task: '' }; }; componentDidUpdate(prevProps) { if (prevProps.predefinedOptions !== this.props.predefinedOptions) { let defaultOptions = this.props.predefinedOptions.default || {attributes: []}; let advancedOptions = this.props.predefinedOptions['last search'] || defaultOptions || {attributes: []}; let initialTextValue = advancedOptions.attributes.join(' ').trim(); let parsedOptions = this.parsedOptions(initialTextValue); this.setState({ textValue: initialTextValue, objectValue: parsedOptions}); } } onTextValueChanged(textValue) { let parsedOptions = this.parsedOptions(textValue.toString()); this.setState({ textValue: textValue.toString(), objectValue: parsedOptions }); } parsedOptions(textValue) { const words = textValue.split(" "); let parsedOptions = this.defaultObjectValue(); // Iterate through the words in steps of 2, treating each pair as an option and its potential value for (let i = 0; i < words.length; i += 2) { // Ensure there is a pair available if (words[i]) { if (words[i].startsWith("-")) { const optionName = words[i].substring(1).trim(); if (words[i + 1]) { // Use the second word as the value for this option parsedOptions[optionName] = words[i + 1]; } else { // No value found for this option, set it to null or a default value parsedOptions[optionName] = null; } } } } return parsedOptions; } optionsPresetsJSX() { return (
{ Object.keys(this.props.predefinedOptions).length > 1 && <>

Settings

Choose a predefined setting or customize BLAST parameters.

{this.presetListJSX()} }
); } presetListJSX() { return ( ) } advancedParamsJSX() { if (this.state.paramsMode !== 'advanced') { return null; } let classNames = 'flex-grow block px-4 py-1 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 text-base'; if (this.state.textValue) { classNames += ' bg-yellow-100'; } return(
{this.props.blastMethod && } {!this.props.blastMethod && Select databases and fill in the query to see options. }
this.onTextValueChanged(e.target.value)} id="advanced" name="advanced" value={this.state.textValue} placeholder="eg: -evalue 1.0e-5 -num_alignments 100" title="View, and enter advanced parameters." />
Options as they would appear in a command line when calling BLAST eg: -evalue 1.0e-5 -num_alignments 100
) } showAdvancedOptionsHelp(e) { const ids = ['blastn', 'tblastn', 'blastp', 'blastx', 'tblastx']; const method = this.props.blastMethod.toLowerCase(); // hide options for other algorithms and only show for selected algorithm for (const id of ids) { if (id === method) { document.getElementById(id).classList.remove('hidden') } else { document.getElementById(id).classList.add('hidden'); } } document.querySelector('[data-help-modal]').classList.remove('hidden') } render() { return (
{this.optionsPresetsJSX()} {this.advancedParamsJSX()}
); } }