Skip to content

Commit

Permalink
Add json output (--json)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjtimmons committed Nov 12, 2022
1 parent 095b3a1 commit b33bc33
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 80 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ print(fwd.tm_total) # 70.0
### CLI

```txt
$ dir tm ttm dg pen seq
FWD 60.8 67.0 -1.86 5.93 GGTCTCAATGAGACAATAGCACACAC
REV 60.8 65.8 0 3.2 GAAGACTTTCGTATGCTGACCTAG
$ primers AATGAGACAATAGCACACACAGCTAGGTCAGCATACGAAA -f GGTCTC -r GAAGAC
dir tm ttm dg pen seq
FWD 61.8 67.6 -1.86 5.23 GGTCTCAATGAGACAATAGCACACACA
REV 61.9 66.5 -0.88 4.85 GAAGACTTTCGTATGCTGACCTAGC
```

```txt
Expand All @@ -50,14 +51,14 @@ usage: primers [-h] [-f SEQ] [-fl INT INT] [-r SEQ] [-rl INT INT] [-t SEQ] [--ve
Create PCR primers for a DNA sequence.
Logs the FWD and REV primer with columns:
dir, tm, ttm, dg, pen, seq
dir, tm, ttm, dg, p, seq
Where:
dir = FWD or REV.
tm = Melting temperature of the annealing/binding part of the primer (Celsius).
ttm = The total melting temperature of the primer with added seq (Celsius).
dg = The minimum free energy of the primer's secondary structure (kcal/mol).
pen = The primer's penalty score. Lower is better.
p = The primer's penalty score. Lower is better.
seq = The sequence of the primer in the 5' to the 3' direction.
positional arguments:
Expand Down
37 changes: 31 additions & 6 deletions primers/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Console entrypoint for creating PCR primers"""

import argparse
import json
import sys
from typing import List

from . import __version__, primers
from .primers import PRIMER_FMT


"""{fwd} {tm} {tm_total} {gc} {dg} {penalty} {seq}"""


def run():
Expand All @@ -25,9 +28,24 @@ def run():
offtarget_check=args.t,
)

print(PRIMER_FMT.format("dir", "tm", "ttm", "dg", "pen", "seq"))
print(fwd)
print(rev)
if args.json:
print(json.dumps([fwd.dict(), rev.dict()]))
else:
table_fmt = "{:>5} {:>5} {:>5} {:>3} {:>6} {:>5} {}"
print(table_fmt.format("dir", "tm", "ttm", "gc", "dg", "p", "seq"))

for p in [fwd, rev]:
print(
table_fmt.format(
"FWD" if p.fwd else "REV",
p.tm,
p.tm_total,
p.gc,
p.dg,
p.scoring.penalty,
p.seq,
)
)


def parse_args(args: List[str]) -> argparse.Namespace:
Expand All @@ -46,13 +64,14 @@ def parse_args(args: List[str]) -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="""Create PCR primers for a DNA sequence.
Logs the FWD and REV primer with columns:
dir, tm, ttm, dg, pen, seq
By default, the primers are logged in table format in rows:
dir, tm, ttm, gc, dg, pen, seq
Where:
dir = FWD or REV.
tm = The melting temperature of the annealing portion of the primer (Celsius).
ttm = The total melting temperature of the primer with added seq (Celsius).
gc = The GC ratio of the primer.
dg = The minimum free energy of the primer (kcal/mol).
pen = The primer's penalty score. Lower is better.
seq = The sequence of the primer in the 5' to the 3' direction.
Expand Down Expand Up @@ -98,6 +117,12 @@ def parse_args(args: List[str]) -> argparse.Namespace:
default="",
metavar="SEQ",
)
parser.add_argument(
"-j",
"--json",
action=argparse.BooleanOptionalAction,
help="whether to write the primers in a JSON array",
)
parser.add_argument(
"--version", action="version", version="seqfold {ver}".format(ver=__version__)
)
Expand Down
6 changes: 3 additions & 3 deletions primers/offtargets.py → primers/off_targets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Find offtargets.
"""Find off-target binding sites.
"""

from collections import defaultdict
from typing import List, Dict


def offtargets(seq: str, check_seq: str) -> List[int]:
"""Return a list of offtarget counts for primers whose end is that index.
def off_targets(seq: str, check_seq: str) -> List[int]:
"""Return a list of off-target counts for primers whose end is that index.
For example, offtarget_cache[20] -> returns the number of offtarget binding
sites whose last bp ends in the 20th index of `seq`
Expand Down
Loading

0 comments on commit b33bc33

Please sign in to comment.