@@ -45,6 +45,7 @@ def visium_hd(
4545 annotate_table_by_labels : bool = False ,
4646 fullres_image_file : str | Path | None = None ,
4747 load_all_images : bool = False ,
48+ var_names_make_unique : bool = True ,
4849 imread_kwargs : Mapping [str , Any ] = MappingProxyType ({}),
4950 image_models_kwargs : Mapping [str , Any ] = MappingProxyType ({}),
5051 anndata_kwargs : Mapping [str , Any ] = MappingProxyType ({}),
@@ -61,7 +62,8 @@ def visium_hd(
6162 path
6263 Path to directory containing the *10x Genomics* Visium HD output.
6364 dataset_id
64- Unique identifier of the dataset. If `None`, it tries to infer it from the file name of the feature slice file.
65+ Unique identifier of the dataset, used to name the elements of the `SpatialData` object. If `None`, it tries to
66+ infer it from the file name of the feature slice file.
6567 filtered_counts_file
6668 It sets the value of `counts_file` to ``{vx.FILTERED_COUNTS_FILE!r}`` (when `True`) or to
6769 ``{vx.RAW_COUNTS_FILE!r}`` (when `False`).
@@ -80,6 +82,8 @@ def visium_hd(
8082 load_all_images
8183 If `False`, load only the full resolution, high resolution and low resolution images. If `True`, also the
8284 following images: ``{vx.IMAGE_CYTASSIST!r}``.
85+ var_names_make_unique
86+ If `True`, call `.var_names_make_unique()` on each `AnnData` table.
8387 imread_kwargs
8488 Keyword arguments for :func:`imageio.imread`.
8589 image_models_kwargs
@@ -100,7 +104,8 @@ def visium_hd(
100104
101105 if dataset_id is None :
102106 dataset_id = _infer_dataset_id (path )
103- filename_prefix = f"{ dataset_id } _"
107+
108+ filename_prefix = _get_filename_prefix (path , dataset_id )
104109
105110 def load_image (path : Path , suffix : str , scale_factors : list [int ] | None = None ) -> None :
106111 _load_image (
@@ -265,6 +270,8 @@ def _get_bins(path_bins: Path) -> list[str]:
265270 region_key = str (VisiumHDKeys .REGION_KEY ),
266271 instance_key = str (VisiumHDKeys .INSTANCE_KEY ),
267272 )
273+ if var_names_make_unique :
274+ tables [bin_size_str ].var_names_make_unique ()
268275
269276 # read full resolution image
270277 if fullres_image_file is not None :
@@ -388,7 +395,8 @@ def _infer_dataset_id(path: Path) -> str:
388395 files = [file .name for file in path .iterdir () if file .is_file () and file .name .endswith (suffix )]
389396 if len (files ) == 0 or len (files ) > 1 :
390397 raise ValueError (
391- f"Cannot infer `dataset_id` from the feature slice file in { path } , please pass `dataset_id` as an argument."
398+ f"Cannot infer `dataset_id` from the feature slice file in { path } , please pass `dataset_id` as an "
399+ f"argument. The `dataset_id` value will be used to name the elements in the `SpatialData` object."
392400 )
393401 return files [0 ].replace (suffix , "" )
394402
@@ -440,6 +448,16 @@ def _get_affine(coefficients: list[int]) -> Affine:
440448 return Affine (matrix , input_axes = ("x" , "y" ), output_axes = ("x" , "y" ))
441449
442450
451+ def _get_filename_prefix (path : Path , dataset_id : str ) -> str :
452+ if (path / f"{ dataset_id } _{ VisiumHDKeys .FEATURE_SLICE_FILE .value } " ).exists ():
453+ return f"{ dataset_id } _"
454+ assert (path / VisiumHDKeys .FEATURE_SLICE_FILE .value ).exists (), (
455+ f"Cannot locate the feature slice file, please ensure the file is present in the { path } directory and/or adjust"
456+ "the `dataset_id` parameter"
457+ )
458+ return ""
459+
460+
443461def _parse_metadata (path : Path , filename_prefix : str ) -> tuple [dict [str , Any ], dict [str , Any ]]:
444462 with h5py .File (path / f"{ filename_prefix } { VisiumHDKeys .FEATURE_SLICE_FILE .value } " , "r" ) as f5 :
445463 metadata = json .loads (dict (f5 .attrs )[VisiumHDKeys .METADATA_JSON ])
0 commit comments