X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2FSequenceTest.java;h=6e18324d8ee8d92c0d50206500cfbe0c2aa508f4;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=5ae7dd9ab9163f25d1a7419362bc91c70bc10385;hpb=c49fa6aa001663914b33fc53a1d002bfc6a291ba;p=jalview.git diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index 5ae7dd9..6e18324 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -20,6 +20,8 @@ */ package jalview.datamodel; +import java.util.Locale; + import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNotNull; @@ -92,7 +94,8 @@ public class SequenceTest assertEquals("getInsertionsAsBits didn't mark expected number of gaps", 6, gapfield.cardinality()); - assertEquals("getInsertionsAsBits not correct.", expectedgaps, gapfield); + assertEquals("getInsertionsAsBits not correct.", expectedgaps, + gapfield); } @Test(groups = ("Functional")) @@ -110,6 +113,23 @@ public class SequenceTest assertTrue(sq.isProtein()); } + @Test(groups = ("Functional")) + public void testIsProteinWithXorNAmbiguityCodes() + { + // test Protein with N - poly asparagine + assertTrue(new Sequence("prot", "ASDFASDFASDFNNNNNNNNN").isProtein()); + assertTrue(new Sequence("prot", "NNNNNNNNNNNNNNNNNNNNN").isProtein()); + // test Protein with X + assertTrue(new Sequence("prot", "ASDFASDFASDFXXXXXXXXX").isProtein()); + // test DNA with X + assertFalse(new Sequence("prot", "ACGTACGTACGTXXXXXXXX").isProtein()); + // test DNA with N + assertFalse(new Sequence("prot", "ACGTACGTACGTNNNNNNNN").isProtein()); + // test RNA with X + assertFalse(new Sequence("prot", "ACGUACGUACGUXXXXXXXXX").isProtein()); + assertFalse(new Sequence("prot", "ACGUACGUACGUNNNNNNNNN").isProtein()); + } + @Test(groups = { "Functional" }) public void testGetAnnotation() { @@ -175,6 +195,38 @@ public class SequenceTest assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty()); } + @Test(groups = { "Functional" }) + public void testGetAlignmentAnnotations_forCalcIdLabelAndDescription() + { + addAnnotation("label1", "desc1", "calcId1", 1f); + AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2", + 1f); + addAnnotation("label2", "desc3", "calcId3", 1f); + AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2", + 1f); + addAnnotation("label5", "desc3", null, 1f); + addAnnotation(null, "desc3", "calcId3", 1f); + + List anns = seq.getAlignmentAnnotations("calcId2", + "label2", "desc3"); + assertEquals(1, anns.size()); + assertSame(ann4, anns.get(0)); + /** + * null matching should fail + */ + assertTrue(seq.getAlignmentAnnotations("calcId3", "label2", null) + .isEmpty()); + + assertTrue(seq.getAlignmentAnnotations("calcId2", "label3", null) + .isEmpty()); + assertTrue(seq.getAlignmentAnnotations("calcId3", "label5", null) + .isEmpty()); + assertTrue( + seq.getAlignmentAnnotations("calcId2", null, null).isEmpty()); + assertTrue(seq.getAlignmentAnnotations(null, "label3", null).isEmpty()); + assertTrue(seq.getAlignmentAnnotations(null, null, null).isEmpty()); + } + /** * Tests for addAlignmentAnnotation. Note this method has the side-effect of * setting the sequenceRef on the annotation. Adding the same annotation twice @@ -184,8 +236,8 @@ public class SequenceTest public void testAddAlignmentAnnotation() { assertNull(seq.getAnnotation()); - final AlignmentAnnotation annotation = new AlignmentAnnotation("a", - "b", 2d); + final AlignmentAnnotation annotation = new AlignmentAnnotation("a", "b", + 2d); assertNull(annotation.sequenceRef); seq.addAlignmentAnnotation(annotation); assertSame(seq, annotation.sequenceRef); @@ -723,7 +775,8 @@ public class SequenceTest /* * SequenceFeature on sequence */ - SequenceFeature sf = new SequenceFeature("Cath", "desc", 2, 4, 2f, null); + SequenceFeature sf = new SequenceFeature("Cath", "desc", 2, 4, 2f, + null); sq.addSequenceFeature(sf); List sfs = sq.getSequenceFeatures(); assertEquals(1, sfs.size()); @@ -762,11 +815,12 @@ public class SequenceTest try { sq.getDatasetSequence().setDatasetSequence(sq); // loop! - Assert.fail("Expected Error to be raised when calling setDatasetSequence with self reference"); + Assert.fail( + "Expected Error to be raised when calling setDatasetSequence with self reference"); } catch (IllegalArgumentException e) { // TODO Jalview error/exception class for raising implementation errors - assertTrue(e.getMessage().toLowerCase() + assertTrue(e.getMessage().toLowerCase(Locale.ROOT) .contains("implementation error")); } assertTrue(sq.getSequenceFeatures().isEmpty()); @@ -819,8 +873,8 @@ public class SequenceTest public void testCreateDatasetSequence() { SequenceI sq = new Sequence("my", "ASDASD"); - sq.addSequenceFeature(new SequenceFeature("type", "desc", 1, 10, 1f, - "group")); + sq.addSequenceFeature( + new SequenceFeature("type", "desc", 1, 10, 1f, "group")); sq.addDBRef(new DBRefEntry("source", "version", "accession")); assertNull(sq.getDatasetSequence()); assertNotNull(PA.getValue(sq, "sequenceFeatureStore")); @@ -869,15 +923,18 @@ public class SequenceTest DBRefEntry pdb1pdb = new DBRefEntry("PDB", "version1", "1PDB"); DBRefEntry pdb2pdb = new DBRefEntry("PDB", "version2", "2PDB"); - List primRefs = Arrays.asList(new DBRefEntry[] { pdb1pdb, - pdb2pdb }); + List primRefs = Arrays + .asList(new DBRefEntry[] + { pdb1pdb, pdb2pdb }); sq.getDatasetSequence().addDBRef(pdb1pdb); // should do nothing sq.getDatasetSequence().addDBRef(pdb2pdb); // should do nothing - sq.getDatasetSequence().addDBRef( - new DBRefEntry("PDB", "version3", "3PDB")); // should do nothing - sq.getDatasetSequence().addDBRef( - new DBRefEntry("PDB", "version4", "4PDB")); // should do nothing + sq.getDatasetSequence() + .addDBRef(new DBRefEntry("PDB", "version3", "3PDB")); // should do + // nothing + sq.getDatasetSequence() + .addDBRef(new DBRefEntry("PDB", "version4", "4PDB")); // should do + // nothing PDBEntry pdbe1a = new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"); PDBEntry pdbe1b = new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"); @@ -893,15 +950,15 @@ public class SequenceTest /* * test we added pdb entries to the dataset sequence */ - Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries(), Arrays - .asList(new PDBEntry[] { pdbe1a, pdbe1b, pdbe2a, pdbe2b }), + Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries(), + Arrays.asList(new PDBEntry[] + { pdbe1a, pdbe1b, pdbe2a, pdbe2b }), "PDB Entries were not found on dataset sequence."); /* * we should recover a pdb entry that is on the dataset sequence via PDBEntry */ - Assert.assertEquals(pdbe1a, - sq.getDatasetSequence().getPDBEntry("1PDB"), + Assert.assertEquals(pdbe1a, sq.getDatasetSequence().getPDBEntry("1PDB"), "PDB Entry '1PDB' not found on dataset sequence via getPDBEntry."); ArrayList annotsList = new ArrayList<>(); System.out.println(">>>>>> " + sq.getSequenceAsString().length()); @@ -910,9 +967,8 @@ public class SequenceTest Annotation[] annots = annotsList.toArray(new Annotation[0]); sq.addAlignmentAnnotation(new AlignmentAnnotation("Test annot", "Test annot description", annots)); - sq.getDatasetSequence().addAlignmentAnnotation( - new AlignmentAnnotation("Test annot", "Test annot description", - annots)); + sq.getDatasetSequence().addAlignmentAnnotation(new AlignmentAnnotation( + "Test annot", "Test annot description", annots)); Assert.assertEquals(sq.getDescription(), "Test sequence description.."); Assert.assertEquals(sq.getDBRefs().size(), 5); // DBRefs are on dataset // sequence @@ -935,8 +991,8 @@ public class SequenceTest Assert.assertNotNull(derived.getAnnotation()); Assert.assertEquals(derived.getAnnotation()[0].annotations.length, 2); Assert.assertEquals(derived.getDatasetSequence().getDBRefs().size(), 5); - Assert.assertEquals(derived.getDatasetSequence().getAllPDBEntries() - .size(), 4); + Assert.assertEquals( + derived.getDatasetSequence().getAllPDBEntries().size(), 4); Assert.assertNotNull(derived.getDatasetSequence().getAnnotation()); assertEquals("CD", derived.getSequenceAsString()); @@ -969,8 +1025,8 @@ public class SequenceTest assertEquals(6, sq.getEnd()); SequenceI derived = sq.deriveSequence(); assertEquals("ABCDEF", derived.getSequenceAsString()); - assertEquals("ABCDEF", derived.getDatasetSequence() - .getSequenceAsString()); + assertEquals("ABCDEF", + derived.getDatasetSequence().getSequenceAsString()); } /** @@ -985,8 +1041,8 @@ public class SequenceTest assertNull(sq.getDatasetSequence()); SequenceI derived = sq.deriveSequence(); assertEquals("AB-C.D EF", derived.getSequenceAsString()); - assertEquals("ABCDEF", derived.getDatasetSequence() - .getSequenceAsString()); + assertEquals("ABCDEF", + derived.getDatasetSequence().getSequenceAsString()); } @Test(groups = { "Functional" }) @@ -994,10 +1050,10 @@ public class SequenceTest { SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF"); seq1.setDescription("description"); - seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc", - 1.3d)); - seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33, - 12.4f, "group")); + seq1.addAlignmentAnnotation( + new AlignmentAnnotation("label", "desc", 1.3d)); + seq1.addSequenceFeature( + new SequenceFeature("type", "desc", 22, 33, 12.4f, "group")); seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File")); seq1.addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345")); @@ -1025,16 +1081,16 @@ public class SequenceTest SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF"); seq1.createDatasetSequence(); seq1.setDescription("description"); - seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc", - 1.3d)); + seq1.addAlignmentAnnotation( + new AlignmentAnnotation("label", "desc", 1.3d)); // JAL-2046 - what is the contract for using a derived sequence's // addSequenceFeature ? - seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33, - 12.4f, "group")); + seq1.addSequenceFeature( + new SequenceFeature("type", "desc", 22, 33, 12.4f, "group")); seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File")); // here we add DBRef to the dataset sequence: - seq1.getDatasetSequence().addDBRef( - new DBRefEntry("EMBL", "1.2", "AZ12345")); + seq1.getDatasetSequence() + .addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345")); SequenceI copy = new Sequence(seq1); @@ -1109,28 +1165,37 @@ public class SequenceTest { SequenceI sq = new Sequence("", "abcde"); // type may not be null - assertFalse(sq.addSequenceFeature(new SequenceFeature(null, "desc", 4, - 8, 0f, null))); - assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4, - 8, 0f, null))); + assertFalse(sq.addSequenceFeature( + new SequenceFeature(null, "desc", 4, 8, 0f, null))); + assertTrue(sq.addSequenceFeature( + new SequenceFeature("Cath", "desc", 4, 8, 0f, null))); // can't add a duplicate feature - assertFalse(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", - 4, 8, 0f, null))); + assertFalse(sq.addSequenceFeature( + new SequenceFeature("Cath", "desc", 4, 8, 0f, null))); // can add a different feature - assertTrue(sq.addSequenceFeature(new SequenceFeature("Scop", "desc", 4, - 8, 0f, null))); // different type - assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", - "description", 4, 8, 0f, null)));// different description - assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 3, - 8, 0f, null))); // different start position - assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4, - 9, 0f, null))); // different end position - assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4, - 8, 1f, null))); // different score - assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4, - 8, Float.NaN, null))); // score NaN - assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4, - 8, 0f, "Metal"))); // different group + assertTrue(sq.addSequenceFeature( + new SequenceFeature("Scop", "desc", 4, 8, 0f, null))); // different + // type + assertTrue(sq.addSequenceFeature( + new SequenceFeature("Cath", "description", 4, 8, 0f, null)));// different + // description + assertTrue(sq.addSequenceFeature( + new SequenceFeature("Cath", "desc", 3, 8, 0f, null))); // different + // start + // position + assertTrue(sq.addSequenceFeature( + new SequenceFeature("Cath", "desc", 4, 9, 0f, null))); // different + // end + // position + assertTrue(sq.addSequenceFeature( + new SequenceFeature("Cath", "desc", 4, 8, 1f, null))); // different + // score + assertTrue(sq.addSequenceFeature( + new SequenceFeature("Cath", "desc", 4, 8, Float.NaN, null))); // score + // NaN + assertTrue(sq.addSequenceFeature( + new SequenceFeature("Cath", "desc", 4, 8, 0f, "Metal"))); // different + // group assertEquals(8, sq.getFeatures().getAllFeatures().size()); } @@ -1184,8 +1249,9 @@ public class SequenceTest * matching ref with a mapping - map updated */ DBRefEntry dbref5 = new DBRefEntry("UniRef", "1", "p00341"); - Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] { - 1, 1 }, 3, 1)); + Mapping map = new Mapping( + new MapList(new int[] + { 1, 3 }, new int[] { 1, 1 }, 3, 1)); dbref5.setMap(map); sq.addDBRef(dbref5); assertEquals(4, sq.getDBRefs().size()); @@ -1225,7 +1291,7 @@ public class SequenceTest assertTrue(primaryDBRefs.isEmpty()); // empty dbrefs - sq.setDBRefs(null); + sq.setDBRefs(null); primaryDBRefs = sq.getPrimaryDBRefs(); assertTrue(primaryDBRefs.isEmpty()); @@ -1235,32 +1301,37 @@ public class SequenceTest // primary - uniprot with congruent map DBRefEntry upentry2 = new DBRefEntry("UNIPROT", "0", "Q04762"); - upentry2.setMap(new Mapping(null, new MapList(new int[] { 10, 22 }, - new int[] { 10, 22 }, 1, 1))); + upentry2.setMap( + new Mapping(null, new MapList(new int[] + { 10, 22 }, new int[] { 10, 22 }, 1, 1))); sq.addDBRef(upentry2); // primary - uniprot with map of enclosing sequence DBRefEntry upentry3 = new DBRefEntry("UNIPROT", "0", "Q04763"); - upentry3.setMap(new Mapping(null, new MapList(new int[] { 8, 24 }, - new int[] { 8, 24 }, 1, 1))); + upentry3.setMap( + new Mapping(null, new MapList(new int[] + { 8, 24 }, new int[] { 8, 24 }, 1, 1))); sq.addDBRef(upentry3); // not primary - uniprot with map of sub-sequence (5') DBRefEntry upentry4 = new DBRefEntry("UNIPROT", "0", "Q04764"); - upentry4.setMap(new Mapping(null, new MapList(new int[] { 10, 18 }, - new int[] { 10, 18 }, 1, 1))); + upentry4.setMap( + new Mapping(null, new MapList(new int[] + { 10, 18 }, new int[] { 10, 18 }, 1, 1))); sq.addDBRef(upentry4); // not primary - uniprot with map that overlaps 3' DBRefEntry upentry5 = new DBRefEntry("UNIPROT", "0", "Q04765"); - upentry5.setMap(new Mapping(null, new MapList(new int[] { 12, 22 }, - new int[] { 12, 22 }, 1, 1))); + upentry5.setMap( + new Mapping(null, new MapList(new int[] + { 12, 22 }, new int[] { 12, 22 }, 1, 1))); sq.addDBRef(upentry5); // not primary - uniprot with map to different coordinates frame DBRefEntry upentry6 = new DBRefEntry("UNIPROT", "0", "Q04766"); - upentry6.setMap(new Mapping(null, new MapList(new int[] { 12, 18 }, - new int[] { 112, 118 }, 1, 1))); + upentry6.setMap( + new Mapping(null, new MapList(new int[] + { 12, 18 }, new int[] { 112, 118 }, 1, 1))); sq.addDBRef(upentry6); // not primary - dbref to 'non-core' database @@ -1280,8 +1351,8 @@ public class SequenceTest // add corroborating PDB entry for primary DBref - // needs to have a file as well as matching ID // note PDB ID is not treated as case sensitive - sq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, new File("/blah") - .toString())); + sq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, + new File("/blah").toString())); // not valid DBRef - no file.. sq.addPDBId(new PDBEntry("1AAA", null, null, null)); @@ -1301,7 +1372,8 @@ public class SequenceTest @Test(groups = { "Functional" }) public void testGetPrimaryDBRefs_nucleotide() { - SequenceI sq = new Sequence("aseq", "TGATCACTCGACTAGCATCAGCATA", 10, 34); + SequenceI sq = new Sequence("aseq", "TGATCACTCGACTAGCATCAGCATA", 10, + 34); // primary - Ensembl DBRefEntry dbr1 = new DBRefEntry("ENSEMBL", "0", "ENSG1234"); @@ -1309,14 +1381,16 @@ public class SequenceTest // not primary - Ensembl 'transcript' mapping of sub-sequence DBRefEntry dbr2 = new DBRefEntry("ENSEMBL", "0", "ENST1234"); - dbr2.setMap(new Mapping(null, new MapList(new int[] { 15, 25 }, - new int[] { 1, 11 }, 1, 1))); + dbr2.setMap( + new Mapping(null, new MapList(new int[] + { 15, 25 }, new int[] { 1, 11 }, 1, 1))); sq.addDBRef(dbr2); // primary - EMBL with congruent map DBRefEntry dbr3 = new DBRefEntry("EMBL", "0", "J1234"); - dbr3.setMap(new Mapping(null, new MapList(new int[] { 10, 34 }, - new int[] { 10, 34 }, 1, 1))); + dbr3.setMap( + new Mapping(null, new MapList(new int[] + { 10, 34 }, new int[] { 10, 34 }, 1, 1))); sq.addDBRef(dbr3); // not primary - to non-core database @@ -1414,19 +1488,39 @@ public class SequenceTest seq.addPDBId(pdbe5); assertEquals(4, seq.getAllPDBEntries().size()); assertSame(pdbe5, seq.getAllPDBEntries().get(3)); + + // add with a fake pdbid + // (models don't have an embedded ID) + String realId = "RealIDQ"; + PDBEntry pdbe6 = new PDBEntry(realId, null, Type.PDB, "real/localpath"); + PDBEntry pdbe7 = new PDBEntry("RealID/real/localpath", "C", Type.MMCIF, + "real/localpath"); + pdbe7.setFakedPDBId(true); + seq.addPDBId(pdbe6); + assertEquals(5, seq.getAllPDBEntries().size()); + seq.addPDBId(pdbe7); + assertEquals(5, seq.getAllPDBEntries().size()); + assertFalse(pdbe6.fakedPDBId()); + assertSame(pdbe6, seq.getAllPDBEntries().get(4)); + assertEquals("C", pdbe6.getChainCode()); + assertEquals(realId, pdbe6.getId()); } @Test( - groups = { "Functional" }, - expectedExceptions = { IllegalArgumentException.class }) + groups = + { "Functional" }, + expectedExceptions = + { IllegalArgumentException.class }) public void testSetDatasetSequence_toSelf() { seq.setDatasetSequence(seq); } @Test( - groups = { "Functional" }, - expectedExceptions = { IllegalArgumentException.class }) + groups = + { "Functional" }, + expectedExceptions = + { IllegalArgumentException.class }) public void testSetDatasetSequence_cascading() { SequenceI seq2 = new Sequence("Seq2", "xyz"); @@ -1463,8 +1557,8 @@ public class SequenceTest "desc", 13, 14, 2f, null); sq.addSequenceFeature(sfContactFG); // add single position feature at [I] - SequenceFeature sfI = new SequenceFeature("Disulfide Bond", - "desc", 16, 16, null); + SequenceFeature sfI = new SequenceFeature("Disulfide Bond", "desc", 16, + 16, null); sq.addSequenceFeature(sfI); // no features in columns 1-2 (-A) @@ -1569,7 +1663,7 @@ public class SequenceTest Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--"); final int tok = (int) PA.getValue(sq, "changeCount"); assertEquals(1, tok); - + // find F pos given A - lastCol gets set in cursor assertEquals(13, sq.findPosition(10, new SequenceCursor(sq, 8, 2, tok))); @@ -1581,7 +1675,7 @@ public class SequenceTest sq.findPosition(2, new SequenceCursor(sq, 13, 10, tok))); assertEquals("test:Pos8:Col2:startCol2:endCol10:tok1", PA.getValue(sq, "cursor").toString()); - + // find C pos given C (neither startCol nor endCol is set) assertEquals(10, sq.findPosition(6, new SequenceCursor(sq, 10, 6, tok))); @@ -1685,7 +1779,7 @@ public class SequenceTest public void testFindPosition_withCursorAndEdits() { Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--"); - + // find F pos given A assertEquals(13, sq.findPosition(10, new SequenceCursor(sq, 8, 2, 0))); int token = (int) PA.getValue(sq, "changeCount"); // 0 @@ -1817,20 +1911,20 @@ public class SequenceTest */ SequenceI sq = new Sequence("test", "-ABC--DEF--", 1, 20); sq.createDatasetSequence(); - + assertTrue(sq.findFeatures(1, 9).isEmpty()); // should be no array bounds exception - JAL-2772 assertTrue(sq.findFeatures(1, 15).isEmpty()); - + // add feature on BCD SequenceFeature sfBCD = new SequenceFeature("Cath", "desc", 2, 4, 2f, null); sq.addSequenceFeature(sfBCD); - + // no features in columns 1-2 (-A) List found = sq.findFeatures(1, 2); assertTrue(found.isEmpty()); - + // columns 1-6 (-ABC--) includes BCD found = sq.findFeatures(1, 6); assertEquals(1, found.size()); @@ -2175,15 +2269,27 @@ public class SequenceTest assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator())); } - @Test(groups= {"Functional"}) - public void testTransferAnnotation() { - Sequence origSeq = new Sequence("MYSEQ","THISISASEQ"); - Sequence toSeq = new Sequence("MYSEQ","THISISASEQ"); + + @Test(groups = { "Functional" }) + public void testTransferAnnotation() + { + Sequence origSeq = new Sequence("MYSEQ", "THISISASEQ"); + Sequence toSeq = new Sequence("MYSEQ", "THISISASEQ"); origSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q12345", null, true)); toSeq.transferAnnotation(origSeq, null); - assertTrue(toSeq.getDBRefs().size()>0); - + assertTrue(toSeq.getDBRefs().size() == 1); + assertTrue(toSeq.getDBRefs().get(0).isCanonical()); - + + // check for promotion of non-canonical + // to canonical (e.g. fetch-db-refs on a jalview project pre 2.11.2) + toSeq.setDBRefs(null); + toSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q12345", null, false)); + toSeq.transferAnnotation(origSeq, null); + assertTrue(toSeq.getDBRefs().size() == 1); + + assertTrue("Promotion of non-canonical DBRefEntry failed", + toSeq.getDBRefs().get(0).isCanonical()); + } }