K-Dense-AI/scientific-agent-skills / skills/primer-design
primer-design
VerifiedDesigns and audits PCR and RT-qPCR primers with Primer3, explicit thermodynamic conditions, reference-based off-target amplification searches, and traceable sequence coordinates. Use for designing primer pairs, checking existing primers, exon-junction or isoform-specific assays, variant masking, cloning tails, multiplex compatibility, and interpreting Primer-BLAST results. Includes bounded local in-silico PCR and BLAST screening; distinguishes computational candidates from experimentally validated assays.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 16.0 KB |
| assets/assay-report-template.md | markdown | 2.4 KB |
| assets/demo-template.fasta | other | 577 B |
| assets/qpcr-config.json | config | 233 B |
| assets/requirements.txt | manifest | 18 B |
| references/design-workflows.md | markdown | 10.3 KB |
| references/input-contract.md | markdown | 11.6 KB |
| references/sources.md | markdown | 4.4 KB |
| references/specificity.md | markdown | 10.3 KB |
| references/thermodynamics.md | markdown | 7.0 KB |
| scripts/_common.py | script | 5.5 KB |
| scripts/_specificity.py | script | 20.1 KB |
| scripts/check_thermodynamics.py | script | 8.5 KB |
| scripts/design_primers.py | script | 15.3 KB |
| scripts/screen_specificity.py | script | 10.7 KB |
scripts/_common.py
View on GitHub"""Validated local inputs and provenance shared by primer-design tools."""
from __future__ import annotations
import csv
import hashlib
import json
import math
import os
import re
import tempfile
from pathlib import Path
IUPAC = "ACGTRYSWKMBDHVN"
PAIR_FIELDS = ("pair_id", "forward", "reverse", "forward_tail", "reverse_tail")
def dna(value: str, label: str, *, ambiguous: bool = False, empty: bool = False) -> str:
if not isinstance(value, str):
raise ValueError(f"{label}: sequence must be a string")
seq = value.strip().upper()
if (not seq and not empty) or any(c not in (IUPAC if ambiguous else "ACGT") for c in seq):
raise ValueError(f"{label}: expected {'IUPAC' if ambiguous else 'ACGT'} DNA, 5-prime to 3-prime, without internal whitespace")
return seq
def revcomp(seq: str) -> str:
return seq.translate(str.maketrans(IUPAC, "TGCAYRSWMKVHDBN"))[::-1]
def read_fasta(path) -> dict[str, str]:
records, chunks, current = {}, [], None
with Path(path).open(encoding="utf-8-sig") as handle:
for number, raw in enumerate(handle, 1):
line = raw.strip()
if not line:
continue
if line.startswith(">"):
if current is not None:
records[current] = dna("".join(chunks), current, ambiguous=True)
current = line[1:].split()[0] if line[1:].split() else ""
if not current or current in records:
raise ValueError(f"FASTA line {number}: empty or duplicate record ID")
chunks = []
else:
if current is None:
raise ValueError(f"FASTA line {number}: sequence before header")
chunks.append(line)
if current is not None:
records[current] = dna("".join(chunks), current, ambiguous=True)
if not records:
raise ValueError("FASTA contains no records")
return records
def read_pairs(path) -> list[dict[str, str]]:
with Path(path).open(newline="", encoding="utf-8-sig") as handle:
reader = csv.DictReader(handle, delimiter="\t")
header = reader.fieldnames or []
if len(set(header)) != len(header) or not {"pair_id", "forward", "reverse"} <= set(header):
raise ValueError("Pair TSV needs unique columns pair_id, forward, reverse; optional forward_tail, reverse_tail")
if set(header) - set(PAIR_FIELDS):
raise ValueError(f"Unknown pair TSV columns: {sorted(set(header) - set(PAIR_FIELDS))}")
result, seen = [], set()
for number, row in enumerate(reader, 2):
if None in row or any(v is None for v in row.values()):
raise ValueError(f"Pair TSV line {number}: wrong column count")
pair_id = row["pair_id"].strip()
if not re.fullmatch(r"[A-Za-z0-9_.-]+", pair_id) or pair_id in seen:
raise ValueError(f"Pair TSV line {number}: duplicate or invalid pair_id")
seen.add(pair_id)
result.append({"pair_id": pair_id, **{
field: dna(row.get(field, ""), f"{pair_id}.{field}", empty=field.endswith("_tail"))
for field in PAIR_FIELDS[1:]
}})
if not result:
raise ValueError("Pair TSV contains no primer pairs")
return result
def sha256_file(path) -> str:
digest = hashlib.sha256()
with Path(path).open("rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def check_output_paths(inputs, outputs):
sources = {Path(p).resolve() for p in inputs if p is not None}
destinations = [Path(p).resolve() for p in outputs if p is not None]
if len(set(destinations)) != len(destinations) or sources.intersection(destinations):
raise ValueError("Output paths must be distinct from each other and all inputs")
paths = list(sources) + destinations
for index, path in enumerate(paths):
if path.exists():
for other in paths[index + 1:]:
if other.exists() and path.samefile(other):
raise ValueError("Output paths must not be hardlink aliases of inputs or other outputs")
def write_json(path, data):
"""Replace a complete JSON document atomically, never serialize NaN/Infinity."""
destination = Path(path)
serialized = json.dumps(data, indent=2, allow_nan=False) + "\n"
destination.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", dir=destination.parent, delete=False) as handle:
temporary = Path(handle.name)
handle.write(serialized)
try:
os.replace(temporary, destination)
finally:
temporary.unlink(missing_ok=True)
def load_primer3():
try:
import primer3
except ImportError as exc:
raise ValueError("primer3-py is not installed; install primer3-py==2.3.1 in an isolated environment") from exc
return primer3
def finite_number(value, name, minimum=0, *, positive=False):
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value):
raise ValueError(f"{name} must be a finite number")
if value < minimum or (positive and value == minimum):
raise ValueError(f"{name} must be {'greater than' if positive else 'at least'} {minimum}")
return value
def integer(value, name, minimum=0):
if isinstance(value, bool) or not isinstance(value, int) or value < minimum:
raise ValueError(f"{name} must be an integer >= {minimum}")
return value
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |