我有一个大文件,如下例所示:
1 10161 10166 3
1 10166 10172 2
1 10172 10182 1
1 10183 10192 1
1 10193 10199 1
1 10212 10248 1
1 10260 10296 1
1 11169 11205 1
1 11336 11372 1
2 11564 11586 2
2 11586 11587 3
2 11587 11600 4
3 11600 11622 2
我想在每行的开头添加一个“chr”,例如:
chr1 10161 10166 3
chr1 10166 10172 2
chr1 10172 10182 1
chr1 10183 10192 1
chr1 10193 10199 1
chr1 10212 10248 1
chr1 10260 10296 1
chr1 11169 11205 1
chr1 11336 11372 1
chr2 11564 11586 2
chr2 11586 11587 3
chr2 11587 11600 4
chr3 11600 11622 2
我在 python 中尝试了以下代码:
file = open("myfile.bg", "r")
for line in file:
newline = "chr" + line
out = open("outfile.bg", "w")
for new in newline:
out.write("n"+new)
但没有返回我想要的。您知道如何为此目的修复代码吗?
完全同意@rychaza,这是我使用你的代码的版本
file = open("myfile.bg", "r")
out = open("outfile.bg", "w")
for line in file:
out.write("chr" + line)
out.close()
file.close()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)