[Genabel-commits] r1186 - in pkg/GenABEL: . src/GAlib

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 4 13:37:27 CEST 2013


Author: yurii
Date: 2013-04-04 13:37:27 +0200 (Thu, 04 Apr 2013)
New Revision: 1186

Modified:
   pkg/GenABEL/CHANGES.LOG
   pkg/GenABEL/src/GAlib/export_plink.cpp
Log:
Fixing bug [#2525] Thanks to Vladimir Naumov for submitting the patch!

Modified: pkg/GenABEL/CHANGES.LOG
===================================================================
--- pkg/GenABEL/CHANGES.LOG	2013-04-04 11:08:52 UTC (rev 1185)
+++ pkg/GenABEL/CHANGES.LOG	2013-04-04 11:37:27 UTC (rev 1186)
@@ -1,6 +1,9 @@
 ***  v. 1.7-5
 
 (2013.04.04)
+Fixing bug [#2525] (http://r-forge.r-project.org/tracker/index.php?func=detail&aid=2525&group_id=505&atid=2058)
+Thanks to Vladimir Naumov for submitting the patch!
+
 Updated documentation files
  
 (2013.04.03) 

Modified: pkg/GenABEL/src/GAlib/export_plink.cpp
===================================================================
--- pkg/GenABEL/src/GAlib/export_plink.cpp	2013-04-04 11:08:52 UTC (rev 1185)
+++ pkg/GenABEL/src/GAlib/export_plink.cpp	2013-04-04 11:37:27 UTC (rev 1186)
@@ -20,14 +20,18 @@
 SEXP export_plink(SEXP Ids, SEXP Snpdata, SEXP Nsnps, SEXP NidsTotal, SEXP Coding, SEXP From, SEXP To,
 		SEXP Male, SEXP Traits, SEXP Pedfilename, SEXP Plink, SEXP Append)
 {
+
+	int from = INTEGER(From)[0];
+	int to = INTEGER(To)[0];
 	std::vector<unsigned short int> sex;
+	sex.clear();
 	unsigned short int sx;
-	for(unsigned int i=0;i<((unsigned int) length(Male));i++) {
+	for(unsigned int i=(from - 1);i<to;i++) {
 		sx = INTEGER(Male)[i];
 		if (sx==0) sx=2;
+		//Rprintf("%d %d\n",i,sx);
 		sex.push_back(sx);
 	}
-
 	std::vector<std::string> ids;
 	for(unsigned int i=0;i<((unsigned int) length(Ids));i++)
 		ids.push_back(CHAR(STRING_ELT(Ids,i)));
@@ -38,8 +42,6 @@
 
 	//Rprintf("0\n");
 	unsigned int nsnps = INTEGER(Nsnps)[0];
-	int from = INTEGER(From)[0];
-	int to = INTEGER(To)[0];
 	int nids = to - from + 1;
 	int nidsTotal = INTEGER(NidsTotal)[0];
 	int ntraits = INTEGER(Traits)[0];
@@ -55,6 +57,8 @@
 
 	//Rprintf("nsnps=%d\n",nsnps);
 	//Rprintf("nids=%d\n",nids);
+	//Rprintf("to=%d\n", to);
+	//Rprintf("from=%d\n", from);
 
 	//char gtMatrix[nids][nsnps];
 	char **gtMatrix = new (std::nothrow) char*[nids];
@@ -90,6 +94,7 @@
 	//Rprintf("B\n");
 	for (int i=0;i<nids;i++) {
 		fileWoA << i+from << " " << ids[i] << " 0 0 " << sex[i];
+
 		for (int j=0;j<ntraits;j++) fileWoA << " " << 0;
 		// unwrap genotypes
 		for (unsigned int csnp=0;csnp<nsnps;csnp++) {
@@ -108,6 +113,7 @@
 	//for (int i=0;i<10;i++) Rprintf("%d ",sex[i]);
 	//Rprintf("oooo!\n" );
 
+	sex.clear();
 	delete [] gtMatrix;
 	delete [] Genotype;
 	delete [] gtint;



More information about the Genabel-commits mailing list