Skip to content

Commit f74c247

Browse files
committed
Parse and pass blast task options from help
This can be used in the front end by the Cloud version plugin to build search params
1 parent 3b97ef6 commit f74c247

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

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/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'

spec/blast/tasks_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'spec_helper'
2+
require 'sequenceserver/blast/tasks'
3+
4+
module SequenceServer
5+
RSpec.describe BLAST::Tasks do
6+
describe '#to_h' do
7+
it "extracts tasks from help text" do
8+
expect(described_class.to_h).to eq({
9+
"blastn"=>["blastn", "blastn-short", "dc-megablast", "megablast", "rmblastn"],
10+
"blastp"=>["blastp", "blastp-fast", "blastp-short"],
11+
"blastx"=>["blastx", "blastx-fast"],
12+
"tblastn"=>["tblastn", "tblastn-fast"],
13+
"tblastx"=>[]
14+
})
15+
end
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)