Search in sources :

Example 6 with TraitSet

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

the class NexusParser method parseCalibrationsBlock.

/**
 * parse calibrations block and create TraitSet *
 */
protected TraitSet parseCalibrationsBlock(final BufferedReader fin) throws IOException {
    final TraitSet traitSet = new TraitSet();
    traitSet.setID("traitsetDate");
    traitSet.traitNameInput.setValue("date", traitSet);
    String str;
    do {
        str = nextLine(fin);
        if (str.toLowerCase().contains("options")) {
            String scale = getAttValue("scale", str);
            if (scale.endsWith("s")) {
                scale = scale.substring(0, scale.length() - 1);
            }
            traitSet.unitsInput.setValue(scale, traitSet);
        }
    } while (str.toLowerCase().contains("tipcalibration"));
    String text = "";
    while (true) {
        str = nextLine(fin);
        if (str.contains(";")) {
            break;
        }
        text += str;
    }
    final String[] strs = text.split(",");
    text = "";
    for (final String str2 : strs) {
        final String[] parts = str2.split(":");
        final String date = parts[0].replaceAll(".*=\\s*", "");
        final String[] taxa = parts[1].split("\\s+");
        for (final String taxon : taxa) {
            if (!taxon.matches("^\\s*$")) {
                text += taxon + "=" + date + ",\n";
            }
        }
    }
    text = text.substring(0, text.length() - 2);
    traitSet.traitsInput.setValue(text, traitSet);
    final TaxonSet taxa = new TaxonSet();
    taxa.initByName("alignment", m_alignment);
    traitSet.taxaInput.setValue(taxa, traitSet);
    traitSet.initAndValidate();
    return traitSet;
}
Also used : TraitSet(beast.evolution.tree.TraitSet)

Example 7 with TraitSet

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

the class UnorderedAlignmentsTest method getDates.

public static TraitSet getDates(TaxonSet taxa) throws Exception {
    TraitSet timeTrait = new TraitSet();
    String trait = String.join(",", (Iterable<String>) IntStream.range(0, 16).mapToObj(i -> taxa.getTaxonId(i) + "=" + i / 3.0)::iterator);
    timeTrait.initByName("traitname", "date-forward", "taxa", taxa, "value", trait);
    return timeTrait;
}
Also used : IntStream(java.util.stream.IntStream) Tree(beast.evolution.tree.Tree) Frequencies(beast.evolution.substitutionmodel.Frequencies) ConstantPopulation(beast.evolution.tree.coalescent.ConstantPopulation) TraitSet(beast.evolution.tree.TraitSet) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Taxon(beast.evolution.alignment.Taxon) Alignment(beast.evolution.alignment.Alignment) RandomTree(beast.evolution.tree.RandomTree) SiteModel(beast.evolution.sitemodel.SiteModel) RealParameter(beast.core.parameter.RealParameter) TaxonSet(beast.evolution.alignment.TaxonSet) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) TestCase(junit.framework.TestCase) Collections(java.util.Collections) SimulatedAlignment(beast.app.seqgen.SimulatedAlignment) HKY(beast.evolution.substitutionmodel.HKY) TraitSet(beast.evolution.tree.TraitSet)

Example 8 with TraitSet

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

the class UnorderedAlignmentsTest method getTree.

public static Tree getTree(TaxonSet taxa) throws Exception {
    Tree tree = new RandomTree();
    TraitSet dates = getDates(taxa);
    ConstantPopulation constant = new ConstantPopulation();
    constant.initByName("popSize", new RealParameter("5.0"));
    tree.initByName("taxonset", taxa, "populationModel", constant, "trait", dates);
    return tree;
}
Also used : ConstantPopulation(beast.evolution.tree.coalescent.ConstantPopulation) RandomTree(beast.evolution.tree.RandomTree) TraitSet(beast.evolution.tree.TraitSet) Tree(beast.evolution.tree.Tree) RandomTree(beast.evolution.tree.RandomTree) RealParameter(beast.core.parameter.RealParameter)

Example 9 with TraitSet

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

the class TraitSetTest method testDateForwardUnspecified.

@Test
public void testDateForwardUnspecified() {
    int Nleaves = 2;
    TraitSet timeTrait = new TraitSet();
    timeTrait.initByName("traitname", "date-forward", "taxa", taxonSet(Nleaves), "value", "t1=10");
    // The trait actually represents the age of the taxa relative to
    // each other with arbitrary zero, so we test it like this.
    assertEquals(0.0, timeTrait.getValue("t0") - timeTrait.getValue("t1"), 1e-7);
}
Also used : TraitSet(beast.evolution.tree.TraitSet) Test(org.junit.Test)

Example 10 with TraitSet

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

the class TraitSetTest method testDateBackward.

@Test
public void testDateBackward() {
    int Nleaves = 2;
    TraitSet timeTrait = new TraitSet();
    timeTrait.initByName("traitname", "date-backward", "taxa", taxonSet(Nleaves), "value", "t0=0, t1=10");
    // The trait actually represents the age of the taxa relative to
    // each other with arbitrary zero, so we test it like this.
    assertEquals(-10.0, timeTrait.getValue("t0") - timeTrait.getValue("t1"), 1e-7);
}
Also used : TraitSet(beast.evolution.tree.TraitSet) Test(org.junit.Test)

Aggregations

TraitSet (beast.evolution.tree.TraitSet)11 Test (org.junit.Test)5 RealParameter (beast.core.parameter.RealParameter)3 Alignment (beast.evolution.alignment.Alignment)3 TaxonSet (beast.evolution.alignment.TaxonSet)3 RandomTree (beast.evolution.tree.RandomTree)3 Tree (beast.evolution.tree.Tree)3 ConstantPopulation (beast.evolution.tree.coalescent.ConstantPopulation)3 Taxon (beast.evolution.alignment.Taxon)2 SimulatedAlignment (beast.app.seqgen.SimulatedAlignment)1 MCMC (beast.core.MCMC)1 CompoundDistribution (beast.core.util.CompoundDistribution)1 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)1 Sequence (beast.evolution.alignment.Sequence)1 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)1 TipDatesRandomWalker (beast.evolution.operators.TipDatesRandomWalker)1 SiteModel (beast.evolution.sitemodel.SiteModel)1 Frequencies (beast.evolution.substitutionmodel.Frequencies)1 HKY (beast.evolution.substitutionmodel.HKY)1 TreeIntervals (beast.evolution.tree.coalescent.TreeIntervals)1