Skip to main content

Compute H-scores in Python, including the canonical cell-based H-score and a pixel-wise implementation inspired by Ram et al. 2021.

Project description

pyhscore

CI PyPI version DOI

Install

First set up a new conda environment with some basic dependencies:

conda create -n pyhscore python pip ipykernel

Then activate the environment and install the package:

conda activate pyhscore
pip install pyhscore

How to use

Always ensure you are using an active environment where the package has been installed to. If you followed the suggested install instructions that can be done by running conda activate pyhscore.

from pyhscore import score

help(score.compute_pxlhscore)
Help on function compute_pxlhscore in module pyhscore.score:

compute_pxlhscore(hed_img, h_threshold=0.05, d_thresholds=[0.12, 0.24, 0.6], verbose=False)
    Computes the pixel H-score for a given HED (Hematoxylin and Eosin-DAB) stained image.

    The H-score is calculated based on the intensity of the DAB stain, which is
    indicative of the presence and quantity of a specific biomarker in IHC images.
    The function allows for automatic thresholding based on the distribution of staining intensities.
    Inspired by the implementation in Ram et al. 2021.

    Parameters:

    - hed_img (numpy.ndarray): The HED-stained image as a NumPy array of shape
        (height, width, channels).

    - h_threshold (str or float): Threshold for Hematoxylin intensity.
        If 'auto', the threshold is set to the mean intensity.

    - d_thresholds (str or list of floats): Thresholds for DAB intensity,
        defining negative, low, medium, and high intensity ranges.
        If 'auto', thresholds are set to the 90th, 94.95th, and 99.9th percentiles.

    - verbose (bool): If True, displays histograms of the distributions of
        Hematoxylin and DAB stain values, and images showing pixels classified
        as high, medium, low, and negative DAB stained.

    Returns:

    - pxlHscore (float): The pixel H-score, a weighted sum of pixels classified
        as having high, medium, or low DAB intensity,
        normalized by the total number of pixels considered.

Development

It is recommended to use the Dev Container provided with the repo (Miniconda with zsh enabled). Once within the container, pip install nbdev and pyhscore ".[dev]".

Ensure also that quarto is installed by doing nbdev_install_quarto.

If working with VS code, note that the nbdev jupyter clean-up hooks might not work properly, so make sure the git commit hooks are setup properly (https://nbdev.fast.ai/tutorials/pre_commit.html) or install the nbdev VS code extension.

Before commiting, ensure the following is run (either manually or via hooks/extensions)

  1. nbdev_export
  2. nbdev_test
  3. nbdev_clean
  4. nbdev_readme
  5. nbdev_preview

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhscore-0.0.3.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhscore-0.0.3-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pyhscore-0.0.3.tar.gz.

File metadata

  • Download URL: pyhscore-0.0.3.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pyhscore-0.0.3.tar.gz
Algorithm Hash digest
SHA256 94759e7230deff60eb34b774b425f8d8533a5cfb38351e58834a6e4b5566f601
MD5 ac7696c63afd39c49594b1677b604a7c
BLAKE2b-256 40d541c1a015e8997cdfdbe8821962821f314cbdb0daa9f0232a34cb7928c1e0

See more details on using hashes here.

File details

Details for the file pyhscore-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyhscore-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pyhscore-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2f8d322fbd8c736988c53f702dda51bbb52f8e9ce47842a848226218fa412cac
MD5 83a482375231842cb5c1e059a5484394
BLAKE2b-256 5b8ac503d84e414c9fe5b9daace982ad35087c9447aa45fa02c66c0689bd2bbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page