Method: TSV.rank_enrichment

Defined in:
lib/rbbt/statistics/random_walk.rb

.rank_enrichment(tsv, list, options = {}) ⇒ Object



576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/rbbt/statistics/random_walk.rb', line 576

def self.rank_enrichment(tsv, list, options = {})
  masked = options[:masked]
  if tsv.fields
    res = TSV.setup({}, :cast => :to_f, :type => :double, :key_field => tsv.key_field, :fields => ["p-value", tsv.fields.first, "Rank"]) 
  else
    res = TSV.setup({}, :cast => :to_f, :type => :double) 
  end

  list = list.clean_annotations if list.respond_to? :clean_annotations
  tsv.with_monitor :desc => "Rank enrichment" do
    tsv.with_unnamed do
      tsv.through do |key, values|
        next if masked and masked.include? key or values.nil?
        values = values.flatten.compact.reject{|v| v.empty?}
        matches = (values.respond_to?(:subset) ? values.subset(list) :  values & list).compact
        next if matches.length < 3
        list.extend OrderedList unless OrderedList === list
        total = list.length
        hits = list.hits(values).collect{|p| p.to_f / total}
        pvalue = rank_enrichment_for_list(list, values, options)
        res[key] = [pvalue, matches, hits]
      end
    end
  end

  FDR.adjust_hash! res, 0 if options[:fdr]

  res
end