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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 3 12:18:34 CET 2011


Author: jombart
Date: 2011-03-03 12:18:33 +0100 (Thu, 03 Mar 2011)
New Revision: 833

Added:
   pkg/man/as.SNPbin.Rd
   pkg/man/as.genlight.Rd
Modified:
   pkg/R/SNPbin.R
   pkg/man/SNPbin.Rd
   pkg/man/genlight.Rd
Log:
Added 'as' conversions for SNPbin/genlight classes.
Can be used instead of the constructor to create objects.


Modified: pkg/R/SNPbin.R
===================================================================
--- pkg/R/SNPbin.R	2011-03-01 16:35:32 UTC (rev 832)
+++ pkg/R/SNPbin.R	2011-03-03 11:18:33 UTC (rev 833)
@@ -690,6 +690,11 @@
 #############
 ## as methods
 #############
+## KLUDGE - needed for as.matrix.genlight to be dispatched correctly (R-2.12.1)
+setGeneric("as.matrix")
+
+
+## SNPbin/genlight -> other
 setAs("SNPbin", "integer", def=function(from){
     res <- .SNPbin2int(from)
     return(res)
@@ -713,9 +718,6 @@
 })
 
 
-## KLUDGE - needed for as.matrix.genlight to be dispatched correctly (R-2.12.1)
-setGeneric("as.matrix")
-
 as.matrix.genlight <- function(x, ...){
     return(as(x, "matrix"))
 }
@@ -745,11 +747,49 @@
 
 
 
+## other -> SNPbin/genlight
+setGeneric("as.SNPbin", function(x, ...) standardGeneric("as.SNPbin"))
+setGeneric("as.genlight", function(x, ...) standardGeneric("as.genlight"))
 
+setAs("integer", "SNPbin", def=function(from){
+    res <- new("SNPbin", from)
+    return(res)
+})
 
+setAs("numeric", "SNPbin", def=function(from){
+    res <- new("SNPbin", from)
+    return(res)
+})
 
 
+setMethod("as.SNPbin", "integer", function(x, ...) as(x, "SNPbin"))
+setMethod("as.SNPbin", "numeric", function(x, ...) as(x, "SNPbin"))
 
+
+setAs("matrix", "genlight", def=function(from){
+    return(new("genlight", from))
+})
+
+
+setAs("data.frame", "genlight", def=function(from){
+    return(new("genlight", from))
+})
+
+
+setAs("list", "genlight", def=function(from){
+    return(new("genlight", from))
+})
+
+
+setMethod("as.genlight", "matrix", function(x, ...) as(x, "genlight"))
+setMethod("as.genlight", "data.frame", function(x, ...) as(x, "genlight"))
+setMethod("as.genlight", "list", function(x, ...) as(x, "genlight"))
+
+
+
+
+
+
 ################################
 ## testing SNPbin
 ##

Modified: pkg/man/SNPbin.Rd
===================================================================
--- pkg/man/SNPbin.Rd	2011-03-01 16:35:32 UTC (rev 832)
+++ pkg/man/SNPbin.Rd	2011-03-03 11:18:33 UTC (rev 833)
@@ -12,14 +12,15 @@
 \alias{names,SNPbin-method}
 \alias{ploidy,SNPbin-method}
 \alias{ploidy<-,SNPbin-method}
-\alias{as,SNPbin,integer-method}
 \alias{coerce,SNPbin,integer-method}
 \alias{as.integer.SNPbin}
 \alias{NA.posi,SNPbin-method}
-\alias{,SNPbin-method}
-\alias{,SNPbin-method}
 \alias{cbind.SNPbin}
 \alias{c.SNPbin}
+\alias{as,integer,SNPbin-method}
+\alias{as,numeric,SNPbin-method}
+
+
 % \alias{,SNPbin-method}
 % \alias{,SNPbin-method}
 % \alias{,SNPbin-method}

Added: pkg/man/as.SNPbin.Rd
===================================================================
--- pkg/man/as.SNPbin.Rd	                        (rev 0)
+++ pkg/man/as.SNPbin.Rd	2011-03-03 11:18:33 UTC (rev 833)
@@ -0,0 +1,54 @@
+\name{as.SNPbin}
+\alias{as,SNPbin,integer-method}
+\alias{as,SNPbin,numeric-method}
+\alias{as.SNPbin}
+\alias{as.SNPbin,integer-method}
+\alias{as.SNPbin,numeric-method}
+\alias{coerce,integer,SNPbin-method}
+\alias{coerce,numeric,SNPbin-method}
+
+% \alias{,SNPbin-method}
+% \alias{,SNPbin-method}
+% \alias{,SNPbin-method}
+% \alias{,SNPbin-method}
+%%%%
+\title{Conversion to class "SNPbin"}
+\description{
+  The class \linkS4class{SNPbin} is a formal (S4) class for storing a genotype
+  of binary SNPs in a compact way, using a bit-level coding scheme. New
+  instances of this class are best created using \code{new}; see the
+  manpage of \linkS4class{SNPbin} for more information on this point.
+
+  As a shortcut, conversion methods can be used to convert various
+  objects into a \linkS4class{SNPbin} object. Conversions can be
+  achieved using S3-style (\code{as.SNPbin(x)}) or S4-style
+  (\code{as(x,"SNPbin"}) procedures. All of them call upon the
+  constructor (\code{new}) of \linkS4class{SNPbin} objects.
+
+  Conversion is currently available from the following objects:
+  - integer vectors
+  - numeric vectors
+}
+\author{Thibaut Jombart (\email{t.jombart at imperial.ac.uk})}
+\seealso{
+  Related class:\cr
+  -  \code{\linkS4class{SNPbin}}
+  -  \code{\linkS4class{genlight}}, for storing multiple binary SNP
+  genotypes. \cr
+}
+\examples{
+## data to be converted
+dat <- c(1,0,0,2,1,1,1,2,2,1,1,0,0,1)
+
+## using the constructor
+x1 <- new("SNPbin", dat)
+x1
+
+## using 'as' methods
+x2 <- as.SNPbin(dat)
+x3 <- as(dat, "SNPbin")
+
+identical(x1,x2)
+identical(x1,x3)
+}
+\keyword{classes}

Added: pkg/man/as.genlight.Rd
===================================================================
--- pkg/man/as.genlight.Rd	                        (rev 0)
+++ pkg/man/as.genlight.Rd	2011-03-03 11:18:33 UTC (rev 833)
@@ -0,0 +1,61 @@
+\name{as.genlight}
+\alias{as,genlight,matrix-method}
+\alias{as,genlight,data.frame-method}
+\alias{as,genlight,list-method}
+\alias{as.genlight}
+\alias{as.genlight,matrix-method}
+\alias{as.genlight,data.frame-method}
+\alias{as.genlight,list-method}
+\alias{coerce,genlight,matrix-method}
+\alias{coerce,genlight,data.frame-method}
+\alias{coerce,genlight,list-method}
+
+% \alias{,genlight-method}
+% \alias{,genlight-method}
+% \alias{,genlight-method}
+% \alias{,genlight-method}
+%%%%
+\title{Conversion to class "genlight"}
+\description{
+  The class \code{genlight} is a formal (S4) class for storing a genotypes
+  of binary SNPs in a compact way, using a bit-level coding scheme. New
+  instances of this class are best created using \code{new}; see the
+  manpage of \linkS4class{genlight} for more information on this point.
+
+  As a shortcut, conversion methods can be used to convert various
+  objects into a \linkS4class{genlight} object. Conversions can be
+  achieved using S3-style (\code{as.genlight(x)}) or S4-style
+  (\code{as(x,"genlight"}) procedures. All of them call upon the
+  constructor (\code{new}) of \linkS4class{genlight} objects.
+
+  Conversion is currently available from the following objects:
+  - matrix of type integer/numeric
+  - data.frame with integer/numeric data
+  - list of vectors of integer/numeric type
+}
+\author{Thibaut Jombart (\email{t.jombart at imperial.ac.uk})}
+\seealso{
+ Related class:\cr
+  -  \code{\linkS4class{SNPbin}}, for storing individual genotypes of
+  binary SNPs\cr
+  
+  -  \code{\linkS4class{genind}}
+}
+\examples{
+## data to be converted
+dat <- list(toto=c(1,1,0,0,2,2,1,2,NA), titi=c(NA,1,1,0,1,1,1,0,0), tata=c(NA,0,3, NA,1,1,1,0,0))
+
+## using the constructor
+x1 <- new("genlight", dat)
+x1
+
+## using 'as' methods
+x2 <- as.genlight(dat)
+x3 <- as(dat, "genlight")
+
+identical(x1,x2)
+identical(x1,x3)
+
+
+}
+\keyword{classes}

Modified: pkg/man/genlight.Rd
===================================================================
--- pkg/man/genlight.Rd	2011-03-01 16:35:32 UTC (rev 832)
+++ pkg/man/genlight.Rd	2011-03-03 11:18:33 UTC (rev 833)
@@ -25,14 +25,14 @@
 \alias{NA.posi,genlight-method}
 \alias{other,genlight-method}
 \alias{other<-,genlight-method}
-\alias{as,genlight,matrix-method}
-\alias{coerce,genlight,matrix-method}
 \alias{as.matrix.genlight}
-\alias{as,genlight,data.frame-method}
-\alias{coerce,genlight,data.frame-method}
 \alias{as.data.frame.genlight}
-\alias{as,genlight,list-method}
-\alias{coerce,genlight,list-method}
+\alias{as,matrix,genlight-method}
+\alias{as,data.frame,genlight-method}
+\alias{as,list,genlight-method}
+\alias{coerce,matrix,genlight-method}
+\alias{coerce,data.frame,genlight-method}
+\alias{coerce,list,genlight-method}
 \alias{as.list.genlight}
 \alias{cbind.genlight}
 \alias{rbind.genlight}



More information about the adegenet-commits mailing list