Search in sources :

Example 91 with BEASTInterface

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

the class Document method calcPluginSet.

// toXML
/**
 * collect all objects and put all top-level beastObjects in a PluginSet
 */
BEASTObjectSet calcPluginSet() {
    // collect all plug-ins
    Collection<BEASTInterface> beastObjects = getPlugins();
    // calc outputs
    HashMap<BEASTInterface, List<BEASTInterface>> outputs = BEASTObjectPanel.getOutputs(beastObjects);
    // put all beastObjects with no ouputs in the PluginSet
    BEASTObjectSet pluginSet = new BEASTObjectSet();
    for (BEASTInterface beastObject : outputs.keySet()) {
        if (outputs.get(beastObject).size() == 0) {
            try {
                pluginSet.setInputValue("beastObject", beastObject);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return pluginSet;
}
Also used : BEASTInterface(beast.core.BEASTInterface) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 92 with BEASTInterface

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

the class Document method checkForOtherPluginShapes.

// addNewShape
void checkForOtherPluginShapes(List<Integer> objects, BEASTObjectShape shape) {
    // check whether we need to create any input beastObjects
    try {
        List<Input<?>> inputs = shape.m_beastObject.listInputs();
        for (Input<?> input : inputs) {
            if (input.get() instanceof BEASTInterface) {
                BEASTInterface beastObject = (BEASTInterface) input.get();
                BEASTObjectShape beastObjectShape = new BEASTObjectShape(beastObject, this);
                beastObjectShape.m_x = Math.max(shape.m_x - DX, 0);
                beastObjectShape.m_y = shape.m_y;
                beastObjectShape.m_w = 100;
                beastObjectShape.m_h = 80;
                setPluginID(beastObjectShape);
                m_objects.add(beastObjectShape);
                objects.add(m_objects.size() - 1);
                Arrow arrow = new Arrow(beastObjectShape, shape, input.getName());
                m_objects.add(arrow);
                objects.add(m_objects.size() - 1);
                // recurse
                checkForOtherPluginShapes(objects, beastObjectShape);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Input(beast.core.Input) BEASTInterface(beast.core.BEASTInterface)

Example 93 with BEASTInterface

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

the class Document method reinit.

void reinit() {
    String xml = toXML();
    m_objects.clear();
    try {
        XMLParser parser = new XMLParser();
        BEASTInterface plugin0 = parser.parseBareFragment(xml, false);
        init(plugin0);
    } catch (Exception e) {
        e.printStackTrace();
    // TODO: handle exception
    }
}
Also used : BEASTInterface(beast.core.BEASTInterface) XMLParser(beast.util.XMLParser)

Example 94 with BEASTInterface

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

the class Document method isValidModel.

int isValidModel() {
    BEASTObjectSet pluginSet = calcPluginSet();
    if (pluginSet.m_plugins.get().size() == 0) {
        return STATUS_EMPTY_MODEL;
    }
    if (pluginSet.m_plugins.get().size() > 1) {
        return STATUS_ORPHANS_IN_MODEL;
    }
    boolean hasRunable = false;
    for (BEASTInterface beastObject : pluginSet.m_plugins.get()) {
        if (beastObject instanceof Runnable) {
            hasRunable = true;
        }
    }
    if (!hasRunable) {
        return STATUS_NOT_RUNNABLE;
    }
    return STATUS_OK;
}
Also used : Runnable(beast.core.Runnable) BEASTInterface(beast.core.BEASTInterface)

Example 95 with BEASTInterface

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

the class Document method loadFile.

public void loadFile(String fileName) {
    m_objects.clear();
    XMLParser parser = new XMLParser();
    try {
        // fileName;
        StringBuilder xml = new StringBuilder();
        String NL = System.getProperty("line.separator");
        Scanner scanner = new Scanner(new File(fileName));
        try {
            while (scanner.hasNextLine()) {
                xml.append(scanner.nextLine() + NL);
            }
        } finally {
            scanner.close();
        }
        BEASTInterface plugin0 = parser.parseBareFragment(xml.toString(), false);
        init(plugin0);
    } catch (Exception e) {
        e.printStackTrace();
    // TODO: handle exception
    }
}
Also used : Scanner(java.util.Scanner) BEASTInterface(beast.core.BEASTInterface) XMLParser(beast.util.XMLParser) File(java.io.File)

Aggregations

BEASTInterface (beast.core.BEASTInterface)111 ArrayList (java.util.ArrayList)43 List (java.util.List)27 IOException (java.io.IOException)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)18 SAXException (org.xml.sax.SAXException)18 NodeList (org.w3c.dom.NodeList)13 Input (beast.core.Input)12 MRCAPrior (beast.math.distributions.MRCAPrior)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 XMLParser (beast.util.XMLParser)11 TransformerException (javax.xml.transform.TransformerException)11 Alignment (beast.evolution.alignment.Alignment)10 XMLParserException (beast.util.XMLParserException)10 BEASTObject (beast.core.BEASTObject)9 Distribution (beast.core.Distribution)9 XMLProducer (beast.util.XMLProducer)9 CompoundDistribution (beast.core.util.CompoundDistribution)8 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)8