Repository navigation
Update operators for Residue - #1567
Conversation
The == operator for residues currently seems to only compare identity of the `id` field which changes behaviour to v1.70. The same applies for the other operators as residues with identical "id" fields are considered equal. This e.g. causes NeighborSearch to report the same residue pair twice if the id field is identical. Last the __le__ and __lt__ were identical which I assume is not intended.
|
Do you have a test case you could share? Ideally using files under Does this link to #1551 perhaps? Also are you comparing the current release Biopython 1.70 with the current code in GitHub (since we have not yet released Biopython 1.71)? |
|
Yes I'll post the example I already shared with @JoaoRodrigues , from Bio.PDB import NeighborSearch, FastMMCIFParser, PDBList, PDBParser
#
# import sys,Bio
# print(sys.version)
# print(Bio.__version__)
def analyse_contacts(contact_list):
"""
Enumerates and classifies contacts based on the chemical characteristics
of the participating amino acids.
"""
bins = {
'AA': 0, 'PP': 0,
'CC': 0, 'AP': 0,
'CP': 0, 'AC': 0,
}
_data = {'ALA': 'A', 'CYS': 'A', 'GLU': 'C', 'ASP': 'C', 'GLY': 'A', 'PHE': 'A', 'ILE': 'A', 'HIS': 'C', 'LYS': 'C',
'MET': 'A', 'LEU': 'A', 'ASN': 'P', 'GLN': 'P', 'PRO': 'A', 'SER': 'P', 'ARG': 'C', 'THR': 'P', 'TRP': 'A',
'VAL': 'A', 'TYR': 'A', }
for (res_i, res_j) in contact_list:
contact_type = (_data.get(res_i.resname), _data.get(res_j.resname))
contact_type = ''.join(sorted(contact_type))
bins[contact_type] += 1
return bins
def run(s):
chains = list(s.get_chains())
for c in chains:
if c.id not in {'A','B'}:
c.parent.detach_child(c.id)
res_list = list(s.get_residues())
def _ignore(r):
return r.id[0][0] == 'W' or r.id[0][0] == 'H'
for res in res_list:
if _ignore(res):
chain = res.parent
chain.detach_child(res.id)
atom_list = list(s.get_atoms())
def _ignore(x):
return x.element == 'H'
for atom in atom_list:
if _ignore(atom):
print('removing atom: {}'.format(atom.name))
residue = atom.parent
residue.detach_child(atom.name)
ns = NeighborSearch(atom_list)
all_list = ns.search_all(radius=5.5, level='R')
print("# all contacts: {}".format(len(all_list)))
ic_list = [c for c in all_list if c[0].parent.id != c[1].parent.id]
print("# iface contacts: {}".format(len(ic_list)))
print(analyse_contacts(ic_list))
p = FastMMCIFParser(QUIET=True)
s = p.get_structure('1xwd', PDBList().retrieve_pdb_file('1xwd', file_format='mmCif'))
run(s)
# p = PDBParser(QUIET=True)
# s = p.get_structure('1xwd', PDBList().retrieve_pdb_file('1xwd', file_format='pdb'))
# run(s) |
|
If this broke since Biopython 1.70, it most likely was from Implements Py3-compatible rich comparison for all Bio.PDB objects #1360, merged August 2017 |
|
Yes I suspected that it might be linked, #1356 which was addressed by this PR was the reason I actually switched to the latest master from v1.70 |
Codecov Report
@@ Coverage Diff @@
## master #1567 +/- ##
==========================================
+ Coverage 84.89% 84.97% +0.08%
==========================================
Files 327 327
Lines 49545 49529 -16
==========================================
+ Hits 42062 42089 +27
+ Misses 7483 7440 -43
Continue to review full report at Codecov.
|
JoaoRodrigues
left a comment
There was a problem hiding this comment.
Looks good, nice catch indeed. I would only add a small unit test to handle Residue comparisons explicitly, just to make sure this is working properly and it does not break again in the future!
|
I quickly looked at the unit test for comparison of SMCRA objects, and the example structure used there indeed doesn't catch the issue observed (same residue ID different chain). @JoaoRodrigues what's your suggestion, adding a separate unit test for residue or extending that one. Either way a second structure matching the criteria (e.g. |
|
@schaarj I would be in favor of modifying |
…ull ID comparing the full ID yields the same result as comparing first the parents and then the entities themselves and for residue fields in the ID are evaluated in the same order as the spelled out comparisons implemented before. Thus a customized test seems superfluous. While this eliminates the changes in Neighbor search reported, comparisons might not yield the expected result but should be consistent with behaviour of version 1.70 in python 2
|
I have a question about using |
|
As mentioned I did a few tests and it appears to sort according to the order in the tuple in python2 and 3, which would be the anticipated sorting order. I also added the parent check for Atom (not yet committed) and all tests pass. Should this be added here as well or should Atom routines remain the way they are (I guess the additional parent check in atom would have the biggest impact on performance) |
This includes: * Extend `a_structure.pdb` with an additional chain including modified residues and residues with insertion code * Test whether residues are sorted correctly according to `parent > HETATM flag > resseq > insertion code` * Test whether comparison of Atoms considers parent
|
Our automated PEP8 style checks are failing, mostly just including the trailing full stop on the new docstrings: |
| """Test inequality.""" | ||
| if isinstance(other, Atom): | ||
| return (self.id, self.altloc) != (other.id, other.altloc) | ||
| return self.full_id != other.full_id |
There was a problem hiding this comment.
Two spaces after return, should be one - that's giving this error on the style checks:
Bio/PDB/Atom.py:88:19: E271 multiple spaces after keyword
| """ | ||
| self.parent = parent | ||
| self.full_id = self.get_full_id() | ||
|
|
There was a problem hiding this comment.
Extra blank line added, PEP8 says just one blank line between methods - that's giving this style check error:
Bio/PDB/Atom.py:285:5: E303 too many blank lines (2)
|
@peterjc Thank you for the notifications and apologies for not catching these style violations in the first place. I indeed missed the other two issues between the full stop warnings. Hopefully everything is in order now. |
|
We currently have to run the style checks on |
|
Already took care of it when I saw the tests failing. Now the Basic tests passed. Since the unit tests (without dependencies) passed in python 2 and 3 on my machine I'm optimistic that the other tests will pass as well. |
|
Some real failures in Python 3.6, The other versions of Python are likely also affected, but we try to have a mix of the optional dependencies - these are the only ones with |
|
Yes, I noticed. Unfortunately |
`_reset_ful_id` regenerate the full_id instead of setting it to None
|
Thanks I should have tested locally in the first place. Just did so now and noticed that this test was most likely not doing what it thought it was doing as it compared values initialised to |
|
I think the required MMTF test change reflects a subtle API change - previously the user-supplied model ID was ignored for atom level comparison, but now it gets checked. I never really understood the intended usage of the user-supplied identifier, so am unsure what to think here. |
|
Yes that's the major issue in this PR, previously Atom comparison only looked at ID and altloc while comparison of other entities was comparing something else. The current implementation of the operators in Entity added in PR #1360 compares also IDs only but changed the behaviour compared to biopython 1.70. So the question is, whether two Entities/Atoms with identical ID but different parents should be considered equal. I modified Atom to be consistent with the other entities but this causes a change in behaviour compared to previous versions, which might be problematic (which is however also true for different behaviour e.g. between residue and atom). The mmtf test was nevertheless flawed as it explicitly stated to compare full IDs (including the structure ID) while it actually tested |
|
Regarding the comment "previously the user-supplied model ID was ignored for atom level comparison, but now it gets checked": |
|
If this passes all tests, it should be good to go. Thanks for adding more tests @schaarj , it will really help us writing better stuff in the future. |
|
Good work. Would the current Can you add yourself to the |
|
Great, I updated |
|
@peterjc Is there a way to force the tests to run again? Seems like it just timed out .. |
|
Re-running the AppVeyor pull request test - it seems its all or nothing, unlike TravisCI which lets you re-run a specific job. IIRC AppVeyor didn't GitHub teams for authentication/permissions, so sharing the account is probably the only way to share this ability. |
|
@peterjc Thanks, seems all good to go, shall I merge or you do it? |
|
Excellent - I'll let you merge this @JoaoRodrigues - thank you! |
|
Thanks everyone, specially @schaarj ! |
Original author Thomas Hamelryck and all the contributors since as tracked with version control have agreed: - Adhemar Zerlotini (@azneto) biopython#1412 (comment) - Fábio Madeira (@biomadeira) biopython#898 (comment) - Brian Osborne (@bosborne) biopython#898 (comment) - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Francesco Gastaldello (@Gasta88) biopython#1063 - João Rodrigues (@JoaoRodrigues) biopython#898 (comment) - Joe Greener (@jgreener64) biopython#1393 - Joerg Schaarschmidt (@schaarj) biopython#1567 - @morrme biopython#1172 (comment) - Nick Negretti (@nimne) biopython#1768 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Rodrigo Dorantes-Gilardi (@rodogi) biopython#1227 (comment) - Sergio Valqui (@svalqui) biopython#1749 - 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: - Ben Reynwar (@benreynwar) biopython#898 (comment) - Brad Chapman (@chapmanb) http://mailman.open-bio.org/pipermail/biopython-dev/2013-July/019903.html - Brian Osborne (@bosborne) 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 - Hongbo Zhu (@hongbo-zhu-cn) biopython#898 (comment) - Joao Rodrigues (@JoaoRodrigues) biopython#898 (comment) - Kristian Rother (@krother) biopython#898 (comment) - Lenna Peterson (@lennax) biopython#898 (comment) - Michiel de Hoon (@mdehoon) biopython#898 (comment) - @morrme biopython#1172 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Ralf Stephan (@rwst) biopython#1900 - Joerg Schaarschmidt (@schaarj) biopython#1567 - Sergio Valqui (@svalqui) biopython#1749 - Suresh Panneerselvam (@Amrithasuresh) biopython#1575 - 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) - Fábio Madeira (@biomadeira) #898 (comment) - Brian Osborne (@bosborne) #898 (comment) - Christian Brueffer (@cbrueffer) #898 (comment) - Eric Talevich (@etal) #898 (comment) - Francesco Gastaldello (@Gasta88) #1063 - João Rodrigues (@JoaoRodrigues) #898 (comment) - Joe Greener (@jgreener64) #1393 - Joerg Schaarschmidt (@schaarj) #1567 - @morrme #1172 (comment) - Nick Negretti (@nimne) #1768 (comment) - Peter Cock (@peterjc) #898 (comment) - Rodrigo Dorantes-Gilardi (@rodogi) #1227 (comment) - Sergio Valqui (@svalqui) #1749 - 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: - Ben Reynwar (@benreynwar) #898 (comment) - Brad Chapman (@chapmanb) http://mailman.open-bio.org/pipermail/biopython-dev/2013-July/019903.html - Brian Osborne (@bosborne) #898 (comment) - Christian Brueffer (@cbrueffer) #898 (comment) - Connor McCoy (@cmccoy) #898 (comment) - Eric Talevich (@etal) #898 (comment) - Francesco Gastaldello (@Gasta88) #1063 - Hongbo Zhu (@hongbo-zhu-cn) #898 (comment) - Joao Rodrigues (@JoaoRodrigues) #898 (comment) - Kristian Rother (@krother) #898 (comment) - Lenna Peterson (@lennax) #898 (comment) - Michiel de Hoon (@mdehoon) #898 (comment) - @morrme #1172 (comment) - Peter Cock (@peterjc) #898 (comment) - Ralf Stephan (@rwst) #1900 - Joerg Schaarschmidt (@schaarj) #1567 - Sergio Valqui (@svalqui) #1749 - Suresh Panneerselvam (@Amrithasuresh) #1575 - 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) 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
The == operator for residues currently seems to only compare identity
of the
idfield which changes behaviour to v1.70.This was observed by different results obtained with following code:
which yields different results between 1.70 an 1.71 if two chains with overlapping residue IDs within the returned set are present.
The same applies for the other operators, as residues with identical "id" fields are considered
equal. This e.g. causes NeighborSearch to report the same residue pair twice if the id field is identical.
Last the
__le__and__lt__operator were identical which I assume is not intended.This pull request addresses issue #...
I hereby agree to dual licence this and any previous contributions under both
the Biopython License Agreement AND the BSD 3-Clause License.
I have read the
CONTRIBUTING.rstfile and understand that AppVeyor andTravisCI will be used to confirm the Biopython unit tests and
flake8stylechecks pass with these changes.
I am happy be thanked by name in the
NEWS.rstandCONTRIB.rstfiles,and have added myself to those files as part of this pull request. (This
acknowledgement is optional. Note we list the names sorted alphabetically.)