def combinePaired(outdir, ref, tbam, nbam, inclusion=None, exclusion=None, mutect=None, indelocator=None, mutect2=None, varscan_snv=None, varscan_indel=None, jsm=None, sniper=None, vardict=None, muse=None, lofreq_snv=None, lofreq_indel=None, scalpel=None, strelka_snv=None, strelka_indel=None, tnscope=None, platypus=None, keep_intermediates=False): hg_dict = re.sub(r'\.fa(sta)?$', '.dict', ref) intermediate_files = set() snv_intermediates = [] indel_intermediates = [] intermediate_vcfs = {'MuTect2': {'snv': None, 'indel': None}, \ 'VarDict': {'snv': None, 'indel': None}, \ 'TNscope': {'snv': None, 'indel': None}, \ 'Platypus': {'snv': None, 'indel': None} } # Modify direct VCF outputs for merging: if mutect or indelocator: import vcfModifier.modify_MuTect as mod_mutect if mutect: mutect_in = bed_intersector( mutect, os.sep.join((outdir, 'intersect.mutect1.vcf')), inclusion, exclusion) intermediate_files.add(mutect_in) snv_mutect_out = os.sep.join((outdir, 'snv.mutect1.vcf')) mod_mutect.convert(mutect_in, snv_mutect_out, tbam, nbam) intermediate_files.add(snv_mutect_out) snv_intermediates.append(snv_mutect_out) if indelocator: indelocator_in = bed_intersector( indelocator, os.sep.join( (outdir, 'intersect.indelocator.vcf')), inclusion, exclusion) intermediate_files.add(indelocator_in) indel_indelocator_out = os.sep.join( (outdir, 'indel.indelocator.vcf')) mod_mutect.convert(indelocator_in, indel_indelocator_out, tbam, nbam) intermediate_files.add(indel_indelocator_out) indel_intermediates.append(indel_indelocator_out) if mutect2: import vcfModifier.modify_MuTect2 as mod_mutect2 mutect2_in = bed_intersector( mutect2, os.sep.join((outdir, 'intersect.mutect2.vcf')), inclusion, exclusion) intermediate_files.add(mutect2_in) snv_mutect_out = os.sep.join((outdir, 'snv.mutect2.vcf')) indel_mutect_out = os.sep.join((outdir, 'indel.mutect2.vcf')) mod_mutect2.convert(mutect2_in, snv_mutect_out, indel_mutect_out, False) for file_i in snv_mutect_out, indel_mutect_out: intermediate_files.add(file_i) snv_intermediates.append(snv_mutect_out) indel_intermediates.append(indel_mutect_out) intermediate_vcfs['MuTect2']['snv'] = snv_mutect_out intermediate_vcfs['MuTect2']['indel'] = indel_mutect_out if varscan_snv or varscan_indel: import vcfModifier.modify_VarScan2 as mod_varscan2 if varscan_snv: varscan_in = bed_intersector( varscan_snv, os.sep.join( (outdir, 'intersect.varscan.snv.vcf')), inclusion, exclusion) intermediate_files.add(varscan_in) snv_varscan_out = os.sep.join((outdir, 'snv.varscan.vcf')) mod_varscan2.convert(varscan_in, snv_varscan_out) intermediate_files.add(snv_varscan_out) snv_intermediates.append(snv_varscan_out) if varscan_indel: varscan_in = bed_intersector( varscan_indel, os.sep.join((outdir, 'intersect.varscan.indel.vcf')), inclusion, exclusion) intermediate_files.add(varscan_in) indel_varscan_out = os.sep.join((outdir, 'indel.varscan.vcf')) mod_varscan2.convert(varscan_in, indel_varscan_out) intermediate_files.add(indel_varscan_out) indel_intermediates.append(indel_varscan_out) if jsm: import vcfModifier.modify_JointSNVMix2 as mod_jsm jsm_in = bed_intersector(jsm, os.sep.join( (outdir, 'intersect.jsm.vcf')), inclusion, exclusion) intermediate_files.add(jsm_in) jsm_out = os.sep.join((outdir, 'snv.jsm.vcf')) mod_jsm.convert(jsm_in, jsm_out) intermediate_files.add(jsm_out) snv_intermediates.append(jsm_out) if sniper: import vcfModifier.modify_SomaticSniper as mod_sniper sniper_in = bed_intersector( sniper, os.sep.join((outdir, 'intersect.sniper.vcf')), inclusion, exclusion) intermediate_files.add(sniper_in) sniper_out = os.sep.join((outdir, 'snv.somaticsniper.vcf')) mod_sniper.convert(sniper_in, sniper_out) intermediate_files.add(sniper_out) snv_intermediates.append(sniper_out) if vardict: import vcfModifier.modify_VarDict as mod_vardict vardict_in = bed_intersector( vardict, os.sep.join((outdir, 'intersect.vardict.vcf')), inclusion, exclusion) intermediate_files.add(vardict_in) snv_vardict_out = os.sep.join((outdir, 'snv.vardict.vcf')) indel_vardict_out = os.sep.join((outdir, 'indel.vardict.vcf')) mod_vardict.convert(vardict_in, snv_vardict_out, indel_vardict_out) sorted_snv_vardict_out = os.sep.join((outdir, 'snv.sort.vardict.vcf')) sorted_indel_vardict_out = os.sep.join( (outdir, 'indel.sort.vardict.vcf')) vcfsorter(ref, snv_vardict_out, sorted_snv_vardict_out) vcfsorter(ref, indel_vardict_out, sorted_indel_vardict_out) for file_i in snv_vardict_out, indel_vardict_out, sorted_snv_vardict_out, sorted_indel_vardict_out: intermediate_files.add(file_i) snv_intermediates.append(sorted_snv_vardict_out) indel_intermediates.append(sorted_indel_vardict_out) intermediate_vcfs['VarDict']['snv'] = sorted_snv_vardict_out intermediate_vcfs['VarDict']['indel'] = sorted_indel_vardict_out if muse: muse_in = bed_intersector(muse, os.sep.join((outdir, 'intersect.muse.vcf')), inclusion, exclusion) intermediate_files.add(muse_in) muse_out = os.sep.join((outdir, 'snv.muse.vcf')) copy_TextFile.copy(muse_in, muse_out) intermediate_files.add(muse_out) snv_intermediates.append(muse_out) if lofreq_snv: lofreq_in = bed_intersector( lofreq_snv, os.sep.join((outdir, 'intersect.lofreq.snv.vcf')), inclusion, exclusion) intermediate_files.add(lofreq_in) snv_lofreq_out = os.sep.join((outdir, 'snv.lofreq.vcf')) copy_TextFile.copy(lofreq_in, snv_lofreq_out) intermediate_files.add(snv_lofreq_out) snv_intermediates.append(snv_lofreq_out) if lofreq_indel: lofreq_in = bed_intersector( lofreq_indel, os.sep.join((outdir, 'intersect.lofreq.indel.vcf')), inclusion, exclusion) intermediate_files.add(lofreq_in) indel_lofreq_out = os.sep.join((outdir, 'indel.lofreq.vcf')) copy_TextFile.copy(lofreq_in, indel_lofreq_out) intermediate_files.add(indel_lofreq_out) indel_intermediates.append(indel_lofreq_out) if scalpel: scalpel_in = bed_intersector( scalpel, os.sep.join((outdir, 'intersect.scalpel.vcf')), inclusion, exclusion) intermediate_files.add(scalpel_in) scalpel_out = os.sep.join((outdir, 'indel.scalpel.vcf')) copy_TextFile.copy(scalpel_in, scalpel_out) intermediate_files.add(scalpel_out) indel_intermediates.append(scalpel_out) if strelka_snv or strelka_indel: import vcfModifier.modify_Strelka as mod_strelka if strelka_snv: strelka_in = bed_intersector( strelka_snv, os.sep.join( (outdir, 'intersect.strelka.snv.vcf')), inclusion, exclusion) intermediate_files.add(strelka_in) snv_strelka_out = os.sep.join((outdir, 'snv.strelka.vcf')) mod_strelka.convert(strelka_in, snv_strelka_out) intermediate_files.add(snv_strelka_out) snv_intermediates.append(snv_strelka_out) if strelka_indel: strelka_in = bed_intersector( strelka_indel, os.sep.join((outdir, 'intersect.strelka.indel.vcf')), inclusion, exclusion) intermediate_files.add(strelka_in) indel_strelka_out = os.sep.join((outdir, 'indel.strelka.vcf')) mod_strelka.convert(strelka_in, indel_strelka_out) intermediate_files.add(indel_strelka_out) indel_intermediates.append(indel_strelka_out) if tnscope: import vcfModifier.modify_MuTect2 as mod_mutect2 tnscope_in = bed_intersector( tnscope, os.sep.join((outdir, 'intersect.tnscope.vcf')), inclusion, exclusion) intermediate_files.add(tnscope_in) snv_tnscope_out = os.sep.join((outdir, 'snv.tnscope.vcf')) indel_tnscope_out = os.sep.join((outdir, 'indel.tnscope.vcf')) mod_mutect2.convert(tnscope_in, snv_tnscope_out, indel_tnscope_out, True) for file_i in snv_tnscope_out, indel_tnscope_out: intermediate_files.add(file_i) snv_intermediates.append(snv_tnscope_out) indel_intermediates.append(indel_tnscope_out) intermediate_vcfs['TNscope']['snv'] = snv_tnscope_out intermediate_vcfs['TNscope']['indel'] = indel_tnscope_out if platypus: platypus_in = bed_intersector( platypus, os.sep.join((outdir, 'intersect.platypus.vcf')), inclusion, exclusion) intermediate_files.add(platypus_in) snv_platypus_out = os.sep.join((outdir, 'snv.platypus.vcf')) indel_platypus_out = os.sep.join((outdir, 'indel.platypus.vcf')) splitVcf.split_into_snv_and_indel(platypus_in, snv_platypus_out, indel_platypus_out) for file_i in snv_platypus_out, indel_platypus_out: intermediate_files.add(file_i) snv_intermediates.append(snv_platypus_out) indel_intermediates.append(indel_platypus_out) intermediate_vcfs['Platypus']['snv'] = snv_platypus_out intermediate_vcfs['Platypus']['indel'] = indel_platypus_out # Combine SNV/INDEL variant candidates snv_combined = os.sep.join((outdir, 'unsorted.CombineVariants.snv.vcf')) indel_combined = os.sep.join( (outdir, 'unsorted.CombineVariants.indel.vcf')) getUniqueVcfPositions.combine(snv_intermediates, snv_combined) getUniqueVcfPositions.combine(indel_intermediates, indel_combined) for file_i in snv_combined, indel_combined: intermediate_files.add(file_i) # Sort them: snv_combined_sorted = os.sep.join((outdir, 'CombineVariants.snv.vcf')) indel_combined_sorted = os.sep.join((outdir, 'CombineVariants.indel.vcf')) vcfsorter(ref, snv_combined, snv_combined_sorted) vcfsorter(ref, indel_combined, indel_combined_sorted) if not keep_intermediates: for file_i in intermediate_files: subprocess.call(('rm', '-v', file_i)) return snv_combined_sorted, indel_combined_sorted, intermediate_vcfs, intermediate_files
def combineSingle(outdir, ref, bam, inclusion=None, exclusion=None, mutect=None, mutect2=None, varscan=None, vardict=None, lofreq=None, scalpel=None, strelka=None, keep_intermediates=False): hg_dict = re.sub(r'\.fa(sta)?$', '.dict', ref) intermediate_files = set() snv_intermediates = [] indel_intermediates = [] intermediate_vcfs = {'MuTect2' :{'snv': None, 'indel': None}, \ 'VarScan2' :{'snv': None, 'indel': None}, \ 'VarDict' :{'snv': None, 'indel': None}, \ 'LoFreq' :{'snv': None, 'indel': None}, \ 'Strelka' :{'snv': None, 'indel': None}, } if mutect: import vcfModifier.modify_MuTect as mod_mutect mutect_in = bed_intersector( mutect, os.sep.join((outdir, 'intersect.mutect1.vcf')), inclusion, exclusion) intermediate_files.add(mutect_in) snv_mutect_out = os.sep.join((outdir, 'snv.mutect1.vcf')) mod_mutect.convert(mutect_in, snv_mutect_out, bam) intermediate_files.add(snv_mutect_out) snv_intermediates.append(snv_mutect_out) if mutect2: import vcfModifier.modify_ssMuTect2 as mod_mutect2 mutect2_in = bed_intersector( mutect2, os.sep.join((outdir, 'intersect.mutect2.vcf')), inclusion, exclusion) intermediate_files.add(mutect2_in) snv_mutect_out = os.sep.join((outdir, 'snv.mutect2.vcf')) indel_mutect_out = os.sep.join((outdir, 'indel.mutect2.vcf')) mod_mutect2.convert(mutect2_in, snv_mutect_out, indel_mutect_out) for file_i in snv_mutect_out, indel_mutect_out: intermediate_files.add(file_i) snv_intermediates.append(snv_mutect_out) indel_intermediates.append(indel_mutect_out) intermediate_vcfs['MuTect2']['snv'] = snv_mutect_out intermediate_vcfs['MuTect2']['indel'] = indel_mutect_out if varscan: import vcfModifier.modify_VarScan2 as mod_varscan2 varscan_in = bed_intersector( varscan, os.sep.join((outdir, 'intersect.varscan.vcf')), inclusion, exclusion) intermediate_files.add(varscan_in) snv_temp = os.sep.join((outdir, 'snv.varscan.temp.vcf')) indel_temp = os.sep.join((outdir, 'indel.varscan.temp.vcf')) snv_varscan_out = os.sep.join((outdir, 'snv.varscan.vcf')) indel_varscan_out = os.sep.join((outdir, 'indel.varscan.vcf')) splitVcf.split_into_snv_and_indel(varscan_in, snv_temp, indel_temp) mod_varscan2.convert(snv_temp, snv_varscan_out) mod_varscan2.convert(indel_temp, indel_varscan_out) for file_i in snv_temp, indel_temp, snv_varscan_out, indel_varscan_out: intermediate_files.add(file_i) snv_intermediates.append(snv_varscan_out) indel_intermediates.append(indel_varscan_out) intermediate_vcfs['VarScan2']['snv'] = snv_varscan_out intermediate_vcfs['VarScan2']['indel'] = indel_varscan_out if vardict: import vcfModifier.modify_VarDict as mod_vardict vardict_in = bed_intersector( vardict, os.sep.join((outdir, 'intersect.vardict.vcf')), inclusion, exclusion) intermediate_files.add(vardict_in) snv_vardict_out = os.sep.join((outdir, 'snv.vardict.vcf')) indel_vardict_out = os.sep.join((outdir, 'indel.vardict.vcf')) mod_vardict.convert(vardict_in, snv_vardict_out, indel_vardict_out) sorted_snv_vardict_out = os.sep.join((outdir, 'snv.sort.vardict.vcf')) sorted_indel_vardict_out = os.sep.join( (outdir, 'indel.sort.vardict.vcf')) vcfsorter(ref, snv_vardict_out, sorted_snv_vardict_out) vcfsorter(ref, indel_vardict_out, sorted_indel_vardict_out) for file_i in snv_vardict_out, indel_vardict_out, sorted_snv_vardict_out, sorted_indel_vardict_out: intermediate_files.add(file_i) snv_intermediates.append(sorted_snv_vardict_out) indel_intermediates.append(sorted_indel_vardict_out) intermediate_vcfs['VarDict']['snv'] = sorted_snv_vardict_out intermediate_vcfs['VarDict']['indel'] = sorted_indel_vardict_out if lofreq: lofreq_in = bed_intersector( lofreq, os.sep.join((outdir, 'intersect.lofreq.vcf')), inclusion, exclusion) intermediate_files.add(lofreq_in) snv_lofreq_out = os.sep.join((outdir, 'snv.lofreq.vcf')) indel_lofreq_out = os.sep.join((outdir, 'indel.lofreq.vcf')) splitVcf.split_into_snv_and_indel(lofreq_in, snv_lofreq_out, indel_lofreq_out) for file_i in snv_lofreq_out, indel_lofreq_out: intermediate_files.add(file_i) snv_intermediates.append(snv_lofreq_out) indel_intermediates.append(indel_lofreq_out) intermediate_vcfs['LoFreq']['snv'] = snv_lofreq_out intermediate_vcfs['LoFreq']['indel'] = indel_lofreq_out if scalpel: scalpel_in = bed_intersector( scalpel, os.sep.join((outdir, 'intersect.scalpel.vcf')), inclusion, exclusion) intermediate_files.add(scalpel_in) scalpel_out = os.sep.join((outdir, 'indel.scalpel.vcf')) copy_TextFile.copy(scalpel_in, scalpel_out) intermediate_files.add(scalpel_out) indel_intermediates.append(scalpel_out) if strelka: import vcfModifier.modify_ssStrelka as mod_strelka strelka_in = bed_intersector( strelka, os.sep.join((outdir, 'intersect.strelka.vcf')), inclusion, exclusion) intermediate_files.add(strelka_in) snv_strelka_out = os.sep.join((outdir, 'snv.strelka.vcf')) indel_strelka_out = os.sep.join((outdir, 'indel.strelka.vcf')) mod_strelka.convert(strelka_in, snv_strelka_out, indel_strelka_out) for file_i in snv_strelka_out, indel_strelka_out: intermediate_files.add(file_i) snv_intermediates.append(snv_strelka_out) indel_intermediates.append(indel_strelka_out) intermediate_vcfs['Strelka']['snv'] = snv_strelka_out intermediate_vcfs['Strelka']['indel'] = indel_strelka_out # Combine SNV/INDEL variant candidates snv_combined = os.sep.join((outdir, 'unsorted.CombineVariants.snv.vcf')) indel_combined = os.sep.join( (outdir, 'unsorted.CombineVariants.indel.vcf')) getUniqueVcfPositions.combine(snv_intermediates, snv_combined) getUniqueVcfPositions.combine(indel_intermediates, indel_combined) for file_i in snv_combined, indel_combined: intermediate_files.add(file_i) # Sort them: snv_combined_sorted = os.sep.join((outdir, 'CombineVariants.snv.vcf')) indel_combined_sorted = os.sep.join((outdir, 'CombineVariants.indel.vcf')) vcfsorter(ref, snv_combined, snv_combined_sorted) vcfsorter(ref, indel_combined, indel_combined_sorted) if not keep_intermediates: for file_i in intermediate_files: subprocess.call(('rm', '-v', file_i)) return snv_combined_sorted, indel_combined_sorted, intermediate_vcfs, intermediate_files
def combineSingle(outdir, ref, bam, inclusion=None, exclusion=None, mutect=None, mutect2=None, varscan=None, vardict=None, lofreq=None, scalpel=None, strelka=None, keep_intermediates=False): hg_dict = re.sub(r'\.fa(sta)?$', '.dict', ref) intermediate_files = set() snv_intermediates = [] indel_intermediates = [] intermediate_vcfs = {'MuTect2' :{'snv': None, 'indel': None}, \ 'VarScan2' :{'snv': None, 'indel': None}, \ 'VarDict' :{'snv': None, 'indel': None}, \ 'LoFreq' :{'snv': None, 'indel': None}, \ 'Strelka' :{'snv': None, 'indel': None}, } if mutect: import vcfModifier.modify_MuTect as mod_mutect mutect_in = bed_intersector(mutect, os.sep.join(( outdir, 'intersect.mutect1.vcf' )), inclusion, exclusion) intermediate_files.add(mutect_in) snv_mutect_out = os.sep.join(( outdir, 'snv.mutect1.vcf' )) mod_mutect.convert(mutect_in, snv_mutect_out, bam) intermediate_files.add(snv_mutect_out) snv_intermediates.append(snv_mutect_out) if mutect2: import vcfModifier.modify_ssMuTect2 as mod_mutect2 mutect2_in = bed_intersector(mutect2, os.sep.join(( outdir, 'intersect.mutect2.vcf' )), inclusion, exclusion) intermediate_files.add(mutect2_in) snv_mutect_out = os.sep.join(( outdir, 'snv.mutect2.vcf' )) indel_mutect_out = os.sep.join(( outdir, 'indel.mutect2.vcf' )) mod_mutect2.convert(mutect2_in, snv_mutect_out, indel_mutect_out) for file_i in snv_mutect_out, indel_mutect_out: intermediate_files.add( file_i ) snv_intermediates.append(snv_mutect_out) indel_intermediates.append(indel_mutect_out) intermediate_vcfs['MuTect2']['snv'] = snv_mutect_out intermediate_vcfs['MuTect2']['indel'] = indel_mutect_out if varscan: import vcfModifier.modify_VarScan2 as mod_varscan2 varscan_in = bed_intersector(varscan, os.sep.join(( outdir, 'intersect.varscan.vcf' )), inclusion, exclusion) intermediate_files.add(varscan_in) snv_temp = os.sep.join(( outdir, 'snv.varscan.temp.vcf' )) indel_temp = os.sep.join(( outdir, 'indel.varscan.temp.vcf' )) snv_varscan_out = os.sep.join(( outdir, 'snv.varscan.vcf' )) indel_varscan_out = os.sep.join(( outdir, 'indel.varscan.vcf' )) splitVcf.split_into_snv_and_indel(varscan_in, snv_temp, indel_temp) mod_varscan2.convert(snv_temp, snv_varscan_out) mod_varscan2.convert(indel_temp, indel_varscan_out) for file_i in snv_temp, indel_temp, snv_varscan_out, indel_varscan_out: intermediate_files.add( file_i ) snv_intermediates.append(snv_varscan_out) indel_intermediates.append(indel_varscan_out) intermediate_vcfs['VarScan2']['snv'] = snv_varscan_out intermediate_vcfs['VarScan2']['indel'] = indel_varscan_out if vardict: import vcfModifier.modify_VarDict as mod_vardict vardict_in = bed_intersector(vardict, os.sep.join(( outdir, 'intersect.vardict.vcf' )), inclusion, exclusion) intermediate_files.add(vardict_in) snv_vardict_out = os.sep.join(( outdir, 'snv.vardict.vcf' )) indel_vardict_out = os.sep.join(( outdir, 'indel.vardict.vcf')) mod_vardict.convert(vardict_in, snv_vardict_out, indel_vardict_out) sorted_snv_vardict_out = os.sep.join(( outdir, 'snv.sort.vardict.vcf')) sorted_indel_vardict_out = os.sep.join(( outdir, 'indel.sort.vardict.vcf')) vcfsorter(ref, snv_vardict_out, sorted_snv_vardict_out) vcfsorter(ref, indel_vardict_out, sorted_indel_vardict_out) for file_i in snv_vardict_out, indel_vardict_out, sorted_snv_vardict_out, sorted_indel_vardict_out: intermediate_files.add( file_i ) snv_intermediates.append(sorted_snv_vardict_out) indel_intermediates.append(sorted_indel_vardict_out) intermediate_vcfs['VarDict']['snv'] = sorted_snv_vardict_out intermediate_vcfs['VarDict']['indel'] = sorted_indel_vardict_out if lofreq: lofreq_in = bed_intersector(lofreq, os.sep.join(( outdir, 'intersect.lofreq.vcf' )), inclusion, exclusion) intermediate_files.add(lofreq_in) snv_lofreq_out = os.sep.join(( outdir, 'snv.lofreq.vcf' )) indel_lofreq_out = os.sep.join(( outdir, 'indel.lofreq.vcf' )) splitVcf.split_into_snv_and_indel(lofreq_in, snv_lofreq_out, indel_lofreq_out) for file_i in snv_lofreq_out, indel_lofreq_out: intermediate_files.add( file_i ) snv_intermediates.append(snv_lofreq_out) indel_intermediates.append(indel_lofreq_out) intermediate_vcfs['LoFreq']['snv'] = snv_lofreq_out intermediate_vcfs['LoFreq']['indel'] = indel_lofreq_out if scalpel: scalpel_in = bed_intersector(scalpel, os.sep.join(( outdir, 'intersect.scalpel.vcf' )), inclusion, exclusion) intermediate_files.add(scalpel_in) scalpel_out = os.sep.join(( outdir, 'indel.scalpel.vcf' )) copy_TextFile.copy(scalpel_in, scalpel_out) intermediate_files.add(scalpel_out) indel_intermediates.append(scalpel_out) if strelka: import vcfModifier.modify_ssStrelka as mod_strelka strelka_in = bed_intersector(strelka, os.sep.join(( outdir, 'intersect.strelka.vcf' )), inclusion, exclusion) intermediate_files.add(strelka_in) snv_strelka_out = os.sep.join(( outdir, 'snv.strelka.vcf' )) indel_strelka_out = os.sep.join(( outdir, 'indel.strelka.vcf' )) mod_strelka.convert(strelka_in, snv_strelka_out, indel_strelka_out) for file_i in snv_strelka_out, indel_strelka_out: intermediate_files.add( file_i ) snv_intermediates.append(snv_strelka_out) indel_intermediates.append(indel_strelka_out) intermediate_vcfs['Strelka']['snv'] = snv_strelka_out intermediate_vcfs['Strelka']['indel'] = indel_strelka_out # Combine SNV/INDEL variant candidates snv_combined = os.sep.join(( outdir, 'unsorted.CombineVariants.snv.vcf' )) indel_combined = os.sep.join(( outdir, 'unsorted.CombineVariants.indel.vcf' )) getUniqueVcfPositions.combine(snv_intermediates, snv_combined) getUniqueVcfPositions.combine(indel_intermediates, indel_combined) for file_i in snv_combined, indel_combined: intermediate_files.add( file_i ) # Sort them: snv_combined_sorted = os.sep.join(( outdir, 'CombineVariants.snv.vcf' )) indel_combined_sorted = os.sep.join(( outdir, 'CombineVariants.indel.vcf' )) vcfsorter(ref, snv_combined, snv_combined_sorted) vcfsorter(ref, indel_combined, indel_combined_sorted) if not keep_intermediates: for file_i in intermediate_files: subprocess.call( ('rm', '-v', file_i ) ) return snv_combined_sorted, indel_combined_sorted, intermediate_vcfs, intermediate_files
def combinePaired(outdir, ref, tbam, nbam, inclusion=None, exclusion=None, mutect=None, indelocator=None, mutect2=None, varscan_snv=None, varscan_indel=None, jsm=None, sniper=None, vardict=None, muse=None, lofreq_snv=None, lofreq_indel=None, scalpel=None, strelka_snv=None, strelka_indel=None, tnscope=None, platypus=None, keep_intermediates=False): hg_dict = re.sub(r'\.fa(sta)?$', '.dict', ref) intermediate_files = set() snv_intermediates = [] indel_intermediates = [] intermediate_vcfs = {'MuTect2': {'snv': None, 'indel': None}, \ 'VarDict': {'snv': None, 'indel': None}, \ 'TNscope': {'snv': None, 'indel': None}, \ 'Platypus': {'snv': None, 'indel': None} } # Modify direct VCF outputs for merging: if mutect or indelocator: import vcfModifier.modify_MuTect as mod_mutect if mutect: mutect_in = bed_intersector(mutect, os.sep.join(( outdir, 'intersect.mutect1.vcf' )), inclusion, exclusion) intermediate_files.add(mutect_in) snv_mutect_out = os.sep.join(( outdir, 'snv.mutect1.vcf' )) mod_mutect.convert(mutect_in, snv_mutect_out, tbam, nbam) intermediate_files.add(snv_mutect_out) snv_intermediates.append(snv_mutect_out) if indelocator: indelocator_in = bed_intersector(indelocator, os.sep.join(( outdir, 'intersect.indelocator.vcf' )), inclusion, exclusion) intermediate_files.add(indelocator_in) indel_indelocator_out = os.sep.join(( outdir, 'indel.indelocator.vcf')) mod_mutect.convert(indelocator_in, indel_indelocator_out, tbam, nbam) intermediate_files.add(indel_indelocator_out) indel_intermediates.append(indel_indelocator_out) if mutect2: import vcfModifier.modify_MuTect2 as mod_mutect2 mutect2_in = bed_intersector(mutect2, os.sep.join(( outdir, 'intersect.mutect2.vcf' )), inclusion, exclusion) intermediate_files.add(mutect2_in) snv_mutect_out = os.sep.join(( outdir, 'snv.mutect2.vcf')) indel_mutect_out = os.sep.join(( outdir, 'indel.mutect2.vcf')) mod_mutect2.convert(mutect2_in, snv_mutect_out, indel_mutect_out, False) for file_i in snv_mutect_out, indel_mutect_out: intermediate_files.add( file_i ) snv_intermediates.append(snv_mutect_out) indel_intermediates.append(indel_mutect_out) intermediate_vcfs['MuTect2']['snv'] = snv_mutect_out intermediate_vcfs['MuTect2']['indel'] = indel_mutect_out if varscan_snv or varscan_indel: import vcfModifier.modify_VarScan2 as mod_varscan2 if varscan_snv: varscan_in = bed_intersector(varscan_snv, os.sep.join(( outdir, 'intersect.varscan.snv.vcf' )), inclusion, exclusion) intermediate_files.add(varscan_in) snv_varscan_out = os.sep.join(( outdir, 'snv.varscan.vcf')) mod_varscan2.convert(varscan_in, snv_varscan_out) intermediate_files.add(snv_varscan_out) snv_intermediates.append(snv_varscan_out) if varscan_indel: varscan_in = bed_intersector(varscan_indel, os.sep.join(( outdir, 'intersect.varscan.indel.vcf' )), inclusion, exclusion) intermediate_files.add(varscan_in) indel_varscan_out = os.sep.join(( outdir, 'indel.varscan.vcf' )) mod_varscan2.convert(varscan_in, indel_varscan_out) intermediate_files.add(indel_varscan_out) indel_intermediates.append(indel_varscan_out) if jsm: import vcfModifier.modify_JointSNVMix2 as mod_jsm jsm_in = bed_intersector(jsm, os.sep.join(( outdir, 'intersect.jsm.vcf' )), inclusion, exclusion) intermediate_files.add(jsm_in) jsm_out = os.sep.join(( outdir, 'snv.jsm.vcf' )) mod_jsm.convert(jsm_in, jsm_out) intermediate_files.add(jsm_out) snv_intermediates.append(jsm_out) if sniper: import vcfModifier.modify_SomaticSniper as mod_sniper sniper_in = bed_intersector(sniper, os.sep.join(( outdir, 'intersect.sniper.vcf' )), inclusion, exclusion) intermediate_files.add(sniper_in) sniper_out = os.sep.join(( outdir, 'snv.somaticsniper.vcf' )) mod_sniper.convert(sniper_in, sniper_out) intermediate_files.add(sniper_out) snv_intermediates.append(sniper_out) if vardict: import vcfModifier.modify_VarDict as mod_vardict vardict_in = bed_intersector(vardict, os.sep.join(( outdir, 'intersect.vardict.vcf' )), inclusion, exclusion) intermediate_files.add(vardict_in) snv_vardict_out = os.sep.join(( outdir, 'snv.vardict.vcf' )) indel_vardict_out = os.sep.join(( outdir, 'indel.vardict.vcf' )) mod_vardict.convert(vardict_in, snv_vardict_out, indel_vardict_out) sorted_snv_vardict_out = os.sep.join(( outdir, 'snv.sort.vardict.vcf' )) sorted_indel_vardict_out = os.sep.join(( outdir, 'indel.sort.vardict.vcf' )) vcfsorter(ref, snv_vardict_out, sorted_snv_vardict_out) vcfsorter(ref, indel_vardict_out, sorted_indel_vardict_out) for file_i in snv_vardict_out, indel_vardict_out, sorted_snv_vardict_out, sorted_indel_vardict_out: intermediate_files.add(file_i) snv_intermediates.append(sorted_snv_vardict_out) indel_intermediates.append(sorted_indel_vardict_out) intermediate_vcfs['VarDict']['snv'] = sorted_snv_vardict_out intermediate_vcfs['VarDict']['indel'] = sorted_indel_vardict_out if muse: muse_in = bed_intersector(muse, os.sep.join(( outdir, 'intersect.muse.vcf' )), inclusion, exclusion) intermediate_files.add(muse_in) muse_out = os.sep.join(( outdir, 'snv.muse.vcf' )) copy_TextFile.copy(muse_in, muse_out) intermediate_files.add(muse_out) snv_intermediates.append(muse_out) if lofreq_snv: lofreq_in = bed_intersector(lofreq_snv, os.sep.join(( outdir, 'intersect.lofreq.snv.vcf' )), inclusion, exclusion) intermediate_files.add(lofreq_in) snv_lofreq_out = os.sep.join(( outdir, 'snv.lofreq.vcf' )) copy_TextFile.copy(lofreq_in, snv_lofreq_out) intermediate_files.add(snv_lofreq_out) snv_intermediates.append(snv_lofreq_out) if lofreq_indel: lofreq_in = bed_intersector(lofreq_indel, os.sep.join(( outdir, 'intersect.lofreq.indel.vcf' )), inclusion, exclusion) intermediate_files.add(lofreq_in) indel_lofreq_out = os.sep.join(( outdir, 'indel.lofreq.vcf' )) copy_TextFile.copy(lofreq_in, indel_lofreq_out) intermediate_files.add(indel_lofreq_out) indel_intermediates.append(indel_lofreq_out) if scalpel: scalpel_in = bed_intersector(scalpel, os.sep.join(( outdir, 'intersect.scalpel.vcf' )), inclusion, exclusion) intermediate_files.add(scalpel_in) scalpel_out = os.sep.join(( outdir, 'indel.scalpel.vcf' )) copy_TextFile.copy(scalpel_in, scalpel_out) intermediate_files.add(scalpel_out) indel_intermediates.append(scalpel_out) if strelka_snv or strelka_indel: import vcfModifier.modify_Strelka as mod_strelka if strelka_snv: strelka_in = bed_intersector(strelka_snv, os.sep.join(( outdir, 'intersect.strelka.snv.vcf' )), inclusion, exclusion) intermediate_files.add(strelka_in) snv_strelka_out = os.sep.join(( outdir, 'snv.strelka.vcf' )) mod_strelka.convert(strelka_in, snv_strelka_out) intermediate_files.add(snv_strelka_out) snv_intermediates.append(snv_strelka_out) if strelka_indel: strelka_in = bed_intersector(strelka_indel, os.sep.join(( outdir, 'intersect.strelka.indel.vcf' )), inclusion, exclusion) intermediate_files.add(strelka_in) indel_strelka_out = os.sep.join(( outdir, 'indel.strelka.vcf' )) mod_strelka.convert(strelka_in, indel_strelka_out) intermediate_files.add(indel_strelka_out) indel_intermediates.append(indel_strelka_out) if tnscope: import vcfModifier.modify_MuTect2 as mod_mutect2 tnscope_in = bed_intersector(tnscope, os.sep.join(( outdir, 'intersect.tnscope.vcf' )), inclusion, exclusion) intermediate_files.add(tnscope_in) snv_tnscope_out = os.sep.join(( outdir, 'snv.tnscope.vcf' )) indel_tnscope_out = os.sep.join(( outdir, 'indel.tnscope.vcf' )) mod_mutect2.convert(tnscope_in, snv_tnscope_out, indel_tnscope_out, True) for file_i in snv_tnscope_out, indel_tnscope_out: intermediate_files.add( file_i ) snv_intermediates.append(snv_tnscope_out) indel_intermediates.append(indel_tnscope_out) intermediate_vcfs['TNscope']['snv'] = snv_tnscope_out intermediate_vcfs['TNscope']['indel'] = indel_tnscope_out if platypus: platypus_in = bed_intersector(platypus, os.sep.join(( outdir, 'intersect.platypus.vcf' )), inclusion, exclusion) intermediate_files.add(platypus_in) snv_platypus_out = os.sep.join(( outdir, 'snv.platypus.vcf' )) indel_platypus_out = os.sep.join(( outdir, 'indel.platypus.vcf' )) splitVcf.split_into_snv_and_indel(platypus_in, snv_platypus_out, indel_platypus_out) for file_i in snv_platypus_out, indel_platypus_out: intermediate_files.add( file_i ) snv_intermediates.append(snv_platypus_out) indel_intermediates.append(indel_platypus_out) intermediate_vcfs['Platypus']['snv'] = snv_platypus_out intermediate_vcfs['Platypus']['indel'] = indel_platypus_out # Combine SNV/INDEL variant candidates snv_combined = os.sep.join(( outdir, 'unsorted.CombineVariants.snv.vcf' )) indel_combined = os.sep.join(( outdir, 'unsorted.CombineVariants.indel.vcf' )) getUniqueVcfPositions.combine(snv_intermediates, snv_combined) getUniqueVcfPositions.combine(indel_intermediates, indel_combined) for file_i in snv_combined, indel_combined: intermediate_files.add( file_i ) # Sort them: snv_combined_sorted = os.sep.join(( outdir, 'CombineVariants.snv.vcf' )) indel_combined_sorted = os.sep.join(( outdir, 'CombineVariants.indel.vcf' )) vcfsorter(ref, snv_combined, snv_combined_sorted) vcfsorter(ref, indel_combined, indel_combined_sorted) if not keep_intermediates: for file_i in intermediate_files: subprocess.call( ('rm', '-v', file_i ) ) return snv_combined_sorted, indel_combined_sorted, intermediate_vcfs, intermediate_files
def combinePaired(outdir, ref, tbam, nbam, inclusion=None, exclusion=None, mutect=None, indelocator=None, mutect2=None, varscan_snv=None, varscan_indel=None, jsm=None, sniper=None, vardict=None, muse=None, lofreq_snv=None, lofreq_indel=None, scalpel=None, strelka_snv=None, strelka_indel=None, tnscope=None, keep_intermediates=False): hg_dict = re.sub(r'\.fa(sta)?$', '.dict', ref) intermediate_files = set() snv_intermediates = [] indel_intermediates = [] intermediate_vcfs = {'MuTect2':{'snv': None, 'indel': None}, \ 'VarDict':{'snv': None, 'indel': None}, \ 'TNscope':{'snv': None, 'indel': None}, } # Modify direct VCF outputs for merging: if mutect or indelocator: import vcfModifier.modify_MuTect as mod_mutect if mutect: if exclusion: mutect_ex = bed_exclude( mutect, exclusion, os.sep.join((outdir, 'snv.mutect1.ex.vcf'))) intermediate_files.add(mutect_ex) else: mutect_ex = mutect if inclusion: mutect_in = bed_include( mutect_ex, inclusion, os.sep.join((outdir, 'snv.mutect1.in.vcf'))) intermediate_files.add(mutect_in) else: mutect_in = mutect_ex snv_mutect_out = os.sep.join((outdir, 'snv.mutect1.vcf')) mod_mutect.convert(mutect_in, snv_mutect_out, tbam, nbam) intermediate_files.add(snv_mutect_out) snv_intermediates.append(snv_mutect_out) if indelocator: if exclusion: indelocator_ex = bed_exclude( indelocator, exclusion, os.sep.join((outdir, 'indel.indelocator.ex.vcf'))) intermediate_files.add(indelocator_ex) else: indelocator_ex = indelocator if inclusion: indelocator_in = bed_include( indelocator_ex, inclusion, os.sep.join((outdir, 'indel.indelocator.in.vcf'))) intermediate_files.add(indelocator_in) else: indelocator_in = indelocator_ex indel_indelocator_out = os.sep.join( (outdir, 'indel.indelocator.vcf')) mod_mutect.convert(indelocator_in, indel_indelocator_out, tbam, nbam) intermediate_files.add(indel_indelocator_out) indel_intermediates.append(indel_indelocator_out) if mutect2: import vcfModifier.modify_MuTect2 as mod_mutect2 if exclusion: mutect2_ex = bed_exclude(mutect2, exclusion, os.sep.join((outdir, 'mutect.ex.vcf'))) intermediate_files.add(mutect2_ex) else: mutect2_ex = mutect2 if inclusion: mutect2_in = bed_include(mutect2_ex, inclusion, os.sep.join((outdir, 'mutect.in.vcf'))) intermediate_files.add(mutect2_in) else: mutect2_in = mutect2_ex snv_mutect_out = os.sep.join((outdir, 'snv.mutect.vcf')) indel_mutect_out = os.sep.join((outdir, 'indel.mutect.vcf')) mod_mutect2.convert(mutect2_in, snv_mutect_out, indel_mutect_out, False) for file_i in snv_mutect_out, indel_mutect_out: intermediate_files.add(file_i) snv_intermediates.append(snv_mutect_out) indel_intermediates.append(indel_mutect_out) intermediate_vcfs['MuTect2']['snv'] = snv_mutect_out intermediate_vcfs['MuTect2']['indel'] = indel_mutect_out if varscan_snv or varscan_indel: import vcfModifier.modify_VarScan2 as mod_varscan2 if varscan_snv: if exclusion: varscan_ex = bed_exclude( varscan_snv, exclusion, os.sep.join((outdir, 'snv.varscan.ex.vcf'))) intermediate_files.add(varscan_ex) else: varscan_ex = varscan_snv if inclusion: varscan_in = bed_include( varscan_ex, inclusion, os.sep.join((outdir, 'snv.varscan.in.vcf'))) intermediate_files.add(varscan_in) else: varscan_in = varscan_ex snv_varscan_out = os.sep.join((outdir, 'snv.varscan.vcf')) mod_varscan2.convert(varscan_in, snv_varscan_out) intermediate_files.add(snv_varscan_out) snv_intermediates.append(snv_varscan_out) if varscan_indel: if exclusion: varscan_ex = bed_exclude( varscan_indel, exclusion, os.sep.join((outdir, 'indel.varscan.ex.vcf'))) intermediate_files.add(varscan_ex) else: varscan_ex = varscan_indel if inclusion: varscan_in = bed_include( varscan_ex, inclusion, os.sep.join((outdir, 'indel.varscan.in.vcf'))) intermediate_files.add(varscan_in) else: varscan_in = varscan_ex indel_varscan_out = os.sep.join((outdir, 'indel.varscan.vcf')) mod_varscan2.convert(varscan_in, indel_varscan_out) intermediate_files.add(indel_varscan_out) indel_intermediates.append(indel_varscan_out) if jsm: import vcfModifier.modify_JointSNVMix2 as mod_jsm if exclusion: jsm_ex = bed_exclude(jsm, exclusion, os.sep.join((outdir, 'snv.jsm.ex.vcf'))) intermediate_files.add(jsm_ex) else: jsm_ex = jsm if inclusion: jsm_in = bed_include(jsm_ex, inclusion, os.sep.join((outdir, 'snv.jsm.in.vcf'))) intermediate_files.add(jsm_in) else: jsm_in = jsm_ex jsm_out = os.sep.join((outdir, 'snv.jsm.vcf')) mod_jsm.convert(jsm_in, jsm_out) intermediate_files.add(jsm_out) snv_intermediates.append(jsm_out) if sniper: import vcfModifier.modify_SomaticSniper as mod_sniper if exclusion: sniper_ex = bed_exclude( sniper, exclusion, os.sep.join((outdir, 'snv.somaticsniper.ex.vcf'))) intermediate_files.add(sniper_ex) else: sniper_ex = sniper if inclusion: sniper_in = bed_include( sniper_ex, inclusion, os.sep.join((outdir, 'snv.somaticsniper.in.vcf'))) intermediate_files.add(sniper_in) else: sniper_in = sniper_ex sniper_out = os.sep.join((outdir, 'snv.somaticsniper.vcf')) mod_sniper.convert(sniper_in, sniper_out) intermediate_files.add(sniper_out) snv_intermediates.append(sniper_out) if vardict: import vcfModifier.modify_VarDict as mod_vardict if exclusion: vardict_ex = bed_exclude(vardict, exclusion, os.sep.join((outdir, 'vardict.ex.vcf'))) intermediate_files.add(vardict_ex) else: vardict_ex = vardict if inclusion: vardict_in = bed_include(vardict_ex, inclusion, os.sep.join((outdir, 'vardict.in.vcf'))) intermediate_files.add(vardict_in) else: vardict_in = vardict_ex snv_vardict_out = os.sep.join((outdir, 'snv.vardict.vcf')) indel_vardict_out = os.sep.join((outdir, 'indel.vardict.vcf')) mod_vardict.convert(vardict_in, snv_vardict_out, indel_vardict_out) sorted_snv_vardict_out = os.sep.join((outdir, 'snv.sort.vardict.vcf')) sorted_indel_vardict_out = os.sep.join( (outdir, 'indel.sort.vardict.vcf')) vcfsorter(ref, snv_vardict_out, sorted_snv_vardict_out) vcfsorter(ref, indel_vardict_out, sorted_indel_vardict_out) for file_i in snv_vardict_out, indel_vardict_out, sorted_snv_vardict_out, sorted_indel_vardict_out: intermediate_files.add(file_i) snv_intermediates.append(sorted_snv_vardict_out) indel_intermediates.append(sorted_indel_vardict_out) intermediate_vcfs['VarDict']['snv'] = sorted_snv_vardict_out intermediate_vcfs['VarDict']['indel'] = sorted_indel_vardict_out if muse: if exclusion: muse_ex = bed_exclude(muse, exclusion, os.sep.join((outdir, 'snv.muse.ex.vcf'))) intermediate_files.add(muse_ex) else: muse_ex = muse if inclusion: muse_in = bed_include(muse_ex, inclusion, os.sep.join((outdir, 'snv.muse.in.vcf'))) intermediate_files.add(muse_in) else: muse_in = muse_ex muse_out = os.sep.join((outdir, 'snv.muse.vcf')) copy_TextFile.copy(muse_in, muse_out) intermediate_files.add(muse_out) snv_intermediates.append(muse_out) if lofreq_snv: if exclusion: lofreq_ex = bed_exclude(lofreq_snv, exclusion, os.sep.join((outdir, 'snv.lofreq.ex.vcf'))) intermediate_files.add(lofreq_ex) else: lofreq_ex = lofreq_snv if inclusion: lofreq_in = bed_include(lofreq_ex, inclusion, os.sep.join((outdir, 'snv.lofreq.in.vcf'))) intermediate_files.add(lofreq_in) else: lofreq_in = lofreq_ex snv_lofreq_out = os.sep.join((outdir, 'snv.lofreq.vcf')) copy_TextFile.copy(lofreq_in, snv_lofreq_out) intermediate_files.add(snv_lofreq_out) snv_intermediates.append(snv_lofreq_out) if lofreq_indel: if exclusion: lofreq_ex = bed_exclude( lofreq_indel, exclusion, os.sep.join((outdir, 'indel.lofreq.ex.vcf'))) intermediate_files.add(lofreq_ex) else: lofreq_ex = lofreq_snv if inclusion: lofreq_in = bed_include( lofreq_ex, inclusion, os.sep.join((outdir, 'indel.lofreq.in.vcf'))) intermediate_files.add(lofreq_in) else: lofreq_in = lofreq_ex indel_lofreq_out = os.sep.join((outdir, 'indel.lofreq.vcf')) copy_TextFile.copy(lofreq_in, indel_lofreq_out) intermediate_files.add(indel_lofreq_out) indel_intermediates.append(indel_lofreq_out) if scalpel: if exclusion: scalpel_ex = bed_exclude( scalpel, exclusion, os.sep.join((outdir, 'indel.scalpel.ex.vcf'))) intermediate_files.add(scalpel_ex) else: scalpel_ex = scalpel if inclusion: scalpel_in = bed_include( scalpel_ex, inclusion, os.sep.join((outdir, 'indel.scalpel.in.vcf'))) intermediate_files.add(scalpel_in) else: scalpel_in = scalpel_ex scalpel_out = os.sep.join((outdir, 'indel.scalpel.vcf')) copy_TextFile.copy(scalpel_in, scalpel_out) intermediate_files.add(scalpel_out) indel_intermediates.append(scalpel_out) if strelka_snv or strelka_indel: import vcfModifier.modify_Strelka as mod_strelka if strelka_snv: if exclusion: strelka_ex = bed_exclude( strelka_snv, exclusion, os.sep.join((outdir, 'snv.strelka.ex.vcf'))) intermediate_files.add(strelka_ex) else: strelka_ex = strelka_snv if inclusion: strelka_in = bed_include( strelka_ex, inclusion, os.sep.join((outdir, 'snv.strelka.in.vcf'))) intermediate_files.add(strelka_in) else: strelka_in = strelka_ex snv_strelka_out = os.sep.join((outdir, 'snv.strelka.vcf')) mod_strelka.convert(strelka_in, snv_strelka_out) intermediate_files.add(snv_strelka_out) snv_intermediates.append(snv_strelka_out) if strelka_indel: if exclusion: strelka_ex = bed_exclude( strelka_indel, exclusion, os.sep.join((outdir, 'indel.strelka.ex.vcf'))) intermediate_files.add(strelka_ex) else: strelka_ex = strelka_snv if inclusion: strelka_in = bed_include( strelka_ex, inclusion, os.sep.join((outdir, 'indel.strelka.in.vcf'))) intermediate_files.add(strelka_in) else: strelka_in = strelka_ex indel_strelka_out = os.sep.join((outdir, 'indel.strelka.vcf')) mod_strelka.convert(strelka_in, indel_strelka_out) intermediate_files.add(indel_strelka_out) indel_intermediates.append(indel_strelka_out) if tnscope: import vcfModifier.modify_MuTect2 as mod_mutect2 if exclusion: tnscope_ex = bed_exclude(tnscope, exclusion, os.sep.join((outdir, 'tnscope.ex.vcf'))) intermediate_files.add(tnscope_ex) else: tnscope_ex = tnscope if inclusion: tnscope_in = bed_include(tnscope_ex, inclusion, os.sep.join((outdir, 'tnscope.in.vcf'))) intermediate_files.add(tnscope_in) else: tnscope_in = tnscope_ex snv_tnscope_out = os.sep.join((outdir, 'snv.tnscope.vcf')) indel_tnscope_out = os.sep.join((outdir, 'indel.tnscope.vcf')) mod_mutect2.convert(tnscope_in, snv_tnscope_out, indel_tnscope_out, True) for file_i in snv_tnscope_out, indel_tnscope_out: intermediate_files.add(file_i) snv_intermediates.append(snv_tnscope_out) indel_intermediates.append(indel_tnscope_out) intermediate_vcfs['TNscope']['snv'] = snv_tnscope_out intermediate_vcfs['TNscope']['indel'] = indel_tnscope_out # Combine SNV/INDEL variant candidates snv_combined = os.sep.join((outdir, 'unsorted.CombineVariants.snv.vcf')) indel_combined = os.sep.join( (outdir, 'unsorted.CombineVariants.indel.vcf')) getUniqueVcfPositions.combine(snv_intermediates, snv_combined) getUniqueVcfPositions.combine(indel_intermediates, indel_combined) for file_i in snv_combined, indel_combined: intermediate_files.add(file_i) # Sort them: snv_combined_sorted = os.sep.join((outdir, 'CombineVariants.snv.vcf')) indel_combined_sorted = os.sep.join((outdir, 'CombineVariants.indel.vcf')) vcfsorter(ref, snv_combined, snv_combined_sorted) vcfsorter(ref, indel_combined, indel_combined_sorted) if not keep_intermediates: for file_i in intermediate_files: subprocess.call(('rm', '-v', file_i)) return snv_combined_sorted, indel_combined_sorted, intermediate_vcfs, intermediate_files