Guest User

Untitled

a guest
Nov 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. library(topGO)
  2.  
  3. # Read in GO mappings to gene ids
  4. # <gene>\t<GOID>,<GOID>,...
  5. vng2GO <- readMappings(file='vng2GO.map')
  6.  
  7. # Load up cluster or gene set identifiers
  8. geneSets <- ## Depends on your analysis, list of vectors of gene ids
  9.  
  10. ################
  11. # Run analysis #
  12. ################
  13. # Make Gene list
  14. geneNames <- # Need to detemine what this is
  15. geneList <- factor(as.integer(geneNames %in% tmp1))
  16. names(geneList) <- geneNames
  17. # Make Biological Process GOData object
  18. tmp1 <- c('VNG####','VNG####') # put in a couple of gene ids to build structure for automation
  19. GOdata.BP <- new("topGOdata", ontology='BP', allGenes = geneList, annot = annFUN.gene2GO, gene2GO = vng2GO)
  20. m1.BP <- matrix(nrow = length(GOdata.BP@graph@nodes), ncol = length(geneSets), dimnames = list(GOdata.BP@graph@nodes, 1:length(geneSets)))
  21. m2.BP <- matrix(nrow = length(geneSets), ncol=2, dimnames = list(1:length(geneSets), c('Top10.Terms.BP', 'BH.sig.GO.Ids.BP')))
  22.  
  23. # Make Molecular Function GOData object
  24. #GOdata.MF <- new("topGOdata", ontology='MF', allGenes = geneList, annot = annFUN.gene2GO, gene2GO = vng2GO)
  25. #m1.MF <- matrix(nrow = length(GOdata.MF@graph@nodes), ncol = length(geneSets), dimnames = list(GOdata.MF@graph@nodes, 1:length(geneSets)))
  26. #m2.MF <- matrix(nrow = length(geneSets), ncol=2, dimnames = list(1:length(geneSets), c('Top10.Terms.MF', 'BH.sig.GO.Ids.MF')))
  27.  
  28. # Make Cellular Component GOData object
  29. #GOdata.CC <- new("topGOdata", ontology='CC', allGenes = geneList, annot = annFUN.gene2GO, gene2GO = vng2GO)
  30. #m1.CC <- matrix(nrow = length(GOdata.CC@graph@nodes), ncol = length(geneSets), dimnames = list(GOdata.CC@graph@nodes, 1:length(geneSets)))
  31. #m2.CC <- matrix(nrow = length(geneSets), ncol=2, dimnames = list(1:length(geneSets), c('Top10.Terms.CC','BH.sig.GO.Ids.CC')))
  32.  
  33. for( geneSet in (1:length(geneSets)) ) {
  34. # Expand gene list and change factor in GOdata
  35. genes <- geneSets[[geneSet]]
  36. GOdata.BP@allScores <- factor(as.integer(geneNames %in% genes))
  37. #GOdata.MF@allScores <- factor(as.integer(geneNames %in% genes))
  38. #GOdata.CC@allScores <- factor(as.integer(geneNames %in% genes))
  39. # Biological process
  40. r1.BP = runTest(GOdata.BP, algorithm = 'classic', statistic = 'fisher')
  41. m1.BP[,biclust] = r1.BP@score
  42. m2.BP[biclust,1] = paste(GenTable(GOdata.BP, r1.BP)[,2],collapse=', ')
  43. m2.BP[biclust,2] = paste(names(which(p.adjust(r1.BP@score,method='BH')<=0.05)),collapse=', ')
  44. #r1.MF = runTest(GOdata.MF, algorithm = 'classic', statistic = 'fisher')
  45. #m1.MF[,biclust] = r1.MF@score
  46. #m2.MF[biclust,1] = paste(GenTable(GOdata.MF, r1.MF)[,2],collapse=', ')
  47. #m2.MF[biclust,2] = paste(names(which(p.adjust(r1.MF@score,method='BH')<=0.05)),collapse=', ')
  48. #r1.CC = runTest(GOdata.CC, algorithm = 'classic', statistic = 'fisher')
  49. #m1.CC[,biclust] = r1.CC@score
  50. #m2.CC[biclust,1] = paste(GenTable(GOdata.CC, r1.CC)[,2],collapse=', ')
  51. #m2.CC[biclust,2] = paste(names(which(p.adjust(r1.CC@score,method='BH')<=0.05)),collapse=', ')
  52. }
  53.  
  54. # Write out the results, can add the others by doing cbind to add the other matrices as columns
  55. write.csv(m2.BP,'biclusterEnrichment_GOBP.csv')
Add Comment
Please, Sign In to add comment