{ "cells": [ { "cell_type": "markdown", "id": "a309d4a5-314d-4937-b8b8-7049534f1409", "metadata": {}, "source": [ "# Image Processing\n", "\n", "Start from this notebook before doing the others in this folder! The other notebooks depend on the directory structure set up in this one." ] }, { "cell_type": "code", "execution_count": 1, "id": "c5402f37-a684-4c1b-8efc-446448b027e3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The PalmettoBUG package is copyrighted 2024-2025 by the Medical University of South Carolina and licensed under the GPL-3 license.\n", "It is free & open source software, can be redistributed in compliance with the GPL3 license, and comes with absolutely no warranty.\n", "In python, use palmettobug.print_license() to see the license, or use palmettobug.print_3rd_party_license_info() to print information\n", "about the licenses and copyright of 3rd party software used in PalmettoBUG itself or in the creation of PalmettoBUG.\n" ] } ], "source": [ "import os\n", "from pathlib import Path\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn.objects as so\n", "import seaborn as sns\n", "\n", "import tifffile as tf\n", "\n", "import palmettobug as pbug" ] }, { "cell_type": "code", "execution_count": 2, "id": "7ed8d69b-0a9c-4b16-b252-7af970cafea7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0.2.11'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pbug.__version__" ] }, { "cell_type": "markdown", "id": "3c480167-7ac3-4374-9406-8b5d28017181", "metadata": {}, "source": [ "### CHANGE The following directory to match an existing directory on your computer if you are testing this tutorial on your own machine!" ] }, { "cell_type": "code", "execution_count": 3, "id": "10bfcaaa-6887-4a24-b3a1-e93d332abd7f", "metadata": {}, "outputs": [], "source": [ "my_computer_path = \"C:/Users/Default/Desktop\" ## CHANGE This DIRECTORY to match an existing directory on your computer if you are testing this tutorial on your own machine!" ] }, { "cell_type": "markdown", "id": "a2751a42-d530-408b-ad0f-90d67ca742ce", "metadata": {}, "source": [ "## Set up a new directory and project\n", "\n", "Here we:\n", "\n", " 1). Set up a fresh directory on our computer that we wll place the project\n", "\n", " 2). fetch the example data from PalmettoBUG into the project directory\n", "\n", " 3). load the directory into a pbug.ImageAnalysis object" ] }, { "cell_type": "code", "execution_count": 4, "id": "a0081295-9de6-45b7-be7b-17f059ad779e", "metadata": {}, "outputs": [], "source": [ "# pbug.fetch_IMC_example(my_computer_path) ## this only needs to be run once\n", " ## Alternatively, you can download and extract the example data directly from Zenodo\n", " ## which is likely faster and more stable! However, if you do download directly\n", " ## from Zenodo, be sure that the directory path you supply in the line below is correct!\n", "project_directory = my_computer_path + \"/Example_IMC\"" ] }, { "cell_type": "code", "execution_count": 5, "id": "b782fb63-d4bc-44ab-8d21-9d8a920c87ec", "metadata": {}, "outputs": [], "source": [ "resolutions = [1.0, 1.0] ## in micrometers. 1 micron is standard IMC resolution\n", "ImageAnalysis = pbug.imc_entrypoint(project_directory, resolutions = resolutions, from_mcds = True) ## The example data is available as .tiff files, because the mcd files are too large to bundle with the program easily." ] }, { "cell_type": "markdown", "id": "f4b55494-1eb5-444a-81b7-43a582323e1e", "metadata": {}, "source": [ "## Next, set up the panel file:" ] }, { "cell_type": "code", "execution_count": 6, "id": "40fa1537-2135-4b79-a7f6-7ef3f7b28286", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | channel | \n", "name | \n", "keep | \n", "segmentation | \n", "
|---|---|---|---|---|
| 0 | \n", "I127 | \n", "127I | \n", "0 | \n", "NaN | \n", "
| 1 | \n", "Xe131 | \n", "131Xe | \n", "0 | \n", "NaN | \n", "
| 2 | \n", "Ba132 | \n", "132Ba | \n", "0 | \n", "NaN | \n", "
| 3 | \n", "Ba138 | \n", "138Ba | \n", "0 | \n", "NaN | \n", "
| 4 | \n", "Pr141 | \n", "aSMA | \n", "1 | \n", "NaN | \n", "
| 5 | \n", "Nd142 | \n", "p-selectin | \n", "1 | \n", "NaN | \n", "
| 6 | \n", "Nd143 | \n", "Vimentin | \n", "1 | \n", "NaN | \n", "
| 7 | \n", "Nd144 | \n", "CD14 | \n", "1 | \n", "NaN | \n", "
| 8 | \n", "Nd145 | \n", "CD31 | \n", "1 | \n", "NaN | \n", "
| 9 | \n", "Nd146 | \n", "CD16 | \n", "1 | \n", "NaN | \n", "
| 10 | \n", "Nd148 | \n", "Pan-Keratin | \n", "1 | \n", "NaN | \n", "
| 11 | \n", "Sm149 | \n", "CD11b | \n", "1 | \n", "NaN | \n", "
| 12 | \n", "Eu151 | \n", "CD163 | \n", "1 | \n", "NaN | \n", "
| 13 | \n", "Sm152 | \n", "CD45 | \n", "1 | \n", "NaN | \n", "
| 14 | \n", "Eu153 | \n", "CD206 | \n", "1 | \n", "NaN | \n", "
| 15 | \n", "Sm154 | \n", "CCL2 | \n", "1 | \n", "NaN | \n", "
| 16 | \n", "Gd155 | \n", "FoxP3 | \n", "1 | \n", "NaN | \n", "
| 17 | \n", "Gd156 | \n", "CD4 | \n", "1 | \n", "NaN | \n", "
| 18 | \n", "Gd158 | \n", "E-cadherin | \n", "1 | \n", "NaN | \n", "
| 19 | \n", "Tb159 | \n", "CD68 | \n", "1 | \n", "NaN | \n", "
| 20 | \n", "Gd160 | \n", "CD66b | \n", "1 | \n", "NaN | \n", "
| 21 | \n", "Dy161 | \n", "CD20 | \n", "1 | \n", "NaN | \n", "
| 22 | \n", "Dy162 | \n", "CD8 | \n", "1 | \n", "NaN | \n", "
| 23 | \n", "Dy163 | \n", "Vitrionectin | \n", "1 | \n", "NaN | \n", "
| 24 | \n", "Dy164 | \n", "CD32b | \n", "1 | \n", "NaN | \n", "
| 25 | \n", "Er167 | \n", "GranzymeB | \n", "1 | \n", "NaN | \n", "
| 26 | \n", "Er168 | \n", "Ki-67 | \n", "1 | \n", "NaN | \n", "
| 27 | \n", "Tm169 | \n", "Collagen-1 | \n", "1 | \n", "NaN | \n", "
| 28 | \n", "Er170 | \n", "CD3 | \n", "1 | \n", "NaN | \n", "
| 29 | \n", "Yb171 | \n", "HistoneH3 | \n", "1 | \n", "1.0 | \n", "
| 30 | \n", "Yb172 | \n", "Beta-Catenin | \n", "1 | \n", "NaN | \n", "
| 31 | \n", "Yb173 | \n", "CD45RO | \n", "1 | \n", "NaN | \n", "
| 32 | \n", "Yb174 | \n", "HLA-DR | \n", "1 | \n", "NaN | \n", "
| 33 | \n", "BCKG190 | \n", "190BCKG | \n", "0 | \n", "NaN | \n", "
| 34 | \n", "Ir191 | \n", "DNA1 | \n", "1 | \n", "1.0 | \n", "
| 35 | \n", "Ir193 | \n", "DNA2 | \n", "1 | \n", "1.0 | \n", "
| 36 | \n", "Pt195 | \n", "Seg1 | \n", "1 | \n", "2.0 | \n", "
| 37 | \n", "Pt196 | \n", "Seg2 | \n", "1 | \n", "2.0 | \n", "
| 38 | \n", "Pt198 | \n", "Seg3 | \n", "1 | \n", "2.0 | \n", "