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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations