+ assertTrue(
+ dbrefs.contains(new DBRefEntry("INTERPRO", "0", "IPR005350")));
+
+ /*
+ * verify mappings to, and sequences for, UNIPROT proteins
+ */
+ int uniprotCount = 0;
+ List<int[]> ranges;
+ for (DBRefEntry dbref : dbrefs)
+ {
+ if ("UNIPROT".equals(dbref.getSource()))
+ {
+ uniprotCount++;
+ Mapping mapping = dbref.getMap();
+ assertNotNull(mapping);
+ MapList map = mapping.getMap();
+ String mappedToName = mapping.getTo().getName();
+ if ("UNIPROT|P0CE16".equals(mappedToName))
+ {
+ assertEquals((ranges = map.getFromRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 1579);
+ assertEquals(ranges.get(0)[1], 2934);
+ assertEquals((ranges = map.getToRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 1);
+ assertEquals(ranges.get(0)[1], 451);
+ // CDS /product carries over as protein product description
+ assertEquals(mapping.getTo().getDescription(),
+ "hypothetical protein");
+ }
+ else if ("UNIPROT|P0CE17".equals(mappedToName))
+ {
+ assertEquals((ranges = map.getFromRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 2928);
+ assertEquals(ranges.get(0)[1], 3992);
+ assertEquals((ranges = map.getToRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 1);
+ assertEquals(ranges.get(0)[1], 354);
+ }
+ else if ("UNIPROT|P0CE18".equals(mappedToName))
+ {
+ assertEquals((ranges = map.getFromRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 4054);
+ assertEquals(ranges.get(0)[1], 4848);
+ assertEquals((ranges = map.getToRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 1);
+ assertEquals(ranges.get(0)[1], 264);
+ }
+ else if ("UNIPROT|P0CE19".equals(mappedToName))
+ {
+ // join(7022..7502,1..437)
+ assertEquals((ranges = map.getFromRanges()).size(), 2);
+ assertEquals(ranges.get(0)[0], 7022);
+ assertEquals(ranges.get(0)[1], 7502);
+ assertEquals(ranges.get(1)[0], 1);
+ assertEquals(ranges.get(1)[1], 437);
+ assertEquals((ranges = map.getToRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 1);
+ assertEquals(ranges.get(0)[1], 305);
+ }
+ else if ("UNIPROT|P0CE20".equals(mappedToName))
+ {
+ // complement(488..1480)
+ assertEquals((ranges = map.getFromRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 1480);
+ assertEquals(ranges.get(0)[1], 488);
+ assertEquals((ranges = map.getToRanges()).size(), 1);
+ assertEquals(ranges.get(0)[0], 1);
+ assertEquals(ranges.get(0)[1], 330);
+ }
+ else if (!"UNIPROT|P0CE23".equals(mappedToName)
+ && !"UNIPROT|P10559".equals(mappedToName)
+ && !"UNIPROT|P10560".equals(mappedToName))
+ {
+ fail("Unexpected UNIPROT dbref to " + mappedToName);
+ }
+ }
+ }
+ assertEquals(uniprotCount, 8);
+ }
+
+ @Test(groups = "Functional")
+ public void testParse_codonStartNot1()
+ {
+ // TODO verify CDS-to-protein mapping for CDS with /codon_start=2
+ // example: https://www.ebi.ac.uk/ena/browser/api/embl/EU498516
+ }
+
+ /**
+ * Test for the case that the EMBL CDS has no UNIPROT xref. In this case
+ * Jalview should synthesize an xref to EMBLCDSPROTEIN in the hope this will
+ * allow Get Cross-References.
+ *
+ * @throws IOException
+ */
+ @Test(groups = "Functional")
+ public void testParse_noUniprotXref() throws IOException
+ {
+ // MN908947 cut down to 40BP, one CDS, length 5 peptide for test purposes
+ String data = "ID MN908947; SV 3; linear; genomic RNA; STD; VRL; 20 BP.\n"
+ + "DE Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1,\n"
+ + "FT CDS 3..17\n"
+ + "FT /protein_id=\"QHD43415.1\"\n"
+ + "FT /translation=\"MRKLD\n"
+ + "SQ Sequence 7496 BP; 2450 A; 1290 C; 1434 G; 2322 T; 0 other;\n"
+ + " ggatGcgtaa gttagacgaa attttgtctt tgcgcacaga 40\n";
+ FileParse fp = new FileParse(data, DataSourceType.PASTE);
+ EmblFlatFile parser = new EmblFlatFile(fp, "EmblTest");
+ parser.parse();
+ List<SequenceI> seqs = parser.getSeqs();
+ assertEquals(seqs.size(), 1);
+ SequenceI seq = seqs.get(0);
+ DBModList<DBRefEntry> dbrefs = seq.getDBRefs();
+
+ /*
+ * dna should have dbref to itself, and to inferred EMBLCDSPROTEIN:QHD43415.1
+ */
+ assertEquals(dbrefs.size(), 2);
+
+ // dbref to self
+ DBRefEntry dbref = dbrefs.get(0);
+ assertEquals(dbref.getSource(), "EMBLTEST");
+ assertEquals(dbref.getAccessionId(), "MN908947");
+ Mapping mapping = dbref.getMap();
+ assertNull(mapping.getTo());
+ MapList map = mapping.getMap();
+ assertEquals(map.getFromLowest(), 1);
+ assertEquals(map.getFromHighest(), 40);
+ assertEquals(map.getToLowest(), 1);
+ assertEquals(map.getToHighest(), 40);
+ assertEquals(map.getFromRatio(), 1);
+ assertEquals(map.getToRatio(), 1);
+
+ // dbref to inferred EMBLCDSPROTEIN:
+ dbref = dbrefs.get(1);
+ assertEquals(dbref.getSource(), "EMBLCDSPROTEIN");
+ assertEquals(dbref.getAccessionId(), "QHD43415.1");
+ mapping = dbref.getMap();
+ SequenceI mapTo = mapping.getTo();
+ assertEquals(mapTo.getName(), "QHD43415.1");
+ assertEquals(mapTo.getSequenceAsString(), "MRKLD");
+ map = mapping.getMap();
+ assertEquals(map.getFromLowest(), 3);
+ assertEquals(map.getFromHighest(), 17);
+ assertEquals(map.getToLowest(), 1);
+ assertEquals(map.getToHighest(), 5);
+ assertEquals(map.getFromRatio(), 3);
+ assertEquals(map.getToRatio(), 1);
+ }
+
+ @Test(groups = "Functional")
+ public void testAdjustForProteinLength()
+ {
+ int[] exons = new int[] { 11, 15, 21, 25, 31, 38 }; // 18 bp
+
+ // exact length match:
+ assertSame(exons, EmblFlatFile.adjustForProteinLength(6, exons));
+
+ // match if we assume exons include stop codon not in protein:
+ assertSame(exons, EmblFlatFile.adjustForProteinLength(5, exons));
+
+ // truncate last exon by 6bp
+ int[] truncated = EmblFlatFile.adjustForProteinLength(4, exons);
+ assertEquals("[11, 15, 21, 25, 31, 32]", Arrays.toString(truncated));
+
+ // remove last exon and truncate preceding by 1bp (so 3bp in total)
+ truncated = EmblFlatFile.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 = EmblFlatFile.adjustForProteinLength(4, exons);
+ assertEquals("[11, 15, 21, 27]", Arrays.toString(truncated));