require 'nyaplot' require 'bionya' arr = [] 10.times do |i| arr.push({group: 'group' + i.to_s ,df: Nyaplot::DataFrame.new({axis: ['a', 'b', 'c'], val: [2, 3, 4]})}) end df = Nyaplot::DataFrame.new(arr) plot = Nyaplot::CircularPlot.new(df, :group, :df) plot.to_json plot.add(1, :arc, :axis, :val) plot.show df = Nyaplot::DataFrame.from_csv('./data/circular/category.csv') df2 = Nyaplot::DataFrame.from_csv('./data/circular/hgmd.tsv', {col_sep: "\t"}) df3 = Nyaplot::DataFrame.from_csv('./data/circular/genes_hgmd.tsv', {col_sep: "\t"}) hash2 = {} df3.each_row do |row| chr_name = "chr" + row[:gene_name].match(/hs(.+)/)[1] hash2[chr_name] ||= [] hash2[chr_name].push({locale: row[:start], name: row[:name]}) end "" hash = {} df2.each_row do |row| chr_name = "chr" + row[:gene_name].match(/hs(.+)/)[1] hash[chr_name] ||= [] hash[chr_name].push({start: row[:start], val: row[:num2]}) end "" bin_size = df.size.max/50 chr_name = df.column(:name).to_a nested = df.column(:size).to_a.map.with_index do |size, i| vals = hash[chr_name[i]] names = hash2[chr_name[i]] vals = [] if vals.nil? names = [] if names.nil? raw = Array.new(size/bin_size, 0).map.with_index {|val, i| val = vals.reduce(0){|memo, v| next memo + v[:val] if v[:start] > i*bin_size && v[:start] < (i+1)*bin_size; memo} name = names.select {|name| name[:locale] > i*bin_size && name[:locale] < (i+1)*bin_size} {axis: i*bin_size, val: val, name: (name.length==0 ? '' : name[0][:name])} } Nyaplot::DataFrame.new(raw) end df.df = nested df df.name = df.column(:name).to_a.map{|name| name.match(/chr(.+)/)[1]} df color = Nyaplot::Colors.qual plot2 = Nyaplot::CircularPlot.new(df, :name, :df) arc = plot2.add(1, :arc, :axis, :val) arc.color(["rgb(56,108,176)"]) labels = plot2.add(2, :labels, :axis, :name) labels.text_size("0.3em") plot2.color(color) plot2.text_size("0.5em") plot2.text_color("#000") plot2.show from=[]; to=[] df.each_row do |row| chr_name = row[:name] axis = row[:df].axis.to_a 2.times do |i| num = axis.sample from.push(chr_name + '.' + num.to_s) num = axis.sample to.push(chr_name + '.' + num.to_s) end end connector_df = Nyaplot::DataFrame.new({from: from.shuffle,to: to.shuffle}) connector_df plot2.add_connector_with_df(connector_df, :from, :to) plot2.show