Module: MADB

Defined in:
lib/MARQ/MADB.rb

Class Method Summary collapse

Class Method Details

.load_positions(dataset, genes) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/MARQ/MADB.rb', line 85

def self.load_positions(dataset, genes)
  positions   = DBcache.load(dataset, genes)
  experiments = 
    DBcache.load(dataset + '_experiments').
      sort_by {|p| p[0].to_i }.
      collect {|p| MARQ::Name.clean(dataset) + ": " + p[1].first }


  
  result = {}; experiments.each {|exp| result[exp] = [] }
  positions.values_at(*genes).each do |values|
    experiments.zip(values || []).each do |p|
      experiment, value = p
      result[experiment] << (value.nil? ? nil : value.to_i)
    end
  end

  result
end

.num_codes(dataset) ⇒ Object



81
82
83
# File 'lib/MARQ/MADB.rb', line 81

def self.num_codes(dataset)
  DBcache.num_rows(dataset + '_codes')
end

.num_values(dataset) ⇒ Object

{{{ Loading Positions



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/MARQ/MADB.rb', line 69

def self.num_values(dataset)
  experiments = 
    DBcache.load(dataset + '_experiments').
      sort_by {|p| p[0].to_i }.
      collect {|p| MARQ::Name.clean(dataset) + ": " + p[1].first }

  values = {}
  experiments.each_with_index do |exp, i| values[exp] = DBcache.num_rows(dataset, "C#{i}") end

  values
end

.save_dataset(dataset) ⇒ Object

Save dataset, all instances, cross_platform if available.



42
43
44
45
46
# File 'lib/MARQ/MADB.rb', line 42

def self.save_dataset(dataset)
  save_dataset_instance(dataset)
  save_dataset_instance(MARQ::Name.cross_platform(dataset)) if MARQ::Dataset.has_cross_platform?(dataset)
  nil
end

.save_dataset_instance(dataset) ⇒ Object

Save the actual data, cross_platform or not



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/MARQ/MADB.rb', line 11

def self.save_dataset_instance(dataset)

  # Get info
  codes        = MARQ::Dataset.codes(dataset);
  experiments  = MARQ::Dataset.experiments(dataset);
  orders       = MARQ::Dataset.orders(dataset).values_at(*experiments).transpose;

  # Save codes and experiments
  DBcache.save(dataset + '_codes', codes)
  DBcache.save(dataset + '_experiments', experiments)

  # Asign orders to codes
  data = {}
  codes.each_with_index{|code,i|
    data[code] = orders[i]
  }

  # Save orders
  case 
  when codes.length < 65535
    type = "SMALLINT UNSIGNED"
  when codes.length < 16777215
    type = "MEDIUMINT UNSIGNED"
  else
    type = "INT UNSIGNED"
  end
  DBcache.save(dataset, data, [type] * orders.first.length)

end

.save_platform(platform) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/MARQ/MADB.rb', line 55

def self.save_platform(platform)
  datasets = MARQ::Platform.datasets(platform).sort
  return if datasets.empty?

  save_platform_instance(platform)
  save_platform_instance(MARQ::Name.cross_platform(platform)) if MARQ::Platform.has_cross_platform?(platform)
  
  datasets.sort.each do |dataset|
    save_dataset(dataset)
  end
end

.save_platform_instance(platform) ⇒ Object



48
49
50
51
52
53
# File 'lib/MARQ/MADB.rb', line 48

def self.save_platform_instance(platform)
  DBcache.save(platform + '_codes', 
               MARQ::Platform.is_cross_platform?(platform) ? 
                 MARQ::Platform.cross_platform(platform) : 
                 MARQ::Platform.codes(platform))
end