[Genabel-commits] r748 - in pkg/GenABEL: . R inst/unitTests src/GAlib

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 7 14:30:56 CEST 2011


Author: yurii
Date: 2011-07-07 14:30:56 +0200 (Thu, 07 Jul 2011)
New Revision: 748

Added:
   pkg/GenABEL/inst/unitTests/runit.convert.snp.R
Modified:
   pkg/GenABEL/CHANGES.LOG
   pkg/GenABEL/NAMESPACE
   pkg/GenABEL/R/alleleID.R
   pkg/GenABEL/R/merge.snp.data.R
   pkg/GenABEL/R/ss.R
   pkg/GenABEL/inst/unitTests/report.html
   pkg/GenABEL/inst/unitTests/report.txt
   pkg/GenABEL/inst/unitTests/reportSummary.txt
   pkg/GenABEL/src/GAlib/convert_snp_illumina.cpp
   pkg/GenABEL/src/GAlib/convert_snp_merlin.cpp
   pkg/GenABEL/src/GAlib/convert_snp_merlin_wslash.cpp
   pkg/GenABEL/src/GAlib/convert_snp_tped.cpp
Log:
addressing monomorphics part 1

Modified: pkg/GenABEL/CHANGES.LOG
===================================================================
--- pkg/GenABEL/CHANGES.LOG	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/CHANGES.LOG	2011-07-07 12:30:56 UTC (rev 748)
@@ -1,5 +1,9 @@
-*** v. 1.6-8 (2011.05.18)
+*** v. 1.6-8 (2011.07.06)
 
+Added coding<- method to gwaa.data and snp.data classes
+
+Added monomorphic classes to 'snp.data' and convert.snp.*
+
 Updated 'polygenic' with use of 'polylik_eigen' developed by 
 Gulnara Svischeva. Now 'polygenic' works MUCH faster. The 
 main advantage of Gulnara's method is that time to compute 

Modified: pkg/GenABEL/NAMESPACE
===================================================================
--- pkg/GenABEL/NAMESPACE	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/NAMESPACE	2011-07-07 12:30:56 UTC (rev 748)
@@ -130,6 +130,7 @@
 	"annotation",
 	"chromosome",
 	"coding",
+	"coding<-",
 	"effallele",
 	"getcall",
 	"getfamily",

Modified: pkg/GenABEL/R/alleleID.R
===================================================================
--- pkg/GenABEL/R/alleleID.R	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/R/alleleID.R	2011-07-07 12:30:56 UTC (rev 748)
@@ -5,17 +5,24 @@
 	alleles <- c("A","T","G","C","-")
 	idx <- 3
 	for (i in alleles) {
-	for (j in alleles) {
-		if (i==j) next;
-		a[[idx]] <- c(i,j)
-		idx <- idx + 1
+		for (j in alleles) {
+			if (i==j) next;
+			a[[idx]] <- c(i,j)
+			idx <- idx + 1
+		}
 	}
-	}
 	a[[idx]] <- c("2","1")
 	idx <- idx + 1
 	a[[idx]] <- c("B","A")
+	idx <- idx + 1
+	allalleles <- c("1","2","B","A","T","G","C","-")
+	for (jj in allalleles) {
+		a[[idx]] <- c(jj,jj)
+		idx <- idx + 1
+	}
 	a
 }
+
 alleleID.codes <- function() {
 	a <- alleleID.alleles()
 	out <- c("OPPA")

Modified: pkg/GenABEL/R/merge.snp.data.R
===================================================================
--- pkg/GenABEL/R/merge.snp.data.R	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/R/merge.snp.data.R	2011-07-07 12:30:56 UTC (rev 748)
@@ -197,6 +197,11 @@
 #-------------------------------------------------------------------
 
 
+# deal with monomorphics
+#cdng_x <- coding(x)
+#cdng_y <- coding(y)
+#mono_x <- alleleID.ismono(cdng_x)
+#mono_y <- alleleID.ismono(cdng_y)
 
 
 return_val <-  .C("fast_merge_C_",

Modified: pkg/GenABEL/R/ss.R
===================================================================
--- pkg/GenABEL/R/ss.R	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/R/ss.R	2011-07-07 12:30:56 UTC (rev 748)
@@ -1,4 +1,3 @@
-#
 #defining snp.mx -- internal class
 #
 #setClass("genotype",contains="data.frame",package="GenABEL")
@@ -15,7 +14,6 @@
 			x <- x at .Data[k, j , drop = FALSE]
 			if (missing(i)) i=c(1:(nrow(x)*4));
 			if (is.logical(i)) i=which(i)
-			x <- sset(as.raw(x),length(j),nrow(x)*4,i)
 			dim(x) <- c(ceiling(length(i)/4),length(j))
 			if (is.matrix(x)) 
 				x <- new("snp.mx",x) 
@@ -688,7 +686,39 @@
 		}
 );
 
+# AAAA
+setGeneric(
+		name = "coding<-",
+		def = function(x,value) {standardGeneric("coding<-");}
+);
+setMethod(
+		f = "coding<-",
+		signature = "snp.data",
+		definition = function(x,value) 
+		{
+			rawVal <- as.raw(alleleID.char2raw()[value])
+			x at coding <- new("snp.coding",rawVal)
+			names(x at coding) <- x at snpnames
+			if (any(is.na(coding(x)))) {
+				cat("wrong coding value, should be one of ")
+				cat(names(alleleID.char2raw()),"\n")
+				stop()
+			}
+			return(x)
+		}
+);
+setMethod(
+		f = "coding<-",
+		signature = "gwaa.data",
+		definition = function(x,value) 
+		{
+			coding(x at gtdata) <- value
+			return(x)
+		}
+);
 
+
+
 setGeneric(
 		name = "refallele",
 		def = function(object) {standardGeneric("refallele");}

Modified: pkg/GenABEL/inst/unitTests/report.html
===================================================================
--- pkg/GenABEL/inst/unitTests/report.html	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/inst/unitTests/report.html	2011-07-07 12:30:56 UTC (rev 748)
@@ -1,9 +1,9 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/transitional.dtd">
-<html><head><title>RUNIT TEST PROTOCOL--Tue May 17 20:27:16 2011</title>
+<html><head><title>RUNIT TEST PROTOCOL--Wed Jul  6 23:29:32 2011</title>
 </head>
-<body><h1 TRUE>RUNIT TEST PROTOCOL--Tue May 17 20:27:16 2011</h1>
-<p>Number of test functions: 9</p>
+<body><h1 TRUE>RUNIT TEST PROTOCOL--Wed Jul  6 23:29:32 2011</h1>
+<p>Number of test functions: 10</p>
 <p>Number of errors: 0</p>
 <p>Number of failures: 0</p>
 <hr>
@@ -15,7 +15,7 @@
 <th width="20%">Failures</th>
 </tr>
 <tr><td><a href="#GenABEL unit testing">GenABEL unit testing</a></td>
-<td>9</td>
+<td>10</td>
 <td>0</td>
 <td>0</td>
 </tr>
@@ -23,22 +23,22 @@
 <hr>
 <h3 TRUE>Details</h3>
 <p><a name="GenABEL unit testing"><h5 TRUE>Test Suite: GenABEL unit testing</h5>
-</a>Test function regexp: ^test.+<br/>Test file regexp: ^runit.+\.[rR]$<br/>Involved directory:<br/>/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests<br/><ul><li><a href="/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.convert.snp.ped.R">Test file: runit.convert.snp.ped.R</a><ul><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.convert.snp.ped.R_test.convert.snp.ped">test.convert.snp.ped: (0 checks) ... OK (0.02 seconds)<br/></a></li></ul></li><li><a href="/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.descriptives.trait.R">Test file: runit.descriptives.trait.R</a><ul><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.descriptives.trait.R_test.descriptives.trait">test.descriptives.trait: (1 checks) ... OK (0.76 seconds)<br/></a></li></ul></li><li><a href="/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.findRelatives.R">Test file: runit.findRelatives.R</a><ul><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.findRelatives.R_test.findRelatives">test.findRelatives: (10 checks) ... OK (106.44 seconds)<br/></a></li></ul></li><li><a href="/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.impute2xxx.R">Test file: runit.impute2xxx.R</a><ul><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.impute2xxx.R_test.impute2databel">test.impute2databel: (23 checks) ... OK (0.74 seconds)<br/></a></li></ul></li><li><a href="/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.impute2xxx_large.R">Test file: runit.impute2xxx_large.R</a><ul><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.impute2xxx_large.R_test.impute2xxx_large">test.impute2xxx_large: (0 checks) ... OK (0 seconds)<br/></a></li></ul></li><li><a href="/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.iterator.R">Test file: runit.iterator.R</a><ul><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.iterator.R_test.qtscore">test.qtscore: (0 checks) ... OK (0 seconds)<br/></a></li><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.iterator.R_test.summary_snp_data">test.summary_snp_data: (3 checks) ... OK (8.06 seconds)<br/></a></li></ul></li><li><a href="/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.mach2databel.R">Test file: runit.mach2databel.R</a><ul><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.mach2databel.R_test.mach2databel">test.mach2databel: (8 checks) ... OK (0.25 seconds)<br/></a></li></ul></li><li><a href="/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.polylik.R">Test file: runit.polylik.R</a><ul><li><a name="GenABEL unit testing__Users_yuriiaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.polylik.R_test.polylik">test.polylik: (6 checks) ... OK (15.03 seconds)<br/></a></li></ul></li></ul><hr>
+</a>Test function regexp: ^test.+<br/>Test file regexp: ^runit.+\.[rR]$<br/>Involved directory:<br/>/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests<br/><ul><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.convert.snp.ped.R">Test file: runit.convert.snp.ped.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.convert.snp.ped.R_test.convert.snp.ped">test.convert.snp.ped: (0 checks) ... OK (0.07 seconds)<br/></a></li></ul></li><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.convert.snp.tped.R">Test file: runit.convert.snp.tped.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.convert.snp.tped.R_test.convert.snp">test.convert.snp: (0 checks) ... OK (0.71 seconds)<br/></a></li></ul></li><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.descriptives.trait.R">Test file: runit.descriptives.trait.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.descriptives.trait.R_test.descriptives.trait">test.descriptives.trait: (1 checks) ... OK (0.41 seconds)<br/></a></li></ul></li><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.findRelatives.R">Test file: runit.findRelatives.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.findRelatives.R_test.findRelatives">test.findRelatives: (10 checks) ... OK (55.68 seconds)<br/></a></li></ul></li><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.impute2xxx.R">Test file: runit.impute2xxx.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.impute2xxx.R_test.impute2databel">test.impute2databel: (23 checks) ... OK (0.82 seconds)<br/></a></li></ul></li><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.impute2xxx_large.R">Test file: runit.impute2xxx_large.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.impute2xxx_large.R_test.impute2xxx_large">test.impute2xxx_large: (0 checks) ... OK (0 seconds)<br/></a></li></ul></li><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.iterator.R">Test file: runit.iterator.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.iterator.R_test.qtscore">test.qtscore: (0 checks) ... OK (0 seconds)<br/></a></li><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.iterator.R_test.summary_snp_data">test.summary_snp_data: (3 checks) ... OK (5.19 seconds)<br/></a></li></ul></li><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.mach2databel.R">Test file: runit.mach2databel.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.mach2databel.R_test.mach2databel">test.mach2databel: (8 checks) ... OK (0.15 seconds)<br/></a></li></ul></li><li><a href="/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.polylik.R">Test file: runit.polylik.R</a><ul><li><a name="GenABEL unit testing__Users_yuryaulchenko_eclipse_workspace_genabel_pkg_GenABEL_tests_.._inst_unitTests_runit.polylik.R_test.polylik">test.polylik: (6 checks) ... OK (7.97 seconds)<br/></a></li></ul></li></ul><hr>
 <table border="0" width="80%" >
 <tr><th>Name</th>
 <th>Value</th>
 </tr>
 <tr><td>platform</td>
-<td>i386-apple-darwin9.8.0</td>
+<td>x86_64-apple-darwin9.8.0</td>
 </tr>
 <tr><td>arch</td>
-<td>i386</td>
+<td>x86_64</td>
 </tr>
 <tr><td>os</td>
 <td>darwin9.8.0</td>
 </tr>
 <tr><td>system</td>
-<td>i386, darwin9.8.0</td>
+<td>x86_64, darwin9.8.0</td>
 </tr>
 <tr><td>status</td>
 <td>Under development (unstable)</td>
@@ -53,25 +53,25 @@
 <td>2011</td>
 </tr>
 <tr><td>month</td>
-<td>05</td>
+<td>06</td>
 </tr>
 <tr><td>day</td>
-<td>16</td>
+<td>30</td>
 </tr>
 <tr><td>svn rev</td>
-<td>55928</td>
+<td>56238</td>
 </tr>
 <tr><td>language</td>
 <td>R</td>
 </tr>
 <tr><td>version.string</td>
-<td>R version 2.14.0 Under development (unstable) (2011-05-16 r55928)</td>
+<td>R version 2.14.0 Under development (unstable) (2011-06-30 r56238)</td>
 </tr>
 <tr><td>host</td>
-<td>yurii-aulchenkos-macbook-2.local</td>
+<td>Yury-Aulchenkos-MacBook-Pro.local</td>
 </tr>
 <tr><td>compiler</td>
-<td>g++</td>
+<td>NA</td>
 </tr>
 </table>
 </body>

Modified: pkg/GenABEL/inst/unitTests/report.txt
===================================================================
--- pkg/GenABEL/inst/unitTests/report.txt	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/inst/unitTests/report.txt	2011-07-07 12:30:56 UTC (rev 748)
@@ -1,12 +1,12 @@
-RUNIT TEST PROTOCOL -- Tue May 17 20:27:16 2011 
+RUNIT TEST PROTOCOL -- Wed Jul  6 23:29:31 2011 
 *********************************************** 
-Number of test functions: 9 
+Number of test functions: 10 
 Number of errors: 0 
 Number of failures: 0 
 
  
 1 Test Suite : 
-GenABEL unit testing - 9 test functions, 0 errors, 0 failures
+GenABEL unit testing - 10 test functions, 0 errors, 0 failures
 
 
 
@@ -16,29 +16,32 @@
 Test function regexp: ^test.+ 
 Test file regexp: ^runit.+\.[rR]$ 
 Involved directory: 
-/Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests 
+/Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests 
 --------------------------- 
-Test file: /Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.convert.snp.ped.R 
-test.convert.snp.ped: (0 checks) ... OK (0.02 seconds)
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.convert.snp.ped.R 
+test.convert.snp.ped: (0 checks) ... OK (0.07 seconds)
 --------------------------- 
-Test file: /Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.descriptives.trait.R 
-test.descriptives.trait: (1 checks) ... OK (0.76 seconds)
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.convert.snp.tped.R 
+test.convert.snp: (0 checks) ... OK (0.71 seconds)
 --------------------------- 
-Test file: /Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.findRelatives.R 
-test.findRelatives: (10 checks) ... OK (106.44 seconds)
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.descriptives.trait.R 
+test.descriptives.trait: (1 checks) ... OK (0.41 seconds)
 --------------------------- 
-Test file: /Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.impute2xxx.R 
-test.impute2databel: (23 checks) ... OK (0.74 seconds)
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.findRelatives.R 
+test.findRelatives: (10 checks) ... OK (55.68 seconds)
 --------------------------- 
-Test file: /Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.impute2xxx_large.R 
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.impute2xxx.R 
+test.impute2databel: (23 checks) ... OK (0.82 seconds)
+--------------------------- 
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.impute2xxx_large.R 
 test.impute2xxx_large: (0 checks) ... OK (0 seconds)
 --------------------------- 
-Test file: /Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.iterator.R 
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.iterator.R 
 test.qtscore: (0 checks) ... OK (0 seconds)
-test.summary_snp_data: (3 checks) ... OK (8.06 seconds)
+test.summary_snp_data: (3 checks) ... OK (5.19 seconds)
 --------------------------- 
-Test file: /Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.mach2databel.R 
-test.mach2databel: (8 checks) ... OK (0.25 seconds)
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.mach2databel.R 
+test.mach2databel: (8 checks) ... OK (0.15 seconds)
 --------------------------- 
-Test file: /Users/yuriiaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.polylik.R 
-test.polylik: (6 checks) ... OK (15.03 seconds)
+Test file: /Users/yuryaulchenko/eclipse_workspace/genabel/pkg/GenABEL/tests/../inst/unitTests/runit.polylik.R 
+test.polylik: (6 checks) ... OK (7.97 seconds)

Modified: pkg/GenABEL/inst/unitTests/reportSummary.txt
===================================================================
--- pkg/GenABEL/inst/unitTests/reportSummary.txt	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/inst/unitTests/reportSummary.txt	2011-07-07 12:30:56 UTC (rev 748)
@@ -1,9 +1,9 @@
-RUNIT TEST PROTOCOL -- Tue May 17 20:27:16 2011 
+RUNIT TEST PROTOCOL -- Wed Jul  6 23:29:31 2011 
 *********************************************** 
-Number of test functions: 9 
+Number of test functions: 10 
 Number of errors: 0 
 Number of failures: 0 
 
  
 1 Test Suite : 
-GenABEL unit testing - 9 test functions, 0 errors, 0 failures
+GenABEL unit testing - 10 test functions, 0 errors, 0 failures

Added: pkg/GenABEL/inst/unitTests/runit.convert.snp.R
===================================================================
--- pkg/GenABEL/inst/unitTests/runit.convert.snp.R	                        (rev 0)
+++ pkg/GenABEL/inst/unitTests/runit.convert.snp.R	2011-07-07 12:30:56 UTC (rev 748)
@@ -0,0 +1,58 @@
+### --- Test setup ---
+#
+# regression test
+#
+
+if(FALSE) {
+	## Not really needed, but can be handy when writing tests
+	library(RUnit)
+	library(GenABEL)
+}
+
+### do not run
+#stop("SKIP THIS TEST")
+###
+
+### ---- common functions and data -----
+
+#source(paste("../inst/unitTests/shared_functions.R"))
+#source(paste(path,"/shared_functions.R",sep=""))
+
+### --- Test functions ---
+
+test.convert.snp <- function()
+{
+	library(GenABEL)
+	convert.snp.tped(tped="gatest.tped", tfam="gatest.tfam", out="gatest.raw", strand="+")
+	data <- load.gwaa.data(gen="gatest.raw", phe="gatest.phe")
+	data
+	coding(data)
+	as.character(data)
+	as.numeric(data)
+	convert.snp.tped(tped="gatest1.tped", tfam="gatest1.tfam", out="gatest1.raw", strand="+")
+	data1 <- load.gwaa.data(gen="gatest1.raw", phe="gatest1.phe")
+	data1
+	coding(data1)
+	as.character(data1)
+	as.numeric(data1)
+	mrg <- merge(gtdata(data),gtdata(data1))
+	mrg
+	coding(mrg$data)
+	as.character(mrg$data)
+	as.numeric(mrg$data)
+	
+	coding(data)
+	class(data)
+	coding(data) <- coding(data1)
+	class(data)
+	coding(data)
+	coding(data1)
+	as.character(data)
+	as.character(data1)
+	mrg <- merge(gtdata(data),gtdata(data1))
+	mrg
+	coding(mrg$data)
+	as.character(mrg$data)
+	as.numeric(mrg$data)
+	unlink("*.raw")
+}
\ No newline at end of file


Property changes on: pkg/GenABEL/inst/unitTests/runit.convert.snp.R
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: pkg/GenABEL/src/GAlib/convert_snp_illumina.cpp
===================================================================
--- pkg/GenABEL/src/GAlib/convert_snp_illumina.cpp	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/src/GAlib/convert_snp_illumina.cpp	2011-07-07 12:30:56 UTC (rev 748)
@@ -170,10 +170,15 @@
 	      }
 	    }
 
-	if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
-	else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
+	if (!allele1 && !allele2) tmp_coding="12"; // all genotypes missing
+	else if (!allele1 && allele2) sprintf(tmp_chcoding,"%c%c",allele2,allele2); // only one allele present
+	else if (allele1 && !allele2) sprintf(tmp_chcoding,"%c%c",allele1,allele1); // only one allele present
+	else if (allele1 && allele2) {
+		if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
+		else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
+	}
+	Rprintf("%s\n",tmp_chcoding);
 	tmp_coding.assign(tmp_chcoding);
-	if (!allele1 || !allele2) tmp_coding="12";
 	int ccd = -1;
 	for (int i = 0; i < ncodes; i++) {
 		if (codeset[i].compare(tmp_coding)==0) {

Modified: pkg/GenABEL/src/GAlib/convert_snp_merlin.cpp
===================================================================
--- pkg/GenABEL/src/GAlib/convert_snp_merlin.cpp	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/src/GAlib/convert_snp_merlin.cpp	2011-07-07 12:30:56 UTC (rev 748)
@@ -298,14 +298,15 @@
 	}
 
 //    if (strandid!=3) {
-	if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
-	else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
+	if (!allele1 && !allele2) tmp_coding="12"; // all genotypes missing
+	else if (!allele1 && allele2) sprintf(tmp_chcoding,"%c%c",allele2,allele2); // only one allele present
+	else if (allele1 && !allele2) sprintf(tmp_chcoding,"%c%c",allele1,allele1); // only one allele present
+	else if (allele1 && allele2) {
+		if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
+		else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
+	}
+	Rprintf("%s\n",tmp_chcoding);
 	tmp_coding.assign(tmp_chcoding);
-	if (!allele1 || !allele2) tmp_coding="12";
-	coding.push_back(tmp_coding);
-//    }
-
-//    	if (strandid==3) tmp_coding = coding[snp];
 	int ccd = -1;
 	for (int i = 0; i < ncodes; i++) {
 		if (codeset[i].compare(tmp_coding)==0) {

Modified: pkg/GenABEL/src/GAlib/convert_snp_merlin_wslash.cpp
===================================================================
--- pkg/GenABEL/src/GAlib/convert_snp_merlin_wslash.cpp	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/src/GAlib/convert_snp_merlin_wslash.cpp	2011-07-07 12:30:56 UTC (rev 748)
@@ -310,14 +310,15 @@
 	}
 
 //    if (strandid!=3) {
-	if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
-	else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
+	if (!allele1 && !allele2) tmp_coding="12"; // all genotypes missing
+	else if (!allele1 && allele2) sprintf(tmp_chcoding,"%c%c",allele2,allele2); // only one allele present
+	else if (allele1 && !allele2) sprintf(tmp_chcoding,"%c%c",allele1,allele1); // only one allele present
+	else if (allele1 && allele2) {
+		if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
+		else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
+	}
+	Rprintf("%s\n",tmp_chcoding);
 	tmp_coding.assign(tmp_chcoding);
-	if (!allele1 || !allele2) tmp_coding="12";
-	coding.push_back(tmp_coding);
-//    }
-
-//    	if (strandid==3) tmp_coding = coding[snp];
 	int ccd = -1;
 	for (int i = 0; i < ncodes; i++) {
 		if (codeset[i].compare(tmp_coding)==0) {

Modified: pkg/GenABEL/src/GAlib/convert_snp_tped.cpp
===================================================================
--- pkg/GenABEL/src/GAlib/convert_snp_tped.cpp	2011-07-06 09:42:07 UTC (rev 747)
+++ pkg/GenABEL/src/GAlib/convert_snp_tped.cpp	2011-07-07 12:30:56 UTC (rev 748)
@@ -30,270 +30,278 @@
 
 
 extern "C" {
-  void convert_snp_tped (char** tpedfilename, char** tfamfilename, char** outfilename, int* Strandid, int* bcast, char **allele_codes, int* Ncodes) {
+void convert_snp_tped (char** tpedfilename, char** tfamfilename, char** outfilename, int* Strandid, int* bcast, char **allele_codes, int* Ncodes) {
 
-  short unsigned int ncodes = *Ncodes;
-  short unsigned int strandid = *Strandid;
+	short unsigned int ncodes = *Ncodes;
+	short unsigned int strandid = *Strandid;
 
-    int verbose = *bcast ? 1 : 0;
+	int verbose = *bcast ? 1 : 0;
 
-    long int linecount = 0;
-    string data;
-    string token;
-    
-    vector<string> iid; string tmp_iid;
-    vector<string> chrom; string tmp_chrom;
-    vector<string> snpnm; string tmp_snpnm;
-    vector<double> genmap; double tmp_genmap;
-    vector<unsigned long> phymap; unsigned long tmp_phymap;
-    vector<unsigned char*> gtype; unsigned char* tmp_gtype;
-  vector<string> coding; string tmp_coding,tmp_coding1;
-  vector<unsigned short int> intcoding;
-  vector<unsigned short int> strand; string tmp_strand;
-  vector<string> codeset(ncodes); 
-  char tmp_chcoding [10];
+	long int linecount = 0;
+	string data;
+	string token;
 
-  for (int i=0;i<ncodes;i++) codeset[i].assign(allele_codes[i]);
+	vector<string> iid; string tmp_iid;
+	vector<string> chrom; string tmp_chrom;
+	vector<string> snpnm; string tmp_snpnm;
+	vector<double> genmap; double tmp_genmap;
+	vector<unsigned long> phymap; unsigned long tmp_phymap;
+	vector<unsigned char*> gtype; unsigned char* tmp_gtype;
+	vector<string> coding; string tmp_coding,tmp_coding1;
+	vector<unsigned short int> intcoding;
+	vector<unsigned short int> strand; string tmp_strand;
+	vector<string> codeset(ncodes);
+	char tmp_chcoding [10];
 
-    ///////////////////////
-    // read the tfamfile //
-    ///////////////////////
+	for (int i=0;i<ncodes;i++) codeset[i].assign(allele_codes[i]);
 
-    ifstream tfamfile (tfamfilename[0]);
-    if (tfamfile == NULL) {
-      error ("could not open file '%s' !",tfamfilename[0]);
-    }
+	///////////////////////
+	// read the tfamfile //
+	///////////////////////
 
-    if (verbose) {
-      Rprintf("Reading individual ids from file '%s' ...\n",tfamfilename[0]);
-    }    
+	ifstream tfamfile (tfamfilename[0]);
+	if (tfamfile == NULL) {
+		error ("could not open file '%s' !",tfamfilename[0]);
+	}
 
-    while (getline(tfamfile,data)) {
-      istringstream datas (data);
-      if ( datas >> token >> tmp_iid) {
-	iid.push_back(tmp_iid);
-      }
-    }
+	if (verbose) {
+		Rprintf("Reading individual ids from file '%s' ...\n",tfamfilename[0]);
+	}
 
-    tfamfile.close();
+	while (getline(tfamfile,data)) {
+		istringstream datas (data);
+		if ( datas >> token >> tmp_iid) {
+			iid.push_back(tmp_iid);
+		}
+	}
 
-    int nids = iid.size();
-    int nbytes = (int)ceil((double)nids/4.);
+	tfamfile.close();
 
-    if (verbose) {
-      Rprintf("... done.  Read %i individual ids from file '%s'\n",nids,tfamfilename[0]);
-    }
+	int nids = iid.size();
+	int nbytes = (int)ceil((double)nids/4.);
 
-    ///////////////////////
-    // read the tpedfile //
-    ///////////////////////
+	if (verbose) {
+		Rprintf("... done.  Read %i individual ids from file '%s'\n",nids,tfamfilename[0]);
+	}
 
-    int idx;
-    char gdata;
-    int* gnum = new int [nids*2];
+	///////////////////////
+	// read the tpedfile //
+	///////////////////////
 
-    int byte;
-    int ind;
-    int offset[4] = {6,4,2,0};
+	int idx;
+	char gdata;
+	int* gnum = new int [nids*2];
 
+	int byte;
+	int ind;
+	int offset[4] = {6,4,2,0};
 
-    ifstream tpedfile (tpedfilename[0]);
-    if (tpedfile == NULL) {
-      error ("could not open file '%s' !",tpedfilename[0]);
-    }
 
-    if (verbose) {
-      Rprintf("Reading genotypes from file '%s' ...\n",tpedfilename[0]);
-    }    
-    
-    linecount = 0;
-    while (getline(tpedfile,data)) {
-      ++linecount;
+	ifstream tpedfile (tpedfilename[0]);
+	if (tpedfile == NULL) {
+		error ("could not open file '%s' !",tpedfilename[0]);
+	}
 
-      istringstream datas (data);
+	if (verbose) {
+		Rprintf("Reading genotypes from file '%s' ...\n",tpedfilename[0]);
+	}
 
-      if (datas >> tmp_chrom >> tmp_snpnm >> tmp_genmap >> tmp_phymap) {
-	chrom.push_back(tmp_chrom);
-	snpnm.push_back(tmp_snpnm);
-	genmap.push_back(tmp_genmap);
-	phymap.push_back(tmp_phymap);
-        strand.push_back(strandid);
+	linecount = 0;
+	while (getline(tpedfile,data)) {
+		++linecount;
 
-	char allele1 = 0;
-	char allele2 = 0;
-  unsigned long int ca1 = 0;
-  unsigned long int ca2 = 0;
+		istringstream datas (data);
 
-	for (idx = 0; idx < 2*nids; ++idx) {
-	  if (datas >> gdata) {
+		if (datas >> tmp_chrom >> tmp_snpnm >> tmp_genmap >> tmp_phymap) {
+			chrom.push_back(tmp_chrom);
+			snpnm.push_back(tmp_snpnm);
+			genmap.push_back(tmp_genmap);
+			phymap.push_back(tmp_phymap);
+			strand.push_back(strandid);
 
-	    if (gdata == allele1) {
-	      gnum[idx] = 1;
-		ca1++;
-	    } else if (gdata == allele2) {
-	      gnum[idx] = 3;
-		ca2++;
-	    } else if (gdata == '0') {
-	      gnum[idx] = 0;
-	    } else {
-	      if (allele1 == 0) {
-		allele1 = gdata;
-		gnum[idx] = 1;
-	      } else if (allele2 == 0) {
-		allele2 = gdata;
-		gnum[idx] = 3;
-	      } else {
-		error ("illegal genotype (three alleles) snp '%s' file '%s' line %li !",
-		       tmp_snpnm.c_str(),tpedfilename[0],linecount);
-	      }
-	    }
+			char allele1 = 0;
+			char allele2 = 0;
+			unsigned long int ca1 = 0;
+			unsigned long int ca2 = 0;
 
-	  } else {
-	    error ("not enough genotypes for snp '%s' file '%s' line %li !",
-		     tmp_snpnm.c_str(),tpedfilename[0],linecount);
-	  }
-	}
+			for (idx = 0; idx < 2*nids; ++idx) {
+				if (datas >> gdata) {
 
+					if (gdata == allele1) {
+						gnum[idx] = 1;
+						ca1++;
+					} else if (gdata == allele2) {
+						gnum[idx] = 3;
+						ca2++;
+					} else if (gdata == '0') {
+						gnum[idx] = 0;
+					} else {
+						if (allele1 == 0) {
+							allele1 = gdata;
+							gnum[idx] = 1;
+						} else if (allele2 == 0) {
+							allele2 = gdata;
+							gnum[idx] = 3;
+						} else {
+							error ("illegal genotype (three alleles) snp '%s' file '%s' line %li !",
+									tmp_snpnm.c_str(),tpedfilename[0],linecount);
+						}
+					}
 
-	if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
-	else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
-	tmp_coding.assign(tmp_chcoding);
-	if (!allele1 || !allele2) tmp_coding="12";
-	int ccd = -1;
-	for (int i = 0; i < ncodes; i++) {
-		if (codeset[i].compare(tmp_coding)==0) {
-			ccd = i + 1;
-			intcoding.push_back(ccd);
+				} else {
+					error ("not enough genotypes for snp '%s' file '%s' line %li !",
+							tmp_snpnm.c_str(),tpedfilename[0],linecount);
+				}
+			}
+
+
+			//	if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
+			//	else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
+			if (!allele1 && !allele2) tmp_coding="12"; // all genotypes missing
+			else if (!allele1 && allele2) sprintf(tmp_chcoding,"%c%c",allele2,allele2); // only one allele present
+			else if (allele1 && !allele2) sprintf(tmp_chcoding,"%c%c",allele1,allele1); // only one allele present
+			else if (allele1 && allele2) {
+				if (ca1 > ca2) sprintf(tmp_chcoding,"%c%c",allele1,allele2);
+				else sprintf(tmp_chcoding,"%c%c",allele2,allele1);
+			}
+			Rprintf("%s\n",tmp_chcoding);
+			tmp_coding.assign(tmp_chcoding);
+			//	if (!allele1 || !allele2) tmp_coding="12";
+			int ccd = -1;
+			for (int i = 0; i < ncodes; i++) {
+				if (codeset[i].compare(tmp_coding)==0) {
+					ccd = i + 1;
+					intcoding.push_back(ccd);
+				}
+			}
+			if (ccd<0) error ("coding '%s' for SNP not recognised !\n",tmp_coding.c_str());
+			try {
+				tmp_gtype = new unsigned char [nbytes];
+			}
+			catch (bad_alloc) {
+				error ("ran out of memory reading file '%s' line %li !");
+			}
+			if (tmp_gtype == NULL) {
+				error ("ran out of memory reading file '%s' line %li !");
+			}
+
+			idx = 0;
+			for (byte = 0; byte < nbytes; ++byte) {
+
+				tmp_gtype[byte] = 0;
+				for (ind = 0; ind < 4; ++ind) {
+
+					switch (gnum[idx]+gnum[idx+1]) {
+					case 2:
+						if (ca1 > ca2)
+							tmp_gtype[byte] = tmp_gtype[byte] | ((unsigned char)1 << offset[ind]);
+						else
+							tmp_gtype[byte] = tmp_gtype[byte] | ((unsigned char)3 << offset[ind]);
+						break;
+					case 4:
+						tmp_gtype[byte] = tmp_gtype[byte] | ((unsigned char)2 << offset[ind]);
+						break;
+					case 6:
+						if (ca1 > ca2)
+							tmp_gtype[byte] = tmp_gtype[byte] | ((unsigned char)3 << offset[ind]);
+						else
+							tmp_gtype[byte] = tmp_gtype[byte] | ((unsigned char)1 << offset[ind]);
+						break;
+					case 0:
+						tmp_gtype[byte] = tmp_gtype[byte] | (0 << offset[ind]); // this does nothing
+						break;
+					default:
+						error ("illegal genotype (half missing) SNP '%s' file '%s' line %li !",
+								snpnm[linecount-1].c_str(),tpedfilename[0],(linecount-1));
+					}
+					idx += 2;
+					if (idx >= 2*nids) break;
+				}
+			}
+
+			gtype.push_back(tmp_gtype);
+
+			if (verbose && linecount % *bcast == 0) {
+				Rprintf("  ... read %li lines ...\n",linecount);
+			}
+
+		} else {
+			// not even four fields on the line; raise error?
 		}
+
 	}
-	if (ccd<0) error ("coding '%s' for SNP not recognised !\n",tmp_coding.c_str());
-	try {
-	  tmp_gtype = new unsigned char [nbytes];
-	}
-	catch (bad_alloc) {
-	  error ("ran out of memory reading file '%s' line %li !");
-	}
-	if (tmp_gtype == NULL) {
-	  error ("ran out of memory reading file '%s' line %li !");
-	}
-	
-	idx = 0;
-	for (byte = 0; byte < nbytes; ++byte) {
 
-	  tmp_gtype[byte] = 0;
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/genabel -r 748


More information about the Genabel-commits mailing list