From: tcofoegbu Date: Fri, 24 Apr 2015 13:51:32 +0000 (+0100) Subject: JAL-1707 bug fix - also search using sequence name X-Git-Tag: Jalview_2_9~46^2~3^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=43a44d10c88ef1ebb6e149b0a48f890c0f803247;p=jalview.git JAL-1707 bug fix - also search using sequence name --- diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 5c86ce2..c913213 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -232,38 +232,82 @@ public class StructureChooser extends GStructureChooser public static String buildQuery(SequenceI seq) { - String query = seq.getName(); - StringBuilder queryBuilder = new StringBuilder(); - int count = 0; + HashSet seqRefs = new LinkedHashSet(); + String seqName = seq.getName(); + String[] names = seqName.toLowerCase().split("\\|"); + for (String name : names) + { + System.out.println("Found name : " + name); + name.trim(); + if (isValidSeqName(name)) + { + seqRefs.add(name); + } + } if (seq.getPDBId() != null) { for (PDBEntry entry : seq.getPDBId()) { - queryBuilder.append("text:").append(entry.getId()).append(" OR "); + seqRefs.add(entry.getId()); } } if (seq.getDBRef() != null && seq.getDBRef().length != 0) { + int count = 0; for (DBRefEntry dbRef : seq.getDBRef()) { - queryBuilder.append("text:") - .append(dbRef.getAccessionId().replaceAll("GO:", "")) - .append(" OR "); + seqRefs.add(getDBRefId(dbRef)); ++count; if (count > 10) { break; } } - int endIndex = queryBuilder.lastIndexOf(" OR "); - query = queryBuilder.toString().substring(5, endIndex); } + + StringBuilder queryBuilder = new StringBuilder(); + for (String seqRef : seqRefs) + { + queryBuilder.append("text:").append(seqRef).append(" OR "); + } + int endIndex = queryBuilder.lastIndexOf(" OR "); + String query = queryBuilder.toString().substring(5, endIndex); return query; } /** + * Ensures sequence ref names are not less than 3 characters and does not + * contain a database name + * + * @param seqName + * @return + */ + public static boolean isValidSeqName(String seqName) + { + String ignoreList = "pdb,uniprot"; + if (seqName.length() < 3) + { + return false; + } + for (String ignoredEntry : ignoreList.split(",")) + { + if (seqName.equalsIgnoreCase(ignoredEntry)) + { + return false; + } + } + return true; + } + + public static String getDBRefId(DBRefEntry dbRef) + { + String ref = dbRef.getAccessionId().replaceAll("GO:", ""); + return ref; + } + + /** * Filters a given list of discovered structures based on supplied argument * * @param fieldToFilterBy diff --git a/test/jalview/gui/StructureChooserTest.java b/test/jalview/gui/StructureChooserTest.java index 24e8bc9..1e73d3e 100644 --- a/test/jalview/gui/StructureChooserTest.java +++ b/test/jalview/gui/StructureChooserTest.java @@ -20,7 +20,8 @@ public class StructureChooserTest @Before public void setUp() throws Exception { - seq = new Sequence("Test_Seq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 26); + seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, + 26); seq.setDatasetSequence(seq); for (int x = 1; x < 5; x++) { @@ -49,9 +50,11 @@ public class StructureChooserTest @Test public void buildQueryTest() { + String query = StructureChooser.buildQuery(seq); + System.out.println(">>>>>>>>>> query : " + query); assertEquals( - "1tim OR text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4", - StructureChooser.buildQuery(seq)); + "4kqy OR text:1tim OR text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4", + query); } @Test @@ -63,13 +66,13 @@ public class StructureChooserTest null); sc.populateFilterComboBox(); int optionsSize = sc.getCmbFilterOption().getItemCount(); - assertEquals(2, optionsSize); // if structures are not discovered then don't + assertEquals(3, optionsSize); // if structures are not discovered then don't // populate filter options sc.setStructuresDiscovered(true); sc.populateFilterComboBox(); optionsSize = sc.getCmbFilterOption().getItemCount(); - assertTrue(optionsSize > 2); // if structures are found, filter options + assertTrue(optionsSize > 3); // if structures are found, filter options // should be populated } diff --git a/test/jalview/ws/dbsources/PDBRestClientTest.java b/test/jalview/ws/dbsources/PDBRestClientTest.java index d86edd2..181fcf1 100644 --- a/test/jalview/ws/dbsources/PDBRestClientTest.java +++ b/test/jalview/ws/dbsources/PDBRestClientTest.java @@ -97,7 +97,6 @@ public class PDBRestClientTest String parsedErrorResponse = PDBRestClient .parseJsonExceptionString(jsonErrorResponse); - System.out.println(parsedErrorResponse); String expectedErrorMsg = "\n============= PDB Rest Client RunTime error =============\n" + "Status: 400\n"