From e8b8c8601ccdc2fdb2093c5228c071d14182004f Mon Sep 17 00:00:00 2001 From: James Procter Date: Mon, 29 May 2023 18:03:08 +0100 Subject: [PATCH 1/1] JAL-4134 JAL-2349 test & fixed implementation(ish) for getMappedPositionsFor(seq,from,to) --- .../datamodel/alphafold/MappableContactMatrix.java | 71 +++++++++++--------- test/jalview/datamodel/PAEContactMatrixTest.java | 37 ++++++++++ 2 files changed, 76 insertions(+), 32 deletions(-) diff --git a/src/jalview/ws/datamodel/alphafold/MappableContactMatrix.java b/src/jalview/ws/datamodel/alphafold/MappableContactMatrix.java index 9a01738..0e617d7 100644 --- a/src/jalview/ws/datamodel/alphafold/MappableContactMatrix.java +++ b/src/jalview/ws/datamodel/alphafold/MappableContactMatrix.java @@ -193,21 +193,9 @@ public abstract class MappableContactMatrix> { throw new Error("Unimplemented when no local sequence given."); } - // return a ContactListI for column - // column is index into localFrame - // 1. map column to corresponding column in matrix - - final int _lcolumn = localFrame.findPosition(from); - final int _rcolumn = (from == to) ? _lcolumn - : localFrame.findPosition(to); - if (toSeq == null) - { - // no mapping - return new int[] { _lcolumn, _rcolumn }; - } - SequenceI lf = localFrame, uf = refSeq; + // check that localFrame is derived from refSeq // just look for dataset sequences and check they are the same. // in future we could use DBRefMappings/whatever. while (lf.getDatasetSequence() != null @@ -229,26 +217,45 @@ public abstract class MappableContactMatrix> + "' is not mappable for the given localFrame sequence. (" + localFrame.getName() + ")"); } + + // now look up from-to matrix columns in toSeq frame + + if (toSeq == null) + { + // no mapping - so we assume 1:1 + return new int[] { from, to }; + } + // from-to are matrix columns + // first locate on reference sequence - int[] mappedPositions = toSeq.locateInFrom(_lcolumn, _rcolumn); - // TODO - trim to localFrame ? - // if (mappedPositions!=null) { - // int s=-1,e=-1; - // for (int p=0;p=localFrame.getStart()) - // { - // s=p; // remember first position within local frame - // } - // if (e==-1 || mappedPositions[p]<=localFrame.getEnd()) - // { - // // update end pointer - // e=p; - // // compute local map - // mappedPositions[p] = localFrame.findIndex(mappedPositions[p]); - // } - // } - // } + int[] mappedPositions = toSeq.locateInFrom(from, to); + if (mappedPositions==null) + { + return null; + } + + // and now map to localFrame + // from-to columns on the associated sequence should be + // i. restricted to positions in localFrame + // ii. + +// int s = -1, e = -1; +// for (int p = 0; p < mappedPositions.length; p++) +// { +// if (s == -1 && mappedPositions[p] >= localFrame.getStart()) +// { +// s = p; // remember first position within local frame +// } +// if (e == -1 || mappedPositions[p] <= localFrame.getEnd()) +// { +// // update end pointer +// e = p; +// // compute local map +// mappedPositions[p] = localFrame.findIndex(mappedPositions[p]); +// } +// } +// int[] _trimmed = new int[e - s + 1]; +// return _trimmed; return mappedPositions; } diff --git a/test/jalview/datamodel/PAEContactMatrixTest.java b/test/jalview/datamodel/PAEContactMatrixTest.java index 8cc2ec4..67edb37 100644 --- a/test/jalview/datamodel/PAEContactMatrixTest.java +++ b/test/jalview/datamodel/PAEContactMatrixTest.java @@ -206,4 +206,41 @@ public class PAEContactMatrixTest } } + /** + * check mapping and resolution methods work + */ + @Test(groups= {"Functional"}) + public void testMappableContactMatrix() { + SequenceI newseq = new Sequence("Seq", "ASDQEASDQEASDQE"); + MapList map = new MapList(new int[] + { 5, 9 }, new int[] { 1, 5 }, 1, 1); + AlignmentAnnotation aa = newseq + .addContactList(new PAEContactMatrix(newseq,map, PAEdata,null)); + ContactListI clist = newseq.getContactListFor(aa, 4); + assertNotNull(clist); + clist = newseq.getContactListFor(aa, 3); + assertNull(clist); + + ContactMatrixI cm = newseq.getContactMatrixFor(aa); + MappableContactMatrixI mcm = (MappableContactMatrixI) cm; + int[] pos = mcm.getMappedPositionsFor(newseq, 0); + assertNull(pos); + + pos = mcm.getMappedPositionsFor(newseq, 1); + assertNotNull(pos); + assertEquals(pos[0],4+newseq.getStart()); + + pos = mcm.getMappedPositionsFor(newseq, 6); // after end of matrix + assertNull(pos); + pos = mcm.getMappedPositionsFor(newseq, 5); // at end of matrix + assertNotNull(pos); + assertEquals(pos[0],8+newseq.getStart()); + SequenceI alseq = newseq.deriveSequence(); + alseq.insertCharAt(5,'-'); + pos = mcm.getMappedPositionsFor(alseq, 5); // at end of matrix + assertNotNull(pos); + assertEquals(pos[0],8+newseq.getStart()); + + + } } -- 1.7.10.2