X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceFetcher.java;h=7dcd2b905f1306f19443b2131ff0793181c4922a;hb=ef9d515865742b8a9b80371c65a201801b7f0253;hp=191e8fe167c223aafc5e9afd792ffa079d94dcfe;hpb=a21b84a669a9620f6943b9b5054e8756cb6f0687;p=jalview.git diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 191e8fe..7dcd2b9 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -20,13 +20,15 @@ */ package jalview.gui; +import jalview.api.FeatureSettingsModelI; +import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; -import jalview.datamodel.DBRefSource; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; -import jalview.io.FormatAdapter; -import jalview.io.IdentifyFile; +import jalview.fts.service.pdb.PDBFTSPanel; +import jalview.fts.service.uniprot.UniprotFTSPanel; +import jalview.io.gff.SequenceOntologyI; import jalview.util.DBRefUtils; import jalview.util.MessageManager; import jalview.ws.dbsources.das.api.DasSourceRegistryI; @@ -54,8 +56,6 @@ import javax.swing.JTextArea; import javax.swing.SwingConstants; import javax.swing.tree.DefaultMutableTreeNode; -import com.stevesoft.pat.Regex; - public class SequenceFetcher extends JPanel implements Runnable { JLabel dbeg = new JLabel(); @@ -116,6 +116,11 @@ public class SequenceFetcher extends JPanel implements Runnable int debounceTrap = 0; + public JTextArea getTextArea() + { + return textArea; + } + /** * Blocking method that initialises and returns the shared instance of the * SequenceFetcher client @@ -160,9 +165,9 @@ public class SequenceFetcher extends JPanel implements Runnable } } if (sfetch == null - || dasRegistry != jalview.bin.Cache.getDasSourceRegistry() - || lastDasSourceRegistry != (jalview.bin.Cache - .getDasSourceRegistry().getDasRegistryURL() + jalview.bin.Cache + || dasRegistry != Cache.getDasSourceRegistry() + || lastDasSourceRegistry != (Cache.getDasSourceRegistry() + .getDasRegistryURL() + Cache .getDasSourceRegistry().getLocalSourceString()) .hashCode()) { @@ -177,7 +182,7 @@ public class SequenceFetcher extends JPanel implements Runnable .getString("status.init_sequence_database_fetchers"), Thread.currentThread().hashCode()); } - dasRegistry = jalview.bin.Cache.getDasSourceRegistry(); + dasRegistry = Cache.getDasSourceRegistry(); dasRegistry.refreshSources(); jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher(); @@ -369,15 +374,22 @@ public class SequenceFetcher extends JPanel implements Runnable { debounceTrap++; String currentSelection = database.getSelectedItem(); - if (!currentSelection.equalsIgnoreCase("pdb")) - { - otherSourceAction(); - } + if (currentSelection.equalsIgnoreCase("pdb") && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) == 0))) { pdbSourceAction(); } + // else if (currentSelection.equalsIgnoreCase("uniprot") + // && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) == + // 0))) + // { + // uniprotSourceAction(); + // } + else + { + otherSourceAction(); + } database.action = -1; } }); @@ -401,10 +413,16 @@ public class SequenceFetcher extends JPanel implements Runnable private void pdbSourceAction() { databaseButt.setText(database.getSelectedItem()); - new PDBSearchPanel(this); + new PDBFTSPanel(this); frame.dispose(); } + private void uniprotSourceAction() + { + databaseButt.setText(database.getSelectedItem()); + new UniprotFTSPanel(this); + frame.dispose(); + } private void otherSourceAction() { try @@ -518,6 +536,7 @@ public class SequenceFetcher extends JPanel implements Runnable resetDialog(); return; } + // TODO: Refactor to GUI independent code and write tests. // indicate if successive sources should be merged into one alignment. boolean addToLast = false; ArrayList aresultq = new ArrayList(), presultTitle = new ArrayList(); @@ -529,6 +548,8 @@ public class SequenceFetcher extends JPanel implements Runnable .split(";")); Iterator en = Arrays.asList(new String[0]).iterator(); int nqueries = qries.length; + + FeatureSettingsModelI preferredFeatureColours = null; while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0)) { if (!en.hasNext() && nextfetch.size() > 0) @@ -552,8 +573,8 @@ public class SequenceFetcher extends JPanel implements Runnable Integer.valueOf(nqueries).toString(), proxy.getDbName() }), Thread.currentThread() .hashCode()); - isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB); - if (proxy.getAccessionSeparator() == null) + isAliSource = proxy.isAlignmentSource(); + if (proxy.getMaximumQueryCount() == 1) { while (en.hasNext()) { @@ -593,7 +614,8 @@ public class SequenceFetcher extends JPanel implements Runnable } } catch (Exception e) { - jalview.bin.Cache.log.info("Error retrieving " + item + Cache.log.info( + "Error retrieving " + item + " from " + proxy.getDbName(), e); nextfetch.add(item); } @@ -639,34 +661,19 @@ public class SequenceFetcher extends JPanel implements Runnable DBRefEntry dbr = new DBRefEntry(), found[] = null; dbr.setSource(proxy.getDbSource()); dbr.setVersion(null); - if (proxy.getAccessionValidator() != null) - { - Regex vgr = proxy.getAccessionValidator(); - vgr.search(q); - if (vgr.numSubs() > 0) - { - dbr.setAccessionId(vgr.stringMatched(1)); - } - else - { - dbr.setAccessionId(vgr.stringMatched()); - } - } - else - { - dbr.setAccessionId(q); - } + String accId = proxy.getAccessionIdFromQuery(q); + dbr.setAccessionId(accId); boolean rfound = false; for (int r = 0; r < rs.length; r++) { - if (rs[r] != null - && (found = DBRefUtils.searchRefs( - rs[r].getDBRefs(), dbr)) != null - && found.length > 0) + if (rs[r] != null) { - rfound = true; - rs[r] = null; - continue; + found = DBRefUtils.searchRefs(rs[r].getDBRefs(), accId); + if (found != null && found.length > 0) + { + rfound = true; + rs[r] = null; + } } } if (!rfound) @@ -710,6 +717,13 @@ public class SequenceFetcher extends JPanel implements Runnable // Stack results ready for opening in alignment windows if (aresult != null && aresult.size() > 0) { + FeatureSettingsModelI proxyColourScheme = proxy + .getFeatureColourScheme(); + if (proxyColourScheme != null) + { + preferredFeatureColours = proxyColourScheme; + } + AlignmentI ar = null; if (isAliSource) { @@ -760,7 +774,8 @@ public class SequenceFetcher extends JPanel implements Runnable // process results while (presult.size() > 0) { - parseResult(presult.remove(0), presultTitle.remove(0), null); + parseResult(presult.remove(0), presultTitle.remove(0), null, + preferredFeatureColours); } // only remove visual delay after we finished parsing. guiWindow.setProgressBar(null, Thread.currentThread().hashCode()); @@ -788,35 +803,6 @@ public class SequenceFetcher extends JPanel implements Runnable resetDialog(); } - AlignmentI parseResult(String result, String title) - { - String format = new IdentifyFile().Identify(result, "Paste"); - AlignmentI sequences = null; - if (FormatAdapter.isValidFormat(format)) - { - sequences = null; - try - { - sequences = new FormatAdapter().readFile(result.toString(), - "Paste", format); - } catch (Exception ex) - { - } - - if (sequences != null) - { - return parseResult(sequences, title, format); - } - } - else - { - showErrorMessage("Error retrieving " + textArea.getText() + " from " - + database.getSelectedItem()); - } - - return null; - } - /** * * @return a standard title for any results retrieved using the currently @@ -828,7 +814,8 @@ public class SequenceFetcher extends JPanel implements Runnable } AlignmentI parseResult(AlignmentI al, String title, - String currentFileFormat) + String currentFileFormat, + FeatureSettingsModelI preferredFeatureColours) { if (al != null && al.getHeight() > 0) @@ -866,6 +853,16 @@ public class SequenceFetcher extends JPanel implements Runnable } } + + if (preferredFeatureColours != null) + { + af.getViewport().applyFeaturesStyle(preferredFeatureColours); + } + if (Cache.getDefault("HIDE_INTRONS", true)) + { + hideIntronsIfPresent(af); + } + Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); @@ -874,7 +871,7 @@ public class SequenceFetcher extends JPanel implements Runnable try { - af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", + af.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false)); } catch (Exception ex) { @@ -888,6 +885,25 @@ public class SequenceFetcher extends JPanel implements Runnable return al; } + /** + * Hide columns not containing 'exon' features, provided there are exon + * features on the alignment + * + * @param af + */ + public void hideIntronsIfPresent(AlignFrame af) + { + boolean hasExons = af.avc.markColumnsContainingFeatures(false, false, + false, + SequenceOntologyI.EXON); + if (hasExons) + { + af.avc.markColumnsContainingFeatures(true, false, true, + SequenceOntologyI.EXON); + af.getViewport().hideSelectedColumns(); + } + } + void showErrorMessage(final String error) { resetDialog();