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
|