Sha256: 597a750ebb5eaa738cf00ffe5d493c3c0dfeade867f2fc1f7638322a08b8ca9b

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

require 'genomer'
require 'genomer-plugin-summary/metrics'
require 'genomer-plugin-summary/format'

class GenomerPluginSummary::Sequences < Genomer::Plugin
  include GenomerPluginSummary::Metrics
  include GenomerPluginSummary::Format
  include GenomerPluginSummary::Enumerators

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

    tabulate(sequences,total,flags)
  end

  COLUMNS    = [:id, :start, :stop, :size, :percent, :gc]

  FORMATTING = {
    :title   => 'Scaffold Sequences',
    :headers => ['Sequence', 'Start (bp)', 'End (bp)', 'Size (bp)', 'Size (%)', 'GC (%)'],
    :width => {
      0 => 16,
      1 => 10,
      2 => 10,
      3 => 10,
      4 => 8,
      5 => 6
    },
    :justification => {
      0 => :left,
      1 => :right,
      2 => :right,
      3 => :right,
      4 => :right,
      5 => :right
    },
    :format => {
      4 => '%#.2f',
      5 => '%#.2f'
    }
  }

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

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

  def calculate(scaffold)
    total_length   = scaffold.mapping(&:sequence).mapping(&:length).inject(&:+).to_f

    enumerator_for(:sequence,scaffold).mapping do |entry|
      sequence = entry.delete(:sequence)

      entry[:size]    = sequence.length
      entry[:gc]      = gc(sequence) / atgc(sequence) * 100
      entry[:percent] = sequence.length / total_length * 100
      entry
    end.to_a
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
genomer-plugin-summary-0.0.5 lib/genomer-plugin-summary/sequences.rb
genomer-plugin-summary-0.0.4 lib/genomer-plugin-summary/sequences.rb