Search in sources :

Example 6 with PartitionTreeModel

use of dr.app.beauti.options.PartitionTreeModel in project beast-mcmc by beast-dev.

the class TipDateSamplingComponentGenerator method writeJointParameters.

private void writeJointParameters(XMLWriter writer, TaxonList taxa) {
    for (int i = 0; i < taxa.getTaxonCount(); i++) {
        Taxon taxon = taxa.getTaxon(i);
        Set<PartitionTreeModel> treeModels = new HashSet<PartitionTreeModel>();
        for (PartitionTreeModel treeModel : options.getPartitionTreeModels()) {
            for (AbstractPartitionData data : options.getDataPartitions(treeModel)) {
                if (data.getTaxonList().asList().contains(taxon)) {
                    treeModels.add(treeModel);
                }
            }
        }
        // if we are sampling within precisions then only include this leaf if precision > 0
        if (treeModels.size() > 0) {
            writer.writeOpenTag("jointParameter", new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "age(" + taxon.getId() + ")") });
            for (PartitionTreeModel treeModel : treeModels) {
                writer.writeTag(ParameterParser.PARAMETER, new Attribute.Default<String>(XMLParser.IDREF, treeModel.getPrefix() + "age(" + taxon.getId() + ")"), true);
            }
            writer.writeCloseTag("jointParameter");
        }
    }
}
Also used : AbstractPartitionData(dr.app.beauti.options.AbstractPartitionData) Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel) HashSet(java.util.HashSet)

Example 7 with PartitionTreeModel

use of dr.app.beauti.options.PartitionTreeModel in project beast-mcmc by beast-dev.

the class TipDateSamplingComponentGenerator method generate.

protected void generate(final InsertionPoint point, final Object item, final String prefix, final XMLWriter writer) {
    TipDateSamplingComponentOptions comp = (TipDateSamplingComponentOptions) options.getComponentOptions(TipDateSamplingComponentOptions.class);
    TaxonList taxa = comp.getTaxonSet();
    switch(point) {
        case IN_TREE_MODEL:
            {
                writeLeafHeightParameters(writer, (PartitionTreeModel) item, taxa);
            }
            break;
        case AFTER_TREE_MODEL:
            if (options.getPartitionTreeModels().size() > 1) {
                // we have multiple treeModels with some or all the same taxa - create a JointParameter for each...
                writeJointParameters(writer, taxa);
            }
            if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_JOINT) {
                writer.writeOpenTag("compoundParameter", new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "treeModel.tipDates") });
                for (int i = 0; i < taxa.getTaxonCount(); i++) {
                    Taxon taxon = taxa.getTaxon(i);
                    writer.writeIDref(ParameterParser.PARAMETER, "age(" + taxon.getId() + ")");
                }
                writer.writeCloseTag("compoundParameter");
            }
            break;
        case IN_MCMC_PRIOR:
            if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_INDIVIDUALLY || comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_PRECISION) {
            // nothing to do - individual parameter priors are written automatically
            } else if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_JOINT) {
            }
            break;
        case IN_FILE_LOG_PARAMETERS:
            if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_INDIVIDUALLY || comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_PRECISION) {
                for (int i = 0; i < taxa.getTaxonCount(); i++) {
                    Taxon taxon = taxa.getTaxon(i);
                    writer.writeIDref(ParameterParser.PARAMETER, "age(" + taxon.getId() + ")");
                }
            } else if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_JOINT) {
                writer.writeIDref(ParameterParser.PARAMETER, "treeModel.tipDates");
            }
            break;
        default:
            throw new IllegalArgumentException("This insertion point is not implemented for " + this.getClass().getName());
    }
}
Also used : Attribute(dr.util.Attribute) TaxonList(dr.evolution.util.TaxonList) Taxon(dr.evolution.util.Taxon) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel)

Example 8 with PartitionTreeModel

use of dr.app.beauti.options.PartitionTreeModel in project beast-mcmc by beast-dev.

the class TipDateSamplingComponentGenerator method writeLeafHeightParameters.

private void writeLeafHeightParameters(XMLWriter writer, PartitionTreeModel item, TaxonList taxa) {
    // only include this taxon as a leaf height if it found in this partition.
    PartitionTreeModel treeModel = (PartitionTreeModel) item;
    Set<Taxon> taxonSet = new HashSet<Taxon>();
    for (AbstractPartitionData data : options.getDataPartitions(treeModel)) {
        if (data.getTaxonList() != null) {
            for (Taxon taxon : data.getTaxonList()) {
                taxonSet.add(taxon);
            }
        }
    }
    for (int i = 0; i < taxa.getTaxonCount(); i++) {
        Taxon taxon = taxa.getTaxon(i);
        if (taxonSet.contains(taxon)) {
            // if we are sampling within precisions then only include this leaf if precision > 0
            writer.writeOpenTag("leafHeight", new Attribute[] { new Attribute.Default<String>(TaxonParser.TAXON, taxon.getId()) });
            writer.writeTag(ParameterParser.PARAMETER, new Attribute.Default<String>(XMLParser.ID, treeModel.getPrefix() + "age(" + taxon.getId() + ")"), true);
            writer.writeCloseTag("leafHeight");
        }
    }
}
Also used : AbstractPartitionData(dr.app.beauti.options.AbstractPartitionData) Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel) HashSet(java.util.HashSet)

Aggregations

PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)8 Attribute (dr.util.Attribute)5 Taxon (dr.evolution.util.Taxon)3 AbstractPartitionData (dr.app.beauti.options.AbstractPartitionData)2 Taxa (dr.evolution.util.Taxa)2 TaxonList (dr.evolution.util.TaxonList)2 HashSet (java.util.HashSet)2 TreePriorType (dr.app.beauti.types.TreePriorType)1 PloidyType (dr.evolution.datatype.PloidyType)1