Skip to content

Commit

Permalink
GeometryCollectionLegacy polygon format
Browse files Browse the repository at this point in the history
*Requested by Matthew Cai*
  • Loading branch information
Viktor Petukhov committed Nov 14, 2024
1 parent a51b70f commit 61f1daf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/cli/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ Run cell segmentation
(default: 4)
- `-o, --output=<path>`: Name of the output file or path to the output directory (default: "segmentation.csv")
- `--polygon-format=<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=<ss>`: 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=<s>`: Scale parameter, which suggest approximate cell radius for the algorithm. Must be in the same
Expand Down
10 changes: 8 additions & 2 deletions src/data_loading/cli_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 61f1daf

Please sign in to comment.