Search in sources :

Example 6 with PartitionSubstitutionModel

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

the class NexusApplicationImporter method parsePAUPBlock.

/**
     * Parses a 'PAUP' block.
     *
     * @param options  the BEAUti options
     * @param charSets a list of char sets to *add* to if any are defined in PAUP block
     * @return a partition model representing the model defined in the PAUP block
     * @throws dr.evolution.io.Importer.ImportException
     *                             if PAUP block is poorly formed
     * @throws java.io.IOException if I/O fails
     */
public PartitionSubstitutionModel parsePAUPBlock(BeautiOptions options, List<CharSet> charSets) throws ImportException, IOException {
    PartitionSubstitutionModel model = new PartitionSubstitutionModel(options, "nucs");
    readTopLevelBlock(options, model, charSets);
    return model;
}
Also used : PartitionSubstitutionModel(dr.app.beauti.options.PartitionSubstitutionModel)

Example 7 with PartitionSubstitutionModel

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

the class PatternListGenerator method writePatternList.

/**
     * Writes the pattern lists
     *
     * @param partition the partition data to write the pattern lists for
     * @param writer    the writer
     */
public void writePatternList(PartitionData partition, XMLWriter writer) {
    writer.writeText("");
    AncestralStatesComponentOptions ancestralStatesOptions = (AncestralStatesComponentOptions) options.getComponentOptions(AncestralStatesComponentOptions.class);
    SequenceErrorModelComponentOptions sequenceErrorOptions = (SequenceErrorModelComponentOptions) options.getComponentOptions(SequenceErrorModelComponentOptions.class);
    PartitionSubstitutionModel model = partition.getPartitionSubstitutionModel();
    String codonHeteroPattern = model.getCodonHeteroPattern();
    int partitionCount = model.getCodonPartitionCount();
    boolean isAncestralStatesModel = (!ancestralStatesOptions.usingAncestralStates(partition) && !sequenceErrorOptions.usingSequenceErrorModel(partition));
    boolean isCovarionModel = model.getDataType().getType() == DataType.COVARION && model.getBinarySubstitutionModel() == BinaryModelType.BIN_COVARION;
    boolean unique = isAncestralStatesModel || isCovarionModel;
    boolean strip = isAncestralStatesModel || isCovarionModel;
    if (model.getDataType().getType() == DataType.NUCLEOTIDES && codonHeteroPattern != null && partitionCount > 1) {
        if (codonHeteroPattern.equals("112")) {
            writer.writeComment("The " + (unique ? "unique " : "") + "patterns for codon positions 1 & 2");
            writer.writeOpenTag(MergePatternsParser.MERGE_PATTERNS, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, partition.getPrefix() + model.getPrefixCodon(1) + SitePatternsParser.PATTERNS) });
            writePatternList(partition, 0, 3, null, unique, strip, writer);
            writePatternList(partition, 1, 3, null, unique, strip, writer);
            writer.writeCloseTag(MergePatternsParser.MERGE_PATTERNS);
            writer.writeComment("The " + (unique ? "unique " : "") + "patterns for codon position 3");
            writePatternList(partition, 2, 3, model.getPrefixCodon(2), unique, strip, writer);
        } else {
            // pattern is 123
            for (int i = 1; i <= 3; i++) {
                writer.writeComment("The " + (unique ? "unique " : "") + "patterns for codon position " + i);
                writePatternList(partition, i - 1, 3, model.getPrefixCodon(i), unique, strip, writer);
            }
        }
    // END: pattern is 123
    } else {
        writePatternList(partition, 0, 1, "", unique, strip, writer);
    }
}
Also used : Attribute(dr.util.Attribute) AncestralStatesComponentOptions(dr.app.beauti.components.ancestralstates.AncestralStatesComponentOptions) PartitionSubstitutionModel(dr.app.beauti.options.PartitionSubstitutionModel) SequenceErrorModelComponentOptions(dr.app.beauti.components.sequenceerror.SequenceErrorModelComponentOptions)

Example 8 with PartitionSubstitutionModel

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

the class AncestralStatesComponentGenerator method writeCountingParameter.

// END: generate
private void writeCountingParameter(XMLWriter writer, AbstractPartitionData partition, String prefix) {
    AncestralStatesComponentOptions component = (AncestralStatesComponentOptions) options.getComponentOptions(AncestralStatesComponentOptions.class);
    if (!component.isCountingStates(partition)) {
        return;
    }
    StringBuilder matrix = new StringBuilder();
    DataType dataType = partition.getDataType();
    int stateCount = dataType.getStateCount();
    if (dataType.getType() == DataType.GENERAL) {
        PartitionSubstitutionModel substModel = partition.getPartitionSubstitutionModel();
        stateCount = substModel.getDiscreteStateSet().size();
    }
    for (int i = 0; i < stateCount; i++) {
        for (int j = 0; j < stateCount; j++) {
            if (i == j) {
                matrix.append(" 0.0");
            } else {
                matrix.append(" 1.0");
            }
        }
    }
    writer.writeTag("parameter", new Attribute[] { new Attribute.Default<String>("id", partition.getPrefix() + "count"), new Attribute.Default<String>("value", matrix.toString()) }, true);
}
Also used : Attribute(dr.util.Attribute) DataType(dr.evolution.datatype.DataType) PartitionSubstitutionModel(dr.app.beauti.options.PartitionSubstitutionModel)

Example 9 with PartitionSubstitutionModel

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

the class AncestralStatesComponentGenerator method writeStateLogger.

private void writeStateLogger(XMLWriter writer, AbstractPartitionData partition, String mrcaId) {
    writer.writeComment("Ancestral state reconstruction for: " + partition.getName());
    writer.writeOpenTag("log", new Attribute[] { new Attribute.Default<String>("id", "fileLog_" + partition.getName()), new Attribute.Default<String>("logEvery", Integer.toString(options.logEvery)), new Attribute.Default<String>("fileName", options.fileNameStem + "." + partition.getName() + STATE_LOG_SUFFIX) });
    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);
            }
            writeAncestralTrait(writer, partition, mrcaId, prefix, name);
        }
    } else {
        writeAncestralTrait(writer, partition, mrcaId, partition.getPrefix(), partition.getName());
    }
    writer.writeCloseTag("log");
}
Also used : Attribute(dr.util.Attribute) PartitionSubstitutionModel(dr.app.beauti.options.PartitionSubstitutionModel)

Example 10 with PartitionSubstitutionModel

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

PartitionSubstitutionModel (dr.app.beauti.options.PartitionSubstitutionModel)17 Attribute (dr.util.Attribute)4 DataType (dr.evolution.datatype.DataType)3 AncestralStatesComponentOptions (dr.app.beauti.components.ancestralstates.AncestralStatesComponentOptions)1 SequenceErrorModelComponentOptions (dr.app.beauti.components.sequenceerror.SequenceErrorModelComponentOptions)1 AbstractPartitionData (dr.app.beauti.options.AbstractPartitionData)1 PartitionData (dr.app.beauti.options.PartitionData)1 NexusApplicationImporter (dr.app.beauti.util.NexusApplicationImporter)1 Alignment (dr.evolution.alignment.Alignment)1 CharSetAlignment (dr.evolution.alignment.CharSetAlignment)1 ConvertAlignment (dr.evolution.alignment.ConvertAlignment)1 Patterns (dr.evolution.alignment.Patterns)1 SitePatterns (dr.evolution.alignment.SitePatterns)1 Microsatellite (dr.evolution.datatype.Microsatellite)1 Importer (dr.evolution.io.Importer)1 NexusImporter (dr.evolution.io.NexusImporter)1 Tree (dr.evolution.tree.Tree)1 dr.evolution.util (dr.evolution.util)1 ArrayList (java.util.ArrayList)1 EmptyBorder (javax.swing.border.EmptyBorder)1