Export Seurat object data to a .pxl file
WriteMPX_pxl_file.Rd
The function only exports the essential data required to create a functional .pxl file. See details below for a description of what data is exported.
Arguments
- object
A
Seurat
object with aCellGraphAssay5
assay object created with pixelatorR.- file
A character string specifying the path to the .pxl file to be created.
- assay
A character string specifying the name of the
CellGraphAssay5
. If set toNULL
the default assay will be used.- export_layouts
A logical value specifying whether to export the layouts from the
Seurat
object. If set toTRUE
, each component must have a layout. SeeLoadCellGraphs
andComputeLayout
for details about how to load graphs and compute layouts.- overwrite
A logical value specifying whether to overwrite the
file
if it already exists.
Exported data
Count data and metadata : The raw count matrix and component metadata from the Seurat object are exported into a .h5ad file that can be read with the anndata Python library.
Polarization scores : The polarization scores are exported to a .parquet file.
Colocalization scores : The colocalization scores are exported to a .parquet file.
Edgelist data : The edgelist data is first collected from the original .pxl file(s), filtered to include the components currently available in the
Seurat
object, and then the component IDs are updated. The resulting merged edgelist data is exported to a .parquet file.Sample meta data : The sample meta data is extracted from the original .pxl file(s), then merged and exported to a .json file.
The structure of the .pxl file is detailed below:
|– adata.h5ad
|– polarization.parquet
|– colocalization.parquet
|– metadata.json
|– edgelist.parquet
The merged files are converted into a zip archive and saved to the target .pxl file.
NOTE: Factors are currently not supported. These will be converted to string arrays.
Examples
# Use Assay5 as the default assay version
options(Seurat.object.assay.version = "v5")
# Create Seurat object
pxl_file <- system.file("extdata/five_cells",
"five_cells.pxl",
package = "pixelatorR"
)
se <- ReadMPX_Seurat(pxl_file)
#> ✔ Created a 'Seurat' object with 5 cells and 80 targeted surface proteins
se_merged <- merge(se, list(se, se, se))
#> Warning: Some cell names are duplicated across objects provided. Renaming to enforce unique cell names.
pxl_file <- fs::path_temp("small.pxl")
# Export data to a new .pxl file
WriteMPX_pxl_file(se_merged, pxl_file)
#> ── Creating .pxl file ──────────────────────────────────────────────────────────
#> → Writing spatial metrics to .parquet files...
#> → Writing polarization scores to polarization.parquet
#> → Writing colocalization scores to colocalization.parquet
#> ✔ Exported spatial metrics
#> → Collecting edge lists from 4 files
#> → Extracting sample 1 edge list
#> → Extracting sample 2 edge list
#> → Extracting sample 3 edge list
#> → Extracting sample 4 edge list
#> → Merging edge lists
#> → Loaded sample 1 edge list
#> → Loaded sample 2 edge list
#> → Loaded sample 3 edge list
#> → Loaded sample 4 edge list
#> → Merging edge lists
#> → Exporting merged edge list
#> ✔ Exported merged edge list
#> ✔ Exported merged meta data
#> ✔ Exported anndata file
#> ℹ Saving .pxl file to /var/folders/gw/bdcqhnvs0m9gs_mq8n51jtbc0000gn/T/RtmpKX8Ziv/small.pxl
#> ✔ Finished!
# Read the new .pxl file
se_merged <- ReadMPX_Seurat(pxl_file)
#> ✔ Created a 'Seurat' object with 20 cells and 80 targeted surface proteins
# Reset global option
options(Seurat.object.assay.version = "v3")