From: James Procter Date: Mon, 15 May 2023 13:46:34 +0000 (+0100) Subject: JAL-4182 failing test X-Git-Tag: Release_2_11_3_0~14^2~3^2^2~29 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=57924096fd7009330b3d879874f7d42874b4f416;p=jalview.git JAL-4182 failing test --- diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index 54093ee..0f3ea96 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -20,6 +20,7 @@ */ package jalview.analysis; +import static org.testng.Assert.assertNotEquals; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNotNull; @@ -54,6 +55,7 @@ import jalview.datamodel.SearchResultsI; import jalview.datamodel.SeqDistanceContactMatrix; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.JvOptionPane; import jalview.io.AppletFormatAdapter; @@ -62,6 +64,7 @@ import jalview.io.FileFormat; import jalview.io.FileFormatI; import jalview.io.FormatAdapter; import jalview.io.gff.SequenceOntologyI; +import jalview.util.Comparison; import jalview.util.MapList; import jalview.util.MappingUtils; @@ -2602,6 +2605,83 @@ public class AlignmentUtilsTests assertSame(seq, cds1.getDatasetSequence()); } + + @Test(groups = "Functional") + public void testAddReferenceAnnotations() + { + SequenceI longseq= new Sequence("longA","ASDASDASDASDAASDASDASDASDA"); + Annotation[] aa = new Annotation[longseq.getLength()]; + + for (int p=0;p tipEntries = new TreeMap<>(); + Map> candidates = new LinkedHashMap<>(); + + AlignmentUtils.findAddableReferenceAnnotations(ourAl.getSequences(), + tipEntries, candidates, ourAl); + AlignmentUtils.addReferenceAnnotations(candidates, ourAl, null); + + assertNotNull(ourAl.getAlignmentAnnotation()); + assertEquals(ourAl.getAlignmentAnnotation().length,2); + + for (AlignmentAnnotation alan:ourAl.getAlignmentAnnotation()) + { + verifyExpectedSequenceAnnotation(alan); + } + // Everything above works for 2.11.3 and 2.11.2.x. + // now simulate copy/paste to new alignment + SequenceI[] newSeqAl = new SequenceI[2]; + // copy sequences but no annotation + newSeqAl[0]=new Sequence(ourAl.getSequenceAt(0),ourAl.getSequenceAt(0).getAnnotation()); + newSeqAl[1]=new Sequence(ourAl.getSequenceAt(1),ourAl.getSequenceAt(1).getAnnotation()); + + Alignment newAl = new Alignment(newSeqAl); + // delete annotation + for (SequenceI sq:newAl.getSequences()) + { + sq.setAlignmentAnnotation(new AlignmentAnnotation[0]); + } + // JAL-4182 scenario test + SequenceGroup sg = new SequenceGroup(Arrays.asList(newSeqAl)); + sg.setStartRes(0); + sg.setEndRes(newAl.getWidth()); + AlignmentUtils.addReferenceAnnotationTo(newAl, newSeqAl[0], newSeqAl[0].getDatasetSequence().getAnnotation()[0], sg); + AlignmentUtils.addReferenceAnnotationTo(newAl, newSeqAl[1], newSeqAl[1].getDatasetSequence().getAnnotation()[0], sg); + for (AlignmentAnnotation alan:newAl.getAlignmentAnnotation()) + { + verifyExpectedSequenceAnnotation(alan); + } + } + + /** + * helper - tests annotation is mapped to position it was originally created for + * @param alan + */ + private void verifyExpectedSequenceAnnotation(AlignmentAnnotation alan) + { + for (int c=0;c=alan.sequenceRef.getLength() || Comparison.isGap(alan.sequenceRef.getCharAt(c))); + } + } + } + @Test(groups = "Functional") public void testAddReferenceContactMap() {