-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.Rmd
99 lines (72 loc) · 3.49 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
output:
github_document:
html_preview: false
bibliography: man/readme_files/references.bib
---
```{r setup1, include=FALSE}
library(tidyverse)
set.seed(1)
```
# anndata for R
<!-- badges: start -->
[![CRAN](https://www.r-pkg.org/badges/version/anndata)](https://cran.r-project.org/package=anndata)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/anndata)](https://cran.r-project.org/package=anndata)
[![R-CMD-check](https://github.com/dynverse/anndata/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dynverse/anndata/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://app.codecov.io/gh/dynverse/anndata/branch/main/graph/badge.svg)](https://app.codecov.io/gh/dynverse/anndata?branch=main)
<!-- badges: end -->
[`anndata`](https://anndata.readthedocs.io/en/latest/) is a commonly used Python package
for keeping track of data and learned annotations, and can be used to read from and write to the h5ad
file format. It is also the main data format used in the scanpy python package [@wolf_scanpylargescalesinglecell_2018].
![](https://raw.githubusercontent.com/dynverse/anndata/master/man/readme_files/anndata_for_r.png)
However, using scanpy/anndata in R can be a major hassle. When trying to read an h5ad file,
R users could approach this problem in one of two ways. A) You could read in the file manually
(since it's an H5 file), but this involves a lot of manual work and a lot of understanding
on how the h5ad and H5 file formats work (also, expect major headaches from cryptic hdf5r bugs).
Or B) interact with scanpy and anndata through reticulate, but run into issues converting
some of the python objects into R.
We recently published [`anndata`](https://cran.r-project.org/package=anndata) on CRAN,
which is a reticulate wrapper for the Python package -- with some syntax sprinkled on top to make
R users feel more at home.
anndata for R is still under active development at [github.com/dynverse/anndata](https://github.com/dynverse/anndata).
If you encounter any issues, feel free to post an issue on GitHub!
## Installation
You can install `anndata` for R from CRAN as follows:
```r
install.packages("anndata")
```
Normally, reticulate should take care of installing Miniconda and the Python anndata.
If not, try running:
```r
reticulate::install_miniconda()
anndata::install_anndata()
```
## Getting started
The API of anndata for R is very similar to its Python counterpart. Here is an example:
```{r}
library(anndata)
ad <- read_h5ad("example_formats/pbmc_1k_protein_v3_processed.h5ad")
ad
Matrix::rowMeans(ad$X[1:10, ])
```
See `?anndata` for a full list of the functions provided by this package.
Check out any of the other vignettes by clicking any of the links below:
```{r vignettes, results='asis', echo=FALSE}
walk(
list.files("vignettes", pattern = "*.Rmd", recursive = TRUE),
function(file) {
title <-
read_lines(paste0("vignettes/", file)) %>%
keep(~ grepl("^title: ", .)) %>%
gsub("title: \"(.*)\"", "\\1", .)
vignette_name <- gsub("\\.Rmd", "", file)
html_name <- gsub("\\.Rmd", ".html", file)
cat("* [", title, "](https://anndata.dynverse.org/articles/", html_name, ")\n", sep = "")
}
)
```
## Future work
In some cases, this package may still act more like a Python package rather than an R package.
Some more helper functions and helper classes need to be defined in order to fully encapsulate
`AnnData()` objects. Examples are `ad$chunked_X(...)`, backed file modes, `read_zarr()` and `ad$write_zarr()`.
## References