Merge branch 'develop' into merge/develop_bug/JAL-2154projectMappings
[jalview.git] / test / jalview / datamodel / SequenceTest.java
index 1fed98b..3ad309e 100644 (file)
@@ -110,8 +110,7 @@ public class SequenceTest
   {
     AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
             1f);
-    AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
-            1f);
+    addAnnotation("label2", "desc2", "calcId2", 1f);
     AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3",
             1f);
     AlignmentAnnotation[] anns = seq.getAnnotation("label1");
@@ -133,16 +132,15 @@ public class SequenceTest
   @Test(groups = { "Functional" })
   public void testGetAlignmentAnnotations_forCalcIdAndLabel()
   {
-    AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
-            1f);
+    addAnnotation("label1", "desc1", "calcId1", 1f);
     AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
             1f);
-    AlignmentAnnotation ann3 = addAnnotation("label2", "desc3", "calcId3",
-            1f);
+    addAnnotation("label2", "desc3", "calcId3", 1f);
     AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
             1f);
-    AlignmentAnnotation ann5 = addAnnotation("label5", "desc3", null, 1f);
-    AlignmentAnnotation ann6 = addAnnotation(null, "desc3", "calcId3", 1f);
+    addAnnotation("label5", "desc3", null, 1f);
+    addAnnotation(null, "desc3", "calcId3", 1f);
+
     List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
             "label2");
     assertEquals(2, anns.size());
@@ -454,8 +452,10 @@ public class SequenceTest
     
     DBRefEntry pdb1pdb = new DBRefEntry("PDB", "version1", "1PDB");
     DBRefEntry pdb2pdb = new DBRefEntry("PDB", "version1", "2PDB");
-    List<DBRefEntry> primRefs = Arrays.asList(new DBRefEntry[] { pdb1pdb,
-        pdb2pdb });
+
+    //FIXME pdb2pdb's matching PDBEntry has Type.MMCIF - but 2.10 only has PDBEntry with type==PDB to indicate ID is a real PDB entry
+    
+    List<DBRefEntry> primRefs = Arrays.asList(new DBRefEntry[] { pdb1pdb });
 
     sq.getDatasetSequence().addDBRef(pdb1pdb);
     sq.getDatasetSequence().addDBRef(pdb2pdb);
@@ -499,7 +499,7 @@ public class SequenceTest
             new AlignmentAnnotation("Test annot", "Test annot description",
                     annots));
     Assert.assertEquals(sq.getDescription(), "Test sequence description..");
-    Assert.assertEquals(sq.getDBRefs().length, 4);
+    Assert.assertEquals(sq.getDBRefs().length, 5);
     Assert.assertEquals(sq.getAllPDBEntries().size(), 4);
     Assert.assertNotNull(sq.getAnnotation());
     Assert.assertEquals(sq.getAnnotation()[0].annotations.length, 2);
@@ -512,7 +512,7 @@ public class SequenceTest
 
     Assert.assertEquals(derived.getDescription(),
             "Test sequence description..");
-    Assert.assertEquals(derived.getDBRefs().length, 4);
+    Assert.assertEquals(derived.getDBRefs().length, 4); // come from dataset
     Assert.assertEquals(derived.getAllPDBEntries().size(), 4);
     Assert.assertNotNull(derived.getAnnotation());
     Assert.assertEquals(derived.getAnnotation()[0].annotations.length, 2);
@@ -530,6 +530,17 @@ public class SequenceTest
     assertNotNull(sq.getSequenceFeatures());
     assertArrayEquals(sq.getSequenceFeatures(),
             derived.getSequenceFeatures());
+    
+    /*
+     *  verify we have primary db refs *just* for PDB IDs with associated
+     *  PDBEntry objects
+     */
+
+    assertEquals(primRefs, sq.getPrimaryDBRefs());
+    assertEquals(primRefs, sq.getDatasetSequence().getPrimaryDBRefs());
+
+    assertEquals(sq.getPrimaryDBRefs(), derived.getPrimaryDBRefs());
+
   }
 
   /**
@@ -754,4 +765,30 @@ public class SequenceTest
     assertSame(dbref3, sq.getDBRefs()[2]);
     assertEquals("3", dbref2.getVersion());
   }
+
+  @Test(groups = { "Functional" })
+  public void testGetPrimaryDBRefs()
+  {
+    /*
+     * test PDB relationships for for getPrimaryDBRefs
+     */
+    SequenceI seq = new Sequence("aseq", "ASDF");
+    DBRefEntry upentry = new DBRefEntry("UNIPROT", "0", "1qip");
+    // primary - uniprot
+    seq.addDBRef(upentry);
+    // primary - type is PDB
+    DBRefEntry pdbentry = new DBRefEntry("PDB", "0", "1qip");
+    seq.addDBRef(pdbentry);
+    // not primary - type of PDBEntry is not PDB
+    seq.addDBRef(new DBRefEntry("PDB", "0", "1AAA"));
+    // not primary - no PDBEntry
+    seq.addDBRef(new DBRefEntry("PDB", "0", "1DDD"));
+    seq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, null));
+    seq.addPDBId(new PDBEntry("1AAA", null, null, null));
+    assertTrue("Couldn't find simple primary reference (UNIPROT)", seq
+            .getPrimaryDBRefs().contains(upentry));
+    assertTrue("Couldn't find expected PDB primary reference", seq
+            .getPrimaryDBRefs().contains(pdbentry));
+    assertEquals(2, seq.getPrimaryDBRefs().size());
+  }
 }