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

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 $!.message
        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, options = {})
  to = options[: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, options = {})
  to = options[:to] || DEFAULT_FORMATS[org] || DEFAULT_FORMAT_ALL
  from = options[:from]

  options = {}
  options[:extra]  = [id_position(org, from)] if from
  options[:native] = id_position(org,to) if to
  options[:case_sensitive] ||= false

  genes = genes.collect{|gene| gene.strip if gene}
  genes = genes.collect{|gene| gene.downcase} unless options[: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), options)

  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, options = {})
  genes = genes.collect{|gene| gene.strip if gene}
  to = options[:to] || DEFAULT_FORMATS[org] || DEFAULT_FORMAT_ALL
  from = options[:from]
  @indexes ||= {}
  if  @indexes[org.to_s + to.to_s + from.to_s].nil?
    puts "Loading #{ org }"
    options = {}
    options[:other] = [from] if from
    options[:native] = to if to
    options[:case_sensitive] = false
    
    @indexes[org.to_s + to.to_s + from.to_s] = Organism.id_index(org, options)
  end

  index =  @indexes[org.to_s + to.to_s + from.to_s]
  
  return genes.collect{|code| 
    code.nil? || code == "" ? nil : index[code]
  }
end