JAL-2353 primary ref candidates that should be promoted should preserve original...
[jalview.git] / test / jalview / ws / dbsources / UniprotTest.java
index e835724..176cddc 100644 (file)
  */
 package jalview.ws.dbsources;
 
+import static org.testng.Assert.assertFalse;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertTrue;
 
-import jalview.datamodel.SequenceI;
-import jalview.gui.JvOptionPane;
-import jalview.xml.binding.uniprot.DbReferenceType;
-import jalview.xml.binding.uniprot.Entry;
-import jalview.xml.binding.uniprot.FeatureType;
-import jalview.xml.binding.uniprot.LocationType;
-import jalview.xml.binding.uniprot.PositionType;
-
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
@@ -43,6 +36,17 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.SequenceI;
+import jalview.gui.JvOptionPane;
+import jalview.util.DBRefUtils;
+import jalview.xml.binding.uniprot.DbReferenceType;
+import jalview.xml.binding.uniprot.Entry;
+import jalview.xml.binding.uniprot.FeatureType;
+import jalview.xml.binding.uniprot.LocationType;
+import jalview.xml.binding.uniprot.PositionType;
+
 public class UniprotTest
 {
 
@@ -58,8 +62,7 @@ public class UniprotTest
           + "<uniprot xmlns=\"http://uniprot.org/uniprot\">"
           + "<entry dataset=\"TrEMBL\" created=\"2008-01-15\" modified=\"2015-03-04\" version=\"38\">"
           + "<accession>A9CKP4</accession>"
-          + "<accession>A9CKP5</accession>"
-          + "<name>A9CKP4_AGRT5</name>"
+          + "<accession>A9CKP5</accession>" + "<name>A9CKP4_AGRT5</name>"
           + "<name>A9CKP4_AGRT6</name>"
           + "<protein><recommendedName><fullName>Mitogen-activated protein kinase 13</fullName></recommendedName></protein>"
           + "<dbReference type=\"PDB\" id=\"2FSQ\"><property type=\"method\" value=\"X-ray\"/><property type=\"resolution\" value=\"1.40\"/></dbReference>"
@@ -153,31 +156,27 @@ public class UniprotTest
 
     sf = features.get(6);
     assertEquals("sequence variant", sf.getType());
-    assertEquals("Foo",
-            sf.getDescription());
+    assertEquals("Foo", sf.getDescription());
     assertEquals(42,
             sf.getLocation().getPosition().getPosition().intValue());
     assertNull(sf.getLocation().getBegin());
     assertNull(sf.getLocation().getEnd());
-    Assert.assertEquals(Uniprot.getDescription(sf),
-            "<html>p.Met42Leu" + "<br/>&nbsp;&nbsp;"
-                    + "p.Met42LeuMetVal Foo</html>");
+    Assert.assertEquals(Uniprot.getDescription(sf), "<html>p.Met42Leu"
+            + "<br/>&nbsp;&nbsp;" + "p.Met42LeuMetVal Foo</html>");
 
     sf = features.get(7);
     assertNull(sf.getLocation().getPosition());
     assertEquals(42, sf.getLocation().getBegin().getPosition().intValue());
     assertEquals(43, sf.getLocation().getEnd().getPosition().intValue());
-    Assert.assertEquals(Uniprot.getDescription(sf),
-            "<html>p.MetLeu42LeuLeu" + "<br/>&nbsp;&nbsp;"
-                    + "p.MetLeu42LeuMetVal Foo</html>");
+    Assert.assertEquals(Uniprot.getDescription(sf), "<html>p.MetLeu42LeuLeu"
+            + "<br/>&nbsp;&nbsp;" + "p.MetLeu42LeuMetVal Foo</html>");
 
     sf = features.get(8);
     assertNull(sf.getLocation().getPosition());
     assertEquals(42, sf.getLocation().getBegin().getPosition().intValue());
     assertEquals(45, sf.getLocation().getEnd().getPosition().intValue());
-    Assert.assertEquals(Uniprot.getDescription(sf),
-            "<html>p.MLML42LeuLeu" + "<br/>&nbsp;&nbsp;"
-                    + "p.MLML42LMVK Foo Too</html>");
+    Assert.assertEquals(Uniprot.getDescription(sf), "<html>p.MLML42LeuLeu"
+            + "<br/>&nbsp;&nbsp;" + "p.MLML42LMVK Foo Too</html>");
 
     /*
      * Check cross-references
@@ -211,12 +210,36 @@ public class UniprotTest
   public void testGetUniprotSequence() throws UnsupportedEncodingException
   {
     InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
-    Entry entry = new Uniprot().getUniprotEntries(
-            is).get(0);
+    Entry entry = new Uniprot().getUniprotEntries(is).get(0);
     SequenceI seq = new Uniprot().uniprotEntryToSequence(entry);
     assertNotNull(seq);
-    assertEquals(6, seq.getDBRefs().length); // 2*Uniprot, PDB, PDBsum, 2*EMBL
-
+    assertEquals(6, seq.getDBRefs().size()); // 2*Uniprot, PDB, PDBsum, 2*EMBL
+    assertEquals(seq.getSequenceAsString(),
+            seq.createDatasetSequence().getSequenceAsString());
+    assertEquals(2, seq.getPrimaryDBRefs().size());
+    List<DBRefEntry> res = DBRefUtils.searchRefs(seq.getPrimaryDBRefs(),
+            "A9CKP4");
+    assertEquals(1, res.size());
+    assertTrue(res.get(0).isCanonical());
+    res = DBRefUtils.searchRefsForSource(seq.getDBRefs(),
+            DBRefSource.UNIPROT);
+    assertEquals(2, res.size());
+    /*
+     * NB this test fragile - relies on ordering being preserved
+     */
+    assertTrue(res.get(0).isCanonical());
+    assertFalse(res.get(1).isCanonical());
+
+    // check version is preserved for EMBLCDS
+    res = DBRefUtils.searchRefs(seq.getDBRefs(), "AAK85932");
+    assertEquals(1, res.size());
+    // Ideally we would expect AAK85932.1 -> AAK85932
+    // assertTrue("1".equals(res.get(0).getVersion()));
+    // but it also passes through DBrefUtils.ensurePrimaries which adds
+    // (promoted) to the version string
+    // FIXME: Jim needs to specify what (promoted) means !! - or perhaps we just
+    // ignore it !
+    assertEquals("1 (promoted)", (res.get(0).getVersion()));
   }
 
   /**
@@ -234,8 +257,7 @@ public class UniprotTest
      * name formatted with Uniprot Entry name
      */
     String expectedName = "A9CKP4_AGRT5|A9CKP4_AGRT6";
-    assertEquals(expectedName,
-            Uniprot.getUniprotEntryId(entry));
+    assertEquals(expectedName, Uniprot.getUniprotEntryId(entry));
   }
 
   /**