Skip to content
Snippets Groups Projects
Commit e8d3a88e authored by Philipp Spohr's avatar Philipp Spohr
Browse files

implemented very very basic functionality

parent f1853e5d
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,7 @@ import org.cytoscape.application.swing.CytoPanelComponent; ...@@ -9,7 +9,7 @@ import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.service.util.AbstractCyActivator; import org.cytoscape.service.util.AbstractCyActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import de.hhu.ba.yoshikoWrapper.core.GraphParser; import de.hhu.ba.yoshikoWrapper.core.Core;
import de.hhu.ba.yoshikoWrapper.gui.MainPanel; import de.hhu.ba.yoshikoWrapper.gui.MainPanel;
import de.hhu.ba.yoshikoWrapper.gui.MainPanelAction; import de.hhu.ba.yoshikoWrapper.gui.MainPanelAction;
...@@ -24,7 +24,7 @@ public class CyActivator extends AbstractCyActivator { ...@@ -24,7 +24,7 @@ public class CyActivator extends AbstractCyActivator {
public void start(BundleContext context) throws Exception { public void start(BundleContext context) throws Exception {
//TODO: Load shared library if installed on startup //TODO: Load shared library if installed on startup
CyApplicationManager cyApplicationManager = getService(context, CyApplicationManager.class); CyApplicationManager cyApplicationManager = getService(context, CyApplicationManager.class);
GraphParser.registerApplicationManager(cyApplicationManager); Core.registerApplicationManager(cyApplicationManager);
CySwingApplication cytoscapeDesktopService = getService(context,CySwingApplication.class); CySwingApplication cytoscapeDesktopService = getService(context,CySwingApplication.class);
......
package de.hhu.ba.yoshikoWrapper.core;
import java.util.HashMap;
//TODO: ADD LOGGER SYSTEM
import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_std__vectorT_int_t;
import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput;
import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_ysk__ClusterEditingSolutions;
public class Core {
private static CyApplicationManager cy;
public static void registerApplicationManager(CyApplicationManager cyApplicationManager) {
cy = cyApplicationManager;
}
public static void performYoshiko() {
CyNetwork currentNetwork = cy.getCurrentNetwork();
if (currentNetwork == null) {
//TODO
}
NodeMap nodeMap = new NodeMap(currentNetwork);
SWIGTYPE_p_yskInput__LibraryInput input = NetworkParser.parseNetwork(currentNetwork,nodeMap);
SWIGTYPE_p_ysk__ClusterEditingSolutions solutions = LibraryInterface.processLibraryInput(input);
long numberOfSolutions = LibraryInterface.ClusterEditingSolutions_getNumberOfSolutions(solutions);
System.out.println("Found: "+numberOfSolutions+" solutions!");
double modificationCost = LibraryInterface.ClusterEditingSolutions_getTotalCost(solutions);
System.out.println("Paid a total modification cost of: "+modificationCost);
for (long i=0;i<numberOfSolutions;i++) {
System.out.println("Processing solution "+(i+1)+" of "+numberOfSolutions);
String columnName = "YOSHIKO_SOLUTION_"+(i+1);
currentNetwork.getDefaultNodeTable().createColumn(columnName, String.class, false);
long numberOfClusters = LibraryInterface.ClusterEditingSolutions_getNumberOfClusters(solutions, i);
for (long k=0;k<numberOfClusters;k++) {
System.out.println("Processing cluster "+(k+1)+" of "+numberOfClusters);
SWIGTYPE_p_std__vectorT_int_t cluster = LibraryInterface.ClusterEditingSolutions_getCluster(solutions, i, k);
long sizeOfCluster = LibraryInterface.IntVector_size(cluster);
for (int l=0;l<sizeOfCluster;l++) { //Unsafe mismatch int long
System.out.println("Processing entry "+(l+1)+ " of "+sizeOfCluster);
int nodeID = LibraryInterface.IntVector_get(cluster, l);
CyNode node = nodeMap.indexOf(nodeID); //<<< Another int/long conversion
if (node == null) {
System.out.println("FATAL ERROR: Node was not previously mapped!");
return;
}
currentNetwork.getRow(node).set(columnName, ""+(k+1));
}
}
}
LibraryInterface.delete_LibraryInput(input);
}
}
package de.hhu.ba.yoshikoWrapper.core; package de.hhu.ba.yoshikoWrapper.core;
import java.util.HashMap;
import java.util.List; import java.util.List;
import org.cytoscape.application.CyApplicationManager; import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyEdge; import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode; import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyTable; import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTableUtil;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput;
public class GraphParser { public class NetworkParser {
private static CyApplicationManager cy;
//**TODO MAKE DYNAMIC //**TODO MAKE DYNAMIC
private static String weightIndex = "weight"; private static String weightIndex = "Weight";
public static SWIGTYPE_p_yskInput__LibraryInput parseGraph() {
if (cy == null) {
//TODO:
} public static SWIGTYPE_p_yskInput__LibraryInput parseNetwork(CyNetwork net,NodeMap nodeMap) {
SWIGTYPE_p_yskInput__LibraryInput generatedInput = LibraryInterface.new_LibraryInput(); SWIGTYPE_p_yskInput__LibraryInput generatedInput = LibraryInterface.new_LibraryInput();
CyNetwork net = cy.getCurrentNetwork();
if (net != null){ if (net != null){
LibraryInterface.LibraryInput_setSize(generatedInput, net.getNodeCount()); LibraryInterface.LibraryInput_setSize(generatedInput, net.getNodeCount());
List<CyEdge> edges = net.getEdgeList(); List<CyEdge> edges = net.getEdgeList();
CyTable edgeTable = net.getDefaultEdgeTable(); Class<?> weightType = net.getDefaultEdgeTable().getColumn(weightIndex).getType();
System.out.println("Column has type:"+weightType.getName());
for (CyEdge e : edges) { for (CyEdge e : edges) {
LibraryInterface.LibraryInput_addEdge( CyRow edgeEntry = net.getRow(e);
generatedInput, double weight = 0.0;
(e.getSource().getSUID()), if (weightType == Integer.class) {
(e.getTarget().getSUID()), weight = (double)edgeEntry.get(weightIndex, Integer.class);
0.0 }
); System.out.println("Found Edge: "+edgeEntry.get("name", String.class)+ "with weight:"+weight);
LibraryInterface.LibraryInput_addEdge(generatedInput,
nodeMap.get(e.getSource()),
nodeMap.get(e.getTarget())
, weight);
} }
} }
return generatedInput; return generatedInput;
} }
public static void registerApplicationManager(CyApplicationManager cyApplicationManager) {
cy = cyApplicationManager;
}
......
package de.hhu.ba.yoshikoWrapper.core;
import java.util.HashMap;
import java.util.Map.Entry;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
public class NodeMap {
private HashMap<CyNode,Long> nodeMap;
public NodeMap(CyNetwork net){
nodeMap = new HashMap<CyNode,Long> ();
long index = 0;
for (CyNode n :net.getNodeList()) {
nodeMap.put(n, index);
index++;
}
}
public long get(CyNode key) {
return nodeMap.get(key);
}
public CyNode indexOf(long nodeID) {
for (Entry<CyNode, Long> entry : nodeMap.entrySet()) {
if (nodeID == entry.getValue()) {
return entry.getKey();
}
}
return null;
}
}
...@@ -3,6 +3,7 @@ package de.hhu.ba.yoshikoWrapper.gui; ...@@ -3,6 +3,7 @@ package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.Component; import java.awt.Component;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.HashMap;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JButton; import javax.swing.JButton;
...@@ -12,8 +13,11 @@ import javax.swing.JOptionPane; ...@@ -12,8 +13,11 @@ import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.cytoscape.application.swing.CytoPanelComponent; import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName; import org.cytoscape.application.swing.CytoPanelName;
import org.cytoscape.model.CyNode;
import de.hhu.ba.yoshikoWrapper.core.GraphParser; import de.hhu.ba.yoshikoWrapper.core.Core;
import de.hhu.ba.yoshikoWrapper.core.NetworkParser;
import de.hhu.ba.yoshikoWrapper.core.NodeMap;
import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput;
...@@ -77,8 +81,8 @@ public class MainPanel extends JPanel implements CytoPanelComponent { ...@@ -77,8 +81,8 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (yoshikoLoader.isLibraryLoaded()){ if (yoshikoLoader.isLibraryLoaded()){
SWIGTYPE_p_yskInput__LibraryInput input = GraphParser.parseGraph(); Core.performYoshiko();
LibraryInterface.delete_LibraryInput(input);
} }
} }
......
...@@ -9,6 +9,52 @@ ...@@ -9,6 +9,52 @@
package de.hhu.ba.yoshikoWrapper.swig; package de.hhu.ba.yoshikoWrapper.swig;
public class LibraryInterface { public class LibraryInterface {
public static SWIGTYPE_p_std__vectorT_int_t new_IntVector() {
long cPtr = LibraryInterfaceJNI.new_IntVector__SWIG_0();
return (cPtr == 0) ? null : new SWIGTYPE_p_std__vectorT_int_t(cPtr, true);
}
public static SWIGTYPE_p_std__vectorT_int_t new_IntVector(long n) {
long cPtr = LibraryInterfaceJNI.new_IntVector__SWIG_1(n);
return (cPtr == 0) ? null : new SWIGTYPE_p_std__vectorT_int_t(cPtr, true);
}
public static long IntVector_size(SWIGTYPE_p_std__vectorT_int_t self) {
return LibraryInterfaceJNI.IntVector_size(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self));
}
public static long IntVector_capacity(SWIGTYPE_p_std__vectorT_int_t self) {
return LibraryInterfaceJNI.IntVector_capacity(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self));
}
public static void IntVector_reserve(SWIGTYPE_p_std__vectorT_int_t self, long n) {
LibraryInterfaceJNI.IntVector_reserve(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self), n);
}
public static boolean IntVector_isEmpty(SWIGTYPE_p_std__vectorT_int_t self) {
return LibraryInterfaceJNI.IntVector_isEmpty(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self));
}
public static void IntVector_clear(SWIGTYPE_p_std__vectorT_int_t self) {
LibraryInterfaceJNI.IntVector_clear(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self));
}
public static void IntVector_add(SWIGTYPE_p_std__vectorT_int_t self, int x) {
LibraryInterfaceJNI.IntVector_add(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self), x);
}
public static int IntVector_get(SWIGTYPE_p_std__vectorT_int_t self, int i) {
return LibraryInterfaceJNI.IntVector_get(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self), i);
}
public static void IntVector_set(SWIGTYPE_p_std__vectorT_int_t self, int i, int val) {
LibraryInterfaceJNI.IntVector_set(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self), i, val);
}
public static void delete_IntVector(SWIGTYPE_p_std__vectorT_int_t self) {
LibraryInterfaceJNI.delete_IntVector(SWIGTYPE_p_std__vectorT_int_t.getCPtr(self));
}
public static SWIGTYPE_p_ysk__ClusterEditingSolutions new_ClusterEditingSolutions() { public static SWIGTYPE_p_ysk__ClusterEditingSolutions new_ClusterEditingSolutions() {
long cPtr = LibraryInterfaceJNI.new_ClusterEditingSolutions(); long cPtr = LibraryInterfaceJNI.new_ClusterEditingSolutions();
return (cPtr == 0) ? null : new SWIGTYPE_p_ysk__ClusterEditingSolutions(cPtr, true); return (cPtr == 0) ? null : new SWIGTYPE_p_ysk__ClusterEditingSolutions(cPtr, true);
......
...@@ -9,6 +9,17 @@ ...@@ -9,6 +9,17 @@
package de.hhu.ba.yoshikoWrapper.swig; package de.hhu.ba.yoshikoWrapper.swig;
public class LibraryInterfaceJNI { public class LibraryInterfaceJNI {
public final static native long new_IntVector__SWIG_0();
public final static native long new_IntVector__SWIG_1(long jarg1);
public final static native long IntVector_size(long jarg1);
public final static native long IntVector_capacity(long jarg1);
public final static native void IntVector_reserve(long jarg1, long jarg2);
public final static native boolean IntVector_isEmpty(long jarg1);
public final static native void IntVector_clear(long jarg1);
public final static native void IntVector_add(long jarg1, int jarg2);
public final static native int IntVector_get(long jarg1, int jarg2);
public final static native void IntVector_set(long jarg1, int jarg2, int jarg3);
public final static native void delete_IntVector(long jarg1);
public final static native long new_ClusterEditingSolutions(); public final static native long new_ClusterEditingSolutions();
public final static native long ClusterEditingSolutions_getNumberOfClusters(long jarg1, long jarg2); public final static native long ClusterEditingSolutions_getNumberOfClusters(long jarg1, long jarg2);
public final static native long ClusterEditingSolutions_getCluster(long jarg1, long jarg2, long jarg3); public final static native long ClusterEditingSolutions_getCluster(long jarg1, long jarg2, long jarg3);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment