Module: MADB::CustomDS

Defined in:
lib/MARQ/MADB.rb

Class Method Summary collapse

Class Method Details

.platform_entries(platform) ⇒ Object



107
108
109
# File 'lib/MARQ/MADB.rb', line 107

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

.positions(dataset, genes) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/MARQ/MADB.rb', line 65

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

  platform_entries = platform_entries(dataset + '_codes').to_f

  data = {}
  matched = []

  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
  }


  matched = (matched + gene_positions.keys).uniq
  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

.save(dataset) ⇒ Object



8
9
10
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/MARQ/MADB.rb', line 8

def self.save(dataset)
  prefix = Object::CustomDS.path(dataset)

  codes = File.open(prefix  + '.codes').collect{|l| l.chomp.downcase}
  
  DBcache.save(dataset + '_codes', codes)

  experiments = File.open(prefix + '.experiments').collect{|l| l.chomp}
  orders = File.open(prefix + '.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

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

  return unless Object::CustomDS::has_cross_platform?(dataset)
  dataset = dataset + '_cross_platform'
  prefix = Object::CustomDS.path(dataset)

  codes = File.open(prefix  + '.codes').collect{|l| l.chomp.downcase}
  
  DBcache.save(dataset + '_codes', codes)

  experiments = File.open(prefix + '.experiments').collect{|l| l.chomp}
  orders = File.open(prefix + '.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

  puts "Saving #{ dataset }"
  DBcache.save(dataset + '_experiments', experiments)
  DBcache.save(dataset, data, [type] * orders.first.length)
  nil
end