简体   繁体   English

Python:在Fasta标头中添加增量ID

[英]Python: add incremental ID in fasta header

I try to create a multi fasta from a .csv file with a incremental ID in the header. 我尝试从.csv文件中在标题中使用增量ID来创建多fasta。 But my script don't works well. 但是我的脚本效果不好。 Any suggestion? 有什么建议吗?

M=open('/home/anna/Scrivania/db_mat/matk_2db_c.csv','r')
M_out=open('/home/anna/Scrivania/db_mat/db_matk_bronx.fas', 'w')

for i in range[1,92]:
    num = "m" + str(i)
for line in M:
    line1=line.split(',')
    ID = line1[0]
    SEQ = line1[1]
    seq =line1[2]
M_out.write('>'+ num +'_' +ID +'_'+ SEQ +'\n' + seq )

M.close()
M_out.close()
for i,line in enumerate(M,1):
    num = "m"+str(i)
    line1=line.split(',')
    ID = line1[0]
    SEQ = line1[1]
    seq =line1[2]
    M_out.write(...)

this just enumerates through the lines and gives you an index from 1..N where N is the number of lines 这只是枚举行,并为您提供从1..N开始的索引,其中N是行数

before you were iterating over all the nums, so by the time you got to for line in M num would equal "m91" for all lines 在遍历所有num之前,因此到for line in M num的for line in M等于所有行的“ m91”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM