JComboBox<StringPair> database;
+ JCheckBox removeVersions = null;
+
JCheckBox replacePunctuation;
JButton okBtn;
{
this.setLayout(new BorderLayout());
+ removeVersions = new JCheckBox(MessageManager
+ .getString("label.remove_version_numbers_from_ids"));
+ removeVersions.setHorizontalAlignment(SwingConstants.LEFT);
+ removeVersions.setFont(new Font("Verdana", Font.ITALIC, 11));
+ boolean removeVersionsDefault = Cache
+ .getDefault("REMOVE_VERSION_FROM_IDENTIFIERS_DEFAULT", true);
+ removeVersions.setSelected(removeVersionsDefault);
+ removeVersions.setEnabled(false);
+ removeVersions.setVisible(false);
+
database = new JComboBox<>();
database.setFont(JvSwingUtils.getLabelFont());
StringPair instructionItem = new StringPair(
.getKey();
updateExampleQuery(currentSelection);
+ boolean showRemoveVersions = false;
if ("pdb".equalsIgnoreCase(currentSelection))
{
frame.dispose();
{
frame.dispose();
new UniprotFTSPanel(SequenceFetcher.this);
+ showRemoveVersions = true;
}
else if ("3d-beacons".equalsIgnoreCase(currentSelection))
{
{
otherSourceAction();
}
+
+ removeVersions.setEnabled(showRemoveVersions);
+ removeVersions.setVisible(showRemoveVersions);
}
});
databasePanel.add(exampleAccession, BorderLayout.CENTER);
JPanel jPanel2a = new JPanel(new BorderLayout());
jPanel2a.add(jLabel1, BorderLayout.NORTH);
+ jPanel2a.add(removeVersions, BorderLayout.CENTER);
jPanel2a.add(replacePunctuation, BorderLayout.SOUTH);
databasePanel.add(jPanel2a, BorderLayout.SOUTH);
* tidy inputs and check there is something to search for
*/
String t0 = textArea.getText();
- String text = t0.trim();
- if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
- {
- text = text.replace(",", ";");
- }
- text = text.replaceAll("(\\s|[; ])+", ";");
+ String text = replaceQueryText(t0,
+ replacePunctuation.isEnabled()
+ && replacePunctuation.isSelected(),
+ removeVersions.isEnabled() && removeVersions.isSelected());
if (!t0.equals(text))
{
textArea.setText(text);
worker.start();
}
+ protected static String replaceQueryText(String text0,
+ boolean replaceSemiColons, boolean removeVersions)
+ {
+ String text = text0.trim();
+ if (replaceSemiColons)
+ {
+ text = text.replace(",", ";");
+ }
+ text = text.replaceAll("(\\s|[; ])+", ";");
+ if (removeVersions)
+ {
+ Console.debug("search text was '" + text + "'");
+ // remove all *last* .123 from an ID. (ID is terminated just before a
+ // non-alphanumeric-or-dot [which is replaced] or end of string)
+ text = text.replaceAll("\\.[0-9]+([^0-9a-zA-Z\\.]|$)", "$1");
+ /* or do we want:
+ // remove everything after a first .123.45.6 in an ID
+ text = text.replaceAll("\\.[0-9\\.]+", "");
+ */
+ Console.debug("search text now '" + text + "'");
+ }
+ return text;
+ }
+
private void resetDialog()
{
exampleBtn.setEnabled(true);
--- /dev/null
+package jalview.gui;
+
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class SequenceFetcherTest
+{
+ @Test(groups = { "Functional" }, dataProvider = "queryConversions")
+ public void testQueryConversions(String query0, boolean replaceSemiColons,
+ boolean removeVersions, String result)
+ {
+ Assert.assertEquals(
+ SequenceFetcher.replaceQueryText(query0, replaceSemiColons,
+ removeVersions),
+ result, "Converted query string isn't as expected");
+ }
+
+ @DataProvider(name = "queryConversions")
+ public Object[][] queryConversions()
+ {
+ /**
+ * String typedInQuery, replaceSemiColons, removeVersions, resultantQuery
+ */
+ return new Object[][] {
+ //
+
+ { "P12345", false, false, "P12345" },
+ { "P12345", true, false, "P12345" },
+ { "P12345", false, true, "P12345" },
+ { "P12345", true, true, "P12345" },
+ //
+ { "P12345.1", false, false, "P12345.1" },
+ { "P12345.1", true, false, "P12345.1" },
+ { "P12345.1", false, true, "P12345" },
+ { "P12345.1", true, true, "P12345" },
+ //
+ { "P12345.1 P22222.2", false, false, "P12345.1;P22222.2" },
+ { "P12345.1 P22222.2", true, false, "P12345.1;P22222.2" },
+ { "P12345.1 P22222.2", false, true, "P12345;P22222" },
+ { "P12345.1 P22222.2", true, true, "P12345;P22222" },
+ //
+ { "P12345.1,P22222.2", false, false, "P12345.1,P22222.2" },
+ { "P12345.1,P22222.2", true, false, "P12345.1;P22222.2" },
+ { "P12345.1,P22222.2", false, true, "P12345,P22222" },
+ { "P12345.1,P22222.2", true, true, "P12345;P22222" },
+ //
+ { "P12345.1.9; P22222.2", false, false, "P12345.1.9;P22222.2" },
+ { "P12345.1.9; P22222.2", true, false, "P12345.1.9;P22222.2" },
+ { "P12345.1.9; P22222.2", false, true, "P12345.1;P22222" },
+ { "P12345.1.9; P22222.2", true, true, "P12345.1;P22222" },
+ //
+ { "P12345.1x; P22222.2", false, false, "P12345.1x;P22222.2" },
+ { "P12345.1x; P22222.2", true, false, "P12345.1x;P22222.2" },
+ { "P12345.1x; P22222.2", false, true, "P12345.1x;P22222" },
+ { "P12345.1x; P22222.2", true, true, "P12345.1x;P22222" },
+
+ //
+ };
+ }
+
+}