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

Merging from dev_graph #9

Merged
merged 48 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d716dc9
Make pre-commit compliant
VarunUllanat Feb 6, 2024
c5b8cb8
Update tests-conda.yml
VarunUllanat Feb 6, 2024
50df092
Update tests-conda.yml
VarunUllanat Feb 6, 2024
45f1be6
revert back to old environment
VarunUllanat Feb 6, 2024
a6a2c5a
Merge branch 'dev_graph' of https://github.com/Dana-Farber-AIOS/pathm…
VarunUllanat Feb 6, 2024
309d489
Update tests-conda.yml to remove Deepcell install
VarunUllanat Feb 6, 2024
7c299d1
Update tests-conda.yml to free space
VarunUllanat Feb 6, 2024
123a0e6
Merge pull request #417 from sreekarreddydfci/dev-tilestitching
sreekarreddydfci Feb 7, 2024
5ebc325
Merge remote-tracking branch 'upstream/dev_graph' into dev-tilestitching
sreekarreddydfci Feb 7, 2024
33f02e7
Merge pull request #418 from Dana-Farber-AIOS/dev-tilestitching
VarunUllanat Feb 7, 2024
ce0c253
Added new two-hop computation
VarunUllanat Feb 8, 2024
2650d5a
Merge branch 'dev_graph' of https://github.com/Dana-Farber-AIOS/pathm…
VarunUllanat Feb 8, 2024
1d36395
Added python version in environment file
VarunUllanat Feb 8, 2024
20757a0
Removed deepcell installation
VarunUllanat Feb 8, 2024
7a7e092
Updated graph utils and clean
VarunUllanat Feb 9, 2024
9350557
Update test_inference.py
sreekarreddydfci Feb 15, 2024
ac2e90f
Update test_inference.py
sreekarreddydfci Feb 15, 2024
5a64b73
Updated stain normalization class
VarunUllanat Feb 21, 2024
9d5885b
Updated stain normalization class
VarunUllanat Feb 21, 2024
c12ca8a
`Merge branch 'dev_graph' of https://github.com/Dana-Farber-AIOS/path…
VarunUllanat Feb 21, 2024
b1f37f4
Updated graph utils tests
VarunUllanat Feb 21, 2024
0d1ad73
Updated example notebooks
sreekarreddydfci Feb 22, 2024
f213b02
Merge remote-tracking branch 'upstream/dev_graph' into dev-tilestitching
sreekarreddydfci Feb 22, 2024
85ce24d
Updated graphs notebook
sreekarreddydfci Feb 22, 2024
044b9bb
Added documentation for graph API
VarunUllanat Feb 22, 2024
09fae9b
Merge pull request #419 from sreekarreddydfci/dev-tilestitching
sreekarreddydfci Feb 22, 2024
9a40d2d
Merge pull request #420 from Dana-Farber-AIOS/dev-tilestitching
VarunUllanat Feb 22, 2024
5a4a493
Updated environment file, added instructions and references
VarunUllanat Feb 23, 2024
90288b4
Cleaned up examples and setup.py
VarunUllanat Feb 23, 2024
71dbb29
Updated example notebook
sreekarreddydfci Feb 26, 2024
7c884fd
Updated notebooks and docs
VarunUllanat Feb 26, 2024
8ad8149
Updated notebooks and docs
VarunUllanat Feb 26, 2024
5cde633
Added JCO example
VarunUllanat Feb 26, 2024
354a1b9
Added JCO example
VarunUllanat Feb 26, 2024
c402649
Reformatted README installation instructions
VarunUllanat Feb 27, 2024
0e5a0c0
Update README.md
VarunUllanat Feb 27, 2024
f72c00c
Update README.md
VarunUllanat Feb 28, 2024
52582b2
Update README.md
VarunUllanat Feb 28, 2024
2b7ff01
Update setup.py to add torch cuda installation
VarunUllanat Feb 28, 2024
0ebb8d7
Update README.md
VarunUllanat Feb 28, 2024
6ce5d82
Added comments for stain normalization
VarunUllanat Feb 28, 2024
f017775
Added our implementation of mesmer model
VarunUllanat Mar 1, 2024
4b88260
Adding note on where mesmer output is saved to doc string
jamesgwen Mar 4, 2024
f803c46
Adjusting the header in mesmer utils file to contain citation
jamesgwen Mar 4, 2024
e96a80f
Added betters tests for segmentmif
VarunUllanat Mar 4, 2024
a3b998c
Added no coverage comments
VarunUllanat Mar 4, 2024
af6b9a1
Merging changes from dev_graph
sreekarreddydfci Mar 5, 2024
e12fc8e
Merge branch 'dev-crossplatformtests' into dev-tilestitching
sreekarreddydfci Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
timeout-minutes: 120

steps:

- uses: actions/checkout@v2

- name: Set up JDK 17
Expand Down Expand Up @@ -185,6 +186,7 @@ jobs:
# # $binPath = Join-Path ${{ github.workspace }} "openslide-binaries/openslide-win64-20231011/bin"
# # Get-ChildItem -Path $binPath
# # shell: pwsh


# - name: Check PATH
# run: |
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Building documentation locally
.. code-block::

cd docs # enter docs directory
pip install -r readthedocs-requirements # install packages to build docs
pip install -r readthedocs-requirements.txt # install packages to build docs
make html # build docs in html format

Then use your favorite web browser to open ``pathml/docs/build/html/index.html``
Expand Down
135 changes: 68 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,19 @@ Imaging datasets in cancer research are growing exponentially in both quantity a
:construction: the `dev` branch is under active development, with experimental features, bug fixes, and refactors that may happen at any time!
Stable versions are available as tagged releases on GitHub, or as versioned releases on PyPI


# Installation

There are several ways to install `PathML`:
`PathML` is an advanced tool for pathology image analysis. Below are simplified instructions to help you install PathML on your system. Whether you're a user or a developer, follow these steps to get started.

1. `pip install` from PyPI (**recommended for users**)
2. Clone repo to local machine and install from source (recommended for developers/contributors)
3. Use the PathML Docker container
## 1. Prerequisites

Options (1) and (2) require that you first install all external dependencies:
* OpenSlide
* JDK 17
We recommend using [Conda](https://conda.io/projects/conda/en/latest/user-guide/getting-started.html#) for managing your environments.

We recommend using conda for environment management.
Download Miniconda [here](https://docs.conda.io/en/latest/miniconda.html)
#### Installing Conda

*Note: these instructions are for Linux. Commands may be different for other platforms.*
If you don't have Conda installed, you can download Miniconda [here]. (https://docs.conda.io/en/latest/miniconda.html)

### Updating Conda and Using libmamba
#### Updating Conda and Using libmamba

Recent versions of Conda have integrated `libmamba`, a faster dependency solver. To benefit from this improvement, first ensure your Conda is updated:

Expand All @@ -61,84 +55,56 @@ conda install -n base conda-libmamba-solver
conda config --set solver libmamba
````

Please refer to [this Anaconda blog post](https://www.anaconda.com/blog/a-faster-conda-for-a-growing-community).
*Note: these instructions are for Linux. Commands may be different for other platforms.*

## Installation option 1: pip install
## 2. PathML Installation Methods

### Common Steps
### 2.1 Install with pip (Recommended for Users)

Create conda environment:
#### Common Steps

Create and Activate Conda Environment:
````
conda create --name pathml python=3.9
conda activate pathml
````

### Platform-Specific External Dependencies
#### Platform-Specific External Dependencies

#### Install external dependencies (Linux) with [Apt](https://ubuntu.com/server/docs/package-management):
* Linux: Install external dependencies with [Apt](https://ubuntu.com/server/docs/package-management):
````
sudo apt-get install openslide-tools g++ gcc libblas-dev liblapack-dev
````

#### Install external dependencies (MacOS) with [Brew](www.brew.sh):
* MacOS: Install external dependencies with [Brew](www.brew.sh):
````
brew install openslide
````

#### Windows
* Windows:

##### Option A: Install with [vcpkg](https://vcpkg.io/en/):
1. Option A: Install with [vcpkg](https://vcpkg.io/en/):
````
vcpkg install openslide
````

##### Option B: Using Pre-built OpenSlide Binaries (Alternative)
2. Option B: Using Pre-built OpenSlide Binaries (Alternative)
For Windows users, an alternative to using `vcpkg` is to download and use pre-built OpenSlide binaries. This method is recommended if you prefer a quicker setup.

1. Download the OpenSlide Windows binaries from the [OpenSlide Downloads](https://openslide.org/download/) page.
2. Extract the archive to your desired location, e.g., `C:\OpenSlide\`.

**Importing PathML in Windows:**

Insert the following code snippet at the beginning of your Python script or Jupyter notebook before importing PathML. This code sets up the DLL directory for OpenSlide, ensuring that the library is properly loaded:

```python
- Download the OpenSlide Windows binaries from the [OpenSlide Downloads](https://openslide.org/download/) page.
- Extract the archive to your desired location, e.g., `C:\OpenSlide\`.

# The path can also be read from a config file, etc.
OPENSLIDE_PATH = r'c:\path\to\openslide-win64\bin'

import os
if hasattr(os, 'add_dll_directory'):
# Windows-specific setup
with os.add_dll_directory(OPENSLIDE_PATH):
import openslide
else:
# For other OSes, this step is not needed
import openslide

# Now you can proceed with using PathML
import pathml

```
This code snippet ensures that the OpenSlide DLLs are correctly found by Python on Windows systems. Replace c:\path\to\openslide-win64\bin with the actual path where you extracted the OpenSlide binaries.

If you encounter any DLL load failures, verify that the OpenSlide `bin` directory is correctly added to your `PATH`.

### Install OpenJDK 17
#### Install OpenJDK 17
````
conda install -c conda-forge 'openjdk<=18.0'
````

### Optionally install CUDA

[Follow instructions here](#CUDA)

### Install `PathML` from PyPI
#### Install `PathML` from PyPI
````
pip install pathml
````

## Installation option 2: clone repo and install from source
### 2.2 Install from Source (Recommended for Developers)

Clone repo:
````
Expand All @@ -147,19 +113,19 @@ cd pathml
````

Create conda environment:

````
conda env create -f environment.yml
conda activate pathml
````

Optionally install CUDA (instructions [here](#CUDA))
To use GPU acceleration for model training or other tasks, you must install CUDA. The default CUDA version in our environment file is 11.6. To install a different CUDA version, refer to the instructions [here](##CUDA)).

Install `PathML` from source:
````
pip install -e .
````

## Installation option 3: Docker
### 2.3 Use Docker Container

First, download or build the PathML Docker container:

Expand Down Expand Up @@ -196,7 +162,7 @@ Note that these instructions assume that there are no other processes using port
Please refer to the `Docker run` [documentation](https://docs.docker.com/engine/reference/run/) for further instructions
on accessing the container, e.g. for mounting volumes to access files on a local machine from within the container.

## Option 4: Google Colab
### 2.4 Use Google Colab

To get PathML running in a Colab environment:

Expand All @@ -214,6 +180,38 @@ os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-17-openjdk-amd64"
*Thanks to all of our open-source collaborators for helping maintain these installation instructions!*
*Please open an issue for any bugs or other problems during installation process.*

## 3. Import PathML

After you have installed all necessary dependencies and PathML itself, import it using the following command:

````
import pathml
````

For Windows users, insert the following code snippet at the beginning of your Python script or Jupyter notebook before importing PathML. This code sets up the DLL directory for OpenSlide, ensuring that the library is properly loaded:

```python

# The path can also be read from a config file, etc.
OPENSLIDE_PATH = r'c:\path\to\openslide-win64\bin'

import os
if hasattr(os, 'add_dll_directory'):
# Windows-specific setup
with os.add_dll_directory(OPENSLIDE_PATH):
import openslide
else:
# For other OSes, this step is not needed
import openslide

# Now you can proceed with using PathML
import pathml
```
This code snippet ensures that the OpenSlide DLLs are correctly found by Python on Windows systems. Replace c:\path\to\openslide-win64\bin with the actual path where you extracted the OpenSlide binaries.

If you encounter any DLL load failures, verify that the OpenSlide `bin` directory is correctly added to your `PATH`.


## CUDA

To use GPU acceleration for model training or other tasks, you must install CUDA.
Expand All @@ -224,22 +222,25 @@ Check the version of CUDA:
nvidia-smi
````

Install correct version of `cudatoolkit`:
Replace both instances of 'cu116' in `requirements/requirements_torch.txt` with the CUDA version you see. For example, for CUDA 11.7, 'cu116' becomes 'cu117'.

Then create the environment:

````
# update this command with your CUDA version number
conda install cudatoolkit=11.0
conda env create -f environment.yml
conda activate pathml
````

After installing PyTorch, optionally verify successful PyTorch installation with CUDA support:
````
python -c "import torch; print(torch.cuda.is_available())"
````

# Using with Jupyter
## Using with Jupyter

Jupyter notebooks are a convenient way to work interactively. To use `PathML` in Jupyter notebooks:

## Set JAVA_HOME environment variable
### Set JAVA_HOME environment variable

PathML relies on Java to enable support for reading a wide range of file formats.
Before using `PathML` in Jupyter, you may need to manually set the `JAVA_HOME` environment variable
Expand All @@ -252,7 +253,7 @@ specifying the path to Java. To do so:
os.environ["JAVA_HOME"] = "/opt/conda/envs/pathml" # change path as needed
````

## Register environment as an IPython kernel
### Register environment as an IPython kernel
````
conda activate pathml
conda install ipykernel
Expand Down
13 changes: 7 additions & 6 deletions docs/source/api_datasets_reference.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Datasets API
============

PanNuke
-------
Downloadable Datasets
----------------------

.. autoapiclass:: pathml.datasets.PanNukeDataModule
.. autoapiclass:: pathml.datasets.DeepFocusDataModule

ML Dataset classes
-------------------

DeepFocus
---------

.. autoapiclass:: pathml.datasets.DeepFocusDataModule
.. autoapiclass:: pathml.datasets.TileDataset
.. autoapiclass:: pathml.datasets.EntityDataset
24 changes: 24 additions & 0 deletions docs/source/api_graph_reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Graph API
=============

Graph Building
--------------------

.. autoapiclass:: pathml.graph.preprocessing.BaseGraphBuilder
.. autoapiclass:: pathml.graph.preprocessing.KNNGraphBuilder
.. autoapiclass:: pathml.graph.preprocessing.RAGGraphBuilder
.. autoapiclass:: pathml.graph.preprocessing.MSTGraphBuilder

Tissue Extraction
------------------

.. autoapiclass:: pathml.graph.preprocessing.SuperpixelExtractor
.. autoapiclass:: pathml.graph.preprocessing.SLICSuperpixelExtractor
.. autoapiclass:: pathml.graph.preprocessing.MergedSuperpixelExtractor
.. autoapiclass:: pathml.graph.preprocessing.ColorMergedSuperpixelExtractor

Graph Feature Extraction
-------------------------

.. autoapiclass:: pathml.graph.preprocessing.GraphFeatureExtractor
:members:
23 changes: 14 additions & 9 deletions docs/source/api_ml_reference.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
ML API
======

h5path Dataset
--------------
Models
---------

.. autoapiclass:: pathml.ml.models.hovernet.HoVerNet
:members:

.. autoapiclass:: pathml.ml.TileDataset
.. autoapiclass:: pathml.ml.models.hactnet.HACTNet
:members:

HoVer-Net
Layers
---------

.. autoapiclass:: pathml.ml.HoVerNet
.. autoapiclass:: pathml.ml.layers.GNNLayer
:members:

Helper functions
^^^^^^^^^^^^^^^^

.. autoapifunction:: pathml.ml.hovernet.compute_hv_map
.. autoapifunction:: pathml.ml.models.hovernet.compute_hv_map

.. autoapifunction:: pathml.ml.models.hovernet.loss_hovernet

.. autoapifunction:: pathml.ml.models.hovernet.remove_small_objs

.. autoapifunction:: pathml.ml.hovernet.loss_hovernet
.. autoapifunction:: pathml.ml.models.hovernet.post_process_batch_hovernet

.. autoapifunction:: pathml.ml.hovernet.remove_small_objs

.. autoapifunction:: pathml.ml.hovernet.post_process_batch_hovernet
18 changes: 16 additions & 2 deletions docs/source/api_utils_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ Core Utils
.. autoapifunction:: pathml.core.utils.readcounts
.. autoapifunction:: pathml.core.utils.writecounts

Graph Utils
--------------

.. autoapifunction:: pathml.graph.utils.Graph
.. autoapifunction:: pathml.graph.utils.HACTPairData
.. autoapifunction:: pathml.graph.utils.get_full_instance_map
.. autoapifunction:: pathml.graph.utils.build_assignment_matrix
.. autoapifunction:: pathml.graph.utils.two_hop
.. autoapifunction:: pathml.graph.utils.two_hop_no_sparse

Datasets Utils
--------------

.. autoapifunction:: pathml.datasets.utils.download_from_url
.. autoapiclass:: pathml.datasets.utils.DeepPatchFeatureExtractor
.. autoapifunction:: pathml.datasets.utils.pannuke_multiclass_mask_to_nucleus_mask
.. autoapifunction:: pathml.datasets.utils.parse_file_size
.. autoapifunction:: pathml.datasets.utils._remove_modules

ML Utils
--------
Expand All @@ -34,6 +44,10 @@ ML Utils
.. autoapifunction:: pathml.ml.utils.dice_score
.. autoapifunction:: pathml.ml.utils.get_sobel_kernels
.. autoapifunction:: pathml.ml.utils.wrap_transform_multichannel
.. autoapifunction:: pathml.ml.utils.scatter_sum
.. autoapifunction:: pathml.ml.utils.broadcast
.. autoapifunction:: pathml.ml.utils.get_degree_histogram
.. autoapifunction:: pathml.ml.utils.get_class_weights

Miscellaneous Utils
-------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/source/examples/link_construct_graphs.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../examples/construct_graphs.ipynb"
}
3 changes: 3 additions & 0 deletions docs/source/examples/link_jco.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../examples/Graph_Analysis_NSCLC.ipynb"
}
Loading
Loading