choosehappy / HistoQC

HistoQC is an open-source quality control tool for digital pathology slides
BSD 3-Clause Clear License
266 stars 105 forks source link

Pipeline fails when no tissue remains #278

Closed jacksonjacobs1 closed 10 months ago

jacksonjacobs1 commented 11 months ago

I've observed an issue where HistoQC skips files (i.e, does not save masks and does not write a row to the tsv file) when no tissue remains in the usable tissue mask:

2023-12-20 16:12:19,242 - INFO - -----Working on:       /data/tortuosity_study/HTAN/kunsh_svs/HT_168_P1_S1H2_Vp1_U2.svs         51 of 838
2023-12-20 16:12:19,282 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    getMag
2023-12-20 16:12:19,567 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    getBasicStats
2023-12-20 16:12:19,567 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    LightDarkModule.saveEqualisedImage
2023-12-20 16:12:19,671 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    ClassificationModule.byExample: pen_markings
2023-12-20 16:12:21,035 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    ClassificationModule.byExample: coverslip_edge
2023-12-20 16:12:22,386 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    LightDarkModule.minimumPixelNeighborhoodFiltering
2023-12-20 16:12:22,592 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    LightDarkModule.getIntensityThresholdPercent:    dark
2023-12-20 16:12:22,711 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    BubbleRegionByRegion.detectSmoothness
2023-12-20 16:12:22,992 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    removeFatlikeTissue
2023-12-20 16:12:23,178 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    fillSmallHoles
2023-12-20 16:12:23,234 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    removeSmallObjects
2023-12-20 16:12:23,334 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    LocalTextureEstimationModule.estimateGreyComatrixFeatures:background_
2023-12-20 16:12:23,526 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    getContrast:background_
2023-12-20 16:12:23,568 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    getContrast:background_
2023-12-20 16:12:23,594 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    getContrast:background_
2023-12-20 16:12:23,619 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    identifyBlurryRegions
2023-12-20 16:12:26,094 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    finalProcessingSpur
2023-12-20 16:12:26,185 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    finalProcessingArea
2023-12-20 16:12:26,218 - WARNING - HT_168_P1_S1H2_Vp1_U2.svs - After BasicModule.finalProcessingArea NO tissue remains detectable! Downstream modules likely to be incorrect/fail
2023-12-20 16:12:26,219 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    compareToTemplates
2023-12-20 16:12:26,235 - WARNING - HT_168_P1_S1H2_Vp1_U2.svs - HistogramModule.compareToTemplates NO tissue remains detectable in mask!
2023-12-20 16:12:26,235 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    getHistogram
2023-12-20 16:12:26,302 - INFO - HT_168_P1_S1H2_Vp1_U2.svs -    LocalTextureEstimationModule.estimateGreyComatrixFeatures:final_
2023-12-20 16:12:26,325 - ERROR - /data/tortuosity_study/HTAN/kunsh_svs/HT_168_P1_S1H2_Vp1_U2.svs - Error analyzing file (skipping):     <class 'ValueError'> Inappropriate argument value (of correct type). a must be greater than 0 unless no samples are taken

This is not desired behavior because we still want to capture the extracted characteristics from these "poor quality" images.

It looks like the problem stems from passing an empty array (related to the usable tissue mask) into a downstream module (I don't believe this problem is specific to the LocalTextureEstimationModule.estimateGreyComatrixFeatures function.

I am using the config_v2.1.ini with the classification module steps uncommented.

[pipeline]
steps= BasicModule.getBasicStats
    LightDarkModule.saveEqualisedImage
    ClassificationModule.byExampleWithFeatures:pen_markings
    ClassificationModule.byExampleWithFeatures:coverslip_edge
    LightDarkModule.minimumPixelIntensityNeighborhoodFiltering
    LightDarkModule.getIntensityThresholdPercent:darktissue
    BubbleRegionByRegion.detectSmoothness
    MorphologyModule.removeFatlikeTissue
    MorphologyModule.fillSmallHoles
    MorphologyModule.removeSmallObjects
    LocalTextureEstimationModule.estimateGreyComatrixFeatures:background
    BrightContrastModule.getContrast:background
    BrightContrastModule.getBrightnessGray:background
    BrightContrastModule.getBrightnessByChannelinColorSpace:RGB_background
    BlurDetectionModule.identifyBlurryRegions
    BasicModule.finalProcessingSpur
    BasicModule.finalProcessingArea
    HistogramModule.compareToTemplates
    HistogramModule.getHistogram
    LocalTextureEstimationModule.estimateGreyComatrixFeatures:final
    BrightContrastModule.getContrast
    BrightContrastModule.getBrightnessGray
    BrightContrastModule.getBrightnessByChannelinColorSpace:RGB
    BrightContrastModule.getBrightnessByChannelinColorSpace:YUV
    DeconvolutionModule.separateStains
    SaveModule.saveFinalMask
    SaveModule.saveMacro
    SaveModule.saveThumbnails
    BasicModule.finalComputations
choosehappy commented 11 months ago

might depend on the particular module - the older ones might be more robust in that context than the newer ones? perhaps we missed some error checking code?

nanli-emory commented 10 months ago

Hi @choosehappy & @jacksonjacobs1: An empty mask (No tissue detected mask) may occur for many reasons such as setting incorrect arguments for modules in config file (area_threshold in remove_small_objects function) or random behaviors ( Classification.byExampleWithFeatures function by using subsampling and RandomForestClassifier function)

The LocalTextureEstimationModule.estimateGreyComatrixFeatures function that doesn't verify the used mask before computation causes the pipeline failure. Many modules verify the mask first before computation in HistoQC such as: https://github.com/choosehappy/HistoQC/blob/master/histoqc/DeconvolutionModule.py#L35 https://github.com/choosehappy/HistoQC/blob/master/histoqc/HistogramModule.py#L61 It is easy to fix. Lets check the mask is empty and abort early before doing the estimate. Please check PR #279.

nanli-emory commented 10 months ago

Hi Ruth,

You can try to remove nsamples_per_example: 10000 in ClassificationModule.byExampleWithFeatures:pen_markings which probably could fix the pipeline failure issue but will increase the computation time. Or you can try PR #279https://github.com/choosehappy/HistoQC/pull/279 which fixes the pipeline failure but the no tissue mask probably still exists.

Best,

Nan


From: Ruth Cranston @.> Sent: Thursday, January 4, 2024 8:44 AM To: choosehappy/HistoQC @.> Cc: Li, Nan @.>; Assign @.> Subject: [External] Re: [choosehappy/HistoQC] Pipeline fails when no tissue remains (Issue #278)

Hi,

I've found this issue with my own images. I found that uncommenting ClassificationModule.byExampleWithFeatures:pen_markings in any config file caused my run to fail. I think maybe this threshold is too high for my image set - I'm going to try changing the threshold and see if I can get it to work.

— Reply to this email directly, view it on GitHubhttps://github.com/choosehappy/HistoQC/issues/278#issuecomment-1877210844, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJSZZPHW7YYJFZATKHB3XDDYM254VAVCNFSM6AAAAABA5C4OHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZXGIYTAOBUGQ. You are receiving this because you were assigned.Message ID: @.***>