This repository has been archived by the owner on Dec 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.R
74 lines (62 loc) · 1.73 KB
/
checks.R
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
## This script is checking whether the MMA1Bit functions are working as intended.
# We simulate a population with 100k SNPs and 10k individuals.
library(miraculix)
# Global RFutils options
RFoptions(install="none", warn_parallel=FALSE)
RFoptions(centered=FALSE, normalized=FALSE, cores=12, helpinfo=FALSE, la_mode=LA_GPU)
# Number of individuals
n <- 10000
# Number of SNPs
snps <- 1e6
# magic number to avoid RAM overflow
divisor <- 1000
# Simulate population
SNPs <- matrix(sample(0:2, n/divisor * snps, replace=T), ncol=n/divisor)
# MMAGPU (reference)
RFoptions(snpcoding=MMAGPU)
Z <- miraculix::genomicmatrix(snps, n)
for (j in 0:(divisor-1)) {
fillGeno(Z, (1:(n/divisor)) + n/divisor * j, SNPs)
}
cat("snpcoding=MMA1Bit, mma version\n")
G <- miraculix::relationshipMatrix(Z,
n_streams = 6, shape = 1, tilesize = 1024
)
# MMA1Bit (naive)
RFoptions(snpcoding=MMA1Bit)
Z <- miraculix::genomicmatrix(snps, n)
for (j in 0:(divisor-1)) {
fillGeno(Z, (1:(n/divisor)) + n/divisor * j, SNPs)
}
H <- miraculix::relationshipMatrix(Z,
warp = FALSE, shape = 6, n_streams = 6, tilesize = 1024, naive = TRUE
)
# Sanity checks
if (all(G == H)) {
cat("\nPass.\n\n")
} else {
cat("\nWrong values!\n\n")
print(G[1:10,1:10])
print(H[1:10,1:10])
print(sum(G!=H))
print(match(1, G!=H))
}
# MMA1Bit (naive = FALSE)
RFoptions(snpcoding=MMA1Bit)
Z <- miraculix::genomicmatrix(snps, n)
for (j in 0:(divisor-1)) {
fillGeno(Z, (1:(n/divisor)) + n/divisor * j, SNPs)
}
H <- miraculix::relationshipMatrix(Z,
warp = FALSE, shape = 6, n_streams = 6, tilesize = 1024, naive = FALSE
)
# Sanity checks
if (all(G == H)) {
cat("\nPass.\n\n")
} else {
cat("\nWrong values!\n\n")
print(G[1:10,1:10])
print(H[1:10,1:10])
print(sum(G!=H))
print(match(1, G!=H))
}