Annotate a VCF file with dbSNP.

    vcfanno has flexible matching for NON_REF gVCF positions, matching
    at position and REF allele, matching ALT NON_REF as a wildcard.

def _add_dbsnp(orig_file, dbsnp_file, data, out_file=None, post_cl=None):
    """Annotate a VCF file with dbSNP.

    vcfanno has flexible matching for NON_REF gVCF positions, matching
    at position and REF allele, matching ALT NON_REF as a wildcard.
    """
    orig_file = vcfutils.bgzip_and_index(orig_file, data["config"])
    if out_file is None:
        out_file = "%s-wdbsnp.vcf.gz" % utils.splitext_plus(orig_file)[0]
    if not utils.file_uptodate(out_file, orig_file):
        with file_transaction(data, out_file) as tx_out_file:
            conf_file = os.path.join(os.path.dirname(out_file), "dbsnp.conf")
            with open(conf_file, "w") as out_handle:
                out_handle.write(_DBSNP_TEMPLATE % os.path.normpath(os.path.join(dd.get_work_dir(data), dbsnp_file)))
            if not post_cl: post_cl = ""
            cores = dd.get_num_cores(data)
            cmd = ("vcfanno -p {cores} {conf_file} {orig_file} | {post_cl} "
                   "bgzip -c > {tx_out_file}")
            do.run(cmd.format(**locals()), "Annotate with dbSNP")
    return vcfutils.bgzip_and_index(out_file, data["config"])