+ 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();
+ int pdbeNonObservedCount = shp.getPdbeNonObserved();
+ int firstPDBResNum = UNASSIGNED;
+ for (Segment segment : segments)
+ {
+ // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
+ // + segStartEnd);
+ List<Residue> residues = segment.getListResidue().getResidue();
+ for (Residue residue : residues)
+ {
+ boolean isObserved = isResidueObserved(residue);
+ int pdbeIndex = getLeadingIntegerValue(residue.getDbResNum(),
+ UNASSIGNED);
+ int currSeqIndex = UNASSIGNED;
+ List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
+ CrossRefDb pdbRefDb = null;
+ for (CrossRefDb cRefDb : cRefDbs)
+ {
+ if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
+ {
+ pdbRefDb = cRefDb;
+ if (firstPDBResNum == UNASSIGNED)
+ {
+ firstPDBResNum = getLeadingIntegerValue(cRefDb.getDbResNum(),
+ UNASSIGNED);
+ }
+ else
+ {
+ if (isObserved)
+ {
+ // after we find the first observed residue we just increment
+ firstPDBResNum++;
+ }
+ }
+ }
+ 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 (!isObserved)
+ {
+ ++pdbeNonObservedCount; // TODO this value is never used
+ }
+ if (seqCoordSys == CoordinateSys.PDB) // FIXME: is seqCoordSys ever PDBe
+ // ???
+ {
+ // if the sequence has a primary reference to the PDB, then we are
+ // dealing with a sequence extracted directly from the PDB. In that
+ // case, numbering is PDBe - non-observed residues
+ currSeqIndex = seq.getStart() - 1 + pdbeIndex;
+ }
+ if (!isObserved)
+ {
+ if (seqCoordSys != CoordinateSys.UNIPROT) // FIXME: PDB or PDBe only
+ // here
+ {
+ // mapping to PDB or PDBe so we need to bookkeep for the
+ // non-observed
+ // SEQRES positions
+ omitNonObserved.add(currSeqIndex);
+ ++nonObservedShiftIndex;
+ }
+ }
+ if (currSeqIndex == UNASSIGNED)
+ {
+ // change in logic - unobserved residues with no currSeqIndex
+ // corresponding are still counted in both nonObservedShiftIndex and
+ // pdbeIndex...
+ continue;
+ }
+ // if (currSeqIndex >= seq.getStart() && currSeqIndex <= seqlength) //
+ // true
+ // numbering
+ // is
+ // not
+ // up
+ // to
+ // seq.getEnd()
+ {
+
+ int resNum = (pdbRefDb == null)
+ ? getLeadingIntegerValue(residue.getDbResNum(),
+ UNASSIGNED)
+ : getLeadingIntegerValue(pdbRefDb.getDbResNum(),
+ UNASSIGNED);
+
+ if (isObserved)
+ {
+ char resCharCode = ResidueProperties
+ .getSingleCharacterCode(ResidueProperties
+ .getCanonicalAminoAcid(residue.getDbResName()));
+ resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
+
+ int[] mappingcols = new int[] { Integer.valueOf(resNum),
+ UNASSIGNED, isObserved ? firstPDBResNum : UNASSIGNED };
+
+ mapping.put(currSeqIndex - nonObservedShiftIndex, mappingcols);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 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;
+ }
+