JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / test / jalview / ws / dbsources / UniprotTest.java
index ec637fe..2df8be6 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
- * Copyright (C) 2015 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
 package jalview.ws.dbsources;
 
 import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertNull;
 
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
 import jalview.datamodel.UniprotEntry;
 
 import java.io.Reader;
@@ -46,6 +49,7 @@ public class UniprotTest
           + "<protein><recommendedName><fullName>Mitogen-activated protein kinase 13</fullName><fullName>Henry</fullName></recommendedName></protein>"
           + "<dbReference type=\"PDB\" id=\"2FSQ\"><property type=\"method\" value=\"X-ray\"/><property type=\"resolution\" value=\"1.40\"/></dbReference>"
           + "<dbReference type=\"PDBsum\" id=\"2FSR\"/>"
+          + "<dbReference type=\"EMBL\" id=\"AE007869\"><property type=\"protein sequence ID\" value=\"AAK85932.1\"/><property type=\"molecule type\" value=\"Genomic_DNA\"/></dbReference>"
           + "<feature type=\"signal peptide\" evidence=\"7\"><location><begin position=\"1\"/><end position=\"18\"/></location></feature>"
           + "<feature type=\"propeptide\" description=\"Activation peptide\" id=\"PRO_0000027399\" evidence=\"9 16 17 18\"><location><begin position=\"19\"/><end position=\"20\"/></location></feature>"
           + "<feature type=\"chain\" description=\"Granzyme B\" id=\"PRO_0000027400\"><location><begin position=\"21\"/><end position=\"247\"/></location></feature>"
@@ -89,19 +93,19 @@ public class UniprotTest
     assertEquals("signal peptide", sf.getType());
     assertNull(sf.getDescription());
     assertNull(sf.getStatus());
-    assertEquals(1, sf.getPosition()); // wrong - Castor bug??
+    assertEquals(1, sf.getPosition());
     assertEquals(1, sf.getBegin());
     assertEquals(18, sf.getEnd());
     sf = features.get(1);
     assertEquals("propeptide", sf.getType());
     assertEquals("Activation peptide", sf.getDescription());
-    assertEquals(19, sf.getPosition()); // wrong - Castor bug??
+    assertEquals(19, sf.getPosition());
     assertEquals(19, sf.getBegin());
     assertEquals(20, sf.getEnd());
     sf = features.get(2);
     assertEquals("chain", sf.getType());
     assertEquals("Granzyme B", sf.getDescription());
-    assertEquals(21, sf.getPosition()); // wrong - Castor bug??
+    assertEquals(21, sf.getPosition());
     assertEquals(21, sf.getBegin());
     assertEquals(247, sf.getEnd());
 
@@ -109,35 +113,70 @@ public class UniprotTest
      * Check cross-references
      */
     Vector<PDBEntry> xrefs = entry.getDbReference();
-    assertEquals(2, xrefs.size());
+    assertEquals(3, xrefs.size());
 
     PDBEntry xref = xrefs.get(0);
     assertEquals("2FSQ", xref.getId());
     assertEquals("PDB", xref.getType());
-    assertEquals(2, xref.getProperty().size());
-    assertEquals("X-ray", xref.getProperty().get("method"));
-    assertEquals("1.40", xref.getProperty().get("resolution"));
+    assertEquals("X-ray", xref.getProperty("method"));
+    assertEquals("1.40", xref.getProperty("resolution"));
 
     xref = xrefs.get(1);
     assertEquals("2FSR", xref.getId());
     assertEquals("PDBsum", xref.getType());
-    assertNull(xref.getProperty());
+    assertFalse(xref.getProperties().hasMoreElements());
+
+    xref = xrefs.get(2);
+    assertEquals("AE007869", xref.getId());
+    assertEquals("EMBL", xref.getType());
+    assertEquals("AAK85932.1",
+ xref.getProperty("protein sequence ID"));
+    assertEquals("Genomic_DNA",
+ xref.getProperty("molecule type"));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetUniprotSequence()
+  {
+    UniprotEntry entry = new Uniprot().getUniprotEntries(
+            new StringReader(UNIPROT_XML)).get(0);
+    SequenceI seq = new Uniprot().uniprotEntryToSequenceI(entry);
+    assertNotNull(seq);
+    assertEquals(6, seq.getDBRefs().length); // 2*Uniprot, PDB, PDBsum, 2*EMBL
+
   }
 
   /**
-   * Test the method that formats the sequence name in Fasta style
+   * Test the method that formats the sequence id
    */
   @Test(groups = { "Functional" })
-  public void testConstructSequenceFastaHeader()
+  public void testGetUniprotEntryId()
   {
-    Uniprot u = new Uniprot();
-    Reader reader = new StringReader(UNIPROT_XML);
-    Vector<UniprotEntry> entries = u.getUniprotEntries(reader);
-    UniprotEntry entry = entries.get(0);
+    UniprotEntry entry = new Uniprot().getUniprotEntries(
+            new StringReader(UNIPROT_XML)).get(0);
 
-    // source + accession ids + names + protein names
-    String expectedName = ">UniProt/Swiss-Prot|A9CKP4|A9CKP5|A9CKP4_AGRT5|A9CKP4_AGRT6 Mitogen-activated protein kinase 13 Henry";
-    assertEquals(expectedName, Uniprot.constructSequenceFastaHeader(entry)
-            .toString());
+    /*
+     * name formatted as source | accession ids | names
+     * source database converted to Jalview canonical name
+     */
+    String expectedName = "UNIPROT|A9CKP4|A9CKP5|A9CKP4_AGRT5|A9CKP4_AGRT6";
+    assertEquals(expectedName, Uniprot.getUniprotEntryId(entry));
+  }
+
+  /**
+   * Test the method that formats the sequence description
+   */
+  @Test(groups = { "Functional" })
+  public void testGetUniprotEntryDescription()
+  {
+    UniprotEntry entry = new Uniprot().getUniprotEntries(
+            new StringReader(UNIPROT_XML)).get(0);
+
+    /*
+     * recommended names concatenated with space separator
+     */
+    String expectedDescription = "Mitogen-activated protein kinase 13 Henry";
+    assertEquals(expectedDescription,
+            Uniprot.getUniprotEntryDescription(entry));
   }
 }