*/
package jalview.gui;
-import jalview.api.FeatureSettingsModelI;
-import jalview.bin.Cache;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.SequenceI;
-import jalview.fts.core.GFTSPanel;
-import jalview.fts.service.pdb.PDBFTSPanel;
-import jalview.fts.service.threedbeacons.TDBeaconsFTSPanel;
-import jalview.fts.service.uniprot.UniprotFTSPanel;
-import jalview.io.FileFormatI;
-import jalview.io.gff.SequenceOntologyI;
-import jalview.util.DBRefUtils;
-import jalview.util.MessageManager;
-import jalview.util.Platform;
-import jalview.ws.seqfetcher.DbSourceProxy;
-
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
+import jalview.api.FeatureSettingsModelI;
+import jalview.bin.Cache;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.SequenceI;
+import jalview.fts.core.GFTSPanel;
+import jalview.fts.service.pdb.PDBFTSPanel;
+import jalview.fts.service.threedbeacons.TDBeaconsFTSPanel;
+import jalview.fts.service.uniprot.UniprotFTSPanel;
+import jalview.io.FileFormatI;
+import jalview.io.gff.SequenceOntologyI;
+import jalview.util.DBRefUtils;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.ws.seqfetcher.DbSourceProxy;
+
/**
* A panel where the use may choose a database source, and enter one or more
* accessions, to retrieve entries from the database.
*/
public class SequenceFetcher extends JPanel implements Runnable
{
+ private class StringPair
+ {
+ private String key;
+
+ private String display;
+
+ public StringPair(String s1, String s2)
+ {
+ key = s1;
+ display = s2;
+ }
+
+ public StringPair(String s)
+ {
+ this(s, s);
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public String getDisplay()
+ {
+ return display;
+ }
+
+ @Override
+ public String toString()
+ {
+ return display;
+ }
+
+ public boolean equals(StringPair other)
+ {
+ return other.key == this.key;
+ }
+ }
+
private static jalview.ws.SequenceFetcher sfetch = null;
JLabel exampleAccession;
- JComboBox<String> database;
+ JComboBox<StringPair> database;
JCheckBox replacePunctuation;
frame = new JInternalFrame();
frame.setContentPane(this);
- Desktop.addInternalFrame(frame, getFrameTitle(), true, 400,
- Platform.isAMacAndNotJS() ? 240 : 180);
+ Desktop.addInternalFrame(frame, getFrameTitle(), true, 400,
+ Platform.isAMacAndNotJS() ? 240 : 180);
}
private String getFrameTitle()
database = new JComboBox<>();
database.setFont(JvSwingUtils.getLabelFont());
- database.setPrototypeDisplayValue("ENSEMBLGENOMES ");
+ StringPair instructionItem = new StringPair(
+ MessageManager.getString("action.select_ddbb"));
+ database.setPrototypeDisplayValue(instructionItem);
String[] sources = new jalview.ws.SequenceFetcher().getSupportedDb();
Arrays.sort(sources, String.CASE_INSENSITIVE_ORDER);
- database.addItem(MessageManager.getString("action.select_ddbb"));
+ database.addItem(instructionItem);
for (String source : sources)
{
- database.addItem(source);
+ List<DbSourceProxy> slist = sfetch.getSourceProxy(source);
+ if (slist.size() == 1 && slist.get(0) != null)
+ {
+ database.addItem(new StringPair(source, slist.get(0).getDbName()));
+ }
+ else
+ {
+ database.addItem(new StringPair(source));
+ }
}
- database.setSelectedItem(selectedDb);
+ setDatabaseSelectedItem(selectedDb);
if (database.getSelectedIndex() == -1)
{
database.setSelectedIndex(0);
@Override
public void actionPerformed(ActionEvent e)
{
- String currentSelection = (String) database.getSelectedItem();
+ String currentSelection = ((StringPair) database.getSelectedItem())
+ .getKey();
updateExampleQuery(currentSelection);
if ("pdb".equalsIgnoreCase(currentSelection))
this.add(databasePanel, BorderLayout.NORTH);
}
+ private void setDatabaseSelectedItem(String db)
+ {
+ for (int i = 0; i < database.getItemCount(); i++)
+ {
+ StringPair sp = database.getItemAt(i);
+ if (sp != null && db != null && db.equals(sp.getKey()))
+ {
+ database.setSelectedIndex(i);
+ return;
+ }
+ }
+ }
+
/**
* Answers a semi-colon-delimited string with the example query or queries for
* the selected database
*/
protected void example_actionPerformed()
{
- String eq = getExampleQueries((String) database.getSelectedItem());
+ String eq = getExampleQueries(
+ ((StringPair) database.getSelectedItem()).getKey());
textArea.setText(eq);
repaint();
}
text = text.replace(",", ";");
}
text = text.replaceAll("(\\s|[; ])+", ";");
- if (!t0.equals(text))
+ if (!t0.equals(text))
{
- textArea.setText(text);
+ textArea.setText(text);
}
if (text.isEmpty())
{
List<String> presultTitle = new ArrayList<>();
List<AlignmentI> presult = new ArrayList<>();
List<AlignmentI> aresult = new ArrayList<>();
- List<DbSourceProxy> sources = sfetch
- .getSourceProxy((String) database.getSelectedItem());
+ List<DbSourceProxy> sources = sfetch.getSourceProxy(
+ ((StringPair) database.getSelectedItem()).getKey());
Iterator<DbSourceProxy> proxies = sources.iterator();
String[] qries = textArea.getText().trim().split(";");
List<String> nextFetch = Arrays.asList(qries);
} catch (Exception e)
{
showErrorMessage("Error retrieving " + textArea.getText() + " from "
- + database.getSelectedItem());
+ + ((StringPair) database.getSelectedItem()).getDisplay());
// error
// +="Couldn't retrieve sequences from "+database.getSelectedItem();
System.err.println("Retrieval failed for source ='"
- + database.getSelectedItem() + "' and query\n'"
- + textArea.getText() + "'\n");
+ + ((StringPair) database.getSelectedItem()).getDisplay()
+ + "' and query\n'" + textArea.getText() + "'\n");
e.printStackTrace();
} catch (OutOfMemoryError e)
{
showErrorMessage("Out of Memory when retrieving "
- + textArea.getText() + " from " + database.getSelectedItem()
+ + textArea.getText() + " from "
+ + ((StringPair) database.getSelectedItem()).getDisplay()
+ "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
e.printStackTrace();
} catch (Error e)
{
showErrorMessage("Serious Error retrieving " + textArea.getText()
- + " from " + database.getSelectedItem());
+ + " from "
+ + ((StringPair) database.getSelectedItem()).getDisplay());
e.printStackTrace();
}
} catch (OutOfMemoryError oome)
{
new OOMWarning("fetching " + multiacc + " from "
- + database.getSelectedItem(), oome, this);
+ + ((StringPair) database.getSelectedItem()).getDisplay(),
+ oome, this);
}
}
for (String q : queries)
{
- // BH 2019.01.25 dbr is never used.
-// DBRefEntry dbr = new DBRefEntry();
-// dbr.setSource(proxy.getDbSource());
-// dbr.setVersion(null);
+ // BH 2019.01.25 dbr is never used.
+ // DBRefEntry dbr = new DBRefEntry();
+ // dbr.setSource(proxy.getDbSource());
+ // dbr.setVersion(null);
String accId = proxy.getAccessionIdFromQuery(q);
-// dbr.setAccessionId(accId);
+ // dbr.setAccessionId(accId);
boolean rfound = false;
for (int r = 0, nr = rs.length; r < nr; r++)
{
*/
public String getDefaultRetrievalTitle()
{
- return "Retrieved from " + database.getSelectedItem();
+ return "Retrieved from "
+ + ((StringPair) database.getSelectedItem()).getDisplay();
}
+
/**
* constructs an alignment frame given the data and metadata
+ *
* @param al
* @param title
* @param currentFileFormat
* @param preferredFeatureColours
- * @return the alignment
+ * @return the alignment
*/
public AlignmentI parseResult(AlignmentI al, String title,
FileFormatI currentFileFormat,