Package: ec-number-prediction
EC number prediction pipelineDescriptionEnzyme Commission (EC) numbers serve as a hierarchical system that categorizes
and organizes enzyme activities.
Within the realm of genome annotation, EC numbers are attributed to protein sequences
to concisely represent specific chemical reaction patterns.
These patterns mirror the chemical transformations enabled by the enzymes associated
with their respective EC numbers. The structure of EC numbers is divided
into four levels: (1) the primary category (e.g., 1 for oxidoreductases,
2 for transferases, 3 for hydrolases, 4 for lyases, 5 for isomerases, 6 for ligases,
and 7 for translocases), (2) the subclass (for instance, 1.2: Targets the aldehyde or
oxo group of donors), (3) the sub-subclass (such as With NAD(+) or NADP(+) as acceptor),
and (4) the final level, which identifies the enzyme's substrate (for example, 1.2.1.3:
aldehyde dehydrogenase (NAD(+))).We have developed a robust framework for evaluating deep learning (DL) models dedicated
to EC number prediction. These models are trained using embeddings from ESM2, ESM1b, and
ProtBERT. Through this detailed method, our objective is to thoroughly examine the efficacy
of both BLASTp and DL models. This will enable us to provide insightful observations on the
superiority of DL models, augmented with the latest large language model (LLM) embeddings,
over traditional alignment-based methods for predicting protein functions.RequirementsPython >= 3.9BLAST >= 2.12.0Install with condacondacreate-nec_numbers_predictionpython=3.9
condaactivateec_numbers_prediction
condainstallbioconda::blast==2.12.0InstallationPippipinstallec-numbers-predictionFrom githubpipinstallgit+https://github.com/jcapels/ec_numbers_prediction.gitRun pipeline to obtain the dataHere is how you can obtain the data from the pipeline using luigi. This pipeline will download the data from theUniProtdatabase, and will process it to obtain the data used in the project.
This will generate several files in the working directory, some are intermediate files, other are the final division into training,
validation and test sets. The final files are the ones that will be used in the next steps of the pipeline.The steps of this pipeline are the following:Download of UniProt data.Scraping of UniProt enzymes.Filter UniProt enzymes with UniRef90 cluster representatives.Enrich underrepresented EC classes with TrEMBL data.Generate a multi-label binary matrix for the resultant dataset.Underrepresented classes removal.Temporary EC numbers removal (e.g. EC 3.5.1.n3)Split the data with a division of 60/20/20.As for the intermediate files, those are the following:uniprot_sprot.xml.gz- SwissProt raw data.uniprot_trembl.xml.gz- TrEMBL raw data.uniref90.xml.gz- UniRef90 raw data.trembl_prot_ec.csv- TrEMBL enzymes with the respective assigned EC number.swiss_prot_ec.csv- SwissProt enzymes with the respective assigned EC number.trembl_prot_ec_filtered.csv- TrEMBL enzymes filtered with UniRef90 cluster representatives.swiss_prot_ec_filtered.csv- SwissProt enzymes filtered with UniRef90 cluster representatives.dataset_enriched.csv- Dataset with SwissProt enzymes enriched with TrEMBL.dataset_binarized.csv- Dataset with a multi-label binary matrix.dataset_binarized_filtered.csv- Dataset with underrepresented classes removed.dataset_binarized_filtered_without_n.csv- Dataset with underrepresented classes and temporary EC numbers removed.train.csv- Training data.test.csv- Test data.validation.csv- Validation data.fromec_number_prediction.run_data_processing_pipelineimportEnzymesPipelineimportluigiluigi.build([EnzymesPipeline()],workers=1,scheduler_host='127.0.0.1',scheduler_port=8083,local_scheduler=True)After this, we shuffled all the datasets for being ready for training and evaluation. Here's an example:importpandasaspdtraining_data=pd.read_csv("train.csv")training_data=training_data.sample(frac=1)training_data.to_csv("train_shuffled.csv",index=False)Extract featuresThe following functions will take the data you have in your working directory (please pass its path as
input to the following functions) and generate features using ESM, ProtBERT and one-hot encoding.fromec_number_prediction.feature_extraction.generate_featuresimportgenerate_esm_vectors,generate_prot_bert_vectors,\generate_one_hot_encodingsgenerate_esm_vectors(esm_function="esm2_t33_650M_UR50D",save_folder="/home/working_dir",dataset_directory="/home/working_dir/data")generate_prot_bert_vectors(save_folder="/home/working_dir",dataset_directory="/home/working_dir/data")generate_one_hot_encodings(save_folder="/home/working_dir",dataset_directory="/home/working_dir/data")Train modelsTraining the baselines is also easy:Train baselinesfromec_number_prediction.train_models.train_baselinesimporttrain_dnn_baselinestrain_dnn_baselines(model="esm2_t33_650M_UR50D",working_dir="/home/working_dir/")Train modelsTrain models with the specific sets, DeepEC and DSPACE. Note that the set chosen in the
following examples is set 1, but
you can choose any of the sets 1, 2, 3, 4. Also, note that the model chosen in the following examples is
esm2_t33_650M_UR50D, but you can choose any of the models:esm2_t33_650M_UR50Desm1b_t33_650M_UR50Sesm2_t30_150M_UR50Desm2_t12_35M_UR50Desm2_t6_8M_UR50Desm2_t36_3B_UR50Dprot_bert_vectorsesm2_t48_15B_UR50Dfromec_number_prediction.train_models.optimize_dnnimporttrain_dnn_optimizationfromec_number_prediction.train_models.train_deep_ecimporttrain_deep_ecfromec_number_prediction.train_models.train_dspaceimporttrain_dspacetrain_dnn_optimization(set_="1",model="esm2_t33_650M_UR50D",working_dir="/home/working_dir/")train_deep_ec(working_dir="/home/working_dir/")train_dspace(working_dir="/home/working_dir/")Train models with both training and validation setsTrain models with the training and validation sets merged.fromec_number_prediction.train_models.optimize_dnnimporttrain_dnn_trials_mergedfromec_number_prediction.train_models.train_deep_ecimporttrain_deep_ec_mergedfromec_number_prediction.train_models.train_dspaceimporttrain_dspace_mergedtrain_dnn_trials_merged(set_="1",model="esm2_t33_650M_UR50D",working_dir="/home/working_dir/")train_deep_ec_merged(working_dir="/home/working_dir/")train_dspace_merged(working_dir="/home/working_dir/")Train models with the whole dataTrain models with the whole data.fromec_number_prediction.train_models.optimize_dnnimporttrain_dnn_optimization_all_datatrain_dnn_optimization_all_data(set_="1",model="esm2_t33_650M_UR50D",working_dir="/home/working_dir/")Predict EC numbersPredict with modelHere you can see how to predict EC numbers with a model. Note that the model chosen in the following examples is
"DNN ProtBERT all data", but you can choose any of the models:DNN ProtBERT all dataDNN ESM1b all dataDNN ESM2 3B all data - note that this model requires at least12 GBof RAM to be run. If you intend to use GPU to
make the predictions, you need to have at least20 GBof GPU memory or 4 GPUs with8 GB.ProtBERT trial 2 train plus validation (for this model, you need to pass all_data=False)DNN ESM1b trial 4 train plus validation (for this model, you need to pass all_data=False)DNN ESM2 3B trial 2 train plus validation (for this model, you need to pass all_data=False)Here you can see the time taken and memory usage for each model to predict for different number of data points:ModelData PointsTime TakenMemory UsageDNN ProtBERT250:00:051GDNN ProtBERT1000:00:081GDNN ProtBERT10000:00:561GDNN ProtBERT100000:09:001GDNN ProtBERT1000001:55:087GDNN ESM1b250:00:282GDNN ESM1b1000:00:402GDNN ESM1b10000:02:222GDNN ESM1b100000:19:222GDNN ESM1b1000003:35:047GDNN ESM2 3B250:01:3510GDNN ESM2 3B1000:03:4010GDNN ESM2 3B10000:28:2710GDNN ESM2 3B100004:33:5010GThe parameters of the function are the following:pipeline: name of the model to use.dataset_path: path to the dataset to predict.output_path: path to the output file.ids_field: name of the column with the ids.all_data: whether to use all the data or not.sequences_field: name of the column with the sequences.device: device to use for the predictions.fromec_number_prediction.predictionsimportpredict_with_modelpredict_with_model(pipeline="DNN ProtBERT all data",dataset_path="/home/jcapela/ec_numbers_prediction/data/test_data.csv",output_path="predictions_prot_bert.csv",ids_field="id",all_data=True,sequences_field="sequence",device="cuda:0")If don't have large enough GPU memory, you can use the following models but have at least 4 GPU with 10 GB of memory:fromec_number_prediction.predictionsimportpredict_with_modelpredict_with_model(pipeline="DNN ESM2 3B all data",dataset_path="/home/jcapela/ec_numbers_prediction/data/test_data.csv",output_path="predictions_prot_bert.csv",ids_field="id",all_data=True,sequences_field="sequence",device="cuda",num_gpus=4)If you don't have a GPU, you can use the CPU:fromec_number_prediction.predictionsimportpredict_with_modelpredict_with_model(pipeline="DNN ESM2 3B all data",dataset_path="/home/jcapela/ec_numbers_prediction/data/test_data.csv",output_path="predictions_prot_bert.csv",ids_field="id",all_data=True,sequences_field="sequence",device="cpu")You can also make predictions using a FASTA file:fromec_number_prediction.predictionsimportpredict_with_model_from_fastapredict_with_model_from_fasta(pipeline="DNN ProtBERT all data",fasta_path="/home/jcapela/ec_numbers_prediction/data/test_data.fasta",output_path="predictions_prot_bert.csv",all_data=True,device="cuda:0")Predict with BLASTHere you can see how to predict EC numbers with BLAST. Note that the database chosen in the following examples is
"BLAST all data", but you can choose any of the databases:BLAST all dataBLAST train plus validationThe parameters of the function are the following:database_name: name of the database to use.dataset_path: path to the dataset to predict.output_path: path to the output file.ids_field: name of the column with the ids.sequences_field: name of the column with the sequences.fromec_number_prediction.predictionsimportpredict_with_blastpredict_with_blast(database_name="BLAST all data",dataset_path="/home/jcapela/ec_numbers_prediction/data/test_data.csv",output_path="test_blast_predictions.csv",ids_field="id",sequences_field="sequence")You can also make predictions using a FASTA file:fromec_number_prediction.predictionsimportpredict_with_blast_from_fastapredict_with_blast_from_fasta(database_name="BLAST all data",fasta_path="/home/jcapela/ec_numbers_prediction/data/test_data.fasta",output_path="test_blast_predictions.csv")Predict with an ensemble of BLAST and DL modelsHere you can see how to predict EC numbers with an ensemble between BLAST and models.The parameters of the function are the following:dataset_path: path to the dataset to predict.output_path: path to the output file.ids_field: name of the column with the ids.sequences_field: name of the column with the sequences.device: device to use for the predictions.fromec_number_prediction.predictionsimportpredict_with_ensemblepredict_with_ensemble(dataset_path="/home/jcapela/ec_numbers_prediction/data/test_data.csv",output_path="predictions_ensemble.csv",ids_field="id",sequences_field="sequence",device="cuda:0")You can also make predictions using a FASTA file:fromec_number_prediction.predictionsimportpredict_with_ensemble_from_fastapredict_with_ensemble_from_fasta(fasta_path="/home/jcapela/ec_numbers_prediction/data/test_data.fasta",output_path="predictions_ensemble.csv",device="cuda:0")