X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FDBRefUtilsTest.java;h=ca5bca35282b031b1ff98b5f6685ad4c64d725c8;hb=f7075b9f56eafbe634efadc1a0cafdab6698139a;hp=c998fa01adb7891b932307ceff0c177c4ad2ec65;hpb=838e4f91d4a53dd315640dbc9ff6ef7a815ee576;p=jalview.git diff --git a/test/jalview/util/DBRefUtilsTest.java b/test/jalview/util/DBRefUtilsTest.java index c998fa0..ca5bca3 100644 --- a/test/jalview/util/DBRefUtilsTest.java +++ b/test/jalview/util/DBRefUtilsTest.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1) - * 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. * @@ -21,7 +21,6 @@ package jalview.util; import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; @@ -32,12 +31,23 @@ import jalview.datamodel.Mapping; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; +import jalview.gui.JvOptionPane; +import java.util.List; + +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class DBRefUtilsTest { + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + /** * Test the method that selects DBRefEntry items whose source is in a supplied * list @@ -72,9 +82,16 @@ public class DBRefUtilsTest assertSame(ref2, selected[0]); assertSame(ref3, selected[1]); - sources = new String[] { "Uniprot", "EMBLCDS" }; + sources = new String[] { "EMBLCDS" }; selected = DBRefUtils.selectRefs(dbrefs, sources); assertNull(selected); + + sources = new String[] { "embl", "uniprot" }; + selected = DBRefUtils.selectRefs(dbrefs, sources); + assertEquals(3, selected.length); + assertSame(ref1, selected[0]); + assertSame(ref2, selected[1]); + assertSame(ref3, selected[2]); } /** @@ -96,39 +113,13 @@ public class DBRefUtilsTest assertEquals("UNIPROT", DBRefUtils.getCanonicalName("UNIPROTKB/TREMBL")); assertEquals("UNIPROTKB/SWISS-CHEESE", DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-CHEESE")); - } + assertEquals("ENSEMBL", DBRefUtils.getCanonicalName("Ensembl")); - @Test(groups = { "Functional" }) - public void testIsDasCoordinateSystem() - { - assertFalse(DBRefUtils.isDasCoordinateSystem(null, null)); - assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null)); - assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry( - "PDB", "v1", "a1"))); - - assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum", - new DBRefEntry("PDB", "v1", "a1"))); - assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM", - new DBRefEntry("PDB", "v1", "a1"))); - // "pdb" is converted to upper-case in DBRefEntry constructor - assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum", - new DBRefEntry("pdb", "v1", "a1"))); - assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry( - "pdb", "v1", "a1"))); - - assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry( - "Uniprot", "v1", "a1"))); - assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry( - "UNIPROT", "v1", "a1"))); - assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB", - new DBRefEntry("pdb", "v1", "a1"))); - - assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry( - "EMBL", "v1", "a1"))); - assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry( - "embl", "v1", "a1"))); - } + // these are not 'known' to Jalview + assertEquals("PFAM", DBRefUtils.getCanonicalName("PFAM")); + assertEquals("pfam", DBRefUtils.getCanonicalName("pfam")); + } /** * Test 'parsing' a DBRef - non PDB case */ @@ -137,13 +128,18 @@ public class DBRefUtilsTest { SequenceI seq = new Sequence("Seq1", "ABCD"); DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890"); - DBRefEntry[] refs = seq.getDBRef(); + DBRefEntry[] refs = seq.getDBRefs(); assertEquals(1, refs.length); assertSame(ref, refs[0]); assertEquals("EMBL", ref.getSource()); assertEquals("1.2", ref.getVersion()); assertEquals("a7890", ref.getAccessionId()); - assertNull(seq.getAllPDBEntries()); + assertTrue(seq.getAllPDBEntries().isEmpty()); + SequenceI seq2 = new Sequence("Seq2", "ABCD"); + // Check that whitespace doesn't confuse parseToDbRef + DBRefEntry ref2 = DBRefUtils.parseToDbRef(seq2, "EMBL", "1.2", + " a7890"); + assertEquals(ref, ref2); } /** @@ -155,7 +151,10 @@ public class DBRefUtilsTest SequenceI seq = new Sequence("Seq1", "ABCD"); DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2", "1WRI A; 7-80;"); - DBRefEntry[] refs = seq.getDBRef(); + // TODO: correct PDBEntry and PDB DBRef accessions need to be generated for + // PDB ref in Stockholm + + DBRefEntry[] refs = seq.getDBRefs(); assertEquals(1, refs.length); assertSame(ref, refs[0]); assertEquals("PDB", ref.getSource()); @@ -190,12 +189,12 @@ public class DBRefUtilsTest ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, 1 }, 1, 1))); - DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1, - ref2, ref3, ref4, ref5 }, target); - assertEquals(3, matches.length); - assertSame(ref1, matches[0]); - assertSame(ref2, matches[1]); - assertSame(ref5, matches[2]); + List matches = DBRefUtils.searchRefs(new DBRefEntry[] { + ref1, ref2, ref3, ref4, ref5 }, target); + assertEquals(3, matches.size()); + assertSame(ref1, matches.get(0)); + assertSame(ref2, matches.get(1)); + assertSame(ref5, matches.get(2)); } /** @@ -223,10 +222,65 @@ public class DBRefUtilsTest new int[] { 1, 1 }, 2, 2)); ref3.setMap(map3); - DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1, - ref2, ref3 }, target); - assertEquals(2, matches.length); - assertSame(ref1, matches[0]); - assertSame(ref2, matches[1]); + List matches = DBRefUtils.searchRefs(new DBRefEntry[] { + ref1, ref2, ref3 }, target); + assertEquals(2, matches.size()); + assertSame(ref1, matches.get(0)); + assertSame(ref2, matches.get(1)); + } + + /** + * Test the method that searches for matching references based on accession id + * only + */ + @Test(groups = { "Functional" }) + public void testSearchRefs_accessionid() + { + + DBRefEntry ref1 = new DBRefEntry("Uniprot", "1", "A1234"); // matches + DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches + // constructor does not upper-case accession id + DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match + DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1235"); // no match + // ref5 matches although it has a mapping - ignored + DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234"); + ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, + 1 }, 1, 1))); + + DBRefEntry[] dbrefs = new DBRefEntry[] { ref1, ref2, ref3, ref4, ref5 }; + List matches = DBRefUtils.searchRefs(dbrefs, "A1234"); + assertEquals(3, matches.size()); + assertSame(ref1, matches.get(0)); + assertSame(ref2, matches.get(1)); + assertSame(ref5, matches.get(2)); + } + + /** + * Test the method that searches for matches references - case when we are + * matching a reference with null (any) accession id + */ + @Test(groups = { "Functional" }) + public void testSearchRefs_wildcardAccessionid() + { + DBRefEntry target = new DBRefEntry("EMBL", "2", null); + + DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // matches + // constructor changes embl to EMBL + DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1235"); // matches + // constructor does not upper-case accession id + DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1236"); // matches + DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); // no match + // ref5 matches although it has a mapping - ignored + DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1237"); + ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, + 1 }, 1, 1))); + + List matches = DBRefUtils.searchRefs(new DBRefEntry[] { + ref1, ref2, ref3, ref4, ref5 }, target); + assertEquals(4, matches.size()); + assertSame(ref1, matches.get(0)); + assertSame(ref2, matches.get(1)); + assertSame(ref3, matches.get(2)); + assertSame(ref5, matches.get(3)); } }