问题描述
我之前发布了一个问题,询问如何分隔文件 (How would I pull multiple partial match strings out of rows and keep them in the same order on the same lines?) 并想出了如何使用
提取部分匹配项prefixes = ["Zm00018ab","Zm00001eb","Zm00039ab"]
with open("MaizeGDB_maize_pangene_2020_08.txt","r") as infile:
with open("pangene_adjusted_2021_06.txt","w") as outfile:
for line in infile:
elements = line.split("\t")
to_write = []
for elem in elements:
if elem[:9] in prefixes:
to_write.append(elem)
print (to_write)
outfile.write("\t""\n".join(to_write))
但我的输出有原始数据中不存在的重复,并且没有分隔单词 输出:
Zm00001eb045170Zm00001eb045170
Zm00018ab047740Zm00001eb045170
Zm00018ab047740
Zm00001eb045180Zm00001eb045170
Zm00018ab047740
Zm00001eb045180
Zm00039ab046010Zm00001eb045170
Zm00018ab047740
我正在寻找如何做到这一点,但我想我会问你有帮助的人,以防在我找到解决方案之前你们中的一个人可以回答。
理想的输出是
Zm00001eb045170 Zm00018ab047740 Zm00038ab046680 Zm00018ab047760 Zm00038ab046670 Zm00001eb045180
new line with more gene IDs
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)