Search in sources :

Example 1 with Logger

use of beast.core.Logger in project beast2 by CompEvol.

the class BeautiSubTemplate method createSubNet.

private BEASTInterface createSubNet(PartitionContext context, /*BeautiDoc doc,*/
HashMap<String, BEASTInterface> idMap, boolean init) {
    subNetDepth++;
    if (subNetDepth > 10) {
        // looks like we cannot find what we are looking for
        throw new IllegalArgumentException("Potential programmer error: It looks like there is a required input that was not specified in the tenmplate");
    }
    // wrap in a beast element with appropriate name spaces
    String _sXML = "<beast version='2.0' \n" + "namespace='beast.app.beauti:beast.core:beast.evolution.branchratemodel:beast.evolution.speciation:beast.evolution.tree.coalescent:beast.core.util:beast.evolution.nuc:beast.evolution.operators:beast.evolution.sitemodel:beast.evolution.substitutionmodel:beast.evolution.likelihood:beast.evolution:beast.math.distributions'>\n" + xml + "</beast>\n";
    // resolve alignment references
    _sXML = _sXML.replaceAll("idref=[\"']data['\"]", "idref='" + context.partition + "'");
    _sXML = _sXML.replaceAll("[\"']@data['\"]", "'@" + context.partition + "'");
    // ensure uniqueness of IDs
    // _sXML.replaceAll("\\$\\(n\\)", partition);
    _sXML = BeautiDoc.translatePartitionNames(_sXML, context);
    XMLParser parser = new XMLParser();
    parser.setRequiredInputProvider(doc, context);
    List<BEASTInterface> beastObjects = null;
    try {
        beastObjects = parser.parseTemplate(_sXML, idMap, true);
        for (BEASTInterface beastObject : beastObjects) {
            doc.addPlugin(beastObject);
            try {
                Log.warning.println("Adding " + beastObject.getClass().getName() + " " + beastObject);
            } catch (Exception e) {
                Log.err.println("Adding " + beastObject.getClass().getName());
            }
        }
        for (BeautiConnector connector : connectors) {
            if (init && connector.atInitialisationOnly()) {
                // ||
                doc.connect(connector, context);
            }
            // System.out.println(connector.sourceID + " == " + connector.targetID);
            if (connector.targetID != null && connector.targetID.equals("prior")) {
                Log.warning.println(">>> No description for connector " + connector.sourceID + " == " + connector.targetID);
            }
            if (connector.getTipText() != null) {
                String ID = BeautiDoc.translatePartitionNames(connector.sourceID, context);
                String tipText = BeautiDoc.translatePartitionNames(connector.getTipText(), context).trim().replaceAll("\\s+", " ");
                // System.out.println(ID + " -> " + tipText);
                doc.tipTextMap.put(ID, tipText);
            }
        }
        if (suppressedInputs.get() != null) {
            String[] inputs = suppressedInputs.get().split(",");
            for (String input : inputs) {
                input = input.trim();
                doc.beautiConfig.suppressBEASTObjects.add(input);
            }
        }
        if (inlineInput.get() != null) {
            String[] inputs = inlineInput.get().split(",");
            for (String input : inputs) {
                input = input.trim();
                doc.beautiConfig.inlineBEASTObject.add(input);
            }
        }
        if (collapsedInput.get() != null) {
            String[] inputs = collapsedInput.get().split(",");
            for (String input : inputs) {
                input = input.trim();
                doc.beautiConfig.collapsedBEASTObjects.add(input);
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (mainID.equals("[top]")) {
        subNetDepth--;
        return beastObjects.get(0);
    }
    String id = mainID;
    // id.replaceAll("\\$\\(n\\)", partition);
    id = BeautiDoc.translatePartitionNames(id, context);
    BEASTInterface beastObject = doc.pluginmap.get(id);
    if (this == doc.beautiConfig.partitionTemplate.get()) {
        // HACK: need to make sure the subst model is of the correct type
        BEASTInterface treeLikelihood = doc.pluginmap.get("treeLikelihood." + context.partition);
        if (treeLikelihood != null && ((GenericTreeLikelihood) treeLikelihood).siteModelInput.get() instanceof SiteModel.Base) {
            SiteModel.Base siteModel = (SiteModel.Base) ((GenericTreeLikelihood) treeLikelihood).siteModelInput.get();
            SubstitutionModel substModel = siteModel.substModelInput.get();
            try {
                if (!siteModel.canSetSubstModel(substModel)) {
                    setUpSubstModel(siteModel, context);
                }
            } catch (Exception e) {
                setUpSubstModel(siteModel, context);
            }
        }
        // HACK2: rename file name for trace log if it has the default value
        Logger logger = (Logger) doc.pluginmap.get("tracelog");
        if (logger != null) {
            String fileName = logger.fileNameInput.get();
            if (fileName.startsWith("beast.") && treeLikelihood != null) {
                Alignment data = ((GenericTreeLikelihood) treeLikelihood).dataInput.get();
                while (data instanceof FilteredAlignment) {
                    data = ((FilteredAlignment) data).alignmentInput.get();
                }
                fileName = data.getID() + fileName.substring(5);
                try {
                    logger.fileNameInput.setValue(fileName, logger);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    subNetDepth--;
    // System.err.println(new XMLProducer().toXML(beastObject));
    return beastObject;
}
Also used : GenericTreeLikelihood(beast.evolution.likelihood.GenericTreeLikelihood) SiteModel(beast.evolution.sitemodel.SiteModel) Logger(beast.core.Logger) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) Base(beast.evolution.sitemodel.SiteModelInterface.Base) SubstitutionModel(beast.evolution.substitutionmodel.SubstitutionModel) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) BEASTInterface(beast.core.BEASTInterface) XMLParser(beast.util.XMLParser)

Example 2 with Logger

use of beast.core.Logger in project beast2 by CompEvol.

the class BeautiBase method traceLogAsString.

String traceLogAsString() {
    Logger logger = (Logger) doc.pluginmap.get("tracelog");
    List<BEASTObject> logs = logger.loggersInput.get();
    return "assertTraceLogEqual" + pluginListAsString(logs);
}
Also used : BEASTObject(beast.core.BEASTObject) Logger(beast.core.Logger)

Example 3 with Logger

use of beast.core.Logger in project beast2 by CompEvol.

the class LoggerTest method isLoggingToStdout.

@Test
public void isLoggingToStdout() throws Exception {
    logger = new Logger();
    logger.initByName("fileName", null, "log", new RealParameter());
    assertTrue("fileName == null", logger.isLoggingToStdout());
    logger = new Logger();
    logger.initByName("fileName", "", "log", new RealParameter());
    assertTrue("fileName.length() == 0", logger.isLoggingToStdout());
    logger = new Logger();
    logger.initByName("fileName", "beast.log", "log", new RealParameter());
    assertFalse("fileName = \"beast.log\"", logger.isLoggingToStdout());
}
Also used : RealParameter(beast.core.parameter.RealParameter) Logger(beast.core.Logger)

Example 4 with Logger

use of beast.core.Logger in project beast2 by CompEvol.

the class BeautiBase method assertTraceLogEqual.

void assertTraceLogEqual(String... ids) {
    System.err.println("assertTraceLogEqual");
    Logger logger = (Logger) doc.pluginmap.get("tracelog");
    List<BEASTObject> logs = logger.loggersInput.get();
    asserListsEqual(logs, ids);
}
Also used : BEASTObject(beast.core.BEASTObject) Logger(beast.core.Logger)

Example 5 with Logger

use of beast.core.Logger in project beast2 by CompEvol.

the class LoggerTest method testScreenLog.

@Test
public void testScreenLog() throws Exception {
    logger = new Logger();
    logger.initByName("fileName", "", "log", new RealParameter(new Double[] { 0.3, 0.7 }));
    logger.init();
    assertTrue("m_out is System.out", logger.getM_out() == System.out);
    logger.log(1);
    // TODO cannot extract content
    // close all file, except stdout
    logger.close();
    assertTrue("m_out is still System.out after close", logger.getM_out() == System.out);
}
Also used : RealParameter(beast.core.parameter.RealParameter) Logger(beast.core.Logger)

Aggregations

Logger (beast.core.Logger)6 RealParameter (beast.core.parameter.RealParameter)3 BEASTObject (beast.core.BEASTObject)2 BEASTInterface (beast.core.BEASTInterface)1 Alignment (beast.evolution.alignment.Alignment)1 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)1 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)1 SiteModel (beast.evolution.sitemodel.SiteModel)1 Base (beast.evolution.sitemodel.SiteModelInterface.Base)1 SubstitutionModel (beast.evolution.substitutionmodel.SubstitutionModel)1 XMLParser (beast.util.XMLParser)1 IOException (java.io.IOException)1 Random (java.util.Random)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 SAXException (org.xml.sax.SAXException)1