Repository

LucaProt

LucaProt: A novel deep learning framework that incorporates protein amino acid sequence and structural information to predict protein function.

Protein Seq Len Range
Average Time

Specs

  • Protein Seq Len RangeAverage Time

README

LucaProt

LucaProt(DeepProtFunc) is an open source project developed by Alibaba and licensed under the Apache License (Version 2.0).

This product contains various third-party components under other open source licenses.
See the NOTICE file for more information.

Notice:
This project provides the Python dependency environment installation file, installation commands, and the running command of the trained LucaProt model for inference or prediction, which can be found in this repository. These models are compatible with Linux, Mac OS, and Windows systems, supporting both CPU and GPU configurations for inference tasks.

TimeLine

  • 2025-05-01
    Add the deployable web application (based on flask, in src/app/)
    Start the service on the server,

    cd LucaProt/src/app  
    # modify the service port in app.py    
    python app.py     

    Then the service can be accessed using the browser on the client: http://${server_ip}:8000

  • 2025-04-17:
    Add the post-processing workflow to classify the viral RdRPs predicted by LucaProt into our 180 supergroups or novel supergroups.
    (Guidance listed in PostProcessingWorkflow.md or PostProcessingWorkflow_zh.mdof this project).

  • 2024-09-01:
    Optimize inference and prediction code to run on GPU with small graphics memory, such as A10.

Introduction

LucaProt: A novel deep learning framework that incorporates protein amino acid sequence and structural information to predict protein function.

1. Model

1) Model Introduction

We developed a new deep learning model, namely, Deep Sequential and Structural Information Fusion Network for Proteins Function Prediction (DeepProtFunc/LucaProt), which takes into account protein sequence and structural information to facilitate the accurate annotation of protein function.

Here, we applied LucaProt to identify viral RdRP.

2) Model Architecture

We treat protein function prediction as a classification problem. For example, viral RdRP identification is a binary-class classification task, and protein general function annotation is a multi-label classification task. The model includes five modules: Input, Tokenizer, Encoder, Pooling, and Output. Its architecture is shown in Figure 1.

Figure 1 The Architecture of LucaProt

3) Model Input/Output

Use the amino acid letter sequence as the input of our model. The model outputs the function label of the input protein, which is a single tag (binary-class classification or multi-class classification) or a set of tags (multi-label classification).

2. Dependence

System: Ubuntu 20.04.5 LTS
Python: 3.9.13
Download anaconda: anaconda
Cuda: cuda11.7 (torch==1.13.1)

# Select 'YES' during installation for initializing the conda environment  
sh Anaconda3-2022.10-Linux-x86_64.sh  
# Source the environment
source ~/.bashrc  
# Verification
conda  
# Install env and python 3.9.13   
conda create -n lucaprot python=3.9.13    
# activate env
conda activate lucaprot  
# Install git      
sudo apt-get update         
sudo apt install git-all

# Enter the project   
cd LucaProt     

# Install
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple        

3. Inference

You can simply use this project to infer or predict for unknown sequences.

1) Prediction from one sequence

cd LucaProt/src/prediction/ 
sh run_predict_one_sample.sh

Note: the embedding matrix of the sample is real-time predictive.

Or:

cd LucaProt/src/

# using GPU(cuda=0)    
export CUDA_VISIBLE_DEVICES="0,1,2,3"
python predict_one_sample.py \
    --protein_id protein_1 \
    --sequence MTTSTAFTGKTLMITGGTGSFGNTVLKHFVHTDLAEIRIFSRDEKKQDDMRHRLQEKSPELADKVRFFIGDVRNLQSVRDAMHGVDYIFHAAALKQVPSCEFFPMEAVRTNVLGTDNVLHAAIDEGVDRVVCLSTDKAAYPINAMGKSKAMMESIIYANARNGAGRTTICCTRYGNVMCSRGSVIPLFIDRIRKGEPLTVTDPNMTRFLMNLDEAVDLVQFAFEHANPGDLFIQKAPASTIGDLAEAVQEVFGRVGTQVIGTRHGEKLYETLMTCEERLRAEDMGDYFRVACDSRDLNYDKFVVNGEVTTMADEAYTSHNTSRLDVAGTVEKIKTAEYVQLALEGREYEAVQ \
    --emb_dir ./emb/ \
    --truncation_seq_length 4096 \
    --dataset_name rdrp_40_extend \
    --dataset_type protein \
    --task_type binary_class \
    --model_type sefn \
    --time_str 20230201140320 \
    --step 100000 \
    --threshold 0.5 \
    --gpu_id 0

# using CPU(gpu_id=-1)    
python predict_one_sample.py \
    --protein_id protein_1 \
    --sequence MTTSTAFTGKTLMITGGTGSFGNTVLKHFVHTDLAEIRIFSRDEKKQDDMRHRLQEKSPELADKVRFFIGDVRNLQSVRDAMHGVDYIFHAAALKQVPSCEFFPMEAVRTNVLGTDNVLHAAIDEGVDRVVCLSTDKAAYPINAMGKSKAMMESIIYANARNGAGRTTICCTRYGNVMCSRGSVIPLFIDRIRKGEPLTVTDPNMTRFLMNLDEAVDLVQFAFEHANPGDLFIQKAPASTIGDLAEAVQEVFGRVGTQVIGTRHGEKLYETLMTCEERLRAEDMGDYFRVACDSRDLNYDKFVVNGEVTTMADEAYTSHNTSRLDVAGTVEKIKTAEYVQLALEGREYEAVQ \
    --emb_dir ./emb/ \
    --truncation_seq_length 4096 \
    --dataset_name rdrp_40_extend \
    --dataset_type protein \
    --task_type binary_class \
    --model_type sefn \
    --time_str 20230201140320 \
    --step 100000 \
    --threshold 0.5 \
    --gpu_id -1
  • --protein_id
    str, the protein id.

  • --sequence
    str, the protein sequence.

  • --truncation_seq_length
    int, truncate sequences longer than the given value. Recommended values: 4096, 2048, 1984, 1792, 1534, 1280, 1152, 1024, default: 4096.

  • --emb_dir(optional)
    path, the saved dirpath of the protein predicted embedding matrix or vector during prediction, optional.

  • --dataset_name
    str, the dataset name for building of our trained model(rdrp_40_extend).

  • --dataset_type
    str, the dataset type for building of our trained model(protein).

  • --task_type
    str, the task type for building of our trained model(binary_class).

  • --model_type
    str, the model name for building of our trained model(sefn).

  • --time_str
    str, the running time string(yyyymmddHimiss) for building of our trained model(20230201140320).

  • --step
    int, the training global step of model finalization(100000).

  • --threshold
    float, sigmoid threshold for binary-class or multi-label classification, None for multi-class classification, default: 0.5.

  • --gpu_id:
    int, the gpu id to use(-1 for cpu).

  • --torch_hub_dir(optional):
    str, the torch hub dir path for saving pretrained model(default: ~/.cache/torch/hub/)

2) Prediction from many sequences

the samples are in *.fasta, sample by sample prediction.

  • --fasta_file
    str, the samples fasta file.

  • --save_file
    str, file path, save the predicted results into the file.

  • --print_per_number
    int, print progress information for every number of samples completed, default: 100.

cd LucaProt/src/prediction/   
sh run_predict_many_samples.sh

Or:

cd LucaProt/src/

# using GPU(cuda=0)   
export CUDA_VISIBLE_DEVICES="0,1,2,3"  
python predict_many_samples.py \
    --fasta_file ../data/rdrp/test/test.fasta  \
    --save_file ../result/rdrp/test/test_result.csv  \
    --emb_dir ../emb/   \
    --truncation_seq_length 4096  \
    --dataset_name rdrp_40_extend  \
    --dataset_type protein     \
    --task_type binary_class     \
    --model_type sefn     \
    --time_str 20230201140320   \
    --step 100000  \
    --threshold 0.5 \
    --print_per_number 10 \
    --gpu_id 0


# using CPU(gpu_id=-1)               
python predict_many_samples.py \
    --fasta_file ../data/rdrp/test/test.fasta  \
    --save_file ../result/rdrp/test/test_result.csv  \
    --emb_dir ../emb/   \
    --truncation_seq_length 4096  \
    --dataset_name rdrp_40_extend  \
    --dataset_type protein     \
    --task_type binary_class     \
    --model_type sefn     \
    --time_str 20230201140320   \
    --step 100000  \
    --threshold 0.5 \
    --print_per_number 10 \
    --gpu_id -1

3) Prediction from the file(embedding file exists in advance)

The test data (small and real) is in demo.csv, where the 7th column of each line is the filename of the structural embedding information prepared in advance.
And the structural embedding files store in embs.

The test data includes 50 viral-RdRPs and 50 non-viral RdRPs.

cd LucaProt/src/prediction/   
sh run_predict_from_file.sh

Or:

cd LucaProt/src/

# using GPU(cuda=0)   
export CUDA_VISIBLE_DEVICES="0,1,2,3"
python predict.py \
    --data_path ../data/rdrp/demo/demo.csv \
    --emb_dir ../data/rdrp/demo/embs/esm2_t36_3B_UR50D \
    --dataset_name rdrp_40_extend \
    --dataset_type protein \
    --task_type binary_class \
    --model_type sefn \
    --time_str 20230201140320 \
    --step 100000 \
    --evaluate \
    --threshold 0.5 \
    --batch_size 16 \
    --print_per_batch 100 \
    --gpu_id 0 

# using CPU(gpu_id=-1)          
python predict.py \
    --data_path ../data/rdrp/demo/demo.csv \
    --emb_dir ../data/rdrp/demo/embs/esm2_t36_3B_UR50D \
    --dataset_name rdrp_40_extend \
    --dataset_type protein \
    --task_type binary_class \
    --model_type sefn \
    --time_str 20230201140320 \
    --step 100000 \
    --evaluate \
    --threshold 0.5 \
    --batch_size 16 \
    --print_per_batch 100 \
    --gpu_id -1
  • --data_path
    path, the file path of prediction data, including 9 columns mentioned above. The value of Column Label can be null.

  • --emb_dir
    path, the saved dirpath of all sample's structural embedding information prepared in advance.

  • --dataset_name
    str, the dataset name for building of our trained model(rdrp_40_extend).

  • --dataset_type
    str, the dataset type for building of our trained model(protein).

  • --task_type
    str, the task name for building of our trained model(binary_class).

  • --model_type
    str, the model name for building of our trained model(sefn).

  • --time_str
    str, the running time string(yyyymmddHimiss) for building of our trained model(20230201140320).

  • --step
    int, the training global step of model finalization(100000).

  • --threshold
    float, sigmoid threshold for binary-class or multi-label classification, None for multi-class classification, default: 0.5.

  • --evaluate(optional)
    store_true, whether to evaluate the predicted results.

  • --ground_truth_col_index(optional)
    int, the ground truth col index of the ${data_path}, default: None.

  • --batch size
    int, batch size per GPU/CPU for evaluation, default: 16.

  • --print_per_batch
    int, how many batches are completed every time for printing progress information, default: 1000.

  • --gpu_id:
    int, the gpu id to use(-1 for cpu).

  • --torch_hub_dir(optional):
    str, the torch hub dir path for saving pretrained model(default: ~/.cache/torch/hub/)

Note: the embedding matrices of all the proteins in this file need to prepare in advance($emb_dir).

4. 11 independent validation datasets

11 verification datasets unrelated to the model building dataset, include 7 exists viral-RdRP datasets and 4 exists non viral-RdRP datasets.
Run the prediction python script https://github.com/alibaba/LucaProt/src/predict_many_samples.py
The performance on these 11 independent verification datasets of LucaProt.
LucaProt-Performance-On-11-Independent-Datasets.xlsx
or LucaProt Figshare

5. LucaProt App

This project is used to predict unlabeled protein sequences and to measure the time spent.
LucaProtApp or LucaProt Figshare

6. Inference Time

LucaProt is suitably speedy because it only needs to predict the structural representation matrix rather than the complete 3D structure of the protein sequence.

Benchmark: For each sequence length range(total 10 groups), selected 50 viral-RdRPS and 50 non-viral RdRPs for each group for inference time cost calculation.
inference_time_data_of_github.csv
or LucaProt Figshare

Note: The spend time includes the time of the structural representation matrix inference, excludes the time of model loading.

1) GPU(Nvidia A100, Cuda: 11.7)

Notice: when the sequence length does not exceed 1024, you can use the 24GB GPU for inference, such as the A10.

Protein Seq Len Range Average Time Maximum Time Minimum Time
300