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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jan 26 13:24:05 CET 2009


Author: jombart
Date: 2009-01-26 13:24:05 +0100 (Mon, 26 Jan 2009)
New Revision: 246

Modified:
   pkg/R/sequences.R
   pkg/man/sequences.Rd
Log:
Fixes. Added thresPoly argument.


Modified: pkg/R/sequences.R
===================================================================
--- pkg/R/sequences.R	2009-01-26 10:47:02 UTC (rev 245)
+++ pkg/R/sequences.R	2009-01-26 12:24:05 UTC (rev 246)
@@ -10,7 +10,7 @@
 ################
 # DNAbin2genind
 ################
-DNAbin2genind <- function(x, pop=NULL, na.char=c("n","-","?")){
+DNAbin2genind <- function(x, pop=NULL, na.char=c("n","-","?"), polyThres=1/100){
 
     ## misc checks
     if(!inherits(x,"DNAbin")) stop("x is not a DNAbin object")
@@ -33,18 +33,20 @@
         colnames(x) <- 1:ncol(x)
     }
 
+    ## replace NAs
+    x[x %in% na.char] <- NA
+
     ## keep only columns with polymorphism (i.e., SNPs)
-    f1 <- function(vec){
-        if(length(unique(vec))==1) return(FALSE)
-        return(TRUE)
+    isPoly <- function(vec){
+        N <- sum(!is.na(vec)) # N: number of sequences
+        temp <- table(vec)/N
+        if(sum(temp > polyThres) >= 2) return(TRUE)
+        return(FALSE)
     }
 
-    toKeep <- apply(x, 2, f1)
+    toKeep <- apply(x, 2, isPoly)
     x <- x[,toKeep]
 
-    ## replace NAs
-    x[x %in% na.char] <- NA
-
     ## build output
     res <- df2genind(x, pop=pop, ploidy=1, ncode=1)
     res$call <- match.call()

Modified: pkg/man/sequences.Rd
===================================================================
--- pkg/man/sequences.Rd	2009-01-26 10:47:02 UTC (rev 245)
+++ pkg/man/sequences.Rd	2009-01-26 12:24:05 UTC (rev 246)
@@ -12,13 +12,15 @@
   - alignement (seqinr package): to come...
 }
 \usage{
-DNAbin2genind(x, pop=NULL, na.char=c("n","-","?"))
+DNAbin2genind(x, pop=NULL, na.char=c("n","-","?"), 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.}
+   considered as NA.}
+ \item{polyThres}{the minimum frequency of a minor allele for a locus to
+  be considered as polymorphic (defaults to 0.01).}
 }
 
 \value{an object of the class \linkS4class{genind}}



More information about the adegenet-commits mailing list