[adegenet-commits] r738 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 13 11:45:28 CET 2010


Author: jombart
Date: 2010-12-13 11:45:28 +0100 (Mon, 13 Dec 2010)
New Revision: 738

Added:
   pkg/R/SNPbin.R
Log:
some raw code for SNPbin


Added: pkg/R/SNPbin.R
===================================================================
--- pkg/R/SNPbin.R	                        (rev 0)
+++ pkg/R/SNPbin.R	2010-12-13 10:45:28 UTC (rev 738)
@@ -0,0 +1,18 @@
+## each byte takes a value on [0,255]
+
+## function to code multiple SNPs on a byte
+## 7 combinations of SNPs can be coded on a single byte
+## we use bytes values from [1,128]
+## 200 is a missing value
+SNPCOMB <- expand.grid(rep(list(c(0,1)), 7))
+
+
+f1 <- function(vecSnp){
+    nbBytes <- 1+ length(vecSnp) %/% 7
+    out.length <- 7*nbBytes
+    temp <- c(vecSnp, rep(0, out.length-length(vecSnp))) # fill the end with 0 of necessary
+    sapply(seq(1, by=7, length=nbBytes), function(i) which(apply(SNPCOMB,1, function(e) all(vecSnp[i:(i+7)]==e))) )
+
+
+    as.raw(length(vecSnp))
+}



More information about the adegenet-commits mailing list