Python module for running Defense Predictor 2, a machine learning model to predict antiphage defense systems
Project description
DefensePredictor2: A Machine Learning Model to Discover Novel Prokaryotic Immune Systems
Python package to run DefensePredictor2, a machine-learning model that leverages embeddings from a protein language model, ESM2, to classify proteins as anti-phage defensive.
This repo is for the second version of DefensePredictor, which was trained with larger ESM2 embeddings and an updated training set. This model has not been experimentally tested, so use with caution.
For additional details, read the original DefensePredictor paper here.
Installation
In a fresh conda or other virutal environment, run:
pip install defense_predictor_2
defense_predictor_2_download
The first command downloads the python package from PyPI and the second downloads the model weights. Once model weights are downloaded you do not need to run this command again.
Requirements
Requires python >= 3.10
Usage
defense_predictor_2 can be run as python code
import defense_predictor_2 as dfp
ncbi_feature_table = 'GCF_003333385.1_ASM333338v1_feature_table.txt'
ncbi_cds_from_genomic = 'GCF_003333385.1_ASM333338v1_cds_from_genomic.fna'
ncbi_protein_fasta = 'GCF_003333385.1_ASM333338v1_protein.faa'
output_df, feature_matrix = dfp.defense_predictor(ft_file=ncbi_feature_table, fna_file=ncbi_cds_from_genomic, faa_file=ncbi_protein_fasta)
output_df.head()
Or from the command line
defense_predictor_2 \
--ncbi_feature_table GCF_003333385.1_ASM333338v1_feature_table.txt \
--ncbi_cds_from_genomic GCF_003333385.1_ASM333338v1_cds_from_genomic.fna \
--ncbi_protein_fasta GCF_003333385.1_ASM333338v1_protein.faa \
--output GCF_003333385_defense_predictor_output.csv
Alternatively, defense_predictor_2 can take a single GFF3 file with embedded genomic FASTA:
output_df, feature_matrix = dfp.defense_predictor(gff='annot_with_genomic_fasta.gff')
defense_predictor_2 \
--gff annot_with_genomic_fasta.gff \
--output defense_predictor_2_output.csv
When given a GFF, defense_predictor_2 translates proteins from the embedded genomic sequence using the bacterial codon table (transl_table=11) and uses each CDS's locus_tag as its identifier.
defense_predictor_2 outputs the predicted log-odds of defense for each input protein in the columns mean_log_odds. We reccomend using a stringent log-odds cutoff of 4 to call a protein predicted defensive.
To see an example you can run the defense_predictor_2_example.ipynb in colab:
We reccomend running defense_predictor_2 on a computer with a cuda-enabled GPU, to maximize computational efficiency.
Inputs
The NCBI input files can be downloaded from the ftp webpage for any gemone of interest, which is linked on its assembly page.
For an unannotated nucleotide assembly, run NCBI's Prokaryotic Genome Annotation Pipeline (PGAP)
or prokka and pass its *.gff output directly via --gff.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file defense_predictor_2-0.0.1.tar.gz.
File metadata
- Download URL: defense_predictor_2-0.0.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.1 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b9bb4d74d0f2ad435ef7619e41f654f9555c35f18aa610a99396909e7371ff9
|
|
| MD5 |
4314ae6920d8d9cbcc2faf3d9a163933
|
|
| BLAKE2b-256 |
3e5d1cb056b2a5ba3665fca0c12b24c2d1870aab9b36b6a09fb41eaa25430df3
|
File details
Details for the file defense_predictor_2-0.0.1-py3-none-any.whl.
File metadata
- Download URL: defense_predictor_2-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.1 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab18015829bf5300b1d9fc27cf2525b96a531d087ead4e1da90c76b79f871de7
|
|
| MD5 |
e854bce63359311df80433c92d469953
|
|
| BLAKE2b-256 |
a959ab9ebeed6626b7f22c7b3a174add3d93b79810b9b9f7b0b1d6dc56f9e2e3
|