Search in sources :

Example 41 with BEASTInterface

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

the class BEASTObjectPanel method getOutputs.

/* calculate outputs for each beastObject
      * and put them as ArrayLists in a Map
      * so they can be retrieved indexed by beastObject like this:
      * ArrayList<BEASTObject> output = outputs.get(beastObject)*/
static HashMap<BEASTInterface, List<BEASTInterface>> getOutputs(Collection<BEASTInterface> beastObjects) {
    HashMap<BEASTInterface, List<BEASTInterface>> outputs = new HashMap<>();
    for (BEASTInterface beastObject : beastObjects) {
        outputs.put(beastObject, new ArrayList<>());
    }
    for (BEASTInterface beastObject : beastObjects) {
        try {
            for (Input<?> input2 : beastObject.listInputs()) {
                Object o = input2.get();
                if (o != null && o instanceof BEASTInterface) {
                    List<BEASTInterface> list = outputs.get(o);
                    // if (list == null) {
                    // int h = 3;
                    // h++;
                    // } else {
                    list.add(beastObject);
                // }
                }
                if (o != null && o instanceof List<?>) {
                    for (Object o2 : (List<?>) o) {
                        if (o2 != null && o2 instanceof BEASTInterface) {
                            List<BEASTInterface> list = outputs.get(o2);
                            if (list != null) {
                                list.add(beastObject);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return outputs;
}
Also used : HashMap(java.util.HashMap) BEASTInterface(beast.core.BEASTInterface) ArrayList(java.util.ArrayList) List(java.util.List)

Example 42 with BEASTInterface

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

the class BEASTObjectPanel method main.

/**
 * rudimentary test *
 */
public static void main(String[] args) {
    init();
    BEASTObjectPanel pluginPanel = null;
    try {
        if (args.length == 0) {
            pluginPanel = new BEASTObjectPanel(new MCMC(), Runnable.class, null);
        } else if (args[0].equals("-x")) {
            StringBuilder text = new StringBuilder();
            String NL = System.getProperty("line.separator");
            Scanner scanner = new Scanner(new File(args[1]));
            try {
                while (scanner.hasNextLine()) {
                    text.append(scanner.nextLine() + NL);
                }
            } finally {
                scanner.close();
            }
            BEASTInterface beastObject = new beast.util.XMLParser().parseBareFragment(text.toString(), false);
            pluginPanel = new BEASTObjectPanel(beastObject, beastObject.getClass(), null);
        } else if (args.length == 1) {
            pluginPanel = new BEASTObjectPanel((BEASTInterface) Class.forName(args[0]).newInstance(), Class.forName(args[0]), null);
        } else if (args.length == 2) {
            pluginPanel = new BEASTObjectPanel((BEASTInterface) Class.forName(args[0]).newInstance(), Class.forName(args[1]), null);
        } else {
            throw new IllegalArgumentException("Incorrect number of arguments");
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Usage: " + BEASTObjectPanel.class.getName() + " [-x file ] [class [type]]\n" + "where [class] (optional, default MCMC) is a BEASTObject to edit\n" + "and [type] (optional only if class is specified, default Runnable) the type of the BEASTObject.\n" + "for example\n" + "");
        System.exit(1);
    }
    pluginPanel.setVisible(true);
    if (pluginPanel.m_bOK) {
        BEASTInterface beastObject = pluginPanel.m_beastObject;
        String xml = new XMLProducer().modelToXML(beastObject);
        System.out.println(xml);
    }
}
Also used : Scanner(java.util.Scanner) XMLProducer(beast.util.XMLProducer) MCMC(beast.core.MCMC) BEASTInterface(beast.core.BEASTInterface) File(java.io.File)

Example 43 with BEASTInterface

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

the class Document method setPluginID.

void setPluginID(BEASTObjectShape shape) {
    if (shape.m_beastObject.getID() != null && shape.m_beastObject.getID().length() > 0) {
        return;
    }
    BEASTInterface beastObject = shape.m_beastObject;
    String base = beastObject.getClass().getName().replaceAll(".*\\.", "");
    int _id = 0;
    while (containsID(base + _id, m_objects, null)) {
        _id++;
    }
    beastObject.setID(base + _id);
}
Also used : BEASTInterface(beast.core.BEASTInterface)

Example 44 with BEASTInterface

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

the class Document method process.

void process(BEASTObjectShape shape, int depth) throws IllegalArgumentException, IllegalAccessException, InstantiationException, ClassNotFoundException {
    BEASTInterface beastObject = shape.m_beastObject;
    List<Input<?>> inputs = beastObject.listInputs();
    for (Input<?> input_ : inputs) {
        Object o = input_.get();
        if (o != null) {
            if (o instanceof List<?>) {
                for (Object o2 : (List<?>) o) {
                    addInput(shape, o2, depth + 1, input_.getName());
                }
            } else if (o instanceof BEASTInterface) {
                addInput(shape, o, depth + 1, input_.getName());
            // } else {
            // it is a primitive type
            }
        }
    }
}
Also used : Input(beast.core.Input) BEASTInterface(beast.core.BEASTInterface) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with BEASTInterface

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

the class Document method init.

public void init(BEASTInterface plugin0) {
    try {
        if (plugin0 instanceof BEASTObjectSet) {
            List<BEASTInterface> set = ((BEASTObjectSet) plugin0).m_plugins.get();
            if (set == null) {
                return;
            }
            for (BEASTInterface beastObject : set) {
                BEASTObjectShape shape = new BEASTObjectShape(beastObject, this);
                shape.m_beastObject = beastObject;
                setPluginID(shape);
                m_objects.add(shape);
                process(shape, 1);
                shape.m_x = DX;
                shape.m_w = 100;
                Random random = new Random();
                shape.m_y = random.nextInt(800);
                shape.m_h = 50;
            }
        } else {
            BEASTObjectShape shape = new BEASTObjectShape(plugin0, this);
            shape.m_beastObject = plugin0;
            setPluginID(shape);
            m_objects.add(shape);
            process(shape, 1);
            shape.m_x = DX;
            shape.m_w = 100;
            Random random = new Random();
            shape.m_y = random.nextInt(800);
            shape.m_h = 50;
        }
    } catch (Exception e) {
        e.printStackTrace();
    // TODO: handle exception
    }
    // clear undo stack after all items have been
    // added since the stack is affected by parsing...
    clearUndoStack();
    recalcArrows();
    layout();
    adjustArrows();
}
Also used : Random(java.util.Random) BEASTInterface(beast.core.BEASTInterface)

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