How can I use biopython to extract each alpha carbon from a PDB file?
1
0
Entering edit mode
5.5 years ago

I have a PDB file (2i0q.pdb), and I must extract the A chain from the PDB file to another file called "A.pdb" which I have already done successfully. Next, I have to take A.pdb and extract each alpha carbon ("CA") into another file. I have tried to write the function that does this, but my output file "CA.txt" appears to be blank. Can someone see what I have done wrong?

from Bio.PDB import *

parser=PDBParser()



structure=parser.get_structure('X', '2i0q.pdb')

#This extracts each chain in the PDB file into its own separate file
for chain in structure.get_chains():
    io.set_structure(chain)
    io.save(chain.get_id() + ".pdb")

structure_2 = parser.get_structure('Y', 'A.pdb')

def CA(structure):
    f = open('CA.txt', 'w')
    for atom in structure:
        if atom =='CA':
            f.write(atom)



CA(structure_2)
python biopython pdb • 4.7k views
ADD COMMENT
2
Entering edit mode
5.5 years ago
Nitin Narwade ★ 1.6k

I am sure there must be some other way to directly parse the structure(using Bio.PDB.PDBParser object) and get the records of the selected atom using Bio.PDB module.

But here I am directly parsing .pdb file and selecting the records of interest using the regular expression

from Bio.PDB import *
import re

parser=PDBParser()
io=PDBIO()
structure=parser.get_structure('X', '2i0q.pdb')

for chain in structure.get_chains():
    io.set_structure(chain)
    io.save(chain.get_id() + ".pdb")

## I am sure there must be some other way to directly parse the pdb structure and get the records of selected atom in Bio.PDB module.

def CA(pdbFileName):
    fw = open('CA.txt', 'w')
    fr = open(pdbFileName, 'r')

    for record in fr:
        if(re.search(r'^ATOM\s+\d+\s+CA\s+', record)):
            fw.write(record)

    fw.close()
    fr.close()

CA('A.pdb')
ADD COMMENT
0
Entering edit mode

This works. Thank you very much!

ADD REPLY

Login before adding your answer.

Traffic: 1892 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6