LoomLayer (class)

A LoomLayer represents a layer of data and provides a numpy ndarray-like interface.

with loompy.connect("mydataset.loom") as ds:
    # Names of all the layers ("" is the main matrix)

    # Upper left corner of the main matrix

    # Shorthand to slice the main matrix

    # Load the entire layer named "spliced"
    ds.layers["spliced"][:, :]

    # Shorthand access to the layer named "spliced"
    ds["spliced"][:, :]

    # Assign a row of data to the named layer
    ds["spliced"][0, :] = new_data

    # Create a new empty layer of `ìnt32`` elements
    ds["empty_layer"] = "int32"

Layers can also be accessed using numpy fancy indexing, e.g. with a vector of bools or a list of element indices.


Note that using fancy indexing to slice more than ~1% of the rows (or columns) is inefficient. If you want to extract a larger subset of rows or columns, you’re better of using LoomConnection.scan().

class loompy.LoomLayer(name: str, ds: Any)[source]

Represents a layer (matrix) of values in the loom file, which can be accessed by slicing.

ds = None

The LoomConnection object this layer belongs to

name = None

Name of the layer (str)

shape = None

Shape of the layer, tuple of (n_rows, n_cols)

dtype = None

Datatype of the layer (str)

last_modified() → str[source]

Return a compact ISO8601 timestamp (UTC timezone) indicating when the file was last modified

Note: if the layer does not contain a timestamp, and the mode is ‘r+’, a new timestamp will be set and returned. Otherwise, the current time in UTC will be returned.

sparse(rows: numpy.ndarray = None, cols: numpy.ndarray = None) → scipy.sparse.coo.coo_matrix[source]
map(f_list: List[Callable[numpy.ndarray, int]], axis: int = 0, chunksize: int = 1000, selection: numpy.ndarray = None) → List[numpy.ndarray][source]

Apply a function along an axis without loading the entire dataset in memory.

  • f_list (list of func) – Function(s) that takes a numpy ndarray as argument
  • axis (int) – Axis along which to apply the function (0 = rows, 1 = columns)
  • chunksize (int) – Number of rows (columns) to load per chunk
  • selection (array of bool) – Columns (rows) to include

numpy.ndarray result of function application

If you supply a list of functions, the result will be a list of numpy arrays. This is more efficient than repeatedly calling map() one function at a time.