lib/genomer-plugin-summary/gaps.rb in genomer-plugin-summary-0.0.3 vs lib/genomer-plugin-summary/gaps.rb in genomer-plugin-summary-0.0.4

- old
+ new

@@ -1,46 +1,38 @@ require 'genomer' -require 'terminal-table' +require 'genomer-plugin-summary/format' class GenomerPluginSummary::Gaps < Genomer::Plugin + include GenomerPluginSummary::Format def run - tabulate determine_gaps scaffold + tabulate(determine_gaps(scaffold),flags) end - def headings - ['Number'.center(8), - 'Length'.center(8), - 'Start'.center(8), - 'End'.center(8), - 'Type'.center(12)] - end + COLUMNS = [:number, :length, :start, :end, :type] - def title - 'Scaffold Gaps' - end + FORMATTING = { + :title => 'Scaffold Gaps', + :headers => ['Number', 'Length', 'Start', 'End', 'Type'], + :width => { + 0 => 8, + 1 => 8, + 2 => 8, + 3 => 8, + 4 => 12 + }, + :justification => { + 0 => :right, + 1 => :right, + 2 => :right, + 3 => :right, + 4 => :center + } + } - def tabulate(contigs) - table = Terminal::Table.new(:title => title) do |t| - t << headings - t << :separator - contigs.each do |ctg| - t << [ctg[:number], - ctg[:length], - ctg[:start], - ctg[:end], - ctg[:type]] - end - end - - table.style = {:width => 60} - table.align_column 0, :right - table.align_column 1, :right - table.align_column 2, :right - table.align_column 3, :right - table.align_column 4, :center - - table.to_s + def tabulate(gaps,flags) + FORMATTING[:output] = flags[:output] + table(gaps.map{|gap| COLUMNS.map{|col| gap[col]}},FORMATTING) end def gap_locations(seq) seq.upcase.enum_for(:scan, /(N+)/).map do (Regexp.last_match.begin(0)+1)..(Regexp.last_match.end(0))