Module: ID
- Defined in:
- lib/MARQ/ID.rb
Constant Summary collapse
- DEFAULT_FORMAT_ALL =
DEFAULT_FORMAT_ALL = ‘Entrez Gene Id’
nil
- DEFAULT_FORMATS =
{}
- @@supported =
{}
Class Method Summary collapse
- .AILUN_translate(platform, genes) ⇒ Object
- .DB_load(org, to = 0) ⇒ Object
- .id_position(org, id) ⇒ Object
- .translate_DB(org, genes, options = {}) ⇒ Object (also: translate)
- .translate_grep(org, genes, options = {}) ⇒ Object
- .translate_index(org, genes, options = {}) ⇒ Object
Class Method Details
.AILUN_translate(platform, genes) ⇒ Object
118 119 120 121 |
# File 'lib/MARQ/ID.rb', line 118 def self.AILUN_translate(platform, genes) index = Open.to_hash("ftp://ailun.stanford.edu/ailun/annotation/geo/#{platform}.annot.gz", :fix => proc{|l| l.match(/^(.*?)\t(.*?)\t.*/); $1.downcase + "\t" + $2 }) index.values_at(*genes.collect{|code| code.strip.downcase}).collect{|v| v.nil? ? nil : v.first.first} end |
.DB_load(org, to = 0) ⇒ Object
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 |
# File 'lib/MARQ/ID.rb', line 16 def self.DB_load(org, to = 0) identifier_file = File.join(Rbbt.datadir,'organisms',org,'identifiers') tablename = "ID_#{org.to_s.strip}_#{to.to_s.strip}" if DBcache.has_table?(tablename) DBcache.drop(tablename) end DBcache.create(tablename, 'CHAR(50)', ['CHAR(50)']) require 'progress-monitor' total_fields = Organism.supported_ids(org).length Progress.monitor "Loading ID DB table for #{ org } - #{to}" total_fields.times{|field| Progress.monitor "Processing file. Field #{ field } / #{total_fields}" File.open(identifier_file).each{|l| next if l =~ /^#/ codes = l.chomp.split(/\t/) native = codes[to] next if native.nil? || native == "" other = codes[field] next if other.nil? || other == "" #codes.collect{|c| c.split("|")}.flatten.compact.select{|c| c != ""}.uniq.each{|code| other.split("|").each{|code| begin DBcache.fast_add(tablename, code.downcase, [native]) rescue puts $!. end } } } end |
.id_position(org, id) ⇒ Object
10 11 12 13 |
# File 'lib/MARQ/ID.rb', line 10 def self.id_position(org, id) @@supported[org] ||= Organism.supported_ids(org) Organism.id_position(@@supported[org], id) end |
.translate_DB(org, genes, options = {}) ⇒ Object Also known as: translate
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/MARQ/ID.rb', line 56 def self.translate_DB(org, genes, = {}) to = [:to] || DEFAULT_FORMATS[org] || DEFAULT_FORMAT_ALL if to to = id_position(org, to) else to = 0 end tablename = "ID_#{org.to_s.strip}_#{to.to_s.strip}" DB_load(org, to) unless DBcache.has_table?(tablename) genes = genes.collect{|gene| gene.strip.downcase} DBcache.load(tablename, genes).values_at(*genes).collect{|gene| gene.first if gene} end |
.translate_grep(org, genes, options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/MARQ/ID.rb', line 94 def self.translate_grep(org, genes, = {}) to = [:to] || DEFAULT_FORMATS[org] || DEFAULT_FORMAT_ALL from = [:from] = {} [:extra] = [id_position(org, from)] if from [:native] = id_position(org,to) if to [:case_sensitive] ||= false genes = genes.collect{|gene| gene.strip if gene} genes = genes.collect{|gene| gene.downcase} unless [:case_sensitive] #genes_re = '\(^\|[' + "\t" + '|]\)' + genes.join('\|') + '\($\|[' + "\t" + '|]\)' #cmd = "cat #{File.join(Rbbt.datadir,'organisms',org,'identifiers')}|grep -i '#{genes_re}'" genes_re = '(?:^|[\t\|])(?:' + genes.join('|') + ')(?:$|[\t\|])' cmd = "cat #{File.join(Rbbt.datadir,'organisms',org,'identifiers')}|ruby -lne 'puts $_ if $_ =~ /#{genes_re}/i'" index = Index.index(IO::popen(cmd), ) index.values_at(*genes) end |
.translate_index(org, genes, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/MARQ/ID.rb', line 71 def self.translate_index(org, genes, = {}) genes = genes.collect{|gene| gene.strip if gene} to = [:to] || DEFAULT_FORMATS[org] || DEFAULT_FORMAT_ALL from = [:from] @indexes ||= {} if @indexes[org.to_s + to.to_s + from.to_s].nil? puts "Loading #{ org }" = {} [:other] = [from] if from [:native] = to if to [:case_sensitive] = false @indexes[org.to_s + to.to_s + from.to_s] = Organism.id_index(org, ) end index = @indexes[org.to_s + to.to_s + from.to_s] return genes.collect{|code| code.nil? || code == "" ? nil : index[code] } end |