본문으로 건너뛰기
cccskills
무료GitHub에 공개

anndata

Data structure for annotated matrices in single-cell analysis; use when reading/writing .h5ad (or zarr) and exchanging data with the scverse ecosystem.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

실행 점수 미검증

설치 방법 보기

포함된 파일(7)

  • SKILL.md6.6 KB
  • anndata_audit_result_v1.json12.2 KB
  • references/best_practices.md11.7 KB
  • references/concatenation.md10.2 KB
  • references/data_structure.md8.5 KB
  • references/io_operations.md9.2 KB
  • references/manipulation.md11.6 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Source: https://github.com/aipoch/medical-research-skills

When to Use

Use AnnData when you need to:

  • Load, inspect, or export annotated single-cell datasets stored as .h5ad (or zarr) for downstream tools.
  • Keep a matrix (cells × features) tightly coupled with observation/feature metadata (e.g., cell types, batches, gene annotations).
  • Work efficiently with large, sparse count matrices (e.g., scRNA-seq) and avoid loading everything into memory (backed mode).
  • Combine multiple experiments/batches/modalities into a unified object while tracking provenance.
  • Subset/filter/transform data while preserving alignment between the matrix and metadata.

Key Features

  • Unified container: X (data matrix) plus aligned annotations: obs, var, uns, and multi-dimensional slots (obsm, varm, obsp, varp), plus layers and optional raw.
  • Interoperable I/O: Native .h5ad and zarr, plus common genomics formats (e.g., 10x, loom, mtx, csv).
  • Scalable workflows: Sparse matrices and backed mode (backed="r") for large datasets.
  • Safe subsetting: Slicing preserves alignment across matrix and annotations; supports views vs copies.
  • Concatenation utilities: ad.concat(...) with join/merge strategies and batch labeling; experimental lazy collections.

Reference notes: the original material mentions additional guides under references/ (e.g., references/data_structure.md, references/io_operations.md, references/concatenation.md, references/manipulation.md, references/best_practices.md) for deeper explanations of each topic.

Dependencies

  • anndata (latest compatible with your environment; install via pip/uv)
  • numpy
  • pandas
  • scipy (recommended for sparse matrices)
  • Optional ecosystem tools (only if needed):
    • scanpy
    • muon
    • torch (for deep learning) and anndata experimental loader utilities

Example Usage

A complete runnable example that creates an AnnData object, writes/reads .h5ad, subsets, concatenates batches, and demonstrates backed mode.

import numpy as np
import pandas as pd
import anndata as ad
from scipy.sparse import csr_matrix

# ----------------------------
# 1) Create an AnnData object
# ----------------------------
rng = np.random.default_rng(0)

n_cells, n_genes = 100, 500
X = rng.poisson(1.0, size=(n_cells, n_genes)).astype(np.float32)

obs = pd.DataFrame(
    {
        "cell_type": (["T cell", "B cell"] * (n_cells // 2)),
        "sample": (["A", "B"] * (n_cells // 2)),
        "quality_score": rng.random(n_cells),
    },
    index=[f"cell_{i}" for i in range(n_cells)],
)

var = pd.DataFrame(
    {"gene_name": [f"Gene_{j}" for j in range(n_genes)]},
    index=[f"ENSG{j:05d}" for j in range(n_genes)],
)

adata = ad.AnnData(X=X, obs=obs, var=var)

# Use sparse storage for typical count-like matrices
adata.X = csr_matrix(adata.X)

# Convert string columns to categoricals to reduce memory and speed up ops
adata.strings_to_categoricals()

print(f"Created: {adata.n_obs} obs × {adata.n_vars} vars")

# ----------------------------
# 2) Write and read .h5ad
# ----------------------------
adata.write_h5ad("example.h5ad", compression="gzip")

adata2 = ad.read_h5ad("example.h5ad")
print(f"Reloaded: {adata2.n_obs} obs × {adata2.n_vars} vars")

# ----------------------------
# 3) Subset (keeps alignment)
# ----------------------------
t_cells = adata2[adata2.obs["cell_type"] == "T cell", :]
high_quality = adata2[adata2.obs["quality_score"] > 0.8, :]

print(f"T cells: {t_cells.n_obs}")
print(f"High quality: {high_quality.n_obs}")

# ----------------------------
# 4) Concatenate batches
# ----------------------------
adata_a = adata2[adata2.obs["sample"] == "A", :].copy()
adata_b = adata2[adata2.obs["sample"] == "B", :].copy()

combined = ad.concat(
    [adata_a, adata_b],
    axis=0,                 # concatenate observations (cells)
    join="inner",           # keep shared variables
    label="batch",          # add a column in .obs
    keys=["A", "B"],        # batch labels
)

print(combined.obs["batch"].value_counts().to_dict())

# ----------------------------
# 5) Backed mode for large files
# ----------------------------
adata_backed = ad.read_h5ad("example.h5ad", backed="r")
# Slicing in backed mode is metadata-friendly; load to memory when needed:
subset_mem = adata_backed[:10, :50].to_memory()
print(f"Backed subset loaded: {subset_mem.shape}")

Implementation Details

Data model (core slots)

  • X: primary data matrix (dense numpy.ndarray or sparse scipy.sparse), shape (n_obs, n_vars).
  • obs: per-observation metadata (pandas.DataFrame), indexed by obs_names (e.g., cell IDs).
  • var: per-variable metadata (pandas.DataFrame), indexed by var_names (e.g., gene IDs).
  • layers: named alternative matrices aligned to X (e.g., "counts", "log1p").
  • obsm / varm: multi-dimensional embeddings aligned to obs/var (e.g., PCA, UMAP coordinates).
  • obsp / varp: pairwise graphs/matrices (e.g., kNN graph in obsp["connectivities"]).
  • uns: unstructured metadata (dict-like), often used for parameters and plotting configs.
  • raw (optional): snapshot of unfiltered/untransformed data for reproducibility.

Views vs copies

  • Slicing like adata_subset = adata[mask, :] typically returns a view (lightweight reference).
  • Use .copy() when you need an independent object (e.g., before in-place modifications).

Backed mode (large datasets)

  • ad.read_h5ad(path, backed="r") keeps the matrix on disk and loads data lazily.
  • Convert a slice to memory with .to_memory() when you need in-memory computation.
  • Backed mode is best for filtering by metadata, chunked processing, and avoiding OOM.

Concatenation behavior

  • ad.concat([...], axis=0) stacks observations; axis=1 stacks variables.
  • join="inner" keeps intersection of variables; join="outer" unions variables (may introduce missing values).
  • label + keys records dataset/batch provenance in .obs[label].
  • Merge strategies control how conflicting .uns and annotation columns are handled (choose based on your data governance needs).

Practical performance parameters

  • Prefer sparse matrices (csr_matrix) for count-like data.
  • Convert repeated strings to categoricals (adata.strings_to_categoricals()).
  • Use compression when writing .h5ad (e.g., compression="gzip") to reduce storage; consider zarr for chunked/cloud-friendly access.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Transform lengthy academic papers into concise, structured 250-word abstracts.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aipoch/medical-research-skills2천2026년 9월 17일 업데이트

Precision editing tool that reduces abstract word count through intelligent compression techniques, maintaining scientific rigor while meeting strict journal and conference requirements.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aipoch/medical-research-skills2천2026년 9월 17일 업데이트

Refines long medical academic texts into SCI-style unstructured Chinese and English abstracts; use when you need to condense drafts/reports/summaries into bilingual abstracts and generate Summary_Report.md.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aipoch/medical-research-skills2천2026년 9월 17일 업데이트

Generates submission-ready Elsevier/SCI Highlights from manuscript text or extracted PDF/DOCX/TXT content. Use when a user needs 3-5 concise, evidence-grounded highlight bullets for a research paper, review, meta-analysis, case report, or bioinformatics manuscript.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aipoch/medical-research-skills2천2026년 9월 17일 업데이트

Generates complete FAERS pharmacovigilance study designs for multi-drug or class-level safety comparison inside one predefined SOC or AE family using active comparators, disproportionality analysis, subgroup characterization, and reviewer-facing evidence control.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aipoch/medical-research-skills2천2026년 9월 17일 업데이트

Analyze data with `adme-property-predictor` using a reproducible workflow, explicit validation, and structured outputs for review-ready interpretation.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aipoch/medical-research-skills2천2026년 9월 17일 업데이트

aipoch의 스킬 모두 보기

이 스킬의 문제 신고