Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ Bug fixes
matches the computed result, and correlation distances are no longer
slightly negative.

.. Documentation
.. ~~~~~~~~~~~~~
Documentation
~~~~~~~~~~~~~

- Document adding derived variables to an existing Zarr dataset and safely
replacing an existing variable after materializing its data.

.. _changelog.0.10.0:

Expand Down
18 changes: 18 additions & 0 deletions docs/how_do_i.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ Call :py:func:`save_dataset`:
Zarr datasets must have equal-sized chunks (except for the final chunk, which may be smaller),
so you may have to `rechunk the dataset <http://xarray.pydata.org/en/stable/generated/xarray.DataArray.chunk.html>`_ first.

Add a variable to an existing Zarr dataset?
-------------------------------------------

Load the existing dataset and compute only the new variable. Pass that variable
to :py:func:`save_dataset` with ``mode="a"`` to add it to the existing store:

.. code-block:: python

ds = sg.load_dataset("ds.zarr")
counts = sg.count_variant_alleles(ds, merge=False).assign_attrs(ds.attrs)
sg.save_dataset(counts, "ds.zarr", mode="a")

If you create the new variable inside a larger dataset, select it with
``ds[["new_variable"]]`` before saving. Append mode can also overwrite variables
with the same names. If the replacement depends on values loaded lazily from
the variable being overwritten, call ``.compute()`` on the replacement before
saving. Use ``assign_attrs(ds.attrs)`` to retain the existing dataset attributes.

Load a dataset from Zarr?
-------------------------

Expand Down