Search in sources :

Example 6 with BEASTObject

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

the class BeautiDoc method determineLinks.

// methods for dealing with linking
void determineLinks() {
    if (!allowLinking) {
        return;
    }
    linked.clear();
    for (BEASTInterface beastObject : posteriorPredecessors) {
        Map<String, Integer> outputIDs = new HashMap<>();
        for (Object output : beastObject.getOutputs()) {
            if (posteriorPredecessors.contains(output)) {
                String id = ((BEASTInterface) output).getID();
                if (id.indexOf('.') >= 0) {
                    id = id.substring(0, id.indexOf('.'));
                    if (outputIDs.containsKey(id)) {
                        outputIDs.put(id, outputIDs.get(id) + 1);
                    } else {
                        outputIDs.put(id, 1);
                    }
                }
            }
        }
        for (Object output : beastObject.getOutputs()) {
            if (posteriorPredecessors.contains(output)) {
                String id = ((BEASTInterface) output).getID();
                if (id.indexOf('.') >= 0) {
                    id = id.substring(0, id.indexOf('.'));
                    if (outputIDs.get(id) > 1) {
                        addLink(beastObject, (BEASTInterface) output);
                    }
                }
            }
        }
        // add parameters that have more than 1 outputs into susbtitution models
        if (beastObject instanceof Parameter<?>) {
            for (Object output : beastObject.getOutputs()) {
                if (posteriorPredecessors.contains(output)) {
                    if (output instanceof SubstitutionModel) {
                        int nrOfSubstModelsInOutput = 0;
                        try {
                            for (Input<?> input : ((BEASTInterface) output).listInputs()) {
                                if (input.get() != null && input.get().equals(beastObject)) {
                                    nrOfSubstModelsInOutput++;
                                }
                            }
                        } catch (Exception e) {
                        // ignore
                        }
                        if (nrOfSubstModelsInOutput > 1) {
                            addLink(beastObject, (BEASTInterface) output);
                        }
                    }
                }
            }
        }
    }
    hasLinkedAtLeastOnce = false;
    for (Input<?> input : linked) {
        if (input.getType().isAssignableFrom(RealParameter.class)) {
            hasLinkedAtLeastOnce = true;
            break;
        }
    }
}
Also used : HashMap(java.util.HashMap) RealParameter(beast.core.parameter.RealParameter) Parameter(beast.core.parameter.Parameter) BEASTInterface(beast.core.BEASTInterface) BEASTObject(beast.core.BEASTObject) SubstitutionModel(beast.evolution.substitutionmodel.SubstitutionModel) XMLParserException(beast.util.XMLParserException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 7 with BEASTObject

use of beast.core.BEASTObject 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 8 with BEASTObject

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

the class DocMaker method getType.

// getHTML
/**
 * determine type of input of a plug in with name name
 */
String getType(BEASTObject beastObject, String name) {
    try {
        Field[] fields = beastObject.getClass().getFields();
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].getType().isAssignableFrom(Input.class)) {
                final Input<?> input = (Input<?>) fields[i].get(beastObject);
                if (input.getName().equals(name)) {
                    Type t = fields[i].getGenericType();
                    Type[] genericTypes = ((ParameterizedType) t).getActualTypeArguments();
                    if (input.getType() != null) {
                        return (input.getType().isAssignableFrom(BEASTObject.class) ? "<a href='" + input.getType().getName() + ".html'>" : "") + input.getType().getName() + (input.get() != null && input.get() instanceof List<?> ? "***" : "") + (input.getType().isAssignableFrom(BEASTObject.class) ? "</a>" : "");
                    }
                    if (input.get() != null && input.get() instanceof List<?>) {
                        Type[] genericTypes2 = ((ParameterizedType) genericTypes[0]).getActualTypeArguments();
                        Class<?> _class = (Class<?>) genericTypes2[0];
                        Object o = null;
                        try {
                            o = Class.forName(_class.getName()).newInstance();
                        } catch (Exception e) {
                        }
                        if (o != null && o instanceof BEASTObject) {
                            return "<a href='" + _class.getName() + ".html'>" + _class.getName() + "***</a>";
                        } else {
                            return _class.getName() + "***";
                        }
                    } else {
                        Class<?> genericType = (Class<?>) genericTypes[0];
                        Class<?> _class = genericType;
                        Object o = null;
                        try {
                            o = Class.forName(_class.getName()).newInstance();
                        } catch (Exception e) {
                        }
                        if (o != null && o instanceof BEASTObject) {
                            return "<a href='" + _class.getName() + ".html'>" + _class.getName() + "</a>";
                        } else {
                            return _class.getName();
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "?";
}
Also used : BEASTObject(beast.core.BEASTObject) FileNotFoundException(java.io.FileNotFoundException) ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) Input(beast.core.Input) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) BEASTObject(beast.core.BEASTObject)

Example 9 with BEASTObject

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

the class CompoundValuable method initAndValidate.

@Override
public void initAndValidate() {
    // determine dimension
    int dimension = 0;
    for (BEASTObject beastObject : m_values.get()) {
        if (!(beastObject instanceof Function)) {
            throw new IllegalArgumentException("Input does not implement Valuable");
        }
        dimension += ((Function) beastObject).getDimension();
    }
    m_fValues = new double[dimension];
}
Also used : Function(beast.core.Function) BEASTObject(beast.core.BEASTObject)

Example 10 with BEASTObject

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

the class CompoundValuable method recompute.

/**
 * collect values of the compounds into an array *
 */
private void recompute() {
    int k = 0;
    for (BEASTObject beastObject : m_values.get()) {
        Function valuable = (Function) beastObject;
        if (beastObject instanceof StateNode) {
            valuable = ((StateNode) beastObject).getCurrent();
        }
        int dimension = valuable.getDimension();
        for (int i = 0; i < dimension; i++) {
            m_fValues[k++] = valuable.getArrayValue(i);
        }
    }
    m_bRecompute = false;
}
Also used : Function(beast.core.Function) StateNode(beast.core.StateNode) BEASTObject(beast.core.BEASTObject)

Aggregations

BEASTObject (beast.core.BEASTObject)23 ArrayList (java.util.ArrayList)10 BEASTInterface (beast.core.BEASTInterface)7 Input (beast.core.Input)6 Test (org.junit.Test)5 RealParameter (beast.core.parameter.RealParameter)4 Distribution (beast.core.Distribution)3 Parameter (beast.core.parameter.Parameter)3 CompoundDistribution (beast.core.util.CompoundDistribution)3 XMLParserException (beast.util.XMLParserException)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 SAXException (org.xml.sax.SAXException)3 Function (beast.core.Function)2 Logger (beast.core.Logger)2 StateNode (beast.core.StateNode)2 Alignment (beast.evolution.alignment.Alignment)2