+ assertNull(sq.sequenceFeatures);
+ assertNull(derived.sequenceFeatures);
+ // derived sequence should access dataset sequence features
+ assertNotNull(sq.getSequenceFeatures());
+ assertArrayEquals(sq.getSequenceFeatures(),
+ derived.getSequenceFeatures());
+
+ /*
+ * verify we have primary db refs *just* for PDB IDs with associated
+ * PDBEntry objects
+ */
+
+ assertEquals(primRefs, sq.getPrimaryDBRefs());
+ assertEquals(primRefs, sq.getDatasetSequence().getPrimaryDBRefs());
+
+ assertEquals(sq.getPrimaryDBRefs(), derived.getPrimaryDBRefs());
+
+ }
+
+ /**
+ * Test for deriveSequence applied to an ungapped sequence with no dataset
+ */
+ @Test(groups = { "Functional" })
+ public void testDeriveSequence_noDatasetUngapped()
+ {
+ SequenceI sq = new Sequence("Seq1", "ABCDEF");
+ assertEquals(1, sq.getStart());
+ assertEquals(6, sq.getEnd());
+ SequenceI derived = sq.deriveSequence();
+ assertEquals("ABCDEF", derived.getSequenceAsString());
+ assertEquals("ABCDEF", derived.getDatasetSequence()
+ .getSequenceAsString());
+ }
+
+ /**
+ * Test for deriveSequence applied to a gapped sequence with no dataset
+ */
+ @Test(groups = { "Functional" })
+ public void testDeriveSequence_noDatasetGapped()
+ {
+ SequenceI sq = new Sequence("Seq1", "AB-C.D EF");
+ assertEquals(1, sq.getStart());
+ assertEquals(6, sq.getEnd());
+ assertNull(sq.getDatasetSequence());
+ SequenceI derived = sq.deriveSequence();
+ assertEquals("AB-C.D EF", derived.getSequenceAsString());
+ assertEquals("ABCDEF", derived.getDatasetSequence()
+ .getSequenceAsString());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCopyConstructor_noDataset()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
+ seq1.setDescription("description");
+ seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
+ 1.3d));
+ seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
+ 12.4f, "group"));
+ seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
+ seq1.addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345"));
+
+ SequenceI copy = new Sequence(seq1);
+
+ assertNull(copy.getDatasetSequence());
+
+ verifyCopiedSequence(seq1, copy);
+
+ // copy has a copy of the DBRefEntry
+ // this is murky - DBrefs are only copied for dataset sequences
+ // where the test for 'dataset sequence' is 'dataset is null'
+ // but that doesn't distinguish it from an aligned sequence
+ // which has not yet generated a dataset sequence
+ // NB getDBRef looks inside dataset sequence if not null
+ DBRefEntry[] dbrefs = copy.getDBRefs();
+ assertEquals(1, dbrefs.length);
+ assertFalse(dbrefs[0] == seq1.getDBRefs()[0]);
+ assertTrue(dbrefs[0].equals(seq1.getDBRefs()[0]));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCopyConstructor_withDataset()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
+ seq1.createDatasetSequence();
+ seq1.setDescription("description");
+ seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
+ 1.3d));
+ // JAL-2046 - what is the contract for using a derived sequence's
+ // addSequenceFeature ?
+ seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
+ 12.4f, "group"));
+ seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
+ // here we add DBRef to the dataset sequence:
+ seq1.getDatasetSequence().addDBRef(
+ new DBRefEntry("EMBL", "1.2", "AZ12345"));
+
+ SequenceI copy = new Sequence(seq1);
+
+ assertNotNull(copy.getDatasetSequence());
+ assertSame(copy.getDatasetSequence(), seq1.getDatasetSequence());
+
+ verifyCopiedSequence(seq1, copy);
+
+ // getDBRef looks inside dataset sequence and this is shared,
+ // so holds the same dbref objects
+ DBRefEntry[] dbrefs = copy.getDBRefs();
+ assertEquals(1, dbrefs.length);
+ assertSame(dbrefs[0], seq1.getDBRefs()[0]);
+ }
+
+ /**
+ * Helper to make assertions about a copied sequence
+ *
+ * @param seq1
+ * @param copy
+ */
+ protected void verifyCopiedSequence(SequenceI seq1, SequenceI copy)
+ {
+ // verify basic properties:
+ assertEquals(copy.getName(), seq1.getName());
+ assertEquals(copy.getDescription(), seq1.getDescription());
+ assertEquals(copy.getStart(), seq1.getStart());
+ assertEquals(copy.getEnd(), seq1.getEnd());
+ assertEquals(copy.getSequenceAsString(), seq1.getSequenceAsString());
+
+ // copy has a copy of the annotation:
+ AlignmentAnnotation[] anns = copy.getAnnotation();
+ assertEquals(1, anns.length);
+ assertFalse(anns[0] == seq1.getAnnotation()[0]);
+ assertEquals(anns[0].label, seq1.getAnnotation()[0].label);
+ assertEquals(anns[0].description, seq1.getAnnotation()[0].description);
+ assertEquals(anns[0].score, seq1.getAnnotation()[0].score);
+
+ // copy has a copy of the sequence feature:
+ SequenceFeature[] sfs = copy.getSequenceFeatures();
+ assertEquals(1, sfs.length);
+ if (seq1.getDatasetSequence() != null
+ && copy.getDatasetSequence() == seq1.getDatasetSequence())
+ {
+ assertTrue(sfs[0] == seq1.getSequenceFeatures()[0]);
+ }
+ else
+ {
+ assertFalse(sfs[0] == seq1.getSequenceFeatures()[0]);
+ }
+ assertTrue(sfs[0].equals(seq1.getSequenceFeatures()[0]));
+
+ // copy has a copy of the PDB entry
+ Vector<PDBEntry> pdbs = copy.getAllPDBEntries();
+ assertEquals(1, pdbs.size());
+ assertFalse(pdbs.get(0) == seq1.getAllPDBEntries().get(0));
+ assertTrue(pdbs.get(0).equals(seq1.getAllPDBEntries().get(0)));
+ }
+
+ @Test(groups = "Functional")
+ public void testGetCharAt()
+ {
+ SequenceI sq = new Sequence("", "abcde");
+ assertEquals('a', sq.getCharAt(0));
+ assertEquals('e', sq.getCharAt(4));
+ assertEquals(' ', sq.getCharAt(5));
+ assertEquals(' ', sq.getCharAt(-1));
+ }
+
+ /**
+ * Tests for adding (or updating) dbrefs
+ *
+ * @see DBRefEntry#updateFrom(DBRefEntry)
+ */
+ @Test(groups = { "Functional" })
+ public void testAddDBRef()
+ {
+ SequenceI sq = new Sequence("", "abcde");
+ assertNull(sq.getDBRefs());
+ DBRefEntry dbref = new DBRefEntry("Uniprot", "1", "P00340");
+ sq.addDBRef(dbref);
+ assertEquals(1, sq.getDBRefs().length);
+ assertSame(dbref, sq.getDBRefs()[0]);
+
+ /*
+ * change of version - new entry
+ */
+ DBRefEntry dbref2 = new DBRefEntry("Uniprot", "2", "P00340");
+ sq.addDBRef(dbref2);
+ assertEquals(2, sq.getDBRefs().length);
+ assertSame(dbref, sq.getDBRefs()[0]);
+ assertSame(dbref2, sq.getDBRefs()[1]);
+
+ /*
+ * matches existing entry - not added
+ */
+ sq.addDBRef(new DBRefEntry("UNIPROT", "1", "p00340"));
+ assertEquals(2, sq.getDBRefs().length);
+
+ /*
+ * different source = new entry
+ */
+ DBRefEntry dbref3 = new DBRefEntry("UniRef", "1", "p00340");
+ sq.addDBRef(dbref3);
+ assertEquals(3, sq.getDBRefs().length);
+ assertSame(dbref3, sq.getDBRefs()[2]);
+
+ /*
+ * different ref = new entry
+ */
+ DBRefEntry dbref4 = new DBRefEntry("UniRef", "1", "p00341");
+ sq.addDBRef(dbref4);
+ assertEquals(4, sq.getDBRefs().length);
+ assertSame(dbref4, sq.getDBRefs()[3]);
+
+ /*
+ * matching ref with a mapping - map updated
+ */
+ DBRefEntry dbref5 = new DBRefEntry("UniRef", "1", "p00341");
+ Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
+ 1, 1 }, 3, 1));
+ dbref5.setMap(map);
+ sq.addDBRef(dbref5);
+ assertEquals(4, sq.getDBRefs().length);
+ assertSame(dbref4, sq.getDBRefs()[3]);
+ assertSame(map, dbref4.getMap());
+
+ /*
+ * 'real' version replaces "0" version
+ */
+ dbref2.setVersion("0");
+ DBRefEntry dbref6 = new DBRefEntry(dbref2.getSource(), "3",
+ dbref2.getAccessionId());
+ sq.addDBRef(dbref6);
+ assertEquals(4, sq.getDBRefs().length);
+ assertSame(dbref2, sq.getDBRefs()[1]);
+ assertEquals("3", dbref2.getVersion());
+
+ /*
+ * 'real' version replaces "source:0" version
+ */
+ dbref3.setVersion("Uniprot:0");
+ DBRefEntry dbref7 = new DBRefEntry(dbref3.getSource(), "3",
+ dbref3.getAccessionId());
+ sq.addDBRef(dbref7);
+ assertEquals(4, sq.getDBRefs().length);
+ assertSame(dbref3, sq.getDBRefs()[2]);
+ assertEquals("3", dbref2.getVersion());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetPrimaryDBRefs_peptide()
+ {
+ SequenceI sq = new Sequence("aseq", "ASDFKYLMQPRST", 10, 22);
+
+ // no dbrefs
+ List<DBRefEntry> primaryDBRefs = sq.getPrimaryDBRefs();
+ assertTrue(primaryDBRefs.isEmpty());
+
+ // empty dbrefs
+ sq.setDBRefs(new DBRefEntry[] {});
+ primaryDBRefs = sq.getPrimaryDBRefs();
+ assertTrue(primaryDBRefs.isEmpty());
+
+ // primary - uniprot
+ DBRefEntry upentry1 = new DBRefEntry("UNIPROT", "0", "Q04760");
+ sq.addDBRef(upentry1);
+
+ // primary - uniprot with congruent map
+ DBRefEntry upentry2 = new DBRefEntry("UNIPROT", "0", "Q04762");
+ upentry2.setMap(new Mapping(null, new MapList(new int[] { 10, 22 },
+ new int[] { 10, 22 }, 1, 1)));
+ sq.addDBRef(upentry2);
+
+ // primary - uniprot with map of enclosing sequence
+ DBRefEntry upentry3 = new DBRefEntry("UNIPROT", "0", "Q04763");
+ upentry3.setMap(new Mapping(null, new MapList(new int[] { 8, 24 },
+ new int[] { 8, 24 }, 1, 1)));
+ sq.addDBRef(upentry3);
+
+ // not primary - uniprot with map of sub-sequence (5')
+ DBRefEntry upentry4 = new DBRefEntry("UNIPROT", "0", "Q04764");
+ upentry4.setMap(new Mapping(null, new MapList(new int[] { 10, 18 },
+ new int[] { 10, 18 }, 1, 1)));
+ sq.addDBRef(upentry4);
+
+ // not primary - uniprot with map that overlaps 3'
+ DBRefEntry upentry5 = new DBRefEntry("UNIPROT", "0", "Q04765");
+ upentry5.setMap(new Mapping(null, new MapList(new int[] { 12, 22 },
+ new int[] { 12, 22 }, 1, 1)));
+ sq.addDBRef(upentry5);
+
+ // not primary - uniprot with map to different coordinates frame
+ DBRefEntry upentry6 = new DBRefEntry("UNIPROT", "0", "Q04766");
+ upentry6.setMap(new Mapping(null, new MapList(new int[] { 12, 18 },
+ new int[] { 112, 118 }, 1, 1)));
+ sq.addDBRef(upentry6);
+
+ // not primary - dbref to 'non-core' database
+ DBRefEntry upentry7 = new DBRefEntry("Pfam", "0", "PF00903");
+ sq.addDBRef(upentry7);
+
+ // primary - type is PDB
+ DBRefEntry pdbentry = new DBRefEntry("PDB", "0", "1qip");
+ sq.addDBRef(pdbentry);
+
+ // not primary - PDBEntry has no file
+ sq.addDBRef(new DBRefEntry("PDB", "0", "1AAA"));
+
+ // not primary - no PDBEntry
+ sq.addDBRef(new DBRefEntry("PDB", "0", "1DDD"));
+
+ // add corroborating PDB entry for primary DBref -
+ // needs to have a file as well as matching ID
+ // note PDB ID is not treated as case sensitive
+ sq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, new File("/blah")
+ .toString()));
+
+ // not valid DBRef - no file..
+ sq.addPDBId(new PDBEntry("1AAA", null, null, null));
+
+ primaryDBRefs = sq.getPrimaryDBRefs();
+ assertEquals(4, primaryDBRefs.size());
+ assertTrue("Couldn't find simple primary reference (UNIPROT)",
+ primaryDBRefs.contains(upentry1));
+ assertTrue("Couldn't find mapped primary reference (UNIPROT)",
+ primaryDBRefs.contains(upentry2));
+ assertTrue("Couldn't find mapped context reference (UNIPROT)",
+ primaryDBRefs.contains(upentry3));
+ assertTrue("Couldn't find expected PDB primary reference",
+ primaryDBRefs.contains(pdbentry));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetPrimaryDBRefs_nucleotide()
+ {
+ SequenceI sq = new Sequence("aseq", "TGATCACTCGACTAGCATCAGCATA", 10, 34);
+
+ // primary - Ensembl
+ DBRefEntry dbr1 = new DBRefEntry("ENSEMBL", "0", "ENSG1234");
+ sq.addDBRef(dbr1);
+
+ // not primary - Ensembl 'transcript' mapping of sub-sequence
+ DBRefEntry dbr2 = new DBRefEntry("ENSEMBL", "0", "ENST1234");
+ dbr2.setMap(new Mapping(null, new MapList(new int[] { 15, 25 },
+ new int[] { 1, 11 }, 1, 1)));
+ sq.addDBRef(dbr2);
+
+ // primary - EMBL with congruent map
+ DBRefEntry dbr3 = new DBRefEntry("EMBL", "0", "J1234");
+ dbr3.setMap(new Mapping(null, new MapList(new int[] { 10, 34 },
+ new int[] { 10, 34 }, 1, 1)));
+ sq.addDBRef(dbr3);
+
+ // not primary - to non-core database
+ DBRefEntry dbr4 = new DBRefEntry("CCDS", "0", "J1234");
+ sq.addDBRef(dbr4);
+
+ // not primary - to protein
+ DBRefEntry dbr5 = new DBRefEntry("UNIPROT", "0", "Q87654");
+ sq.addDBRef(dbr5);
+
+ List<DBRefEntry> primaryDBRefs = sq.getPrimaryDBRefs();
+ assertEquals(2, primaryDBRefs.size());
+ assertTrue(primaryDBRefs.contains(dbr1));
+ assertTrue(primaryDBRefs.contains(dbr3));
+ }
+
+ /**
+ * Test the method that updates the list of PDBEntry from any new DBRefEntry
+ * for PDB
+ */
+ @Test(groups = { "Functional" })
+ public void testUpdatePDBIds()
+ {
+ PDBEntry pdbe1 = new PDBEntry("3A6S", null, null, null);
+ seq.addPDBId(pdbe1);
+ seq.addDBRef(new DBRefEntry("Ensembl", "8", "ENST1234"));
+ seq.addDBRef(new DBRefEntry("PDB", "0", "1A70"));
+ seq.addDBRef(new DBRefEntry("PDB", "0", "4BQGa"));
+ seq.addDBRef(new DBRefEntry("PDB", "0", "3a6sB"));
+ // 7 is not a valid chain code:
+ seq.addDBRef(new DBRefEntry("PDB", "0", "2GIS7"));
+
+ seq.updatePDBIds();
+ List<PDBEntry> pdbIds = seq.getAllPDBEntries();
+ assertEquals(4, pdbIds.size());
+ assertSame(pdbe1, pdbIds.get(0));
+ // chain code got added to 3A6S:
+ assertEquals("B", pdbe1.getChainCode());
+ assertEquals("1A70", pdbIds.get(1).getId());
+ // 4BQGA is parsed into id + chain
+ assertEquals("4BQG", pdbIds.get(2).getId());
+ assertEquals("a", pdbIds.get(2).getChainCode());
+ assertEquals("2GIS7", pdbIds.get(3).getId());
+ assertNull(pdbIds.get(3).getChainCode());
+ }
+
+ /**
+ * Test the method that either adds a pdbid or updates an existing one
+ */
+ @Test(groups = { "Functional" })
+ public void testAddPDBId()
+ {
+ PDBEntry pdbe = new PDBEntry("3A6S", null, null, null);
+ seq.addPDBId(pdbe);
+ assertEquals(1, seq.getAllPDBEntries().size());
+ assertSame(pdbe, seq.getPDBEntry("3A6S"));
+ assertSame(pdbe, seq.getPDBEntry("3a6s")); // case-insensitive
+
+ // add the same entry
+ seq.addPDBId(pdbe);
+ assertEquals(1, seq.getAllPDBEntries().size());
+ assertSame(pdbe, seq.getPDBEntry("3A6S"));
+
+ // add an identical entry
+ seq.addPDBId(new PDBEntry("3A6S", null, null, null));
+ assertEquals(1, seq.getAllPDBEntries().size());
+ assertSame(pdbe, seq.getPDBEntry("3A6S"));
+
+ // add a different entry
+ PDBEntry pdbe2 = new PDBEntry("1A70", null, null, null);
+ seq.addPDBId(pdbe2);
+ assertEquals(2, seq.getAllPDBEntries().size());
+ assertSame(pdbe, seq.getAllPDBEntries().get(0));
+ assertSame(pdbe2, seq.getAllPDBEntries().get(1));
+
+ // update pdbe with chain code, file, type
+ PDBEntry pdbe3 = new PDBEntry("3a6s", "A", Type.PDB, "filepath");
+ seq.addPDBId(pdbe3);
+ assertEquals(2, seq.getAllPDBEntries().size());
+ assertSame(pdbe, seq.getAllPDBEntries().get(0)); // updated in situ
+ assertEquals("3A6S", pdbe.getId()); // unchanged
+ assertEquals("A", pdbe.getChainCode()); // updated
+ assertEquals(Type.PDB.toString(), pdbe.getType()); // updated
+ assertEquals("filepath", pdbe.getFile()); // updated
+ assertSame(pdbe2, seq.getAllPDBEntries().get(1));
+
+ // add with a different file path
+ PDBEntry pdbe4 = new PDBEntry("3a6s", "A", Type.PDB, "filepath2");
+ seq.addPDBId(pdbe4);
+ assertEquals(3, seq.getAllPDBEntries().size());
+ assertSame(pdbe4, seq.getAllPDBEntries().get(2));
+
+ // add with a different chain code
+ PDBEntry pdbe5 = new PDBEntry("3a6s", "B", Type.PDB, "filepath");
+ seq.addPDBId(pdbe5);
+ assertEquals(4, seq.getAllPDBEntries().size());
+ assertSame(pdbe5, seq.getAllPDBEntries().get(3));
+ }
+
+ @Test(
+ groups = { "Functional" },
+ expectedExceptions = { IllegalArgumentException.class })
+ public void testSetDatasetSequence_toSelf()
+ {
+ seq.setDatasetSequence(seq);
+ }
+
+ @Test(
+ groups = { "Functional" },
+ expectedExceptions = { IllegalArgumentException.class })
+ public void testSetDatasetSequence_cascading()
+ {
+ SequenceI seq2 = new Sequence("Seq2", "xyz");
+ seq2.createDatasetSequence();
+ seq.setDatasetSequence(seq2);