rbbt-dm 1.1.25 → 1.1.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/statistics/random_walk.rb +36 -42
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e5b27776c034b4c967220236bfccd5755449a22
|
4
|
+
data.tar.gz: 2a302c7c957ba414c11bd9741c958c1214bf137c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 017abb949fb6b639922267d2444e9ba6890e82c9609ef91ead6765af9bc026bfa8737d9bb4635dbcb1de3d011e37a80056dccf17ce75c076e6ef971d95d107e8
|
7
|
+
data.tar.gz: 974b43b88f3969ededb3c4a4dfb8a4e2c2443b52db480798303b27ff692a21949a9433c19e8595e0922e16a79be3888d0ec010c46b0d67f506488d3245758043
|
@@ -221,6 +221,7 @@ module RandomWalk
|
|
221
221
|
end
|
222
222
|
|
223
223
|
set_scoring :score_fitted_weight
|
224
|
+
#set_scoring :score_plain_weight
|
224
225
|
|
225
226
|
|
226
227
|
def self.combine(up, down)
|
@@ -294,7 +295,7 @@ module RandomWalk
|
|
294
295
|
|
295
296
|
def self.persisted_permutations(size, total, missing = 0, times = 10_000)
|
296
297
|
require 'rbbt/util/tc_cache'
|
297
|
-
repo_file = "/tmp/
|
298
|
+
repo_file = "/tmp/rw_repo9_" << scoring_method.to_s
|
298
299
|
key = Misc.digest([size, total, missing, times, scoring_method].inspect)
|
299
300
|
cache = TCCache.open(repo_file, :float_array)
|
300
301
|
p = cache.cache(key) do
|
@@ -305,7 +306,7 @@ module RandomWalk
|
|
305
306
|
|
306
307
|
def self.persisted_permutations_up_down(up_size, down_size, total, missing = 0, times = 10_000)
|
307
308
|
require 'rbbt/util/tc_cache'
|
308
|
-
repo_file = "/tmp/
|
309
|
+
repo_file = "/tmp/rw_repo9_" << scoring_method.to_s
|
309
310
|
key = Misc.digest([up_size, down_size, total, missing, times, scoring_method].inspect)
|
310
311
|
cache = TCCache.open(repo_file, :float_array)
|
311
312
|
p = cache.cache(key) do
|
@@ -318,10 +319,12 @@ module RandomWalk
|
|
318
319
|
def self.pvalue(permutations, score)
|
319
320
|
positive = score > 0
|
320
321
|
score = score.abs
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
322
|
+
|
323
|
+
count = permutations.select{|per| per.abs >= score.abs }.length
|
324
|
+
|
325
|
+
pvalue = (0.0 + count) / (permutations.length)
|
326
|
+
|
327
|
+
pvalue = 1.0/permutations.length if pvalue == 0.0
|
325
328
|
|
326
329
|
positive ? pvalue : - pvalue
|
327
330
|
end
|
@@ -423,15 +426,6 @@ module OrderedList
|
|
423
426
|
OrderedList.draw_hits(self, set, filename, options)
|
424
427
|
end
|
425
428
|
|
426
|
-
#def pvalue(set, options = {})
|
427
|
-
# set = Set.new(set.compact) unless Set === set
|
428
|
-
# options = Misc.add_defaults options, :permutations => 10000, :missing => 0
|
429
|
-
# hits = hits(set)
|
430
|
-
# score = RandomWalk.score(hits.sort, self.length, 0)
|
431
|
-
# permutations = RandomWalk.permutations(set.length, self.length, options[:missing], options[:permutations])
|
432
|
-
# RandomWalk.pvalue(permutations, score)
|
433
|
-
#end
|
434
|
-
|
435
429
|
def pvalue(set, cutoff = 0.1, options = {})
|
436
430
|
set = Set.new(set.compact) unless Set === set
|
437
431
|
options = Misc.add_defaults options, :permutations => 10000, :missing => 0
|
@@ -439,12 +433,13 @@ module OrderedList
|
|
439
433
|
|
440
434
|
hits = hits(set)
|
441
435
|
|
442
|
-
return 1.0 if hits.
|
436
|
+
return 1.0 if hits.length < 3
|
443
437
|
|
444
438
|
target_score = RandomWalk.score(hits.sort, self.length, missing)
|
439
|
+
total = self.length
|
445
440
|
|
446
|
-
if persist_permutations
|
447
|
-
permutations = RandomWalk.persisted_permutations(
|
441
|
+
if persist_permutations
|
442
|
+
permutations = RandomWalk.persisted_permutations(hits.length, self.length, missing, permutations)
|
448
443
|
RandomWalk.pvalue(permutations, target_score)
|
449
444
|
else
|
450
445
|
# P-value computation
|
@@ -452,27 +447,23 @@ module OrderedList
|
|
452
447
|
|
453
448
|
max = (permutations.to_f * cutoff).ceil
|
454
449
|
|
455
|
-
size =
|
450
|
+
size = hits.length
|
456
451
|
total = self.length
|
457
452
|
better_permutation_score_count = 1
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
(1..permutations).each do
|
462
|
-
p= []
|
463
|
-
RandomWalk.sample_without_replacement(total, size, p)
|
464
|
-
|
465
|
-
permutation_score = RandomWalk.score(p.sort, total, missing).abs
|
466
|
-
if permutation_score.abs > target_score_abs
|
467
|
-
better_permutation_score_count += 1
|
468
|
-
end
|
453
|
+
(1..permutations).each do
|
454
|
+
p= []
|
455
|
+
RandomWalk.sample_without_replacement(total, size, p)
|
469
456
|
|
470
|
-
|
457
|
+
permutation_score = RandomWalk.score(p.sort, total, missing).abs
|
458
|
+
if permutation_score.abs > target_score_abs
|
459
|
+
better_permutation_score_count += 1
|
471
460
|
end
|
472
|
-
|
473
|
-
|
474
|
-
p
|
461
|
+
|
462
|
+
return 1.0 if better_permutation_score_count > max
|
475
463
|
end
|
464
|
+
p = (better_permutation_score_count.to_f + 1) / permutations
|
465
|
+
p = -p if target_score < 0
|
466
|
+
p
|
476
467
|
end
|
477
468
|
end
|
478
469
|
|
@@ -486,12 +477,12 @@ module OrderedList
|
|
486
477
|
up_hits = hits(up_set)
|
487
478
|
down_hits = hits(down_set)
|
488
479
|
|
489
|
-
return 1.0 if up_hits.
|
480
|
+
return 1.0 if up_hits.length + down_hits.length < 3
|
490
481
|
|
491
482
|
target_score = RandomWalk.score_up_down(up_hits.sort, down_hits.sort, self.length, missing)
|
492
483
|
|
493
484
|
if persist_permutations
|
494
|
-
permutations = RandomWalk.persisted_permutations_up_down(
|
485
|
+
permutations = RandomWalk.persisted_permutations_up_down(up_hits.length, down_hits.length, self.length, missing, permutations)
|
495
486
|
RandomWalk.pvalue(permutations, target_score)
|
496
487
|
else
|
497
488
|
# P-value computation
|
@@ -539,7 +530,7 @@ module OrderedList
|
|
539
530
|
|
540
531
|
hits = hits(set)
|
541
532
|
|
542
|
-
return 1.0 if hits.
|
533
|
+
return 1.0 if hits.length < 3
|
543
534
|
|
544
535
|
target_score = RandomWalk.score_weights(hits.sort, @weights, @total_weights, self.length, 0)
|
545
536
|
target_score_abs = target_score.abs
|
@@ -557,7 +548,7 @@ module OrderedList
|
|
557
548
|
RandomWalk.sample_without_replacement(total, size, p)
|
558
549
|
|
559
550
|
permutation_score = RandomWalk.score_weights(p.sort, @weights, @total_weights, total, missing).abs
|
560
|
-
if permutation_score.abs
|
551
|
+
if permutation_score.abs >= target_score_abs
|
561
552
|
better_permutation_score_count += 1
|
562
553
|
end
|
563
554
|
|
@@ -574,7 +565,7 @@ module TSV
|
|
574
565
|
|
575
566
|
def self.rank_enrichment_for_list(list, hits, options = {})
|
576
567
|
cutoff = options[:cutoff]
|
577
|
-
list.extend OrderedList
|
568
|
+
list.extend OrderedList unless OrderedList === list
|
578
569
|
if cutoff
|
579
570
|
list.pvalue(hits, cutoff, options)
|
580
571
|
else
|
@@ -585,7 +576,7 @@ module TSV
|
|
585
576
|
def self.rank_enrichment(tsv, list, options = {})
|
586
577
|
masked = options[:masked]
|
587
578
|
if tsv.fields
|
588
|
-
res = TSV.setup({}, :cast => :to_f, :type => :double, :key_field => tsv.key_field, :fields => ["p-value", tsv.fields.first])
|
579
|
+
res = TSV.setup({}, :cast => :to_f, :type => :double, :key_field => tsv.key_field, :fields => ["p-value", tsv.fields.first, "Hits"])
|
589
580
|
else
|
590
581
|
res = TSV.setup({}, :cast => :to_f, :type => :double)
|
591
582
|
end
|
@@ -597,9 +588,12 @@ module TSV
|
|
597
588
|
next if masked and masked.include? key
|
598
589
|
values = values.flatten.compact.reject{|v| v.empty?}
|
599
590
|
matches = (values.respond_to?(:subset) ? values.subset(list) : values & list).compact
|
600
|
-
next if matches.length <
|
591
|
+
next if matches.length < 3
|
592
|
+
list.extend OrderedList unless OrderedList === list
|
593
|
+
total = list.length
|
594
|
+
hits = list.hits(values).collect{|p| p.to_f / total}
|
601
595
|
pvalue = rank_enrichment_for_list(list, values, options)
|
602
|
-
res[key] = [pvalue, matches]
|
596
|
+
res[key] = [pvalue, matches, hits]
|
603
597
|
end
|
604
598
|
end
|
605
599
|
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.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbbt-util
|