Commit 3a543ec9 authored by Sander Bollen's avatar Sander Bollen
Browse files

Add option to ignore errors

parent b9d0c2e1
......@@ -18,6 +18,11 @@ REGION_XSD = os.path.join(os.path.join(os.path.dirname(__file__), "static"), 're
from .models import *
from .utils import calc_gc, datehash
try:
from itertools import zip_longest as longzip
except ImportError:
from itertools import izip_longest as longzip
def miracle_to_primer_and_var(xml, xsd=DEFAULT_XSD):
with open(xsd, "rb") as xsd_handle:
......@@ -156,6 +161,27 @@ def common_xml(miracle_id, paneldatum, panel=True, old=True):
return document, results
def primer_to_xml(root, prim, var):
primer_f = etree.SubElement(root, "PRIMER_F")
f_code = etree.SubElement(primer_f, "CODE")
f_code.text = var.gene_id + "_F." + datehash()
f_seq = etree.SubElement(primer_f, "SEQUENTIE")
f_seq.text = prim.left
f_loc = etree.SubElement(primer_f, "COORDINATE")
f_loc.text = str(prim.left_pos)
primer_r = etree.SubElement(root, "PRIMER_R")
r_code = etree.SubElement(primer_r, "CODE")
r_code.text = var.gene_id + "_R." + datehash()
r_seq = etree.SubElement(primer_r, "SEQUENTIE")
r_seq.text = prim.right
r_loc = etree.SubElement(primer_r, "COORDINATE")
r_loc.text = str(prim.right_pos)
return root
def vars_and_primers_to_xml(variants, primers, xml_path=None, xsd=DEFAULT_XSD, old=True):
panel = int(variants[0].in_gene_panel) == 1
......@@ -167,7 +193,7 @@ def vars_and_primers_to_xml(variants, primers, xml_path=None, xsd=DEFAULT_XSD, o
document, results = common_xml(variants[0].miracle_id, variants[0].datum, panel, old=old)
i = 1
for var, prim in zip(variants, primers):
for var, prim in longzip(variants, primers, fillvalue=None):
uitslag = etree.SubElement(results, "UITSLAG")
variant = etree.SubElement(uitslag, "VARIANT")
......@@ -215,33 +241,23 @@ def vars_and_primers_to_xml(variants, primers, xml_path=None, xsd=DEFAULT_XSD, o
variation_prot.text = var.variant_on_transcript_protein
prims = etree.SubElement(variant, "PRIMERS")
frag_len = etree.SubElement(prims, "FRAGMENT_LENGTH")
# fragment is the region between the end of the forward primer, and the start of the reverse primer
frag_len.text = str(int(prim.right_pos) - (int(prim.left_pos) + len(prim.left)))
if prim is not None:
prims = primer_to_xml(prims, prim, var)
frag_len = etree.SubElement(prims, "FRAGMENT_LENGTH")
# fragment is the region between the end of the forward primer, and the start of the reverse primer
gc_perc = etree.SubElement(prims, "GC_PERC")
frag_len.text = str(int(prim.right_pos) - (int(prim.left_pos) + len(prim.left)))
try:
gc_perc.text = str(int(calc_gc(prim.fragment_sequence)))
except ValueError:
gc_perc.text = '0'
gc_perc = etree.SubElement(prims, "GC_PERC")
primer_f = etree.SubElement(prims, "PRIMER_F")
f_code = etree.SubElement(primer_f, "CODE")
f_code.text = var.gene_id + "_F." + datehash()
f_seq = etree.SubElement(primer_f, "SEQUENTIE")
f_seq.text = prim.left
f_loc = etree.SubElement(primer_f, "COORDINATE")
f_loc.text = str(prim.left_pos)
primer_r = etree.SubElement(prims, "PRIMER_R")
r_code = etree.SubElement(primer_r, "CODE")
r_code.text = var.gene_id + "_R." + datehash()
r_seq = etree.SubElement(primer_r, "SEQUENTIE")
r_seq.text = prim.right
r_loc = etree.SubElement(primer_r, "COORDINATE")
r_loc.text = str(prim.right_pos)
try:
gc_perc.text = str(int(calc_gc(prim.fragment_sequence)))
except ValueError:
gc_perc.text = '0'
else:
comment = etree.SubElement(uitslag, "OPMERKING")
comment.text = "NO PRIMERS FOUND"
denovo = etree.SubElement(uitslag, "DE_NOVO")
if var.variant_on_genome_origin == "De novo":
......
......@@ -11,7 +11,7 @@ import argparse
from prinia.lovd import *
from prinia.design import *
from prinia.miracle_xml import vars_and_primers_to_xml, regions_and_primers_to_xml
from prinia.utils import generate_fastq_from_primers
from prinia.utils import generate_fastq_from_primers, NoPrimersException
__author__ = 'ahbbollen'
......@@ -19,19 +19,25 @@ __author__ = 'ahbbollen'
def primers_from_lovd(lovd_file, padding, product_size, n_prims, reference,
blat_exe, primer3_exe, dbsnp, field, max_freq,
m13=False, m13_f="", m13_r="", strict=False,
min_margin=10):
min_margin=10, ignore_errors=False):
variants = var_from_lovd(lovd_file)
primers = []
for var in variants:
region = Region.from_variant(var, padding_l=padding, padding_r=padding)
_, prims = get_primer_from_region(region, reference, product_size,
try:
_, prims = get_primer_from_region(region, reference, product_size,
n_prims, blat_exe, primer3_exe,
dbsnp=dbsnp, field=field,
max_freq=max_freq,
strict=strict,
min_margin=min_margin)
primers.append(prims[0])
primers.append(prims[0])
except NoPrimersException:
if ignore_errors:
continue
else:
raise NoPrimersException
if m13:
primers = m13_primers(primers, m13_f, m13_r)
......@@ -154,6 +160,8 @@ def main():
parser.add_argument('--primer3', help="Path to primer3_core exe", default=None, required=True)
parser.add_argument('--blat', help="Path to blat exe", default=None, required=True)
parser.add_argument("--ignore-errors", help="Ignore errors", action="store_true")
args = parser.parse_args()
if not args.lovd and not args.region:
......@@ -179,7 +187,8 @@ def main():
args.m13, args.m13_forward,
args.m13_reverse,
args.strict,
args.min_margin)
args.min_margin,
args.ignore_errors)
primers_to_xml(variants, primers, args.xml, type='variants')
elif args.region and args.xml:
......@@ -205,7 +214,8 @@ def main():
args.m13, args.m13_forward,
args.m13_reverse,
args.strict,
args.min_margin)
args.min_margin,
args.ignore_errors)
primers_to_tsv(variants, primers, args.tsv, type='variants')
elif args.region and args.tsv:
......
......@@ -44,9 +44,9 @@
<xs:element name="PRIMERS">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:short" name="FRAGMENT_LENGTH"/>
<xs:element type="xs:byte" name="GC_PERC"/>
<xs:element name="PRIMER_F">
<xs:element type="xs:short" name="FRAGMENT_LENGTH" minOccurs="0"/>
<xs:element type="xs:byte" name="GC_PERC" minOccurs="0"/>
<xs:element name="PRIMER_F" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="CODE"/>
......@@ -55,7 +55,7 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PRIMER_R">
<xs:element name="PRIMER_R" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="CODE"/>
......@@ -70,6 +70,7 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="OPMERKING" minOccurs="0"/>
<xs:element type="xs:string" name="DE_NOVO"/>
<xs:element type="xs:string" name="PATERNAAL"/>
<xs:element type="xs:string" name="MATERNAAL"/>
......
......@@ -44,9 +44,9 @@
<xs:element name="PRIMERS">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:short" name="FRAGMENT_LENGTH"/>
<xs:element type="xs:byte" name="GC_PERC"/>
<xs:element name="PRIMER_F">
<xs:element type="xs:short" name="FRAGMENT_LENGTH" minOccurs="0"/>
<xs:element type="xs:byte" name="GC_PERC" minOccurs="0"/>
<xs:element name="PRIMER_F" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="CODE"/>
......@@ -55,7 +55,7 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PRIMER_R">
<xs:element name="PRIMER_R" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="CODE"/>
......@@ -70,6 +70,7 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="OPMERKING" minOccurs="0"/>
<xs:element type="xs:string" name="DE_NOVO"/>
<xs:element type="xs:string" name="PATERNAAL"/>
<xs:element type="xs:string" name="MATERNAAL"/>
......
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