Skip to content

Instantly share code, notes, and snippets.

@wstrinz
Created June 8, 2013 06:03
Show Gist options
  • Save wstrinz/5734224 to your computer and use it in GitHub Desktop.
Save wstrinz/5734224 to your computer and use it in GitHub Desktop.
first code for RQTL to RDF tool
require 'qtl2rdf'
def print_usage
puts "Usage: java -jar QTL2RDF.jar variable [directory]"
end
var = ARGV[0]
dir = ARGV[1] || '.'
unless var
print_usage
exit
end
cl = QTL2RDF.new(dir)
h = cl.dump_scanone(var)
h.each {|v| puts v}
require 'rserve'
require 'rdf/4store'
class QTL2RDF
def initialize(dir='.')
dir = File.absolute_path(dir)
@R = Rserve::Connection.new()
@R.eval("load('#{dir}/.RData')") if File.exist?(dir + "/.RData")
@R.eval("loadhistory('#{dir}/.Rhistory')") if File.exist?(dir + "/.Rhistory")
end
def dump_scanone(var)
x = @R.eval(var)
rownames = x.attr.payload["row.names"].to_ruby
colnames = x.payload.names
rh = {}
rownames.each_with_index.map{ |row,i|
rh[row]={}
colnames.map{ |col|
rh[row][col] = x.payload[col].to_a[i]
}
}
rh
end
# rna.each_with_index.map{|row,i| rh[row]={}; na.map{|nn| rh[row][nn] = p[nn].to_a[i] }}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment