context("Calculate species-specific transcripts from mixed species experiments")
test_that("correct output is produced from dge summary data", {
# create mock dge summary data -----------------------------------------------
# generate cell barcodes
cells <- c("TTCTTGAGTGTT", "TGGTGGTCTTGA", "CAAAAACGGGTT", "GCCTTGCAATGC")
# number of genes and transcripts
h_genes <- c(4500, 100, 900, 150)
m_genes <- c(100, 4000, 300, 5)
h_txs <- h_genes * 5
m_txs <- m_genes * 5
# create data.frame containing dge summary
dge_summary <- data.frame(CELL_BARCODE = cells,
NUM_GENES_HUMAN = h_genes,
NUM_TRANSCRIPTS_HUMAN = h_txs,
NUM_GENES_MOUSE = m_genes,
NUM_TRANSCRIPTS_MOUSE = m_txs,
stringsAsFactors = FALSE
)
# test with default settings -------------------------------------------------
expect_out <- data.frame(cell_barcode = cells,
num_transcripts_human = h_txs,
num_transcripts_mouse = m_txs,
frac_transcripts_human = h_txs / (h_txs + m_txs),
frac_transcripts_mouse = m_txs / (h_txs + m_txs),
species = c("human", "mouse", "mixed", NA),
stringsAsFactors = FALSE
)
# run test
expect_equal(txs_ms_dge_summary(dge_summary), expected = expect_out)
# adjust min_txs parameter ---------------------------------------------------
expect_out[4, "species"] <- "human"
# run test
expect_equal(txs_ms_dge_summary(dge_summary, min_txs = 500),
expected = expect_out)
# adjust min_frac parameter --------------------------------------------------
expect_out[4, "species"] <- NA # revert previous change
expect_out[3, "species"] <- "human"
# run test
expect_equal(txs_ms_dge_summary(dge_summary, min_frac = 0.75),
expected = expect_out)
})
test_that("correct output is produced from dge data", {
# create mock dge summary data -----------------------------------------------
# generate gene expression profile for cells
genex <- data.frame(TTCTTGAGTGTT = c(1300, 5),
TGGTGGTCTTGA = c(0, 1000),
CAAAAACGGGTT = c(750, 250),
GCCTTGCAATGC = c(500, 2)
)
# create data.frame containing dge data
dge <- data.frame(GENE = paste0("GENE", 1:2),
SPECIES = c("human", "mouse"),
genex
)
# test with default settings -------------------------------------------------
# create expected output
h_txs <- as.numeric(dge[1, -c(1:2)])
m_txs <- as.numeric(dge[2, -c(1:2)])
expect_out <- data.frame(cell_barcode = colnames(genex),
num_transcripts_human = h_txs,
num_transcripts_mouse = m_txs,
frac_transcripts_human = h_txs / (h_txs + m_txs),
frac_transcripts_mouse = m_txs / (h_txs + m_txs),
species = c("human", "mouse", "mixed", NA),
stringsAsFactors = FALSE
)
# run test
expect_equal(txs_ms_dge(dge), expected = expect_out)
# adjust min_txs parameter ---------------------------------------------------
expect_out[4, "species"] <- "human"
# run test
expect_equal(txs_ms_dge(dge, min_txs = 500), expected = expect_out)
# adjust min_frac parameter --------------------------------------------------
expect_out[4, "species"] <- NA # revert previous change
expect_out[3, "species"] <- "human"
# run test
expect_equal(txs_ms_dge(dge, min_frac = 0.75), expected = expect_out)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.