setwd("/var/www/forge2/production/src/html/files/0x454A546E8E9C11EA8198793F5BFE3F98") results<-read.table("Unnamed.GWAS.erc.chart.tsv.gz", header = TRUE, sep="\t") # Class splits the data into non-significant, marginally significant and significant according to 0.05 and 0.01 (in -log10 scale) results$Class <- cut(results$Pvalue, breaks =c(0, 0.01, 0.05, 1)/length(unique(results[,'Tissue'])), labels=FALSE, include.lowest=TRUE) # Class splits the data into non-significant, marginally significant and significant according to q-value (B-Y FDR adjusted) results$Class2 <- cut(results$Qvalue, breaks =c(0, 0.01, 0.05, 1), labels=FALSE, include.lowest=TRUE) color.axis.palette = c(); if (length(which(results$Class2 == 1)) > 0 ) { color.axis.palette = c('red'); } if (length(which(results$Class2 == 2)) > 0 ) { color.axis.palette = c(color.axis.palette, '#FF82ab'); } color.axis.palette = c(color.axis.palette, 'lightblue'); if (length(color.axis.palette) <= 2) { color.axis.palette = c(color.axis.palette, 'lightblue'); # Add it twice to force the color if only non-significant values } results$log10pvalue <- -log10(results$Pvalue) # Re-order the entries according to tissue first and then cell type/line tissue.cell.order <- unique(results[, c('Tissue', 'Cell')]) tissue.cell.order <- tissue.cell.order[order(tissue.cell.order[,1], tissue.cell.order[,2]), ] # Collapse into a single string (to support same cell type in different tissues) tissue.cell.order2 <- apply(tissue.cell.order, 1, paste, collapse = ' -- ') results$TissueCell <- apply(results[, c('Tissue', 'Cell')], 1, paste, collapse = ' -- ') results$TissueCell <- factor(results$TissueCell, levels=tissue.cell.order2) # Count number of cell types for each tissue (to be able to draw the vertical separation lines afterwards tissues <- c(0, cumsum(summary(tissue.cell.order[,'Tissue']))) require(rCharts) dplot.height=900 dplot.width=2000 bounds.x=60 bounds.y=50 bounds.height=dplot.height - 300 bounds.width=dplot.width - bounds.x - 20 # Create a dimple plot, showing p-value vs cell, split data by tissue, cell, probe, etc to see individual points instead of aggregate avg d1 <- dPlot( y = 'log10pvalue', x = c('TissueCell'), groups = c('TissueCell', 'Accession', 'Pvalue', 'Qvalue', 'Datatype', 'Probe', 'Class2'), data = results, type = 'bubble', width = dplot.width, height = dplot.height, bounds = list(x=bounds.x, y=bounds.y, height=bounds.height, width=bounds.width), id = 'chart.Unnamed.GWAS.erc' ) # Force the order on the X-axis d1$xAxis( type = 'addCategoryAxis', grouporderRule = 'Cell', orderRule = tissue.cell.order[,2]) d1$xAxis( type = 'addCategoryAxis', grouporderRule = 'TissueCell', orderRule = as.factor(tissue.cell.order2)) d1$yAxis( type = 'addMeasureAxis' ) # Color points according to the q-value d1$colorAxis( type = 'addColorAxis', colorSeries = 'Class2', palette = color.axis.palette) # Builds a JS string to add labels for tissues labels.string = paste(paste0(" // Adds labels for tissues myChart.svg.insert('text', 'g') .attr('x', 0) .attr('y', 0) .attr('font-size', 16) .attr('font-family', 'Arial') .style('fill', '#A9A9A9') .attr('transform', 'translate(", (bounds.x + 5 + bounds.width * (tissues[1:(length(tissues)-1)] + tissues[2:length(tissues)]) / (2 * max(tissues))), ", 60) rotate(-90)') .attr('text-anchor', 'end') .text('", names(tissues[2:length(tissues)]), "') "), collapse='') # Builds a JS string to add vertical lines to separate tissues lines.string = paste(paste0(" // Adds vertical lines between tissues myChart.svg.append('line') .attr('x1', ", (bounds.x + bounds.width * tissues[2:(length(tissues)-1)]/ max(tissues)), ") .attr('y1', 50) .attr('x2', ", (bounds.x + bounds.width * tissues[2:(length(tissues)-1)]/ max(tissues)), ") .attr('y2', ", (50 + bounds.height), ") .style('stroke', '#A9A9A9') .style('stroke-dasharray', '10,3,3,3') "), collapse='') # Adds some JS to be run after building the plot to get the image we want d1$setTemplate(afterScript = paste0(" ")) d1$save('Unnamed.GWAS.erc.dchart.html', cdn = F)