Differences between revisions 1 and 17 (spanning 16 versions)
Revision 1 as of 2012-03-16 23:49:36
Size: 367
Editor: server2
Comment:
Revision 17 as of 2012-03-19 23:38:57
Size: 9219
Editor: server2
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Describe Cytoscape_3/AppDeveloper/Cytoscape_3_App_Cookbook here.

About the cookbook
<<TableOfContents(2)>>
= About the cookbook =
Line 11: Line 10:

= How to use the cookbook? =
SVN repository: http://chianti.ucsd.edu/svn/core3/support/trunk/samples/

Steps:

 1. Check out sample project from SVN repository with the above URL
 1. Compile with “mvn clean install”
 1. Copy the jar in the project target directory to Cytoscape installation: bundles/apps
 1. Start Cytoscape 3.0


= The list of app examples in the cookbook =

The list of sample apps is basically the same as in [[http://cytoscape.wodaklab.org/wiki/plugin_developer_tutorial|the cookbook for Cytoscape 2.X]]. They are mostly Cytoscape Bundle apps, but also include a few Simple apps. Some of them are,

== Introduction ==
This tutorial will show some code snippets about how to use Cytoscape APIs on plugin development. Each feature is included in a sample plugin, which can serve as a starting point or template for new plugin developers. The code snippets can also be used as reference for experienced developers.

Cytoscape plugin is usually packaged in a jar file and deployed to the plugins directory of Cytoscape. When Cytoscape starts up and initializes, its plugin manager will look up all the plugins in plugins directory. A plugin should have following three components.

    A class, which extends CytoscapePlugin. This is the entry point to Cytoscape.

    A manifest file, explicitly list the class, which extended CytoscapePlugin class

    A plugin.props file, which list the information about the plugin, such as plugin name, author, release date and more. Although this file is not absolutely required, it is recommended to have one, since plugin manager will need the information to handle the plugin properly. See the page at http://www.cytoscape.org/cgi-bin/moin.cgi/Cytoscape_Plugin_Tutorial for detail about the definition of a plugin.props.

If plugin developer will share and publish their plugins, they are encouraged to submit their plugins to Cytoscape plugin website at http://cytoscape.org/plugins/index.php .

== How to add a tabbed Panel to Control panel? ==
It takes three steps to add a tabbed panel to the control panel.
{{{
#!java
//1. Define a CytoPanel class
public class MyCytoPanel extends JPanel implements CytoPanelComponent {

    ...
    @Override
    public CytoPanelName getCytoPanelName() {
 return CytoPanelName.WEST;
    }
     ...
}

// 2. Create an instance of MyCytoPanel
MyCytoPanel myPanel = new MyPanel();

//3. Register myPanel as a service
   registerService(bc,myCytoPanel,CytoPanelComponent.class, new Properties());
}}}

Download a sample plugin, here.

== How to add an image icon (menu item) to the toolbar? ==


{{{
#!java
// Define a CyAction class
public class AddImageIconAction extends AbstractCyAction {
 
    public AddImageIconAction(CySwingApplication desktopApp){
        ...
        ImageIcon icon = new ImageIcon(getClass().getResource("/images/tiger.jpg"));

 putValue(LARGE_ICON_KEY, icon);
       ...
    }

    public boolean isInToolBar() {
 return true;
    }
    ...
}
}}}

{{{
#!java
// Register the CyAction as service
AddImageIconAction addImageIconAction = new AddImageIconAction(cytoscapeDesktopService);
registerService(bc,addImageIconAction,CyAction.class, new Properties());
}}}

== How to create a submenu? ==

{{{
#!java
// Define a CyAction class
public class Sample04 extends AbstractCyAction {
    ...
    public Sample04(CySwingApplication desktopApp){
 // Add a sub-menu item -- Apps->Sample04->sample04
 super("sample04...");
 setPreferredMenu("Apps.Sample04");
 //Specify the menuGravity value to put the menuItem in the desired place
        setMenuGravity(2.0f);
        ...
    }
}}}

{{{
#!java
// Register the CyAction as service
Sample04 Sample04Action = new Sample04(cytoscapeDesktopService);
registerService(bc,Sample04Action,CyAction.class, new Properties());
}}}


== How to create, modify, and destroy a network, nodes, and edges? ==

{{{
#!java

}}}

== How to create, modify, and destroy a network view? ==
{{{
#!java

}}}

== How to save/restore app states? ==
{{{
#!java

}}}

== How to determine which nodes are currently selected on a network? ==
{{{
#!java

}}}

== How to handle events from a network (and discuss each event type)? ==
{{{
#!java

}}}

== How to change the background color of a view? ==
{{{
#!java

}}}

== How to zoom a network view? ==


{{{
#!java
// Define a task
public class ZoomTask extends AbstractNetworkViewTask {
    ...
    ZoomTask(CyNetworkView v) {
 super(v);
        ...
    }

    public void run(TaskMonitor tm) {
 ...
        // Get the scale and adjust it
 double newScale = view.getVisualProperty(NETWORK_SCALE_FACTOR).doubleValue() * scale;
 view.setVisualProperty(NETWORK_SCALE_FACTOR, newScale);
  
 view.updateView();
 }
    }
    ...
}
}}}

{{{
#!java
// Define taskFactory and pass in the view as parameter to the task
public class Sample10TaskFactory extends AbstractNetworkViewTaskFactory {
    ....
    public TaskIterator createTaskIterator() {
        ...
 return new TaskIterator(new ZoomTask(this.view));
        ....
    }
}
}}}

{{{
#!java
// Register the task factory as service
registerService(bc,sample10TaskFactory,TaskFactory.class, sample10TaskFactoryProps);
}}}

== How to load attribute data? ==
{{{
#!java
// Define a task
public class CreateTableTask extends AbstractTask {
    ....
    @Override
    public void run(TaskMonitor tm) throws IOException {
 // Step 1: create a new table
 CyTable table = tableFactory.createTable("MyAttrTable " + Integer.toString(numImports++),
       "name", String.class, true, true);

 // create a column for the table
 String attributeNmae = "MyAttributeName";
 table.createColumn(attributeNmae, Integer.class, false);
  
 // Step 2: populate the table with some data
 String[] keys = {"YLL021W","YBR170C","YLR249W"}; //map to the the "name" column
 CyRow row = table.getRow(keys[0]);
 row.set(attributeNmae, new Integer(2));

 row = table.getRow(keys[1]);
 row.set(attributeNmae, new Integer(3));

 row = table.getRow(keys[2]);
 row.set(attributeNmae, new Integer(4));

 // We are loading node attribute
 Class<? extends CyTableEntry> type = CyNode.class;

 // Step 3: pass the new table to MapNetworkAttrTask
 super.insertTasksAfterCurrentTask( new MapNetworkAttrTask(type,table,netMgr,appMgr,rootNetworkManager) );
    }
    ....
}




}}}


== How to remove attributes? ==
{{{
#!java

}}}

== How to use a web service client? ==
{{{
#!java

}}}


== How to write a web service client? ==
{{{
#!java

}}}

== How to use the VizMapper programmatically? ==
{{{
#!java

}}}

== How to apply a continuous color gradient to nodes according to their degree? ==
{{{
#!java

}}}

== How to load a visual properties file? ==
{{{
#!java

}}}

== How to write a layout algorithm? ==
{{{
#!java

}}}

== How to write a Group Viewer? ==
{{{
#!java

}}}


== How to add components to the node view, edge view, and attribute browser context menus? ==
{{{
#!java

}}}

== How to save/restore plugin states? ==
{{{
#!java

}}}



== How to use the Cytoscape task monitor to show the progress of my job? ==
{{{
#!java

}}}


== How to add new attribute functions via a Cytoscape plug-in? ==
{{{
#!java

}}}


== How to add plug-in specific help to the Cytoscape main help system? ==
{{{
#!java

}}}


= Trouble shooting =

If you get compile error,

 1. Check the version number of parent POM, the latest is at [[http://chianti.ucsd.edu/svn/core3/parent/trunk|Cytoscape repository]]
 1. If this is a dependency problem, check the version number of depended bundle at [[http://cytoscape.wodaklab.org/nexus/index.html|Cytoscape repository]]


= Recommendations =
 1. If you’re a beginner you probably want to use the Simple app type. see example02a, example03a
 1. If you want to port as quickly as possible, again, go with the Simple app type.
 1. If you want to publish an API you must use the Bundle app type
 1. If you experience version conflicts or anticipate future version conflicts, again you must use the Bundle app type.
 1. If you are in doubt, you should probably use the Simple app type. You can always port it to the Bundle app type later should that become necessary. Both styles are supported and will be until (at least) version 4.0.


= App Porting Hints =
How to

 1. get current network --- see sample app 5
 1. get attributes --- see sample app 11
 1. add a menu item --- see sample app 3

= Questions, suggestions =

Please send e-mail to [[http://groups.google.com/group/cytoscape-helpdesk?pli=1|cytoscape help desk]] or [[http://groups.google.com/group/cytoscape-discuss|discussion group]]

About the cookbook

To help app developers to develop their own app, the Cytoscape developer team developed the cookbook, a collection of small apps. The cookbook could be used to

  1. get your feet wet
  2. find a template project to extend
  3. find out how to do something in Cytoscape.

How to use the cookbook?

SVN repository: http://chianti.ucsd.edu/svn/core3/support/trunk/samples/

Steps:

  1. Check out sample project from SVN repository with the above URL
  2. Compile with “mvn clean install”
  3. Copy the jar in the project target directory to Cytoscape installation: bundles/apps
  4. Start Cytoscape 3.0

The list of app examples in the cookbook

The list of sample apps is basically the same as in the cookbook for Cytoscape 2.X. They are mostly Cytoscape Bundle apps, but also include a few Simple apps. Some of them are,

Introduction

This tutorial will show some code snippets about how to use Cytoscape APIs on plugin development. Each feature is included in a sample plugin, which can serve as a starting point or template for new plugin developers. The code snippets can also be used as reference for experienced developers.

Cytoscape plugin is usually packaged in a jar file and deployed to the plugins directory of Cytoscape. When Cytoscape starts up and initializes, its plugin manager will look up all the plugins in plugins directory. A plugin should have following three components.

  • A class, which extends CytoscapePlugin. This is the entry point to Cytoscape.

    A manifest file, explicitly list the class, which extended CytoscapePlugin class

    A plugin.props file, which list the information about the plugin, such as plugin name, author, release date and more. Although this file is not absolutely required, it is recommended to have one, since plugin manager will need the information to handle the plugin properly. See the page at http://www.cytoscape.org/cgi-bin/moin.cgi/Cytoscape_Plugin_Tutorial for detail about the definition of a plugin.props.

If plugin developer will share and publish their plugins, they are encouraged to submit their plugins to Cytoscape plugin website at http://cytoscape.org/plugins/index.php .

How to add a tabbed Panel to Control panel?

It takes three steps to add a tabbed panel to the control panel.

   1 //1. Define a CytoPanel class
   2 public class MyCytoPanel extends JPanel implements CytoPanelComponent {
   3 
   4     ...
   5     @Override
   6     public CytoPanelName getCytoPanelName() {
   7         return CytoPanelName.WEST;
   8     }
   9      ...
  10 }
  11 
  12 // 2. Create an instance of MyCytoPanel
  13 MyCytoPanel myPanel = new MyPanel();
  14 
  15 //3. Register myPanel as a service
  16    registerService(bc,myCytoPanel,CytoPanelComponent.class, new Properties());
  17 

Download a sample plugin, here.

How to add an image icon (menu item) to the toolbar?

   1 // Define a CyAction class
   2 public class AddImageIconAction extends AbstractCyAction {
   3         
   4     public AddImageIconAction(CySwingApplication desktopApp){
   5         ...
   6         ImageIcon icon = new ImageIcon(getClass().getResource("/images/tiger.jpg"));
   7 
   8         putValue(LARGE_ICON_KEY, icon);
   9        ...
  10     }
  11 
  12     public boolean isInToolBar() {
  13         return true;
  14     }
  15     ...
  16 }
  17 

   1 // Register the CyAction as service
   2 AddImageIconAction addImageIconAction = new AddImageIconAction(cytoscapeDesktopService);
   3 registerService(bc,addImageIconAction,CyAction.class, new Properties());
   4 

How to create a submenu?

   1 // Define a CyAction class
   2 public class Sample04 extends AbstractCyAction {
   3     ...
   4     public Sample04(CySwingApplication desktopApp){
   5         // Add a sub-menu item -- Apps->Sample04->sample04
   6         super("sample04...");
   7         setPreferredMenu("Apps.Sample04");
   8         //Specify the menuGravity value to put the menuItem in the desired place
   9         setMenuGravity(2.0f);
  10         ...
  11     }
  12 

   1 // Register the CyAction as service
   2 Sample04 Sample04Action = new Sample04(cytoscapeDesktopService);
   3 registerService(bc,Sample04Action,CyAction.class, new Properties());
   4 

How to create, modify, and destroy a network, nodes, and edges?

   1 
   2 

How to create, modify, and destroy a network view?

   1 
   2 

How to save/restore app states?

   1 
   2 

How to determine which nodes are currently selected on a network?

   1 
   2 

How to handle events from a network (and discuss each event type)?

   1 
   2 

How to change the background color of a view?

   1 
   2 

How to zoom a network view?

   1 // Define a task
   2 public class ZoomTask extends AbstractNetworkViewTask {
   3     ...
   4     ZoomTask(CyNetworkView v) {
   5         super(v);
   6         ...
   7     }
   8 
   9     public void run(TaskMonitor tm) {
  10         ...     
  11         // Get the scale and adjust it  
  12         double newScale = view.getVisualProperty(NETWORK_SCALE_FACTOR).doubleValue() * scale;
  13         view.setVisualProperty(NETWORK_SCALE_FACTOR, newScale);
  14                 
  15         view.updateView();
  16         }
  17     }
  18     ...
  19 }
  20 

   1 // Define  taskFactory and pass in the view as parameter to the task
   2 public class Sample10TaskFactory extends AbstractNetworkViewTaskFactory {
   3     ....        
   4     public TaskIterator createTaskIterator() {
   5         ...
   6         return new TaskIterator(new ZoomTask(this.view));
   7         ....
   8     } 
   9 }
  10 

   1 // Register the task factory as service
   2 registerService(bc,sample10TaskFactory,TaskFactory.class, sample10TaskFactoryProps);
   3 

How to load attribute data?

   1 // Define a task
   2 public class CreateTableTask extends AbstractTask {
   3     ....
   4     @Override
   5     public void run(TaskMonitor tm) throws IOException {
   6         // Step 1: create a new table
   7         CyTable table = tableFactory.createTable("MyAttrTable " + Integer.toString(numImports++), 
   8                                    "name", String.class, true, true);
   9 
  10         // create a column for the table
  11         String attributeNmae = "MyAttributeName"; 
  12         table.createColumn(attributeNmae, Integer.class, false);
  13                 
  14         // Step 2: populate the table with some data
  15         String[] keys = {"YLL021W","YBR170C","YLR249W"}; //map to the the "name" column
  16         CyRow row = table.getRow(keys[0]);
  17         row.set(attributeNmae, new Integer(2));
  18 
  19         row = table.getRow(keys[1]);
  20         row.set(attributeNmae, new Integer(3));
  21 
  22         row = table.getRow(keys[2]);
  23         row.set(attributeNmae, new Integer(4));
  24 
  25         // We are loading node attribute
  26         Class<? extends CyTableEntry> type = CyNode.class;
  27 
  28         // Step 3: pass the new table to MapNetworkAttrTask
  29         super.insertTasksAfterCurrentTask( new MapNetworkAttrTask(type,table,netMgr,appMgr,rootNetworkManager) );
  30     }
  31     ....
  32 }
  33 

How to remove attributes?

   1 
   2 

How to use a web service client?

   1 
   2 

How to write a web service client?

   1 
   2 

How to use the VizMapper programmatically?

   1 
   2 

How to apply a continuous color gradient to nodes according to their degree?

   1 
   2 

How to load a visual properties file?

   1 
   2 

How to write a layout algorithm?

   1 
   2 

How to write a Group Viewer?

   1 
   2 

How to add components to the node view, edge view, and attribute browser context menus?

   1 
   2 

How to save/restore plugin states?

   1 
   2 

How to use the Cytoscape task monitor to show the progress of my job?

   1 
   2 

How to add new attribute functions via a Cytoscape plug-in?

   1 
   2 

How to add plug-in specific help to the Cytoscape main help system?

   1 
   2 

Trouble shooting

If you get compile error,

  1. Check the version number of parent POM, the latest is at Cytoscape repository

  2. If this is a dependency problem, check the version number of depended bundle at Cytoscape repository

Recommendations

  1. If you’re a beginner you probably want to use the Simple app type. see example02a, example03a
  2. If you want to port as quickly as possible, again, go with the Simple app type.
  3. If you want to publish an API you must use the Bundle app type
  4. If you experience version conflicts or anticipate future version conflicts, again you must use the Bundle app type.
  5. If you are in doubt, you should probably use the Simple app type. You can always port it to the Bundle app type later should that become necessary. Both styles are supported and will be until (at least) version 4.0.

App Porting Hints

How to

  1. get current network --- see sample app 5
  2. get attributes --- see sample app 11
  3. add a menu item --- see sample app 3

Questions, suggestions

Please send e-mail to cytoscape help desk or discussion group

Cytoscape_3/AppDeveloper/Cytoscape_3_App_Cookbook (last edited 2020-02-05 19:54:29 by KristinaHanspers)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux