Class: Bio::KEGG::KGML
- Inherits:
-
Object
- Object
- Bio::KEGG::KGML
- Defined in:
- lib/sylfy/add/bio_kegg_kgml.rb
Overview
Class Bio::KEGG::KGML
Instance Method Summary collapse
-
#to_mjson ⇒ Object
convert KGML to mjson (map json).
Instance Method Details
#to_mjson ⇒ Object
convert KGML to mjson (map json)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sylfy/add/bio_kegg_kgml.rb', line 10 def to_mjson() mjson = {:identifier => :id} # <pathway> attributes mjson[:name] = @name mjson[:org] = @org mjson[:number] = @number mjson[:title] = @title mjson[:link] = @link mjson[:image] = {} mjson[:image][:source] = @image begin dim = open(@image).read()[0x10..0x18].unpack('NN') mjson[:image][:width] = dim[0] mjson[:image][:height] = dim[1] rescue end # <entry> attributes @entries.each do |entry| = {:id => entry.id, :entryname => entry.name, :link => entry.link, :entrytype => entry.type, :keggid => entry.names} [:reaction] = entry.reaction if entry.reaction # <graphics> attributes graphicinfo = {} if entry.graphics.length == 1 graphicinfo[:fill] = entry.graphics[0].bgcolor if entry.graphics[0].bgcolor graphicinfo[:stroke] = entry.graphics[0].fgcolor if entry.graphics[0].fgcolor graphicinfo[:name] = entry.graphics[0].name if entry.graphics[0].name case entry.graphics[0].type when 'rectangle' graphicinfo[:type] = :rect graphicinfo[:width] = entry.graphics[0].width graphicinfo[:height] = entry.graphics[0].height graphicinfo[:x] = entry.graphics[0].x graphicinfo[:y] = entry.graphics[0].y when 'roundrectangle' graphicinfo[:type] = :rect graphicinfo[:width] = entry.graphics[0].width graphicinfo[:height] = entry.graphics[0].height graphicinfo[:x] = entry.graphics[0].x graphicinfo[:y] = entry.graphics[0].y graphicinfo[:r] = 10 when 'circle' graphicinfo[:type] = :circle graphicinfo[:r] = entry.graphics[0].width/2 graphicinfo[:cx] = entry.graphics[0].x graphicinfo[:cy] = entry.graphics[0].y when 'line' graphicinfo[:type] = :path paths = [] entry.graphics[0].coords.each {|coord| paths.push(coord.join(" "))} graphicinfo[:fill] = entry.graphics[0].bgcolor if entry.graphics[0].bgcolor graphicinfo[:stroke] = entry.graphics[0].fgcolor if entry.graphics[0].fgcolor graphicinfo[:name] = entry.graphics[0].name if entry.graphics[0].name graphicinfo[:d] ||= "" graphicinfo[:d] += "M #{paths.join("L")}" if !paths.empty?() graphicinfo[:"stroke-width"] = 3 graphicinfo[:"stroke-linecap"] = "square" end else entry.graphics.each do |graph| if graph.type == 'line' paths = [] graph.coords.each {|coord| paths.push(coord.join(" "))} graphicinfo[:type] = :path graphicinfo[:fill] = graph.bgcolor if graph.bgcolor graphicinfo[:stroke] = graph.fgcolor if graph.fgcolor graphicinfo[:name] = graph.name if graph.name graphicinfo[:d] ||= "" graphicinfo[:d] += "M #{paths.join("L")}" if !paths.empty?() graphicinfo[:"stroke-width"] = 3 graphicinfo[:"stroke-linecap"] = "square" else raise "Graphic parsinf error to #{id}:#{entry.id}" end end end [:graphic] = graphicinfo mjson[graphicinfo[:type]] ||= [] mjson[graphicinfo[:type]].push() # <component> attributes end return mjson end |