agentsclimarketplace

Scgpt

Skill naity/FM4Life/skills/scgpt

Skills for life science foundation models — structured knowledge bundles that let AI coding agents work with ESM, AlphaFold, RFdiffusion, DiffDock, scGPT, and more out of the box.

Install
npx -y skills add naity/FM4Life --skill scgpt

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Skill for single-cell biology with scGPT, a foundation model trained on 33 million human single cells. Use this skill when a user wants to annotate cell types, predict perturbation responses, integrate multi-batch scRNA-seq data, extract cell embeddings, perform reference mapping, infer gene regulatory networks, or analyze CITE-seq multi-omic data. Also trigger when the user mentions scGPT, single-cell GPT, scRNA-seq foundation models, or single-cell transcriptomics AI.

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

7.4 KB, as published. Nobody here has run it

scGPT: Foundation Model for Single-Cell Biology

Overview

scGPT is a generative pretrained transformer trained on 33 million human single cells. It learns a universal representation of gene expression that transfers across tissues, diseases, and experimental batches.

Core tasks:

  • Cell type annotation — classify cell types by fine-tuning on labeled data
  • Cell embedding — zero-shot or fine-tuned cell representations for clustering/UMAP
  • Perturbation prediction — predict gene expression changes after knockouts/overexpression
  • Multi-batch integration — harmonize data across studies and technologies
  • Reference mapping — map query cells onto a large reference atlas
  • Gene regulatory network (GRN) — infer gene-gene relationships from learned embeddings
  • Multi-omics — integrate RNA + protein (CITE-seq) or RNA + ATAC

Input: AnnData objects with raw or normalized count matrices (adata.X, genes × cells).
Output: Cell embeddings (stored in adata.obsm['X_scGPT']), cell type predictions, perturbation forecasts.

Installation

pip install scgpt "flash-attn<1.0.5"

Requirements: Python ≥ 3.7.12, PyTorch ≥ 1.13, CUDA 11.7 recommended.

Key dependencies installed automatically: scanpy, scvi-tools, numba, umap-learn, leidenalg.

Pretrained Checkpoints

Download from the scGPT Google Drive. Each checkpoint contains vocab.json, best_model.pt, and args.json.

ModelTraining dataBest for
scGPT_human (whole-human)33M normal human cellsGeneral-purpose default
scGPT_CP (continual-pretrained)Refined on Tabula SapiensZero-shot embedding, cell typing
scGPT_brain13.2M human brain cellsBrain tissue analysis
scGPT_blood10.3M hematopoietic cellsBlood / immune studies
scGPT_heart1.8M cardiac cellsHeart tissue
scGPT_lung2.1M lung cellsLung tissue
scGPT_kidney814K kidney cellsKidney tissue
scGPT_panCancer5.7M cancer cellsCancer type classification

Core Workflows

1. Load pretrained model

import json
import torch
from pathlib import Path
from scgpt.tokenizer.gene_tokenizer import GeneVocab
from scgpt.model import TransformerModel

model_dir = Path("save/scGPT_human")
vocab = GeneVocab.from_file(model_dir / "vocab.json")
config = json.load(open(model_dir / "args.json"))

model = TransformerModel(
    ntokens=len(vocab),
    embsize=config["embsize"],
    nhead=config["nheads"],
    d_hid=config["d_hid"],
    nlayers=config["nlayers"],
    vocab=vocab,
)
model.load_state_dict(torch.load(model_dir / "best_model.pt"))
model.eval()

2. Preprocess AnnData

import scanpy as sc
from scgpt.preprocess import Preprocessor

adata = sc.read_h5ad("data.h5ad")

preprocessor = Preprocessor(
    n_top_genes=1200,   # highly variable genes to keep
    binning=51,         # expression quantization bins
    normalize_total=10000,
    log1p=True,
)
preprocessor(adata, batch_key=None)  # pass batch_key for multi-batch

3. Extract cell embeddings (zero-shot)

from scgpt.tasks.cell_emb import get_batch_cell_embeddings

embeddings = get_batch_cell_embeddings(
    adata,
    cell_embedding_mode="cls",  # "cls", "avg-pool", or "w-pool"
    model=model,
    vocab=vocab,
    max_length=1200,
    batch_size=64,
)
adata.obsm["X_scGPT"] = embeddings

# Downstream: UMAP, clustering
sc.pp.neighbors(adata, use_rep="X_scGPT")
sc.tl.umap(adata)
sc.pl.umap(adata, color="cell_type")

4. Cell type annotation (fine-tuning)

import torch.nn as nn

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
optimizer = torch.optim.Adam(model.parameters(), lr=1e-4)
criterion = nn.CrossEntropyLoss()

for epoch in range(10):
    model.train()
    for batch in train_loader:
        gene_ids = batch["gene_ids"].to(device)
        values   = batch["values"].to(device)
        labels   = batch["labels"].to(device)

        output = model(gene_ids, values, CLS=True)
        loss = criterion(output["cls_output"], labels)

        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

5. Multi-batch integration

import scanpy as sc

adata = sc.concat([adata1, adata2], label="batch")
preprocessor(adata, batch_key="batch")

# Encode with batch labels
cell_embeddings = model.encode_batch(
    all_gene_ids,
    all_values.float(),
    batch_labels=torch.from_numpy(batch_ids).long(),
    batch_size=64,
    return_np=True,
)
adata.obsm["X_scGPT"] = cell_embeddings

6. Perturbation prediction

from scgpt.model.generation_model import TransformerGenerator

generator = TransformerGenerator(...)  # load with pretrained weights

perturbations = [["GENE1"], ["GENE1", "GENE2"]]
predictions = generator.pred_perturb(batch_data, pert_list=perturbations)
# predictions: (n_cells, n_genes) predicted expression matrix

7. Gene regulatory network

from scgpt.tasks.grn import GeneEmbedding

# Extract gene embeddings from the model
gene_emb = GeneEmbedding(gene_embeddings_dict)

# Find genes similar to a query gene
similar = gene_emb.get_similar_genes("TP53", subset=hvg_list)

# Build network graph
network = gene_emb.generate_network(threshold=0.5)

Key Parameters

ParameterDefaultDescription
n_top_genes1200Highly variable genes to select
binning51Expression quantization bins
normalize_total10000Depth normalization target
max_length1200Max genes per cell (sequence length)
batch_size64Inference batch size
cell_embedding_mode"cls"Embedding pooling: "cls", "avg-pool", "w-pool"
embsize128–512Model embedding dimension (from config)
mask_ratio0.4MLM masking ratio during training

Gene Vocabulary

scGPT uses a vocabulary of 60,697 human gene symbols (HGNC standardized). Special tokens: <pad>, <cls>, <eoc>. The vocabulary file (vocab.json) maps gene names to integer IDs and is bundled with each checkpoint.

If your data uses Ensembl IDs or non-standard gene names, convert to HGNC symbols first.

Scripts

  • scripts/embed.py — extract cell embeddings from an h5ad file; see scripts/embed.py --help

Resources

References

  • references/api-reference.md — full API reference: TransformerModel, Preprocessor, GeneVocab, task functions, multi-omics, FAISS reference mapping

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.