Skip to content

Commit

Permalink
Merge pull request #139 from cnio-bu/rc2_2
Browse files Browse the repository at this point in the history
Update beyondcell to version 2.2.0
  • Loading branch information
SGMartin authored Aug 7, 2023
2 parents c280bd8 + 5b739e3 commit 9e06657
Show file tree
Hide file tree
Showing 33 changed files with 401 additions and 475 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/conda_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ jobs:
- name: Archive beyondcell package for GNU/Linux
uses: actions/upload-artifact@v3
with:
name: Linux_r-beyondcell-v2.1.0
path: /usr/share/miniconda3/envs/bc_builds/conda-bld/linux-64/r-beyondcell-2.1.0-r42_0.tar.bz2
name: Linux_r-beyondcell-v2.2.0
path: /usr/share/miniconda3/envs/bc_builds/conda-bld/linux-64/r-beyondcell-2.2.0-r43_0.tar.bz2

- name: Archive beyondcell package for macOS
uses: actions/upload-artifact@v3
with:
name: macOS_r-beyondcell-v2.1.0
path: /Users/runner/miniconda3/envs/bc_builds/conda-bld/osx-64/r-beyondcell-2.1.0-r42_0.tar.bz2
name: macOS_r-beyondcell-v2.2.0
path: /Users/runner/miniconda3/envs/bc_builds/conda-bld/osx-64/r-beyondcell-2.2.0-r43_0.tar.bz2
4 changes: 3 additions & 1 deletion .github/workflows/helpers/mambabuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ channels:
- defaults

dependencies:
- boa=0.6.2
- boa

channel_priority: strict
2 changes: 1 addition & 1 deletion .github/workflows/r-beyondcell/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set version = '2.1.0' %}
{% set version = '2.2.0' %}
{% set name = "beyondcell" %}
{% set posix = 'm2-' if win else '' %}
{% set native = 'm2w64-' if win else '' %}
Expand Down
Binary file modified .img/drug_signatures.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .img/workflow_tutorial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# [2.2.0] - 2023-07-06
* **Fixed** an issue ([#132](https://github.com/cnio-bu/beyondcell/issues/132)) where `bcScore`'s check for normalized data failed.
* **Fixed** an issue ([#135](https://github.com/cnio-bu/beyondcell/issues/135)) where `bcRanks` was not computing the residual's mean.
* **Updated** tutorials.
* **Removed** `bcRanks` "general" statistics computation.
* **Removed** `GetStatistics` function.

# [2.1.0] - 2023-03-31
* **Fixed** error in `bcClusters` and `bcSignatures` when `spatial = TRUE` and `images = NULL`.
* **Fixed** title error in `bc4Squares`. The curent title matches the corresponding `idents` level.
* **Fixed** an error in `bcClusters` and `bcSignatures` when `spatial = TRUE` and `images = NULL`.
* **Fixed** title error in `bc4Squares`. The current title matches the corresponding `idents` level.
* **Fixed** error in `bc4Squares` when drug names were passed as `topnames`.
* **Updated** pre-loaded collections, which have been trimmed to 250 up and 250 down genes.
* **Updated** SSc collection, which only contains protein-coding genes.
Expand All @@ -22,17 +29,17 @@
* **Removed** the `method` argument from `bcUMAP`. Only the UWOT library implementation of UMAP is available.

# [1.3.3] - 2022-01-12
* **Fixed** an error in `bcSubset` when filtering by the proportion of `NaN` values. Previously, the beyondcell object wasn't subset when using `nan.sigs` or `nan.cells`. Now those signatures/cells below or equal to the `NaN` threshold are kept. Related to issue #21.
* **Fixed** an error in `bcSubset` when filtering by the proportion of `NaN` values. Previously, the beyondcell object wasn't a subset when using `nan.sigs` or `nan.cells`. Now those signatures/cells below or equal to the `NaN` threshold are kept. Related to issue #21.

# [1.3.2] - 2021-12-20
* **Fixed** an issue (#17) where if all the cells have a number of expressed genes < `expr.thres`,
* **Fixed** an issue ([#17](https://github.com/cnio-bu/beyondcell/issues/17)) where if all the cells have a number of expressed genes < `expr.thres`,
all the values for that signature will be `NaN` and so will be the switch point.

# [1.3.1] - 2021-09-9
* **Added** group annotation to rank tables: high/low/differential sensitivity is now defined for each tested drug.

# [1.2.1] - 2021-06-29
* **Fixed** an issue (#14) where `bcSignatures` would fail when used with pathways
* **Fixed** an issue ([#14](https://github.com/cnio-bu/beyondcell/issues/14)) where `bcSignatures` would fail when used with pathways

# [1.2.0] - 2021-06-8
* **Fixed** an issue where `bcMerge` would fail if the background matrix was empty.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: beyondcell
Title: A Tool for the Analysis of Tumour Therapeutic Heterogeneity in
single-cell RNA-seq and Spatial Transcriptomics
Version: 2.1.0
Version: 2.2.0
Authors@R: c(
person("Maria Jose", "Jimenez-Santos", , "[email protected]", role = c("aut", "cre")),
person("Santiago", "Garcia-Martin", , "[email protected]", role = "aut"),
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export(FindDrugs)
export(GenerateGenesets)
export(GetCollection)
export(GetIDs)
export(GetStatistics)
export(ListFilters)
export(Mean.Med.SD)
export(SwitchPoint)
Expand All @@ -34,9 +33,11 @@ import(Seurat)
import(ggplot2)
import(scales)
import(stringr)
import(tidyverse)
importFrom(DMwR,knnImputation)
importFrom(RColorBrewer,brewer.pal)
importFrom(cowplot,theme_cowplot)
importFrom(data.table,frank)
importFrom(dplyr,left_join)
importFrom(ggrepel,geom_text_repel)
importFrom(grDevices,colorRampPalette)
Expand Down
159 changes: 0 additions & 159 deletions R/Basics.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,165 +82,6 @@ Mean.Med.SD <- function(x) {
c("mean", "median", "sd")))
}

#' @title Computes the BCS' statistics and ranks
#' @description This function computes the beyondcell scores' (BCS) statistics
#' and ranks returned by \code{\link[beyondcell]{bcRanks}}.
#' @name GetStatistics
#' @param bc \code{\link[beyondcell]{beyondcell}} object.
#' @param signatures Vector with the names of the signatures of interest.
#' @param cells Vector with the names of the cells of interest.
#' @param pb \code{\link[utils]{txtProgressBar}}.
#' @param total Number of iterations to complete the \code{pb}.
#' @param i Iteration number. Used to increase the \code{pb}.
#' @param n.rows Number of signatures. Used to increase the \code{pb}.
#' @param extended If \code{extended = TRUE}, this function returns the switch
#' point, mean, median, sd, variance, min, max, proportion of \code{NaN} and
#' residuals' mean per signature. If \code{extended = FALSE}, this function
#' returns only the switch point, mean and residuals' mean.
#'
#' @return A \code{data.frame} with the BCS' statistics and ranks.
#' @examples
#' @export

GetStatistics <- function(bc, signatures, cells, pb, total, i, n.rows,
extended) {
# --- Checks ---
# Check that bc is a beyondcell object.
if (class(bc) != "beyondcell") stop('bc must be a beyondcell object.')
# Check signatures.
in.signatures <- !is.null(signatures) & signatures %in% rownames(bc@normalized)
if (all(!in.signatures)) {
stop('None of the specified signatures were found.')
} else if (any(!in.signatures)) {
warning(paste0('These signatures were not found in bc: ',
paste0(signatures[!in.signatures], collapse = ", "), '.'))
}
# Check cells.
in.cells <- !is.null(cells) & cells %in% colnames(bc@normalized)
if (all(!in.cells)) {
stop('None of the specified cells were found.')
} else if (any(!in.cells)) {
warning(paste0('These cells were not found in bc: ',
paste0(cells[!in.cells], collapse = ", "), '.'))
}
# Check pb.
if (class(pb) != "txtProgressBar") stop('pb must be a txtProgressBar object.')
# Check total.
if (length(total) != 1 | total[1] <= 0 | total[1]%%1 != 0) {
stop('total must be a positive integer.')
}
# Check i.
if (length(i) != 1 | i[1] <= 0 | i[1]%%1 != 0) {
stop('i must be a positive integer.')
}
# Check n.rows.
if (length(n.rows) != 1 | n.rows[1] <= 0 | n.rows[1]%%1 != 0) {
stop('n.rows must be a positive integer.')
}
# Check extended.
if (length(extended) != 1 | !is.logical(extended[1])) {
stop('extended must be TRUE or FALSE.')
}
# --- Code ---
# Signatures and cells.
signatures <- signatures[in.signatures]
cells <- cells[in.cells]
# Bins: Number of iterations to complete each 1% of the progress bar.
bins <- ceiling(total / 100)
# Switch points per signature.
switch.p <- bc@switch.point[signatures]
if (extended) {
# Dataframe with mean, median and sd per signature.
data <- cbind(seq_len(n.rows) + (n.rows * 6) * (i - 1),
bc@normalized[signatures, cells])
mean.med.sd <- as.data.frame(t(apply(data, 1, function(u) {
mms <- round(Mean.Med.SD(u[-1]), digits = 2)
### Update the progress bar.
if (u[1]%%bins == 0) {
Sys.sleep(0.1)
setTxtProgressBar(pb, value = u[1])
}
return(mms)
})))
# Variance per signature.
data[, 1] <- data[, 1] + n.rows
variance.bcscore <- apply(data, 1, function(v) {
variance <- var(v[-1], na.rm = TRUE)
### Update the progress bar.
if (v[1]%%bins == 0) {
Sys.sleep(0.1)
setTxtProgressBar(pb, value = v[1])
}
return(variance)
})
# Min normalized BCS per signature.
data[, 1] <- data[, 1] + n.rows
min.bcscore <- apply(data, 1, function(w) {
min.bcs <- min(w[-1], na.rm = TRUE)
### Update the progress bar.
if (w[1]%%bins == 0) {
Sys.sleep(0.1)
setTxtProgressBar(pb, value = w[1])
}
return(min.bcs)
})
# Max normalized BCS per signature.
data[, 1] <- data[, 1] + n.rows
max.bcscore <- apply(data, 1, function(x) {
max.bcs <- max(x[-1], na.rm = TRUE)
### Update the progress bar.
if (x[1]%%bins == 0) {
Sys.sleep(0.1)
setTxtProgressBar(pb, value = x[1])
}
return(max.bcs)
})
# NA proportion per signature.
data[, 1] <- data[, 1] + n.rows
prop.na <- apply(data, 1, function(y) {
nas <- round(sum(is.na(y[-1]))/length(y[-1]), digits = 2)
### Update the progress bar.
if (y[1]%%bins == 0) {
Sys.sleep(0.1)
setTxtProgressBar(pb, value = y[1])
}
return(nas)
})
# Residuals.
normalized <- cbind(seq_len(n.rows) + (n.rows * i * 5) + (n.rows * (i - 1)),
bc@normalized[signatures, cells])
# Create dataframe.
stats <- data.frame(switch.point = switch.p, mean = mean.med.sd$mean,
median = mean.med.sd$median, sd = mean.med.sd$sd,
variance = variance.bcscore, min = min.bcscore,
max = max.bcscore, prop.na = prop.na,
row.names = signatures)
} else {
# Mean BCS per signature.
mean.bc <- round(rowMeans(bc@normalized[signatures, cells], na.rm = TRUE),
digits = 2)
# Residuals.
normalized <- cbind(seq_len(n.rows) + (n.rows * (i - 1)),
bc@normalized[signatures, cells])
# Create dataframe.
stats <- data.frame(switch.point = switch.p, mean = mean.bc,
row.names = signatures)
}
# Residuals' mean.
resid <- apply(normalized, 1, function(z) {
res <- round(mean(z[-1], na.rm = TRUE), digits = 2)
### Update the progress bar.
if (z[1]%%bins == 0 | z[1] == total) {
Sys.sleep(0.1)
setTxtProgressBar(pb, value = z[1])
}
return(res)
})
# Update dataframe.
stats <- cbind(stats, data.frame(residuals.mean = resid, row.names = signatures))
return(stats)
}

#' @title Returns the IDs that match the specified filter's values
#' @description This function subsets \code{df} to select only the entries that
#' match the specified \code{filter}'s \code{values} and returns the
Expand Down
Loading

0 comments on commit 9e06657

Please sign in to comment.