1
$\begingroup$

I'm new to biopython & I'm trying to extract residues from specific chain of each file from a list of 316 pdb files. Eg: 1d8t has four chains A, B, C & D of which my interest is to extract just the residues of C chain. As the chain of interest differs for different files, I'm not knowing how to extract specific chain residue from each file and save it separately.

from Bio import *
from Bio.PDB.PDBParser import PDBParser
from Bio.PDB.Polypeptide import PPBuilder
structure = PDBParser().get_structure('1d8t', '1d8t.pdb')    


model = structure[0]
chain = model['C']

for i in chain.get_residues():
    print(i)

With the above code I was able to extract the residues of C chains not sure how to proceed for multiple files in python.

$\endgroup$

1 Answer 1

1
$\begingroup$

Create a function and run it for each pdb file.

from Bio.PDB import PDBParser

def print_residues(name, pdb_file, chain_key, out_file):
    parser = PDBParser()
    structure = parser.get_structure(name, pdb_file)
    model = structure[0]
    chain = model[chain_key]
    with open(out_file, 'w') as fp:
        for i in chain.get_residues():
            print(i, file=fp)

Then run the function for all pdb files.

print_residues('1d8t', '1d8t.pdb', 'C', '1d8t.txt')
# ...
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.