package jalview.datamodel.xdb.embl;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertSame;
+import jalview.analysis.SequenceIdMatcher;
+import jalview.datamodel.DBRefEntry;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
// not the whole sequence but enough for this test...
SequenceI dna = new Sequence("J03321", "GGATCCGTAAGTTAGACGAAATT");
List<SequenceI> peptides = new ArrayList<SequenceI>();
+ SequenceIdMatcher matcher = new SequenceIdMatcher(peptides);
EmblFile ef = EmblTestHelper.getEmblFile();
- EmblFeature feature = null;
- for (EmblFeature feat : ef.getEntries().get(0).getFeatures())
+
+ /*
+ * parse three CDS features, with two/one/no Uniprot cross-refs
+ */
+ EmblEntry testee = new EmblEntry();
+ for (EmblFeature feature : ef.getEntries().get(0).getFeatures())
{
- if ("CDS".equals(feat.getName()))
+ if ("CDS".equals(feature.getName()))
{
- feature = feat;
- break;
+ testee.parseCodingFeature(feature, "EMBL", dna, peptides, matcher);
}
}
- EmblEntry testee = new EmblEntry();
- testee.parseCodingFeature(feature, "EMBL", dna, peptides);
+ /*
+ * 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 / "
+ * EMBL product and synthesized EMBLCDSPROTEINaccession for the third
+ */
+ assertEquals(6, peptides.size());
+ assertEquals("CAA30420.1", peptides.get(0).getName());
+ assertEquals("MLCF", peptides.get(0).getSequenceAsString());
+ assertEquals("UNIPROT|B0BCM4", peptides.get(1).getName());
+ assertEquals("MLCF", peptides.get(1).getSequenceAsString());
+ assertEquals("UNIPROT|P0CE20", peptides.get(2).getName());
+ assertEquals("MLCF", peptides.get(2).getSequenceAsString());
+ assertEquals("CAA30421.1", peptides.get(3).getName());
+ 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(4, dbrefs.length);
+ DBRefEntry dbRefEntry = dbrefs[0];
+ assertEquals("UNIPROT", dbRefEntry.getSource());
+ assertEquals("B0BCM4", dbRefEntry.getAccessionId());
+ assertSame(peptides.get(1), dbRefEntry.getMap().getTo());
+ List<int[]> fromRanges = dbRefEntry.getMap().getMap().getFromRanges();
+ assertEquals(1, fromRanges.size());
+ assertEquals(57, fromRanges.get(0)[0]);
+ assertEquals(46, fromRanges.get(0)[1]);
+ List<int[]> toRanges = dbRefEntry.getMap().getMap().getToRanges();
+ assertEquals(1, toRanges.size());
+ assertEquals(1, toRanges.get(0)[0]);
+ assertEquals(4, toRanges.get(0)[1]);
+
+ dbRefEntry = dbrefs[1];
+ assertEquals("UNIPROT", dbRefEntry.getSource());
+ assertEquals("P0CE20", dbRefEntry.getAccessionId());
+ assertSame(peptides.get(2), dbRefEntry.getMap().getTo());
+ fromRanges = dbRefEntry.getMap().getMap().getFromRanges();
+ assertEquals(1, fromRanges.size());
+ assertEquals(57, fromRanges.get(0)[0]);
+ assertEquals(46, fromRanges.get(0)[1]);
+ toRanges = dbRefEntry.getMap().getMap().getToRanges();
+ assertEquals(1, toRanges.size());
+ assertEquals(1, toRanges.get(0)[0]);
+ assertEquals(4, toRanges.get(0)[1]);
+
+ dbRefEntry = dbrefs[2];
+ assertEquals("UNIPROT", dbRefEntry.getSource());
+ assertEquals("B0BCM3", dbRefEntry.getAccessionId());
+ assertSame(peptides.get(4), dbRefEntry.getMap().getTo());
+ fromRanges = dbRefEntry.getMap().getMap().getFromRanges();
+ assertEquals(1, fromRanges.size());
+ assertEquals(4, fromRanges.get(0)[0]);
+ assertEquals(15, fromRanges.get(0)[1]);
+ toRanges = dbRefEntry.getMap().getMap().getToRanges();
+ 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));
}
}