From: James Procter Date: Sat, 13 May 2023 15:50:47 +0000 (+0100) Subject: JAL-2349 JAL-3855 PAE tests covers ContactListI.getMappedPositons X-Git-Tag: Release_2_11_3_0~14^2~3^2^2~33 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=108f2d4b40f172ad6a34647133dbb18dfab150f7;p=jalview.git JAL-2349 JAL-3855 PAE tests covers ContactListI.getMappedPositons --- diff --git a/src/jalview/datamodel/ContactListImpl.java b/src/jalview/datamodel/ContactListImpl.java index 6a37864..b71c4b7 100644 --- a/src/jalview/datamodel/ContactListImpl.java +++ b/src/jalview/datamodel/ContactListImpl.java @@ -96,4 +96,9 @@ public class ContactListImpl implements ContactListI } return cr; } + @Override + public int[] getMappedPositionsFor(int cStart, int cEnd) + { + return clist.getMappedPositionsFor(cStart, cEnd); + } } diff --git a/src/jalview/datamodel/ContactListProviderI.java b/src/jalview/datamodel/ContactListProviderI.java index a4e0b79..75de1a4 100644 --- a/src/jalview/datamodel/ContactListProviderI.java +++ b/src/jalview/datamodel/ContactListProviderI.java @@ -30,7 +30,7 @@ public interface ContactListProviderI /** - * Return positions in local reference corresponding to cStart and cEnd in matrix data + * Return positions in local reference corresponding to cStart and cEnd in matrix data. Positions are base 1 column indices for sequence associated matrices. * @param cStart * @param cEnd * @return int[] { start, end (inclusive) for each contiguous segment} diff --git a/test/jalview/datamodel/PAEContactMatrixTest.java b/test/jalview/datamodel/PAEContactMatrixTest.java index 7426cba..71e824e 100644 --- a/test/jalview/datamodel/PAEContactMatrixTest.java +++ b/test/jalview/datamodel/PAEContactMatrixTest.java @@ -6,6 +6,8 @@ import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import jalview.analysis.AlignmentUtils; +import jalview.analysis.SeqsetUtils; import jalview.gui.JvOptionPane; import jalview.util.MapList; import jalview.ws.datamodel.MappableContactMatrixI; @@ -81,6 +83,22 @@ public class PAEContactMatrixTest // last column assertNotNull(newseq.getContactListFor(newaa, -1+newseq.findIndex(10))); + // verify MappedPositions includes discontinuity + int[] mappedCl = newseq.getContactListFor(newaa, 5).getMappedPositionsFor(0, 4); + assertEquals(4,mappedCl.length,"getMappedPositionsFor doesn't support discontinuous mappings to contactList"); + + // make it harder. + + SequenceI alseq = newseq.getSubSequence(6, 10); + alseq.insertCharAt(2, 2, '-'); + AlignmentI alForSeq=new Alignment(new SequenceI[] { alseq }); + newaa = AlignmentUtils.addReferenceAnnotationTo(alForSeq, alseq, newaa, null); + ContactListI alcl = alForSeq.getContactListFor(newaa, 1); + assertNotNull(alcl); + mappedCl = alcl.getMappedPositionsFor(0, 4); + assertNotNull(mappedCl); + assertEquals(4,mappedCl.length,"getMappedPositionsFor doesn't support discontinuous mappings to contactList"); + // remap2 - test with original matrix map from 1-5 remapped to 5-9 seq = new Sequence("Seq/1-5","ASDQE"); @@ -114,7 +132,6 @@ public class PAEContactMatrixTest newaa = newseq.addContactList(remapped); verify_mapping(newseq, newaa); - } /** * checks that the PAE matrix is located at positions 1-9 in newseq, and columns are not truncated. @@ -134,16 +151,19 @@ public class PAEContactMatrixTest assertNull(newseq.getContactListFor(newaa, -1+newseq.findIndex(10))); verifyPAEmatrix(newseq, newaa, 4, 4, 8); - - } private void verifyPAEmatrix(SequenceI seq, AlignmentAnnotation aa, int topl, int rowl, int rowr) { + int[] mappedCl; for (int f=rowl;f<=rowr;f++) { ContactListI clist = seq.getContactListFor(aa, f); assertNotNull(clist,"No ContactListI for position "+(f)); assertEquals(clist.getContactAt(0), (double) f-topl+1,"for column "+f+" relative to "+topl); + mappedCl = clist.getMappedPositionsFor(0, 0); + assertNotNull(mappedCl); + assertEquals(mappedCl[0],mappedCl[1]); + assertEquals(mappedCl[0],seq.findIndex(seq.getStart()+topl)); assertEquals(clist.getContactAt(f-topl),1d, "for column and row "+f+" relative to "+topl); } }