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, for consistent representation when no chain
+ * specified
+ */
+ public static String NO_CHAIN = " ";
+
String mappingDetails;
SequenceI sequence;
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<Integer, int[]> mapping;
}
/**
+ * 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]);
}
/**
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
}
}
/**
+ * 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<Integer, int[]> 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;
}
/**
return mappingDetails;
}
- public HashMap<Integer, int[]> getMapping()
- {
- return mapping;
- }
}