CoolFace
Apppublic

Chimera418/protein-ssp

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

๐Ÿงฌ Protein Secondary Structure Predictor

A full end-to-end deep learning pipeline for predicting protein secondary structures โ€” ฮฑ-Helix (H), ฮฒ-Sheet (E), and Coil (C) โ€” from raw amino acid sequences. The project uses ProtT5-XL-UniRef50 as a protein language model backbone to produce per-residue embeddings, which are then classified by a custom architecture combining 1D-CNNs, BiLSTMs, and Multi-Head Attention.

![Live App](https://huggingface.co/spaces/Chimera418/protein-ssp) ![Model Artifacts](https://huggingface.co/Chimera418/protein-ssp-artifacts) ![GitHub](https://github.com/Chimera418/protein-ssp)


๐ŸŒŸ Key Features

  • โ€”ProtT5 Backbone: Uses Rostlab/prot_t5_xl_uniref50 โ€” a large protein language model โ€” to generate rich per-residue context-aware embeddings (1024-dim).
  • โ€”Five Prediction Modes: Choose between five different feature engineering pipelines, each with its own trained model.
  • โ€”Custom Architecture: 1D-CNN (local motif detection) โ†’ BiLSTM (sequence context) โ†’ Multi-Head Attention (global dependencies) โ†’ Linear head (3 classes).
  • โ€”Interactive Streamlit UI: Real-time per-residue predictions, colour-coded sequence rendering, confidence charts, composition pie chart, and CSV export.
  • โ€”Decoupled Artifact Storage: Model weights are hosted separately on HF Model Hub and downloaded on-demand at runtime.

๐ŸŽฏ Prediction Modes & Performance

All metrics are evaluated on a held-out test set of proteins not seen during training.

ModeInput DimsQ3 AccuracyMacro F1AUCNotes
Direct102485.03%0.84940.9685Raw ProtT5, no reduction
Pearson-filtered101785.41%0.85300.9683Pearson correlation filter only
PCA Pipeline โ˜…73985.67%0.85630.9692Pearson โ†’ PCA โ€” best performance
Feature Selected V110984.21%0.84130.9617Pearson โ†’ PCA โ†’ ExtraTrees (109 dims)
Feature Selected V21282.30%0.82150.9600Pearson โ†’ PCA โ†’ ExtraTrees top-12
โ˜… PCA Pipeline (739-dim) is the default and recommended mode.

๐Ÿš€ Live Demo

The Streamlit app is live on Hugging Face Spaces:

๐Ÿ‘‰ [Try the Live App Here](https://huggingface.co/spaces/Chimera418/protein-ssp)

How to use it

  1. 1.Open the app. The sidebar lets you select a prediction mode.
  2. 2.Paste any amino acid sequence in single-letter code (e.g. MVLSPADKTNVK...), or click ๐Ÿ“‹ Sample to load a human haemoglobin example.
  3. 3.Click ๐Ÿ”ฎ Predict.
  4. 4.The app will:
  5. 5.Encode your sequence using ProtT5 (~2 min on first run while the model downloads)
  6. 6.Apply the feature pipeline for the selected mode
  7. 7.Run the selected deep learning model
  8. 8.Display a colour-coded annotated sequence, per-residue confidence chart, and composition breakdown
  9. 9.Download results as CSV using the โฌ‡๏ธ Download Predictions button.
Note: On first launch, ProtT5 (~3 GB) downloads automatically from Hugging Face. Model weights (~300 MB) also download from the artifacts repo on first prediction. Subsequent runs use the cached files.

๐Ÿ—๏ธ Storage Architecture

Because the trained models, embeddings, and datasets are too large for a standard Git repository (~30 GB total), the project uses a decoupled two-repository architecture:

ComponentLocation
Application code (app.py, phase_*.py)GitHub โ†’ synced to HF Space
Model weights & pkl artifacts`Chimera418/protein-ssp-artifacts/models/`
Pre-computed embeddings (~26.7 GB)`Chimera418/protein-ssp-artifacts/embeddings/`
Curated dataset CSVs (~1.1 GB)`Chimera418/protein-ssp-artifacts/data/`
Raw RCSB/PISCES source data (~2.2 GB)`Chimera418/protein-ssp-artifacts/raw_data/`

The app's ensure_model_exists() function lazily pulls model files from HF Hub at runtime if they are not already present locally.


๐Ÿ’ป Local Installation

Prerequisites

  • โ€”Python 3.9+
  • โ€”~5 GB free disk space (ProtT5 + model weights)
  • โ€”GPU recommended for fast embedding generation; CPU works but is slow

Steps

1. Clone the repository:

bash
git clone https://github.com/Chimera418/protein-ssp.git
cd protein-ssp

2. Install dependencies:

bash
pip install -r requirements.txt

3. Run the Streamlit app:

bash
streamlit run app.py

The app will open at http://localhost:8501.

First run: ProtT5-XL-UniRef50 (~3 GB) downloads automatically from Hugging Face when you first run a prediction. The five trained model .pt files (~300 MB total) are also pulled on-demand from Chimera418/protein-ssp-artifacts on first prediction per mode, then cached locally under models/.

Optional: Pre-download all model weights

To avoid waiting for downloads during the first prediction, you can pre-fetch all model files using:

python
from huggingface_hub import snapshot_download
snapshot_download(repo_id="Chimera418/protein-ssp-artifacts", allow_patterns="models/*", local_dir=".")

๐Ÿ”ง Run the Full Pipeline Yourself (Train From Scratch)

You are not required to use the pre-trained models or artifacts from the HF Hub. All the phase scripts are included in the repository โ€” you can run the entire pipeline end-to-end on your own machine to generate your own data, embeddings, and trained models from scratch.

Hardware note: Phase 4 (embedding generation for ~9,000 proteins) and Phase 8 (model training) benefit strongly from a GPU. On CPU, Phase 4 alone can take many hours.

Full pipeline execution order

bash
# Phase 1 โ€” Download RCSB PDB sequences and parse raw CSV
python phase_1_raw_sequences.py

# Phase 2 โ€” Deduplicate, filter, and remove redundant sequences via PISCES
python phase_2_data_curate.py

# Phase 3 โ€” Match per-residue SST8/SST3 labels from RCSB to curated sequences
python phase_3_labelled_curated_sequence.py

# Phase 4 โ€” Benchmark 4 protein LLMs, select best (ProtT5), generate full embeddings
# โš ๏ธ Requires significant RAM + GPU. Output: embeddings/Rostlab_prot_t5_xl_uniref50.pkl (~9 GB)
python phase_4_embedding_generation.py

# Phase 5 โ€” Pearson correlation filter: 1024 โ†’ 1017 dims, saves keep_indices.pkl
python phase_5_feature_filtering.py

# Phase 6 โ€” PCA: 1017 โ†’ 739 dims, saves pca_model.pkl
python phase_6_dimensionality_reduction.py

# Phase 7 โ€” ExtraTrees feature selection: 739 โ†’ 109 dims, saves feature_selector_mask.pkl
python phase_7_feature_selection.py

# Phase 7.5 โ€” Second-pass refinement: 109 โ†’ 12 dims, saves feature_selector_mask_v2.pkl
python phase_7_5_feature_refinement.py

# Phase 8 โ€” Train all 5 CNN+BiLSTM+Attention models (one per feature space)
# Output: models/phase_8_best_model_*.pt
python phase_8_deep_learning_model.py

# Phase 9 (optional) โ€” SHAP explainability analysis
python phase_9_explainable_ai.py

After running all phases, your models/, embeddings/, data/, and raw_data/ directories will be fully populated with your own generated artifacts. You can then run the Streamlit app normally:

bash
streamlit run app.py

The app detects locally present model files and skips the HF Hub download entirely.

Using the CLI predictor (no Streamlit)

If you just want predictions from the command line without opening the web UI:

bash
python phase_10_predict.py --sequence "MVLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFD"

protein-ssp/
โ”œโ”€โ”€ app.py                          # Streamlit web application
โ”œโ”€โ”€ requirements.txt                # Python dependencies
โ”‚
โ”œโ”€โ”€ phase_1_raw_sequences.py        # Data collection pipeline
โ”œโ”€โ”€ phase_2_data_curate.py          # Dataset curation & redundancy removal
โ”œโ”€โ”€ phase_3_labelled_curated_sequence.py  # Secondary structure labelling
โ”œโ”€โ”€ phase_4_embedding_generation.py # ProtT5 embedding generation & model benchmarking
โ”œโ”€โ”€ phase_5_feature_filtering.py    # Pearson correlation feature filtering
โ”œโ”€โ”€ phase_6_dimensionality_reduction.py   # PCA dimensionality reduction
โ”œโ”€โ”€ phase_7_feature_selection.py    # ExtraTrees feature importance selection
โ”œโ”€โ”€ phase_7_5_feature_refinement.py # Second-pass top-12 feature refinement
โ”œโ”€โ”€ phase_8_deep_learning_model.py  # CNN + BiLSTM + Attention model training
โ”œโ”€โ”€ phase_9_explainable_ai.py       # SHAP/XAI analysis of model decisions
โ”œโ”€โ”€ phase_10_predict.py             # CLI inference script (no Streamlit)
โ”‚
โ”œโ”€โ”€ models/                         # Trained weights (git-ignored; downloaded from HF Hub)
โ”œโ”€โ”€ embeddings/                     # Pre-computed embeddings (git-ignored; on HF Hub)
โ”œโ”€โ”€ data/                           # Curated CSVs (git-ignored; on HF Hub)
โ””โ”€โ”€ raw_data/                       # Raw RCSB/PISCES downloads (git-ignored; on HF Hub)

๐Ÿ”ฌ Pipeline Description

The project is structured as a sequential 10-phase pipeline:

PhaseScriptWhat it does
1phase_1_raw_sequences.pyDownloads the RCSB PDB ss.txt.gz file and organism index (source.idx), parses all protein sequences, and exports protein_sequences_raw.csv
2phase_2_data_curate.pyCleans the raw dataset by removing duplicates, filtering by length (40โ€“10,000 aa), stripping invalid amino acids, and performing redundancy removal using the PISCES culled list (โ‰ค70% sequence identity)
3phase_3_labelled_curated_sequence.pyParses per-residue 8-class secondary structure labels (SST8) from RCSB, maps them to the curated sequences, and converts them to 3-class labels (SST3: H/E/C) using standard DSSP mapping
4phase_4_embedding_generation.pyBenchmarks four protein language models (ProtT5, ProtBERT, ProtALBERT, DistilProtBERT) on a 100-sequence subset using 5-fold stratified cross-validation, selects the best model (ProtT5), then generates full per-residue embeddings (1024-dim) for all ~9,000 sequences
5phase_5_feature_filtering.pyComputes per-feature Pearson correlation with the secondary structure label, removes near-zero-variance and highly correlated dimensions, reducing 1024 โ†’ 1017 features, and saves keep_indices.pkl
6phase_6_dimensionality_reduction.pyFits a PCA transformation on the Pearson-filtered embeddings, retaining 739 principal components (99% variance explained), and saves pca_model.pkl
7phase_7_feature_selection.pyTrains an ExtraTrees classifier in the PCA space and uses Boruta-style feature importance to select the top 109 discriminative PCA components, saving feature_selector_mask.pkl
7.5phase_7_5_feature_refinement.pyApplies a second hard-capped ExtraTrees pass on the 109-feature space, composing both masks to select the top 12 most informative features, saving feature_selector_mask_v2.pkl
8phase_8_deep_learning_model.pyTrains five separate CNN+BiLSTM+Attention models โ€” one for each of the five feature spaces โ€” with early stopping, saving the best checkpoint per mode as .pt files
9phase_9_explainable_ai.pyGenerates SHAP explainability reports, attention weight visualisations, and per-residue importance scores to interpret model decisions
10phase_10_predict.pyStandalone CLI inference script that accepts a raw sequence and returns per-residue predictions without the Streamlit interface

๐Ÿ› ๏ธ Built With

  • โ€”[PyTorch](https://pytorch.org/) โ€” Deep learning model architecture and training
  • โ€”[Hugging Face Transformers](https://huggingface.co/docs/transformers) โ€” ProtT5-XL-UniRef50 protein language model
  • โ€”[Streamlit](https://streamlit.io/) โ€” Interactive web application
  • โ€”[Scikit-Learn](https://scikit-learn.org/) โ€” PCA, ExtraTrees, cross-validation
  • โ€”[Hugging Face Hub](https://huggingface.co/docs/huggingface_hub) โ€” Artifact storage and on-demand model downloads
  • โ€”[Matplotlib](https://matplotlib.org/) โ€” Confidence and composition visualisations

๐Ÿ“œ License

This project is licensed under the MIT License.