Search in sources :

Example 6 with AbstractPartitionData

use of dr.app.beauti.options.AbstractPartitionData 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);
        }
    }
}
Also used : AbstractPartitionData(dr.app.beauti.options.AbstractPartitionData) Attribute(dr.util.Attribute)

Example 7 with AbstractPartitionData

use of dr.app.beauti.options.AbstractPartitionData 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 8 with AbstractPartitionData

use of dr.app.beauti.options.AbstractPartitionData 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)

Example 9 with AbstractPartitionData

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

the class AncestralStatesComponentGenerator method writeLogs.

// END: writeCodonPartitionedRobustCounting()
private void writeLogs(XMLWriter writer, AncestralStatesComponentOptions component) {
    for (AbstractPartitionData partition : options.getDataPartitions()) {
        if (component.dNdSRobustCounting(partition)) {
            String prefix = partition.getName() + ".";
            writer.writeIDref("codonPartitionedRobustCounting", prefix + "robustCounting1");
            writer.writeIDref("codonPartitionedRobustCounting", prefix + "robustCounting2");
        } else {
        }
    }
}
Also used : AbstractPartitionData(dr.app.beauti.options.AbstractPartitionData)

Example 10 with AbstractPartitionData

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

the class AncestralStatesComponentGenerator method writeTreeLogs.

private void writeTreeLogs(XMLWriter writer, AncestralStatesComponentOptions component, PartitionTreeModel treeModel) {
    for (AbstractPartitionData partition : options.getDataPartitions()) {
        if (partition.getPartitionTreeModel() == treeModel) {
            if (component.dNdSRobustCounting(partition)) {
                String prefix = partition.getName() + ".";
                writer.writeIDref("codonPartitionedRobustCounting", prefix + "robustCounting1");
                writer.writeIDref("codonPartitionedRobustCounting", prefix + "robustCounting2");
            }
            if (component.reconstructAtNodes(partition)) {
                // is an alignment data partition
                PartitionSubstitutionModel substModel = partition.getPartitionSubstitutionModel();
                int cpCount = partition.getPartitionSubstitutionModel().getCodonPartitionCount();
                if (cpCount > 1) {
                    for (int i = 1; i <= substModel.getCodonPartitionCount(); i++) {
                        String prefix = partition.getPrefix() + substModel.getPrefixCodon(i);
                        String name = partition.getName() + "." + substModel.getPrefixCodon(i);
                        if (name.endsWith(".")) {
                            name = name.substring(0, name.length() - 1);
                        }
                        writeTrait(writer, partition, prefix, AncestralStateTreeLikelihoodParser.RECONSTRUCTION_TAG, name);
                    }
                } else {
                    writeTrait(writer, partition, partition.getPrefix(), AncestralStateTreeLikelihoodParser.RECONSTRUCTION_TAG, partition.getName());
                }
            }
            if (component.isCountingStates(partition)) {
                if (partition.getDataType().getType() == DataType.CONTINUOUS) {
                    throw new RuntimeException("Can't do counting on Continuous data partition");
                }
                PartitionSubstitutionModel substModel = partition.getPartitionSubstitutionModel();
                int cpCount = partition.getPartitionSubstitutionModel().getCodonPartitionCount();
                if (cpCount > 1) {
                    for (int i = 1; i <= substModel.getCodonPartitionCount(); i++) {
                        String prefix = partition.getPrefix() + substModel.getPrefixCodon(i);
                        String name = partition.getName() + "." + substModel.getPrefixCodon(i) + "count";
                        writeTrait(writer, partition, prefix, "count", name);
                    }
                } else {
                    writeTrait(writer, partition, partition.getPrefix(), "count", partition.getName() + ".count");
                }
            }
        }
    }
}
Also used : AbstractPartitionData(dr.app.beauti.options.AbstractPartitionData) PartitionSubstitutionModel(dr.app.beauti.options.PartitionSubstitutionModel)

Aggregations

AbstractPartitionData (dr.app.beauti.options.AbstractPartitionData)11 Attribute (dr.util.Attribute)6 SequenceErrorType (dr.app.beauti.types.SequenceErrorType)4 PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)2 Taxon (dr.evolution.util.Taxon)2 HashSet (java.util.HashSet)2 PartitionSubstitutionModel (dr.app.beauti.options.PartitionSubstitutionModel)1 EmptyBorder (javax.swing.border.EmptyBorder)1