├── .gitattributes ├── .github └── workflows │ ├── build-unix-mac-win.yml │ ├── dockerhub.yml │ ├── docs.yml │ ├── draft-pdf.yml │ └── nbtomd.yml ├── .gitignore ├── .isort.cfg ├── .mypy.ini ├── .pydocstyle.ini ├── .pylint.ini ├── .verchew.ini ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── archive ├── _add_roi_omero.py ├── _gate_finder.py ├── _gmm_gate.py ├── _image_viewer.py ├── _rescale.py ├── _spatial_expression.py ├── dev.py ├── lasso_selector.py ├── rescale-01-04-24.py └── spatial_scatterPlot _withouttoplayer.py ├── bin ├── checksum ├── open ├── update └── verchew ├── docs ├── .Rhistory ├── CNAME ├── Functions │ ├── hl │ │ ├── addROI_omero.md │ │ ├── animate.md │ │ ├── classify.md │ │ ├── dropFeatures.md │ │ ├── merge_adata_obs.md │ │ ├── rename.md │ │ └── scimap_to_csv.md │ ├── pl │ │ ├── addROI_image.md │ │ ├── cluster_plots.md │ │ ├── densityPlot2D.md │ │ ├── distPlot.md │ │ ├── foldchange.md │ │ ├── gate_finder.md │ │ ├── groupCorrelation.md │ │ ├── heatmap.md │ │ ├── image_viewer.md │ │ ├── markerCorrelation.md │ │ ├── napariGater.md │ │ ├── pie.md │ │ ├── spatialInteractionNetwork.md │ │ ├── spatial_distance.md │ │ ├── spatial_interaction.md │ │ ├── spatial_pscore.md │ │ ├── spatial_scatterPlot.md │ │ ├── stacked_barplot.md │ │ ├── umap.md │ │ └── voronoi.md │ ├── pp │ │ ├── combat.md │ │ ├── log1p.md │ │ ├── mcmicro_to_scimap.md │ │ └── rescale.md │ └── tl │ │ ├── .Rhistory │ │ ├── cluster.md │ │ ├── foldchange.md │ │ ├── phenotype_cells.md │ │ ├── spatial_aggregate.md │ │ ├── spatial_cluster.md │ │ ├── spatial_count.md │ │ ├── spatial_distance.md │ │ ├── spatial_expression.md │ │ ├── spatial_interaction.md │ │ ├── spatial_lda.md │ │ ├── spatial_pscore.md │ │ ├── spatial_similarity_search.md │ │ └── umap.md ├── Getting Started.md ├── Tools Shortcut.md ├── assets │ ├── favicon.png │ ├── scimap_logo.jpg │ └── scimap_logo_b.png ├── contribute.md ├── index.md ├── stylesheets │ ├── .Rhistory │ ├── extra.css │ └── font │ │ ├── Avenir-Black.eot │ │ ├── Avenir-Black.ttf │ │ ├── Avenir-Black.woff │ │ ├── Avenir-Black.woff2 │ │ ├── Avenir-BlackOblique.eot │ │ ├── Avenir-BlackOblique.ttf │ │ ├── Avenir-BlackOblique.woff │ │ ├── Avenir-BlackOblique.woff2 │ │ ├── Avenir-Book.eot │ │ ├── Avenir-Book.ttf │ │ ├── Avenir-Book.woff │ │ ├── Avenir-Book.woff2 │ │ ├── Avenir-BookOblique.eot │ │ ├── Avenir-BookOblique.ttf │ │ ├── Avenir-BookOblique.woff │ │ ├── Avenir-BookOblique.woff2 │ │ ├── Avenir-Heavy.eot │ │ ├── Avenir-Heavy.ttf │ │ ├── Avenir-Heavy.woff │ │ ├── Avenir-Heavy.woff2 │ │ ├── Avenir-HeavyOblique.eot │ │ ├── Avenir-HeavyOblique.ttf │ │ ├── Avenir-HeavyOblique.woff │ │ ├── Avenir-HeavyOblique.woff2 │ │ ├── Avenir-Light.eot │ │ ├── Avenir-Light.ttf │ │ ├── Avenir-Light.woff │ │ ├── Avenir-Light.woff2 │ │ ├── Avenir-LightOblique.eot │ │ ├── Avenir-LightOblique.ttf │ │ ├── Avenir-LightOblique.woff │ │ ├── Avenir-LightOblique.woff2 │ │ ├── Avenir-Medium.eot │ │ ├── Avenir-Medium.ttf │ │ ├── Avenir-Medium.woff │ │ ├── Avenir-Medium.woff2 │ │ ├── Avenir-MediumOblique.eot │ │ ├── Avenir-MediumOblique.ttf │ │ ├── Avenir-MediumOblique.woff │ │ ├── Avenir-MediumOblique.woff2 │ │ ├── Avenir-Oblique.eot │ │ ├── Avenir-Oblique.ttf │ │ ├── Avenir-Oblique.woff │ │ ├── Avenir-Oblique.woff2 │ │ ├── Avenir-Roman.eot │ │ ├── Avenir-Roman.ttf │ │ ├── Avenir-Roman.woff │ │ └── Avenir-Roman.woff2 ├── tutorials │ ├── Releases │ │ ├── CHANGELOG.md │ │ └── license.md │ ├── archive │ │ ├── 1-scimap-tutorial-getting-started.md │ │ ├── 2-scimap-tutorial-cell-phenotyping.md │ │ ├── 3-Cell_Type_calling_and_adding_ROIs.md │ │ ├── 3-Cell_Type_calling_and_adding_ROIs_files │ │ │ ├── 3-Cell_Type_calling_and_adding_ROIs_23_2.png │ │ │ ├── 3-Cell_Type_calling_and_adding_ROIs_25_0.png │ │ │ ├── 3-Cell_Type_calling_and_adding_ROIs_27_0.png │ │ │ └── 3-Cell_Type_calling_and_adding_ROIs_35_0.png │ │ ├── 4-CellType_Proportion_Exploration.md │ │ ├── 4-CellType_Proportion_Exploration_files │ │ │ ├── 4-CellType_Proportion_Exploration_10_0.png │ │ │ ├── 4-CellType_Proportion_Exploration_16_0.png │ │ │ ├── 4-CellType_Proportion_Exploration_17_0.png │ │ │ ├── 4-CellType_Proportion_Exploration_7_0.png │ │ │ └── 4-CellType_Proportion_Exploration_8_0.png │ │ ├── 5-Simple_Spatial_Analysis.md │ │ ├── 5-Simple_Spatial_Analysis_files │ │ │ ├── 5-Simple_Spatial_Analysis_10_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_11_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_12_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_13_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_14_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_15_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_16_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_17_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_23_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_24_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_26_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_27_0.png │ │ │ ├── 5-Simple_Spatial_Analysis_32_1.png │ │ │ ├── 5-Simple_Spatial_Analysis_33_1.png │ │ │ └── 5-Simple_Spatial_Analysis_34_0.png │ │ ├── 6_animate_with_scimap.md │ │ ├── 6_animate_with_scimap_files │ │ │ ├── 6_animate_with_scimap_18_0.png │ │ │ ├── 6_animate_with_scimap_20_1.png │ │ │ ├── 6_animate_with_scimap_22_0.png │ │ │ └── 6_animate_with_scimap_24_0.png │ │ ├── scimap-tutorial-cell-phenotyping_files │ │ │ ├── scimap-tutorial-cell-phenotyping_13_0.png │ │ │ ├── scimap-tutorial-cell-phenotyping_16_0.png │ │ │ ├── scimap-tutorial-cell-phenotyping_18_0.png │ │ │ ├── scimap-tutorial-cell-phenotyping_40_0.png │ │ │ ├── scimap-tutorial-cell-phenotyping_41_0.png │ │ │ ├── scimap-tutorial-cell-phenotyping_42_0.png │ │ │ └── scimap-tutorial-cell-phenotyping_43_0.png │ │ └── scimap-tutorial-getting-started_files │ │ │ ├── scimap-tutorial-getting-started_26_0.png │ │ │ ├── scimap-tutorial-getting-started_27_0.png │ │ │ └── scimap-tutorial-getting-started_28_0.png │ ├── md │ │ ├── add_rois_scimap.md │ │ ├── add_rois_scimap_files │ │ │ ├── add_rois_scimap_11_0.png │ │ │ ├── add_rois_scimap_12_0.png │ │ │ └── add_rois_scimap_13_1.png │ │ ├── animate_scimap.md │ │ ├── animate_scimap_files │ │ │ ├── animate_scimap_11_1.png │ │ │ ├── animate_scimap_13_2.png │ │ │ ├── animate_scimap_17_0.png │ │ │ └── animate_scimap_19_1.png │ │ ├── anndata_scimap.md │ │ ├── cell_interaction_scimap.md │ │ ├── cell_interaction_scimap_files │ │ │ ├── cell_interaction_scimap_11_0.png │ │ │ ├── cell_interaction_scimap_13_0.png │ │ │ ├── cell_interaction_scimap_17_0.png │ │ │ ├── cell_interaction_scimap_19_1.png │ │ │ └── cell_interaction_scimap_7_0.png │ │ ├── cell_proportion_scimap.md │ │ ├── cell_proportion_scimap_files │ │ │ ├── cell_proportion_scimap_10_0.png │ │ │ ├── cell_proportion_scimap_13_1.png │ │ │ ├── cell_proportion_scimap_15_1.png │ │ │ ├── cell_proportion_scimap_17_0.png │ │ │ ├── cell_proportion_scimap_19_1.png │ │ │ ├── cell_proportion_scimap_4_0.png │ │ │ ├── cell_proportion_scimap_5_0.png │ │ │ └── cell_proportion_scimap_9_0.png │ │ ├── clustering_scimap.md │ │ ├── clustering_scimap_files │ │ │ ├── clustering_scimap_12_1.png │ │ │ ├── clustering_scimap_15_0.png │ │ │ └── clustering_scimap_8_1.png │ │ ├── demo_data_scimap.md │ │ ├── export_scimap.md │ │ ├── install_scimap.md │ │ ├── proximity_scimap.md │ │ ├── proximity_scimap_files │ │ │ ├── proximity_scimap_5_0.png │ │ │ ├── proximity_scimap_6_0.png │ │ │ └── proximity_scimap_8_0.png │ │ ├── scimap_helper_functions.md │ │ ├── scimap_phenotyping.md │ │ ├── scimap_phenotyping_files │ │ │ ├── scimap_phenotyping_14_0.png │ │ │ ├── scimap_phenotyping_16_0.png │ │ │ ├── scimap_phenotyping_16_1.png │ │ │ ├── scimap_phenotyping_17_0.png │ │ │ ├── scimap_phenotyping_18_1.png │ │ │ ├── scimap_phenotyping_19_1.png │ │ │ ├── scimap_phenotyping_28_1.png │ │ │ ├── scimap_phenotyping_30_1.png │ │ │ ├── scimap_phenotyping_31_0.png │ │ │ ├── scimap_phenotyping_31_1.png │ │ │ ├── scimap_phenotyping_32_0.png │ │ │ ├── scimap_phenotyping_33_1.png │ │ │ ├── scimap_phenotyping_34_0.png │ │ │ ├── scimap_phenotyping_34_1.png │ │ │ └── scimap_phenotyping_35_0.png │ │ ├── scimap_video.md │ │ ├── spatial_analysis_scimap.md │ │ ├── spatial_analysis_scimap_files │ │ │ ├── spatial_analysis_scimap_10_0.png │ │ │ ├── spatial_analysis_scimap_13_0.png │ │ │ ├── spatial_analysis_scimap_15_0.png │ │ │ ├── spatial_analysis_scimap_17_0.png │ │ │ ├── spatial_analysis_scimap_19_0.png │ │ │ ├── spatial_analysis_scimap_21_0.png │ │ │ ├── spatial_analysis_scimap_6_0.png │ │ │ └── spatial_analysis_scimap_8_0.png │ │ ├── spatial_biology_scimap.md │ │ ├── spatial_lag_scimap.md │ │ ├── spatial_lag_scimap_files │ │ │ └── spatial_lag_scimap_6_0.png │ │ ├── spatial_lda_scimap.md │ │ ├── spatial_lda_scimap_files │ │ │ ├── spatial_lda_scimap_11_0.png │ │ │ ├── spatial_lda_scimap_19_1.png │ │ │ ├── spatial_lda_scimap_22_1.png │ │ │ ├── spatial_lda_scimap_29_0.png │ │ │ └── spatial_lda_scimap_9_0.png │ │ ├── spatial_search_scimap.md │ │ └── spatial_search_scimap_files │ │ │ ├── spatial_search_scimap_13_0.png │ │ │ ├── spatial_search_scimap_19_0.png │ │ │ └── spatial_search_scimap_8_0.png │ └── nbs │ │ ├── add_rois_scimap.ipynb │ │ ├── animate_scimap.ipynb │ │ ├── anndata_scimap.ipynb │ │ ├── cell_interaction_scimap.ipynb │ │ ├── cell_proportion_scimap.ipynb │ │ ├── clustering_scimap.ipynb │ │ ├── demo_data_scimap.ipynb │ │ ├── export_scimap.ipynb │ │ ├── install_scimap.ipynb │ │ ├── proximity_scimap.ipynb │ │ ├── scimap_helper_functions.ipynb │ │ ├── scimap_phenotyping.ipynb │ │ ├── scimap_video.ipynb │ │ ├── spatial_analysis_scimap.ipynb │ │ ├── spatial_biology_scimap.ipynb │ │ ├── spatial_lag_scimap.ipynb │ │ ├── spatial_lda_scimap.ipynb │ │ └── spatial_search_scimap.ipynb └── workspace.code-workspace ├── mkdocs.yml ├── paper ├── figure-workflow.png ├── paper.bib └── paper.md ├── poetry.lock ├── pyproject.toml ├── pytest.ini └── scimap ├── __init__.py ├── __main__.py ├── cli ├── __init__.py ├── _scimap_mcmicro.py └── test.py ├── dev ├── cluster.py ├── image_viewer_vit.py └── roi_building.py ├── external └── __init__.py ├── helpers ├── __init__.py ├── addROI_omero.py ├── add_roi_scatter.py ├── animate.py ├── classify.py ├── downloadDemoData.py ├── dropFeatures.py ├── merge_adata_obs.py ├── rename.py └── scimap_to_csv.py ├── plotting ├── __init__.py ├── addROI_image.py ├── cluster_plots.py ├── densityPlot2D.py ├── distPlot.py ├── foldchange.py ├── gate_finder.py ├── groupCorrelation.py ├── heatmap.py ├── image_viewer.py ├── markerCorrelation.py ├── napariGater.py ├── pie.py ├── spatialInteractionNetwork.py ├── spatial_distance.py ├── spatial_interaction.py ├── spatial_pscore.py ├── spatial_scatterPlot.py ├── stacked_barplot.py ├── umap.py └── voronoi.py ├── preprocessing ├── __init__.py ├── combat.py ├── log1p.py ├── mcmicro_to_scimap.py ├── ngraph.py └── rescale.py ├── tests ├── _data │ ├── example_data.csv │ ├── example_data.h5ad │ └── phenotype_workflow.csv ├── expected_test_values │ ├── test_classify.pkl │ ├── test_cluster.pkl │ ├── test_combat.npz │ ├── test_foldchange.npz │ ├── test_log1p.npz │ ├── test_phenotype.pkl │ ├── test_rename.pkl │ ├── test_rescale.npz │ ├── test_spatial_aggregate.pkl │ ├── test_spatial_cluster.pkl │ ├── test_spatial_count.npz │ ├── test_spatial_distance.npz │ ├── test_spatial_expression.npz │ ├── test_spatial_lda.npz │ ├── test_spatial_pscore.npz │ ├── test_spatial_similarity_search.pkl │ └── test_umap.npz ├── scimapExampleData │ ├── exemplar-001--unmicst_cell.csv │ ├── manual_gates.csv │ ├── markers.csv │ ├── phenotype_workflow.csv │ └── scimapExampleData.h5ad ├── test_hl.py ├── test_pl.py ├── test_pp.py └── test_tl.py └── tools ├── __init__.py ├── cluster.py ├── foldchange.py ├── phenotype_cells.py ├── spatial_aggregate.py ├── spatial_cluster.py ├── spatial_count.py ├── spatial_distance.py ├── spatial_expression.py ├── spatial_interaction.py ├── spatial_lda.py ├── spatial_pscore.py ├── spatial_similarity_search.py └── umap.py /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | CHANGELOG.md merge=union 3 | -------------------------------------------------------------------------------- /.github/workflows/build-unix-mac-win.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: build-unix-mac-win 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | env: 13 | # To fix an error when running Poetry on Windows 14 | # (https://github.com/python-poetry/poetry/issues/2629), 15 | # we set Poetry's cache directory to .poetry_cache in the current directory. 16 | # It makes it easier to later remove the virtualenv when it's broken. 17 | # Absolute path is necessary to avoid this issue: 18 | # https://github.com/python-poetry/poetry/issues/3049 19 | POETRY_CACHE_DIR: ${{ github.workspace }}/.poetry_cache 20 | 21 | jobs: 22 | ci: 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | python-version: ['3.9', '3.10'] 27 | os: [ubuntu-latest, macos-13, windows-latest] 28 | runs-on: ${{ matrix.os }} 29 | 30 | steps: 31 | - name: Checkout current branch 32 | uses: actions/checkout@v4 33 | 34 | - name: Install required version of Python 35 | uses: actions/setup-python@v5 36 | with: 37 | python-version: ${{ matrix.python-version }} 38 | architecture: x64 39 | 40 | - name: Python Poetry Action 41 | uses: abatilo/actions-poetry@v2 42 | # with: 43 | # poetry-version: 1.1.2 44 | 45 | - name: Set up the cache 46 | uses: actions/cache@v3 47 | with: 48 | path: .poetry_cache 49 | key: tests-poetry-cache-v12-${{ matrix.os }}-py${{ matrix.python-version }} 50 | 51 | - name: Install project dependencies 52 | run: poetry install -vv || { rm -rf .poetry_cache/virtualenvs/*; poetry install -vv; } 53 | 54 | - name: Run tests with Poetry 55 | run: poetry run pytest 56 | -------------------------------------------------------------------------------- /.github/workflows/dockerhub.yml: -------------------------------------------------------------------------------- 1 | name: dockerhub 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | docker: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - 12 | name: Set up QEMU 13 | uses: docker/setup-qemu-action@v1 14 | - 15 | name: Set up Docker Buildx 16 | uses: docker/setup-buildx-action@v1 17 | - 18 | name: Login to DockerHub 19 | uses: docker/login-action@v1 20 | with: 21 | username: ${{ secrets.MCMICRO_USERNAME }} 22 | password: ${{ secrets.MCMICRO_TOKEN }} 23 | - 24 | name: Build and push 25 | id: docker_build 26 | uses: docker/build-push-action@v2 27 | with: 28 | push: true 29 | tags: labsyspharm/scimap:${{ github.event.release.tag_name }} 30 | - 31 | name: Image digest 32 | run: echo ${{ steps.docker_build.outputs.digest }} 33 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: docs 2 | on: 3 | push: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | deploy: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-python@v4 13 | with: 14 | python-version: 3.8 15 | architecture: x64 16 | #- run: pip install scimap mkdocs-material mkdocstrings 17 | - run: pip install mkdocs-material mkdocstrings mkdocstrings-python 18 | - run: mkdocs gh-deploy --force 19 | -------------------------------------------------------------------------------- /.github/workflows/draft-pdf.yml: -------------------------------------------------------------------------------- 1 | on: [push] 2 | 3 | jobs: 4 | paper: 5 | runs-on: ubuntu-latest 6 | name: Paper Draft 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v4 10 | - name: Build draft PDF 11 | uses: openjournals/openjournals-draft-action@master 12 | with: 13 | journal: joss 14 | # This should be the path to the paper within your repo. 15 | paper-path: paper/paper.md 16 | - name: Upload 17 | uses: actions/upload-artifact@v4 18 | with: 19 | name: paper 20 | # This is the output path where Pandoc will write the compiled 21 | # PDF. Note, this should be the same directory as the input 22 | # paper.md 23 | path: paper/paper.pdf 24 | -------------------------------------------------------------------------------- /.github/workflows/nbtomd.yml: -------------------------------------------------------------------------------- 1 | name: nbtomd 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | permissions: 12 | contents: write 13 | 14 | jobs: 15 | deploy: 16 | runs-on: ubuntu-latest 17 | env: 18 | CI_COMMIT_MESSAGE: Continuous Integration Build Artifacts 19 | CI_COMMIT_AUTHOR: Continuous Integration 20 | steps: 21 | - uses: actions/checkout@v3 22 | - uses: actions/setup-python@v4 23 | with: 24 | python-version: 3.x 25 | - uses: actions/cache@v3 26 | with: 27 | key: ${{ github.ref }} 28 | path: .cache 29 | - run: pip install jupyter 30 | - run: pip install nbconvert 31 | - run: jupyter nbconvert --to markdown docs/tutorials/nbs/*.ipynb 32 | #- run: mv docs/Tutorials/notebooks/*.md docs/Tutorials/ 33 | - run: | 34 | for file in docs/tutorials/nbs/*; do 35 | if [[ ! "$file" =~ \.ipynb$ ]]; then 36 | rsync -av --remove-source-files "$file" docs/tutorials/md/ 37 | fi 38 | done 39 | - run: ls docs/tutorials/ 40 | 41 | - name: GIT Commit 42 | # Only run on main branch push (e.g. after pull request merge). 43 | if: github.event_name == 'push' 44 | run: | 45 | git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}" 46 | git config --global user.email "ajitjohnson@users.noreply.github.com" 47 | git add docs/tutorials/md/* 48 | if [ -z "$(git status --porcelain)" ]; then 49 | echo "Nothing to commit, working tree is clean." 50 | exit 0 51 | fi 52 | git commit -m "${{ env.CI_COMMIT_MESSAGE }}" 53 | git push 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Temporary Python files 2 | *.pyc 3 | *.egg-info 4 | __pycache__ 5 | .ipynb_checkpoints 6 | setup.py 7 | pip-wheel-metadata/ 8 | 9 | # Temporary OS files 10 | Icon* 11 | .DS_Store 12 | 13 | #VS code 14 | .vscode/ 15 | 16 | # Temporary virtual environment files 17 | /.cache/ 18 | /.venv/ 19 | 20 | # Temporary server files 21 | .env 22 | *.pid 23 | 24 | # Generated documentation 25 | /docs/gen/ 26 | /docs/apidocs/ 27 | /site/ 28 | /*.html 29 | /docs/*.png 30 | 31 | # Google Drive 32 | *.gdoc 33 | *.gsheet 34 | *.gslides 35 | *.gdraw 36 | 37 | # Testing and coverage results 38 | /.coverage 39 | /.coverage.* 40 | /htmlcov/ 41 | 42 | # Build and release directories 43 | /build/ 44 | /dist/ 45 | *.spec 46 | 47 | # Sublime Text 48 | *.sublime-workspace 49 | 50 | # Eclipse 51 | .settings 52 | 53 | -------------------------------------------------------------------------------- /.isort.cfg: -------------------------------------------------------------------------------- 1 | [settings] 2 | 3 | not_skip = __init__.py 4 | 5 | multi_line_output = 3 6 | 7 | known_standard_library = dataclasses,typing_extensions 8 | known_third_party = click,log 9 | known_first_party = scimap 10 | 11 | combine_as_imports = true 12 | force_grid_wrap = false 13 | include_trailing_comma = true 14 | 15 | lines_after_imports = 2 16 | line_length = 88 17 | -------------------------------------------------------------------------------- /.mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | 3 | ignore_missing_imports = true 4 | no_implicit_optional = true 5 | check_untyped_defs = true 6 | 7 | cache_dir = .cache/mypy/ 8 | -------------------------------------------------------------------------------- /.pydocstyle.ini: -------------------------------------------------------------------------------- 1 | [pydocstyle] 2 | 3 | # D211: No blank lines allowed before class docstring 4 | add_select = D211 5 | 6 | # D100: Missing docstring in public module 7 | # D101: Missing docstring in public class 8 | # D102: Missing docstring in public method 9 | # D103: Missing docstring in public function 10 | # D104: Missing docstring in public package 11 | # D105: Missing docstring in magic method 12 | # D107: Missing docstring in __init__ 13 | # D202: No blank lines allowed after function docstring 14 | add_ignore = D100,D101,D102,D103,D104,D105,D107,D202 15 | -------------------------------------------------------------------------------- /.verchew.ini: -------------------------------------------------------------------------------- 1 | [Make] 2 | 3 | cli = make 4 | version = GNU Make 5 | 6 | [Python] 7 | 8 | cli = python 9 | version = 0.0 10 | 11 | [Poetry] 12 | 13 | cli = poetry 14 | version = 1 15 | 16 | [Graphviz] 17 | 18 | cli = dot 19 | cli_version_arg = -V 20 | version = 2 21 | optional = true 22 | message = This is only needed to generate UML diagrams for documentation. 23 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.8 2 | 3 | RUN pip install --no-cache-dir scimap --upgrade 4 | 5 | COPY . /app/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Laboratory of Systems Pharmacology @ Harvard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SCIMAP: A Python Toolkit for Integrated Spatial Analysis of Multiplexed Imaging Data 2 |
3 | 4 | [![build-unix-mac-win](https://github.com/labsyspharm/scimap/actions/workflows/build-unix-mac-win.yml/badge.svg)](https://github.com/labsyspharm/scimap/actions/workflows/build-unix-mac-win.yml) 5 | [![docs](https://github.com/labsyspharm/scimap/actions/workflows/docs.yml/badge.svg)](https://github.com/labsyspharm/scimap/actions/workflows/docs.yml) 6 | [![Downloads](https://pepy.tech/badge/scimap)](https://pepy.tech/project/scimap) 7 | [![PyPI Version](https://img.shields.io/pypi/v/scimap.svg)](https://pypi.org/project/scimap) 8 | [![PyPI License](https://img.shields.io/pypi/l/scimap.svg)](https://pypi.org/project/scimap) 9 | [![DOI](https://joss.theoj.org/papers/10.21105/joss.06604/status.svg)](https://doi.org/10.21105/joss.06604) 10 | 11 |
12 | 13 | 14 | 15 |
16 | 17 | *Scimap* is a scalable toolkit for analyzing spatial molecular data. The underlying framework is generalizable to spatial datasets mapped to XY coordinates. The package uses the [anndata](https://anndata.readthedocs.io/en/stable/anndata.AnnData.html) framework making it easy to integrate with other popular single-cell analysis toolkits. It includes preprocessing, phenotyping, visualization, clustering, spatial analysis and differential spatial testing. The Python-based implementation efficiently deals with large datasets of millions of cells. 18 | 19 | ## Citing scimap 20 | Nirmal et al., (2024). SCIMAP: A Python Toolkit for Integrated Spatial Analysis of Multiplexed Imaging Data. *Journal of Open Source Software*, 9(97), 6604, [https://doi.org/10.21105/joss.06604](https://joss.theoj.org/papers/10.21105/joss.06604#) 21 | 22 | ## Installation 23 | 24 | We strongly recommend installing `scimap` in a fresh virtual environment. 25 | 26 | ``` 27 | # If you have conda installed 28 | conda create --name scimap python=3.10 29 | conda activate scimap 30 | ``` 31 | 32 | Install `scimap` directly into an activated virtual environment: 33 | 34 | **Firstly, we suggest installing `scimap` and `napari` together to enable visualization out of the box. Keep in mind, `napari` needs a GUI toolkit, such as PyQt. If you run into any issues because of your computer's operating system, install `scimap` and `napari` separately by following the guidance in `napari's` documentation.** 35 | 36 | Here's how you can install both using pip: 37 | 38 | ```python 39 | pip install "scimap[napari]" 40 | ``` 41 | 42 | **If you encounter a problem with PyQt6 during the installation, you can install `scimap` alone first. Later on, if you find you need `napari`, you can go ahead and install it by itself.** 43 | 44 | To install just `scimap`: 45 | 46 | ```python 47 | pip install scimap 48 | ``` 49 | 50 | After installation, the package can be imported as: 51 | 52 | ```python 53 | $ python 54 | >>> import scimap as sm 55 | ``` 56 | 57 | 58 | ## Get Started 59 | 60 | #### Detailed documentation of `scimap` functions and tutorials are available [here](http://scimap.xyz/). 61 | 62 | *Scimap* development was led by [Ajit Johnson Nirmal](https://ajitjohnson.com/), Harvard Medical School. 63 | Check out other tools from the [Nirmal Lab](https://nirmallab.com/tools/). 64 | 65 | 66 | ## Contibute 67 | Interested in contributing to the package? Check out our guidelines at [https://scimap.xyz/contribute/](https://scimap.xyz/contribute/) for detailed instructions. 68 | 69 | 70 | ## Funding 71 | This work was supported by the following NIH grant K99-CA256497 72 | 73 | -------------------------------------------------------------------------------- /archive/_gmm_gate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # Created on Tue May 12 19:06:40 2020 4 | # @author: Ajit Johnson Nirmal 5 | """ abstract "Short Description" 6 | Manual Gate finder 7 | """ 8 | 9 | import pandas as pd 10 | import numpy as np 11 | from sklearn.mixture import GaussianMixture 12 | from scipy import stats 13 | import seaborn as sns; sns.set(color_codes=True) 14 | import matplotlib.pyplot as plt 15 | 16 | 17 | def gmm_gate (adata, marker_of_interest): 18 | """ 19 | Parameters: 20 | 21 | adata : Ann Data Object 22 | marker_of_interest : string 23 | Marker of interest. 24 | 25 | Returns: 26 | Distribution plot of the marker of interest along with GMM overlaid. 27 | 28 | Example: 29 | ```python 30 | sm.pl.gmm_dist_plot (adata, marker_of_interest='CD45') 31 | ``` 32 | """ 33 | 34 | # If no raw data is available make a copy 35 | if adata.raw is None: 36 | adata.raw = adata 37 | 38 | # Copy of the raw data if it exisits 39 | if adata.raw is not None: 40 | adata.X = adata.raw.X 41 | 42 | # Make a copy of the data with the marker of interest 43 | data = pd.DataFrame(np.log1p(adata.X), columns = adata.var.index, index= adata.obs.index)[[marker_of_interest]] 44 | 45 | # Clip of the top and bottom outliers before applying the model 46 | data = data.clip(lower =np.percentile(data,1), upper=np.percentile(data,99)) 47 | 48 | # Apply Gaussian mixture model 49 | m = data[marker_of_interest].values 50 | data_gm = m.reshape(-1, 1) 51 | gmm = GaussianMixture(n_components=2) 52 | gmm.fit(data_gm) 53 | gate = np.mean(gmm.means_) 54 | 55 | mean = gmm.means_ 56 | cov = gmm.covariances_ 57 | std = [ np.sqrt( np.trace(cov[i])/2) for i in range(0,2) ] 58 | #std = np.sqrt(np.trace(cov)/2) 59 | 60 | 61 | # Merge with image ID 62 | if len(adata.obs['ImageId'].unique()) > 1: 63 | # Identify the most and least positivity of the given marker of interest 64 | # Generate a dataframe with various gates 65 | dd = data.values 66 | dd = np.where(dd < gate, np.nan, dd) 67 | np.warnings.filterwarnings('ignore') 68 | dd = np.where(dd > gate, 1, dd) 69 | dd = pd.DataFrame(dd, index = data.index, columns = ['gate']) 70 | dd = dd.merge(pd.DataFrame(adata.obs['ImageId']), how='outer', left_index=True, right_index=True) 71 | dd = dd[dd['gate'] == 1] 72 | image_positivity = dd.groupby('ImageId').count().sort_values('gate') 73 | # Create a string for overlaying on image 74 | low = list(image_positivity.head(3).index) 75 | low = ','.join(low) 76 | high = list(image_positivity.tail(3).index) 77 | high = ','.join(high) 78 | # Dor image 79 | textstr = '\n'.join(( 80 | ("Most positive in: ", 81 | high, 82 | "Least positive in ", 83 | low 84 | ))) 85 | 86 | # Plot 87 | sns.set_style("white") 88 | fig, ax = plt.subplots() 89 | x = np.linspace(mean[0] - 3*std[0], mean[0] + 3*std[0], 1000) 90 | y = np.linspace(mean[1] - 3*std[1], mean[1] + 3*std[1], 1000) 91 | sns.distplot(data[marker_of_interest], color = 'grey') 92 | plt.axvline(x= mean[0], c='#000000', linestyle='dotted') 93 | plt.axvline(x= mean[1], c='#000000', linestyle='dotted') 94 | plt.plot(x, stats.norm.pdf(x, mean[0], std[0]), linestyle='dashed') 95 | plt.plot(y, stats.norm.pdf(y, mean[1], std[1]), linestyle='dashed') 96 | plt.xticks(np.arange(min(data[marker_of_interest])-1, max(data[marker_of_interest])+1, 0.5)) 97 | plt.title(marker_of_interest, fontsize=20) 98 | if len(adata.obs['ImageId'].unique()) > 1: 99 | ax.text(0.05, 0.95, textstr, fontsize=14, transform=ax.transAxes, 100 | verticalalignment='top') 101 | 102 | 103 | -------------------------------------------------------------------------------- /archive/_image_viewer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Wed Apr 1 21:57:54 2020 5 | @author: Ajit Johnson Nirmal 6 | Using Napari to Visualize images overlayed with phenotypes or any categorical column 7 | """ 8 | 9 | #%gui qt 10 | import napari 11 | import pandas as pd 12 | import random 13 | import tifffile as tiff 14 | 15 | def image_viewer (image_path, adata, overlay=None, 16 | overlay_category=None,markers=None,channel_names='default', 17 | x_coordinate='X_centroid',y_coordinate='Y_centroid',point_size=10, 18 | point_color=None,subset=None,imageid='imageid',seg_mask=None): 19 | """ 20 | Parameters 21 | ---------- 22 | image_path : string 23 | Location to the image file. 24 | seg_mask: string (The default is None) 25 | Location to the segmentation mask file. 26 | adata : AnnData Object 27 | overlay : string, optional (The default is None) 28 | Name of the column with any categorical data such as phenotypes or clusters. 29 | overlay_category : list, optional (The default is None) 30 | If only specfic categories within the overlay column is needed, pass their names as a list. 31 | If None, all categories will be used. 32 | markers : list, optional (The default is None) 33 | Markers to be included. If none, all markers will be displayed. 34 | channel_names : list, optional (The default is `adata.uns['all_markers']`) 35 | List of channels in the image in the exact order as image. 36 | x_coordinate : string, optional (The default is 'X_centroid') 37 | X axis coordinate column name in AnnData object. 38 | y_coordinate : string, optional (The default is 'Y_centroid') 39 | Y axis coordinate column name in AnnData object. 40 | point_size : int, optional (The default is 10) 41 | point size in the napari plot. 42 | imageid : string, optional *(The default is `imageid`)* 43 | Column name of the column containing the image id. 44 | subset : string, optional *(The default is None)* 45 | imageid of a single image to be subsetted for analyis. Only useful when multiple images are being analyzed together. 46 | 47 | Returns 48 | ------- 49 | None. 50 | 51 | Example 52 | ------- 53 | image_path = '/Users/aj/Desktop/ptcl_tma/image.tif' 54 | sm.pl.image_viewer (image_path, adata, overlay='phenotype',overlay_category=None, 55 | markers=['CD31', "CD3D","DNA11",'CD19','CD45','CD163','FOXP3'], 56 | point_size=7,point_color='white') 57 | 58 | """ 59 | # Plot only the Image that is requested 60 | if subset is not None: 61 | adata = adata[adata.obs[imageid] == subset] 62 | 63 | # Recover the channel names from adata 64 | if channel_names is 'default': 65 | channel_names = adata.uns['all_markers'] 66 | else: 67 | channel_names = channel_names 68 | 69 | # Index of the marker of interest and corresponding names 70 | if markers is None: 71 | idx = list(range(len(channel_names))) 72 | channel_names = channel_names 73 | else: 74 | idx = [] 75 | for i in markers: 76 | idx.append(list(channel_names).index(i)) 77 | channel_names = markers 78 | 79 | 80 | # Load the image 81 | image = tiff.imread(image_path, key = idx) 82 | 83 | # Load the segmentation mask 84 | if seg_mask is not None: 85 | seg_m = tiff.imread(seg_mask) 86 | 87 | # Load the viewer 88 | viewer = napari.view_image( 89 | image, 90 | #is_pyramid=False, 91 | channel_axis=0, 92 | name = None if channel_names is None else channel_names, 93 | visible = False) 94 | 95 | # Add the seg mask 96 | if seg_mask is not None: 97 | viewer.add_labels(seg_m, name='segmentation mask') 98 | 99 | # Add phenotype layer function 100 | def add_phenotype_layer (adata, overlay, phenotype_layer,x,y,viewer,point_size,point_color): 101 | coordinates = adata[adata.obs[overlay] == phenotype_layer] 102 | coordinates = pd.DataFrame({'y': coordinates.obs[y],'x': coordinates.obs[x]}) 103 | points = coordinates.values.tolist() 104 | if point_color is None: 105 | r = lambda: random.randint(0,255) # random color generator 106 | point_color = '#%02X%02X%02X' % (r(),r(),r()) # random color generator 107 | viewer.add_points(points, size=point_size,face_color=point_color,visible=False,name=phenotype_layer) 108 | 109 | if overlay is not None: 110 | # categories under investigation 111 | if overlay_category is None: 112 | available_phenotypes = list(adata.obs[overlay].unique()) 113 | else: 114 | available_phenotypes = overlay_category 115 | 116 | # Run the function on all phenotypes 117 | for i in available_phenotypes: 118 | add_phenotype_layer (adata=adata, overlay=overlay, 119 | phenotype_layer=i, x=x_coordinate, y=y_coordinate, viewer=viewer, 120 | point_size=point_size,point_color=point_color) 121 | -------------------------------------------------------------------------------- /archive/dev.py: -------------------------------------------------------------------------------- 1 | # %% 2 | import anndata as ad 3 | import scimap as sm 4 | 5 | adata = ad.read_h5ad( 6 | '/Users/aj/Partners HealthCare Dropbox/Ajit Nirmal/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad' 7 | ) 8 | adata 9 | # %% 10 | 11 | # %% 12 | image_path = '/Users/aj/Partners HealthCare Dropbox/Ajit Nirmal/nirmal lab/resources/exemplarData/scimapExampleData/registration/exemplar-001.ome.tif' 13 | image_viewer( 14 | adata=adata, 15 | image_path=image_path, 16 | overlay='phenotype', 17 | embed_notebook=False, 18 | point_color='white', 19 | ) 20 | # %% 21 | 22 | # %% 23 | image_viewer( 24 | adata=adata, 25 | image_path=image_path, 26 | # overlay='phenotype', 27 | embed_notebook=True, 28 | # point_color='white', 29 | backend='vitessce', 30 | ) 31 | # %% 32 | 33 | 34 | # %% 35 | from vitessce import ( 36 | VitessceConfig, 37 | CoordinationLevel as CL, 38 | get_initial_coordination_scope_prefix, 39 | ) 40 | from os.path import join 41 | import ipywidgets 42 | 43 | # %% 44 | 45 | # %% 46 | vc = VitessceConfig(schema_version="1.0.16", name="BioMedVis Challenge") 47 | dataset = vc.add_dataset(name="Blood Vessel", uid="bv").add_file( 48 | url="/Users/aj/Partners HealthCare Dropbox/Ajit Nirmal/nirmal lab/resources/exemplarData/scimapExampleData/registration/exemplar-001.ome.tif", 49 | file_type="image", 50 | ) 51 | 52 | # spatial = vc.add_view("spatialBeta", dataset=dataset) 53 | # lc = vc.add_view("layerControllerBeta", dataset=dataset) 54 | 55 | # vc.layout(spatial | lc) 56 | vw = vc.widget(js_package_version="3.4.5", remount_on_uid_change=False) 57 | vw 58 | # %% 59 | 60 | 61 | # %% 62 | import vizarr 63 | import zarr 64 | 65 | image_path = '/Users/aj/Partners HealthCare Dropbox/Ajit Nirmal/nirmal lab/resources/exemplarData/scimapExampleData/registration/exemplar-001.ome.tif' 66 | image = tiff.TiffFile(image_path, is_ome=False) # is_ome=False 67 | store = zarr.open(image.aszarr()) # convert image to Zarr array 68 | viewer = vizarr.Viewer() 69 | viewer.add_image(store) 70 | viewer 71 | # %% 72 | -------------------------------------------------------------------------------- /archive/lasso_selector.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Tue Nov 5 14:17:09 2019 4 | @author: Ajit Johnson Nirmal 5 | Program: Lasso Selector for selecting regions of interest 6 | """ 7 | 8 | # Load packages 9 | from __future__ import print_function 10 | #from six.moves import input 11 | import numpy as np 12 | from matplotlib.widgets import LassoSelector 13 | from matplotlib.path import Path 14 | from IPython import get_ipython 15 | get_ipython().run_line_magic('matplotlib', 'auto') 16 | import matplotlib.pyplot as plt 17 | 18 | class SelectFromCollection(object): 19 | """Select indices from a matplotlib collection using `LassoSelector`. 20 | 21 | Selected indices are saved in the `ind` attribute. This tool highlights 22 | selected points by fading them out (i.e., reducing their alpha values). 23 | If your collection has alpha < 1, this tool will permanently alter them. 24 | 25 | Note that this tool selects collection objects based on their *origins* 26 | (i.e., `offsets`). 27 | 28 | Parameters 29 | ---------- 30 | ax : :class:`~matplotlib.axes.Axes` 31 | Axes to interact with. 32 | 33 | collection : :class:`matplotlib.collections.Collection` subclass 34 | Collection you want to select from. 35 | 36 | alpha_other : 0 <= float <= 1 37 | To highlight a selection, this tool sets all selected points to an 38 | alpha value of 1 and non-selected points to `alpha_other`. 39 | 40 | Example: 41 | marker = 'CD45' 42 | x = adata.obs['X_position'] 43 | y = adata.obs['Y_position'] 44 | 45 | m_idx = adata.var.index.tolist().index(marker) # Get the index of marker of interest 46 | tmp_dataframe = pd.DataFrame(adata.X) 47 | hue = np.array(tmp_dataframe[m_idx]) 48 | 49 | # Plotting 50 | fig, ax = plt.subplots() 51 | pts = ax.scatter(x, y, s=1,c=hue,cmap='viridis') 52 | ax.invert_yaxis() 53 | 54 | # Function call to do the Lasso selection 55 | selector = SelectFromCollection(ax, pts) 56 | # Return indeces of the selected points 57 | tumor_idx= selector.ind 58 | len(tumor_idx) 59 | 60 | # Update adata 61 | adata.obs.loc[adata.obs.index[tumor_idx], 'roi-1'] = "roi-1" 62 | adata.obs['roi-1'].value_counts() # Checking 63 | 64 | """ 65 | 66 | def __init__(self, ax, collection,alpha_other=0.3): 67 | self.canvas = ax.figure.canvas 68 | self.collection = collection 69 | self.alpha_other = alpha_other 70 | 71 | self.xys = collection.get_offsets() 72 | self.Npts = len(self.xys) 73 | 74 | # Ensure that we have separate colors for each object 75 | self.fc = collection.get_facecolors() 76 | if len(self.fc) == 0: 77 | raise ValueError('Collection must have a facecolor') 78 | elif len(self.fc) == 1: 79 | self.fc = np.tile(self.fc, self.Npts).reshape(self.Npts, -1) 80 | 81 | self.lasso = LassoSelector(ax, onselect=self.onselect) 82 | self.ind = [] 83 | 84 | def onselect(self, verts): 85 | path = Path(verts) 86 | self.ind = np.nonzero([path.contains_point(xy) for xy in self.xys])[0] 87 | self.fc[:, -1] = self.alpha_other 88 | self.fc[self.ind, -1] = 1 89 | self.collection.set_facecolors(self.fc) 90 | self.canvas.draw_idle() 91 | 92 | def disconnect(self): 93 | self.lasso.disconnect_events() 94 | self.fc[:, -1] = 1 95 | self.collection.set_facecolors(self.fc) 96 | self.canvas.draw_idle() -------------------------------------------------------------------------------- /bin/checksum: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import hashlib 5 | import sys 6 | 7 | 8 | def run(paths): 9 | sha = hashlib.sha1() 10 | 11 | for path in paths: 12 | try: 13 | with open(path, 'rb') as f: 14 | for chunk in iter(lambda: f.read(4096), b''): 15 | sha.update(chunk) 16 | except IOError: 17 | sha.update(path.encode()) 18 | 19 | print(sha.hexdigest()) 20 | 21 | 22 | if __name__ == '__main__': 23 | run(sys.argv[1:]) 24 | -------------------------------------------------------------------------------- /bin/open: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import sys 6 | 7 | 8 | COMMANDS = { 9 | 'linux': "open", 10 | 'win32': "cmd /c start", 11 | 'cygwin': "cygstart", 12 | 'darwin': "open", 13 | } 14 | 15 | 16 | def run(path): 17 | command = COMMANDS.get(sys.platform, "open") 18 | os.system(command + ' ' + path) 19 | 20 | 21 | if __name__ == '__main__': 22 | run(sys.argv[-1]) 23 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import importlib 6 | import tempfile 7 | import shutil 8 | import subprocess 9 | import sys 10 | 11 | CWD = os.getcwd() 12 | TMP = tempfile.gettempdir() 13 | CONFIG = { 14 | "full_name": "Ajit Johnson Nirmal", 15 | "email": "ajitjohnson.n@gmail.com", 16 | "github_username": "ajitjohnson", 17 | "github_repo": "scimap", 18 | "default_branch": "master", 19 | "project_name": "scimap", 20 | "package_name": "scimap", 21 | "project_short_description": "Single-Cell Image Analysis Package", 22 | "python_major_version": 0, 23 | "python_minor_version": 0, 24 | } 25 | 26 | 27 | def install(package='cookiecutter'): 28 | try: 29 | importlib.import_module(package) 30 | except ImportError: 31 | print("Installing cookiecutter") 32 | subprocess.check_call([sys.executable, '-m', 'pip', 'install', package]) 33 | 34 | 35 | def run(): 36 | print("Generating project") 37 | 38 | from cookiecutter.main import cookiecutter 39 | 40 | os.chdir(TMP) 41 | cookiecutter( 42 | 'https://github.com/jacebrowning/template-python.git', 43 | no_input=True, 44 | overwrite_if_exists=True, 45 | extra_context=CONFIG, 46 | ) 47 | 48 | 49 | def copy(): 50 | for filename in [ 51 | '.appveyor.yml', 52 | '.coveragerc', 53 | '.gitattributes', 54 | '.gitignore', 55 | '.isort.cfg', 56 | '.mypy.ini', 57 | '.pydocstyle.ini', 58 | '.pylint.ini', 59 | '.scrutinizer.yml', 60 | '.travis.yml', 61 | '.verchew.ini', 62 | 'CONTRIBUTING.md', 63 | 'Makefile', 64 | os.path.join('bin', 'checksum'), 65 | os.path.join('bin', 'open'), 66 | os.path.join('bin', 'update'), 67 | os.path.join('bin', 'verchew'), 68 | 'pytest.ini', 69 | 'scent.py', 70 | ]: 71 | src = os.path.join(TMP, CONFIG['project_name'], filename) 72 | dst = os.path.join(CWD, filename) 73 | print("Updating " + filename) 74 | shutil.copy(src, dst) 75 | 76 | 77 | if __name__ == '__main__': 78 | install() 79 | run() 80 | copy() 81 | -------------------------------------------------------------------------------- /docs/.Rhistory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/.Rhistory -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | scimap.xyz -------------------------------------------------------------------------------- /docs/Functions/hl/addROI_omero.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.helpers.addROI_omero -------------------------------------------------------------------------------- /docs/Functions/hl/animate.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.helpers.animate -------------------------------------------------------------------------------- /docs/Functions/hl/classify.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.helpers.classify -------------------------------------------------------------------------------- /docs/Functions/hl/dropFeatures.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.helpers.dropFeatures -------------------------------------------------------------------------------- /docs/Functions/hl/merge_adata_obs.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.helpers.merge_adata_obs -------------------------------------------------------------------------------- /docs/Functions/hl/rename.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.helpers.rename -------------------------------------------------------------------------------- /docs/Functions/hl/scimap_to_csv.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.helpers.scimap_to_csv -------------------------------------------------------------------------------- /docs/Functions/pl/addROI_image.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.addROI_image -------------------------------------------------------------------------------- /docs/Functions/pl/cluster_plots.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.cluster_plots -------------------------------------------------------------------------------- /docs/Functions/pl/densityPlot2D.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.densityPlot2D -------------------------------------------------------------------------------- /docs/Functions/pl/distPlot.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.distPlot -------------------------------------------------------------------------------- /docs/Functions/pl/foldchange.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.foldchange -------------------------------------------------------------------------------- /docs/Functions/pl/gate_finder.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.gate_finder -------------------------------------------------------------------------------- /docs/Functions/pl/groupCorrelation.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.groupCorrelation -------------------------------------------------------------------------------- /docs/Functions/pl/heatmap.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.heatmap -------------------------------------------------------------------------------- /docs/Functions/pl/image_viewer.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.image_viewer -------------------------------------------------------------------------------- /docs/Functions/pl/markerCorrelation.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.markerCorrelation -------------------------------------------------------------------------------- /docs/Functions/pl/napariGater.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.napariGater -------------------------------------------------------------------------------- /docs/Functions/pl/pie.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.pie -------------------------------------------------------------------------------- /docs/Functions/pl/spatialInteractionNetwork.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.spatialInteractionNetwork -------------------------------------------------------------------------------- /docs/Functions/pl/spatial_distance.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.spatial_distance -------------------------------------------------------------------------------- /docs/Functions/pl/spatial_interaction.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.spatial_interaction -------------------------------------------------------------------------------- /docs/Functions/pl/spatial_pscore.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.spatial_pscore -------------------------------------------------------------------------------- /docs/Functions/pl/spatial_scatterPlot.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.spatial_scatterPlot -------------------------------------------------------------------------------- /docs/Functions/pl/stacked_barplot.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.stacked_barplot -------------------------------------------------------------------------------- /docs/Functions/pl/umap.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.umap -------------------------------------------------------------------------------- /docs/Functions/pl/voronoi.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.plotting.voronoi -------------------------------------------------------------------------------- /docs/Functions/pp/combat.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.preprocessing.combat -------------------------------------------------------------------------------- /docs/Functions/pp/log1p.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.preprocessing.log1p -------------------------------------------------------------------------------- /docs/Functions/pp/mcmicro_to_scimap.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.preprocessing.mcmicro_to_scimap -------------------------------------------------------------------------------- /docs/Functions/pp/rescale.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.preprocessing.rescale -------------------------------------------------------------------------------- /docs/Functions/tl/.Rhistory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/Functions/tl/.Rhistory -------------------------------------------------------------------------------- /docs/Functions/tl/cluster.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.cluster -------------------------------------------------------------------------------- /docs/Functions/tl/foldchange.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.foldchange -------------------------------------------------------------------------------- /docs/Functions/tl/phenotype_cells.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.phenotype_cells -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_aggregate.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_aggregate -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_cluster.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_cluster -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_count.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_count -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_distance.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_distance -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_expression.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_expression -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_interaction.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_interaction -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_lda.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_lda -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_pscore.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_pscore -------------------------------------------------------------------------------- /docs/Functions/tl/spatial_similarity_search.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.spatial_similarity_search -------------------------------------------------------------------------------- /docs/Functions/tl/umap.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - toc # Hide table of contents 4 | --- 5 | ::: scimap.tools.umap -------------------------------------------------------------------------------- /docs/assets/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/assets/favicon.png -------------------------------------------------------------------------------- /docs/assets/scimap_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/assets/scimap_logo.jpg -------------------------------------------------------------------------------- /docs/assets/scimap_logo_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/assets/scimap_logo_b.png -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: SCIMAP 3 | description: Spatial Single-Cell Analysis Toolkit 4 | hide: 5 | - toc # Hide table of contents 6 | - navigation 7 | --- 8 | 9 | # Home 10 | 11 | [![build-unix-mac-win](https://github.com/labsyspharm/scimap/actions/workflows/build-unix-mac-win.yml/badge.svg)](https://github.com/labsyspharm/scimap/actions/workflows/build-unix-mac-win.yml) 12 | [![docs](https://github.com/labsyspharm/scimap/actions/workflows/docs.yml/badge.svg)](https://github.com/labsyspharm/scimap/actions/workflows/docs.yml) 13 | [![Downloads](https://pepy.tech/badge/scimap)](https://pepy.tech/project/scimap) 14 | [![PyPI Version](https://img.shields.io/pypi/v/scimap.svg)](https://pypi.org/project/scimap) 15 | [![PyPI License](https://img.shields.io/pypi/l/scimap.svg)](https://pypi.org/project/scimap) 16 | [![DOI](https://joss.theoj.org/papers/10.21105/joss.06604/status.svg)](https://doi.org/10.21105/joss.06604) 17 |
18 |
19 | 20 |
21 | 22 | *Scimap* is a scalable toolkit for analyzing spatial molecular data. The underlying framework is generalizable to spatial datasets mapped to XY coordinates. The package uses the [anndata](https://anndata.readthedocs.io/en/stable/anndata.AnnData.html) framework making it easy to integrate with other popular single-cell analysis toolkits. It includes preprocessing, phenotyping, visualization, clustering, spatial analysis and differential spatial testing. The Python-based implementation efficiently deals with large datasets of millions of cells. 23 | 24 | *Scimap* operates on segmented single-cell data derived from imaging data using tools such as cellpose or MCMICRO. The essential inputs for SCIMAP are: (a) a single-cell expression matrix and (b) the X and Y coordinates for each cell. Additionally, multi-stack OME-TIFF or TIFF images can be optionally provided to enable visualization of the data analysis on the original raw images. 25 |
26 | 27 | *Scimap* development was led by [Ajit Johnson Nirmal](https://ajitjohnson.com/), Harvard Medical School. 28 | Check out other tools from the [Nirmal Lab](https://nirmallab.com/tools/). 29 | 30 | ### Citing scimap 31 | Nirmal et al., (2024). SCIMAP: A Python Toolkit for Integrated Spatial Analysis of Multiplexed Imaging Data. *Journal of Open Source Software*, 9(97), 6604, [https://doi.org/10.21105/joss.06604](https://joss.theoj.org/papers/10.21105/joss.06604#) 32 | 33 | 34 | ### Funding 35 | This work was supported by the following NIH grant K99-CA256497 36 | 37 | 38 | -------------------------------------------------------------------------------- /docs/stylesheets/.Rhistory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/.Rhistory -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Black.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Black.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Black.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Black.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Black.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Black.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Black.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Black.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-BlackOblique.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-BlackOblique.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-BlackOblique.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-BlackOblique.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-BlackOblique.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-BlackOblique.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-BlackOblique.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-BlackOblique.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Book.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Book.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Book.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Book.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Book.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Book.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Book.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Book.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-BookOblique.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-BookOblique.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-BookOblique.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-BookOblique.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-BookOblique.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-BookOblique.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-BookOblique.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-BookOblique.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Heavy.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Heavy.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Heavy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Heavy.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Heavy.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Heavy.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Heavy.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Heavy.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-HeavyOblique.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-HeavyOblique.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-HeavyOblique.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-HeavyOblique.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-HeavyOblique.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-HeavyOblique.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-HeavyOblique.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-HeavyOblique.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Light.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Light.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Light.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Light.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Light.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-LightOblique.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-LightOblique.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-LightOblique.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-LightOblique.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-LightOblique.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-LightOblique.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-LightOblique.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-LightOblique.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Medium.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Medium.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Medium.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Medium.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Medium.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-MediumOblique.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-MediumOblique.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-MediumOblique.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-MediumOblique.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-MediumOblique.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-MediumOblique.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-MediumOblique.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-MediumOblique.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Oblique.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Oblique.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Oblique.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Oblique.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Oblique.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Oblique.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Oblique.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Oblique.woff2 -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Roman.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Roman.eot -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Roman.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Roman.ttf -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Roman.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Roman.woff -------------------------------------------------------------------------------- /docs/stylesheets/font/Avenir-Roman.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/stylesheets/font/Avenir-Roman.woff2 -------------------------------------------------------------------------------- /docs/tutorials/Releases/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 1.3.14 (2024-03-20) 3 | 4 | - Added tutorials 5 | 6 | # 0.21.0 (2022-05-29) 7 | 8 | - Added `sm.hl.animate` and `sm.pl.umap` 9 | 10 | # 0.20.16 (2022-05-28) 11 | 12 | - Added `sm.tl.umap` and `sm.tl.spatial_similarity_search` 13 | 14 | # 0.19.0 (2022-04-03) 15 | 16 | - Included support for `Apple M1` machines 17 | - Included support for native rendering of Zarr stored images using Napari: `pl.image_viewer` and `pl.gate_finder` 18 | 19 | # 0.14.0 (2021-04-10) 20 | 21 | - Included `sm.tl.foldchange` function. Also calculated p-val by Fisher exact test 22 | 23 | # 0.12.0 (2021-02-12) 24 | 25 | - Included `sm.pl.voronoi` function. Now possible to draw voronoi diagram of the images using X/Y coordinates 26 | 27 | # 0.11.0 (2021-01-30) 28 | 29 | - Included `spatial_pscore` function 30 | 31 | # 0.10.0 (2020-11-27) 32 | 33 | - Included `stacked_barplot` function to generate a stacked barplot from any two cloumns 34 | 35 | # 0.9.0 (2020-11-21) 36 | 37 | - Updated `pl.image_viewer` and `pl.gate_finder` functions - 38 | Implemeted Zarr functionality for napari viz. 39 | 40 | # 0.8.7 (2020-11-18) 41 | 42 | - Updated `pl.spatial_interaction` function to include two additional parameters - 43 | `subset_phenotype` and `subset_neighbour_phenotype`. 44 | 45 | # 0.8.3 (2020-11-16) 46 | 47 | - Added `hl.add_roi` function. Used to incorporate ROI's extracted from Omero into the scimap object. 48 | 49 | 50 | # 0.8.0 (2020-11-09) 51 | 52 | - Updated `pp.mcmicro_to_scimap` function. Added a new parameter `unique_CellId` 53 | - Added a helper function `scimap_to_csv` to save the andata object as a CSV. 54 | - Added documentation and tests for `scimap_to_csv` 55 | 56 | # 0.7.10 (2020-10-30) 57 | 58 | - Updated `pp.rescale` function. If a gate is included in the `manual_gate.csv` 59 | file but no gate value is provided, the algorithm simply scales the data between 60 | 0-1 without changing the undelying structure. 61 | 62 | # 0.7.6 (2020-10-27) 63 | 64 | - Updated `hl.spatial_distance` to include option to convert to 65 | log scale and also pass multiple `distance_to` parameter. 66 | 67 | # 0.7.5 (2020-10-27) 68 | 69 | - Updated `hl.classify` to improve speed 70 | 71 | # 0.7.3 (2020-10-27) 72 | 73 | - Addition of binary view in `pl.spatial_interaction` 74 | 75 | 76 | # 0.7.2 (2020-10-26) 77 | 78 | - Addition of `hl.classify` function. 79 | - Documentation for `hl.classify` function. 80 | - Readme file modification 81 | -------------------------------------------------------------------------------- /docs/tutorials/Releases/license.md: -------------------------------------------------------------------------------- 1 | **The MIT License (MIT)** 2 | 3 | Copyright © 2020, Ajit Johnson Nirmal 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/tutorials/archive/3-Cell_Type_calling_and_adding_ROIs_files/3-Cell_Type_calling_and_adding_ROIs_23_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/3-Cell_Type_calling_and_adding_ROIs_files/3-Cell_Type_calling_and_adding_ROIs_23_2.png -------------------------------------------------------------------------------- /docs/tutorials/archive/3-Cell_Type_calling_and_adding_ROIs_files/3-Cell_Type_calling_and_adding_ROIs_25_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/3-Cell_Type_calling_and_adding_ROIs_files/3-Cell_Type_calling_and_adding_ROIs_25_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/3-Cell_Type_calling_and_adding_ROIs_files/3-Cell_Type_calling_and_adding_ROIs_27_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/3-Cell_Type_calling_and_adding_ROIs_files/3-Cell_Type_calling_and_adding_ROIs_27_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/3-Cell_Type_calling_and_adding_ROIs_files/3-Cell_Type_calling_and_adding_ROIs_35_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/3-Cell_Type_calling_and_adding_ROIs_files/3-Cell_Type_calling_and_adding_ROIs_35_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_10_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_10_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_16_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_16_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_17_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_7_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_7_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_8_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/4-CellType_Proportion_Exploration_files/4-CellType_Proportion_Exploration_8_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_10_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_10_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_11_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_11_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_12_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_12_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_13_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_13_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_14_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_14_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_15_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_15_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_16_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_16_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_17_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_23_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_23_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_24_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_24_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_26_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_26_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_27_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_27_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_32_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_32_1.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_33_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_33_1.png -------------------------------------------------------------------------------- /docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_34_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/5-Simple_Spatial_Analysis_files/5-Simple_Spatial_Analysis_34_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/6_animate_with_scimap_files/6_animate_with_scimap_18_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/6_animate_with_scimap_files/6_animate_with_scimap_18_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/6_animate_with_scimap_files/6_animate_with_scimap_20_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/6_animate_with_scimap_files/6_animate_with_scimap_20_1.png -------------------------------------------------------------------------------- /docs/tutorials/archive/6_animate_with_scimap_files/6_animate_with_scimap_22_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/6_animate_with_scimap_files/6_animate_with_scimap_22_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/6_animate_with_scimap_files/6_animate_with_scimap_24_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/6_animate_with_scimap_files/6_animate_with_scimap_24_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_13_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_13_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_16_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_16_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_18_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_18_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_40_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_40_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_41_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_41_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_42_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_42_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_43_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-cell-phenotyping_files/scimap-tutorial-cell-phenotyping_43_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-getting-started_files/scimap-tutorial-getting-started_26_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-getting-started_files/scimap-tutorial-getting-started_26_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-getting-started_files/scimap-tutorial-getting-started_27_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-getting-started_files/scimap-tutorial-getting-started_27_0.png -------------------------------------------------------------------------------- /docs/tutorials/archive/scimap-tutorial-getting-started_files/scimap-tutorial-getting-started_28_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/archive/scimap-tutorial-getting-started_files/scimap-tutorial-getting-started_28_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/add_rois_scimap.md: -------------------------------------------------------------------------------- 1 | # 🙌 Add Region of Interest (ROIs) for Comparitive Analysis 2 | 3 | Frequently, adding Regions of Interest (ROIs) to an image is crucial for conducting comparative analysis, such as identifying distinct histological sites, tumor regions, or boundaries. To incorporate ROIs into scimap, there are two approaches: 4 | 5 | 1. Directly drawing on the image using napari. 6 | 2. For images stored on OMERO, ROIs can be added, exported, and then imported into scimap. 7 | 8 | 9 | ```python 10 | # import packages 11 | import scimap as sm 12 | import anndata as ad 13 | ``` 14 | 15 | Running SCIMAP 1.3.14 16 | 17 | 18 | 19 | ```python 20 | # Load the data that we saved in the last tutorial (cell phenotyping) 21 | adata = ad.read_h5ad('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 22 | ``` 23 | 24 | ### 1. Add ROIs via Napari 25 | 26 | When you open napari, a new layer named "ROI" is automatically added by default. To create Regions of Interest, select the "Add Polygons" tool and draw your desired ROIs, which can include multiple polygons. You also have the option to rename this layer to something more specific, such as "Tumor Regions." For different classes of ROIs, like stromal regions, simply create a new layer and repeat the process. 27 | 28 | **It's important to note that ROIs should not overlap, since each cell can only be assigned to one unique ROI.** 29 | 30 | To save the ROIs, simply close the napari window. 31 | 32 | 33 | ```python 34 | %gui qt 35 | image_path = '/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/registration/exemplar-001.ome.tif' 36 | ``` 37 | 38 | 39 | ```python 40 | adata = sm.pl.addROI_image(image_path, adata) 41 | ``` 42 | 43 | 44 | Opening Napari; 45 | Add shape layers (on left) to draw ROI's. 46 | Rename the shape layer to give a name to your ROI 47 | Multiple shape layers are supported 48 | ROI's should not overlap 49 | Close Napari to save ROI's. 50 | 51 | Identifying cells within selected ROI's 52 | ROIs saved under adata.obs['ROI'] 53 | 54 | 55 | 56 | ```python 57 | 58 | ``` 59 | 60 | I've created three layers, "ROI1", "ROI2" and "ROI3" with each layer containing several designated areas. 61 | 62 | 63 | ```python 64 | # print the number of cells within the assigned ROIs 65 | adata.obs['ROI'].value_counts() 66 | ``` 67 | 68 | 69 | 70 | 71 | ROI 72 | Other 9132 73 | ROI3 1513 74 | ROI2 497 75 | ROI1 59 76 | Name: count, dtype: int64 77 | 78 | 79 | 80 | 81 | ```python 82 | # check the added ROIs 83 | sm.pl.spatial_scatterPlot (adata, colorBy = ['ROI'],figsize=(3,3), s=0.7, fontsize=5, catCmap='Set1') 84 | ``` 85 | 86 | 87 | 88 | ![png](add_rois_scimap_files/add_rois_scimap_11_0.png) 89 | 90 | 91 | 92 | 93 | ```python 94 | # We can now do any downstream analysis for example let's look at the distribution of cell types within these ROIs 95 | sm.pl.stacked_barplot (adata, x_axis='ROI', y_axis='phenotype') 96 | ``` 97 | 98 | 99 | 100 | ![png](add_rois_scimap_files/add_rois_scimap_12_0.png) 101 | 102 | 103 | 104 | 105 | ```python 106 | # or look at the correaltion of cell types between ROIs 107 | sm.pl.groupCorrelation(adata, groupBy='phenotype', condition='ROI', figsize=(6,4)) 108 | ``` 109 | 110 | /Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/groupCorrelation.py:127: FutureWarning: 111 | 112 | The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning. 113 | 114 | 115 | 116 | 117 | 118 | ![png](add_rois_scimap_files/add_rois_scimap_13_1.png) 119 | 120 | 121 | 122 | 123 | ```python 124 | 125 | ``` 126 | 127 | ### 2. Add ROIs via Omero 128 | 129 | `sm.hl.add_roi_omero` function seamlessly integrates Regions of Interest ( ROIs) extracted from Omero into AnnData object. 130 | 131 | The function allows users to add annotations that have been extracted from Omero using the following **[script](https://gist.github.com/Yu-AnChen/58754f960ccd540e307ed991bc6901b0)** 132 | 133 | The script will download a CSV file. The same conditions apply as before. No ROI should overlap. 134 | 135 | ```python 136 | roi_df = pd.read_csv('path/to/roi.csv') 137 | 138 | # Add ROIs to a single image dataset 139 | adata = sm.hl.addROI_omero(adata, roi=roi_df, label='Omero_ROI') 140 | ``` 141 | 142 | 143 | ```python 144 | 145 | ``` 146 | 147 | ### Save Results 148 | 149 | 150 | ```python 151 | # Save the results 152 | adata.write('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 153 | ``` 154 | 155 | 156 | ```python 157 | 158 | ``` 159 | -------------------------------------------------------------------------------- /docs/tutorials/md/add_rois_scimap_files/add_rois_scimap_11_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/add_rois_scimap_files/add_rois_scimap_11_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/add_rois_scimap_files/add_rois_scimap_12_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/add_rois_scimap_files/add_rois_scimap_12_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/add_rois_scimap_files/add_rois_scimap_13_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/add_rois_scimap_files/add_rois_scimap_13_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/animate_scimap_files/animate_scimap_11_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/animate_scimap_files/animate_scimap_11_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/animate_scimap_files/animate_scimap_13_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/animate_scimap_files/animate_scimap_13_2.png -------------------------------------------------------------------------------- /docs/tutorials/md/animate_scimap_files/animate_scimap_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/animate_scimap_files/animate_scimap_17_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/animate_scimap_files/animate_scimap_19_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/animate_scimap_files/animate_scimap_19_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_11_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_11_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_13_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_13_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_17_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_19_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_19_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_7_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_interaction_scimap_files/cell_interaction_scimap_7_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_10_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_10_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_13_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_13_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_15_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_15_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_17_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_19_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_19_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_4_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_4_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_5_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_5_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_9_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/cell_proportion_scimap_files/cell_proportion_scimap_9_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/clustering_scimap.md: -------------------------------------------------------------------------------- 1 | # 🤹🏼‍♂️ Cell phenotyping by unsupervised clustering of the single cell data 2 | 3 | 4 | ```python 5 | # import packages 6 | import scimap as sm 7 | import anndata as ad 8 | ``` 9 | 10 | Running SCIMAP 1.3.12 11 | 12 | 13 | 14 | ```python 15 | # Load the data that we saved in the last tutorial - (Prepare data for SCIMAP) 16 | adata = ad.read_h5ad('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 17 | ``` 18 | 19 | `sm.tl.cluster` function can be used for clustering cells within the dataset. It supports three popular clustering algorithms: 20 | 21 | - kmeans 22 | - phenograph 23 | - leiden 24 | 25 | Users are encouraged to select the clustering algorithm that best matches their data's nature and their analytical goals. 26 | 27 | 28 | ```python 29 | adata = sm.tl.cluster(adata, method='leiden', resolution=0.3, use_raw=False, log=False) 30 | ``` 31 | 32 | Leiden clustering 33 | 34 | 35 | /Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scanpy/preprocessing/_pca.py:229: ImplicitModificationWarning: 36 | 37 | Setting element `.obsm['X_pca']` of view, initializing view as actual. 38 | 39 | 40 | 41 | 42 | ```python 43 | # view the results 44 | adata.obs['leiden'].value_counts() 45 | ``` 46 | 47 | 48 | 49 | 50 | leiden 51 | 0 3895 52 | 1 2661 53 | 2 1563 54 | 3 1223 55 | 4 820 56 | 5 496 57 | 6 462 58 | 7 81 59 | Name: count, dtype: int64 60 | 61 | 62 | 63 | 64 | ```python 65 | 66 | ``` 67 | 68 | Now, let us construct a heatmap to examine the expression levels of specific markers across each identified cluster. 69 | 70 | 71 | ```python 72 | sm.pl.heatmap(adata, groupBy='leiden', standardScale='column', figsize=(5,4), showPrevalence=True) 73 | ``` 74 | 75 | /Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/heatmap.py:312: UserWarning: 76 | 77 | This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. 78 | 79 | 80 | 81 | 82 | 83 | ![png](clustering_scimap_files/clustering_scimap_8_1.png) 84 | 85 | 86 | 87 | 88 | ```python 89 | 90 | ``` 91 | 92 | Based on the expression profile of markers, we shall assign a cell type to each cluster. Utilize the `rename` function for this purpose. 93 | 94 | 95 | ```python 96 | rename_dict = {'Tumor': ['5','1'], 97 | 'Myeloid': ['2'], 98 | 'Treg': ['6'], 99 | 'Vessels': ['4'], 100 | 'Artifacts': ['7'], 101 | 'Immune': ['3','0']} 102 | 103 | adata = sm.hl.rename(adata, rename=rename_dict, from_column='leiden', to_column='leiden_phenotype') 104 | ``` 105 | 106 | Renaming 5 to Tumor 107 | Renaming 1 to Tumor 108 | Renaming 2 to Myeloid 109 | Renaming 6 to Treg 110 | Renaming 4 to Vessels 111 | Renaming 7 to Artifacts 112 | Renaming 3 to Immune 113 | Renaming 0 to Immune 114 | 115 | 116 | 117 | ```python 118 | # now rebuild the heatmap to verify the expression pattern of markers within each cell type 119 | sm.pl.heatmap(adata, groupBy='leiden_phenotype', standardScale='column', figsize=(5,4), showPrevalence=True) 120 | ``` 121 | 122 | /Users/aj/miniconda3/envs/scimap/lib/python3.10/site-packages/scimap/plotting/heatmap.py:312: UserWarning: 123 | 124 | This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. 125 | 126 | 127 | 128 | 129 | 130 | ![png](clustering_scimap_files/clustering_scimap_12_1.png) 131 | 132 | 133 | 134 | 135 | ```python 136 | 137 | ``` 138 | 139 | I often overlay the defined cell types on a spatial scatterplot too, just to see if they match up with the tissue's histology. 140 | 141 | 142 | ```python 143 | sm.pl.spatial_scatterPlot (adata, colorBy = ['leiden_phenotype'],figsize=(3,3), s=0.7, fontsize=5, catCmap='Set1') 144 | ``` 145 | 146 | 147 | 148 | ![png](clustering_scimap_files/clustering_scimap_15_0.png) 149 | 150 | 151 | 152 | 153 | ```python 154 | %gui qt 155 | ``` 156 | 157 | While useful, to ensure accurate cell type assignment, you'd want to overlay the cell types on the actual image. By examining marker combinations, confirm the assignments are correct. If not, adjust the clustering parameters and refine the cell types. 158 | 159 | 160 | ```python 161 | # pass in the path to the image 162 | image_path = '/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/registration/exemplar-001.ome.tif' 163 | 164 | # view in napari 165 | sm.pl.image_viewer(image_path=image_path, 166 | adata=adata, 167 | overlay='leiden_phenotype', 168 | point_size=10, 169 | point_color='white') 170 | 171 | # Note that if your AnnotatedData object (adata) includes multiple images, 172 | # you can use the `subset` parameter to specify the image name found in the `imageid` column, 173 | # enabling the loading of just that particular image. 174 | ``` 175 | 176 | ### Save Results 177 | 178 | 179 | ```python 180 | # Save the results 181 | adata.write('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 182 | ``` 183 | 184 | 185 | ```python 186 | 187 | ``` 188 | -------------------------------------------------------------------------------- /docs/tutorials/md/clustering_scimap_files/clustering_scimap_12_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/clustering_scimap_files/clustering_scimap_12_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/clustering_scimap_files/clustering_scimap_15_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/clustering_scimap_files/clustering_scimap_15_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/clustering_scimap_files/clustering_scimap_8_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/clustering_scimap_files/clustering_scimap_8_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/demo_data_scimap.md: -------------------------------------------------------------------------------- 1 | # 📥 SCIMAP Demo Data 2 | 3 | A short guide to downloading our demo data for trying out the **scimap toolbox**. 4 | 5 | **You can download the data in two methods:** 6 | 7 | 1. Utilize the built-in download function of scimap. 8 | 2. Visit the website through your browser and manually download the data. 9 | 10 | ### 1. Built in function 11 | 12 | 13 | ```python 14 | import scimap as sm 15 | ``` 16 | 17 | Running SCIMAP 1.3.16 18 | 19 | 20 | 21 | ```python 22 | # Provide a download directory 23 | download_directory = '/Users/aj/Downloads' 24 | sm.hl.downloadDemoData (download_directory) 25 | ``` 26 | 27 | Downloading scimapExampleData.zip... 28 | 29 | 30 | scimapExampleData.zip: 100%|███████████████████████████████████████████████████████████| 287M/287M [04:35<00:00, 1.09MiB/s] 31 | 32 | Downloaded scimapExampleData.zip to /Users/aj/Downloads/scimapExampleData.zip 33 | 34 | 35 | 36 | 37 | 38 | A zipped data folder will appear in the specified directory. Simply unzip it, and you'll be all set to start. 39 | 40 | ### 2. Download from Zonodo 41 | 42 | - Go to [Zonodo](https://zenodo.org/records/10845625) 43 | - Click on the download button 44 | - unzip the downloaded file 45 | 46 | DOI: [10.5281/zenodo.10845624](https://zenodo.org/records/10845625) 47 | 48 | If you have any questions or encounter any issues while following the tutorial, please don't hesitate to contact us for assistance. 49 | -------------------------------------------------------------------------------- /docs/tutorials/md/export_scimap.md: -------------------------------------------------------------------------------- 1 | # ⬇️ Export data from SCIMAP into csv 2 | 3 | After completing some analysis and when you're ready to export the data, you can utilize the specified function for this purpose. However, it's important to note that if you plan to return and continue your analysis later, you should rely on the `.h5ad` file you've saved. While exporting to a CSV file can be handy, only a subset of the data—specifically, what's contained in `adata.obs` and `adata.X`—is exported. Be aware that all other compartments of the data are not preserved during the CSV export process. 4 | 5 | 6 | ```python 7 | # import packages 8 | import scimap as sm 9 | import anndata as ad 10 | ``` 11 | 12 | Running SCIMAP 1.3.14 13 | 14 | 15 | 16 | ```python 17 | # Load the data that we saved in the last tutorial (with ROIs added) 18 | adata = ad.read_h5ad('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 19 | ``` 20 | 21 | 22 | ```python 23 | # by default the raw data is exported 24 | output_dir= '/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData' 25 | sm.hl.scimap_to_csv(adata, output_dir=output_dir, file_name='scimapProcessed.csv') 26 | ``` 27 | 28 | Refer to the documentation to learn how to export additional layers beyond just the raw data. 29 | 30 | 31 | ```python 32 | 33 | ``` 34 | -------------------------------------------------------------------------------- /docs/tutorials/md/install_scimap.md: -------------------------------------------------------------------------------- 1 | # 📁 Setting up SCIMAP 2 | 3 | Before we set up *SCIMAP*, we highly recommend using an environment manager like Conda. Using an environment manager like Conda allows you to create and manage isolated environments with specific package versions and dependencies. 4 | 5 | Download and Install the right [conda](https://docs.anaconda.com/free/miniconda/) based on the opertating system that you are using 6 | 7 |
8 | 9 | ## Let's create a new conda environment and install SCIMAP 10 | 11 | Use the terminal (mac/linux) and anaconda promt (windows) to run the following command 12 | 13 | ``` 14 | conda create --name scimap -y python=3.10 15 | ``` 16 | 17 | Install SCIMAP within the conda environment. 18 | 19 | ``` 20 | conda activate scimap 21 | pip install scimap 22 | ``` 23 | 24 |
25 | 26 | ## Set up Jupyter Notebook / Spyder or any interactive IDE 27 | 28 | Install jupyter notebook within the conda environment 29 | 30 | 31 | ``` 32 | pip install notebook ipywidgets 33 | ``` 34 | 35 | After installation, open Jupyter Notebook by typing the following command in the terminal, ensuring that the cspot environment is activated and you are within the environment before executing the jupyter notebook command. 36 | 37 | ``` 38 | jupyter notebook 39 | ``` 40 | 41 | We will talk about how to run *SCIMAP* in the next tutorial. 42 | -------------------------------------------------------------------------------- /docs/tutorials/md/proximity_scimap.md: -------------------------------------------------------------------------------- 1 | # ⚖️ Tool for Computing Proximity Scores between Samples 2 | 3 | 4 | ```python 5 | # import packages 6 | import scimap as sm 7 | import anndata as ad 8 | ``` 9 | 10 | Running SCIMAP 1.3.14 11 | 12 | 13 | 14 | ```python 15 | # Load the data that we saved in the last tutorial (with ROIs added) 16 | adata = ad.read_h5ad('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 17 | ``` 18 | 19 | Quantifying the proximity score with `sm.tl.spatial_pscore` offers a systematic way to evaluate the closeness between specific cell types as defined by the user. 20 | 21 | This analysis generates two key metrics: the *Proximity Density* and the *Proximity Volume*, both of which are saved in `adata.uns`. 22 | 23 | **Proximity Density** reflects the ratio of identified interactions to the total number of cells of the interacting types, providing insight into how frequently these cell types interact relative to their population size. 24 | 25 | **Proximity Volume**, on the other hand, compares the number of interactions to the total cell count in the dataset, offering a broader view of the interaction's significance across the entire sample. 26 | 27 | Additionally, the locations of these interaction sites are recorded and saved in `adata.obs`, allowing for detailed spatial analysis. Running this analysis can elucidate the biological significance of the spatial arrangement of cell types, which is crucial for understanding tissue structure, function, and disease pathology in a more nuanced and quantitative manner. 28 | 29 | 30 | ```python 31 | # Calculate the score for proximity between `Tumor` cells and `Blood Vessels` 32 | adata = sm.tl.spatial_pscore (adata,proximity= ['ECAD+', 'SMA+'], 33 | score_by = 'ROI', 34 | phenotype='phenotype', 35 | method='radius', 36 | radius=50) 37 | ``` 38 | 39 | Identifying neighbours within 50 pixels of every cell 40 | Please check: 41 | adata.obs['spatial_pscore'] & 42 | adata.uns['spatial_pscore'] for results 43 | 44 | 45 | 46 | ```python 47 | sm.pl.spatial_pscore (adata, color='black', plot_score='Proximity Volume', figsize=(4,2)) # 48 | ``` 49 | 50 | 51 | 52 | ![png](proximity_scimap_files/proximity_scimap_5_0.png) 53 | 54 | 55 | 56 | 57 | ```python 58 | sm.pl.spatial_pscore (adata, color='Black', plot_score='Proximity Density', figsize=(4,2)) 59 | ``` 60 | 61 | 62 | 63 | ![png](proximity_scimap_files/proximity_scimap_6_0.png) 64 | 65 | 66 | 67 | As previously noted, the locations of these interactions are recorded, enabling us to spatially plot and examine their distribution within the tissue. 68 | 69 | 70 | ```python 71 | sm.pl.voronoi(adata, color_by='spatial_pscore', 72 | voronoi_edge_color = 'black', 73 | size_max=3000, 74 | voronoi_line_width = 0.3, 75 | voronoi_alpha = 0.8, 76 | overlay_points=None, 77 | plot_legend=True, 78 | legend_size=6) 79 | ``` 80 | 81 | 82 | 83 | ![png](proximity_scimap_files/proximity_scimap_8_0.png) 84 | 85 | 86 | 87 | ### Save Results 88 | 89 | 90 | ```python 91 | # Save the results 92 | adata.write('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 93 | ``` 94 | 95 | 96 | ```python 97 | 98 | ``` 99 | -------------------------------------------------------------------------------- /docs/tutorials/md/proximity_scimap_files/proximity_scimap_5_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/proximity_scimap_files/proximity_scimap_5_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/proximity_scimap_files/proximity_scimap_6_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/proximity_scimap_files/proximity_scimap_6_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/proximity_scimap_files/proximity_scimap_8_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/proximity_scimap_files/proximity_scimap_8_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_helper_functions.md: -------------------------------------------------------------------------------- 1 | # 👑 Additional Helper Function to make Your Life Easier 2 | 3 | 4 | ```python 5 | # import packages 6 | import scimap as sm 7 | import anndata as ad 8 | ``` 9 | 10 | Running SCIMAP 1.3.14 11 | 12 | 13 | 14 | ```python 15 | # Load the data that we saved in the last tutorial (with ROIs added) 16 | adata = ad.read_h5ad('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 17 | ``` 18 | 19 | ### classify 20 | 21 | The `sm.hl.classify` function allows users to annotate cells based on the presence or absence of certain markers, providing the option to apply classifications across the entire dataset or within specific subsets, such as groups of cells that have already been phenotyped or clustered. This functionality is especially useful for quickly determining the percentage of cells expressing a particular marker within a subset of interest. A prerequisite for using this function is that gating has been performed and the rescale function has been applied, as it relies on threshold-based classification. 22 | 23 | 24 | ```python 25 | adata.var.index 26 | ``` 27 | 28 | 29 | 30 | 31 | Index(['ELANE', 'CD57', 'CD45', 'CD11B', 'SMA', 'CD16', 'ECAD', 'FOXP3', 32 | 'NCAM'], 33 | dtype='object') 34 | 35 | 36 | 37 | 38 | ```python 39 | # I am going to find out how many cells are CD45 and FOXP3 positive and ECAD negative likely indicating Tregs 40 | adata = sm.hl.classify(adata, pos=['CD45', 'FOXP3'], neg=['ECAD'], collapse_failed=False, label='T_cell_classification') 41 | ``` 42 | 43 | 44 | ```python 45 | # let's look at the results 46 | adata.obs['T_cell_classification'].value_counts() 47 | ``` 48 | 49 | 50 | ```python 51 | 52 | ``` 53 | 54 | ### dropFeatures 55 | 56 | The `sm.hl.dropFeatures` function simplifies the refinement of an adata object by allowing users to selectively exclude markers, cells, metadata columns, and particular cell groups. 57 | 58 | 59 | ```python 60 | adata 61 | ``` 62 | 63 | 64 | 65 | 66 | AnnData object with n_obs × n_vars = 11201 × 9 67 | obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'leiden', 'leiden_phenotype', 'ROI', 'phenotype', 'spatial_pscore', 'index_info', 'neigh_kmeans', 'RCNs', 'spatial_lda_kmeans', 'spatial_expression_kmeans', 'spatial_aggregate_radius', 'tumor_similarity_ROI1' 68 | uns: 'all_markers', 'foldchange_fc', 'foldchange_pval', 'gates', 'spatial_count', 'spatial_distance', 'spatial_expression', 'spatial_interaction_radius', 'spatial_interaction_radius_roi', 'spatial_lda', 'spatial_lda_probability', 'spatial_pscore', 'tumor_similarity' 69 | obsm: 'umap' 70 | layers: 'log' 71 | 72 | 73 | 74 | The dataset now contains 11201 cella and 9 markers 75 | 76 | 77 | ```python 78 | # Lets drop 2 markers 79 | adata = sm.hl.dropFeatures(adata, drop_markers=['CD45', 'FOXP3']) 80 | ``` 81 | 82 | 83 | ```python 84 | adata 85 | ``` 86 | 87 | 88 | 89 | 90 | AnnData object with n_obs × n_vars = 11201 × 7 91 | obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'leiden', 'leiden_phenotype', 'ROI', 'phenotype', 'spatial_pscore', 'index_info', 'neigh_kmeans', 'RCNs', 'spatial_lda_kmeans', 'spatial_expression_kmeans', 'spatial_aggregate_radius', 'tumor_similarity_ROI1' 92 | uns: 'all_markers', 'foldchange_fc', 'foldchange_pval', 'gates', 'spatial_count', 'spatial_distance', 'spatial_expression', 'spatial_interaction_radius', 'spatial_interaction_radius_roi', 'spatial_lda', 'spatial_lda_probability', 'spatial_pscore', 'tumor_similarity' 93 | obsm: 'umap' 94 | layers: 'log' 95 | 96 | 97 | 98 | As you can see now the dataset contains only 7 markers 99 | 100 | 101 | ```python 102 | # lets also drop some cells 103 | adata = sm.hl.dropFeatures(adata, drop_groups='ROI3', groups_column='ROI') 104 | ``` 105 | 106 | 107 | ```python 108 | adata 109 | ``` 110 | 111 | 112 | 113 | 114 | AnnData object with n_obs × n_vars = 9629 × 7 115 | obs: 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation', 'CellID', 'imageid', 'leiden', 'leiden_phenotype', 'ROI', 'phenotype', 'spatial_pscore', 'index_info', 'neigh_kmeans', 'RCNs', 'spatial_lda_kmeans', 'spatial_expression_kmeans', 'spatial_aggregate_radius', 'tumor_similarity_ROI1' 116 | uns: 'all_markers', 'foldchange_fc', 'foldchange_pval', 'gates', 'spatial_count', 'spatial_distance', 'spatial_expression', 'spatial_interaction_radius', 'spatial_interaction_radius_roi', 'spatial_lda', 'spatial_lda_probability', 'spatial_pscore', 'tumor_similarity' 117 | obsm: 'umap' 118 | layers: 'log' 119 | 120 | 121 | 122 | As you can see now the dataset contains only 9629 cells now 123 | 124 | 125 | ```python 126 | 127 | ``` 128 | -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_14_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_14_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_16_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_16_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_16_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_16_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_17_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_18_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_18_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_19_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_19_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_28_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_28_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_30_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_30_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_31_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_31_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_31_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_31_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_32_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_32_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_33_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_33_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_34_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_34_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_34_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_34_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_35_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/scimap_phenotyping_files/scimap_phenotyping_35_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/scimap_video.md: -------------------------------------------------------------------------------- 1 | # 🎥 Video Tutorials 2 | 3 | ## 2021 4 | 5 | 6 | ```python 7 | from IPython.display import HTML 8 | HTML('') 9 | 10 | ``` 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ```python 21 | 22 | ``` 23 | -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap.md: -------------------------------------------------------------------------------- 1 | # 📍 Simple Spatial Analysis 2 | 3 | 4 | ```python 5 | # import packages 6 | import scimap as sm 7 | import anndata as ad 8 | ``` 9 | 10 | Running SCIMAP 1.3.14 11 | 12 | 13 | 14 | ```python 15 | # Load the data that we saved in the last tutorial (with ROIs added) 16 | adata = ad.read_h5ad('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 17 | ``` 18 | 19 | ### Compute the distances among cell types. 20 | 21 | 22 | ```python 23 | adata = sm.tl.spatial_distance (adata, phenotype='phenotype') 24 | ``` 25 | 26 | Processing Image: exemplar-001--unmicst_cell 27 | 28 | 29 | We'll utilize built-in plotting functions for visualization; however, for those interested in conducting additional analysis or custom plotting of these distances, the results can be found in `adata.uns['spatial_distance']`. 30 | 31 | 32 | ```python 33 | # This is one of the most complicated plotting functions in the package 34 | # as I packed a lot of options into one (see the documentation) 35 | # I will try and split this into multiple functions in the future 36 | # To start- let's get an overview with a heatmap 37 | 38 | sm.pl.spatial_distance (adata, figsize=(5,4)) 39 | ``` 40 | 41 | 42 | 43 | ![png](spatial_analysis_scimap_files/spatial_analysis_scimap_6_0.png) 44 | 45 | 46 | 47 | For datasets containing multiple images, the default behavior averages the distances across all images. To analyze and plot the distances for each image individually, you should set `heatmap_summarize` to `False`. Although in this example with only one image the plot will appear similar to the previous one, you'll observe a difference in the y-axis. 48 | 49 | 50 | ```python 51 | sm.pl.spatial_distance (adata, heatmap_summarize=False, figsize=(9,4)) 52 | ``` 53 | 54 | 55 | 56 | ![png](spatial_analysis_scimap_files/spatial_analysis_scimap_8_0.png) 57 | 58 | 59 | 60 | By default, summarization is performed using the `imageid` column, but you can also plot based on different conditions (such as control vs. treated) present in the dataset. Since we've included Regions of Interest (ROIs) in this dataset, let's attempt to plot the data based on these ROIs. 61 | 62 | 63 | ```python 64 | sm.pl.spatial_distance (adata, heatmap_summarize=False, imageid='ROI', figsize=(7,5)) 65 | ``` 66 | 67 | 68 | 69 | ![png](spatial_analysis_scimap_files/spatial_analysis_scimap_10_0.png) 70 | 71 | 72 | 73 | These heatmaps provide a comprehensive overview of the proximity between cell types and how this proximity varies by ROIs, conditions, or across different images. After gaining an understanding of the broader landscape and possibly formulating some hypotheses, it's time to delve into a more detailed analysis. 74 | 75 | Let's say there is an interest in identifying the cells closest to tumor cells; we will do the following analysis to address this interest. 76 | 77 | 78 | ```python 79 | # Numeric plot of the shortest distance of phenotypes from tumor cells 80 | 81 | sm.pl.spatial_distance (adata, method='numeric',distance_from='ECAD+', height=3, aspect=11/8) 82 | 83 | ``` 84 | 85 | 86 | 87 | ![png](spatial_analysis_scimap_files/spatial_analysis_scimap_13_0.png) 88 | 89 | 90 | 91 | From the above plot, it's clear that NK cells and dendritic cells are distant from the tumor cells, while other cell types are so closely positioned that it's difficult to distinguish them. So, let's log the x-axis to make the pattern more distinct. 92 | 93 | 94 | ```python 95 | sm.pl.spatial_distance (adata, method='numeric',distance_from='ECAD+', log=True, height=3, aspect=11/8) 96 | 97 | ``` 98 | 99 | 100 | 101 | ![png](spatial_analysis_scimap_files/spatial_analysis_scimap_15_0.png) 102 | 103 | 104 | 105 | Excellent, now let's say you're interested in comparing these observations between different conditions in your dataset (such as control vs. treatment). Since our dataset doesn't include multiple images, we'll use the ROIs as a substitute once again, as the underlying concept remains the same. 106 | 107 | 108 | ```python 109 | sm.pl.spatial_distance (adata, method='numeric',distance_from='ECAD+', log=True, imageid='ROI', height=3, aspect=9/8) 110 | ``` 111 | 112 | 113 | 114 | ![png](spatial_analysis_scimap_files/spatial_analysis_scimap_17_0.png) 115 | 116 | 117 | 118 | Now, let's say you've narrowed down to a few cell types of interest. We can also subset and display only these selected cells. 119 | 120 | 121 | ```python 122 | distance_to = ['SMA+', 'Treg', 'NK cells', 'Dendritic cells'] 123 | sm.pl.spatial_distance (adata, method='numeric', 124 | distance_from='ECAD+', distance_to=distance_to, 125 | log=True, imageid='ROI', 126 | height=3, aspect=9/8) 127 | ``` 128 | 129 | 130 | 131 | ![png](spatial_analysis_scimap_files/spatial_analysis_scimap_19_0.png) 132 | 133 | 134 | 135 | We can also visualize this using distribution plots instead of box plots, which is particularly useful if you want to demonstrate that the distance between two cell types vary across different conditions. However, in this case, the difference might not be apparent since we are working with demo data. 136 | 137 | 138 | ```python 139 | sm.pl.spatial_distance (adata, method='distribution',distance_from='ECAD+',distance_to = 'SMA+', imageid='ROI', log=True, height=3, aspect=9/8) 140 | ``` 141 | 142 | 143 | 144 | ![png](spatial_analysis_scimap_files/spatial_analysis_scimap_21_0.png) 145 | 146 | 147 | 148 | ### Save Results 149 | 150 | 151 | ```python 152 | # Save the results 153 | adata.write('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 154 | ``` 155 | 156 | 157 | ```python 158 | 159 | ``` 160 | -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_10_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_10_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_13_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_13_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_15_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_15_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_17_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_19_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_19_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_21_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_21_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_6_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_6_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_8_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_analysis_scimap_files/spatial_analysis_scimap_8_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_biology_scimap.md: -------------------------------------------------------------------------------- 1 | # 🗂️ Mastering Spatial Analysis of Multiplex Imaging Data with SCIMAP 2 | 3 |
4 | 5 | This series is designed to equip researchers, data scientists, and enthusiasts with the knowledge and tools necessary to unlock the full potential of spatial analysis techniques. Whether you're new to the field or looking to deepen your understanding, these tutorials will guide you through the intricacies of analyzing complex imaging data, enabling you to uncover the spatial relationships and patterns that lie within. 6 | 7 | 𝕏 Let us know what else you would like to see [here](https://twitter.com/nirmallab)! 8 | 9 |
10 | 11 | ## Set up 12 | 13 | 🤖 [Install Scimap](../md/install_scimap.md) 14 | 📥 [Download demo data](../md/demo_data_scimap.md) 15 | 📁 [Prepare demo data for analysis](../md/anndata_scimap.md) 16 | 17 | ## Cell Phenotyping 18 | 19 | 🤹🏼‍♂️ [Phenotype cells by unsupervised clustering](../md/clustering_scimap.md) 20 | 👽 [Phenotype cells using a hierarchical probabilistic model](../md/scimap_phenotyping.md) 21 | 🙌 [Add Regions of Interest (ROIs) for exploration](../md/add_rois_scimap.md) 22 | 🤩 [Explore the composition of defined cell types between samples and ROIs](../md/cell_proportion_scimap.md) 23 | 24 | ## Spatial Analysis 25 | 26 | 📍 [Calculate and visualize distances between cell types](../md/spatial_analysis_scimap.md) 27 | 🤏 [Cell-cell interaction/ co-occurrence analysis](../md/cell_interaction_scimap.md) 28 | ⚖️ [Compare proximity scores between samples](../md/proximity_scimap.md) 29 | 🔭 [Search for spatial patterns](../md/spatial_search_scimap.md) 30 | 31 | ## Cellular Neighbourhoods 32 | 33 | 🌳 [Compute neighborhoods using cell-type or cluster information (includes LDA method)](../md/spatial_lda_scimap.md) 34 | 🚀 [Compute neighborhoods using expression data](../md/spatial_lag_scimap.md) 35 | 36 | ## Export and Helper Functions 37 | 38 | ⬇️ [Export analysis results to `.csv`](../md/export_scimap.md) 39 | 👩‍🎨 [Animate with scimap](../md/animate_scimap.md) 40 | 👑 [Merge objects, Classify cells etc..](../md/scimap_helper_functions.md) 41 | 42 | ## Videos 43 | 44 | 🎥 [Video tutorials](../md/scimap_video.md) 45 | -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_lag_scimap.md: -------------------------------------------------------------------------------- 1 | # 🚀 Identify Spatial Neighbourhoods on Expression Data 2 | 3 | As mentioned earlier, `spatial_count` and `spatial_lda` are tailored for categorical data, specifically cell phenotypes. But what if cell types haven't been defined and there's a need to discern cellular neighborhoods directly from expression data? This approach carries both pros and cons. On the upside, there's no prerequisite to define cell types. However, interpreting neighborhoods can become challenging without defined cell types, and the method may be susceptible to batch effects. A significant advantage of working with categorical data is that, ideally, batch effects would have been addressed during the phenotyping stage, simplifying subsequent analyses. 4 | 5 | 6 | ```python 7 | # import packages 8 | import scimap as sm 9 | import anndata as ad 10 | ``` 11 | 12 | Running SCIMAP 1.3.14 13 | 14 | 15 | 16 | ```python 17 | # Load the data that we saved in the last tutorial (with ROIs added) 18 | adata = ad.read_h5ad('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 19 | ``` 20 | 21 | 22 | ```python 23 | # make sure you drop markers that are background or antibodies that did not work as all these can affect your results 24 | adata = sm.tl.spatial_expression(adata, method='radius', radius=80, label='spatial_expression') 25 | ``` 26 | 27 | Identifying neighbours within 80 pixels of every cell 28 | 29 | 30 | 31 | ```python 32 | # note that the df_name parameter needs to the same as the label used in the previous step. 33 | adata = sm.tl.spatial_cluster(adata, df_name='spatial_expression', method='kmeans', k=6, label='spatial_expression_kmeans') 34 | ``` 35 | 36 | Kmeans clustering 37 | 38 | 39 | 40 | ```python 41 | # Let's visualize the results. 42 | sm.pl.voronoi(adata, color_by='spatial_expression_kmeans', 43 | voronoi_edge_color = 'black', 44 | voronoi_line_width = 0.3, 45 | voronoi_alpha = 0.8, 46 | size_max=3000, 47 | overlay_points=None, 48 | plot_legend=True, 49 | legend_size=6) 50 | ``` 51 | 52 | 53 | 54 | ![png](spatial_lag_scimap_files/spatial_lag_scimap_6_0.png) 55 | 56 | 57 | 58 | Now, please return to the tutorials for `spatial_count` and `spatial_lda` to continue. The steps for understanding neighborhoods follow the same principles outlined there. 59 | 60 | ### Save Results 61 | 62 | 63 | ```python 64 | # Save the results 65 | adata.write('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad') 66 | ``` 67 | 68 | 69 | ```python 70 | 71 | ``` 72 | -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_lag_scimap_files/spatial_lag_scimap_6_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_lag_scimap_files/spatial_lag_scimap_6_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_11_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_11_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_19_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_19_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_22_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_22_1.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_29_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_29_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_9_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_lda_scimap_files/spatial_lda_scimap_9_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_search_scimap_files/spatial_search_scimap_13_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_search_scimap_files/spatial_search_scimap_13_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_search_scimap_files/spatial_search_scimap_19_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_search_scimap_files/spatial_search_scimap_19_0.png -------------------------------------------------------------------------------- /docs/tutorials/md/spatial_search_scimap_files/spatial_search_scimap_8_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/docs/tutorials/md/spatial_search_scimap_files/spatial_search_scimap_8_0.png -------------------------------------------------------------------------------- /docs/tutorials/nbs/demo_data_scimap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1be33375-5961-4de0-b298-2e95bd03f000", 6 | "metadata": {}, 7 | "source": [ 8 | "# 📥 SCIMAP Demo Data" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "19f306b3-25e3-4130-995e-382d59b74d2b", 14 | "metadata": {}, 15 | "source": [ 16 | "A short guide to downloading our demo data for trying out the **scimap toolbox**." 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "dfa7001e-ac43-4e2e-ab77-6c899dcee781", 22 | "metadata": {}, 23 | "source": [ 24 | "**You can download the data in two methods:**\n", 25 | "\n", 26 | "1. Utilize the built-in download function of scimap.\n", 27 | "2. Visit the website through your browser and manually download the data." 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "id": "cc076a7d-528f-4115-a907-e21fb9fb8d54", 33 | "metadata": {}, 34 | "source": [ 35 | "### 1. Built in function" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 1, 41 | "id": "d99d5348-fe28-4676-acd1-7c651f8c5fc1", 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "name": "stdout", 46 | "output_type": "stream", 47 | "text": [ 48 | "Running SCIMAP 1.3.16\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "import scimap as sm" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 2, 59 | "id": "eb92e132-674c-47f0-b4a0-65a75eb8058b", 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "Downloading scimapExampleData.zip...\n" 67 | ] 68 | }, 69 | { 70 | "name": "stderr", 71 | "output_type": "stream", 72 | "text": [ 73 | "scimapExampleData.zip: 100%|███████████████████████████████████████████████████████████| 287M/287M [04:35<00:00, 1.09MiB/s]" 74 | ] 75 | }, 76 | { 77 | "name": "stdout", 78 | "output_type": "stream", 79 | "text": [ 80 | "Downloaded scimapExampleData.zip to /Users/aj/Downloads/scimapExampleData.zip\n" 81 | ] 82 | }, 83 | { 84 | "name": "stderr", 85 | "output_type": "stream", 86 | "text": [ 87 | "\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "# Provide a download directory\n", 93 | "download_directory = '/Users/aj/Downloads'\n", 94 | "sm.hl.downloadDemoData (download_directory)" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "id": "7b01408a-6505-468e-b384-be5316afd352", 100 | "metadata": {}, 101 | "source": [ 102 | "A zipped data folder will appear in the specified directory. Simply unzip it, and you'll be all set to start." 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "id": "83a9cf87-7904-46b1-9d52-45f4780cb30f", 108 | "metadata": {}, 109 | "source": [ 110 | "### 2. Download from Zonodo" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "id": "17a4ece7-4a97-40a4-be25-4d247ebb1f8a", 116 | "metadata": {}, 117 | "source": [ 118 | "- Go to [Zonodo](https://zenodo.org/records/10845625)\n", 119 | "- Click on the download button\n", 120 | "- unzip the downloaded file\n", 121 | "\n", 122 | "DOI: [10.5281/zenodo.10845624](https://zenodo.org/records/10845625)" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "id": "15b3e78f-7464-4bd8-9a95-e953a80f1b48", 128 | "metadata": {}, 129 | "source": [ 130 | "If you have any questions or encounter any issues while following the tutorial, please don't hesitate to contact us for assistance." 131 | ] 132 | } 133 | ], 134 | "metadata": { 135 | "kernelspec": { 136 | "display_name": "Python 3 (ipykernel)", 137 | "language": "python", 138 | "name": "python3" 139 | }, 140 | "language_info": { 141 | "codemirror_mode": { 142 | "name": "ipython", 143 | "version": 3 144 | }, 145 | "file_extension": ".py", 146 | "mimetype": "text/x-python", 147 | "name": "python", 148 | "nbconvert_exporter": "python", 149 | "pygments_lexer": "ipython3", 150 | "version": "3.10.13" 151 | } 152 | }, 153 | "nbformat": 4, 154 | "nbformat_minor": 5 155 | } 156 | -------------------------------------------------------------------------------- /docs/tutorials/nbs/export_scimap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "943955c9-a4f4-459c-9e5e-9c482fc55015", 6 | "metadata": {}, 7 | "source": [ 8 | "# ⬇️ Export data from SCIMAP into csv" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "55d4b8b9-250b-459f-8f8c-fd5bfd907be8", 14 | "metadata": {}, 15 | "source": [ 16 | "After completing some analysis and when you're ready to export the data, you can utilize the specified function for this purpose. However, it's important to note that if you plan to return and continue your analysis later, you should rely on the `.h5ad` file you've saved. While exporting to a CSV file can be handy, only a subset of the data—specifically, what's contained in `adata.obs` and `adata.X`—is exported. Be aware that all other compartments of the data are not preserved during the CSV export process." 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "id": "596c35d1-fa5c-42a8-ae0e-02e0acb36d16", 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "name": "stdout", 27 | "output_type": "stream", 28 | "text": [ 29 | "Running SCIMAP 1.3.14\n" 30 | ] 31 | } 32 | ], 33 | "source": [ 34 | "# import packages\n", 35 | "import scimap as sm\n", 36 | "import anndata as ad" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "id": "7865a0b4-e6fe-4943-8e52-faeecf4b9160", 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "# Load the data that we saved in the last tutorial (with ROIs added)\n", 47 | "adata = ad.read_h5ad('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData/scimapExampleData.h5ad')" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 3, 53 | "id": "d2b4abb4-2dd5-47a6-ba13-394502cae60f", 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "# by default the raw data is exported\n", 58 | "output_dir= '/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/resources/exemplarData/scimapExampleData'\n", 59 | "sm.hl.scimap_to_csv(adata, output_dir=output_dir, file_name='scimapProcessed.csv')" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "id": "54ae39d1-bd27-44d5-b54b-5ae0b0ec56b0", 65 | "metadata": {}, 66 | "source": [ 67 | "Refer to the documentation to learn how to export additional layers beyond just the raw data." 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "id": "c00a6919-4364-4407-82c5-dc4d82360be8", 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [] 77 | } 78 | ], 79 | "metadata": { 80 | "kernelspec": { 81 | "display_name": "Python 3 (ipykernel)", 82 | "language": "python", 83 | "name": "python3" 84 | }, 85 | "language_info": { 86 | "codemirror_mode": { 87 | "name": "ipython", 88 | "version": 3 89 | }, 90 | "file_extension": ".py", 91 | "mimetype": "text/x-python", 92 | "name": "python", 93 | "nbconvert_exporter": "python", 94 | "pygments_lexer": "ipython3", 95 | "version": "3.10.13" 96 | } 97 | }, 98 | "nbformat": 4, 99 | "nbformat_minor": 5 100 | } 101 | -------------------------------------------------------------------------------- /docs/tutorials/nbs/install_scimap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "27ab4d1b-aebd-4c7f-add4-fd6f95c59384", 6 | "metadata": {}, 7 | "source": [ 8 | "# 📁 Setting up SCIMAP" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "36347b5f-c35a-4523-858e-c0a13e5aaa3d", 14 | "metadata": {}, 15 | "source": [ 16 | "Before we set up *SCIMAP*, we highly recommend using an environment manager like Conda. Using an environment manager like Conda allows you to create and manage isolated environments with specific package versions and dependencies.\n", 17 | "\n", 18 | "Download and Install the right [conda](https://docs.anaconda.com/free/miniconda/) based on the opertating system that you are using" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "id": "cbc707f4-22d5-4e0a-8f42-223e02b8ed1b", 24 | "metadata": {}, 25 | "source": [ 26 | "
" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "id": "a601ee55-0a0b-46f7-83b8-03ba775fb00f", 32 | "metadata": {}, 33 | "source": [ 34 | "## Let's create a new conda environment and install SCIMAP" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "id": "a2fdc58c-2022-4004-bce5-f3d60d903b67", 40 | "metadata": {}, 41 | "source": [ 42 | "Use the terminal (mac/linux) and anaconda promt (windows) to run the following command" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "id": "a1a491b0-6e6a-4123-9a25-bcdbdcb8b29a", 48 | "metadata": {}, 49 | "source": [ 50 | "```\n", 51 | "conda create --name scimap -y python=3.10\n", 52 | "```" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "id": "6a7ae5f4-ae92-4bd7-bc00-7e3d1f893cd4", 58 | "metadata": {}, 59 | "source": [ 60 | "Install SCIMAP within the conda environment." 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "id": "052ac398-cdef-43bd-bed2-c8369346e9ed", 66 | "metadata": {}, 67 | "source": [ 68 | "```\n", 69 | "conda activate scimap\n", 70 | "pip install scimap\n", 71 | "```" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "id": "c920c0d2-46e9-49f7-8af0-14905ebe589a", 77 | "metadata": {}, 78 | "source": [ 79 | "
" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "id": "5d41a4e4-7a74-47bf-8ff8-ab44f68740b3", 85 | "metadata": {}, 86 | "source": [ 87 | "## Set up Jupyter Notebook / Spyder or any interactive IDE" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "id": "782c8025-f547-4809-8c10-55f3e497c5f8", 93 | "metadata": {}, 94 | "source": [ 95 | "Install jupyter notebook within the conda environment\n" 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "id": "7c30ed1b-b706-450c-89a1-af038cff6f98", 101 | "metadata": {}, 102 | "source": [ 103 | "```\n", 104 | "pip install notebook ipywidgets\n", 105 | "```" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "id": "75dd2c81-85f6-4f78-9742-def6ed37a351", 111 | "metadata": {}, 112 | "source": [ 113 | "After installation, open Jupyter Notebook by typing the following command in the terminal, ensuring that the cspot environment is activated and you are within the environment before executing the jupyter notebook command." 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "id": "527ea50b-3b57-4ef0-ac14-853244700887", 119 | "metadata": {}, 120 | "source": [ 121 | "```\n", 122 | "jupyter notebook\n", 123 | "```" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "id": "d9b6e555-c4e2-4194-9553-9e80370c3c99", 129 | "metadata": {}, 130 | "source": [ 131 | "We will talk about how to run *SCIMAP* in the next tutorial." 132 | ] 133 | } 134 | ], 135 | "metadata": { 136 | "kernelspec": { 137 | "display_name": "Python 3 (ipykernel)", 138 | "language": "python", 139 | "name": "python3" 140 | }, 141 | "language_info": { 142 | "codemirror_mode": { 143 | "name": "ipython", 144 | "version": 3 145 | }, 146 | "file_extension": ".py", 147 | "mimetype": "text/x-python", 148 | "name": "python", 149 | "nbconvert_exporter": "python", 150 | "pygments_lexer": "ipython3", 151 | "version": "3.10.13" 152 | } 153 | }, 154 | "nbformat": 4, 155 | "nbformat_minor": 5 156 | } 157 | -------------------------------------------------------------------------------- /docs/tutorials/nbs/scimap_video.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "596cd615-f4c0-4947-aade-1bf78d5c3d77", 6 | "metadata": {}, 7 | "source": [ 8 | "# 🎥 Video Tutorials" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "e175b770-7967-43f8-bcd0-50f47c7deac7", 14 | "metadata": {}, 15 | "source": [ 16 | "## 2021" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 4, 22 | "id": "e51cee29-0cad-4017-a6f5-59e9dc5650f4", 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "data": { 27 | "text/html": [ 28 | "" 29 | ], 30 | "text/plain": [ 31 | "" 32 | ] 33 | }, 34 | "execution_count": 4, 35 | "metadata": {}, 36 | "output_type": "execute_result" 37 | } 38 | ], 39 | "source": [ 40 | "from IPython.display import HTML\n", 41 | "HTML('')\n" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "id": "b5371992-b0fa-4982-a6df-4cc8562ad1ad", 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [] 51 | } 52 | ], 53 | "metadata": { 54 | "kernelspec": { 55 | "display_name": "Python 3 (ipykernel)", 56 | "language": "python", 57 | "name": "python3" 58 | }, 59 | "language_info": { 60 | "codemirror_mode": { 61 | "name": "ipython", 62 | "version": 3 63 | }, 64 | "file_extension": ".py", 65 | "mimetype": "text/x-python", 66 | "name": "python", 67 | "nbconvert_exporter": "python", 68 | "pygments_lexer": "ipython3", 69 | "version": "3.10.13" 70 | } 71 | }, 72 | "nbformat": 4, 73 | "nbformat_minor": 5 74 | } 75 | -------------------------------------------------------------------------------- /docs/tutorials/nbs/spatial_biology_scimap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "d1cbee0e-c2db-439e-9a65-6668a8f7c2f7", 6 | "metadata": {}, 7 | "source": [ 8 | "# 🗂️ Mastering Spatial Analysis of Multiplex Imaging Data with SCIMAP" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "85372f11-761d-46a4-b284-ec09c7d852e6", 14 | "metadata": {}, 15 | "source": [ 16 | "
" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "e3bf3531-be5d-4897-8973-53dec2ea0410", 22 | "metadata": {}, 23 | "source": [ 24 | "This series is designed to equip researchers, data scientists, and enthusiasts with the knowledge and tools necessary to unlock the full potential of spatial analysis techniques. Whether you're new to the field or looking to deepen your understanding, these tutorials will guide you through the intricacies of analyzing complex imaging data, enabling you to uncover the spatial relationships and patterns that lie within." 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "id": "78e9fc52-0057-4e52-b7aa-8b4eba6f5efd", 30 | "metadata": {}, 31 | "source": [ 32 | "𝕏 Let us know what else you would like to see [here](https://twitter.com/nirmallab)!" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "id": "f5a8f66e-ad98-4e4c-ac2a-221d75236475", 38 | "metadata": {}, 39 | "source": [ 40 | "
" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "id": "0007b804-4141-4e5f-8b31-09bb67fa329d", 46 | "metadata": {}, 47 | "source": [ 48 | "## Set up" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "id": "87e54ec3-4a00-413f-946f-ca71b089d1d3", 54 | "metadata": {}, 55 | "source": [ 56 | "🤖 [Install Scimap](../md/install_scimap.md) \n", 57 | "📥 [Download demo data](../md/demo_data_scimap.md) \n", 58 | "📁 [Prepare demo data for analysis](../md/anndata_scimap.md) " 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "id": "c067ea75-9634-46d2-83ed-f307bd553404", 64 | "metadata": {}, 65 | "source": [ 66 | "## Cell Phenotyping" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "id": "8325f12b-54ae-458d-b31f-8461bc201ae5", 72 | "metadata": {}, 73 | "source": [ 74 | "🤹🏼‍♂️ [Phenotype cells by unsupervised clustering](../md/clustering_scimap.md) \n", 75 | "👽 [Phenotype cells using a hierarchical probabilistic model](../md/scimap_phenotyping.md) \n", 76 | "🙌 [Add Regions of Interest (ROIs) for exploration](../md/add_rois_scimap.md) \n", 77 | "🤩 [Explore the composition of defined cell types between samples and ROIs](../md/cell_proportion_scimap.md) " 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "a1173f6d-0251-4f1b-9bc6-35569d521314", 83 | "metadata": {}, 84 | "source": [ 85 | "## Spatial Analysis" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "id": "f3c1c61a-80ca-4e8b-bf30-86f9927ef116", 91 | "metadata": {}, 92 | "source": [ 93 | "📍 [Calculate and visualize distances between cell types](../md/spatial_analysis_scimap.md) \n", 94 | "🤏 [Cell-cell interaction/ co-occurrence analysis](../md/cell_interaction_scimap.md) \n", 95 | "⚖️ [Compare proximity scores between samples](../md/proximity_scimap.md) \n", 96 | "🔭 [Search for spatial patterns](../md/spatial_search_scimap.md) " 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "id": "f534998e-d659-432c-b662-6353fb32f2f4", 102 | "metadata": {}, 103 | "source": [ 104 | "## Cellular Neighbourhoods" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "id": "918987af-a8ce-4f17-ac51-a6e185bd7f07", 110 | "metadata": {}, 111 | "source": [ 112 | "🌳 [Compute neighborhoods using cell-type or cluster information (includes LDA method)](../md/spatial_lda_scimap.md) \n", 113 | "🚀 [Compute neighborhoods using expression data](../md/spatial_lag_scimap.md) " 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "id": "92b66145-228e-4035-ae54-f13ec84c2a15", 119 | "metadata": {}, 120 | "source": [ 121 | "## Export and Helper Functions" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "id": "0b75751d-7ebd-4973-9fb7-82c3821476a2", 127 | "metadata": {}, 128 | "source": [ 129 | "⬇️ [Export analysis results to `.csv`](../md/export_scimap.md) \n", 130 | "👩‍🎨 [Animate with scimap](../md/animate_scimap.md) \n", 131 | "👑 [Merge objects, Classify cells etc..](../md/scimap_helper_functions.md) " 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "id": "b92a5ce9-c4c9-4340-8e7e-2dc424356768", 137 | "metadata": {}, 138 | "source": [ 139 | "## Videos" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "id": "bde23447-396b-4a3f-8983-6a4ff20928c2", 145 | "metadata": {}, 146 | "source": [ 147 | "🎥 [Video tutorials](../md/scimap_video.md) " 148 | ] 149 | } 150 | ], 151 | "metadata": { 152 | "kernelspec": { 153 | "display_name": "Python 3 (ipykernel)", 154 | "language": "python", 155 | "name": "python3" 156 | }, 157 | "language_info": { 158 | "codemirror_mode": { 159 | "name": "ipython", 160 | "version": 3 161 | }, 162 | "file_extension": ".py", 163 | "mimetype": "text/x-python", 164 | "name": "python", 165 | "nbconvert_exporter": "python", 166 | "pygments_lexer": "ipython3", 167 | "version": "3.10.13" 168 | } 169 | }, 170 | "nbformat": 4, 171 | "nbformat_minor": 5 172 | } 173 | -------------------------------------------------------------------------------- /docs/workspace.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": ".." 5 | } 6 | ], 7 | "settings": {} 8 | } -------------------------------------------------------------------------------- /paper/figure-workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/paper/figure-workflow.png -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | 3 | name = "SCIMAP" 4 | version = "2.3.4" 5 | description = "Spatial Single-Cell Analysis Toolkit" 6 | 7 | license = "MIT" 8 | 9 | authors = ["Ajit Johnson Nirmal "] 10 | 11 | readme = "README.md" 12 | 13 | homepage = "https://pypi.org/project/scimap/" 14 | documentation = "https://scimap.xyz" 15 | repository = "https://github.com/labsyspharm/scimap" 16 | 17 | keywords = ["image analysis","multiplex imaging","single cell analysis"] 18 | 19 | classifiers = [ 20 | "Development Status :: 5 - Production/Stable", 21 | "Natural Language :: English", 22 | "Operating System :: OS Independent", 23 | "Programming Language :: Python", 24 | ] 25 | 26 | exclude = ["docs"] 27 | 28 | [tool.poetry.dependencies] 29 | 30 | python = ">=3.9,<3.13" 31 | pytest = "^7.4.3" 32 | anndata = "^0.10.5.post1" 33 | pandas = "^2.1.3" 34 | scipy = ">1.11.3,<=1.12.0" 35 | seaborn = "^0.13.2" 36 | tifffile = "^2023.9.26" 37 | numpy = "^1.26.2" 38 | pytest-xvfb = "^3.0.0" 39 | matplotlib = "^3.8.1" 40 | PhenoGraph = "^1.5.7" 41 | scanpy = "^1.9.6" 42 | mkdocs = "^1.5.3" 43 | plotly = "^5.18.0" 44 | TiffFile = "^2023.9.26" 45 | dask = {extras = ["array"], version = "^2023.11.0"} 46 | zarr = "2.10.3" 47 | napari = {version = "^0.4.18", optional = true} 48 | numba = ">=0.58.1" 49 | shapely = "^2.0.2" 50 | gensim = "^4.3.2" 51 | mkdocs-material = "^9.4.8" 52 | napari-ome-zarr = {version = "^0.4.0", optional = true} 53 | llvmlite = "^0.41.1" 54 | combat = "^0.3.3" 55 | mpl-scatter-density = "^0.7" 56 | pyqt6 = {version = "^6.6.1", optional = true} 57 | scikit-learn = "^1.4.2" 58 | 59 | [tool.poetry.extras] 60 | napari = ["pyqt6", "napari-ome-zarr", "napari"] 61 | 62 | [tool.poetry.dev-dependencies] 63 | 64 | # Formatters 65 | black = "24.3.0" 66 | isort = "4.3.21" 67 | 68 | # Linters 69 | mypy = "^1.7.0" 70 | pydocstyle = "^6.3.0" 71 | pylint = "^3.0.2" 72 | 73 | # Testing 74 | pytest = "^7.4.3" 75 | pytest-cov = "^4.1.0" 76 | pytest-describe = { git = "https://github.com/pytest-dev/pytest-describe", rev = "453aa9045b265e313f356f1492d8991c02a6aea6" } # use 2.0 when released 77 | pytest-expecter = "^3.0" 78 | pytest-random = "^0.02" 79 | freezegun = "^1.2.2" 80 | 81 | 82 | # Documentation 83 | mkdocs = "^1.5.3" 84 | pygments = "^2.16.1" 85 | 86 | # Tooling 87 | pyinstaller = "^6.2.0" 88 | sniffer = "^0.4.1" 89 | MacFSEvents = { version = "^0.8.4", platform = "darwin" } 90 | pync = { version = "^2.0.3", platform = "darwin" } 91 | ipython = "^8.17.2" 92 | 93 | [tool.poetry.scripts] 94 | 95 | scimap-mcmicro = "scimap.cli._scimap_mcmicro:mcmicro_wrap" 96 | scimap-clustering = "scimap.cli._scimap_mcmicro:clustering" 97 | scimap-merge-h5ad = "scimap.cli._scimap_mcmicro:merge" 98 | 99 | [tool.black] 100 | 101 | target-version = ["py36", "py37"] 102 | skip-string-normalization = true 103 | 104 | [build-system] 105 | 106 | #requires = ["poetry>=0.12"] 107 | #build-backend = "poetry.masonry.api" 108 | requires = ["poetry-core"] 109 | #requires = ["poetry-core>=1.0.0"] 110 | build-backend = "poetry.core.masonry.api" 111 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | 3 | addopts = -ra -q 4 | python_files = test_*.py 5 | testpaths = scimap/tests/ 6 | xfail_strict = true 7 | -------------------------------------------------------------------------------- /scimap/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib.metadata 2 | 3 | try: 4 | __version__ = importlib.metadata.version('scimap') 5 | except importlib.metadata.PackageNotFoundError: 6 | __version__ = '(local)' 7 | 8 | import scimap 9 | 10 | print(f"Running SCIMAP {scimap.__version__}") 11 | 12 | from . import preprocessing as pp 13 | from . import plotting as pl 14 | from . import tools as tl 15 | from . import helpers as hl 16 | from . import external as ex 17 | -------------------------------------------------------------------------------- /scimap/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python -------------------------------------------------------------------------------- /scimap/cli/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/cli/__init__.py -------------------------------------------------------------------------------- /scimap/cli/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Thu Apr 20 10:18:22 2023 5 | @author: aj 6 | """ 7 | 8 | # print out scimap version 9 | import argparse 10 | import toml 11 | 12 | # Read the version number from pyproject.toml 13 | with open('../../pyproject.toml', 'r') as f: 14 | pyproject = toml.load(f) 15 | version = pyproject['tool']['poetry']['version'] 16 | 17 | # Parse command line arguments 18 | parser = argparse.ArgumentParser() 19 | parser.add_argument('-V', '--version', action='store_true', help='Print version number') 20 | args = parser.parse_args() 21 | 22 | # Print the version number if requested 23 | if args.version: 24 | print(version) -------------------------------------------------------------------------------- /scimap/external/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/external/__init__.py -------------------------------------------------------------------------------- /scimap/helpers/__init__.py: -------------------------------------------------------------------------------- 1 | from .rename import rename from .classify import classify from .scimap_to_csv import scimap_to_csv from .addROI_omero import addROI_omero from .animate import animate from .dropFeatures import dropFeatures from .merge_adata_obs import merge_adata_obs from .downloadDemoData import downloadDemoData -------------------------------------------------------------------------------- /scimap/helpers/add_roi_scatter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Sat Feb 13 21:43:29 2021 5 | @author: Ajit Johnson Nirmal 6 | Lasso selector to annotate regions of interest to the anndata object 7 | """ 8 | 9 | # Library 10 | import matplotlib.pyplot as plt 11 | from matplotlib.widgets import LassoSelector 12 | from matplotlib.path import Path 13 | import numpy as np 14 | import pandas as pd 15 | 16 | 17 | # Function 18 | 19 | def add_roi_scatter (adata, method=None, marker=None, threshold=0.5, raw=False, log=False, subset=None, imageid='imageid', 20 | x_coordinate='X_centroid', y_coordinate='Y_centroid',size=5,cmap='gist_heat', 21 | lasso_alpha=0.8, lasso_linewidth=3, lasso_color='red', 22 | roi_name='selected_roi', label='roi_scatter'): 23 | 24 | 25 | # create a copy of the anndata object 26 | adata = combined_excluded_RJP.copy() 27 | bdata = adata.copy() 28 | 29 | # Subset the image of interest 30 | if subset is not None: 31 | bdata = bdata[bdata.obs[imageid] == subset] 32 | 33 | # indentify the index of the marker of interest 34 | if marker is not None: 35 | marker_index = bdata.var.index.get_loc(marker) 36 | 37 | # generate the dataframe needed with 38 | if method is None: 39 | data = pd.DataFrame({'x': bdata.obs[x_coordinate], 'y': bdata.obs[y_coordinate]}) 40 | else: 41 | if marker is None: 42 | raise ValueError('Please choose a marker to be able to use the selected method') 43 | 44 | # If a method is passed first create the data frame with expression values 45 | if method is not None and raw is False: 46 | data = pd.DataFrame({'x': bdata.obs[x_coordinate], 'y': bdata.obs[y_coordinate], marker: bdata.X[:,marker_index]}) 47 | if log is True: 48 | data[marker] = np.log1p(data[marker]) 49 | elif method is not None and raw is True: 50 | data = pd.DataFrame({'x': bdata.obs[x_coordinate], 'y': bdata.obs[y_coordinate], marker: bdata.raw.X[:,marker_index]}) 51 | if log is True: 52 | data[marker] = np.log1p(data[marker]) 53 | 54 | # If threshold method is passed convert the marker expression to binary 55 | if method == 'threshold': 56 | hue = np.array(data[marker]) 57 | hue = ['red' if x >= threshold else 'grey' for x in hue] 58 | 59 | 60 | # Scatter plot start 61 | fig, ax = plt.subplots() 62 | 63 | # plot 64 | if method == 'threshold': 65 | collection = ax.scatter(x=data['x'], y=data['y'], c=hue, s=size) 66 | elif method == 'expression': 67 | collection = ax.scatter(x=data['x'], y=data['y'], c=data[marker], cmap=cmap, s=size) 68 | else: 69 | collection = ax.scatter(x=data['x'], y=data['y'], s=size) 70 | ax.invert_yaxis() 71 | plt.xticks([]) ; plt.yticks([]); 72 | 73 | 74 | xys = collection.get_offsets() 75 | ind = [] 76 | 77 | def onSelect(verts): 78 | path = Path(verts) 79 | ind = np.nonzero(path.contains_points(xys))[0] 80 | adata.obs.loc[data.iloc[ind].index, label] = roi_name 81 | print('Added Selected ROI to adata.obs.' + str(label)) 82 | 83 | lineprops = {'color': lasso_color, 'linewidth': lasso_linewidth, 'alpha': lasso_alpha} 84 | lsso = LassoSelector(ax=ax, onselect=onSelect, lineprops=lineprops) 85 | 86 | 87 | plt.show() 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /scimap/helpers/downloadDemoData.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Wed Mar 20 15:04:25 2024 5 | @author: aj 6 | """ 7 | 8 | import requests 9 | from tqdm import tqdm 10 | import os 11 | 12 | def downloadDemoData(directory, api_url=None): 13 | """ 14 | Downloads all files from a Zenodo record into the specified directory, 15 | showing a progress bar for each file. 16 | 17 | Parameters: 18 | - directory: The directory where the files will be saved. 19 | 20 | Returns: 21 | - None 22 | """ 23 | 24 | # Ensure the target directory exists 25 | if not os.path.exists(directory): 26 | os.makedirs(directory) 27 | print(f"Created directory: {directory}") 28 | 29 | # Get record details from Zenodo API 30 | if api_url is None: 31 | api_url = "https://zenodo.org/api/records/10845625" 32 | 33 | response = requests.get(api_url) 34 | if response.status_code != 200: 35 | print(f"Failed to retrieve record details. HTTP status code: {response.status_code}") 36 | return 37 | 38 | # Extract file links from the record information 39 | record_data = response.json() 40 | files = record_data.get('files', []) 41 | 42 | # Download each file 43 | for file_info in files: 44 | file_url = file_info['links']['self'] 45 | filename = file_info['key'] 46 | save_path = os.path.join(directory, filename) 47 | 48 | # Download the file with progress bar 49 | print(f"Downloading {filename}...") 50 | response = requests.get(file_url, stream=True) 51 | total_size_in_bytes = int(response.headers.get('content-length', 0)) 52 | block_size = 1024 # 1 Kibibyte 53 | 54 | with open(save_path, 'wb') as file, tqdm( 55 | desc=filename, 56 | total=total_size_in_bytes, 57 | unit='iB', 58 | unit_scale=True, 59 | unit_divisor=1024, 60 | ) as progress_bar: 61 | for data in response.iter_content(block_size): 62 | progress_bar.update(len(data)) 63 | file.write(data) 64 | 65 | print(f"Downloaded {filename} to {save_path}") 66 | -------------------------------------------------------------------------------- /scimap/helpers/dropFeatures.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Created on Mon Jul 4 09:27:32 2022 3 | # @author: Ajit Johnson Nirmal 4 | # Drop provided markers or cells from anndata object including the raw matrix 5 | 6 | 7 | """ 8 | !!! abstract "Short Description" 9 | `sm.hl.dropFeatures`: This versatile function streamlines the process of 10 | refining an AnnData object by enabling users to selectively remove markers, 11 | cells, metadata columns, and specific cell groups. It facilitates targeted 12 | dataset curation, ensuring analyses are performed on relevant and clean data subsets. 13 | 14 | ## Function 15 | """ 16 | 17 | import numpy as np 18 | import anndata as ad 19 | 20 | def dropFeatures (adata, 21 | drop_markers=None, 22 | drop_cells=None, 23 | drop_meta_columns=None, 24 | drop_groups=None, 25 | groups_column=None, 26 | subset_raw=True, 27 | verbose=True): 28 | """ 29 | Parameters: 30 | adata (anndata.AnnData): 31 | Annotated data matrix or path to an AnnData object, containing spatial gene expression data. 32 | 33 | drop_markers (list, optional): 34 | A list of gene or marker names to be removed from `adata.var`. 35 | 36 | drop_cells (list, optional): 37 | A list of cell identifiers (index names) to be removed from `adata.obs`. 38 | 39 | drop_meta_columns (list, optional): 40 | A list of metadata column names to be removed from `adata.obs`. 41 | 42 | drop_groups (list, optional): 43 | A list of category names to be removed based on the column specified by `groups_column`. 44 | 45 | groups_column (str, optional): 46 | The name of the column in `adata.obs` that contains the categorical data for `drop_groups`. 47 | 48 | subset_raw (bool, optional): 49 | If True, the same dropping operations are applied to `adata.raw`. 50 | 51 | verbose (bool, optional): 52 | If True, print messages about the dropping process. 53 | 54 | Returns: 55 | adata (anndata.AnnData): 56 | The AnnData object after the specified features have been removed. 57 | 58 | Example: 59 | ```python 60 | # Example 1: Drop specific markers from the dataset 61 | adata = sm.hl.dropFeatures(adata, drop_markers=['CD3D', 'CD19']) 62 | 63 | # Example 2: Remove cells based on their identifiers 64 | adata = sm.hl.dropFeatures(adata, drop_cells=['cell_001', 'cell_002']) 65 | 66 | # Example 3: Remove metadata columns from adata.obs 67 | adata = sm.hl.dropFeatures(adata, drop_meta_columns=['Batch', 'Condition']) 68 | 69 | # Example 4: Exclude specific groups from a categorical column in adata.obs 70 | adata = sm.hl.dropFeatures(adata, drop_groups=['B cell', 'NK cell'], groups_column='Cell_Type') 71 | 72 | ``` 73 | 74 | """ 75 | 76 | # Drop Markers 77 | if drop_markers is not None: 78 | if isinstance(drop_markers, str): 79 | drop_markers = [drop_markers] 80 | # find the index of the given markers 81 | idx_markers = [adata.var.index.get_loc(x) for x in drop_markers] 82 | # remove from adata 83 | keep_markes = list(set(adata.var.index).difference(drop_markers)) 84 | adata = adata[:, keep_markes] 85 | # remove from raw 86 | if subset_raw is True: 87 | raw = np.delete(adata.raw.X, idx_markers, axis=1) 88 | del adata.raw 89 | adata.raw = ad.AnnData (raw) 90 | 91 | # Drop cells 92 | if drop_cells is not None: 93 | if isinstance(drop_cells, str): 94 | drop_cells = [drop_cells] 95 | # find the index of the given markers 96 | idx_markers = [adata.obs.index.get_loc(x) for x in drop_cells] 97 | # remove from adata 98 | keep_markes = list(set(adata.obs.index).difference(drop_cells)) 99 | adata = adata[keep_markes, :] 100 | # remove from raw 101 | if subset_raw is True: 102 | raw = np.delete(adata.raw.X, idx_markers, axis=1) 103 | del adata.raw 104 | adata.raw = ad.AnnData (raw) 105 | 106 | # Drop meta columns 107 | if drop_meta_columns is not None: 108 | if isinstance(drop_meta_columns, str): 109 | drop_meta_columns = [drop_meta_columns] 110 | # remove from adata 111 | adata.obs = adata.obs.drop(drop_meta_columns, axis=1) 112 | 113 | # Drop specific categories of cells 114 | if drop_groups is not None: 115 | if isinstance(drop_groups, str): 116 | drop_groups = [drop_groups] 117 | if isinstance(groups_column, list): 118 | groups_column = groups_column[0] 119 | # find the index of the given markers 120 | idx = adata[adata.obs[groups_column].isin(drop_groups)].obs.index 121 | idx_markers = [adata.obs.index.get_loc(x) for x in idx] 122 | # remove from raw 123 | if subset_raw is True: 124 | raw = np.delete(adata.raw.X, idx_markers, axis=0) 125 | # remove from adata 126 | adata = adata[~adata.obs[groups_column].isin(drop_groups)] 127 | # return adata raw 128 | if subset_raw is True: 129 | del adata.raw 130 | adata.raw = ad.AnnData (raw) 131 | 132 | 133 | # return 134 | return adata 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /scimap/helpers/merge_adata_obs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | !!! abstract "Short Description" 5 | `sm.pl.merge_adata_obs`: This function is designed to consolidate multiple AnnData 6 | objects originating from the same image or dataset into a single cohesive unit. 7 | It is particularly useful when each object contains distinct metadata in `.obs`, 8 | such as results from various clustering algorithms executed in parallel. 9 | By merging these objects, users can streamline analyses and comparisons within 10 | a unified framework. It's important to note that this function is intended for 11 | merging objects from the same source and may not be suitable for combining 12 | data across different images or datasets. 13 | 14 | ## Function 15 | """ 16 | 17 | import argparse 18 | import sys 19 | import pathlib 20 | import pandas as pd 21 | import anndata as ad 22 | 23 | 24 | def main(argv=sys.argv): 25 | parser = argparse.ArgumentParser( 26 | description='The function allows users to combine multiple anndata objects that are from the same image or dataset but differ in the stored metadata' 27 | ) 28 | parser.add_argument( 29 | '--adata', required=True, nargs='*', 30 | help='AnnData object loaded into memory or path to AnnData object.' 31 | ) 32 | parser.add_argument( 33 | '--output_dir', type=str, required=False, default=None, 34 | help='Path to output directory.' 35 | ) 36 | args = parser.parse_args(argv[1:]) 37 | print(vars(args)) 38 | merge_adata_obs(**vars(args)) 39 | 40 | 41 | 42 | def merge_adata_obs (adata, 43 | output_dir=None, 44 | verbose=True): 45 | 46 | 47 | """ 48 | Parameters: 49 | adata (list of anndata.AnnData or list of str): 50 | A list containing AnnData objects to be merged or paths to AnnData files. 51 | Each item in the list should either be an AnnData object already loaded into memory 52 | or a string representing the path to an AnnData file. 53 | 54 | output_dir (str, optional): 55 | The directory where the merged AnnData object should be saved. 56 | If specified, the merged object is saved to this directory as 'merged_adata.h5ad'. 57 | If not specified, the merged AnnData object is not automatically saved to disk. 58 | 59 | verbose (bool, optional): 60 | If True, prints messages about the renaming process. 61 | 62 | Returns: 63 | adata (anndata.AnnData): 64 | A single AnnData object resulting from the merger of input AnnData objects or files. 65 | 66 | Example: 67 | ```python 68 | 69 | # Example 1: Merge AnnData objects already loaded in memory 70 | combined_adata = sm.hl.merge_adata_obs(adata=[adata1, adata2]) 71 | 72 | # Example 2: Merge AnnData objects from file paths 73 | combined_adata = sm.hl.merge_adata_obs(adata=['./data/adata1.h5ad', './data/adata2.h5ad']) 74 | 75 | # Example 3: Merge AnnData objects and save the combined object to a specified directory 76 | combined_adata = sm.hl.merge_adata_obs(adata=[adata1, adata2], output_dir='./merged_data') 77 | 78 | ``` 79 | """ 80 | 81 | #adata = ["/Users/aj/Downloads/mcmicro_output.h5ad", "/Users/aj/Downloads/mcmicro_output_1.h5ad"] 82 | 83 | 84 | # Convert to list of anndata objects 85 | if isinstance (adata, list): 86 | adata = adata 87 | else: 88 | adata = [adata] 89 | 90 | # Resoluve the OBS and UNS section 91 | if isinstance(adata[0], str): 92 | df = pd.DataFrame() 93 | uns_count = [] 94 | for i in adata: 95 | tmp = ad.read_h5ad(i) 96 | # OBS 97 | tmp_df = tmp.obs 98 | df = pd.concat([df, tmp_df], axis=1) 99 | # UNS 100 | uns_count.append(len(tmp.uns)) 101 | # Keep non-duplicate obs columns 102 | df = df.loc[:,~df.columns.duplicated()] 103 | # Highest UNS 104 | uns_index = [i for i, j in enumerate(uns_count) if j == max(uns_count)][0] 105 | else: 106 | df = pd.DataFrame() 107 | uns_count = [] 108 | for i in adata: 109 | # OBS 110 | tmp_df = i.obs 111 | df = pd.concat([df, tmp_df], axis=1) 112 | # UNS 113 | uns_count.append(len(i.uns)) 114 | # Keep non-duplicate obs columns 115 | df = df.loc[:,~df.columns.duplicated()] 116 | # Highest UNS 117 | uns_index = [i for i, j in enumerate(uns_count) if j == max(uns_count)][0] 118 | 119 | 120 | # create the final anndata object 121 | # Load the data 122 | if isinstance(adata[0], str): 123 | final_adata = ad.read_h5ad(adata[uns_index]) 124 | else: 125 | final_adata = adata[uns_index] 126 | 127 | # reindex 128 | df = df.reindex (final_adata.obs.index) 129 | 130 | # replace obs 131 | final_adata.obs = df 132 | 133 | 134 | # Save data if requested 135 | if output_dir is not None: 136 | output_dir = pathlib.Path(output_dir) 137 | output_dir.mkdir(exist_ok=True, parents=True) 138 | final_adata.write(output_dir / 'combined_adata.h5ad') 139 | else: 140 | # Return data 141 | return final_adata 142 | 143 | 144 | 145 | if __name__ == '__main__': 146 | main() 147 | 148 | -------------------------------------------------------------------------------- /scimap/helpers/rename.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # Created on Sun Mar 22 13:08:26 2020 4 | # @author: Ajit Johnson Nirmal 5 | """ 6 | !!! abstract "Short Description" 7 | `sm.hl.rename`: This function offers a straightforward way to rename specific 8 | categories within a chosen column of an AnnData object, with the new names 9 | being stored in a separate column. It streamlines the process of updating or 10 | consolidating category labels for enhanced data clarity and analysis. 11 | 12 | ## Function 13 | """ 14 | # Import 15 | import functools 16 | import re 17 | 18 | # Function 19 | def rename (adata, 20 | rename, 21 | from_column='phenotype', 22 | to_column='phenotype_renamed', 23 | verbose=True): 24 | """ 25 | Parameters: 26 | adata (anndata.AnnData): 27 | Annotated data matrix or path to an AnnData object, containing spatial gene expression data. 28 | 29 | rename (dict): 30 | A dictionary mapping existing category names (values) to new category names (keys). 31 | Each key corresponds to the new name, and its value is a list of existing names to be consolidated under this new name. 32 | 33 | from_column (str, optional): 34 | The name of the column in `adata.obs` where the categories to be renamed are located. Defaults to 'phenotype'. 35 | 36 | to_column (str, optional): 37 | The name of the new column in `adata.obs` where the renamed categories will be stored. Defaults to 'phenotype_renamed'. 38 | 39 | verbose (bool, optional): 40 | If True, prints messages about the renaming process. 41 | 42 | Returns: 43 | adata (anndata.AnnData): 44 | The AnnData object after applying the renaming operation, with the newly named categories stored in the specified `adata.obs[to_column]`. 45 | 46 | Example: 47 | ```python 48 | 49 | # Example 1: Simplify phenotype labels 50 | rename_dict = {'tumor': ['cd45 neg tumor', 'cd8 tumor', 'cd4 tumor'], 51 | 'macrophages': ['m1 macrophages', 'm2 macrophages']} 52 | adata = sm.hl.rename(adata, rename=rename_dict, from_column='phenotype', to_column='simplified_phenotype') 53 | 54 | # Example 2: Merge similar phenotypes under a common name 55 | merge_dict = {'immune cells': ['cd45+', 't-cells', 'b-cells']} 56 | adata = sm.hl.rename(adata, rename=merge_dict, from_column='cell_type', to_column='merged_cell_type') 57 | 58 | # Example 3: Rename and create a new column for easier identification 59 | new_names = {'activated': ['activated_tcells', 'activated_bcells'], 60 | 'resting': ['resting_tcells', 'resting_bcells']} 61 | adata = sm.hl.rename(adata, rename=new_names, from_column='status', to_column='status_simplified') 62 | 63 | ``` 64 | """ 65 | 66 | # Sanity check: if the values are not list convert them into list 67 | for i in rename: 68 | if isinstance(rename[i], str): 69 | rename[i] = [rename[i]] 70 | 71 | # Get the from_column 72 | rename_from = list(adata.obs[from_column].values) 73 | 74 | # Split multiple renaming events into independent events 75 | name = functools.reduce( lambda x,y: dict(x, **y), (dict(map(lambda x: (x,i), rename[i])) for i in rename)) 76 | 77 | # Rename 78 | for i in name: 79 | if verbose: 80 | print ('Renaming ' + str(i) + ' to ' + str(name[i])) 81 | #rename_from = [x.replace(i, name[i]) for x in rename_from] 82 | s = str(i) 83 | s = s.replace('+', '\+') 84 | #rename_from = [re.sub(r'^\b%s\b$' % s, name[i], j) for j in rename_from] 85 | rename_from = [re.sub(r'^\b%s$' % s, name[i], j) for j in rename_from] 86 | 87 | 88 | # Append to adata as a new column 89 | adata.obs[to_column] = rename_from 90 | 91 | # Return 92 | return adata 93 | -------------------------------------------------------------------------------- /scimap/plotting/__init__.py: -------------------------------------------------------------------------------- 1 | from .gate_finder import gate_finder 2 | from .image_viewer import image_viewer 3 | from .spatial_interaction import spatial_interaction 4 | from .spatial_distance import spatial_distance 5 | from .stacked_barplot import stacked_barplot 6 | from .spatial_pscore import spatial_pscore 7 | from .voronoi import voronoi 8 | from .foldchange import foldchange 9 | from .pie import pie 10 | from .cluster_plots import cluster_plots 11 | from .addROI_image import addROI_image 12 | from .umap import umap 13 | from .densityPlot2D import densityPlot2D 14 | from .distPlot import distPlot 15 | from .spatial_scatterPlot import spatial_scatterPlot 16 | from .heatmap import heatmap 17 | from .markerCorrelation import markerCorrelation 18 | from .groupCorrelation import groupCorrelation 19 | from .spatialInteractionNetwork import spatialInteractionNetwork 20 | from .napariGater import napariGater -------------------------------------------------------------------------------- /scimap/preprocessing/__init__.py: -------------------------------------------------------------------------------- 1 | from .mcmicro_to_scimap import mcmicro_to_scimap from .rescale import rescale from .combat import combat from .log1p import log1p -------------------------------------------------------------------------------- /scimap/preprocessing/combat.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Created on Wed Apr 19 16:53:02 2023 3 | # @author: Ajit Johnson Nirmal 4 | 5 | 6 | """ 7 | !!! abstract "Short Description" 8 | ComBat is a well-established method for correcting batch effects in high-dimensional data, such as single-cell RNA-seq. 9 | This implementation uses the `combat` function to correct batch effects across multiple slides. 10 | 11 | ## Function 12 | """ 13 | 14 | # import libs 15 | from combat.pycombat import pycombat 16 | import pandas as pd 17 | import anndata as ad 18 | import numpy as np 19 | import argparse 20 | 21 | 22 | def combat( 23 | adata, 24 | batch='imageid', 25 | layer=None, 26 | log=False, 27 | replaceOriginal=False, 28 | label='combat'): 29 | 30 | """ 31 | Parameters: 32 | adata (AnnData object): 33 | Annotated data matrix. 34 | 35 | batch (str, optional): 36 | The batch key or column in `adata.obs` that indicates the batches for each cell. 37 | 38 | layer (str or None, optional): 39 | The layer in `adata.layers` that contains the expression data to correct. If None, 40 | `adata.X` is used. use `raw` to use the data stored in `adata.raw.X` 41 | 42 | log (bool, optional): 43 | Whether to log transform the data before applying ComBat. Generally use it with `raw`. 44 | 45 | replaceOriginal (bool, optional): 46 | Whether to replace the original expression data in `adata` with the corrected data. 47 | 48 | label (str, optional): 49 | The prefix for the key in `adata` that will contain the corrected data. If `replaceOriginal` is `True`, this parameter has no effect. 50 | 51 | Returns: 52 | adata (anndata): 53 | The corrected expression data is stored in a new layer `adata.layers['combat']`. 54 | 55 | Example: 56 | ```python 57 | 58 | # applying batch correction using raw data 59 | adata = sm.pp.combat (adata, 60 | batch='imageid', 61 | layer='raw', 62 | log=True, 63 | replaceOriginal=False, 64 | label='combat') 65 | 66 | # results will be available in adata.layers['combat'] 67 | 68 | ``` 69 | """ 70 | 71 | # isolate the data 72 | if layer is None: 73 | data = pd.DataFrame(adata.X, index=adata.obs.index, columns=adata.var.index) 74 | elif layer == 'raw': 75 | data = pd.DataFrame(adata.raw.X, index=adata.obs.index, columns=adata.var.index) 76 | else: 77 | data = pd.DataFrame(adata.layers[layer], index=adata.obs.index, columns=adata.var.index) 78 | 79 | # log the data if requested 80 | if log is True: 81 | data = np.log1p(data) 82 | 83 | # isolate batch 84 | batchData = adata.obs[batch] 85 | 86 | # convert to category 87 | batchData = batchData.astype('category') 88 | 89 | # make sure there are atleast two batches 90 | if len(batchData.unique()) < 2: 91 | raise Exception( 92 | "Sorry a minimum of 2 batches is required. Please check the '" 93 | + str(batch) 94 | + "' column" 95 | ) 96 | 97 | # perform batch correction 98 | batchCorrected = pycombat(data.T, batchData).T 99 | 100 | # add as a specific layer 101 | adata.layers[label] = batchCorrected 102 | 103 | # replace original 104 | if replaceOriginal is True: 105 | if layer is None: 106 | adata.X = batchCorrected 107 | elif layer == 'raw': 108 | del adata.raw 109 | adata.raw = ad.AnnData(batchCorrected, obs=adata.obs) 110 | else: 111 | adata.layers[layer] = batchCorrected 112 | 113 | # return adata 114 | return adata 115 | 116 | 117 | # Make the Function CLI compatable 118 | if __name__ == '__main__': 119 | parser = argparse.ArgumentParser(description='Run ComBat batch correction.') 120 | parser.add_argument('--adata', type=str, help='Annotated data matrix.') 121 | parser.add_argument( 122 | '--batch', 123 | type=str, 124 | default='imageid', 125 | help='The batch key or column in `adata.obs` that indicates the batches for each cell.', 126 | ) 127 | parser.add_argument( 128 | '--layer', 129 | type=str, 130 | default=None, 131 | help='The layer in `adata.layers` that contains the expression data to correct. If None, `adata.X` is used. use `raw` to use the data stored in `adata.raw.X`', 132 | ) 133 | parser.add_argument( 134 | '--log', 135 | type=bool, 136 | default=False, 137 | help='Whether to log transform the data before applying ComBat. Generally use it with `raw`.', 138 | ) 139 | parser.add_argument( 140 | '--replaceOriginal', 141 | type=bool, 142 | default=False, 143 | help='Whether to replace the original expression data in `adata` with the corrected data.', 144 | ) 145 | parser.add_argument( 146 | '--label', 147 | type=str, 148 | default='combat', 149 | help='The prefix for the key in `adata` that will contain the corrected data. If `replaceOriginal` is True, this parameter has no effect.', 150 | ) 151 | args = parser.parse_args() 152 | combat( 153 | adata=args.adata, 154 | batch=args.batch, 155 | layer=args.layer, 156 | log=args.log, 157 | replaceOriginal=args.replaceOriginal, 158 | label=args.label) 159 | -------------------------------------------------------------------------------- /scimap/preprocessing/log1p.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | #Created on Thu Nov 10 09:53:28 2022 3 | #@author: Ajit Johnson Nirmal 4 | #Function to incorporate log transformation 5 | 6 | """ 7 | !!! abstract "Short Description" 8 | `sm.pp.log1p` applies a log1p transformation to the raw data of an AnnData object and saves the transformed data in a specified layer. 9 | If a string path to an AnnData file is provided, the file is loaded, transformed, and overwritten with the 10 | transformed data. The function ensures the raw data exists before applying the transformation and allows for verbose output. 11 | 12 | ## Function 13 | """ 14 | 15 | # import library 16 | import anndata as ad 17 | import numpy as np 18 | from pathlib import Path 19 | import argparse 20 | 21 | 22 | def log1p (adata, 23 | layer='log', 24 | verbose=True): 25 | 26 | """ 27 | Parameters: 28 | adata (str or anndata.AnnData): 29 | The AnnData object or a string path to an AnnData file. If a path is provided, the function will load the AnnData object from the file. The transformation is applied to the raw data of this object. 30 | 31 | layer (str): 32 | Name of the new layer where the log-transformed data will be stored. Default is 'log'. If the layer already exists, it will be overwritten with the new log-transformed data. 33 | 34 | verbose (bool): 35 | If True, the function will print messages about its progress and actions, including warnings if the specified layer already exists and confirmation when the AnnData object is saved to a file. Default is True. 36 | 37 | 38 | Returns: 39 | adata (anndata): 40 | The modified AnnData object, only if the input is an AnnData object and not a file path. If a file path is provided and successfully processed, the function returns None. 41 | 42 | Example: 43 | ```python 44 | 45 | # Using a path to an AnnData file: 46 | # will overwrite the original file with the transformed AnnData object. 47 | 48 | sm.pp.log1p("path/to/your/adata.h5ad", layer="log", verbose=True) 49 | 50 | # Using an AnnData object directly: 51 | # Assuming `adata` is your pre-loaded into memory 52 | # This will apply log1p transformation and the modified AnnData object 53 | 54 | adata = sm.pp.log1p(adata, layer="log", verbose=True) 55 | 56 | ``` 57 | """ 58 | 59 | # load adata 60 | if isinstance(adata, str): 61 | adata_path = Path(adata) 62 | if not adata_path.exists(): 63 | raise FileNotFoundError(f"The file {adata} does not exist.") 64 | adata = ad.read_h5ad(adata_path) 65 | else: 66 | adata_path = None 67 | 68 | 69 | if layer in adata.layers: 70 | if verbose: 71 | print(f"Warning: Layer '{layer}' already exists. It will be overwritten with the new log-transformed data.") 72 | 73 | if adata.raw is None: 74 | raise AttributeError("adata.raw does not exist. Please assign RAW data to adata.raw before proceeding (e.g., adata.raw = adata).") 75 | 76 | # perform the operation 77 | adata.layers[layer] = np.log1p(adata.raw.X) 78 | 79 | # return 80 | # Overwrite the original file with the modified AnnData object if requested 81 | if isinstance(adata_path, Path): 82 | adata.write_h5ad(adata_path) 83 | if verbose: 84 | print(f"Modified AnnData object has been saved to {adata_path}") 85 | else: 86 | return adata 87 | 88 | 89 | 90 | if __name__ == '__main__': 91 | parser = argparse.ArgumentParser(description='Apply a log1p transformation to the raw data of an AnnData object and save the transformed data in a specified layer.') 92 | 93 | parser.add_argument('--adata', type=str, required=True, help='Path to an AnnData object file. The AnnData object will be loaded from this file.') 94 | parser.add_argument('--layer', type=str, default='log', help="Name of the new layer where the log-transformed data will be stored. Default is 'log'.") 95 | parser.add_argument('--verbose', action='store_true', help="If set, print messages about progress and actions. Default is False.") 96 | 97 | args = parser.parse_args() 98 | 99 | # Call log1p function with the provided arguments 100 | log1p(args.adata, layer=args.layer, verbose=args.verbose) -------------------------------------------------------------------------------- /scimap/preprocessing/ngraph.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | #Created on Sun Mar 17 16:09:22 2024 4 | #@author: Ajit Johnson Nirmal 5 | #Create a neighbourhood graph 6 | 7 | """ 8 | !!! abstract "Short Description" 9 | `sm.pp.nGraph` constructs a k-neighbors graph from single-cell data contained within an AnnData object. It offers options for data preprocessing such as standard scaling and principal component analysis (PCA) before graph construction. The resulting graph is stored in the `.obsp['connectivities']` of the AnnData object. The function accommodates data from the raw layer, a specified layer, or the default data layer (`adata.X`), and allows for specifying the number of neighbors to define connectivity. 10 | 11 | ## Function 12 | """ 13 | 14 | 15 | # lib 16 | from sklearn.neighbors import kneighbors_graph 17 | from sklearn.preprocessing import StandardScaler 18 | from sklearn.decomposition import PCA 19 | import numpy as np 20 | import igraph as ig 21 | 22 | 23 | # function 24 | 25 | def nGraph (adata, 26 | layer='raw', 27 | standardScale=False, 28 | runPCA=False, 29 | k_neighbors=15): 30 | 31 | """ 32 | Generates a k-neighbors graph from high-dimensional single-cell data, with options for preprocessing steps 33 | such as standard scaling and principal component analysis (PCA). 34 | 35 | Parameters: 36 | adata (AnnData): 37 | An AnnData object containing single-cell data. Must have `.X` for data matrix, `.raw.X` for raw data, 38 | and `.layers` for additional data layers. 39 | 40 | layer (str, optional): 41 | Specifies which layer of the `adata` to use for graph construction. The default is 'raw', indicating 42 | that `adata.raw.X` will be used. If `None`, `adata.X` will be utilized. Otherwise, specifies the key 43 | to use data from `adata.layers`. 44 | 45 | standardScale (bool, optional): 46 | If `True`, applies standard scaling to the data, making the mean of each feature 0 and the variance 1. 47 | 48 | runPCA (bool, optional): 49 | If `True`, performs principal component analysis on the data and uses the principal components for 50 | graph construction. This is often done to reduce dimensionality and noise. 51 | 52 | k_neighbors (int, optional): 53 | The number of neighbors to use for k-neighbors graph construction. This parameter determines the 54 | connectivity of the graph. Defaults to 15. 55 | 56 | Returns: 57 | adata (annData): 58 | The input `adata` object is returned after adding the k-neighbors graph to `.obsp['connectivities']`. 59 | 60 | Examples: 61 | ```python 62 | 63 | # Example 1: Basic usage with raw layer data and default settings 64 | adata = sm.pp.nGraph(adata) 65 | 66 | # Example 2: Using data from default layer, with standard scaling and PCA applied, specifying k_neighbors 67 | adata = sm.pp.nGraph(adata, layer=None, standardScale=True, runPCA=True, k_neighbors=20) 68 | ``` 69 | """ 70 | 71 | # prepare data 72 | if layer == 'raw': 73 | data = adata.raw.X.copy() 74 | elif layer is None: 75 | data = adata.X.copy() 76 | else: 77 | data = adata.layers[layer].copy() 78 | 79 | if standardScale: 80 | scaler = StandardScaler() 81 | data = scaler.fit_transform(data) 82 | 83 | if runPCA: 84 | # Initialize PCA object 85 | pca = PCA(n_components=None) # 'None' to obtain all PCs 86 | # Fit PCA on the data 87 | pca.fit(data.T) 88 | # Transform the data 89 | X_pca = pca.transform(data.T) 90 | # X_pca now contains the principal components 91 | data = pca.components_.T 92 | 93 | 94 | # Generate a k-neighbors graph from the data 95 | graph = kneighbors_graph(X=data, n_neighbors=k_neighbors, mode='connectivity') 96 | adata.obsp['connectivities'] = graph 97 | 98 | # return graph 99 | return adata 100 | -------------------------------------------------------------------------------- /scimap/tests/_data/example_data.h5ad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/_data/example_data.h5ad -------------------------------------------------------------------------------- /scimap/tests/_data/phenotype_workflow.csv: -------------------------------------------------------------------------------- 1 | ,,ASMA,CD163,CD206,CD68,CD20,CD21,CD3D,CD45,CD5,CD56,CD8A,FOXP3,CD11B,CD11C,CD15,CD4,PD1,HLADR,CD25,CD30,KI67 2 | all,Other Immune cells,,,,,,,,pos,,,,,,,,,,,,, 3 | all,Non-immune cells,,,,,,,,neg,,,,,,,,,,,,, 4 | all,ASMA+ cells,pos,,,,,,,,,,,,,,,,,,,, 5 | Non-immune cells,Tumor CD45- CD30+,,,,,,,,,,,,,,,,,,,,pos, 6 | Non-immune cells,Aberrant T cells CD45- CD3+,,,,,,,pos,,,,,,,,,,,,,, 7 | Aberrant T cells CD45- CD3+,Aberrant T cells CD45- CD3+ FOXP3+,,,,,,,,,,,,pos,,,,,,,,, 8 | Other Immune cells,Tumor CD30+,,,,,,,,,,,,,,,,,,,,pos, 9 | Other Immune cells,T cells,,,,,,,pos,,,,,,,,,,,,,neg, 10 | Other Immune cells,B cells,,,,,pos,,,,,,,,,,,,,,,, 11 | Other Immune cells,Myeloid Lineage,,anypos,anypos,anypos,,,,,,,,,anypos,anypos,,,,,,, 12 | Other Immune cells,NK cells,,,,,,,,,,pos,,,,,,,,,,, 13 | Other Immune cells,Granulocytes,,,,,,,,,,,,,,,pos,,,,,, 14 | Myeloid Lineage,T cells,,,,,,,pos,,,,,,,,,,,,,, 15 | Myeloid Lineage,B cells,,,,,pos,,,,,,,,,,,,,,,, 16 | Myeloid Lineage,NK cells,,,,,,,,,,pos,,,,,,,,,,, 17 | Myeloid Lineage,Granulocytes,,,,,,,,,,,,,,,pos,,,,,, 18 | T cells,Tumor CD30+,,,,,,,,,,,,,,,,,,,,pos, 19 | T cells-rest,CD4 T cells,,,,,,,,,,,,,,,,pos,,,,, 20 | T cells-rest,CD8 T cells,,,,,,,,,,,pos,,,,,,,,,, 21 | T cells-rest,Tumor CD4+ CD8+,,,,,,,,,,allpos,,,,,allpos,,,,,, 22 | CD4 T cells,Regulatory T cells,,,,,,,,,,,,pos,,,,,,,,, 23 | CD4 T cells,Tumor CD30+,,,,,,,,,,,,,,,,,,,,pos, 24 | CD4 T cells,Follicular Helper T cells,,,,,,,,,,,,,,,,,pos,,,, 25 | CD8 T cells,Tumor CD30+,,,,,,,,,,,,,,,,,,,,pos, 26 | CD8 T cells,PD1+ T cells,,,,,,,,,,,,,,,,,pos,,,, 27 | Myeloid Lineage,CD68+ Macrophages,,,,pos,,,,,,,,,,,,,,,,, 28 | Myeloid Lineage,M2 Macrophages,,anypos,anypos,,,,,,,,,,,,,,,,,, 29 | Myeloid Lineage,Myeloid Dendritic cells,,,,,,,,,,,,,,,,,,pos,,, 30 | Myeloid Lineage,Follicular Dendritic cells,,,,,,pos,,,,,,,,,,,,,,, 31 | CD68+ Macrophages,M1 Macrophages,,,,,,,,,,,,,,,,,,pos,,, 32 | Myeloid Dendritic cells,CD25+ Dendritic cells,,,,,,,,,,,,,,,,,,,pos,, 33 | Tumor CD30+,Tumor CD30+ KI67+,,,,,,,,,,,,,,,,,,,,,pos -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_classify.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_classify.pkl -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_cluster.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_cluster.pkl -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_combat.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_combat.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_foldchange.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_foldchange.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_log1p.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_log1p.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_phenotype.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_phenotype.pkl -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_rename.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_rename.pkl -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_rescale.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_rescale.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_spatial_aggregate.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_spatial_aggregate.pkl -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_spatial_cluster.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_spatial_cluster.pkl -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_spatial_count.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_spatial_count.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_spatial_distance.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_spatial_distance.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_spatial_expression.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_spatial_expression.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_spatial_lda.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_spatial_lda.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_spatial_pscore.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_spatial_pscore.npz -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_spatial_similarity_search.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_spatial_similarity_search.pkl -------------------------------------------------------------------------------- /scimap/tests/expected_test_values/test_umap.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/expected_test_values/test_umap.npz -------------------------------------------------------------------------------- /scimap/tests/scimapExampleData/manual_gates.csv: -------------------------------------------------------------------------------- 1 | markers,exemplar-001--unmicst_cell 2 | ELANE,7.8 3 | CD57,8.9 4 | CD45,6.4 5 | CD11B,7.6 6 | SMA,7.5 7 | CD16,6.5 8 | ECAD,7.35 9 | FOXP3,7.4 10 | NCAM,7 -------------------------------------------------------------------------------- /scimap/tests/scimapExampleData/markers.csv: -------------------------------------------------------------------------------- 1 | channel_number,cycle_number,marker_name,Filter,excitation_wavelength,emission_wavelength,background,exposure,remove 2 | 21,6,DNA_6,DAPI,395,431,,100, 3 | 22,6,ELANE,FITC,485,525,,100, 4 | 23,6,CD57,Sytox,555,590,,100, 5 | 24,6,CD45,Cy5,640,690,,100, 6 | 25,7,DNA_7,DAPI,395,431,,100, 7 | 26,7,CD11B,FITC,485,525,,100, 8 | 27,7,SMA,Sytox,555,590,,100, 9 | 28,7,CD16,Cy5,640,690,,100, 10 | 29,8,DNA_8,DAPI,395,431,,100, 11 | 30,8,ECAD,FITC,485,525,,100, 12 | 31,8,FOXP3,Sytox,555,590,,100, 13 | 32,8,NCAM,Cy5,640,690,,100, 14 | -------------------------------------------------------------------------------- /scimap/tests/scimapExampleData/phenotype_workflow.csv: -------------------------------------------------------------------------------- 1 | ,,ELANE,CD57,CD45,CD11B,SMA,CD16,ECAD,FOXP3,NCAM 2 | all,ECAD+,,,,,,,pos,, 3 | all,Immune,,,pos,,,,,, 4 | all,SMA+,,,,,pos,,,, 5 | Immune,NK cells,,allpos,,neg,,allpos,,, 6 | Immune,Other myeloid cells,,,,pos,,,,, 7 | Immune,Treg,,,,,,,,pos, 8 | Other myeloid cells,Dendritic cells,,allneg,,,,allneg,,, 9 | -------------------------------------------------------------------------------- /scimap/tests/scimapExampleData/scimapExampleData.h5ad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/scimap/4b7e1bcd1b46744235b2ffb8016b964b2a7675ca/scimap/tests/scimapExampleData/scimapExampleData.h5ad -------------------------------------------------------------------------------- /scimap/tests/test_hl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Tue Apr 23 20:14:55 2024 5 | @author: aj 6 | Test helper function 7 | """ 8 | 9 | import pytest 10 | import os 11 | import anndata as ad 12 | import pandas as pd 13 | import pickle 14 | 15 | 16 | load_pickle = lambda filename: pickle.load(open(filename, 'rb')) 17 | #save_pickle(list(adata.obs['phenotype_renamed']), '/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/softwares/scimap/scimap/tests/expected_test_values/test_rename.pkl') 18 | 19 | # load data 20 | @pytest.fixture 21 | def adata(): 22 | image_path = os.getcwd() + '/scimap/tests/scimapExampleData/scimapExampleData.h5ad' 23 | adata = ad.read_h5ad(image_path) 24 | return adata 25 | 26 | 27 | # classify 28 | def test_classify (adata): 29 | from scimap.helpers.classify import classify 30 | adata = classify(adata, pos=['FOXP3'], neg=['ECAD'], phenotype='phenotype') 31 | # load expected data 32 | loaded_data = load_pickle(os.getcwd() + '/scimap/tests/expected_test_values/test_classify.pkl') 33 | assert loaded_data == list(adata.obs['classify']), "The lists do not match." 34 | 35 | # rename 36 | def test_rename (adata): 37 | from scimap.helpers.rename import rename 38 | name= {'renamed': ['Dendritic cells', 'NK cells']} 39 | adata = rename (adata, name, from_column='phenotype', to_column='phenotype_renamed') 40 | # load expected data 41 | loaded_data = load_pickle(os.getcwd() + '/scimap/tests/expected_test_values/test_rename.pkl') 42 | assert loaded_data == list(adata.obs['phenotype_renamed']), "The lists do not match." 43 | 44 | # dropFeatures 45 | def test_dropFeatures (adata): 46 | from scimap.helpers.dropFeatures import dropFeatures 47 | adata = dropFeatures(adata, drop_markers=['ELANE', 'NCAM']) 48 | assert len(adata.var.index) == 7 49 | 50 | # merge_adata_obs 51 | def test_merge_adata_obs (adata): 52 | from scimap.helpers.merge_adata_obs import merge_adata_obs 53 | bdata = adata.copy() 54 | bdata.obs['new_col'] = bdata.obs['imageid'] 55 | combined_adata = merge_adata_obs(adata=[adata, bdata]) 56 | assert len(combined_adata.obs.columns) == 14 57 | 58 | # scimap_to_csv 59 | def test_scimap_to_csv (adata): 60 | from scimap.helpers.scimap_to_csv import scimap_to_csv 61 | data = scimap_to_csv(adata) 62 | assert data.shape == (11201, 22) 63 | 64 | # downloadDemoData 65 | def downloadDemoData (): 66 | from scimap.helpers.downloadDemoData import downloadDemoData 67 | download_directory = os.getcwd() + '/demodata' 68 | downloadDemoData (download_directory, api_url="https://zenodo.org/api/records/11054442") 69 | downloaded_data = pd.read_csv(os.getcwd() + '/demodata/manual_gates.csv') 70 | assert downloaded_data.shape == (9, 2) 71 | 72 | # addROI_omero 73 | 74 | # animate -------------------------------------------------------------------------------- /scimap/tests/test_pp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Mon Apr 22 22:16:06 2024 5 | @author: aj 6 | Pre processing tools tests 7 | """ 8 | 9 | import pytest 10 | import os 11 | import anndata as ad 12 | import pandas as pd 13 | import numpy as np 14 | 15 | 16 | #os.chdir ('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/softwares/scimap') 17 | # np.savez('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/softwares/scimap/scimap/tests/expected_test_values/test_log1p.npz', data=adata.layers['log_test']) 18 | 19 | # loading via mcmicro 20 | def test_mcmicro_to_scimap(): 21 | from scimap.preprocessing.mcmicro_to_scimap import mcmicro_to_scimap 22 | feature_table_path = [os.getcwd() + '/scimap/tests/scimapExampleData/exemplar-001--unmicst_cell.csv'] 23 | adata = mcmicro_to_scimap (feature_table_path) 24 | assert adata.shape == (11201, 9) 25 | 26 | 27 | @pytest.fixture 28 | def adata(): 29 | image_path = os.getcwd() + '/scimap/tests/scimapExampleData/scimapExampleData.h5ad' 30 | adata = ad.read_h5ad(image_path) 31 | return adata 32 | 33 | 34 | # log1p 35 | def test_log1p (adata): 36 | from scimap.preprocessing.log1p import log1p 37 | adata = log1p (adata, layer='log_test') 38 | # load expected data 39 | loaded_data = np.load( os.getcwd() + '/scimap/tests/expected_test_values/test_log1p.npz')['data'] 40 | assert np.allclose(loaded_data, adata.layers['log_test']), "The arrays do not match." 41 | 42 | 43 | # rescale 44 | def test_rescale (adata): 45 | from scimap.preprocessing.rescale import rescale 46 | manual_gate = pd.read_csv(os.getcwd() + '/scimap/tests/scimapExampleData/manual_gates.csv') 47 | adata = rescale (adata, gate=manual_gate) 48 | # load expected data 49 | loaded_data = np.load( os.getcwd() + '/scimap/tests/expected_test_values/test_rescale.npz')['data'] 50 | assert np.allclose(loaded_data, adata.X), "The arrays do not match." 51 | 52 | 53 | # combat 54 | def test_combat (adata): 55 | from scimap.preprocessing.combat import combat 56 | adata = combat (adata, batch='ROI') 57 | assert adata.layers['combat'].shape == (11201, 9) 58 | adata = combat (adata, batch='ROI', layer='raw', label='combat_raw') 59 | assert adata.layers['combat_raw'].shape == (11201, 9) 60 | adata = combat (adata, batch='ROI', log=True, label='combat_log') 61 | assert adata.layers['combat_log'].shape == (11201, 9) 62 | adata = combat (adata, batch='ROI', layer='log', label='combat_log_layer') 63 | assert adata.layers['combat_log_layer'].shape == (11201, 9) 64 | adata = combat (adata, batch='ROI', replaceOriginal=True) 65 | # load expected data 66 | loaded_data = np.load( os.getcwd() + '/scimap/tests/expected_test_values/test_combat.npz')['data'] 67 | assert np.allclose(loaded_data, adata.X), "The arrays do not match." 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /scimap/tools/__init__.py: -------------------------------------------------------------------------------- 1 | from .phenotype_cells import phenotype_cells from .spatial_count import spatial_count from .spatial_expression import spatial_expression from .spatial_aggregate import spatial_aggregate from .cluster import cluster from .spatial_interaction import spatial_interaction from .spatial_distance import spatial_distance from .spatial_pscore import spatial_pscore from .spatial_lda import spatial_lda from .foldchange import foldchange from .spatial_cluster import spatial_cluster from .spatial_similarity_search import spatial_similarity_search from .umap import umap -------------------------------------------------------------------------------- /scimap/tools/umap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # Created on Sat May 28 19:13:24 2022 4 | # @author: Ajit Johnson Nirmal 5 | # UMAP Function 6 | 7 | """ 8 | !!! abstract "Short Description" 9 | `sm.tl.umap`: This function enables dimensionality reduction on high-dimensional 10 | datasets using UMAP, allowing for the visualization of complex data structures 11 | in a lower-dimensional space. It supports customization through various parameters, 12 | including data source selection, logarithmic transformation, and manifold 13 | approximation settings, accommodating a wide range of analytical needs. Results 14 | are stored in `adata.obsm`, ready for subsequent visualization or analysis. 15 | 16 | ## Function 17 | """ 18 | 19 | # libs 20 | import umap as um 21 | import numpy as np 22 | 23 | 24 | # function 25 | def umap (adata, 26 | use_layer=None, 27 | use_raw=False, 28 | log=False, 29 | n_neighbors=15, 30 | n_components=2, 31 | metric='euclidean', 32 | min_dist=0.1, 33 | random_state=0, 34 | label='umap', **kwargs): 35 | """ 36 | Parameters: 37 | adata (anndata.AnnData): 38 | Annotated data matrix or path to an AnnData object, containing spatial gene expression data. 39 | 40 | use_layer (str, optional): 41 | Specifies a layer in `adata.layers` for UMAP. Defaults to using `adata.X`. 42 | 43 | use_raw (bool, optional): 44 | Whether to use `adata.raw.X` for the analysis. 45 | 46 | log (bool, optional): 47 | Applies natural log transformation to the data if `True`. 48 | 49 | n_neighbors (int, optional): 50 | Number of neighboring points used in manifold approximation. 51 | 52 | n_components (int, optional): 53 | Dimensionality of the target embedding space. 54 | 55 | metric (str, optional): 56 | Metric used to compute distances in high-dimensional space. 57 | 58 | min_dist (float, optional): 59 | Effective minimum distance between embedded points. 60 | 61 | random_state (int, optional): 62 | Seed used by the random number generator for reproducibility. 63 | 64 | label (str, optional): 65 | Key for storing UMAP results in `adata.obsm`. 66 | 67 | Returns: 68 | adata (anndata.AnnData): 69 | The input `adata` object, updated with UMAP embedding results in `adata.obsm[label]`. 70 | 71 | Example: 72 | ```python 73 | 74 | # Basic UMAP reduction 75 | adata = sm.tl.umap(adata, n_neighbors=15, min_dist=0.1, label='umap_basic') 76 | 77 | # UMAP using specific layer and log transformation 78 | adata = sm.tl.umap(adata, use_layer='counts', use_raw=True, log=True, n_neighbors=30, min_dist=0.05, label='umap_layer_log') 79 | 80 | # UMAP with a different metric and higher dimensionality 81 | adata = sm.tl.umap(adata, metric='manhattan', n_components=3, n_neighbors=50, label='umap_manhattan_3d') 82 | 83 | # plot results 84 | sm.pl.umap(adata) 85 | 86 | ``` 87 | """ 88 | 89 | # adata_layer=None;use_raw=False;log=False;n_neighbors=15;n_components=2;metric='euclidean';min_dist=0.1; 90 | # random_state=0; 91 | # load data 92 | if use_layer is not None: 93 | data = adata.layers[use_layer] 94 | elif use_raw is True: 95 | data = adata.raw.X 96 | else: 97 | data = adata.X 98 | 99 | # log the data if user requests 100 | if log is True: 101 | data = np.log1p(data) 102 | 103 | 104 | # embedding 105 | embedding = um.UMAP(n_neighbors=n_neighbors, 106 | n_components=n_components, 107 | metric=metric, 108 | min_dist=min_dist, 109 | random_state=random_state).fit_transform(data) 110 | 111 | # plot 112 | #plt.scatter(embedding[:, 0], embedding[:, 1], s=5) 113 | 114 | # return data 115 | adata.obsm[label] = embedding 116 | return adata 117 | --------------------------------------------------------------------------------