脚本代码:
#!/usr/bin/env Rscript library(getopt) library(ggtree) library(EBImage) library(ggplot2) library(stringr) library(reshape2) spec <- matrix(c( 'help', 'h', 0, "logical", "help print", 'tree', 'i', 1, "character", "input file tree.nwk, required.", 'tax', 't', 1, "character", "input file heatmap , required.", 'height' , 'H', 1, "integer","the height of graph ,unit is inches [optional, default: 8]", 'width' , 'W', 1, "integer","the width of graph ,unit is inches [optional, default: 6]", 'outdir', 'o', 1, "character", "output directory for pic file, [optional, default: cwd]", 'name', 'n', 1, "character", "output file name prefix, [optional, default: tree_heatmap_plot]" ), byrow = TRUE, ncol = 5) opt <- getopt(spec) if ( !is.null(opt$help) | is.null(opt$tree) | is.null(opt$tax)) { cat(getopt(spec, usage=TRUE)) q(status=1) } tree <-read.tree(opt$tree) tax <- read.table(opt$tax,row.names = 1,header = TRUE,check.names = FALSE,sep = "\t") groupInfo <- split(row.names(tax),tax$phylum) tree2 <- groupOTU(tree,groupInfo) tax_p <- tax[,-1] p <- ggtree(tree2,aes(color=group),right = TRUE)+theme(legend.position= "right")+geom_tiplab(align=TRUE,linetype = "solid")#linetype线条类型,dotted点线;solid实线;
p1 <- gheatmap(p,tax_p, offset=1, #offset设置两者间距,用于解决图重叠问题;
font.size=3, #font.size设置热图文字大小,解决文字过大重叠;
low="white", #最低值颜色 high="red", #最高值颜色 width = 1, #width设置热图相对树图的宽度,解决热图和树图大小关系;
colnames_position = "bottom", #热图文字文字位置 colnames_angle=45, #调节热图角度 hjust =1, #调整热图标签位置,解决文字与热图重叠问题。
) pdf(file=paste(opt$outdir,"/",opt$name,".pdf",sep=""), height=opt$height, width=opt$width) print(p1) dev.off()
Rscript tree_heatmap_plot.r -i tree.nwk -t my_tax.txt -n phylogenetic_heatmap_plot -H 8 -W 6 -o phylogenetic
-i 加树文件
-t 加热图文件
-n 绘图名称
-H 设置图片高度
-W设置图片宽度
-o 输出目录
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!