Attachment 'kegg_sample1.rb'

Download

   1 $LOAD_PATH << 'gems/1.8/gems/bio-1.2.1/lib'
   2 $LOAD_PATH << 'site_ruby/1.8'
   3 $LOAD_PATH << 'site_ruby'
   4 $LOAD_PATH << '1.8'
   5 $LOAD_PATH << '1.8/java'
   6 $LOAD_PATH << 'jruby'
   7 
   8 require 'set'
   9 require 'java'
  10 require 'bio'
  11 
  12 include_class 'java.util.ArrayList'
  13 include_class 'cytoscape.Cytoscape'
  14 include_class 'cytoscape.data.CyAttributes'
  15 include_class 'cytoscape.CyNode'
  16 include_class 'cytoscape.CyEdge'
  17 include_class 'cytoscape.CyNetwork'
  18 
  19 # original node id type.  You can change this to uniprot, genbank, etc.
  20 ID_TYPE = "ncbi-geneid"
  21 
  22 # Nodes in current network
  23 nodes =  Cytoscape.getCurrentNetwork.nodesList
  24 
  25 # Node Attributes
  26 nodeAttr = Cytoscape.getNodeAttributes
  27 
  28 serv = Bio::KEGG::API.new
  29 
  30 counter = 0
  31 buffer = ""
  32 
  33 # Conversion table as tab delimited text
  34 keggid = ""
  35 
  36 nodes.each do |node|
  37 	if counter < 100 && counter != 99
  38 		buffer = buffer + ID_TYPE + ":" + node.getIdentifier + " "
  39 		counter = counter + 1
  40 	elsif counter == 99
  41 		puts buffer
  42 		keggid = keggid + serv.bconv(buffer.strip)
  43 		counter = 0
  44 		buffer = ""
  45 	end
  46 end
  47 
  48 keggid = keggid + serv.bconv(buffer.strip)
  49 
  50 targetIDs = Set.new(enum = nil)
  51 nameHash = Hash.new
  52 
  53 keggid.each_line {|line| 
  54 	id_array = line.split("\t")
  55 	uniprotID = id_array[0].split(":")[1]
  56 	targetIDs << id_array[1]
  57 	nodeAttr.setAttribute(uniprotID, "KEGG ID", id_array[1])
  58 	nameHash[id_array[1]] = uniprotID
  59 }
  60 
  61 pathwaySet = Set.new(enum = nil)
  62 
  63 targetIDs.each do |kid|
  64 	puts kid + " ====> " + nameHash[kid]
  65 	if nameHash[kid] != nil
  66 		genes = [kid]
  67 		pathways = serv.get_pathways_by_genes(genes)
  68 	
  69 		pList = ArrayList.new()
  70 		pathways.each do |pathway|
  71 			if pathway.strip != ""
  72 				pathwaySet << pathway.strip
  73 				pList.add(pathway.strip)
  74 			end
  75 		end
  76 	
  77 		nodeAttr.setListAttribute(nameHash[kid], "KEGG Pathway", pList)
  78 	end
  79 end
  80 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this 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