def write_stats_to_file(filename, counts, mincount):
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename + ".txt", 'w', encoding="utf-8") as f:
if args.perc == 0:
percentile = 0
else:
percentile = numpy.percentile(numpy.fromiter(counts.values(), numpy.int32), args.perc)
threshold = max(percentile, mincount)
for k, v in counts.items():
if v >= threshold:
entry = k.split(SEPARATOR)
entry.append(str(v))
f.write('\t'.join(entry) + '\n')
if args.pickle:
with open(filename + ".pickle", 'wb') as f:
pickle.dump(counts, f)
评论列表
文章目录