-->

如何提取从PDB文件链?(How to extract chains from a PDB file

2019-07-30 16:00发布

我想提取pdb文件链。 我有一个名为pdb.txt文件,其中包含PDB的ID,如下图所示。 前四个字符表示PDB ID和最后一个字符是连锁的ID。

1B68A 
1BZ4B
4FUTA

我想1)读出由线2上的文件中的行)从相应的PDB文件下载每个链的原子坐标。
3)将输出保存到文件夹。

我用下面的脚本提取链。 但是这个代码仅打印从PDB文件链。

for i in 1B68 1BZ4 4FUT
do 
wget -c "http://www.pdb.org/pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId="$i -O $i.pdb
grep  ATOM $i.pdb | grep 'A' > $i\_A.pdb
done

Answer 1:

下面BioPython代码应该满足您的需求很好。

它使用PDB.Select仅选择所需的链(在你的情况下,一个链)和PDBIO()创建只包含链的结构。

import os
from Bio import PDB


class ChainSplitter:
    def __init__(self, out_dir=None):
        """ Create parsing and writing objects, specify output directory. """
        self.parser = PDB.PDBParser()
        self.writer = PDB.PDBIO()
        if out_dir is None:
            out_dir = os.path.join(os.getcwd(), "chain_PDBs")
        self.out_dir = out_dir

    def make_pdb(self, pdb_path, chain_letters, overwrite=False, struct=None):
        """ Create a new PDB file containing only the specified chains.

        Returns the path to the created file.

        :param pdb_path: full path to the crystal structure
        :param chain_letters: iterable of chain characters (case insensitive)
        :param overwrite: write over the output file if it exists
        """
        chain_letters = [chain.upper() for chain in chain_letters]

        # Input/output files
        (pdb_dir, pdb_fn) = os.path.split(pdb_path)
        pdb_id = pdb_fn[3:7]
        out_name = "pdb%s_%s.ent" % (pdb_id, "".join(chain_letters))
        out_path = os.path.join(self.out_dir, out_name)
        print "OUT PATH:",out_path
        plural = "s" if (len(chain_letters) > 1) else ""  # for printing

        # Skip PDB generation if the file already exists
        if (not overwrite) and (os.path.isfile(out_path)):
            print("Chain%s %s of '%s' already extracted to '%s'." %
                    (plural, ", ".join(chain_letters), pdb_id, out_name))
            return out_path

        print("Extracting chain%s %s from %s..." % (plural,
                ", ".join(chain_letters), pdb_fn))

        # Get structure, write new file with only given chains
        if struct is None:
            struct = self.parser.get_structure(pdb_id, pdb_path)
        self.writer.set_structure(struct)
        self.writer.save(out_path, select=SelectChains(chain_letters))

        return out_path


class SelectChains(PDB.Select):
    """ Only accept the specified chains when saving. """
    def __init__(self, chain_letters):
        self.chain_letters = chain_letters

    def accept_chain(self, chain):
        return (chain.get_id() in self.chain_letters)


if __name__ == "__main__":
    """ Parses PDB id's desired chains, and creates new PDB structures. """
    import sys
    if not len(sys.argv) == 2:
        print "Usage: $ python %s 'pdb.txt'" % __file__
        sys.exit()

    pdb_textfn = sys.argv[1]

    pdbList = PDB.PDBList()
    splitter = ChainSplitter("/home/steve/chain_pdbs")  # Change me.

    with open(pdb_textfn) as pdb_textfile:
        for line in pdb_textfile:
            pdb_id = line[:4].lower()
            chain = line[4]
            pdb_fn = pdbList.retrieve_pdb_file(pdb_id)
            splitter.make_pdb(pdb_fn, chain)

最后一点: 不要写你自己的PDB文件分析器 。 格式规范是丑陋的( 真难看 ),以及故障的PDB文件的数量那里是惊人的。 使用像BioPython一个工具,将处理解析为您服务!

此外,而不是使用wget ,你应该使用与PDB数据库你互动的工具。 他们把FTP连接限制考虑,PDB数据库性质的变化,等等。 我应该知道-我更新Bio.PDBList考虑到数据库的变化。 =)



Answer 2:

比方说,你有以下文件pdb_structures

1B68A 
1BZ4B
4FUTA

然后在load_pdb.sh代码

while read name
do
    chain=${name:4:1}
    name=${name:0:4}
    wget -c "http://www.pdb.org/pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId="$name -O $name.pdb
    awk -v chain=$chain '$0~/^ATOM/ && substr($0,20,1)==chain {print}' $name.pdb > $name\_$chain.pdb
    #   rm $name.pdb
done

取消注释的最后一行,如果你不需要原始PDB的。
执行

cat pdb_structures | ./load_pdb.sh


Answer 3:

这可能是对asnwering这个问题有点晚,但我会说出我的意见。 Biopython有一些非常方便的功能,将帮助您轻松实现这样的想法。 您可以使用类似的自定义选择类,然后调用它要内选择与原PDB文件循环链中的每一个。

    from Bio.PDB import Select, PDBIO
    from Bio.PDB.PDBParser import PDBParser

    class ChainSelect(Select):
        def __init__(self, chain):
            self.chain = chain

        def accept_chain(self, chain):
            if chain.get_id() == self.chain:
                return 1
            else:          
                return 0

    chains = ['A','B','C']
    p = PDBParser(PERMISSIVE=1)       
    structure = p.get_structure(pdb_file, pdb_file)

    for chain in chains:
        pdb_chain_file = 'pdb_file_chain_{}.pdb'.format(chain)                                 
        io_w_no_h = PDBIO()               
        io_w_no_h.set_structure(structure)
        io_w_no_h.save('{}'.format(pdb_chain_file), ChainSelect(chain))


文章来源: How to extract chains from a PDB file?