Package org.biojava.nbio.structure
Class PdbId
- java.lang.Object
-
- org.biojava.nbio.structure.PdbId
-
- All Implemented Interfaces:
Serializable
,Comparable<PdbId>
public class PdbId extends Object implements Comparable<PdbId>, Serializable
A wrapper class for the PDB identifier. It handles conversion between current (short)[1-9][0-9A-Z]{3}
and upcoming (extended)PDB_\d{4}[1-9][09-A-Z]
PDB ID format.
Instances of this class are immutable.
Creation of PdBId instance follows strict PDB ID convention. There is only one exception to this rule which is XXXX. XXXX objects are not considered equal (unless they are the one and the same object).- Since:
- 6.0.0
- Author:
- Amr ALHOSSARY
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Pattern
PATTERN_EXTENDED_PDBID
A regular expression that matches a PDB ID in the extended format.static Pattern
PATTERN_SHORT_PDBID
A regular expression that matches a PDB ID in the short format.static Pattern
PATTERN_SHORTABLE_EXTENDED_PDBID
/ * A regular expression that matches an extended PDB ID that is compatible with the short format.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
clone()
int
compareTo(PdbId o)
boolean
equals(Object obj)
String
getId()
Get aString
representation of this PdbId instance.
By default this function will try to get the PdbId in the short (4 letters) format.String
getId(boolean prefereShort)
Get aString
representation of this PdbId instance, using the passed in behavior.String
getShortId()
Get the PDB Id in the short format.int
hashCode()
static boolean
isShortCompatible(String extendedId)
Checks whether an Extended PDB ID is shortable, assuming it is a valid extended PDB ID.static boolean
isValidExtendedPdbId(String id)
Check whetherid
represents a valid PDB ID in the extended format.static boolean
isValidShortPdbId(String id)
Check whetherid
represents a valid PDB ID in the short format.static String
toExtendedId(String shortId)
ConvertsshortId
to the PDB ID extended format.static String
toShortId(String extendedId)
ConvertsextendedId
to the PDB ID short format.String
toString()
-
-
-
Field Detail
-
PATTERN_SHORT_PDBID
public static final Pattern PATTERN_SHORT_PDBID
A regular expression that matches a PDB ID in the short format.
-
PATTERN_EXTENDED_PDBID
public static final Pattern PATTERN_EXTENDED_PDBID
A regular expression that matches a PDB ID in the extended format.
-
PATTERN_SHORTABLE_EXTENDED_PDBID
public static final Pattern PATTERN_SHORTABLE_EXTENDED_PDBID
/ * A regular expression that matches an extended PDB ID that is compatible with the short format.
-
-
Constructor Detail
-
PdbId
public PdbId(String id)
- Parameters:
id
- A valid PDB ID in either short (case insensitive) or extended format.- Throws:
IllegalArgumentException
- Ifid
is not a valid identifier.NullPointerException
- Ifid
isnull
.
-
-
Method Detail
-
isValidShortPdbId
public static boolean isValidShortPdbId(String id)
Check whetherid
represents a valid PDB ID in the short format.- Parameters:
id
- Prospect ID- Returns:
true
ifid
is a valid short PDB ID,false
otherwise.- Throws:
NullPointerException
- ifid
isnull
.- See Also:
isValidExtendedPdbId(String)
-
isValidExtendedPdbId
public static boolean isValidExtendedPdbId(String id)
Check whetherid
represents a valid PDB ID in the extended format.- Parameters:
id
- Prospect ID- Returns:
true
ifid
is a valid extended PDB ID,false
otherwise.- Throws:
NullPointerException
- ifid
isnull
.- See Also:
isValidShortPdbId(String)
-
isShortCompatible
public static boolean isShortCompatible(String extendedId)
Checks whether an Extended PDB ID is shortable, assuming it is a valid extended PDB ID.- Parameters:
extendedId
- the supposedly valid extended PDB ID.- Returns:
true
ifextendedId
can be shortened (ie. it matches the regular expression "(pdb|PDB)_0000[1-9][a-zA-Z0-9]{3}"),false
otherwise.- See Also:
isValidExtendedPdbId(String)
-
clone
protected Object clone() throws CloneNotSupportedException
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
getId
public String getId()
Get aString
representation of this PdbId instance.
By default this function will try to get the PdbId in the short (4 letters) format. If not possible, it will return the long format. N.B. This default behavior may change later;- Returns:
- the PdbId code, preferably in short format.
-
getId
public String getId(boolean prefereShort)
Get aString
representation of this PdbId instance, using the passed in behavior.- Parameters:
prefereShort
- when it istrue
, the class will try to produce the short ID whenever possible.- Returns:
- The PdbId in short format if possible and
prefereShort
istrue
, the extended PDB ID form otherwise.
-
getShortId
public String getShortId() throws StructureException
Get the PDB Id in the short format. Throws an exception if the conversion is not possible.
Use this method only if you know that this PDB ID is shortable.- Returns:
- the PDB ID in the short format.
- Throws:
StructureException
- if the conversion was not possible.
-
toExtendedId
public static String toExtendedId(String shortId) throws StructureException
ConvertsshortId
to the PDB ID extended format. IfshortId
is a valid short PDB ID, it would be converted to an extended ID, ifshortId
is a valid extended PDB ID, it would be returned in UPPER CASE, aStructureException
is thrown otherwise.- Parameters:
shortId
- the PDB ID to convert to extended format- Returns:
- the ID in the extended UPPER CASE format.
- Throws:
StructureException
- if the conversion was not possible.
-
toShortId
public static String toShortId(String extendedId) throws StructureException
ConvertsextendedId
to the PDB ID short format. IfextendedId
is a valid extended PDB ID, it would be converted to a short ID, ifextendedId
is a valid short PDB ID, it would be returned in UPPER CASE, aStructureException
is thrown otherwise.- Parameters:
extendedId
- the PDB ID to convert to short format- Returns:
- the ID in the short UPPER CASE format.
- Throws:
StructureException
- if the conversion was not possible.
-
compareTo
public int compareTo(PdbId o)
- Specified by:
compareTo
in interfaceComparable<PdbId>
-
-