[adegenet-commits] r136 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jun 28 18:20:59 CEST 2008
Author: jombart
Date: 2008-06-28 18:20:58 +0200 (Sat, 28 Jun 2008)
New Revision: 136
Modified:
pkg/R/import.R
Log:
Somes fixes to df2genind for haploid and triploid cases.
Modified: pkg/R/import.R
===================================================================
--- pkg/R/import.R 2008-06-26 16:02:13 UTC (rev 135)
+++ pkg/R/import.R 2008-06-28 16:20:58 UTC (rev 136)
@@ -46,6 +46,9 @@
res <- list()
+ ## make sure X is in character mode
+ mode(X) <- "character"
+
n <- nrow(X)
nloc <- ncol(X)
ploidy <- as.integer(ploidy)
@@ -71,8 +74,10 @@
## ERASE ENTIRELY NON-TYPE LOCI AND INDIVIDUALS
tempX <- X
if(!is.null(sep)) tempX <- gsub(sep,"",X)
+ ## turn NANANA, 00000, ... into NA
tempX <- gsub("^0*$",NA,X)
-
+ tempX <- gsub("(NA)+",NA,tempX)
+
## Erase entierely non-typed loci
temp <- apply(tempX,2,function(c) all(is.na(c)))
if(any(temp)){
@@ -93,6 +98,8 @@
}
n <- nrow(X)
+ X <- gsub("^.*NA.*$",NA,X) # set correct NAs in X
+
# ind.names <- rownames(X) this erases the real labels
# note: if X is kept as a matrix, duplicate row names are no problem
@@ -278,7 +285,7 @@
pop <- factor(rep(pop.names,pop.nind))
## pass X to df2genind
- res <- df2genind(X=X, ncode=6, pop=pop, missing=missing)
+ res <- df2genind(X=X, ncode=6, pop=pop, missing=missing, ploidy=2)
res at call <- match.call()
if(!quiet) cat("\n...done.\n\n")
@@ -320,7 +327,7 @@
colnames(X) <- loc.names
rownames(X) <- 1:nrow(X)
- res <- df2genind(X=X,pop=pop,missing=missing)
+ res <- df2genind(X=X,pop=pop,missing=missing, ploidy=2)
# beware : fstat files do not yield ind names
res at ind.names <- rep("",length(res at ind.names))
names(res at ind.names) <- rownames(res at tab)
@@ -451,7 +458,7 @@
pop.names <- ind.names[pop.names.idx]
levels(pop) <- pop.names
- res <- df2genind(X=X,pop=pop,missing=missing)
+ res <- df2genind(X=X,pop=pop,missing=missing, ploidy=2)
res at call <- prevcall
if(!quiet) cat("\n...done.\n\n")
@@ -617,7 +624,7 @@
rownames(X) <- ind.names
colnames(X) <- loc.names
- res <- df2genind(X=X,pop=pop,missing=missing)
+ res <- df2genind(X=X,pop=pop,missing=missing, ploidy=2)
res at call <- match.call()
More information about the adegenet-commits
mailing list