X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=fc59062bbf4c07f25da7cf1452e12464ed9ac170;hb=301ee338cd1b31b9d50cfd983e00513861940c27;hp=9bc4bc0146189b9e002ac4665abc3839cb025a6b;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 9bc4bc0..fc59062 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -13,12 +13,13 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * along with this program; if not, write to the Free Softwarechang * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.gui; import java.beans.*; +import java.io.*; import java.util.*; import java.awt.*; @@ -35,18 +36,34 @@ import jalview.jbgui.*; import jalview.schemes.*; import jalview.ws.*; +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class AlignFrame extends GAlignFrame { + /** DOCUMENT ME!! */ public static final int NEW_WINDOW_WIDTH = 700; + + /** DOCUMENT ME!! */ public static final int NEW_WINDOW_HEIGHT = 500; final AlignmentPanel alignPanel; final AlignViewport viewport; - public String currentFileFormat = "Jalview"; + + /** DOCUMENT ME!! */ + public String currentFileFormat = null; Stack historyList = new Stack(); Stack redoList = new Stack(); private int treeCount = 0; + /** + * Creates a new AlignFrame object. + * + * @param al DOCUMENT ME! + */ public AlignFrame(AlignmentI al) { viewport = new AlignViewport(al); @@ -74,8 +91,113 @@ public class AlignFrame }); } }); + addServiceListeners(); + } + + /* Set up intrinsic listeners for dynamically generated GUI bits. */ + private void addServiceListeners() + { + + final AlignFrame thisFrame = this; + final java.beans.PropertyChangeListener thisListener; + // Do this once to get current state + thisFrame.BuildWebServiceMenu(); + Desktop.discoverer.addPropertyChangeListener( + thisListener = new java.beans.PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + // System.out.println("Discoverer property change."); + if (evt.getPropertyName().equals("services")) + { + // System.out.println("Rebuilding web service menu"); + thisFrame.BuildWebServiceMenu(); + } + } + }); + addInternalFrameListener(new javax.swing.event. + InternalFrameAdapter() + { + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + // System.out.println("deregistering discoverer listener"); + Desktop.discoverer.removePropertyChangeListener(thisListener); + } + ; + }); + + } + + /** + * DOCUMENT ME! + * + * @param String DOCUMENT ME! + */ + + public void parseGroupsFile(String file) + { + try + { + BufferedReader in = new BufferedReader(new FileReader(file)); + SequenceI seq = null; + String line, text, token; + UserColourScheme ucs; + int index, start, end; + StringTokenizer st; + SequenceGroup sg; + while ( (line = in.readLine()) != null) + { + st = new StringTokenizer(line, "\t"); + if (st.countTokens() != 6) + { + System.out.println("Groups file " + file + + " is invalid. Read help file."); + System.exit(1); + } + + while (st.hasMoreElements()) + { + text = st.nextToken(); + token = st.nextToken(); + if (!token.equals("ID_NOT_SPECIFIED")) + { + index = viewport.alignment.findIndex(viewport.alignment.findName( + token)); + st.nextToken(); + } + else + { + index = Integer.parseInt(st.nextToken()); + } + + start = Integer.parseInt(st.nextToken()); + end = Integer.parseInt(st.nextToken()); + ucs = new UserColourScheme(st.nextToken()); + + seq = viewport.alignment.getSequenceAt(index); + start = seq.findIndex(start) - 1; + end = seq.findIndex(end) - 1; + + sg = new SequenceGroup(text, ucs, true, true, false, start, end); + sg.addSequence(seq, true); + + viewport.alignment.addGroup(sg); + } + } + + } + catch (Exception ex) + { + System.out.println("Error parsing groups file: " + ex); + } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void saveAlignmentMenu_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. @@ -104,43 +226,61 @@ public class AlignFrame jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat); - if (currentFileFormat.equals("Jalview")) - { - String shortName = title; + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - if (shortName.indexOf(java.io.File.separatorChar) > -1) - { - shortName = shortName.substring(shortName.lastIndexOf( - java.io.File.separatorChar) + 1); - } + saveAlignment(choice, currentFileFormat); + } + } - String choice = chooser.getSelectedFile().getPath(); - Jalview2XML.SaveState(this, choice, shortName); + public boolean saveAlignment(String file, String format) + { + if (format.equalsIgnoreCase("Jalview")) + { + String shortName = title; - // USE Jalview2XML to save this file - return; + if (shortName.indexOf(java.io.File.separatorChar) > -1) + { + shortName = shortName.substring(shortName.lastIndexOf( + java.io.File.separatorChar) + 1); } - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + Jalview2XML.SaveAlignment(this, file, shortName); - String output = FormatAdapter.formatSequences(currentFileFormat, - viewport.getAlignment().getSequences()); + // USE Jalview2XML to save this file + return true; + } + else + { + String output = FormatAdapter.formatSequences(format, + viewport.getAlignment(). + getSequences()); + if (output == null) + { + return false; + } try { - java.io.PrintWriter out = new java.io.PrintWriter(new java.io. - FileWriter( - choice)); + java.io.PrintWriter out = new java.io.PrintWriter( + new java.io.FileWriter(file)); out.println(output); out.close(); + return true; } catch (Exception ex) { + ex.printStackTrace(); } } + return false; } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void outputText_actionPerformed(ActionEvent e) { CutAndPasteTransfer cap = new CutAndPasteTransfer(); @@ -152,21 +292,46 @@ public class AlignFrame getSequences())); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void htmlMenuItem_actionPerformed(ActionEvent e) { new HTMLOutput(viewport); } - protected void createPNG_actionPerformed(ActionEvent e) + public void createImageMap(File file, String image) { - alignPanel.makePNG(); + alignPanel.makePNGImageMap(file, image); } - protected void epsFile_actionPerformed(ActionEvent e) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void createPNG(File f) { - alignPanel.makeEPS(); + alignPanel.makePNG(f); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void createEPS(File f) + { + alignPanel.makeEPS(f); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void printMenuItem_actionPerformed(ActionEvent e) { //Putting in a thread avoids Swing painting problems @@ -174,6 +339,11 @@ public class AlignFrame thread.start(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void closeMenuItem_actionPerformed(ActionEvent e) { try @@ -185,6 +355,9 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + */ void updateEditMenuBar() { if (historyList.size() > 0) @@ -214,12 +387,22 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + * + * @param hi DOCUMENT ME! + */ public void addHistoryItem(HistoryItem hi) { historyList.push(hi); updateEditMenuBar(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void undoMenuItem_actionPerformed(ActionEvent e) { HistoryItem hi = (HistoryItem) historyList.pop(); @@ -228,6 +411,11 @@ public class AlignFrame restoreHistoryItem(hi); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void redoMenuItem_actionPerformed(ActionEvent e) { HistoryItem hi = (HistoryItem) redoList.pop(); @@ -287,6 +475,11 @@ public class AlignFrame viewport.getAlignment().getSequences()); } + /** + * DOCUMENT ME! + * + * @param up DOCUMENT ME! + */ public void moveSelectedSequences(boolean up) { SequenceGroup sg = viewport.getSelectionGroup(); @@ -344,6 +537,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void copy_actionPerformed(ActionEvent e) { if (viewport.getSelectionGroup() == null) @@ -365,7 +563,8 @@ public class AlignFrame orderedSeqs.put(index + "", seq); } - int index = 0; + int index = 0, startRes, endRes; + char ch; for (int i = 0; i < sg.getSize(); i++) { @@ -385,22 +584,53 @@ public class AlignFrame index++; } } + //FIND START RES + //Returns residue following index if gap + startRes = seq.findPosition(sg.getStartRes()); + + //FIND END RES + //Need to find the residue preceeding index if gap + endRes = 0; + + for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++) + { + ch = seq.getCharAt(j); + if (!jalview.util.Comparison.isGap( (ch))) + { + endRes++; + } + } + + if (endRes > 0) + { + endRes += seq.getStart() - 1; + } buffer.append(seq.getName() + "\t" + - seq.findPosition(sg.getStartRes()) + "\t" + - seq.findPosition(sg.getEndRes()) + "\t" + - sg.getSequenceAt(i).getSequence(sg.getStartRes(), - sg.getEndRes() + 1) + "\n"); + startRes + "\t" + + endRes + "\t" + + seq.getSequence(sg.getStartRes(), + sg.getEndRes() + 1) + "\n"); } c.setContents(new StringSelection(buffer.toString()), null); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void pasteNew_actionPerformed(ActionEvent e) { paste(true); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void pasteThis_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, @@ -408,6 +638,11 @@ public class AlignFrame paste(false); } + /** + * DOCUMENT ME! + * + * @param newAlignment DOCUMENT ME! + */ void paste(boolean newAlignment) { try @@ -480,12 +715,22 @@ public class AlignFrame // could be anything being pasted in here } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void cut_actionPerformed(ActionEvent e) { copy_actionPerformed(null); delete_actionPerformed(null); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void delete_actionPerformed(ActionEvent e) { boolean seqsdeleted = false; @@ -499,6 +744,11 @@ public class AlignFrame HistoryItem.HIDE)); SequenceGroup sg = viewport.getSelectionGroup(); + boolean allSequences = false; + if (sg.sequences.size() == viewport.alignment.getHeight()) + { + allSequences = true; + } for (int i = 0; i < sg.sequences.size(); i++) { @@ -506,6 +756,13 @@ public class AlignFrame int index = viewport.getAlignment().findIndex(seq); seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1); + // If the cut affects all sequences, remove highlighted columns + if (allSequences) + { + viewport.getColumnSelection().removeElements(sg.getStartRes(), + sg.getEndRes() + 1); + } + if (seq.getSequence().length() < 1) { seqsdeleted = true; @@ -544,6 +801,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void deleteGroups_actionPerformed(ActionEvent e) { viewport.alignment.deleteAllGroups(); @@ -551,6 +813,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) { SequenceGroup sg = new SequenceGroup(); @@ -558,35 +825,58 @@ public class AlignFrame for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++) { - sg.addSequence(viewport.getAlignment().getSequenceAt(i)); + sg.addSequence(viewport.getAlignment().getSequenceAt(i), false); } - sg.setEndRes(viewport.alignment.getWidth()); + sg.setEndRes(viewport.alignment.getWidth() - 1); viewport.setSelectionGroup(sg); - PaintRefresher.Refresh(null); + PaintRefresher.Refresh(null, viewport.alignment); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e) { viewport.setSelectionGroup(null); viewport.getColumnSelection().clear(); viewport.setSelectionGroup(null); - PaintRefresher.Refresh(null); + alignPanel.annotationPanel.activeRes = null; + PaintRefresher.Refresh(null, viewport.alignment); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void invertSequenceMenuItem_actionPerformed(ActionEvent e) { SequenceGroup sg = viewport.getSelectionGroup(); + if (sg == null) + { + selectAllSequenceMenuItem_actionPerformed(null); + + return; + } + for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++) { - sg.addOrRemove(viewport.getAlignment().getSequenceAt(i)); + sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false); } - PaintRefresher.Refresh(null); + PaintRefresher.Refresh(null, viewport.alignment); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void remove2LeftMenuItem_actionPerformed(ActionEvent e) { ColumnSelection colSel = viewport.getColumnSelection(); @@ -621,6 +911,11 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void remove2RightMenuItem_actionPerformed(ActionEvent e) { ColumnSelection colSel = viewport.getColumnSelection(); @@ -654,6 +949,11 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Remove Gapped Columns", @@ -665,6 +965,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment, @@ -673,13 +978,32 @@ public class AlignFrame SequenceI current; int jSize; - for (int i = 0; i < viewport.getAlignment().getSequences().size(); - i++) + Vector seqs = null; + + int start = 0; + int end = viewport.alignment.getWidth(); + + if (viewport.getSelectionGroup() != null + && viewport.getSelectionGroup().sequences != null + && viewport.getSelectionGroup().sequences.size() > 0) { - current = viewport.getAlignment().getSequenceAt(i); + seqs = viewport.getSelectionGroup().sequences; + start = viewport.getSelectionGroup().getStartRes(); + end = viewport.getSelectionGroup().getEndRes(); + } + else + { + seqs = viewport.alignment.getSequences(); + } + + for (int i = 0; i < seqs.size(); i++) + { + current = (SequenceI) seqs.elementAt(i); jSize = current.getLength(); - for (int j = 0; j < jSize; j++) + int j = start; + + do { if (jalview.util.Comparison.isGap(current.getCharAt(j))) { @@ -687,7 +1011,9 @@ public class AlignFrame j--; jSize--; } + j++; } + while (j < end && j < jSize); } viewport.updateConservation(); @@ -695,13 +1021,18 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void padGapsMenuitem_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, HistoryItem.HIDE)); SequenceI current; - int Width = viewport.getAlignment().getWidth() - 1; + int Width = viewport.getAlignment().getWidth(); for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++) @@ -710,7 +1041,7 @@ public class AlignFrame if (current.getLength() < Width) { - current.insertCharAt(Width, viewport.getGapCharacter()); + current.insertCharAt(Width - 1, viewport.getGapCharacter()); } } @@ -719,6 +1050,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void findMenuItem_actionPerformed(ActionEvent e) { JInternalFrame frame = new JInternalFrame(); @@ -728,11 +1064,21 @@ public class AlignFrame frame.setLayer(JLayeredPane.PALETTE_LAYER); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void font_actionPerformed(ActionEvent e) { FontChooser fc = new FontChooser(alignPanel); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void fullSeqId_actionPerformed(ActionEvent e) { viewport.setShowFullId(fullSeqId.isSelected()); @@ -741,12 +1087,22 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void colourTextMenuItem_actionPerformed(ActionEvent e) { viewport.setColourText(colourTextMenuItem.isSelected()); alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void wrapMenuItem_actionPerformed(ActionEvent e) { viewport.setWrapAlignment(wrapMenuItem.isSelected()); @@ -757,42 +1113,77 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void scaleAbove_actionPerformed(ActionEvent e) { viewport.setScaleAboveWrapped(scaleAbove.isSelected()); alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void scaleLeft_actionPerformed(ActionEvent e) { viewport.setScaleLeftWrapped(scaleLeft.isSelected()); alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void scaleRight_actionPerformed(ActionEvent e) { viewport.setScaleRightWrapped(scaleRight.isSelected()); alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { viewport.setShowBoxes(viewBoxesMenuItem.isSelected()); alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void viewTextMenuItem_actionPerformed(ActionEvent e) { viewport.setShowText(viewTextMenuItem.isSelected()); alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void renderGapsMenuItem_actionPerformed(ActionEvent e) { viewport.setRenderGaps(renderGapsMenuItem.isSelected()); alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ public void sequenceFeatures_actionPerformed(ActionEvent evt) { viewport.showSequenceFeatures(sequenceFeatures.isSelected()); @@ -809,6 +1200,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void annotationPanelMenuItem_actionPerformed(ActionEvent e) { if (annotationPanelMenuItem.isSelected() && @@ -823,6 +1219,11 @@ public class AlignFrame alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void overviewMenuItem_actionPerformed(ActionEvent e) { if (alignPanel.overviewPanel != null) @@ -850,124 +1251,170 @@ public class AlignFrame alignPanel.setOverviewPanel(overview); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void noColourmenuItem_actionPerformed(ActionEvent e) { changeColour(null); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void clustalColour_actionPerformed(ActionEvent e) { changeColour(new ClustalxColourScheme( viewport.alignment.getSequences(), viewport.alignment.getWidth())); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void zappoColour_actionPerformed(ActionEvent e) { changeColour(new ZappoColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void taylorColour_actionPerformed(ActionEvent e) { changeColour(new TaylorColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void hydrophobicityColour_actionPerformed(ActionEvent e) { changeColour(new HydrophobicColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void helixColour_actionPerformed(ActionEvent e) { changeColour(new HelixColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void strandColour_actionPerformed(ActionEvent e) { changeColour(new StrandColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void turnColour_actionPerformed(ActionEvent e) { changeColour(new TurnColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void buriedColour_actionPerformed(ActionEvent e) { changeColour(new BuriedColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void nucleotideColour_actionPerformed(ActionEvent e) { changeColour(new NucleotideColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void applyToAllGroups_actionPerformed(ActionEvent e) { viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected()); } + /** + * DOCUMENT ME! + * + * @param cs DOCUMENT ME! + */ void changeColour(ColourSchemeI cs) { int threshold = 0; - if (viewport.getAbovePIDThreshold()) + if(cs!=null) { - threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, - "Background"); - - if (cs instanceof ResidueColourScheme) + if (viewport.getAbovePIDThreshold()) { - ( (ResidueColourScheme) cs).setThreshold(threshold); + threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, + "Background"); + + cs.setThreshold(threshold, + viewport.getIgnoreGapsConsensus()); + + viewport.setGlobalColourScheme(cs); } - else if (cs instanceof ScoreColourScheme) + else { - ( (ScoreColourScheme) cs).setThreshold(threshold); + cs.setThreshold(0, viewport.getIgnoreGapsConsensus()); } - viewport.setGlobalColourScheme(cs); - } - else if (cs instanceof ResidueColourScheme) - { - ( (ResidueColourScheme) cs).setThreshold(0); - } - else if (cs instanceof ScoreColourScheme) - { - ( (ScoreColourScheme) cs).setThreshold(0); - } - - if (viewport.getConservationSelected()) - { - ConservationColourScheme ccs = null; - - Alignment al = (Alignment) viewport.alignment; - Conservation c = new Conservation("All", - ResidueProperties.propHash, 3, - al.getSequences(), 0, - al.getWidth() - 1); + if (viewport.getConservationSelected()) + { - c.calculate(); - c.verdict(false, viewport.ConsPercGaps); + Alignment al = (Alignment) viewport.alignment; + Conservation c = new Conservation("All", + ResidueProperties.propHash, 3, + al.getSequences(), 0, + al.getWidth() - 1); - ccs = new ConservationColourScheme(c, cs); + c.calculate(); + c.verdict(false, viewport.ConsPercGaps); - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - ccs.setConsensus(viewport.vconsensus); - viewport.setGlobalColourScheme(ccs); + cs.setConservation(c); - ccs.inc = SliderPanel.setConservationSlider(alignPanel, ccs, - "Background"); - } - else - { - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - if (cs != null) + cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs, + "Background")); + } + else { - cs.setConsensus(viewport.vconsensus); + cs.setConservation(null); } - viewport.setGlobalColourScheme(cs); + cs.setConsensus(viewport.vconsensus); } + viewport.setGlobalColourScheme(cs); + if (viewport.getColourAppliesToAllGroups()) { Vector groups = viewport.alignment.getGroups(); @@ -979,8 +1426,10 @@ public class AlignFrame if (cs == null) { sg.cs = null; + continue; } - else if (cs instanceof ClustalxColourScheme) + + if (cs instanceof ClustalxColourScheme) { sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth()); } @@ -1001,18 +1450,15 @@ public class AlignFrame if (viewport.getAbovePIDThreshold()) { - if (sg.cs instanceof ResidueColourScheme) - { - ( (ResidueColourScheme) sg.cs).setThreshold(threshold); - } - else if (sg.cs instanceof ScoreColourScheme) - { - ( (ScoreColourScheme) sg.cs).setThreshold(threshold); - } + sg.cs.setThreshold(threshold, + viewport.getIgnoreGapsConsensus()); sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth())); } + else + sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus()); + if (viewport.getConservationSelected()) { @@ -1022,21 +1468,10 @@ public class AlignFrame viewport.alignment.getWidth() - 1); c.calculate(); c.verdict(false, viewport.ConsPercGaps); - - ConservationColourScheme ccs = new ConservationColourScheme(c, - sg.cs); - - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - ccs.setConsensus(AAFrequency.calculate(sg.sequences, 0, - sg.getWidth())); - sg.cs = ccs; - } - else if (cs != null) - { - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, - sg.getWidth())); + sg.cs.setConservation(c); } + else + sg.cs.setConservation(null); } } @@ -1048,9 +1483,14 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void modifyPID_actionPerformed(ActionEvent e) { - if (viewport.getAbovePIDThreshold()) + if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null) { SliderPanel.setPIDSliderSource(alignPanel, viewport.getGlobalColourScheme(), @@ -1059,9 +1499,14 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void modifyConservation_actionPerformed(ActionEvent e) { - if (viewport.getConservationSelected()) + if (viewport.getConservationSelected() && viewport.globalColourScheme!=null) { SliderPanel.setConservationSlider(alignPanel, viewport.globalColourScheme, @@ -1070,6 +1515,11 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void conservationMenuItem_actionPerformed(ActionEvent e) { viewport.setConservationSelected(conservationMenuItem.isSelected()); @@ -1077,20 +1527,16 @@ public class AlignFrame viewport.setAbovePIDThreshold(false); abovePIDThreshold.setSelected(false); - ColourSchemeI cs = viewport.getGlobalColourScheme(); - - if (cs instanceof ConservationColourScheme) - { - changeColour( ( (ConservationColourScheme) cs).cs); - } - else - { - changeColour(cs); - } + changeColour(viewport.getGlobalColourScheme()); modifyConservation_actionPerformed(null); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void abovePIDThreshold_actionPerformed(ActionEvent e) { viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected()); @@ -1100,33 +1546,122 @@ public class AlignFrame ColourSchemeI cs = viewport.getGlobalColourScheme(); - if (cs instanceof ConservationColourScheme) + changeColour(viewport.getGlobalColourScheme()); + + modifyPID_actionPerformed(null); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void userDefinedColour_actionPerformed(ActionEvent e) + { + if (e.getActionCommand().equals("User Defined...")) { - changeColour( ( (ConservationColourScheme) cs).cs); + new UserDefinedColours(alignPanel, null); } else { - changeColour(cs); - } + UserColourScheme udc = (UserColourScheme) UserDefinedColours. + getUserColourSchemes().get(e.getActionCommand()); - modifyPID_actionPerformed(null); + changeColour(udc); + } } - public void userDefinedColour_actionPerformed(ActionEvent e) + public void updateUserColourMenu() { - new UserDefinedColours(alignPanel, null); + + Component[] menuItems = colourMenu.getMenuComponents(); + int i, iSize = menuItems.length; + for (i = 0; i < iSize; i++) + { + if (menuItems[i].getName() != null && + menuItems[i].getName().equals("USER_DEFINED")) + { + colourMenu.remove(menuItems[i]); + iSize--; + } + } + if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null) + { + java.util.Enumeration userColours = jalview.gui.UserDefinedColours. + getUserColourSchemes().keys(); + + while (userColours.hasMoreElements()) + { + final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours. + nextElement().toString()); + radioItem.setName("USER_DEFINED"); + radioItem.addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent evt) + { + if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt)) + { + radioItem.removeActionListener(radioItem.getActionListeners()[0]); + + int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop, + "Remove from default list?", + "Remove user defined colour", + JOptionPane.YES_NO_OPTION); + if(option == JOptionPane.YES_OPTION) + { + jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText()); + colourMenu.remove(radioItem); + } + else + radioItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + userDefinedColour_actionPerformed(evt); + } + }); + } + } + }); + radioItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + userDefinedColour_actionPerformed(evt); + } + }); + + colourMenu.insert(radioItem, 15); + colours.add(radioItem); + } + } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void PIDColour_actionPerformed(ActionEvent e) { changeColour(new PIDColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void BLOSUM62Colour_actionPerformed(ActionEvent e) { changeColour(new Blosum62ColourScheme()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void sortPairwiseMenuItem_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, @@ -1136,6 +1671,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void sortIDMenuItem_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, @@ -1144,16 +1684,25 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void sortGroupMenuItem_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, HistoryItem.SORT)); - // AlignmentSorter.sortByGroup(viewport.getAlignment()); - AlignmentSorter.sortGroups(viewport.getAlignment()); + AlignmentSorter.sortByGroup(viewport.getAlignment()); alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void removeRedundancyMenuItem_actionPerformed(ActionEvent e) { RedundancyPanel sp = new RedundancyPanel(alignPanel, this); @@ -1163,6 +1712,11 @@ public class AlignFrame 100, false); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e) { if ( (viewport.getSelectionGroup() == null) || @@ -1181,6 +1735,11 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void PCAMenuItem_actionPerformed(ActionEvent e) { if ( ( (viewport.getSelectionGroup() != null) && @@ -1214,29 +1773,55 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) { NewTreePanel("AV", "PID", "Average distance tree using PID"); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void neighbourTreeMenuItem_actionPerformed(ActionEvent e) { NewTreePanel("NJ", "PID", "Neighbour joining tree using PID"); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) { NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) { NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62"); } + /** + * DOCUMENT ME! + * + * @param type DOCUMENT ME! + * @param pwType DOCUMENT ME! + * @param title DOCUMENT ME! + */ void NewTreePanel(String type, String pwType, String title) { - String ltitle; final TreePanel tp; if ( (viewport.getSelectionGroup() != null) && @@ -1294,6 +1879,12 @@ public class AlignFrame Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500); } + /** + * DOCUMENT ME! + * + * @param title DOCUMENT ME! + * @param order DOCUMENT ME! + */ public void addSortByOrderMenuItem(String title, final AlignmentOrder order) { final JMenuItem item = new JMenuItem("by " + title); @@ -1312,6 +1903,15 @@ public class AlignFrame }); } + /** + * Maintain the Order by->Displayed Tree menu. + * Creates a new menu item for a TreePanel with an appropriate + * jalview.analysis.AlignmentSorter call. Listeners are added + * to remove the menu item when the treePanel is closed, and adjust + * the tree leaf to sequence mapping when the alignment is modified. + * @param treePanel Displayed tree window. + * @param title SortBy menu item title. + */ void addTreeMenuItem(final TreePanel treePanel, String title) { final JMenuItem item = new JMenuItem(title); @@ -1365,9 +1965,13 @@ public class AlignFrame }); } - public void clustalAlignMenuItem_actionPerformed(ActionEvent e) + /** + * Work out whether the whole set of sequences + * or just the selected set will be submitted for multiple alignment. + * + */ + private SequenceI[] gatherSequencesForAlignment() { - // TODO:resolve which menu item was actually selected // Now, check we have enough sequences SequenceI[] msa = null; @@ -1398,56 +2002,16 @@ public class AlignFrame } } } - - if (msa != null) - { - jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", - title, msa, false, true); - } + return msa; } - public void ClustalRealign_actionPerformed(ActionEvent e) - { - // TODO:resolve which menu item was actually selected - // Now, check we have enough sequences - SequenceI[] msa = null; - - if ( (viewport.getSelectionGroup() != null) && - (viewport.getSelectionGroup().getSize() > 1)) - { - // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! - SequenceGroup seqs = viewport.getSelectionGroup(); - int sz; - msa = new SequenceI[sz = seqs.getSize()]; - - for (int i = 0; i < sz; i++) - { - msa[i] = (SequenceI) seqs.getSequenceAt(i); - } - } - else - { - Vector seqs = viewport.getAlignment().getSequences(); - - if (seqs.size() > 1) - { - msa = new SequenceI[seqs.size()]; - - for (int i = 0; i < seqs.size(); i++) - { - msa[i] = (SequenceI) seqs.elementAt(i); - } - } - } - - if (msa != null) - { - jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", - title, msa, true, true); - } - } - - protected void jpred_actionPerformed(ActionEvent e) + /** + * Decides what is submitted to a secondary structure prediction service, + * the currently selected sequence, or the currently selected alignment + * (where the first sequence in the set is the one that the prediction + * will be for). + */ + SequenceI[] gatherSeqOrMsaForSecStrPrediction() { SequenceI seq = null; SequenceI[] msa = null; @@ -1491,63 +2055,26 @@ public class AlignFrame } } } - if (msa != null) { - JPredClient ct = new JPredClient(title, msa); - } - else if (seq != null) - { - JPredClient ct = new JPredClient(title, seq); + return msa; } else { - System.err.print( - "JALVIEW ERROR! - Unexpected JPred selection state!\n"); - } - } - - protected void msaAlignMenuItem_actionPerformed(ActionEvent e) - { - // TODO:resolve which menu item was actually selected - // Now, check we have enough sequences - SequenceI[] msa = null; - - if ( (viewport.getSelectionGroup() != null) && - (viewport.getSelectionGroup().getSize() > 1)) - { - // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! - SequenceGroup seqs = viewport.getSelectionGroup(); - int sz; - msa = new SequenceI[sz = seqs.getSize()]; - - for (int i = 0; i < sz; i++) + if (seq != null) { - msa[i] = (SequenceI) seqs.getSequenceAt(i); + return new SequenceI[] + { + seq}; } } - else - { - Vector seqs = viewport.getAlignment().getSequences(); - - if (seqs.size() > 1) - { - msa = new SequenceI[seqs.size()]; - - for (int i = 0; i < seqs.size(); i++) - { - msa[i] = (SequenceI) seqs.elementAt(i); - } - } - } - - if (msa != null) - { - MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS", title, msa, - false, true); - } + return null; } - + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) { // Pick the tree file @@ -1569,7 +2096,7 @@ public class AlignFrame { jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File"); - ShowNewickTree(fin, choice); + viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree()); } catch (Exception ex) { @@ -1582,27 +2109,38 @@ public class AlignFrame } } - public void ShowNewickTree(NewickFile nf, String title) + /** + * DOCUMENT ME! + * + * @param nf DOCUMENT ME! + * @param title DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public TreePanel ShowNewickTree(NewickFile nf, String title) { + TreePanel tp = null; + try { nf.parse(); if (nf.getTree() != null) { - TreePanel tp = new TreePanel(viewport, - viewport.getAlignment().getSequences(), nf, - "FromFile", - title); + tp = new TreePanel(viewport, + viewport.getAlignment().getSequences(), nf, + "FromFile", + title); Desktop.addInternalFrame(tp, title, 600, 500); addTreeMenuItem(tp, title); - viewport.setCurrentTree(tp.getTree()); } } catch (Exception ex) { ex.printStackTrace(); } + + return tp; } class PrintThread @@ -1627,4 +2165,111 @@ public class AlignFrame } } } + + /** + * Generates menu items and listener event actions for web service clients + * + */ + public void BuildWebServiceMenu() + { + if ( (Desktop.discoverer.services != null) + && (Desktop.discoverer.services.size() > 0)) + { + Vector msaws = (Vector) Desktop.discoverer.services.get("MsaWS"); + Vector secstrpr = (Vector) Desktop.discoverer.services.get("SecStrPred"); + Vector wsmenu = new Vector(); + if (msaws != null) + { + // Add any Multiple Sequence Alignment Services + final JMenu msawsmenu = new JMenu("Alignment"); + for (int i = 0, j = msaws.size(); i < j; i++) + { + final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws. + get(i); + final JMenuItem method = new JMenuItem(sh.getName()); + method.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + SequenceI[] msa = gatherSequencesForAlignment(); + MsaWSClient ct = new jalview.ws.MsaWSClient(sh, title, msa, + false, true); + + } + + }); + msawsmenu.add(method); + // Deal with services that we know accept partial alignments. + if (sh.getName().indexOf("lustal") > -1) + { + // We know that ClustalWS can accept partial alignments for refinement. + final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign"); + methodR.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + SequenceI[] msa = gatherSequencesForAlignment(); + MsaWSClient ct = new jalview.ws.MsaWSClient(sh, title, msa, + true, true); + + } + + }); + msawsmenu.add(methodR); + + } + } + wsmenu.add(msawsmenu); + } + if (secstrpr != null) + { + // Add any secondary structure prediction services + final JMenu secstrmenu = new JMenu("Secondary Structure Prediction"); + for (int i = 0, j = secstrpr.size(); i < j; i++) + { + final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) + secstrpr.get(i); + final JMenuItem method = new JMenuItem(sh.getName()); + method.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + SequenceI[] msa = gatherSeqOrMsaForSecStrPrediction(); + if (msa.length == 1) + { + // Single Sequence prediction + jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh, + title, msa[0]); + } + else + { + if (msa.length > 1) + { + // Single Sequence prediction + jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh, + title, msa); + } + } + } + }); + secstrmenu.add(method); + } + wsmenu.add(secstrmenu); + } + this.webService.removeAll(); + for (int i = 0, j = wsmenu.size(); i < j; i++) + { + webService.add( (JMenu) wsmenu.get(i)); + } + } + else + { + this.webService.removeAll(); + this.webService.add(this.webServiceNoServices); + } + // TODO: add in rediscovery function + // TODO: reduce code redundancy. + // TODO: group services by location as well as function. + } + }