Archive for the ‘Programming’ Category
Set up an app project in Eclipse for Cytoscape 3
The new Cytoscape 3 is based on OSGI, which I barely know anything about. Even though Cytoscape 3 is still in beta, manuals, wikies and tutorials have been flowing around in the web, which could be overwhelming if you want to create a new C3 compatible bundle app. Today I tried to set up an Cytoscape 3 bundle App (aka Plugin in the Cytoscape 2.x world) development environment in Eclipse. To my surprise, it is without any hassle by following a tutorial and a wiki page.
First, by following this tutorial: Create a Bundle App Using IDE , it’s really straightforward to create the app with Maven and Eclipse (M2Eclipse is required). After everything is set up, I made sure that the app was installed by running “mvn install” (either in the app directory from command line or within eclipse) and checked my local maven repository ~/.m2/repository/groupid/architectid (yes I am using Linux).
Then I followed this wiki page: Interactive Shell , and deployed the app and tested it.
First download cytoscape 3:
> wget http://chianti.ucsd.edu/cytoscape-3.0.0-M4/cytoscape-unix-3.0.0-M4.tar.gz > tar xzf cytoscape-unix-3.0.0-M4.tar.gz > cd cytoscape-unix-3.0.0-M4 > ./cytoscape.sh # this will start cytoscape shell and the GUI Cytoscape 3.0.0-M4> install mvn:groupid/artifactid Bundle ID: 162 Cytoscape 3.0.0-M4> start 162
Now go to the Cytoscape GUI, and open Apps menu, and there it is: “Hello World!”

igraph example: edge-labeled graph or weighted graph
Here is an example of how to create a edge-labeled graph using igraph.
> a a [,1] [,2] [,3] [1,] 0 2 1 [2,] 2 0 3 [3,] 1 3 0 > g1 g1 Vertices: 3 Edges: 6 Directed: TRUE Edges: [0] 0 -> 1 [1] 0 -> 2 [2] 1 -> 0 [3] 1 -> 2 [4] 2 -> 0 [5] 2 -> 1 > E(g1)$weight [1] 2 1 2 3 1 3 > E(g1) Edge sequence: [0] 0 -> 1 [1] 0 -> 2 [2] 1 -> 0 [3] 1 -> 2 [4] 2 -> 0 [5] 2 -> 1 > get.adjacency(g1, attr="weight") [,1] [,2] [,3] [1,] 0 2 1 [2,] 2 0 3 [3,] 1 3 0
Add noise to data
There are two easy ways to add noise, by scale the original data, or by mask some noise on the data.
First for a simple function , the following matlab code add 10% noise to it.
N = 100; x = linspace(-pi, pi, N); y = sin(x); plot(x, y, 'r'); hold on; % add 10% noise based on gaussian scale = 0.1; n1 = randn(1, N); % noise with mean=0 and std=1; y1 = y + n1.*y*scale; plot(x, y1, 'g'); % mask signal with noise n2 = 0.1*randn(1,N)*sqrt(max(abs(y))); % noise with mean=0 and %std=max(amplitude); y2 = y + n2; plot(x, y2, 'b'); % Of course we can combine the two y3 = y1 + n2; plot(x, y3, 'm');
The final result looks like this:

We can also try to add noise to a more complicated synthetic data. For example, the famous swiss roll data[1] in manifold learning. First, we can generate the dataset by this function:
Plot a scatter plot of will give us a swiss roll dataset. For example, the following matlab code will create this figure.
N = 500; r = linspace(0,1,N); t = (3*pi/2)*(1+2*r); x = t.*cos(t); y = t.*sin(t); z = 20*rand(1,N); scatter3(x, y, z, 12, t, 'filled');
Now after adding noise. the standard deviation of the noise is 2% of smallest dimension of the bounding box enclosing the data (as discussed in [2])
mindim = min(max(y)-min(y), max(x)-min(x)); x = x+0.02*randn(1,N)*sqrt(mindim); y = y+0.02*randn(1,N)*sqrt(mindim); scatter3(x, y, z, 12, t, 'filled');
1. Tenenbaum, J.B., Silva, V.D. & Langford, J.C. A Global Geometric Framework for Nonlinear Dimensionality Reduction. Science 290, 2319-2323 (2000).
2. Balasubramanian, M., Schwartz, E.L., Tenenbaum, J.B., de Silva, V. & Langford, J.C. The Isomap Algorithm and Topological Stability. Science 295, 7a (2002).

