X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=b2dc4ca92cb134f80b07ab237ec28ce91f165aa4;hb=b3b59df08fc4183bb35e4ed5a54841a990b71346;hp=79f1e8b47cfa82dd871ecc698d65d1742a1040f3;hpb=f3bc67915e61855d87866b4a614fe7a953813408;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 79f1e8b..b2dc4ca 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -34,9 +34,9 @@ import jalview.io.*; import jalview.jbgui.*; import jalview.schemes.*; import jalview.util.ShiftList; +import jalview.commands.*; import jalview.ws.*; import java.awt.dnd.*; -import org.biojava.dasobert.eventmodel.*; /** * DOCUMENT ME! @@ -44,8 +44,7 @@ import org.biojava.dasobert.eventmodel.*; * @author $author$ * @version $Revision$ */ -public class AlignFrame - extends GAlignFrame implements DropTargetListener, FeatureListener +public class AlignFrame extends GAlignFrame implements DropTargetListener { /** DOCUMENT ME!! */ public static final int DEFAULT_WIDTH = 700; @@ -107,6 +106,7 @@ public class AlignFrame { viewport = ap.av; alignPanel = ap; + alignPanel.alignFrame = this; addAlignmentPanel(ap); init(); } @@ -115,15 +115,14 @@ public class AlignFrame { this.setDropTarget(new java.awt.dnd.DropTarget(this, this)); - if (viewport.vconsensus == null) + if (viewport.conservation == null) { - //Out of memory calculating consensus. BLOSUM62Colour.setEnabled(false); - PIDColour.setEnabled(false); conservationMenuItem.setEnabled(false); modifyConservation.setEnabled(false); - abovePIDThreshold.setEnabled(false); - modifyPID.setEnabled(false); + // PIDColour.setEnabled(false); + // abovePIDThreshold.setEnabled(false); + // modifyPID.setEnabled(false); } String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort"); @@ -415,6 +414,9 @@ public class AlignFrame tabbedPane.addTab(ap.av.viewName==null?"Original":ap.av.viewName, ap); } + ap.av.updateConsensus(ap); + ap.av.updateConservation(ap); + ap.av.addPropertyChangeListener(new PropertyChangeListener() { @@ -487,17 +489,6 @@ public class AlignFrame } } - public void comeBackLater(FeatureEvent evt) - {} - - public void newFeatures(FeatureEvent evt) - { - if (evt.getFeatures().length > 0) - { - alignPanel.seqPanel.seqCanvas.fr.featuresAdded(); - alignPanel.repaint(); - } - } Hashtable progressBars; public void setProgressBar(String message, long id) @@ -538,6 +529,8 @@ public class AlignFrame } + + /* Added so Castor Mapping file can obtain Jalview Version */ @@ -832,12 +825,12 @@ public class AlignFrame */ void updateEditMenuBar() { + if (historyList.size() > 0) { undoMenuItem.setEnabled(true); - - HistoryItem hi = (HistoryItem) historyList.peek(); - undoMenuItem.setText("Undo " + hi.getDescription()); + CommandI command = (CommandI) historyList.peek(); + undoMenuItem.setText("Undo " + command.getDescription()); } else { @@ -849,8 +842,8 @@ public class AlignFrame { redoMenuItem.setEnabled(true); - HistoryItem hi = (HistoryItem) redoList.peek(); - redoMenuItem.setText("Redo " + hi.getDescription()); + CommandI command = (CommandI) redoList.peek(); + redoMenuItem.setText("Redo " + command.getDescription()); } else { @@ -859,18 +852,18 @@ public class AlignFrame } } - /** - * DOCUMENT ME! - * - * @param hi DOCUMENT ME! - */ - public void addHistoryItem(HistoryItem hi) + + public void addHistoryItem(CommandI command) { - historyList.push(hi); + historyList.push(command); redoList.clear(); updateEditMenuBar(); + + viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null; } + + /** * DOCUMENT ME! * @@ -878,12 +871,18 @@ public class AlignFrame */ protected void undoMenuItem_actionPerformed(ActionEvent e) { - HistoryItem nh,hi = (HistoryItem) historyList.pop(); - redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment, - HistoryItem.HIDE)); - if (hi.alColumnChanges!=null) - nh.alColumnChanges = hi.alColumnChanges.getInverse(); - restoreHistoryItem(hi); + CommandI command = (CommandI)historyList.pop(); + redoList.push(command); + command.undoCommand(); + + // HistoryItem nh,hi = (HistoryItem) historyList.pop(); + // redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment, + // HistoryItem.HIDE)); + // if (hi.alColumnChanges!=null) + // nh.alColumnChanges = hi.alColumnChanges.getInverse(); + // restoreHistoryItem(hi); + viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null; + updateEditMenuBar(); viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } @@ -894,27 +893,21 @@ public class AlignFrame */ protected void redoMenuItem_actionPerformed(ActionEvent e) { - HistoryItem nh,hi = (HistoryItem) redoList.pop(); - historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment, - HistoryItem.HIDE)); - if (hi.alColumnChanges!=null) - nh.alColumnChanges=hi.alColumnChanges.getInverse(); - restoreHistoryItem(hi); + CommandI command = (CommandI) redoList.pop(); + historyList.push(command); + command.doCommand(); + viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null; + + // HistoryItem nh,hi = (HistoryItem) redoList.pop(); + // historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment, + // HistoryItem.HIDE)); + // if (hi.alColumnChanges!=null) + // nh.alColumnChanges=hi.alColumnChanges.getInverse(); + // restoreHistoryItem(hi); updateEditMenuBar(); viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } - // used by undo and redo - void restoreHistoryItem(HistoryItem hi) - { - - hi.restore(viewport.getColumnSelection()); - - updateEditMenuBar(); - - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); - } /** * DOCUMENT ME! @@ -1077,8 +1070,6 @@ public class AlignFrame */ protected void pasteThis_actionPerformed(ActionEvent e) { - addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, - HistoryItem.PASTE)); paste(false); } @@ -1158,19 +1149,33 @@ public class AlignFrame alignment = viewport.getAlignment(); //!newAlignment + SequenceI [] newseqs = new SequenceI[sequences.length]; for (int i = 0; i < sequences.length; i++) { - Sequence newseq = new Sequence(sequences[i].getName(), + newseqs[i] = new Sequence(sequences[i].getName(), sequences[i].getSequence(), sequences[i].getStart(), sequences[i].getEnd()); - alignment.addSequence(newseq); + alignment.addSequence(newseqs[i]); PaintRefresher.Refresh(alignPanel, alignPanel.av.getSequenceSetId(), - null,newseq); + null,newseqs[i]); } + /* + //ADD HISTORY ITEM + */ + addHistoryItem(new EditCommand( + "Add sequences", + EditCommand.PASTE, + newseqs, + 0, + alignment.getWidth(), + alignment) + ); + + viewport.setEndSeq(alignment.getHeight()); alignment.getWidth(); viewport.firePropertyChange("alignment", null, alignment.getSequences()); @@ -1273,43 +1278,48 @@ public class AlignFrame protected void delete_actionPerformed(ActionEvent e) { - if (viewport.getSelectionGroup() == null) + SequenceGroup sg = viewport.getSelectionGroup(); + if (sg == null) { return; } - - SequenceGroup sg = viewport.getSelectionGroup(); - - - addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, - HistoryItem.HIDE)); - - + Vector seqs = new Vector(); + int cutLength = sg.getEndRes()-sg.getStartRes()+1; + SequenceI seq; for (int i = 0; i < sg.getSize(false); i++) { - SequenceI seq = sg.getSequenceAt(i); - int index = viewport.getAlignment().findIndex(seq); + seq = sg.getSequenceAt(i); + seqs.addElement(seq); + if(seq.getLength()<=cutLength) + PaintRefresher.Refresh(alignPanel, + alignPanel.av.getSequenceSetId(), + seq, + null); + } - seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1); + // If the cut affects all sequences, remove highlighted columns + if (sg.getSize(false) == viewport.alignment.getHeight()) + { + viewport.getColumnSelection().removeElements(sg.getStartRes(), + sg.getEndRes() + 1); + } - // If the cut affects all sequences, remove highlighted columns - if (sg.getSize(false) == viewport.alignment.getHeight()) - { - viewport.getColumnSelection().removeElements(sg.getStartRes(), - sg.getEndRes() + 1); - } - if (seq.getSequence().length() < 1) - { - viewport.getAlignment().deleteSequence(seq); - PaintRefresher.Refresh(alignPanel,alignPanel.av.getSequenceSetId(),seq,null); - } - else - { - viewport.getAlignment().getSequences().setElementAt(seq, index); - } - } + SequenceI [] cut = new SequenceI[seqs.size()]; + for(int i=0; i 0) - { - HistoryItem edit; - addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment, - HistoryItem.HIDE)); - - int min = colSel.getMin(); - viewport.getAlignment().trimLeft(min); - colSel.compensateForEdit(0, min); - edit.addShift(0,min); - if (viewport.getSelectionGroup() != null) - { - viewport.getSelectionGroup().adjustForRemoveLeft(min); - } - - Vector groups = viewport.alignment.getGroups(); - - for (int i = 0; i < groups.size(); i++) - { - SequenceGroup sg = (SequenceGroup) groups.get(i); - - if (!sg.adjustForRemoveLeft(min)) - { - viewport.alignment.deleteGroup(sg); - } - } - - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); - } + trimAlignment(true); } /** @@ -1465,21 +1443,51 @@ public class AlignFrame */ public void remove2RightMenuItem_actionPerformed(ActionEvent e) { + trimAlignment(false); + } + + void trimAlignment(boolean trimLeft) + { ColumnSelection colSel = viewport.getColumnSelection(); + int column; if (colSel.size() > 0) { - addHistoryItem(new HistoryItem("Remove Right", viewport.alignment, - HistoryItem.HIDE)); + if(trimLeft) + column = colSel.getMin(); + else + column = colSel.getMax(); + + SequenceI [] seqs; + if(viewport.getSelectionGroup()!=null) + seqs = viewport.getSelectionGroup().getSequencesAsArray(true); + else + seqs = viewport.alignment.getSequencesArray(); + - int max = colSel.getMax(); - viewport.getAlignment().trimRight(max); - // TODO: delete hidden column entries in colSel to right of max - // TODO: record hidden columns in history for undo. - if (viewport.getSelectionGroup() != null) + TrimRegionCommand trimRegion; + if(trimLeft) { - viewport.getSelectionGroup().adjustForRemoveRight(max); + trimRegion = new TrimRegionCommand("Remove Left", + TrimRegionCommand.TRIM_LEFT, + seqs, + column, + viewport.alignment, + viewport.colSel, + viewport.selectionGroup); } + else + { + trimRegion = new TrimRegionCommand("Remove Right", + TrimRegionCommand.TRIM_RIGHT, + seqs, + column, + viewport.alignment, + viewport.colSel, + viewport.selectionGroup); + } + + addHistoryItem(trimRegion); Vector groups = viewport.alignment.getGroups(); @@ -1487,7 +1495,8 @@ public class AlignFrame { SequenceGroup sg = (SequenceGroup) groups.get(i); - if (!sg.adjustForRemoveRight(max)) + if ( (trimLeft && !sg.adjustForRemoveLeft(column)) + || (!trimLeft && !sg.adjustForRemoveRight(column))) { viewport.alignment.deleteGroup(sg); } @@ -1504,20 +1513,34 @@ public class AlignFrame */ public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) { - HistoryItem edit; - addHistoryItem(edit=new HistoryItem("Remove Gapped Columns", - viewport.alignment, HistoryItem.HIDE)); + int start = 0, end = viewport.alignment.getWidth()-1; + + SequenceI[] seqs; + if (viewport.getSelectionGroup() != null) + { + seqs = viewport.getSelectionGroup().getSequencesAsArray(true); + start = viewport.getSelectionGroup().getStartRes(); + end = viewport.getSelectionGroup().getEndRes(); + } + else + seqs = viewport.alignment.getSequencesArray(); + + + addHistoryItem(new RemoveGapColCommand("Remove Gapped Columns", + seqs, + start, end, + viewport.getGapCharacter())); //This is to maintain viewport position on first residue //of first sequence SequenceI seq = viewport.alignment.getSequenceAt(0); int startRes = seq.findPosition(viewport.startRes); - ShiftList shifts; - viewport.getAlignment().removeGaps(shifts=new ShiftList()); - edit.alColumnChanges=shifts.getInverse(); - if (viewport.hasHiddenColumns) - viewport.getColumnSelection().compensateForEdits(shifts); - viewport.setStartRes(seq.findIndex(startRes)-1); + // ShiftList shifts; + // viewport.getAlignment().removeGaps(shifts=new ShiftList()); + // edit.alColumnChanges=shifts.getInverse(); + // if (viewport.hasHiddenColumns) + // viewport.getColumnSelection().compensateForEdits(shifts); + viewport.setStartRes(seq.findIndex(startRes)-1); viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } @@ -1529,71 +1552,27 @@ public class AlignFrame */ public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) { - // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences - // TODO: columnSelection.compensateforedits should be called (and passed to history item) - addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment, - HistoryItem.HIDE)); + int start = 0, end = viewport.alignment.getWidth()-1; + + SequenceI[] seqs; + if (viewport.getSelectionGroup() != null) + { + seqs = viewport.getSelectionGroup().getSequencesAsArray(true); + start = viewport.getSelectionGroup().getStartRes(); + end = viewport.getSelectionGroup().getEndRes(); + } + else + seqs = viewport.alignment.getSequencesArray(); //This is to maintain viewport position on first residue //of first sequence SequenceI seq = viewport.alignment.getSequenceAt(0); int startRes = seq.findPosition(viewport.startRes); - - SequenceI current; - - Vector seqs = null; - - int start = 0; - int end = viewport.alignment.getWidth(); - - if (viewport.getSelectionGroup() != null - && viewport.getSelectionGroup().getSequences(true) != null - && viewport.getSelectionGroup().getSize(true) > 0) - { - seqs = viewport.getSelectionGroup().getSequences(true); - start = viewport.getSelectionGroup().getStartRes(); - end = viewport.getSelectionGroup().getEndRes()+1; - } - else - { - seqs = viewport.alignment.getSequences(); - } - /* Commented out regions below are partial implementation of todo above. - * divide start,end into visible chunks, and for each: - int diff=end-start+1; - int diffmax=0; - int dr[] = new int[seqs.size()]; - */ - for (int i = 0; i < seqs.size(); i++) - { - current = (SequenceI) seqs.elementAt(i); - //dr[i]= - current.removeGaps(start, end); - /*if (d0) { - // record shift for history. - editgaps.addShift(start, diff); - if (viewport.hasHiddenColumns && diffmax>diff) { - // pad sequence - StringBuffer gaps=new StringBuffer(diffmax); - for (int i=0,j=diffmax-diff; i0) { - String sq = current.getSequence(); - current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring()); - } - } - } - }*/ + addHistoryItem(new RemoveGapsCommand("Remove Gaps", + seqs, + start, end, + viewport.getGapCharacter())); viewport.setStartRes(seq.findIndex(startRes)-1); @@ -1611,13 +1590,14 @@ public class AlignFrame ap = (AlignmentPanel) alignPanels.elementAt(i); av = ap.av; - if (av.padGaps) + if (av.padGaps) av.getAlignment().padGaps(); - if (av.vconsensus != null && av.autoCalculateConsensus) + if (av.hconsensus != null && av.autoCalculateConsensus) { - av.updateConsensus(); - av.updateConservation(); + av.updateConsensus(ap); + av.updateConservation(ap); + ap.annotationPanel.repaint(); } resetAllColourSchemes(); @@ -1643,7 +1623,7 @@ public class AlignFrame viewport.alignment.getWidth()); } - cs.setConsensus(viewport.vconsensus); + cs.setConsensus(viewport.hconsensus); if (cs.conservationApplied()) { Alignment al = (Alignment) viewport.alignment; @@ -1678,8 +1658,8 @@ public class AlignFrame */ public void padGapsMenuitem_actionPerformed(ActionEvent e) { - addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, - HistoryItem.HIDE)); + // addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, + // HistoryItem.HIDE)); viewport.padGaps = padGapsMenuitem.isSelected(); @@ -2089,7 +2069,7 @@ public class AlignFrame cs.setConservation(null); } - cs.setConsensus(viewport.vconsensus); + cs.setConsensus(viewport.hconsensus); } viewport.setGlobalColourScheme(cs); @@ -2345,10 +2325,10 @@ public class AlignFrame */ public void sortPairwiseMenuItem_actionPerformed(ActionEvent e) { - addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, - HistoryItem.SORT)); + SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray(); AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0)); + addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment)); alignPanel.repaint(); } @@ -2359,9 +2339,9 @@ public class AlignFrame */ public void sortIDMenuItem_actionPerformed(ActionEvent e) { - addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, - HistoryItem.SORT)); + SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray(); AlignmentSorter.sortByID(viewport.getAlignment()); + addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment)); alignPanel.repaint(); } @@ -2372,10 +2352,10 @@ public class AlignFrame */ public void sortGroupMenuItem_actionPerformed(ActionEvent e) { - addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, - HistoryItem.SORT)); - + SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray(); AlignmentSorter.sortByGroup(viewport.getAlignment()); + addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment)); + alignPanel.repaint(); } @@ -2573,11 +2553,13 @@ public class AlignFrame { public void actionPerformed(ActionEvent e) { - addHistoryItem(new HistoryItem("Sort", viewport.alignment, - HistoryItem.SORT)); + SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray(); // TODO: JBPNote - have to map order entries to curent SequenceI pointers AlignmentSorter.sortBy(viewport.getAlignment(), order); + + addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment)); + alignPanel.repaint(); } }); @@ -2608,10 +2590,15 @@ public class AlignFrame { public void actionPerformed(ActionEvent e) { - addHistoryItem(new HistoryItem("Tree Sort", - viewport.alignment, HistoryItem.SORT)); + SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray(); AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree()); + + addHistoryItem(new OrderCommand("Tree Sort", + oldOrder, + viewport.alignment)); + + alignPanel.repaint(); } }); @@ -2747,16 +2734,26 @@ public class AlignFrame { return ShowNewickTree(nf,title,600,500,4,5); } + public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input) + { + return ShowNewickTree(nf,title, input, 600,500,4,5); + } + public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) { + return ShowNewickTree(nf, title, null, w, h, x, y); + } /** - * DOCUMENT ME! - * - * @param nf DOCUMENT ME! - * @param title DOCUMENT ME! + * Add a treeviewer for the tree extracted from a newick file object to the current alignment view * - * @return DOCUMENT ME! + * @param nf the tree + * @param title tree viewer title + * @param input Associated alignment input data (or null) + * @param w width + * @param h height + * @param x position + * @param y position + * @return TreePanel handle */ - public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) - { + public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) { TreePanel tp = null; try @@ -2768,7 +2765,7 @@ public class AlignFrame tp = new TreePanel(alignPanel, "FromFile", title, - nf); + nf, input); tp.setSize(w,h); @@ -2884,7 +2881,7 @@ public class AlignFrame if (msa.getSequences().length == 1) { // Single Sequence prediction - new jalview.ws.JPredClient(sh, title, false, msa, af); + new jalview.ws.JPredClient(sh, title, false, msa, af, true); } else { @@ -2892,7 +2889,7 @@ public class AlignFrame { // Sequence profile based prediction new jalview.ws.JPredClient(sh, - title, true, msa, af); + title, true, msa, af, true); } } }