# Load libs functions library("fgsea") library("DESeq2") library("ggplot2") library("pheatmap") library("biomaRt") source("AnalyseMetadataCorrelationBulk.R") # Counts and metadata rawCounts <- data.frame(read.table("Pln/Aso/readcounts_raw.txt", header=T, row.names=1, stringsAsFactors=F)) metadata <- data.frame(read.table("Pln/Aso/sample_annot.txt", sep='\t', header=T, row.names=1)) # Differential gene expression dds <- DESeqDataSetFromMatrix(countData=rawCounts[,rownames(metadata)], colData=metadata, design= ~ Condition) dds$Condition <- relevel(dds$Condition, ref='8w_wt_unt') dds <- DESeq(dds) #DE Lists res.hom.over.wt <- as.data.frame(results(dds, contrast=c("Condition", '8w_hom_sham', '8w_wt_unt'))) res.treatment.over.sham <- as.data.frame(results(dds, contrast=c("Condition", '8w_hom_tr', '8w_hom_sham'))) res.treatment.over.wt <-as.data.frame(results(dds, contrast=c("Condition", '8w_hom_tr', '8w_wt_unt'))) # Principle component analysis rld <- rlog(dds, blind=FALSE) pcadata <- plotPCA(rld, intgroup=colnames(metadata), returnData=T) pca <- ggplot(pcadata, aes(x=PC1, y=PC2, group = Condition)) + geom_point(aes(color=Condition)) # Gene set enrichment analysis genesForGSEA <- res.hom.over.wt outDir <- 'hom.over.wt' # Convert to human orthologous genes human = useMart("ensembl", dataset = "hsapiens_gene_ensembl") mouse = useMart("ensembl", dataset = "mmusculus_gene_ensembl") ortho_table <- getLDS(attributes = c('ensembl_gene_id'),filters = 'ensembl_gene_id', values = row.names(genesForGSEA), mart = mouse,attributesL = c("hgnc_symbol"), martL = human, uniqueRows = TRUE) genesForGSEA <- merge(genesForGSEA, ortho_table, by.x="row.names", by.y=colnames(ortho_table)[1], sort=F, all.x=F, all.y=F) # run GSEA gmtFiles <- list.files('Database/MSigdb/v6.2/symbol/') fgseaRes <- list() for(j in 1:length(gmtFiles)) { rankedgenesForGSEA <- genesForGSEA[order(genesForGSEA[,'stat'], decreasing = T ),] rankedGenes <- rankedgenesForGSEA[,'stat'] names(rankedGenes) <- rankedgenesForGSEA$HGNC.symbol pathwaysForGSEA <- gmtPathways(file(paste0('/Users/k.boogerd/Documents/DATA/R/Scripts/GSEA/test/',gmtFiles[j]))) fgseaRes[[gmtFiles[j]]] <- fgsea(pathways = pathwaysForGSEA, stats = rankedGenes, minSize=15,maxSize=500,nperm=10000,gseaParam = 1) } # Correlation analysis corrLVEF <- analyseMetaDataCorrelationBulk( scsMetadata=metadata, dfCounts=counts(dds, normalized=TRUE), parameterName = 'LVEF', percentage=50, correlationMethod = "spearman")