Is a command-line pipeline for adipocyte detection and analysis from .ndpi digital histological images (DHIs) of adipocyte depots. It performs automated segmentation, quantification, and analysis of adipocytes. It supports subcutaneous (sWAT), perigonadal (pWAT), and inguinal (iWAT) white adipose tissues, producing both numerical data and visual summaries for downstream analysis.
- The
.ndpishould have good quality and high resolution (20ร magnification or above) for good detection of adipocytes - Accepts a single
.ndpifile, a directory of.ndpislides, a CSV list of.ndpipaths, or a comma-separated list on the command line - Generates TIFFs, tissue masks, cropped regions, and adipocyte detection outputs
- Configurable for subcutaneous white adipose tissue (
sWAT) or perigonadal white adipose tissue (pWAT) - Automatic filename sanitization: replaces any non-alphanumeric character with
_, collapses repeats, and trims
- Streamlit-based interface to explore results interactively
- Accepts either:
- Folder path containing outputs, or
- Uploaded
.csv+ image files
- Visualizes histograms, box/violin plots, scatter plots
- Built-in filters for
outlier_scoreandmean_dist - Statistical tests: Welch t-test, MannโWhitney U, KS, ANOVA/LM
- Optional metadata integration (
case_id,Sex,Genotype, or any columns)
- Python>=3.9
- ndpisplit -> move file to
/usr/local/bin - TensorFlow / Keras (required by segmentation models)
AdipoInsights/
โโโ Analyzer/
โ โโโ configs/ # JSON config files
โ โโโ data_extraction/ # Scripts for data extraction
โ โโโ optimize/ # Optimization scripts
โ โโโ segmentation/ # Segmentation model code
โ โโโ training/ # Training scripts and notebooks
โ โโโ utils/ # Utility functions and helpers
โโโ adipo_viewer/ # Streamlit-based interactive platform
โ โโโ app.py # Main application entry point
โ โโโ main_app.py # Page controllers and rendering logic
โ โโโ config.py # Configuration and constants
โ โโโ models.py # Data models and structures
โ โโโ data_loaders.py # Data loading and assembly
โ โโโ visualizations.py # Plotting and chart generation
โ โโโ statistics.py # Statistical tests and analysis
โ โโโ ui_components.py # Reusable UI components
โ โโโ ui_styles.py # UI styling and theming
โ โโโ image_processing.py # Image handling for outlier viz
โ โโโ requirements.txt # Viewer dependencies
โโโ ndpisplit/ # Helpers to split large .ndpi files
โโโ parent_dir/
โ โโโ models/ # Pretrained models (download via Zenodo)
โโโ requirements.txt # Full pipeline dependencies
โโโ script_notebooks/
โ โโโ run_adipocytes_pipeline.sh # Bash wrapper for CLI pipeline
โ โโโ testing_WAT_inf.py # Main Python inference script
โโโ README.md
-
Model directory: Place your pretrained models under models:
adipocytes_IsolationForest.pklskin_tissue_segmentation.ckptwat_tissue_segmentation.ckpt
Model weights download: You can download the pretrained model weights from Zenodo: https://doi.org/10.5281/zenodo.15321697
-
Config files: Update thresholds and parameters in
Analyzer/configs/*.jsonif needed.
Each JSON config (e.g., Analyzer/configs/subcutaneous_wat.json) defines key parameters that you can tweak directly:
tissue_type: Type of WAT to process. Options:"sWAT"or"pWAT".shape_ratio_thresh: Maximum ratio of minor/major axis for cell shape filtering (lower values enforce rounder cells).max_20xsize: Maximum allowed pixel area at 20ร magnification; cells larger than this are ignored.device: Compute device for models. Use"cpu"or e.g."gpu"if you have a GPU, or"mps"for macOS.num_tissues: Number of separate tissue regions to segment per slide.edge_detector: Method for edge detection ("canny","otsu", etc.).cell_segmentation_interval_binary:[min, max]pixel-area range for initial binary segmentation.cell_segmentation_interval_binary_inv:[min, max]range for inverse segmentation mask.min_adipocyte_intensity: Normalized intensity threshold (0โ1) for removal of non-adipocyte structures.outlier_threshold: Isolation forest outlier cutoff for cell outlier removal.
You can edit these values directly in the JSON to customize processing without changing any code.
-
Clone github repository to local:
git clone git@github.com:ExperimentalGenetics/AdipoInsights.git
-
Using conda create a virtual environment
a. Install Miniconda (if required)
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh source miniconda3/etc/profile.d/conda.shb. Create conda environment and install dependencies
conda create --name wat -y python=3.9 conda activate wat pip install -r requirements.txt
First go into the cloned directory:
cd /path/to/AdipoInsightsscript_notebooks/run_adipocytes_pipeline.sh \
/path/to/ndpi_folder \
/path/to/output_dir \
sWAT \
/path/to/parent_dirCreate a CSV (slides.csv) with one column of .ndpi paths:
ndpi_path
/data/A.ndpi
/data/B.ndpiRun:
script_notebooks/run_adipocytes_pipeline.sh /path/to/slides.csv /path/to/output sWAT /path/to/parent_dirscript_notebooks/run_adipocytes_pipeline.sh "A.ndpi,B.ndpi,C.ndpi" /path/to/output_dir sWAT /parent_dirscript_notebooks/run_adipocytes_pipeline.sh /data/slideX.ndpi /path/to/output_dir pWAT /parent_dirFor each slide, the pipeline creates a folder named after the sanitized filename. Inside you will find:
*_fixed.tif,*_resized.tifโ intermediate images*_wat.png,*_wat_post.pngโ tissue masks*_x5_cropped.tif,*_x20_cropped.tifโ cropped ROIs*_wat_cropped.pngโ final mask*_shape_data.npzโ raw adipocyte shape data*_mean.csv,*_all.csvโ aggregated and per-cell features*_x20_wat.jpg,*_cells.jpgโ visualizations
Once your pipeline generates the *_all.csv and *_mean.csv files, you can explore results using the Adipo Viewer โ a comprehensive Streamlit-based analysis platform.
cd adipo_viewer
streamlit run app.pyThis launches the app at http://localhost:8501.
The Adipo Viewer has three main tabs:
Six collapsible sections for comprehensive visualization:
- Group Summary: Adipocyte counts and sample sizes by Sex ร Genotype
- Cell-level Distributions: Box plots of features across groups
- Per-Mouse Analysis: Side-by-side comparisons for males vs. females
- Stratified Histograms: 4-panel view (Mutants/Controls ร Males/Females)
- Mouse-Level Analysis: Scatter plots and box plots with independent feature selectors
- Spatial Heatmaps: Visualize cell property distributions by location
- Histogram of cells per outlier score bin (configurable bins)
- Bin inspection with data tables and image visualization
- Bounding box overlays on example images
Cell-Level Tests: KS test, Cohen's d, t-Test, Two-way ANOVA
Sample-Level Tests: Mann-Whitney, Two-way ANOVA, Cohen's d, Linear Models with covariate adjustment (Age/Bodyweight)
Features: Automatic p-value highlighting, effect size interpretation, descriptive statistics
๐ Data Source: Choose folder path or upload files
๐ Metadata (optional): Upload CSV, specify path, or use inline editor. Supports case_id, Sex, Genotype, Age, Bodyweight with automatic column mapping.
๐ Filters: Outlier score threshold (โฅ) and mean distance threshold (โค)
๐ฏ Sample Selection: Select all or choose specific samples via multi-select dropdown
- Start with Group Summary: Get an overview of your data distribution
- Use Filters: Refine your dataset by adjusting outlier score and mean distance thresholds
- Explore Collapsible Sections: Each section can be expanded/collapsed for focused analysis
- Metadata is Optional: The viewer works without metadata but provides richer analysis with it
- Covariate Analysis: If Age or Bodyweight data is available, ANOVA automatically shows adjusted models
- Independent Plot Controls: In mouse-level analysis, scatter and box plots have separate feature selectors
- Outlier Investigation: Use the Outlier tab to visually inspect cells with specific outlier scores
- Statistical Power: Use cell-level tests for large sample effects, sample-level for biological interpretation
If you use the upload option, clear temporary staged files using "๐๏ธ Clear uploaded files" in the sidebar.
Below are examples of the visualizations available through the Adipo Viewer interface:
| Visualization | Description |
|---|---|
| ๐ Box Plots | Compare per-cell features such as area, perimeter, or solidity between Genotype ร Sex groups with outlier detection. |
| ๐ญ Per-Mouse Analysis | Side-by-side comparison of features across individual mice, split by sex with color-coded genotypes. |
| ๐ Scatter Plots | Explore relationships between sample-level variables with regression lines and confidence intervals. |
| ๐ Histograms | 4-panel stratified view showing distributions across all Sex ร Genotype combinations. |
| ๐บ๏ธ Spatial Heatmaps | Visualize spatial distribution of cell properties using bounding box coordinates. |
| ๐ฌ Outlier Inspection | Interactive bin selection with visual examples showing cell images with bounding box overlays. |
| ๐งฎ Statistical Tests | Comprehensive test suite with automatic p-value highlighting and effect size interpretation. |
| ๐ Covariate Analysis | Adjust for Age and Bodyweight while testing Sex and Genotype effects. |
Below are common issues you might encounter while running AdipoInsights or the Adipo Viewer, along with suggested fixes:
| Issue | Possible Fix |
|---|---|
| "Skin region could not be identified" | Adjust mask thresholds in your configuration JSON file under Analyzer/configs/. |
| Missing dependencies or import errors | Ensure all packages are installed: pip install -r requirements.txt |
openslide-python errors |
Install both openslide-python and the openslide-bin system library. On macOS: brew install openslide. |
| Issue | Possible Fix |
|---|---|
| Streamlit fails to launch | Verify you're in the adipo_viewer directory with the virtual environment active: streamlit run app.py |
| No data after loading | Check that your folder contains valid *_all.csv and *_mean.csv files with correct column headers. |
| Plots not displaying or empty | Ensure selected filters aren't excluding all data. Try resetting filter values to defaults. |
| "Permission denied" errors | Ensure read/write permissions for input/output directories. |
| Images not showing in Outlier tab | Verify image files (*_cells.jpg, *_shape_data.npz) exist in the same directory as CSVs. Check that sample IDs in data match file names. |
| Metadata not matching | Ensure the ID column in metadata matches the sample ID column in your CSV files exactly. Use the column mapping UI to verify. |
| Viewer not updating after upload | Use "Clear uploaded files" in the sidebar to reset cached data, then re-upload. |
| Slow performance | Limit the number of samples or use sample selection. Close unused expander sections. |
| Statistical tests failing | Ensure you have sufficient samples per group (minimum 2-3 per group for most tests). Check that Sex and Genotype columns have valid values. |
| Covariate models not showing | Verify Age or Bodyweight columns contain numeric values and have sufficient variability. |