本文整理汇总了Java中dr.xml.XMLParser类的典型用法代码示例。如果您正苦于以下问题:Java XMLParser类的具体用法?Java XMLParser怎么用?Java XMLParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMLParser类属于dr.xml包,在下文中一共展示了XMLParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeGeneralDataType
import dr.xml.XMLParser; //导入依赖的package包/类
private void writeGeneralDataType(PartitionSubstitutionModel model, XMLWriter writer) {
writer.writeComment("general data type for discrete trait model, '" + model.getName() + "'");
Set<String> states = options.getStatesForDiscreteModel(model);
String prefix = model.getName() + ".";
// <generalDataType>
writer.writeOpenTag(GeneralDataTypeParser.GENERAL_DATA_TYPE, new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, prefix + "dataType")});
int numOfStates = states.size();
writer.writeComment("Number Of States = " + numOfStates);
for (String eachGD : states) {
writer.writeTag(GeneralDataTypeParser.STATE, new Attribute[]{
new Attribute.Default<String>(GeneralDataTypeParser.CODE, eachGD)}, true);
}
writer.writeCloseTag(GeneralDataTypeParser.GENERAL_DATA_TYPE);
}
示例2: writeTaxa
import dr.xml.XMLParser; //导入依赖的package包/类
/**
* Generate a taxa block from these beast options
*
* @param writer the writer
* @param taxonList the taxon list to write
* @throws dr.app.util.Arguments.ArgumentException
* ArgumentException
*/
private void writeTaxa(TaxonList taxonList, XMLWriter writer) throws Arguments.ArgumentException {
// -1 (single taxa), 0 (1st gene of multi-taxa)
writer.writeComment("The list of taxa to be analysed (can also include dates/ages).",
"ntax=" + taxonList.getTaxonCount());
writer.writeOpenTag(TaxaParser.TAXA, new Attribute[]{new Attribute.Default<String>(XMLParser.ID, TaxaParser.TAXA)});
boolean hasAttr = options.traits.size() > 0;
boolean firstDate = true;
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Taxon taxon = taxonList.getTaxon(i);
boolean hasDate = false;
if (options.clockModelOptions.isTipCalibrated()) {
hasDate = TaxonList.Utils.hasAttribute(taxonList, i, dr.evolution.util.Date.DATE);
}
if (hasDate) {
dr.evolution.util.Date date = (dr.evolution.util.Date) taxon.getAttribute(dr.evolution.util.Date.DATE);
if (firstDate) {
options.units = date.getUnits();
firstDate = false;
} else {
if (options.units != date.getUnits()) {
System.err.println("Error: Units in dates do not match.");
}
}
}
writeTaxon(taxon, hasDate, hasAttr, writer);
}
writer.writeCloseTag(TaxaParser.TAXA);
}
示例3: writeDifferentTaxa
import dr.xml.XMLParser; //导入依赖的package包/类
public void writeDifferentTaxa(AbstractPartitionData dataPartition, XMLWriter writer) {
TaxonList taxonList = dataPartition.getTaxonList();
String name = dataPartition.getPartitionTreeModel().getName();
writer.writeComment("gene name = " + name + ", ntax= " + taxonList.getTaxonCount());
writer.writeOpenTag(TaxaParser.TAXA, new Attribute[]{new Attribute.Default<String>(XMLParser.ID, name + "." + TaxaParser.TAXA)});
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
if ( !(dataPartition instanceof PartitionPattern && ((PartitionPattern) dataPartition).getPatterns().isMasked(i) ) ) {
final Taxon taxon = taxonList.getTaxon(i);
writer.writeIDref(TaxonParser.TAXON, taxon.getId());
}
}
writer.writeCloseTag(TaxaParser.TAXA);
}
示例4: writeMultiSpecies
import dr.xml.XMLParser; //导入依赖的package包/类
/**
* write tag <sp>
*
* @param taxonList TaxonList
* @param writer XMLWriter
*/
private void writeMultiSpecies(TaxonList taxonList, XMLWriter writer) {
List<String> species = options.starBEASTOptions.getSpeciesList();
String sp;
numOfSpecies = species.size(); // used in private String getIndicatorsParaValue()
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);
}
示例5: writeParameter
import dr.xml.XMLParser; //导入依赖的package包/类
/**
* write a parameter
*
* @param parameterId the parameter name/id
* @param parameterColumn the parameter column from which the samples are taken
* @param fileName the file from which the samples are taken
* @param burnin the number of samples to be discarded
* @param writer the writer
*/
public void writeParameter(String parameterId, String parameterColumn, String fileName, int burnin, XMLWriter writer) {
ArrayList<Attribute.Default> attributes = new ArrayList<Attribute.Default>();
attributes.add(new Attribute.Default<String>(XMLParser.ID, parameterId));
attributes.add(new Attribute.Default<String>("parameterColumn", parameterColumn));
attributes.add(new Attribute.Default<String>("fileName", fileName));
attributes.add(new Attribute.Default<String>("burnin", "" + burnin));
Attribute[] attrArray = new Attribute[attributes.size()];
for (int i = 0; i < attrArray.length; i++) {
attrArray[i] = attributes.get(i);
}
writer.writeTag(ParameterParser.PARAMETER, attrArray, true);
}
示例6: writeTaxaRef
import dr.xml.XMLParser; //导入依赖的package包/类
private void writeTaxaRef(String taxaId, PartitionTreeModel model, XMLWriter writer) {
Attribute[] taxaAttribute = {new Attribute.Default<String>(XMLParser.IDREF, taxaId)};
if (options.taxonSets != null && options.taxonSets.size() > 0 && !options.useStarBEAST) { // need !options.useStarBEAST,
// *BEAST case is in STARBEASTGenerator.writeStartingTreeForCalibration(XMLWriter writer)
writer.writeOpenTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
writer.writeTag(TaxaParser.TAXA, taxaAttribute, true);
for (Taxa taxa : options.taxonSets) {
if (options.taxonSetsTreeModel.get(taxa).equals(model)) {
Parameter statistic = options.getStatistic(taxa);
Attribute mono = new Attribute.Default<Boolean>(
OldCoalescentSimulatorParser.IS_MONOPHYLETIC, options.taxonSetsMono.get(taxa));
writer.writeOpenTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT, mono);
writer.writeIDref(TaxaParser.TAXA, taxa.getId());
if (model.getPartitionTreePrior().getNodeHeightPrior() == TreePriorType.YULE_CALIBRATION
&& statistic.priorType == PriorType.UNIFORM_PRIOR) {
writeDistribution(statistic, false, writer);
}
writer.writeCloseTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT);
}
}
writer.writeCloseTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
} else {
writer.writeTag(TaxaParser.TAXA, taxaAttribute, true);
}
}
示例7: getModelAttributes
import dr.xml.XMLParser; //导入依赖的package包/类
private Attribute[] getModelAttributes(HierarchicalPhylogeneticModel hpm) {
switch (hpm.getPriorType()){
case NORMAL_HPM_PRIOR:
return new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, getModelName(hpm)),
};
case LOGNORMAL_HPM_PRIOR:
return new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, getModelName(hpm)),
//new Attribute.Default<Boolean>(LogNormalDistributionModelParser.MEAN_IN_REAL_SPACE, false),
};
default:
}
throw new RuntimeException("Unimplemented HPM prior type");
}
示例8: getMeanPriorAttributes
import dr.xml.XMLParser; //导入依赖的package包/类
private Attribute[] getMeanPriorAttributes(HierarchicalPhylogeneticModel hpm) {
return new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, getMeanPriorName(hpm)),
new Attribute.Default<Double>(PriorParsers.MEAN, hpm.getConditionalParameterList().get(0).mean),
new Attribute.Default<Double>(PriorParsers.STDEV, hpm.getConditionalParameterList().get(0).stdev),
};
}
示例9: getPrecisionPriorAttributes
import dr.xml.XMLParser; //导入依赖的package包/类
private Attribute[] getPrecisionPriorAttributes(HierarchicalPhylogeneticModel hpm) {
return new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, getPrecisionPriorName(hpm)),
new Attribute.Default<Double>(PriorParsers.SHAPE, hpm.getConditionalParameterList().get(1).shape),
new Attribute.Default<Double>(PriorParsers.SCALE, hpm.getConditionalParameterList().get(1).scale),
new Attribute.Default<Double>(PriorParsers.OFFSET, 0.0),
};
}
示例10: readSequence
import dr.xml.XMLParser; //导入依赖的package包/类
private Sequence readSequence(Element e, TaxonList taxa) throws Importer.ImportException {
String taxonID = e.getChild(TaxonParser.TAXON).getAttributeValue(XMLParser.IDREF);
int index = taxa.getTaxonIndex(taxonID);
if (index < 0) {
throw new Importer.ImportException("Unknown taxon, " + taxonID + ", in alignment");
}
Taxon taxon = taxa.getTaxon(index);
String[] seq = e.getTextTrim().split("\\s");
StringBuilder sb = new StringBuilder();
for (String part : seq) {
sb.append(part);
}
return new Sequence(taxon, sb.toString());
}
示例11: writeNewick
import dr.xml.XMLParser; //导入依赖的package包/类
private void writeNewick(TreeModel tree, XMLWriter writer,
String suffix) {
writer.writeOpenTag(NewickParser.NEWICK,
new Attribute[] { new Attribute.Default<String>(XMLParser.ID,
Utils.TOPOLOGY + suffix), //
new Attribute.Default<String>(NewickParser.USING_DATES,
"false"), //
new Attribute.Default<String>(NewickParser.USING_HEIGHTS,
"true") //
});
writer.writeText(TreeUtils.newick(tree));
writer.writeCloseTag(NewickParser.NEWICK);
}
示例12: writeTaxa
import dr.xml.XMLParser; //导入依赖的package包/类
private void writeTaxa(Taxa taxa, XMLWriter writer, String suffix) {
writer.writeOpenTag(TaxaParser.TAXA, // tagname
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(
TaxonParser.TAXON, // tagname
new Attribute[] { // attributes[]
new Attribute.Default<String>(XMLParser.ID, taxon.getId()) },
true // close
);
}// END: i loop
writer.writeCloseTag(TaxaParser.TAXA);
}
示例13: writeTreeModel
import dr.xml.XMLParser; //导入依赖的package包/类
private void writeTreeModel(
// TreeModel tree,
XMLWriter writer, String suffix) {
final String treeModelName = TreeModel.TREE_MODEL + suffix;
writer.writeTag(TreeModel.TREE_MODEL, new Attribute.Default<String>(
XMLParser.ID, treeModelName), false);
writer.writeIDref("tree", Utils.TOPOLOGY + suffix);
writeParameter(TreeModelParser.ROOT_HEIGHT, treeModelName + "."
+ TreeModelParser.ROOT_HEIGHT, 1, null, writer);
writer.writeOpenTag(TreeModelParser.NODE_HEIGHTS,
new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES,
"true"));
writeParameter(null, treeModelName + "." + "internalNodeHeights", 1,
null, writer);
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") });
writeParameter(null, treeModelName + "." + "allInternalNodeHeights", 1,
null, writer);
writer.writeCloseTag(TreeModelParser.NODE_HEIGHTS);
writer.writeCloseTag(TreeModel.TREE_MODEL);
}
示例14: writeParameter
import dr.xml.XMLParser; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private void writeParameter(String wrapper, String id, int dimension,
String value, XMLWriter writer) {
if (wrapper != null) {
writer.writeOpenTag(wrapper);
}
ArrayList<Attribute.Default> attributes = new ArrayList<Attribute.Default>();
if (id != null) {
attributes.add(new Attribute.Default<String>(XMLParser.ID, id));
}
if (dimension > 1) {
attributes.add(new Attribute.Default<String>(
ParameterParser.DIMENSION, String.valueOf(dimension)));
}
if (value != null) {
attributes.add(new Attribute.Default<String>(ParameterParser.VALUE,
value));
}
Attribute[] attrArray = new Attribute[attributes.size()];
for (int i = 0; i < attrArray.length; i++) {
attrArray[i] = attributes.get(i);
}
writer.writeTag(ParameterParser.PARAMETER, attrArray, true);
if (wrapper != null) {
writer.writeCloseTag(wrapper);
}
}
示例15: writeJCModel
import dr.xml.XMLParser; //导入依赖的package包/类
/**
* Write the JC model XML block.
*
* @param num the model number
* @param writer the writer
* @param model the partition model to write in BEAST XML
*/
public void writeJCModel(int num, XMLWriter writer, PartitionSubstitutionModel model) {
String prefix = model.getPrefix(num);
writer.writeComment("The JC substitution model (Jukes & Cantor, 1969)");
writer.writeOpenTag(NucModelType.HKY.getXMLName(),
new Attribute[]{new Attribute.Default<String>(XMLParser.ID, prefix + "jc")}
);
writer.writeOpenTag(HKYParser.FREQUENCIES);
writeFrequencyModelDNA(writer, model, num);
writer.writeCloseTag(HKYParser.FREQUENCIES);
writer.writeOpenTag(HKYParser.KAPPA);
writeParameter("", 1, 1.0, Double.NaN, Double.NaN, writer);
writer.writeCloseTag(HKYParser.KAPPA);
writer.writeCloseTag(NucModelType.HKY.getXMLName());
}