annotate R/heatmap_ani.R @ 15:dbde253606c5 draft default tip

Uploaded
author dereeper
date Wed, 11 Dec 2024 08:25:06 +0000
parents e42d30da7a74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/local/R-4.1.2/bin/R
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
2
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
3 library(RColorBrewer)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
4 library(dendextend)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
5 library("optparse")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
6
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
7 #args = commandArgs(trailingOnly=TRUE)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
8
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9 option_list = list(
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10 make_option(c("-f", "--file"), type="character", default=NULL,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 help="dataset file name", metavar="character"),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 make_option(c("-o", "--out"), type="character", default="out.txt",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 help="output file name [default= %default]", metavar="character")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 );
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15 opt_parser = OptionParser(option_list=option_list);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16 opt = parse_args(opt_parser);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18 if (is.null(opt$file)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19 print_help(opt_parser)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 stop("At least one argument must be supplied (input file).\n", call.=FALSE)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 if (is.null(opt$out)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 print_help(opt_parser)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 stop("At least one argument must be supplied (out file).\n", call.=FALSE)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 #svglite(opt$out,width = 31, height = 28)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 pdf(opt$out,width = 31,height = 28)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 mydata <- read.table(opt$file, header=TRUE,sep="\t", row.names="Genomes")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 iris <- mydata
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 #dend_r <- iris %>% dist(method = "man") %>% hclust(method = "ward.D") %>% as.dendrogram %>% ladderize
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 dend_r <- iris %>% dist(method = "man") %>% hclust(method = "com") %>% as.dendrogram %>% ladderize
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 #dend_c <- t(iris) %>% dist(method = "man") %>% hclust(method = "com") %>% as.dendrogram %>% ladderize
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 dend_c <- t(iris) %>% dist(method = "man") %>% hclust(method = "ward.D") %>% as.dendrogram %>% ladderize
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 #write(hc2Newick(dend_c),file='hclust.newick')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 Colors=c("yellow","red")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 Colors=colorRampPalette(Colors)(100)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 mat <- as.matrix(t(iris-1))
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 out <- gplots::heatmap.2(mat,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 main = "",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 scale="none",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 #srtCol=NULL,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 Rowv = dend_r,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 Colv = dend_r,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 #key = FALSE,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 margins =c(20,20),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 col=Colors,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 trace="row", hline = NA, tracecol = NA
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 )
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 write.table(
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 data.frame(gene = rownames(mat)[out$rowInd]),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 paste(opt$out, "rows.csv", sep="."),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 row.names = FALSE,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 quote = FALSE,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 sep = ',')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 write.table(
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 data.frame(gene = colnames(mat)[out$colInd]),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 paste(opt$out, "cols.csv", sep="."),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 row.names = FALSE,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 quote = FALSE,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70 sep = ',')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 dev.off()
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73