-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add subworkflow for merging per-sample SpatialData
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import spatialdata | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Merge SpatialData objects") | ||
parser.add_argument("files", nargs="+", help="List of SpatialData files to merge") | ||
parser.add_argument("output", help="Output file name") | ||
args = parser.parse_args() | ||
|
||
# Read all zarr SpatialData folders | ||
sdatas = [] | ||
for file in args.files: | ||
sdata = spatialdata.read_zarr(file) | ||
sdatas.append(sdata) | ||
|
||
# Merge the data | ||
output_sdata = spatialdata.concatenate( | ||
sdatas, | ||
region_key=None, | ||
instance_key=None, | ||
concatenate_tables=False, | ||
obs_names_make_unique=True, | ||
modify_tables_inplace=False, | ||
) | ||
|
||
# Save the concatenated data | ||
output_sdata.write( | ||
args.output, | ||
overwrite=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Merge per-sample SpatialData into a single SpatialData | ||
// | ||
process MERGE_SDATA { | ||
|
||
label 'process_low' | ||
container "docker.io/erikfas/spatialvi" | ||
|
||
input: | ||
path(sdata, stageAs: "?/*") | ||
|
||
output: | ||
path("aggregated-sdata.zarr"), emit: sdata | ||
path("versions.yml") , emit: versions | ||
|
||
when: | ||
task.ext.when == null || task.ext.when | ||
|
||
script: | ||
if (workflow.profile.tokenize(',').intersect(['conda', 'mamba']).size() >= 1) { | ||
exit 1, "The MERGE_SDATA module does not support Conda/Mamba, please use Docker / Singularity / Podman instead." | ||
} | ||
""" | ||
# Set environment variables | ||
export XDG_CACHE_HOME="./.xdg_cache_home" | ||
export XDG_DATA_HOME="./.xdg_data_home" | ||
# Execute script | ||
merge_sdata.py \\ | ||
${sdata} \\ | ||
aggregated-sdata.zarr | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
spatialdata_io: \$(python -c "import spatialdata_io; print(spatialdata_io.__version__)") | ||
END_VERSIONS | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Subworkflow for aggregation of sample data | ||
// | ||
|
||
include { MERGE_SDATA } from '../../modules/local/merge_sdata' | ||
|
||
workflow AGGREGATION { | ||
|
||
take: | ||
ch_sdata // Channel: [ meta, zarr ] | ||
|
||
main: | ||
|
||
ch_versions = Channel.empty() | ||
|
||
// | ||
// MODULE: Merge per-sample SpatialData objects into one | ||
// | ||
ch_sdata_files = ch_sdata | ||
| map { | ||
meta, zarr -> | ||
return [zarr] | ||
} | ||
MERGE_SDATA ( | ||
ch_sdata_files.collect() | ||
) | ||
ch_versions = ch_versions.mix(MERGE_SDATA.out.versions) | ||
ch_merged_sdata = MERGE_SDATA.out.sdata | ||
|
||
emit: | ||
merged_sdata = ch_merged_sdata // channel: [ aggregated-sdata.zarr ] | ||
versions = ch_versions // channel: [ versions.yml ] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters