/*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
+ * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program 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.
+ * Jalview is free software: you can redistribute it and/or
+ * 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.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * 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 <http://www.gnu.org/licenses/>.
*/
package jalview.gui;
import org.jibble.epsgraphics.*;
import jalview.analysis.*;
+import jalview.commands.CommandI;
import jalview.commands.OrderCommand;
import jalview.datamodel.*;
import jalview.io.*;
if (tree == null)
{
System.out.println("tree is null");
+ // TODO: deal with case when a change event is received whilst a
+ // tree is still being calculated - should save reference for
+ // processing message later.
+ return;
}
if (evt.getNewValue() == null)
{
buffer.append("PID");
}
- Desktop.addInternalFrame(cap, buffer.toString(), 500, 100);
+ jalview.io.NewickFile fout = new jalview.io.NewickFile(
+ tree.getTopNode());
+ try
+ {
+ cap.setText(fout.print(tree.isHasBootstrap(), tree.isHasDistances(),
+ tree.isHasRootDistance()));
+ Desktop.addInternalFrame(cap, buffer.toString(), 500, 100);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("generating newick tree file", oom);
+ cap.dispose();
+ }
- jalview.io.NewickFile fout = new jalview.io.NewickFile(tree
- .getTopNode());
- cap.setText(fout.print(tree.isHasBootstrap(), tree.isHasDistances(),
- tree.isHasRootDistance()));
}
/**
*/
public void saveAsNewick_actionPerformed(ActionEvent e)
{
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
- .getProperty("LAST_DIRECTORY"));
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle("Save tree as newick file");
chooser.setToolTipText("Save");
try
{
- jalview.io.NewickFile fout = new jalview.io.NewickFile(tree
- .getTopNode());
- String output = fout.print(tree.isHasBootstrap(), tree
- .isHasDistances(), tree.isHasRootDistance());
+ jalview.io.NewickFile fout = new jalview.io.NewickFile(
+ tree.getTopNode());
+ String output = fout.print(tree.isHasBootstrap(),
+ tree.isHasDistances(), tree.isHasRootDistance());
java.io.PrintWriter out = new java.io.PrintWriter(
new java.io.FileWriter(choice));
out.println(output);
/**
* sort the associated alignment view by the current tree.
+ *
* @param e
*/
public void sortByTree_actionPerformed(ActionEvent e)
{
- AlignmentPanel ap = av.getAlignPanel();
- SequenceI[] oldOrder = av.getAlignment().getSequencesArray();
- AlignmentSorter.sortByTree(av.getAlignment(), tree);
-
- ap.alignFrame
- .addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
- av.alignment));
+
+ if (treeCanvas.applyToAllViews)
+ {
+ final ArrayList<CommandI> commands = new ArrayList<CommandI>();
+ for (AlignmentPanel ap: PaintRefresher.getAssociatedPanels(av
+ .getSequenceSetId()))
+ {
+ commands.add(sortAlignmentIn(ap.av.getAlignPanel()));
+ }
+ av.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
+ {
+
+ @Override
+ public void undoCommand(AlignmentI[] views)
+ {
+ for (CommandI tsort:commands)
+ {
+ tsort.undoCommand(views);
+ }
+ }
+
+ @Override
+ public int getSize()
+ {
+ return commands.size();
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return "Tree Sort (many views)";
+ }
+
+ @Override
+ public void doCommand(AlignmentI[] views)
+ {
- ap.paintAlignment(true);
+ for (CommandI tsort:commands)
+ {
+ tsort.doCommand(views);
+ }
+ }
+ });
+ for (AlignmentPanel ap: PaintRefresher.getAssociatedPanels(av
+ .getSequenceSetId()))
+ {
+ // ensure all the alignFrames refresh their GI after adding an undo item
+ ap.alignFrame.updateEditMenuBar();
+ }
+ } else {
+ treeCanvas.ap.alignFrame.addHistoryItem(sortAlignmentIn(treeCanvas.ap));
+ }
}
+ public CommandI sortAlignmentIn(AlignmentPanel ap)
+ {
+ AlignViewport av = ap.av;
+ SequenceI[] oldOrder = av.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByTree(av.getAlignment(), tree);
+ CommandI undo;
+ undo=new OrderCommand("Tree Sort", oldOrder,
+ av.alignment);
+ ap.paintAlignment(true);
+ return undo;
+ }
/**
* DOCUMENT ME!
*
ex.printStackTrace();
}
}
+
/**
- * change node labels to the annotation referred to by labelClass
- * TODO: promote to a datamodel modification that can be undone
- * TODO: make argument one case of a generic transformation function ie { undoStep = apply(Tree, TransformFunction)};
+ * change node labels to the annotation referred to by labelClass TODO:
+ * promote to a datamodel modification that can be undone TODO: make argument
+ * one case of a generic transformation function ie { undoStep = apply(Tree,
+ * TransformFunction)};
+ *
* @param labelClass
*/
public void changeNames(final String labelClass)
{
- tree.applyToNodes(new NodeTransformI() {
+ tree.applyToNodes(new NodeTransformI()
+ {
public void transform(BinaryNode node)
{
- if (node instanceof SequenceNode && !((SequenceNode) node).isPlaceholder() && !((SequenceNode) node).isDummy())
+ if (node instanceof SequenceNode
+ && !((SequenceNode) node).isPlaceholder()
+ && !((SequenceNode) node).isDummy())
{
- String newname=null;
+ String newname = null;
SequenceI sq = (SequenceI) ((SequenceNode) node).element();
- if (sq!=null)
+ if (sq != null)
{
// search dbrefs, features and annotation
- DBRefEntry[] refs = jalview.util.DBRefUtils.selectRefs(sq.getDBRef(), new String[] {labelClass.toUpperCase()});
- if (refs!=null)
+ DBRefEntry[] refs = jalview.util.DBRefUtils.selectRefs(
+ sq.getDBRef(), new String[]
+ { labelClass.toUpperCase() });
+ if (refs != null)
{
- for (int i=0; i<refs.length;i++)
+ for (int i = 0; i < refs.length; i++)
{
- if (newname == null) {
- newname = new String(refs[i].getAccessionId());
- } else {
- newname = newname +"; "+refs[i].getAccessionId();
+ if (newname == null)
+ {
+ newname = new String(refs[i].getAccessionId());
+ }
+ else
+ {
+ newname = newname + "; " + refs[i].getAccessionId();
}
}
}
- if (newname==null)
+ if (newname == null)
{
SequenceFeature sf[] = sq.getSequenceFeatures();
- for (int i=0;sf!=null && i<sf.length; i++)
+ for (int i = 0; sf != null && i < sf.length; i++)
{
if (sf[i].getType().equals(labelClass))
{
- if (newname==null)
+ if (newname == null)
{
newname = new String(sf[i].getDescription());
- } else {
- newname = newname + "; "+sf[i].getDescription();
+ }
+ else
+ {
+ newname = newname + "; " + sf[i].getDescription();
}
}
}
}
- }
- if (newname!=null)
+ }
+ if (newname != null)
{
String oldname = ((SequenceNode) node).getName();
// TODO : save in the undo object for this modification.