Package: sequence-unet
Sequence UNET 1.0.3Sequence UNET is a fully convolutional neural network variant effect predictor, able to predict the pathogenicity of protein coding variants and the frequency they occur across large multiple sequence alignments.
A description and discussion of the model is available on bioRxiv(Dunham et al. 2022).
It uses a U-shaped architecture inspired by the U-NET medical image segmentation network(Ronneberger et al. 2015), with an optional Graph CNN section to incorporate information from protein structure:This repo contains a python package for downloading and using the trained models as well as code used to train, explore and analyse the models.
The package can download, load and predict with 8 variant trained models, which are also available for manual download onBioStudies.
The python package is contained in thesequence_unetdirectory, with documentation in thedocsdirectory.
It is also possible to use the modules and scripts used for training and exploring different models, found inanalysis,binandsource.
The python scripts and modules require adding thesrcdirectory to your python path.InstallationIn most cases pip should be able to handle all the dependancies, meaning installation is simple:pip install sequence_unetOr the latest development version from GitHub:pip install git+https://github.com/allydunham/sequence_unetManual installationIf pip can't resolve the correct dependancies the requirements might be able to be installed manually:Install Tensorflow (or tensorflow-macos on M1 Macs):pip install tensorfloworpip install tensorflow-macosInstall other PyPi requirements:pip install numpy pandas biopython tqdm proteinnetpyInstall Sequence UNET:pip install --no-deps sequence_unetThis was needed on M1 Macs before I updatedpyproject.tomlto usetensorflow-macosfor those systems since no versions of Tensorflow were available which matched the requirements.
It might help similar compatibility issues too.RequirementsThe python package requires:Python 3+Tensorflow 2.6+NumpyPandasBiopythonTQDMProteinNetPyI have tried to maintain as broad requirements as possible but future changes, particularly in Tensorflow, may result in more restrictive version support.Figure generation and performance analysis was performed in R 4.0, largely usingTidyversepackages.
All R packages used are loaded insrc/config.Ror the top of the respective script.Basic UsageDetaileddocumentationof the modules functions and scripts are available on ReadTheDocs.Loading ModelsTrained models are downloaded and loaded using thesequence_unet.modelsmodule, which also provides functions to initialise untrained models.
The loaded model is a TensorFlow Keras model, so easily interfaces with other code.fromsequence_unetimportmodels# Download a trained modelmodel_path=models.download_trained_model("freq_classifier",root="models",model_format="tf")# Load the downloaded model via its path. This function can also download the model if not foundmodel=models.load_trained_model(model=model_path)# or via name and rootmodel=models.load_trained_model(model="freq_classifier",root="models")model.summary()PredictionThesequence_unet.predictmodule provides functions to predict from sequences or ProteinNet files.
Other input data can easily be parsed into one of these formats or transformed in Python to fit the models input shapes (described in themodels.sequence_unetfunction).frompandasimportconcatfromBioimportSeqIOfromproteinnetpy.dataimportProteinNetDatasetfromsequence_unet.modelsimportload_trained_modelfromsequence_unet.predictimportpredict_sequence,predict_proteinnet# load a modelmodel=load_trained_model(model="freq_classifier",download=True)# Predict from a fasta filefasta=SeqIO.parse("path/to/fasta.fa",format="fasta")preds=concat([pforpinpredict_sequence(model,sequences=fasta,wide=True)])# Predict from a ProteinNet filedata=ProteinNetDataset(path="path/to/proteinnet",preload=False)preds=concat([pforpinpredict_proteinnet(model,data,wide=True)])The package also binds thesequence_unetcommand, which allows users to make predictions from the command line.
It supports predicting scores for proteins in a fasta orProteinNetfile.
A full description is available in thedocumentationand can be accessed using-h.TrainingThesequence_unetpackage does not include specific code for training new models, as the best way to do this will be specific to the users needs.
However, the loaded models areTensorFlow Keras modelsand inherently support straightforward and extensible training.
I used thetraining.pyscript to train the models, based on a saved model and data loading function saved by themake_experiment_dirfunction insrc/utils.py.
Usage of the script is documented in it's docstring and can be accessed using-h.
The training scripts in subdirectories ofmodelsgive examples of the model training procedures I used to train the various forms of the model.
This setup can be adapted for other users needs reasonably easily.