use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class STARBEASTGenerator method writeMultiSpecies.
/**
* write tag <sp>
*
* @param taxonList TaxonList
* @param writer XMLWriter
*/
private void writeMultiSpecies(TaxonList taxonList, XMLWriter writer) {
List<String> species = options.starBEASTOptions.getSpeciesList();
String sp;
// used in private String getIndicatorsParaValue()
numOfSpecies = species.size();
for (String eachSp : species) {
writer.writeOpenTag(SpeciesBindingsSPinfoParser.SP, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, eachSp) });
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Taxon taxon = null;
try {
taxon = taxonList.getTaxon(i);
sp = taxon.getAttribute(TraitData.TRAIT_SPECIES).toString();
} catch (Exception e) {
throw new IllegalArgumentException("Cannot get value from Taxon " + taxon.getId());
}
if (sp.equals(eachSp)) {
writer.writeIDref(TaxonParser.TAXON, taxon.getId());
}
}
writer.writeCloseTag(SpeciesBindingsSPinfoParser.SP);
}
writeGeneTrees(writer);
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class STARBEASTGenerator method writeGeneTrees.
private void writeGeneTrees(XMLWriter writer) {
writer.writeComment("Collection of Gene Trees");
writer.writeOpenTag(SpeciesBindingsParser.GENE_TREES, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SpeciesBindingsParser.GENE_TREES) });
boolean isSameAllPloidyType = true;
PloidyType checkSamePloidyType = options.getPartitionTreeModels().get(0).getPloidyType();
for (PartitionTreeModel model : options.getPartitionTreeModels()) {
if (checkSamePloidyType != model.getPloidyType()) {
isSameAllPloidyType = false;
break;
}
}
if (isSameAllPloidyType) {
// generate gene trees regarding each data partition
for (PartitionTreeModel model : options.getPartitionTreeModels()) {
writer.writeIDref(TreeModel.TREE_MODEL, model.getPrefix() + TreeModel.TREE_MODEL);
}
} else {
// give ploidy
for (PartitionTreeModel model : options.getPartitionTreeModels()) {
writer.writeOpenTag(SpeciesBindingsParser.GTREE, new Attribute[] { new Attribute.Default<String>(SpeciesBindingsParser.PLOIDY, Double.toString(model.getPloidyType().getValue())) });
writer.writeIDref(TreeModel.TREE_MODEL, model.getPrefix() + TreeModel.TREE_MODEL);
writer.writeCloseTag(SpeciesBindingsParser.GTREE);
}
}
writer.writeCloseTag(SpeciesBindingsParser.GENE_TREES);
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class STARBEASTGenerator method writeSpeciesTreeLikelihood.
private void writeSpeciesTreeLikelihood(XMLWriter writer) {
TreePriorType nodeHeightPrior = options.getPartitionTreePriors().get(0).getNodeHeightPrior();
if (nodeHeightPrior == TreePriorType.SPECIES_BIRTH_DEATH) {
writer.writeComment("Species Tree Likelihood: Birth Death Model");
writer.writeOpenTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SPECIATION_LIKE) });
writer.writeOpenTag(SpeciationLikelihoodParser.MODEL);
writer.writeIDref(BirthDeathModelParser.BIRTH_DEATH_MODEL, BirthDeathModelParser.BIRTH_DEATH);
writer.writeCloseTag(SpeciationLikelihoodParser.MODEL);
} else if (nodeHeightPrior == TreePriorType.SPECIES_YULE || nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
writer.writeComment("Species Tree Likelihood: Yule Model");
writer.writeOpenTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SPECIATION_LIKE) });
writer.writeOpenTag(SpeciationLikelihoodParser.MODEL);
writer.writeIDref(YuleModelParser.YULE_MODEL, YuleModelParser.YULE);
writer.writeCloseTag(SpeciationLikelihoodParser.MODEL);
if (nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
// should be only 1 calibrated node with monophyletic for species tree at moment
if (options.speciesSets.size() == 1 && options.speciesSetsMono.size() == 1) {
Taxa t = options.speciesSets.get(0);
Parameter nodeCalib = options.getStatistic(t);
writer.writeOpenTag(SpeciationLikelihoodParser.CALIBRATION, new Attribute[] { new Attribute.Default<String>(SpeciationLikelihoodParser.CORRECTION, CalibrationPoints.CorrectionType.EXACT.toString()) });
writer.writeOpenTag(SpeciationLikelihoodParser.POINT);
writer.writeIDref(TaxaParser.TAXA, t.getId());
writeDistribution(nodeCalib, true, writer);
writer.writeCloseTag(SpeciationLikelihoodParser.POINT);
writer.writeCloseTag(SpeciationLikelihoodParser.CALIBRATION);
if (!options.treeModelOptions.isNodeCalibrated(nodeCalib)) {
}
} else {
throw new IllegalArgumentException("Calibrated Yule model is only applied to 1 calibrated node with monophyletic for species tree at moment !");
}
}
} else {
throw new IllegalArgumentException("Get wrong species tree prior using *BEAST : " + nodeHeightPrior.toString());
}
// <sp> tree
writer.writeOpenTag(SpeciesTreeModelParser.SPECIES_TREE);
writer.writeIDref(SpeciesTreeModelParser.SPECIES_TREE, SP_TREE);
writer.writeCloseTag(SpeciesTreeModelParser.SPECIES_TREE);
writer.writeCloseTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD);
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class SubstitutionModelGenerator method writeBinaryCovarionModel.
/**
* Write the Binary covarion model XML block
*
* @param writer the writer
* @param model the partition model to write
*/
public void writeBinaryCovarionModel(XMLWriter writer, PartitionSubstitutionModel model) {
// String dataTypeDescription = TwoStateCovarion.INSTANCE.getDescription(); // dataType="twoStateCovarion" for COVARION_MODEL
String prefix = model.getPrefix();
writer.writeComment("The Binary covarion model");
writer.writeOpenTag(BinaryCovarionModelParser.COVARION_MODEL, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, prefix + "bcov") });
if (model.getFrequencyPolicy() == FrequencyPolicyType.EMPIRICAL) {
List<AbstractPartitionData> partitions = options.getDataPartitions(model);
Alignment alignment = ((PartitionData) partitions.get(0)).getAlignment();
// Patterns patterns = new Patterns(partitions.get(0).getAlignment());
// for (int i = 1; i < partitions.size(); i++) {
// patterns.addPatterns(partitions.get(i).getAlignment());
// }
double[] frequencies = alignment.getStateFrequencies();
writer.writeOpenTag(FrequencyModelParser.FREQUENCIES);
writer.writeTag(ParameterParser.PARAMETER, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, prefix + "frequencies"), new Attribute.Default<String>(ParameterParser.VALUE, frequencies[0] + " " + frequencies[1]) }, true);
writer.writeCloseTag(FrequencyModelParser.FREQUENCIES);
} else {
writeFrequencyModelBinary(writer, model, prefix);
}
writeParameter(BinaryCovarionModelParser.HIDDEN_FREQUENCIES, prefix + "hfrequencies", 2, 0.5, 0.0, 1.0, // hfrequencies also 0.5 0.5
writer);
writeParameter(BinaryCovarionModelParser.ALPHA, "bcov.alpha", model, writer);
writeParameter(BinaryCovarionModelParser.SWITCHING_RATE, "bcov.s", model, writer);
writer.writeCloseTag(BinaryCovarionModelParser.COVARION_MODEL);
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class XMLGenerator method writeTaxa.
// END: writeBranchRatesModel
private void writeTaxa(Taxa taxa, XMLWriter writer, String suffix) {
// tagname
writer.writeOpenTag(// tagname
TaxaParser.TAXA, new Attribute[] { // attributes[]
new Attribute.Default<String>(XMLParser.ID, TaxaParser.TAXA + suffix) });
for (int i = 0; i < taxa.getTaxonCount(); i++) {
Taxon taxon = taxa.getTaxon(i);
writer.writeTag(// tagname
TaxonParser.TAXON, new Attribute[] { // attributes[]
new Attribute.Default<String>(XMLParser.ID, taxon.getId()) }, // close
true);
}
// END: i loop
writer.writeCloseTag(TaxaParser.TAXA);
}
Aggregations