comparison PanExplorer_workflow/R/heatmap_ani.R @ 1:032f6b3806a3 draft

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