Gallery: 100pg Non-coding SNVs

### PREAMBLE ######################################################################################
library(BoutrosLab.plotting.general)
 
# Read in tables
total_df_to_plot <- data.frame(read.table("clustered_recurrent_ncSNV.tsv", header = TRUE, sep="\t"))
covariate_to_plot <- data.frame(read.table("covariate_ncSNV.tsv", header = TRUE, sep="\t"))
covariate_colour_scheme <- data.frame(read.table("covariate_colour_scheme.tsv", comment.char = "", stringsAsFactors=FALSE, header = TRUE, sep="\t"))
 
### CREATE PLOTS ##################################################################################
# Create Subplots
main <- create.heatmap(
    x = total_df_to_plot,
    clustering.method = 'none',
    scale.data = FALSE,
    grid.col = TRUE,
    col.colour = 'black',
    row.colour = 'darkgrey',
    col.lines = get.line.breaks(covariate_to_plot$TumourGleason),
    row.lwd = 0.5,
    colour.scheme = c('white','black'),
    same.as.matrix = TRUE,
    description = 'ncSNV heatmap: black - ncSNV, white - noSNV'
    )
 
sum_nc_somatic_by_patient_barplot <- create.barplot(
    formula = colSums(total_df_to_plot) ~ seq(1,ncol(total_df_to_plot),1),
    data = total_df_to_plot,
    col = 'gray33',
    ylimits = c(0,15),
    yat = seq(0,15,5),
    abline.v = get.line.breaks(covariate_to_plot$TumourGleason),
    bottom.padding = 0,
    border.col = 'transparent',
    description = 'number of non-coding somatic SNVs per patient'
    )
 
sum_nc_somatic_by_position_barplot <- create.barplot(
    formula = seq(1,nrow(total_df_to_plot),1) ~ rev(rowSums(total_df_to_plot)),
    plot.horizontal = TRUE,
    ylim = c(0+0.5,nrow(total_df_to_plot)+0.5),
    xlim = c(0,15),
    xat = seq(0,15,5),
    col = 'gray33',
    border.col = 'transparent',
    data = total_df_to_plot,
    description = 'number of non-coding somatic SNVs per position'
    )
 
covariate.heatmap <- create.heatmap(
  x = covariate_to_plot,
  clustering.method = 'none',
  scale.data =  FALSE,
  width = 8,
  height = 1,
  grid.row = TRUE,
  grid.col = TRUE,
  col.colour = 'black',
  row.colour = 'black',
  col.lines = get.line.breaks(covariate_to_plot$TumourGleason),
  colour.scheme = covariate_colour_scheme$colour,
  fill.colour = 'slategray',
  print.colour.key = FALSE,
  total.colours = length(covariate_colour_scheme$colour) + 1,
  description = 'covariate heatmap'
)
 
# Create Legends
covariate.legend <- list(
  legend = list(
    colours = covariate_colour_scheme[12:15,"colour"],
    labels = c(covariate_colour_scheme[12:15,"definition"]),
    title = expression(bold(underline('Age'))),
    lwd = 0.5
  ),
  legend = list(
    colours = c(covariate_colour_scheme[8:11,"colour"], 'slategrey'),
    labels = c(covariate_colour_scheme[8:11,"definition"], 'N/A'),
    title = expression(bold(underline('T-Category'))),
    lwd = 0.5
  ),
  legend = list(
    colours = c(covariate_colour_scheme[5:7,"colour"], 'slategrey'),
    labels = c(covariate_colour_scheme[5:7,"definition"], 'N/A'),
    title = expression(bold(underline('PSA (ng/mL)'))),
    lwd = 0.5    
  ),
  legend = list(
    colours =  c(covariate_colour_scheme[1:4,"colour"]), 
    labels = c(covariate_colour_scheme[1:4,"definition"]), 
    title = expression(bold(underline('Gleason'))),
    lwd = 0.5
  )
)
 
side.legend <-legend.grob(
    legends = rev(covariate.legend),
    label.cex = 1.5,
    title.cex = 1.5,
    title.just = 'left',
    title.fontface = 'bold',
    size = 5
  )
 
legend.bottom <- legend.grob(
    list(
        legend = list(
            colours = "white",
            title = expression(bold("Recurrence")),
            labels = c(""),
            border = 'white'        
            )
        ),
    size = 1,
    label.cex = 1.5,
    title.cex = 1.5,
    title.just = 'left'
    );
 
# Create Multiplot
combine.plots <- create.multiplot(
  plot.objects = list(covariate.heatmap, main, sum_nc_somatic_by_position_barplot, sum_nc_somatic_by_patient_barplot),
  height = 12,
  width = 18,
  plot.layout = c(2,3),
  panel.widths = c(8, 1.5),
  panel.heights = c(1.0, 5, 0.5),
  x.spacing = c(-0.75,-0.75),
  y.spacing = c(-1,-1),
  resolution = 1000,
  filename = '100pg_ncSNV_BPG.tiff',
  layout.skip = c(F, T, 
                  F, F, 
                  F, T),
  xlab.label = c( "\t", "\t", "\t", "\t", "\t", "\t", "\t", "\t", "\t"),
  xlab.cex = 2,
  ylab.label = c("ncSNV count   ", "\t", "\t", "\t", "\t", "\t", "\t"),
  ylab.cex = 1.1, 
  yaxis.labels = list(c('Age', 'T-Category', 'PSA (ng/mL)', 'Gleason'), NULL, NULL, seq(0,15,5)),
  yat = list(NA, NA, NA, seq(0,15,5)),
  yaxis.cex = 1.1,
  xat = list(NA, NA, seq(0,15,5), NA),
  xaxis.labels = list(NULL, NULL, seq(0,15,5), NULL),
  xaxis.cex = 1.1,
  xaxis.alternating = 0,
  yaxis.alternating = 0,
  xlab.to.xaxis.padding = -7,
  axes.lwd = 0.9,
  legend = list(
    left = list(
      x = 0.5,
      fun = side.legend
      ),
    inside = list(
      x = 0.88,
      y = 0.05,
      size = 50,
      label.cex = 40,
      title.cex = 40,
      fun = legend.bottom
      )
    ),
  print.new.legend = TRUE,
  bottom.padding = 5,
  ylab.padding = 0
  )

Created by Pretty R at inside-R.org