Class: SequenceServer::BLAST::Report

Inherits:
Report
  • Object
show all
Defined in:
lib/sequenceserver/blast/report.rb

Overview

Captures results of a BLAST search.

A report is constructed from a search id. Search id is simply the basename of the temporary file that holds BLAST results in binary BLAST archive format.

For a given search id, result is obtained in XML format using the Formatter class, parsed into a simple intermediate representation (Array of values and Arrays) and information extracted from the intermediate representation (ir).

Instance Attribute Summary collapse

Attributes inherited from Report

#job

Instance Method Summary collapse

Methods inherited from Report

generate

Constructor Details

#initialize(job) ⇒ Report

Returns a new instance of Report.



25
26
27
28
29
30
# File 'lib/sequenceserver/blast/report.rb', line 25

def initialize(job)
  super do
    @queries = []
    @querydb = job.databases
  end
end

Instance Attribute Details

#dbtypeObject (readonly)

Attributes parsed from job metadata and BLAST output.



36
37
38
# File 'lib/sequenceserver/blast/report.rb', line 36

def dbtype
  @dbtype
end

#paramsObject (readonly)

Attributes parsed from job metadata and BLAST output.



36
37
38
# File 'lib/sequenceserver/blast/report.rb', line 36

def params
  @params
end

#programObject (readonly)

Attributes parsed out from BLAST output.



33
34
35
# File 'lib/sequenceserver/blast/report.rb', line 33

def program
  @program
end

#program_versionObject (readonly)

Attributes parsed out from BLAST output.



33
34
35
# File 'lib/sequenceserver/blast/report.rb', line 33

def program_version
  @program_version
end

#queriesObject (readonly)

Attributes parsed out from BLAST output.



33
34
35
# File 'lib/sequenceserver/blast/report.rb', line 33

def queries
  @queries
end

#querydbObject (readonly)

Attributes parsed from job metadata and BLAST output.



36
37
38
# File 'lib/sequenceserver/blast/report.rb', line 36

def querydb
  @querydb
end

#statsObject (readonly)

Attributes parsed out from BLAST output.



33
34
35
# File 'lib/sequenceserver/blast/report.rb', line 33

def stats
  @stats
end

Instance Method Details

#done?Boolean

Returns:

  • (Boolean)


90
91
92
93
94
# File 'lib/sequenceserver/blast/report.rb', line 90

def done?
  return true if job.imported_xml_file

  File.exist?(xml_formatter.filepath) && File.exist?(tsv_formatter.filepath)
end

#generateObject

Generate report.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/sequenceserver/blast/report.rb', line 62

def generate
  return self if @_generated

  job.raise!
  xml_ir = nil
  tsv_ir = nil
  if job.imported_xml_file
    xml_ir = parse_xml File.read(job.imported_xml_file)
    tsv_ir = Hash.new do |h1, k1|
      h1[k1] = Hash.new do |h2, k2|
        h2[k2] = ['', '', []]
      end
    end
  else
    xml_ir = parse_xml(xml_formatter.read_file)
    tsv_ir = parse_tsv(tsv_formatter.read_file)
  end
  extract_program_info xml_ir
  extract_db_info xml_ir
  extract_params xml_ir
  extract_stats xml_ir
  extract_queries xml_ir, tsv_ir

  @_generated = true

  self
end

#to_json(*_args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sequenceserver/blast/report.rb', line 38

def to_json(*_args)
  generate

  %i[querydb program program_version params stats
     queries].inject({}) do |h, k|
    h[k] = send(k)
    h
  end.update(search_id: job.id,
             submitted_at: job..utc,
             imported_xml: !job.imported_xml_file.nil?,
             seqserv_version: SequenceServer::VERSION,
             cloud_sharing_enabled: SequenceServer.config[:cloud_share_url].start_with?('http'),
             non_parse_seqids: !!job.databases&.any?(&:non_parse_seqids?)).to_json
end

#xml_file_sizeObject



53
54
55
56
57
58
59
# File 'lib/sequenceserver/blast/report.rb', line 53

def xml_file_size
  return File.size(job.imported_xml_file) if job.imported_xml_file

  generate

  xml_formatter.size
end