X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureMapping.java;fp=src%2Fjalview%2Fstructure%2FStructureMapping.java;h=40789edf8740ce1cab6d8fd384aa8a4f830cb5be;hb=d5bcc3830eab04e6db816e1c2ad8fce1dc189612;hp=78634e06d0dee01b9b95f8e570a2bb2831ca2f9e;hpb=3ebdd4e28382e38a181aae1eed71549f603f9025;p=jalview.git diff --git a/src/jalview/structure/StructureMapping.java b/src/jalview/structure/StructureMapping.java index 78634e0..40789ed 100644 --- a/src/jalview/structure/StructureMapping.java +++ b/src/jalview/structure/StructureMapping.java @@ -23,7 +23,9 @@ package jalview.structure; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceI; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; public class StructureMapping { @@ -47,6 +49,18 @@ public class StructureMapping // and atomNo HashMap mapping; + /** + * Constructor + * + * @param seq + * @param pdbfile + * @param pdbid + * @param chain + * @param mapping + * a map from sequence to two values, { resNo, atomNo } in the + * structure + * @param mappingDetails + */ public StructureMapping(SequenceI seq, String pdbfile, String pdbid, String chain, HashMap mapping, String mappingDetails) @@ -111,6 +125,70 @@ public class StructureMapping } /** + * Returns a (possibly empty) list of [start, end] residue positions in the + * mapped structure, corresponding to the given range of sequence positions + * + * @param fromSeqPos + * @param toSeqPos + * @return + */ + public List getPDBResNumRanges(int fromSeqPos, int toSeqPos) + { + List result = new ArrayList(); + int startRes = -1; + int endRes = -1; + + for (int i = fromSeqPos; i <= toSeqPos; i++) + { + int resNo = getPDBResNum(i); + if (resNo == UNASSIGNED_VALUE) + { + continue; // no mapping from this sequence position + } + if (startRes == -1) + { + startRes = resNo; + endRes = resNo; + } + if (resNo >= startRes && resNo <= endRes) + { + // within the current range - no change + continue; + } + if (resNo == startRes - 1) + { + // extend beginning of current range + startRes--; + continue; + } + if (resNo == endRes + 1) + { + // extend end of current range + endRes++; + continue; + } + + /* + * resNo is not within or contiguous with last range, + * so write out the last range + */ + result.add(new int[] { startRes, endRes }); + startRes = resNo; + endRes = resNo; + } + + /* + * and add the last range + */ + if (startRes != -1) + { + result.add(new int[] { startRes, endRes }); + } + + return result; + } + + /** * * @param pdbResNum * @return -1 or the corresponding sequence position for a pdb residue number