Commit 8d2d605f authored by Lena Hersemann's avatar Lena Hersemann

adjusted createImgMap() to only plot pathways with clickable links for which...

adjusted createImgMap() to only plot pathways with clickable links for which gene information are available (for the others the .pathways/*.png files will be plotted)
parent 2c73d150
......@@ -585,52 +585,75 @@ pathwayName <- function(pathwayID, enrResults) enrResults %>%
## extended version with clickable links
createImgMap <- function(plotData){
warning("compiling overlay toolips...")
# cat(paste0("pathway:", plotData$pathway_id) # todo rather show the pathway name here and create anhor list on top of section
# pathwayName("mmu05145", enrResults)
cat(paste0("<h3>", pathwayName(plotData$pathway_id, enrResults), "</h3>"))
#pngFile="mmu04015.pathview.png"
#plotData <- pathwayPlots[[1]]
#plotData <- unlist(pathwayPlots)
# pathway_id=(basename(pngFile) %>% str_split_fixed("[.]", 2))[,1]
pngFile <- plotData$plotfile
stopifnot(file.exists(pngFile))
pathway_id = plotData$pathway_id
## create link for image map
keggNodes <- plotData$plot.data.gene %>%
## remove box offset
mutate(x = x - 22, y = y - 8) %>% ## todo does not work for non-gene elements
mutate(link = paste0("http://www.kegg.jp/dbget-bin/www_bget?", keggOrCode, ":", kegg.names)) %>%
rowwise() %>%
do({ curNode = .; mutate(as_df(curNode), tooltip = makeTooltip(as.integer(curNode$kegg.names)))})
## create tooltip by using mapping to
# "http://www.kegg.jp/dbget-bin/www_bget?mmu:16412
## first the image itself
# cat(paste0("<img usemap='#", pathway_id,"' src='", pngFile, "'><br>"))
# cat(paste0("<p><div style='width: 2000px'><img style='float: left' usemap='#", pathway_id,"' src='", pngFile, "'></div><br>"))
## it seems that formatting works better without the left alignment
cat(paste0("<p><div style='width: 2000px'><img usemap='#", pathway_id, "' src='", pngFile, "'></div><br>"))
cat(paste0("<map name='", pathway_id, "'>"))
#keggNodes %>% rowwise() %>% {curNode=.; cat(curNode$name)}
#see http://www.html-world.de/180/image-map/
keggNodes %>% plyr::a_ply(1, function(curNode){
rectDef = with(curNode, paste(x, y, x + width, y + height, sep = ","))
# paste0("<area href='", curNode$link, "' alt='Text' coords='", rectDef , "' shape='rect'>") %>% cat()
paste0("<area href='", curNode$link, "' title='", curNode$tooltip, "' alt='Text' coords='", rectDef , "' shape='rect'>") %>% cat()
})
cat("</map></p><br>")
# plots will only be rendered if they contain gene information; hsa01200 for instance is a pathway which does not reflect the genes whereas hsa05322 does
if (!is.null(plotData$plot.data.gene)) {
warning("compiling overlay toolips...")
# cat(paste0("pathway:", plotData$pathway_id) # todo rather show the pathway name here and create anhor list on top of section
# pathwayName("mmu05145", enrResults)
cat(paste0("<h3>", pathwayName(plotData$pathway_id, enrResults), "</h3>"))
#pngFile="mmu04015.pathview.png"
#plotData <- pathwayPlots[[1]]
#plotData <- unlist(pathwayPlots)
# pathway_id=(basename(pngFile) %>% str_split_fixed("[.]", 2))[,1]
pngFile <- plotData$plotfile
stopifnot(file.exists(pngFile))
pathway_id = plotData$pathway_id
## create link for image map
keggNodes <- plotData$plot.data.gene %>%
## remove box offset
mutate(x = x - 22, y = y - 8) %>% ## todo does not work for non-gene elements
mutate(link = paste0("http://www.kegg.jp/dbget-bin/www_bget?", keggOrCode, ":", kegg.names)) %>%
rowwise() %>%
do({ curNode = .; mutate(as_df(curNode), tooltip = makeTooltip(as.integer(curNode$kegg.names)))})
## create tooltip by using mapping to
# "http://www.kegg.jp/dbget-bin/www_bget?mmu:16412
## first the image itself
# cat(paste0("<img usemap='#", pathway_id,"' src='", pngFile, "'><br>"))
# cat(paste0("<p><div style='width: 2000px'><img style='float: left' usemap='#", pathway_id,"' src='", pngFile, "'></div><br>"))
## it seems that formatting works better without the left alignment
cat(paste0("<p><div style='width: 2000px'><img usemap='#", pathway_id, "' src='", pngFile, "'></div><br>"))
cat(paste0("<map name='", pathway_id, "'>"))
#keggNodes %>% rowwise() %>% {curNode=.; cat(curNode$name)}
#see http://www.html-world.de/180/image-map/
keggNodes %>% plyr::a_ply(1, function(curNode){
rectDef = with(curNode, paste(x, y, x + width, y + height, sep = ","))
# paste0("<area href='", curNode$link, "' alt='Text' coords='", rectDef , "' shape='rect'>") %>% cat()
paste0("<area href='", curNode$link, "' title='", curNode$tooltip, "' alt='Text' coords='", rectDef , "' shape='rect'>") %>% cat()
})
cat("</map></p><br>")
}
}
pathwayPlots %>% walk(createImgMap)
#'
#' <br>
#'
#' All of the following pathways (or parts of them) were found to be enriched. The hits are not visualized but can be all be found in the enrResults.txt file.
#'
#' <br>
#'
#+ results="asis", echo=FALSE, eval=hasEnrPathways
invisible(lapply(1:length(pathwayPlots), function(x){
if (is.null(pathwayPlots[[x]]$plot.data.gene)){
cat("![](",paste0(".pathways/", pathwayPlots[[x]]$pathway_id,".pathview.png"),")")
}
}))
## respin it for cild inclusion
# require(knitr); setwd("/Volumes/projects/bioinfo/scripts/ngs_tools/dev/common"); spin("cp_enrichment.R", knit=F)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment