Class: GeneValidator::TabularParser

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/genevalidator/tabular_parser.rb

Overview

This class parses the tabular output of BLAST (outfmt 6 & 7)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tab_file = opt[:blast_tabular_file], format = opt[:blast_tabular_options], type = config[:type]) ⇒ TabularParser

Initializes the object



22
23
24
25
26
27
28
# File 'lib/genevalidator/tabular_parser.rb', line 22

def initialize(tab_file = opt[:blast_tabular_file],
               format = opt[:blast_tabular_options], type = config[:type])
  @column_names = format.gsub(/[-\d]/, '').split(/[ ,]/)
  @type         = type
  @tab_results  = analayse_tabular_file(tab_file)
  @rows         = @tab_results.to_enum
end

Instance Attribute Details

#column_namesObject (readonly)

Returns the value of attribute column_names.



17
18
19
# File 'lib/genevalidator/tabular_parser.rb', line 17

def column_names
  @column_names
end

#rowsObject (readonly)

Returns the value of attribute rows.



15
16
17
# File 'lib/genevalidator/tabular_parser.rb', line 15

def rows
  @rows
end

#tab_resultsObject (readonly)

Returns the value of attribute tab_results.



16
17
18
# File 'lib/genevalidator/tabular_parser.rb', line 16

def tab_results
  @tab_results
end

#typeObject (readonly)

Returns the value of attribute type.



18
19
20
# File 'lib/genevalidator/tabular_parser.rb', line 18

def type
  @type
end

Instance Method Details

#analayse_tabular_file(filename) ⇒ Object



32
33
34
35
36
# File 'lib/genevalidator/tabular_parser.rb', line 32

def analayse_tabular_file(filename)
  lines = CSV.parse(File.read(filename), col_sep: "\t", skip_lines: /^#/,
                                         headers: @column_names)
  lines.map(&:to_hash)
end

#nextObject Also known as: move_to_next_query

move to next query



40
41
42
43
44
45
46
47
# File 'lib/genevalidator/tabular_parser.rb', line 40

def next
  current_entry = @rows.peek['qseqid']
  loop do
    entry = @rows.peek['qseqid']
    @rows.next
    break unless entry == current_entry
  end
end

#parse_next(query_id = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/genevalidator/tabular_parser.rb', line 53

def parse_next(query_id = nil)
  current_id = @rows.peek['qseqid']
  return [] if !query_id.nil? && current_id != query_id
  hit_seq = initialise_classes(current_id)
  move_to_next_query
  hit_seq
rescue StopIteration
  []
end