Skip to main content

A tool to design primers that target specific variants in genomic sequences. Alingment-free and fast.

Project description

DiffPrimer

diffprimer_logo

DiffPrimer is a bioinformatics tool designed to identify unique genomic regions in a reference genome compared to a set of other "background" genomes and automatically design specific PCR primers for these markers.

It combines high-performance k-mer analysis (written in Rust) with standard primer design tools (Primer3) to generate diagnostic markers that are exclusive to your target organism.

Key Features

  • Exclusive Region Discovery: Identifies genomic regions present in your reference but absent in a database of other genomes.
  • Automated Primer Design: Integrated with Primer3 to design optimal primer pairs for identified unique regions.
  • Specificity Check:
    • Validates designed primers against all input background genomes.
    • Uses a hybrid Myers Bit-Vector Algorithm (Global) and Semiglobal Alignment (Local) to detect potential off-target amplification, even with insertions/deletions.
  • Annotation Integration: Cross-references unique regions with GFF3 annotation files to identify which genes (if any) the markers overlap with.
  • Parallel Processing: Fully parallelized core for fast execution on large datasets.

Installation

Prerequisites

  • Operating System: Linux (Recommended) or macOS.
  • Python: Version 3.13 or higher (Strict requirement).
  • Rust: Required to build the core engine. Install via rustup.

Quick Install (Recommended)

We recommend using uv or pip in a clean environment.

  1. Clone the repository:

    git clone https://github.com/yourusername/diffprimer.git
    cd diffprimer
    
  2. Create a Virtual Environment:

    # Using uv (Recommended)
    uv venv --python 3.13
    source .venv/bin/activate
    
    # OR using standard python
    python3.13 -m venv .venv
    source .venv/bin/activate
    
  3. Install:

    uv pip install .
    # OR
    pip install .
    

Troubleshooting (Conda/Anaconda Users)

If you are working inside a Conda environment, the system linker may conflict with Rust, causing build errors (e.g., undefined symbol: getauxval). To fix this:

  1. Deactivate Conda completely for the build step.
  2. Use the system's standard PATH.
# In your terminal
unset CONDA_PREFIX
export PATH=/usr/local/bin:/usr/bin:/bin:$HOME/.cargo/bin
source .venv/bin/activate
uv pip install --force-reinstall .

Usage

Running diffprimer executes the full pipeline: finding unique regions -> designing primers -> verifying specificity.

Basic Command

diffprimer \
    --reference-file reference.fasta \
    --sequences-path genomes_directory/ \

Complete Example

diffprimer \
    --reference-file data/target_species.fasta \
    --sequences-path data/background_species/ \
    --annotation-path data/target_annotations.gff3 \
    --config-file primer3_config.ini \
    --min-region-length 200 \
    --cpus 8 \
    --check-specificity

Arguments Explained

Argument Short Description
--reference-file -r Required. Path to the target reference genome (FASTA).
--sequences-path -s Required. Directory containing background genomes (FASTA) to compare against. Regions found in these genomes will be excluded.
--annotation-path -a (Optional) GFF3 file for the reference. Used to annotate output regions with gene names + product info.
--config-file -c (Optional) Primer3 configuration file defining Tm, GC%, and size constraints.
--reference-max-abundance Maximum allowed frequency of a k-mer in the reference genome to be considered a candidate marker. Use 1 for strictly unique markers (default). Increasing this value allows markers that are repeated a few times in the reference. (Default: 1)
--kmer-size -k K-mer size for uniqueness check (Default: 21).
--min-region-length -m Minimum length of unique regions to keep (Default: 200 bp).
--check-specificity Highly Recommended. Enables the rigorous cryptographic check of primer specificity. Without this, primers are only designed on unique regions but not physically verified against off-targets.
--similarity-threshold Global similarity threshold (%) for off-target flagging (Default: 80.0).
--local-mismatch-threshold Positional mismatch score threshold for the local specificity check. Standard mismatches add 1, 3' end mismatches add 3 (configurable via --penalty-array). Default is 7, allowing up to 2 mismatches in the 3' region to still be considered non-specific (capable of amplifying).
--penalty-array Penalty values for mismatches. Provide a comma-separated list of 6 values. The first value is the penalty outside the 3' region. The next 5 values are the penalties for the 5 nucleotides of the 3' region. (Default: 1,3,3,3,3,3)

Output Format

The output is a CSV file containing one row per designed primer pair. Key columns include:

  • Sequence_Header: Contig/Region name.
  • Region_Start/End: Coordinates of the unique region.
  • Forward_Primer / Reverse_Primer (and _Tm, _GC, etc.): Primer details.
  • Specificity_Tag: The result of the specificity analysis (if --check-specificity is used).
    • Specific_LowGlobalSim: The region is globally unique; off-targets are extremely dissimilar, so primers are specific.
    • Specific_PositionalMismatches: The region has high global similarity to a background genome, BUT the primers themselves are specific because they have biological mismatches in critical locations (like the 3' end) that prevent binding.
    • NonSpecific_Amplification: The primers bind perfectly or near-perfectly to a similar region in a background genome resulting in cross-reactivity. Do NOT use.
    • Not_Checked: Specificity check was skipped.
  • Gene_Name / Product: Annotation info (if GFF3 provided).

Configuration

You can customize Primer3 settings by providing a file with --config-file. Example format:

PRIMER_OPT_SIZE=20
PRIMER_MIN_SIZE=18
PRIMER_MAX_SIZE=27
PRIMER_OPT_TM=60.0
PRIMER_MIN_TM=57.0
PRIMER_MAX_TM=63.0
PRIMER_MIN_GC=20.0
PRIMER_MAX_GC=80.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffprimer-0.1.2.tar.gz (471.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

diffprimer-0.1.2-cp39-abi3-win_amd64.whl (413.2 kB view details)

Uploaded CPython 3.9+Windows x86-64

diffprimer-0.1.2-cp39-abi3-win32.whl (386.3 kB view details)

Uploaded CPython 3.9+Windows x86

diffprimer-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (629.9 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

diffprimer-0.1.2-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (637.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ i686

diffprimer-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (590.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

diffprimer-0.1.2-cp39-abi3-macosx_11_0_arm64.whl (528.4 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

diffprimer-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl (538.4 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file diffprimer-0.1.2.tar.gz.

File metadata

  • Download URL: diffprimer-0.1.2.tar.gz
  • Upload date:
  • Size: 471.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for diffprimer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 df95720ad455fcdc9b85298b7e80d1e8ecb0eacc53d1bce2597a2f0d707a34c1
MD5 fb5f456ad5f5727d3d5e90d725fc058a
BLAKE2b-256 1bfa1efa7ff4fab079af05e46cedf22de60813665bd51986a776eec41ea64430

See more details on using hashes here.

File details

Details for the file diffprimer-0.1.2-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for diffprimer-0.1.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 baf97b143f89f9d7126f1712f1e4833d5cb8a57e4b46893ad209eabb0574b428
MD5 0031819fbc97d6793ce4c447db1f8c15
BLAKE2b-256 3cd0c42852e537869484a94fbf3de65e3e8f6a45708d7372125105fab3ef6efa

See more details on using hashes here.

File details

Details for the file diffprimer-0.1.2-cp39-abi3-win32.whl.

File metadata

  • Download URL: diffprimer-0.1.2-cp39-abi3-win32.whl
  • Upload date:
  • Size: 386.3 kB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for diffprimer-0.1.2-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 69fde84d7bee0be5651f22d5bbe7cda5d5c1dba69737525b9540af523120acc1
MD5 d42efd43154d9219ecbbbdca0fabd4d1
BLAKE2b-256 e952cc341e295977b11c0335488763b2c359caa4ce91cd653de6892fd7ee2916

See more details on using hashes here.

File details

Details for the file diffprimer-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for diffprimer-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2609fefc3c3af9b1c518f8dd6e531c219ce39e73fbc11b69d9d6b930a2743931
MD5 92fdb2b74f8c2a88d5c3f5aa811d7bb3
BLAKE2b-256 a7cf585b8afb213aa30fd1cc131c9135c89b6a248c3a03c92895bf269b15bc88

See more details on using hashes here.

File details

Details for the file diffprimer-0.1.2-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for diffprimer-0.1.2-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 c64943150afba720cdd34fd24e7c179eff649792bb05a329e5414e025da89e22
MD5 bc7aca9f8a6940d6343a14279c468ab3
BLAKE2b-256 e4bd63058b1ffe7c6f76951f84d8850d933745f720df602750278d5bb83255d0

See more details on using hashes here.

File details

Details for the file diffprimer-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for diffprimer-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a33f7403347ee59c403af8016cd9bb4a1b6f69cfd60e73a0d92e56bc47afc2f9
MD5 7e2b47b8e4724e0a7232b7da293c0b8e
BLAKE2b-256 d3c2225e3d296a29402c5ac07f1247dfa43db467731e7109e72abc713a86c51c

See more details on using hashes here.

File details

Details for the file diffprimer-0.1.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for diffprimer-0.1.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bd2d7a23834543788ddb538e66026da0a7ebf4955d8bd06a7ad4e8171d07a0c4
MD5 46e225b673b82fb53ce4cefb149ca263
BLAKE2b-256 5d0b89baf206538de9a7b0a80f78ec6935048649e08a220f2c8c40b4d98f761d

See more details on using hashes here.

File details

Details for the file diffprimer-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for diffprimer-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1d318c291bd92eb884caca4423b624f9abba4ffdce5b891d0be4e8e511b4bf1d
MD5 5d2fa5ceaae47d5f944c12eb339e1bd8
BLAKE2b-256 17dac50118472f5d4c78254842dbdfb65406f166f747cde4e9becf491401f37f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page