44import spatialdata as sd
55import anndata as ad
66import pandas as pd
7+ import sys
78import os
89import shutil
910
11+ sys .path .insert (0 , os .path .abspath ("/ClusterMap" ))
12+
1013import time
1114from datetime import timedelta
1215import math
@@ -76,7 +79,7 @@ def run_clustermap_over_chunks(
7679 ):
7780 """
7881 """
79-
82+
8083 # Infer parameters
8184 num_gene = np .max (spots ['gene' ])
8285 num_dims = len (dapi .shape )
@@ -102,7 +105,7 @@ def run_clustermap_over_chunks(
102105
103106 if spots_tile .shape [0 ] < 20 :
104107 continue
105-
108+
106109 # Instantiate model for tile
107110 t0_model = time .time ()
108111 model_tile = ClusterMap (
@@ -111,14 +114,14 @@ def run_clustermap_over_chunks(
111114 )
112115 time_model = timedelta (seconds = (time .time () - t0_model ))
113116
114-
117+
115118 # Preprocessing
116119 t0_prepro = time .time ()
117120 model_tile .preprocess (
118121 dapi_grid_interval = dapi_grid_interval , pct_filter = pct_filter , LOF = LOF , contamination = contamination
119122 )
120123 time_prepro = timedelta (seconds = (time .time () - t0_prepro ))
121-
124+
122125 # Segmentation
123126 model_tile .min_spot_per_cell = min_spot_per_cell
124127 t0_segment = time .time ()
@@ -143,7 +146,7 @@ def run_clustermap_over_chunks(
143146 flush = True
144147 )
145148 #TODO: include an assertion for an expected_time < 24 h? And a recommendation to decrease dapi_grid_interval?/data_size
146-
149+
147150
148151 return model .spots
149152
@@ -164,7 +167,7 @@ def run_clustermap(
164167 spots = spots , dapi = dapi , gene_list = gene_list , num_dims = num_dims , xy_radius = xy_radius , z_radius = z_radius ,
165168 fast_preprocess = fast_preprocess , gauss_blur = gauss_blur , sigma = sigma
166169 )
167-
170+
168171 # Preprocessing
169172 model .preprocess (dapi_grid_interval = dapi_grid_interval , pct_filter = pct_filter , LOF = LOF , contamination = contamination )
170173
@@ -174,7 +177,7 @@ def run_clustermap(
174177 cell_num_threshold = cell_num_threshold , dapi_grid_interval = dapi_grid_interval , add_dapi = add_dapi ,
175178 use_genedis = use_genedis
176179 )
177-
180+
178181 return model .spots
179182
180183
@@ -208,7 +211,8 @@ def run_clustermap(
208211if isinstance (sdata_segm ["segmentation" ], xr .DataTree ):
209212 label_image = sdata_segm ["segmentation" ]["scale0" ].image .to_numpy ()
210213else :
211- label_image = sdata_segm ["segmentation" ].to_numpy ()
214+ label_image = sdata_segm ["segmentation" ].to_numpy ()
215+
212216dapi_image = np .squeeze (sdata ['morphology_mip' ]['scale0' ]['image' ].compute ())
213217
214218# Extract coordinates and feature names (= gene names) from SpatialData
@@ -297,4 +301,5 @@ def run_clustermap(
297301print ('Write transcripts with cell ids' , flush = True )
298302if os .path .exists (par ["output" ]):
299303 shutil .rmtree (par ["output" ])
304+
300305sdata_transcripts_only .write (par ['output' ])
0 commit comments