[adegenet-commits] r846 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 10 12:15:16 CET 2011


Author: jombart
Date: 2011-03-10 12:15:16 +0100 (Thu, 10 Mar 2011)
New Revision: 846

Modified:
   pkg/R/glHandle.R
Log:
Updated the [ operator.
Now does not use as.matrix so that data are converted one at a time.
Subsetting position and chromosome.


Modified: pkg/R/glHandle.R
===================================================================
--- pkg/R/glHandle.R	2011-03-09 13:37:54 UTC (rev 845)
+++ pkg/R/glHandle.R	2011-03-10 11:15:16 UTC (rev 846)
@@ -41,8 +41,8 @@
     } else {
         ori.pop <- NULL
     }
-    
 
+
     ## HANDLE 'OTHER' SLOT ##
     nOther <- length(other(x))
     namesOther <- names(other(x))
@@ -70,8 +70,15 @@
         return(x)
     } else { # need to subset SNPs
         old.other <- other(x)
-        x <- as.matrix(x)[, j, drop=FALSE] # maybe need to process one row at a time
-        x <- new("genlight", gen=x, pop=ori.pop, ploidy=ori.ploidy, other=old.other)
+
+        ## handle loc.names, chromosome and position
+        new.loc.names <- locNames(x)[j]
+        new.chr <- chr(x)[j]
+        new.position <- position(x)[j]
+        new.gen <- lapply(x at gen, function(e) e[j])
+        ##x <- as.matrix(x)[, j, drop=FALSE] # maybe need to process one row at a time
+        x <- new("genlight", gen=new.gen, pop=ori.pop, ploidy=ori.ploidy, loc.names=new.loc.names,
+                 chromosome=new.chr, position=new.position, other=old.other)
     }
 
     return(x)



More information about the adegenet-commits mailing list