[Biopython] Merging different pdbs into a single object structure and writing it

Lenna Peterson lennalenna at gmail.com
Wed Jun 25 16:26:14 UTC 2014


Hi Claudia,

* You don't need a separate parser for each PDB file, you can just use the
same parser object and it will return separate structure objects.
* An alternative to using chr on integers would to be to use
string.ascii_uppercase
* Yes, set_structure() is replacing each structure in turn, so you're only
writing out the last structure.

You can only write one structure at a time, so you need to combine multiple
structures into different chains in one structure. To do this, you'll need
to use the detach_parent() and add() methods. Something like this may work:

import string
index = 0
main_structure = list_of_structures[0]
# Set chains in structures and move to first structure
for x, structure in enumerate(list_of_structures):
    for chain in structure:
        chain.id = string.ascii_uppercase[index]
        index += 1
        # Don't move chains of first structure
        if x == 0: continue
        chain.detach_parent()
        main_structure[0].add(chain)

Let me know whether or not that works for you.

Cheers,

Lenna


On Wed, Jun 25, 2014 at 11:48 AM, Claudia Millán Nebot <cmncri at ibmb.csic.es>
wrote:

> Hi :) I'm newbie to BioPython and I am trying to do the following:
>
> I have a set of different pdbs that I want to merge together into a single
> file. I would like to take into consideration that there could be issues
> with the naming, so, after reading a few other posts in this same list, I
> came up with the following code:
>
>             list_parsers=[]
>             list_of_structures=[]
>             for index in range(len(list_of_filenames)):
>                 parser=PDBParser()
>                 list_parsers.append(parser)
>
> structure=parser.get_structure(list_of_filenames[index][:-4],list_of_filenames[index])
>                 list_of_structures.append(structure)
>             i_chain = 65
>             for structure in list_of_structures:
>               for chain in structure:
>                 chain.id = chr(i_chain)
>                 i_chain += 1
>             io=PDBIO()
>             for structure in list_of_structures:
>                 io.set_structure(structure)
>             io.save(clust_fold+key[:-4]+"_fused.pda")
>
> This is not working, as I guess i'm just changing the structure set each
> time I do  io.set_structure, and writing the last one. And as there is not
> such a thing as the append_structure() method I have just tried a silly
> thing. So my question would be which is the best way to get the pdbs
> merged? Should I save as independent unfold entities and then write them by
> using a Select class?
>
> Thanks in advance and regards,
>
> Claudia Millán (cmncri at ibmb.csic.es)
>
> Crystallographic Methods Group
>
> http://chango.ibmb.csic.es
>
> Institut de Biologia Molecular de Barcelona (IBMB-CSIC)
>
> Barcelona, Spain
>
> _______________________________________________
> Biopython mailing list  -  Biopython at mailman.open-bio.org
> http://mailman.open-bio.org/mailman/listinfo/biopython
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20140625/fffaace2/attachment.html>


More information about the Biopython mailing list