Class: Bio::LazyBlast::Report

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bio/appl/blast/lazyblastxml.rb

Defined Under Namespace

Classes: Iteration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Report

Returns a new instance of Report.



9
10
11
12
13
14
15
16
17
18
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 9

def initialize(filename)
  @filename = filename
  @reader = LibXML::XML::Reader.file(@filename)
  @nodes = Enumerator.new do |yielder|
    while @reader.read 
      yielder << @reader if @reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
    end
  end
  setup_report_values
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



7
8
9
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 7

def db
  @db
end

#programObject (readonly)

Returns the value of attribute program.



7
8
9
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 7

def program
  @program
end

#query_defObject (readonly)

Returns the value of attribute query_def.



7
8
9
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 7

def query_def
  @query_def
end

#query_idObject (readonly)

Returns the value of attribute query_id.



7
8
9
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 7

def query_id
  @query_id
end

#query_lenObject (readonly)

Returns the value of attribute query_len.



7
8
9
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 7

def query_len
  @query_len
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



7
8
9
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 7

def statistics
  @statistics
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 7

def version
  @version
end

Instance Method Details

#eachObject Also known as: each_iteration



51
52
53
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 51

def each
  @nodes.each{|node| yield Iteration.new(node) if node.name == "Iteration"}
end

#rewindObject



56
57
58
59
60
61
62
63
64
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 56

def rewind
  @reader.close
  @reader = LibXML::XML::Reader.file(@filename)
  @nodes = Enumerator.new do |yielder|
    while @reader.read 
      yielder << @reader if @reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
    end
  end
end

#setup_report_valuesObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bio/appl/blast/lazyblastxml.rb', line 20

def setup_report_values
  @statistics = Hash.new
  @nodes.each do |node|
    return if node.name == "BlastOutput_iterations"
    case node.name
    when 'BlastOutput_program'
      @program = node.read_inner_xml
    when 'BlastOutput_version'
      @version = node.read_inner_xml
    when 'BlastOutput_db'
      @db = node.read_inner_xml
    when 'BlastOutput_query-ID'
      @query_id = node.read_inner_xml
    when 'BlastOutput_query-def'
      @query_def = node.read_inner_xml
    when 'BlastOutput_query-len'
      @query_len = node.read_inner_xml.to_i
    when 'Parameters_matrix'
      @statistics['matrix'] = node.read_inner_xml
    when 'Parameters_expect'
      @statistics['expect'] = node.read_inner_xml.to_i
    when 'Parameters_gap-open'
      @statistics['gap-open'] = node.read_inner_xml.to_i
    when 'Parameters_gap-extend'
      @statistics['gap-extend'] = node.read_inner_xml.to_i
    when 'Parameters_filter'
      @statistics['filter'] = node.read_inner_xml
    end
  end
end