/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
* Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
*
* This file is part of Jalview.
private static jalview.ws.SequenceFetcher sfetch = null;
private static String dasRegistry = null;
- private static boolean _initingFetcher=false;
- private static Thread initingThread=null;
+
+ private static boolean _initingFetcher = false;
+
+ private static Thread initingThread = null;
+
/**
* Blocking method that initialises and returns the shared instance of the
* SequenceFetcher client
public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton(
final IProgressIndicator guiWindow)
{
- if (_initingFetcher && initingThread!=null && initingThread.isAlive())
+ if (_initingFetcher && initingThread != null && initingThread.isAlive())
{
if (guiWindow != null)
{
- guiWindow.setProgressBar("Waiting for Sequence Database Fetchers to initialise",
+ guiWindow.setProgressBar(
+ "Waiting for Sequence Database Fetchers to initialise",
Thread.currentThread().hashCode());
}
- // initting happening on another thread - so wait around to see if it finishes.
- while (_initingFetcher && initingThread!=null && initingThread.isAlive())
+ // initting happening on another thread - so wait around to see if it
+ // finishes.
+ while (_initingFetcher && initingThread != null
+ && initingThread.isAlive())
{
- try {Thread.sleep(10);} catch (Exception e){};
+ try
+ {
+ Thread.sleep(10);
+ } catch (Exception e)
+ {
+ }
+ ;
}
if (guiWindow != null)
{
- guiWindow.setProgressBar("Waiting for Sequence Database Fetchers to initialise",
+ guiWindow.setProgressBar(
+ "Waiting for Sequence Database Fetchers to initialise",
Thread.currentThread().hashCode());
}
}
if (sfetch == null
|| dasRegistry != DasSourceBrowser.getDasRegistryURL())
{
- _initingFetcher=true;
- initingThread=Thread.currentThread();
+ _initingFetcher = true;
+ initingThread = Thread.currentThread();
/**
* give a visual indication that sequence fetcher construction is occuring
*/
if (guiWindow != null)
{
guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
- initingThread.hashCode());
+ Thread.currentThread().hashCode());
}
sfetch = sf;
- _initingFetcher=false;
- initingThread=null;
+ _initingFetcher = false;
+ initingThread = null;
}
return sfetch;
}
frame.setContentPane(this);
if (new jalview.util.Platform().isAMac())
{
- Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180);
+ Desktop.addInternalFrame(frame, getFrameTitle(), 400, 240);
}
else
{
- Desktop.addInternalFrame(frame, getFrameTitle(), 400, 140);
+ Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180);
}
}
{
this.setLayout(borderLayout2);
- database.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
+ database.setFont(JvSwingUtils.getLabelFont());
dbeg.setFont(new java.awt.Font("Verdana", Font.BOLD, 11));
jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
- jLabel1
- .setText("Separate multiple accession ids with semi colon \";\"");
+ jLabel1.setText("Separate multiple accession ids with semi colon \";\"");
+
+ replacePunctuation.setHorizontalAlignment(SwingConstants.CENTER);
+ replacePunctuation
+ .setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
+ replacePunctuation.setText("Replace commas with semi-colons");
ok.setText("OK");
ok.addActionListener(new ActionListener()
{
close_actionPerformed(e);
}
});
- textArea.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
+ textArea.setFont(JvSwingUtils.getLabelFont());
textArea.setLineWrap(true);
textArea.addKeyListener(new KeyAdapter()
{
{
db = sfetch.getSourceProxy((String) sources.get(database
.getSelectedItem()));
- dbeg.setText("Example query: " + db.getTestQuery());
+ String eq = db.getTestQuery();
+ dbeg.setText("Example query: " + eq);
+ replacePunctuation.setEnabled(!(eq != null && eq.indexOf(",") > -1));
} catch (Exception ex)
{
dbeg.setText("");
+ replacePunctuation.setEnabled(true);
}
jPanel2.repaint();
}
dbeg.setText("");
jPanel2.add(database, java.awt.BorderLayout.NORTH);
jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
- jPanel2.add(jLabel1, java.awt.BorderLayout.SOUTH);
+ JPanel jPanel2a = new JPanel(new BorderLayout());
+ jPanel2a.add(jLabel1, java.awt.BorderLayout.NORTH);
+ jPanel2a.add(replacePunctuation, java.awt.BorderLayout.SOUTH);
+ jPanel2.add(jPanel2a, java.awt.BorderLayout.SOUTH);
// jPanel2.setPreferredSize(new Dimension())
jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
this.add(jPanel1, java.awt.BorderLayout.SOUTH);
JLabel jLabel1 = new JLabel();
+ JCheckBox replacePunctuation = new JCheckBox();
+
JButton ok = new JButton();
JButton clear = new JButton();
{
error += "Please select the source database\n";
}
- // TODO: make this transformation optional and configurable
- com.stevesoft.pat.Regex empty = new com.stevesoft.pat.Regex(
- "(\\s|[,; ])+", ";"); // \\s+", "");
+ // TODO: make this transformation more configurable
+ com.stevesoft.pat.Regex empty;
+ if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
+ {
+ empty = new com.stevesoft.pat.Regex(
+ // replace commas and spaces with a semicolon
+ "(\\s|[,; ])+", ";");
+ }
+ else
+ {
+ // just turn spaces and semicolons into single semicolons
+ empty = new com.stevesoft.pat.Regex("(\\s|[; ])+", ";");
+ }
textArea.setText(empty.replaceAll(textArea.getText()));
// see if there's anthing to search with
if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
resetDialog();
return;
}
- AlignmentI aresult = null;
+ ArrayList<String> aresultq=new ArrayList<String>();
+ ArrayList<AlignmentI> aresult = new ArrayList<AlignmentI>();
Object source = database.getSelectedItem();
Enumeration en = new StringTokenizer(textArea.getText(), ";");
+ boolean isAliSource=false;
try
{
- guiWindow.setProgressBar("Fetching Sequences from "
- + database.getSelectedItem(), Thread.currentThread()
- .hashCode());
+ guiWindow.setProgressBar(
+ "Fetching Sequences from " + database.getSelectedItem(),
+ Thread.currentThread().hashCode());
DbSourceProxy proxy = sfetch.getSourceProxy((String) sources
.get(source));
+ isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
if (proxy.getAccessionSeparator() == null)
{
while (en.hasMoreElements())
indres = proxy.getSequenceRecords(item);
} catch (OutOfMemoryError oome)
{
- new OOMWarning(
- "fetching " + item + " from "
- + database.getSelectedItem(),oome,
- this);
+ new OOMWarning("fetching " + item + " from "
+ + database.getSelectedItem(), oome, this);
}
if (indres != null)
{
- if (aresult == null)
- {
- aresult = indres;
- }
- else
- {
- aresult.append(indres);
- }
+ aresultq.add(item);
+ aresult.add(indres);
}
} catch (Exception e)
{
}
try
{
- aresult = proxy.getSequenceRecords(multiacc.toString());
+ aresultq.add(multiacc.toString());
+ aresult.add(proxy.getSequenceRecords(multiacc.toString()));
} catch (OutOfMemoryError oome)
{
- new OOMWarning(
- "fetching " + multiacc + " from "
- + database.getSelectedItem(),oome,
- this);
+ new OOMWarning("fetching " + multiacc + " from "
+ + database.getSelectedItem(), oome, this);
}
-
-
+
}
} catch (Exception e)
+ " from " + database.getSelectedItem());
e.printStackTrace();
}
- if (aresult != null)
+ if (aresult != null && aresult.size()>0)
{
- parseResult(aresult, null, null);
+ AlignmentI ar=null;
+ if (isAliSource) {
+ // new window for each result
+ while (aresult.size()>0)
+ {
+ parseResult(aresult.remove(0), aresultq.remove(0)+" "+getDefaultRetrievalTitle(), null);
+ }
+ } else {
+ // concatenate all results in one window
+ while (aresult.size()>0)
+ {
+ if (ar==null) { ar = aresult.remove(0);}
+ else { ar.append(aresult.remove(0)); };
+ }
+ parseResult(ar, null, null);
+ }
}
// only remove visual delay after we finished parsing.
guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
return null;
}
+ /**
+ *
+ * @return a standard title for any results retrieved using the currently selected source and settings
+ */
+ public String getDefaultRetrievalTitle() {
+ return "Retrieved from " + database.getSelectedItem();
+ }
AlignmentI parseResult(AlignmentI al, String title,
String currentFileFormat)
{
if (title == null)
{
- title = "Retrieved from " + database.getSelectedItem();
+ title = getDefaultRetrievalTitle();
}
SequenceFeature[] sfs = null;
for (Enumeration sq = al.getSequences().elements(); sq