Module: Heatmap

Defined in:
lib/rbbt/plots/heatmap.rb

Class Method Summary collapse

Class Method Details

.heatmap(values, filename, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rbbt/plots/heatmap.rb', line 4

def self.heatmap(values, filename, options = {})
  scale, take_log, add_to_height, colors = Misc.process_options options, 
    :scale, :take_log, :add_to_height, :colors

  width = 200 + (values.fields.length * 16)
  height = 200 + (values.length * 16)
  size = [width, height].max
  size = [size, 10000].min

  heatmap_script = <<-EOF 
  #{ take_log ? "data <- log(data)" : ""}
      my.hclust <- function(d){ hclust(d, method="ward") }; 
      my.hclust <- function(d){ hclust(d) }; 
      rbbt.png_plot(
        '#{filename}', 
  #{ size }, 
  #{ (defined?(add_to_height) and not add_to_height.nil?) ? (size + (add_to_height * 16 * [1, (height.to_f / width)].max).to_i) : size }, 
        'heatmap(as.matrix(data),
  #{
  case scale.to_s
  when "true", 'row'
    'scale="row",' 
  when 'column' 
    'scale="column",' 
  when "none", ""
    'scale="none",'
  end
  }
  #{colors.nil? ? "" : "ColSideColors=#{colors},"} 
        hclustfun=my.hclust, 
        )',
        pointsize=12, type='cairo', res=150)
      data = NULL;
  EOF

  values.R heatmap_script
  
  filename
end

.heatmap2(values, filename, options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rbbt/plots/heatmap.rb', line 44

def self.heatmap2(values, filename, options = {})
  scale, take_log, add_to_height, colors = Misc.process_options options, 
    :scale, :take_log, :add_to_height, :colors

  width = 200 + (values.fields.length * 16)
  height = 200 + (values.length * 16)
  size = [width, height].max
  size = [size, 20000].min

  heatmap_script = <<-EOF 
  library(ggplot2);

  EOF

  values.R heatmap_script
  
  filename
end