*/
package jalview.analysis;
-import jalview.analysis.scoremodels.SimilarityParams;
import jalview.api.analysis.DistanceScoreModelI;
import jalview.api.analysis.ScoreModelI;
import jalview.api.analysis.SimilarityParamsI;
* compute similarity and invert it to give a distance measure
*/
MatrixI result = ((SimilarityScoreModelI) sm).findSimilarities(
- seqData, SimilarityParams.Jalview);
+ seqData, scoreOptions);
result.reverseRange(true);
distances = result;
}
* if true, the denominator is the shorter sequence length (possibly
* including gaps)
*/
- SimilarityParams(boolean includeGapGap, boolean matchGap,
+ public SimilarityParams(boolean includeGapGap, boolean matchGap,
boolean includeGaps, boolean shortestLength)
{
includeGappedColumns = includeGapGap;
data = aparser.getValue("tree", true);
if (data != null)
{
- jalview.io.NewickFile fin = null;
try
{
System.out.println("CMD [-tree " + data
+ "] executed successfully!");
- fin = new NewickFile(data,
+ NewickFile nf = new NewickFile(data,
AppletFormatAdapter.checkProtocol(data));
- if (fin != null)
- {
- af.getViewport().setCurrentTree(
- af.ShowNewickTree(fin, data).getTree());
- }
+ af.getViewport().setCurrentTree(
+ af.showNewickTree(nf, data).getTree());
} catch (IOException ex)
{
System.err.println("Couldn't add tree " + data);
import jalview.analysis.AlignmentUtils;
import jalview.analysis.CrossRef;
import jalview.analysis.Dna;
-import jalview.analysis.NJTree;
import jalview.analysis.ParseProperties;
import jalview.analysis.SequenceIdMatcher;
import jalview.api.AlignExportSettingI;
import jalview.api.SplitContainerI;
import jalview.api.ViewStyleI;
import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.commands.CommandI;
}
/**
- * DOCUMENT ME!
+ * Constructs a tree panel and adds it to the desktop
*
* @param type
- * DOCUMENT ME!
- * @param pwType
- * DOCUMENT ME!
- * @param title
- * DOCUMENT ME!
+ * tree type (NJ or AV)
+ * @param sm
+ * distance or similarity score model used to compute the tree
+ * @param options
+ * parameters for the distance or similarity calculation
*/
- void newTreePanel(String type, String pwType, String title)
+ void newTreePanel(String type, ScoreModelI sm, SimilarityParamsI options)
{
+ String frameTitle = "";
TreePanel tp;
if (viewport.getSelectionGroup() != null
}
}
- title = title + " on region";
- tp = new TreePanel(alignPanel, type, pwType);
+ tp = new TreePanel(alignPanel, type, sm, options);
+ frameTitle = tp.getPanelTitle() + " on region";
}
else
{
return;
}
- tp = new TreePanel(alignPanel, type, pwType);
+ tp = new TreePanel(alignPanel, type, sm, options);
+ frameTitle = tp.getPanelTitle();
}
- title += " from ";
+ frameTitle += " from ";
if (viewport.viewName != null)
{
- title += viewport.viewName + " of ";
+ frameTitle += viewport.viewName + " of ";
}
- title += this.title;
+ frameTitle += this.title;
- Desktop.addInternalFrame(tp, title, 600, 500);
+ Desktop.addInternalFrame(tp, frameTitle, 600, 500);
}
/**
if (value == JalviewFileChooser.APPROVE_OPTION)
{
- String choice = chooser.getSelectedFile().getPath();
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
- jalview.io.NewickFile fin = null;
+ String filePath = chooser.getSelectedFile().getPath();
+ Cache.setProperty("LAST_DIRECTORY", filePath);
+ NewickFile fin = null;
try
{
- fin = new NewickFile(choice, DataSourceType.FILE);
- viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
+ fin = new NewickFile(filePath, DataSourceType.FILE);
+ viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
} catch (Exception ex)
{
JvOptionPane
}
}
- public TreePanel ShowNewickTree(NewickFile nf, String title)
+ public TreePanel showNewickTree(NewickFile nf, String treeTitle)
{
- return ShowNewickTree(nf, title, 600, 500, 4, 5);
+ return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
}
- public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
+ public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
int h, int x, int y)
{
- return ShowNewickTree(nf, title, null, w, h, x, y);
+ return showNewickTree(nf, treeTitle, null, w, h, x, y);
}
/**
- * Add a treeviewer for the tree extracted from a newick file object to the
+ * Add a treeviewer for the tree extracted from a Newick file object to the
* current alignment view
*
* @param nf
* position
* @return TreePanel handle
*/
- public TreePanel ShowNewickTree(NewickFile nf, String title,
+ public TreePanel showNewickTree(NewickFile nf, String treeTitle,
AlignmentView input, int w, int h, int x, int y)
{
TreePanel tp = null;
if (nf.getTree() != null)
{
- tp = new TreePanel(alignPanel, NJTree.FROM_FILE, title, nf, input);
+ tp = new TreePanel(alignPanel, nf, treeTitle, input);
tp.setSize(w, h);
tp.setLocation(x, y);
}
- Desktop.addInternalFrame(tp, title, w, h);
+ Desktop.addInternalFrame(tp, treeTitle, w, h);
}
} catch (Exception ex)
{
ColourMenuHelper.setColourSelected(colourMenu, schemeName);
}
-
- public void newTreePanel(String treeType, ScoreModelI sm)
- {
- String scoreModelName = sm.getName();
- final String ttl = TreePanel.getPanelTitle(treeType, scoreModelName);
- newTreePanel(treeType, scoreModelName, ttl);
- }
}
class PrintThread extends Thread
TreePanel tp = (TreePanel) retrieveExistingObj(tree.getId());
if (tp == null)
{
- tp = af.ShowNewickTree(
+ tp = af.showNewickTree(
new jalview.io.NewickFile(tree.getNewick()),
tree.getTitle(), tree.getWidth(), tree.getHeight(),
tree.getXpos(), tree.getYpos());
Tree tree = jms.getTree(t);
- TreePanel tp = af.ShowNewickTree(
+ TreePanel tp = af.showNewickTree(
new jalview.io.NewickFile(tree.getNewick()),
tree.getTitle(), tree.getWidth(), tree.getHeight(),
tree.getXpos(), tree.getYpos());
import jalview.analysis.NJTree;
import jalview.analysis.scoremodels.ScoreModels;
+import jalview.analysis.scoremodels.SimilarityParams;
import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.util.MessageManager;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
+import java.awt.GridLayout;
import java.awt.event.ActionEvent;
+import java.beans.PropertyVetoException;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
+import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
private ButtonGroup treeTypes;
+ private JCheckBox includeGaps;
+
+ private JCheckBox matchGaps;
+
+ private JCheckBox includeGappedColumns;
+
+ private JCheckBox shorterSequence;
+
/**
* Constructor
*
init();
}
+ /**
+ * Lays out the panel and adds it to the desktop
+ */
void init()
{
frame = new JInternalFrame();
frame.setContentPane(this);
this.setBackground(Color.white);
+ /*
+ * Layout consists of 4 panels:
+ * - first with choice of tree method NJ or AV
+ * - second with choice of score model
+ * - third with score model parameter options
+ * - fourth with OK and Cancel
+ */
neighbourJoining = new JRadioButton(
MessageManager.getString("label.tree_calc_nj"));
neighbourJoining.setOpaque(false);
treeTypes.add(neighbourJoining);
treeTypes.add(averageDistance);
neighbourJoining.setSelected(true);
-
+ JPanel treeChoicePanel = new JPanel();
+ treeChoicePanel.setOpaque(false);
+ treeChoicePanel.add(neighbourJoining);
+ treeChoicePanel.add(averageDistance);
+
+ /*
+ * score model drop-down
+ */
matrixNames = new JComboBox<String>();
ScoreModels scoreModels = ScoreModels.getInstance();
for (ScoreModelI sm : scoreModels.getModels())
matrixNames.addItem(sm.getName());
}
}
-
+ JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ scoreModelPanel.setOpaque(false);
+ scoreModelPanel.add(matrixNames, FlowLayout.LEFT);
+
+ /*
+ * score model parameters
+ */
+ JPanel paramsPanel = new JPanel(new GridLayout(5, 1));
+ paramsPanel.setOpaque(false);
+ includeGaps = new JCheckBox("Include gaps");
+ matchGaps = new JCheckBox("Match gaps");
+ includeGappedColumns = new JCheckBox("Include gapped columns");
+ shorterSequence = new JCheckBox("Match on shorter sequence");
+ paramsPanel.add(new JLabel("Pairwise sequence scoring options"));
+ paramsPanel.add(includeGaps);
+ paramsPanel.add(matchGaps);
+ paramsPanel.add(includeGappedColumns);
+ paramsPanel.add(shorterSequence);
+
+ /*
+ * OK / Cancel buttons
+ */
JButton ok = new JButton(MessageManager.getString("action.ok"));
ok.setFont(VERDANA_11PT);
ok.addActionListener(new java.awt.event.ActionListener()
ok_actionPerformed(e);
}
});
-
JButton cancel = new JButton(MessageManager.getString("action.cancel"));
cancel.setFont(VERDANA_11PT);
cancel.addActionListener(new java.awt.event.ActionListener()
cancel_actionPerformed(e);
}
});
+ JPanel actionPanel = new JPanel();
+ actionPanel.setOpaque(false);
+ actionPanel.add(ok);
+ actionPanel.add(cancel);
- JPanel p1 = new JPanel();
- p1.setOpaque(false);
- p1.add(neighbourJoining);
- p1.add(averageDistance);
- this.add(p1);
- JPanel p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
- p2.setOpaque(false);
- p2.add(matrixNames, FlowLayout.LEFT);
- this.add(p2);
- JPanel p3 = new JPanel();
- p3.setOpaque(false);
- p3.add(ok);
- p3.add(cancel);
- this.add(p3);
+ this.add(treeChoicePanel);
+ this.add(scoreModelPanel);
+ this.add(paramsPanel);
+ this.add(actionPanel);
Desktop.addInternalFrame(frame,
- MessageManager.getString("label.choose_tree"),
- 400, 200, false);
+ MessageManager.getString("label.choose_tree"), 400, 400, false);
frame.setLayer(JLayeredPane.PALETTE_LAYER);
}
*/
protected void ok_actionPerformed(ActionEvent e)
{
+ String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
+ : NJTree.AVERAGE_DISTANCE;
+ ScoreModelI sm = ScoreModels.getInstance().forName(
+ matrixNames.getSelectedItem().toString());
+ SimilarityParamsI params = getSimilarityParameters();
+ af.newTreePanel(treeType, sm, params);
+
try
{
frame.setClosed(true);
- String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
- : NJTree.AVERAGE_DISTANCE;
- ScoreModelI sm = ScoreModels.getInstance().forName(
- matrixNames.getSelectedItem().toString());
- af.newTreePanel(treeType, sm);
- } catch (Exception ex)
+ } catch (PropertyVetoException ex)
{
}
}
+ private SimilarityParamsI getSimilarityParameters()
+ {
+ SimilarityParamsI params = new SimilarityParams(
+ includeGappedColumns.isSelected(), matchGaps.isSelected(),
+ includeGaps.isSelected(), shorterSequence.isSelected());
+ return params;
+ }
+
/**
* Closes dialog on cancel
*
import jalview.analysis.AlignmentSorter;
import jalview.analysis.NJTree;
-import jalview.analysis.scoremodels.ScoreModels;
-import jalview.analysis.scoremodels.SimilarityParams;
import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.api.analysis.ViewBasedAnalysisI;
import jalview.bin.Cache;
import jalview.commands.CommandI;
*/
public class TreePanel extends GTreePanel
{
- String type;
+ String treeType;
- String pwtype;
+ ScoreModelI scoreModel; // if tree computed
+
+ String treeTitle; // if tree loaded
+
+ SimilarityParamsI similarityParams;
TreeCanvas treeCanvas;
/**
* Creates a new TreePanel object.
*
- * @param av
- * DOCUMENT ME!
- * @param seqVector
- * DOCUMENT ME!
+ * @param ap
* @param type
- * DOCUMENT ME!
- * @param pwtype
- * DOCUMENT ME!
- * @param s
- * DOCUMENT ME!
- * @param e
- * DOCUMENT ME!
+ * @param sm
+ * @param options
*/
- public TreePanel(AlignmentPanel ap, String type, String pwtype)
+ public TreePanel(AlignmentPanel ap, String type, ScoreModelI sm,
+ SimilarityParamsI options)
{
super();
- initTreePanel(ap, type, pwtype, null, null);
+ this.similarityParams = options;
+ initTreePanel(ap, type, sm, null, null);
// We know this tree has distances. JBPNote TODO: prolly should add this as
// a userdefined default
// showDistances(true);
}
- public TreePanel(AlignmentPanel av, String type, String pwtype,
- NewickFile newtree, AlignmentView inputData)
+ public TreePanel(AlignmentPanel alignPanel, NewickFile newtree,
+ String theTitle, AlignmentView inputData)
{
super();
- initTreePanel(av, type, pwtype, newtree, inputData);
+ this.treeTitle = theTitle;
+ initTreePanel(alignPanel, null, null, newtree, inputData);
}
public AlignmentI getAlignment()
return treeCanvas.av;
}
- void initTreePanel(AlignmentPanel ap, String type, String pwtype,
+ void initTreePanel(AlignmentPanel ap, String type, ScoreModelI sm,
NewickFile newTree, AlignmentView inputData)
{
av = ap.av;
- this.type = type;
- this.pwtype = pwtype;
+ this.treeType = type;
+ this.scoreModel = sm;
treeCanvas = new TreeCanvas(this, ap, scrollPane);
scrollPane.setViewportView(treeCanvas);
{
NewickFile newtree;
- jalview.datamodel.AlignmentView odata = null;
+ AlignmentView odata = null;
- public TreeLoader(NewickFile newtree)
+ public TreeLoader(NewickFile newickFile)
{
- this.newtree = newtree;
- if (newtree != null)
+ this.newtree = newickFile;
+ if (newickFile != null)
{
// Must be outside run(), as Jalview2XML tries to
// update distance/bootstrap visibility at the same time
- showBootstrap(newtree.HasBootstrap());
- showDistances(newtree.HasDistances());
+ showBootstrap(newickFile.HasBootstrap());
+ showDistances(newickFile.HasDistances());
}
}
}
else
{
- int start, end;
- SequenceI[] seqs;
- boolean selview = av.getSelectionGroup() != null
- && av.getSelectionGroup().getSize() > 1;
- AlignmentView seqStrings = av.getAlignmentView(selview);
- if (!selview)
- {
- start = 0;
- end = av.getAlignment().getWidth();
- seqs = av.getAlignment().getSequencesArray();
- }
- else
- {
- start = av.getSelectionGroup().getStartRes();
- end = av.getSelectionGroup().getEndRes() + 1;
- seqs = av.getSelectionGroup().getSequencesInOrder(
- av.getAlignment());
- }
- ScoreModelI sm = configureScoreModel(pwtype);
- tree = new NJTree(av, type, sm, SimilarityParams.Jalview);
+ ScoreModelI sm = configureScoreModel();
+ tree = new NJTree(av, treeType, sm, similarityParams);
showDistances(true);
}
{
CutAndPasteTransfer cap = new CutAndPasteTransfer();
- String newTitle = getPanelTitle(type, pwtype);
+ String newTitle = getPanelTitle();
NewickFile fout = new NewickFile(tree.getTopNode());
try
public CommandI sortAlignmentIn(AlignmentPanel ap)
{
- AlignmentViewport av = ap.av;
- SequenceI[] oldOrder = av.getAlignment().getSequencesArray();
- AlignmentSorter.sortByTree(av.getAlignment(), tree);
+ AlignmentViewport viewport = ap.av;
+ SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
CommandI undo;
- undo = new OrderCommand("Tree Sort", oldOrder, av.getAlignment());
+ undo = new OrderCommand("Tree Sort", oldOrder, viewport.getAlignment());
ap.paintAlignment(true);
return undo;
return treeCanvas.font;
}
- public void setTreeFont(Font font)
+ public void setTreeFont(Font f)
{
if (treeCanvas != null)
{
- treeCanvas.setFont(font);
+ treeCanvas.setFont(f);
}
}
}
if (newname != null)
{
- String oldname = ((SequenceNode) node).getName();
- // TODO : save in the undo object for this modification.
+ // String oldname = ((SequenceNode) node).getName();
+ // TODO : save oldname in the undo object for this modification.
((SequenceNode) node).setName(newname);
}
}
* Neighbour Joining Using BLOSUM62
* <p>
* For a tree loaded from file, just uses the file name
- *
- * @param treeType
- * NJ or AV or FromFile
- * @param modelOrFileName
* @return
*/
- public static String getPanelTitle(String treeType, String modelOrFileName)
+ public String getPanelTitle()
{
- if (NJTree.FROM_FILE.equals(treeType))
+ if (treeTitle != null)
{
- return modelOrFileName;
+ return treeTitle;
}
/*
+ treeType.toLowerCase());
/*
- * i18n description (if any) of score model used
+ * i18n description (if available) of score model used
*/
String smn = MessageManager.getStringOrReturn("label.score_model_",
- modelOrFileName);
+ scoreModel.getName());
/*
* put them together as <method> Using <model>
}
/**
- * Gets the score model for the given name. If the score model is one that
- * requires to get state data from the current view, allow it to do so
+ * If the score model is one that requires to get state data from the current
+ * view, create and configure a new instance of it
*
- * @param sm
* @return
*/
- protected ScoreModelI configureScoreModel(String modelName)
+ protected ScoreModelI configureScoreModel()
{
- ScoreModelI sm = ScoreModels.getInstance().forName(modelName);
- if (sm instanceof ViewBasedAnalysisI)
+ if (scoreModel instanceof ViewBasedAnalysisI)
{
try
{
- sm = sm.getClass().newInstance();
- ((ViewBasedAnalysisI) sm).configureFromAlignmentView(treeCanvas.ap);
+ scoreModel = scoreModel.getClass().newInstance();
+ ((ViewBasedAnalysisI) scoreModel)
+ .configureFromAlignmentView(treeCanvas.ap);
} catch (Exception q)
{
Cache.log.error("Couldn't create a scoremodel instance for "
- + sm.getName());
+ + scoreModel.getName());
}
}
- return sm;
+ return scoreModel;
}
}
TreePanel tp = null;
if (vstree.isValidTree())
{
- tp = alignFrame.ShowNewickTree(vstree.getNewickTree(),
+ tp = alignFrame.showNewickTree(vstree.getNewickTree(),
vstree.getTitle(), vstree.getInputData(), 600,
500, t * 20 + 50, t * 20 + 50);
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
if (nf != null)
{
- af.ShowNewickTree(nf, MessageManager.formatMessage(
+ af.showNewickTree(nf, MessageManager.formatMessage(
"label.tree_from", new String[] { this.alTitle }));
}
// initialise with same renderer settings as in parent alignframe.