def _add_bed_to_output(out, data): """Call ploidy and convert into BED representation. """ call_file = "%s-call%s" % os.path.splitext(out["cns"]) gender = dd.get_gender(data) if not utils.file_exists(call_file): with file_transaction(data, call_file) as tx_call_file: cmd = [os.path.join(os.path.dirname(sys.executable), "cnvkit.py"), "call", "--ploidy", str(dd.get_ploidy(data)), "-o", tx_call_file, out["cns"]] if gender: cmd += ["--gender", gender] if gender.lower() == "male": cmd += ["--male-reference"] do.run(cmd, "CNVkit call ploidy") out_file = "%s.bed" % os.path.splitext(call_file)[0] if not utils.file_exists(out_file): with file_transaction(data, out_file) as tx_out_file: cmd = [os.path.join(os.path.dirname(sys.executable), "cnvkit.py"), "export", "bed", "--sample-id", dd.get_sample_name(data), "--ploidy", str(dd.get_ploidy(data)), "-o", tx_out_file, call_file] if gender and gender.lower() == "male": cmd += ["--male-reference"] do.run(cmd, "CNVkit export BED") out["call_file"] = call_file out["vrn_file"] = annotate.add_genes(out_file, data) return out
def _add_variantcalls_to_output(out, data): """Call ploidy and convert into VCF and BED representations. """ call_file = "%s-call%s" % os.path.splitext(out["cns"]) gender = dd.get_gender(data) if not utils.file_exists(call_file): with file_transaction(data, call_file) as tx_call_file: cmd = [os.path.join(os.path.dirname(sys.executable), "cnvkit.py"), "call", "--ploidy", str(dd.get_ploidy(data)), "-o", tx_call_file, out["cns"]] if gender: cmd += ["--gender", gender] if gender.lower() == "male": cmd += ["--male-reference"] do.run(cmd, "CNVkit call ploidy") calls = {} for outformat in ["bed", "vcf"]: out_file = "%s.%s" % (os.path.splitext(call_file)[0], outformat) calls[outformat] = out_file if not utils.file_exists(out_file): with file_transaction(data, out_file) as tx_out_file: cmd = [os.path.join(os.path.dirname(sys.executable), "cnvkit.py"), "export", outformat, "--sample-id", dd.get_sample_name(data), "--ploidy", str(dd.get_ploidy(data)), "-o", tx_out_file, call_file] if gender and gender.lower() == "male": cmd += ["--male-reference"] do.run(cmd, "CNVkit export %s" % outformat) out["call_file"] = call_file out["vrn_bed"] = annotate.add_genes(calls["bed"], data) effects_vcf, _ = effects.add_to_vcf(calls["vcf"], data, "snpeff") out["vrn_file"] = effects_vcf or calls["vcf"] return out
def _code_gender(data): g = dd.get_gender(data) if g and g.lower() == "male": return 1 elif g and g.lower() == "female": return 2 else: return 0
def _code_gender(data): g = dd.get_gender(data) if g and str(g).lower() in ["male", "m"]: return 1 elif g and str(g).lower() in ["female", "f"]: return 2 else: return 0
def get_gender(data): """Retrieve gender from metadata, codified as male/female/unknown. """ g = str(dd.get_gender(data)) if g and str(g).lower() in ["male", "m", "1"]: return "male" elif g and str(g).lower() in ["female", "f", "2"]: return "female" else: return "unknown"
def _add_diagram_plot(out, data): out_file = "%s-diagram.pdf" % os.path.splitext(out["cnr"])[0] cnr = _remove_haplotype_chroms(out["cnr"], data) cns = _remove_haplotype_chroms(out["cns"], data) if not utils.file_exists(out_file): with file_transaction(data, out_file) as tx_out_file: cmd = [_get_cmd(), "diagram", "-s", cns, "-o", tx_out_file, cnr] gender = dd.get_gender(data) if gender and gender.lower() == "male": cmd += ["--male-reference"] do.run(cmd, "CNVkit diagram plot") return out_file
def _add_diagram_plot(out, data): out_file = "%s-diagram.pdf" % os.path.splitext(out["cnr"])[0] cnr = _remove_haplotype_chroms(out["cnr"], data) cns = _remove_haplotype_chroms(out["cns"], data) if _cnx_is_empty(cnr) or _cnx_is_empty(cns): return None if not utils.file_exists(out_file): with file_transaction(data, out_file) as tx_out_file: cmd = [_get_cmd(), "diagram", "-s", cns, "-o", tx_out_file, cnr] gender = dd.get_gender(data) if gender and gender.lower() == "male": cmd += ["--male-reference"] do.run(cmd, "CNVkit diagram plot") return out_file
def _add_bed_to_output(out, data): """Add FreeBayes cnvmap BED-like representation to the output. """ out_file = "%s.bed" % os.path.splitext(out["cns"])[0] if not utils.file_exists(out_file): with file_transaction(data, out_file) as tx_out_file: cmd = [os.path.join(os.path.dirname(sys.executable), "cnvkit.py"), "export", "freebayes", "--name", dd.get_sample_name(data), "--ploidy", str(dd.get_ploidy(data)), "-o", tx_out_file, out["cns"]] gender = dd.get_gender(data) if gender: cmd += ["--gender", gender] do.run(cmd, "CNVkit export FreeBayes BED cnvmap") out["vrn_file"] = out_file return out
def _add_variantcalls_to_output(out, data): """Call ploidy and convert into VCF and BED representations. """ call_file = "%s-call%s" % os.path.splitext(out["cns"]) gender = dd.get_gender(data) if not utils.file_exists(call_file): with file_transaction(data, call_file) as tx_call_file: cmd = [ os.path.join(os.path.dirname(sys.executable), "cnvkit.py"), "call", "--ploidy", str(dd.get_ploidy(data)), "-o", tx_call_file, out["cns"] ] if gender: cmd += ["--gender", gender] if gender.lower() == "male": cmd += ["--male-reference"] do.run(cmd, "CNVkit call ploidy") calls = {} for outformat in ["bed", "vcf"]: out_file = "%s.%s" % (os.path.splitext(call_file)[0], outformat) calls[outformat] = out_file if not utils.file_exists(out_file): with file_transaction(data, out_file) as tx_out_file: cmd = [ os.path.join(os.path.dirname(sys.executable), "cnvkit.py"), "export", outformat, "--sample-id", dd.get_sample_name(data), "--ploidy", str(dd.get_ploidy(data)), "-o", tx_out_file, call_file ] if gender and gender.lower() == "male": cmd += ["--male-reference"] do.run(cmd, "CNVkit export %s" % outformat) out["call_file"] = call_file out["vrn_bed"] = annotate.add_genes(calls["bed"], data) effects_vcf, _ = effects.add_to_vcf(calls["vcf"], data, "snpeff") out["vrn_file"] = effects_vcf or calls["vcf"] return out