Skip to content

Cytoscape Integration

Christian Zmasek edited this page Jun 30, 2015 · 11 revisions

This document is now outdated (as of 2015-06-30) Java-doc is here: http://cmzmasek.github.io/cx-impl/index.html

General CX documentation is here: https://github.com/cmzmasek/cxio/wiki/Java-Library-for-CX-Serialization-and-De-serialization

#Deployment

Copy the cx-impl-3.3.0-SNAPSHOT.jar from https://github.com/cmzmasek/cx-impl/tree/master/cx-impl/target into your CytoscapeConfiguration/3/apps/installed directory.

#Cytoscape Integration (Write)

The cxio Java library for CX serialization and de-serialization is being integrated into Cytoscape as a bundle named "cx-impl".

The two import classes for using the cxio library for writing from within Cytoscape are:

Example on how to serialize a Cytoscape network to a CX formatted Json stream:

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import org.cytoscape.io.internal.cxio.CxNetworkWriterFactory;
import org.cytoscape.io.write.CyWriter;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.NetworkTestSupport;

public class Example {

    public void example() throws Exception {
        
        // Creating a simple example network with two nodes and one edge:
        final NetworkTestSupport t = new NetworkTestSupport();
        final CyNetwork n = t.getNetwork();
        final CyNode a = n.addNode();
        final CyNode b = n.addNode();
        n.addEdge(a, b, true);
    
        // Creating the CxNetworkWriterFactory:
        final CxNetworkWriterFactory factory = new CxNetworkWriterFactory();

        // Using a ByteArrayOutputStream as example output stream:
        final OutputStream out = new ByteArrayOutputStream();

        // Using CxNetworkWriterFactory to create a CxNetworkWriter: 
        final CyWriter cx_network_writer = factory.createWriter(out, n);

        // Using the CxNetworkWriter to write network "n" to "out"
        // (TaskMonitor is not being used, thus the argument to "run" is null):
        cx_network_writer.run(null);

        // Printing the resting CX Json stream to the screen:
        System.out.println(out.toString());
    }
}

The output (the result of System.out.println(out.toString())) of this toy example looks like this (with indentations added):

[
    { "nodes":[
        {"@id":"91"},
        {"@id":"90"} ]
    },
    { "edges":[
        {"@id":"92","source":"90","target":"91"} ]
    }
]

Current issues and limitations

Currently, only nodes, edges, and node coordinates are written as CX Json. The next iteration will give the client the ability to choose which aspects to include, and provide support for more aspects (NodeAttributes, EdgeAttributes, ...)

When this feature becomes available, additional createWriter methods will be exposed.

Clone this wiki locally