Commit 2a75543e authored by tekath's avatar tekath
Browse files

styler changes and fixed typo.

parent c463ae9a
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
DTUrtle News
================

# DTUrtle 1.0.2

## Changes

  - `plot_transcripts_view()`: now creates missing save folder, like
    other plotting functions.
  - `check_unique_by_partition()`: now handles columns with only `NA`
    values.
  - `get_by_partition()`: correctly retains factor columns.
  - styled R code with `styler`-package for better code readability.

# DTUrtle 1.0.1

## Changes
@@ -87,7 +98,7 @@ DTUrtle News
    extension.
  - removed dependency of ‘stringi’.
  - added ‘sparseDRIMSeq’ to depending packages, to get rid of sometimes
    not-occuring package load.
    not-occurring package load.
  - fixed some smaller bugs.

# DTUrtle 0.7.1
+205 −186
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import_dge_counts <- function(files, type, ...){
  assertthat::assert_that(length(files) >= 1)
  message("Reading in ", length(files), " ", type, " runs.")

    args=list(...)
  args <- list(...)

  if (methods::hasArg("countsFromAbundance")) {
    if (args$countsFromAbundance != "no") {
@@ -50,7 +50,7 @@ import_dge_counts <- function(files, type, ...){
  }

  if (type == "alevin" || type == "bustools") {
        return_obj = list()
    return_obj <- list()

    if (type == "alevin") {
      assertthat::assert_that(all(basename(files) == "quants_mat.gz"), msg = "Expecting 'files' to point to 'quants_mat.gz' file in a directory 'alevin'\n  also containing 'quants_mat_rows.txt' and 'quant_mat_cols.txt'.\n  Please re-run alevin preserving output structure.")
@@ -71,7 +71,6 @@ import_dge_counts <- function(files, type, ...){
    if (!args$txOut) {
      return_obj <- lapply(return_obj, function(i) summarize_to_gene(i, args$tx2gene))
    }

  } else {
    args$files <- files
    args$type <- type
@@ -155,13 +154,17 @@ run_deseq2 <- function(counts, pd, id_col=NULL, cond_col, cond_levels=NULL, lfc_

  if (is.null(id_col)) {
    assertthat::assert_that(all(rownames(pd) %in% colnames(counts)), msg = "Provided id_col does not match with sample names in counts.")
        samp <- data.frame("sample_id"=rownames(pd), "condition"=as.character(pd[[cond_col]]),
    samp <- data.frame(
      "sample_id" = rownames(pd), "condition" = as.character(pd[[cond_col]]),
      pd[, -c(which(colnames(pd) == cond_col)), drop = FALSE],
                           row.names = NULL, stringsAsFactors = FALSE)
      row.names = NULL, stringsAsFactors = FALSE
    )
  } else {
        samp <- data.frame("sample_id"=pd[[id_col]], "condition"=as.character(pd[[cond_col]]),
    samp <- data.frame(
      "sample_id" = pd[[id_col]], "condition" = as.character(pd[[cond_col]]),
      pd[, -c(which(colnames(pd) %in% c(id_col, cond_col))), drop = FALSE],
                           row.names = NULL, stringsAsFactors = FALSE)
      row.names = NULL, stringsAsFactors = FALSE
    )
  }

  if (!is.null(subset_feature) | !is.null(subset_sample)) {
@@ -204,12 +207,16 @@ run_deseq2 <- function(counts, pd, id_col=NULL, cond_col, cond_levels=NULL, lfc_

  if (exists("eff_len")) {
    eff_len <- eff_len[rownames(counts), colnames(counts), drop = FALSE]
        dds <- DESeq2::DESeqDataSetFromTximport(txi = list("counts"=counts, "length"=eff_len, "countsFromAbundance"=cfa),
                                                colData = samp, design = ~condition)
    dds <- DESeq2::DESeqDataSetFromTximport(
      txi = list("counts" = counts, "length" = eff_len, "countsFromAbundance" = cfa),
      colData = samp, design = ~condition
    )
  } else {
    counts <- round(counts)
        dds <- DESeq2::DESeqDataSetFromMatrix(countData = counts, colData = samp,
                                              design = ~condition)
    dds <- DESeq2::DESeqDataSetFromMatrix(
      countData = counts, colData = samp,
      design = ~condition
    )
  }

  dds$condition <- stats::relevel(dds$condition, ref = cond_levels[[2]])
@@ -219,13 +226,17 @@ run_deseq2 <- function(counts, pd, id_col=NULL, cond_col, cond_levels=NULL, lfc_
  if (dge_calling_strategy == "sc") {
    # use recommended parameters for single-cell analysis from the DESeq2 vignette and https://doi.org/10.1186/s13059-018-1406-4.
    # DESeq2 version must be >=1.3.0 for glmGamPoi
        use_deseq_opts <- utils::modifyList(use_deseq_opts,
                                            list("fitType" = "glmGamPoi",
    use_deseq_opts <- utils::modifyList(
      use_deseq_opts,
      list(
        "fitType" = "glmGamPoi",
        "sfType" = "poscounts",
        "test" = "LRT",
        "reduced" = ~1,
        "useT" = TRUE, "minmu" = 1e-6,
                                                 "minReplicatesForReplace"=Inf))
        "minReplicatesForReplace" = Inf
      )
    )

    if (utils::packageVersion("DESeq2") < "1.3.0") {
      warning("DESeq2 1.3.0 and above offer a much faster and more precise GLM estimation method (glmGamPoi).
@@ -243,12 +254,14 @@ run_deseq2 <- function(counts, pd, id_col=NULL, cond_col, cond_levels=NULL, lfc_
  dds <- do.call(DESeq2::DESeq, c(list("object" = dds), use_deseq_opts))

  # prepare LFC shrinking
    use_lfc_shrink_opts <- list("coef"=paste0("condition_",make.names(cond_levels[[1]]),"_vs_",make.names(cond_levels[[2]])),
  use_lfc_shrink_opts <- list(
    "coef" = paste0("condition_", make.names(cond_levels[[1]]), "_vs_", make.names(cond_levels[[2]])),
    "type" = "apeglm",
    "svalue" = TRUE,
    "lfcThreshold" = lfc_threshold,
    "parallel" = TRUE,
                                "BPPARAM"=BPPARAM)
    "BPPARAM" = BPPARAM
  )

  if (!requireNamespace("apeglm", quietly = TRUE)) {
    warning("Installation of the bioconductor package 'apeglm' would offer a better performing shrinkage estimator.
@@ -278,11 +291,17 @@ run_deseq2 <- function(counts, pd, id_col=NULL, cond_col, cond_levels=NULL, lfc_
  message("\t\tUnder-expressed: ", sum(res_sig$log2FoldChange < 0))

  comp_name <- paste0(cond_col, "__", cond_levels[[1]], "_vs_", cond_levels[[2]])
    return_list <- stats::setNames(list(res_all, res_sig, dds, sig_threshold,
  return_list <- stats::setNames(
    list(
      res_all, res_sig, dds, sig_threshold,
      comp_name, cond_levels[[1]], cond_levels[[2]],
                                 samp, use_deseq_opts, use_lfc_shrink_opts),
                            c("results_all", "results_sig", "dds", paste0(threshold_col, "_threshold"),
                              "comparison", "condition1", "condition2", "sample_table", "deseq_opts", "lfc_shrink_opts"))
      samp, use_deseq_opts, use_lfc_shrink_opts
    ),
    c(
      "results_all", "results_sig", "dds", paste0(threshold_col, "_threshold"),
      "comparison", "condition1", "condition2", "sample_table", "deseq_opts", "lfc_shrink_opts"
    )
  )
  if (!return_dds) {
    return_list$dds <- NULL
  }
+433 −409
Original line number Diff line number Diff line
@@ -33,10 +33,10 @@ import_counts <- function(files, type, ...){
  assertthat::assert_that(length(files) >= 1)
  message("Reading in ", length(files), " ", type, " runs.")

    args=list(...)
  args <- list(...)

  if (type == "alevin" || type == "bustools") {
        return_obj = list()
    return_obj <- list()

    if (methods::hasArg("countsFromAbundance")) {
      warning(paste0("\nImport of ", type, " files currently does not support using scaling methods.\nPlease note, that in tagged-end single-cell protocols (like 10X chromium or SureCell) it is assumed\nthat there is no length effect in the fragment generation process - thus making a scaling unnecessary."))
@@ -56,7 +56,6 @@ import_counts <- function(files, type, ...){
    if (!is.null(names(files))) {
      names(return_obj) <- names(files)
    }

  } else {
    if (methods::hasArg("countsFromAbundance")) {
      if (!args$countsFromAbundance %in% c("dtuScaledTPM", "scaledTPM")) {
@@ -105,7 +104,6 @@ import_counts <- function(files, type, ...){
#' @family DTUrtle DTU
#' @export
combine_to_matrix <- function(tx_list, cell_extensions = NULL, cell_extension_side = "append", seurat_obj = NULL, tx2gene = NULL, assay_name = "dtutx") {

  if (!is.null(seurat_obj)) {
    assertthat::assert_that(requireNamespace("Seurat", quietly = TRUE), msg = "The package Seurat is needed for adding the combined matrix to a seurat object.")
    assertthat::assert_that(utils::packageVersion("Seurat") >= "3.0.0", msg = "At least Version 3 of Seurat is needed. Currently only Seurat 3 objects are supported.")
@@ -118,7 +116,7 @@ combine_to_matrix <- function(tx_list, cell_extensions=NULL, cell_extension_side
    tx_list <- list(tx_list)
  }

    if(!all(as.logical(lapply(tx_list, FUN = function(x) methods::is(x, 'sparseMatrix'))))){
  if (!all(as.logical(lapply(tx_list, FUN = function(x) methods::is(x, "sparseMatrix"))))) {
    stop("Your 'tx_list' object contains non sparseMatrix elements.")
  }

@@ -152,10 +150,11 @@ combine_to_matrix <- function(tx_list, cell_extensions=NULL, cell_extension_side
          if (dup) {
            stop("Duplicated cell names present, but no cell name extension could be found.")
          }
          }
          else if(length(cell_extensions)!=length(names(tx_list))){
            stop("Could not 1:1 map inferred seurat cellname extensions and tx file list.\n",
                 "Either provide explicit cell extensions or try subsetting the seurat object, if you do not want to provide tx information for all samples.")
        } else if (length(cell_extensions) != length(names(tx_list))) {
          stop(
            "Could not 1:1 map inferred seurat cellname extensions and tx file list.\n",
            "Either provide explicit cell extensions or try subsetting the seurat object, if you do not want to provide tx information for all samples."
          )
        }
      } else if (cell_extension_side == "append") {
        cell_extensions <- paste0("_", seq_along(tx_list))
@@ -222,8 +221,7 @@ combine_to_matrix <- function(tx_list, cell_extensions=NULL, cell_extension_side
      seurat_obj <- seurat_add_tx2gene(seurat_obj, tx2gene)
    }
    return(seurat_obj)
    }
    else{
  } else {
    return(tx_list)
  }
}
@@ -298,8 +296,10 @@ run_drimseq <- function(counts, tx2gene, pd, id_col=NULL, cond_col, cond_levels=
  assertthat::assert_that(is.null(subset_feature) | length(subset_feature) > 0, msg = "`subset_feature` must be `NULL` or of length>=1.")
  assertthat::assert_that(is.null(subset_sample) | length(subset_sample) > 0, msg = "`subset_sample` must be `NULL` or of length>=1.")
  assertthat::assert_that(is.logical(carry_over_metadata), msg = "`carry_over_metadata` must be `TRUE` or `FALSE`.")
    assertthat::assert_that((length(intersect(rownames(counts), tx2gene[[1]]))>0), msg = paste0("The provided counts names and tx2gene names do not match.\n\tCounts names: ",
                            paste0(rownames(utils::head(counts, n = 5)), collapse = ", "), "\n\tTx2gene names: ", paste0(utils::head(tx2gene, n = 5)[[1]], collapse = ", ")))
  assertthat::assert_that((length(intersect(rownames(counts), tx2gene[[1]])) > 0), msg = paste0(
    "The provided counts names and tx2gene names do not match.\n\tCounts names: ",
    paste0(rownames(utils::head(counts, n = 5)), collapse = ", "), "\n\tTx2gene names: ", paste0(utils::head(tx2gene, n = 5)[[1]], collapse = ", ")
  ))
  assertthat::assert_that(is.logical(filter_only), msg = "The 'filter_only' paramter must be TRUE or FALSE.")


@@ -336,13 +336,17 @@ run_drimseq <- function(counts, tx2gene, pd, id_col=NULL, cond_col, cond_levels=

  if (is.null(id_col)) {
    assertthat::assert_that(all(rownames(pd) %in% colnames(counts)), msg = "Provided id_col does not match with sample names in counts.")
      samp <- data.frame("sample_id"=rownames(pd), "condition"=as.character(pd[[cond_col]]),
    samp <- data.frame(
      "sample_id" = rownames(pd), "condition" = as.character(pd[[cond_col]]),
      pd[, -c(which(colnames(pd) == cond_col)), drop = FALSE],
                         row.names = NULL, stringsAsFactors = FALSE)
      row.names = NULL, stringsAsFactors = FALSE
    )
  } else {
      samp <- data.frame("sample_id"=pd[[id_col]], "condition"=as.character(pd[[cond_col]]),
    samp <- data.frame(
      "sample_id" = pd[[id_col]], "condition" = as.character(pd[[cond_col]]),
      pd[, -c(which(colnames(pd) %in% c(id_col, cond_col))), drop = FALSE],
                         row.names = NULL, stringsAsFactors = FALSE)
      row.names = NULL, stringsAsFactors = FALSE
    )
  }
  samp$condition <- factor(samp$condition, levels = cond_levels)
  samp <- samp[samp$sample_id %in% colnames(counts), , drop = FALSE]
@@ -360,27 +364,36 @@ run_drimseq <- function(counts, tx2gene, pd, id_col=NULL, cond_col, cond_levels=
  assertthat::assert_that(all(table(samp$condition) > 0), msg = "No sample in each group left for comparison. Aborting!")

  message("\nFiltering...\n")
    filter_opt_list <- list("min_samps_gene_expr" = 0,
  filter_opt_list <- list(
    "min_samps_gene_expr" = 0,
    "min_samps_feature_expr" = 0, "min_samps_feature_prop" = 0,
    "min_gene_expr" = 0, "min_feature_expr" = 0, "min_feature_prop" = 0,
                             "run_gene_twice" = FALSE)
    "run_gene_twice" = FALSE
  )
  switch(filtering_strategy,
    sc = {
      smallest_group <- min(table(samp$condition)) * 0.05
        filter_opt_list <- utils::modifyList(filter_opt_list, list("min_samps_feature_prop" = smallest_group,
                                      "min_feature_prop" = 0.05, "run_gene_twice" = TRUE))
      filter_opt_list <- utils::modifyList(filter_opt_list, list(
        "min_samps_feature_prop" = smallest_group,
        "min_feature_prop" = 0.05, "run_gene_twice" = TRUE
      ))
    },
    bulk = {
      smallest_group <- min(table(samp$condition)) * 0.5
        filter_opt_list <- utils::modifyList(filter_opt_list,
                                      list("min_samps_gene_expr" = smallest_group,
      filter_opt_list <- utils::modifyList(
        filter_opt_list,
        list(
          "min_samps_gene_expr" = smallest_group,
          "min_gene_expr" = 5,
          "min_samps_feature_prop" = smallest_group,
                                           "min_feature_prop" = 0.05, "run_gene_twice" = TRUE))
          "min_feature_prop" = 0.05, "run_gene_twice" = TRUE
        )
      )
    },
    own = {
      filter_opt_list <- utils::modifyList(filter_opt_list, list(...))
    })
    }
  )
  # force garbage collection before RAM intensive computations.
  x <- gc(verbose = FALSE)
  BiocParallel::bpprogressbar(BPPARAM) <- TRUE
@@ -393,17 +406,20 @@ run_drimseq <- function(counts, tx2gene, pd, id_col=NULL, cond_col, cond_levels=

  tx2gene <- tx2gene[match(rownames(counts), tx2gene$feature_id), ]

    if(methods::is(counts, 'sparseMatrix')&force_dense){
  if (methods::is(counts, "sparseMatrix") & force_dense) {
    counts <- tryCatch(
      {
        as.matrix(counts)
      },
      error = function(cond) {
        message(cond)
                stop("Your sparse count matrix is probably too big and a non-sparse representation would need too much memory.",
        stop(
          "Your sparse count matrix is probably too big and a non-sparse representation would need too much memory.",
          "\nTry subsetting or filtering the sparse matrix beforehand.\n\nOperation would require approximately ",
                     format(structure(as.double(nrow(counts))*as.double(ncol(counts))*8, class="object_size"), units="auto"), " of memory.")
            })
          format(structure(as.double(nrow(counts)) * as.double(ncol(counts)) * 8, class = "object_size"), units = "auto"), " of memory."
        )
      }
    )
  }

  drim <- sparseDRIMSeq::sparse_dmDSdata(tx2gene = tx2gene, counts = counts, samples = samp)
@@ -434,10 +450,12 @@ run_drimseq <- function(counts, tx2gene, pd, id_col=NULL, cond_col, cond_levels=
  exp_in_gn <- rapply(exp_in_gn, as.character, classes = "factor", how = "replace")
  exp_in_tx <- rapply(exp_in_tx, as.character, classes = "factor", how = "replace")

    return_obj <- list("meta_table_gene"=exp_in_gn, "meta_table_tx"=exp_in_tx, "meta_table_sample"=samp,
  return_obj <- list(
    "meta_table_gene" = exp_in_gn, "meta_table_tx" = exp_in_tx, "meta_table_sample" = samp,
    "drim" = drim_test, "design_full" = design_full, "group" = group,
    "used_filtering_options" = list("DRIM" = filter_opt_list),
                       "add_pseudocount"=add_pseudocount)
    "add_pseudocount" = add_pseudocount
  )
  class(return_obj) <- append("dturtle", class(return_obj))
  return(return_obj)
}
@@ -501,10 +519,14 @@ posthoc_and_stager <- function(dturtle, ofdr=0.05, posthoc=0.1){
    message("No gene passed the screening test. If applicable try to adjust the OFDR level.")
  }

    return_obj <- append(list("sig_gene" = sig_gene, "sig_tx" = sig_tx,
                                       "FDR_table" = fdr_table), dturtle)
    return_obj$used_filtering_options$posthoc_stager <- list("ofdr" = ofdr,
                                       "posthoc"=ifelse(posthoc==FALSE, 0, posthoc))
  return_obj <- append(list(
    "sig_gene" = sig_gene, "sig_tx" = sig_tx,
    "FDR_table" = fdr_table
  ), dturtle)
  return_obj$used_filtering_options$posthoc_stager <- list(
    "ofdr" = ofdr,
    "posthoc" = ifelse(posthoc == FALSE, 0, posthoc)
  )
  class(return_obj) <- append("dturtle", class(return_obj))
  return(return_obj)
}
@@ -550,8 +572,10 @@ priming_bias_detection_probability <- function(counts, gtf, tx2gene, one_to_one=
  assertthat::assert_that(methods::is(gtf, "character") && file.exists(gtf) || methods::is(gtf, "GRanges") || is.data.frame(gtf), msg = "Invalid gtf filepath or object. Must be either a filepath to a gtf, a previously created granges object or a data frame.")
  assertthat::assert_that(methods::is(tx2gene, "data.frame"), msg = "Tx2gene must be a data frame.")
  assertthat::assert_that(ncol(tx2gene) > 1, msg = "'tx2gene' should at least have two columns [feature | gene --- in that order].")
  assertthat::assert_that((length(intersect(rownames(counts), tx2gene[[1]]))>0), msg = paste0("The provided counts names and tx2gene names do not match.\n\tCounts names: ",
                                                                                              paste0(rownames(utils::head(counts, n = 5)), collapse = ", "), "\n\tTx2gene names: ", paste0(utils::head(tx2gene, n = 5)[[1]], collapse = ", ")))
  assertthat::assert_that((length(intersect(rownames(counts), tx2gene[[1]])) > 0), msg = paste0(
    "The provided counts names and tx2gene names do not match.\n\tCounts names: ",
    paste0(rownames(utils::head(counts, n = 5)), collapse = ", "), "\n\tTx2gene names: ", paste0(utils::head(tx2gene, n = 5)[[1]], collapse = ", ")
  ))
  assertthat::assert_that(all(rownames(counts) %in% tx2gene[[1]]), msg = "Could not find all count transcript names in first column of tx2gene.")
  assertthat::assert_that(is.null(one_to_one) || isTRUE(one_to_one) || (methods::is(one_to_one, "character") && length(one_to_one) == 1), msg = "The one_to_one object must be a character vector of length 1, TRUE or NULL.")
  assertthat::assert_that(is.character(priming_enrichment) && priming_enrichment %in% c("5", "3") && length(priming_enrichment) == 1, msg = "`priming_enrichment` must be either '3' or '5'.")
+75 −69
Original line number Diff line number Diff line
@@ -25,24 +25,27 @@ sparse_filter <- function(counts, tx2gene, BPPARAM=BiocParallel::SerialParam(),

    ### genes with min expression
    if (!sum(Matrix::colSums(expr_features) >= min_gene_expr, na.rm = TRUE) >=
           min_samps_gene_expr )
      min_samps_gene_expr) {
      return(NULL)
    }

    ### features with min expression
    row_index <- Matrix::rowSums(expr_features >= min_feature_expr, na.rm = TRUE) >=
      min_samps_feature_expr

    ### no genes with one feature
        if(sum(row_index) <= 1)
    if (sum(row_index) <= 1) {
      return(NULL)
    }

    expr_features <- expr_features[row_index, , drop = FALSE]

    ### genes with zero expression
    samps2keep <- Matrix::colSums(expr_features) > 0 & !is.na(expr_features[1, ])

        if(sum(samps2keep) < max(1, min_samps_feature_prop))
    if (sum(samps2keep) < max(1, min_samps_feature_prop)) {
      return(NULL)
    }

    temp <- expr_features[, samps2keep, drop = FALSE]
    prop <- temp %*% Matrix::diag(1 / Matrix::colSums(temp), names = FALSE)
@@ -51,21 +54,24 @@ sparse_filter <- function(counts, tx2gene, BPPARAM=BiocParallel::SerialParam(),
    row_index <- Matrix::rowSums(prop >= min_feature_prop) >= min_samps_feature_prop

    ### no genes with one feature
        if(sum(row_index) <= 1)
    if (sum(row_index) <= 1) {
      return(NULL)
    }

    expr <- expr_features[row_index, , drop = FALSE]

    if (run_gene_twice) {
      ### no genes with no expression
            if(sum(expr_features, na.rm = TRUE) == 0)
      if (sum(expr_features, na.rm = TRUE) == 0) {
        return(NULL)
      }

      ### genes with min expression
      if (!sum(Matrix::colSums(expr_features) >= min_gene_expr, na.rm = TRUE) >=
               min_samps_gene_expr )
        min_samps_gene_expr) {
        return(NULL)
      }
    }
    return(rownames(expr))
  }

+270 −262
Original line number Diff line number Diff line
@@ -211,9 +211,11 @@ ratio_expression_in <- function(drim, type, BPPARAM=BiocParallel::SerialParam())
      rownames(data),
      Matrix::rowSums(data != 0) / ncol(data),
      BiocParallel::bplapply(cond, FUN = function(x) {
                              group_data = data[,drim@samples$sample_id[drim@samples$condition==x],drop=FALSE]
        group_data <- data[, drim@samples$sample_id[drim@samples$condition == x], drop = FALSE]
        return(Matrix::rowSums(group_data != 0) / ncol(group_data))
                          }, BPPARAM = BPPARAM), stringsAsFactors = FALSE)
      }, BPPARAM = BPPARAM),
      stringsAsFactors = FALSE
    )
    BiocParallel::bpstop(BPPARAM)
    colnames(ret) <- c("gene", "tx", "exp_in", paste0("exp_in_", cond))
  } else {
@@ -224,9 +226,11 @@ ratio_expression_in <- function(drim, type, BPPARAM=BiocParallel::SerialParam())
    ret <- data.frame(rownames(data),
      Matrix::rowSums(data != 0) / ncol(data),
      BiocParallel::bplapply(cond, FUN = function(x) {
                              group_data = data[,drim@samples$sample_id[drim@samples$condition==x],drop=FALSE]
        group_data <- data[, drim@samples$sample_id[drim@samples$condition == x], drop = FALSE]
        return(Matrix::rowSums(group_data != 0) / ncol(group_data))
                          }, BPPARAM = BPPARAM), stringsAsFactors = FALSE)
      }, BPPARAM = BPPARAM),
      stringsAsFactors = FALSE
    )
    BiocParallel::bpstop(BPPARAM)
    colnames(ret) <- c("gene", "exp_in", paste0("exp_in_", cond))
  }
@@ -255,7 +259,9 @@ check_unique_by_partition <- function(df, partitioning, columns=NULL){
  cols <- colnames(df)
  for (part in partitioning) {
    dat <- df[part, cols, drop = FALSE]
        cols <- cols[apply(dat, 2, function(x){all(x == x[1])})]
    cols <- cols[apply(dat, 2, function(x) {
      all(x == x[1])
    })]
    cols <- cols[!is.na(cols)]
    if (length(cols) == 0) {
      return(NULL)
@@ -316,8 +322,10 @@ get_by_partition <- function(df, partitioning, FUN, columns=NULL, simplify=TRUE,
summarize_to_gene <- function(mtx, tx2gene, fun = "sum", genes = NULL) {
  assertthat::assert_that(methods::is(mtx, "matrix") || methods::is(mtx, "sparseMatrix"), msg = "The provided mtx must be either of class matrix or sparseMatrix.")
  assertthat::assert_that(is.data.frame(tx2gene), msg = "The provided tx2gene must be a data frame.")
    assertthat::assert_that(all(rownames(mtx) %in% tx2gene[[1]]), msg=paste0("The provided names in the first tx2gene column and the data do not match. Summarising not possible.\nNames in data: ",
                                                                             paste0(utils::head(rownames(mtx)), collapse = ", "),"\nNames in tx2gene: ", paste0(utils::head(tx2gene[[1]]), collapse=", ")))
  assertthat::assert_that(all(rownames(mtx) %in% tx2gene[[1]]), msg = paste0(
    "The provided names in the first tx2gene column and the data do not match. Summarising not possible.\nNames in data: ",
    paste0(utils::head(rownames(mtx)), collapse = ", "), "\nNames in tx2gene: ", paste0(utils::head(tx2gene[[1]]), collapse = ", ")
  ))
  assertthat::assert_that(is.null(genes) || (methods::is(genes, "character") && length(genes) > 0), msg = "The genes object must be either NULL, or a character vector of length>0.")

  if (!is.null(genes)) {
Loading