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;
}
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);
}
}
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);
}
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");
}
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");
}
}
}
}
}
Aggregations