Module: MADB::GEO

Defined in:
lib/MARQ/MADB.rb

Class Method Summary collapse

Class Method Details

.platform_entries(platform) ⇒ Object



229
230
231
# File 'lib/MARQ/MADB.rb', line 229

def self.platform_entries(platform)
  DBcache.num_rows(platform)
end

.positions(platform, genes) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/MARQ/MADB.rb', line 185

def self.positions(platform, genes)
  return [{},[]] if genes.empty?
  genes = genes.collect{|gene| gene.downcase.strip}

  datasets = Object::GEO.platform_datasets(platform).sort
  platform_entries = platform_entries(platform).to_f

  data = {}
  matched = nil

  datasets.each{|dataset|
    dataset += '_cross_platform' if Object::GEO::is_cross_platform?(platform)
    gene_positions = DBcache.load(dataset, genes)
    matched ||= gene_positions.keys
    
    experiments = DBcache.load(dataset + '_experiments').sort{|a,b| 
      a[0].to_i <=> b[0].to_i
    }.collect{|p| 
      Object::GEO::clean(dataset) + ": " + p[1].first
    }

    scale = (0..experiments.length - 1).collect{|i| 
      rows = DBcache.num_rows(dataset, "C#{i}"); 
      if rows > 0 
        platform_entries / rows 
      else 
        nil 
      end 
    }
    
    gene_x_experiment = gene_positions.values

    experiment_x_gene = gene_x_experiment.transpose

    experiments.each_with_index{|experiment, i|
      next if scale[i].nil? || experiment_x_gene[i].nil?
      values = experiment_x_gene[i].collect{|v| v.nil? ? nil : (v.to_f * scale[i]).to_i}
      data[experiment] = values
    }
  }

  [data, matched]
end

.saveGPL(platform) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/MARQ/MADB.rb', line 119

def self.saveGPL(platform)
  datasets = Object::GEO.platform_datasets(platform).sort
  return if datasets.empty?

  puts "Saving #{ platform }, #{datasets.length} datasets"

  codes = File.open(File.join(Object::GEO.platform_path(platform),'codes')).collect{|l| l.chomp.downcase}
  
  DBcache.save(platform, codes)

  Progress.monitor("Saving #{ platform }")
  datasets.sort.each{|dataset|
    path = Object::GEO.dataset_path(dataset)
    experiments = File.open(path + '.experiments').collect{|l| l.chomp}
    orders = File.open(path + '.orders').collect{|l| values = l.chomp.split(/\t/).collect{|v| v == "NA" ? nil : v.to_i };}

    data = {}
    codes.each_with_index{|code,i|
      data[code.to_sym] = orders[i]
    }
    case 
    when codes.length < 65535
      type = "SMALLINT UNSIGNED"
    when codes.length < 16777215
      type = "MEDIUMINT UNSIGNED"
    else
      type = "INT UNSIGNED"
    end

    DBcache.save(dataset + '_experiments', experiments)
    DBcache.save(dataset, data, [type] * orders.first.length)
  }


  return unless File.exist?(File.join(Object::GEO.platform_path(platform),'cross_platform'))
  codes = File.open(File.join(Object::GEO.platform_path(platform),'cross_platform')).collect{|l| l.chomp.downcase}

  DBcache.save(platform + '_cross_platform', codes)

  Progress.monitor("Saving #{ platform }")
  datasets.sort.each{|dataset|
    path = Object::GEO.dataset_path(dataset)
    next unless File.exists?(path + '_cross_platform.experiments')
    experiments = File.open(path + '_cross_platform.experiments').collect{|l| l.chomp}
    orders = File.open(path + '_cross_platform.orders').collect{|l| values = l.chomp.split(/\t/).collect{|v| v == "NA" ? nil : v.to_i };}

    data = {}
    codes.each_with_index{|code,i|
      data[code.to_sym] = orders[i]
    }

    case 
    when codes.length < 65535
      type = "SMALLINT UNSIGNED"
    when codes.length < 16777215
      type = "MEDIUMIN UNSIGNED"
    else
      type = "INT UNSIGNED"
    end


    DBcache.save(dataset + '_cross_platform_experiments', experiments)
    DBcache.save(dataset + '_cross_platform', data, [type] * orders.first.length)
  }
end