Format Conversion Tool (transform)
transform converts data among zarr, h5ad, and seurat (.rds) formats so that you can continue spatial transcriptomics analysis in different software ecosystems.
For the configuration reference, see transform.yaml Reference.
Typical use cases
Export a Spatialsnake
zarrobject to the Scanpy ecosystem ash5ad.Convert an existing
h5adobject back tozarrfor use in Spatialsnake.Convert an object to Seurat
.rdsformat.
Before you start
Make sure that:
The necessary packages have been installed; this is typically done by running
spatialsnake --install-packages.Some previously analyzed data may be lost during conversion due to format differences. Please verify the results against your intended purpose. Spatialsnake only guarantees successful conversion of the core data.
Sufficient disk space is available, because
zarr -> seuratcreates an intermediateh5adfile.
General command template
spatialsnake useful_tool --option=transform <INPUT> --transform_from=<src> --transform_to=<dst> --output_dir=results/useful_results
Scenario 1: zarr -> h5ad
Convert a zarr object into h5ad so that it can be used in Scanpy.
spatialsnake useful_tool --option=transform results/S1/annotation/S1.zarr --transform_from=zarr --transform_to=h5ad --save_image=True --output_dir=results/useful_results
Notes:
--save_image=Trueattempts to preserve spatial image information.Multiple input
zarrobjects are supported and can be combined into oneh5adoutput.The default output filename uses the basename of the first input, for example
S1.h5ad.
Scenario 2: h5ad -> zarr
Convert h5ad back into zarr so that the object can re-enter the Spatialsnake workflow.
spatialsnake useful_tool --option=transform results/useful_results/S1.h5ad --transform_from=h5ad --transform_to=zarr --output_dir=results/useful_results
Notes:
The current implementation is best suited to a single
h5adinput.If multiple
h5adfiles are provided, the current script writes out the last loaded object, so multi-input use is not recommended.
Scenario 3: h5ad -> seurat (.rds)
Convert h5ad into a Seurat .rds object by calling an R script.
spatialsnake useful_tool --option=transform results/useful_results/S1.h5ad --transform_from=h5ad --transform_to=seurat --type=st --output_dir=results/useful_results
Available --type values:
st: spatial transcriptomics (default)sc: single-cell
Scenario 4: zarr -> seurat (.rds)
This mode first converts zarr into an intermediate h5ad file and then continues to .rds.
spatialsnake useful_tool --option=transform results/S1/annotation/S1.zarr --transform_from=zarr --transform_to=seurat --save_image=True --type=st --output_dir=results/useful_results
The output typically includes:
S1.h5ad(intermediate file)S1.rds(final Seurat file)
Key parameters in practice
Parameter |
Typical values |
Description |
|---|---|---|
|
|
Specifies the input format |
|
|
Specifies the output format |
|
|
Whether to preserve image information when converting from |
|
|
Data type used when converting to Seurat; default is |
|
|
Output directory |
How to validate the results
Check whether the target file (
.h5ad,.zarr, or.rds) has been generated in the output directory.If the target is Seurat, also confirm that the intermediate
.h5adfile was created successfully.Open the result with the appropriate downstream tool to make sure the object loads correctly.
Common errors and how to fix them
The workflow exits immediately because input and output formats are identical
Cause:
--transform_fromand--transform_towere set to the same value.Fix: change one of them so that the source and target formats differ.
Rscriptfails during Seurat conversionCause: the R environment is missing or required packages are not installed.
Fix: first test
Rscript --versionon the command line, then install the required R packages.
The intermediate
h5adfile is not generated duringzarr -> seuratCause: the first step from
zarrtoh5adfailed.Fix: run
zarr -> h5adseparately first and confirm that the object and image information can be converted successfully.
Note
For this module, we adopted schard, an open-source utility package developed by Pavel Mazin et al. Although several tools are available for format conversion, such as SeuratDisk, our comparison indicated that schard is better aligned with the Spatialsnake workflow and provides more stable conversion in practice.
For more information, see: schard