Skip to content
datavilPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

124 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kyto

Lazy, streaming single-cell analysis, written in Rust, used from Python. Results match scanpy on the reference fixtures; the matrix is read in blocks, within a stated memory limit.

Chained methods build a plan and read nothing. Only the terminals (collect, sink_*, pull, select, to_*) run it. Every method returns a new plan; layers, seeds, devices and memory limits are arguments, never global settings. The rules are in AGENTS.md; the roadmap is Implementation Plan.md.

Pipeline

The first steps of scanpy's PBMC 3k tutorial. kyto.convert turns an .h5ad, 10x .h5 or Matrix Market file into a kyto store first: ky.convert("pbmc3k.h5ad", "pbmc3k.kyto", layer="counts").

import kyto as ky
from kyto import cell_column, gene_column, qc

atlas = ky.scan("pbmc3k.kyto").with_default_layer("counts")
mito = gene_column("symbol").str.starts_with("MT-")
hvg = (
    atlas.with_cells(
        n_genes_by_counts=qc.genes_detected(),
        total_counts=qc.total_counts(),
        pct_counts_mt=qc.percent_counts_in(mito),
    )
    .filter(
        (cell_column("n_genes_by_counts") >= 200)
        & (cell_column("n_genes_by_counts") < 2500)
        & (cell_column("pct_counts_mt") < 5)
    )
    .normalize_total(1e4)  # writes the layer "normalized"
    .log1p()  # reads "normalized", writes "log1p"
    .highly_variable_genes(n_top_genes=2000)  # reads "log1p"
    .filter(gene_column("highly_variable"))
)
print(hvg.explain())  # the logical and optimized plans; nothing is read yet
print(hvg.estimate())  # bytes read, peak memory and passes, before running
hvg.sink_zarr("pbmc3k_hvg.kyto", memory_limit="1GB")  # runs the plan

result = ky.scan("pbmc3k_hvg.kyto").with_default_layer("log1p")
markers = (
    result.with_cells(high_counts=cell_column("total_counts") > 2500)
    .rank_genes_groups("high_counts", method="wilcoxon", n_genes=5)
    .collect()  # a polars.DataFrame
)
print(markers)

# PCA and neighbours build lazily too (sinks write their outputs; reading them from Python arrives with 7.3).
graph = result.pca(
    n_components=50, seed=0
).neighbors()  # into "X_pca", then searches it
print(graph.estimate())

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages