[Biopython-dev] [Bug 2777] [Solution is one line change!] Entity sorting altered by detach_child() calls

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Wed Mar 4 14:37:34 UTC 2009


http://bugzilla.open-bio.org/show_bug.cgi?id=2777





------- Comment #4 from biopython-bugzilla at maubp.freeserve.co.uk  2009-03-04 09:37 EST -------
Created an attachment (id=1254)
 --> (http://bugzilla.open-bio.org/attachment.cgi?id=1254&action=view)
Patch for Bio/PDB/Entity.py based on Klaus Kopec's suggestion

I've attached a patch which makes the suggested change.  I'm hoping to get
Thomas (the original author) to comment but otherwise I see no reason not to
commit this fix soon.

The old code did this:

    def detach_child(self, id):
        "Remove a child."
        child=self.child_dict[id] 
        child.detach_parent()
        del self.child_dict[id]
        self.child_list=self.child_dict.values()
        self.child_list.sort(self._sort)

It used a sort which should have preserved the order - but that only works if
the child_list is always kept sorted.  Looking at the add method, this isn't
true:

    def add(self, entity):
        "Add a child to the Entity."
        entity_id=entity.get_id()
        if self.has_id(entity_id):
            raise PDBConstructionException( \
                "%s defined twice" % str(entity_id))
        entity.set_parent(self)
        self.child_list.append(entity)
        #self.child_list.sort(self._sort)
        self.child_dict[entity_id]=entity

Interestingly the sort was commented out in the original version first
committed to Biopython's CVS, so this change predates the integration into
Biopython.

I haven't checked to see if there are any other ways the child_list could
become unsorted - that doesn't really matter.


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list