[adegenet-commits] r829 - in pkg: R src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 1 12:12:30 CET 2011


Author: jombart
Date: 2011-03-01 12:12:30 +0100 (Tue, 01 Mar 2011)
New Revision: 829

Modified:
   pkg/R/SNPbin.R
   pkg/src/snpbin.c
   pkg/src/snpbin.h
Log:
Swtiching from one bug to another.
Restored .SNPbin - works well.
glPca now crashes again.


Modified: pkg/R/SNPbin.R
===================================================================
--- pkg/R/SNPbin.R	2011-03-01 10:43:05 UTC (rev 828)
+++ pkg/R/SNPbin.R	2011-03-01 11:12:30 UTC (rev 829)
@@ -672,7 +672,8 @@
 ## convert SNPbin to integers (0/1/2...)
 .SNPbin2int <- function(x){
     ##res <- lapply(x at snp, .raw2bin)
-    res <- .C("bytesToInt", unlist(x at snp), length(x at snp[[1]]), length(x at snp), integer(x at n.loc*8), PACKAGE="adegenet")[[4]][1:x at n.loc]
+    
+    res <- .C("bytesToInt", unlist(x at snp), length(x at snp[[1]]), length(x at snp), integer(nLoc(x)), as.integer(nLoc(x)), PACKAGE="adegenet")[[4]][1:nLoc(x)]
     ##res <- lapply(res, function(e) e[1:x at n.loc])
     ##res <- as.integer(Reduce("+", res))
     if(length(x at NA.posi)>0){

Modified: pkg/src/snpbin.c
===================================================================
--- pkg/src/snpbin.c	2011-03-01 10:43:05 UTC (rev 828)
+++ pkg/src/snpbin.c	2011-03-01 11:12:30 UTC (rev 829)
@@ -177,13 +177,13 @@
 /* veclength is the length of one vector of bytes */
 /* nbvec is the nb of input vectors*/
 /* input 'vecbytes' is actually concatenated, ie of size veclength * nbvec */
-void bytesToInt(unsigned char *vecbytes, int *veclength, int *nbvec, int *vecres, int reslength){
+void bytesToInt(unsigned char *vecbytes, int *veclength, int *nbvec, int *vecres, int *reslength){
 	int i, j, k, idres=0, *temp; /* idres: index in vecres*/
 
 	temp = (int *) calloc(8, sizeof(int));
 
 	/* initialize result vector to 0 */
-	for(i=0; i < reslength; i++){
+	for(i=0; i < *reslength; i++){
 		vecres[i]=0;
 	}
 
@@ -205,13 +205,13 @@
 
 
 
-void bytesToDouble(unsigned char *vecbytes, int *veclength, int *nbvec, double *vecres, int reslength){
+void bytesToDouble(unsigned char *vecbytes, int *veclength, int *nbvec, double *vecres, int *reslength){
 	int i, j, k, idres=0; /* idres: index in vecres*/
 	double *temp;
 	temp = (double *) calloc(8, sizeof(double));
 
 	/* initialize result vector to 0 */
-	for(i=0; i < reslength; i++){
+	for(i=0; i < *reslength; i++){
 		vecres[i]=0.0;
 	}
 
@@ -309,7 +309,9 @@
 
 /* transform a snpbin into a vector of integers */
 void snpbin2intvec(struct snpbin *x, int *out){
-	bytesToInt(x->bytevec, x->byteveclength, x->bytevecnb, out, nLoc(x));
+	int *temp;
+	*temp=nLoc(x);
+	bytesToInt(x->bytevec, x->byteveclength, x->bytevecnb, out, temp);
 /*reminders:
 - void bytesToInt(unsigned char *vecbytes, int *veclength, int *nbvec, int *vecres, int reslength){
 - snpbin: unsigned char *bytevec; int *byteveclength, *bytevecnb, *nloc, *nanb, *naposi; */
@@ -320,7 +322,9 @@
 /* transform a snpbin into a vector of frequencies (double) */
 void snpbin2freq(struct snpbin *x, double *out){
 	double ploid = (double) ploidy(x);
-	bytesToDouble(x->bytevec, x->byteveclength, x->bytevecnb, out, nLoc(x));
+	int *temp;
+	*temp=nLoc(x);
+	bytesToDouble(x->bytevec, x->byteveclength, x->bytevecnb, out, temp);
 	int i;
  	
 	for(i=0; i < nLoc(x); i++){

Modified: pkg/src/snpbin.h
===================================================================
--- pkg/src/snpbin.h	2011-03-01 10:43:05 UTC (rev 828)
+++ pkg/src/snpbin.h	2011-03-01 11:12:30 UTC (rev 829)
@@ -60,8 +60,8 @@
    ===============================
 */
 
-void bytesToInt(unsigned char *vecbytes, int *veclength, int *nbvec, int *vecres, int reslength);
-void bytesToDouble(unsigned char *vecbytes, int *veclength, int *nbvec, double *vecres, int reslength);
+void bytesToInt(unsigned char *vecbytes, int *veclength, int *nbvec, int *vecres, int *reslength);
+void bytesToDouble(unsigned char *vecbytes, int *veclength, int *nbvec, double *vecres, int *reslength);
 void binIntToBytes(int *vecsnp, int *vecsize, unsigned char *vecres, int *ressize);
 
 



More information about the adegenet-commits mailing list