Merge branch 'issue-3' into develop

This commit is contained in:
Waldir Leoncio 2022-07-28 14:15:12 +02:00
commit eef819a9c3
3 changed files with 36 additions and 2 deletions

View file

@ -1,6 +1,6 @@
Package: rBAPS
Title: Bayesian Analysis of Population Structure
Version: 0.0.0.9008
Version: 0.0.0.9009
Date: 2020-11-09
Authors@R:
c(
@ -36,7 +36,7 @@ Description: Partial R implementation of the BAPS software
License: GPL-3
BugReports: https://github.com/ocbe-uio/rBAPS/issues
Encoding: UTF-8
RoxygenNote: 7.2.0
RoxygenNote: 7.2.1
Suggests:
testthat (>= 2.1.0)
Imports:

25
R/computeCounts.R Normal file
View file

@ -0,0 +1,25 @@
computeCounts <- function(cliques, separators, npops, PARTITION) {
ncliq <- size(cliques, 1)
nsep <- size(separators, 1)
cliqPartition <- zeros(ncliq, size(cliques, 2))
sepPartition <- zeros(nsep, size(separators, 2))
apuCliq <- find(cliques > 0)
apuSep <- find(separators > 0)
cliqPartition[apuCliq] <- PARTITION[cliques[apuCliq]]
sepPartition[apuSep] <- PARTITION[separators[apuSep]]
cliqcounts <- zeros(ncliq, npops)
for (i in 1:npops) {
cliqcounts[, i] <- rowSums(cliqPartition == i)
}
sepcounts <- zeros(nsep, npops)
for (i in 1:npops) {
sepcounts[, i] <- rowSums(sepPartition == i)
}
return(list(cliqcounts = cliqcounts, sepcounts = sepcounts))
}

View file

@ -0,0 +1,9 @@
context("Spatial mixture")
test_that("functions work with basic input", {
x <- c(1, 3, 0, 2)
y <- array(c(1, 3, 2, 4, 5, 7, 6, 8), c(2, 2, 2))
z <- computeCounts(x, 4, 5, y)
expect_equal(z$cliqcounts, t(c(1, 1, 1, 0, 0)))
expect_equal(z$sepcounts, t(c(0, 0, 0, 1, 0)))
})