Skip to content

Commit

Permalink
Allow images/ to be missing for spatial_experiments with no images. (#39
Browse files Browse the repository at this point in the history
)
  • Loading branch information
LTLA authored Nov 9, 2024
1 parent 4517a63 commit 0fb4fd4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.24)

project(takane
VERSION 0.7.0
VERSION 0.7.1
DESCRIPTION "ArtifactDB file validators"
LANGUAGES CXX)

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ Currently, **takane** provides validators for the following objects:
[1.0](https://github.com/ArtifactDB/takane/tree/gh-pages/docs/specifications/single_cell_experiment/1.0.md).
- `spatial_experiment`:
[1.0](https://github.com/ArtifactDB/takane/tree/gh-pages/docs/specifications/spatial_experiment/1.0.md),
[1.1](https://github.com/ArtifactDB/takane/tree/gh-pages/docs/specifications/spatial_experiment/1.1.md).
[1.1](https://github.com/ArtifactDB/takane/tree/gh-pages/docs/specifications/spatial_experiment/1.1.md),
[1.2](https://github.com/ArtifactDB/takane/tree/gh-pages/docs/specifications/spatial_experiment/1.2.md).
- `string_factor`:
[1.0](https://github.com/ArtifactDB/takane/tree/gh-pages/docs/specifications/string_factor/1.0.md).
- `summarized_experiment`:
Expand Down
2 changes: 1 addition & 1 deletion docs/specifications/_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ listings <- list.files(pattern="\\.Rmd$")
default <- "1.0"
known.variants <- list(
simple_list.Rmd="1.1",
spatial_experiment.Rmd="1.1"
spatial_experiment.Rmd=c("1.1", "1.2")
)

dest <- "compiled"
Expand Down
8 changes: 7 additions & 1 deletion docs/specifications/spatial_experiment.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The array should be two-dimensional and the extent of the first dimension should
The extent of the second dimension should be either 2 or 3.
Each row of the dense array contains the spatial x/y(/z) coordinates of the corresponding sample in the spatial experiment.

The directory should contain an `images` subdirectory, which in turn contains a `mapping.h5` HDF5 file.
The directory may contain an `images` subdirectory, which in turn contains a `mapping.h5` HDF5 file.
This file should contain a `spatial_experiment` group, which contains the following children:

- `sample_names`, a 1-dimensional string dataset containing sample names.
Expand Down Expand Up @@ -94,6 +94,12 @@ Each image file should start with the magic numbers for its expected format.")
}
```

```{r, results="asis", echo=FALSE}
if (.version >= package_version("1.2")) {
cat("Alternatively, the `images` directory may be absent, in which case the `spatial_experiment` is assumed to have no images.")
}
```

## Height

The height of the `spatial_experiment` is defined in the same manner as that of the underlying [`summarized_experiment`](../summarized_experiment).
Expand Down
5 changes: 5 additions & 0 deletions include/takane/spatial_experiment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ inline void validate_image(const std::filesystem::path& path, size_t i, const st

inline void validate_images(const std::filesystem::path& path, size_t ncols, Options& options, const ritsuko::Version& version) {
auto image_dir = path / "images";
if (!std::filesystem::exists(image_dir)) {
// No images at all, which is permitted.
return;
}

auto mappath = image_dir / "mapping.h5";
auto ihandle = ritsuko::hdf5::open_file(mappath);
auto ghandle = ritsuko::hdf5::open_group(ihandle, "spatial_experiment");
Expand Down
10 changes: 10 additions & 0 deletions tests/src/spatial_experiment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ TEST_F(SpatialExperimentTest, ColumnSamples) {
expect_error("equal the number of columns");
}

TEST_F(SpatialExperimentTest, NoImages) {
spatial_experiment::Options options(20, 19);
options.num_samples = 3;
options.num_images_per_sample = 0;
spatial_experiment::mock(dir, options);
std::filesystem::remove_all(dir / "images");
EXPECT_FALSE(std::filesystem::exists(dir / "images"));
test_validate(dir);
}

TEST_F(SpatialExperimentTest, ImageSamples) {
spatial_experiment::Options options(20, 19);
options.num_samples = 3;
Expand Down

0 comments on commit 0fb4fd4

Please sign in to comment.