somacore
somacore provides the Python-language API specification and base utilities for the SOMA (Scalable Open Multi-omics Array) system. It defines abstract base classes and protocols for core SOMA objects like Experiment, Measurement, DataFrame, and Arrays. As of version 1.0.29, it focuses on defining the SOMA data model for interoperability. The library is actively maintained with frequent updates, often aligning with updates to the broader SOMA specification.
Common errors
-
TypeError: SOMAObject cannot be instantiated directly
cause Attempting to create an instance of an abstract SOMA type (protocol) directly from `somacore`.fixImport and use concrete SOMA object classes provided by an implementation library, such as `tiledbsoma.SOMACollection` or `tiledbsoma.SOMADataFrame`, which adhere to the `somacore` protocols. -
AttributeError: module 'somacore' has no attribute 'Experiment' (or similar for other concrete classes like 'DataFrame')
cause Expecting `somacore` to expose concrete SOMA implementation classes directly, rather than abstract definitions.fix`somacore` provides abstract definitions. For concrete SOMA objects like `Experiment` or `DataFrame` that you can instantiate and populate, you need to import them from a specific SOMA implementation library (e.g., `from tiledbsoma import Experiment`). -
ModuleNotFoundError: No module named 'somacore.experiment'
cause Trying to import a specific, concrete SOMA object like `Experiment` from a sub-module of `somacore` based on an incorrect assumption about its structure.fixConcrete SOMA objects like `Experiment` are typically provided by SOMA implementation libraries (e.g., `tiledbsoma`) and imported from their top-level package, not from `somacore` or its submodules. Check the documentation of your chosen SOMA implementation.
Warnings
- breaking The SOMA API specification underwent significant changes with the 1.0.0 release. Code written for `somacore` 0.x (and earlier versions of SOMA implementations) is generally incompatible with `somacore` 1.x.
- gotcha `somacore` solely defines the SOMA API specification and provides abstract types (Protocols/ABCs). It does not provide concrete, instantiable SOMA objects, data storage mechanisms, or I/O operations itself.
- gotcha SOMA objects (e.g., `Experiment`, `DataFrame`) are represented as Python `Protocol`s in `somacore`. While they define interfaces for type checking, they are not intended for direct instantiation or subclassing by users without a concrete implementation.
Install
-
pip install somacore
Imports
- SOMAObject
from somacore import SOMAObject
- DataFrame
from somacore.base import DataFrame
from somacore import DataFrame
- Axis
from somacore import Axis
- OpenMode
from somacore import OpenMode
- query
from somacore.query import query
Quickstart
import somacore
from somacore import AxisType, OpenMode, SOMAObject
# somacore provides abstract base classes (Protocols)
# for SOMA objects and related concepts.
print(f"somacore version: {somacore.__version__}")
# You can import and inspect enumeration types
print(f"Available Axis Types: {list(AxisType)}")
print(f"Read mode for opening objects: {OpenMode.READ}")
# SOMAObject is a core Protocol (an Abstract Base Class for type hinting)
print(f"SOMAObject is a {type(SOMAObject).__name__}")
# You cannot instantiate these protocols directly;
# they are meant for type checking and as interfaces for implementations.
# For example, this would raise a TypeError:
# try:
# obj = SOMAObject("some_uri")
# except TypeError as e:
# print(f"\nCannot instantiate SOMAObject directly: {e}")
print("\nsomacore defines the SOMA API. For concrete implementations,")
print("refer to libraries like `tiledbsoma` which implement these protocols.")