Module: GenomerPluginSummary::Metrics

Includes:
Enumerators
Included in:
Contigs, Genome, Sequences
Defined in:
lib/genomer-plugin-summary/metrics.rb

Constant Summary collapse

ALL =
: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

Instance Method Details

#atgc(sequence) ⇒ Object



35
36
37
# File 'lib/genomer-plugin-summary/metrics.rb', line 35

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

#count(type, scfd) ⇒ Object



16
17
18
# File 'lib/genomer-plugin-summary/metrics.rb', line 16

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

#gc(sequence) ⇒ Object



31
32
33
# File 'lib/genomer-plugin-summary/metrics.rb', line 31

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

#gc_content(type, scfd) ⇒ Object



10
11
12
13
14
# File 'lib/genomer-plugin-summary/metrics.rb', line 10

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

#length(type, scfd) ⇒ Object



24
25
26
27
28
29
# File 'lib/genomer-plugin-summary/metrics.rb', line 24

def length(type,scfd)
  enumerator_for(type,scfd).
    mapping{|i| i[:sequence]}.
    mapping(&:length).
    inject(:+) || 0
end

#percent(type, scfd) ⇒ Object



20
21
22
# File 'lib/genomer-plugin-summary/metrics.rb', line 20

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

#sequence_total(seqs) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/genomer-plugin-summary/metrics.rb', line 39

def sequence_total(seqs)
  return Hash[[:start, :stop, :size, :percent, :gc].map{|i| [i, 0]}] if seqs.empty?

  totals = seqs.inject({:size => 0, :percent => 0, :gc => 0}) do |hash,entry|
    hash[:start]  ||= entry[:start]
    hash[:stop]     = entry[:stop]
    hash[:size]    += entry[:size]
    hash[:percent] += entry[:percent]
    hash[:gc]      += entry[:gc] * entry[:size]

    hash
  end
  totals[:gc] /= totals[:size]
  totals
end