Skip to content

Commit bbc50c7

Browse files
authored
Merge pull request #744 from tadast/tt/advanced-params
Refresh options UI
2 parents e84332b + 859e320 commit bbc50c7

20 files changed

Lines changed: 2001 additions & 1356 deletions

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ module.exports = {
77
'@babel/plugin-proposal-class-properties',
88
'@babel/plugin-syntax-dynamic-import',
99
],
10-
};
10+
};

jest.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ module.exports = {
4444
'circos$': '<rootDir>/public/js/tests/mocks/circos.js',
4545
'grapher': '<rootDir>/public/js/grapher.js',
4646
'histogram': '<rootDir>/public/js/null_plugins/grapher/histogram.js',
47-
'query_stats': '<rootDir>/public/js/null_plugins/query_stats.js'
47+
'query_stats': '<rootDir>/public/js/null_plugins/query_stats.js',
48+
'^options$': '<rootDir>/public/js/options.js'
4849
},
4950
watchPlugins: [
5051
'jest-watch-typeahead/filename',
5152
'jest-watch-typeahead/testname'
5253
],
53-
resetMocks: true
54+
resetMocks: true,
5455
};

jest_scripts/babelTransform.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const hasJsxRuntime = (() => {
1212
return false;
1313
}
1414
})();
15+
16+
1517
module.exports = babelJest.createTransformer({
1618
presets: [
1719
[

lib/sequenceserver/blast/tasks.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module SequenceServer
2+
module BLAST
3+
# Shells out to each blast algorithm to get the help text and then parses it to extract the tasks.
4+
module Tasks
5+
ALGORITHMS = %w[blastn blastp blastx tblastn tblastx].freeze
6+
7+
def self.to_h
8+
@to_h ||= ALGORITHMS.map do |algorithm|
9+
help_text = `#{algorithm} -help`
10+
[algorithm, extract_tasks(help_text)]
11+
end.to_h
12+
end
13+
14+
def self.extract_tasks(help_text)
15+
lines = help_text.split("\n")
16+
17+
# Find task help paragraph start
18+
task_line_index = lines.find_index { |line| line =~ /^\W-task/ }
19+
return [] unless task_line_index.to_i.positive?
20+
21+
lines.slice!(0...task_line_index)
22+
23+
# Find the end of task help paragraph
24+
next_option_line_index = lines.find_index { |line| line =~ /^\W-/ && !line.include?('-task') }
25+
lines.slice!(next_option_line_index..-1)
26+
27+
extract_tasks_from_paragraph(lines)
28+
end
29+
30+
def self.extract_tasks_from_paragraph(paragraph_lines)
31+
as_one_liner = paragraph_lines.map(&:strip).join(' ')
32+
as_one_liner.split('Permissible values:').last.split('>').first.split(' ').map do |task|
33+
task.strip.gsub("'", '')
34+
end.reject(&:empty?)
35+
end
36+
end
37+
end
38+
end

lib/sequenceserver/config.rb

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def initialize(data = {})
2222

2323
return unless @upgraded
2424

25-
logger.info 'You are using old configuration syntax. ' \
25+
logger.warn 'You are using old configuration syntax. ' \
2626
'Run `sequenceserver -s` to update your config file syntax.'
2727
end
2828

@@ -69,20 +69,7 @@ def normalize(data)
6969
@upgrade = true
7070
end
7171

72-
# Old config files may have an options hash with array values. We turn the
73-
# array values into a hash. The logic is simple: If the array value is the
74-
# same as default, we give it the key 'default', otherwise we give it the
75-
# key 'custom'
76-
data[:options]&.each do |key, val|
77-
next if val.is_a? Hash
78-
79-
data[:options][key] = if val == defaults[:options][key][:default]
80-
{ default: val }
81-
else
82-
{ custom: val }
83-
end
84-
@upgraded = true
85-
end
72+
data[:options] = convert_deprecated_options(data[:options]) if data[:options]
8673

8774
data
8875
end
@@ -112,19 +99,34 @@ def defaults
11299
databases_widget: 'classic',
113100
options: {
114101
blastn: {
115-
default: ['-task blastn', '-evalue 1e-5']
102+
default: {
103+
description: nil,
104+
attributes: ['-task blastn', '-evalue 1e-5']
105+
}
116106
},
117107
blastp: {
118-
default: ['-evalue 1e-5']
108+
default: {
109+
description: nil,
110+
attributes: ['-evalue 1e-5']
111+
}
119112
},
120113
blastx: {
121-
default: ['-evalue 1e-5']
114+
default: {
115+
description: nil,
116+
attributes: ['-evalue 1e-5']
117+
}
122118
},
123119
tblastx: {
124-
default: ['-evalue 1e-5']
120+
default: {
121+
description: nil,
122+
attributes: ['-evalue 1e-5']
123+
}
125124
},
126125
tblastn: {
127-
default: ['-evalue 1e-5']
126+
default: {
127+
description: nil,
128+
attributes: ['-evalue 1e-5']
129+
}
128130
}
129131
},
130132
num_threads: 1,
@@ -137,5 +139,37 @@ def defaults
137139
optimistic: false # Faster, but does not perform DB compatibility checks
138140
}
139141
end
142+
143+
def convert_deprecated_options(options)
144+
options.each do |blast_algo, algo_config|
145+
if algo_config.is_a?(Array)
146+
# Very old config files may have a single array with CLI args.
147+
# e.g. { blastn: ['-task blastn', '-evalue 1e-5'] }
148+
# Convert the array values into a single hash naming it 'default' if
149+
# the values match SequenceServer defaults.
150+
options[blast_algo] = if algo_config == defaults.dig(:options, blast_algo, :default, :attributes)
151+
{ default: { attributes: algo_config } }
152+
else
153+
{ custom: { attributes: algo_config } }
154+
end
155+
@upgraded = true
156+
elsif algo_config.is_a?(Hash)
157+
# v3.0.1 and older config files contain a flatter structure
158+
# with an array instead of 'description' and 'attributes' keys.
159+
# e.g. { blastn: { default: ['-task blastn', '-evalue 1e-5'] }
160+
algo_config.each do |config_name, config|
161+
next unless config.is_a?(Array)
162+
163+
options[blast_algo][config_name] = {
164+
description: nil,
165+
attributes: config
166+
}
167+
@upgraded = true
168+
end
169+
end
170+
end
171+
172+
options
173+
end
140174
end
141175
end

lib/sequenceserver/routes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
require 'sequenceserver/job'
77
require 'sequenceserver/blast'
8+
require 'sequenceserver/blast/tasks'
89
require 'sequenceserver/report'
910
require 'sequenceserver/database'
1011
require 'sequenceserver/sequence'
@@ -85,7 +86,8 @@ class Routes < Sinatra::Base
8586
searchdata = {
8687
query: Database.retrieve(params[:query]),
8788
database: Database.all,
88-
options: SequenceServer.config[:options]
89+
options: SequenceServer.config[:options],
90+
blastTaskMap: SequenceServer::BLAST::Tasks.to_h
8991
}
9092

9193
searchdata.update(tree: Database.tree) if SequenceServer.config[:databases_widget] == 'tree'

0 commit comments

Comments
 (0)