Module: SequenceServer::BLAST::Tasks

Defined in:
lib/sequenceserver/blast/tasks.rb

Overview

Shells out to each blast algorithm to get the help text and then parses it to extract the tasks.

Constant Summary collapse

ALGORITHMS =
%w[blastn blastp blastx tblastn tblastx].freeze

Class Method Summary collapse

Class Method Details

.extract_tasks(help_text) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sequenceserver/blast/tasks.rb', line 14

def self.extract_tasks(help_text)
  lines = help_text.split("\n")

  # Find task help paragraph start
  task_line_index = lines.find_index { |line| line =~ /^\W-task/ }
  return [] unless task_line_index.to_i.positive?

  lines.slice!(0...task_line_index)

  # Find the end of task help paragraph
  next_option_line_index = lines.find_index { |line| line =~ /^\W-/ && !line.include?('-task') }
  lines.slice!(next_option_line_index..-1)

  extract_tasks_from_paragraph(lines)
end

.extract_tasks_from_paragraph(paragraph_lines) ⇒ Object



30
31
32
33
34
35
# File 'lib/sequenceserver/blast/tasks.rb', line 30

def self.extract_tasks_from_paragraph(paragraph_lines)
  as_one_liner = paragraph_lines.map(&:strip).join(' ')
  as_one_liner.split('Permissible values:').last.split('>').first.split(' ').map do |task|
    task.strip.gsub("'", '')
  end.reject(&:empty?)
end

.to_hObject



7
8
9
10
11
12
# File 'lib/sequenceserver/blast/tasks.rb', line 7

def self.to_h
  @to_h ||= ALGORITHMS.map do |algorithm|
    help_text, = SequenceServer.sys("#{algorithm} -help", path: SequenceServer.config[:bin])
    [algorithm, extract_tasks(help_text)]
  end.to_h
end