Class: SequenceServer::BLAST::Job

Inherits:
Job
  • Object
show all
Defined in:
lib/sequenceserver/blast/job.rb

Overview

Extends SequenceServer::Job to describe a BLAST job.

Instance Attribute Summary collapse

Attributes inherited from Job

#completed_at, #exitstatus, #id, #submitted_at

Instance Method Summary collapse

Methods inherited from Job

all, create, delete, #dir, #done?, enqueue, fetch, #run, serializable_classes, #stderr, #stdout

Constructor Details

#initialize(params) ⇒ Job

Returns a new instance of Job.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sequenceserver/blast/job.rb', line 10

def initialize(params)
  if params.key?(:xml)
    super do
      @imported_xml_file = File.basename params[:xml]
      # Copy over the XML file to job directory so that a job dir in
      # itself is self-contained. This will help with tests among
      # other things.
      FileUtils.cp(params[:xml], dir)
      @databases = []
      done!
    end
  else
    validate params
    super do
      @method    = params[:method]
      @qfile     = store('query.fa', params[:sequence])
      @databases = Database[params[:databases]]
      @advanced  = params[:advanced].to_s.strip
      @options   = @advanced + defaults
      # The following params are for analytics only
      @num_threads = config[:num_threads]
      @query_length = calculate_query_size
      @databases_ncharacters_total = calculate_databases_ncharacters_total
    end
  end
end

Instance Attribute Details

#advancedObject (readonly)

:nodoc: Attributes used by us - should be considered private.



39
40
41
# File 'lib/sequenceserver/blast/job.rb', line 39

def advanced
  @advanced
end

#advanced_paramsObject (readonly)

:nodoc: Deprecated; see Report#extract_params



44
45
46
# File 'lib/sequenceserver/blast/job.rb', line 44

def advanced_params
  @advanced_params
end

#databasesObject (readonly)

Returns the value of attribute databases.



40
41
42
# File 'lib/sequenceserver/blast/job.rb', line 40

def databases
  @databases
end

#databases_ncharacters_totalObject (readonly)

Returns the value of attribute databases_ncharacters_total.



40
41
42
# File 'lib/sequenceserver/blast/job.rb', line 40

def databases_ncharacters_total
  @databases_ncharacters_total
end

#methodObject (readonly)

Returns the value of attribute method.



40
41
42
# File 'lib/sequenceserver/blast/job.rb', line 40

def method
  @method
end

#num_threadsObject (readonly)

Returns the value of attribute num_threads.



40
41
42
# File 'lib/sequenceserver/blast/job.rb', line 40

def num_threads
  @num_threads
end

#optionsObject (readonly)

Returns the value of attribute options.



40
41
42
# File 'lib/sequenceserver/blast/job.rb', line 40

def options
  @options
end

#qfileObject (readonly)

Returns the value of attribute qfile.



40
41
42
# File 'lib/sequenceserver/blast/job.rb', line 40

def qfile
  @qfile
end

#query_lengthObject (readonly)

Returns the value of attribute query_length.



40
41
42
# File 'lib/sequenceserver/blast/job.rb', line 40

def query_length
  @query_length
end

Instance Method Details

#as_archived_file(&block) ⇒ Object

Use it with a block to get a self-cleaning temporary archive file of the contents of the job directory. job.as_archived_file do |tmp_file|

# do things with tmp_file

end



69
70
71
72
73
74
75
76
77
# File 'lib/sequenceserver/blast/job.rb', line 69

def as_archived_file(&block)
  Dir.mktmpdir(id.to_s) do |tmp_dir|
    file_path = "#{tmp_dir}/#{id}.zip"
    ZipFileGenerator.new(dir, file_path).write
    File.open(file_path, 'r') do |file|
      block.call(file)
    end
  end
end

#commandObject

Returns the command that will be executed. Job super class takes care of actual execution.



55
56
57
58
# File 'lib/sequenceserver/blast/job.rb', line 55

def command
  @command ||= "#{method} -db '#{databases.map(&:name).join(' ')}'" \
               " -query '#{qfile}' #{options}"
end

#imported_xml_fileObject

:nodoc: Returns path to the imported xml file if the job was created using the –import switch. Returns nil otherwise.



49
50
51
# File 'lib/sequenceserver/blast/job.rb', line 49

def imported_xml_file
  File.join(dir, @imported_xml_file) if @imported_xml_file
end

#raise!Object



60
61
62
# File 'lib/sequenceserver/blast/job.rb', line 60

def raise!
  SequenceServer::BLAST::Error.new(exitstatus: exitstatus, stdout: stdout, stderr: stderr).raise!
end