X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAlignFrame.java;h=49486130b5c19cd0d61bd6f83e98580db34421f6;hb=281872ba376cdbbf4cc000ae8dc96958acae6177;hp=e03f2f4126b30b104e5d06d8800837163026b6f7;hpb=1c66dc9053356a709e9cd9d3282517b5221f1ba2;p=jalview.git diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index e03f2f4..4948613 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -1,18 +1,18 @@ /* * 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. - * + * * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License + * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ package jalview.appletgui; @@ -35,6 +35,7 @@ import jalview.datamodel.AlignmentOrder; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.AnnotationFile; @@ -87,6 +88,7 @@ import java.net.URL; import java.net.URLEncoder; import java.util.Enumeration; import java.util.Hashtable; +import java.util.List; import java.util.StringTokenizer; import java.util.Vector; @@ -101,7 +103,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis int DEFAULT_HEIGHT = 500; String jalviewServletURL; - + public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet, String title, boolean embedded) { @@ -231,25 +233,28 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * Load a features file onto the alignment - * + * * @param file file URL, content, or other resolvable path * @param type is protocol for accessing data referred to by file */ - public void parseFeaturesFile(String file, String type) + public boolean parseFeaturesFile(String file, String type) { - parseFeaturesFile(file, type, true); + return parseFeaturesFile(file, type, true); } - + /** * Load a features file onto the alignment - * + * * @param file file URL, content, or other resolvable path * @param type is protocol for accessing data referred to by file * @param autoenabledisplay when true, display features flag will be automatically enabled if features are loaded + * @return true if data parsed as a features file */ - public void parseFeaturesFile(String file, String type, boolean autoenabledisplay) - { + public boolean parseFeaturesFile(String file, String type, boolean autoenabledisplay) + { + // TODO: test if importing a features file onto an alignment which already has features with links overwrites the original links. + Hashtable featureLinks = new Hashtable(); boolean featuresFile = false; try @@ -279,10 +284,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis viewport.featureSettings.refreshTable(); } alignPanel.paintAlignment(true); + statusBar.setText("Successfully added features to alignment."); } - + return featuresFile; } + @Override public void keyPressed(KeyEvent evt) { if (viewport.cursorMode @@ -296,8 +303,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis { case 27: // escape key deselectAllSequenceMenuItem_actionPerformed(); - - alignPanel.alabels.cancelDrag(); + + alignPanel.alabels.cancelDrag(); break; case KeyEvent.VK_X: if (evt.isControlDown() || evt.isMetaDown()) @@ -544,7 +551,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * called by key handler and the hide all/show all menu items - * + * * @param toggleSeqs * @param toggleCols */ @@ -609,14 +616,17 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis } } + @Override public void keyReleased(KeyEvent evt) { } + @Override public void keyTyped(KeyEvent evt) { } + @Override public void itemStateChanged(ItemEvent evt) { if (evt.getSource() == displayNonconservedMenuItem) @@ -733,6 +743,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis this.alignPanel.annotationPanel.repaint(); } + @Override public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); @@ -753,9 +764,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis { loadAnnotations(); } - else if( source == loadScores ) { - loadScores(); - } else if (source == outputAnnotations) { outputAnnotations(true); @@ -955,9 +963,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis else if (source == clustalColour) { abovePIDThreshold.setState(false); - changeColour(new ClustalxColourScheme( - viewport.getAlignment().getSequences(), - viewport.getAlignment().getWidth())); + changeColour(new ClustalxColourScheme(viewport.getAlignment(),null)); } else if (source == zappoColour) { @@ -1104,18 +1110,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis public void loadAnnotations() { CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this); - cap.setText("Paste your features / annotations file here."); + cap.setText("Paste your features / annotations / T-coffee score file here."); cap.setAnnotationImport(); Frame frame = new Frame(); frame.add(cap); jalview.bin.JalviewLite.addFrame(frame, "Paste Annotations ", 400, 300); } - - public void loadScores() { - //TODO - - } public String outputAnnotations(boolean displayTextbox) { @@ -1178,7 +1179,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis features = "# No features visible - paste some and import them here."; frimport=true; } - + CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this); if (frimport) { @@ -1290,8 +1291,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis public void closeMenuItem_actionPerformed() { PaintRefresher.RemoveComponent(alignPanel); - PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas); - PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas); + if (alignPanel.seqPanel!=null && alignPanel.seqPanel.seqCanvas!=null) + { + PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas); + } + if (alignPanel.idPanel!=null && alignPanel.idPanel.idCanvas!=null) { + PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas); + } if (PaintRefresher.components.size() == 0 && viewport.applet == null) { @@ -1352,7 +1358,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * TODO: JAL-1104 * DOCUMENT ME! - * + * * @param e * DOCUMENT ME! */ @@ -1381,7 +1387,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * TODO: JAL-1104 * DOCUMENT ME! - * + * * @param e * DOCUMENT ME! */ @@ -1456,57 +1462,16 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis { return; } - - if (up) - { - for (int i = 1; i < viewport.getAlignment().getHeight(); i++) - { - SequenceI seq = viewport.getAlignment().getSequenceAt(i); - if (!sg.getSequences(null).contains(seq)) - { - continue; - } - - SequenceI temp = viewport.getAlignment().getSequenceAt(i - 1); - if (sg.getSequences(null).contains(temp)) - { - continue; - } - - viewport.getAlignment().getSequences().setElementAt(temp, i); - viewport.getAlignment().getSequences().setElementAt(seq, i - 1); - } - } - else - { - for (int i = viewport.getAlignment().getHeight() - 2; i > -1; i--) - { - SequenceI seq = viewport.getAlignment().getSequenceAt(i); - if (!sg.getSequences(viewport.getHiddenRepSequences()).contains(seq)) - { - continue; - } - - SequenceI temp = viewport.getAlignment().getSequenceAt(i + 1); - if (sg.getSequences(viewport.getHiddenRepSequences()).contains(temp)) - { - continue; - } - - viewport.getAlignment().getSequences().setElementAt(temp, i); - viewport.getAlignment().getSequences().setElementAt(seq, i + 1); - } - } - + viewport.getAlignment().moveSelectedSequencesByOne(sg, up ? null : viewport.getHiddenRepSequences(), up); alignPanel.paintAlignment(true); } synchronized void slideSequences(boolean right, int size) { - Vector sg = new Vector(); + Listsg = new Vector(); if (viewport.cursorMode) { - sg.addElement(viewport.getAlignment() + sg.add(viewport.getAlignment() .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY)); } else if (viewport.getSelectionGroup() != null @@ -1522,7 +1487,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis return; } - Vector invertGroup = new Vector(); + Vector invertGroup = new Vector(); for (int i = 0; i < viewport.getAlignment().getHeight(); i++) { @@ -1530,13 +1495,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis invertGroup.addElement(viewport.getAlignment().getSequenceAt(i)); } - SequenceI[] seqs1 = new SequenceI[sg.size()]; - for (int i = 0; i < sg.size(); i++) - seqs1[i] = (SequenceI) sg.elementAt(i); + SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]); - SequenceI[] seqs2 = new SequenceI[invertGroup.size()]; + SequenceI[] seqs2 = invertGroup.toArray(new SequenceI[invertGroup.size()]); for (int i = 0; i < invertGroup.size(); i++) - seqs2[i] = (SequenceI) invertGroup.elementAt(i); + seqs2[i] = invertGroup.elementAt(i); SlideSequencesCommand ssc; if (right) @@ -1828,7 +1791,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * group consensus toggled - * + * */ protected void showGroupConsensus_actionPerformed() { @@ -1848,7 +1811,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /* * (non-Javadoc) - * + * * @see * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt * .event.ActionEvent) @@ -1860,7 +1823,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis } /* * (non-Javadoc) - * + * * @see * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt * .event.ActionEvent) @@ -1897,9 +1860,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis Color col = new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255)); col = col.brighter(); - for (Enumeration sq = gps[g].getSequences(null).elements(); sq - .hasMoreElements(); viewport.setSequenceColour( - (SequenceI) sq.nextElement(), col)) + for (SequenceI sq : gps[g].getSequences(null)) + viewport.setSequenceColour( + sq, col) ; } PaintRefresher.Refresh(this, viewport.getSequenceSetId()); @@ -2016,12 +1979,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis addHistoryItem(trimRegion); - Vector groups = viewport.getAlignment().getGroups(); - for (int i = 0; i < groups.size(); i++) - { - SequenceGroup sg = (SequenceGroup) groups.elementAt(i); + for (SequenceGroup sg:viewport.getAlignment().getGroups()) + { if ((trimLeft && !sg.adjustForRemoveLeft(column)) || (!trimLeft && !sg.adjustForRemoveRight(column))) { @@ -2113,7 +2074,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * create a new view derived from the current view - * + * * @param viewtitle * @return frame for the new view */ @@ -2186,7 +2147,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis } /** - * + * * @return list of feature groups on the view */ public String[] getFeatureGroups() @@ -2202,7 +2163,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * get sequence feature groups that are hidden or shown - * + * * @param visible * true is visible * @return list @@ -2220,7 +2181,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * Change the display state for the given feature groups - * + * * @param groups * list of group strings * @param state @@ -2288,11 +2249,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis overview.getPreferredSize().height + 50); frame.pack(); + final AlignmentPanel ap=alignPanel; frame.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { - alignPanel.setOverviewPanel(null); + if (ap!=null) { + ap.setOverviewPanel(null); + } }; }); @@ -2344,71 +2309,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis cs.setConsensus(viewport.getSequenceConsensusHash()); - } + } viewport.setGlobalColourScheme(cs); - if (viewport.getColourAppliesToAllGroups()) - { - Vector groups = viewport.getAlignment().getGroups(); - for (int i = 0; i < groups.size(); i++) - { - SequenceGroup sg = (SequenceGroup) groups.elementAt(i); - - if (cs == null) - { - sg.cs = null; - continue; - } - if (cs instanceof ClustalxColourScheme) - { - sg.cs = new ClustalxColourScheme( - sg.getSequences(viewport.getHiddenRepSequences()), - sg.getWidth()); - } - else - { - try - { - sg.cs = cs.getClass().newInstance(); - } catch (Exception ex) - { - ex.printStackTrace(); - sg.cs = cs; - } - } - - if (viewport.getAbovePIDThreshold() - || cs instanceof PIDColourScheme - || cs instanceof Blosum62ColourScheme) - { - sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - sg.cs.setConsensus(AAFrequency.calculate( - sg.getSequences(viewport.getHiddenRepSequences()), 0, - sg.getWidth())); - } - else - { - sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus()); - } - - if (viewport.getConservationSelected()) - { - Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, - sg.getSequences(viewport.getHiddenRepSequences()), 0, - viewport.getAlignment().getWidth() - 1); - c.calculate(); - c.verdict(false, viewport.getConsPercGaps()); - sg.cs.setConservation(c); - } - else - { - sg.cs.setConservation(null); - sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus()); - } - - } - } if (alignPanel.getOverviewPanel() != null) { @@ -2633,7 +2536,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * sort the alignment using the given treePanel - * + * * @param treePanel * tree used to sort view * @param title @@ -2654,7 +2557,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * Do any automatic reordering of the alignment and add the necessary bits to * the menu structure for the new tree - * + * * @param treePanel * @param title */ @@ -2665,14 +2568,16 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis sortByTreeMenu.add(item); item.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent evt) { sortByTree(treePanel, title); // treePanel.getTitle()); } }); - + treePanel.addWindowListener(new WindowAdapter() { + @Override public void windowOpened(WindowEvent e) { if (viewport.sortByTree) @@ -2682,6 +2587,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis super.windowOpened(e); } + @Override public void windowClosing(WindowEvent e) { sortByTreeMenu.remove(item); @@ -2725,6 +2631,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis this.builddate = builddate; } + @Override public void paint(Graphics g) { g.setColor(Color.white); @@ -2794,8 +2701,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis MenuItem loadTree = new MenuItem("Load Associated Tree ..."); MenuItem loadAnnotations = new MenuItem("Load Features/Annotations ..."); - - MenuItem loadScores = new MenuItem("Load Associated T-Coffee scores ..."); MenuItem outputFeatures = new MenuItem("Export Features ..."); @@ -2871,13 +2776,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis MenuItem purinePyrimidineColour = new MenuItem(); MenuItem RNAHelixColour = new MenuItem(); - + MenuItem userDefinedColour = new MenuItem(); MenuItem PIDColour = new MenuItem(); MenuItem BLOSUM62Colour = new MenuItem(); - + MenuItem tcoffeeColour = new MenuItem(); MenuItem njTreeBlosumMenuItem = new MenuItem(); @@ -2965,7 +2870,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis CheckboxMenuItem seqLimits = new CheckboxMenuItem(); CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem(); - + CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem(); Menu autoAnnMenu=new Menu(); CheckboxMenuItem showSequenceLogo= new CheckboxMenuItem(); @@ -2990,6 +2895,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis item.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { outputText_actionPerformed(e); @@ -3003,7 +2909,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis loadTree.addActionListener(this); loadAnnotations.addActionListener(this); - loadScores.addActionListener(this); outputFeatures.addActionListener(this); outputAnnotations.addActionListener(this); selectAllSequenceMenuItem.addActionListener(this); @@ -3191,7 +3096,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis applyAutoAnnotationSettings.setLabel("Apply to all groups"); applyAutoAnnotationSettings.setState(true); autoAnnMenu.setLabel("Autocalculated Annotation"); - + invertColSel.addActionListener(this); showColumns.addActionListener(this); showSeqs.addActionListener(this); @@ -3221,8 +3126,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis fileMenu.add(inputText); fileMenu.add(loadTree); fileMenu.add(loadAnnotations); - fileMenu.add(loadScores); - + fileMenu.addSeparator(); fileMenu.add(outputTextboxMenu); fileMenu.add(outputFeatures); @@ -3380,7 +3284,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis * Attach the alignFrame panels after embedding menus, if necessary. This used * to be called setEmbedded, but is now creates the dropdown menus in a * platform independent manner to avoid OSX/Mac menu appendage daftness. - * + * * @param reallyEmbedded * true to attach the view to the applet area on the page rather than * in a new window @@ -3408,14 +3312,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis final AlignFrame me = this; viewport.applet.addFocusListener(new FocusListener() { - + @Override public void focusLost(FocusEvent e) { if (me.viewport.applet.currentAlignFrame==me) { me.viewport.applet.currentAlignFrame = null; }} - + @Override public void focusGained(FocusEvent e) { @@ -3450,7 +3354,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis * structures in the original jmol window. Note This method doesn't work * without an additional javascript library to exchange messages between the * distinct applets. See http://issues.jalview.org/browse/JAL-621 - * + * * @param viewer * JmolViewer instance * @param sequenceIds @@ -3515,7 +3419,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis } /** * bind a pdb file to a sequence in the current view - * + * * @param sequenceId * - sequenceId within the dataset. * @param pdbEntryString @@ -3687,7 +3591,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis /** * modify the current selection, providing the user has not made a selection already. - * @param sel - sequences from this alignment + * @param sel - sequences from this alignment * @param csel - columns to be selected on the alignment */ public void select(SequenceGroup sel, ColumnSelection csel) @@ -3697,15 +3601,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis public void scrollTo(int row, int column) { - alignPanel.seqPanel.scrollTo(row, column); + alignPanel.seqPanel.scrollTo(row, column); } public void scrollToRow(int row) { - alignPanel.seqPanel.scrollToRow(row); + alignPanel.seqPanel.scrollToRow(row); } public void scrollToColumn(int column) { - alignPanel.seqPanel.scrollToColumn(column); + alignPanel.seqPanel.scrollToColumn(column); } /** * @return the alignments unique ID. @@ -3713,13 +3617,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis public String getSequenceSetId() { return viewport.getSequenceSetId(); } - - + + /** - * Load the (T-Coffee) score file from the specified url - * + * Load the (T-Coffee) score file from the specified url + * * @param source File/URL/T-COFFEE score file contents - * @throws IOException + * @throws IOException * @return true if alignment was annotated with data from source */ public boolean loadScoreFile( String source ) throws IOException { @@ -3731,17 +3635,17 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis System.err.println("Origin was:\n"+source); return false; } - + /* * check that the score matrix matches the alignment dimensions */ - AlignmentI aln; + AlignmentI aln; if( (aln=viewport.getAlignment()) != null && (aln.getHeight() != file.getHeight() || aln.getWidth() != file.getWidth()) ) { // TODO: raise a dialog box here rather than bomb out. System.err.println("The scores matrix does not match the alignment dimensions"); - + } - + // TODO add parameter to indicate if matching should be done if (file.annotateAlignment(alignPanel.getAlignment(), false)) { @@ -3758,6 +3662,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis } return false; } - - + + }