想根据列表给fasta文件改名字, 但是搜索不到有这个功能的软件, 只好自己写一个
list文件的格式是用tab分割的两列列表,这里是change.list.txt:
A B
C D
E F
要改变的文档格式没限制,只要是文本文档就行, 这里是file.fas
效果就是把所有A字符串替换成B字符串, 把所有C字符串替换成D字符串
import pandas as pd
listname = "D:/BioEdit/change.list.txt" ##list文件
list = pd.read_csv(listname,sep='\t',header=None)
list_dic = {}
for index, row in list.iterrows():
list_dic[row[0]] = row[1]
filename = "D:/BioEdit/file.fas" ##文本文件
newfasta = filename + ".rename"
f = open(newfasta , "a")
with open (filename) as fasta:
for line in fasta.readlines():
for k, v in list_dic.items():
line = line.replace(k, v)
f.write(line)
f.close()
网友评论