I am trying to obtain the sequence from PDB file, but no output is given when I run the following code :
from Bio import SeqIO with open("1a9l.pdb", "r") as handle: for record in SeqIO.parse(handle, "pdb-atom"): print(record.seq)
Bioinformatics Stack Exchange is a question and answer site for researchers, developers, students, teachers, and end users interested in bioinformatics. It only takes a minute to sign up.Sign up to join this community
If you are using a conda version of python you can use Pymol module for this, which is actually more robust in some aspects than
bio.PDB, although errors may cause segmentation faults. The following:
import pymol2 ## paralellisable version. with pymol2.PyMOL() as pymol: pymol.cmd.fetch('1a9l') print(pymol.cmd.get_fastastr('polymer.nucleic'))
Alternatively, you can use PDBe's API.
import requests response = requests.get('https://www.ebi.ac.uk/pdbe/api/pdb/entry/molecules/1a9l').json()['1a9l'] for entity in response: if entity['molecule_type'] == 'polyribonucleotide': print(entity['sequence'])
Do note that missing 'residues' (residues, small molecules and nucleotides) will cause issues. PDB files do not have missing 'residues', while mmCIF files have a dictionary that does. The API will give you the latter.
That PDB entry is an RNA molecule, so there is no protein sequence to extract.
If it extracted the RNA sequence by default here you can see there could be an ambiguity as to whether it was an RNA sequence or a protein sequence, as the alphabets share characters.