New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements Py3-compatible rich comparison for all Bio.PDB objects #1360
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
22d9cd0
Added explicit comparison operators to allow direct comparison of SMC…
JoaoRodrigues bc61681
Modified example structure to test sorting. Refactored test suite for…
JoaoRodrigues a64bd6c
Missed parenthesis when refactoring public sort method.
JoaoRodrigues 284b652
Fixed flake8 warnings
JoaoRodrigues 2250b91
Fixed further flake8 warnings
JoaoRodrigues eff0089
Reviewed comparison/equality methods to test for comparison between d…
JoaoRodrigues fabc488
Added DeprecationWarning for public sort() method in Residue
JoaoRodrigues 385b12e
Added tests to explicitly check for comparisons instead of just sorting
JoaoRodrigues 2b309b7
Fixed testing __gt__ and friends between different types to account f…
JoaoRodrigues fd356bc
Rephrased deprecation warning. Fixed US spelling.
JoaoRodrigues File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,48 @@ def __repr__(self): | |
full_id = (resname, hetflag, resseq, icode) | ||
return "<Residue %s het=%s resseq=%s icode=%s>" % full_id | ||
|
||
# Residue-specific sorting methods | ||
# Sort first by HETATM flag, then by resseq, finally by insertion code | ||
def __gt__(self, other): | ||
hetflag_s, resseq_s, icode_s = self.id | ||
hetflag_o, resseq_o, icode_o = other.id | ||
if hetflag_o != hetflag_s: | ||
return hetflag_s > hetflag_o | ||
elif resseq_o != resseq_s: | ||
return resseq_s > resseq_o | ||
else: | ||
return icode_s > icode_o | ||
|
||
def __ge__(self, other): | ||
hetflag_s, resseq_s, icode_s = self.id | ||
hetflag_o, resseq_o, icode_o = other.id | ||
if hetflag_o != hetflag_s: | ||
return hetflag_s >= hetflag_o | ||
elif resseq_o != resseq_s: | ||
return resseq_s >= resseq_o | ||
else: | ||
return icode_s >= icode_o | ||
|
||
def __lt__(self, other): | ||
hetflag_s, resseq_s, icode_s = self.id | ||
hetflag_o, resseq_o, icode_o = other.id | ||
if hetflag_o != hetflag_s: | ||
return hetflag_s < hetflag_o | ||
elif resseq_o != resseq_s: | ||
return resseq_s < resseq_o | ||
else: | ||
return icode_s < icode_o | ||
|
||
def __le__(self, other): | ||
hetflag_s, resseq_s, icode_s = self.id | ||
hetflag_o, resseq_o, icode_o = other.id | ||
if hetflag_o != hetflag_s: | ||
return hetflag_s < hetflag_o | ||
elif resseq_o != resseq_s: | ||
return resseq_s < resseq_o | ||
else: | ||
return icode_s < icode_o | ||
|
||
def add(self, atom): | ||
"""Add an Atom object. | ||
|
||
|
@@ -54,19 +96,8 @@ def sort(self): | |
by name, with any alternative location specifier for disordered | ||
atoms (altloc) as a tie-breaker. | ||
""" | ||
# Defining sort key function within the sort method's scope: | ||
def sort_index(atom): | ||
"""Build tuple of (int, name, alt-loc) for sorting. | ||
|
||
The first integer is 0, 1, 2, 3, 4 for atoms N, CA, C, O, other. | ||
""" | ||
try: | ||
i = ["N", "CA", "C", "O"].index(atom.name) | ||
except ValueError: | ||
i = 4 | ||
return (i, atom.name, atom.altloc) | ||
|
||
self.child_list.sort(key=sort_index) | ||
|
||
self.child_list.sort | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should that not be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well spotted! |
||
|
||
def flag_disordered(self): | ||
"""Set the disordered flag.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to remove this blank link to make
flake8
happy: