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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| volcanofun <- function(datset=NC_PC_DEP, genelist=c("FIBB","FIBA","FA5","EGF","OIT3","IBP2","GANAB","RELN","LYSC","CADH1"), group_name=subgrp[1:2], group_col=grp.col[1:2], pval=0.05, fc=1){ dat <- datset %>% mutate(color=factor(Enrichment, levels = c(group_name, "Nonsignif"))) dat_status <- table(dat$color) dat_status_number <- as.numeric(dat_status) dat_status_name <- names(dat_status) legend_label <- c(paste0(dat_status_name[1], " (", dat_status_number[1], ")"), paste0(dat_status_name[2], " (", dat_status_number[2], ")"), paste0("Nonsignif", " (", dat_status_number[3], ")")) dat.signif <- subset(dat, adj.P.Val < pval & abs(logFC) > fc) %>% filter(GeneID%in%genelist) print(table(dat.signif$color)) group_col_new <- c(group_col, "#979797") group_name_new <- levels(dat$color) xlabel <- paste0("log2(", paste(group_name, collapse="/"), ")") pl <- ggplot(dat, aes(x = -logFC, y = -log10(adj.P.Val), color = color))+ geom_point(size = 2, alpha = 1, stroke = 1)+ scale_color_manual(name = NULL, values = group_col_new, labels = c(legend_label, "Nonsignif"))+ xlab(xlabel) + ylab(expression(-log[10]("adjusted p-value")))+ geom_hline(yintercept=-log10(pval), alpha=.8, linetype=2, size=.7)+ geom_vline(xintercept=fc, alpha=.8, linetype=2, size=.7)+ geom_vline(xintercept=-fc, alpha=.8, linetype=2, size=.7)+ geom_text_repel(data = dat.signif, aes(label = GeneID), size = 4, max.overlaps = getOption("ggrepel.max.overlaps", default = 80), segment.linetype = 1, segment.curvature = -1e-20, box.padding = unit(0.35, "lines"), point.padding = unit(0.3, "lines"), arrow = arrow(length = unit(0.005, "npc")), color = "black", bg.color = "white", bg.r = 0.15)+ annotate("text", x=min(dat$logFC), y=-log10(pval), label=pval, size=6, color="red")+ annotate("text", x=fc, y=0, label=fc, size=6, color="red")+ annotate("text", x=-fc, y=0, label=-fc, size=6, color="red")+ scale_y_continuous(trans = "log1p")+ guides(color=guide_legend(override.aes = list(size = 3)))+ theme_bw()+ theme(axis.title = element_text(color = "black", size = 12), axis.text = element_text(color = "black", size = 10), text = element_text(size = 8, color = "black", family="serif"), panel.grid = element_blank(), legend.position = c(.15, .1), legend.key.height = unit(0.6,"cm"), legend.text = element_text(face = "bold", color = "black", size = 8), strip.text = element_text(face = "bold", size = 14)) return(pl) }
Gene_boxplot <- function(datset=ExprSet, genelist=c("FIBB","FIBA","FA5","EGF","OIT3","IBP2","GANAB","RELN","LYSC","CADH1"), group_name=subgrp[1:2], group_col=grp.col[1:2]){
pheno <- pData(datset) %>% filter(SubGroup%in%group_name) pheno$SubGroup <- factor(as.character(pheno$SubGroup), levels = group_name)
edata <- data.frame(exprs(datset)) %>% dplyr::select(rownames(pheno)) %>% rownames_to_column("GeneID") %>% filter(GeneID%in%genelist) %>% column_to_rownames("GeneID") mdat <- pheno %>% dplyr::select(SubGroup) %>% rownames_to_column("SampleID") %>% inner_join(t(edata) %>% data.frame() %>% rownames_to_column("SampleID"), by = "SampleID") %>% column_to_rownames("SampleID") plotdata <- mdat %>% tidyr::gather(key="geneID", value="value", -SubGroup) %>% mutate(SubGroup=factor(SubGroup, levels = group_name)) plotdata$geneID <- factor(plotdata$geneID, levels = genelist) pl <- ggplot(plotdata, aes(x = SubGroup, y = value, fill= SubGroup))+ stat_boxplot(geom = "errorbar", width = 0.15, position = position_dodge(0.4)) + geom_boxplot(width = 0.4, outlier.colour = "black", outlier.shape = 21, outlier.size = .5)+ scale_fill_manual(values = group_col)+ facet_wrap(facets = "geneID", scales = "free_y", nrow = 2)+ labs(x="", y="Relative Abundance (Mass Spectrometry)")+ guides(fill=F)+ theme_classic()+ theme(axis.title = element_text(color = "black", size = 12), axis.text.x = element_text(color = "black", size = 10, hjust = .5, vjust = .5), text = element_text(size = 8, color = "black", family="serif"), panel.grid = element_blank(), strip.text = element_text(face = "bold", size = 12)) return(pl) }
NC_PC_volcano <- volcanofun(datset=NC_PC_DEP, genelist=c("FIBB","FIBA","FA5","OIT3","IBP2","GANAB","RELN","LYSC","CADH1","EGF"), group_name=subgrp[1:2], group_col=grp.col[1:2])
NC_PC_volcano ggsave("NC_PC_Mass_volcano.pdf", NC_PC_volcano, width = 8, height = 6) NC_PC_boxplot <- Gene_boxplot(datset=ExprSet, genelist=c("FIBB","FIBA","FA5","OIT3","IBP2","GANAB","RELN","LYSC","CADH1","EGF"), group_name=subgrp[1:2], group_col=grp.col[1:2]) NC_PC_boxplot ggsave("NC_PC_Mass_SpecificDEP_boxplot.pdf", NC_PC_boxplot, width = 8, height = 6)
|