Search in sources :

Example 86 with BEASTInterface

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

the class BeautiSubTemplate method createSubNet.

public BEASTInterface createSubNet(PartitionContext partition, BEASTInterface beastObject, Input<?> input, boolean init) {
    removeSubNet(input.get());
    if (xml == null) {
        // this is the NULL_TEMPLATE
        input.setValue(null, beastObject);
        return null;
    }
    BEASTInterface o = createSubNet(partition, doc.pluginmap, init);
    input.setValue(o, beastObject);
    return o;
}
Also used : BEASTInterface(beast.core.BEASTInterface)

Example 87 with BEASTInterface

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

the class BeautiPanelConfig method sync.

@SuppressWarnings("unchecked")
public void sync(int partitionIndex) {
    if (parentInputs.size() > 0 && _input.get() != null) {
        final Input<?> input = parentInputs.get(partitionIndex);
        if (isList) {
            List<Object> list = (List<Object>) _input.get();
            List<Object> targetList = ((List<Object>) input.get());
            // only clear former members
            for (BEASTInterface beastObject : startInputs) {
                targetList.remove(beastObject);
            }
            targetList.addAll(list);
            // sync outputs of items in list
            for (Object o : list) {
                if (o instanceof BEASTInterface) {
                    ((BEASTInterface) o).getOutputs().add(parentBEASTObjects.get(partitionIndex));
                }
            }
        } else {
            try {
                // System.err.println("sync " + parentBEASTObjects.get(partitionIndex) + "[" + input.getName() + "] = " + _input.get());
                input.setValue(_input.get(), parentBEASTObjects.get(partitionIndex));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : BEASTObject(beast.core.BEASTObject) List(java.util.List) ArrayList(java.util.ArrayList) BEASTInterface(beast.core.BEASTInterface)

Example 88 with BEASTInterface

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

the class BeautiPanelConfig method resolveInput.

/**
 * Find the input associated with this panel
 * based on the path Input.
 */
@SuppressWarnings("unchecked")
public final Input<?> resolveInput(BeautiDoc doc, int partitionIndex) {
    try {
        // if (parentBEASTObjects != null && parentBEASTObjects.size() > 0 && _input != null)
        // System.err.println("sync " + parentBEASTObjects.get(partitionIndex) + "[?] = " + _input.get());
        List<BEASTInterface> beastObjects;
        if (hasPartitionsInput.get() == Partition.none) {
            beastObjects = new ArrayList<>();
            beastObjects.add(doc.mcmc.get());
        } else {
            beastObjects = doc.getPartitions(hasPartitionsInput.get().toString());
        }
        parentBEASTObjects = new ArrayList<>();
        parentInputs = new ArrayList<>();
        parentBEASTObjects.add(doc);
        parentInputs.add(doc.mcmc);
        type = doc.mcmc.getType();
        isList = false;
        for (int i = 0; i < pathComponents.length; i++) {
            List<BEASTInterface> oldPlugins = beastObjects;
            beastObjects = new ArrayList<>();
            parentBEASTObjects = new ArrayList<>();
            parentInputs = new ArrayList<>();
            for (BEASTInterface beastObject : oldPlugins) {
                final Input<?> namedInput = beastObject.getInput(pathComponents[i]);
                type = namedInput.getType();
                if (namedInput.get() instanceof List<?>) {
                    isList = true;
                    List<?> list = (List<?>) namedInput.get();
                    if (conditionalAttribute[i] == null) {
                        for (Object o : list) {
                            BEASTInterface beastObject2 = (BEASTInterface) o;
                            beastObjects.add(beastObject2);
                            parentBEASTObjects.add(beastObject);
                            parentInputs.add(namedInput);
                        }
                    // throw new Exception ("Don't know which element to pick from the list. List component should come with a condition. " + m_sPathComponents[i]);
                    } else {
                        int matches = 0;
                        for (int j = 0; j < list.size(); j++) {
                            BEASTInterface beastObject2 = (BEASTInterface) list.get(j);
                            if (matches(beastObject2, conditionalAttribute[i], conditionalValue[i])) {
                                beastObjects.add(beastObject2);
                                parentBEASTObjects.add(beastObject);
                                parentInputs.add(namedInput);
                                matches++;
                                break;
                            }
                        }
                        if (matches == 0) {
                            parentInputs.add(namedInput);
                            parentBEASTObjects.add(beastObject);
                        }
                    }
                } else if (namedInput.get() instanceof BEASTInterface) {
                    isList = false;
                    if (conditionalAttribute[i] == null) {
                        beastObjects.add((BEASTInterface) namedInput.get());
                        parentBEASTObjects.add(beastObject);
                        parentInputs.add(namedInput);
                    } else {
                        if (matches(beastObject, conditionalAttribute[i], conditionalValue[i])) {
                            // if ((m_sConditionalAttribute[i].equals("id") && beastObject.getID().equals(m_sConditionalValue[i])) ||
                            // (m_sConditionalAttribute[i].equals("type") && beastObject.getClass().getName().equals(m_sConditionalValue[i]))) {
                            beastObjects.add(beastObject);
                            parentBEASTObjects.add(beastObject);
                            parentInputs.add(namedInput);
                        }
                    }
                } else {
                    throw new IllegalArgumentException("input " + pathComponents[i] + "  is not a beastObject or list");
                }
            }
        }
        if (typeInput.get() != null) {
            type = Class.forName(typeInput.get());
        }
        // sanity check
        if (!isList && (hasPartitionsInput.get() == Partition.none) && beastObjects.size() > 1) {
            Log.warning.println("WARNING: multiple beastObjects match, but hasPartitions=none");
            // this makes sure that all mathing beastObjects are available in one go
            isList = true;
            // this suppresses syncing
            parentInputs.clear();
        }
        inputs.clear();
        startInputs.clear();
        for (BEASTInterface beastObject : beastObjects) {
            inputs.add(beastObject);
            startInputs.add(beastObject);
        }
        if (!isList) {
            _input = new FlexibleInput<>();
        } else {
            _input = new FlexibleInput<>(new ArrayList<>());
        }
        _input.setRule(Validate.REQUIRED);
        syncTo(partitionIndex);
        if (isList) {
            checkForDups((List<Object>) _input.get());
        }
        return _input;
    } catch (Exception e) {
        Log.err.println("Warning: could not find objects in path " + Arrays.toString(pathComponents));
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) BEASTInterface(beast.core.BEASTInterface) List(java.util.List) ArrayList(java.util.ArrayList) BEASTObject(beast.core.BEASTObject)

Example 89 with BEASTInterface

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

the class BeautiPanelConfig method syncTo.

/**
 * initialise m_input, and either m_beastObject or m_pluginList *
 */
public void syncTo(int partitionIndex) {
    _input.setType(type);
    try {
        if (isList) {
            for (BEASTInterface beastObject : inputs) {
                _input.setValue(beastObject, this);
            }
        } else {
            if (inputs.size() > 0) {
                BEASTInterface beastObject = inputs.get(partitionIndex);
                _input.setValue(beastObject, this);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : BEASTInterface(beast.core.BEASTInterface)

Example 90 with BEASTInterface

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

the class BEASTObjectPanel method listAscendants.

/**
 * collect all beastObjects that can reach this input (actually, it's parent)
 * and add them to the tabu list.
 */
static List<BEASTInterface> listAscendants(BEASTInterface parent, Collection<BEASTInterface> beastObjects) {
    /* First, calculate outputs for each beastObject */
    HashMap<BEASTInterface, List<BEASTInterface>> outputs = getOutputs(beastObjects);
    /* process outputs */
    List<BEASTInterface> ascendants = new ArrayList<>();
    ascendants.add(parent);
    boolean progress = true;
    while (progress) {
        progress = false;
        for (int i = 0; i < ascendants.size(); i++) {
            BEASTInterface ascendant = ascendants.get(i);
            if (outputs.containsKey(ascendant)) {
                for (BEASTInterface parent2 : outputs.get(ascendant)) {
                    if (!ascendants.contains(parent2)) {
                        ascendants.add(parent2);
                        progress = true;
                    }
                }
            }
        }
    }
    return ascendants;
}
Also used : ArrayList(java.util.ArrayList) BEASTInterface(beast.core.BEASTInterface) ArrayList(java.util.ArrayList) List(java.util.List) Point(java.awt.Point)

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