Class: Bio::KEGG::EXPRESSION

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/db/kegg/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ EXPRESSION

Returns a new instance of EXPRESSION.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bio/db/kegg/expression.rb', line 19

def initialize(entry)
  @orf2val   = Hash.new('')
  @orf2rgb   = Hash.new('')
  @orf2ratio = Hash.new('')
  @max_intensity = 10000
  entry.split("\n").each do |line|
    unless /^#/ =~ line
      ary = line.split("\t")
      orf = ary.shift
      val = ary[2, 4].collect {|x| x.to_f}
      @orf2val[orf] = val 
    end
  end
end

Instance Attribute Details

#max_intensityObject (readonly)

Returns the value of attribute max_intensity.



36
37
38
# File 'lib/bio/db/kegg/expression.rb', line 36

def max_intensity
  @max_intensity
end

#orf2ratioObject (readonly)

Returns the value of attribute orf2ratio.



35
36
37
# File 'lib/bio/db/kegg/expression.rb', line 35

def orf2ratio
  @orf2ratio
end

#orf2rgbObject (readonly)

Returns the value of attribute orf2rgb.



34
35
36
# File 'lib/bio/db/kegg/expression.rb', line 34

def orf2rgb
  @orf2rgb
end

#orf2valObject (readonly)

Returns the value of attribute orf2val.



33
34
35
# File 'lib/bio/db/kegg/expression.rb', line 33

def orf2val
  @orf2val
end

Instance Method Details

#control_avgObject



38
39
40
41
42
43
44
# File 'lib/bio/db/kegg/expression.rb', line 38

def control_avg
  sum = 0.0
  @orf2val.values.each do |v|
    sum += v[0] - v[1]
  end
  sum/orf2val.size
end

#control_sdObject



74
75
76
77
# File 'lib/bio/db/kegg/expression.rb', line 74

def control_sd
  var = self.control_var
  Math.sqrt(var)
end

#control_varObject



54
55
56
57
58
59
60
61
62
# File 'lib/bio/db/kegg/expression.rb', line 54

def control_var
  sum = 0.0
  avg = self.control_avg
  @orf2val.values.each do |v|
    tmp = v[0] - v[1]
    sum += (tmp - avg)*(tmp - avg)
  end
  sum/orf2val.size
end

#down_regulated(num = 20, threshold = nil) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/bio/db/kegg/expression.rb', line 98

def down_regulated(num=20, threshold=nil)
  logy_minus_logx
  ary = @orf2ratio.to_a.sort{|a, b| a[1] <=> b[1]}
  if threshold != nil
    i = 0
    while ary[i][1] < threshold
      i += 1
    end
    return ary[0..i]
  else
    return ary[0..num-1]
  end
end

#logy_minus_logxObject



126
127
128
129
130
# File 'lib/bio/db/kegg/expression.rb', line 126

def logy_minus_logx
  @orf2val.each do |k, v|
    @orf2ratio[k] = (1.0/Math.log10(2))*(Math.log10(v[2]-v[3]) - Math.log10(v[0]-v[1]))
  end
end

#regulated(num = 20, threshold = nil) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/bio/db/kegg/expression.rb', line 112

def regulated(num=20, threshold=nil)
  logy_minus_logx
  ary = @orf2ratio.to_a.sort{|a, b| b[1].abs <=> a[1].abs}
  if threshold != nil
    i = 0
    while ary[i][1].abs > threshold
      i += 1
    end
    return ary[0..i]
  else
    return ary[0..num-1]
  end
end

#target_avgObject



46
47
48
49
50
51
52
# File 'lib/bio/db/kegg/expression.rb', line 46

def target_avg
  sum = 0.0
  @orf2val.values.each do |v|
    sum += v[2] - v[3]
  end
  sum/orf2val.size
end

#target_sdObject



79
80
81
82
# File 'lib/bio/db/kegg/expression.rb', line 79

def target_sd
  var = self.target_var
  Math.sqrt(var)
end

#target_varObject



64
65
66
67
68
69
70
71
72
# File 'lib/bio/db/kegg/expression.rb', line 64

def target_var
  sum = 0.0
  avg = self.target_avg
  @orf2val.values.each do |v|
    tmp = v[2] - v[3]
    sum += (tmp - avg)*(tmp - avg)
  end
  sum/orf2val.size
end

#up_regulated(num = 20, threshold = nil) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/bio/db/kegg/expression.rb', line 84

def up_regulated(num=20, threshold=nil)
  logy_minus_logx
  ary = @orf2ratio.to_a.sort{|a, b| b[1] <=> a[1]}
  if threshold != nil
    i = 0
    while ary[i][1] > threshold
      i += 1
    end
    return ary[0..i]
  else
    return ary[0..num-1]
  end
end

#val2rgbObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/bio/db/kegg/expression.rb', line 132

def val2rgb
  col_unit = @max_intensity/255
  @orf2val.each do |k, v|
    tmp_val = ((v[0] - v[1])/col_unit).to_i
    if tmp_val > 255
      g = "ff" 
    else
      g = format("%02x", tmp_val)
    end
    tmp_val = ((v[2] - v[3])/col_unit).to_i
    if tmp_val > 255
      r = "ff" 
    else
      r = format("%02x", tmp_val)
    end
    @orf2rgb[k] = r + g + "00"
  end

end