1、结果处理
plantCARE_output_PlantCARE_******.tab的文件为结果文件,对其进行简单的过滤处理,将第二列中空白和unname的部分进行过滤,最后保存为一个promoter.cvs文件,在R中进行绘制图像。
2、R绘图
#加载需要用到的R包
library(data.table)
library(tidyverse)
library(paletteer)
package.list=c("tidyverse","ggsci","ggh4x","aplot","RColorBrewer","ggpubr","cowplot","grid","ggplotify")
group_color <- c(paletteer_d("ggprism::greenwash"),paletteer_d("ggprism::colors"))
for (package in package.list) {
if (!require(package,character.only=T, quietly=T)) {
install.packages(package)
library(package, character.only=T)
}
}
#导入文件
cis <- fread("/path/you/promoter.csv")
#对文件进行处理,统计顺式元件格式和展示的geneID
fun <- cis %>% select(V2,V8)
fun <- fun[!duplicated(fun),]
#顺式元件的描述
FILT=unique(cis$V8)
#顺式元件的名称
data <- cis %>% filter(V2 %in% unique(cis$V2)| V8 %in% FILT) %>%
mutate(V1=V1) %>% select(1,2,8) %>%
group_by(V1) %>%
count(V2) %>% ungroup() %>%
spread(V2,n) %>%
mutate_all(~replace(.,is.na(.), 0)) %>%
gather(key="name",value = "value",-1) %>%
mutate(value=as.character(value),signif=value,signif=case_when(value=="0" ~ " ",TRUE ~ as.character(value)))
df <- data %>% select(name) %>% distinct()
df_fun <- data.frame(fun= fun[match(df$name,fun$V2),2]) %>% rename(fun=V8)
df <- cbind(df,df_fun)
df$group <- "NA"
df$group[str_which(df$fun,'light') ] <- 'Light'
df$group[str_which(df$fun,'abscisic ') ] <- 'ABA'
df$group[str_which(df$fun,'auxin') ] <- 'Aux'
df$group[str_which(df$fun,'MeJA') ] <- 'MeJA'
df$group[str_which(df$fun,'salicylic') ] <- 'SA'
df$group[str_which(df$fun,'gibberellin') ] <- 'Gas'
df$group[str_which(df$name,'WUN') ] <- 'Wound'
df$group[str_which(df$name,'LTR') ] <- 'Stress'
df$group[str_which(df$name,"TC-rich repeats") ] <- 'Stress'
df$group[str_which(df$group,"NA") ] <- 'MYB'
df <- df %>% left_join(.,data,by="name")
df2 <- df
#id信息
levels=unique(cis$V1)
#统计分组
df2$V1 <- factor(df2$V1,levels=rev(levels))
group_levels=c('ABA','Aux','Gas','MeJA','SA','Light','Wound','Stress','MYB')
df2$group <- factor(df2$group,levels=group_levels)
##开始绘图
##随机颜色
colors <- colors()
colors <- colors[colors != "black"]#不挑选黑色
#set.seed(123)
random_colors <- sample(colors, length(unique(cis$V2)))
color <- random_colors
# color <- c("white","#709AE1FF","#8A9197FF","#D2AF81FF","#FD7446FF",
# "#D5E4A2FF","#197EC0FF","#F05C3BFF","#46732EFF",
# "#71D0F5FF","#370335FF","#075149FF","#C80813FF","#91331FFF",
# "#1A9993FF","#FD8CC1FF")
#第一张图
p1 <- df2 %>%
ggplot(.,aes(interaction(name,group),V1,color=value,fill=value))+
geom_tile(color="grey80",fill="white",size=0.5)+
geom_point(pch=22,size=5)+
geom_text(aes(label=signif),size=3,color="black")+
guides(x="axis_nested")+
labs(x = NULL,y = NULL,color=NULL)+
scale_color_manual(values=color)+
scale_fill_manual(values=color)+
scale_x_discrete(expand=c(0,0)) +
scale_y_discrete(expand=c(0,0),position="left")+
theme(axis.text.x=element_text(color="black",angle=90,size=8,hjust=0),
axis.text.y=element_text(color="black",size=8),
axis.ticks.x=element_blank(),
axis.ticks.y=element_blank(),
panel.border=element_rect(fill=NA,color="grey80",size=1,linetype="solid"),
ggh4x.axis.nestline.x = element_line(size = 1),
ggh4x.axis.nesttext.x = element_text(colour =sample(group_color, length(unique(df2$group))),angle =30),
legend.position = "non",
plot.margin=unit(c(0.2,0.2,0.2,0.2),units=,"cm"))+
scale_x_discrete(expand = c(0,0),position = 'top')
pdf(file = "n.pdf",width = 11,height = 8)
print(p1)
dev.off()
#第二张图
p2 <- df2 %>% select(name,V1,value,group) %>% mutate(value=as.numeric(value)) %>%
ggplot(aes(value,V1,fill=group))+
geom_col(position="stack",width=0.5)+
labs(x=NULL,y=NULL)+
scale_fill_manual(values= sample(group_color, length(unique(df2$group))))+
scale_x_continuous(expand = expansion(0),position = 'top')+
theme_test()+
theme(axis.text.x=element_text(color="black",size=8,hjust=0),
axis.text.y=element_blank(),
axis.ticks.x=element_blank(),
axis.ticks.y=element_blank(),
panel.border=element_rect(fill=NA,color="grey70",size=1,linetype="solid"),
ggh4x.axis.nestline.x = element_line(size = 1),
legend.position = "non",
legend.key=element_blank(),
legend.title = element_blank(),
legend.text = element_text(color="black",size=5),
legend.spacing.x=unit(0.1,'cm'),
legend.spacing.y=unit(0.1,'cm'),
legend.key.width=unit(0.3,'cm'),
legend.key.height=unit(0.3,'cm'),
legend.background=element_blank(),
plot.margin=unit(c(0.2,0.2,0.2,0.2),units=,"cm"))+
guides(fill = guide_legend(direction = "horizontal"))+
guides(fill=guide_legend(nrow=6, byrow=TRUE))
p3 <- p2 + theme(legend.position = "top")
pdf(file = "n.pdf",width = 15,height = 8)
p1 %>% insert_right(p2,width=.6) %>% as.grob() %>% ggdraw()+
draw_plot(ggpubr::get_legend(p3) %>% as_ggplot(),scale=0.05,x=0.345,y=0.43) +
theme(plot.margin = unit(c(1,1,1,1), "cm"))
dev.off()
3、结果展示
![](https://img.haomeiwen.com/i16304853/fcaa83ee18acff5a.png)
网友评论