-
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
Changes from 1 commit
6c22796
dc12461
7b08387
c39632c
7dd8528
e8466b9
12efad9
d4dfc95
22e9158
5c6bcdc
76112f0
d95e561
f54dd7d
727aff6
960a1e6
605c6f8
ec53cee
fd48eba
84d9654
e900fe5
711fb8a
f92db27
d9e15e0
b410f16
6c8d267
a03a657
a55aa95
732a2c2
34cb49e
40a55d2
141d667
c91a4dc
9ce50fe
0fb6742
02bfee4
0d96963
87fbc10
17f366e
ef9cf3f
02974cd
108fe97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Only the ID proper is stored (in upper case).
e.g. for 1abc we store 00001ABC.
This format is the trade off between storing short/extended format and
all extended format.
storing the ID proper allows direct comparison and fast ordering of
PDBId objects with uniform names in the format \d{4}[1-9][0-9A-Z]{3}.- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ public PDBIdException(Throwable cause) { | |
| public static final Pattern PATTERN_EXTENDED_PDBID = Pattern.compile("PDB_\\d{5}\\p{Alnum}{3}"); | ||
|
|
||
| /** | ||
| * Keeps the ID in UPPER CASE. | ||
| * Keeps the ID in UPPER CASE, in a reduced form (without the <code>PDB_</code> prefix). | ||
| */ | ||
| private String idCode; | ||
| private static final String XXXX_STRING = "XXXX"; | ||
|
|
@@ -56,11 +56,9 @@ public PDBId(String id) throws PDBIdException { | |
| throw new PDBIdException("ID can not be null"); | ||
| } | ||
| if(accept_xxxx && XXXX_STRING.equalsIgnoreCase(id)) {// the only exception | ||
| this.idCode = toExtendedId(XXXX_STRING); | ||
| }else if (isExtendedPDBID(id)) { | ||
| this.idCode = id.toUpperCase(); | ||
| } else { | ||
| this.idCode = toExtendedId(id); | ||
| this.idCode = toInternalFormat(XXXX_STRING); | ||
| }else { | ||
| this.idCode = toInternalFormat(id); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -122,13 +120,17 @@ public String getId() { | |
| * @return The PDBId in short format if possible and <code>b</code> equals <code>Behavior.PREFER_SHORT</code>, the extended PdBID form otherwise. | ||
| */ | ||
| public String getId(Behavior b) { | ||
| if (b == Behavior.PREFER_SHORT && isShortCompatible(idCode)) | ||
| return toShortNoCheck(idCode); | ||
| return idCode; | ||
| if (b == Behavior.PREFER_SHORT && isInternalShortCompatible(idCode)) | ||
| return internalToShortNoCheck(idCode); | ||
| return internalToExtendedFormat(idCode); | ||
| } | ||
|
|
||
| public String getShortId() throws PDBIdException{ | ||
| return toShortId(idCode); | ||
| if(isInternalShortCompatible(idCode)) { | ||
| return internalToShortNoCheck(idCode); | ||
| } else { | ||
| throw new PDBIdException("ID ("+getId()+") is not short format compatible"); | ||
| } | ||
| } | ||
|
|
||
| public static String toExtendedId(String shortId) throws PDBIdException{ | ||
|
|
@@ -151,10 +153,31 @@ public static String toShortId(String extendedId) throws PDBIdException{ | |
| } | ||
| } | ||
|
|
||
| private static boolean isInternalShortCompatible(String intId) { | ||
| return intId.substring(0, 4).equalsIgnoreCase("0000"); | ||
| } | ||
|
|
||
| private static String toInternalFormat(String id) throws PDBIdException { | ||
| if (isShortPDBID(id) || XXXX_STRING.equalsIgnoreCase(id)) { | ||
| return ("0000"+id).toUpperCase(); | ||
| }else if (isExtendedPDBID(id)) { | ||
| return id.substring(4).toUpperCase(); | ||
| } else { | ||
| throw new PDBIdException("Unknown format ["+id+"]"); | ||
| } | ||
| } | ||
|
|
||
| private static String internalToExtendedFormat(String id){ | ||
| return "PDB_" + id; | ||
|
Contributor
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. I think the
Member
Author
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. I extracted the literals as per your advice. However, I believe using it in the regex will make it too complicated for no much added value. |
||
| } | ||
|
|
||
| private static String internalToShortNoCheck(String extendedId) { | ||
| return extendedId.substring(4).toUpperCase(); | ||
| } | ||
|
|
||
| private static String toShortNoCheck(String extendedId) { | ||
| return extendedId.substring(8).toUpperCase(); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public int compareTo(PDBId o) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.