Class: Transrate::ContigMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/transrate/contig_metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assembly) ⇒ ContigMetrics

Returns a new instance of ContigMetrics.



12
13
14
15
16
# File 'lib/transrate/contig_metrics.rb', line 12

def initialize assembly
  @assembly = assembly
  self.initial_values
  @has_run = false
end

Instance Attribute Details

#at_skewObject (readonly)

Returns the value of attribute at_skew.



7
8
9
# File 'lib/transrate/contig_metrics.rb', line 7

def at_skew
  @at_skew
end

#bases_nObject (readonly)

Returns the value of attribute bases_n.



9
10
11
# File 'lib/transrate/contig_metrics.rb', line 9

def bases_n
  @bases_n
end

#cpg_ratioObject (readonly)

Returns the value of attribute cpg_ratio.



7
8
9
# File 'lib/transrate/contig_metrics.rb', line 7

def cpg_ratio
  @cpg_ratio
end

#gc_propObject (readonly)

Returns the value of attribute gc_prop.



7
8
9
# File 'lib/transrate/contig_metrics.rb', line 7

def gc_prop
  @gc_prop
end

#gc_skewObject (readonly)

Returns the value of attribute gc_skew.



7
8
9
# File 'lib/transrate/contig_metrics.rb', line 7

def gc_skew
  @gc_skew
end

#has_runObject (readonly)

Returns the value of attribute has_run.



10
11
12
# File 'lib/transrate/contig_metrics.rb', line 10

def has_run
  @has_run
end

#linguistic_complexityObject (readonly)

Returns the value of attribute linguistic_complexity.



8
9
10
# File 'lib/transrate/contig_metrics.rb', line 8

def linguistic_complexity
  @linguistic_complexity
end

#proportion_nObject (readonly)

Returns the value of attribute proportion_n.



9
10
11
# File 'lib/transrate/contig_metrics.rb', line 9

def proportion_n
  @proportion_n
end

#shannonObject (readonly)

Returns the value of attribute shannon.



8
9
10
# File 'lib/transrate/contig_metrics.rb', line 8

def shannon
  @shannon
end

#wootton_federhenObject (readonly)

Returns the value of attribute wootton_federhen.



8
9
10
# File 'lib/transrate/contig_metrics.rb', line 8

def wootton_federhen
  @wootton_federhen
end

#zlib_compObject (readonly)

Returns the value of attribute zlib_comp.



8
9
10
# File 'lib/transrate/contig_metrics.rb', line 8

def zlib_comp
  @zlib_comp
end

Instance Method Details

#calculateObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/transrate/contig_metrics.rb', line 33

def calculate
  total = 0
  a = 0
  c = 0
  g = 0
  t = 0
  @bases_n = 0
  cpg_count = 0
  lc = 0
  k = 6
  @assembly.assembly.each_value do |contig|
    total += contig.length
    a += contig.bases_a
    c += contig.bases_c
    g += contig.bases_g
    t += contig.bases_t
    @bases_n += contig.bases_n
    cpg_count += contig.cpg_count
    lc += contig.linguistic_complexity k
  end
  @gc_prop = (g + c) / (a + c + g + t).to_f
  @gc_skew = (g - c) / (g + c).to_f
  @at_skew = (a - t) / (a + t).to_f
  @cpg_ratio = cpg_count.to_f / (c * g) * total
  @linguistic_complexity = lc / @assembly.assembly.size.to_f
  @proportion_n = @bases_n / total.to_f
end

#initial_valuesObject



18
19
20
21
22
23
24
25
26
# File 'lib/transrate/contig_metrics.rb', line 18

def initial_values
  @gc_prop = -1
  @gc_skew = -1
  @at_skew = -1
  @cpg = -1
  @bases_n = -1
  @proportion_n = -1
  @linguistic_complexity = -1
end

#resultsObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/transrate/contig_metrics.rb', line 61

def results
  return if !@has_run
  return {'gc' => @gc_prop,
          'gc_skew' => @gc_skew,
          'at_skew' => @at_skew,
          'cpg_ratio' => @cpg_ratio,
          'bases_n' => @bases_n,
          'proportion_n' => @proportion_n,
          'linguistic_complexity' => @linguistic_complexity
         }
end

#runObject



28
29
30
31
# File 'lib/transrate/contig_metrics.rb', line 28

def run
  calculate
  @has_run = true
end