This file is indexed.

/usr/lib/R/site-library/GenABEL/unitTests/runit.impute2xxx.R is in r-cran-genabel 1.7-6-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
### --- Test setup ---

if(FALSE) {
	## Not really needed, but can be handy when writing tests
	library("RUnit")
	library("GenABEL")
	library("DatABEL")
}

### 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.impute2databel <- function()
{
	
	#library(GenABEL)
	#library("RUnit")
	unlink("*.fv?")
	
	makedose <- function(prob) {
		dose <- 2*prob[c(F,F,T)]+prob[c(F,T,F)]
		bp <- prob[c(T,F,F)]
		miss <- which((bp+dose)<0.9)
		if (length(miss) > 0 ) dose[miss] <- NA
		return(dose)
	}
	makeprob <- function(prob) {
		dose2 <- prob[c(F,F,T)]
		dose1 <- prob[c(F,T,F)]
		bp <- prob[c(T,F,F)]
		miss <- which((bp+dose1+dose2)<0.9)
		out <- matrix(c(dose2,dose1),ncol=2)
		if (length(miss) > 0 ) out[miss,] <- NA
		out
	}
	
	
	tmp0 <- read.table("TEST10x15.geno",head=F,strings=F)
	snps <- tmp0[,2]
	tmp0 <- tmp0[,c(6:dim(tmp0)[2])]
	dose <- apply(tmp0,FUN="makedose",MAR=1)
	rownames(dose)
	prb <- makeprob(tmp0[1,])
	for (i in 2:dim(tmp0)[1])
		prb <- cbind(prb,makeprob(tmp0[i,]))
	dm <- dim(prb)
	prb <- as.numeric(prb)
	prb <- matrix(prb,ncol=dm[2])
	
	tmp1 <- impute2databel(geno="TEST10x15.geno",
			sample="impute.sample5",
			out="TEST10x15_T.geno",
			makeprob=FALSE,
			old=TRUE)
	tmp1
	tmp1_m <- as(tmp1,"matrix")
	tmp1_m
	
	
	print(tmp0[1:5,1:6])
	tmp2 <- impute2databel(geno="TEST10x15.geno",
			sample="impute.sample5",
			out="TEST10x15_F.geno",
			makeprob=TRUE,
			old=FALSE)
	print(tmp2)
	tmp2_m <- as(tmp2,"matrix")
	
	
	tmp3 <- databel("TEST10x15_F.geno.prob")
	tmp3_m <- as(tmp3,"matrix")
	
	checkIdentical(TRUE,all(abs(dose-tmp1_m)<1e-7,na.rm=TRUE))
	checkIdentical(TRUE,all(abs(dose-tmp2_m)<1e-7,na.rm=TRUE))
	checkIdentical(TRUE,all(abs(prb-tmp3_m)<1e-7,na.rm=TRUE))
	checkIdentical(TRUE,all(abs(tmp1_m-tmp2_m)<1e-8,na.rm=TRUE))
	checkEqualsNumeric(dose,tmp1_m,checkNames=FALSE,tolerance = 5*(.Machine$double.eps^0.5))
	checkEqualsNumeric(dose,tmp2_m,checkNames=FALSE,tolerance = 5*(.Machine$double.eps^0.5))
	checkEqualsNumeric(prb,tmp3_m,checkNames=FALSE,tolerance = 5*(.Machine$double.eps^0.5))
	checkIdentical(tmp1_m,tmp2_m)
	checkEqualsNumeric(tmp1_m,tmp2_m)
	
	smpl <- read.table("impute.sample5",head=F,skip=2,strings=F)[,1]
	rownames(dose) <- smpl
	rownames(prb) <- smpl
	
	checkEquals(dose,tmp1_m,tolerance=4*sqrt(.Machine$double.eps))
	checkEquals(dose,tmp2_m,tolerance=4*sqrt(.Machine$double.eps))
	checkEquals(prb,tmp3_m,tolerance=4*sqrt(.Machine$double.eps))
	checkIdentical(tmp1_m,tmp2_m)
	checkEqualsNumeric(tmp1_m,tmp2_m)
	checkIdentical(rownames(tmp1),smpl)
	checkIdentical(rownames(tmp2),smpl)
	checkIdentical(rownames(tmp3),smpl)
	checkIdentical(dimnames(tmp1),dimnames(tmp1_m))
	checkIdentical(dimnames(tmp2),dimnames(tmp2_m))
	checkIdentical(dimnames(tmp3),dimnames(tmp3_m))
	checkIdentical(get_dimnames(tmp1),list(smpl,snps))
	checkIdentical(get_dimnames(tmp2),list(smpl,snps))
	snps2 <- rep(0,2*length(snps))
	snps2[c(T,F)] <- paste(snps,"_11",sep="")
	snps2[c(F,T)] <- paste(snps,"_01",sep="")
	checkIdentical(get_dimnames(tmp3),list(smpl,snps2))
	
	rm(list=ls());gc()
	
	unlink("*.fv?")
	
}

# fixing CRAN NOTE
#
test.SNPquoted <- function() {	
	#library("RUnit")
	#library("GenABEL")
	require(DatABEL)
# generate some random data in "prob" format
	Nids <- 10
	Nsnps <- 3
	q <- runif(Nsnps,min=0.2,max=0.8)
	PROB0 <- apply(matrix(q,ncol=1),MARGIN=1,FUN=function(x){
				cBB <- rnorm(Nids,mean=x^2,sd=0.01)
				cAB <- rnorm(Nids,mean=2*x*(1-x),sd=0.01)
				cAA <- 1-cBB-cAB
				cAA <- matrix(cAA,ncol=1)
				return(c(cAA,cAB,cBB))
			})
	PROB <- matrix(NA,ncol=3*Nsnps,nrow=Nids)
	for (i in 1:Nsnps) {
		for (j in 1:3) {
			PROB[,(i-1)*3+j] <- PROB0[c(((j-1)*Nids+1):(j*Nids)),i]
		}
	}
	daProb <- matrix2databel(t(PROB),filename="temp_daProb")
	
# conversion functions
	makedose <- function(prob) {
		dose <- 2*prob[c(F,F,T)]+prob[c(F,T,F)]
		bp <- prob[c(T,F,F)]
		miss <- which(abs(bp)<1e-16 & abs(dose)<1e-16)
		if (length(miss) > 0 ) dose[miss] <- NA
		return(dose)
	}
	pfun <- function(a) return(a)

	dosefile <- apply2dfo(dfodata=daProb, anFUN = "makedose", 
			MAR = 2, procFUN = "pfun",prob=get("SNP"),
			outclass="databel",
			outfile="temp_myTestDose",
			type="DOUBLE",transpose=FALSE)
	
# check equality
	DOSE <- matrix(NA,ncol=Nids,nrow=Nsnps)
	for (i in 1:Nids) for (j in 1:Nsnps) {
			DOSE[j,i] <- 2*PROB[i,j*3]+PROB[i,j*3-1]
		}
	
	checkEqualsNumeric(DOSE,as(dosefile,"matrix"))
	
	rm(dosefile); gc()
	unlink("temp_myTestDose.fv?")
	
	rm(daProb); gc()
	unlink("temp_daProb.fv?")
}