ai4bio-protein-function-prediction

AI for BiologyDeepProteinrigorous codebase

Description

Task: Protein Sequence Encoder Design for Function Prediction

Research Question

Design a novel protein sequence encoder architecture that learns effective representations for predicting protein function from amino acid sequences. The goal is a general-purpose encoder that transfers well across diverse protein property prediction tasks.

Background

Protein function prediction from sequence is a fundamental problem in computational biology. Given a protein's amino acid sequence (up to ~1000 residues), the model must learn structural and functional patterns to predict properties like enzymatic activity, fluorescence, and solubility.

Current approaches fall into three categories:

  • Sequential models: CNN and RNN-based encoders that treat the sequence as a 1D signal (e.g., convolutional filters over one-hot amino acid encodings).
  • Attention models: Transformer-based encoders that capture long-range residue interactions via self-attention over learned token embeddings.
  • Graph models: GNN-based encoders that construct residue contact graphs and perform message passing (e.g., GCN on k-nearest neighbor sequence graphs).

Key challenges include:

  • Long sequences: Proteins can have hundreds to thousands of residues; efficient encoding of long-range dependencies is critical.
  • Sparse vocabulary: Only 20 standard amino acids, but local context and global structure both matter.
  • Cross-task generalization: The same encoder must work for regression (continuous property values) and classification tasks.

What to Implement

Implement the ProteinEncoder class in custom_protein.py (lines 107-177). You must implement:

  1. __init__(self, vocab_size, onehot_dim, max_seq_len): Initialize your encoder architecture.
  2. forward(self, batch: ProteinBatch) -> Tensor [B, output_dim]: Encode a batch of protein sequences into fixed-size representations.

Your encoder must set self.output_dim (an integer) so the downstream prediction head knows the representation size.

Input Format (ProteinBatch)

class ProteinBatch:
    token_ids: Tensor     # [B, max_len] integer amino acid indices (0=pad, 1-20=amino acids)
    onehot: Tensor        # [B, max_len, 20] one-hot encoded sequences
    mask: Tensor          # [B, max_len] attention mask (1=real residue, 0=padding)
    seq_lengths: Tensor   # [B] actual sequence lengths
    targets: Tensor       # [B] regression/classification targets

You may use any combination of these input formats. The token_ids are suitable for embedding layers, onehot for convolutional or linear layers, and mask for attention-based models.

Amino Acid Vocabulary

20 standard amino acids (ACDEFGHIKLMNPQRSTVWY), index 0 is padding. Maximum sequence length is 1000 (truncated/padded).

Evaluation

The encoder is evaluated on 3 protein property prediction benchmarks from the Therapeutics Data Commons (TDC):

Regression (metric: Spearman correlation, higher is better):

  • Beta-lactamase: Enzyme activity prediction (~4,158 proteins, TAPE benchmark)
  • Fluorescence: GFP fluorescence intensity (~21,446 proteins, TAPE benchmark)

Regression (metric: Spearman correlation, higher is better):

  • Solubility: Protein solubility prediction (~40,174 proteins, TDC benchmark)

All benchmarks use pre-defined train/valid/test splits. The primary metric is Spearman correlation.

Editable Region

Lines 107-177 of custom_protein.py are editable (between EDITABLE SECTION START and EDITABLE SECTION END markers). You may define helper classes, layers, or functions within this region. The region must contain a ProteinEncoder class with the specified interface.

Code

custom_protein.py
EditableRead-only
1"""
2Protein Function Prediction — Self-contained template.
3Predicts protein properties from amino acid sequences:
4 - Beta-lactamase activity (regression, Spearman correlation)
5 - Fluorescence intensity (regression, Spearman correlation)
6 - Solubility (regression, Spearman correlation)
7
8Structure:
9 Lines 1-106: FIXED — Imports, constants, amino acid encoding, data loading
10 Lines 107-220: EDITABLE — ProteinEncoder class (starter: simple MLP)
11 Lines 221+: FIXED — Classifier head, training loop, evaluation
12"""
13import os
14import sys
15import math

Results

ModelTypespearman Beta pearson Beta mse Beta spearman Fluorescence pearson Fluorescence mse Fluorescence spearman Solubility pearson Solubility mse Solubility
cnnbaseline0.6890.7410.0470.6830.9480.0990.4600.4920.194
dgl_gcnbaseline0.2900.3760.1040.6710.8740.2320.5600.5580.175
dgl_gcnbaseline---------
dgl_gcnbaseline---------
dgl_gcnbaseline---------
transformerbaseline0.2060.0940.1040.5540.6191.0880.5280.5270.184
transformerbaseline0.1150.1150.1040.4670.4851.6620.5370.5400.181
transformerbaseline0.2630.2560.1030.5560.6171.0790.5370.5380.188
transformerbaseline0.1680.0920.1030.5380.5931.1200.5300.5300.185
transformerbaseline0.2350.2690.1040.6410.8010.5070.5530.5550.176