JAL-2110 fixes and tests for synthesized EMBLCDSPROTEIN dbrefs
[jalview.git] / test / jalview / datamodel / xdb / embl / EmblEntryTest.java
index 3de5e3f..d987e53 100644 (file)
@@ -42,8 +42,7 @@ public class EmblEntryTest
     EmblFile ef = EmblTestHelper.getEmblFile();
 
     /*
-     * parse two CDS features, one with two Uniprot cross-refs,
-     * the other with one
+     * parse three CDS features, with two/one/no Uniprot cross-refs
      */
     EmblEntry testee = new EmblEntry();
     for (EmblFeature feature : ef.getEntries().get(0).getFeatures())
@@ -57,9 +56,10 @@ public class EmblEntryTest
     /*
      * peptides should now have five entries:
      * EMBL product and two Uniprot accessions for the first CDS / translation
-     * EMBL product and one Uniprot accession for the second CDS / translation
+     * EMBL product and one Uniprot accession for the second CDS / "
+     * EMBL product and synthesized EMBLCDSPROTEINaccession for the third
      */
-    assertEquals(5, peptides.size());
+    assertEquals(6, peptides.size());
     assertEquals("CAA30420.1", peptides.get(0).getName());
     assertEquals("MLCF", peptides.get(0).getSequenceAsString());
     assertEquals("UNIPROT|B0BCM4", peptides.get(1).getName());
@@ -70,12 +70,14 @@ public class EmblEntryTest
     assertEquals("MSSS", peptides.get(3).getSequenceAsString());
     assertEquals("UNIPROT|B0BCM3", peptides.get(4).getName());
     assertEquals("MSSS", peptides.get(4).getSequenceAsString());
+    assertEquals("CAA12345.6", peptides.get(5).getName());
+    assertEquals("MSS", peptides.get(5).getSequenceAsString());
 
     /*
      * verify dna sequence has dbrefs with mappings to the peptide 'products'
      */
     DBRefEntry[] dbrefs = dna.getDBRefs();
-    assertEquals(3, dbrefs.length);
+    assertEquals(4, dbrefs.length);
     DBRefEntry dbRefEntry = dbrefs[0];
     assertEquals("UNIPROT", dbRefEntry.getSource());
     assertEquals("B0BCM4", dbRefEntry.getAccessionId());
@@ -114,5 +116,51 @@ public class EmblEntryTest
     assertEquals(1, toRanges.size());
     assertEquals(1, toRanges.get(0)[0]);
     assertEquals(4, toRanges.get(0)[1]);
+
+    dbRefEntry = dbrefs[3];
+    assertEquals("EMBLCDSPROTEIN", dbRefEntry.getSource());
+    assertEquals("CAA12345.6", dbRefEntry.getAccessionId());
+    assertSame(peptides.get(5), dbRefEntry.getMap().getTo());
+    fromRanges = dbRefEntry.getMap().getMap().getFromRanges();
+    assertEquals(2, fromRanges.size());
+    assertEquals(4, fromRanges.get(0)[0]);
+    assertEquals(6, fromRanges.get(0)[1]);
+    assertEquals(10, fromRanges.get(1)[0]);
+    assertEquals(15, fromRanges.get(1)[1]);
+    toRanges = dbRefEntry.getMap().getMap().getToRanges();
+    assertEquals(1, toRanges.size());
+    assertEquals(1, toRanges.get(0)[0]);
+    assertEquals(3, toRanges.get(0)[1]);
+  }
+
+  @Test(groups = "Functional")
+  public void testAdjustForProteinLength()
+  {
+    int[] exons = new int[] { 11, 15, 21, 25, 31, 38 }; // 18 bp
+
+    // exact length match:
+    assertSame(exons, EmblEntry.adjustForProteinLength(6, exons));
+
+    // match if we assume exons include stop codon not in protein:
+    assertSame(exons, EmblEntry.adjustForProteinLength(5, exons));
+
+    // truncate last exon by 6bp
+    int[] truncated = EmblEntry.adjustForProteinLength(4, exons);
+    assertEquals("[11, 15, 21, 25, 31, 32]",
+            Arrays.toString(truncated));
+
+    // remove last exon and truncate preceding by 1bp
+    truncated = EmblEntry.adjustForProteinLength(3, exons);
+    assertEquals("[11, 15, 21, 24]", Arrays.toString(truncated));
+
+    // exact removal of exon case:
+    exons = new int[] { 11, 15, 21, 27, 33, 38 }; // 18 bp
+    truncated = EmblEntry.adjustForProteinLength(4, exons);
+    assertEquals("[11, 15, 21, 27]", Arrays.toString(truncated));
+
+    // what if exons are too short for protein?
+    truncated = EmblEntry.adjustForProteinLength(7, exons);
+    assertSame(exons, truncated);
+    // assertEquals("[11, 15, 21, 27]", Arrays.toString(truncated));
   }
 }