Write Simple Plugin with Ruby

(Under construction!)

rubyPlugin1.png

Introduction

By using scripting feature in Cytoscape, you can write a simple Ruby code to register your function as a menu item in Cytoscape Desktop.

Example

require 'java'

include_class 'cytoscape.Cytoscape'
include_class 'cytoscape.plugin.CytoscapePlugin'
include_class 'cytoscape.view.CyMenus'
include_class 'cytoscape.util.CytoscapeAction'

include_class 'java.awt.event.ActionEvent'
include_class 'javax.swing.JOptionPane'

class RubyAction < CytoscapeAction
  def initialize()
    super("Plugin written in Ruby")
    setPreferredMenu("Plugins")
  end

  def actionPerformed(evt)
    JOptionPane.showMessageDialog(
    nil, "Hello Ruby world", "JRuby on Cytoscape",
    JOptionPane::INFORMATION_MESSAGE)
  end
end

class RubyPlugin < CytoscapePlugin
  def register_menu
    cyMenus = Cytoscape.getDesktop().getCyMenus()
    cyMenus.addAction(RubyAction.new)
  end
end

RubyPlugin.new.register_menu()

When you run this script from Execute Scripts --> Ruby Scripting Engine, you can see the new menu item under Plugins. You can call your own analysis/visualization/utility functions from actionPerformed method.


Back to Scripting Plugin Page

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