Search in sources :

Example 6 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class ClockModelListInputEditor method setUpOperator.

/**
 * set up relative weights and parameter input *
 */
private void setUpOperator() {
    String weights = "";
    List<RealParameter> parameters = operator.parameterInput.get();
    parameters.clear();
    double commonClockRate = -1;
    boolean isAllClocksAreEqual = true;
    try {
        for (int i = 0; i < doc.alignments.size(); i++) {
            Alignment data = doc.alignments.get(i);
            int weight = data.getSiteCount();
            BranchRateModel.Base clockModel = (BranchRateModel.Base) doc.clockModels.get(i);
            RealParameter clockRate = clockModel.meanRateInput.get();
            // clockRate.m_bIsEstimated.setValue(true, clockRate);
            if (clockRate.isEstimatedInput.get()) {
                if (commonClockRate < 0) {
                    commonClockRate = clockRate.valuesInput.get().get(0);
                } else {
                    if (Math.abs(commonClockRate - clockRate.valuesInput.get().get(0)) > 1e-10) {
                        isAllClocksAreEqual = false;
                    }
                }
                weights += weight + " ";
                parameters.add(clockRate);
            }
        // doc.autoSetClockRate = false;
        }
        if (!fixMeanRatesCheckBox.isSelected()) {
            fixMeanRatesValidateLabel.setVisible(false);
            return;
        }
        if (parameters.size() == 0) {
            fixMeanRatesValidateLabel.setVisible(true);
            fixMeanRatesValidateLabel.m_circleColor = Color.red;
            fixMeanRatesValidateLabel.setToolTipText("The model is invalid: At least one clock rate should be estimated.");
            return;
        }
        IntegerParameter weightParameter = new IntegerParameter(weights);
        weightParameter.setID("weightparameter");
        weightParameter.isEstimatedInput.setValue(false, weightParameter);
        operator.parameterWeightsInput.setValue(weightParameter, operator);
        if (!isAllClocksAreEqual) {
            fixMeanRatesValidateLabel.setVisible(true);
            fixMeanRatesValidateLabel.m_circleColor = Color.orange;
            fixMeanRatesValidateLabel.setToolTipText("Not all clocks are equal. Are you sure this is what you want?");
        } else if (parameters.size() == 1) {
            fixMeanRatesValidateLabel.setVisible(true);
            fixMeanRatesValidateLabel.m_circleColor = Color.orange;
            fixMeanRatesValidateLabel.setToolTipText("At least 2 clock models should have their rate estimated");
        } else if (parameters.size() < doc.alignments.size()) {
            fixMeanRatesValidateLabel.setVisible(true);
            fixMeanRatesValidateLabel.m_circleColor = Color.orange;
            fixMeanRatesValidateLabel.setToolTipText("Not all partitions have their rate estimated");
        } else {
            fixMeanRatesValidateLabel.setVisible(false);
        }
        repaint();
    // doc.autoSetClockRate = true;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) Alignment(beast.evolution.alignment.Alignment) BranchRateModel(beast.evolution.branchratemodel.BranchRateModel) RealParameter(beast.core.parameter.RealParameter)

Example 7 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class FilteredAlignmentTest method testIndividualsFiltered.

@Test
public void testIndividualsFiltered() throws Exception {
    Alignment data = getAlignment();
    FilteredAlignment data2 = new FilteredAlignment();
    data2.initByName("data", data, "filter", "1");
    assertEquals(1, data2.getSiteCount());
    data2.initByName("data", data, "filter", "2,5");
    assertEquals(2, data2.getSiteCount());
    data2.initByName("data", data, "filter", "2,5,3,4");
    assertEquals(4, data2.getSiteCount());
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Test(org.junit.Test)

Example 8 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class FilteredAlignmentTest method getAlignment2.

public static Alignment getAlignment2() throws Exception {
    // reordered from getAlignment()
    Sequence human = new Sequence("0human", "AAAACCCCTTTTGGGG");
    Sequence chimp = new Sequence("1chimp", "ACTGACGTACGTACGT");
    Alignment data = new Alignment();
    data.initByName("sequence", human, "sequence", chimp, "dataType", "nucleotide");
    return data;
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Sequence(beast.evolution.alignment.Sequence)

Example 9 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class FilteredAlignmentTest method testConstantSites.

@Test
public void testConstantSites() throws Exception {
    Alignment data = getAlignment();
    FilteredAlignment data2 = new FilteredAlignment();
    // missing one weight for constant sites (nucleotide data)
    try {
        data2.initByName("data", data, "filter", "-", "constantSiteWeights", "11232  2  3");
        throw new Exception("Should have failed by now");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
    }
    // filter alignment with constant sites
    data2 = new FilteredAlignment();
    data2.initByName("data", data, "filter", "-", "constantSiteWeights", "11232  2  3 4");
    String weights = Arrays.toString(data2.getWeights());
    System.err.println(weights);
    assertEquals("[11233, 1, 1, 1, 1, 3, 1, 1, 1, 1, 4, 1, 1, 1, 1, 5]", weights);
    // filter alignment with constant sites, so some constant sites are missing from the original alignment
    data2 = new FilteredAlignment();
    data2.initByName("data", data, "filter", "-8", "constantSiteWeights", "11232 2 3 4");
    weights = Arrays.toString(data2.getWeights());
    System.err.println(weights);
    assertEquals("[11233, 1, 1, 1, 1, 3, 1, 1, 3, 4]", weights);
    // add constant sites to ordinary alignment and strip constant sites
    data2 = new FilteredAlignment();
    data2.initByName("data", data, "filter", "-8", "constantSiteWeights", "11232 2 3 4", "strip", true);
    weights = Arrays.toString(data2.getWeights());
    System.err.println(weights);
    assertEquals("[11232, 1, 1, 1, 1, 2, 1, 1, 3, 4]", weights);
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Test(org.junit.Test)

Example 10 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class FilteredAlignmentTest method getAlignment.

public static Alignment getAlignment() throws Exception {
    Sequence human = new Sequence("0human", "AAAACCCCGGGGTTTT");
    Sequence chimp = new Sequence("1chimp", "ACGTACGTACGTACGT");
    Alignment data = new Alignment();
    data.initByName("sequence", human, "sequence", chimp, "dataType", "nucleotide");
    return data;
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Sequence(beast.evolution.alignment.Sequence)

Aggregations

Alignment (beast.evolution.alignment.Alignment)102 Test (org.junit.Test)43 Sequence (beast.evolution.alignment.Sequence)31 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)30 Tree (beast.evolution.tree.Tree)29 SiteModel (beast.evolution.sitemodel.SiteModel)27 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)22 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)20 ArrayList (java.util.ArrayList)17 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)17 Frequencies (beast.evolution.substitutionmodel.Frequencies)13 RealParameter (beast.core.parameter.RealParameter)12 TaxonSet (beast.evolution.alignment.TaxonSet)11 BEASTInterface (beast.core.BEASTInterface)10 ClusterTree (beast.util.ClusterTree)9 Taxon (beast.evolution.alignment.Taxon)6 HKY (beast.evolution.substitutionmodel.HKY)6 Node (beast.evolution.tree.Node)6 TreeParser (beast.util.TreeParser)6 IOException (java.io.IOException)6