[adegenet-commits] r247 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jan 26 14:02:33 CET 2009
Author: jombart
Date: 2009-01-26 14:02:33 +0100 (Mon, 26 Jan 2009)
New Revision: 247
Modified:
pkg/R/sequences.R
pkg/man/sequences.Rd
Log:
Regexp used to replace NAs, much faster.
Modified: pkg/R/sequences.R
===================================================================
--- pkg/R/sequences.R 2009-01-26 12:24:05 UTC (rev 246)
+++ pkg/R/sequences.R 2009-01-26 13:02:33 UTC (rev 247)
@@ -10,7 +10,7 @@
################
# DNAbin2genind
################
-DNAbin2genind <- function(x, pop=NULL, na.char=c("n","-","?"), polyThres=1/100){
+DNAbin2genind <- function(x, pop=NULL, exp.char=c("a","t","g","c"), na.char=NULL, polyThres=1/100){
## misc checks
if(!inherits(x,"DNAbin")) stop("x is not a DNAbin object")
@@ -34,7 +34,22 @@
}
## replace NAs
- x[x %in% na.char] <- NA
+ if(is.null(na.char)){
+ if(is.null(exp.char)) stop("both exp.char and na.char are NULL")
+ temp <- paste(exp.char, collapse="", sep="")
+ if(any(exp.char=="-")) {
+ temp <- paste("-",temp, sep="") # string '-' must start the regexp
+ }
+ temp <- paste("[^", temp, "]", sep="") # anything but the expected is NA
+ x <- gsub(temp,NA,x)
+ } else {
+ temp <- paste(na.char, collapse="", sep="")
+ if(any(na.char=="-")) {
+ temp <- paste("-",temp, sep="") # string '-' must start the regexp
+ }
+ temp <- paste("[", temp, "]", sep="")
+ x <- gsub(temp,NA,x)
+ }
## keep only columns with polymorphism (i.e., SNPs)
isPoly <- function(vec){
Modified: pkg/man/sequences.Rd
===================================================================
--- pkg/man/sequences.Rd 2009-01-26 12:24:05 UTC (rev 246)
+++ pkg/man/sequences.Rd 2009-01-26 13:02:33 UTC (rev 247)
@@ -12,13 +12,15 @@
- alignement (seqinr package): to come...
}
\usage{
-DNAbin2genind(x, pop=NULL, na.char=c("n","-","?"), polyThres=1/100)
+DNAbin2genind(x, pop=NULL, exp.char=c("a","t","g","c"), na.char=NULL, polyThres=1/100)
}
\arguments{
\item{x}{an object containing aligned sequences.}
\item{pop}{an optional factor giving the population to which each sequence belongs.}
- \item{na.char}{a character vector providing values that should be
- considered as NA.}
+ \item{exp.char}{a vector of single character providing expected values;
+ all other characters will be turned to NA.}
+ \item{na.char}{a vector of single characters providing values that should be
+ considered as NA. If not NULL, this is used instead of \code{exp.char}.}
\item{polyThres}{the minimum frequency of a minor allele for a locus to
be considered as polymorphic (defaults to 0.01).}
}
More information about the adegenet-commits
mailing list