Gallery: Endogenous Role of the AHR

Hypergeometric testing was conducted on overlapping significant GO terms to compare the observed overlap to that expected by chance alone. Fold enrichment is calculated as the ratio of observed to expected counts of GO terms common to two datasets. Magnitude of enrichment is represented by spot size; background shade denotes q-values from hypergeometric testing.

### figure4c.R ####################################################################################
# This project aims to compare basal mRNA levels of various mice and rat tissues
# This script compares the parsed and processed results files from GoMiner analysis and create
# a mulitplot to show enrichment of common GO terms across datasets
 
### PREAMBLE ######################################################################################
library(BoutrosLab.plotting.general);
 
# read in data
plot.data <- read.delim('endogenous_ahr_figure4c_plot_data.txt', header = TRUE);
 
### LEGENDS #######################################################################################
# covariate legends
covariates.legend <- list(
	legend = list(
		title = 'Species',
		labels = c('Mouse', 'Rat'),
		colours = c(
			rgb(232, 212, 203, maxColorValue = 255),
			rgb(204, 169, 156, maxColorValue = 255)
			),
		border = 'white'
		),
	legend = list(
		title = 'Tissues',
		labels = c('Kidney', 'Liver', 'Adipose', 'Hypothalamus'),
		colours = c(
			rgb(51, 106, 144, maxColorValue = 255),
			rgb(101, 180, 162, maxColorValue = 255),
			rgb(177, 211, 154, maxColorValue = 255),
			rgb(244, 224, 166, maxColorValue = 255)
			),
		border = 'white'
		)
	);
 
cov.legend.grob <- legend.grob(
	legends = covariates.legend, 
	layout = c(2, 1), 
	title.just = 'left', 
	label.cex = 1.5, 
	title.cex = 1.5
	);
 
# spot size key
key.sizes <- seq(4, 0, -1);
 
# spot size and colour functions
spot.size.function <- function(x){ 0.1 + (2*abs(x)); }
spot.border.function <- function(x){
	x[x!=0] <- 'black';
	x[x==0] <- 'transparent';
	return(x);
	}
spot.colour.function <- function(x){
	colours <- rep('white', length(x));
	colours[sign(x) ==  1] <- 'firebrick2';
	return(colours);
 	}
 
# draw spot size key for right side
spot.size.grob <- draw.key(
	key = list(
		space = 'right',
		padding.text = 10,
		between = 1,
		title = parse(text = "bold('Enrichment')"),
		cex.title = 2,
		points = list(
			cex = spot.size.function(key.sizes),
			fill = spot.colour.function(key.sizes),
			col = spot.border.function(key.sizes),
			pch = 21
			),
		text = list(
			lab = paste0("+", key.sizes, '.0'),
			cex = 2,
			adj = 1.0,
	                fontface = 'bold'
	                ),
	        background = 'white'
	        ),
	draw = FALSE
	);
dev.off();
 
### PARENT GO TERM LEGEND #########################################################################
# define colour palette - using manhattan plot, chromosomes palette
parent.GO.palette <- default.colours(
	palette.type = 'chromosomes',
	number.of.colours = 9
	);
parent.GO.palette <- parent.GO.palette[c(1, 3, 5)];
 
parentGO.legend <- list(
	legend = list(
		colours = parent.GO.palette,
		labels = levels(as.factor(plot.data$Parent.GO.Def)),
		title = "Parent GO Terms"
		)
	);
 
parentGO.legend.grob <- legend.grob(
	legends = parentGO.legend, 
	size = 3, 
	label.cex = 1.5, 
	title.cex = 1.5, 
	border = list(
		col = 'black', 
		lwd = 2
		)
	);
 
### CREATE COVARIATE HEATMAPS #####################################################################
# covariate heatmap for Species and Tissues
top.cov.data <- data.frame(
	Species = c(1, 2)[as.factor(c('Mouse', 'Mouse', 'Rat', 'Rat', 'Rat'))],
	Tissues = c(3, 4, 5, 6)[as.factor(c('Kidney', 'Liver', 'Liver', 'Adipose', 'Hypothalamus'))]
	);
 
top.cov.heatmap <- create.heatmap(
	x = top.cov.data,
	clustering.method = 'none',
	yaxis.lab = NULL,
	xaxis.lab = NULL,
	colour.scheme = c(
		rgb(232, 212, 203, maxColorValue = 255),
		rgb(191, 136, 116, maxColorValue = 255),
		rgb(177, 211, 154, maxColorValue = 255),
		rgb(244, 224, 166, maxColorValue = 255),
		rgb(51, 106, 144, maxColorValue = 255),
		rgb(101, 180, 162, maxColorValue = 255)
		),
	row.colour = 'white',
	col.colour = 'white',
	grid.row = TRUE,
	grid.col = TRUE,
	at = 0:6,
	total.colours = 6,
	print.colour.key = FALSE
	);
 
right.cov.data <- rev((1:length(plot.data$Parent.GO.Def))[as.factor(plot.data$Parent.GO.Def)]);
right.cov.data <- as.data.frame(t(right.cov.data));
 
# covariate heatmap for parent GO terms
right.cov.heatmap <- create.heatmap(
	x = right.cov.data,
	clustering.method = 'none',
	yaxis.lab = NULL,
	xaxis.lab = NULL,
	colour.scheme = parent.GO.palette,
	row.colour = 'grey60',
	col.colour = 'grey60',
	grid.row = TRUE,
	grid.col = TRUE,
	at = 0:length(parent.GO.palette),
	total.colours = length(parent.GO.palette),
	print.colour.key = FALSE
	);
 
# covariate dotmap of Parent GO terms from goslim
cov.dotmap <- create.dotmap(
	x = plot.data$Enrichment,
	bg.data = -log10(plot.data$FDR),
	xaxis.lab = NULL,
	yaxis.lab = NULL,
	xaxis.cex = 1.5,
	yaxis.cex = 1.5,
	spot.colour.function = spot.colour.function,
	spot.size.function = spot.size.function,
	pch = 21,
	colourkey = FALSE,
	colour.scheme = c('white', 'black'),
	at = c(0, -log10(0.05), seq(2, 6, 1)),
	bg.alpha = 0.8,
	yaxis.tck = c(0, 0),
	xaxis.tck = c(0, 0),
	row.colour = 'grey60',
	col.colour = 'grey60'
	);
 
### MAIN PLOT #####################################################################################
# Draw dotmap
main.dotmap <- create.dotmap(
	x = plot.data[, 1:5],
	bg.data = -log10(as.matrix(plot.data[, 6:10])),
	NA.spot.size = 3,
	xaxis.lab = NA,
	yaxis.lab = NA,
	xaxis.cex = 1.5,
	yaxis.cex = 1.5,
	spot.colour.function = spot.colour.function,
	spot.size.function = spot.size.function,
	pch = 21,
	colourkey = FALSE,
	colour.scheme = c('white', 'black'),
	at = c(0, -log10(0.05), seq(2, 6, 1)),
	bg.alpha = 0.8,
	yaxis.tck = c(0, 0),
	xaxis.tck = c(0, 0),
	row.colour = 'grey60',
	col.colour = 'grey60'
	);
 
main.labels <- c(
	'bold(kidney - bolditalic(Mm))',
	'bold(liver - bolditalic(Mm))',
	'bold(liver - bolditalic(Rn))',
	'bold(adipose - bolditalic(Rn))',
	'bold(hypothalamus - bolditalic(Rn))'
	);
 
create.multiplot(
	plot.objects = list(main.dotmap, cov.dotmap, right.cov.heatmap, top.cov.heatmap),
	filename = paste0(Sys.Date(), '_multiplot.tiff'),
	plot.layout = c(3,2),
	layout.skip = c(FALSE, FALSE, FALSE, FALSE, TRUE, TRUE),
	panel.widths = c(1, 0.25, 0.05),
	panel.height = c(0.05, 1),
	xaxis.labels = list(
		parse(text = main.labels), 
		'Common GO terms', 
		c(), 
		c()
		),
	yaxis.labels = list(rev(rownames(plot.data)), c(), c(), c()),
	x.relation = 'free',
	y.relation = 'free',
	xat = list(1:5, c(1), c(), c()),
	yat = list(1:10, c(), c(), c()),
	xlimits = list(c(), c(0.6,1.4), c(0.6,0.9), c()),
	xaxis.alternating = 0, 
	yaxis.alternating = 0,
	x.spacing = -6,
	y.spacing = -12,
	xaxis.rot = 90,
	xaxis.cex = 1.5,
	yaxis.cex = 1.5,
	legend = list(
		inside = list(
			fun = cov.legend.grob,
			x = 0.2,
			y = 1.15
			),
		inside = list(
			fun = parentGO.legend.grob,
			x = 1.05, 
			y = 0.11
			),
		inside = list(
			fun = spot.size.grob,
			x = 1.15,
			y = 0.75
			),
		inside = list(
			fun = create.colourkey(
				x = plot.data[, 1:5], 
				colour.scheme = c('white', 'black'),
				at = c(0, -log10(0.05), seq(2, 6, 1)),
				colourkey.labels.cex = 2,
				colourkey.labels = c(
					expression(1.0^phantom(1)),
					expression(0.05^phantom(1)),
					expression(10^-3),
					substitute(p.value<=10^-6, list(p.value = ''))
					),
				colourkey.labels.at = c(0, -log10(0.05), 3, 6),
				placement = viewport(just='left', x=0.5, y=-0.75, width=0.73)
				)
			)
		),
	top.padding = 20,
	bottom.padding = 10,
	right.padding = 55,
	left.padding = 40,
	height = 16,
	width = 16,
	resolution = 500,
	print.new.legend = TRUE,
	retrieve.plot.labels = FALSE
	);

Created by Pretty R at inside-R.org