X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceFetcher.java;h=2f90ba067ebfbd0b581b2302072889d7afd5c948;hb=ba085b0611979fc641da5bb1abe4995a57b57629;hp=c5a923531493c052c2ad05f9ae629474f252e557;hpb=9dbf492494f3a054ae007fa7ce17ddd2d9884c40;p=jalview.git diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index c5a9235..2f90ba0 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -1,5 +1,5 @@ /* - * 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. @@ -57,8 +57,11 @@ public class SequenceFetcher extends JPanel implements Runnable 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 @@ -70,29 +73,39 @@ public class SequenceFetcher extends JPanel implements Runnable 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 */ @@ -106,11 +119,11 @@ public class SequenceFetcher extends JPanel implements Runnable 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; } @@ -198,11 +211,11 @@ public class SequenceFetcher extends JPanel implements Runnable 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); } } @@ -216,12 +229,16 @@ public class SequenceFetcher extends JPanel implements Runnable { 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() { @@ -255,7 +272,7 @@ public class SequenceFetcher extends JPanel implements Runnable close_actionPerformed(e); } }); - textArea.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + textArea.setFont(JvSwingUtils.getLabelFont()); textArea.setLineWrap(true); textArea.addKeyListener(new KeyAdapter() { @@ -284,10 +301,13 @@ public class SequenceFetcher extends JPanel implements Runnable { 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(); } @@ -295,7 +315,10 @@ public class SequenceFetcher extends JPanel implements Runnable 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); @@ -331,6 +354,8 @@ public class SequenceFetcher extends JPanel implements Runnable JLabel jLabel1 = new JLabel(); + JCheckBox replacePunctuation = new JCheckBox(); + JButton ok = new JButton(); JButton clear = new JButton(); @@ -393,9 +418,19 @@ public class SequenceFetcher extends JPanel implements Runnable { 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 @@ -409,16 +444,19 @@ public class SequenceFetcher extends JPanel implements Runnable resetDialog(); return; } - AlignmentI aresult = null; + ArrayList aresultq=new ArrayList(); + ArrayList aresult = new ArrayList(); 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()) @@ -445,21 +483,13 @@ public class SequenceFetcher extends JPanel implements Runnable 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) { @@ -481,16 +511,14 @@ public class SequenceFetcher extends JPanel implements Runnable } 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) @@ -517,9 +545,24 @@ public class SequenceFetcher extends JPanel implements Runnable + " 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()); @@ -698,6 +741,13 @@ public class SequenceFetcher extends JPanel implements Runnable 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) { @@ -718,7 +768,7 @@ public class SequenceFetcher extends JPanel implements Runnable if (title == null) { - title = "Retrieved from " + database.getSelectedItem(); + title = getDefaultRetrievalTitle(); } SequenceFeature[] sfs = null; for (Enumeration sq = al.getSequences().elements(); sq