我正在从另一个文件的行中搜索一个值。确切的值只会在搜索文件中出现一次。我怎样才能使这个过程更快?这是我当前的代码:
filltaxlist = open("file with query number.txt", "rw")
fulltaxa = open("output file with hit line match", "rw")
for line in filltaxalist:
line = line.strip()
taxid = re.split("\t", line)
lookup = taxid[5] # this value is a number and I need the exact match only so I convert it to an integer
int1 = int(lookup)
for line in open("File to search.txt", "r"):
data = re.split(',', line)
hit = int(data[0]) # every value in this file is a number separated by a ,
if lookup in line:
if int1 == hit:
fulltaxa.write(line)
这很好用,因为它写得很慢。此外,我正在搜索的文件大小超过 GB。这
行示例filltaxlist
:
cvvel_1234 403454663 29.43 3e-30 55.55555555234 1172189
cvell_1444 2342333 30.00 1e-50 34.34584359345 5911
cvell_1444 234230055 23.23 1e-60 32.23445983454 46245
cvell_1444 233493003 23.44 1e-43 35.23595604593 46245
fulltaxa
应该返回什么:
1172189, 5943, 1002030, 12345
5911, 11234, 112356, 234, 3456, 44568, 78356
46245, 123, 3432456, 123488976, 23564, 334
46245, 123, 3432456, 123488976, 23564, 334