Search in sources :

Example 1 with ONDEXLogger

use of net.sourceforge.ondex.logging.ONDEXLogger in project knetbuilder by Rothamsted.

the class RelationCollapserStringJoinTest method init.

@Before
public void init() throws Exception {
    collapser.setONDEXGraph(graph);
    ONDEXPluginArguments args = new ONDEXPluginArguments(collapser.getArgumentDefinitions());
    args.addOption(ArgumentNames.RELATION_TYPE_ARG, joinme.getId());
    collapser.setArguments(args);
    collapser.addONDEXListener(new ONDEXLogger());
}
Also used : ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger) Before(org.junit.Before)

Example 2 with ONDEXLogger

use of net.sourceforge.ondex.logging.ONDEXLogger in project knetbuilder by Rothamsted.

the class RelationNeighboursFilter method callFilter.

/**
 * Calls backend filter.
 *
 * @throws ParseException
 */
private void callFilter() throws Exception {
    if (targets != null && targets.size() > 0) {
        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
        desktop.setRunningProcess(this.getName());
        // this will also clear the concept list
        PickedState<ONDEXConcept> state = viewer.getVisualizationViewer().getPickedVertexState();
        state.clear();
        // contains results
        Set<ONDEXConcept> concepts = null;
        Set<ONDEXRelation> relations = null;
        // get depth
        depth = slider.getValue();
        // prevent self-loop in interactive mode
        state.removeItemListener(this);
        Set<String> ids = new HashSet<String>();
        // multiple filter calls
        for (ONDEXConcept target : targets) {
            ids.add(String.valueOf(target.getId()));
            // highlight seed concepts
            state.pick(target, true);
        }
        state.addItemListener(this);
        // create new filter
        Filter filter = new Filter();
        // construct filter arguments
        ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
        fa.addOptions(ArgumentNames.SEEDCONCEPT_ARG, ids.toArray(new String[ids.size()]));
        fa.addOption(ArgumentNames.DEPTH_ARG, Integer.valueOf(depth));
        // start filter
        filter.addONDEXListener(new ONDEXLogger());
        filter.setONDEXGraph(graph);
        filter.setArguments(fa);
        filter.start();
        // these are the filter results
        concepts = filter.getVisibleConcepts();
        relations = filter.getVisibleRelations();
        if (concepts != null) {
            // set all relations to invisible
            graph.setVisibility(graph.getRelations(), false);
            // set all concepts to invisible
            graph.setVisibility(graph.getConcepts(), false);
            // first set concepts visible
            graph.setVisibility(concepts, true);
            // second set relations visible
            graph.setVisibility(relations, true);
            // propagate change to viewer
            viewer.getVisualizationViewer().getModel().fireStateChanged();
        }
        // notify desktop
        edit.end();
        viewer.getUndoManager().addEdit(edit);
        desktop.getOVTK2Menu().updateUndoRedo(viewer);
        desktop.notifyTerminationOfProcess();
    }
}
Also used : OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.relationneighbours.Filter) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger) HashSet(java.util.HashSet)

Example 3 with ONDEXLogger

use of net.sourceforge.ondex.logging.ONDEXLogger in project knetbuilder by Rothamsted.

the class OnePairShortestPathFilter method callFilter.

/**
 * Calls backend filter.
 */
private void callFilter() {
    if (startSet != null && startSet.size() > 0 && endSet != null && endSet.size() > 0) {
        final SimpleMonitor monitor = new SimpleMonitor("preparing...", (startSet.size() * endSet.size()) + 1);
        Thread filterThread = new Thread("shortest path filter thread") {

            public void run() {
                // contains results
                Set<ONDEXConcept> concepts = null;
                Set<ONDEXRelation> relations = null;
                boolean useweights = !(ANselection == null || ANselection.equals(// no nullpointer danger because of
                defVal));
                // lazy
                // evaluation!
                boolean aborted = false;
                StringBuilder messages = new StringBuilder("Errors occurred during operation:\n");
                long before = System.currentTimeMillis();
                // multiple filter calls
                Iterator<ONDEXConcept> it = startSet.iterator();
                while (it.hasNext()) {
                    ONDEXConcept startConcept = it.next();
                    Iterator<ONDEXConcept> it2 = endSet.iterator();
                    while (it2.hasNext()) {
                        ONDEXConcept endConcept = it2.next();
                        if (startConcept.equals(endConcept))
                            continue;
                        String message = null;
                        // create new filter
                        Filter filter = new Filter();
                        try {
                            // construct filter arguments
                            ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
                            fa.addOption(ArgumentNames.STARTCONCEPT_ARG, startConcept.getId());
                            fa.addOption(ArgumentNames.STOPCONCEPT_ARG, endConcept.getId());
                            fa.addOption(ArgumentNames.ONLYDIRECTED_ARG, dirBox.isSelected());
                            fa.addOption(ArgumentNames.USEWEIGHTS_ARG, useweights);
                            if (useweights)
                                fa.addOption(ArgumentNames.WEIGHTATTRIBUTENAME_ARG, ANselection);
                            fa.addOption(ArgumentNames.INVERSE_WEIGHT_ARG, invBox.isSelected());
                            filter.addONDEXListener(new ONDEXLogger());
                            filter.setONDEXGraph(graph);
                            filter.setArguments(fa);
                            filter.start();
                        } catch (Exception e) {
                            if (e.getMessage() != null)
                                message = e.getMessage();
                            else
                                message = e.toString();
                        }
                        if (message == null) {
                            if (concepts == null) {
                                concepts = filter.getVisibleConcepts();
                                relations = filter.getVisibleRelations();
                            } else {
                                concepts = BitSetFunctions.or(concepts, filter.getVisibleConcepts());
                                relations = BitSetFunctions.or(relations, filter.getVisibleRelations());
                            }
                        } else {
                            messages.append(message + "\n");
                        }
                        aborted = !monitor.next(MonitoringToolKit.calculateWaitingTime(before, monitor));
                        if (aborted) {
                            break;
                        }
                    }
                    if (aborted) {
                        break;
                    }
                }
                if (!aborted) {
                    if (concepts != null) {
                        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
                        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
                        desktop.setRunningProcess(this.getName());
                        // set all relations to invisible
                        for (ONDEXRelation r : graph.getRelations()) {
                            graph.setVisibility(r, false);
                        }
                        // set all concepts to invisible
                        for (ONDEXConcept c : graph.getConcepts()) {
                            graph.setVisibility(c, false);
                        }
                        // first set concepts visible
                        for (ONDEXConcept c : concepts) {
                            graph.setVisibility(c, true);
                        }
                        // second set relations visible
                        for (ONDEXRelation r : relations) {
                            graph.setVisibility(r, true);
                        }
                        // propagate change to viewer
                        viewer.getVisualizationViewer().getModel().fireStateChanged();
                        edit.end();
                        viewer.getUndoManager().addEdit(edit);
                        desktop.getOVTK2Menu().updateUndoRedo(viewer);
                        desktop.notifyTerminationOfProcess();
                        monitor.complete();
                    } else {
                        monitor.complete();
                        JOptionPane.showMessageDialog(OVTK2Desktop.getInstance().getMainFrame(), messages.toString(), "Error", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        };
        OVTKProgressMonitor.start(OVTK2Desktop.getInstance().getMainFrame(), "Shortest path filter", monitor);
        filterThread.start();
    }
}
Also used : OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) SimpleMonitor(net.sourceforge.ondex.tools.threading.monitoring.SimpleMonitor) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.onepairshortestpath.Filter) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger)

Example 4 with ONDEXLogger

use of net.sourceforge.ondex.logging.ONDEXLogger in project knetbuilder by Rothamsted.

the class Parser method loadOXL.

/**
 * Utility to use this plug-in to load a graph outside of ONDEX, ONDEX Mini or alike. This is mainly useful for
 * testing.
 *
 * It populates the graph parameter and returns it. When the graph is null, creates a {@link MemoryONDEXGraph}.
 */
public static ONDEXGraph loadOXL(String filePath, ONDEXGraph graph) {
    try {
        if (graph == null)
            graph = new MemoryONDEXGraph("default");
        Parser parser = new Parser();
        parser.setONDEXGraph(graph);
        parser.addONDEXListener(new ONDEXLogger());
        ONDEXPluginArguments args = new ONDEXPluginArguments(parser.getArgumentDefinitions());
        args.setOption(FileArgumentDefinition.INPUT_FILE, filePath);
        parser.setArguments(args);
        parser.start();
        return graph;
    } catch (PluginConfigurationException ex) {
        throw ExceptionUtils.buildEx(UnexpectedValueException.class, ex, "Internal error while loading '%s': %s", filePath, ex.getMessage());
    }
}
Also used : UnexpectedValueException(uk.ac.ebi.utils.exceptions.UnexpectedValueException) MemoryONDEXGraph(net.sourceforge.ondex.core.memory.MemoryONDEXGraph) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) PluginConfigurationException(net.sourceforge.ondex.exception.type.PluginConfigurationException) ONDEXParser(net.sourceforge.ondex.parser.ONDEXParser)

Example 5 with ONDEXLogger

use of net.sourceforge.ondex.logging.ONDEXLogger in project knetbuilder by Rothamsted.

the class LuceneEnvTest method setUp.

@Before
public void setUp() throws IOException {
    og = new MemoryONDEXGraph(this.getClass().getName());
    dataSource = og.getMetaData().getFactory().createDataSource("dataSource");
    dataSource1 = og.getMetaData().getFactory().createDataSource("dataSource1");
    // cv2 = og.getMetaData().createDataSource( "cv2");
    cc = og.getMetaData().getFactory().createConceptClass("cc");
    cc1 = og.getMetaData().getFactory().createConceptClass("cc1");
    et = og.getMetaData().getFactory().createEvidenceType("et");
    // et1 = og.getMetaData().createEvidenceType( "et1");
    rts = og.getMetaData().getFactory().createRelationType("bla");
    at = og.getMetaData().getFactory().createAttributeName("att", String.class);
    // file = new File(File.createTempFile("lucene", "test").getParentFile().getAbsolutePath()+File.separator+"LuceneTest");
    // + System.currentTimeMillis ();
    String fpath = "target/lucene-env-test";
    file = new File(fpath);
    // System.out.println ( "Indexing on: " + fpath );
    if (file.exists())
        DirUtils.deleteTree(file);
    lenv = new LuceneEnv(file.getAbsolutePath(), true);
    lenv.addONDEXListener(new ONDEXLogger());
}
Also used : MemoryONDEXGraph(net.sourceforge.ondex.core.memory.MemoryONDEXGraph) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger) File(java.io.File) Before(org.junit.Before)

Aggregations

ONDEXLogger (net.sourceforge.ondex.logging.ONDEXLogger)14 ONDEXPluginArguments (net.sourceforge.ondex.ONDEXPluginArguments)9 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)5 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)5 MemoryONDEXGraph (net.sourceforge.ondex.core.memory.MemoryONDEXGraph)5 File (java.io.File)4 IOException (java.io.IOException)4 StateEdit (javax.swing.undo.StateEdit)4 OVTK2Filter (net.sourceforge.ondex.ovtk2.filter.OVTK2Filter)4 VisibilityUndo (net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)4 OVTK2Desktop (net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop)4 UncheckedIOException (java.io.UncheckedIOException)2 HashSet (java.util.HashSet)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 InvalidPluginArgumentException (net.sourceforge.ondex.InvalidPluginArgumentException)2 PluginConfigurationException (net.sourceforge.ondex.exception.type.PluginConfigurationException)2 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Optional (java.util.Optional)1