Last data update: 2014.03.03

R: function to visualize GC content or CpG content of input...
plot.gcR Documentation

function to visualize GC content or CpG content of input sequences

Description

plot.gc calculates the GC (or CpG) content based on a window size for each sequence and plots the content for all sequences as a heatmap over position and sequence.

Usage

## S4 method for signature 'cobindr'
plot.gc(x, seq.ids, cpg = F, wind.size = 50,
sig.test = F, hm.margin = c(4, 10), frac = 10, n.cpu = NA)

Arguments

x

an object of the class "cobindr", which will hold all necessary information about the sequences.

seq.ids

list of sequence identifiers, for which the GC (or CpG) content will be plotted.

cpg

logical flag, if cpg=TRUE the CpG content rather than the GC content will be calculated and plotted.

wind.size

integer describing the window size for GC content calculation

sig.test

logical flag, if sig.test=TRUE wilcoxon.test is performed per individual window against all windows in other sequence at the same position. The significance test might be slow for large number of sequences

hm.margin

optional argument providing the margin widths for the heatmap (if sig.test=FALSE)

frac

determines the overlap between consecutive windows as fraction wind.size/frac

n.cpu

number of CPUs to be used for parallelization. Default value is 'NA' in which case the number of available CPUs is checked and than used.

Author(s)

Robert Lehmann <r.lehmann@biologie.hu-berlin.de>

See Also

testCpG

Examples

library(Biostrings)

n <- 50 # number of input sequences
l <- 100 # length of sequences
bases <- c("A","C","G","T") # alphabet
# generate random input sequences with two groups with differing GC content
seqs <- sapply(1:(3*n/4), function(x) paste(sample(bases, l, replace=TRUE, 
		prob=c(.3,.22,.2,.28)), collapse=""))
seqs <- append(seqs, sapply(1:(n/4), function(x) paste(sample(bases, l, 
		replace=TRUE, prob=c(.25,.25,.25,.25)), collapse="")))
#save sample sequences in fasta file
tmp.file <- tempfile(pattern = "cobindr_sample_seq", tmpdir = tempdir(),
fileext = ".fasta")
writeXStringSet(DNAStringSet(seqs), tmp.file)

cfg <- new('configuration')
slot(cfg, 'sequence_type') <- 'fasta'
slot(cfg, 'sequence_source') <- tmp.file
# avoid complaint of validation mechanism 
slot(cfg, 'pfm_path') <- system.file('extdata/pfms',package='cobindR')
slot(cfg, 'pairs') <- ''

runObj <- new('cobindr', cfg, 'test')

plot.gc(runObj, cpg = TRUE)

unlink(tmp.file)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(cobindR)

Attaching package: 'cobindR'

The following object is masked from 'package:base':

    sequence

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/cobindR/plot.gc.Rd_%03d_medium.png", width=480, height=480)
> ### Name: plot.gc
> ### Title: function to visualize GC content or CpG content of input
> ###   sequences
> ### Aliases: plot.gc plot.gc-method plot.gc,cobindr-method
> ### Keywords: dplot hplot
> 
> ### ** Examples
> 
> library(Biostrings)
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
Loading required package: XVector
> 
> n <- 50 # number of input sequences
> l <- 100 # length of sequences
> bases <- c("A","C","G","T") # alphabet
> # generate random input sequences with two groups with differing GC content
> seqs <- sapply(1:(3*n/4), function(x) paste(sample(bases, l, replace=TRUE, 
+ 		prob=c(.3,.22,.2,.28)), collapse=""))
> seqs <- append(seqs, sapply(1:(n/4), function(x) paste(sample(bases, l, 
+ 		replace=TRUE, prob=c(.25,.25,.25,.25)), collapse="")))
> #save sample sequences in fasta file
> tmp.file <- tempfile(pattern = "cobindr_sample_seq", tmpdir = tempdir(),
+ fileext = ".fasta")
> writeXStringSet(DNAStringSet(seqs), tmp.file)
> 
> cfg <- new('configuration')
Warning message:
In .local(.Object, ...) :
  no config-file defined, generating configuration-object with default values
> slot(cfg, 'sequence_type') <- 'fasta'
> slot(cfg, 'sequence_source') <- tmp.file
> # avoid complaint of validation mechanism 
> slot(cfg, 'pfm_path') <- system.file('extdata/pfms',package='cobindR')
> slot(cfg, 'pairs') <- ''
> 
> runObj <- new('cobindr', cfg, 'test')
[1] "Creating a new experiment!"
reading file /tmp/Rtmp6Q7qNg/cobindr_sample_seq675a619ab566.fasta ...
   |                                                                               |                                                                      |   0%   |                                                                               |=                                                                     |   2%   |                                                                               |===                                                                   |   4%   |                                                                               |====                                                                  |   6%   |                                                                               |======                                                                |   8%   |                                                                               |=======                                                               |  10%   |                                                                               |=========                                                             |  12%   |                                                                               |==========                                                            |  14%   |                                                                               |===========                                                           |  16%   |                                                                               |=============                                                         |  18%   |                                                                               |==============                                                        |  20%   |                                                                               |================                                                      |  22%   |                                                                               |=================                                                     |  24%   |                                                                               |===================                                                   |  27%   |                                                                               |====================                                                  |  29%   |                                                                               |=====================                                                 |  31%   |                                                                               |=======================                                               |  33%   |                                                                               |========================                                              |  35%   |                                                                               |==========================                                            |  37%   |                                                                               |===========================                                           |  39%   |                                                                               |=============================                                         |  41%   |                                                                               |==============================                                        |  43%   |                                                                               |===============================                                       |  45%   |                                                                               |=================================                                     |  47%   |                                                                               |==================================                                    |  49%   |                                                                               |====================================                                  |  51%   |                                                                               |=====================================                                 |  53%   |                                                                               |=======================================                               |  55%   |                                                                               |========================================                              |  57%   |                                                                               |=========================================                             |  59%   |                                                                               |===========================================                           |  61%   |                                                                               |============================================                          |  63%   |                                                                               |==============================================                        |  65%   |                                                                               |===============================================                       |  67%   |                                                                               |=================================================                     |  69%   |                                                                               |==================================================                    |  71%   |                                                                               |===================================================                   |  73%   |                                                                               |=====================================================                 |  76%   |                                                                               |======================================================                |  78%   |                                                                               |========================================================              |  80%   |                                                                               |=========================================================             |  82%   |                                                                               |===========================================================           |  84%   |                                                                               |============================================================          |  86%   |                                                                               |=============================================================         |  88%   |                                                                               |===============================================================       |  90%   |                                                                               |================================================================      |  92%   |                                                                               |==================================================================    |  94%   |                                                                               |===================================================================   |  96%   |                                                                               |===================================================================== |  98%   |                                                                               |======================================================================| 100%ready retrieving sequences!
 reading pfm files: /home/ddbj/local/lib64/R/library/cobindR/extdata/pfms ...
[1] "ES_Sox2_1_c1058"
[1] "ES_Klf4_3_c1373"
[1] "ES_Oct4_1_c570"
[1] "ES_Sox2_1_c1058"
ignored files:
 
Using the parallel (multicore) version of cobindR - function cpg.gc.content with 4 cores
There were 50 or more warnings (use warnings() to see the first 50)
> 
> plot.gc(runObj, cpg = TRUE)
Loading required package: RColorBrewer
   |                                                                               |                                                                      |   0%calculating GC / CpG content...
Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.5625
   |                                                                               |=                                                                     |   2%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.9259259
   |                                                                               |===                                                                   |   4%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.282051
   |                                                                               |====                                                                  |   6%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 2.097902
   |                                                                               |======                                                                |   8%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.8333333
   |                                                                               |=======                                                               |  10%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.7211538
   |                                                                               |=========                                                             |  12%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.7142857
   |                                                                               |==========                                                            |  14%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.4545455
   |                                                                               |===========                                                           |  16%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.9259259
   |                                                                               |=============                                                         |  18%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.4201681
   |                                                                               |==============                                                        |  20%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.9615385
   |                                                                               |================                                                      |  22%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.25
   |                                                                               |=================                                                     |  24%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.470588
   |                                                                               |===================                                                   |  27%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.617284
   |                                                                               |====================                                                  |  29%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.515152
   |                                                                               |=====================                                                 |  31%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.602564
   |                                                                               |=======================                                               |  33%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.4545455
   |                                                                               |========================                                              |  35%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.9090909
   |                                                                               |==========================                                            |  37%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.515152
   |                                                                               |===========================                                           |  39%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.6410256
   |                                                                               |=============================                                         |  41%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.5681818
   |                                                                               |==============================                                        |  43%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.428571
   |                                                                               |===============================                                       |  45%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.9090909
   |                                                                               |=================================                                     |  47%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.020408
   |                                                                               |==================================                                    |  49%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.298701
   |                                                                               |====================================                                  |  51%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.136364
   |                                                                               |=====================================                                 |  53%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.9090909
   |                                                                               |=======================================                               |  55%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0
   |                                                                               |========================================                              |  57%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 2.040816
   |                                                                               |=========================================                             |  59%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.8333333
   |                                                                               |===========================================                           |  61%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.176471
   |                                                                               |============================================                          |  63%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.5494505
   |                                                                               |==============================================                        |  65%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.7575758
   |                                                                               |===============================================                       |  67%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.176471
   |                                                                               |=================================================                     |  69%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0
   |                                                                               |==================================================                    |  71%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 2.307692
   |                                                                               |===================================================                   |  73%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.6944444
   |                                                                               |=====================================================                 |  76%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0
   |                                                                               |======================================================                |  78%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.6410256
   |                                                                               |========================================================              |  80%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.010101
   |                                                                               |=========================================================             |  82%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.052632
   |                                                                               |===========================================================           |  84%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.190476
   |                                                                               |============================================================          |  86%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.363636
   |                                                                               |=============================================================         |  88%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.6993007
   |                                                                               |===============================================================       |  90%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.25
   |                                                                               |================================================================      |  92%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.25
   |                                                                               |==================================================================    |  94%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.234568
   |                                                                               |===================================================================   |  96%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 1.298701
   |                                                                               |===================================================================== |  98%Using the parallel (multicore) version of cobindR - function wind.cpg.content with 4 cores
[1] 0.8241758
   |                                                                               |======================================================================| 100%
> 
> unlink(tmp.file)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>