@@ -132,9 +132,14 @@ def __init__(
132132 adata , group_key , rank_key , gene_symbols_column , coordinates_key
133133 )
134134
135+ # Use original labels as IDs if all are short (<=3 chars), otherwise enumerate
136+ _unique_group_categories : list [str | int ] = natsorted (
137+ adata .obs [group_key ].unique ().tolist ()
138+ )
139+ _short_ids = all (len (str (x )) <= 3 for x in _unique_group_categories )
135140 self .cluster_map = {
136- str (x ): str (n + 1 )
137- for n , x in enumerate (natsorted ( adata . obs [ group_key ]. unique (). tolist ()) )
141+ str (x ): str (x ) if _short_ids else str ( n )
142+ for n , x in enumerate (_unique_group_categories )
138143 }
139144 self .clusters = [
140145 self .cluster_map [str (x )] for x in adata .obs [group_key ].values .tolist ()
@@ -199,6 +204,7 @@ def _build_and_upload_artifacts(
199204 obs_duckdb_path : str ,
200205 upload_timeout_seconds : int ,
201206 upload_max_workers : int = 4 ,
207+ coordinates_key : str | None = None ,
202208 ) -> tuple [dict [str , str ], list [tuple [str , Exception ]]]:
203209 """Build and upload each artifact as an independent unit.
204210
@@ -240,9 +246,16 @@ def _build_and_upload_artifacts(
240246 # --- obs.duckdb (save then upload) ---
241247 try :
242248 logger .info ("Saving obs.duckdb artifact from observation metadata..." )
249+ obsm_coordinates = (
250+ self .adata .obsm [coordinates_key ]
251+ if coordinates_key and coordinates_key in self .adata .obsm
252+ else None
253+ )
243254 save_obs_duckdb_file (
244255 out_file = obs_duckdb_path ,
245256 obs_df = self .adata .obs ,
257+ obsm_coordinates = obsm_coordinates ,
258+ coordinates_key = coordinates_key ,
246259 )
247260 logger .info ("Uploading obs.duckdb artifact..." )
248261 obs_upload = upload_obs_duckdb_file (
@@ -394,6 +407,7 @@ def run(
394407 obs_duckdb_path = obs_duckdb_path ,
395408 upload_timeout_seconds = upload_timeout_seconds ,
396409 upload_max_workers = upload_max_workers ,
410+ coordinates_key = self .coordinates_key ,
397411 )
398412 if uploaded_file_refs :
399413 payload ["uploaded_files" ] = uploaded_file_refs
0 commit comments