+ void processSegments(List<Segment> segments, SegmentHelperPojo shp)
+ {
+ SequenceI seq = shp.getSeq();
+ HashMap<Integer, int[]> mapping = shp.getMapping();
+ TreeMap<Integer, String> resNumMap = shp.getResNumMap();
+ List<Integer> omitNonObserved = shp.getOmitNonObserved();
+ int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
+ for (Segment segment : segments)
+ {
+ // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
+ // + segStartEnd);
+ List<Residue> residues = segment.getListResidue().getResidue();
+ for (Residue residue : residues)
+ {
+ int currSeqIndex = UNASSIGNED;
+ List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
+ CrossRefDb pdbRefDb = null;
+ for (CrossRefDb cRefDb : cRefDbs)
+ {
+ if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
+ {
+ pdbRefDb = cRefDb;
+ }
+ if (cRefDb.getDbCoordSys()
+ .equalsIgnoreCase(seqCoordSys.getName())
+ && isAccessionMatched(cRefDb.getDbAccessionId()))
+ {
+ currSeqIndex = getLeadingIntegerValue(
+ cRefDb.getDbResNum(), UNASSIGNED);
+ if (pdbRefDb != null)
+ {
+ break;// exit loop if pdb and uniprot are already found
+ }
+ }
+ }
+ if (currSeqIndex == UNASSIGNED)
+ {
+ continue;
+ }
+ if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
+ {
+
+ int resNum = (pdbRefDb == null) ? getLeadingIntegerValue(
+ residue.getDbResNum(), UNASSIGNED)
+ : getLeadingIntegerValue(pdbRefDb.getDbResNum(),
+ UNASSIGNED);
+
+ if (isResidueObserved(residue)
+ || seqCoordSys == CoordinateSys.UNIPROT)
+ {
+ char resCharCode = ResidueProperties
+ .getSingleCharacterCode(ResidueProperties
+ .getCanonicalAminoAcid(residue.getDbResName()));
+ resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
+ }
+ else
+ {
+ omitNonObserved.add(currSeqIndex);
+ ++nonObservedShiftIndex;
+ }
+ mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
+ Integer.valueOf(resNum), UNASSIGNED });
+ }
+ }
+ }
+ }
+
+ /**
+ * Get the leading integer part of a string that begins with an integer.
+ *
+ * @param input
+ * - the string input to process
+ * @param failValue
+ * - value returned if unsuccessful
+ * @return
+ */
+ static int getLeadingIntegerValue(String input, int failValue)
+ {
+ if (input == null)
+ {
+ return failValue;
+ }
+ String[] parts = input.split("(?=\\D)(?<=\\d)");
+ if (parts != null && parts.length > 0 && parts[0].matches("[0-9]+"))
+ {
+ return Integer.valueOf(parts[0]);
+ }
+ return failValue;
+ }
+
+