/*----------------------------------------------------------------------+ | Title: Phylap.java | | Applet | | (uses PhylPanel.java and Phyltree.java) | | | | Author: David E. Joyce | | Department of Mathematics and Computer Science | | Clark University | | Worcester, MA 01610-1477 | | U.S.A. | | | | http://aleph0.clarku.edu/~djoyce/ | | | | Date: January, 1996. Version 0.1f | | November, 2002. Version 0.2 | +----------------------------------------------------------------------*/ import java.awt.*; import java.applet.*; import java.awt.event.*; public class Phylap extends Applet implements ActionListener, KeyListener, ItemListener, WindowListener { int species; int chars; int alts; double rate; boolean showActual, showGenome, showMatrix, showConstructed; int method; int genome[][]; double diffMatrix[][], timeMatrix[][]; TextField inputSpecies,inputChars, inputAlts, inputRate; TextArea matrixPanel; Button newPhyltreeButton, mutateButton; Panel actualControls, mutationControls, constructionControls; Phyltree actualTree, constructedTree; PhylPanel actualTreePanel, constructedTreePanel; GenomePanel genomePanel; Frame remoteFrame; Choice methodChoice = new Choice(); final static int remoteFrameWidth=100; final static int remoteFrameHeight=400; final static Color actColor = new Color(250,250,200); final static Color matColor = new Color(250,230,240); final static Color conColor = new Color(200,230,240); public String getAppletInfo() { return "Phylap. Copyright 1996, 2002, David Joyce, Clark University. Version 0.2"; } public String[][] getParameterInfo() { String[][] pinfo = { {"species", "int", "number of species"}, {"chars", "int", "number of characters"}, {"alts", "int", "number of alternatives/trait"}, {"rate", "int", "mutation rate * 1000"}, {"method", "int", "reconstruction method (-1,0,or 1)"}, {"showActual", "bool", "show actual tree"}, {"showGenome", "bool", "show genome sequences"}, {"showMatrix", "bool", "show distance matrix"}, {"showConstructed","bool", "show constructed tree"} }; return pinfo; } public void init() { String param = getParameter("species"); species = (param == null) ? 10 : Integer.parseInt(param); if (species > 100) species = 100; inputSpecies = new TextField(String.valueOf(species)); inputSpecies.addKeyListener(this); param = getParameter("chars"); chars = (param == null) ? 10 : Integer.parseInt(param); inputChars = new TextField(String.valueOf(chars)); inputChars.addKeyListener(this); param = getParameter("alts"); alts = (param == null) ? 4 : Integer.parseInt(param); inputAlts = new TextField(String.valueOf(alts)); inputAlts.addKeyListener(this); param = getParameter("rate"); rate = (param == null) ? 0.1 : Integer.parseInt(param)/1000.0; inputRate = new TextField(String.valueOf((int)(rate*1000))); inputRate.addKeyListener(this); param = getParameter("method"); method = (param == null) ? 0 : Integer.parseInt(param); param = getParameter("showActual"); showActual = (param != null & (param.equalsIgnoreCase("yes") || param.equalsIgnoreCase("true"))); param = getParameter("showGenome"); showGenome = (param != null & (param.equalsIgnoreCase("yes") || param.equalsIgnoreCase("true"))); param = getParameter("showMatrix"); showMatrix = (param != null & (param.equalsIgnoreCase("yes") || param.equalsIgnoreCase("true"))); param = getParameter("showConstructed"); showConstructed = (param != null & (param.equalsIgnoreCase("yes") || param.equalsIgnoreCase("true"))); // Prepare the panels to be inserted setFont(new Font("TimesRoman",Font.PLAIN,10)); actualControls = new Panel(); actualControls.setBackground(actColor); actualControls.setLayout(new GridLayout(2,2,4,4)); actualControls.add(new Label(" ")); newPhyltreeButton = new Button("New Phyltree"); newPhyltreeButton.addActionListener(this); actualControls.add(newPhyltreeButton); actualControls.add(new Label("Species:",Label.RIGHT)); actualControls.add(inputSpecies); actualTree = new Phyltree(species); actualTreePanel = new PhylPanel(actualTree); actualTreePanel.setBackground(actColor); mutationControls = new Panel(); mutationControls.setBackground(matColor); mutationControls.setLayout(new GridLayout(2,4,4,4)); mutationControls.add(new Label(" ")); mutateButton = new Button("Mutate"); mutateButton.addActionListener(this); mutationControls.add(mutateButton); mutationControls.add(new Label("Chars:",Label.RIGHT)); mutationControls.add(inputChars); mutationControls.add(new Label("Alts:",Label.RIGHT)); mutationControls.add(inputAlts); mutationControls.add(new Label("Rate:",Label.RIGHT)); mutationControls.add(inputRate); genomePanel = new GenomePanel(); matrixPanel = new TextArea(8,80); matrixPanel.setBackground(matColor); matrixPanel.setFont(new Font("Courier",Font.PLAIN,10)); matrixPanel.setEditable(false); constructionControls = new Panel(); constructionControls.setBackground(conColor); constructionControls.setLayout(new GridLayout(2,1,4,4)); constructionControls.add(new Label("Reconstruction method:")); methodChoice.addItem("Mimimum"); methodChoice.addItem("Average"); methodChoice.addItem("Maximum"); if (method<0) methodChoice.select("Mimimum"); else if (method>0) methodChoice.select("Maximum"); else methodChoice.select("Average"); methodChoice.addItemListener(this); constructionControls.add(methodChoice); constructedTree = new Phyltree(species); constructedTreePanel = new PhylPanel(constructedTree); constructedTreePanel.setBackground(conColor); // Put them in the applet panel and the remote panel setLayout(new BorderLayout(10,10)); Panel controlPanel = new Panel(); controlPanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,10)); controlPanel.add(actualControls); if (showMatrix || showGenome || showConstructed) controlPanel.add(mutationControls); if (showConstructed) controlPanel.add(constructionControls); add("North",controlPanel); Panel centerPanel = new Panel(); centerPanel.setLayout(new GridLayout(1,2,10,10)); if (showActual) centerPanel.add(actualTreePanel); if (showConstructed) centerPanel.add(constructedTreePanel); add("Center",centerPanel); if (showMatrix) add("South",matrixPanel); if (showGenome) { remoteFrame = new Frame("Phyltree"); remoteFrame.setSize(remoteFrameWidth,remoteFrameHeight); remoteFrame.add(genomePanel); remoteFrame.setVisible(true); } makeTree(); } // init private void makeTree() { actualTree.setSize(species); actualTree.random(0.1); actualTreePanel.repaint(); mutate(); } private void mutate() { genome = actualTree.createRandomGenome(chars,alts,rate); genomePanel.setGenome(genome,species,alts); genomePanel.repaint(); reconstruct(); } /* Change the entries in the distance matrix from differences to * estimated times according to the formula * * t = -(1/r) log(1-m/(n(m-1)) y) * * where r is the mutation rate, m is the number of traits, * m is the the number of alternates, and y is the number of different * characters. */ private double[][] distToTime (double dist[][], int traits, int alts, double rate) { double time[][] = new double[species][]; for (int i=0; i