// Applet user interface for algorithms for building phylogenetic trees // from Durbin et al: Biological Sequence Analysis, CUP 1998, chapter 7. // Peter Sestoft, sestoft@itu.dk 1999-12-07 version 0.3 // Reference: http://www.itu.dk/people/sestoft/bsa.html // License: Anybody can use this code for any purpose, including // teaching, research, and commercial purposes, provided proper // reference is made to its origin. Neither the author nor the Royal // Veterinary and Agricultural University, Copenhagen, Denmark, can // take any responsibility for the consequences of using this code. import java.awt.*; import java.awt.event.*; import java.applet.Applet; // Applet user interface to the phylogenetic (clustering) algorithms // UPGMA and Neighbour Joining public class Match7Applet extends Applet { TextField dimInput = new TextField("4", 10); Button newInputButton = new Button("New input size"); Button randomButton = new Button("Random data"); Button buildButton = new Button("Build trees"); TreeFrame upgma, nj; ScrollPane scp = new ScrollPane(); Panel insidescp = new Panel(); int dim; InputPanel inp; public void init() { setLayout(new BorderLayout()); add(scp, "Center"); scp.add(insidescp); Panel cont = new Panel(); cont.setLayout(new GridLayout(1, 5)); cont.add(new Label("Sequence count")); cont.add(dimInput); cont.add(newInputButton); cont.add(randomButton); cont.add(buildButton); add(cont, "South"); dimInput.addActionListener(new dimInputListener()); newInputButton.addActionListener(new dimInputListener()); randomButton.addActionListener(new RandomButListener()); buildButton.addActionListener(new buildListener()); fillExample(); } public void destroy() { if (upgma != null) upgma.dispose(); if (nj != null) nj.dispose(); } class dimInputListener implements ActionListener { public void actionPerformed(ActionEvent e) { newInputPanel(Integer.parseInt(dimInput.getText())); } } class buildListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (inp != null) { double[][] ds = inp.getData(); UPGMA upclu = new UPGMA(ds); if (upgma == null) { upgma = new TreeFrame("UPGMA tree", upclu.getRoot()); upgma.addWindowListener(new UPGMAFrameClosed()); } else upgma.setCluster(upclu.getRoot()); NJ njclu = new NJ(ds); if (nj == null) { nj = new TreeFrame("Neighbour tree", njclu.getRoot()); nj.addWindowListener(new NJFrameClosed()); } else nj.setCluster(njclu.getRoot()); } } } class RandomButListener implements ActionListener { public void actionPerformed(ActionEvent e) { // Create Euclidean random data (to satisfy the triangle inequality) if (inp == null) if (dimInput.getText().equals("")) return; else newInputPanel(Integer.parseInt(dimInput.getText())); double[] xs = new double[dim]; double[] ys = new double[dim]; for (int i=0; ij); } input[i-1][i-1].setText("0.0"); } } public double[][] getData() { double[][] ds = new double[dim][]; for (int i=0; i