Skip to main content

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: Open 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.

Metadata

Release files for defense-predictor-2 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for defense-predictor-2 0.0.1
File Size Uploaded Provenance Actions
defense_predictor_2-0.0.1.tar.gz 14.3 kB Without provenance Details for defense_predictor_2-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for defense-predictor-2 0.0.1
File Interpreter ABI Platform Actions
defense_predictor_2-0.0.1-py3-none-any.whl Python 3 none any Details for defense_predictor_2-0.0.1-py3-none-any.whl

Total release size: 29.1 kB

Release files / defense_predictor_2-0.0.1.tar.gz

Download URL defense_predictor_2-0.0.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5b9bb4d74d0f2ad435ef7619e41f654f9555c35f18aa610a99396909e7371ff9
BLAKE2b-256 checksum
How to use checksums
3e5d1cb056b2a5ba3665fca0c12b24c2d1870aab9b36b6a09fb41eaa25430df3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.13.1 Darwin/25.2.0

Release files / defense_predictor_2-0.0.1-py3-none-any.whl

Download URL defense_predictor_2-0.0.1-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab18015829bf5300b1d9fc27cf2525b96a531d087ead4e1da90c76b79f871de7
BLAKE2b-256 checksum
How to use checksums
a959ab9ebeed6626b7f22c7b3a174add3d93b79810b9b9f7b0b1d6dc56f9e2e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.13.1 Darwin/25.2.0

Security for defense-predictor-2 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page