May I have some assistance please? I have performed topGO analysis on a GeoMx DSP dataset. I set the parameters for the significance value and estimate in the code for differentially expressed genes in the topGO analysis, but when I look at the list go 'significant' genes in the TopGO output, some of the genes included aren't actually differentially expressed and are outside of the parameters I set out.
Please note that genesInTerm provides exactly what one might expect a function with that name might provide - the genes that are annotated to a term. You instead want the genes in that node that are also significant. I don't see a function intended to do that directly (under the hood, topGO just uses intersect between the significant genes and the genes in the term). Here is a self-contained example.
You need to provide some example code and output that shows what you are seeing.
df <- data.frame( Gene = results2$Gene, PV = results2$
Pr(>|t|)
, Estimate = results2$Estimate ) rownames(df) <- df$Genevalid_genes <- rownames(df) %in% keys(org.Hs.eg.db, keytype = "SYMBOL") df_filtered <- df[valid_genes, ] cat("Dimensions of filtered data frame:", dim(df_filtered), "\n")
p_values <- df_filtered$PV scores <- df_filtered$Estimate significant_condition <- p_values < 0.05 & abs(scores) > 0.5
filtered_genes <- rownames(df_filtered)[significant_condition] filtered_scores <- scores[significant_condition] filtered_pvalues <- p_values[significant_condition]
filtered_results <- data.frame( Gene = filtered_genes, Score = filtered_scores, PValue = filtered_pvalues ) head(filtered_results)
all_genes <- rownames(df_filtered) geneList <- rep(0, length(all_genes)) names(geneList) <- all_genes geneList[filtered_genes] <- 1
geneSelectionFun <- function(geneList) { return(geneList == 1) }
GOdata <- new("topGOdata", description = "GO Enrichment for Significant Genes", ontology = "BP", allGenes = geneList, geneSelectionFun = geneSelectionFun, annot = annFUN.org, mapping = "org.Hs.eg.db", ID = "SYMBOL")
result <- runTest(GOdata, algorithm = "classic", statistic = "fisher")
enriched_terms <- GenTable(GOdata, classicFisher = result, topNodes = 10)
enriched_terms$classicFisher <- as.character(enriched_terms$classicFisher) enriched_terms$classicFisher[enriched_terms$classicFisher == "< 1e-30"] <- "1e-30" enriched_terms$log_p_value <- -log10(as.numeric(enriched_terms$classicFisher))
go_terms <- AnnotationDbi::select( GO.db, keys = enriched_terms$GO.ID, columns = c("TERM"), keytype = "GOID" )
enriched_terms_full <- merge(enriched_terms, go_terms, by.x = "GO.ID", by.y = "GOID") head(enriched_terms_full)
library(ggplot2)
enriched_terms_full$classicFisher <- as.numeric(enriched_terms_full$classicFisher) enriched_terms_full$log_p_value <- -log10(enriched_terms_full$classicFisher)
genes_in_term <- genesInTerm(GOdata, whichGO = "GO:0002181")[[1]]
interesction<-intersect(filtered_genes,genes_in_term)