Sha256: bf3d8326a96ddecefb33b9a43743763e558d1c5b20281da04a59d93ea286b344

Contents?: true

Size: 842 Bytes

Versions: 1

Compression:

Stored size: 842 Bytes

Contents

require 'genomer'
require 'lazing'

module GenomerPluginSummary::Metrics

  ALL = :all

  def gc_content(type,scfd)
    gc   = enumerator_for(type,scfd).mapping{|i|   gc(i)}.inject(:+) || 0.0
    atgc = enumerator_for(type,scfd).mapping{|i| atgc(i)}.inject(:+) || 0.0
    gc / atgc * 100
  end

  def count(type,scfd)
    enumerator_for(type,scfd).count
  end

  def percent(type,scfd)
    length(type,scfd) / length(ALL,scfd).to_f * 100
  end

  def length(type,scfd)
    enumerator_for(type,scfd).
      mapping(&:sequence).
      mapping(&:length).
      inject(:+) || 0
  end

  def gc(entry)
    entry.sequence.gsub(/[^GCgc]/,'').length.to_f
  end

  def atgc(entry)
    entry.sequence.gsub(/[^ATGCatgc]/,'').length.to_f
  end

  def enumerator_for(type,scaffold)
    scaffold.selecting{|i| [ALL,i.entry_type].include? type }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
genomer-plugin-summary-0.0.3 lib/genomer-plugin-summary/metrics.rb