Search in sources :

Example 71 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class Partition method traverse.

// END: simulatePartition
private //
void traverse(//
NodeRef node, //
int[] parentSequence, //
int[] category) {
    if (DEBUG) {
        synchronized (this) {
            System.out.println();
            System.out.println("I'm at: " + node.toString());
            System.out.println();
        }
    }
    for (int iChild = 0; iChild < treeModel.getChildCount(node); iChild++) {
        NodeRef child = treeModel.getChild(node, iChild);
        int[] partitionSequence = new int[partitionSiteCount];
        double[] cProb = new double[stateCount];
        double[][] probabilities = getTransitionProbabilities(child);
        if (DEBUG) {
            synchronized (this) {
                System.out.println("Going to child " + iChild + ": " + child.toString());
                System.out.println("Child finite transition probs matrix:");
                Utils.print2DArray(probabilities, stateCount);
                System.out.println();
            }
        }
        for (int i = 0; i < partitionSiteCount; i++) {
            System.arraycopy(probabilities[category[i]], parentSequence[i] * stateCount, cProb, 0, stateCount);
            if (DEBUG) {
                synchronized (this) {
                    System.out.println("site:" + i);
                    System.out.println("site probs:");
                    Utils.printArray(cProb);
                }
            }
            // END: DEBUG
            partitionSequence[i] = randomChoicePDF(cProb, partitionNumber, "seq");
        }
        if (DEBUG) {
            synchronized (this) {
                //					partitionSequence = new int[]{1, 3, 2, 3, 0, 1, 0, 1, 0, 2, 2, 0, 1, 3, 3, 3, 0, 1, 2, 1, 3, 1, 1, 1, 1, 3, 0, 0, 3, 2, 3, 2, 3, 2, 1, 2, 1, 3, 2, 3, 3, 0, 2, 2, 3, 2, 3, 2, 3, 1, 2, 0, 2, 1, 3, 2, 3, 1, 1, 1, 1, 0, 2, 3, 1, 0, 2, 1, 2, 1, 3, 0, 0, 0, 0, 0, 2, 0, 2, 3, 1, 0, 1, 3, 0, 2, 1, 2, 1, 3, 0, 0, 3, 2, 2, 0, 1, 0, 0, 3  };
                System.out.println("Simulated sequence:");
                Utils.printArray(partitionSequence);
            }
        }
        if (treeModel.getChildCount(child) == 0) {
            Taxon taxon = treeModel.getNodeTaxon(child);
            alignmentMap.put(taxon, partitionSequence);
            if (DEBUG) {
                synchronized (this) {
                    System.out.println("Simulated sequence (translated):");
                    System.out.println(Utils.intArray2Sequence(taxon, partitionSequence, BeagleSequenceSimulator.gapFlag, dataType).getSequenceString());
                }
            }
        // END: DEBUG
        } else {
            if (outputAncestralSequences) {
                alignmentMap.put(new Taxon("internalNodeHeight" + treeModel.getNodeHeight(child)), partitionSequence);
            }
        }
        // END: tip node check
        traverse(treeModel.getChild(node, iChild), partitionSequence, category);
    }
// END: child nodes loop
}
Also used : NodeRef(dr.evolution.tree.NodeRef) Taxon(dr.evolution.util.Taxon)

Example 72 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class TaxonSetPanel method initPanel.

protected void initPanel(Action addTaxonSetAction, Action removeTaxonSetAction) {
    JScrollPane scrollPane1 = new JScrollPane(taxonSetsTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    ActionPanel actionPanel1 = new ActionPanel(false);
    actionPanel1.setAddAction(addTaxonSetAction);
    actionPanel1.setRemoveAction(removeTaxonSetAction);
    addTaxonSetAction.setEnabled(false);
    removeTaxonSetAction.setEnabled(false);
    JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    controlPanel1.add(actionPanel1);
    // Excluded Taxon List
    excludedTaxaTableModel = new TaxaTableModel(false);
    excludedTaxaTable = new JTable(excludedTaxaTableModel);
    excludedTaxaTable.getColumnModel().getColumn(0).setCellRenderer(new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
    excludedTaxaTable.getColumnModel().getColumn(0).setMinWidth(20);
    excludedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            excludedTaxaTableSelectionChanged();
        }
    });
    JScrollPane scrollPane2 = new JScrollPane(excludedTaxaTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    includedTaxonSetsComboBox = new JComboBox(new String[] { TAXON.toLowerCase() + "..." });
    excludedTaxonSetsComboBox = new JComboBox(new String[] { TAXON.toLowerCase() + "..." });
    includedTaxaLabel.setText("");
    excludedTaxaLabel.setText("");
    Box panel1 = new Box(BoxLayout.X_AXIS);
    panel1.add(new JLabel("Select: "));
    panel1.setOpaque(false);
    excludedTaxonSetsComboBox.setOpaque(false);
    panel1.add(excludedTaxonSetsComboBox);
    // Included Taxon List
    includedTaxaTableModel = new TaxaTableModel(true);
    includedTaxaTable = new JTable(includedTaxaTableModel);
    includedTaxaTable.getColumnModel().getColumn(0).setCellRenderer(new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
    includedTaxaTable.getColumnModel().getColumn(0).setMinWidth(20);
    includedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            includedTaxaTableSelectionChanged();
        }
    });
    includedTaxaTable.doLayout();
    JScrollPane scrollPane3 = new JScrollPane(includedTaxaTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    Box panel2 = new Box(BoxLayout.X_AXIS);
    panel2.add(new JLabel("Select: "));
    panel2.setOpaque(false);
    includedTaxonSetsComboBox.setOpaque(false);
    panel2.add(includedTaxonSetsComboBox);
    Icon includeIcon = null, excludeIcon = null;
    try {
        includeIcon = new ImageIcon(IconUtils.getImage(BeautiApp.class, "images/include.png"));
        excludeIcon = new ImageIcon(IconUtils.getImage(BeautiApp.class, "images/exclude.png"));
    } catch (Exception e) {
    // do nothing
    }
    JPanel buttonPanel = createAddRemoveButtonPanel(includeTaxonAction, includeIcon, "Include selected " + TAXA.toLowerCase() + " in the " + TAXON.toLowerCase(), excludeTaxonAction, excludeIcon, "Exclude selected " + TAXA.toLowerCase() + " from the " + TAXON.toLowerCase(), BoxLayout.Y_AXIS);
    taxonSetEditingPanel = new JPanel();
    taxonSetEditingPanel.setBorder(BorderFactory.createTitledBorder(""));
    taxonSetEditingPanel.setOpaque(false);
    taxonSetEditingPanel.setLayout(new GridBagLayout());
    excludedTaxaSearchField.setColumns(12);
    excludedTaxaSearchField.putClientProperty("JTextField.variant", "search");
    excludedTaxaSearchField.putClientProperty("Quaqua.TextField.style", "search");
    excludedTaxaSearchField.putClientProperty("Quaqua.TextField.sizeVariant", "small");
    includedTaxaSearchField.setColumns(12);
    includedTaxaSearchField.putClientProperty("JTextField.variant", "search");
    includedTaxaSearchField.putClientProperty("Quaqua.TextField.style", "search");
    includedTaxaSearchField.putClientProperty("Quaqua.TextField.sizeVariant", "small");
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(3, 6, 3, 0);
    taxonSetEditingPanel.add(excludedTaxaSearchField, c);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0.5;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 6, 0, 0);
    taxonSetEditingPanel.add(scrollPane2, c);
    c.gridx = 0;
    c.gridy = 2;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 6, 3, 0);
    taxonSetEditingPanel.add(excludedTaxaLabel, c);
    c.gridx = 0;
    c.gridy = 3;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 6, 3, 0);
    taxonSetEditingPanel.add(panel1, c);
    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 0;
    c.weighty = 1;
    c.gridheight = 4;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(12, 2, 12, 4);
    taxonSetEditingPanel.add(buttonPanel, c);
    c.gridx = 2;
    c.gridy = 0;
    c.weightx = 0.5;
    c.weighty = 0;
    c.gridheight = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(3, 0, 3, 6);
    taxonSetEditingPanel.add(includedTaxaSearchField, c);
    c.gridx = 2;
    c.gridy = 1;
    c.weightx = 0.5;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 0, 6);
    taxonSetEditingPanel.add(scrollPane3, c);
    c.gridx = 2;
    c.gridy = 2;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 3, 6);
    taxonSetEditingPanel.add(includedTaxaLabel, c);
    c.gridx = 2;
    c.gridy = 3;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 3, 6);
    taxonSetEditingPanel.add(panel2, c);
    JPanel panel3 = new JPanel();
    panel3.setOpaque(false);
    panel3.setLayout(new GridBagLayout());
    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.5;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 2, 12);
    panel3.add(scrollPane1, c);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(2, 0, 0, 12);
    panel3.add(actionPanel1, c);
    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 0.5;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 0, 0);
    panel3.add(taxonSetEditingPanel, c);
    setOpaque(false);
    setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12)));
    setLayout(new BorderLayout(0, 0));
    add(panel3, BorderLayout.CENTER);
    //		taxonSetsTable.addMouseListener(new MouseAdapter() {
    //			public void mouseClicked(MouseEvent e) {
    //				if (e.getClickCount() == 2) {
    //					JTable target = (JTable)e.getSource();
    //					int row = target.getSelectedRow();
    //					taxonSetsTableDoubleClicked(row);
    //				}
    //			}
    //		});
    includedTaxaSearchField.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
            selectIncludedTaxa(includedTaxaSearchField.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            selectIncludedTaxa(includedTaxaSearchField.getText());
        }

        public void insertUpdate(DocumentEvent e) {
            selectIncludedTaxa(includedTaxaSearchField.getText());
        }
    });
    excludedTaxaSearchField.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
            selectExcludedTaxa(excludedTaxaSearchField.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            selectExcludedTaxa(excludedTaxaSearchField.getText());
        }

        public void insertUpdate(DocumentEvent e) {
            selectExcludedTaxa(excludedTaxaSearchField.getText());
        }
    });
    includedTaxaTable.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                includeSelectedTaxa();
            }
        }
    });
    excludedTaxaTable.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                excludeSelectedTaxa();
            }
        }
    });
    includedTaxaTable.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent focusEvent) {
            excludedTaxaTable.clearSelection();
        }
    });
    excludedTaxaTable.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent focusEvent) {
            includedTaxaTable.clearSelection();
        }
    });
    includedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!includedSelectionChanging) {
                if (includedTaxonSetsComboBox.getSelectedIndex() != 0) {
                    includedTaxonSetsComboBox.setSelectedIndex(0);
                }
                includedTaxaSearchField.setText("");
            }
        }
    });
    includedTaxonSetsComboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            includedSelectionChanging = true;
            includedTaxaTable.clearSelection();
            if (includedTaxonSetsComboBox.getSelectedIndex() > 0) {
                String taxaName = includedTaxonSetsComboBox.getSelectedItem().toString();
                if (!taxaName.endsWith("...")) {
                    Taxa taxa = options.getTaxa(taxaName);
                    if (taxa != null) {
                        for (int i = 0; i < taxa.getTaxonCount(); i++) {
                            Taxon taxon = taxa.getTaxon(i);
                            int index = includedTaxa.indexOf(taxon);
                            includedTaxaTable.getSelectionModel().addSelectionInterval(index, index);
                        }
                    }
                }
            }
            includedSelectionChanging = false;
        }
    });
    excludedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!excludedSelectionChanging) {
                if (excludedTaxonSetsComboBox.getSelectedIndex() != 0) {
                    excludedTaxonSetsComboBox.setSelectedIndex(0);
                }
                excludedTaxaSearchField.setText("");
            }
        }
    });
    excludedTaxonSetsComboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            excludedSelectionChanging = true;
            excludedTaxaTable.clearSelection();
            if (excludedTaxonSetsComboBox.getSelectedIndex() > 0) {
                String taxaName = excludedTaxonSetsComboBox.getSelectedItem().toString();
                if (!taxaName.endsWith("...")) {
                    Taxa taxa = options.getTaxa(taxaName);
                    if (taxa != null) {
                        for (int i = 0; i < taxa.getTaxonCount(); i++) {
                            Taxon taxon = taxa.getTaxon(i);
                            int index = excludedTaxa.indexOf(taxon);
                            excludedTaxaTable.getSelectionModel().addSelectionInterval(index, index);
                        }
                    }
                }
            }
            excludedSelectionChanging = false;
        }
    });
    includedTaxaTable.doLayout();
    excludedTaxaTable.doLayout();
}
Also used : DocumentListener(javax.swing.event.DocumentListener) BorderUIResource(javax.swing.plaf.BorderUIResource) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Taxa(dr.evolution.util.Taxa) TableRenderer(jam.table.TableRenderer) Taxon(dr.evolution.util.Taxon) DocumentEvent(javax.swing.event.DocumentEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionPanel(jam.panels.ActionPanel)

Example 73 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class TreeUtils method setHeightsFromDates.

/**
     * Sets the tip heights from the tip dates
     */
public static void setHeightsFromDates(MutableTree tree) {
    dr.evolution.util.Date mostRecent = null;
    for (int i = 0; i < tree.getExternalNodeCount(); i++) {
        Taxon taxon = tree.getNodeTaxon(tree.getExternalNode(i));
        dr.evolution.util.Date date = (dr.evolution.util.Date) taxon.getAttribute("date");
        if (date != null) {
            if ((mostRecent == null) || date.after(mostRecent)) {
                mostRecent = date;
            }
        }
    }
    TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
    for (int i = 0; i < tree.getExternalNodeCount(); i++) {
        NodeRef node = tree.getExternalNode(i);
        Taxon taxon = tree.getNodeTaxon(node);
        dr.evolution.util.Date date = (dr.evolution.util.Date) taxon.getAttribute("date");
        if (date != null) {
            double height = timeScale.convertTime(date.getTimeValue(), date);
            tree.setNodeHeight(node, height);
        } else {
            tree.setNodeHeight(node, 0.0);
        }
    }
    adjustInternalHeights(tree, tree.getRoot());
    if (mostRecent != null) {
        tree.setUnits(mostRecent.getUnits());
    }
}
Also used : NodeRef(dr.evolution.tree.NodeRef) Taxon(dr.evolution.util.Taxon) Date(dr.evolution.util.Date) TimeScale(dr.evolution.util.TimeScale) Date(dr.evolution.util.Date)

Example 74 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class TreeUtils method getTipDates.

/**
     * Gets the tip dates from a tree.
     */
public static void getTipDates(Tree tree, Variate dates) {
    for (int i = 0; i < tree.getExternalNodeCount(); i++) {
        Taxon taxon = tree.getNodeTaxon(tree.getExternalNode(i));
        Object date = taxon.getAttribute("date");
        if (date != null) {
            if (date instanceof Date) {
                dates.add(((Date) date).getTimeValue());
            } else {
                try {
                    dates.add(Double.parseDouble(date.toString()));
                } catch (NumberFormatException nfe) {
                    dates.add(0.0);
                }
            }
        } else {
            dates.add(0.0);
        }
    }
}
Also used : Taxon(dr.evolution.util.Taxon) Date(dr.evolution.util.Date)

Example 75 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class TraitsPanel method guessTrait.

public void guessTrait() {
    if (options.taxonList == null) {
        // validation of check empty taxonList
        return;
    }
    if (currentTrait == null) {
        if (!addTrait()) {
            // if addTrait() cancel then false
            return;
        }
    }
    int result;
    do {
        TraitGuesser currentTraitGuesser = new TraitGuesser(currentTrait);
        if (guessTraitDialog == null) {
            guessTraitDialog = new GuessTraitDialog(frame);
        }
        guessTraitDialog.setDescription("Extract values for trait '" + currentTrait + "' from taxa labels");
        result = guessTraitDialog.showDialog();
        if (result == -1 || result == JOptionPane.CANCEL_OPTION) {
            return;
        }
        guessTraitDialog.setupGuesserFromDialog(currentTraitGuesser);
        try {
            int[] selRows = dataTable.getSelectedRows();
            if (selRows.length > 0) {
                Taxa selectedTaxa = new Taxa();
                for (int row : selRows) {
                    Taxon taxon = (Taxon) dataTable.getValueAt(row, 0);
                    selectedTaxa.addTaxon(taxon);
                }
                currentTraitGuesser.guessTrait(selectedTaxa);
            } else {
                currentTraitGuesser.guessTrait(options.taxonList);
            }
        } catch (IllegalArgumentException iae) {
            JOptionPane.showMessageDialog(this, iae.getMessage(), "Unable to guess trait value", JOptionPane.ERROR_MESSAGE);
            result = -1;
        }
        dataTableModel.fireTableDataChanged();
    } while (result < 0);
}
Also used : TraitGuesser(dr.app.beauti.options.TraitGuesser) Taxa(dr.evolution.util.Taxa) Taxon(dr.evolution.util.Taxon)

Aggregations

Taxon (dr.evolution.util.Taxon)151 Taxa (dr.evolution.util.Taxa)31 ArrayList (java.util.ArrayList)24 TaxonList (dr.evolution.util.TaxonList)19 NodeRef (dr.evolution.tree.NodeRef)18 Date (dr.evolution.util.Date)18 Tree (dr.evolution.tree.Tree)15 Sequence (dr.evolution.sequence.Sequence)12 TreeModel (dr.evomodel.tree.TreeModel)12 Parameter (dr.inference.model.Parameter)12 Attribute (dr.util.Attribute)11 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)10 Patterns (dr.evolution.alignment.Patterns)9 NewickImporter (dr.evolution.io.NewickImporter)7 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)7 Microsatellite (dr.evolution.datatype.Microsatellite)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 PatternList (dr.evolution.alignment.PatternList)4 DataType (dr.evolution.datatype.DataType)4