Sha256: ceac080ed40dd9a389d989e77c5ecd8759e73bd141ea3b83fef147a762fdcc95

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

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

class GenomerPluginSummary::Gaps < Genomer::Plugin
  include GenomerPluginSummary::Format

  def run
    tabulate(determine_gaps(scaffold),flags)
  end

  COLUMNS    = [:number,  :length,  :start,  :end,  :type]

  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(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))
    end
  end

  def determine_gaps(scaffold)
    count  = 0
    length = 0

    scaffold.map do |entry|
      gaps = case entry.entry_type
             when :sequence then
               gap_locations(entry.sequence).map do |gap|
                 count += 1
                 {:number => count,
                  :length => (gap.end - gap.begin) + 1,
                  :start  => gap.begin + length,
                  :end    => gap.end   + length,
                  :type   => :contig}
               end
             when :unresolved then
               count += 1
               {:number => count,
                :length => entry.sequence.length,
                :start  => length + 1,
                :end    => length + entry.sequence.length,
                :type   => :unresolved}
             end
      length += entry.sequence.length
      gaps
    end.flatten
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

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