+ 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;
+ }
+ if (seqCoordSys == seqCoordSys.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 = pdbeIndex;
+ }
+ if (currSeqIndex == UNASSIGNED)
+ {
+ continue;
+ }
+ 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 >= 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 (isResidueObserved(residue)
+ || seqCoordSys == CoordinateSys.UNIPROT)
+ {
+ char resCharCode = ResidueProperties
+ .getSingleCharacterCode(ResidueProperties
+ .getCanonicalAminoAcid(residue.getDbResName()));
+ resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
+ }
+ // TODO: mapping should have SeqCoordSysNum => int[] {PDBeNum,
+ // PDBRESNUM, ATOMNUM }
+ mapping.put(currSeqIndex - nonObservedShiftIndex,
+ new int[]
+ { Integer.valueOf(resNum), UNASSIGNED,
+ isObserved ? firstPDBResNum
+ : UNASSIGNED });
+ }
+ }
+ }