### Setup Conda Environment Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/source/notes/download.md Create the virtual environment from the provided YAML file and manage activation. ```bash $ conda env create -f environment.yml $ ## Build virtual environment with all packages installed using conda $ $ conda activate DeepPurpose $ ## Activate conda environment $ $ $ conda deactivate ### exit ``` -------------------------------- ### Protein-Protein Interaction Framework Initialization Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/README.md Initial setup for the PPI module. ```python from DeepPurpose import PPI as models from DeepPurpose.utils import * from DeepPurpose.dataset import * ``` -------------------------------- ### Install via pip Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/README.md Commands to create a conda environment and install DeepPurpose using pip. ```bash conda create -n DeepPurpose python=3.6 conda activate DeepPurpose conda install -c conda-forge notebook pip install git+https://github.com/bp-kelley/descriptastorus pip install DeepPurpose ``` -------------------------------- ### Create Conda Environment (First Time) Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/_sources/notes/download.rst.txt Build the virtual environment with all necessary packages using the provided env.yml file. This is a one-time setup. ```bash $ conda env create -f env.yml $ ## Build virtual environment with all packages installed using conda $ $ conda activate DeepPurpose $ ## Activate conda environment $ $ $ conda deactivate ### exit ``` -------------------------------- ### Create Conda Environment Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/notes/download.html Build the virtual environment with all necessary packages using the provided env.yml file. This is for first-time setup. ```bash $ conda env create -f env.yml $ ## Build virtual environment with all packages installed using conda ``` -------------------------------- ### Data Preparation and Training Start Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Drug_Property_Prediction_Bacterial_Activity.ipynb Indicates the commencement of data preparation and the initiation of the model training process. ```text --- Data Preparation --- --- Go for Training --- ``` -------------------------------- ### Build Drug Target Interaction Model from Scratch Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/notes/casestudy.html A framework for researchers to build drug-target interaction models from scratch. This example demonstrates loading and processing data, defining model architecture, training, and repurposing/virtual screening. ```python from DeepPurpose import models from DeepPurpose.utils import * from DeepPurpose.dataset import * # Load Data, an array of SMILES for drug, # an array of Amino Acid Sequence for Target # and an array of binding values/0-1 label. # e.g. ['Cc1ccc(CNS(=O)(=O)c2ccc(s2)S(N)(=O)=O)cc1', ...], # ['MSHHWGYGKHNGPEHWHKDFPIAKGERQSPVDIDTH...', ...], # [0.46, 0.49, ...] # In this example, BindingDB with Kd binding score is used. X_drug, X_target, y = process_BindingDB(download_BindingDB(SAVE_PATH), y = 'Kd', binary = False, convert_to_log = True) # Type in the encoding names for drug/protein. drug_encoding, target_encoding = 'MPNN', 'Transformer' # Data processing, here we select cold protein split setup. 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]) # Generate new model using default parameters; # also allow model tuning via input parameters. config = generate_config(drug_encoding, target_encoding, \ transformer_n_layer_target = 8) net = models.model_initialize(**config) # Train the new model. # Detailed output including a tidy table storing # validation loss, metrics, AUC curves figures and etc. # are stored in the ./result folder. net.train(train, val, test) # or simply load pretrained model from a model directory path # or reproduced model name such as DeepDTA net = models.model_pretrained(MODEL_PATH_DIR or MODEL_NAME) # Repurpose using the trained model or pre-trained model # In this example, loading repurposing dataset using # Broad Repurposing Hub and SARS-CoV 3CL Protease Target. X_repurpose, drug_name, drug_cid = load_broad_repurposing_hub(SAVE_PATH) target, target_name = load_SARS_CoV_Protease_3CL() _ = models.repurpose(X_repurpose, target, net, drug_name, target_name) # Virtual screening using the trained model or pre-trained model X_repurpose, drug_name, target, target_name = \ ['CCCCCCCOc1cccc(c1)C([O-])=O', ...], ['16007391', ...], \ ['MLARRKPVLPALTINPTIAEGPSPTSEGASEANLVDLQKKLEEL...', ...],\ ['P36896', 'P00374'] _ = models.virtual_screening(X_repurpose, target, net, drug_name, target_name) ``` -------------------------------- ### MPNN Model Setup with Data Loading and Balancing Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Drug_Property_Prediction_Bacterial_Activity.ipynb Python function to set up and run a Message Passing Neural Network (MPNN) model. It loads training, development, and testing data from CSV files and includes an option for oversampling the training data if it's imbalanced. ```python def run_MPNN(fold_n, balanced): train = pd.read_csv('./aicures_data/train_cv/fold_'+str(fold_n)+'/train.csv') dev = pd.read_csv('./aicures_data/train_cv/fold_'+str(fold_n)+'/dev.csv') test = pd.read_csv('./aicures_data/train_cv/fold_'+str(fold_n)+'/test.csv') if balanced: # oversample balanced training train = pd.concat([train[train.activity == 1].sample(n = len(train[train.activity == 0]), replace=True), train[train.activity == 0]]).sample(frac = 1).reset_index(drop = True) X_train = train.smiles.values y_train = train.activity.values X_dev = dev.smiles.values y_dev = dev.activity.values X_test = test.smiles.values y_test = test.activity.values drug_encoding = 'MPNN' train = data_process(X_drug = X_train, y = y_train, ``` -------------------------------- ### Model Training Console Output Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_KIBA.ipynb Example of the log output generated during the model training process, showing loss metrics and validation results per epoch. ```text in total: 118254 drug-target pairs encoding drug... unique drugs: 2068 drug encoding finished... encoding protein... unique target sequence: 229 protein encoding finished... splitting dataset... Done. Let's use 1 GPU! --- Data Preparation --- --- Go for Training --- Training at Epoch 1 iteration 0 with loss 137.375. Total time 0.00055 hours Training at Epoch 1 iteration 100 with loss 0.73625. Total time 0.01361 hours Training at Epoch 1 iteration 200 with loss 0.77524. Total time 0.02611 hours Training at Epoch 1 iteration 300 with loss 0.53874. Total time 0.03861 hours Validation at Epoch 1 , MSE: 0.43557 , Pearson Correlation: 0.62300 with p-value: 0.0 , Concordance Index: 0.72845 Training at Epoch 2 iteration 0 with loss 0.62621. Total time 0.0475 hours Training at Epoch 2 iteration 100 with loss 0.53729. Total time 0.06055 hours Training at Epoch 2 iteration 200 with loss 0.53652. Total time 0.07305 hours Training at Epoch 2 iteration 300 with loss 0.62497. Total time 0.08527 hours Validation at Epoch 2 , MSE: 0.39649 , Pearson Correlation: 0.67185 with p-value: 0.0 , Concordance Index: 0.76154 Training at Epoch 3 iteration 0 with loss 0.53607. Total time 0.09416 hours Training at Epoch 3 iteration 100 with loss 0.63429. Total time 0.10666 hours Training at Epoch 3 iteration 200 with loss 0.55238. Total time 0.11888 hours Training at Epoch 3 iteration 300 with loss 0.71161. Total time 0.13138 hours Validation at Epoch 3 , MSE: 0.39586 , Pearson Correlation: 0.68508 with p-value: 0.0 , Concordance Index: 0.77513 Training at Epoch 4 iteration 0 with loss 0.46794. Total time 0.14027 hours Training at Epoch 4 iteration 100 with loss 0.70592. Total time 0.15277 hours Training at Epoch 4 iteration 200 with loss 0.48416. Total time 0.16527 hours Training at Epoch 4 iteration 300 with loss 0.49529. Total time 0.17777 hours Validation at Epoch 4 , MSE: 0.45934 , Pearson Correlation: 0.69426 with p-value: 0.0 , Concordance Index: 0.77600 Training at Epoch 5 iteration 0 with loss 0.68272. Total time 0.18666 hours Training at Epoch 5 iteration 100 with loss 0.55647. Total time 0.19916 hours Training at Epoch 5 iteration 200 with loss 0.45495. Total time 0.21138 hours Training at Epoch 5 iteration 300 with loss 0.66338. Total time 0.22361 hours Validation at Epoch 5 , MSE: 0.41195 , Pearson Correlation: 0.69573 with p-value: 0.0 , Concordance Index: 0.77669 Training at Epoch 6 iteration 0 with loss 0.60721. Total time 0.2325 hours Training at Epoch 6 iteration 100 with loss 0.49610. Total time 0.245 hours Training at Epoch 6 iteration 200 with loss 0.61494. Total time 0.2575 hours Training at Epoch 6 iteration 300 with loss 0.46168. Total time 0.26972 hours Validation at Epoch 6 , MSE: 0.37019 , Pearson Correlation: 0.69362 with p-value: 0.0 , Concordance Index: 0.77476 Training at Epoch 7 iteration 0 with loss 0.46543. Total time 0.27861 hours Training at Epoch 7 iteration 100 with loss 0.57097. Total time 0.29111 hours Training at Epoch 7 iteration 200 with loss 0.50702. Total time 0.30361 hours Training at Epoch 7 iteration 300 with loss 0.80186. Total time 0.31583 hours Validation at Epoch 7 , MSE: 0.43107 , Pearson Correlation: 0.69451 with p-value: 0.0 , Concordance Index: 0.77930 Training at Epoch 8 iteration 0 with loss 0.44603. Total time 0.32472 hours Training at Epoch 8 iteration 100 with loss 0.69652. Total time 0.33722 hours Training at Epoch 8 iteration 200 with loss 0.62096. Total time 0.34944 hours Training at Epoch 8 iteration 300 with loss 0.57744. Total time 0.36166 hours Validation at Epoch 8 , MSE: 0.65092 , Pearson Correlation: 0.69387 with p-value: 0.0 , Concordance Index: 0.77813 Training at Epoch 9 iteration 0 with loss 0.77665. Total time 0.37083 hours Training at Epoch 9 iteration 100 with loss 0.52356. Total time 0.38333 hours Training at Epoch 9 iteration 200 with loss 0.40369. Total time 0.39555 hours Training at Epoch 9 iteration 300 with loss 0.72641. Total time 0.40777 hours Validation at Epoch 9 , MSE: 0.42831 , Pearson Correlation: 0.69911 with p-value: 0.0 , Concordance Index: 0.77864 Training at Epoch 10 iteration 0 with loss 0.68815. Total time 0.41638 hours Training at Epoch 10 iteration 100 with loss 0.57422. Total time 0.42916 hours Training at Epoch 10 iteration 200 with loss 0.42554. Total time 0.44138 hours ``` -------------------------------- ### Clone DeepPurpose Repository Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/_sources/notes/download.rst.txt Use this command to download the DeepPurpose code from GitHub. Ensure you have Git installed. ```bash $ git clone git@github.com:kexinhuang12345/DeepPurpose.git $ ### Download code repository $ $ $ cd DeepPurpose $ ### Change directory to DeepPurpose ``` -------------------------------- ### Import DeepPurpose Core Modules Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/MPNN_CNN_Davis.ipynb Import essential modules for DeepPurpose's DTI modeling, utility functions, and dataset handling. Ensure DeepPurpose is installed in your environment. ```python import DeepPurpose.DTI as models from DeepPurpose.utils import * from DeepPurpose.dataset import * ``` -------------------------------- ### Drug Target Interaction Prediction Example Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/README.md Basic setup for loading data and defining encodings for a DTI prediction task. ```python from DeepPurpose import DTI as models from DeepPurpose.utils import * from DeepPurpose.dataset import * SAVE_PATH='./saved_path' import os if not os.path.exists(SAVE_PATH): os.makedirs(SAVE_PATH) # Load Data, an array of SMILES for drug, an array of Amino Acid Sequence for Target and an array of binding values/0-1 label. # e.g. ['Cc1ccc(CNS(=O)(=O)c2ccc(s2)S(N)(=O)=O)cc1', ...], ['MSHHWGYGKHNGPEHWHKDFPIAKGERQSPVDIDTH...', ...], [0.46, 0.49, ...] # In this example, BindingDB with Kd binding score is used. X_drug, X_target, y = process_BindingDB(download_BindingDB(SAVE_PATH), y = 'Kd', binary = False, convert_to_log = True) # Type in the encoding names for drug/protein. drug_encoding, target_encoding = 'CNN', 'Transformer' ``` -------------------------------- ### Build from Source Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/README.md Commands to clone the repository, set up the environment, and run the project locally. ```bash git clone https://github.com/kexinhuang12345/DeepPurpose.git ## Download code repository cd DeepPurpose ## Change directory to DeepPurpose conda env create -f environment.yml ## Build virtual environment with all packages installed using conda conda activate DeepPurpose ## Activate conda environment (use "source activate DeepPurpose" for anaconda 4.4 or earlier) jupyter notebook ## open the jupyter notebook with the conda env ## run our code, e.g. click a file in the DEMO folder ... ... conda deactivate ## when done, exit conda environment ``` ```bash cd DeepPurpose ## Change directory to DeepPurpose conda activate DeepPurpose ## Activate conda environment jupyter notebook ## open the jupyter notebook with the conda env ## run our code, e.g. click a file in the DEMO folder ... ... conda deactivate ## when done, exit conda environment ``` -------------------------------- ### Activate Conda Environment Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/notes/download.html Activate the DeepPurpose conda environment to use its installed packages. This command is used for both initial setup and subsequent usage. ```bash $ conda activate DeepPurpose $ ## Activate conda environment ``` -------------------------------- ### Initialize DeepPurpose Environment Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Make-DAVIS-Correlation-Figure.ipynb Sets up the working directory and imports necessary libraries for dataset handling. ```python import os os.chdir('../') from DeepPurpose import dataset import numpy as np import pandas as pd ``` -------------------------------- ### Enable Sphinx navigation Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/notes/oneliner_folder/virtual_screening.html Initializes the Sphinx documentation navigation theme. ```javascript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### Get Repurposing Drug Count Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/oneliner_repurpose_customized_training_3CLpro_Reproduce_Result.ipynb Calculates and displays the number of drugs available for repurposing. ```python len(X_repurpose) ``` -------------------------------- ### Run Optimization Trials Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Drug_Property_Pred-Ax-Hyperparam-Tune.ipynb Executes Sobol initialization followed by Gaussian Process with Expected Improvement (GP+EI) optimization trials. ```python sobol = modelbridge.get_sobol(search_space=exp.search_space) print(f"\nRunning Sobol initialization trials...\n{'='*40}\n") for _ in range(init_trials): exp.new_trial(generator_run=sobol.gen(1)) for i in range(opt_trials): print(f"\nRunning GP+EI optimization trial {i+1}/{opt_trials}...\n{'='*40}\n") gpei = modelbridge.get_GPEI(experiment=exp, data=exp.eval()) exp.new_trial(generator_run=gpei.gen(1)) ``` -------------------------------- ### Get Training Drug Count Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/oneliner_repurpose_customized_training_3CLpro_Reproduce_Result.ipynb Calculates and displays the number of training drug samples loaded. ```python len(train_drug) ``` -------------------------------- ### Process Data and Initialize Model for Training Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_KIBA.ipynb Prepare datasets using specified encoding methods and split them into training, validation, and testing sets. Configure and initialize the model with specified hyperparameters and begin the training process. ```python drug_encoding = 'Morgan' target_encoding = 'AAC' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2], random_seed = 1) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256 ) model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Process Data and Initialize Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_DAVIS.ipynb Prepare data by splitting it into training, validation, and testing sets using specified encoding methods and split ratios. Then, generate a configuration for the model, including hidden layer dimensions, training epochs, learning rate, and batch size. ```python drug_encoding = 'Daylight' target_encoding = 'AAC' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2], random_seed = 5) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256 ) model = models.model_initialize(**config) ``` -------------------------------- ### Import Common Modules - Python Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/notes/encoder.html These are the standard PyTorch and utility modules commonly imported when working with DeepPurpose models. Ensure these libraries are installed. ```python import torch from torch.autograd import Variable import torch.nn.functional as F from torch import nn import numpy as np import pandas as pd ``` -------------------------------- ### Configure and Train Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_DAVIS.ipynb Initializes data processing, sets model configuration parameters, and executes the training process. ```python drug_encoding = 'Daylight' target_encoding = 'AAC' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2], random_seed = 2) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256 ) model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Data Preparation and Model Training Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_DAVIS.ipynb Prepare datasets using specified encoding methods and split them into training, validation, and testing sets. Configure model parameters and initialize the model for training. This snippet is suitable for initiating a new training run. ```python drug_encoding = 'Daylight' target_encoding = 'AAC' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2], random_seed = 3) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256 ) model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Get Unique Labels in Python Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/Tutorial_2_Drug_Property_Pred_Assay_Data.ipynb Determine the unique labels present in the dataset using `np.unique`. This is useful for understanding the distribution of the target variable. ```python import numpy as np np.unique(y) ``` -------------------------------- ### Import DeepPurpose Modules Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/Tutorial_1_DTI_Prediction.ipynb Initializes the environment by importing utility, dataset, and DTI model modules. Suppresses warning messages for cleaner output. ```python from DeepPurpose import utils, dataset from DeepPurpose import DTI as models import warnings warnings.filterwarnings("ignore") ``` -------------------------------- ### Read Custom Bioassay Data Source: https://context7.com/kexinhuang12345/deeppurpose/llms.txt Load bioassay data from a text file starting with a target sequence, followed by lines of SMILES and Score. Uses `read_file_training_dataset_bioassay`. ```python from DeepPurpose.dataset import ( read_file_training_dataset_drug_target_pairs, read_file_training_dataset_bioassay, read_file_repurposing_library, read_file_target_sequence ) # Bioassay data file format: # TargetSequence (first line) # SMILES1 Score1 # SMILES2 Score2 X_drug, target, y = read_file_training_dataset_bioassay('bioassay_data.txt') ``` -------------------------------- ### Configure and Train a Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_DAVIS.ipynb Process data, generate configuration, and execute the training process for a drug-target model. ```python drug_encoding = 'Daylight' target_encoding = 'AAC' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2], random_seed = 4) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256 ) model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Initialize DeepPurpose Environment Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Drug_Property_Prediction_Bacterial_Activity-RDKit2D_MIT_AiCures.ipynb Configures the working directory and imports essential modules for compound prediction and evaluation. ```python import os os.chdir('../') import DeepPurpose.CompoundPred as models from DeepPurpose.utils import * from DeepPurpose.dataset import * from sklearn.metrics import mean_squared_error, roc_auc_score, average_precision_score, f1_score ``` -------------------------------- ### Generate Atom Features in Python Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/notes/chem/atom_features.html Use this function to get a feature vector for an atom in a molecular graph. It requires the 'torch' library and assumes 'onek_encoding_unk' and 'ELEM_LIST' are defined elsewhere. ```python def atom_features(atom): return torch.Tensor(onek_encoding_unk(atom.GetSymbol(), ELEM_LIST) + onek_encoding_unk(atom.GetDegree(), [0,1,2,3,4,5]) + onek_encoding_unk(atom.GetFormalCharge(), [-1,-2,1,2,0]) + onek_encoding_unk(int(atom.GetChiralTag()), [0,1,2,3]) + [atom.GetIsAromatic()]) ``` -------------------------------- ### Initialize DeepPurpose Environment Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/Tutorial_2_Drug_Property_Pred_Assay_Data.ipynb Imports necessary modules and suppresses warnings for a clean training environment. ```python from DeepPurpose import utils, dataset, CompoundPred import warnings warnings.filterwarnings("ignore") ``` -------------------------------- ### Drug Property Prediction Mode Initialization Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Drug_Property_Prediction_Bacterial_Activity.ipynb Messages indicating the start of the 'Drug Property Prediction Mode', including the total number of drugs processed and the status of drug encoding. ```text predicting... predicting... Drug Property Prediction Mode... in total: 3290 drugs encoding drug... unique drugs: 1688 drug encoding finished... do not do train/test split on the data for already splitted data Drug Property Prediction Mode... in total: 201 drugs encoding drug... unique drugs: 201 drug encoding finished... do not do train/test split on the data for already splitted data Drug Property Prediction Mode... in total: 208 drugs encoding drug... unique drugs: 208 drug encoding finished... do not do train/test split on the data for already splitted data Drug Property Prediction Mode... in total: 238 drugs encoding drug... unique drugs: 238 drug encoding finished... do not do train/test split on the data for already splitted data ``` -------------------------------- ### Load BindingDB Sample Data Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/Tutorial_1_DTI_Prediction.ipynb Retrieves a sample dataset from BindingDB for virtual screening tasks. ```python t, d = dataset.load_IC50_1000_Samples() ``` -------------------------------- ### Load and Use Pretrained Models Source: https://context7.com/kexinhuang12345/deeppurpose/llms.txt Shows how to load a pretrained model by name or directory and perform inference on new drug-target pairs. ```python from DeepPurpose import DTI as models # Load pretrained model by name # Available models: MPNN_CNN_DAVIS, CNN_CNN_BindingDB, Morgan_AAC_KIBA, etc. model = models.model_pretrained(model='MPNN_CNN_DAVIS') # Or load from a saved directory model = models.model_pretrained(path_dir='./saved_model') # Use model for prediction from DeepPurpose.utils import data_process X_drug = ['CC1=C(C=C(C=C1)NC(=O)C2=CC=C(C=C2)CN3CCN(CC3)C)NC4=NC=CC(=N4)C5=CN=CC=C5'] X_target = ['MKKFFDSRREQGGSGLGSGSSGGGGSTSGLGSGYIGRVFGIGRQQVTVDEVLAEGGFAIVFLVRTSNGMKCALKRMFVNNEHDLQVCKREIQIMRDLSGHKNIVGYIDSSINNVSSGDVWEVLILMDFCRGGQVVNLMNQRLQTGFTENEVLQIFCDTCEAVARLHQCKTPIIHRDLKVENILLHDRGHYVLCDFGSATNKFQNPQTEGVNAVEDEIKKYTTLSYRAPEMVNLYSGKIITTKADIWALGCLLYKLCYFTLPFGESQVAICDGNFTIPDNSRYSQDMHCLIRYMLEPDPDKRPDIYQVSYFSFKLLKKECPIPNVQNSPIPAKLPEPVKASEAAAKKTQPKARLTDPIPTTETSIAPRQRPKAGQTQPNPGILPIQPALTPRKRATVQPPPQAAGSSNQPGLLASVPQPKPQAPPSQPLPQTQAKQPQAPPTPQQTPSTQAQGLPAQAQATPQHQQQLFLKQQQQQQQPPPAQQQPAGTFYQQQQAQTQQFQAVHPATQKPAIAQFPVVSQGGSQQQLMQNFYQQQQQQQQQQQQQQLATALHQQQLMTQQAALQQKPTMAAGQQPQPQPAAAPQPAPAQEPAIQAPVRQQPKVQTTPPPAVQGQKVGSLTPPSSPKTQRAGHRRILSDVTHSAVFGVPASKSTQLLQAAAAEASLNKSKSATTTPSGSPRTSQQNVYNPSEGSTWNPFDDDNFSKLTAEELLNKDFAKLGEGKHPEKLGGSAESLIPGFQSTQGDAFATTSFSAGTAEKRKGGQTVDSGLPLLSVSDPFIPLQVPDAPEKLIEGLKSPDTSLLLPDLLPMTDPFGSTSDAVIEKADVAVESLIPGLEPPVPQRLPSQTESVTSNRTDSLTGEDSLLDCSLLSNPTTDLLEEFAPTAISAPVHKAAEDSNLISGFDVPEGSDKVAEDEFDPIPVLITKNPQGGHSRNSSGSSESSLPNLARSLLLVDQLIDL'] # Process for prediction df_data, _, _ = data_process( X_drug, X_target, drug_encoding=model.drug_encoding, target_encoding=model.target_encoding, split_method='repurposing_VS' ) predictions = model.predict(df_data) print(f"Predicted binding affinity (pKd): {predictions[0]:.2f}") # Output: Predicted binding affinity (pKd): 7.23 ``` -------------------------------- ### Change Directory to DeepPurpose Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/notes/download.html Navigate into the downloaded DeepPurpose directory. ```bash $ cd DeepPurpose $ ### Change directory to DeepPurpose ``` -------------------------------- ### Initialize DeepPurpose Environment Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/CNN_CNN-Binary-SARS-CoV-3CL.ipynb Sets the working directory and imports necessary modules for Drug-Target Interaction (DTI) modeling. ```python import os os.chdir('../') import DeepPurpose.DTI as models from DeepPurpose.utils import * from DeepPurpose.dataset import * ``` -------------------------------- ### Download BindingDB Dataset Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/load_data_tutorial.ipynb Initiates the download of the BindingDB dataset to a specified local directory. Returns the path to the downloaded file. ```python data_path = dataset.download_BindingDB('./data/') ``` -------------------------------- ### Configure manual experiment search space Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Drug_Property_Pred-Ax-Hyperparam-Tune.ipynb Defines a custom search space and initializes a SimpleExperiment for more granular control. ```python opt_trials = 16 init_trials = 5 dset = 'Morgan' # Search space search_space = SearchSpace(parameters=[ RangeParameter( name='LR', parameter_type=ParameterType.FLOAT, lower=1e-6, upper=1e-3, log_scale=False), RangeParameter( name='decay', parameter_type=ParameterType.FLOAT, lower=0, upper=0.2, log_scale=False), ChoiceParameter( name='batch_size', parameter_type=ParameterType.INT, values=[64, 128, 256]), ChoiceParameter( name='cls_hidden_dims', parameter_type=ParameterType.INT, values=[64, 128, 256, 512]), ]) # Create Experiment exp = SimpleExperiment( name = 'Morgan', search_space = search_space, evaluation_function = run_Morgan, objective_name = 'accuracy', ) ``` -------------------------------- ### Initialize and Train DeepPurpose Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/GNN_Models_Release_Example.ipynb Sets up the environment, loads data, configures, and trains a DeepPurpose model for drug property prediction. Ensure to comment out the first two lines if using the pip version. ```python ## if you are using the pip version, please comment out the below two lines import os os.chdir('../') from DeepPurpose import CompoundPred as models from DeepPurpose.utils import * from tdc import BenchmarkGroup group = BenchmarkGroup(name = 'ADMET_Group', path = 'data/') import warnings warnings.filterwarnings("ignore") ## 0.1.2 new supported models: ## DGL_GCN, DGL_NeuralFP, DGL_GIN_AttrMasking, DGL_GIN_ContextPred, DGL_AttentiveFP drug_encoding = 'DGL_GCN' benchmark = group.get('Caco2_Wang') train, valid = group.get_train_valid_split(benchmark = benchmark['name'], split_type = 'default', seed = 1) train = data_process(X_drug = train.Drug.values, y = train.Y.values, drug_encoding = drug_encoding, split_method='no_split') val = data_process(X_drug = valid.Drug.values, y = valid.Y.values, drug_encoding = drug_encoding, split_method='no_split') test = data_process(X_drug = benchmark['test'].Drug.values, y = benchmark['test'].Y.values, drug_encoding = drug_encoding, split_method='no_split') config = generate_config(drug_encoding = drug_encoding, cls_hidden_dims = [512], train_epoch = 10, LR = 0.001, batch_size = 128, ) model = models.model_initialize(**config) model.train(train, val, test, verbose = True) y_pred = model.predict(test) ``` -------------------------------- ### Initialize and Train DeepPurpose Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_KIBA.ipynb Configures the model with specific encodings and hyperparameters, then executes the training process on prepared data. ```python drug_encoding = 'Morgan' target_encoding = 'AAC' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2], random_seed = 5) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256 ) model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Initialize and Train DeepPurpose Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_DAVIS.ipynb Prepares data using specified encodings, generates a configuration for the model, initializes the model, and then trains it using the prepared datasets. Supports random splitting and custom data fractions. ```python drug_encoding = 'Morgan' target_encoding = 'AAC' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2], random_seed = 1) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256 ) model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Process Data with Cold-Start Splitting Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/Tutorial_1_DTI_Prediction.ipynb Loads and processes DAVIS dataset with a cold-drug split method to evaluate model robustness on unseen drugs. ```python X_drugs, X_targets, y = dataset.load_process_DAVIS(path = './data', binary = False, convert_to_log = True, threshold = 30) train, val, test = utils.data_process(X_drugs, X_targets, y, drug_encoding, target_encoding, split_method='cold_drug',frac=[0.7,0.1,0.2], random_seed = 1) ``` -------------------------------- ### Initialize Compound Prediction Model in Python Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/Tutorial_2_Drug_Property_Pred_Assay_Data.ipynb Initialize the compound prediction model using the generated configuration. The `model_initialize` function takes the configuration parameters as keyword arguments. ```python model = CompoundPred.model_initialize(**config) model ``` -------------------------------- ### Import DeepPurpose packages Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/load_data_tutorial.ipynb Load the required modules from the DeepPurpose library to initialize dataset processing. ```python from DeepPurpose import utils, dataset ``` -------------------------------- ### Access Model Configuration (Local Load) Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/load_pretraining_models_tutorial.ipynb Displays the configuration parameters of the loaded pretrained model. ```python net.config ``` -------------------------------- ### Initialize DeepPurpose Environment Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Drug_Property_Pred-Ax-Hyperparam-Tune.ipynb Imports necessary modules and initializes the notebook plotting environment for DeepPurpose. ```python import os os.chdir('../') import DeepPurpose.CompoundPred as property_pred from DeepPurpose.utils import * from DeepPurpose.dataset import * from sklearn.metrics import mean_squared_error, roc_auc_score, average_precision_score, f1_score import numpy as np from ax.plot.contour import interact_contour, plot_contour from ax.plot.trace import optimization_trace_single_method from ax.service.managed_loop import optimize from ax.utils.notebook.plotting import render, init_notebook_plotting from ax.utils.tutorials.cnn_utils import load_mnist, train, evaluate, CNN import warnings warnings.filterwarnings("ignore") init_notebook_plotting() ``` -------------------------------- ### Initialize and Train DeepPurpose Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/CNN_Transformer_KIBA-gpu.ipynb Configures the model architecture and training parameters, then executes the training loop on the provided dataset. ```python config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, test_every_X_epoch = 100, LR = 0.001, batch_size = 128, hidden_dim_drug = 128, cnn_drug_filters = [32,64,96], cnn_drug_kernels = [4,8,12], transformer_n_layer_target = 2 ) model = models.model_initialize(**config) t2 = time() print("cost about " + str(int(t2-t1)) + " seconds") model.train(train, val, test) ``` -------------------------------- ### Initialize Classifier Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/_sources/notes/dtba/classifier.rst.txt Create an instance of the Classifier. Requires drug and protein encoder models and optional configuration parameters. ```python Classifier(model_drug, model_protein, **config) ``` -------------------------------- ### Initialize MPNN Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/_sources/notes/mpnn.rst.txt Use the constructor to create an MPNN model. Specify the hidden layer size and the depth of the network. ```python class DeepPurpose.models.MPNN(nn.Sequential) ``` ```python __init__(self, mpnn_hidden_size, mpnn_depth) ``` -------------------------------- ### Process Data and Configure Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Transformer+CNN_BindingDB.ipynb Processes the BindingDB dataset and generates a configuration dictionary for the model architecture. ```python X_drug, X_target, y = process_BindingDB('../data/BindingDB_All.tsv', y = 'Kd', binary = False, convert_to_log = True) drug_encoding = 'Transformer' target_encoding = 'CNN' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2]) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 128, cnn_target_filters = [32,64,96], cnn_target_kernels = [4,8,12] ) ``` -------------------------------- ### Configure and Train DeepPurpose Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/CNN-Binary-Example-DAVIS.ipynb Initializes the model configuration with specific hyperparameters and executes the training process. ```python config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256, cnn_drug_filters = [32,64,96], cnn_target_filters = [32,64,96], cnn_drug_kernels = [4,6,8], cnn_target_kernels = [4,8,12] ) ``` ```python model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Load Pretrained Model from Local Directory Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/load_pretraining_models_tutorial.ipynb Loads a pretrained DeepPurpose model from a local directory. Ensure the directory contains 'config.pkl' and 'model.pt'. ```python path = utils.download_pretrained_model('Morgan_AAC_DAVIS') net = models.model_pretrained(path_dir = path) ``` -------------------------------- ### Generate Configuration Parameters Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/_sources/notes/configuration.rst.txt Use this function to initialize the configuration dictionary for training and inference models. It accepts various parameters for drug and target encoding architectures. ```python utils.generate_config( drug_encoding, target_encoding, result_folder = "./result/", input_dim_drug = 1024, input_dim_protein = 8420, hidden_dim_drug = 256, hidden_dim_protein = 256, cls_hidden_dims = [1024, 1024, 512], mlp_hidden_dims_drug = [1024, 256, 64], mlp_hidden_dims_target = [1024, 256, 64], batch_size = 256, train_epoch = 10, test_every_X_epoch = 20, LR = 1e-4, transformer_emb_size_drug = 128, transformer_intermediate_size_drug = 512, transformer_num_attention_heads_drug = 8, transformer_n_layer_drug = 8, transformer_emb_size_target = 128, transformer_intermediate_size_target = 512, transformer_num_attention_heads_target = 8, transformer_n_layer_target = 4, transformer_dropout_rate = 0.1, transformer_attention_probs_dropout = 0.1, transformer_hidden_dropout_rate = 0.1, mpnn_hidden_size = 50, mpnn_depth = 3, cnn_drug_filters = [32,64,96], cnn_drug_kernels = [4,6,8], cnn_target_filters = [32,64,96], cnn_target_kernels = [4,8,12], rnn_Use_GRU_LSTM_drug = 'GRU', rnn_drug_hid_dim = 64, rnn_drug_n_layers = 2, rnn_drug_bidirectional = True, rnn_Use_GRU_LSTM_target = 'GRU', rnn_target_hid_dim = 64, rnn_target_n_layers = 2, rnn_target_bidirectional = True ) ``` -------------------------------- ### Initialize and Train DeepPurpose Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_KIBA.ipynb This snippet demonstrates initializing a DeepPurpose model with custom configurations for drug and target encodings, hidden layer dimensions, training epochs, learning rate, and batch size. It then proceeds to train the model using the prepared datasets. ```python drug_encoding = 'Morgan' target_encoding = 'AAC' train, val, test = data_process(X_drug, X_target, y, drug_encoding, target_encoding, split_method='random',frac=[0.7,0.1,0.2], random_seed = 2) config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256 ) model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Configure Model Parameters Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_DAVIS.ipynb Initializes the model configuration using specific hyperparameters for drug and target encoding, learning rate, and batch size. ```python config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256, cnn_target_filters = [32,64,96], cnn_target_kernels = [4,8,12] ) ``` -------------------------------- ### Initialize DeepPurpose Model Configuration Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/Morgan_CNN_Morgan_AAC_Daylight_AAC_KIBA.ipynb Configure and initialize a DeepPurpose model using parameters specified in the research paper. Ensure all required encoding types and training hyperparameters are set. ```python config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, LR = 0.001, batch_size = 256, cnn_target_filters = [32,64,96], cnn_target_kernels = [4,8,12] ) model = models.model_initialize(**config) model.train(train, val, test) ``` -------------------------------- ### Initialize DeepPurpose Model Configuration Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/MPNN_CNN_Kiba.ipynb Configure the DeepPurpose model using parameters specified in the paper 'https://arxiv.org/abs/1801.10193'. This includes settings for drug and target encoding, hidden layer dimensions, training epochs, learning rate, batch size, and specific model architecture parameters. ```python config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, test_every_X_epoch = 10, LR = 0.001, batch_size = 128, hidden_dim_drug = 128, mpnn_hidden_size = 128, mpnn_depth = 3, cnn_target_filters = [32,64,96], cnn_target_kernels = [4,8,12] ) model = models.model_initialize(**config) t2 = time() print("cost about " + str(int(t2-t1)) + " seconds") ``` -------------------------------- ### Initialize DBTA Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/build/html/_sources/notes/dtba/dbta.rst.txt Constructor for creating a DBTA instance with specific configuration parameters for drug and target encoding. ```python class DeepPurpose.models.DBTA ``` ```python __init__(self, **config) ``` -------------------------------- ### Configure and Initialize DeepPurpose Model Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/DEMO/CNN_Transformer_KIBA-gpu.ipynb Use this snippet to configure the DeepPurpose model with specific parameters as outlined in the research paper. Ensure all necessary encoding types and dimensionalities are correctly set before initialization. ```python config = generate_config(drug_encoding = drug_encoding, target_encoding = target_encoding, cls_hidden_dims = [1024,1024,512], train_epoch = 100, test_every_X_epoch = 100, LR = 0.001, batch_size = 128, hidden_dim_drug = 128, cnn_drug_filters = [32,64,96], cnn_drug_kernels = [4,8,12], transformer_n_layer_target = 2 ) model = models.model_initialize(**config) ``` -------------------------------- ### load_AID1706_txt_file Source: https://github.com/kexinhuang12345/deeppurpose/blob/master/docs/source/notes/data/load_AID1706_txt_file.md Loads the KIBA dataset from a specified directory. ```APIDOC ## load_AID1706_txt_file ### Description Loads the KIBA dataset from a specified directory. ### Method Python Function Call ### Endpoint N/A (Python function) ### Parameters #### Path Parameters - **path** (str) - Required - The directory that saves the AID1706 dataset file. Example: ’./data’. ### Request Example ```python load_AID1706_txt_file(path = './data') ``` ### Response #### Success Response (200) N/A (Python function return value not specified) #### Response Example N/A ```