I/O
momapy.io
IO subpackage for reading and writing maps.
Provides functions and registries for reading and writing molecular maps in various formats (SBGN-ML, CellDesigner, SBML, etc.).
Examples:
from momapy.io import get_reader, get_writer
reader = get_reader("sbgnml")
writer = get_writer("sbgnml")
Modules:
| Name | Description |
|---|---|
core |
Base classes and functions for reading and writing maps. |
pickle |
Pickle-based reader and writer. |
utils |
Internal utilities for map readers. |
Classes:
| Name | Description |
|---|---|
ReaderResult |
Result from reading a map file. |
WriterResult |
Result from writing a map file. |
Functions:
| Name | Description |
|---|---|
get_reader |
Get a reader class by name. |
get_writer |
Get a writer class by name. |
list_readers |
List all available reader names. |
list_writers |
List all available writer names. |
read |
Read a map file. |
register_lazy_reader |
Register a reader for lazy loading. |
register_lazy_writer |
Register a writer for lazy loading. |
register_reader |
Register a reader class. |
register_writer |
Register a writer class. |
write |
Write an object to a file. |
ReaderResult
dataclass
ReaderResult(obj: Any | None = None, element_to_annotations: frozendict | None = None, element_to_notes: frozendict | None = None, id_to_element: frozendict | None = None, source_id_to_model_element: FrozenIdentityMultiDict | None = None, source_id_to_layout_element: FrozenSurjectionDict | None = None, source_id_to_annotations: frozendict | None = None, source_id_to_notes: frozendict | None = None, file_path: str | PathLike | None = None)
Bases: IOResult
Result from reading a map file.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any | None
|
|
None
|
element_to_annotations
|
frozendict | None
|
|
None
|
element_to_notes
|
frozendict | None
|
|
None
|
id_to_element
|
frozendict | None
|
|
None
|
source_id_to_model_element
|
FrozenIdentityMultiDict | None
|
|
None
|
source_id_to_layout_element
|
FrozenSurjectionDict | None
|
|
None
|
source_id_to_annotations
|
frozendict | None
|
|
None
|
source_id_to_notes
|
frozendict | None
|
|
None
|
file_path
|
str | PathLike | None
|
|
None
|
WriterResult
dataclass
Bases: IOResult
Result from writing a map file.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any | None
|
|
None
|
file_path
|
str | PathLike | None
|
|
None
|
get_reader
Get a reader class by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Reader name (e.g., "sbgnml", "celldesigner"). |
required |
Returns:
| Type | Description |
|---|---|
type[Reader]
|
Reader class for the specified format. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no reader with that name exists. |
Source code in src/momapy/io/core.py
get_writer
Get a writer class by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Writer name (e.g., "sbgnml", "pickle"). |
required |
Returns:
| Type | Description |
|---|---|
type[Writer]
|
Writer class for the specified format. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no writer with that name exists. |
Source code in src/momapy/io/core.py
list_readers
List all available reader names.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of available reader names. |
list_writers
List all available writer names.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of available writer names. |
read
read(file_path: str | PathLike, reader: str | None = None, **options: Any) -> ReaderResult
Read a map file.
If reader is specified, uses that reader. Otherwise, checks all registered readers to find one that supports the file format using their check_file method. Uses the first matching reader found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | PathLike
|
Path of the file to read. |
required |
reader
|
str | None
|
Name of registered reader to use (e.g., "sbgnml"). If None, auto-detects based on file format. |
None
|
options
|
Any
|
Additional options passed to the reader. |
{}
|
Returns:
| Type | Description |
|---|---|
ReaderResult
|
ReaderResult containing the read object and metadata. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no suitable reader is found. |
Examples:
Source code in src/momapy/io/core.py
register_lazy_reader
Register a reader for lazy loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name to register the reader under. |
required |
import_path
|
str
|
Import path in format "module.path:ClassName". |
required |
Source code in src/momapy/io/core.py
register_lazy_writer
Register a writer for lazy loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name to register the writer under. |
required |
import_path
|
str
|
Import path in format "module.path:ClassName". |
required |
Source code in src/momapy/io/core.py
register_reader
Register a reader class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name to register the reader under. |
required |
cls
|
type[Reader]
|
Reader class (must inherit from Reader). |
required |
register_writer
Register a writer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name to register the writer under. |
required |
cls
|
type[Writer]
|
Writer class (must inherit from Writer). |
required |
write
write(obj: Any, file_path: str | PathLike, writer: str, **options: Any) -> WriterResult
Write an object to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Object to write (typically a MapElement). |
required |
file_path
|
str | PathLike
|
Path of the file to write to. |
required |
writer
|
str
|
Name of registered writer to use (e.g., "sbgnml"). |
required |
options
|
Any
|
Additional options passed to the writer. |
{}
|
Returns:
| Type | Description |
|---|---|
WriterResult
|
WriterResult containing the written object and metadata. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the writer is not found. |
Examples: