本文整理匯總了Python中svtools.vcf.file.Vcf.file_format方法的典型用法代碼示例。如果您正苦於以下問題:Python Vcf.file_format方法的具體用法?Python Vcf.file_format怎麽用?Python Vcf.file_format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類svtools.vcf.file.Vcf
的用法示例。
在下文中一共展示了Vcf.file_format方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: bedpeToVcf
# 需要導入模塊: from svtools.vcf.file import Vcf [as 別名]
# 或者: from svtools.vcf.file.Vcf import file_format [as 別名]
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 and header if no variants found
if in_header == True:
myvcf.add_header(header)
myvcf.file_format='VCFv4.2'
vcf_out.write(myvcf.get_header() + '\n')
vcf_out.close()
return
示例2: bedpeToVcf
# 需要導入模塊: from svtools.vcf.file import Vcf [as 別名]
# 或者: from svtools.vcf.file.Vcf import file_format [as 別名]
def bedpeToVcf(bedpe_file, vcf_out):
myvcf = Vcf()
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', 14)[-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'))
if bedpe.svtype == 'BND':
bedpe1_list = [
bedpe.c1,
bedpe.b1 + 1,
bedpe.name + '_1', #ID
'N',
'<' + str(bedpe.svtype) + '>', #ALT
bedpe.score,
bedpe.filter
]
bedpe1_list.extend(bedpe.misc)
var1 = Variant(bedpe1_list, myvcf)
if bedpe.o1 == '+':
if bedpe.o2 == '-':
var1.alt = '%s[%s:%s[' % (var1.ref, bedpe.c2, bedpe.b2 + 1)
elif bedpe.o2 == '+':
var1.alt = '%s]%s:%s]' % (var1.ref, bedpe.c2, bedpe.b2 + 1)
elif bedpe.o1 == '-':
if bedpe.o2 == '+':
var1.alt = ']%s:%s]%s' % (bedpe.c2, bedpe.b2 + 1, var1.ref)
elif bedpe.o2 == '-':
var1.alt = '[%s:%s[%s' % (bedpe.c2, bedpe.b2 + 1, var1.ref)
misc = copy.deepcopy(bedpe.misc)
strands = re.split('=|:',''.join(filter(lambda x: 'STRANDS=' in x, bedpe.misc[0].split(";"))))
strands_str = str(strands[0]) + '=' + str(strands[1][::-1]) + ':' + str(strands[2])
misc[0]=misc[0].replace(''.join(filter(lambda x: 'STRANDS=' in x, bedpe.misc[0].split(";"))), strands_str)
#add the cipos ciend,cipos95 and ciend95 variables
misc[0]=misc[0].replace(''.join(filter(lambda x: 'CIPOS=' in x, bedpe.misc[0].split(";"))),'CIPOS='+ re.split('=',''.join(filter(lambda x: 'CIEND=' in x, bedpe.misc[0].split(";"))))[1])
misc[0]=misc[0].replace(''.join(filter(lambda x: 'CIEND=' in x, bedpe.misc[0].split(";"))),'CIEND='+ re.split('=',''.join(filter(lambda x: 'CIPOS=' in x, bedpe.misc[0].split(";"))))[1])
misc[0]=misc[0].replace(''.join(filter(lambda x: 'CIPOS95=' in x, bedpe.misc[0].split(";"))),'CIPOS95='+ re.split('=',''.join(filter(lambda x: 'CIEND95=' in x, bedpe.misc[0].split(";"))))[1])
misc[0]=misc[0].replace(''.join(filter(lambda x: 'CIEND95=' in x, bedpe.misc[0].split(";"))),'CIEND95='+ re.split('=',''.join(filter(lambda x: 'CIPOS95=' in x, bedpe.misc[0].split(";"))))[1])
#Change MATEID
misc[0]= misc[0].replace(''.join(filter(lambda x: 'MATEID=' in x, bedpe.misc[0].split(";"))),'MATEID=' + bedpe.name + '_2')
#ADD IDENTIFIER FOR SECONDARY BREAKEND MATE
misc[0]=misc[0].replace(''.join(filter(lambda x: 'EVENT=' in x, bedpe.misc[0].split(";"))),''.join(filter(lambda x: 'EVENT=' in x, bedpe.misc[0].split(";"))) + ';SECONDARY;')
bedpe2_list = [
bedpe.c2, #chrom1
bedpe.b2 + 1,
bedpe.name + '_2', #ID
'N',
'<' + str(bedpe.svtype) + '>', #ALT
bedpe.score,
bedpe.filter
]
bedpe2_list.extend(misc)
var2 = Variant(bedpe2_list, myvcf)
# add the strands field. For variant 2 must switch the order
if bedpe.o2 == '+':
if bedpe.o1 == '-':
var2.alt = '%s[%s:%s[' % (var2.ref, bedpe.c1, bedpe.b1 + 1)
elif bedpe.o1 == '+':
var2.alt = '%s]%s:%s]' % (var2.ref, bedpe.c1, bedpe.b1 + 1)
elif bedpe.o2 == '-':
if bedpe.o1 == '+':
var2.alt = ']%s:%s]%s' % (bedpe.c1, bedpe.b1 + 1, var2.ref)
elif bedpe.o1 == '-':
var2.alt = '[%s:%s[%s' % (bedpe.c1, bedpe.b1 + 1, var2.ref)
if bedpe.malformedFlag == 0:
vcf_out.write(var1.get_var_string() + '\n')
vcf_out.write(var2.get_var_string() + '\n')
elif bedpe.malformedFlag == 1:
vcf_out.write(var2.get_var_string() + '\n')
elif bedpe.malformedFlag == 2:
vcf_out.write(var1.get_var_string() + '\n')
else:
# set VCF info elements for simple events
bedpe_list = [
#.........這裏部分代碼省略.........