Search in sources :

Example 31 with Attribute

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);
}
Also used : Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon)

Example 32 with Attribute

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);
}
Also used : Attribute(dr.util.Attribute) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel) PloidyType(dr.evolution.datatype.PloidyType)

Example 33 with Attribute

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);
}
Also used : Taxa(dr.evolution.util.Taxa) Attribute(dr.util.Attribute) Parameter(dr.app.beauti.options.Parameter) TreePriorType(dr.app.beauti.types.TreePriorType)

Example 34 with Attribute

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);
}
Also used : Alignment(dr.evolution.alignment.Alignment) Attribute(dr.util.Attribute)

Example 35 with Attribute

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);
}
Also used : Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon)

Aggregations

Attribute (dr.util.Attribute)45 Taxa (dr.evolution.util.Taxa)11 Taxon (dr.evolution.util.Taxon)11 Parameter (dr.app.beauti.options.Parameter)6 AbstractPartitionData (dr.app.beauti.options.AbstractPartitionData)5 PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)5 PartitionSubstitutionModel (dr.app.beauti.options.PartitionSubstitutionModel)4 TreePriorType (dr.app.beauti.types.TreePriorType)4 AncestralStatesComponentOptions (dr.app.beauti.components.ancestralstates.AncestralStatesComponentOptions)3 DataType (dr.evolution.datatype.DataType)3 ArrayList (java.util.ArrayList)3 SequenceErrorType (dr.app.beauti.types.SequenceErrorType)2 Alignment (dr.evolution.alignment.Alignment)2 SitePatterns (dr.evolution.alignment.SitePatterns)2 Date (dr.evolution.util.Date)2 TaxonList (dr.evolution.util.TaxonList)2 HashSet (java.util.HashSet)2 SequenceErrorModelComponentOptions (dr.app.beauti.components.sequenceerror.SequenceErrorModelComponentOptions)1 TreePriorParameterizationType (dr.app.beauti.types.TreePriorParameterizationType)1 XMLWriter (dr.app.beauti.util.XMLWriter)1