Skip to content

Added a feature for changing the id of an PDB.Entity's child. - #968

Merged
peterjc merged 6 commits into
biopython:masterfrom
Bernhard10:master
Oct 21, 2016
Merged

peterjc merged 6 commits into
biopython:masterfrom
Bernhard10:master

Conversation

@Bernhard10

Copy link
Copy Markdown
Contributor

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_id has 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.id a property with a costum setter method that uses the .parent attribute to acces the parent's child_dict
If this feature makes sense, I could implement this alternative version.

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.
@codecov-io

codecov-io commented Oct 12, 2016 •

Copy link
Copy Markdown

Current coverage is 80.17% (diff: 100%)

Merging #968 into master will increase coverage by 0.01%

@@             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          

Powered by Codecov. Last update abc9bed...99a9e4b

@peterjc

peterjc commented Oct 12, 2016

Copy link
Copy Markdown
Member

@Bernhard10 I recommend installing the pep8 command line tool via pip install pep8 to help ensure your changes will pass on TravisCI. We also have a git pre-commit hook you could use which does a similar check, see #493 and #883

@etal @JoaoRodrigues @lennax your thoughts on the PDB changes please?

@JoaoRodrigues

JoaoRodrigues commented Oct 13, 2016 via email

Copy link
Copy Markdown
Member

@Bernhard10

Copy link
Copy Markdown
Contributor Author

@JoaoRodrigues I only thought of the @id.setter solution when I was done coding the current version.
But yeah, the setter version is better, so if this is feature is going to be merged, I will change it to the setter version.

@peterjc

peterjc commented Oct 14, 2016

Copy link
Copy Markdown
Member

Given @JoaoRodrigues agrees in principle, please work on the setter version.

This will also need a new test in tests_PDB.py as well. Thanks!

@peterjc peterjc left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Tests/test_PDB.py
def test_change_model_id(self):
"""Change the id of a model"""
for model in self.struc:
break # Get first model in structure

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would have to be

next(iter(self.struc))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes.

Comment thread Tests/test_PDB.py Outdated
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', ' ')):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Bernhard10 Bernhard10 Oct 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of our tests depend on sample files - relatively few create test data structures in code.

Comment thread Bio/PDB/Entity.py Outdated
self.child_list.append(entity)
self.child_dict[entity_id] = entity

def reset_full_id(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@peterjc

peterjc commented Oct 21, 2016

Copy link
Copy Markdown
Member

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!

@Bernhard10

Copy link
Copy Markdown
Contributor Author

Yeah, thanks, I am happy with both.
My name is Bernhard Thiel, in case it doesn't show up on github.

@peterjc
peterjc merged commit ee1f508 into biopython:master Oct 21, 2016
peterjc added a commit that referenced this pull request Oct 21, 2016
See his contribution from pull request #968 (previous commit)
MarkusPiotrowski pushed a commit to MarkusPiotrowski/biopython that referenced this pull request Oct 31, 2017
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.
MarkusPiotrowski pushed a commit to MarkusPiotrowski/biopython that referenced this pull request Oct 31, 2017
See his contribution from pull request biopython#968 (previous commit)
peterjc added a commit to peterjc/biopython that referenced this pull request Aug 14, 2019
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)
peterjc added a commit that referenced this pull request Aug 29, 2019
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)
peterjc added a commit to peterjc/biopython that referenced this pull request Aug 30, 2019
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
peterjc added a commit to peterjc/biopython that referenced this pull request Aug 30, 2019
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
peterjc added a commit that referenced this pull request Nov 4, 2019
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
peterjc added a commit that referenced this pull request Nov 4, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants