Skip to content

Instantly share code, notes, and snippets.

@dritoshi
Created July 10, 2012 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dritoshi/3081343 to your computer and use it in GitHub Desktop.
Save dritoshi/3081343 to your computer and use it in GitHub Desktop.
Transforming gene symbol to genomic position
#!/usr/bin/env ruby
require "rubygems"
require "biomart"
require "pp"
htgt = Biomart::Server.new( "http://www.sanger.ac.uk/htgt/biomart" )
ensmus = htgt.datasets["mmusculus_gene_ensembl"]
# pp ensmus.list_filters
gene_symbol = ARGF.each do |line|
line.chomp!
refseqid, gene_symbol, ensg = line.split(/,/)
res = ensmus.search(
:filters => { "ensembl_gene_id" => ensg },
:attributes => ["ensembl_gene_id", "chromosome_name", "start", "end"]
)
ensg, chr, start_bp, end_bp = res[:data].flatten
puts [gene_symbol, ensg, "chr#{chr}:#{start_bp}-#{end_bp}"].join("\t")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment