anndata-general-io
Read generic Matrix Market and Excel data, access HDF5 elements, and combine backed AnnData objects.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- anndata-general-io
- license
- MIT
- description
- Read generic Matrix Market and Excel data, access HDF5 elements, and combine backed AnnData objects.
02 资源文件 4
- 许可证LICENSE1.0 KB
- 参考文档provenance/original.io_operations.md9.2 KB
- 参考文档provenance/original.SKILL.md10.0 KB
- 参考文档repair.json1.8 KB
03 SKILL.md 正文
AnnData: selected I/O operations
Apply Caveman for every task, CocoIndex Code before broad repository navigation,
and Crawl4AI for web-page research. Follow docs/agent-tools.md in the
repository root and retain the required execution evidence.
These examples supplement the separate 10x and backed-metadata overlay. They cover selected operations from the original I/O reference, not the complete AnnData skill. The tested version is AnnData 0.13.4; validate versions, formats, data semantics and outputs for the user's actual dataset.
Generic Matrix Market input
The following assumes the matrix has features as rows and observations as columns, and each tab-separated label file has exactly one ID per line in the same order as its corresponding matrix axis. Check those assumptions with the data producer: matching lengths alone cannot establish correct ordering. Choose a dtype appropriate for the data and required precision.
import anndata as ad
import pandas as pd
def read_ids(path):
table = pd.read_csv(path, sep="\t", header=None, dtype=str, keep_default_na=False, skip_blank_lines=False)
if table.shape[1] != 1 or table[0].eq("").any() or table[0].duplicated().any():
raise ValueError("ID file must contain one nonempty, unique ID per row")
return table[0].tolist()
data = ad.io.read_mtx(matrix_path, dtype="float64").T
obs_ids = read_ids(observation_ids_path)
var_ids = read_ids(feature_ids_path)
if data.shape != (len(obs_ids), len(var_ids)):
raise ValueError("Matrix dimensions do not match the supplied IDs")
data.obs_names = obs_ids
data.var_names = var_ids
This is a generic Matrix Market example, not a substitute for Scanpy's 10x readers. AnnData stores observations in rows and variables in columns.
Excel input
Supply the sheet explicitly. The example expects the first row and first
column to contain variable and observation names respectively, with numeric
values in the remaining cells. Inspect names, orientation and values before
analysis; .xlsx files require an Excel-reading dependency such as openpyxl.
import anndata as ad
data = ad.io.read_excel(workbook_path, sheet=sheet_name)
HDF5 elements
read_elem accepts an opened storage element, not a path string. This example
creates a new HDF5 file and reopens it for reading; the caller supplies values
and a destination that does not already exist.
import anndata as ad
import h5py
with h5py.File(element_path, "x") as store:
ad.io.write_elem(store, "values", values)
with h5py.File(element_path, "r") as store:
restored = ad.io.read_elem(store["values"])
Collection of backed files
Open the files as backed AnnData objects and keep their handles open while
using the collection. This example reads the combined matrix and observation
metadata into memory before closing its inputs; ensure they fit. It does not
copy variable metadata, layers, embeddings or other AnnData fields.
join_vars="inner" keeps
shared variables, and join_obs="inner" keeps shared observation columns.
Confirm that these choices, feature identities, order and generated observation
IDs are appropriate for the data. AnnCollection is experimental.
from contextlib import ExitStack
import anndata as ad
from anndata.experimental import AnnCollection
with ExitStack() as stack:
datasets = []
for path in input_paths:
dataset = ad.io.read_h5ad(path, backed="r")
stack.callback(dataset.file.close)
datasets.append(dataset)
collection = AnnCollection(datasets, join_obs="inner", join_vars="inner", index_unique="-")
matrix = collection[:].X
if matrix is None:
raise ValueError("The selected collection has no X matrix")
observations = collection.obs.copy()
variables = collection.var_names.copy()
In the tested AnnData 0.13.4 environment, calling collection[:].to_adata()
failed on the synthetic backed inputs, so do not assume that operation works
for this version. Test any other fields and materialization paths separately.
The component controls use synthetic data. They do not establish biological validity, performance on large datasets, correctness of all file layouts, or coding-agent improvement.
04 同仓库更多 Skills
makefile-generator-project-wrappers
Repair Python, Java and generic GNU Make wrappers that report false success, miss changed inputs or clean dependency environments. Preserve the actual project build system and test runner; use when adapting the collection's original Makefile generator.
makefile-generator-go
Author or repair GNU Make wrappers for Go modules, retaining Go's dependency discovery and build cache. Use when wrapper timestamps hide embedded-resource changes or build failures; preserve the project's existing build system and real test commands.
strategic-compact-resume
Checkpoint and resume long agent work when context pressure or a handoff could lose constraints, verified progress, or ownership of active jobs.
makefile-generator-cpp
Author or repair GNU Make builds for C++ executables, preserving compiler/linker flags, header dependencies and real project test contracts. Use the optional scaffold for a flat src directory; retain an existing build system unless the task requires changing it.
eval-harness-integrity
Design and verify matched coding-agent evaluations when comparing skills, prompts, models, or harnesses using executable acceptance checks and native result evidence.
eval-harness-evidence
Design and verify matched coding-agent evaluations when comparing skills, prompts, models, or harnesses using executable acceptance checks and native result evidence.