您的位置:首页 > 编程语言 > Python开发

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

2017-11-29 09:16 771 查看
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)

   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐