Skip to main content

gset

GSET (Gene Signals from Embedding Trajectories) is a Python package that selects a compact set of genes from time-resolved single-cell data. The selected genes are meant as the gene context of a mechanistic gene regulatory network (GRN) inference method such as CardamomOT, whose cost grows quickly with the number of genes.

The method follows every gene along two embedding trajectories. A co-expression embedding (a graph neural network on the co-expression graph of each timepoint) shows the changes of the co-expression neighbourhood of a gene, measured by a KL divergence. An embedding of the expression distribution (a DeepSets encoder) shows the changes of the activity of a gene, measured by an optimal transport (OT) residual, which is the displacement of a gene after the global movement of all genes is removed. The genes are grouped into programs, and lagged comparisons of the two signals between consecutive programs retrieve the bridge genes that link them.

Main functionalities:

  1. Gene programs from the temporal co-expression embeddings;
  2. Bridge genes between consecutive programs, from the KL signal without lag and the OT signal with lag 1;
  3. A compact gene set of a given size: the bridge genes and the core genes of the programs.

Installation

pip install gset

Python 3.11 or newer. The package depends on numpy, scipy, pandas, scikit-learn, torch, torch_geometric and pot. anndata is needed to read an AnnData object.

Basic usage

import anndata as ad
from gset import select_genes

adata = ad.read_h5ad("my_data.h5ad")    # raw counts in X, the time of every cell in adata.obs["time"]
genes = adata.var_names[select_genes(adata, budget=30, n_programs=3)]

select_genes returns the indices of the selected genes, sorted. By default a third of the budget goes to the core genes of the programs and two thirds to the bridge genes, and the programs are found by clustering, with their number given.

About the data

The data are single-cell snapshots of the same genes at several timepoints. The cells collected at the same time form a snapshot, and successive snapshots are made of different cells, because the measurement destroys the cells. The cells of different timepoints are therefore not matched. The input is a table of raw counts (cells x genes) with the time of every cell, or a list of count matrices, one per timepoint in the order of the time. With several replicates of the same experiment, give a list with one such list per replicate.

Settings

Argument Default Description
data AnnData object, or a list of count matrices (cells x genes), one per timepoint, or a list of such lists
time_key "time" column of adata.obs with the time of the cells
budget 30 number of genes to select
n_cores a third of the budget number of core genes
n_bridges the rest of the budget number of bridge genes. If n_cores and n_bridges are both given, the budget is their sum
n_kl, n_ot 70% and 30% of the bridges bridges from the KL signal without lag, and from the OT signal with lag 1
n_programs 3 number of programs, found by clustering the genes
query_genes None indices of one gene per program, in the order in which the programs become active. The program of a query gene is the gene and its program_size - 1 nearest genes, and the other genes go to the program with the nearest centroid
program_size 30 size of the program of a query gene
labels, order None the program of every gene (0, 1, 2, ...) and the order of the programs
coexpr_encoder "simulation" encoder of the co-expression embedding, see below
seed, n_epochs 42, None training of the encoders. By default 300 epochs for "simulation", 200 and 150 for "real_data"

Programs are chosen in one of three ways: n_programs (clustering), query_genes, or labels and order.

# the numbers of cores and bridges (the budget is their sum), and of the two channels of the bridges
genes = select_genes(adata, n_cores=10, n_bridges=20, n_kl=14, n_ot=6, n_programs=3)

# programs built around one query gene each, in the order in which the programs become active
queries = [adata.var_names.get_loc("Lox"), adata.var_names.get_loc("Birc5")]
genes = select_genes(adata, budget=30, query_genes=queries, program_size=10)

# programs of your own: the program of every gene (0, 1, 2, ...) and the order of the programs
genes = select_genes(adata, budget=30, labels=labels, order=[0, 1, 2])

# the data as a list of count matrices (cells x genes), one per timepoint
genes = select_genes([X_t0, X_t1, X_t2], budget=30, n_programs=3)

All the settings are described in help(select_genes).

Encoders

The co-expression embedding has two encoders. The default one ("simulation") takes the correlation profile of a gene as its features and is meant for panels of tens to a few hundred genes. The other one ("real_data") takes the leading singular vectors of the correlation matrix as features and adds self-loops to the graph, for thousands of genes:

genes = select_genes(adata, budget=30, n_programs=3, coexpr_encoder="real_data")

The expression embedding (DeepSets) is the same in both cases.

Gene Program Explorer

The genes related to a query gene, at the static level and with the lagged signals, can also be explored interactively in the Gene Program Explorer: https://rmsexplorer.org

Reproducibility

The training of the neural networks gives slightly different numbers from one run to the next when it uses several threads. To get the same genes every time, call make_reproducible() once before select_genes:

from gset import make_reproducible, select_genes

make_reproducible()

Citation

Zeev Weizmann and Elias Ventre. GSET: Gene Signals from Embedding Trajectories select compact contexts for mechanistic GRN inference.

Metadata

Release files for gset 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gset 0.1.3
File Size Uploaded Provenance
gset-0.1.3.tar.gz 25.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gset 0.1.3
File Interpreter ABI Platform
gset-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 50.6 kB

Release files / gset-0.1.3.tar.gz

Download URL gset-0.1.3.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4fcefa63634928c76ab81d37bddcda9097a1c8b9a81d36ef7d3a4026a85a0d8f
BLAKE2b-256 checksum
How to use checksums
d74b9ae35de4052242a7087c8fe680280cd7750b031c1172ed11f55d07447251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release files / gset-0.1.3-py3-none-any.whl

Download URL gset-0.1.3-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7ba73806512df2522b9823e7a722c20df2f4d6d55e3fe83466ab6aad1b928a3
BLAKE2b-256 checksum
How to use checksums
295d0234ceda99a9b92fc786cf4e0515f2324e1d20bc4e7a7c7d8b3a4e008b3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Security for gset 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page