lib/genevalidator/tabular_parser.rb in genevalidator-1.6.12 vs lib/genevalidator/tabular_parser.rb in genevalidator-2.1.3

- old
+ new

@@ -3,11 +3,10 @@ require 'genevalidator/exceptions' require 'genevalidator/hsp' require 'genevalidator/query' -# module GeneValidator ## # This class parses the tabular output of BLAST (outfmt 6 & 7) class TabularParser extend Forwardable @@ -29,18 +28,13 @@ end ## # def analayse_tabular_file(filename) - results = [] - file = File.read(filename) - lines = CSV.parse(file, col_sep: "\t", skip_lines: /^#/, - headers: @column_names) - lines.each do |line| - results << line.to_hash - end - results + lines = CSV.parse(File.read(filename), col_sep: "\t", skip_lines: /^#/, + headers: @column_names) + lines.map(&:to_hash) end ## # move to next query def next @@ -61,41 +55,26 @@ return [] if !query_id.nil? && current_id != query_id hit_seq = initialise_classes(current_id) move_to_next_query hit_seq rescue StopIteration - return [] + [] end private ## # def initialise_classes(current_id, tab_results = @tab_results) hits = tab_results.partition { |h| h['qseqid'] == current_id }[0] - hit_list = [] grouped_hits = hits.group_by { |row| row['sseqid'] } - grouped_hits.each do |query_id, row| + grouped_hits.map do |_query_id, rows| hit_seq = Query.new - hit_seq.init_tabular_attribute(row[0]) - - initialise_all_hsps(query_id, hits, hit_seq) - + hit_seq.init_tabular_attribute(rows[0]) + hit_seq.hsp_list = rows.map { |row| Hsp.new(tabular_input: row) } hit_seq.type = :protein - hit_list.push(hit_seq) - end - hit_list - end - - ## - # - def initialise_all_hsps(current_query_id, hits, hit_seq) - hsps = hits.select { |row| row['sseqid'] == current_query_id } - hsps.each do |row| - hsp = Hsp.new - hsp.init_tabular_attribute(row) - hit_seq.hsp_list.push(hsp) + hit_seq end end end end