From 7854596f9b77a6af3b1ceb8744f4798f3bbd626b Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 6 Aug 2024 14:09:28 +0200 Subject: [PATCH] disallow points with zero lenght cosmx --- src/spatialdata_io/readers/cosmx.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/spatialdata_io/readers/cosmx.py b/src/spatialdata_io/readers/cosmx.py index 258c894f..8867fa76 100644 --- a/src/spatialdata_io/readers/cosmx.py +++ b/src/spatialdata_io/readers/cosmx.py @@ -271,17 +271,18 @@ def cosmx( sub_table[CosmxKeys.INSTANCE_KEY] = sub_table[CosmxKeys.INSTANCE_KEY].astype("category") # we rename z because we want to treat the data as 2d sub_table.rename(columns={"z": "z_raw"}, inplace=True) - points[f"{fov}_points"] = PointsModel.parse( - sub_table, - coordinates={"x": CosmxKeys.X_LOCAL_TRANSCRIPT, "y": CosmxKeys.Y_LOCAL_TRANSCRIPT}, - feature_key=CosmxKeys.TARGET_OF_TRANSCRIPT, - instance_key=CosmxKeys.INSTANCE_KEY, - transformations={ - fov: Identity(), - "global": aff, - "global_only_labels": aff, - }, - ) + if len(sub_table) > 0: + points[f"{fov}_points"] = PointsModel.parse( + sub_table, + coordinates={"x": CosmxKeys.X_LOCAL_TRANSCRIPT, "y": CosmxKeys.Y_LOCAL_TRANSCRIPT}, + feature_key=CosmxKeys.TARGET_OF_TRANSCRIPT, + instance_key=CosmxKeys.INSTANCE_KEY, + transformations={ + fov: Identity(), + "global": aff, + "global_only_labels": aff, + }, + ) # TODO: what to do with fov file? # if fov_file is not None: