multiplexILP is an R package for designing multiplex PCR assays using Integer Linear Programming (ILP). It leverages mathematical optimization to select optimal primer sets, addressing key challenges such as primer compatibility, multi-channel fluorescence assignment, and amplicon size optimization in multiplex PCR experiments.
- Generate ILP models for single-primer and primer-pair selection strategies
- Parse solutions from popular ILP solvers (e.g., SCIP)
- Visualize selected primer pairs and channel assignments
- Support for multiple fluorescence channels, amplicon size ranges, and annealing temperature constraints
- Optimize constraints
- R (>= 3.5.0)
- A C++11 compatible compiler (GCC, Clang, or Rtools for Windows)
- SCIP Solver (>= 8.0.0) Download
- #conda install --channel conda-forge scip
# Install CRAN packages
install.packages(c("Rcpp", "ggplot2", "dplyr", "stringr", "devtools"))# From GitHub (replace 'username' with actual repo owner)
library(devtools)
install_github("limeng12/multiplexILP")library(multiplexILP)
# Generate simulated data
primer_single_data <- generate_single_primer_data(
n_primers = 150,
n_loci = 10,
num_channels = 2,
size_gap = 10,
seed = 123
)
View( as.data.frame(primer_single_data[1:9]))
# Generate ILP model
ilp_result <- gen_ilp_single_primer(primer_single_data)
# Solve with SCIP (ensure SCIP is in PATH)
unlink("sol.txt")
system(paste0("scip -f ", ilp_result$lp_file, " -l sol.txt"))
# Parse results
parsed_results <- parse_scip_single_primer_solution(
scip_output_file = "sol.txt",
primers_info_file = ilp_result$primers_info_file,
output_prefix = "single_primer_analysis"
)
# Visualize
plots <- generate_simple_plots(parsed_results$selected_primer_pairs, "single_primer_report")
plots$amplicon_plotlibrary(multiplexILP)
# Generate simulated data
primer_pair_data <- generate_primer_pair_data(
n_pairs = 500,
n_loci = 6,
num_channels = 2,
size_gap = 10,
seed = 1123
)
View( as.data.frame(primer_pair_data[1:12]))
# Generate ILP model
ilp_result <- gen_ilp_primer_pair(primer_pair_data, lower_bound = 0)
# Solve with SCIP
unlink("sol.txt")
system(paste0("scip -f ", ilp_result$lp_file, " -l sol.txt"))
# Parse results
parsed_results <- parse_scip_locus_C_kt_solution(
scip_output_file = "sol.txt",
primers_info_file = ilp_result$primers_info_file,
output_prefix = "primer_pair_analysis"
)
# Visualize
plots <- generate_simple_plots(parsed_results$selected_primers, "primer_pair_report")
plots$amplicon_plot- Many MIPs have a large number of constraints of the type X + Y <= 1. For any number of such constraints, very high compression ratios can be achieved without altering the original meaning of the constraints using independent set trick.
library(multiplexILP)
library(stringr)
gen_cons<-function(n=20, percent=0.8){
result <- expand.grid(i = 1:(n-1), j = 1:(n-1));
result <- result[result$j > result$i, ];
x <- result$i;
y <- result$j;
n_keep <- floor(length(x) * percent) # 保留90%
keep_idx <- sample(length(x), n_keep) # 随机选择要保留的位置
x_trimmed <- x[keep_idx]
y_trimmed <- y[keep_idx]
cons<-str_c("X", x_trimmed," + X", y_trimmed," <= 1")
unique(cons)
}
# Generate raw constraints randomly
raw_constraints <- gen_cons(n = 60, percent = 0.9)
# Optimize constraints
optimized_cons <- convert_constraints(raw_constraints)
cat("Original:", length(raw_constraints), "constraints\n")
cat("Original (10):", (raw_constraints)[1:10], sep = "\n")
cat("Optimized:", length(optimized_cons), "constraints\n")
cat("Optimized (5):", (optimized_cons)[1:5], sep = "\n")| Variable | Type | Description |
|---|---|---|
| Binary | Indicates if primer |
|
| Binary | Indicates if locus |
|
| Binary | Assigns locus |
|
| Binary | Indicates if loci |
| Variable | Type | Description |
|---|---|---|
| Binary | Indicates if primer pair |
|
| Binary | Assigns locus |
|
| Binary | Indicates if loci |
|
| Binary | Indicates if locus |
The package generates the following files:
-
.tsv: Primer information file with indices and properties -
.lp: ILP model file for SCIP solver -
.txt: Parsed solution file with selected primers/channels -
.pdf: Visual report of amplicon sizes and channel assignments
-
SCIP not found: Ensure SCIP is installed and the
scipexecutable is in your systemPATH. -
Compilation errors: Verify a C++11 compiler is installed and configured with R.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.


