Commit 0f4f8bd0 authored by Sander Bollen's avatar Sander Bollen
Browse files

thermodynamic params in tool.

parent ec1b3935
......@@ -65,6 +65,7 @@ usage: primerdesign [-h] (-l LOVD | --region REGION) [-p PADDING]
[-f FIELD] [-af ALLELE_FREQ] [-fq1 FQ1] [-fq2 FQ2] -R
REFERENCE [--dbsnp DBSNP] --primer3 PRIMER3 [--bwa BWA]
[--samtools SAMTOOLS] [--settings-json SETTINGS_JSON]
[--thermodynamic-params THERMODYNAMIC_PARAMS]
[--ignore-errors]
optional arguments:
......@@ -106,6 +107,9 @@ optional arguments:
--samtools SAMTOOLS Path to samtools exe
--settings-json SETTINGS_JSON
Optional path to primer3 settings json file.
--thermodynamic-params THERMODYNAMIC_PARAMS
Optional path to primer3 thermodynamic parameters
location
--ignore-errors Ignore errors
```
......
......@@ -33,7 +33,7 @@ def get_sequence_fasta(region, reference=None, padding=True):
def run_primer3(sequence, region, primer3_exe: str, settings_dict: dict,
padding=True):
padding=True, thermodynamic_params: Optional[Path] = None):
"""Run primer 3. All other kwargs will be passed on to primer3"""
if padding:
target_start = region.padding_left
......@@ -44,7 +44,8 @@ def run_primer3(sequence, region, primer3_exe: str, settings_dict: dict,
target = ",".join(map(str, [target_start, target_len]))
p3 = Primer3(primer3_exe, sequence, target, target, settings_dict)
p3 = Primer3(primer3_exe, sequence, target, target, settings_dict,
thermodynamic_params=thermodynamic_params)
p3_out = p3.run()
primers = parse_primer3_output(p3_out)
return primers
......@@ -374,7 +375,8 @@ def get_primer_from_region(region, reference, bwa_exe,
samtools_exe, primer3_exe,
output_bam=None, dbsnp=None, field=None,
max_freq=None, strict=False, min_margin=10,
settings_json: Optional[Path] = None):
settings_json: Optional[Path] = None,
thermodynamic_params: Optional[Path] = None):
"""**prim_args will be passed on to primer3"""
settings_dict = parse_settings(settings_json)
......@@ -391,7 +393,8 @@ def get_primer_from_region(region, reference, bwa_exe,
for reg in regions:
sequence = get_sequence_fasta(reg, reference=reference)
raw_primers = run_primer3(sequence, reg, primer3_exe,
settings_dict, padding=True)
settings_dict, padding=True,
thermodynamic_params=thermodynamic_params)
bam = aln_primers(raw_primers, bwa_exe=bwa_exe,
samtools_exe=samtools_exe,
ref=reference, output_bam=output_bam)
......
......@@ -93,19 +93,26 @@ class Primer3(object):
def __init__(self, primer3_exe: str, template: str,
target: str, excluded_region: str,
settings_dict: dict):
settings_dict: dict,
thermodynamic_params: Optional[Path] = None):
self.primer3_exe = primer3_exe
self.template = template
self.target = target
self.excluded_region = excluded_region
self.settings_dict = settings_dict
self.thermodynamic_params = thermodynamic_params
def run(self):
cfg = NamedTemporaryFile(delete=False, mode="w")
out = NamedTemporaryFile()
cfg.write(create_primer3_config(self.settings_dict, self.template,
self.target, self.excluded_region))
settings = create_primer3_config(
self.settings_dict, self.template,
self.target, self.excluded_region,
thermodynamic_params=self.thermodynamic_params
)
cfg.write(settings)
cfg.close()
args = [self.primer3_exe, "-output", out.name, cfg.name]
......
......@@ -22,7 +22,8 @@ def primers_from_lovd(lovd_file, padding, reference, bwa_exe, samtools_exe,
primer3_exe, output_bam, dbsnp, field, max_freq,
m13=False, m13_f="", m13_r="", strict=False,
min_margin=10, ignore_errors=False,
settings_json: Optional[Path] = None):
settings_json: Optional[Path] = None,
thermodynamic_params: Optional[Path] = None):
"""**prim_args will be passed on to primer3"""
variants = var_from_lovd(lovd_file)
......@@ -38,7 +39,8 @@ def primers_from_lovd(lovd_file, padding, reference, bwa_exe, samtools_exe,
dbsnp=dbsnp, field=field,
max_freq=max_freq, strict=strict,
min_margin=min_margin,
settings_json=settings_json)
settings_json=settings_json,
thermodynamic_params=thermodynamic_params) # noqa
primers.append(prims[0])
except NoPrimersException:
if ignore_errors:
......@@ -55,7 +57,8 @@ def primers_from_region(bed_path, padding, reference, bwa_exe, samtools_exe,
primer3_exe, output_bam, dbsnp, field, max_freq,
m13=False, m13_f="", m13_r="", strict=False,
min_margin=10, ignore_errors=False,
settings_json: Optional[Path] = None):
settings_json: Optional[Path] = None,
thermodynamic_params: Optional[Path] = None):
"""**prim_args will be passed on to primer3"""
regions = []
primers = []
......@@ -75,7 +78,8 @@ def primers_from_region(bed_path, padding, reference, bwa_exe, samtools_exe,
max_freq=max_freq,
strict=strict,
min_margin=min_margin,
settings_json=settings_json) # noqa
settings_json=settings_json, # noqa
thermodynamic_params=thermodynamic_params) # noqa
regions += regs
primers += prims
except NoPrimersException:
......@@ -202,6 +206,10 @@ def main():
parser.add_argument('--settings-json', type=Path, default=None,
required=False,
help="Optional path to primer3 settings json file.")
parser.add_argument("--thermodynamic-params", type=Path, default=None,
required=False,
help="Optional path to primer3 thermodynamic"
" parameters location")
parser.add_argument("--ignore-errors", help="Ignore errors",
action="store_true")
......@@ -236,7 +244,8 @@ def main():
"strict": args.strict,
"min_margin": args.min_margin,
"ignore_errors": args.ignore_errors,
"settings_json": args.settings_json
"settings_json": args.settings_json,
"thermodynamic_params": args.thermodynamic_params
}
if args.lovd and args.xml:
......
......@@ -155,7 +155,7 @@ def conf_params():
def test_primer3_conf_with_params(conf_params):
some_path = Path("/some/path/to/params")
generated_conf = create_primer3_config(
parse_settings(),"ACTG", "50-60", "50-60",
parse_settings(), "ACTG", "50-60", "50-60",
thermodynamic_params=some_path)
with conf_params.open("r") as chandle:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment