Skip to content

Commit 00c6845

Browse files
committed
add vignette
1 parent 8682f53 commit 00c6845

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

vignettes/usage_python.Rmd

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: "Python Integration with anndataR"
3+
output: rmarkdown::html_vignette
4+
vignette: >
5+
%\VignetteIndexEntry{Python Integration with anndataR}
6+
%\VignetteEngine{knitr::rmarkdown}
7+
%\VignetteEncoding{UTF-8}
8+
---
9+
10+
```{r, include = FALSE}
11+
knitr::opts_chunk$set(
12+
collapse = TRUE,
13+
comment = "#>"
14+
)
15+
```
16+
17+
## Introduction
18+
19+
anndataR works with Python AnnData objects through reticulate.
20+
You can load Python objects, apply Python functions to them, and
21+
convert to Seurat or SingleCellExperiment objects without manual conversion steps.
22+
23+
## Basic Integration with Scanpy
24+
25+
Install required Python packages if needed:
26+
27+
```{r python_setup, eval=FALSE}
28+
reticulate::py_install("scanpy")
29+
```
30+
31+
```{r load_libraries}
32+
library(anndataR)
33+
library(reticulate)
34+
sc <- import("scanpy")
35+
```
36+
37+
Load a dataset directly from scanpy:
38+
39+
```{r load_python_data}
40+
adata <- sc$datasets$pbmc3k_processed()
41+
print(adata)
42+
```
43+
44+
Apply scanpy functions directly:
45+
46+
```{r apply_python_functions}
47+
sc$pp$filter_cells(adata, min_genes = 200L)
48+
sc$pp$normalize_total(adata, target_sum = 1e4)
49+
sc$pp$log1p(adata)
50+
```
51+
52+
Convert to Seurat object:
53+
54+
```{r convert_to_seurat}
55+
seurat_obj <- adata$as_Seurat()
56+
print(seurat_obj)
57+
```
58+
59+
Convert to SingleCellExperiment object:
60+
61+
```{r convert_to_sce}
62+
sce_obj <- adata$as_SingleCellExperiment()
63+
print(sce_obj)
64+
```
65+
66+
## Multi-modal Data with MuData
67+
68+
Install required Python packages if needed:
69+
70+
```{r mudata_setup, eval=FALSE}
71+
reticulate::py_install("mudata")
72+
```
73+
74+
```{r load_mudata}
75+
md <- import("mudata")
76+
```
77+
78+
Load a MuData object from file:
79+
80+
```{r load_mudata_example}
81+
url <- "https://github.com/gtca/h5xx-datasets/raw/b1177ac8877c89d8bb355b072164384b4e9cc81d/datasets/minipbcite.h5mu"
82+
path <- tempfile(fileext = ".h5mu")
83+
download.file(url, path)
84+
mdata <- md$read_h5mu(path)
85+
```
86+
87+
Access individual modalities and convert them:
88+
89+
```{r access_modalities}
90+
rna_mod <- mdata$mod[["rna"]]
91+
92+
rna_seurat <- rna_mod$as_Seurat()
93+
print(rna_seurat)
94+
95+
rna_sce <- rna_mod$as_SingleCellExperiment()
96+
print(rna_sce)
97+
```
98+

0 commit comments

Comments
 (0)