<commit_before>/*
 * PartitionTreePriorPanel.java
 *
 * Copyright (C) 2002-2009 <NAME> and <NAME>
 *
 * This file is part of BEAST.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership and licensing.
 *
 * BEAST is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * BEAST is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with BEAST; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

package dr.app.beauti.treespanel;

import dr.app.beauti.options.PartitionTreeModel;
import dr.app.beauti.options.PartitionTreePrior;
import dr.app.beauti.types.TreePriorParameterizationType;
import dr.app.beauti.types.TreePriorType;
import dr.app.beauti.util.PanelUtils;
import dr.app.gui.components.WholeNumberField;
import dr.app.util.OSType;
import dr.evomodel.coalescent.VariableDemographicModel;
import dr.evomodelxml.speciation.BirthDeathModelParser;
import dr.evomodelxml.speciation.BirthDeathSerialSamplingModelParser;
import jam.panels.OptionsPanel;

import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.EnumSet;

/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @version $Id: PriorsPanel.java,v 1.9 2006/09/05 13:29:34 rambaut Exp $
 */
public class PartitionTreePriorPanel extends OptionsPanel {

    private static final long serialVersionUID = 5016996360264782252L;

    private JComboBox treePriorCombo = new JComboBox(EnumSet.range(TreePriorType.CONSTANT,
            TreePriorType.BIRTH_DEATH_SERI_SAMP_ESTIM).toArray());

    private JComboBox parameterizationCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.GROWTH_RATE,
            TreePriorParameterizationType.DOUBLING_TIME).toArray());
    //    private JComboBox parameterizationCombo1 = new JComboBox(EnumSet.of(TreePriorParameterizationType.DOUBLING_TIME).toArray());
    private JComboBox bayesianSkylineCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.CONSTANT_SKYLINE,
            TreePriorParameterizationType.LINEAR_SKYLINE).toArray());
    private WholeNumberField groupCountField = new WholeNumberField(2, Integer.MAX_VALUE);

    private JComboBox extendedBayesianSkylineCombo = new JComboBox(
            new VariableDemographicModel.Type[]{VariableDemographicModel.Type.LINEAR, VariableDemographicModel.Type.STEPWISE});

    private JComboBox gmrfBayesianSkyrideCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.UNIFORM_SKYRIDE,
            TreePriorParameterizationType.TIME_AWARE_SKYRIDE).toArray());

//    RealNumberField samplingProportionField = new RealNumberField(Double.MIN_VALUE, 1.0);

//	private BeautiFrame frame = null;
//	private BeautiOptions options = null;

    PartitionTreePrior partitionTreePrior;
    private final TreesPanel treesPanel;

    private boolean settingOptions = false;


    public PartitionTreePriorPanel(PartitionTreePrior parTreePrior, TreesPanel parent) {
        super(12, (OSType.isMac() ? 6 : 24));

        this.partitionTreePrior = parTreePrior;
        this.treesPanel = parent;

        PanelUtils.setupComponent(treePriorCombo);
        treePriorCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                if (treePriorCombo.getSelectedItem() != null) {
                    partitionTreePrior.setNodeHeightPrior((TreePriorType) treePriorCombo.getSelectedItem());
                    setupPanel();
                }
            }
        });

        PanelUtils.setupComponent(parameterizationCombo);
        parameterizationCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                partitionTreePrior.setParameterization((TreePriorParameterizationType) parameterizationCombo.getSelectedItem());
            }
        });

//        PanelUtils.setupComponent(parameterizationCombo1);
//        parameterizationCombo1.addItemListener(new ItemListener() {
//            public void itemStateChanged(ItemEvent ev) {
//            	partitionTreePrior.setParameterization((TreePriorParameterizationType) parameterizationCombo1.getSelectedItem());
//            }
//        });

        PanelUtils.setupComponent(groupCountField);
        groupCountField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent ev) {
                // move to here?
            }
        });


        PanelUtils.setupComponent(bayesianSkylineCombo);
        bayesianSkylineCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                partitionTreePrior.setSkylineModel((TreePriorParameterizationType) bayesianSkylineCombo.getSelectedItem());
            }
        });

        PanelUtils.setupComponent(extendedBayesianSkylineCombo);
        extendedBayesianSkylineCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                partitionTreePrior.setExtendedSkylineModel(((VariableDemographicModel.Type)
                        extendedBayesianSkylineCombo.getSelectedItem()));
            }
        });

        PanelUtils.setupComponent(gmrfBayesianSkyrideCombo);
        gmrfBayesianSkyrideCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                partitionTreePrior.setSkyrideSmoothing((TreePriorParameterizationType) gmrfBayesianSkyrideCombo.getSelectedItem());
            }
        });


//	        samplingProportionField.addKeyListener(keyListener);

        setupPanel();
    }

    private void setupPanel() {

        removeAll();

        JTextArea citationText = new JTextArea(1, 200);
        citationText.setLineWrap(true);
        citationText.setEditable(false);
        citationText.setFont(this.getFont());
//        JScrollPane scrollPane = new JScrollPane(citation, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
//                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
//        scrollPane.setOpaque(true);

        String citation = null;
        String citationCoalescent = "<NAME>., (1982) The coalescent. Stochastic Process. Appl. 13:235-248.";

        addComponentWithLabel("Tree Prior:", treePriorCombo);

        switch ((TreePriorType) treePriorCombo.getSelectedItem()) {
            case CONSTANT:
                citation = citationCoalescent;
                break;

            case EXPONENTIAL:
            case LOGISTIC:
            case EXPANSION:
                addComponentWithLabel("Parameterization for growth:", parameterizationCombo);
                partitionTreePrior.setParameterization((TreePriorParameterizationType) parameterizationCombo.getSelectedItem());

                citation = citationCoalescent
                        + "\n<NAME>., <NAME>., 1994. Sampling theory for neutral alleles in a varying environment. " +
                        "Philos Trans R Soc Lond B Biol Sci, 344(1310):403-410."
                        + "\nD<NAME>, Rambaut A & Shapiro B and Pybus OG (2005) Mol Biol Evol 22, 1185-1192.";
                break;

            case SKYLINE:
                groupCountField.setColumns(6);
                addComponentWithLabel("Number of groups:", groupCountField);
                addComponentWithLabel("Skyline Model:", bayesianSkylineCombo);

                citation = citationCoalescent + "\n<NAME>, Rambaut A & Shapiro B and Pybus OG (2005) Mol Biol Evol 22, 1185-1192.";
                break;

            case EXTENDED_SKYLINE:
                addComponentWithLabel("Model Type:", extendedBayesianSkylineCombo);
                treesPanel.linkTreePriorCheck.setSelected(true);
                treesPanel.updateShareSameTreePriorChanged();

                citation = citationCoalescent + "\n<NAME> and <NAME> (2008) Bayesian inference of population size history " +
                        "from multiple loci. BMC Evolutionary Biology, 8, 289.";
                break;

            case GMRF_SKYRIDE:
                addComponentWithLabel("Smoothing:", gmrfBayesianSkyrideCombo);
                //For GMRF, one tree prior has to be associated to one tree model. The validation is in BeastGenerator.checkOptions()
                addLabel("<html>For GMRF, tree model/tree prior combination not implemented by BEAST yet. "
                        + "It is only available for single tree model partition for this release.<br>"
                        + "Please go to Data Partition panel to link all tree models." + "</html>");

                citation = citationCoalescent + "\n<NAME> and Suchard (2008) Mol Biol Evol, 25, 1459-1471.";
                break;
            case YULE:

                citation = "<NAME> (1925) A Mathematical Theory of Evolution, based on the Conclusions of Dr. <NAME>, F.R.S., " +
                        "Philosophical Transactions of the Royal Society of London, Ser. B, 213, 2187.";
                break;
            case BIRTH_DEATH:
                citation = BirthDeathModelParser.getCitation();
                break;
            case BIRTH_DEATH_INCOM_SAMP:
                citation = BirthDeathModelParser.getCitationRHO();
                break;
            case BIRTH_DEATH_SERI_SAMP:
                citation = BirthDeathSerialSamplingModelParser.getCitationPsiOrg();
                break;
            case BIRTH_DEATH_SERI_SAMP_ESTIM:
                citation = BirthDeathSerialSamplingModelParser.getCitationRT();
                break;
            default:
                throw new RuntimeException("No tree prior has been specified so cannot refer to it");
        }

        if (treesPanel.options.maximumTipHeight > 0)
            citation = citation<commit_msg>Added Tanja's paper back to the Yule citation.<commit_after>/*
 * PartitionTreePriorPanel.java
 *
 * Copyright (C) 2002-2009 <NAME> and <NAME>
 *
 * This file is part of BEAST.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership and licensing.
 *
 * BEAST is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * BEAST is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with BEAST; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

package dr.app.beauti.treespanel;

import dr.app.beauti.options.PartitionTreeModel;
import dr.app.beauti.options.PartitionTreePrior;
import dr.app.beauti.types.TreePriorParameterizationType;
import dr.app.beauti.types.TreePriorType;
import dr.app.beauti.util.PanelUtils;
import dr.app.gui.components.WholeNumberField;
import dr.app.util.OSType;
import dr.evomodel.coalescent.VariableDemographicModel;
import dr.evomodelxml.speciation.BirthDeathModelParser;
import dr.evomodelxml.speciation.BirthDeathSerialSamplingModelParser;
import jam.panels.OptionsPanel;

import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.EnumSet;

/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @version $Id: PriorsPanel.java,v 1.9 2006/09/05 13:29:34 rambaut Exp $
 */
public class PartitionTreePriorPanel extends OptionsPanel {

    private static final long serialVersionUID = 5016996360264782252L;

    private JComboBox treePriorCombo = new JComboBox(EnumSet.range(TreePriorType.CONSTANT,
            TreePriorType.BIRTH_DEATH_SERI_SAMP_ESTIM).toArray());

    private JComboBox parameterizationCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.GROWTH_RATE,
            TreePriorParameterizationType.DOUBLING_TIME).toArray());
    //    private JComboBox parameterizationCombo1 = new JComboBox(EnumSet.of(TreePriorParameterizationType.DOUBLING_TIME).toArray());
    private JComboBox bayesianSkylineCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.CONSTANT_SKYLINE,
            TreePriorParameterizationType.LINEAR_SKYLINE).toArray());
    private WholeNumberField groupCountField = new WholeNumberField(2, Integer.MAX_VALUE);

    private JComboBox extendedBayesianSkylineCombo = new JComboBox(
            new VariableDemographicModel.Type[]{VariableDemographicModel.Type.LINEAR, VariableDemographicModel.Type.STEPWISE});

    private JComboBox gmrfBayesianSkyrideCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.UNIFORM_SKYRIDE,
            TreePriorParameterizationType.TIME_AWARE_SKYRIDE).toArray());

//    RealNumberField samplingProportionField = new RealNumberField(Double.MIN_VALUE, 1.0);

//	private BeautiFrame frame = null;
//	private BeautiOptions options = null;

    PartitionTreePrior partitionTreePrior;
    private final TreesPanel treesPanel;

    private boolean settingOptions = false;


    public PartitionTreePriorPanel(PartitionTreePrior parTreePrior, TreesPanel parent) {
        super(12, (OSType.isMac() ? 6 : 24));

        this.partitionTreePrior = parTreePrior;
        this.treesPanel = parent;

        PanelUtils.setupComponent(treePriorCombo);
        treePriorCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                if (treePriorCombo.getSelectedItem() != null) {
                    partitionTreePrior.setNodeHeightPrior((TreePriorType) treePriorCombo.getSelectedItem());
                    setupPanel();
                }
            }
        });

        PanelUtils.setupComponent(parameterizationCombo);
        parameterizationCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                partitionTreePrior.setParameterization((TreePriorParameterizationType) parameterizationCombo.getSelectedItem());
            }
        });

//        PanelUtils.setupComponent(parameterizationCombo1);
//        parameterizationCombo1.addItemListener(new ItemListener() {
//            public void itemStateChanged(ItemEvent ev) {
//            	partitionTreePrior.setParameterization((TreePriorParameterizationType) parameterizationCombo1.getSelectedItem());
//            }
//        });

        PanelUtils.setupComponent(groupCountField);
        groupCountField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent ev) {
                // move to here?
            }
        });


        PanelUtils.setupComponent(bayesianSkylineCombo);
        bayesianSkylineCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                partitionTreePrior.setSkylineModel((TreePriorParameterizationType) bayesianSkylineCombo.getSelectedItem());
            }
        });

        PanelUtils.setupComponent(extendedBayesianSkylineCombo);
        extendedBayesianSkylineCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                partitionTreePrior.setExtendedSkylineModel(((VariableDemographicModel.Type)
                        extendedBayesianSkylineCombo.getSelectedItem()));
            }
        });

        PanelUtils.setupComponent(gmrfBayesianSkyrideCombo);
        gmrfBayesianSkyrideCombo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ev) {
                partitionTreePrior.setSkyrideSmoothing((TreePriorParameterizationType) gmrfBayesianSkyrideCombo.getSelectedItem());
            }
        });


//	        samplingProportionField.addKeyListener(keyListener);

        setupPanel();
    }

    private void setupPanel() {

        removeAll();

        JTextArea citationText = new JTextArea(1, 200);
        citationText.setLineWrap(true);
        citationText.setEditable(false);
        citationText.setFont(this.getFont());
//        JScrollPane scrollPane = new JScrollPane(citation, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
//                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
//        scrollPane.setOpaque(true);

        String citation = null;
        String citationCoalescent = "<NAME>., (1982) The coalescent. Stochastic Process. Appl. 13:235-248.";

        addComponentWithLabel("Tree Prior:", treePriorCombo);

        switch ((TreePriorType) treePriorCombo.getSelectedItem()) {
            case CONSTANT:
                citation = citationCoalescent;
                break;

            case EXPONENTIAL:
            case LOGISTIC:
            case EXPANSION:
                addComponentWithLabel("Parameterization for growth:", parameterizationCombo);
                partitionTreePrior.setParameterization((TreePriorParameterizationType) parameterizationCombo.getSelectedItem());

                citation = citationCoalescent
                        + "\n<NAME>., <NAME>., 1994. Sampling theory for neutral alleles in a varying environment. " +
                        "Philos Trans R Soc Lond B Biol Sci, 344(1310):403-410."
                        + "\n<NAME>, <NAME> & <NAME> and Pybus OG (2005) Mol Biol Evol 22, 1185-1192.";
                break;

            case SKYLINE:
                groupCountField.setColumns(6);
                addComponentWithLabel("Number of groups:", groupCountField);
                addComponentWithLabel("Skyline Model:", bayesianSkylineCombo);

                citation = citationCoalescent + "\n<NAME>, Rambaut A & <NAME> and Pybus OG (2005) Mol Biol Evol 22, 1185-1192.";
                break;

            case EXTENDED_SKYLINE:
                addComponentWithLabel("Model Type:", extendedBayesianSkylineCombo);
                treesPanel.linkTreePriorCheck.setSelected(true);
                treesPanel.updateShareSameTreePriorChanged();

                citation = citationCoalescent + "\n<NAME> and <NAME> (2008) Bayesian inference of population size history " +
                        "from multiple loci. BMC Evolutionary Biology, 8, 289.";
                break;

            case GMRF_SKYRIDE:
                addComponentWithLabel("Smoothing:", gmrfBayesianSkyrideCombo);
                //For GMRF, one tree prior has to be associated to one tree model. The validation is in BeastGenerator.checkOptions()
                addLabel("<html>For GMRF, tree model/tree prior combination not implemented by BEAST yet. "
                        + "It is only available for single tree model partition for this release.<br>"
                        + "Please go to Data Partition panel to link all tree models." + "</html>");

                citation = citationCoalescent + "\n<NAME> (2008) Mol Biol Evol, 25, 1459-1471.";
                break;
            case YULE:

                citation = "<NAME>., 2008. The conditioned reconstructed process. J Theor Biol 253, 769-778.\n" +
                            "<NAME> (1925) A Mathematical Theory of Evolution, based on the Conclusions of Dr. <NAME>, F.R.S., " +
                            "Philosophical Transactions of the Royal Society of London, Ser. B, 213, 21-87.";
                break;
            case BIRTH_DEATH:
                citation = BirthDeathModelParser.getCitation();
                break;
            case BIRTH_DEATH_INCOM_SAMP:
                citation = BirthDeathModelParser.getCitationRHO();
                break;
            case BIRTH_DEATH_SERI_SAMP:
                citation = BirthDeathSerialSamplingModelParser.getCitationPsiOrg();
                break;
            case BIRTH_DEATH_SERI_SAMP_ESTIM:
                citation = BirthDeathSerialSamplingModelParser.getCitationRT();
                break;
            default:
                throw new RuntimeException("No tree prior has been specified so cannot refer to it");
        }

        if (treesPanel.options.maximumTipHeight > 0)
            citation = citation
{'fraction_non_alphanumeric': 0.08185036124715124, 'fraction_numerical': 0.01643795762013286, 'mean_word_length': 2.761444464709101, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4624459', 'n_tokens_mistral': 5936, 'n_tokens_neox': 5324, 'n_words': 1286}