Search
Question: SomaticSignatures : change order of x-axis in plotMutationSpectrum
1
gravatar for sergio.martinezcuesta
3.1 years ago by
United Kingdom
sergio.martinezcuesta10 wrote:

Hi Julian,

I want to change the order of triplets in the Motif x-axis of plotMutationSpectrum so that Gs at the 3' are clumped together next to each other. In other words, say for C>T, I want to change the order from:

A . A   A . C   A . G   A . T   C . A   C . C   C . G   C . T   G . A   G . C   G . G   G . T   T . A   T . C   T . G   T . T

to:

A . A   C . A   G . A   T . A   A . C   C . C   G . C   T . C   A . G   C . G   G . G   T . G   A . T   C . T   G . T   T . T

I have read ?plotMutationSpectrum however there does not seem to be an option to do this.

What's the easiest way to change plotMutationSpectrum in order to achieve this?

Sergio

Code:

plotMutationSpectrum(motifs, group="comparison", normalize = FALSE)

 

> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets
[8] methods   base     

other attached packages:
 [1] SomaticSignatures_2.6.0    gplots_2.17.0             
 [3] VariantAnnotation_1.16.3   Rsamtools_1.22.0          
 [5] Biostrings_2.38.0          XVector_0.10.0            
 [7] SummarizedExperiment_1.0.0 Biobase_2.30.0            
 [9] GenomicRanges_1.22.0       GenomeInfoDb_1.6.1        
[11] IRanges_2.4.1              S4Vectors_0.8.0           
[13] BiocGenerics_0.16.0       

loaded via a namespace (and not attached):
 [1] splines_3.2.1           foreach_1.4.3           gtools_3.5.0           
 [4] Formula_1.2-1           latticeExtra_0.6-26     RBGL_1.46.0            
 [7] BSgenome_1.38.0         RSQLite_1.0.0           lattice_0.20-33        
[10] biovizBase_1.18.0       digest_0.6.8            RColorBrewer_1.1-2     
[13] colorspace_1.2-6        ggbio_1.18.0            plyr_1.8.3             
[16] OrganismDbi_1.12.0      XML_3.98-1.3            biomaRt_2.26.0         
[19] zlibbioc_1.16.0         xtable_1.8-0            scales_0.3.0           
[22] gdata_2.17.0            BiocParallel_1.4.0      proxy_0.4-15           
[25] pkgmaker_0.22           ggplot2_1.0.1           GenomicFeatures_1.22.3
[28] nnet_7.3-11             proto_0.3-10            survival_2.38-3        
[31] magrittr_1.5            GGally_0.5.0            doParallel_1.0.10      
[34] MASS_7.3-44             NMF_0.20.6              foreign_0.8-66         
[37] graph_1.48.0            BiocInstaller_1.20.0    tools_3.2.1            
[40] registry_0.3            gridBase_0.4-7          stringr_1.0.0          
[43] munsell_0.4.2           cluster_2.0.3           rngtools_1.2.4         
[46] AnnotationDbi_1.32.0    lambda.r_1.1.7          pcaMethods_1.60.0      
[49] caTools_1.17.1          futile.logger_1.4.1     grid_3.2.1             
[52] RCurl_1.95-4.7          dichromat_2.0-0         iterators_1.0.8        
[55] bitops_1.0-6            gtable_0.1.2            codetools_0.2-14       
[58] DBI_0.3.1               reshape_0.8.5           reshape2_1.4.1         
[61] GenomicAlignments_1.6.1 gridExtra_2.0.0         rtracklayer_1.30.1     
[64] Hmisc_3.17-0            futile.options_1.0.0    KernSmooth_2.23-15     
[67] stringi_1.0-1           Rcpp_0.12.1             rpart_4.1-10           
[70] acepack_1.3-3.3

 

ADD COMMENTlink modified 3.1 years ago by Julian Gehring1.3k • written 3.1 years ago by sergio.martinezcuesta10

Hi Sergio, I just saw your post so sorry about the late reply. The ordering of the x-axis is determined implicitly by the graphics library ggplot2. I haven't thought about an option for changing the order, but it makes sense to have this freedom. Let me check what the easiest way would be, I'll get back to you soon.

ADD REPLYlink written 3.1 years ago by Julian Gehring1.3k
3
gravatar for Julian Gehring
3.1 years ago by
Julian Gehring1.3k
Julian Gehring1.3k wrote:

The simplest way that comes to my mind is changing the ordering of the x-axis/scale in the graphics output itself. It is one of the nice properties in ggplot2 that we can practically change every parameter manually.

If we start with our old plot, and the "normal" ordering with 'A.A' on the left:

​data("sca_sigs", package = "SomaticSignatures")
p = plotSignatures(sigs_nmf, normalize = TRUE)
p ## old plot

Now we do the important work: We get the data from the plot, change it and feed it back into the object. What we want is to modify the context variable and give it an explicit ordering that we want. For this, we create a factor in which levels defines the ordering of choice. Here, I have simply inverted the ordering, such that e.g. 'A.A' is on the right and 'T.T' on the left end of the x-axis.

d = p$data
c = d$context
c = factor(c, levels = rev(unique(c))) ## levels defines the order of choice
d$context = c
p$data = d
p ## new plot

The new plot then gives us the new ordering of the x-axis, here we have effectively inverted the axis.

In your case, if you want to group by the suffix base, replace the third line with:

l = unique(c)
l = l[order(sapply(l, reverse))]
c = factor(c, levels = l)

I hope this helps, and please let me know if you have questions. Please note that all our changes only affect the plot, not the analysis of the somatic signatures itself. I'm thinking of offering an option to define the order as part of the plotMutationSpectrum function, but the solution here should give you instant results.

ADD COMMENTlink modified 3.1 years ago • written 3.1 years ago by Julian Gehring1.3k

Thanks Julian, it works!

ADD REPLYlink written 3.1 years ago by sergio.martinezcuesta10
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 2.2.0
Traffic: 332 users visited in the last hour