X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureMapping.java;h=b8a0fc6550d0ff99074bcec374a3fbafa4b123a8;hb=19b5db52eb1285a22f8225f4baa914c2d7b15edd;hp=d6eb1ebbbcbf0c3709a71c43a1cce75e62f35852;hpb=12ce719d6e83d2a5411da7d8ac4c40c174c93747;p=jalview.git diff --git a/src/jalview/structure/StructureMapping.java b/src/jalview/structure/StructureMapping.java index d6eb1eb..b8a0fc6 100644 --- a/src/jalview/structure/StructureMapping.java +++ b/src/jalview/structure/StructureMapping.java @@ -26,12 +26,19 @@ import jalview.datamodel.SequenceI; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; public class StructureMapping { + public static final int UNASSIGNED = -1; + + public static final int PDB_RES_NUM_INDEX = 0; + + public static final int PDB_ATOM_NUM_INDEX = 1; + /** - * Space character constant, recommended for consistent representation when no - * chain specified + * Space character constant, for consistent representation when no chain + * specified */ public static String NO_CHAIN = " "; @@ -45,12 +52,6 @@ public class StructureMapping String pdbchain; - public static final int UNASSIGNED_VALUE = -1; - - private static final int PDB_RES_NUM_INDEX = 0; - - private static final int PDB_ATOM_NUM_INDEX = 1; - // Mapping key is residue index while value is an array containing PDB resNum, // and atomNo HashMap mapping; @@ -95,39 +96,31 @@ public class StructureMapping } /** + * Answers the structure atom number mapped to the given sequence position, or + * -1 if no mapping * * @param seqpos - * @return 0 or corresponding atom number for the sequence position + * @return */ public int getAtomNum(int seqpos) { int[] resNumAtomMap = mapping.get(seqpos); - if (resNumAtomMap != null) - { - return resNumAtomMap[PDB_ATOM_NUM_INDEX]; - } - else - { - return UNASSIGNED_VALUE; - } + return (resNumAtomMap == null ? UNASSIGNED + : resNumAtomMap[PDB_ATOM_NUM_INDEX]); } /** + * Answers the structure residue number mapped to the given sequence position, + * or -1 if no mapping * * @param seqpos - * @return 0 or the corresponding residue number for the sequence position + * @return */ public int getPDBResNum(int seqpos) { int[] resNumAtomMap = mapping.get(seqpos); - if (resNumAtomMap != null) - { - return resNumAtomMap[PDB_RES_NUM_INDEX]; - } - else - { - return UNASSIGNED_VALUE; - } + return (resNumAtomMap == null ? UNASSIGNED + : resNumAtomMap[PDB_RES_NUM_INDEX]); } /** @@ -147,7 +140,7 @@ public class StructureMapping for (int i = fromSeqPos; i <= toSeqPos; i++) { int resNo = getPDBResNum(i); - if (resNo == UNASSIGNED_VALUE) + if (resNo == UNASSIGNED) { continue; // no mapping from this sequence position } @@ -195,20 +188,22 @@ public class StructureMapping } /** + * Answers the sequence position mapped to the given structure residue number, + * or -1 if no mapping is found * * @param pdbResNum - * @return -1 or the corresponding sequence position for a pdb residue number + * @return */ public int getSeqPos(int pdbResNum) { - for (Integer seqPos : mapping.keySet()) + for (Entry map : mapping.entrySet()) { - if (pdbResNum == getPDBResNum(seqPos)) + if (pdbResNum == map.getValue()[PDB_RES_NUM_INDEX]) { - return seqPos; + return map.getKey(); } } - return UNASSIGNED_VALUE; + return UNASSIGNED; } /**