Debian Codegraph @

src/dr/evomodelxml/tree/HiddenLinkageLoggerParser.java

raw symbols SCIP
1 /*
2 * HiddenLinkageLoggerParser.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evomodelxml.tree;
27
28 import java.io.PrintWriter;
29
30 import dr.evomodel.tree.HiddenLinkageLogger;
31 import dr.evomodel.tree.HiddenLinkageModel;
32 import dr.inference.loggers.LogFormatter;
33 import dr.inference.loggers.TabDelimitedFormatter;
34 import dr.inferencexml.loggers.LoggerParser;
35 import dr.xml.AttributeRule;
36 import dr.xml.ElementRule;
37 import dr.xml.StringAttributeRule;
38 import dr.xml.XMLObject;
39 import dr.xml.XMLParseException;
40 import dr.xml.XMLSyntaxRule;
41
42 /**
43 * @author Aaron Darling
44 */
45 public class HiddenLinkageLoggerParser extends LoggerParser {
46 public static final String LOG_HIDDEN_LINKAGE = "logHiddenLinkage";
47
48 public String getParserName() {
49 return LOG_HIDDEN_LINKAGE;
50 }
51
52 /**
53 * @return an object based on the XML element it was passed.
54 */
55 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
56 HiddenLinkageModel hlm = (HiddenLinkageModel)xo.getChild(HiddenLinkageModel.class);
57 // logEvery of zero only displays at the end
58 final int logEvery = xo.getAttribute(LOG_EVERY, 0);
59 final PrintWriter pw = getLogFile(xo, getParserName());
60 final LogFormatter formatter = new TabDelimitedFormatter(pw);
61
62 return new HiddenLinkageLogger(hlm, formatter, logEvery);
63 }
64
65 public String getParserDescription() {
66 return "Logs a linkage groups for metagenomic reads to a file";
67 }
68
69 public Class getReturnType() {
70 return HiddenLinkageLogger.class;
71 }
72
73 public XMLSyntaxRule[] getSyntaxRules() {
74 return rules;
75 }
76 private final XMLSyntaxRule[] rules = {
77 AttributeRule.newIntegerRule(LOG_EVERY, true),
78 new StringAttributeRule(FILE_NAME,
79 "The name of the file to send log output to. " +
80 "If no file name is specified then log is sent to standard output", true),
81 new ElementRule(HiddenLinkageModel.class, "The linkage model which is to be logged"),
82 };
83 }