Read, write, and create single-cell data objects using Seurat (R) and Scanpy (Python). Use for loading 10X Genomics data, importing/exporting h5ad and RDS files, creating Seurat objects and AnnData objects, and converting between formats. Use when loading, saving, or converting single-cell data formats.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Read, write, and create single-cell data objects using Seurat (R) and Scanpy (Python). Use for loading 10X Genomics data, importing/exporting h5ad and RDS files, creating Seurat objects and AnnData objects, and converting between formats. Use when loading, saving, or converting single-cell data formats.
Before using code patterns, verify installed versions match. If versions differ:
Python: pip show <package> then help(module.function) to check signatures
R: packageVersion('<pkg>') then ?function_name to verify parameters
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
Single-Cell Data I/O
Read, write, and create single-cell data objects for analysis.
Scanpy (Python)
Goal: Load, create, and save single-cell data objects using Scanpy and AnnData.
Approach: Read 10X Genomics output, CSV, or Loom formats into AnnData objects, manipulate metadata and layers, and write to h5ad format.
"Load my 10X data" → Read Cell Ranger output directory or h5 file into an AnnData object with expression matrix, cell barcodes, and gene annotations.
Required Imports
import scanpy as sc
import anndata as ad
import pandas as pd
import numpy as np
import anndata as ad
import numpy as np
import pandas as pd
counts = np.random.poisson(1, size=(100, 500)) # 100 cells x 500 genes
cell_ids = [f'cell_{i}'for i inrange(100)]
gene_ids = [f'gene_{i}'for i inrange(500)]
adata = ad.AnnData(
X=counts,
obs=pd.DataFrame(index=cell_ids),
var=pd.DataFrame(index=gene_ids)
)
Reading/Writing h5ad Files
# h5ad is the native AnnData format
adata = sc.read_h5ad('data.h5ad')
# Write to h5ad
adata.write_h5ad('output.h5ad')
# Write compressed
adata.write_h5ad('output.h5ad', compression='gzip')
Reading Other Formats
# CSV/TSV (genes as columns, cells as rows)
adata = sc.read_csv('counts.csv')
# Loom format
adata = sc.read_loom('data.loom')
# Text file (tab-separated)
adata = sc.read_text('counts.txt')
# Store raw counts before normalization
adata.raw = adata.copy()
# Access raw counts later
raw_counts = adata.raw.X
# Or use layers
adata.layers['counts'] = adata.X.copy()
Seurat (R)
Goal: Load, create, and save single-cell data objects using Seurat.
Approach: Read 10X Genomics output into Seurat objects, manipulate metadata, merge samples, and serialize with RDS or h5Seurat formats.