lib/sequenceserver/blast.rb in sequenceserver-1.0.0.pre.3 vs lib/sequenceserver/blast.rb in sequenceserver-1.0.0.pre.4

- old
+ new

@@ -3,10 +3,12 @@ require 'English' require 'ox' require 'sequenceserver/links' require 'sequenceserver/blast/exceptions' +require 'sequenceserver/blast/constants' +require 'sequenceserver/blast/formatter' require 'sequenceserver/blast/report' require 'sequenceserver/blast/query' require 'sequenceserver/blast/hit' require 'sequenceserver/blast/hsp' @@ -14,29 +16,10 @@ # Simple wrapper around BLAST+ search algorithms. # # `BLAST::ArgumentError` and `BLAST::RuntimeError` signal errors encountered # when attempting a BLAST search. module BLAST - ERROR_LINE = /\(CArgException.*\)\s(.*)/ - - ALGORITHMS = %w(blastn blastp blastx tblastn tblastx) - - OUTFMT = { - 'pairwise' => [0, 'txt'], - 'qa_identity' => [1, 'txt'], - 'qa_no_identity' => [2, 'txt'], - 'fqa_identity' => [3, 'txt'], - 'fqa_no_identity' => [4, 'txt'], - 'xml' => [5, 'xml'], - 'tsv' => [6, 'tsv'], - 'tsv_commented' => [7, 'tsv'], - 'asn_text' => [8, 'asn'], - 'asn_binary' => [9, 'asn'], - 'csv' => [10, 'csv'], - 'archive' => [11, 'txt'] - } # See [1] - class << self extend Forwardable def_delegators SequenceServer, :config, :logger @@ -107,52 +90,20 @@ error = efile.read efile.close fail RuntimeError.new(status, error) end - Report.new(File.basename(rfile), databases) + Search << rfile + Report.new(File.basename(rfile.path), databases) end - - def format(params) - validate_format_params params - - rfile = create_file_path params['report'] - ofmt = OUTFMT[params['format']] - type = params['type'] - - oname = "seqserv_#{type}_#{Time.now.strftime('%H%M')}.#{ofmt[1]}" - ofile = Tempfile.new oname - - command = "blast_formatter -archive '#{rfile}' -out #{ofile.path}" \ - " -outfmt '#{ofmt[0]} #{params['specifiers']}' 2> /dev/null" - - logger.debug("Executing: #{command}") - system command - - { - :filepath => ofile.path, - :filename => oname, - :type => ofmt[1] - } - end # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity # rubocop:enable Metrics/MethodLength def pre_process(params) params[:sequence].strip! unless params[:sequence].nil? end - def validate_format_params(params) - return true if params.include?('report') && - params.include?('format') && - File.exist?(create_file_path params['report']) - fail ArgumentError, <<MSG -Incorrect request parameters. Please ensure that requested file name is -correct and the file type is either xml or tsv. -MSG - end - def validate_blast_params(params) validate_blast_method params[:method] validate_blast_sequences params[:sequence] validate_blast_databases params[:databases] validate_blast_options params[:advanced] @@ -197,15 +148,9 @@ failedopt = Regexp.last_match[0] fail ArgumentError, "Option \"#{failedopt}\" is prohibited." end true - end - - # Returns filename if path exists otherwise returns a path to tmp dir. - def create_file_path(filename) - return File.join(Dir.tmpdir, filename) unless File.exist? filename - filename end def allowed_chars /\A[a-z0-9\-_\. ']*\Z/i end