def initialize_pipeline(phase_path, haplotype_path, cnv_path): exons_path = bamhelp.GetExons() event, extension = os.path.splitext(os.path.basename(cnv_path)) phased_bed = "/".join([phase_path, "PHASED.BED"]) bedtools_path = bamhelp.GetBedtoolsPath() try: logger.debug(' --- Initializing input files --- ') exonsinroibed = "/".join( [haplotype_path, "exons_in_roi" + str(event) + ".bed"]) nonhetbed = "/".join([haplotype_path, "non_het" + str(event) + ".bed"]) hetbed = "/".join([haplotype_path, "het" + str(event) + ".bed"]) hetsnpbed = "/".join([haplotype_path, "het_snp" + str(event) + ".bed"]) tmp = "/".join([haplotype_path, str(event) + "_tmp.bed"]) command = " ".join([ bedtools_path, "intersect -a", exons_path, "-b", cnv_path, "-wa -wb > ", tmp ]) runCommand(command) cmd = "".join([ """awk '{print $1"\t"$2"\t"$3"\t"$NF}' """, tmp, " > ", exonsinroibed ]) runCommand(cmd) splitBed(exonsinroibed, '_exons_in_roi' + str(event)) command = " ".join([ bedtools_path, "intersect -a", phased_bed, "-b", exonsinroibed, "-wa -wb >", tmp ]) runCommand(command) cmd = "".join([ """awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$NF}' """, tmp, " > ", hetsnpbed ]) runCommand(cmd) splitBed(hetsnpbed, '_het_snp' + str(event)) os.remove(tmp) except: logger.exception("Initialization error !") raise logger.debug("--- initialization complete ---") return
def initialize0(results_path, cancer_dir_path): try: vcf_path = bamhelp.GetVCF() exons_path = bamhelp.GetExons() reference_path = bamhelp.GetRef() bedtools_path = bamhelp.GetBedtoolsPath() vpath, vcf = os.path.split(vcf_path) if (params.GetPhase()): phasedvcf = "/".join( [results_path, sub('.vcf$', '_phased.vcf.gz', vcf)]) vcftobed = "/".join([results_path, sub('.vcf$', '.bed', vcf)]) hap1vcf = "/".join([results_path, "hap1_het.vcf"]) hap2vcf = "/".join([results_path, "hap2_het.vcf"]) hap1vcffiltered = "/".join([results_path, "hap1_het_filtered"]) hap2vcffiltered = "/".join([results_path, "hap2_het_filtered"]) hap1vcffilteredtobed = "/".join( [results_path, "hap1_het_filtered.bed"]) hap2vcffilteredtobed = "/".join( [results_path, "hap2_het_filtered.bed"]) phased_bed = "/".join([results_path, "PHASED.BED"]) phaseVCF(vcf_path, phasedvcf) getVCFHaplotypes(phasedvcf, hap1vcf, hap2vcf) thinVCF(hap1vcf, hap1vcffiltered) thinVCF(hap2vcf, hap2vcffiltered) convertvcftobed(hap1vcffiltered + ".recode.vcf", hap1vcffilteredtobed) convertvcftobed(hap2vcffiltered + ".recode.vcf", hap2vcffilteredtobed) cmd1 = """sed -i 's/$/\thap1/' """ + hap1vcffilteredtobed cmd2 = """sed -i 's/$/\thap2/' """ + hap2vcffilteredtobed cmd3 = "cat " + hap1vcffilteredtobed + " " + hap2vcffilteredtobed + " > " + 'tmp.bed' cmd4 = "sort -V -k1,1 -k2,2 tmp.bed > " + phased_bed runCommand(cmd1) runCommand(cmd2) runCommand(cmd3) runCommand(cmd4) os.remove('tmp.bed') except: raise return
def initialize_pipeline(phase_path, haplotype_path, cnv_path): """ Intersect CNV region with exons and then intersect with phased VCF bed. """ exons_path = params.GetExonsPath() cnv_bed = params.GetCNV() event, extension = os.path.splitext(os.path.basename(cnv_path)) phased_bed = "/".join([phase_path, "PHASED.BED"]) nonroibedfn = "/".join([haplotype_path, "non_roi.bed"]) bedtools_path = bamhelp.GetBedtoolsPath() try: logger.debug(' --- Initializing input files --- ') exonsinroibed = "/".join([haplotype_path, "exons_in_roi" + str(event) + ".bed"]) nonhetbed = "/".join([haplotype_path, "non_het" + str(event) + ".bed"]) hetbed = "/".join([haplotype_path, "het" + str(event) + ".bed"]) hetsnpbed = "/".join([haplotype_path, "het_snp" + str(event) + ".bed"]) tmp1 = "/".join([haplotype_path, str(event) + "_tmp1.bed"]) tmp2 = "/".join([haplotype_path, str(event) + "_tmp2.bed"]) command = " ".join([bedtools_path, "intersect -a", cnv_path, "-b", exons_path, " > ", exonsinroibed]) runCommand(command) splitBed(exonsinroibed, '_exons_in_roi' + str(event)) command = " ".join([bedtools_path, "intersect -a", phased_bed, "-b", exonsinroibed, "-wa -wb >", tmp2]) runCommand(command) removeIfEmptyBed(tmp2) if os.path.isfile(tmp2): filterColumns(tmp2, hetsnpbed, [0,1,2,3,4,5,9])#[i for i in range(0, 8)]) splitBed(hetsnpbed, '_het_snp' + str(event)) # non-roi bed: if not os.path.isfile(nonroibedfn): command = " ".join([bedtools_path, "subtract -a", exons_path, "-b", cnv_bed, ">", nonroibedfn]) runCommand(command) removeIfEmptyBed(nonroibedfn) if os.path.isfile(nonroibedfn): splitBedByChr(nonroibedfn, haplotype_path) except: logger.exception("Initialization error !") raise logger.debug("--- initialization complete ---") return
def initialize0(results_path, cancer_dir_path): try: vcf_path = bamhelp.GetVCF() exons_path = bamhelp.GetExons() reference_path = bamhelp.GetRef() bedtools_path = bamhelp.GetBedtoolsPath() vpath, vcf = os.path.split(vcf_path) if params.GetPhase(): phasedvcf = "/".join( [results_path, sub('.vcf$', '_phased.vcf.gz', vcf)]) vcftobed = "/".join([results_path, sub('.vcf$', '.bed', vcf)]) hap1vcf = "/".join([results_path, "hap1_het.vcf"]) hap2vcf = "/".join([results_path, "hap2_het.vcf"]) hap1vcffiltered = "/".join([results_path, "hap1_het_filtered"]) hap2vcffiltered = "/".join([results_path, "hap2_het_filtered"]) hap1vcffilteredtobed = "/".join( [results_path, "hap1_het_filtered.bed"]) hap2vcffilteredtobed = "/".join( [results_path, "hap2_het_filtered.bed"]) phased_bed = "/".join([results_path, "PHASED.BED"]) phaseVCF(vcf_path, phasedvcf) getVCFHaplotypes(phasedvcf, hap1vcf, hap2vcf) thinVCF(hap1vcf, hap1vcffiltered) thinVCF(hap2vcf, hap2vcffiltered) convertvcftobed(hap1vcffiltered + ".recode.vcf", hap1vcffilteredtobed) convertvcftobed(hap2vcffiltered + ".recode.vcf", hap2vcffilteredtobed) generatePhasedBed(hap1vcffilteredtobed, hap2vcffilteredtobed, phased_bed) except: logger.exception("Initialization error !") raise return
def initialize0(results_path, cancer_dir_path): """ Initialize paths for files provided by user. Phasing is also performed if requested by user. """ try: vcf_path = params.GetVCFPath() exons_path = params.GetExonsPath() #reference_path = bamhelp.GetRef() bedtools_path = bamhelp.GetBedtoolsPath() vpath, vcf = os.path.split(vcf_path) phasedvcf = "/".join([results_path, sub('.vcf$', '_phased.vcf.gz', vcf)]) vcftobed = "/".join([results_path, sub('.vcf$', '.bed', vcf)]) hap1vcf = "/".join([results_path, "hap1_het.vcf"]) hap2vcf = "/".join([results_path, "hap2_het.vcf"]) hap1vcffiltered = "/".join([results_path, "hap1_het_filtered"]) hap2vcffiltered = "/".join([results_path, "hap2_het_filtered"]) hap1vcffilteredtobed = "/".join([results_path, "hap1_het_filtered.bed"]) hap2vcffilteredtobed = "/".join([results_path, "hap2_het_filtered.bed"]) phased_bed = "/".join([results_path, "PHASED.BED"]) if params.GetPhase(): phaseVCF(vcf_path, phasedvcf) getVCFHaplotypes(phasedvcf, hap1vcf, hap2vcf) else: getVCFHaplotypes(vcf_path, hap1vcf, hap2vcf) convertvcftobed(hap1vcf, hap1vcffilteredtobed) convertvcftobed(hap2vcf, hap2vcffilteredtobed) generatePhasedBed(hap1vcffilteredtobed, hap2vcffilteredtobed, phased_bed) except: logger.exception("Initialization error!") raise return