Search in sources :

Example 1 with TreeDistribution

use of beast.evolution.tree.TreeDistribution in project beast2 by CompEvol.

the class TreeDistributionInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int listItemNr, ExpandOption isExpandOption, boolean addButtons) {
    m_bAddButtons = addButtons;
    m_input = input;
    m_beastObject = beastObject;
    this.itemNr = listItemNr;
    Box itemBox = Box.createHorizontalBox();
    TreeDistribution distr = (TreeDistribution) beastObject;
    String text = "";
    if (distr.treeInput.get() != null) {
        text += distr.treeInput.get().getID();
    } else {
        text += distr.treeIntervalsInput.get().treeInput.get().getID();
    }
    JLabel label = new JLabel(text);
    Font font = label.getFont();
    Dimension size = new Dimension(font.getSize() * 200 / 12, font.getSize() * 2);
    label.setMinimumSize(size);
    label.setPreferredSize(size);
    itemBox.add(label);
    // List<String> availableBEASTObjects =
    // PluginPanel.getAvailablePlugins(m_input, m_beastObject, null);
    List<BeautiSubTemplate> availableBEASTObjects = doc.getInputEditorFactory().getAvailableTemplates(m_input, m_beastObject, null, doc);
    // make sure we are dealing with a TreeDistribution
    for (int i = availableBEASTObjects.size() - 1; i >= 0; i--) {
        BeautiSubTemplate t = availableBEASTObjects.get(i);
        Class<?> c = t._class;
        if (!(TreeDistribution.class.isAssignableFrom(c))) {
            availableBEASTObjects.remove(i);
        }
    }
    JComboBox<BeautiSubTemplate> comboBox = new JComboBox<>(availableBEASTObjects.toArray(new BeautiSubTemplate[] {}));
    comboBox.setName("TreeDistribution");
    for (int i = availableBEASTObjects.size() - 1; i >= 0; i--) {
        if (!TreeDistribution.class.isAssignableFrom(availableBEASTObjects.get(i)._class)) {
            availableBEASTObjects.remove(i);
        }
    }
    String id = distr.getID();
    try {
        // id = BeautiDoc.parsePartition(id);
        id = id.substring(0, id.indexOf('.'));
    } catch (Exception e) {
        throw new RuntimeException("Improperly formatted ID: " + distr.getID());
    }
    for (BeautiSubTemplate template : availableBEASTObjects) {
        if (template.matchesName(id)) {
            // getMainID().replaceAll(".\\$\\(n\\)",
            // "").equals(id)) {
            comboBox.setSelectedItem(template);
        }
    }
    comboBox.addActionListener(e -> {
        m_e = e;
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                @SuppressWarnings("unchecked") JComboBox<BeautiSubTemplate> currentComboBox = (JComboBox<BeautiSubTemplate>) m_e.getSource();
                @SuppressWarnings("unchecked") List<BEASTInterface> list = (List<BEASTInterface>) m_input.get();
                BeautiSubTemplate template = (BeautiSubTemplate) currentComboBox.getSelectedItem();
                PartitionContext partitionContext = doc.getContextFor(list.get(itemNr));
                try {
                    template.createSubNet(partitionContext, list, itemNr, true);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                sync();
                refreshPanel();
            }
        });
    });
    itemBox.add(comboBox);
    itemBox.add(Box.createGlue());
    m_validateLabel = new SmallLabel("x", new Color(200, 0, 0));
    m_validateLabel.setVisible(false);
    validateInput();
    itemBox.add(m_validateLabel);
    add(itemBox);
}
Also used : SmallLabel(beast.app.draw.SmallLabel) JComboBox(javax.swing.JComboBox) Color(java.awt.Color) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JComboBox(javax.swing.JComboBox) Dimension(java.awt.Dimension) Font(java.awt.Font) TreeDistribution(beast.evolution.tree.TreeDistribution) List(java.util.List) BEASTInterface(beast.core.BEASTInterface)

Example 2 with TreeDistribution

use of beast.evolution.tree.TreeDistribution in project beast2 by CompEvol.

the class PriorListInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
    List<?> list = (List<?>) input.get();
    Collections.sort(list, (Object o1, Object o2) -> {
        if (o1 instanceof BEASTInterface && o2 instanceof BEASTInterface) {
            String d1 = ((BEASTInterface) o1).getID();
            String id2 = ((BEASTInterface) o2).getID();
            // first the tree priors
            if (o1 instanceof TreeDistribution) {
                if (o2 instanceof TreeDistribution) {
                    TreeInterface tree1 = ((TreeDistribution) o1).treeInput.get();
                    if (tree1 == null) {
                        tree1 = ((TreeDistribution) o1).treeIntervalsInput.get().treeInput.get();
                    }
                    TreeInterface tree2 = ((TreeDistribution) o2).treeInput.get();
                    if (tree2 == null) {
                        tree2 = ((TreeDistribution) o2).treeIntervalsInput.get().treeInput.get();
                    }
                    return d1.compareTo(id2);
                } else {
                    return -1;
                }
            } else if (o1 instanceof MRCAPrior) {
                // last MRCA priors
                if (o2 instanceof MRCAPrior) {
                    return d1.compareTo(id2);
                } else {
                    return 1;
                }
            } else {
                if (o2 instanceof TreeDistribution) {
                    return 1;
                }
                if (o2 instanceof MRCAPrior) {
                    return -1;
                }
                if (o1 instanceof Prior) {
                    d1 = ((Prior) o1).getParameterName();
                }
                if (o2 instanceof Prior) {
                    id2 = ((Prior) o2).getParameterName();
                }
                return d1.compareTo(id2);
            }
        }
        return 0;
    });
    rangeButtons = new ArrayList<>();
    taxonButtons = new ArrayList<>();
    // m_buttonStatus = ButtonStatus.NONE;
    super.init(input, beastObject, itemNr, isExpandOption, addButtons);
    if (beastObject instanceof BeautiPanelConfig) {
        BeautiPanelConfig config = (BeautiPanelConfig) beastObject;
        if (config.parentBEASTObjects != null && config.parentBEASTObjects.size() > 0 && config.parentBEASTObjects.get(0).getID().equals("speciescoalescent")) {
            m_buttonStatus = ButtonStatus.NONE;
        }
    }
    if (m_buttonStatus == ButtonStatus.ALL || m_buttonStatus == ButtonStatus.ADD_ONLY) {
        addButton = new SmallButton("+ Add Prior", true);
        addButton.setName("addItem");
        addButton.setToolTipText("Add new prior (like an MRCA-prior) to the list of priors");
        addButton.addActionListener(e -> {
            addItem();
        });
        buttonBox.add(addButton);
        buttonBox.add(Box.createHorizontalGlue());
    }
}
Also used : TreeDistribution(beast.evolution.tree.TreeDistribution) Prior(beast.math.distributions.Prior) MRCAPrior(beast.math.distributions.MRCAPrior) MRCAPrior(beast.math.distributions.MRCAPrior) SmallButton(beast.app.draw.SmallButton) ArrayList(java.util.ArrayList) List(java.util.List) BEASTInterface(beast.core.BEASTInterface) TreeInterface(beast.evolution.tree.TreeInterface)

Example 3 with TreeDistribution

use of beast.evolution.tree.TreeDistribution in project beast2 by CompEvol.

the class TreeDistributionInputEditor method validateInput.

@Override
public void validateInput() {
    TreeDistribution distr = (TreeDistribution) m_beastObject;
    // TODO: robustify for the case the tree is not a simple binary tree
    Tree tree = (Tree) distr.treeInput.get();
    if (tree == null) {
        tree = distr.treeIntervalsInput.get().treeInput.get();
    }
    if (tree.hasDateTrait()) {
        if (!distr.canHandleTipDates()) {
            m_validateLabel.setToolTipText("This tree prior cannot handle dated tips. Choose another tree prior.");
            m_validateLabel.m_circleColor = Color.red;
            m_validateLabel.setVisible(true);
            return;
        }
    }
    super.validateInput();
}
Also used : TreeDistribution(beast.evolution.tree.TreeDistribution) Tree(beast.evolution.tree.Tree)

Aggregations

TreeDistribution (beast.evolution.tree.TreeDistribution)3 BEASTInterface (beast.core.BEASTInterface)2 List (java.util.List)2 SmallButton (beast.app.draw.SmallButton)1 SmallLabel (beast.app.draw.SmallLabel)1 Tree (beast.evolution.tree.Tree)1 TreeInterface (beast.evolution.tree.TreeInterface)1 MRCAPrior (beast.math.distributions.MRCAPrior)1 Prior (beast.math.distributions.Prior)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 ArrayList (java.util.ArrayList)1 Box (javax.swing.Box)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1