library(devtools) install_github("Stefanos-Apostle/NixSEA-package") library(NixSEA) library(msigdbr) library(fgsea) library(tools) library(ggplot2)
setwd("/secondary/projects/mnp/stefanos/yang/RNAseq/nnat") #BiocManager::install("DESeq2") library(DESeq2) setwd("/secondary/projects/mnp/stefanos/yang/RNAseq/nnat") countdata <- read.delim("counts_yang.txt", sep="\t", row.names = 1) coldata <- read.delim("sample_sheet.txt", row.names = 1) coldata$num. <- factor(coldata$num.) coldata$batch <- factor(coldata$batch) ddsFullCountTable <- DESeqDataSetFromMatrix(countData = countdata, colData = coldata, design = ~ batch + sex + condition) ddsFullCountTable$condition <- relevel(ddsFullCountTable$condition, ref = "wt") ##reorders data set so that wt is the first point which is used to calculate log2 change dds <- DESeq(ddsFullCountTable) ##DE results wt vs gigantic res_gig_wt <- results(dds, contrast = c("condition","gigantic", "wt")) sum(res_gig_wt$padj < 0.1, na.rm = TRUE) #total number of significantly expressed genes with adjusted pvalue < 0.1 (allows for 10% false positives) Sigres_gig_wt <- res_gig_wt[which(res_gig_wt$padj < 0.1),] head(Sigres_gig_wt[order(Sigres_gig_wt$log2FoldChange),]) ##top downregulated genes tail(Sigres_gig_wt[order(Sigres_gig_wt$log2FoldChange),]) ##top upregulated genes plotMA(res_gig_wt, ylim = c(-10,10)) plotDispEsts(dds, ylim = c(1e-6, 1e1)) hist(res_gig_wt$padj, col = "grey", main = "Adjusted P-value Distribution") library(biomaRt) res_gig_wt$ensembl <- sapply( strsplit( rownames(res_gig_wt), split="\\+" ), "[", 1 ) ensembl = useMart( "ensembl", dataset = "mmusculus_gene_ensembl" ) genemap <- getBM( attributes = c("ensembl_gene_id", "entrezgene_id", "mgi_symbol"), filters = "ensembl_gene_id", values = res_gig_wt$ensembl, mart = ensembl )
idx <- match( res_gig_wt$ensembl, genemap$ensembl_gene_id ) res_gig_wt$entrez <- genemap$entrezgene[ idx ] res_gig_wt$mgi_symbol <- genemap$mgi_symbol[ idx ]#uppercase because GSEA uses human gene names head(res_gig_wt, 5)
library(devtools) install_github("Stefanos-Apostle/NixSEA-package") library(NixSEA) library(msigdbr) library(fgsea) library(tools)
RNK_file <- RNK_make(res_gig_wt) hist(RNK_file, xlab = "Gene Rank", xlim=c(-50,50))
msigdb <- msigdbr(species = "Mus musculus", category = "C2") sets <- keyword_geneset(msigdb, "") genesets <- geneset_list(sets) fgseaRes <- fgsea(genesets, RNK_file, nperm = 10000, minSize = 15, maxSize = 500) #fgseaRes[order(fgseaRes$padj),] head(fgseaRes[order(fgseaRes$NES, decreasing = FALSE),])
HFD_enrich <- fgseaRes[which(fgseaRes$NES > 0),] HFD_sig <- HFD_enrich[which(HFD_enrich$padj < 0.05),] HFD_vsig <- HFD_enrich[which(HFD_enrich$padj < 0.01),] length(HFD_enrich$pathway) length(HFD_sig$pathway) length(HFD_vsig$pathway)
NC_enrich <- fgseaRes[which(fgseaRes$NES < 0),] NC_sig <- NC_enrich[which(NC_enrich$padj < 0.05),] NC_vsig <- NC_enrich[which(NC_enrich$padj < 0.01),] length(NC_enrich$pathway) length(NC_sig$pathway) length(NC_vsig$pathway)
plotEnrichment(genesets$BURTON_ADIPOGENESIS_6, RNK_file)
sets <- NixSEA::keyword_geneset(msigdb, "BURTON_ADIPOGENESIS_6") genesets <- NixSEA::geneset_list(sets) figure1 <- enrichment_analysis(genesets, RNK_file, sets, figure_header = "Testing enrichment in down phenotype")
RNK_table <- data.frame("Genename" = names(RNK_file), "stat" = RNK_file) write.table(RNK_table, "/secondary/projects/mnp/stefanos/tools/R-packages/NixSEA/example/Validation_GvWT.rnk",quote=F, sep="\t",eol = "\r", row.names = F)
knitr::include_graphics("/secondary/projects/mnp/stefanos/tools/R-packages/NixSEA/example/Index_GvWT_GSEA.png")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.