Merge commit 'alpha/update_2_12_for_2_11_2_series_merge^2' into HEAD
[jalview.git] / test / jalview / datamodel / SequenceTest.java
index e7cdc6a..c65ba28 100644 (file)
@@ -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;
@@ -109,6 +111,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()
   {
@@ -174,6 +193,35 @@ 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<AlignmentAnnotation> 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
@@ -773,7 +821,7 @@ public class SequenceTest
     } 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());
@@ -1421,6 +1469,21 @@ 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(
@@ -2182,4 +2245,25 @@ 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");
+    origSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q12345", null, true));
+    toSeq.transferAnnotation(origSeq, null);
+    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());
+    
+    
+  }
 }