[adegenet-commits] r862 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 20 16:19:57 CEST 2011


Author: jombart
Date: 2011-04-20 16:19:57 +0200 (Wed, 20 Apr 2011)
New Revision: 862

Modified:
   pkg/R/glHandle.R
   pkg/man/seploc.Rd
Log:
Finished seploc. Documented method for genlight objects.


Modified: pkg/R/glHandle.R
===================================================================
--- pkg/R/glHandle.R	2011-04-18 11:42:06 UTC (rev 861)
+++ pkg/R/glHandle.R	2011-04-20 14:19:57 UTC (rev 862)
@@ -238,7 +238,7 @@
 ## seploc
 ##########
 setMethod("seploc", signature(x="genlight"), function(x, n.block=NULL, block.size=NULL, random=FALSE,
-                               multicore=FALSE, n.cores=NULL){
+                               multicore=require(multicore), n.cores=NULL){
     ## CHECKS ##
     if(is.null(n.block) & is.null(block.size)) stop("n.block and block.size are both missing.")
     if(!is.null(n.block) & !is.null(block.size)) stop("n.block and block.size are both provided.")
@@ -276,12 +276,12 @@
     }
 
     if(multicore){
-        res <- mclapply(levels(fac.block), function(lev) x[,fac.block==lev],
+        res <- mclapply(levels(fac.block), function(lev) x[,sample(which(fac.block==lev))],
                         mc.cores=n.cores, mc.silent=TRUE, mc.cleanup=TRUE, mc.preschedule=FALSE)
+    } else {
+        res <- lapply(levels(fac.block), function(lev) x[,sample(which(fac.block==lev))])
     }
 
-    res <- lapply(levels(fac.block), function(lev) x[,fac.block==lev])
-
     ## return result ##
     names(res) <- paste("block", 1:length(res),sep=".")
 

Modified: pkg/man/seploc.Rd
===================================================================
--- pkg/man/seploc.Rd	2011-04-18 11:42:06 UTC (rev 861)
+++ pkg/man/seploc.Rd	2011-04-20 14:19:57 UTC (rev 862)
@@ -9,13 +9,18 @@
 \alias{seploc,genlight-method}
 \title{ Separate data per locus}
 \description{
-  The function \code{seploc} splits an object (\linkS4class{genind} or
-  \linkS4class{genpop}) by marker, returning a list of objects whose components
-  each correspond to a marker.\cr
+  The function \code{seploc} splits an object (\linkS4class{genind},
+  \linkS4class{genpop} or \linkS4class{genlight}) by marker. For
+  \linkS4class{genind} and \linkS4class{genpop} objects, the method
+  returns a list of objects whose components each correspond to a
+  marker. For \linkS4class{genlight} objects, the methods returns blocks
+  of SNPs.
 }
 \usage{
 \S4method{seploc}{genind}(x,truenames=TRUE,res.type=c("genind","matrix"))
 \S4method{seploc}{genpop}(x,truenames=TRUE,res.type=c("genpop","matrix"))
+\S4method{seploc}{genlight}(x, n.block=NULL, block.size=NULL, random=FALSE,
+       multicore=require(multicore), n.cores=NULL)
 }
 \arguments{
     \item{x}{a \linkS4class{genind} or a \linkS4class{genpop} object.}
@@ -24,6 +29,18 @@
     \item{res.type}{a character indicating the type of returned results,
       a genind or genpop object (default) or a matrix of data
       corresponding to the 'tab' slot.}
+    \item{n.block}{an integer indicating the number of blocks of SNPs to
+      be returned.}
+    \item{block.size}{an integer indicating the size (in number of SNPs)
+      of the blocks to be returned.}
+    \item{random}{should blocks be formed of contiguous SNPs, or should
+      they be made or randomly chosen SNPs.}
+    \item{multicore}{a logical indicating whether multiple cores -if
+      available- should be used for the computations (TRUE, default), or
+      not (FALSE); requires the package \code{multicore} to be installed.}
+    \item{n.cores}{if \code{multicore} is TRUE, the number of cores to be
+      used in the computations; if NULL, then the maximum number of cores
+      available on the computer is used.}
 }
 \value{The function \code{seploc} returns an list of objects of the
   same class as the initial object, or a list of matrices similar to
@@ -32,6 +49,7 @@
 \author{Thibaut Jombart \email{t.jombart at imperial.ac.uk} }
 \seealso{\code{\link{seppop}}, \code{\link{repool}}}
 \examples{
+## example on genind objects
 data(microbov)
 
 # separate all markers
@@ -39,5 +57,20 @@
 names(obj)
 
 obj$INRA5
+
+
+## example on genlight objects
+x <- glSim(100, 1000, 0, ploidy=2) # simulate data
+x <- x[,order(glSum(x))] # reorder loci by frequency of 2nd allele
+glPlot(x, main="All data") # plot data
+foo <- seploc(x, n.block=3) # form 3 blocks
+foo
+glPlot(foo[[1]], main="1st block") # plot 1st block
+glPlot(foo[[2]], main="2nd block") # plot 2nd block
+glPlot(foo[[3]], main="3rd block") # plot 3rd block
+
+foo <- seploc(x, block.size=600, random=TRUE) # split data, randomize loci
+foo # note the different block sizes
+glPlot(foo[[1]])
 }
 \keyword{manip}
\ No newline at end of file



More information about the adegenet-commits mailing list