diff --git a/tests/testthat/test-alignment.R b/tests/testthat/test-alignment.R index 2bd4a04..995e998 100644 --- a/tests/testthat/test-alignment.R +++ b/tests/testthat/test-alignment.R @@ -86,7 +86,7 @@ test_that("Alignment works on synthetic data", { batched_cds = cluster_cells(batched_cds, k=10, reduction_method="PCA", resolution=1e-3) plot_cells(batched_cds, reduction_method="PCA", color_cells_by="partition") - expect_equal(length(unique(partitions(batched_cds, reduction_method="PCA"))), 5) + expect_equal(length(unique(partitions(batched_cds, reduction_method="PCA"))), 4) #batched_cds = preprocess_cds(batched_cds, num_dim=2, residual_model_formula_str="~cell_type") @@ -106,7 +106,7 @@ test_that("Alignment works on synthetic data", { batched_cds = cluster_cells(batched_cds, k=10, reduction_method="Aligned", resolution=1e-3) plot_cells(batched_cds, reduction_method="Aligned", color_cells_by="batch") - expect_equal(length(unique(partitions(batched_cds, reduction_method="Aligned"))), 10) + expect_equal(length(unique(partitions(batched_cds, reduction_method="Aligned"))), 9) #plot_cells(batched_cds, reduction_method="PCA", color_cells_by="cluster") diff --git a/tests/testthat/test-cluster_cells.R b/tests/testthat/test-cluster_cells.R index ad8f8db..72ffc34 100644 --- a/tests/testthat/test-cluster_cells.R +++ b/tests/testthat/test-cluster_cells.R @@ -56,9 +56,8 @@ test_that("cluster_cells works", { expect_equal(length(cds@clusters[["UMAP"]]), 3) expect_equal(length(cds@clusters[["UMAP"]]$cluster_result$optim_res$membership), nrow(colData(cds))) - expect_equal(cds@clusters[["UMAP"]]$cluster_result$optim_res$membership[[1]], - 3) - expect_equal(length(unique(clusters(cds, reduction_method = "UMAP"))), 17) + expect_equal(cds@clusters[["UMAP"]]$cluster_result$optim_res$membership[[1]], 16) + expect_equal(length(unique(clusters(cds, reduction_method = "UMAP"))), 20) ## louvain cds <- cluster_cells(cds, cluster_method = "louvain", random_seed = 100) @@ -68,7 +67,7 @@ test_that("cluster_cells works", { nrow(colData(cds))) expect_equal(cds@clusters[["UMAP"]]$cluster_result$optim_res$membership[[1]], 1) - expect_equal(length(unique(clusters(cds, reduction_method = "UMAP"))), 8) + expect_equal(length(unique(clusters(cds, reduction_method = "UMAP"))), 11) # non-standard opts cds <- cluster_cells(cds, cluster_method = "louvain", k=22, weight = TRUE, @@ -80,7 +79,7 @@ test_that("cluster_cells works", { nrow(colData(cds))) expect_equal(cds@clusters[["UMAP"]]$cluster_result$optim_res$membership[[1]], 1) - expect_equal(length(unique(clusters(cds, reduction_method = "UMAP"))), 12) + expect_equal(length(unique(clusters(cds, reduction_method = "UMAP"))), 13) ### tSNE ##leiden @@ -102,8 +101,8 @@ test_that("cluster_cells works", { expect_equal(length(cds@clusters[["tSNE"]]$cluster_result$optim_res$membership), nrow(colData(cds))) expect_equal(cds@clusters[["tSNE"]]$cluster_result$optim_res$membership[[1]], - 6) - expect_equal(length(unique(clusters(cds, reduction_method = "tSNE"))), 21) + 17) + expect_equal(length(unique(clusters(cds, reduction_method = "tSNE"))), 22) ### PCA diff --git a/tests/testthat/test-fit_models.R b/tests/testthat/test-fit_models.R index 3a9c17a..a4f8827 100644 --- a/tests/testthat/test-fit_models.R +++ b/tests/testthat/test-fit_models.R @@ -9,6 +9,7 @@ skip_not_travis <- function () skip("Not on Travis") } +library(pryr) cds <- load_a549() #cds <- estimate_size_factors(cds) @@ -321,7 +322,7 @@ test_that("fit_models() can handle cluster in model formulae",{ expression_family = "quasipoisson") expect_equal(pos_ctrl_gene_fit$status[[1]], "OK") pos_ctrl_coefs = coefficient_table(pos_ctrl_gene_fit) - expect_equal(pos_ctrl_coefs$estimate[2], -0.0962, tolerance=1e-3) + expect_equal(pos_ctrl_coefs$estimate[2], -0.99, tolerance=1e-2) }) diff --git a/tests/testthat/test-graph_test.R b/tests/testthat/test-graph_test.R index 647937b..1f9d760 100644 --- a/tests/testthat/test-graph_test.R +++ b/tests/testthat/test-graph_test.R @@ -42,15 +42,15 @@ test_that("test graph_test returns Dex-dependent genes",{ pos_ctrl_gene = test_cds[rowData(cds)$gene_short_name == "che-1",] pr_test_res = graph_test(pos_ctrl_gene) expect_equal(pr_test_res$status[1], "OK") - expect_equal(pr_test_res$morans_I, 0.65, tolerance=1e-2) + expect_equal(pr_test_res$morans_I, 0.661, tolerance=1e-2) expect_equal(pr_test_res$morans_test_statistic, 204.72, tolerance=1e-1) expect_lt(pr_test_res$p_value[1], 0.05) neg_ctrl_gene = test_cds[rowData(cds)$gene_short_name == "R02D3.1",] pr_test_res = graph_test(neg_ctrl_gene) expect_equal(pr_test_res$status[1], "OK") - expect_equal(pr_test_res$morans_I, -0.00264, tolerance=1e-4) - expect_equal(pr_test_res$morans_test_statistic, -0.731, tolerance=1e-2) + expect_equal(pr_test_res$morans_I, -0.000752, tolerance=1e-5) + expect_equal(pr_test_res$morans_test_statistic, -0.173, tolerance=1e-2) expect_gt(pr_test_res$p_value[1], 0.05) }) diff --git a/tests/testthat/test-io.R b/tests/testthat/test-io.R index 46f6f4c..c6a7007 100644 --- a/tests/testthat/test-io.R +++ b/tests/testthat/test-io.R @@ -280,7 +280,7 @@ test_that("save_transform_models and load_transform_models", { # check UMAP reduced dims matrix and nearest neighbors expect_equivalent(ncol(reducedDims(cds)[['UMAP']]), 2) expect_equivalent(nrow(reducedDims(cds)[['UMAP']]), 500) - expect_equivalent(reducedDims(cds)[['UMAP']][[1,1]], 1.96, tol=1e-2) + expect_equivalent(reducedDims(cds)[['UMAP']][[1,1]], 2.7, tol=1e-1) nn_res <- search_nn_index(query_matrix=reducedDims(cds)[['UMAP']], nn_index=get_cds_nn_index(cds, reduction_method='UMAP', nn_method=nn_method, verbose=FALSE), k=5, nn_control=list(method=nn_method, metric='euclidean', n_trees=50)) expect_equivalent(nn_res[['nn.idx']][[1]], 1) expect_equivalent(nn_res[['nn.dists']][[1]], 0) @@ -349,7 +349,7 @@ test_that("save_monocle_objects and load_monocle_objects", { # check UMAP reduced dims matrix and nearest neighbors expect_equivalent(ncol(reducedDims(cds)[['UMAP']]), 2) expect_equivalent(nrow(reducedDims(cds)[['UMAP']]), 500) - expect_equivalent(reducedDims(cds)[['UMAP']][[1,1]], 1.96, tol=1e-2) + expect_equivalent(reducedDims(cds)[['UMAP']][[1,1]], 2.7, tol=1e-1) nn_res <- search_nn_index(query_matrix=reducedDims(cds)[['UMAP']], nn_index=get_cds_nn_index(cds, reduction_method='UMAP', nn_method=nn_method), k=5, nn_control=list(method=nn_method, metric='euclidean', n_trees=50)) expect_equivalent(nn_res[['nn.idx']][[1]], 1) expect_equivalent(nn_res[['nn.dists']][[1]], 0) diff --git a/tests/testthat/test-learn_graph.R b/tests/testthat/test-learn_graph.R index c6f18af..ff4206d 100644 --- a/tests/testthat/test-learn_graph.R +++ b/tests/testthat/test-learn_graph.R @@ -33,8 +33,8 @@ test_that("learn_graph stays the same", { skip_on_travis() cds <- learn_graph(cds) expect_is(principal_graph(cds)[["UMAP"]], "igraph") - expect_equal(length(principal_graph(cds)[["UMAP"]]), 63) - expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "3") + expect_equal(length(principal_graph(cds)[["UMAP"]]), 33) + expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "24") # Force partition temp <- rep(c(1,2), length.out=length(partitions(cds))) @@ -42,23 +42,23 @@ test_that("learn_graph stays the same", { cds@clusters[["UMAP"]]$partitions <- temp cds <- learn_graph(cds, use_partition = FALSE) expect_is(principal_graph(cds)[["UMAP"]], "igraph") - expect_equal(length(principal_graph(cds)[["UMAP"]]), 63) - expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "3") + expect_equal(length(principal_graph(cds)[["UMAP"]]), 33) + expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "24") cds <- learn_graph(cds) expect_is(principal_graph(cds)[["UMAP"]], "igraph") - expect_equal(length(principal_graph(cds)[["UMAP"]]), 104) - expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "24") + expect_equal(length(principal_graph(cds)[["UMAP"]]), 74) + expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "36") cds <- learn_graph(cds, close_loop = TRUE) expect_is(principal_graph(cds)[["UMAP"]], "igraph") - expect_equal(length(principal_graph(cds)[["UMAP"]]), 104) - expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "24") + expect_equal(length(principal_graph(cds)[["UMAP"]]), 74) + expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "36") cds <- learn_graph(cds, learn_graph_control = list(prune_graph = FALSE)) expect_is(principal_graph(cds)[["UMAP"]], "igraph") - expect_equal(length(principal_graph(cds)[["UMAP"]]), 216) - expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "46") + expect_equal(length(principal_graph(cds)[["UMAP"]]), 144) + expect_equal(as.character(principal_graph(cds)[["UMAP"]][[1]]$Y_1[[1]]), "8") }) diff --git a/tests/testthat/test-order_cells.R b/tests/testthat/test-order_cells.R index 821bc22..7da8873 100644 --- a/tests/testthat/test-order_cells.R +++ b/tests/testthat/test-order_cells.R @@ -36,21 +36,21 @@ cds <- learn_graph(cds) test_that("order_cells works", { skip_on_travis() cds <- order_cells(cds, root_pr_nodes = "Y_1") - expect_equal(max(pseudotime(cds)), 16.5, tol = 1e-1) + expect_equal(max(pseudotime(cds)), 11.9, tol = 1e-1) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 0.111, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.0538, tol = 1e-3) cds <- order_cells(cds, root_pr_nodes = c("Y_1", "Y_10")) - expect_equal(max(pseudotime(cds)), 9.08, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 6.34, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 0.111, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.0538, tol = 1e-3) cds <- order_cells(cds, root_cells = "G07_B02_RT_587") - expect_equal(max(pseudotime(cds)), 14.9, tol = 1e-1) + expect_equal(max(pseudotime(cds)), 13.2, tol = 1e-1) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 2.18, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 1.5, tol = 1e-1) cds <- order_cells(cds, root_cells = c("G07_B02_RT_587", "F06_A01_RT_598")) - expect_equal(max(pseudotime(cds)), 8.89, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 7.26, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 2.18, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 1.5, tol = 1e-1) }) cds <- reduce_dimension(cds, max_components = 3, umap.fast_sgd=FALSE) @@ -62,19 +62,19 @@ test_that("order_cells works 3d", { cds <- order_cells(cds, root_pr_nodes = "Y_1") expect_equal(max(pseudotime(cds)), 10.0, tol = 1e-1) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 9.67e-7, tol = 1e-8) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.664, tol = 1e-3) cds <- order_cells(cds, root_pr_nodes = c("Y_1", "Y_10")) - expect_equal(max(pseudotime(cds)), 7.69, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 8.64, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 9.67e-7, tol = 1e-8) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.664, tol = 1e-3) cds <- order_cells(cds, root_cells = "G07_B02_RT_587") - expect_equal(max(pseudotime(cds)), 13.4, tol = 1e-1) + expect_equal(max(pseudotime(cds)), 10.4, tol = 1e-1) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 3.17, tol = 1e-1) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.664, tol = 1e-3) cds <- order_cells(cds, root_cells = c("G07_B02_RT_587", "F06_A01_RT_598")) expect_equal(max(pseudotime(cds)), 10.2, tol = 1e-1) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 3.17, tol = 1e-1) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.664, tol = 1e-3) }) cds <- cluster_cells(cds, random_seed = 100) @@ -83,21 +83,21 @@ cds <- learn_graph(cds) test_that("order_cells works leiden", { skip_on_travis() cds <- order_cells(cds, root_pr_nodes = "Y_1") - expect_equal(max(pseudotime(cds)), 6.35, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 9.94, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 1.94, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 4.49, tol = 1e-2) cds <- order_cells(cds, root_pr_nodes = c("Y_1", "Y_2")) - expect_equal(max(pseudotime(cds)), 3.76, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 4.72, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 1.94, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 4.35, tol = 1e-2) cds <- order_cells(cds, root_cells = "G07_B02_RT_587") - expect_equal(max(pseudotime(cds)), 6.35, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 8.03, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 1.94 , tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.121 , tol = 1e-3) cds <- order_cells(cds, root_cells = c("G07_B02_RT_587", "F06_A01_RT_598")) - expect_equal(max(pseudotime(cds)), 4.15, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 5.85, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 1.94 , tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.121 , tol = 1e-3) }) cds <- reduce_dimension(cds, max_components = 3, umap.fast_sgd=FALSE) @@ -107,21 +107,21 @@ cds <- learn_graph(cds) test_that("order_cells works leiden 3d", { skip_on_travis() cds <- order_cells(cds, root_pr_nodes = "Y_1") - expect_equal(max(pseudotime(cds)), 6.35, tol = 1e-1) + expect_equal(max(pseudotime(cds)), 9.94, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 1.94, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 4.49, tol = 1e-2) cds <- order_cells(cds, root_pr_nodes = c("Y_1", "Y_2")) - expect_equal(max(pseudotime(cds)), 3.76, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 4.72, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 1.94, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 4.35, tol = 1e-2) cds <- order_cells(cds, root_cells = "G07_B02_RT_587") - expect_equal(max(pseudotime(cds)), 6.35, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 8.03, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 1.94, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.121, tol = 1e-3) cds <- order_cells(cds, root_cells = c("G07_B02_RT_587", "F06_A01_RT_598")) - expect_equal(max(pseudotime(cds)), 4.15, tol = 1e-2) + expect_equal(max(pseudotime(cds)), 5.85, tol = 1e-2) expect_equal(min(pseudotime(cds)), 0) - expect_equal(as.numeric(pseudotime(cds)[1]), 1.94, tol = 1e-2) + expect_equal(as.numeric(pseudotime(cds)[1]), 0.121, tol = 1e-3) }) diff --git a/tests/testthat/test-reduce_dimension.R b/tests/testthat/test-reduce_dimension.R index 837eddb..75ee98b 100644 --- a/tests/testthat/test-reduce_dimension.R +++ b/tests/testthat/test-reduce_dimension.R @@ -27,25 +27,25 @@ test_that("reduce_dimension runs", { cds <- reduce_dimension(cds, umap.fast_sgd=FALSE, cores=1) expect_equal(nrow(reducedDims(cds)$UMAP), nrow(colData(cds))) expect_equal(ncol(reducedDims(cds)$UMAP), 2) - expect_equal(as.numeric(reducedDims(cds)$UMAP[1,1]), -2.86, + expect_equal(as.numeric(reducedDims(cds)$UMAP[1,1]), 2.26, tolerance = 1e-2) cds <- reduce_dimension(cds, max_components = 3, umap.fast_sgd=FALSE, cores=1, reduction_method = "UMAP") expect_equal(nrow(reducedDims(cds)$UMAP), nrow(colData(cds))) expect_equal(ncol(reducedDims(cds)$UMAP), 3) - expect_equal(as.numeric(reducedDims(cds)$UMAP[1,1]), 1.69, - tolerance = 1e-2) + expect_equal(as.numeric(reducedDims(cds)$UMAP[1,1]), 0.265, + tolerance = 1e-3) cds <- reduce_dimension(cds, reduction_method = "tSNE") expect_equal(nrow(reducedDims(cds)$tSNE), nrow(colData(cds))) expect_equal(ncol(reducedDims(cds)$tSNE), 2) - expect_equal(as.numeric(reducedDims(cds)$tSNE[1,1]), -1.16, + expect_equal(as.numeric(reducedDims(cds)$tSNE[1,1]), -3.74, tolerance = 1e-2) cds <- reduce_dimension(cds, max_components = 3, reduction_method = "tSNE") expect_equal(nrow(reducedDims(cds)$tSNE), nrow(colData(cds))) expect_equal(ncol(reducedDims(cds)$tSNE), 3) - expect_equal(as.numeric(reducedDims(cds)$tSNE[1,1]), -4.29, + expect_equal(as.numeric(reducedDims(cds)$tSNE[1,1]), -5.29, tolerance = 1e-2) cds <- reduce_dimension(cds, reduction_method = "PCA") @@ -57,14 +57,14 @@ test_that("reduce_dimension runs", { cds <- reduce_dimension(cds, umap.fast_sgd=FALSE, cores=1, preprocess_method = "LSI") expect_equal(nrow(reducedDims(cds)$UMAP), nrow(colData(cds))) expect_equal(ncol(reducedDims(cds)$UMAP), 2) - expect_equal(as.numeric(reducedDims(cds)$UMAP[1,1]), -0.163, - tolerance = 1e-3) + expect_equal(as.numeric(reducedDims(cds)$UMAP[1,1]), -1.21, + tolerance = 1e-2) cds <- reduce_dimension(cds, reduction_method = "tSNE", preprocess_method = "LSI") expect_equal(nrow(reducedDims(cds)$tSNE), nrow(colData(cds))) expect_equal(ncol(reducedDims(cds)$tSNE), 2) - expect_equal(as.numeric(reducedDims(cds)$tSNE[1,1]), -2.15, - tolerance = 1e-2) + expect_equal(as.numeric(reducedDims(cds)$tSNE[1,1]), 0.738, + tolerance = 1e-3) # check model set.seed(100) @@ -78,7 +78,7 @@ test_that("reduce_dimension runs", { expect_equal(cds@reduce_dim_aux[['UMAP']][['model']][['umap_min_dist']], 0.1, tol=1e-1) expect_equal(cds@reduce_dim_aux[['UMAP']][['model']][['umap_n_neighbors']], 15, tol=1e1) expect_equal(cds@reduce_dim_aux[['UMAP']][['model']][['umap_fast_sgd']], FALSE) - expect_equal(cds@reduce_dim_aux[['UMAP']][['model']][['umap_model']][['embedding']][[1,1]], -1.80, tol=1e-1) + expect_equal(cds@reduce_dim_aux[['UMAP']][['model']][['umap_model']][['embedding']][[1,1]], 2.03, tol=1e-2) expect_equal(cds@reduce_dim_aux[['UMAP']][['model']][['umap_model']][['n_neighbors']][[1]], 15, tol=1e1)