Skip to content

Commit

Permalink
Merge pull request #94 from MannLabs/fix_sdata_annotations
Browse files Browse the repository at this point in the history
Fix sdata annotations
  • Loading branch information
sophiamaedler authored Nov 5, 2024
2 parents a988cee + da3270d commit 5cf7169
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/scportrait/pipeline/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ def _write_results_sdata(self, results, label, mask_type="seg_all"):
# save nucleus segmentation
obs = pd.DataFrame()
obs.index = obs_indices
obs["instance_id"] = obs_indices
obs["instance_id"] = obs_indices.astype(
int
) # this needs to be int otherwise data will not be loaded correctly
obs["region"] = f"{mask_type}_{self.MASK_NAMES[0]}"
obs["region"] = obs["region"].astype("category")

Expand All @@ -564,7 +566,7 @@ def _write_results_sdata(self, results, label, mask_type="seg_all"):
instance_key="instance_id",
)

self.project._write_table_object_sdata(
self.filehandler._write_table_object_sdata(
table,
f"{self.__class__.__name__ }_{label}_{self.MASK_NAMES[0]}",
overwrite=self.overwrite_run_path,
Expand All @@ -574,7 +576,9 @@ def _write_results_sdata(self, results, label, mask_type="seg_all"):
# save cytoplasm segmentation
obs = pd.DataFrame()
obs.index = obs_indices
obs["instance_id"] = obs_indices
obs["instance_id"] = obs_indices.astype(
int
) # this needs to be int otherwise data will not be loaded correctly
obs["region"] = f"{mask_type}_{self.MASK_NAMES[1]}"
obs["region"] = obs["region"].astype("category")

Expand All @@ -586,7 +590,7 @@ def _write_results_sdata(self, results, label, mask_type="seg_all"):
instance_key="instance_id",
)

self.project._write_table_object_sdata(
self.filehandler._write_table_object_sdata(
table,
f"{self.__class__.__name__ }_{label}_{self.MASK_NAMES[1]}",
overwrite=self.overwrite_run_path,
Expand Down Expand Up @@ -1200,7 +1204,7 @@ def _write_results_sdata(self, results, mask_type="seg_all"):

obs = pd.DataFrame()
obs.index = obs_indices
obs["instance_id"] = obs_indices
obs["instance_id"] = obs_indices.astype(int)
obs["region"] = f"{mask_type}_{self.MASK_NAMES[0]}"
obs["region"] = obs["region"].astype("category")

Expand Down Expand Up @@ -1236,7 +1240,7 @@ def _write_results_sdata(self, results, mask_type="seg_all"):

obs = pd.DataFrame()
obs.index = obs_indices
obs["instance_id"] = obs_indices
obs["instance_id"] = obs_indices.astype(int)
obs["region"] = f"{mask_type}_{self.MASK_NAMES[1]}"
obs["region"] = obs["region"].astype("category")

Expand Down
4 changes: 2 additions & 2 deletions src/scportrait/pipeline/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def load_input_from_sdata(

table = remap_region_annotation_table(table, region_name=region_name)

self._write_table_object_sdata(table, new_table_name)
self.filehandler._write_table_object_sdata(table, new_table_name)
self.log(
f"Added annotation {new_table_name} to spatialdata object for segmentation object {region_name}."
)
Expand All @@ -955,7 +955,7 @@ def load_input_from_sdata(
new_table_name = f"annot_{region_name}_{table_name}"

table = remap_region_annotation_table(table, region_name=region_name)
self._write_table_object_sdata(table, new_table_name)
self.filehandler._write_table_object_sdata(table, new_table_name)

self.log(
f"Added annotation {new_table_name} to spatialdata object for segmentation object {region_name}."
Expand Down

0 comments on commit 5cf7169

Please sign in to comment.