File size: 1,112 Bytes
a0e2695
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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