lazappi / clustree

@@ -182,7 +182,7 @@
Loading
182 182
                          is_cluster) {
183 183
184 184
    if (col_name %in% colnames(metadata)) {
185 -
        clust_meta <- metadata[is_cluster, col_name]
185 +
        clust_meta <- metadata[[col_name]][is_cluster]
186 186
        col_aggr_fun <- match.fun(col_aggr)
187 187
        aggr_col_name <- paste0(col_aggr, "_", col_name)
188 188
        node_data[aggr_col_name] <- col_aggr_fun(clust_meta)

@@ -117,8 +117,8 @@
Loading
117 117
#' layout object depending on the value of `return`
118 118
#'
119 119
#' @examples
120 -
#' data(iris_clusts)
121 -
#' clustree(iris_clusts, prefix = "K")
120 +
#' data(nba_clusts)
121 +
#' clustree(nba_clusts, prefix = "K")
122 122
#'
123 123
#' @export
124 124
clustree <- function (x, ...) {
@@ -208,7 +208,9 @@
Loading
208 208
             call. = FALSE)
209 209
    }
210 210
211 -
    x <- x[, order(as.numeric(res_clean))]
211 +
    res_order <- order(as.numeric(res_clean))
212 +
    x <- x[, res_order]
213 +
    res_clean <- res_clean[res_order]
212 214
213 215
    if (!(is.null(metadata))) {
214 216
        metadata_names <- make.names(colnames(metadata))
@@ -396,14 +398,22 @@
Loading
396 398
    }
397 399
398 400
    args <- list(...)
399 -
    for (node_aes in c("node_colour", "node_size", "node_alpha")) {
400 -
        if (node_aes %in% names(args)) {
401 -
            node_aes_value <- args[[node_aes]]
402 -
            if (node_aes_value %in% rownames(x)) {
403 -
                aes_name <- paste0(exprs, "_", node_aes_value)
404 -
                x@colData[aes_name] <- exprs_mat[node_aes_value, ]
405 -
                args[[node_aes]] <- aes_name
401 +
    node_aes_sel <- c("node_colour", "node_size", "node_alpha")
402 +
    node_aes_sel <- node_aes_sel[node_aes_sel %in% names(args)]
403 +
    for (node_aes in node_aes_sel) {
404 +
        node_aes_value <- args[[node_aes]]
405 +
        if (node_aes_value %in% rownames(x)) {
406 +
            node_aes_name <- make.names(node_aes_value)
407 +
            if (node_aes_value != node_aes_name) {
408 +
                warning(
409 +
                    "The feature name ", node_aes_value,
410 +
                    " will be converted to ", node_aes_name,
411 +
                    call. = FALSE
412 +
                )
406 413
            }
414 +
            aes_name <- paste0(exprs, "_", node_aes_name)
415 +
            x@colData[aes_name] <- exprs_mat[node_aes_value, ]
416 +
            args[[node_aes]] <- aes_name
407 417
        }
408 418
    }
409 419
@@ -485,16 +495,23 @@
Loading
485 495
486 496
    exprs <- match.arg(arg = exprs)
487 497
    args <- list(...)
488 -
    gene_names <- rownames(x = x)
489 -
    for (node_aes in c("node_colour", "node_size", "node_alpha")) {
490 -
        if (node_aes %in% names(x = args)) {
491 -
            node_aes_value <- args[[node_aes]]
492 -
            if (node_aes_value %in% gene_names) {
493 -
                aes_name <- paste0(exprs, "_", node_aes_value)
494 -
                x[[aes_name]] <- Seurat::FetchData(x, vars = node_aes_value,
495 -
                                                   slot = exprs)
496 -
                args[[node_aes]] <- aes_name
498 +
    node_aes_sel <- c("node_colour", "node_size", "node_alpha")
499 +
    node_aes_sel <- node_aes_sel[node_aes_sel %in% names(args)]
500 +
    for (node_aes in node_aes_sel) {
501 +
        node_aes_value <- args[[node_aes]]
502 +
        if (node_aes_value %in% rownames(x)) {
503 +
            node_aes_name <- make.names(node_aes_value)
504 +
            if (node_aes_value != node_aes_name) {
505 +
                warning(
506 +
                    "The feature name ", node_aes_value,
507 +
                    " will be converted to ", node_aes_name,
508 +
                    call. = FALSE
509 +
                )
497 510
            }
511 +
            aes_name <- paste0(exprs, "_", node_aes_name)
512 +
            x[[aes_name]] <- Seurat::FetchData(x, vars = node_aes_value,
513 +
                                               slot = exprs)
514 +
            args[[node_aes]] <- aes_name
498 515
        }
499 516
    }
500 517

@@ -113,8 +113,8 @@
Loading
113 113
#' objects if `plot_sides` is `TRUE`
114 114
#'
115 115
#' @examples
116 -
#' data(iris_clusts)
117 -
#' clustree_overlay(iris_clusts, prefix = "K", x_value = "PC1", y_value = "PC2")
116 +
#' data(nba_clusts)
117 +
#' clustree_overlay(nba_clusts, prefix = "K", x_value = "PC1", y_value = "PC2")
118 118
#'
119 119
#' @export
120 120
clustree_overlay <- function (x, ...) {
@@ -427,22 +427,23 @@
Loading
427 427
    args <- list(...)
428 428
    args$x_value <- x_value
429 429
    args$y_value <- y_value
430 -
431 -
    for (node_aes in c("x_value", "y_value", "node_colour", "node_size",
432 -
                       "node_alpha")) {
433 -
        if (node_aes %in% names(args)) {
434 -
            node_aes_value <- args[[node_aes]]
435 -
            if (node_aes_value %in% rownames(x)) {
436 -
                aes_name <- paste0(exprs, "_", node_aes_value)
437 -
                x@colData[aes_name] <- exprs_mat[node_aes_value, ]
438 -
                args[[node_aes]] <- aes_name
439 -
                if (node_aes == "x_value") {
440 -
                    x_value <- paste0(exprs, "_", x_value)
441 -
                }
442 -
                if (node_aes == "y_value") {
443 -
                    y_value <- paste0(exprs, "_", y_value)
444 -
                }
430 +
    node_aes_sel <- c("x_value", "y_value", "node_colour", "node_size",
431 +
                      "node_alpha")
432 +
    node_aes_sel <- node_aes_sel[node_aes_sel %in% names(args)]
433 +
    for (node_aes in node_aes_sel) {
434 +
        node_aes_value <- args[[node_aes]]
435 +
        if (node_aes_value %in% rownames(x)) {
436 +
            node_aes_name <- make.names(node_aes_value)
437 +
            if (node_aes_value != node_aes_name) {
438 +
                warning(
439 +
                    "The feature name ", node_aes_value,
440 +
                    " will be converted to ", node_aes_name,
441 +
                    call. = FALSE
442 +
                )
445 443
            }
444 +
            aes_name <- paste0(exprs, "_", node_aes_name)
445 +
            x@colData[aes_name] <- exprs_mat[node_aes_value, ]
446 +
            args[[node_aes]] <- aes_name
446 447
        }
447 448
    }
448 449
@@ -589,17 +590,23 @@
Loading
589 590
    args <- list(...)
590 591
    args$x_value <- x_value
591 592
    args$y_value <- y_value
592 -
    gene_names <- rownames(x)
593 -
594 -
    for (node_aes in c("node_colour", "node_size", "node_alpha")) {
595 -
        if (node_aes %in% names(x = args)) {
596 -
            node_aes_value <- args[[node_aes]]
597 -
            if (node_aes_value %in% gene_names) {
598 -
                aes_name <- paste0(exprs, "_", node_aes_value)
599 -
                x[[aes_name]] <- Seurat::FetchData(x, vars = node_aes_value,
600 -
                                                   slot = exprs)
601 -
                args[[node_aes]] <- aes_name
593 +
    node_aes_sel <- c("node_colour", "node_size", "node_alpha")
594 +
    node_aes_sel <- node_aes_sel[node_aes_sel %in% names(args)]
595 +
    for (node_aes in node_aes_sel) {
596 +
        node_aes_value <- args[[node_aes]]
597 +
        if (node_aes_value %in% rownames(x)) {
598 +
            node_aes_name <- make.names(node_aes_value)
599 +
            if (node_aes_value != node_aes_name) {
600 +
                warning(
601 +
                    "The feature name ", node_aes_value,
602 +
                    " will be converted to ", node_aes_name,
603 +
                    call. = FALSE
604 +
                )
602 605
            }
606 +
            aes_name <- paste0(exprs, "_", node_aes_name)
607 +
            x[[aes_name]] <- Seurat::FetchData(x, vars = node_aes_value,
608 +
                                               slot = exprs)
609 +
            args[[node_aes]] <- aes_name
603 610
        }
604 611
    }
605 612
Files Coverage
R 89.31%
Project Totals (5 files) 89.31%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading