def calculate_sv_bins(*items): """Determine bin sizes and regions to use for samples. Unified approach to prepare regional bins for coverage calculations across multiple CNV callers. Splits into target and antitarget regions allowing callers to take advantage of both. Provides consistent target/anti-target bin sizes across batches. Uses callable_regions as the access BED file and mosdepth regions in variant_regions to estimate depth for bin sizes. """ from bcbio.structural import cnvkit if all(not cnvkit.use_general_sv_bins(utils.to_single_data(x)) for x in items): return items items = [utils.to_single_data(x) for x in items] out = [] for cnv_group in _group_by_cnv_method(multi.group_by_batch(items, False)): size_calc_fn = MemoizedSizes(cnv_group.region_file, cnv_group.items).get_target_antitarget_bin_sizes for data in cnv_group.items: target_bed, anti_bed = cnvkit.targets_w_bins(cnv_group.region_file, cnv_group.access_file, size_calc_fn, cnv_group.work_dir, data) if not data.get("regions"): data["regions"] = {} data["regions"]["bins"] = {"target": target_bed, "antitarget": anti_bed} out.append([data]) if not len(out) == len(items): raise AssertionError("Inconsistent samples in and out of SV bin calculation:\nout: %s\nin : %s" % (sorted([dd.get_sample_name(utils.to_single_data(x)) for x in out]), sorted([dd.get_sample_name(x) for x in items]))) return out
def _calculate_sv_bins_cnvkit(data, cnv_group, size_calc_fn): """Calculate structural variant bins using target/anti-target approach from CNVkit. """ from bcbio.structural import cnvkit if dd.get_background_cnv_reference(data, "cnvkit"): target_bed, anti_bed = cnvkit.targets_from_background(dd.get_background_cnv_reference(data, "cnvkit"), cnv_group.work_dir, data) else: target_bed, anti_bed = cnvkit.targets_w_bins(cnv_group.region_file, cnv_group.access_file, size_calc_fn, cnv_group.work_dir, data) return target_bed, anti_bed, None
def _calculate_sv_bins_cnvkit(data, cnv_group, size_calc_fn): """Calculate structural variant bins using target/anti-target approach from CNVkit. """ from bcbio.structural import cnvkit if dd.get_background_cnv_reference(data, "cnvkit"): target_bed, anti_bed = cnvkit.targets_from_background(dd.get_background_cnv_reference(data, "cnvkit"), cnv_group.work_dir, data) else: target_bed, anti_bed = cnvkit.targets_w_bins(cnv_group.region_file, cnv_group.access_file, size_calc_fn, cnv_group.work_dir, data) return target_bed, anti_bed, None
def calculate_sv_bins(*items): """Determine bin sizes and regions to use for samples. Unified approach to prepare regional bins for coverage calculations across multiple CNV callers. Splits into target and antitarget regions allowing callers to take advantage of both. Provides consistent target/anti-target bin sizes across batches. Uses callable_regions as the access BED file and mosdepth regions in variant_regions to estimate depth for bin sizes. """ from bcbio.structural import cnvkit if all(not cnvkit.use_general_sv_bins(utils.to_single_data(x)) for x in items): return items items = [utils.to_single_data(x) for x in items] out = [] for batch, batch_items in multi.group_by_batch(items, False).items(): work_dir = utils.safe_makedir( os.path.join(dd.get_work_dir(items[0]), "structural", "bins", batch)) access_file = tz.get_in(["config", "algorithm", "callable_regions"], batch_items[0]) cnv_file = get_base_cnv_regions(batch_items[0], work_dir, "transcripts100", include_gene_names=False) target_bin, anti_bin = _get_target_antitarget_bin_sizes( cnv_file, items) for data in batch_items: target_bed, anti_bed = cnvkit.targets_w_bins( cnv_file, access_file, target_bin, anti_bin, work_dir, data) if not data.get("regions"): data["regions"] = {} data["regions"]["bins"] = { "target": target_bed, "antitarget": anti_bed } out.append([data]) if not len(out) == len(items): raise AssertionError( "Inconsistent samples in and out of SV bin calculation:\nout: %s\nin : %s" % (sorted( [dd.get_sample_name(utils.to_single_data(x)) for x in out]), sorted([dd.get_sample_name(x) for x in items]))) return out