|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import sys\n", |
| 10 | + "\n", |
| 11 | + "sys.path.append(\"..\") # Adds higher directory to python modules path.\n", |
| 12 | + "import os\n", |
| 13 | + "from src import RASPRoutines\n", |
| 14 | + "\n", |
| 15 | + "RASP = RASPRoutines.RASP_Routines()" |
| 16 | + ] |
| 17 | + }, |
| 18 | + { |
| 19 | + "cell_type": "code", |
| 20 | + "execution_count": null, |
| 21 | + "metadata": {}, |
| 22 | + "outputs": [], |
| 23 | + "source": [ |
| 24 | + "\"\"\"This notebook tunes the two new parameters needed for the three-colour\n", |
| 25 | + "(oligomer + cell + bulk stain) pipeline, on a single test image, before\n", |
| 26 | + "running the full folder analysis in Step3_ImageFolderAnalysis.ipynb.\n", |
| 27 | + "\n", |
| 28 | + "Radiality (flatness/integratedGrad) is assumed already calibrated via\n", |
| 29 | + "Step1_RadialityCalibration.ipynb (also copied into this folder).\n", |
| 30 | + "\n", |
| 31 | + "Step A below tunes the bulk-stain threshold: RASP.bulk_threshold (and, if\n", |
| 32 | + "needed, RASP.bulk_sigma1/RASP.bulk_sigma2) controls how the bulk stain\n", |
| 33 | + "channel is thresholded into a binary mask (same difference-of-Gaussians\n", |
| 34 | + "detector already used for cell/large-object masks, just a single threshold).\n", |
| 35 | + "The plot below shows the raw bulk image with the resulting mask as a\n", |
| 36 | + "semi-transparent overlay -- adjust RASP.bulk_threshold and re-run until the\n", |
| 37 | + "mask tracks the bulk-stained regions you expect.\n", |
| 38 | + "\n", |
| 39 | + "These values persist as attributes on RASP, so whatever you set here is\n", |
| 40 | + "picked up automatically by RASP.analyse_images(..., bulk_string=...) in\n", |
| 41 | + "Step3 -- no need to pass them again.\n", |
| 42 | + "\"\"\"\n", |
| 43 | + "\n", |
| 44 | + "RASP.bulk_threshold = 100.0 # tune this\n", |
| 45 | + "# RASP.bulk_sigma1 = 2.0 # rarely needs changing\n", |
| 46 | + "# RASP.bulk_sigma2 = 60.0 # rarely needs changing\n", |
| 47 | + "\n", |
| 48 | + "protein_file = os.path.abspath(\n", |
| 49 | + " r\"../example_images/Example_01_ProteinImage_C1.tif\"\n", |
| 50 | + ") # example file, replace as you wish. Always input as the absolute path of a raw string\n", |
| 51 | + "bulk_file = os.path.abspath(\n", |
| 52 | + " r\"../example_images/Example_01_CellImage_C0.tif\"\n", |
| 53 | + ") # placeholder: this repo doesn't ship a real bulk-stain example image, so\n", |
| 54 | + "# the cell image stands in here purely to demonstrate the overlay plot --\n", |
| 55 | + "# replace with your actual bulk stain channel image.\n", |
| 56 | + "\n", |
| 57 | + "RASP.single_image_analysis(\n", |
| 58 | + " protein_file,\n", |
| 59 | + " thres=0.05,\n", |
| 60 | + " large_thres=250.0,\n", |
| 61 | + " gsigma=1.4,\n", |
| 62 | + " rwave=2.0,\n", |
| 63 | + " image_size=500,\n", |
| 64 | + " save_figure=False,\n", |
| 65 | + " cell_file=None,\n", |
| 66 | + " bulk_file=bulk_file,\n", |
| 67 | + ")" |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "code", |
| 72 | + "execution_count": null, |
| 73 | + "metadata": {}, |
| 74 | + "outputs": [], |
| 75 | + "source": [ |
| 76 | + "\"\"\"Step B: tune the cell-detection parameters, the same way as in the\n", |
| 77 | + "two-colour pipeline (example_twocolour_notebooks/Step2_SingleImageAnalysis.ipynb).\n", |
| 78 | + "\n", |
| 79 | + "RASP.cell_threshold1 / RASP.cell_threshold2 / RASP.cell_sigma1 /\n", |
| 80 | + "RASP.cell_sigma2 control the cell mask detector. The plot below shows the\n", |
| 81 | + "raw cell image with the resulting mask drawn as a contour border -- adjust\n", |
| 82 | + "and re-run until the outline matches the cells you expect.\n", |
| 83 | + "\n", |
| 84 | + "These also persist as attributes on RASP and are picked up automatically by\n", |
| 85 | + "RASP.analyse_images(..., cell_string=..., cell_analysis=True) in Step3.\n", |
| 86 | + "\"\"\"\n", |
| 87 | + "\n", |
| 88 | + "RASP.cell_threshold1 = 200.0 # tune this\n", |
| 89 | + "RASP.cell_threshold2 = 200.0 # tune this\n", |
| 90 | + "# RASP.cell_sigma1 = 2.0 # rarely needs changing\n", |
| 91 | + "# RASP.cell_sigma2 = 40.0 # rarely needs changing\n", |
| 92 | + "\n", |
| 93 | + "protein_file = os.path.abspath(\n", |
| 94 | + " r\"../example_images/Example_01_ProteinImage_C1.tif\"\n", |
| 95 | + ") # example file, replace as you wish. Always input as the absolute path of a raw string\n", |
| 96 | + "cell_file = os.path.abspath(\n", |
| 97 | + " r\"../example_images/Example_01_CellImage_C0.tif\"\n", |
| 98 | + ") # example file, replace as you wish. Always input as the absolute path of a raw string\n", |
| 99 | + "\n", |
| 100 | + "RASP.single_image_analysis(\n", |
| 101 | + " protein_file,\n", |
| 102 | + " thres=0.05,\n", |
| 103 | + " large_thres=250.0,\n", |
| 104 | + " gsigma=1.4,\n", |
| 105 | + " rwave=2.0,\n", |
| 106 | + " image_size=500,\n", |
| 107 | + " save_figure=False,\n", |
| 108 | + " cell_file=cell_file,\n", |
| 109 | + " bulk_file=None,\n", |
| 110 | + ")" |
| 111 | + ] |
| 112 | + } |
| 113 | + ], |
| 114 | + "metadata": { |
| 115 | + "kernelspec": { |
| 116 | + "display_name": "Python 3 (ipykernel)", |
| 117 | + "language": "python", |
| 118 | + "name": "python3" |
| 119 | + }, |
| 120 | + "language_info": { |
| 121 | + "codemirror_mode": { |
| 122 | + "name": "ipython", |
| 123 | + "version": 3 |
| 124 | + }, |
| 125 | + "file_extension": ".py", |
| 126 | + "mimetype": "text/x-python", |
| 127 | + "name": "python", |
| 128 | + "nbconvert_exporter": "python", |
| 129 | + "pygments_lexer": "ipython3", |
| 130 | + "version": "3.12.7" |
| 131 | + } |
| 132 | + }, |
| 133 | + "nbformat": 4, |
| 134 | + "nbformat_minor": 5 |
| 135 | +} |
0 commit comments