Skip to content

API Docs

Networkx Backend

geff.read_nx

read_nx(
    path: Path | str, validate: bool = True
) -> nx.Graph

Read a geff file into a networkx graph. Metadata attributes will be stored in the graph attributes, accessed via G.graph[key] where G is a networkx graph.

Parameters:

Name Type Description Default
path Path | str

The path to the root of the geff zarr, where the .attrs contains the geff metadata

required
validate bool

Flag indicating whether to perform validation on the geff file before loading into memory. If set to False and there are format issues, will likely fail with a cryptic error. Defaults to True.

True

Returns:

Type Description
Graph

A networkx graph containing the graph that was stored in the geff file format

geff.write_nx

write_nx(
    graph: Graph,
    path: str | Path,
    position_attr: str | None = None,
    axis_names: list[str] | None = None,
    axis_units: list[str] | None = None,
    zarr_format: int = 2,
    validate: bool = True,
)

Write a networkx graph to the geff file format

Parameters:

Name Type Description Default
graph Graph

A networkx graph

required
path str | Path

The path to the output zarr. Opens in append mode, so will only overwrite geff-controlled groups.

required
position_attr Optional[str]

The name of the position attribute present on every node, if present. Defaults to None.

None
axis_names Optional[list[str]]

The names of the spatial dims represented in position attribute. Defaults to None. Will override value in graph attributes if provided.

None
axis_units Optional[list[str]]

The units of the spatial dims represented in position attribute. Defaults to None. Will override value in graph attributes if provided.

None
zarr_format int

The version of zarr to write. Defaults to 2.

2
validate bool

Flag indicating whether to perform validation on the networkx graph before writing anything to disk. If set to False and there are missing attributes, will likely fail with a KeyError, leading to an incomplete graph written to disk. Defaults to True.

True

Utilities

geff.validate

validate(path: str | Path)

Check that the structure of the zarr conforms to geff specification

Parameters:

Name Type Description Default
path str | Path

Path to geff zarr

required

Raises:

Type Description
AssertionError

If geff specs are violated

geff.GeffMetadata

Bases: BaseModel

Geff metadata schema to validate the attributes json file in a geff zarr

read classmethod

read(group: Group | Path) -> GeffMetadata

Helper function to read GeffMetadata from a zarr geff group.

Parameters:

Name Type Description Default
group Group | Path

The zarr group containing the geff metadata

required

Returns:

Name Type Description
GeffMetadata GeffMetadata

The GeffMetadata object

write

write(group: Group | Path)

Helper function to write GeffMetadata into the zarr geff group.

Parameters:

Name Type Description Default
group Group | Path

The geff group to write the metadata to

required