Search in sources :

Example 1 with ONDEXPluginArguments

use of net.sourceforge.ondex.ONDEXPluginArguments in project knetbuilder by Rothamsted.

the class OndexPluginUtils method runPlugin.

/**
 * Helper to invoke a plug-in as stand-alone, outside of the workflow.
 *
 * @param args these are translated into {@link ONDEXPluginArguments}. In case of multi-value
 * 				arguments, use list values.
 *
 * @return a result that depends on the plug-in type: if it's instance of {@link ProducerONDEXPlugin}, returns
 *         {@link ProducerONDEXPlugin#collectResults() collectResults()}, if it's {@link RequiresGraph}, returns
 *         {@link RequiresGraph#getGraph() the plugin's graph}, else returns null.
 */
public static <T> T runPlugin(ONDEXPlugin plugin, Map<String, Object> args) throws UncheckedPluginException {
    try {
        // Prepare the arguments from the map
        // 
        var pargDefs = plugin.getArgumentDefinitions();
        var pargs = new ONDEXPluginArguments(pargDefs);
        args.forEach(Exceptions.sneak().fromBiConsumer((argName, valObj) -> {
            @SuppressWarnings("unchecked") Collection<Object> vlist = valObj instanceof Collection ? (Collection<Object>) valObj : List.of(valObj);
            // if the arg is accepting a type other than string, addOption() will try to parse it
            // using ArgugmentDefition.parseString()
            vlist.forEach(Exceptions.sneak().consumer(val -> pargs.addOption(argName, val)));
        }));
        // OK, now set them
        plugin.setArguments(pargs);
        plugin.start();
        if (plugin instanceof ProducerONDEXPlugin)
            ((ProducerONDEXPlugin) plugin).collectResults();
        if (plugin instanceof RequiresGraph)
            ((RequiresGraph) plugin).getGraph();
        return null;
    } catch (Exception ex) {
        throw new UncheckedPluginException("Error during plug-in execution: " + ex.getMessage(), ex);
    }
}
Also used : ONDEXGraph(net.sourceforge.ondex.core.ONDEXGraph) Collection(java.util.Collection) ONDEXPlugin(net.sourceforge.ondex.ONDEXPlugin) UncheckedPluginException(net.sourceforge.ondex.UncheckedPluginException) RequiresGraph(net.sourceforge.ondex.RequiresGraph) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) ProducerONDEXPlugin(net.sourceforge.ondex.producer.ProducerONDEXPlugin) ExceptionUtils(uk.ac.ebi.utils.exceptions.ExceptionUtils) Map(java.util.Map) Exceptions(com.machinezoo.noexception.Exceptions) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) ConstructorUtils(org.apache.commons.lang3.reflect.ConstructorUtils) Collection(java.util.Collection) RequiresGraph(net.sourceforge.ondex.RequiresGraph) ProducerONDEXPlugin(net.sourceforge.ondex.producer.ProducerONDEXPlugin) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) UncheckedPluginException(net.sourceforge.ondex.UncheckedPluginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UncheckedPluginException(net.sourceforge.ondex.UncheckedPluginException)

Example 2 with ONDEXPluginArguments

use of net.sourceforge.ondex.ONDEXPluginArguments in project knetbuilder by Rothamsted.

the class Engine method runTransformer.

/**
 * Runs a Transformer producer on the specified graph
 *
 * @param transformer      the Transformer to run
 * @param args  arguments for the transformer
 * @param graphInput the graph to use as input (and by implication output)
 * @throws Exception
 */
public ONDEXGraph runTransformer(ONDEXTransformer transformer, ONDEXPluginArguments args, ONDEXGraph graphInput) throws Exception {
    if (graphInput == null)
        throw new NullPointerException("Can not run plugin with a null graphInput");
    if (args == null)
        args = new ONDEXPluginArguments(transformer.getArgumentDefinitions());
    LuceneEnv lenv = null;
    if (transformer.requiresIndexedGraph()) {
        lenv = getIndex(graphInput, transformer.getName());
    }
    try {
        String name = transformer.getName();
        transformer.addONDEXListener(pluginLogger);
        transformer.setArguments(args);
        long start = System.currentTimeMillis();
        transformer.setONDEXGraph(graphInput);
        transformer.start();
        fireEventOccurred(new GeneralOutputEvent(name + " took " + ((System.currentTimeMillis() - start) / 1000) + " seconds", getCurrentMethodName()));
        removeIndex(graphInput, lenv);
        return graphInput;
    } finally {
        if (lenv != null)
            lenv.closeAll();
    }
}
Also used : LuceneEnv(net.sourceforge.ondex.core.searchable.LuceneEnv) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) GeneralOutputEvent(net.sourceforge.ondex.event.type.GeneralOutputEvent)

Example 3 with ONDEXPluginArguments

use of net.sourceforge.ondex.ONDEXPluginArguments in project knetbuilder by Rothamsted.

the class Engine method runMapping.

/**
 * Runs a Mapping producer
 *
 * @param mapping    the mapping to run
 * @param args  arguments for the mapping
 * @param graphInput the graph to use as input (and by implication output)
 */
public ONDEXGraph runMapping(ONDEXMapping mapping, ONDEXPluginArguments args, ONDEXGraph graphInput) throws Exception {
    if (graphInput == null)
        throw new NullPointerException("Can not run plugin with a null graphInput");
    Set<ONDEXRelation> rit = graphInput.getRelations();
    if (rit == null)
        return graphInput;
    long relationsPre = rit.size();
    if (args == null) {
        args = new ONDEXPluginArguments(mapping.getArgumentDefinitions());
    }
    LuceneEnv lenv = null;
    if (mapping.requiresIndexedGraph()) {
        lenv = getIndex(graphInput, mapping.getName());
    }
    try {
        String name = mapping.getName();
        mapping.addONDEXListener(pluginLogger);
        mapping.setArguments(args);
        long start = System.currentTimeMillis();
        mapping.setONDEXGraph(graphInput);
        mapping.start();
        fireEventOccurred(new GeneralOutputEvent(name + " took " + +((System.currentTimeMillis() - start) / 1000) + " seconds", getCurrentMethodName()));
        rit = graphInput.getRelations();
        long relationsPost = rit.size() - relationsPre;
        fireEventOccurred(new GeneralOutputEvent("New Relations: " + relationsPost, getCurrentMethodName()));
        rit = null;
        removeIndex(graphInput, lenv);
        return graphInput;
    } finally {
        if (lenv != null)
            lenv.closeAll();
    }
}
Also used : LuceneEnv(net.sourceforge.ondex.core.searchable.LuceneEnv) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) GeneralOutputEvent(net.sourceforge.ondex.event.type.GeneralOutputEvent)

Example 4 with ONDEXPluginArguments

use of net.sourceforge.ondex.ONDEXPluginArguments in project knetbuilder by Rothamsted.

the class Engine method runExport.

/**
 * Runs an export plug-in on the specified graph
 *
 * @param exporter     the export to run
 * @param exportArgs   the args to run with
 * @param inputGraph   the graph to export
 * @throws Exception   if the export fails
 */
public void runExport(ONDEXExport exporter, ONDEXPluginArguments exportArgs, ONDEXGraph inputGraph) throws Exception {
    if (inputGraph == null)
        throw new NullPointerException("Can not run plugin with a null inputGraph");
    if (exportArgs == null)
        exportArgs = new ONDEXPluginArguments(exporter.getArgumentDefinitions());
    String name = exporter.getName();
    exporter.setArguments(exportArgs);
    exporter.addONDEXListener(pluginLogger);
    if (exporter.requiresValidators() != null && exporter.requiresValidators().length > 0) {
        initializeValidators(exporter.requiresValidators(), inputGraph);
    }
    long start = System.currentTimeMillis();
    exporter.setONDEXGraph(inputGraph);
    exporter.start();
    fireEventOccurred(new GeneralOutputEvent("Exporting with " + name + " took " + ((System.currentTimeMillis() - start) / 1000) + " seconds", getCurrentMethodName()));
}
Also used : ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) GeneralOutputEvent(net.sourceforge.ondex.event.type.GeneralOutputEvent)

Example 5 with ONDEXPluginArguments

use of net.sourceforge.ondex.ONDEXPluginArguments in project knetbuilder by Rothamsted.

the class Engine method runParser.

/**
 * Runs a parser producer
 *
 * @param parser the parser to run
 * @param args  arguments for the parser
 * @param graphInput the graph to use as input (and by implication output)
 * @throws Exception
 */
public ONDEXGraph runParser(ONDEXParser parser, ONDEXPluginArguments args, ONDEXGraph graphInput) throws Exception {
    if (graphInput == null)
        throw new NullPointerException("Can not run plugin with a null graphInput");
    if (args == null)
        args = new ONDEXPluginArguments(parser.getArgumentDefinitions());
    LuceneEnv lenv = null;
    if (parser.requiresIndexedGraph()) {
        lenv = getIndex(graphInput, parser.getName());
    }
    try {
        parser.addONDEXListener(pluginLogger);
        parser.setArguments(args);
        if (parser.requiresValidators() != null && parser.requiresValidators().length > 0) {
            initializeValidators(parser.requiresValidators(), graphInput);
        }
        long start = System.currentTimeMillis();
        parser.setONDEXGraph(graphInput);
        parser.start();
        fireEventOccurred(new GeneralOutputEvent(parser.getName() + " took " + +((System.currentTimeMillis() - start) / 1000) + " seconds", getCurrentMethodName()));
        removeIndex(graphInput, lenv);
        return graphInput;
    } finally {
        if (lenv != null)
            lenv.closeAll();
    }
}
Also used : LuceneEnv(net.sourceforge.ondex.core.searchable.LuceneEnv) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) GeneralOutputEvent(net.sourceforge.ondex.event.type.GeneralOutputEvent)

Aggregations

ONDEXPluginArguments (net.sourceforge.ondex.ONDEXPluginArguments)78 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)43 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)29 Test (org.junit.Test)27 File (java.io.File)19 ONDEXGraph (net.sourceforge.ondex.core.ONDEXGraph)19 MemoryONDEXGraph (net.sourceforge.ondex.core.memory.MemoryONDEXGraph)15 StateEdit (javax.swing.undo.StateEdit)13 ConceptClass (net.sourceforge.ondex.core.ConceptClass)13 VisibilityUndo (net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)13 OVTK2Desktop (net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop)13 LuceneEnv (net.sourceforge.ondex.core.searchable.LuceneEnv)12 OVTK2Filter (net.sourceforge.ondex.ovtk2.filter.OVTK2Filter)12 Attribute (net.sourceforge.ondex.core.Attribute)11 AttributeName (net.sourceforge.ondex.core.AttributeName)11 DataSource (net.sourceforge.ondex.core.DataSource)11 Parser (net.sourceforge.ondex.parser.oxl.Parser)11 EvidenceType (net.sourceforge.ondex.core.EvidenceType)10 HashSet (java.util.HashSet)9 ArgumentDefinition (net.sourceforge.ondex.args.ArgumentDefinition)9