import re from tname import * from Rfile import * def Merge_Dlsc(sc_file, dl_file): scontents = j_reads(sc_file.name) scores = [] # 读取并保存第一个scores值 content = re.match('.*score=(\d.\d+?),', scontents[0]) score = content.group(1) scores.append(float(score)) # 保存剩下的scores值 for i in range(2, len(scontents)): if i % 2 == 0: # 使用正则表达式 content = re.match('.*score=(\d.\d+?),', scontents[i]) score = content.group(1) scores.append(float(score)) dcontents = j_reads(dl_file.name) dcontents[0] = dcontents[0].strip() + "\t" + "scores value" + "\n" name = Name() name = name + r"kcat_scores.tsv" # 结果文件名称 # 第一行与其它行格式不一样,单独写入 with open(name, "a") as f: f.write(dcontents[0]) # 写入剩下的行 for i in range(1, len(dcontents)): dcontents[i] = dcontents[i].strip() + "\t" + str(scores[i - 1]) + "\n" with open(name, "a") as f: f.write(dcontents[i]) return name