Class: GenomerPluginSummary::Contigs

Inherits:
Genomer::Plugin
  • Object
show all
Includes:
Enumerators, Format, Metrics
Defined in:
lib/genomer-plugin-summary/contigs.rb

Constant Summary collapse

FORMATTING =
{
  :title   => 'Scaffold Contigs',
  :headers => ['Contig', 'Start (bp)', 'End (bp)', 'Size (bp)', 'Size (%)', 'GC (%)'],
  :width => {
    0 => 6,
    1 => 10,
    2 => 10,
    3 => 10,
    4 => 8,
    5 => 6
  },
  :justification => {
    0 => :right,
    1 => :right,
    2 => :right,
    3 => :right,
    4 => :right,
    5 => :right
  },
  :format => {
    4 => '%#.2f',
    5 => '%#.2f'
  }
}
COLUMNS =
[:id, :start, :stop, :size, :percent, :gc]

Constants included from Format

Format::DEFAULTS

Constants included from Metrics

Metrics::ALL

Instance Method Summary collapse

Methods included from Enumerators

#enumerator_for, #enumerator_for_all, #enumerator_for_contig, #enumerator_for_gap, #enumerator_for_sequence, #enumerator_for_unresolved

Methods included from Format

#create_cells, #csv, #format_cell, #pretty, #table

Methods included from Metrics

#atgc, #count, #gc, #gc_content, #length, #percent, #sequence_total

Instance Method Details

#calculate(scaffold) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/genomer-plugin-summary/contigs.rb', line 53

def calculate(scaffold)
  total_length = scaffold.mapping(&:sequence).mapping(&:length).inject(&:+).to_f
  enumerator_for_contig(scaffold).
    mapping{|i| i[:gc] = gc(i[:sequence]) / atgc(i[:sequence]) * 100; i}.
    mapping{|i| i[:size] = i[:sequence].length; i}.
    mapping{|i| i[:percent] = i[:size] / total_length * 100; i}.
    mapping{|i| i.delete(:sequence); i}.
    to_a
end

#runObject



37
38
39
40
41
42
# File 'lib/genomer-plugin-summary/contigs.rb', line 37

def run
  contigs = calculate(scaffold)
  total   = sequence_total(contigs)

  tabulate(contigs,total,flags)
end

#tabulate(contigs, total, flags) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/genomer-plugin-summary/contigs.rb', line 44

def tabulate(contigs,total,flags)
  rows = contigs.map{|contig| COLUMNS.map{|col| contig[col]}}.
    <<(:separator).
    <<(COLUMNS.map{|col| total[col] || 'All'})

  FORMATTING[:output] = flags[:output]
  table(rows,FORMATTING)
end