Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image processing with stardist #11

Open
alipirani88 opened this issue Nov 12, 2024 · 2 comments
Open

Image processing with stardist #11

alipirani88 opened this issue Nov 12, 2024 · 2 comments
Assignees

Comments

@alipirani88
Copy link

Hi, I am ex=ncountering this error while stardist image processing. Any idea what might be causing this error?

Traceback (most recent call last):
File "/rsrch5/home/neuro_rsrch/apirani/2024_11_07_Enact_Demo/enact_915422.py", line 9, in
so_hd.run_enact()
File "/home/apirani/.local/lib/python3.10/site-packages/enact/pipeline.py", line 999, in run_enact
cell_labels, cell_polys = self.segment_cells(image=wsi_norm)
File "/home/apirani/.local/lib/python3.10/site-packages/enact/pipeline.py", line 318, in segment_cells
labels, polys = self.stardist_model.predict_instances_big(
File "/home/apirani/.local/lib/python3.10/site-packages/stardist/models/base.py", line 930, in predict_instances_big
blocks = BlockND.cover(img.shape, axes, block_size, min_overlap, context, grid)
File "/home/apirani/.local/lib/python3.10/site-packages/stardist/big.py", line 448, in cover
cover_1d = [Block.cover(*args) for args in zip(shape, block_size, min_overlap, context, grid)]
File "/home/apirani/.local/lib/python3.10/site-packages/stardist/big.py", line 448, in
cover_1d = [Block.cover(args) for args in zip(shape, block_size, min_overlap, context, grid)]
File "/home/apirani/.local/lib/python3.10/site-packages/stardist/big.py", line 186, in cover
assert 0 <= min_overlap+2
context < block_size <= size
AssertionError

@Mena-SA-Kamel
Copy link
Contributor

Can you provide me more context on the configurations you used and the size of the image to be able to reproduce your error? It seems like an issue on the Stardist side with the patching/restitching steps. Here is the part of the code that runs Stardist on the image: https://github.com/Sanofi-Public/enact-pipeline/blob/c1282932af1f73e825a5afdf4ca5a27ddc64a197/src/enact/pipeline.py#L317C13-L327C14

labels, polys = self.stardist_model.predict_instances_big(
                image,
                axes="YXC",
                block_size=4096,
                prob_thresh=prob_thresh,
                nms_thresh=0.001,
                min_overlap=128,
                context=128,
                normalizer=None,
                n_tiles=(4, 4, 1),
            )

I suggest you change the block_size parameter. In a future release, we will allow users to specify the Stardist parameters as part of ENACT's parameters but for now it is hardcoded.

@alipirani88
Copy link
Author

alipirani88 commented Nov 20, 2024

Hi,

These are the parameters I am using.

analysis_name: "238688-HD01_915422-5-2"
run_synthetic: False # True if you want to run bin to cell assignment on synthetic dataset, False otherwise.
cache_dir: "/rsrch5/home/neuro_rsrch/apirani/2024_11_07_Enact_Demo/enact-pipeline/ENACT_supporting_files/output_files"
paths:
  wsi_path: "/rsrch5/home/neuro_rsrch/apirani/10X_Visium_HD_data/2024-07-23_H5_First_Batch/images/915422-5.2_bigtiff.tif"
  visiumhd_h5_path: "/rsrch5/home/neuro_rsrch/apirani/10X_Visium_HD_data/2024-07-23_H5_First_Batch/238688-HD01_915422-5-2/binned_outputs/square_002um/filtered_feature_bc_matrix.h5"
  tissue_positions_path: "/rsrch5/home/neuro_rsrch/apirani/10X_Visium_HD_data/2024-07-23_H5_First_Batch/238688-HD01_915422-5-2/binned_outputs/square_002um/spatial/tissue_positions.parquet"
steps:
  segmentation: True # True if you want to run segmentation
  bin_to_geodataframes: True # True to convert bin to geodataframes
  bin_to_cell_assignment: True # True to assign cells to bins
  cell_type_annotation: True # True to run cell type annotation
params:
  seg_method: "stardist" # Stardist is the only option for now
  patch_size: 4000 # Defines the patch size. The whole resolution image will be broken into patches of this size
  bin_representation: "polygon"  # or point TODO: Remove support for anything else
  bin_to_cell_method: "weighted_by_cluster" # or naive
  cell_annotation_method: "celltypist"
  cell_typist_model: "Human_Colorectal_Cancer.pkl"
  use_hvg: True # Only run analysis on highly variable genes + cell markers specified
  n_hvg: 1000 # Number of highly variable genes to use
  n_clusters: 4 
  chunks_to_run: [
    # "patch_2_0.csv",
    # "patch_2_1.csv",
  ]
cell_markers:
  # # Human Colon
  Epithelial: ["CDH1","EPCAM","CLDN1","CD2"]
  Enterocytes: ["CD55", "ELF3", "PLIN2", "GSTM3", "KLF5", "CBR1", "APOA1", "CA1", "PDHA1", "EHF"]
  Goblet cells: ["MANF", "KRT7", "AQP3", "AGR2", "BACE2", "TFF3", "PHGR1", "MUC4", "MUC13", "GUCA2A"]
  Enteroendocrine cells: ["NUCB2", "FABP5", "CPE", "ALCAM", "GCG", "SST", "CHGB", "IAPP", "CHGA", "ENPP2"]
  Crypt cells: ["HOPX", "SLC12A2", "MSI1", "SMOC2", "OLFM4", "ASCL2", "PROM1", "BMI1", "EPHB2", "LRIG1"]
  Endothelial: ["PECAM1","CD34","KDR","CDH5","PROM1","PDPN","TEK","FLT1","VCAM1","PTPRC","VWF","ENG","MCAM","ICAM1","FLT4"]     
  Fibroblast: ["COL1A1","COL3A1","COL5A2","PDGFRA","ACTA2","TCF21","FN"]
  Smooth muscle cell: ["BGN","MYL9","MYLK","FHL2","ITGA1","ACTA2","EHD2","OGN","SNCG","FABP4"]
  B cells: ["CD74", "HMGA1", "CD52", "PTPRC", "HLA-DRA", "CD24", "CXCR4", "SPCS3", "LTB", "IGKC"]
  T cells: ["JUNB", "S100A4", "CD52", "PFN1P1", "CD81", "EEF1B2P3", "CXCR4", "CREM", "IL32", "TGIF1"]
  NK cells: ["S100A4", "IL32", "CXCR4", "FHL2", "IL2RG", "CD69", "CD7", "NKG7", "CD2", "HOPX"]

  # # Mouse intestine
  # Enterocytes: ["Cbr1", "Plin2", "Gls", "Plin3", "Dab1", "Pmepa1", "Acsl5", "Hmox1", "Abcg2", "Cd36"]
  # Goblet cells: ["Manf", "Krt7", "Ccl9", "Muc13", "Phgr1", "Cdx2", "Aqp3", "Creb3L1", "Guca2A", "Klk1"]
  # Enteroendocrine cells: ["Fabp5", "Cpe", "Enpp2", "Chgb", "Alcam", "Chga", "Pax6", "Neurod1", "Cck", "Isl1"]
  # Paneth cells: ["Gpx2", "Fabp4", "Lyz1", "Kcnn4", "Lgals2", "Guca2B", "Lgr4", "Defa24", "Il4Ra", "Guca2A"]
  # Crypt cells: ["Prom1", "Hopx", "Msi1", "Olfm4", "Kcne3", "Bmi1", "Axin2", "Kcnq1", "Ascl2", "Lrig1"]
  # Smooth muscle cells: ["Bgn", "Myl9", "Pcp4L1", "Itga1", "Nrp2", "Mylk", "Ehd2", "Fabp4", "Acta2", "Ogn"]
  # B cells: ["Cd52", "Bcl11A", "Ebf1", "Cd74", "Ptprc", "Pold4", "Ighm", "Cd14", "Creld2", "Fli1"]
  # T cells: ["Cd81", "Junb", "Cd52", "Ptprcap", "H2-Q7", "Ccl6", "Bcl2", "Maff", "Ccl4", "Ccl3"]
  # NK cells: ["Ctla2A", "Ccl4", "Cd3G", "Ccl3", "Nkg7", "Lat", "Dusp2", "Itgam", "Fhl2", "Ccl5"]

The size of the image is 4.5G in bigtiff format.

I am experiencing another issue - Since I am running the job on HPC, I dont have the ability to access internet and the job fails with connection timeout error. Can we manually download the models and give access to them from configuration settings?

Exception: 🛑 Cannot fetch 'https://celltypist.cog.sanger.ac.uk/models/models.json', the error is: HTTPSConnectionPool(host='celltypist.cog.sanger.ac.uk', port=443): Max retries exceeded with url: /models/models.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x15530db93bb0>, 'Connection to celltypist.cog.sanger.ac.uk timed out. (connect timeout=30)'))

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants