X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=5fa168d2e5e3a667ec1a9312ffaa23022302b086;hb=f37c3fd4fe12799de498de5f397252e9f457fee9;hp=bcb8423a6456a466e6bf1485266739ab7ac220de;hpb=5e22c6b15dc429055036c19fcfc48c16d37d7ad0;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index bcb8423..5fa168d 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -94,7 +94,6 @@ import jalview.schemes.ColourSchemes; import jalview.schemes.ResidueColourScheme; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; -import jalview.util.StringUtils; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; @@ -140,12 +139,9 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; +import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Scanner; +import java.util.Set; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; @@ -168,9 +164,6 @@ import javax.swing.SwingUtilities; public class AlignFrame extends GAlignFrame implements DropTargetListener, IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener { - - Map distribution = new HashMap<>(); // temporary - public static final int DEFAULT_WIDTH = 700; public static final int DEFAULT_HEIGHT = 500; @@ -1145,36 +1138,30 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return true; } + /** + * Opens a file browser and adds the selected file, if in Fasta, Stockholm or + * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a + * comma-separated list) + */ @Override public void addDatabase_actionPerformed() throws IOException { - if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null) + if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null) { Cache.setProperty(Preferences.HMMSEARCH_DBS, ""); - Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, ""); } String path = openFileChooser(false); - if (new File(path).exists()) + if (path != null && new File(path).exists()) { IdentifyFile identifier = new IdentifyFile(); FileFormatI format = identifier.identify(path, DataSourceType.FILE); if (format == FileFormat.Fasta || format == FileFormat.Stockholm || format == FileFormat.Pfam) { - String currentDbs = Cache.getProperty(Preferences.HMMSEARCH_DBS); String currentDbPaths = Cache - .getProperty(Preferences.HMMSEARCH_DB_PATHS); - currentDbPaths += " " + path; - - String fileName = StringUtils.getLastToken(path, File.separator); - Scanner scanner = new Scanner(fileName).useDelimiter("."); - String name = scanner.next(); - scanner.close(); - currentDbs += " " + path; // TODO remove path from file name - scanner.close(); - - Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, currentDbPaths); + .getProperty(Preferences.HMMSEARCH_DBS); + currentDbPaths += Preferences.COMMA + path; Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths); } else @@ -1183,21 +1170,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, MessageManager.getString("warn.invalid_format")); } } - else - { - JOptionPane.showMessageDialog(this, - MessageManager.getString("label.not_enough_sequences")); - } } /** - * Opens a file chooser + * Opens a file chooser, optionally restricted to selecting folders + * (directories) only. Answers the path to the selected file or folder, or + * null if none is chosen. * - * @param forFolder + * @param * @return */ protected String openFileChooser(boolean forFolder) { + // TODO duplicates GPreferences method - relocate to JalviewFileChooser? String choice = null; JFileChooser chooser = new JFileChooser(); if (forFolder) @@ -3491,6 +3476,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.setOverviewPanel(null); }; }); + if (getKeyListeners().length > 0) + { + frame.addKeyListener(getKeyListeners()[0]); + } alignPanel.setOverviewPanel(overview); } @@ -3918,35 +3907,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (viewport.getAlignment().getAlignmentAnnotation() - .hashCode() != _annotationScoreVectorHash) + .hashCode() == _annotationScoreVectorHash) + { + return; + } + + sortByAnnotScore.removeAll(); + Set scoreSorts = new HashSet<>(); + for (SequenceI sqa : viewport.getAlignment().getSequences()) { - sortByAnnotScore.removeAll(); - // almost certainly a quicker way to do this - but we keep it simple - Hashtable scoreSorts = new Hashtable(); - AlignmentAnnotation aann[]; - for (SequenceI sqa : viewport.getAlignment().getSequences()) + AlignmentAnnotation[] anns = sqa.getAnnotation(); + for (int i = 0; anns != null && i < anns.length; i++) { - aann = sqa.getAnnotation(); - for (int i = 0; aann != null && i < aann.length; i++) + AlignmentAnnotation aa = anns[i]; + if (aa != null && aa.hasScore() && aa.sequenceRef != null) { - if (aann[i].hasScore() && aann[i].sequenceRef != null) - { - scoreSorts.put(aann[i].label, aann[i].label); - } + scoreSorts.add(aa.label); } } - Enumeration labels = scoreSorts.keys(); - while (labels.hasMoreElements()) - { - addSortByAnnotScoreMenuItem(sortByAnnotScore, - (String) labels.nextElement()); - } - sortByAnnotScore.setVisible(scoreSorts.size() > 0); - scoreSorts.clear(); - - _annotationScoreVectorHash = viewport.getAlignment() - .getAlignmentAnnotation().hashCode(); } + for (String label : scoreSorts) + { + addSortByAnnotScoreMenuItem(sortByAnnotScore, label); + } + sortByAnnotScore.setVisible(!scoreSorts.isEmpty()); + + _annotationScoreVectorHash = viewport.getAlignment() + .getAlignmentAnnotation().hashCode(); } /** @@ -4691,17 +4678,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int assocfiles = 0; if (filesmatched.size() > 0) { - if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false) - || JvOptionPane.showConfirmDialog(thisaf, - MessageManager.formatMessage( - "label.automatically_associate_structure_files_with_sequences_same_name", - new Object[] - { Integer.valueOf(filesmatched.size()) - .toString() }), - MessageManager.getString( - "label.automatically_associate_structure_files_by_name"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION) - + boolean autoAssociate = Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false); + if (!autoAssociate) + { + String msg = MessageManager.formatMessage( + "label.automatically_associate_structure_files_with_sequences_same_name", + new Object[] + { Integer.valueOf(filesmatched.size()) + .toString() }); + String ttl = MessageManager.getString( + "label.automatically_associate_structure_files_by_name"); + int choice = JvOptionPane.showConfirmDialog(thisaf, msg, + ttl, JvOptionPane.YES_NO_OPTION); + autoAssociate = choice == JvOptionPane.YES_OPTION; + } + if (autoAssociate) { for (Object[] fm : filesmatched) { @@ -4727,6 +4718,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.paintAlignment(true, false); } } + else + { + /* + * add declined structures as sequences + */ + for (Object[] o : filesmatched) + { + filesnotmatched.add((String) o[0]); + } + } } if (filesnotmatched.size() > 0) { @@ -5813,22 +5814,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } @Override - public void hmmerMenu_actionPerformed(ActionEvent e) - { - SequenceGroup grp = getViewport().getSelectionGroup(); - if (grp != null) - { - hmmBuild.setText(MessageManager.getString("label.hmmbuild") + " from " - + grp.getName()); - } - else - { - hmmBuild.setText(MessageManager.getString("label.hmmbuild") - + " from Alignment"); - } - } - - @Override protected void loadVcf_actionPerformed() { JalviewFileChooser chooser = new JalviewFileChooser(