plotMutationSpectrum Colour By Patient with Multiple Samples
1
0
Entering edit mode
bruce.moran ▴ 30
@brucemoran-8388
Last seen 3.1 years ago
Ireland

Hi,

I have multiple timepoint samples pre- and post-treatment for several patients. I cannot see a standard way to colour mutation spectrum by a 'group' variable, as opposed to sample or mutation. I have the group in the VRanges object supplied to mutationContext, but cannot force via scale_fill_brewer or other such.

Is there a simple way to do this? I had a look in the ggplot2 object ('p' in the tutorial), this yields p$data, p$labels$fill. I could try and hack that to allow a group variable in p$data, but would be neater if there is a proposed solution from authors/others.

Thanks,

Bruce.

plotMutationSpectrum somaticsignatures somaticsignatures package • 1.2k views
ADD COMMENT
0
Entering edit mode
Julian Gehring ★ 1.3k
@julian-gehring-5818
Last seen 5.5 years ago

This is an interesting use case - it will not work out of the box, but we can make it happen.

I have created a modified version of the plotMutationSpectrum function that has the extra functionality:

library(SomaticSignatures)
library(ggplot2)
plotMutationSpectrumWithColorMapping <- function(vr, group,
    colorby = c("sample", "alteration", "colormapping"),
    normalize = TRUE, colormapping = NULL)
{
  colorby = match.arg(colorby)
  x = motifMatrix(vr, group, normalize = normalize)
  w_df = reshape2::melt(x, varnames = c("motif", "sample"))
  w_df$colormapping = colormapping[w_df$sample]
  w_df$alteration = sub("([ACGTN])([ACGTN]) .+", "\\1>\\2", w_df$motif)
  w_df$context = sub("[ACGTN][ACGTN] (.+)", "\\1", w_df$motif)
  p = ggplot(w_df)
  p = p + geom_bar(aes_string(x = "context", y = "value", fill = colorby),
                   stat = "identity", position = "identity")
  p = p + facet_grid(sample ~ alteration)
  p = p + SomaticSignatures:::theme_ss() + SomaticSignatures:::theme_small_axis()
  p = p + theme(legend.position = "none")
  p = p + scale_fill_brewer(palette = "Set3")
  p = p + xlab("Motif") + ylab("Contribution")
  return(p)
}

Let's try it with a small example data set:

library(SomaticSignatures)
library(ggplot2)
data(sca_motifs_tiny)

We want to split the data set according to cancer type and additionally distinguish between lung and non-lung cancer via color. For this, we define a mapping between our grouping (cancer studies) and our coloring (lung cancers) variable:

studies = as.character(unique(sca_motifs_tiny$study))
groups = ifelse(grepl("^L", colormapping), "lung", "non-lung")
colormapping = setNames(groups, studies)

      KIRC       SKCM       LUAD       LUSC       HNSC        GBM       THCA 
"non-lung" "non-lung"     "lung"     "lung" "non-lung" "non-lung" "non-lung" 
        OV 
"non-lung" 

Plotting and coloring the mutational spectrum according to sample/group and alteration type works as before:

plotMutationSpectrumWithColorMapping(sca_motifs_tiny, "study", "sample") + scb


plotMutationSpectrumWithColorMapping(sca_motifs_tiny, "study", "alteration") + scb

Most importantly, we can now use the color mapping defined above:

plotMutationSpectrumWithColorMapping(sca_motifs_tiny, "study", "colormap", colormapping = cm) + scb

This is not perfect, but let me know if this is what you were looking for and if turns out to be helpful.

 

ADD COMMENT

Login before adding your answer.

Traffic: 718 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6