Module: CustomDS

Defined in:
lib/MARQ/CustomDS.rb

Constant Summary collapse

DATA_DIR =
File.join(MARQ.datadir,'CustomDS')
@@r =
nil

Class Method Summary collapse

Class Method Details

.dataset_organism(dataset) ⇒ Object



95
96
97
# File 'lib/MARQ/CustomDS.rb', line 95

def self.dataset_organism(dataset)
  platform_organism(dataset)
end

.dataset_path(dataset) ⇒ Object



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

def self.dataset_path(dataset)

  organisms.each do |organism|
    if File.exists?(File.join(DATA_DIR, organism, dataset + '.orders')) || File.exists?(File.join(DATA_DIR, organism, dataset + '.skip'))
      return File.join(DATA_DIR, organism, dataset)
    end
  end

  return nil
end

.dataset_platform(dataset) ⇒ Object



99
100
101
# File 'lib/MARQ/CustomDS.rb', line 99

def self.dataset_platform(dataset)
  dataset
end

.datasets(org) ⇒ Object



41
42
43
# File 'lib/MARQ/CustomDS.rb', line 41

def self.datasets(org)
  Dir.glob(File.join(DATA_DIR, org) + '/*.orders').collect{|f| clean(File.basename(f.sub(/.orders/,'')))}.uniq
end

.info(dataset) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/MARQ/CustomDS.rb', line 21

def self.info(dataset)
  begin
    text =  Open.read(path(dataset) + '.description')
    if text =~ /(.*)\n--\n(.*)/
      {:title => $1.strip, :description => $2.strip}
    elsif text.collect.length > 1 || text.length > 200
      {:title => "", :description => text}
    else
      {:title => text, :description => ""}
    end
  rescue Exception
    puts $!.message
    {:title => "" , :description => "" }
  end
end

.organism(dataset) ⇒ Object



37
38
39
# File 'lib/MARQ/CustomDS.rb', line 37

def self.organism(dataset)
  path(dataset).match(/#{ DATA_DIR }\/(.*?)\//)[1]
end

.organism_platforms(organism) ⇒ Object



103
104
105
106
# File 'lib/MARQ/CustomDS.rb', line 103

def self.organism_platforms(organism)
  Dir.glob(File.join(DATA_DIR, organism, '*', 'codes')).
    collect {|path| File.basename(File.dirname(path))}.uniq
end

.organismsObject



63
64
65
66
67
# File 'lib/MARQ/CustomDS.rb', line 63

def self.organisms
  Dir.glob(File.join(DATA_DIR, '*')).
    select {|path| File.directory? path}.
    collect {|path| File.basename path}
end

.platform_datasets(platform) ⇒ Object



84
85
86
# File 'lib/MARQ/CustomDS.rb', line 84

def self.platform_datasets(platform)
  MARQ::Name.clean(platform)
end

.platform_organism(platform) ⇒ Object



88
89
90
91
92
93
# File 'lib/MARQ/CustomDS.rb', line 88

def self.platform_organism(platform)
  path = platform_path(platform)
  return nil if path.nil?
  path.match(/#{DATA_DIR}\/(.*)\/#{ platform }$/)
  return $1
end

.platform_path(platform) ⇒ Object



80
81
82
# File 'lib/MARQ/CustomDS.rb', line 80

def self.platform_path(platform)
  Dir.glob(File.join(DATA_DIR, '*', platform)).first
end

.process_dataset(dataset, platform) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/MARQ/CustomDS.rb', line 45

def self.process_dataset(dataset, platform)
  org    = platform_organism(platform)
  platform_path = platform_path(platform)
  prefix = File.join(DATA_DIR, org, MARQ::Name.clean(dataset))
  
  conditions  = Dir.glob(File.join(platform_path, '*')).collect{|f| File.basename(f)} - %w(values codes info description cross_platform)
  description = Open.read(File.join(platform_path, 'description'))
  info        = YAML.load(File.open(File.join(platform_path, 'info')))

  if MARQ::Dataset.is_cross_platform?(dataset)
    r.CustomDS_process(prefix, true, conditions, description, info["two_channel"], !info["log2"])
  else
    r.CustomDS_process(prefix, false, conditions, description, info["two_channel"], !info["log2"])
  end

 
end

.process_platform(platform) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/MARQ/CustomDS.rb', line 108

def self.process_platform(platform)
  prefix = platform_path(platform)
  org    = platform_organism(platform)

  codes = Open.read(File.join(prefix,'codes')).collect{|l| l.chomp}
  cross_platform = ID.translate(org, codes) 

  if cross_platform.length > codes.length / 4
    Open.write(File.join(prefix,'cross_platform'),cross_platform.collect{|c| c || "NO MATCH"}.join("\n"))
  end
end

.rObject



11
12
13
14
15
16
17
18
19
# File 'lib/MARQ/CustomDS.rb', line 11

def self.r
  require 'rsruby'
  if @@r.nil?
    RSRuby.instance.source(MARQ.rootdir + '/R/MA.R')
    RSRuby.instance.source(MARQ.rootdir + '/R/CustomDS.R')
    @@r = RSRuby.instance
  end
  @@r
end