This works. Thank you very much!
• 1 views
•
link
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)
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')
This works. Thank you very much!
Log in to answer this question.