Skip to content

Commit

Permalink
Make GNN plots available as an SPT CLI command and API endpoint (#320)
Browse files Browse the repository at this point in the history
* move into spt/graphs

* sketch CLI

* rename fraction plotter

* rely on api server implementation for now

* accommodate configreader's stripped down toml support

* rename db upload_sync

* add gnn plot api endpoint

* hotfix typos, missing import

* add gnn plot config table

* finish apiserver endpoint

* change upload-sync-small to upload a config file string

* have fastapi handle img format validation

* remove unused file

* Update test artifact

* remove weird thread pool stuff

* hotfix config reading when calling from apiserver

* update analysis_replication for gnn plots

* Version bump

* Remove some build dependencies

---------

Co-authored-by: James Mathews <mail@jmath.read-books.org>
  • Loading branch information
CarlinLiao and jimmymathews committed May 15, 2024
1 parent fcf5342 commit f1ce820
Show file tree
Hide file tree
Showing 28 changed files with 739 additions and 292 deletions.
10 changes: 5 additions & 5 deletions analysis_replication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ substituting the argument with the address of your local API server. (See *Setti
- You can alternatively store the API host in `api_host.txt` and omit the command-line argument above.
- The run result is here in [results.txt](results.txt).

# Cell arrangment figure generation
## Cell arrangement figure generation

One figure is generated programmatically from published source TIFF files.
To run the figure generation script, alter the command below to reference your own database configuration file and path to unzipped Moldoveanu et al dataset.
Expand All @@ -39,11 +39,11 @@ To run the figure generation script, alter the command below to reference your o
python retrieve_example_plot.py dataset_directory/ ~/.spt_db.config
```

# GNN importance fractions figure generation
## GNN importance fractions figure generation

Another figure is generated programmatically from extractions from Graph Neural Network models, provided by the API.
This plot replication requires the installation of SPT, as it's not a script in this directory. Instead, it's a command in the `spt graphs` CLI that uses the configuration files stored in `gnn_figure/` to reproduce the plots seen in our publication.

```bash
cd gnn_figure/
python graph_plugin_plots.py
spt graphs plot-importance-fractions --config_path gnn_figure/melanoma_intralesional_il2.config --output_filename gnn_figure/melanoma_intralesional_il2.png
spt graphs plot-importance-fractions --config_path gnn_figure/urothelial_ici.config --output_filename gnn_figure/urothelial_ici.png
```
15 changes: 15 additions & 0 deletions analysis_replication/gnn_figure/melanoma_intralesional_il2.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[general]
study_name = Melanoma intralesional IL2

[plot-importance-fractions]
host_name = http://oncopathtk.org/api
phenotypes = Tumor, Adipocyte or Langerhans cell, Natural killer cell, CD4+ T cell, Nerve, B cell, CD4+/CD8+ T cell, CD4+ regulatory T cell, CD8+ natural killer T cell, CD8+ regulatory T cell, CD8+ T cell, Double negative regulatory T cell, T cell/null phenotype, Natural killer T cell, CD4+ natural killer T cell
plugins = cg-gnn, graph-transformer
figure_size = 11, 8
orientation = horizontal
[plot-importance-fractions.cohort0]
index_int = 1
label = Non-responder
[plot-importance-fractions.cohort1]
index_int = 3
label = Responder
63 changes: 0 additions & 63 deletions analysis_replication/gnn_figure/melanoma_intralesional_il2.json

This file was deleted.

15 changes: 15 additions & 0 deletions analysis_replication/gnn_figure/urothelial_ici.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[general]
study_name = Urothelial ICI

[plot-importance-fractions]
host_name = http://oncopathtk.org/api
phenotypes = Tumor, CD4- CD8- T cell, T cytotoxic cell, T helper cell, Macrophage, intratumoral CD3+ LAG3+, Regulatory T cell
plugins = cg-gnn, graph-transformer
figure_size = 14, 5
orientation = vertical
[plot-importance-fractions.cohort0]
index_int = 1
label = Responder
[plot-importance-fractions.cohort1]
index_int = 2
label = Non-responder
41 changes: 0 additions & 41 deletions analysis_replication/gnn_figure/urothelial_ici.json

This file was deleted.

1 change: 1 addition & 0 deletions build/apiserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN python -m pip install scikit-learn==1.2.2
RUN python -m pip install Pillow==9.5.0
RUN python -m pip install pydantic==2.0.2
RUN python -m pip install secure==0.3.0
RUN python -m pip install matplotlib==3.7.1
ARG version
ARG service_name
ARG WHEEL_FILENAME
Expand Down
2 changes: 1 addition & 1 deletion build/apiserver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ ${TESTS}: setup-testing
clean:
>@rm -f ${WHEEL_FILENAME}
>@rm -f status_code
>@for f in dlogs.db.txt dlogs.api.txt dlogs.od.txt ../../${TEST_LOCATION}\/${MODULE_NAME}/_proximity.json ../../${TEST_LOCATION}\/${MODULE_NAME}/_squidpy.json; do rm -f $$f; done;
>@for f in dlogs.db.txt dlogs.api.txt dlogs.od.txt ../../${TEST_LOCATION}\/${MODULE_NAME}/_proximity.json ../../${TEST_LOCATION}\/${MODULE_NAME}/_squidpy.json ../../${TEST_LOCATION}\/${MODULE_NAME}/_gnn.svg ; do rm -f $$f; done;
7 changes: 7 additions & 0 deletions build/build_scripts/.graph_transformer.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[general]
db_config_file_path = build/db/.spt_db.config.local
study_name = Melanoma intralesional IL2

[upload-importances]
plugin_used = graph-transformer
datetime_of_run = 2023-10-02 10:46 AM
6 changes: 3 additions & 3 deletions build/build_scripts/expected_table_counts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
diagnosis 2
diagnostic_selection_criterion 4
expression_quantification 18200
feature_specification 1
feature_specifier 4
feature_specification 2
feature_specifier 8
histological_structure 700
histological_structure_identification 700
histology_assessment_process 7
intervention 2
plane_coordinates_reference_system 0
publication 2
quantitative_feature_value 700
quantitative_feature_value 1400
research_professional 32
shape_file 700
specimen_collection_process 7
Expand Down
4 changes: 3 additions & 1 deletion build/build_scripts/import_test_dataset1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ nextflow run .
rm -f .nextflow.log*; rm -rf .nextflow/; rm -f configure.sh; rm -f run.sh; rm -f main.nf; rm -f nextflow.config; rm -rf work/; rm -rf results/

spt graphs upload-importances --config_path=build/build_scripts/.graph.config --importances_csv_path=test/test_data/gnn_importances/1.csv
spt graphs upload-importances --config_path=build/build_scripts/.graph_transformer.config --importances_csv_path=test/test_data/gnn_importances/1.csv

spt db upload-sync-findings --database-config-file=build/db/.spt_db.config.local test/test_data/findings.json
spt db upload-sync-small --database-config-file=build/db/.spt_db.config.local findings test/test_data/findings.json
spt db upload-sync-small --database-config-file=build/db/.spt_db.config.local gnn_plot_configurations test/test_data/gnn_plot.json

spt db status --database-config-file build/db/.spt_db.config.local > table_counts.txt
diff build/build_scripts/expected_table_counts.txt table_counts.txt
Expand Down
4 changes: 3 additions & 1 deletion docs/maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ The modules in this repository are built, tested, and deployed using `make` and
| [Docker Engine](https://docs.docker.com/engine/install/) | 20.10.17 |
| [Docker Compose](https://docs.docker.com/compose/install/) | 2.10.2 |
| [bash](https://www.gnu.org/software/bash/) | >= 4 |
| [python](https://www.python.org/downloads/) | >=3.7 |
| [python](https://www.python.org/downloads/) | >=3.7 <3.12 |
| [postgresql](https://www.postgresql.org/download/) | 13.4 |
| [toml](https://pypi.org/project/toml/) | 0.10.2 |

A typical development workflow looks like:

Expand Down
6 changes: 6 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: spt
channels:
- conda-forge
dependencies:
- python=3.11
- libpq
4 changes: 3 additions & 1 deletion pyproject.toml.unversioned
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ repository = "https://github.com/nadeemlab/SPT"

[project.optional-dependencies]
apiserver = [
"matplotlib==3.7.1",
"fastapi==0.100.0",
"uvicorn>=0.15.0,<0.16.0",
"pandas==2.0.2",
Expand Down Expand Up @@ -190,7 +191,7 @@ packages = [
"drop.py",
"drop_ondemand_computations.py",
"delete_feature.py",
"upload_sync_findings.py",
"upload_sync_small.py",
"collection.py",
]
"spatialprofilingtoolbox.db.data_model" = [
Expand All @@ -211,6 +212,7 @@ packages = [
"extract.py",
"finalize_graphs.py",
"generate_graphs.py",
"plot_importance_fractions.py",
"plot_interactives.py",
"prepare_graph_creation.py",
"upload_importances.py",
Expand Down

0 comments on commit f1ce820

Please sign in to comment.