use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class STARBEASTGenerator method writeStartingTreeForCalibration.
public void writeStartingTreeForCalibration(XMLWriter writer) {
writer.writeComment("species starting tree for calibration");
writer.writeText("");
writer.writeOpenTag(OldCoalescentSimulatorParser.COALESCENT_TREE, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SP_START_TREE) });
Attribute[] taxaAttribute = { new Attribute.Default<String>(XMLParser.IDREF, ALL_SPECIES) };
writer.writeOpenTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
writer.writeTag(TaxaParser.TAXA, taxaAttribute, true);
for (Taxa taxa : options.speciesSets) {
Parameter statistic = options.getStatistic(taxa);
Attribute mono = new Attribute.Default<Boolean>(OldCoalescentSimulatorParser.IS_MONOPHYLETIC, options.speciesSetsMono.get(taxa));
writer.writeOpenTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT, mono);
writer.writeIDref(TaxaParser.TAXA, taxa.getId());
if (options.getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_YULE_CALIBRATION && statistic.priorType == PriorType.UNIFORM_PRIOR) {
writeDistribution(statistic, false, writer);
}
writer.writeCloseTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT);
}
writer.writeCloseTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
writer.writeOpenTag(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "spInitDemo"), new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(options.units)) });
writer.writeOpenTag(ConstantPopulationModelParser.POPULATION_SIZE);
// "initial" is "value"
double popSizeValue = options.getPartitionTreePriors().get(0).getParameter("constant.popSize").getInitial();
writer.writeTag(ParameterParser.PARAMETER, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "sp.popSize"), new Attribute.Default<Double>(ParameterParser.VALUE, popSizeValue) }, true);
writer.writeCloseTag(ConstantPopulationModelParser.POPULATION_SIZE);
writer.writeCloseTag(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL);
writer.writeCloseTag(OldCoalescentSimulatorParser.COALESCENT_TREE);
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class STARBEASTGenerator method writeSpeciesTreePrior.
private void writeSpeciesTreePrior(XMLWriter writer) {
Parameter para;
TreePriorType nodeHeightPrior = options.getPartitionTreePriors().get(0).getNodeHeightPrior();
if (nodeHeightPrior == TreePriorType.SPECIES_BIRTH_DEATH) {
writer.writeComment("Species tree prior: Birth Death Model");
writer.writeOpenTag(BirthDeathModelParser.BIRTH_DEATH_MODEL, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, BirthDeathModelParser.BIRTH_DEATH), new Attribute.Default<String>(XMLUnits.UNITS, XMLUnits.SUBSTITUTIONS) });
writer.writeOpenTag(BirthDeathModelParser.BIRTHDIFF_RATE);
para = options.starBEASTOptions.getParameter(TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME);
// writer.writeTag(ParameterParser.PARAMETER, new Attribute[]{
// new Attribute.Default<String>(XMLParser.ID, TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME),
// new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(para.initial)),
// new Attribute.Default<String>(ParameterParser.LOWER, Double.toString(para.lower)),
// new Attribute.Default<String>(ParameterParser.UPPER, Double.toString(para.upper))}, true);
writeParameter(TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME, para, writer);
writer.writeCloseTag(BirthDeathModelParser.BIRTHDIFF_RATE);
writer.writeOpenTag(BirthDeathModelParser.RELATIVE_DEATH_RATE);
para = options.starBEASTOptions.getParameter(TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME);
// writer.writeTag(ParameterParser.PARAMETER, new Attribute[]{
// new Attribute.Default<String>(XMLParser.ID, TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME),
// new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(para.initial)),
// new Attribute.Default<String>(ParameterParser.LOWER, Double.toString(para.lower)),
// new Attribute.Default<String>(ParameterParser.UPPER, Double.toString(para.upper))}, true);
writeParameter(TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME, para, writer);
writer.writeCloseTag(BirthDeathModelParser.RELATIVE_DEATH_RATE);
writer.writeCloseTag(BirthDeathModelParser.BIRTH_DEATH_MODEL);
} else if (nodeHeightPrior == TreePriorType.SPECIES_YULE || nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
writer.writeComment("Species tree prior: Yule Model");
writer.writeOpenTag(YuleModelParser.YULE_MODEL, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, YuleModelParser.YULE), new Attribute.Default<String>(XMLUnits.UNITS, XMLUnits.SUBSTITUTIONS) });
writer.writeOpenTag(YuleModelParser.BIRTH_RATE);
para = options.starBEASTOptions.getParameter(TraitData.TRAIT_SPECIES + "." + YuleModelParser.YULE + "." + YuleModelParser.BIRTH_RATE);
// writer.writeTag(ParameterParser.PARAMETER, new Attribute[]{
// new Attribute.Default<String>(XMLParser.ID, TraitData.TRAIT_SPECIES + "." + YuleModelParser.YULE + "." + YuleModelParser.BIRTH_RATE),
// new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(para.initial)),
// new Attribute.Default<String>(ParameterParser.LOWER, Double.toString(para.lower)),
// new Attribute.Default<String>(ParameterParser.UPPER, Double.toString(para.upper))}, true);
writeParameter(TraitData.TRAIT_SPECIES + "." + YuleModelParser.YULE + "." + YuleModelParser.BIRTH_RATE, para, writer);
writer.writeCloseTag(YuleModelParser.BIRTH_RATE);
writer.writeCloseTag(YuleModelParser.YULE_MODEL);
} else if (nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
} else {
throw new IllegalArgumentException("Get wrong species tree prior using *BEAST : " + nodeHeightPrior.toString());
}
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class XMLWriter method writeTag.
public void writeTag(String tagname, Attribute[] attributes, boolean close) {
StringBuffer buffer = new StringBuffer("<");
buffer.append(tagname);
for (Attribute attribute : attributes) {
if (attribute != null) {
buffer.append(' ');
buffer.append(attribute.getAttributeName());
buffer.append("=\"");
buffer.append(attribute.getAttributeValue());
buffer.append("\"");
}
}
if (close) {
buffer.append("/");
}
buffer.append(">");
writeText(buffer.toString());
if (!close) {
increaseLevel();
}
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class SubstitutionModelGenerator method writeSubstitutionSiteModel.
/**
* Writes the substitution model to XML.
*
* @param writer the writer
* @param model the partition model to write in BEAST XML
*/
public void writeSubstitutionSiteModel(PartitionSubstitutionModel model, XMLWriter writer) {
DataType dataType = model.getDataType();
String dataTypeDescription = dataType.getDescription();
switch(dataType.getType()) {
case DataType.NUCLEOTIDES:
if (model.isUnlinkedSubstitutionModel()) {
for (int i = 1; i <= model.getCodonPartitionCount(); i++) {
switch(model.getNucSubstitutionModel()) {
case JC:
writeJCModel(i, writer, model);
break;
case HKY:
writeHKYModel(i, writer, model);
break;
case TN93:
writeTN93Model(i, writer, model);
break;
case GTR:
writeGTRModel(i, writer, model);
break;
default:
throw new IllegalArgumentException("unknown substition model type");
}
}
} else {
switch(model.getNucSubstitutionModel()) {
case JC:
writeJCModel(-1, writer, model);
break;
case HKY:
writeHKYModel(-1, writer, model);
break;
case TN93:
writeTN93Model(-1, writer, model);
break;
case GTR:
writeGTRModel(-1, writer, model);
break;
default:
throw new IllegalArgumentException("unknown substitution model type");
}
}
//****************** Site Model *****************
if (model.getCodonPartitionCount() > 1) {
//model.getCodonHeteroPattern() != null) {
for (int i = 1; i <= model.getCodonPartitionCount(); i++) {
writeNucSiteModel(i, writer, model);
}
writer.println();
} else {
writeNucSiteModel(-1, writer, model);
}
break;
case DataType.AMINO_ACIDS:
// Amino Acid model
String aaModel = model.getAaSubstitutionModel().getXMLName();
writer.writeComment("The " + aaModel + " substitution model");
writer.writeTag(EmpiricalAminoAcidModelParser.EMPIRICAL_AMINO_ACID_MODEL, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, model.getPrefix() + "aa"), new Attribute.Default<String>("type", aaModel) }, true);
//****************** Site Model *****************
writeAASiteModel(writer, model);
break;
case DataType.TWO_STATES:
case DataType.COVARION:
switch(model.getBinarySubstitutionModel()) {
case BIN_DOLLO:
return;
case BIN_SIMPLE:
writeBinarySimpleModel(writer, model);
break;
case BIN_COVARION:
writeBinaryCovarionModel(writer, model);
break;
}
//****************** Site Model *****************
writeTwoStateSiteModel(writer, model);
break;
case DataType.GENERAL:
case DataType.CONTINUOUS:
//handled by component
break;
case DataType.MICRO_SAT:
writeMicrosatSubstModel(model, writer);
break;
default:
throw new IllegalArgumentException("Unknown data type");
}
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class TreeModelGenerator method writeTreeModel.
/**
* Write tree model XML block.
*
* @param model
* @param writer the writer
*/
void writeTreeModel(PartitionTreeModel model, XMLWriter writer) {
setModelPrefix(model.getPrefix());
// treemodel.treeModel or treeModel
final String treeModelName = modelPrefix + TreeModel.TREE_MODEL;
writer.writeComment("Generate a tree model");
writer.writeTag(TreeModel.TREE_MODEL, new Attribute.Default<String>(XMLParser.ID, treeModelName), false);
final String STARTING_TREE = InitialTreeGenerator.STARTING_TREE;
switch(model.getStartingTreeType()) {
case USER:
writer.writeIDref("tree", modelPrefix + STARTING_TREE);
break;
case UPGMA:
writer.writeIDref(UPGMATreeParser.UPGMA_TREE, modelPrefix + STARTING_TREE);
break;
case RANDOM:
writer.writeIDref(OldCoalescentSimulatorParser.COALESCENT_TREE, modelPrefix + STARTING_TREE);
break;
default:
throw new IllegalArgumentException("Unknown StartingTreeType");
}
writer.writeOpenTag(TreeModelParser.ROOT_HEIGHT);
writer.writeTag(ParameterParser.PARAMETER, new Attribute.Default<String>(XMLParser.ID, treeModelName + "." + OldCoalescentSimulatorParser.ROOT_HEIGHT), true);
writer.writeCloseTag(TreeModelParser.ROOT_HEIGHT);
writer.writeOpenTag(TreeModelParser.NODE_HEIGHTS, new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES, "true"));
writer.writeTag(ParameterParser.PARAMETER, new Attribute.Default<String>(XMLParser.ID, treeModelName + "." + "internalNodeHeights"), true);
writer.writeCloseTag(TreeModelParser.NODE_HEIGHTS);
writer.writeOpenTag(TreeModelParser.NODE_HEIGHTS, new Attribute[] { new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES, "true"), new Attribute.Default<String>(TreeModelParser.ROOT_NODE, "true") });
writer.writeTag(ParameterParser.PARAMETER, new Attribute.Default<String>(XMLParser.ID, treeModelName + "." + "allInternalNodeHeights"), true);
writer.writeCloseTag(TreeModelParser.NODE_HEIGHTS);
// int randomLocalClockCount = 0;
// int autocorrelatedClockCount = 0;
// for (PartitionData pd : model.getDataPartitions()) { // only the PDs linked to this tree model
// PartitionClockModel clockModel = pd.getPartitionClockModel();
// switch (clockModel.getClockType()) {
// case AUTOCORRELATED_LOGNORMAL: autocorrelatedClockCount += 1; break;
// case RANDOM_LOCAL_CLOCK: randomLocalClockCount += 1; break;
// }
// }
//
// if (autocorrelatedClockCount > 1 || randomLocalClockCount > 1 || autocorrelatedClockCount + randomLocalClockCount > 1) {
// //FAIL
// throw new IllegalArgumentException("clock model/tree model combination not implemented by BEAST yet!");
// }
// move to validateClockTreeModelCombination(PartitionTreeModel model)
// if (autocorrelatedClockCount == 1) {
// if (count[0] == 1) {
// writer.writeOpenTag(TreeModelParser.NODE_RATES,
// new Attribute[]{
// new Attribute.Default<String>(TreeModelParser.ROOT_NODE, "false"),
// new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES, "true"),
// new Attribute.Default<String>(TreeModelParser.LEAF_NODES, "true")
// });
// writer.writeTag(ParameterParser.PARAMETER,
// new Attribute.Default<String>(XMLParser.ID, treeModelName + "." + TreeModelParser.NODE_RATES), true);
// writer.writeCloseTag(TreeModelParser.NODE_RATES);
//
// writer.writeOpenTag(TreeModelParser.NODE_RATES,
// new Attribute[]{
// new Attribute.Default<String>(TreeModelParser.ROOT_NODE, "true"),
// new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES, "false"),
// new Attribute.Default<String>(TreeModelParser.LEAF_NODES, "false")
// });
// writer.writeTag(ParameterParser.PARAMETER,
// new Attribute.Default<String>(XMLParser.ID,
// treeModelName + "." + RateEvolutionLikelihood.ROOTRATE), true);
// writer.writeCloseTag(TreeModelParser.NODE_RATES);
//// } else if (randomLocalClockCount == 1 ) {
// } else
//+++++++++++++ removed because random local clock XML is changed ++++++++++++++++
// int[] count = validateClockTreeModelCombination(model);
// if (count[1] == 1) {
// writer.writeOpenTag(TreeModelParser.NODE_RATES,
// new Attribute[]{
// new Attribute.Default<String>(TreeModelParser.ROOT_NODE, "false"),
// new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES, "true"),
// new Attribute.Default<String>(TreeModelParser.LEAF_NODES, "true")
// });
// writer.writeTag(ParameterParser.PARAMETER,
// new Attribute.Default<String>(XMLParser.ID, modelPrefix + ClockType.LOCAL_CLOCK + ".relativeRates"), true);
// writer.writeCloseTag(TreeModelParser.NODE_RATES);
//
// writer.writeOpenTag(TreeModelParser.NODE_TRAITS,
// new Attribute[]{
// new Attribute.Default<String>(TreeModelParser.ROOT_NODE, "false"),
// new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES, "true"),
// new Attribute.Default<String>(TreeModelParser.LEAF_NODES, "true")
// });
// writer.writeTag(ParameterParser.PARAMETER,
// new Attribute.Default<String>(XMLParser.ID, modelPrefix + ClockType.LOCAL_CLOCK + ".changes"), true);
// writer.writeCloseTag(TreeModelParser.NODE_TRAITS);
// }
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_TREE_MODEL, model, writer);
writer.writeCloseTag(TreeModel.TREE_MODEL);
// if (autocorrelatedClockCount == 1) {
// if (count[0] == 1) {
// writer.writeText("");
// writer.writeOpenTag(CompoundParameter.COMPOUND_PARAMETER,
// new Attribute[]{new Attribute.Default<String>(XMLParser.ID, treeModelName + "." + "allRates")});
// writer.writeIDref(ParameterParser.PARAMETER, treeModelName + "." + TreeModelParser.NODE_RATES);
// writer.writeIDref(ParameterParser.PARAMETER, treeModelName + "." + RateEvolutionLikelihood.ROOTRATE);
// writer.writeCloseTag(CompoundParameter.COMPOUND_PARAMETER);
// }
writer.writeComment("Statistic for time of most recent common ancestor of tree");
writer.writeTag(TMRCAStatisticParser.TMRCA_STATISTIC, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, treeModelName + ".rootAge"), new Attribute.Default<String>(TMRCAStatisticParser.ABSOLUTE, "true") }, false);
writer.writeIDref(TreeModel.TREE_MODEL, treeModelName);
writer.writeCloseTag(TMRCAStatisticParser.TMRCA_STATISTIC);
if (model.getDataType().getType() == DataType.MICRO_SAT) {
for (AbstractPartitionData partitionData : options.getDataPartitions(model)) {
writer.writeComment("Generate a microsatellite tree model");
writer.writeTag(MicrosatelliteSamplerTreeModelParser.TREE_MICROSATELLITE_SAMPLER_MODEL, new Attribute.Default<String>(XMLParser.ID, partitionData.getName() + "." + MicrosatelliteSamplerTreeModelParser.TREE_MICROSATELLITE_SAMPLER_MODEL), false);
writer.writeOpenTag(MicrosatelliteSamplerTreeModelParser.TREE);
writer.writeIDref(TreeModel.TREE_MODEL, treeModelName);
writer.writeCloseTag(MicrosatelliteSamplerTreeModelParser.TREE);
writer.writeOpenTag(MicrosatelliteSamplerTreeModelParser.INTERNAL_VALUES);
writer.writeTag(ParameterParser.PARAMETER, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, partitionData.getName() + "." + MicrosatelliteSamplerTreeModelParser.TREE_MICROSATELLITE_SAMPLER_MODEL + ".internalNodesParameter"), new Attribute.Default<Integer>(ParameterParser.DIMENSION, model.getDimension()) }, true);
writer.writeCloseTag(MicrosatelliteSamplerTreeModelParser.INTERNAL_VALUES);
writer.writeOpenTag(MicrosatelliteSamplerTreeModelParser.EXTERNAL_VALUES);
writer.writeIDref(MicrosatellitePatternParser.MICROSATPATTERN, partitionData.getName());
writer.writeCloseTag(MicrosatelliteSamplerTreeModelParser.EXTERNAL_VALUES);
writer.writeCloseTag(MicrosatelliteSamplerTreeModelParser.TREE_MICROSATELLITE_SAMPLER_MODEL);
}
}
}
Aggregations