Repository navigation
Added a feature for changing the id of an PDB.Entity's child. - #968
Conversation
When changing the id of an element, it has to be changed at 2 places: *) The element's attribute `id` *) The parent's `child_dict`. Further more, the full_id has to be invalidated recursively for all children. Alternatively one could change the id field for the Entity class to a property and write the logic into the setter.
The Test for invalidating cached full_ids now changes a chain's id, to observe if the residue's full_id is updated. Note that the model does not seem to have the Structure set as a parent.
Current coverage is 80.17% (diff: 100%)@@ master #968 diff @@
==========================================
Files 319 319
Lines 48734 48751 +17
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 39063 39086 +23
+ Misses 9671 9665 -6
Partials 0 0
|
|
@Bernhard10 I recommend installing the @etal @JoaoRodrigues @lennax your thoughts on the PDB changes please? |
|
Hi there,
If I understand correctly, the problem is that if you say, e.g. a chain ID,
you want to propagate that change to its children.
It's fine as it is, bar the occasional pep8 issues. However, why not do
this directly when you set the id, by defining a @id.setter decorator?
Cheers,
João
|
|
@JoaoRodrigues I only thought of the |
|
Given @JoaoRodrigues agrees in principle, please work on the setter version. This will also need a new test in |
There was a problem hiding this comment.
I've noted some minor technical issues, what do you think @JoaoRodrigues?
Note we'll squash this into a single commit when merging to keep the history clear.
| def test_change_model_id(self): | ||
| """Change the id of a model""" | ||
| for model in self.struc: | ||
| break # Get first model in structure |
There was a problem hiding this comment.
Assuming this works it would be more elegant (here and the other examples below):
model = next(self.struc)
This will also give a clear error if there were ever no models.
There was a problem hiding this comment.
I guess it would have to be
next(iter(self.struc))
| for atom in self.struc.get_atoms(): | ||
| break # First atom | ||
| original_id = atom.get_full_id() # ('X', 0, 'A', ('H_PCA', 1, ' '), ('N', ' ')) | ||
| if original_id != ('X', 0, 'A', ('H_PCA', 1, ' '), ('N', ' ')): |
There was a problem hiding this comment.
This should be:
self.assertEqual(original_id, ('X', 0, 'A', ('H_PCA', 1, ' '), ('N', ' ')))
You can include an error message as well but it seems unnecessary.
There was a problem hiding this comment.
I did not use assertEqual on purpose, because I am asserting something about the file I load for the test, not about the functionality I am testing, so I thought letting the test result in an Error not a Failure is clearer. (As for the second raise ValueError: There is currently no test addressing the caching of full_ids)
The way I wrote the tests (depending on a loaded pdb file instead of creating an instance of Entity and mocking all external dependencies) is in accordance with the other tests in test_PDB.py and somewhat more practical/ easier, but it brings clear disadvantages, such as depending on the content of the file.
There was a problem hiding this comment.
Most of our tests depend on sample files - relatively few create test data structures in code.
| self.child_list.append(entity) | ||
| self.child_dict[entity_id] = entity | ||
|
|
||
| def reset_full_id(self): |
There was a problem hiding this comment.
Do you think this should be a new public method, or denote it as private using a leading underscore? i.e. def _reset_full_id(self):
There was a problem hiding this comment.
I would go for a private method. I don't see much of a use outside the main function to set a new id in the parent.
…l version of one test. I changed the ValueErrors in the tests to self.asserts. One could even comment out the first 2 asserts in `test_full_id_is_updated_chain` and `test_full_id_is_updated_residue`. The first assert mostly serves to document my assumptions about the data loaded. The second verifies that there is indeed caching taking place, so we need to invalidate the full_id. The third and fourth assertion test the desired behaviour of the public API. They are the main assertions of the tests.
|
This looks good. Two questions before I squash-and-mege this: Are you happy to be named in the NEWS and CONTRIB files? Are you happy to dual licence your Biopython contributions under both the current Biopython Licence Agreement and the 3-Clause BSD license? See #898 Thanks! |
|
Yeah, thanks, I am happy with both. |
See his contribution from pull request #968 (previous commit)
Squashed commit of pull request biopython#968 Added a feature for changing the id of an PDB Entity's child. When changing the id of an element, it has to be changed at 2 places: - The element's attribute `id` - The parent's `child_dict` Furthermore, the full_id has to be invalidated recursively for all children. Alternatively one could change the id field for the Entity class to a property and write the logic into the setter. The Test for invalidating cached full_ids changes a chain's id, to observe if the residue's full_id is updated.
See his contribution from pull request biopython#968 (previous commit)
Original author Kristian Rother and contributors since as recorded in version control have agreed: - Bernhard C. Thiel (@Bernhard10) biopython#968 - Brian Osborne (@bosborne) biopython#898 (comment) - Carlos Pena (@carlosp420) biopython#898 (comment) - Carlos Rios Vera (@crosvera) biopython#898 (comment) - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Connor McCoy (@cmccoy) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Francesco Gastaldello (@Gasta88) biopython#1063 - Jeremy LaBarge (@biojerm) biopython#1847 (comment) - Joe Greener (@jgreener64) biopython#1393 - Kristian Rother (@krother) biopython#898 (comment) - Lenna Peterson (@lennax) biopython#898 (comment) - Michiel de Hoon (@mdehoon) biopython#898 (comment) - Michael Moritz (@mikepm35) biopython#2081 - @morrme biopython#1172 (comment) - Nick Negretti (@nimne) biopython#1768 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Rob Miller (@rob-miller) biopython#1933 - Sergei Lebedev (@superbobry) biopython#898 (comment) - Suresh Panneerselvam (@Amrithasuresh) biopython#1575 - Thomas Hamelryck (CVS username nisse) https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html - Wayne Decatur (@fomightez) biopython#898 (comment)
Original author Kristian Rother and contributors since as recorded in version control have agreed: - Bernhard C. Thiel (@Bernhard10) #968 - Brian Osborne (@bosborne) #898 (comment) - Carlos Pena (@carlosp420) #898 (comment) - Carlos Rios Vera (@crosvera) #898 (comment) - Christian Brueffer (@cbrueffer) #898 (comment) - Connor McCoy (@cmccoy) #898 (comment) - Eric Talevich (@etal) #898 (comment) - Francesco Gastaldello (@Gasta88) #1063 - Jeremy LaBarge (@biojerm) #1847 (comment) - Joe Greener (@jgreener64) #1393 - Kristian Rother (@krother) #898 (comment) - Lenna Peterson (@lennax) #898 (comment) - Michiel de Hoon (@mdehoon) #898 (comment) - Michael Moritz (@mikepm35) #2081 - @morrme #1172 (comment) - Nick Negretti (@nimne) #1768 (comment) - Peter Cock (@peterjc) #898 (comment) - Rob Miller (@rob-miller) #1933 - Sergei Lebedev (@superbobry) #898 (comment) - Suresh Panneerselvam (@Amrithasuresh) #1575 - Thomas Hamelryck (CVS username nisse) https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html - Wayne Decatur (@fomightez) #898 (comment)
Original authors Thomas Hamelryck and Eric Talevich (for the unittest conversion), and the contributors as tracked with version control have agreed: - Andrew Guy (@andrewguy) biopython#2212 (comment) - Ben Reynwar (@benreynwar) biopython#898 (comment) - Bernhard C. Thiel (@Bernhard10) biopython#968 - Carlos Pena (@carlosp420) biopython#898 (comment) - Chris Rands (@chris-rands) biopython#1301 - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Francesco Gastaldello (@Gasta88) biopython#1063 - Gokcen Eraslan (@gokceneraslan) biopython#898 (comment) - Jack Twilley (@mathuin) biopython#1049 (comment) - Jeroen Van Goey (@BioGeek) biopython#898 (comment) - Joe Greener (@jgreener64) biopython#1393 - Joerg Schaarschmidt (@schaarj) biopython#1567 - João Rodrigues (@JoaoRodrigues) biopython#898 (comment) - Kian Ho (@kianho) biopython#898 (comment) - Kristian Davidsen (@krdav) biopython#898 (comment) - Kristian Rother (@krother) biopython#898 (comment) - Lenna Peterson (@lennax) biopython#898 (comment) - Markus Piotrowski (@MarkusPiotrowski) biopython#898 (comment) - Milind Luthra (@milindl) biopython#1020 - Nick Negretti (@nimne) biopython#1768 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Rasmus Fonseca (@RasmusFonseca) biopython#1171 (comment) - Siong Kong (@siongkong) biopython#1516 - Stefans Mezulis (@StefansM) biopython#1445 - Thomas Hamelryck (CVS username nisse) https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html
Original author Thomas Hamelryck and all the contributors since as tracked with version control have agreed: - Adhemar Zerlotini (@azneto) biopython#1412 (comment) - Alexander (@asford) biopython#2212 (comment) - @Amrithasuresh biopython#1575 - Andrew Guy (@andrewguy) biopython#2212 (comment) - Ben Reynwar (@benreynwar) biopython#898 (comment) - Bernhard C. Thiel (@Bernhard10) biopython#968 - Brad Chapman (@chapmanb) http://mailman.open-bio.org/pipermail/biopython-dev/2013-July/019903.html - Brian Osborne (@bosborne) biopython#898 (comment) - Carlos Pena (@carlosp420) biopython#898 (comment) - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Connor McCoy (@cmccoy) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Francesco Gastaldello (@Gasta88) biopython#1063 - Joe Greener (@jgreener64) biopython#1393 - Joerg Schaarschmidt (@schaarj) biopython#1567 - João Rodrigues (@JoaoRodrigues) biopython#898 (comment) - Klaus Kopec (@klauskopec) biopython#2241 (comment) - Michiel de Hoon (@mdehoon) biopython#898 (comment) - @morrme biopython#1172 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Ralf Stephan (@rwst) biopython#1900 - Sergio Valqui (@svalqui) biopython#1749 - Thomas Hamelryck (CVS username nisse) https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html
Original authors Thomas Hamelryck and Eric Talevich (for the unittest conversion), and the contributors as tracked with version control have agreed: - Andrew Guy (@andrewguy) #2212 (comment) - Ben Reynwar (@benreynwar) #898 (comment) - Bernhard C. Thiel (@Bernhard10) #968 - Carlos Pena (@carlosp420) #898 (comment) - Chris Rands (@chris-rands) #1301 - Christian Brueffer (@cbrueffer) #898 (comment) - Eric Talevich (@etal) #898 (comment) - Francesco Gastaldello (@Gasta88) #1063 - Gokcen Eraslan (@gokceneraslan) #898 (comment) - Jack Twilley (@mathuin) #1049 (comment) - Jeroen Van Goey (@BioGeek) #898 (comment) - Joe Greener (@jgreener64) #1393 - Joerg Schaarschmidt (@schaarj) #1567 - João Rodrigues (@JoaoRodrigues) #898 (comment) - Kian Ho (@kianho) #898 (comment) - Kristian Davidsen (@krdav) #898 (comment) - Kristian Rother (@krother) #898 (comment) - Lenna Peterson (@lennax) #898 (comment) - Markus Piotrowski (@MarkusPiotrowski) #898 (comment) - Milind Luthra (@milindl) #1020 - Nick Negretti (@nimne) #1768 (comment) - Peter Cock (@peterjc) #898 (comment) - Rasmus Fonseca (@RasmusFonseca) #1171 (comment) - Siong Kong (@siongkong) #1516 - Stefans Mezulis (@StefansM) #1445 - Thomas Hamelryck (CVS username nisse) https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html
Original author Thomas Hamelryck and all the contributors since as tracked with version control have agreed: - Adhemar Zerlotini (@azneto) #1412 (comment) - Alexander (@asford) #2212 (comment) - @Amrithasuresh #1575 - Andrew Guy (@andrewguy) #2212 (comment) - Ben Reynwar (@benreynwar) #898 (comment) - Bernhard C. Thiel (@Bernhard10) #968 - Brad Chapman (@chapmanb) http://mailman.open-bio.org/pipermail/biopython-dev/2013-July/019903.html - Brian Osborne (@bosborne) #898 (comment) - Carlos Pena (@carlosp420) #898 (comment) - Christian Brueffer (@cbrueffer) #898 (comment) - Connor McCoy (@cmccoy) #898 (comment) - Eric Talevich (@etal) #898 (comment) - Francesco Gastaldello (@Gasta88) #1063 - Joe Greener (@jgreener64) #1393 - Joerg Schaarschmidt (@schaarj) #1567 - João Rodrigues (@JoaoRodrigues) #898 (comment) - Klaus Kopec (@klauskopec) #2241 (comment) - Michiel de Hoon (@mdehoon) #898 (comment) - @morrme #1172 (comment) - Peter Cock (@peterjc) #898 (comment) - Ralf Stephan (@rwst) #1900 - Sergio Valqui (@svalqui) #1749 - Thomas Hamelryck (CVS username nisse) https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html
When changing the id of an
PDB.Entity, it has to be changed at 2 places:*) The element's attribute
id*) The parent's
child_dict.Further more, the
full_idhas to be invalidated recursively for all children.I do not know biopython well enough to know if there are many usecases for this feature and if there are other pitfalls that I missed, but this is a first reference implementation how changing an entity's id could work.
A probably better implementation would be making
Entity.ida property with a costum setter method that uses the.parentattribute to acces the parent'schild_dictIf this feature makes sense, I could implement this alternative version.