Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rworkflows #105

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
^pkgdown$
^vignettes/diagrams/*\.mmd$
^vignettes/diagrams/*\.svg$
^vignettes/design\.Rmd$
^vignettes/design\.Rmd$
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/rworkflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: rworkflows
'on':
push:
branches:
- master
- main
- devel
- RELEASE_**
- rworkflows
pull_request:
branches:
- master
- main
- devel
- RELEASE_**
- rworkflows
jobs:
rworkflows:
permissions: write-all
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
container: ${{ matrix.config.cont }}
strategy:
fail-fast: ${{ false }}
matrix:
config:
- os: ubuntu-latest
bioc: devel
r: auto
cont: ghcr.io/bioconductor/bioconductor_docker:devel
rspm: ~
- os: macOS-latest
bioc: release
r: auto
cont: ~
rspm: ~
- os: windows-latest
bioc: release
r: auto
cont: ~
rspm: ~
steps:
- name: Install Python dependencies for reticulate
run: |
reticulate::install_miniconda()
reticulate::py_install(c("anndata", "scanpy"), pip = TRUE)
shell: Rscript {0}
- uses: neurogenomics/rworkflows@master
with:
run_bioccheck: ${{ true }}
run_rcmdcheck: ${{ true }}
as_cran: ${{ true }}
run_vignettes: ${{ true }}
has_testthat: ${{ true }}
run_covr: ${{ true }}
run_pkgdown: ${{ true }}
has_runit: ${{ false }}
has_latex: ${{ false }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run_docker: ${{ true }}
11 changes: 9 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: anndataR
Title: AnnData interoperability in R
Version: 0.0.0.9000
Version: 0.99.1
Authors@R: c(
person(
"Robrecht", "Cannoodt",
Expand Down Expand Up @@ -57,11 +57,14 @@ Description: Bring the power and flexibility of AnnData to the R
License: MIT + file LICENSE
URL: https://scverse.org/anndataR, https://github.com/scverse/anndataR
BugReports: https://github.com/scverse/anndataR/issues
BioViews:
Software
Depends:
R (>= 3.2.0)
R (>= 4.3.0)
Imports:
Matrix,
methods,
stats,
R6
Suggests:
anndata,
Expand All @@ -83,5 +86,9 @@ Config/Needs/website: pkgdown, tibble, knitr, rprojroot, stringr, readr,
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE, r6 = TRUE)
<<<<<<< HEAD
RoxygenNote: 7.2.3
biocViews: SingleCell, DataImport, DataRepresentation
=======
RoxygenNote: 7.2.3.9000
>>>>>>> 3a22fe5dbde8f24cb3156e150427d537c904a79c
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

export(AnnData)
export(InMemoryAnnData)
export(dummy_data)
export(from_DimReduc)
export(from_Seurat)
export(from_SingleCellExperiment)
export(read_h5ad)
<<<<<<< HEAD
export(to_DimReduc)
=======
export(setup_conda)
>>>>>>> 3a22fe5dbde8f24cb3156e150427d537c904a79c
export(to_HDF5AnnData)
export(to_InMemoryAnnData)
export(to_Seurat)
export(to_SingleCellExperiment)
export(write_h5ad)
importFrom(Matrix,as.matrix)
importFrom(Matrix,rsparsematrix)
importFrom(Matrix,sparseMatrix)
importFrom(Matrix,t)
importFrom(R6,R6Class)
importFrom(methods,as)
importFrom(stats,runif)
55 changes: 54 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
# anndataR 0.99.1

## New features

* Harmonise all references to `h5ad_file` (`file`,`h5ad_path`,`ad`)
* Harmonise all references to `ad` (`adata`)
* Use `@returns` in Roxygen notes to allow multi-line notes.
* Export helper function `dummy_data`
- Makes examples much less verbose and more consistent.
- Include "obsm","varm","obsp","varp" and "layers" wherever possible.
* *Seurat.R*
- Add/extract `DimRed` elements whenever available.
- Add unit tests for `from_Seurat`.
* New functions
- `graphs_to_anndata`: When converting Seurat --> AnnData,
store `obsp` and `varp` anndata slots from `graphs`. Does some inference
about whether each matrix should go into the `obsp` vs. `varp` slot based
on whether they have the same dimensions as the number of rows.
- `anndata_to_graphs`: When converting AnnData --> Seurat,
store `obsp` and `varp` anndata slots in `graphs`.
* *DimReduc.R*
- New functions for converting Seurat's DimReduc objects.

## Bug fixes

* *DESCRIPTION*:
- Add "email" tag to `Authors`.
- Add `BiocViews`
* Fix `BiocCheck` WARNINGS:
- `Empty or missing \value sections found in man pages.`
* Fix `BiocCheck` NOTES:
- Make all vignettes use `BiocStyle`
- `Update R version dependency from 3.2.0 to 4.3.0.`
- `'sessionInfo' not found in vignette(s)`
- `Avoid the use of 'paste' in condition signals`
- `Avoid 'cat' and 'print' outside of 'show' methods`
- `Consider adding runnable examples to man pages that document exported objects.`
- Added helper function `messager` to avoid notes about pasting inside messages.
Can also easily turn off verbosity by setting the env var "ANNDATAR_VERBOSE".
* Fix all unit tests given updates.

# anndataR 0.99.0

## New features

- Add `rworkflows` CI.
- Update *lint.yaml* to use `actions/checkout@v4` (which has less issues).
- New function `setup_conda` automatically installs miniconda
and sets up conda env: #97
- Change version to Bioc-recommended devel version: 0.99.0

# anndataR 0.1.0

## New features

bschilder marked this conversation as resolved.
Show resolved Hide resolved
Initial release of anndataR, providing support for working with AnnData objects in R.

Feature list:
Expand All @@ -18,4 +71,4 @@ Feature list:

* Converters:
- SingleCellExperiment
- Seurat
- Seurat
62 changes: 42 additions & 20 deletions R/AbstractAnnData.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#' Abstract [R6][R6::R6Class] class representing an AnnData
#' object. Defines the interface.
#' @importFrom R6 R6Class
#' @returns An [R6][R6::R6Class] object of class "AbstractAnnData".
AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
active = list(
#' @field X NULL or an observation x variable matrix (without
Expand Down Expand Up @@ -77,8 +78,9 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
#' computationally expensive.
#' @param ... Optional arguments to print method.
print = function(...) {
cat("AnnData object with n_obs \u00D7 n_vars = ", self$n_obs(), " \u00D7 ", self$n_vars(), "\n", sep = "")

messager("AnnData object with n_obs \u00D7 n_var =",
self$n_obs(), "\u00D7 ",
self$n_var(), "\n")
for (attribute in c(
"obs",
"var",
Expand All @@ -97,7 +99,7 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
NULL
}
if (length(keys) > 0) {
cat(
messager(
" ", attribute, ":",
paste("'", keys, "'", collapse = ", "),
"\n",
Expand All @@ -111,15 +113,15 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
shape = function() {
c(
self$n_obs(),
self$n_vars()
self$n_var()
)
},
#' @description Number of observations in the AnnData object.
n_obs = function() {
length(self$obs_names)
},
#' @description Number of variables in the AnnData object.
n_vars = function() {
n_var = function() {
length(self$var_names)
},
#' @description Keys ('column names') of `obs`.
Expand Down Expand Up @@ -180,20 +182,22 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
if (nrow(mat) != self$n_obs()) {
stop("nrow(", label, ") should be the same as nrow(obs)")
}
if (ncol(mat) != self$n_vars()) {
if (ncol(mat) != self$n_var()) {
stop("ncol(", label, ") should be the same as nrow(var)")
}

if (!is.null(rownames(mat))) {
warning(wrap_message(
"rownames(", label, ") should be NULL, removing them from the matrix"
"rownames(", label,
") should be NULL, removing them from the matrix"
))
rownames(mat) <- NULL
}

if (!is.null(colnames(mat))) {
warning(wrap_message(
"colnames(", label, ") should be NULL, removing them from the matrix"
"colnames(", label,
") should be NULL, removing them from the matrix"
))
colnames(mat) <- NULL
}
Expand All @@ -211,13 +215,18 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
# @param shape Expected dimensions of matrix
# @param expected_rownames
# @param excepted_colnames
.validate_aligned_array = function(mat, label, shape, expected_rownames = NULL, expected_colnames = NULL) {
.validate_aligned_array = function(mat,
label,
shape,
expected_rownames = NULL,
expected_colnames = NULL) {
mat_dims <- dim(mat)
for (i in seq_along(shape)) {
expected_dim <- shape[i]
found_dim <- mat_dims[i]
if (found_dim != expected_dim) {
stop("dim(", label, ")[", i, "] should have shape: ", expected_dim, ", found: ", found_dim, ".")
stop("dim(", label, ")[", i, "] should have shape: ",
expected_dim, ", found: ", found_dim, ".")
}
}
if (!is.null(expected_rownames) & !is.null(rownames(mat))) {
Expand Down Expand Up @@ -250,17 +259,25 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
# @param collection A named list of 0 or more matrix elements with
# whose entries will be validated
# @param label The label of the collection, used for error messages
# @param shape Expected dimensions of arrays. Arrays may have more dimensions than specified here
# @param shape Expected dimensions of arrays. Arrays may have more
# dimensions than specified here
# @param expected_rownames
# @param expected_colnames
.validate_aligned_mapping = function(collection, label, shape, expected_rownames = NULL, expected_colnames = NULL) {
.validate_aligned_mapping = function(collection,
label,
shape,
expected_rownames = NULL,
expected_colnames = NULL) {
if (is.null(collection)) {
return(collection)
}

collection_names <- names(collection)
if (!is.list(collection) || ((length(collection) != 0) && is.null(collection_names))) {
stop(paste0(label, " must be a named list, was ", class(collection)))
if (!is.list(collection) ||
((length(collection) != 0) &&
is.null(collection_names))) {
stp <- paste0(label, " must be a named list, was ", class(collection))
stop(stp)
}

for (mtx_name in collection_names) {
Expand All @@ -286,7 +303,7 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint

expected_nrow <- switch(label,
obs = self$n_obs(),
var = self$n_vars()
var = self$n_var()
)

if (is.null(df)) {
Expand All @@ -308,7 +325,8 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint

if (.row_names_info(df) > 0) {
warning(wrap_message(
"'", label, "' should not have any rownames, removing them from the data frame."
"'", label,
"' should not have any rownames, removing them from the data frame."
))
rownames(df) <- NULL
}
Expand All @@ -320,22 +338,26 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
# are NULL or consistent with the dimensions of `obs` or `var`.
# @param names A vector to validate
# @param label Must be `"obs"` or `"var"`
.validate_obsvar_names = function(names, label = c("obs", "var"), check_length = TRUE) {
.validate_obsvar_names = function(names,
label = c("obs", "var"),
check_length = TRUE) {
label <- match.arg(label)

if (is.null(names)) {
stop(wrap_message(label, "_names should be defined."))
}

# only check whether sizes match if the obsvar names has already been defined
# only check whether sizes match if the obsvar names has
# already been defined.
prev_names <- attr(self, paste0(label, "_names"))
if (!is.null(prev_names)) {
expected_len <- length(prev_names)

if (length(names) != expected_len) {
size_check_label <- if (label == "obs") "n_obs" else "n_vars"
size_check_label <- if (label == "obs") "n_obs" else "n_var"
stop(wrap_message(
"length(", label, "_names) should be the same as ad$", size_check_label, "()"
"length(", label, "_names) should be the same as ad$",
size_check_label, "()"
))
}
}
Expand Down
Loading
Loading