DeepPurpose

repository·master·Indexed 22 days ago

https://github.com/kexinhuang12345/deeppurpose

A PyTorch-based deep learning library for molecular modeling. It provides tools for predicting Drug-Target Interaction (DTI), Drug-Drug Interaction (DDI), Protein-Protein Interaction (PPI), protein function, and compound properties. The library features over 15 encodings for drugs and proteins, including CNNs, Transformers, and GNNs, and supports CPU and GPU acceleration.

Tokens
38K
Snippets
118
Records
129
Agent score
77%

What's inside DeepPurpose

  1. Overview of DeepPurpose capabilities

    master

    DeepPurpose is a PyTorch-based deep learning toolkit designed for molecular modeling and prediction. It supports a wide range of life science tasks including:

    • DTI: Drug-Target Interaction prediction (binary) or binding affinity prediction (regression).
    • DDI: Drug-Drug Interaction prediction.
    • PPI: Protein-Protein Interaction prediction.
    • Protein Function Prediction.
    • Compound Property Prediction: Including drug property prediction and virtual screening.

    Key features include over 15 powerful encodings for drugs and proteins (CNN, Transformers, GNNs, etc.) and support for both CPU and GPU (including Multi-GPU) acceleration.

  2. Overview of DeepPurpose features

    master

    DeepPurpose is a PyTorch-based toolkit designed for Deep Learning-based Drug Repurposing and Virtual Screening. It serves two primary user groups:

    1. Non-computational researchers (e.g., wet-lab biochemists): Can obtain drug repurposing/virtual screening results using a single line of code. The output is an ensemble of five pretrained deep learning models.
    2. Computational researchers: Provides a flexible framework to research deep learning methods in this domain. It offers 15+ encodings for drugs and proteins (including CNN, Transformers, and Message Passing Graph Neural Networks) and 50+ combined models. Switching encodings is as simple as changing the encoding names.

    Key Capabilities:

    • Automatic Task Identification: Automatically detects whether to perform drug-target binding affinity (regression) or drug-target interaction prediction (binary classification).
    • Robust Evaluation: Supports 'cold target' and 'cold drug' settings for model evaluation and handles single-target high-throughput sequencing assay data.
    • Extensive Data Support: Includes scripts for loading/downloading/unzipping datasets like BindingDB, DAVIS, KIBA, and COVID-19 targets.
    • Comprehensive Metrics:
      • Binary tasks: ROC-AUC, PR-AUC, F1.
      • Regression tasks: MSE, R-squared, Concordance Index.
    • Hardware Support: Built on PyTorch, supporting CPU, GPU, and Multi-GPU configurations.
  3. Predict Protein-Protein Interactions (PPI)

    master

    Use the DeepPurpose.PPI module to study relations among targets by predicting interactions between protein pairs.

    Workflow:

    1. Load protein-protein pair data using read_file_training_dataset_protein_protein_pairs.
    2. Process data with data_process using a target_encoding (e.g., 'CNN').
    3. Initialize and train the model.
    from DeepPurpose import PPI as models
    from DeepPurpose.utils import *
    from DeepPurpose.dataset import *
    
    # Load protein-protein pair data
    X_targets, X_targets_, y = read_file_training_dataset_protein_protein_pairs("toy_data/ppi.txt")
    
    target_encoding = 'CNN'
    train, val, test = data_process(X_target=X_targets, X_target_=X_targets_, y=y, target_encoding=target_encoding, split_method='random', random_seed=1)
    
    # Initialize and train
    config = generate_config(target_encoding=target_encoding, cls_hidden_dims=[512], train_epoch=20, LR=0.001, batch_size=128)
    model = models.model_initialize(**config)
    model.train(train, val, test)
  4. Perform virtual screening with one line of code

    master

    If you have a specific list of drug SMILES and target sequences, you can perform virtual screening using the oneliner.virtual_screening method to retrieve drug-target pairs with the top predicted binding scores.

    from DeepPurpose import oneliner
    
    # Pass a list of target sequences and a list of drug SMILES
    oneliner.virtual_screening(['MKK...LIDL', ...], ['CC1=C...C4)N', ...])
  5. Predict Drug-Target Interaction (DTI)

    master

    Use the DeepPurpose.DTI module to predict interactions between drugs (represented by SMILES) and targets (represented by Amino Acid sequences). The workflow involves loading data (e.g., via process_BindingDB), processing it with specific encodings (e.g., 'CNN', 'Transformer'), splitting the data, initializing a model with a configuration, and training it.

    Key functions:

    • process_BindingDB(...): Processes BindingDB data.
    • data_process(...): Splits data into train, val, and test sets using methods like cold_protein or random.
    • generate_config(...): Creates a configuration dictionary for model initialization.
    • models.model_initialize(**config): Initializes the neural network.
    • net.train(train, val, test): Trains the model.
    • models.repurpose(...): Performs drug repurposing using a trained or pretrained model.
    • models.virtual_screening(...): Performs virtual screening.
    from DeepPurpose import DTI as models
    from DeepPurpose.utils import *
    from DeepPurpose.dataset import *
    
    SAVE_PATH='./saved_path'
    # ... setup SAVE_PATH ...
    
    # Load and process data
    X_drug, X_target, y = process_BindingDB(download_BindingDB(SAVE_PATH), y='Kd', binary=False, convert_to_log=True)
    
    drug_encoding, target_encoding = 'CNN', 'Transformer'
    train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='cold_protein', frac=[0.7,0.1,0.2])
    
    # Initialize and train
    config = generate_config(drug_encoding, target_encoding, transformer_n_layer_target=8)
    net = models.model_initialize(**config)
    net.train(train, val, test)
  6. Predict Drug Properties

    master

    Use the DeepPurpose.CompoundPred module for drug property prediction tasks, such as high-throughput screening data where only the drug and its activity score are available. This is useful for predicting properties over a large space of drugs.

    Workflow:

    1. Load assay data (e.g., load_AID1706_SARS_CoV_3CL).
    2. Process data using data_process with a chosen drug_encoding (e.g., 'rdkit_2d_normalized').
    3. Generate config and train the model.
    4. Use models.repurpose to predict properties for a new drug library.
    from DeepPurpose import CompoundPred as models
    from DeepPurpose.utils import *
    from DeepPurpose.dataset import *
    
    # Load data
    X_drugs, _, y = load_AID1706_SARS_CoV_3CL()
    
    drug_encoding = 'rdkit_2d_normalized'
    train, val, test = data_process(X_drug=X_drugs, y=y, drug_encoding=drug_encoding, split_method='random', random_seed=1)
    
    # Initialize and train
    config = generate_config(drug_encoding=drug_encoding, cls_hidden_dims=[512], train_epoch=20, LR=0.001, batch_size=128)
    model = models.model_initialize(**config)
    model.train(train, val, test)
    
    # Repurpose
    X_repurpose, drug_name, drug_cid = load_broad_repurposing_hub(SAVE_PATH)
    _ = models.repurpose(X_repurpose, model, drug_name)
  7. Perform Rapid Drug Repurposing with oneliner

    master

    The DeepPurpose.oneliner module provides high-level functions for rapid drug repurposing tasks.

    Scenario 1: Using Pretrained Models Retrieve repurposing drugs for a target using pretrained models (e.g., for SARS-CoV2 3CL Protease).

    from DeepPurpose import oneliner
    from DeepPurpose.dataset import *
    oneliner.repurpose(*load_SARS_CoV2_Protease_3CL(), *load_antiviral_drugs(no_cid = True))

    Scenario 2: Using Customized Training Data Train a model from scratch (or finetune) on new data (e.g., AID1706 Bioassay) and then retrieve repurposing drugs from a library.

    from DeepPurpose import oneliner
    from DeepPurpose.dataset import *
    
    oneliner.repurpose(*load_SARS_CoV_Protease_3CL(), *load_antiviral_drugs(no_cid = True), *load_AID1706_SARS_CoV_3CL(), split='HTS', convert_y = False, frac=[0.8,0.1,0.1], pretrained = False, agg = 'max_effect')

    Parameters for oneliner.repurpose:

    • split: Data splitting method (e.g., 'HTS').
    • convert_y: Whether to convert labels.
    • frac: List defining train/val/test fractions.
    • pretrained: Boolean to use pretrained weights.
    • agg: Aggregation method (e.g., 'max_effect').
    from DeepPurpose import oneliner
    from DeepPurpose.dataset import *
    
    # Example: Repurposing with customized data in one line
    oneliner.repurpose(*load_SARS_CoV_Protease_3CL(), *load_antiviral_drugs(no_cid = True), *load_AID1706_SARS_CoV_3CL(), split='HTS', convert_y = False, frac=[0.8,0.1,0.1], pretrained = False, agg = 'max_effect')
  8. How to include a new encoder in DeepPurpose

    master

    To integrate a new encoder model into the DeepPurpose framework, you must follow a three-step process involving data transformation, model definition, and training script updates.

    1. Data and Parameter Preparation (utils.py and generate_config)

    • Data Transformation: Since different encoders require different input formats (e.g., MPNN requires molecular graphs instead of SMILES), you must define how to transform raw inputs.
      • Define a new function smiles2xxx (for drugs) or target2xxx (for proteins) in utils.py that converts a single SMILES/sequence into the required encoding format.
      • Update encode_drug or encode_protein in utils.py by adding an elif statement that uses your new transformation function on the input dataframe.
      • For on-the-fly transformations, add an elif statement to the relevant data loader (e.g., data_process_loader, data_process_DDI_loader, etc.).
    • Configuration: In generate_config, add an elif statement to include the encoder's specific parameters (e.g., input_dim, model_dim). If the encoder requires new user-specified parameters for model_initialize, add them to the parameter space with default values.

    2. Model Definition (encoders.py)

    Define your encoder model in encoders.py following these requirements:

    • __init__ method: Must accept encoding (either 'drug' or 'protein') and **config (containing the parameters defined in the configuration step).
    • forward method: Must accept one feature matrix as input and return the hidden embedding as output.

    3. Training Script Integration

    Update the training wrappers to recognize your new model. In the __init__ function of the main class in the relevant training script, add an elif statement to instantiate your model based on the definitions in encoders.py.

  9. Predict Protein Function

    master

    Use the DeepPurpose.ProteinPred module to predict protein functions such as GO terms or structural classifications. This is useful for screening biologics.

    Workflow:

    1. Load protein function data using read_file_protein_function.
    2. Process data with data_process using a target_encoding (e.g., 'CNN').
    3. Initialize and train the model.
    from DeepPurpose import ProteinPred as models
    from DeepPurpose.utils import *
    from DeepPurpose.dataset import *
    
    # Load protein function data
    X_targets, y = read_file_protein_function()
    
    target_encoding = 'CNN'
    train, val, test = data_process(X_target=X_targets, y=y, target_encoding=target_encoding, split_method='random', random_seed=1)
    
    # Initialize and train
    config = generate_config(target_encoding=target_encoding, cls_hidden_dims=[512], train_epoch=20, LR=0.001, batch_size=128)
    model = models.model_initialize(**config)
    model.train(train, val, test)