-
Notifications
You must be signed in to change notification settings - Fork 26
/
plot_mg_heatdend.r
61 lines (52 loc) · 2.87 KB
/
plot_mg_heatdend.r
1
2
3
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# This is a function that uses matR to generate heatmap-dendrogram vizualizations
# It's a stripped down simple version for basic viz
# pretty much the only user option is to decide if they want the rows labeled
# here's a minimal invocation:
# plot_mg_heatdend(table_in="test_data.txt")
# here's an invocation that explicitly addresses all of the input args:
# plot_mg_heatdend(table_in="test_data.txt", image_out="my_heat-dend",label_rows=TRUE, image_width_in=10, image_height_in=10, image_res_dpi=200)
plot_mg_heatdend <<- function(
table_in="", # annotation abundance table (raw or normalized values)
image_out="default",
label_rows=FALSE,
order_columns=FALSE,
figure_title=NULL, # NULL for no title or quoted text string for figure title
colCex="0.25", # scale factor for column labels
rowCex="0.25", # scale factor for row labels
image_width_in=8.5,
image_height_in=11,
image_res_dpi=300
)
{
require(matR)
###################################################################################################################################
# generate filename for the image output
if ( identical(image_out, "default") ){
image_out = paste(table_in, ".heat-dend.png", sep="", collapse="")
}else{
image_out = paste(image_out, ".png", sep="", collapse="")
}
###################################################################################################################################
###################################################################################################################################
######## import/parse all inputs
# import DATA the data (from tab text)
data_matrix <- data.matrix(read.table(table_in, row.names=1, header=TRUE, sep="\t", comment.char="", quote="", check.names=FALSE))
# convert data to a matR collection
data_collection <- suppressWarnings(as(data_matrix, "collection")) # take the input data and create a matR object with it
###################################################################################################################################
# Generate the plot
png(
filename = image_out,
width = image_width_in,
height = image_height_in,
res = image_res_dpi,
units = 'in'
)
# Can create heat dend with or without row labels
if ( identical( label_rows, FALSE ) ){
suppressWarnings(matR::heatmap(data_collection, colsep=NULL, main=figure_title, Colv=order_columns, cexRow=rowCex, cexCol=colCex))
}else{
suppressWarnings(matR::heatmap(data_collection, colsep=NULL, main=figure_title, Colv=order_columns, labRow=dimnames(data_collection$x)[[1]]))
}
dev.off()
}