Package: pySAR
pySAR - Python Sequence Activity RelationshippySARis a Python library for analysing Sequence Activity Relationships (SARs)/Sequence Function Relationships (SFRs) of protein sequences.The published research article is availablehere.A quick Colab notebook demo ofpySARis availablehere.AMediumarticle that dives deeper into SARs and thepySARsoftware itself is availablehere.Table of ContentsIntroductionRequirementsInstallationUsageDirectoriesIssuesContactLicenseReferencesResearch ArticleThe research article that accompanied this software is titled: "Machine Learning Based Predictive Model for the Analysis of Sequence Activity Relationships Using Protein Spectra and Protein Descriptors" and was published in the Journal of Biomedical Informatics and is availablehere[1].How to citeMckenna, A., & Dubey, S. (2022). Machine learning based predictive model for the analysis of sequence activity relationships using protein spectra and protein descriptors. Journal of Biomedical Informatics, 128(104016), 104016.https://doi.org/10.1016/j.jbi.2022.104016IntroductionpySARis a Python library for analysing Sequence Activity Relationships (SARs)/Sequence Function Relationships (SFRs) of protein sequences.pySARoffers extensive and verbose functionalities that allow you to numerically encode a dataset of protein sequences using a large abundance of available methodologies and features. The software uses physiochemical and biochemical features from the Amino Acid Index (AAI) database[2], as well as allowing for the calculation of a range of structural, physiochemical and biochemical protein descriptors, via the custom-builtprotpypackage.After finding the optimal technique and feature set at which to numerically encode your dataset of sequences,pySARcan then be used to build a predictive regression ML model with the training data being that of the encoded protein sequences, and training labels being the in vitro experimentally pre-calculated activity values for each protein sequence. This model maps a set of protein sequences to the sought-after activity value, being able to accurately predict the activity/fitness value of new unseen sequences. The use-case for the software is within the field of Protein Engineering, Directed Evolution and or Drug Discovery, where a user has a set of in vitro experimentally determined activity/fitness values for a library of mutant protein sequences and wants to computationally predict the sought activity value for a selection of mutated unseen sequences, in the aim of finding the best sequence that minimises/maximises their activity value.In the publishedresearch, the sought activity/fitness characteristic is the thermostability of proteins from a recombination library designed from parental cytochrome P450's. This thermostability is measured using the T50 metric (temperature at which 50% of a protein is irreversibly denatured after 10 mins of incubation, ranging from 39.2 to 64.4 degrees C), which we want to maximise[1].Two additionalcustom-builtsoftwares were created alongsidepySAR-aaindexandprotpy. Theaaindexsoftware package is used for parsing the amino acid index which is a database of numerical indices representing various physicochemical and biochemical properties of amino acids and pairs of amino acids[2].protpyis used for calculating a series of protein physiochemical, biochemical and structural protein descriptors. Both of these software packages are integrated intopySARbut can also be used individually for their respective purposes.A quick Colab notebook demo ofpySARis availablehere. There is also a Medium article that dives deeper into SARs and thepySARsoftware itself, availablehere.RequirementsPython>= 3.8aaindex>= 1.1.2protpy>= 1.2.0numpy>= 1.24.2pandas>= 1.5.3scikit-learn>= 1.2.1scipy>= 1.10.1tqdm>= 4.65.0matplotlib>= 3.6.2seaborn>= 0.12.2InstallationInstall the latest version ofpySARviaPyPiusing pip:pip3installpysar--upgradeInstallation from source:gitclone-bmasterhttps://github.com/amckenna41/pySAR.git
python3setup.pyinstallcdpySARUsageConfile FilepySARworks mainly via JSON configuration files. There are many different customisable parameters for the functionalities inpySARincluding the metaparameters of some of the available protein descriptors, all Digital Signal Processing (DSP) parameters in thepyDSPmodule, the type of regression model to use and parameters specific to the dataset - a description of each parameter is available on theCONFIG.mdfile.These config files offer a more straightforward way of making any changes to thepySARpipeline. The names ofAllthe parameters as listed in the example config files must remain unchanged, only the value of each parameter should be changed, any parameters not being used can be set tonull. Additionally, you can pass in the individual parameter names and values to thepySARandEncodingclasses when numerically encoding the protein sequences viakwargs. An example of the config file used in my research project (thermostability.json), with most of the available parameters, can be seen below and in the example config file -CONFIG.md.{"dataset":{"dataset":"thermostability.txt","sequence_col":"sequence","activity":"T50"},"model":{"algorithm":"plsregression","parameters":"","test_split":0.2},"descriptors":{"descriptors_csv":"descriptors_thermostability.csv","moreaubroto_autocorrelation":{"lag":30,"properties":["CIDH920105","BHAR880101","CHAM820101","CHAM820102","CHOC760101","BIGC670101","CHAM810101","DAYM780201"],"normalize":1},...},"pyDSP":{"use_dsp":1,"spectrum":"power","window":{"type":"hamming",...},"filter":{"type":null,...}}}ExamplesEncoding protein sequences using all 566 AAIndex indices:Encoding protein sequences in dataset using all 566 indices in the AAI1 database. Each sequence encoded via an index in the AAI can be passed through an additional step where its protein spectra can be generated following an FFT. pySAR supports generation of the power, imaginary, real or absolute spectra as well as other DSP functionalities including windowing and filter functions.In the example below, the encoded sequences will be used to generate a imaginary protein spectra with a blackman window function applied. This will then be used as feature data to build a predictive regression ML model that can be used for accurate prediction of the sought activity value (thermostability) of unseen protein sequences. The encoding class also takes the JSON config file as input which will have all the required parameter values. The output results will show the calculated metric values for each index in the AAI when measuring predicted vs observed activity values for the unseen test sequences.#import encoding modulefrompySAR.encodingimport*'''thermostability.json{"dataset":{"dataset": "thermostability.txt","activity": "T50"...}"model":{"algorithm": "randomforest",...}"pyDSP":{"use_dsp": 1,"spectrum": "imaginary","window": {"type": "blackman"}}}'''#create instance of Encoding class, using RF algorithm with its default paramsencoding=Encoding(config_file='thermostability.json')#encode sequences using all indices in the AAI if input parameter "aai_indices" is empty/Noneaai_encoding=encoding.aai_encoding()Output results showing AAI index and its category as well as all the associated metric values for each predictive model. From the results below we can determine that theCHOP780206index in the AAI has the highest predictability (R2 score) for our chosen dataset (thermostability) and this generated model can be used for predicting the thermostability of new unseen sequences:IndexCategoryR2RMSEMSERPDMAEExplained Var0CHOP780206secondary_struct0.627373.8561914.87021.638183.167550.7134671QIAN880131secondary_struct0.6266893.9057615.2551.636683.098490.6315822QIAN880118secondary_struct0.6251563.9958115.96651.633333.320380.6258973PRAM900104secondary_struct0.6158663.9038915.24031.613463.249060.617799.........................................................................Encoding using list of 4 AAI indices, with no DSP functionalities:This method follows a similar procedure as the previous step, except 4 indices from the AAI are being specifically input into the function, with the encoded sequence output being concatenated together and used as feature data to build the predictive PLSRegression model with its default parameters. The config parameteruse_dsptells the function to not generate the protein spectra or apply any additional DSP processing to the sequences.#import encoding modulefrompySAR.encodingimport*'''thermostability.json{"dataset":{"dataset": "thermostability.txt","activity": "T50"...}"model":{"algorithm": "plsreg","parameters": null}"pyDSP":{"use_dsp": 0,...}}'''#create instance of Encoding class, using PLS algorithm with its default paramsencoding=Encoding(config_file='thermostability.json')#encode sequences using 4 indices specified by user, use_dsp = Falseaai_encoding=encoding.aai_encoding(aai_indices=["PONP800102","RICJ880102","ROBB760107","KARS160113"])Output DataFrame showing the 4 predictive models built using the PLS algorithm, with the 4 indices from the AAI. From the results below we can determine that thePONP800102index in the AAI has the highest predictability (R2 score) for our chosen dataset (thermostability) and this generated model can be used for predicting the thermostability of unseen sequences:IndexCategoryR2RMSEMSERPDMAEExplained Var0PONP800102hydrophobic0.747263.08179.496881.989132.637420.7510321ROBB760107secondary_struct0.6665273.1980110.22731.731692.503050.6682552RICJ880102secondary_struct0.5680673.8397614.74381.521573.013420.5682743KARS160113meta0.5441294.0426616.34311.481083.260470.544693Encoding protein sequences using all available protein descriptors:Calculate the protein descriptor values for a dataset of protein sequences from the 15 available descriptors in thedescriptorsmodule. Use each descriptor as a feature set in the building of the predictive ML models used to predict the activity value of unseen sequences. By default, the function will look for a csv file pointed to by the"descriptors_csv"parameter in the config file that contains the pre-calculated descriptor values for a dataset. If file is not found then all descriptor values will be calculated for the dataset using thedescriptorsmodule and custom-builtprotpypackage.#import encoding modulefrompySAR.encodingimport*'''thermostability.json{"dataset":{"dataset": "thermostability.txt","activity": "T50"...}"model":{"algorithm": "adaboost","parameters": [{"estimators": 100,"learning_rate": 1.5...},"descriptors":{"descriptors_csv": "descriptors_thermostability.csv","moreaubroto_autocorrelation": {"lag": 30,"properties": ["CIDH920105", "BHAR880101", "CHAM820101", "CHAM820102","CHOC760101", "BIGC670101", "CHAM810101", "DAYM780201"],"normalize": 1},...}}'''#create instance of Encoding class using AdaBoost algorithm, using 100 estimators & a learning rate of 1.5encoding=Encoding(config_file='thermostability.json')#building predictive models using all available descriptors, calculating evaluation metrics values for# models and storing into desc_results_df DataFramedesc_results_df=encoding.descriptor_encoding()Output results showing the protein descriptor and its group as well as all the associated metric values for each predictive model. From the results below we can determine that theCTD Distributiondescriptor has the highest predictability (R2 score) for our chosen dataset (thermostability) and this generated model can be used for predicting the thermostability of unseen sequences:DescriptorGroupR2RMSEMSERPDMAEExplained Var0ctd_dCTD0.7218853.2615910.6381.896212.606790.7273891geary_autocorrelationAutocorrelation0.6481213.6741813.49961.685792.828680.6667452tripeptide_compositionComposition0.6165773.397911.54571.614962.537360.6755713amino_acid_compositionComposition0.6128243.3744711.38711.607112.796980.6438644................................................Encoding using AAI + protein descriptors:Encoding protein sequences in the dataset using ALL 566 indices in the AAI database combined with ALL available protein descriptors. All 566 indices can be used in concatenation with 1, 2 or 3 descriptors. At each iteration the encoded sequences generated from the indices from the AAI will be combined with the feature set generated from the dataset's descriptor values and used to build a predictive regression ML model that can be used for the accurate prediction of the sought activity/fitness value of unseen protein sequences. The output results will show the calculated metric values when measuring predicted vs observed activity values for the test sequences.#import encoding modulefrompySAR.encodingimport*'''thermostability.json{"dataset":{"dataset": "thermostability.txt","activity": "T50"...}"model":{"algorithm": "randomforest","parameters":{"estimators": 100,"learning_rate": 1.5,...}},"descriptors":{"descriptors_csv": "descriptors_thermostability.csv","moreaubroto_autocorrelation": {"lag": 30,"properties": ["CIDH920105", "BHAR880101", "CHAM820101", "CHAM820102","CHOC760101", "BIGC670101", "CHAM810101", "DAYM780201"],"normalize": 1},...},"pyDSP":{"use_dsp": 0,"spectrum": "power","window": ""...}}'''#create instance of Encoding class using RF algorithm, using 100 estimators with a learning rate of 1.5 - as listed in configencoding=Encoding('thermostability.json')#building predictive models using all available aa_indices + descriptors, calculating evaluation metric values for models and storing into aai_desc_results_df DataFrameaai_desc_results_df=encoding.aai_descriptor_encoding()Output results showing AAI index and its category, the protein descriptor and its group as well as all output metric values for each predictive model. From the results below we can determine that theARGP820103index in concatenation with theConjoint Triaddescriptor has the highest predictability (R2 score) for our chosen dataset (thermostability) and this generated model can be used for predicting the thermostability of unseen sequences:IndexCategoryDescriptorDescriptor GroupR2RMSE0ARGP820103composition_conjoint_triadConjoint Triad0.727543.221351ARGP820101hydrophobic_quasi_seq_orderQuasi-Sequence-Order0.7222843.309952ARGP820101hydrophobic_seq_order_coupling_numberQuasi-Sequence-Order0.7221583.349263ANDN920101observable_seq_order_coupling_numberQuasi-Sequence-Order0.708263.252324..............................Building predictive model from subset of AAI and protein descriptors:The below code will build a PLSRegression model using the AAI indexCIDH920105and theamino acid compositiondescriptor. The index is passed through a DSP pipeline and is transformed into its informational protein spectra using thepower spectra, with a hamming window function applied to the output of the FFT. The concatenated features from the AAI index and the descriptor will be used as the feature data in building the PLS ML model. This model is then used to access its predictability by testing on test unseen sequences. The output results will show the calculated metric values when measuring predicted vs observed activity values for the test sequences.#import pySAR modulefrompySAR.pySARimport*'''thermostability.json{"dataset":{"dataset": "thermostability.txt","activity": "T50"...},"model":{"algorithm": "plsregression","parameters": "",...},"descriptors":{"descriptors_csv": "descriptors_thermostability.csv","moreaubroto_autocorrelation": {"lag": 30,"properties": ["CIDH920105", "BHAR880101", "CHAM820101", "CHAM820102","CHOC760101", "BIGC670101", "CHAM810101", "DAYM780201"],"normalize": 1},...},"pyDSP":{"use_dsp": 1,"spectrum": "power","window": "hamming",...}}'''#create instance of PySAR class, inputting path to configuration filepySAR=PySAR(config_file="thermostability.json")#encode protein sequences using both the CIDH920105 index + aa_composition descriptorresults_df=pySAR.encode_aai_descriptor(aai_indices="CIDH920105",descriptors="amino_acid_composition")Output results showing AAI index and its category, the protein descriptor and its group as well as the metric values for the generated predictive model. From the results below we can determine that theCIDH920105index in concatenation with theAmino Acid Compositiondescriptor has medium predictability (R2 score) but a high error rate (MSE/RMSE) for our chosen dataset (thermostability) and this feature set combination is not that effective for predicting the thermostability of unseen sequences:################################################################################################################################ Parameters ######################################### AAI Indices: CIDH920105# Descriptors: amino_acid_composition# Configuration File: thermostability_config.json# Dataset: thermostability.txt# Number of Sequences/Sequence Length: 261 x 466# Target Activity: T50# Algorithm: PLSRegression# Model Parameters: {'copy': True, 'max_iter': 500, 'n_components': 2, 'scale': True,#'tol': 1e-06}# Test Split: 0.2# Feature Space: (261, 486)################################################################################################################################## Results ########################################## R2: 0.6720111107323943# RMSE: 3.7522525079464457# MSE: 14.079398883390391# MAE: 3.0713217158459805# RPD 1.7461053136208489# Explained Variance 0.6721157080699659##########################################################################################Calculate individual descriptor values, e.g Tripeptide Composition and Geary Autocorrelation:The individual protein descriptor values for the dataset of protein sequences can be calculated using the custom-builtprotpypackage via thedescriptormodule. The full list of descriptors can be seen via the functionall_descriptors_list()as well as on theprotpyrepo homepage.#import descriptors classfrompySAR.descriptorsimport*#create instance of descriptors classdesc=Descriptors(config_file="thermostability.json")#calculate tripeptide composition descriptortripeptide_composition=desc.get_tripeptide_composition()#calculate geary autocorrelation descriptorgeary_autocorrelation=desc.get_geary_autocorrelation()Calculate and export all protein descriptors:Prior to evaluating the various available properties and features at which to encode a set of protein sequences, it is reccomened that you pre-calculate all the available descriptors in one go, saving them to a csv for later thatpySARwill then import from. Output values are stored in a csv set by thedescriptors_csvconfig parameter (the name of the exported csv via thedescriptors_export_filenameparameter can also be passed into the function). Output will be of the shape N x M, where N is the number of protein sequences in the dataset and M is the total number of features calculated from all 15 descriptors which varies depending on some descriptor-specific metaparameters. For example, using the thermostability dataset, the output will be 261 x 9714.'''thermostability.json{"dataset":{"dataset": "thermostability.txt","activity": "T50"...},"model":{...}"descriptors":{"descriptors_csv": "descriptors_thermostability.csv","moreaubroto_autocorrelation": {"lag": 30,"properties": ["CIDH920105", "BHAR880101", "CHAM820101", "CHAM820102","CHOC760101", "BIGC670101", "CHAM810101", "DAYM780201"],"normalize": 1},...},"pyDSP":{...}}'''#import descriptors classfrompySAR.descriptorsimport*#create instance of descriptors classdesc=Descriptors(config_file="thermostability.json")#export all descriptors to csv using parameters in config, export=True will export to csvdesc.get_all_descriptors(export=True,descriptors_export_filename="descriptors_thermostability.csv")Get record from AAIndex database:A custom-built package calledaaindexwas created for this project to work with all the data in the AAIndex databases, primarily theaaindex1. The AAIndex library offers diverse functionalities for obtaining all data from all records within theaaindex1. Each record is stored in json format and can be retrieved via its accession number, and can also be searched via its name/description. Each record contains the following attributes: description, references, category, notes, correlation coefficient, pmid and values.fromaaindeximportaaindex1record=aaindex1['CHOP780206']#get full recorddescription=aaindex1['CHOP780206'].description#get record's descriptionrefs=aaindex1['CHOP780206'].references#get record's referencescategory=aaindex1['CHOP780206'].category#get record's categorynotes=aaindex1['CHOP780206'].notes#get record's notescorrellation_coefficient=aaindex1['CHOP780206'].correllation_coefficient#get record's correllation_coefficientpmid=aaindex1['CHOP780206'].pmid#get record's pmidvalues=aaindex1['CHOP780206'].values#get amino acid values from recordnum_record=aaindex1.num_records()#get total number of recordsrecord_names=aaindex1.record_names()#get list of all record namesamino_acids=aaindex1.amino_acids()#get list of all canonical amino acidsrecords=aaindex1.search("hydrophobicity")#get all records with hydrophobicity in their title/descriptionDirectories and Files/config- configuration files for the example datasets thatpySARhas been tested with, as well as the thermostability.json config file that was used in the research. These config files should be used as a template for future datasets used withpySAR./data- data files used in the research proejct including the thermostability dataset, config file and pre-calculated protein descriptors./docs- documentation forpySAR(pending)./example_datasets- example datasets used for the building and testing ofpySAR, including the thermostability dataset used in the research. The format of these datasets should be used as a template for future datasets used withpySAR./images- all images used throughout the repo./pySAR- source code forpySARsoftware./tests- unit and integration tests forpySAR.pySAR_research.pdf- published research article.pySAR_research.pptx- powerpoint demo of the software development process of pySAR.CONFIG.md- example markdown file describing each of the available parameters in the config files.IssuesAny issues, errors or bugs can be raised via theIssuestab in the repository.ContactIf you have any questions or comments, please contactamckenna41@qub.ac.ukor raise an issue on theIssuestab.LicenseDistributed under the MIT License. SeeLICENSEfor more details.References[1]: Mckenna, A., & Dubey, S. (2022). Machine learning based predictive model for the analysis of sequence activity relationships using protein spectra and protein descriptors. Journal of Biomedical Informatics, 128(104016), 104016.https://doi.org/10.1016/j.jbi.2022.104016[2]: Kawashima, S. and Kanehisa, M., 2000. AAindex: amino acid index database. Nucleic acids research, 28(1), pp.374-374. DOI: 10.1093/nar/27.1.368[3]: Fontaine NT, Cadet XF, Vetrivel I. Novel Descriptors and Digital Signal Processing- Based Method for Protein Sequence Activity Relationship Study. Int J Mol Sci. 2019 Nov 11;20(22):5640. doi: 10.3390/ijms20225640. PMID: 31718061; PMCID: PMC6888668.[4]: Cadet, F., Fontaine, N., Li, G. et al. A machine learning approach for reliable prediction of amino acid interactions and its application in the directed evolution of enantioselective enzymes. Sci Rep 8, 16757 (2018).[5]: Lutz S. Beyond directed evolution--semi-rational protein engineering and design. Curr Opin Biotechnol. 2010 Dec;21(6):734-43. doi: 10.1016/j.copbio.2010.08.011. Epub 2010 Sep 24. PMID: 20869867; PMCID: PMC2982887.[6]: Yang, K.K., Wu, Z. & Arnold, F.H. Machine-learning-guided directed evolution for protein engineering. Nat Methods 16, 687–694 (2019).https://doi.org/10.1038/s41592-019-0496-6[7]: Yuting Xu, Deeptak Verma, Robert P. Sheridan, Andy Liaw, Junshui Ma, Nicholas M. Marshall, John McIntosh, Edward C. Sherer, Vladimir Svetnik, and Jennifer M. Johnston
Journal of Chemical Information and Modeling 2020 60 (6), 2773-2790
DOI: 10.1021/acs.jcim.0c00073[8]: Medina-Ortiz, D., Contreras, S., Amado-Hinojosa, J., Torres-Almonacid, J., Asenjo, J. A., Navarrete, M., & Olivera-Nappa, Á. (2020). Combination of digital signal processing and assembled predictive models facilitates the rational design of proteins. ArXiv [Cs.CE].Back to top