A comprehensive Python pipeline for analyzing PIEZO1 protein localization and cell edge dynamics using fluorescence microscopy data.
- Quick Start
- What This Pipeline Does
- Installation
- Basic Usage
- Batch Processing
- Configuration
- Individual Steps
- Output Files
- Troubleshooting
- Advanced Features
Organize your data in this structure:
data/
βββ experiment1/
β βββ experiment1_piezo1.tif # PIEZO1 fluorescence images
β βββ experiment1_Mask.tif # Cell mask
βββ experiment2/
β βββ experiment2_piezo1.tif
β βββ experiment2_Mask.tif
βββ experiment3/
βββ experiment3_piezo1.tif
βββ experiment3_Mask.tif
File naming requirements:
- PIEZO1 images: Must contain
piezo1,Piezo1, orPIEZO1in filename - Masks: Must contain
Mask,mask, orMASKin filename
# Process all datasets automatically
python run_all_steps.py --batch# Get summary of all results
python summarize_batch_results.py results/
# Generate combined analysis
python combined_batch_analysis.pyThat's it! Your correlation analysis results are in results/DATASET/step9_results/correlation_statistics.json
The pipeline analyzes the relationship between cell edge movement and PIEZO1 protein localization:
- Loads and preprocesses fluorescence images and cell masks
- Detects cell edges from masks
- Calculates edge displacement between frames
- Classifies movement (extruding/retracting/stable)
- Samples edge points for intensity measurement
- Creates sampling rectangles perpendicular to edge
- Extracts PIEZO1 intensities at edge locations
- Assigns movements to intensity measurements
- Correlates intensity with movement and performs statistical analysis
Output: Correlation coefficient between PIEZO1 intensity and cell edge movement direction.
- Python 3.7+
- Required packages:
pip install numpy scipy matplotlib scikit-image tifffile
pandas- for CSV exportseaborn- for enhanced visualizations
Process all your datasets with one command:
python run_all_steps.py --batchThe script will:
- Automatically find all datasets in
data/folder - Process each through all 9 analysis steps
- Save organized results in
results/folder - Show progress and timing for each step
Process one dataset at a time:
python run_all_steps.py --batch --dataset experiment1Run individual steps for fine control:
python step1_data_loading.py --image-stack-path data/exp1/exp1_piezo1.tif \
--mask-stack-path data/exp1/exp1_Mask.tif
python step2_edge_detection.py --input-dir step1_results
python step3_displacement_calculation.py --input-dir-step1 step1_results \
--input-dir-step2 step2_results
# ... continue through step9# Process all datasets
python run_all_steps.py --batch
# Interactive prompt:
# Found 3 dataset(s):
# 1. experiment1
# 2. experiment2
# 3. experiment3
# Process all 3 datasets? [y/N]: ypython run_all_steps.py --batch \
--data-dir /path/to/your/data \
--results-dir /path/to/results# Test parameters on single dataset
python run_all_steps.py --batch --dataset experiment1
# Review results
cat results/experiment1/step9_results/correlation_statistics.json
# If satisfied, process all
python run_all_steps.py --batchEdit run_all_steps.py to customize analysis parameters:
PIPELINE_CONFIG = {
# Step 1: Preprocessing
'step1': {
'normalize_frames': True, # Normalize intensity
'subtract_background': True, # Remove background (recommended)
'background_percentile': 10, # Background level (0-100)
'normalization_scale': 100.0, # Scaling factor (reference maps to this)
'create_verification_figures': True # Quality control images
},
# Step 2: Edge Detection
'step2': {
'smooth_edges': True, # Smooth noisy edges (recommended)
'smoothing_sigma': 20.0, # Smoothing strength (typical 10-40)
'create_verification_figures': True
},
# Step 4 & 9: Movement Classification
'step4': {
'movement_threshold': 5, # Threshold in pixels
# ...
},
'step9': {
'movement_threshold': 5, # Should match step4
'binning_method': 'equal_count', # Binning approach
'n_bins': 10, # Number of bins
# ...
}
}For typical PIEZO1 imaging:
'step1': {
'subtract_background': True, # Enable
'background_percentile': 10, # Conservative
}
'step2': {
'smooth_edges': True, # Enable
'smoothing_sigma': 5.0, # Moderate
}For high-quality data:
'step1': {'subtract_background': False}
'step2': {'smooth_edges': False}For noisy data:
'step1': {'background_percentile': 15} # More aggressive
'step2': {'smoothing_sigma': 20.0} # Stronger smoothingDisable verification figures for 3-5x faster processing:
'create_verification_figures': False # Set for all stepsEach step can be run independently with command-line arguments:
python step1_data_loading.py \
--image-stack-path data/exp1/exp1_piezo1.tif \
--mask-stack-path data/exp1/exp1_Mask.tif \
--output-dir step1_results \
--subtract-background true \
--background-percentile 10Key parameters:
--subtract-background- Remove background noise (true/false)--background-percentile- Percentile for background (0-100, default: 10)--normalization-scale- Scale normalized values (default: 1.0)
python step2_edge_detection.py \
--input-dir step1_results \
--output-dir step2_results \
--smooth-edges true \
--smoothing-sigma 2.0Key parameters:
--smooth-edges- Apply Gaussian smoothing (true/false)--smoothing-sigma- Smoothing strength (default: 2.0, range: 0.5-50.0)
python step3_displacement_calculation.py \
--input-dir-step1 step1_results \
--input-dir-step2 step2_results \
--output-dir step3_results \
--min-movement-pixels 5Key parameters:
--min-movement-pixels- Minimum displacement threshold (default: 5)
python step4_movement_classification.py \
--input-dir-step1 step1_results \
--input-dir-step2 step2_results \
--input-dir-step3 step3_results \
--output-dir step4_results \
--movement-threshold 5Key parameters:
--movement-threshold- Threshold for extruding vs retracting (default: 5 pixels)
python step5_edge_sampling.py \
--input-dir-step1 step1_results \
--input-dir-step2 step2_results \
--output-dir step5_results \
--sampling-method displacement_like \
--target-points-displacement 20Key parameters:
--sampling-method- Sampling strategy (per_frame/fixed_x/dense/displacement_like)--target-points-displacement- Points per frame for displacement_like (default: 20)--y-selection- Select uppermost or lowermost edge points (uppermost/lowermost)
Continue similarly for remaining steps. Use --help with any script to see all options:
python step6_sampling_rectangles.py --help
python step7_intensity_extraction.py --help
python step8_movement_assignment.py --help
python step9_correlation_analysis.py --helpresults/
βββ experiment1/
βββ step1_results/
β βββ images.npy # Preprocessed images
β βββ masks.npy # Binary masks
β βββ metadata.json # Processing parameters
β βββ verification_figures/ # Quality control images
βββ step2_results/
β βββ edges.pkl # Detected edges
β βββ edge_statistics.json
β βββ verification_figures/
βββ step3_results/
β βββ displacement_data.pkl # Edge displacements
β βββ verification_figures/
βββ step4_results/
β βββ movement_classifications.pkl
β βββ classification_statistics.json
β βββ verification_figures/
βββ step5_results/
β βββ sampled_edges.pkl # Sampling points
β βββ verification_figures/
βββ step6_results/
β βββ sampling_rectangles.pkl
β βββ verification_figures/
βββ step7_results/
β βββ intensity_data.pkl # PIEZO1 intensities
β βββ verification_figures/
βββ step8_results/
β βββ combined_data.pkl # Intensities + movements
β βββ combined_statistics.json
β βββ verification_figures/
βββ step9_results/ β MAIN RESULTS
βββ correlation_statistics.json β Correlation results
βββ binned_statistics.json # Binned analysis
βββ verification_figures/ # Result plots
correlation_statistics.json contains:
{
"correlation_coefficient": 0.456, // Pearson correlation
"p_value": 2.3e-89, // Statistical significance
"r_squared": 0.208, // Coefficient of determination
"total_points": 7336, // Number of data points
"mean_displacement": -0.123, // Average movement
"mean_intensity": 123.45, // Average PIEZO1 intensity
"extruding_count": 3012, // Cells moving outward
"retracting_count": 2567, // Cells moving inward
"stable_count": 1757 // Minimal movement
}# View correlation for all datasets
grep correlation_coefficient results/*/step9_results/correlation_statistics.json
# Get formatted summary
python summarize_batch_results.py results/
# Export to CSV
python summarize_batch_results.py results/ --csv summary.csvProblem: Files don't match expected naming patterns
Solution:
# Check filenames
ls data/your_dataset/
# Rename to match pattern:
mv your_image.tif experiment_piezo1.tif
mv your_mask.tif experiment_Mask.tifProblem: Error during processing
Solution:
# 1. Check verification figures from previous step
ls results/dataset/stepX-1_results/verification_figures/
# 2. Review error message in terminal
# 3. Rerun that step manually with verbose output
python stepX_script.py --input-dir ... --output-dir ...
# 4. Check if preprocessing parameters need adjustmentProblem: Large datasets exhausting RAM
Solution:
# In run_all_steps.py, disable verification figures:
'create_verification_figures': False # For all stepsProblem: Parameters not optimal for your data
Solution:
# 1. Test different preprocessing settings
python run_all_steps.py --batch --dataset test_1
# 2. Check verification figures at each step
ls results/test_1/*/verification_figures/
# 3. Adjust parameters in PIPELINE_CONFIG
# 4. Reprocess and compareProblem: Removing actual signal
Solution:
# Reduce background percentile
'background_percentile': 5 # Instead of 10Problem: Insufficient smoothing
Solution:
# Increase smoothing sigma
'smoothing_sigma': 3.0 # Instead of 2.0Background Subtraction:
- Removes uniform background fluorescence
- Based on histogram percentile
- Applied before normalization
- Recommended for most datasets
Normalization Scaling:
- Scales normalized values to custom range
- Useful for matching specific intensity scales
- Default: [0, 1]
Example:
'step1': {
'subtract_background': True,
'background_percentile': 10,
'normalization_scale': 255 # Scale to 8-bit range
}See the "Normalization Reference & Intensity Statistic" section above, or the in-app Help β Analysis Guide (Step 1 section), for a detailed guide.
Gaussian Edge Smoothing:
- Reduces noise in detected edges
- Smooths frame-to-frame jitter
- Preserves endpoints to prevent artifacts
- Recommended for typical imaging data
Example:
'step2': {
'smooth_edges': True,
'smoothing_sigma': 2.0 # Moderate smoothing
}See the in-app Help β Analysis Guide (Step 2 section) for a detailed guide.
By default each frame is normalized so its single brightest pixel maps to the
scale (e.g. 100), and each sampling rectangle reports its mean intensity. A
lone hot pixel can therefore push typical edge values far down the scale. Several
options let you choose a more robust reference and a different per-rectangle
statistic. Defaults reproduce the original behaviour, and every plot's axis
label states the choice, e.g. PIEZO1 intensity (mean, % of per-frame max).
# Robust, frame-to-frame-consistent normalization (in-mask 99.9th percentile,
# computed once across the whole stack) + brightest-pixel-per-rectangle readout
python step1_data_loading.py ... \
--normalization-method percentile --normalization-percentile 99.9 \
--normalization-region mask --normalization-scope global
python step7_intensity_extraction.py ... --intensity-statistic max| Stage | Option | Values (default first) |
|---|---|---|
| step1 | --normalization-method |
max, percentile |
| step1 | --normalization-percentile |
99.9 |
| step1 | --normalization-region |
frame, mask |
| step1 | --normalization-scope |
per_frame, global |
| step7 | --intensity-statistic |
mean, max, percentile |
| step7 | --intensity-percentile |
95 |
In the GUI these appear under Configure Step β Step 1 (normalization) and
Step 7 (intensity statistic); batch runs read them from PIPELINE_CONFIG.
Analyze all datasets together for higher statistical power:
# After batch processing
python combined_batch_analysis.py
# Results in: combined_analysis/combined_correlation_statistics.jsonThis pools data from all datasets to compute an overall correlation.
If your files use different naming conventions, edit run_all_steps.py:
IMAGE_PATTERNS = ['*_TIRF.tif', '*_GFP.tif']
MASK_PATTERNS = ['*_binary.tif', '*_seg.tif']# Create directory structure
mkdir -p data/experiment1 data/experiment2
# Copy your TIFF files into folders
# (Ensure filenames contain 'piezo1' and 'Mask')# Process one dataset
python run_all_steps.py --batch --dataset experiment1
# Check results
cat results/experiment1/step9_results/correlation_statistics.json
# Review verification figures
ls results/experiment1/*/verification_figures/# Edit run_all_steps.py PIPELINE_CONFIG
# Modify preprocessing or analysis parameters# Run complete batch
python run_all_steps.py --batch# Get summary
python summarize_batch_results.py results/
# Combined analysis
python combined_batch_analysis.py
# Export for further analysis
python summarize_batch_results.py results/ --csv results.csvBuilt with AI assistance from Claude (Anthropic).