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
114 115 116 117 |
# File 'lib/MARQ/ID.rb', line 114 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
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 |
# File 'lib/MARQ/ID.rb', line 17 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)']) total_fields = Organism.supported_ids(org).length total_fields.times{|field| 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.strip.downcase, [native]) rescue puts $!. end } } } end |
.id_position(org, id) ⇒ Object
11 12 13 14 |
# File 'lib/MARQ/ID.rb', line 11 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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/MARQ/ID.rb', line 52 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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/MARQ/ID.rb', line 90 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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/MARQ/ID.rb', line 67 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 |