Pipeline for segmenting nuclei and masking corresponding fluorescent signals
This pipeline processes multi-channel 3D TIFF images, performing segmentation, masking, and reporting for nuclei and associated biomarkers. Follow these steps to set up and run the pipeline on your data.
- Environment: Ensure you have
condaormambainstalled. - GPU: A CUDA-capable GPU is required for prediction.
- Data Preparation: Create a copy of your TIFF files in a dedicated working directory to avoid altering source data.
Activate the conda environment:
mamba activate your-env-nameReplace your-env-name with the name of your conda/mamba environment containing necessary dependencies (napari, PyTorch, etc.).
Navigate to the directory containing the segmentation scripts:
cd /path/to/nuclei-segmenterReplace /path/to/nuclei-segmenter with the actual path where you've cloned this repository.
The model weights are too large to host on GitHub so please download the root.tar file from this link.
Then untar the file called root somewhere convenient. You will need them later during the prediction step.
Break multi-channel TIFF stacks into individual channels:
python split_tiff_channels.py --input_dir /path/to/your/working/dirReplace /path/to/your/working/dir with your actual working directory path.
This script creates individual subdirectories for each TIFF, containing separated channel stacks. Once completed, remove original multi-channel TIFF files:
rm /path/to/your/working/dir/*.tifRun predictions using a pretrained model:
python predict.py --device 0 --input_dir /path/to/your/working/dir --channel_id 1 --root_dir /path/to/model/weights/rootParameters:
device: GPU number (e.g., 0)input_dir: Path to your working directorychannel_id: Channel number for nuclei segmentationroot_dir: Where you put the model weightsrootdirectory from Step 0
Ensure the pretrained model file is available or adjust the path accordingly in predict.py.
Post-process predictions to form cohesive 3D nuclei blobs and remove small artifacts:
python post_process.py --input_dir /path/to/your/working/dirCalculate average and summed intensities for nuclei regions within your specified biomarker channel:
python mask_and_report.py --input_dir /path/to/your/working/dir --background_value 101 --channel_id 2Parameters:
input_dir: Path to your working directorybackground_value: Pixel intensity value representing background (adjust as needed)channel_id: Channel number of biomarker for masking and intensity reporting
A mask_report.csv will be created within each image subdirectory.
Combine individual reports into a summarized CSV for the entire experiment:
python aggregate.py --input_dir /path/to/your/working/dirThis produces:
condition_summary.csv: Breakdown by position and experimental conditiontotal_masked_results.csv: Comprehensive data across all images