+ /**
+ * This method was added because EntityId is NOT always equal to ChainId.
+ * Hence, it provides the logic to greedily detect the "true" Entity for a
+ * given chainId where discrepancies exist.
+ *
+ * @param chainId
+ * @return
+ */
+ public Entity getEntityByMostOptimalMatchedId(String chainId)
+ {
+ System.out
+ .println("--------------> advanced greedy entityId matching block entered..");
+ List<Entity> entities = siftsEntry.getEntity();
+ SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
+ int count = 0;
+ for (Entity entity : entities)
+ {
+ sPojo[count] = new SiftsEntitySortPojo();
+ sPojo[count].entityId = entity.getEntityId();
+
+ List<Segment> segments = entity.getSegment();
+ for (Segment segment : segments)
+ {
+ List<Residue> residues = segment.getListResidue().getResidue();
+ for (Residue residue : residues)
+ {
+ List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
+ for (CrossRefDb cRefDb : cRefDbs)
+ {
+ if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
+ {
+ continue;
+ }
+ ++sPojo[count].resCount;
+ if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
+ {
+ ++sPojo[count].chainIdFreq;
+ }
+ }
+ }
+ }
+ sPojo[count].pid = 100 * (sPojo[count].chainIdFreq / sPojo[count].resCount);
+ ++count;
+ }
+ Arrays.sort(sPojo, Collections.reverseOrder());
+ System.out.println("highest matched entity : " + sPojo[0].entityId);
+ System.out.println("highest matched pid : " + sPojo[0].pid);
+
+ if (sPojo[0].entityId != null)
+ {
+ for (Entity entity : entities)
+ {
+ if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
+ {
+ continue;
+ }
+ return entity;
+ }
+ }
+ return null;
+ }
+
+ public class SiftsEntitySortPojo implements
+ Comparable<SiftsEntitySortPojo>
+ {
+ public String entityId;
+
+ public int chainIdFreq;
+
+ public int pid;
+
+ public int resCount;
+
+ @Override
+ public int compareTo(SiftsEntitySortPojo o)
+ {
+ return this.pid - o.pid;
+ }
+ }
+