File: test-correlate-genes.R

package info (click to toggle)
r-bioc-scran 1.26.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,692 kB
  • sloc: cpp: 733; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 853 bytes parent folder | download | duplicates (2)
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
# Tests the correlateGenes function.
# library(testthat); library(scran); source("test-correlate-genes.R")

set.seed(100022)
Ngenes <- 20
Ncells <- 100
X <- log(matrix(rpois(Ngenes*Ncells, lambda=10), nrow=Ngenes) + 1)
rownames(X) <- paste0("X", seq_len(Ngenes))
ref <- correlatePairs(X)

test_that("correlateGenes works correctly", {
    out <- correlateGenes(ref)
    for (x in rownames(X)) {
        collected <- ref$gene1 == x | ref$gene2==x

        simes.p <- min(p.adjust(ref$p.value[collected], method="BH"))
        expect_equal(simes.p, out$p.value[out$gene==x])

        max.i <- which.max(abs(ref$rho[collected]))
        expect_equal(ref$rho[collected][max.i], out$rho[out$gene==x])
    }
})

test_that("correlateGenes handles silly inputs", {
    out <- correlateGenes(ref[1:10,])
    expect_identical(out[0,], correlateGenes(ref[0,]))
})