python分别用while和for于vcf格式提取复等位基因的snp(并计算分别条数)

line=open('cleanqt.vcf','r').readlines()     #use ‘while’
out1=open('alle=1.vcf','w')
out2=open('alle=2.vcf','w')
out3=open('alle=3.vcf','w')

a=0
b=0
c=0
d=0
while a     word=line[a].split()
    if  len(word[4])==3:
        out2.write(line[a])
        b+=1
    elif len(word[4])==5:
        out3.write(line[a])
        c+=1
    else:
        out1.write(line[a])
        d+=1
    a+=1

print(d,b,c)  


line=open('cleanqt.vcf','r').readlines() #use ‘for  in’
out1=open('alle=1.vcf','w')
out2=open('alle=2.vcf','w')
out3=open('alle=3.vcf','w')

a=0
b=0
c=0
for l in line:
    word=str(l).split()
    if len(word[4])==3:
        out2.write(str(l))
        b+=1
    elif len(word[4])==5:
        out3.write(str(l))
        c+=1
    else:
        out1.write(str(l))
        a+=1
print(a,b,c)
   


你可能感兴趣的:(python分别用while和for于vcf格式提取复等位基因的snp(并计算分别条数))