-
Notifications
You must be signed in to change notification settings - Fork 395
Support extended pdbid #950
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
Merged
josemduarte
merged 41 commits into
biojava:master
from
aalhossary:Support_Extended_PDBID
Oct 29, 2021
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
6c22796
Support for extended PDBID PDB_nnnnNXXX
aalhossary dc12461
Some deprecated functions removal
aalhossary 7b08387
Fix typo
aalhossary c39632c
Targeted most of Spencer's comments
aalhossary 7dd8528
Fixed a bug in PDBId.equals() method
aalhossary e8466b9
Changing PDBID in SCOP record to lower case
aalhossary 12efad9
public static PDBId field XXXX
aalhossary d4dfc95
Behavior is now an enum
aalhossary 22e9158
Expose Pattern objects instead of Strings
aalhossary 5c6bcdc
ID stored internally in a reduced format (without initial "PDB_" prefix)
aalhossary 76112f0
Enhancements and bug fix
aalhossary d95e561
Added BDBId Unit test
aalhossary f54dd7d
Merge branch 'master' into Support_Extended_PDBID
aalhossary 727aff6
Added @Deprecated codeTag
aalhossary 960a1e6
Adding more TODOs
aalhossary 605c6f8
more replacement of deprecated methods
aalhossary ec53cee
Removed PDBIdException
aalhossary fd48eba
review and untouch regular expressions
aalhossary 84d9654
Un-deprecate, copy javadoc, and remove @author on methods
aalhossary e900fe5
Remove NullPointerException
aalhossary 711fb8a
Bug fix
aalhossary f92db27
clean commented out code
aalhossary d9e15e0
Update CHANGELOG
aalhossary b410f16
Fix unit test
aalhossary 6c8d267
PdbPair does not accept null
aalhossary a03a657
Addressing reviewer's comments
aalhossary a55aa95
Change capitalization state
aalhossary 732a2c2
Fix probable NPE + keep consistent PdbId method naming convention
aalhossary 34cb49e
Addressed some of the reviewer's comments.
aalhossary 40a55d2
Use JUnit 5
aalhossary 141d667
PdbId class Documentation
aalhossary c91a4dc
JavaDoc style update
aalhossary 9ce50fe
Minor updates
aalhossary 0fb6742
Reverting a wrong optimization
aalhossary 02bfee4
Merge branch 'biojavaorigin/master' into Support_Extended_PDBID
aalhossary 0d96963
Adding BioJava development code
aalhossary 87fbc10
Javadoc
aalhossary 17f366e
XXXX PdbId objects are not equal unless they are the same object
aalhossary ef9cf3f
No more XXXX. ANY malformed PdbId gracefully set to null
aalhossary 02974cd
Addressing Reviewer's comments
aalhossary 108fe97
Removing TODOs
aalhossary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added BDBId Unit test
- Loading branch information
commit d95e5616d61e42bcefbf7dee2fc0a4d1f7ccc86b
There are no files selected for viewing
272 changes: 272 additions & 0 deletions
272
biojava-structure/src/test/java/org/biojava/nbio/structure/TestPDBId.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,272 @@ | ||
| package org.biojava.nbio.structure; | ||
|
|
||
| import static org.junit.Assert.assertArrayEquals; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNotEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import org.biojava.nbio.structure.PDBId.PDBIdException; | ||
| import org.junit.Test; | ||
|
|
||
| public class TestPDBId { | ||
|
|
||
|
|
||
| @Test | ||
| public void testGetIdInDefaultFormat() { | ||
| try { | ||
| PDBId pdbId = new PDBId("1abc"); | ||
| String id = pdbId.getId(); | ||
| assertEquals(id, "1ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Unexpected Exception thrown"); | ||
| } | ||
| try { | ||
| PDBId pdbId = new PDBId("PDB_55551abc"); | ||
| String id = pdbId.getId(); | ||
| assertEquals(id, "PDB_55551ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Unexpected Exception thrown"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetIdPrefereShortFormat() { | ||
| try { | ||
| PDBId pdbId = new PDBId("1abc"); | ||
| String id = pdbId.getId(PDBId.Behavior.PREFER_SHORT); | ||
| assertEquals(id, "1ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Unexpected Exception thrown"); | ||
| } | ||
| try { | ||
| PDBId pdbId = new PDBId("PDB_55551abc"); | ||
| String id = pdbId.getId(PDBId.Behavior.PREFER_SHORT); | ||
| assertEquals(id, "PDB_55551ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Unexpected Exception thrown"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetIdPrefereExtendedFormat() { | ||
| try { | ||
| PDBId pdbId = new PDBId("1abc"); | ||
| String id = pdbId.getId(PDBId.Behavior.PREFER_EXTENDED); | ||
| assertEquals(id, "PDB_00001ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Unexpected Exception thrown"); | ||
| } | ||
| try { | ||
| PDBId pdbId = new PDBId("PDB_55551abc"); | ||
| String id = pdbId.getId(PDBId.Behavior.PREFER_EXTENDED); | ||
| assertEquals(id, "PDB_55551ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Unexpected Exception thrown"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetIdInShortFormat() { | ||
| try { | ||
| PDBId pdbId = new PDBId("1abc"); | ||
| String id = pdbId.getShortId(); | ||
| assertEquals(id, "1ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Unexpected Exception thrown"); | ||
| } | ||
|
aalhossary marked this conversation as resolved.
Outdated
|
||
|
|
||
| try { | ||
| PDBId pdbId = new PDBId("PDB_55551abc"); | ||
| pdbId.getShortId(); | ||
| fail("wrongly shortened a non-shortable ID"); | ||
|
aalhossary marked this conversation as resolved.
Outdated
|
||
| } catch (PDBIdException e) {} | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testIsShortPDBID() { | ||
| assertTrue("Didn't accept lower case", PDBId.isShortPDBID("1abc")); | ||
| assertTrue("Didn't accept upper case", PDBId.isShortPDBID("4HHB")); | ||
| assertFalse("Accepted wrong format", PDBId.isShortPDBID("HHHB")); | ||
| assertFalse("Accepted extended format", PDBId.isShortPDBID("PDB_00001ABC")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsExtendedPDBID() { | ||
| assertTrue("Didn't accept lower case", PDBId.isExtendedPDBID("PDB_00001abc")); | ||
| assertTrue("Didn't accept upper case", PDBId.isExtendedPDBID("PDB_00004HHB")); | ||
| assertTrue("Didn't accept upper case", PDBId.isExtendedPDBID("PDB_22224HHB")); | ||
| assertFalse("Accepted wrong format", PDBId.isExtendedPDBID("PDB_AAAA4HHB")); | ||
| assertFalse("Accepted short format", PDBId.isExtendedPDBID("1ABC")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsShortCompatible() { | ||
| assertTrue("Didn't accept lower case", PDBId.isShortCompatible("PDB_00001abc")); | ||
| assertTrue("Didn't accept upper case", PDBId.isShortCompatible("PDB_00004HHB")); | ||
| assertFalse("Accepted short format", PDBId.isShortCompatible("1ABC")); | ||
| assertFalse("Accepted wrong format", PDBId.isShortCompatible("PDB_AAAA4HHB")); | ||
|
|
||
| //Although this is wrong, returning true is the expected behavior of | ||
| // this method; because it does NOT validate the passed in string. | ||
| assertTrue("Accepted wrong format", PDBId.isShortCompatible("PDB_0000XXXXXXXXXXXXX")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToExtendedFormat() { | ||
| try { | ||
| assertEquals(PDBId.toExtendedId("1abc"), "PDB_00001ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Couldn't extend Id"); | ||
| } | ||
|
|
||
| try { | ||
| assertEquals(PDBId.toExtendedId("PDB_00001abc"), "PDB_00001ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Didn't recognize extended format"); | ||
| } | ||
|
|
||
| try { | ||
| PDBId.toExtendedId("PDB_aaaa1abc"); | ||
| fail("Accepted wrong format"); | ||
| } catch (PDBIdException e) {} | ||
| } | ||
|
|
||
| @Test | ||
| public void testToShortFormat() { | ||
| try { | ||
| assertEquals(PDBId.toShortId("PDB_00001ABC"), "1ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Couldn't shorten Id"); | ||
| } | ||
|
|
||
| try { | ||
| assertEquals(PDBId.toShortId("1abc"), "1ABC"); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("Didn't recognize short format"); | ||
| } | ||
|
|
||
| try { | ||
| PDBId.toShortId("PDB_aaaa1abc"); | ||
| fail("Accepted wrong format"); | ||
| } catch (PDBIdException e) {} | ||
|
|
||
| try { | ||
| PDBId.toShortId("aabc"); | ||
| fail("Accepted wrong format"); | ||
| } catch (PDBIdException e) {} | ||
| } | ||
|
|
||
| @Test | ||
| public void testHashCodeAndEquals() { | ||
| PDBId id1, id2, id3/* , id4 */; | ||
| PDBId other; | ||
| try { | ||
| id1 = new PDBId("1abc"); | ||
| id2 = new PDBId("PDB_00001ABC"); | ||
| id3 = new PDBId("1ABC"); | ||
| // id4 = new PDBId("pdb_00001abc"); | ||
| other = new PDBId("2ABC"); | ||
|
|
||
| assertEquals(id1.hashCode(), id2.hashCode()); | ||
| assertEquals(id1.hashCode(), id3.hashCode()); | ||
| // assertEquals(id1.hashCode(), id4.hashCode()); | ||
| assertNotEquals(id1.hashCode(), other.hashCode()); | ||
|
|
||
| assertTrue(id1.equals(id2)); | ||
| assertTrue(id1.equals(id3)); | ||
| // assertTrue(id1.equals(id4)); | ||
| assertFalse(id1.equals(other)); | ||
|
|
||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("unexpected exception thrown"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testClone() { | ||
| PDBId id1, clone; | ||
| try { | ||
| id1 = new PDBId("1abc"); | ||
| clone = (PDBId) id1.clone(); | ||
|
|
||
| assertFalse(id1 == clone); | ||
| assertTrue(id1.equals(clone)); | ||
| assertEquals(id1.hashCode(), clone.hashCode()); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("unexpected exception thrown"); | ||
| } catch (CloneNotSupportedException e) { | ||
| e.printStackTrace(); | ||
| fail("unexpected exception thrown while cloning"); | ||
| } | ||
|
aalhossary marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testCompareTo() { | ||
| PDBId id1, id2, id3, id4, id5 ; | ||
| PDBId[] array, expected; | ||
| try { | ||
| id1 = new PDBId("1abc"); | ||
| id2 = new PDBId("PDB_00011ABC"); | ||
| id3 = new PDBId("2ABC"); | ||
| id4 = new PDBId("PDB_00001ABA"); | ||
| id5 = new PDBId("1100"); | ||
|
|
||
| array = new PDBId[] {id1, id2, id3, id4, id5}; | ||
| System.out.println(Arrays.deepToString(array)); | ||
| Arrays.sort(array); | ||
| System.out.println(Arrays.deepToString(array)); | ||
| expected = new PDBId[] {id5, id4, id1, id3, id2}; | ||
| System.out.println(Arrays.deepToString(expected)); | ||
| assertArrayEquals(expected, array); | ||
|
|
||
|
|
||
| //let's try to have some "distinct but equal" objects. | ||
| id1 = new PDBId("1abc"); | ||
| id2 = new PDBId("PDB_00011ABC"); | ||
| id3 = new PDBId("2ABC"); | ||
| id4 = new PDBId("PDB_00001ABA"); | ||
| id5 = new PDBId("1ABA"); | ||
|
|
||
| array = new PDBId[] {id1, id2, id3, id4, id5}; | ||
| // System.out.println(Arrays.deepToString(array)); | ||
| Arrays.sort(array); | ||
| // System.out.println(Arrays.deepToString(array)); | ||
| expected = new PDBId[] {id5, id4, id1, id3, id2}; | ||
| // System.out.println(Arrays.deepToString(expected)); | ||
| assertArrayEquals(expected, array); // They should be. | ||
| //Now let the real test begins | ||
| boolean foundEqualButNotTheSame = false; | ||
| for (int i = 0; i < expected.length; i++) { | ||
| if(expected[i] == array[i]) { | ||
| foundEqualButNotTheSame = true; | ||
| break; | ||
| } | ||
| } | ||
| assertTrue("Couldn't detect 2 objects that are equal but not the same", foundEqualButNotTheSame); | ||
| } catch (PDBIdException e) { | ||
| e.printStackTrace(); | ||
| fail("unexpected exception thrown"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.