- 论坛徽章:
- 4
|
回复 6# yusmile0618
不确定我们说的对齐是不是一致,把这边修改的给贴一下:- import xlwt
- fname=open("1.txt","r")
- flocation=open("2.txt","r")
- fsnp=open("3.txt","r")
- book=xlwt.Workbook(encoding="utf-8",style_compression=0)
- sheet=book.add_sheet("snp",cell_overwrite_ok=True)
- n=0
- row=0
- for names in fname.readlines():
- name=names.strip("\n")
- row=row+1
- n=n+1
- col=5
- for locations in flocation.readlines():
- location=locations.split("\t")
- col=col+1
- snp1=location[0]
- position=str(location[1])
- ref=location[2]+" "+location[2]
- for snps in fsnp:
- snps=snps.split("\t")
- sample_name=snps[0]
- sample_snp=snps[2]
- sample_position=str(snps[3])
- genotype=snps[5]
- allele=genotype[0]+" "+genotype[1]
- if name==sample_name and position in sample_position:
- print "%d, %d, %s"%(row, col, allele)
- sheet.write(row,col,allele)
- else:
- pass
- #sheet.write(row,col,ref)
- fsnp.seek(0)
- flocation.seek(0)
- book.save("result.xls")
复制代码 |
|