X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceFetcher.java;h=3fa00f5d491c1a6583f1b56db8bde4cbfe0b5035;hb=57c960648b550f10c7db40e39c7bb6a761d732b1;hp=34f0e798783cbca017a71b2405808cdc60761a41;hpb=d423f22792e47dbc800ae220a58677f988971d06;p=jalview.git diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 34f0e79..3fa00f5 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) - * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle * * This file is part of Jalview. * @@ -58,6 +58,10 @@ public class SequenceFetcher extends JPanel implements Runnable private static String dasRegistry = null; + private static boolean _initingFetcher = false; + + private static Thread initingThread = null; + /** * Blocking method that initialises and returns the shared instance of the * SequenceFetcher client @@ -69,9 +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 (guiWindow != null) + { + 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()) + { + try + { + Thread.sleep(10); + } catch (Exception e) + { + } + ; + } + if (guiWindow != null) + { + guiWindow.setProgressBar( + "Waiting for Sequence Database Fetchers to initialise", + Thread.currentThread().hashCode()); + } + } if (sfetch == null || dasRegistry != DasSourceBrowser.getDasRegistryURL()) { + _initingFetcher = true; + initingThread = Thread.currentThread(); /** * give a visual indication that sequence fetcher construction is occuring */ @@ -88,7 +122,8 @@ public class SequenceFetcher extends JPanel implements Runnable Thread.currentThread().hashCode()); } sfetch = sf; - + _initingFetcher = false; + initingThread = null; } return sfetch; } @@ -176,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); } } @@ -194,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() { @@ -233,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() { @@ -262,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(); } @@ -273,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); @@ -309,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(); @@ -371,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 @@ -387,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()) @@ -416,17 +476,20 @@ public class SequenceFetcher extends JPanel implements Runnable } } - AlignmentI indres = proxy.getSequenceRecords(item); + + AlignmentI indres = null; + try + { + indres = proxy.getSequenceRecords(item); + } catch (OutOfMemoryError oome) + { + 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) { @@ -446,7 +509,16 @@ public class SequenceFetcher extends JPanel implements Runnable multiacc.append(proxy.getAccessionSeparator()); } } - aresult = proxy.getSequenceRecords(multiacc.toString()); + try + { + aresultq.add(multiacc.toString()); + aresult.add(proxy.getSequenceRecords(multiacc.toString())); + } catch (OutOfMemoryError oome) + { + new OOMWarning("fetching " + multiacc + " from " + + database.getSelectedItem(), oome, this); + } + } } catch (Exception e) @@ -473,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()); @@ -654,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) { @@ -674,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