Skip to content

Unable to patch with use_mask=False #101

@katimbach

Description

@katimbach

Creating HEST objects from some of my objects, I have found that masking sometimes misses tissue areas (both using deep and otsu), so downstream patches are not created for those areas based on the defaults of dump_patches:

Image

I was trying to get around this by setting use_mask=False, but it throws an error about valid barcodes:

UnboundLocalError                         Traceback (most recent call last)
Cell In[32], line 2
      1 new_patch_size = 224 # size of patches used as input for UNI and Virchow2
----> 2 st.dump_patches(patches_dir,
      3                 target_patch_size=new_patch_size, target_pixel_size=0.5,
      4                 use_mask=False)

File ~/HEST/src/hest/HESTData.py:346, in HESTData.dump_patches(self, patch_save_dir, name, target_patch_size, target_pixel_size, verbose, dump_visualization, use_mask, threshold, coords_only)
    343 if mask is not None:
    344     valid_barcodes = barcodes[patcher.valid_mask]
--> 346 patcher.to_h5(h5_path, extra_assets={'barcode': valid_barcodes})
    348 if dump_visualization:
    349     patcher.save_visualization(os.path.join(patch_save_dir, name + '_patch_vis.png'), dpi=400)

UnboundLocalError: local variable 'valid_barcodes' referenced before assignment"

I also tried just not masking for the sample, and not specifying use_mask, but this led to:
Exception: No tissue segmentation attached to this sample, segment tissue first by calling segment_tissue() for this object

Briefly, I have run my samples with autoalignment upstream- though I have /spatial/ output from cellranger, I do not have alignment.json available, and providing the spatial_coord_path was resulting in misalignment of spots, so I switched to auto.

Is it possible to ignore the masking, and force patching around every spot in st.adata.obs.index?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions