History: Profile_r_heatmaps_test
Source of version: 4 (current)
Copy to clipboard
Below you should see a heatmap produced if everything (Tiki, R, PluginR, and the required R packages) are successfuly instaled and configured. You can [tiki-editpage.php?page=HeatMaps Test|edit this page] to tweak some parameters by hand if you wish or needed. {RR(loadandsave="1", echo="1", svg="1", pdf="1")} ################################################################## ### Chunk 1: Installation of easyHeatMap package and dependencies ################################################################## ##### NOTE: # * You need a few packages: install the ones you are missing in the central server location for R packages. # * In this example we install them with this params: lib="/usr/lib/R/site-library", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/" # but adapt the server paths or urls to your specific case # * Remember you can install packages: # * from the terminal with some command like: # R CMD INSTALL /home/foo/myPackage.tar.gz --library="/usr/lib/R/site-library" # * or from an R session with something like: # install.packages(pkgs="/home/foo/myPackage.tar.gz", lib="/usr/lib/R/site-library", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") cat("Cheacking dependencies:\n") if (is.na(match("gplots", installed.packages()))) { install.packages("gplots", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") } else { cat(" Package gplots is already installed. OK.\n") } if (is.na(match("gtools", installed.packages()))) { install.packages("gtools", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") } else { cat(" Package gtools is already installed. OK.\n") } if (is.na(match("gdata", installed.packages()))) { install.packages("gdata", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") } else { cat(" Package gdata is already installed. OK.\n") } if (is.na(match("caTools", installed.packages()))) { install.packages("caTools", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") } else { cat(" Package caTools is already installed. OK.\n") } if (is.na(match("easyHeatMap", installed.packages()))) { ##### Install the package "easyHeatMap" ### for the time being you can fetch it from: ### https://ueb.ir.vhebron.net/files/easyHeatMap_1.18.tar.gz ### or ### http://dl.dropbox.com/u/24830595/easyHeatMap_1.18.tar.gz cat("Attempting to download easyHeatMaps from http://ueb.ir.vhebron.net/files/easyHeatMap_1.18.tar.gz \n") download.file("http://ueb.ir.vhebron.net/files/easyHeatMap_1.18.tar.gz", "./easyHeatMap_1.18.tar.gz") cat("Attempting to install package easyHeatMaps \n") install.packages(pkgs="easyHeatMap_1.18.tar.gz") if (is.na(match("easyHeatMap", installed.packages()))) { cat(" Something must have gone wrong, since the package didn't get successfully installed for some reason") } else { cat(" Package easyHeatMaps successfully installed. \n You can now proceed to create some <a href=\"tiki-index.php?page=HeatMaps&cookietab=2\">HeatMaps</a>") } } else { cat(" Package easyHeatMap is already installed. OK.\n") cat("\n You can now proceed to create some <a href=\"tiki-index.php?page=HeatMaps&cookietab=2\">HeatMaps</a>\n") } ####################################################################################### ### Chunk 2: R commands to generate the required files server-side from BioConductor ### "expres.filtered.ALL.txt", "expres.selected.ALL.txt" and "colorsForColumns.txt" ############################################################################################# ##### A few packages are required from Bioconductor to produce HeatMaps with real data # source("http://www.bioconductor.org/biocLite.R") # biocLite("ALL", lib="/usr/lib/R/site-library") # biocLite("genefilter", lib="/usr/lib/R/site-library") # biocLite("hgu95av2.db", lib="/usr/lib/R/site-library") # require(ALL) # require(genefilter) # require(hgu95av2.db) # The ALL package contains a sample "ExpressionSet" with expression values form # 128 samples and 12625 genes # ("features =probesets, remembering there may be more than one probeset per gene") # The dataset contains five different genotypes # ALL1/AF4 BCR/ABL E2A/PBX1 NEG NUP-98 p15/p16 # 10 37 5 74 1 1 # The two example datasets keep only samples from the first and second groups # To use a small number of genes two standard 'filtering approaches' are tested # 1) Non specific filtering # Only most variables are kept. Their expressions are stored in file "expres.filtered.ALL.txt" # 2) Specific filtering # We retain genes according to a test comparison between two groups. # Their expressions are stored in file "expres.selected.ALL.txt" # # # 1- Selecting genes by non-specific filtering # # require(ALL) # data(ALL) # require(genefilter) # filtered095 <- nsFilter (ALL, var.cutoff=0.95) # filtered099 <- nsFilter (ALL, var.cutoff=0.99) # esetSel095<-filtered095$eset # esetSel099<-filtered099$eset # esetSel <- esetSel099 # esetSel<- esetSel[,pData(esetSel)$mol.bio %in% c("ALL1/AF4", "BCR/ABL")] # colnames(exprs(esetSel))<- paste("X", colnames(exprs(esetSel)), sep="") # write.exprs(esetSel, file="expres.filtered.ALL.txt") # # 2- Selecting genes by specific filtering # require ("ALL") # data("ALL") # eset <- ALL[, ALL$mol.biol %in% c("BCR/ABL", "ALL1/AF4")] # library("limma") # f <- factor(as.character(eset$mol.biol)) # design <- model.matrix(~f) # fit <- eBayes(lmFit(eset,design)) # selected05 <- p.adjust(fit$p.value[, 2]) <0.05 # selected01 <- p.adjust(fit$p.value[, 2]) <0.01 # esetSel <- eset [selected05, ] # colnames(exprs(esetSel))<- paste("X", colnames(exprs(esetSel)), sep="") # write.exprs(esetSel, file="expres.selected.ALL.txt") # # # # I per crear l'arxiu amb un color diferent per cada grup (basat en la columna "mol.biol") # # # write.table(cbind(paste("X",rownames(pData(esetSel)),sep=""), # as.integer(pData(esetSel)$mol.biol)+1), sep="\t", # row.names=FALSE, col.names=c("Column", "Group"), quote=FALSE, # file="colorsForColumns.txt") # # # # # Això és un exemple del que voldríem haver capturat a través del formulari # # COMPTE perque, en aquesta versió, no considerem la possibilitat de treure # # - Ni, com paràmetre, la possibilitat d'enviar els gràfics a un arxiu PDF # # --> toPDF es deixa a FALSE # # - Ni un arxiu amb els gens de cada cluster # # --> numClusters es deixa a 0 # # - Ni un arxiu/gràfic amb els perfils de cada cluster # # --> plotProfiles es deixa a FALSE # # ####################################################################################### ### Chunk 3: Call to easyHeatMap functions ############################################################################################# require(easyHeatMap) download.file("http://ueb.ir.vhebron.net/dl220", "./expres.filtered.ALL.txt") download.file("http://ueb.ir.vhebron.net/dl221", "./colorsForColumns.txt") clustPar<-newClustPar(expres = NULL , # We'll give it a file attached to the tracker item expresFileName ="expres.filtered.ALL", # For a file "foo.txt", you have to indicate here "foo" (without extension) fileType = "txt", comparisonName = "ALL", Title = "My Plot: BCR/ABL vs ALL1/AF4", numClusters = 0, # Confirm that with zero nothing is done plotProfiles=FALSE, rowDistance = 'cor', colDistance = 'euclidean', RowVals = TRUE, ColVals = TRUE, escala = "row", colorsSet = redblue(64), #colors, colsForGroups = NULL, colsForGroupsFileName="colorsForColumns", densityInfo = "density", cexForColumns = 0.8, cexForRows = 0.8, outputDir=".", toPDF = FALSE, ) # HeatMap generation hm.ALL <- doHMAnalysis(clustPar) # Now it is easy to change paramters and re-draw the heatmap ## We can use a different colorset #clustPar$colorsSet <- heat.colors(64) #hm.ALL <- doHMAnalysis(clustPar) ## We can change the distance function for rows and/or columns #clustPar$rowDistance = 'cor' #clustPar$colDistance = 'minkowski' #hm.ALL <- doHMAnalysis(clustPar) ## We can use a different dataset #clustPar$expresFileName="expres.selected.ALL" #hm.ALL <- doHMAnalysis(clustPar) ############################################################# ### Optional change 1: PDF generation server side ############################################################# # # Imprimim a pdf # # COMPTE: els arxius s'anomenen per defecte # # el del heatmap: paste(paste("HM", comparisonName, sep=""),"pdf", sep=".") # # el dels perfils: paste(paste("plotProfiles", comparisonName, sep=""),"pdf", sep=".") # # el dels gens als clusters: paste(paste("genesInClusters", comparisonName, sep=""),"txt", sep=".") # # # Això es important de cara a descarregar-los des de l'aplicatiu web # # clustPar$toPDF<-TRUE # clustPar$plotProfiles <-TRUE # # hm.ALL <- doHMAnalysis(clustPar) ############################################################# ### Optional change 2: Changingthecolour palette ############################################################# # clustPar$toPDF<-FALSE # clustPar$plotProfiles <-FALSE # # # We can try with other colour palettes # colores1 <- heat.colors(64) # Veure a RColorBrewer altres formes # colores2 <- redblue(64) # Veure a RColorBrewer altres formes # colores3 <- greenred(16) # Veure a RColorBrewer altres formes # colores4 <- topo.colors(64) # Veure a RColorBrewer altres formes # colores5 <- terrain.colors (64) # colores6 <- colorpanel(36, "green", "white", "red") # colores7 <- rainbow(36) # # clustPar$toPDF<-FALSE # clustPar$plotProfiles <-FALSE # clustPar$colorsSet <-colores2 # hm.ALL <- doHMAnalysis(clustPar) {RR}