Question: plotMutationSpectrum Colour By Patient with Multiple Samples
0
gravatar for bruce.moran
21 months ago by
bruce.moran20
Ireland
bruce.moran20 wrote:

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.

ADD COMMENTlink modified 21 months ago by Julian Gehring1.3k • written 21 months ago by bruce.moran20
Answer: plotMutationSpectrum Colour By Patient with Multiple Samples
0
gravatar for Julian Gehring
21 months ago by
Julian Gehring1.3k
Julian Gehring1.3k wrote:

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 COMMENTlink modified 18 months ago • written 21 months ago by Julian Gehring1.3k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 155 users visited in the last hour