A python package for generating 10x cloupe files from anndata objects
Project description
from loupepy import get_count_matrixWhile this tool is independently maintained and not officially supported by 10x Genomics, it relies on code from LoupeR, an R package developed by 10x Genomics. LoupeR is licensed for use only in connection with data generated from 10x Genomics products. For more information, please refer to the 10x End User Software License. By using the setup function of this tool, you will need to agree to this license with an interactive prompt.
Main Functions
create_loupe_from_anndata(anndata, output_cloupe="cloupe.cloupe", layer=None, ...)
Creates a Loupe Browser compatible .cloupe file from an AnnData object.
Parameters:
anndata: AnnData object containing single-cell dataoutput_cloupe: Path to save the output file (default: "cloupe.cloupe")layer: Layer in AnnData to use for counts (default: None, uses.X)dims: List of dimension reduction keys fromadata.obsm(default: None, uses all valid projections)obs_keys: List of categorical annotations fromadata.obsto include (default: None, uses all valid categories)strict_checking: Whether to strictly validate inputs (default: False)tmp_file: Temporary file path for intermediate data (default: 'tmp.h5')dims: List of dimension reduction keys fromadata.obsmto include (default: None, uses all valid projections)obs_keys: List of categorical annotations fromadata.obsto include (default: None, uses all valid categories)loupe_converter_path: Path to the Loupe converter binary (default: None, uses default installation path)clean_tmp_file: Whether to delete the temporary file after creation (default: True)force: Whether to overwrite existing cloupe file (default: False)test_mode: Whether to run in test mode. Will not create a cloupe file.
Example:
import scanpy as sc
import loupepy
from scipy.sparse import diags
# Load data
adata = sc.datasets.pbmc3k_processed().raw.to_adata()
# Revert to raw counts, as loupee converter only takes raw counts
n_counts = adata.obs["n_counts"].values
counts_matrix = adata.X.expm1()
counts = diags(n_counts) * counts_matrix
adata.X = counts
# Create Loupe file with default settings
loupepy.create_loupe_from_anndata(adata, "my_results.cloupe")
# Create with specific dimensions and annotations
loupepy.create_loupe_from_anndata(
adata,
"my_custom_results.cloupe",
dims=["X_umap"],
obs_keys=["leiden"]
)
Utility Functions
get_obs(anndata, obs_keys=None, strict=False)
Extracts categorical observation data from an AnnData object.
Parameters:
anndata: AnnData object containing the dataobs_keys: List of keys to extract fromadata.obs(default: None, uses all valid categories)strict: Whether to strictly validate the keys. If true will throw errors on invalid keys instead of dropping (default: False)
get_obsm(anndata, obsm_keys=None, strict=False)
Extracts dimensional reduction data from an AnnData object. Parameters:
anndata: AnnData object containing the dataobsm_keys: List of keys to extract fromadata.obsm(default: None, uses all valid dimension reductions)strict: Whether to strictly validate the keys. If true will throw errors on invalid keys instead of dropping (default: False)
get_count_matrix(anndata, layer=None)
Gets the count matrix from an AnnData object in the format required for Loupe.
Parameters:
anndata: AnnData object containing the datalayer: Layer in AnnData to use for counts (default: None, uses.X)
create_loupe(mat, obs, var, obsm, tmp_file, ...)
Lower-level function to create a Loupe file from raw data components.
Parameters:
mat: CSC matrix of counts (shape: n_features × n_cells)obs: DataFrame of categorical cell annotationsvar: DataFrame of gene/feature informationobsm: Dictionary of dimension reduction embeddingstmp_file: Path for temporary fileoutput_path: Path to save the output filestrict_checking: Whether to strictly validate inputs (default: False)loupe_converter_path: Path to the Loupe converter binary (default: None, uses default installation path)'clean_tmp_file: Whether to delete the temporary file after creation (default: True)force: Whether to overwrite existing cloupe file (default: False)test_mode: Whether to run in test mode. Will not create a cloupe file.
Example:
import scanpy as sc
import loupepy
from scipy.sparse import diags
# Load data
adata = sc.datasets.pbmc3k_processed().raw.to_adata()
# Revert to raw counts, as loupee converter only takes raw counts
n_counts = adata.obs["n_counts"].values
counts_matrix = adata.X.expm1()
counts = diags(n_counts) * counts_matrix
adata.X = counts
mat = loupepy.get_count_matrix(adata)
obs = loupepy.get_obs(adata, obs_keys=["leiden"])
var = adata.var
obsm = loupepy.get_obsm(adata, obsm_keys=["X_umap"])
loupepy.create_loupe(mat,obs,var,obsm,"my_results.cloupe")
Setup Functions
setup(path=None)
Downloads and installs the Loupe converter binary.
Parameters:
path: Installation directory path (default: None, uses OS-specific default location)
Example:
import loupepy
# Install the Loupe converter to the default location
loupepy.setup()
eula(path=None)
Parameters:
path: Installation path (default: None, uses OS-specific default install location. Usually same path as setup)
eula_reset(path=None)
Resets the EULA agreement and removes the installed Loupe converter binary.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loupepy-0.1.0.tar.gz.
File metadata
- Download URL: loupepy-0.1.0.tar.gz
- Upload date:
- Size: 30.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e32cbe557fc01467055881f9987b2fcce8e36e31324a2d47935529d4977eac6e
|
|
| MD5 |
ab72f02e786a084d30590cbbc26e8ece
|
|
| BLAKE2b-256 |
2c474c7ee349a090ed726c447bed8e03cdc01ed83c0a786c19b040f6a79c4ed8
|
File details
Details for the file loupepy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: loupepy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94ea0bf2fda7d35b4b55cbd7b771b88130043af2cd3222ee10778e0f94f15c5c
|
|
| MD5 |
ed760ab5b65a9a60c95e1417e678f3a8
|
|
| BLAKE2b-256 |
eb31daa4852119a820088b0bbc5061fd4751003116c25d7bdb3da0a7330d6155
|