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

来源:互联网 发布:node.js 实战 第二版 编辑:程序博客网 时间:2024/05/20 21:57
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<len(line):
    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)
   


阅读全文
0 0