Example #1
0
class PDBFile:
    def __init__(self, code, in_pdb):
        self.code = code
        self.struct = PDBParser(PERMISSIVE=1,
                                QUIET=1).get_structure(self.code, in_pdb)

    def residues_map(self, selected_chain=None, standard_aa=True):
        rmap = {}
        for chain in self.struct.get_chains():
            if (not selected_chain) or (selected_chain == chain.id):
                residues = [
                    x for x in chain.get_residues()
                    if is_aa(x, standard=standard_aa)
                ]
                rmap[chain.id] = {i: x.id for i, x in enumerate(residues)}
        return rmap

    def seq(self, selected_chain=None, standard_aa=True):
        records = []
        for chain in self.struct.get_chains():
            if (not selected_chain) or (selected_chain == chain.id):
                residues = [
                    x for x in chain.get_residues()
                    if is_aa(x, standard=standard_aa)
                ]
                if residues:
                    seq = "".join([seq1(x.resname) for x in residues])
                    start = str(residues[0].id[1])
                    end = str(residues[-1].id[1])
                    record = SeqRecord(id="_".join(
                        [self.code, chain.id, start, end]),
                                       description="",
                                       seq=Seq(seq))
                    records.append(record)
        return records
Example #2
0
    def records_from_pdb(self, pdb, pdb_file_path, standard_aa=True, selected_chain=None):
        records = []
        struct = PDBParser(PERMISSIVE=1, QUIET=1).get_structure(pdb, pdb_file_path)[0]

        for chain in struct.get_chains():
            if (not selected_chain) or (selected_chain == chain.id):
                residues = [x for x in chain.get_residues() if is_aa(x, standard=standard_aa)]
                if residues:
                    seq = "".join([seq1(x.resname) for x in residues])
                    start = str(residues[0].id[1])
                    end = str(residues[-1].id[1])
                    record = SeqRecord(id="_".join([pdb, chain.id, start, end]), description="", seq=Seq(seq))
                    records.append(record)
        return records
Example #3
0
def FASTA_Gen(pdb_file, pdb_id, output_file):

    m = PDBParser(PERMISSIVE=1).get_structure(pdb_id, pdb_file)

    w = open(output_file, 'w')
    for chain in m.get_chains():
        residues = list(chain.get_residues())
        chain_id = chain.get_id()

        s = ''
        peptides = PPBuilder().build_peptides(chain, aa_only=False)
        for peptide in peptides:
            s = s + peptide.get_sequence() + '\n\n'

        w.write('>{0}_{1}|{2}-{3}\n'.format(pdb_id, chain_id,
                                            residues[0].get_id()[1],
                                            residues[-1].get_id()[1]))
        w.write(str(s))

    w.close()
Example #4
0
# %%
import os

io = PDBIO()
end = "_ligand.pdb"
directory = "./ligands/"

for filename in os.listdir(directory):
    if filename.endswith(end):  # IF the file ends with the generic ending,
        fileid = filename  # duplicate the fileid for a shortened title
        fileid = fileid.replace(end, '')  # remove the end
        pdb = PDBParser().get_structure(fileid, directory +
                                        filename)  # get the structure
        ress = model.get_residues()
        for chain in pdb.get_chains():
            for res in chain.get_residues(
            ):  # for each chain in the structure,
                io.set_structure(residue)  # set the structure to the chain
                #io.save(pdb.get_id() + "_" + chain.get_id() + ".pdb")   # save the chain to a new PDB file
                io.save(fileid + "_" + chain.get_id() +
                        ".pdb")  # save the chain to a new PDB file

# %%
ligs = structure[:][:][:]

# %%
import os

io = PDBIO()
end = "_ligand.pdb"