rbbt-dm 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rbbt/matrix/barcode.rb +14 -0
- data/lib/rbbt/matrix/differential.rb +14 -0
- data/lib/rbbt/matrix.rb +104 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 412564d1fb5e11cd74d9d5f5831d3169c3b41bfc
|
4
|
+
data.tar.gz: b8015384a48dd97d9aaacc87f409d4a003b6a25e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c27963bc45ac247de676b90f64748a6c8e6108a27e5c493620156a758db8c0709c9666e3c9d016b273ec754c8063d6636e2887680ce7aef51db8f34ae69112c
|
7
|
+
data.tar.gz: 65da093976bce048ab5572f904e831628178eb01dba43888bdebb7c2f2e9150070905610cebe52a8c59ea1503505d57fe4c4a3d179f358e617a15dde6150f65f
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rbbt/util/R'
|
2
|
+
|
3
|
+
class Matrix
|
4
|
+
def barcode(outfile, factor = 2)
|
5
|
+
|
6
|
+
FileUtils.mkdir_p File.dirname(outfile) unless outfile.nil? or File.exists? File.dirname(outfile)
|
7
|
+
cmd =<<-EOF
|
8
|
+
source('#{Rbbt.share.R['barcode.R'].find}')
|
9
|
+
rbbt.GE.barcode(#{ R.ruby2R self.data_file }, #{ R.ruby2R outfile }, #{ R.ruby2R factor })
|
10
|
+
EOF
|
11
|
+
|
12
|
+
R.run(cmd, :stderr => true)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Matrix
|
2
|
+
def differential(main, contrast, path = nil)
|
3
|
+
if Array === main and Array === contrast
|
4
|
+
main_samples, contrast_samples = main, contrast
|
5
|
+
else
|
6
|
+
main_samples, contrast_samples = comparison main, contrast
|
7
|
+
end
|
8
|
+
|
9
|
+
Persist.persist(data_file, :tsv, :other => {:main => main_samples, :contrast => contrast_samples}, :prefix => "GENE", :dir => Matrix.matrix_dir, :no_load => true, :path => path) do |file|
|
10
|
+
log2 = value_type == "count"
|
11
|
+
GE.analyze(data_file, main_samples, contrast_samples, log2, path, format)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rbbt/matrix.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rbbt-util'
|
2
|
+
require 'rbbt/sources/organism'
|
3
|
+
|
4
|
+
class Matrix
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :matrix_dir
|
8
|
+
def matrix_dir
|
9
|
+
@matrix_dir ||= Rbbt.var.matrices
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :data_file, :labels, :value_type, :format, :organism
|
14
|
+
def initialize(data_file, labels, value_type, format, organism=nil, identifiers=nil)
|
15
|
+
@data_file = data_file
|
16
|
+
@labels = labels
|
17
|
+
@value_type = value_type
|
18
|
+
@format = format
|
19
|
+
@organism = organism
|
20
|
+
@organism ||= begin
|
21
|
+
TSV.parse_header(@data_file).namespace || "Hsa"
|
22
|
+
end
|
23
|
+
@identifiers = identifiers || Organism.identifiers(organism)
|
24
|
+
end
|
25
|
+
|
26
|
+
def samples
|
27
|
+
@samples ||= TSV.parse_header(@data_file).fields
|
28
|
+
end
|
29
|
+
|
30
|
+
def subsets
|
31
|
+
@subsets ||= begin
|
32
|
+
subsets = {}
|
33
|
+
case @labels
|
34
|
+
when TSV
|
35
|
+
factors = @labels.fields
|
36
|
+
@labels.through do |sample,values|
|
37
|
+
factors.zip(values).each do |factor,value|
|
38
|
+
subsets[factor] ||= {}
|
39
|
+
subsets[factor][value] ||= []
|
40
|
+
subsets[factor][value] << sample
|
41
|
+
end
|
42
|
+
end
|
43
|
+
when Hash
|
44
|
+
@labels.each do |factor,info|
|
45
|
+
subsets[factors] ||= []
|
46
|
+
info.each do |value, samples|
|
47
|
+
subsets[factors][value] = case samples
|
48
|
+
when Array
|
49
|
+
samples
|
50
|
+
when String
|
51
|
+
samples.split ','
|
52
|
+
else
|
53
|
+
raise "Format of samples not understood: #{Misc.finguerprint samples}"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
subsets
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def comparison(main, contrast, subsets = nil)
|
64
|
+
|
65
|
+
if main.index "="
|
66
|
+
main_factor, main_value = main.split "="
|
67
|
+
raise ParameterException, "Main selection not understood" if subsets[main_factor].nil? or subsets[main_factor][main_value].nil?
|
68
|
+
main_samples = subsets[main_factor][main_value].split ','
|
69
|
+
else
|
70
|
+
main_samples = main.split(/[|,\n]/)
|
71
|
+
end
|
72
|
+
|
73
|
+
if contrast
|
74
|
+
if contrast.index "="
|
75
|
+
contrast_factor, contrast_value = contrast.split "="
|
76
|
+
raise ParameterException, "Contrast selection not understood" if subsets[contrast_factor].nil? or subsets[contrast_factor][contrast_value].nil?
|
77
|
+
contrast_samples = subsets[contrast_factor][contrast_value].split ','
|
78
|
+
else
|
79
|
+
contrast_samples = contrast.split(/[|,\n]/)
|
80
|
+
end
|
81
|
+
else
|
82
|
+
if subsets and defined? main_factor
|
83
|
+
contrast_samples = subsets[main_factor].values.collect{|s| s.split ',' }.flatten.uniq - main_samples
|
84
|
+
else
|
85
|
+
contrast_samples = samples - main_samples
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
[main_samples, contrast_samples]
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def to_gene(identifiers = nil)
|
94
|
+
require 'rbbt/tsv/change_id'
|
95
|
+
file = Persist.persist(data_file, :tsv, :prefix => "GENE", :dir => Matrix.matrix_dir, :no_load => true) do
|
96
|
+
identifiers = [Organism.identifiers(organism), @identifiers, identifiers].compact.uniq
|
97
|
+
|
98
|
+
data_file.tsv(:cast => :to_f).change_key("Ensembl Gene ID", :identifiers => identifiers) do |v|
|
99
|
+
Misc.mean(v.compact)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
Matrix.new file, labels, value_type, format
|
103
|
+
end
|
104
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-dm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbbt-util
|
@@ -91,6 +91,9 @@ files:
|
|
91
91
|
- lib/rbbt/expression_old/expression.rb
|
92
92
|
- lib/rbbt/expression_old/matrix.rb
|
93
93
|
- lib/rbbt/expression_old/signature.rb
|
94
|
+
- lib/rbbt/matrix.rb
|
95
|
+
- lib/rbbt/matrix/barcode.rb
|
96
|
+
- lib/rbbt/matrix/differential.rb
|
94
97
|
- lib/rbbt/network/paths.rb
|
95
98
|
- lib/rbbt/plots/bar.rb
|
96
99
|
- lib/rbbt/plots/heatmap.rb
|