def bedpeToVcf(bedpe_file, vcf_out): myvcf = Vcf() converter = BedpeToVcfConverter(myvcf) in_header = True # parse the bedpe data header = list() for line in bedpe_file: if in_header: if line[0:2] == '##': header.append(line) continue elif line[0] == '#' and line[1] != '#': sample_list_str = line.rstrip().split('\t', 20)[-1] header.append('\t'.join([ '#CHROM', 'POS', 'ID', 'REF', 'ALT', 'QUAL', 'FILTER', 'INFO', sample_list_str ])) continue else: in_header = False myvcf.add_header(header) myvcf.file_format = 'VCFv4.2' vcf_out.write(myvcf.get_header() + '\n') # bedpe = Bedpe(line.rstrip().split('\t')) variants = converter.convert(bedpe) for v in variants: vcf_out.write(v.get_var_string() + '\n') # close the VCF output file vcf_out.close() return
def setUp(self): vcf = Vcf() self.converter = BedpeToVcfConverter(vcf)