diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a0af0d..7b7e01d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Upcoming] +### Added + +- `--polygon-format=GeometryCollectionLegacy` format similar to `GeometryCollection`, but with integer cell IDs. Used for compatibility with Xenium Ranger. This option will be deprecated after Xenium Ranger is updated. + ### Fixed - CLI argument parsing diff --git a/src/cli/main.jl b/src/cli/main.jl index 40ce6a7..dacba1e 100644 --- a/src/cli/main.jl +++ b/src/cli/main.jl @@ -28,9 +28,11 @@ Run cell segmentation (default: 4) - `-o, --output=`: Name of the output file or path to the output directory (default: "segmentation.csv") - `--polygon-format=`: Format to save estimated cell boundary polygons to a file with a specified `format`. - Two types of 'GeoJSON' format are currently supported: 'FeatureCollection' produces the - same output as Xenium Ranger and 'GeometryCollection' is the old Baysor format. Set to "none" - to disable saving polygons. (default: 'FeatureCollection'). + Two main types of 'GeoJSON' format are currently supported: 'FeatureCollection' produces the + same output as Xenium Ranger and 'GeometryCollection' is the old Baysor format. Additionally, + `GeometryCollectionLegacy` format is similar to `GeometryCollection`, but with integer cell IDs + *(used for compatibility with Xenium Ranger, this option will be deprecated after Xenium Ranger + is updated)*. Set to "none" to disable saving polygons. (default: 'FeatureCollection'). - `--scale-std=`: Standard deviation of scale across cells. Can be either number, which means absolute value of the std, or string ended with '%' to set it relative to scale (default: "25%") - `-s, --scale=`: Scale parameter, which suggest approximate cell radius for the algorithm. Must be in the same diff --git a/src/data_loading/cli_wrappers.jl b/src/data_loading/cli_wrappers.jl index f61e71e..ce9820d 100644 --- a/src/data_loading/cli_wrappers.jl +++ b/src/data_loading/cli_wrappers.jl @@ -72,15 +72,21 @@ function save_molecule_counts( return file end - """ polygons_to_geojson(polygons::PolygonCollection; format::String="FeatureCollection") Converts a collection of polygons to GeoJSON format. - Uses either `FeatureCollection` (compatible with 10x Xenium Ranger) or `GeometryCollection` (original Baysor) format. + Uses either `FeatureCollection` (10x Xenium Ranger output), `GeometryCollection` (original Baysor) or `GeometryCollectionLegacy` (Baysor v0.6 with integer cell IDs) format. """ function polygons_to_geojson(polygons::PolygonCollection; format::String="FeatureCollection") format_lc = lowercase(format) + if format_lc == "geometrycollectionlegacy" + if eltype(keys(polygons)) <: AbstractString + polygons = Dict(parse(Int, split(k, '-')[2]) => p for (k,p) in polygons) + end + + format_lc = "geometrycollection" + end if format_lc == "geometrycollection" geoms = [Dict("type" => "Polygon", "coordinates" => [collect.(eachrow(p))], "cell" => c) for (c,p) in polygons] return Dict("type" => "GeometryCollection", "geometries" => geoms);