Script Overview
ppi_ml_croissant.py is a Python script for training and
evaluating machine learning models on the ELIXIR PPI benchmark
dataset with advanced cross-validation, feature evaluation,
and structural feature extraction from PDB/mmCIF files.
It provides an end-to-end machine learning pipeline for
protein-protein interaction (PPI) classification. It combines:
FAIR Data Loading
Loads Croissant-formatted JSON-LD metadata from local directories or GitHub repositories
Structural Feature Extraction
Extracts interface features from PDB/mmCIF files (residues within 10Å distance)
Advanced ML Pipeline
GroupKFold cross-validation, feature evaluation, and multiple ML models
Key Features:
- Cluster-Aware Validation: GroupKFold CV ensures all interfaces from the same sequence cluster stay together
- Structural Biology Integration: Extracts interface residues within 10Å using BioPython
- Case Sensitivity Handling: Automatically handles uppercase/lowercase PDB file names
- Gzipped File Support: Works directly with .pdb.gz and .cif.gz files (no decompression needed)
- Comprehensive Feature Evaluation: ANOVA, mutual information, PCA, correlation analysis
- Multiple ML Models: Random Forest, SVM, Logistic Regression with hyperparameter tuning
- Visualization Suite: ROC curves, confusion matrices, feature importance plots
Quick Start
Basic Usage
# Basic usage with local dataset
python ppi_ml_croissant.py --local ./bioschemas_output
# With structural feature extraction (mmCIF format)
python ppi_ml_croissant.py --local ./bioschemas_output --extract-pdb-features
# With PDB format
python ppi_ml_croissant.py --local ./bioschemas_output --extract-pdb-features --pdb-format
# Quick mode (reduced output)
python ppi_ml_croissant.py --local ./bioschemas_output --quick
Advanced Usage
# Full pipeline with all features
python ppi_ml_croissant.py \
--local ./bioschemas_output \
--extract-pdb-features \
--pdb-local-dir ./structure_files \
--evaluate-features \
--feature-analysis \
--save-plots \
--output-dir ./ml_results \
--folds 5 \
--random-state 42 \
--log-level INFO
# Download structure files only
python ppi_ml_croissant.py --local ./bioschemas_output --extract-pdb-features --pdb-features-only
# Train/test split instead of CV
python ppi_ml_croissant.py --local ./bioschemas_output --test-split 0.2
Output
Typical Console Output
Generated Files Structure
ml_results/
├── group_kfold_cv_results.json # Complete ML results with all metrics
├── structural_features.csv # Extracted PDB/mmCIF interface features
├── feature_evaluation_report.json # Comprehensive feature analysis
├── group_kfold_cv_results.png # CV performance visualization
├── feature_evaluation_plots.png # Feature analysis visualizations
├── feature_importance.png # Feature importance ranking
└── feature_ranking_analysis.png # Comparison of feature ranking methods
Example JSON Output (group_kfold_cv_results.json)
{
"Random Forest": {
"cv_metrics": {
"accuracy": 0.827,
"precision": 0.831,
"recall": 0.824,
"f1": 0.827,
"roc_auc": 0.898
},
"overall_metrics": {
"accuracy": 0.829,
"precision": 0.833,
"recall": 0.826,
"f1": 0.829,
"roc_auc": 0.901
},
"fold_metrics": {
"accuracies": [0.819, 0.831, 0.825, 0.834, 0.826],
"precisions": [0.822, 0.836, 0.828, 0.839, 0.830],
"recalls": [0.816, 0.830, 0.822, 0.833, 0.825],
"f1_scores": [0.819, 0.833, 0.825, 0.836, 0.827],
"roc_aucs": [0.895, 0.901, 0.897, 0.903, 0.894]
}
},
"cross_validation_settings": {
"n_splits": 5,
"method": "GroupKFold cross-validation (ClusterID as groups)",
"random_state": 42,
"best_model": "Random Forest"
}
}
Visual Output Example
The script generates comprehensive visualizations:
ROC Curves
Model discrimination
Confusion Matrices
Error analysis
Feature Importance
Key predictors
PCA Analysis
Dimensionality reduction
Pipeline Workflow
Load Dataset
Parse Croissant JSON-LD metadata from local files or GitHub
Extract Features
Parse interface properties, labels, and cluster IDs
Structural Features
Extract interface residues within 10Å from PDB/mmCIF
Preprocess
Scale features, handle missing values, encode categories
Train Models
GroupKFold CV with Random Forest, SVM, Logistic Regression
Evaluate
Generate metrics, plots, and feature importance analysis
Command Line Options
| Option | Description | Default |
|---|---|---|
--local |
Path to local directory with dataset_with_interfaces.json | Required (or --github) |
--github |
GitHub repository URL containing dataset | |
--extract-pdb-features |
Extract structural features from PDB/mmCIF files | False |
--pdb-local-dir |
Local directory for interface structure files | ./structure_files |
--pdb-format |
Use PDB format (default: mmCIF) | False |
--pdb-features-only |
Only extract structural features (skip ML) | False |
--folds |
Number of cross-validation folds | 5 |
--test-split |
Fraction for train/test split (0 for CV only) | 0.0 |
--evaluate-features |
Perform comprehensive feature evaluation | False |
--feature-analysis |
Run feature importance analysis | False |
--save-plots |
Save plots to files | False |
--output-dir |
Directory to save results | ./group_kfold_results |
--quick |
Run quick demo with basic output | False |
--log-level |
Logging level (DEBUG, INFO, WARNING, ERROR) | INFO |
Structural Feature Extraction
What it extracts:
- Interface Residues: Unique residues per chain within 10Å of the other chain
- C-alpha Distance: Uses only C-alpha atoms for distance calculations (faster)
- Chain Pair Analysis: Analyzes all possible chain pairs in biological assemblies
- Fraction Metrics: Interface residues as fraction of total chain residues
- Biological Assembly Handling: Automatically generates assemblies from monomer mmCIF files
File Handling Features
# BioPython can parse gzipped files directly - no decompression needed!
- 1abc.pdb.gz → Direct parsing
- 1abc.cif.gz → Direct parsing
- 1abc.pdb → Regular parsing
- 1abc.cif → Regular parsing
# Case sensitivity handling (both work)
- 1ABC.pdb.gz → Uppercase PDB ID
- 1abc.pdb.gz → Lowercase PDB ID
- MixedCase.pdb.gz → Automatic detection
Example Structural Features Output
interface_id,extraction_success,pdb_file,chain_ids,pdb_avg_total_interface_residues,...
1ABC_1,True,1abc.cif.gz,A-B,24.5,...
1DEF_1,True,1def.pdb.gz,C-D,18.2,...
2GHI_1,False,2ghi.cif.gz,E-F,NaN,... # Extraction failed
3JKL_1,True,3jkl.cif.gz,G-H,32.1,...
Machine Learning Models
Random Forest
- Type: Ensemble of decision trees
- Strengths: Handles non-linear relationships, robust to outliers
- Feature Importance: Built-in importance scores
- Parameters: 100 estimators, random_state=42
Support Vector Machine
- Type: Maximum margin classifier
- Strengths: Effective in high-dimensional spaces
- Kernel: RBF (Radial Basis Function)
- Probability: Enabled for ROC curves
Logistic Regression
- Type: Linear classifier
- Strengths: Interpretable, fast training
- Regularization: L2 penalty
- Max Iterations: 1000 for convergence
Typical Performance Metrics (Example Output)
| Model | Accuracy | Precision | Recall | F1-Score | ROC-AUC |
|---|---|---|---|---|---|
| Random Forest | 0.827 | 0.831 | 0.824 | 0.827 | 0.898 |
| Support Vector Machine | 0.812 | 0.818 | 0.807 | 0.812 | 0.885 |
| Logistic Regression | 0.798 | 0.804 | 0.793 | 0.798 | 0.872 |
GroupKFold Cross-Validation
Why GroupKFold for PPI data?
- Prevents Data Leakage: Interfaces from the same sequence cluster are highly similar
- Realistic Evaluation: Simulates predicting interfaces for new protein families
- Cluster-Aware: All interfaces with same ClusterID stay together in same fold
- Stratified: Maintains class distribution across folds
Example Console Output for GroupKFold
INFO: === CREATING GROUPKFOLD CROSS-VALIDATION SPLITS ===
INFO: Number of folds: 5
INFO: Using ClusterID as groups to ensure same-cluster samples stay together
INFO: Split analysis:
INFO: Fold 1:
INFO: Training: 1342 samples, 242 unique clusters, 678 physio (50.5%)
INFO: Testing: 335 samples, 61 unique clusters, 166 physio (49.6%)
INFO: Fold 2:
INFO: Training: 1341 samples, 241 unique clusters, 675 physio (50.3%)
INFO: Testing: 336 samples, 62 unique clusters, 169 physio (50.3%)
INFO: No clusters appear in both train and test sets
Complete Examples
Example 1: Full ML Pipeline with Structural Features
# Run complete ML pipeline with structural features
python ppi_ml_croissant.py \
--local ./bioschemas_output \
--extract-pdb-features \
--pdb-local-dir ./structures \
--pdb-format \
--evaluate-features \
--feature-analysis \
--save-plots \
--output-dir ./full_ml_run \
--folds 5 \
--random-state 123 \
--log-level INFO
# Expected output in ./full_ml_run:
# - group_kfold_cv_results.json # JSON results
# - structural_features.csv # PDB features
# - feature_evaluation_report.json # Feature analysis
# - group_kfold_cv_results.png # Main visualization
# - 3-4 additional plot files # Detailed analyses
Example 2: Quick Test Run
# Quick analysis for testing (minimal output)
python ppi_ml_croissant.py \
--local ./bioschemas_output \
--quick \
--output-dir ./quick_test
# Console output shows:
# - Dataset statistics
# - Best model performance
# - Quick summary metrics
# Generated files are minimal
Example 3: Download Structure Files Only
# Just download structure files without ML
python ppi_ml_croissant.py \
--local ./bioschemas_output \
--extract-pdb-features \
--pdb-features-only \
--pdb-local-dir ./structure_files
# Output shows:
# - Files available locally
# - Files downloaded
# - Files missing
# No ML training performed
Integration with ELIXIR FAIR Metadata
Connection to Main FAIR Metadata
This ML pipeline directly uses the FAIR-compliant metadata generated by the main ELIXIR PPI benchmark repository:
Data Source
Reads dataset_with_interfaces.json from the FAIR metadata output
View metadata structure
Croissant Format
Leverages MLCommons Croissant 1.0 standard for ML readiness
View Croissant compliance
Complete FAIR ML Workflow:
FAIR Metadata → ML Pipeline → Research Insights
Why GroupKFold for PPI data?
- Prevents Data Leakage: Interfaces from the same sequence cluster are highly similar
- Realistic Evaluation: Simulates predicting interfaces for new protein families
- Cluster-Aware: All interfaces with same ClusterID stay together in same fold
- Stratified: Maintains class distribution across folds
Complete Examples
Example 1: Full ML Pipeline with Structural Features
# Run complete ML pipeline with structural features
python ppi_ml_croissant.py \
--local ./bioschemas_output \
--extract-pdb-features \
--pdb-local-dir ./structures \
--pdb-format \
--evaluate-features \
--feature-analysis \
--save-plots \
--output-dir ./full_ml_run \
--folds 5 \
--random-state 123 \
--log-level INFO
# Expected output in ./full_ml_run:
# - group_kfold_cv_results.json # JSON results
# - structural_features.csv # PDB features
# - feature_evaluation_report.json # Feature analysis
# - group_kfold_cv_results.png # Main visualization
# - 3-4 additional plot files # Detailed analyses
Example 2: Quick Test Run
# Quick analysis for testing (minimal output)
python ppi_ml_croissant.py \
--local ./bioschemas_output \
--quick \
--output-dir ./quick_test
# Console output shows:
# - Dataset statistics
# - Best model performance
# - Quick summary metrics
# Generated files are minimal
Example 3: Download Structure Files Only
# Just download structure files without ML
python ppi_ml_croissant.py \
--local ./bioschemas_output \
--extract-pdb-features \
--pdb-features-only \
--pdb-local-dir ./structure_files
# Output shows:
# - Files available locally
# - Files downloaded
# - Files missing
# No ML training performed
Integration with ELIXIR FAIR Metadata
Connection to Main FAIR Metadata
This ML pipeline directly uses the FAIR-compliant metadata generated by the main ELIXIR PPI benchmark repository:
Data Source
Reads dataset_with_interfaces.json from the FAIR metadata output
Croissant Format
Leverages MLCommons Croissant 1.0 standard for ML readiness
View Croissant complianceComplete FAIR ML Workflow: