loompy

raw JSON →
3.0.8 verified Mon Apr 27 auth: no python

A Python library for working with Loom file format (version 3.0.8), which is used for storing single-cell RNA-seq data. It supports reading, writing, and creating Loom files with sparse matrices, variable-length string attributes, and provides a command-line tool for creating Loom files from FASTQ. Release cadence is irregular.

pip install loompy
error ModuleNotFoundError: No module named 'loompy'
cause loompy is not installed.
fix
Install with pip install loompy
error AttributeError: module 'loompy' has no attribute 'LoomFile'
cause Using the deprecated LoomFile class which was removed in version 3.0.0.
fix
Use loompy.connect() to open files and loompy.create() to create them.
error OSError: Unable to open file (unable to open file: name = 'test.loom', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
cause Trying to read a file that does not exist.
fix
Check that the file path is correct and the file exists.
error ValueError: Shape mismatch. Matrix has shape (100, 200) but row_attrs has length 50
cause The dimensions of the matrix do not match the number of row attributes.
fix
Ensure that the number of rows in the matrix equals the length of row attribute values, and columns equal length of column attributes.
breaking loompy 3.0.0 introduced a major API overhaul: old classes like LoomFile are replaced with connect(), create(), etc. Code written for loompy 2.x will not run without modification.
fix Migrate from LoomFile('file.loom', 'r') to loompy.connect('file.loom'), and from creating with LoomFile('file.loom', 'w') to loompy.create().
gotcha When opening a Loom file in write mode using connect() with mode='w', the file is overwritten. Ensure you have a backup.
fix Use mode='r+' to read/write without truncation, or check file existence beforehand.
deprecated Some older API methods like loompy.LoomFile and loompy.File are deprecated in 3.0.x and may be removed in future versions.
fix Replace with loompy.connect() for reading/writing and loompy.create() for creating new files.

Create a Loom file with a small matrix and read it back.

import loompy
import numpy as np
# Create a minimal loom file
row_attrs = {'Gene': ['A', 'B']}
col_attrs = {'CellID': ['cell1', 'cell2']}
matrix = np.array([[1, 2], [3, 4]], dtype='float32')
loompy.create('test.loom', matrix, row_attrs, col_attrs)
# Read it backts = loompy.connect('test.loom')
print(fts.shape)
fts.close()