为什么re.match在这里不能正常运行?

问题描述

我正在尝试使用Python解析pdb文件(蛋白质数据库)。

文件中的此类行引起了麻烦:

ATOM 4811 HB2ASER A 329 41.099 -2.338 37.406 0.74 12.06 H

否则,它们将采用以下格式:

ATOM 4810 HA BSER A 329 39.458 -2.064 39.518 0.26 11.30 H

在这里,可见,列表中的第3个和第4个元素将被合并,当我拆分列表时,它们被视为单个元素。

这是我要克服的方法:

for line in pdbfile:
        line_list = line.split()
        id = line_list[0]
        
        if id == 'ATOM':
            s_no = line_list[1]
            atom = line_list[3]
            chain_id = line_list[4]
            if len(chain_id) > 1:
                line_list.insert(0,0)
                match = re.match(r"([a-z]+)([0-9]+)([a-z]+)",atom,re.I)
                if match:
                    atom = match.groups()[-1]

            x_coord = line_list[6]
            y_coord = line_list[7]
            z_coord = line_list[8]

            with open('coordinates.csv','a',newline='') as csvfile:
                # print(chain_id)
                writer = csv.writer(csvfile)
                writer.writerow([s_no,pdb_id,resolution,chain_id,x_coord,y_coord,z_coord])

当我在外壳中运行相同的代码时,它将产生正确的输出。但是,当我运行该程序时,我尝试创建的csv文件没有任何更改。结果是:

csv result

因此,基本上,上面的if语句并没有在shell中执行它的操作。为什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...