Apply VQSR based on the specified tranche, returning a filtered VCF file.

def _apply_vqsr(in_file, ref_file, recal_file, tranch_file,
                sensitivity_cutoff, filter_type, data):
    """Apply VQSR based on the specified tranche, returning a filtered VCF file.
    """
    base, ext = utils.splitext_plus(in_file)
    out_file = "{base}-{filter}filter{ext}".format(base=base, ext=ext,
                                                   filter=filter_type)
    if not utils.file_exists(out_file):
        with file_transaction(data, out_file) as tx_out_file:
            broad_runner = broad.runner_from_config(data["config"])
            gatk_type = broad_runner.gatk_type()
            if gatk_type == "gatk4":
                params = ["-T", "ApplyVQSR",
                          "--variant", in_file,
                          "--output", tx_out_file,
                          "--recal-file", recal_file,
                          "--tranches-file", tranch_file]
            else:
                params = ["-T", "ApplyRecalibration",
                          "--input", in_file,
                          "--out", tx_out_file,
                          "--recal_file", recal_file,
                          "--tranches_file", tranch_file]
            params += ["-R", ref_file,
                       "--mode", filter_type]
            resources = config_utils.get_resources("gatk_apply_recalibration", data["config"])
            opts = resources.get("options", [])
            if not opts:
                if gatk_type == "gatk4":
                    opts += ["--truth-sensitivity-filter-level", sensitivity_cutoff]
                else:
                    opts += ["--ts_filter_level", sensitivity_cutoff]
            params += opts
            broad_runner.run_gatk(params)
    return out_file