rbbt-util 5.14.33 → 5.14.34
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/bin/rbbt +2 -0
 - data/lib/rbbt/association/database.rb +153 -0
 - data/lib/rbbt/association/index.rb +89 -20
 - data/lib/rbbt/association/open.rb +37 -0
 - data/lib/rbbt/association/util.rb +133 -0
 - data/lib/rbbt/association.rb +1 -380
 - data/lib/rbbt/entity/identifiers.rb +106 -0
 - data/lib/rbbt/entity.rb +1 -0
 - data/lib/rbbt/knowledge_base/entity.rb +107 -0
 - data/lib/rbbt/knowledge_base/query.rb +83 -0
 - data/lib/rbbt/knowledge_base/registry.rb +106 -0
 - data/lib/rbbt/knowledge_base/syndicate.rb +22 -0
 - data/lib/rbbt/knowledge_base.rb +6 -359
 - data/lib/rbbt/tsv/accessor.rb +4 -0
 - data/lib/rbbt/tsv/change_id.rb +119 -0
 - data/lib/rbbt/tsv/index.rb +6 -2
 - data/lib/rbbt/tsv/parser.rb +7 -5
 - data/lib/rbbt/tsv/util.rb +1 -1
 - data/lib/rbbt/tsv.rb +2 -1
 - data/lib/rbbt/util/R/model.rb +1 -1
 - data/lib/rbbt/util/log.rb +2 -2
 - data/lib/rbbt/util/misc/bgzf.rb +2 -0
 - data/lib/rbbt/util/misc/inspect.rb +1 -1
 - data/lib/rbbt-util.rb +11 -7
 - data/lib/rbbt.rb +0 -1
 - data/share/rbbt_commands/app/start +1 -1
 - data/share/rbbt_commands/tsv/change_id +2 -2
 - data/test/rbbt/association/test_database.rb +61 -0
 - data/test/rbbt/association/test_index.rb +67 -22
 - data/test/rbbt/association/test_open.rb +68 -0
 - data/test/rbbt/association/test_util.rb +108 -0
 - data/test/rbbt/entity/test_identifiers.rb +40 -0
 - data/test/rbbt/knowledge_base/test_entity.rb +0 -0
 - data/test/rbbt/knowledge_base/test_query.rb +45 -0
 - data/test/rbbt/knowledge_base/test_registry.rb +52 -0
 - data/test/rbbt/test_association.rb +3 -3
 - data/test/rbbt/test_knowledge_base.rb +79 -51
 - data/test/rbbt/test_monitor.rb +0 -2
 - data/test/rbbt/test_packed_index.rb +1 -1
 - data/test/rbbt/test_resource.rb +6 -6
 - data/test/rbbt/test_tsv.rb +34 -44
 - data/test/rbbt/tsv/parallel/test_through.rb +2 -4
 - data/test/rbbt/tsv/parallel/test_traverse.rb +30 -28
 - data/test/rbbt/tsv/test_change_id.rb +10 -0
 - data/test/rbbt/util/R/test_model.rb +9 -10
 - data/test/rbbt/util/test_misc.rb +1 -1
 - data/test/test_helper.rb +4 -1
 - metadata +24 -2
 
    
        data/lib/rbbt/tsv/util.rb
    CHANGED
    
    | 
         @@ -171,7 +171,7 @@ module TSV 
     | 
|
| 
       171 
171 
     | 
    
         
             
                str = "" 
         
     | 
| 
       172 
172 
     | 
    
         
             
                str << preamble.strip << "\n" if preamble and not preamble.empty?
         
     | 
| 
       173 
173 
     | 
    
         
             
                if fields
         
     | 
| 
       174 
     | 
    
         
            -
                  str << "#" << (key_field || "ID") << sep << fields * sep << "\n"
         
     | 
| 
      
 174 
     | 
    
         
            +
                  str << "#" << (key_field || "ID").to_s << sep << (fields * sep) << "\n" 
         
     | 
| 
       175 
175 
     | 
    
         
             
                end
         
     | 
| 
       176 
176 
     | 
    
         | 
| 
       177 
177 
     | 
    
         
             
                str
         
     | 
    
        data/lib/rbbt/tsv.rb
    CHANGED
    
    | 
         @@ -124,7 +124,8 @@ module TSV 
     | 
|
| 
       124 
124 
     | 
    
         | 
| 
       125 
125 
     | 
    
         
             
              def self.parse(stream, data, options = {})
         
     | 
| 
       126 
126 
     | 
    
         | 
| 
       127 
     | 
    
         
            -
                parser =  
     | 
| 
      
 127 
     | 
    
         
            +
                parser = Misc.process_options options, :parser
         
     | 
| 
      
 128 
     | 
    
         
            +
                parser = TSV::Parser.new stream, options if parser.nil?
         
     | 
| 
       128 
129 
     | 
    
         | 
| 
       129 
130 
     | 
    
         
             
                # dump with tchmgr
         
     | 
| 
       130 
131 
     | 
    
         
             
                if defined? TokyoCabinet and TokyoCabinet::HDB === data and parser.straight and
         
     | 
    
        data/lib/rbbt/util/R/model.rb
    CHANGED
    
    
    
        data/lib/rbbt/util/log.rb
    CHANGED
    
    | 
         @@ -235,8 +235,8 @@ module Log 
     | 
|
| 
       235 
235 
     | 
    
         | 
| 
       236 
236 
     | 
    
         
             
              def self.tsv(tsv)
         
     | 
| 
       237 
237 
     | 
    
         
             
                STDERR.puts Log.color :magenta, "TSV log: " << Log.last_caller(caller)
         
     | 
| 
       238 
     | 
    
         
            -
                 
     | 
| 
       239 
     | 
    
         
            -
                 
     | 
| 
      
 238 
     | 
    
         
            +
                puts Log.color(:blue, "=> "<< Misc.fingerprint(tsv), true) 
         
     | 
| 
      
 239 
     | 
    
         
            +
                puts Log.color(:cyan, "=> " << tsv.summary)
         
     | 
| 
       240 
240 
     | 
    
         
             
              end
         
     | 
| 
       241 
241 
     | 
    
         | 
| 
       242 
242 
     | 
    
         
             
              def self.stack(stack)
         
     | 
    
        data/lib/rbbt/util/misc/bgzf.rb
    CHANGED
    
    
| 
         @@ -161,7 +161,7 @@ module Misc 
     | 
|
| 
       161 
161 
     | 
    
         | 
| 
       162 
162 
     | 
    
         
             
                  end
         
     | 
| 
       163 
163 
     | 
    
         | 
| 
       164 
     | 
    
         
            -
                  str << "_" << hash2md5(v.info) if defined? Annotated and Annotated === v and not AssociationItem === v
         
     | 
| 
      
 164 
     | 
    
         
            +
                  str << "_" << hash2md5(v.info) if defined? Annotated and Annotated === v and not (defined? AssociationItem and AssociationItem === v)
         
     | 
| 
       165 
165 
     | 
    
         
             
                end
         
     | 
| 
       166 
166 
     | 
    
         
             
                hash.unnamed = unnamed if hash.respond_to? :unnamed
         
     | 
| 
       167 
167 
     | 
    
         | 
    
        data/lib/rbbt-util.rb
    CHANGED
    
    | 
         @@ -1,13 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'rbbt'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rbbt/util/misc'
         
     | 
| 
       2 
3 
     | 
    
         
             
            require 'rbbt/util/open'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            require 'rbbt/util/filecache'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'rbbt/tsv'
         
     | 
| 
      
 4 
     | 
    
         
            +
            Open.cachedir        = Rbbt.var.cache["open-remote"].find :user
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       7 
6 
     | 
    
         
             
            require 'rbbt/persist'
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            Persist.cachedir = Rbbt.var.cache.persistence
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
            require 'rbbt/util/filecache'
         
     | 
| 
       10 
10 
     | 
    
         
             
            FileCache.cachedir   = Rbbt.var.cache.filecache.find :user
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            require 'rbbt/util/tmpfile'
         
     | 
| 
       12 
13 
     | 
    
         
             
            TmpFile.tmpdir       = Rbbt.tmp.find :user
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            require 'rbbt/util/cmd'
         
     | 
| 
      
 16 
     | 
    
         
            +
            require 'rbbt/tsv'
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
    
        data/lib/rbbt.rb
    CHANGED
    
    
| 
         @@ -3,7 +3,7 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'rbbt-util'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'rbbt/util/simpleopt'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            options = SOPT.get "-e--environment*:-p--port*:-s--server*:-f--finder 
     | 
| 
      
 6 
     | 
    
         
            +
            options = SOPT.get "-e--environment*:-p--port*:-s--server*:-f--finder:-R--Rserve_session*"
         
     | 
| 
       7 
7 
     | 
    
         
             
            options[:Port] ||= options[:port]
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         | 
| 
         @@ -11,7 +11,7 @@ $ rbbt command command [options] -f file 
     | 
|
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
            Use - to read from STDIN. The `field` is the tsv column to change.
         
     | 
| 
       13 
13 
     | 
    
         
             
            the `target` is the target format, as appearing in the `identifiers`
         
     | 
| 
       14 
     | 
    
         
            -
            file or in `Organism.identifiers("Hsa")`.
         
     | 
| 
      
 14 
     | 
    
         
            +
            file or in `Organism.identifiers(Organism.default_code("Hsa"))`.
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            -f--file* File to process
         
     | 
| 
       17 
17 
     | 
    
         
             
            -f--field* Field to change
         
     | 
| 
         @@ -26,7 +26,7 @@ SOPT.require options, :file, :field, :target 
     | 
|
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
            require 'rbbt/sources/organism'
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
            identifiers = options[:identifiers] || Organism.identifiers("Hsa").find
         
     | 
| 
      
 29 
     | 
    
         
            +
            identifiers = options[:identifiers] || Organism.identifiers(Organism.default_code("Hsa")).find
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
            begin
         
     | 
| 
       32 
32 
     | 
    
         
             
              index = TSV.index(identifiers, :persist => true, :target => target, :merge => true)
         
     | 
| 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rbbt-util'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rbbt/association'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rbbt/association'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rbbt/association/database'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class TestAssociationDatabase < Test::Unit::TestCase
         
     | 
| 
      
 8 
     | 
    
         
            +
               
         
     | 
| 
      
 9 
     | 
    
         
            +
              EFFECT =<<-END
         
     | 
| 
      
 10 
     | 
    
         
            +
            #: :sep=" "#:type=:double
         
     | 
| 
      
 11 
     | 
    
         
            +
            #SG TG Effect directed?
         
     | 
| 
      
 12 
     | 
    
         
            +
            MDM2 TP53 inhibition false
         
     | 
| 
      
 13 
     | 
    
         
            +
            TP53 NFKB1|GLI1 activation|activation true|true
         
     | 
| 
      
 14 
     | 
    
         
            +
              END
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              EFFECT_OPTIONS = {
         
     | 
| 
      
 17 
     | 
    
         
            +
                :source => "SG=~Associated Gene Name",
         
     | 
| 
      
 18 
     | 
    
         
            +
                :target => "TG=~Associated Gene Name=>Ensembl Gene ID",
         
     | 
| 
      
 19 
     | 
    
         
            +
                :persist => false,
         
     | 
| 
      
 20 
     | 
    
         
            +
                :identifiers => datafile_test('identifiers'),
         
     | 
| 
      
 21 
     | 
    
         
            +
              }
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              EFFECT_TSV = TSV.open EFFECT, EFFECT_OPTIONS.dup
         
     | 
| 
      
 24 
     | 
    
         
            +
              def test_tsv
         
     | 
| 
      
 25 
     | 
    
         
            +
                assert_equal %w(NFKB1 GLI1), EFFECT_TSV["TP53"]["TG"]
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              EFFECT_DATABASE = Association.database(EFFECT_TSV, EFFECT_OPTIONS.dup)
         
     | 
| 
      
 29 
     | 
    
         
            +
              
         
     | 
| 
      
 30 
     | 
    
         
            +
              def test_open_new_tsv
         
     | 
| 
      
 31 
     | 
    
         
            +
                tsv = Association.database EFFECT_TSV, :fields => ["Effect"], :target => "TG=~Associated Gene Name=>Ensembl Gene ID"
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert_equal ["Ensembl Gene ID", "Effect"], tsv.fields
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal "SG", tsv.key_field
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert tsv.include? "MDM2"
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              def test_open_new_tsv_reverse
         
     | 
| 
      
 38 
     | 
    
         
            +
                tsv = Association.database EFFECT_TSV, :fields => ["Effect"], :target => "SG=~Associated Gene Name=>Ensembl Gene ID", :zipped => true
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert_equal ["Ensembl Gene ID", "Effect"], tsv.fields
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal "TG", tsv.key_field
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert tsv.include? "NFKB1"
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              def test_database_translate
         
     | 
| 
      
 45 
     | 
    
         
            +
                database = Association.database(EFFECT_TSV, EFFECT_OPTIONS.merge({:source => "SG=~Associated Gene Name=>Ensembl Gene ID", :target => "TG"}))
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_equal %w(inhibition), database["ENSG00000135679"]["Effect"]
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert_equal %w(activation activation), database["ENSG00000141510"]["Effect"]
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              def test_database
         
     | 
| 
      
 51 
     | 
    
         
            +
                assert_equal %w(inhibition), EFFECT_DATABASE["MDM2"]["Effect"]
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_equal %w(activation activation), EFFECT_DATABASE["TP53"]["Effect"]
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
              def test_index_list
         
     | 
| 
      
 56 
     | 
    
         
            +
                file = datafile_test('gene_ages')
         
     | 
| 
      
 57 
     | 
    
         
            +
                tsv = Association.database(file)
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal [["Bilateria"], ["Euteleostomi"], ["Duplicate"]], tsv["ENSG00000000003"]
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,37 +1,82 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
         
     | 
| 
       2 
     | 
    
         
            -
            require 'rbbt/ 
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rbbt/util/misc'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'rbbt/association'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'rbbt/association/index'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            #Workflow.require_workflow "Genomics"
         
     | 
| 
       7 
     | 
    
         
            -
            #require 'rbbt/entity/gene'
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
6 
     | 
    
         
             
            class TestAssociationIndex < Test::Unit::TestCase
         
     | 
| 
      
 7 
     | 
    
         
            +
               
         
     | 
| 
      
 8 
     | 
    
         
            +
              EFFECT =<<-END
         
     | 
| 
      
 9 
     | 
    
         
            +
            #: :sep=" "#:type=:double
         
     | 
| 
      
 10 
     | 
    
         
            +
            #SG TG Effect directed?
         
     | 
| 
      
 11 
     | 
    
         
            +
            MDM2 TP53 inhibition false
         
     | 
| 
      
 12 
     | 
    
         
            +
            TP53 NFKB1|GLI1 activation|activation true|true
         
     | 
| 
      
 13 
     | 
    
         
            +
              END
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              EFFECT_OPTIONS = {
         
     | 
| 
      
 16 
     | 
    
         
            +
                :source => "SG=~Associated Gene Name",
         
     | 
| 
      
 17 
     | 
    
         
            +
                :target => "TG=~Associated Gene Name=>Ensembl Gene ID",
         
     | 
| 
      
 18 
     | 
    
         
            +
                :persist => false,
         
     | 
| 
      
 19 
     | 
    
         
            +
                :identifiers => datafile_test('identifiers'),
         
     | 
| 
      
 20 
     | 
    
         
            +
                :namespace => "Hsa"
         
     | 
| 
      
 21 
     | 
    
         
            +
              }
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              EFFECT_TSV = TSV.open EFFECT, EFFECT_OPTIONS.dup
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def test_index_no_persist_string
         
     | 
| 
      
 26 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:source => "TG", :target => "SG=~Associated Gene Name"), :persist => false)
         
     | 
| 
      
 27 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal "inhibition", tsv["TP53~MDM2"]["Effect"]
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              def test_index_no_persist_string_undirected
         
     | 
| 
      
 32 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:undirected => true, :source => "TG", :target => "SG=~Associated Gene Name"), :persist => false)
         
     | 
| 
      
 33 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_equal "inhibition", tsv["TP53~MDM2"]["Effect"]
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
       10 
36 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
              def  
     | 
| 
      
 37 
     | 
    
         
            +
              def test_index_persist_string
         
     | 
| 
      
 38 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:source => "SG", :target => "TG=~Associated Gene Name"), :persist => true, :update => true)
         
     | 
| 
      
 39 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal "inhibition", tsv["MDM2~TP53"]["Effect"]
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal %w(TP53~NFKB1 TP53~GLI1).sort, tsv.match("TP53").sort
         
     | 
| 
       12 
42 
     | 
    
         
             
              end
         
     | 
| 
       13 
43 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              def  
     | 
| 
      
 44 
     | 
    
         
            +
              def test_index_persist_reverse
         
     | 
| 
      
 45 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:source => "TG", :target => "SG=~Associated Gene Name"), :persist => true, :update => true).reverse
         
     | 
| 
      
 46 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert_equal "inhibition", tsv["MDM2~TP53"]["Effect"]
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal %w(MDM2~TP53), tsv.match("MDM2")
         
     | 
| 
       15 
49 
     | 
    
         
             
              end
         
     | 
| 
       16 
50 
     | 
    
         | 
| 
      
 51 
     | 
    
         
            +
              def test_index_persist_undirected
         
     | 
| 
      
 52 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:undirected => true, :source => "TG=~Associated Gene Name", :target => "SG=~Associated Gene Name"), :persist => true)
         
     | 
| 
      
 53 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 54 
     | 
    
         
            +
                assert_equal "inhibition", tsv["MDM2~TP53"]["Effect"]
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert_equal "inhibition", tsv["TP53~MDM2"]["Effect"]
         
     | 
| 
      
 56 
     | 
    
         
            +
                assert_equal %w(MDM2~TP53), tsv.match("MDM2")
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
       17 
58 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
              def  
     | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
       20 
     | 
    
         
            -
                 
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                                            :undirected => true}, 
         
     | 
| 
       27 
     | 
    
         
            -
                                            {:dir => '/tmp/test_association3', :update => false})
         
     | 
| 
       28 
     | 
    
         
            -
                genes = tp53.pina_interactors.ensembl
         
     | 
| 
       29 
     | 
    
         
            -
                genes << tp53
         
     | 
| 
      
 59 
     | 
    
         
            +
              def test_index_persist_directed_subset
         
     | 
| 
      
 60 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:undirected => true, :source => "TG=~Associated Gene Name", :target => "SG=~Associated Gene Name"), :persist => true)
         
     | 
| 
      
 61 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 62 
     | 
    
         
            +
                assert_equal %w(TP53~GLI1 TP53~MDM2).sort, tsv.subset(["TP53"], ["GLI1","MDM2"]).sort
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert_equal %w(MDM2~TP53).sort, tsv.subset(["MDM2"], :all).sort
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert_equal %w(GLI1~TP53).sort, tsv.subset(["GLI1"], :all).sort
         
     | 
| 
      
 65 
     | 
    
         
            +
                assert_equal %w(TP53~GLI1).sort, tsv.subset(:all, ["GLI1"]).sort
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
       30 
67 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
      
 68 
     | 
    
         
            +
              def test_index_persist_undirected_subset
         
     | 
| 
      
 69 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:undirected => false, :source => "SG=~Associated Gene Name", :target => "TG=~Associated Gene Name"), :persist => true)
         
     | 
| 
      
 70 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 71 
     | 
    
         
            +
                assert_equal %w(TP53~GLI1 TP53~NFKB1).sort, tsv.subset(["TP53"], ["GLI1","MDM2", "NFKB1"]).sort
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
       34 
73 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 74 
     | 
    
         
            +
              def test_index_flat
         
     | 
| 
      
 75 
     | 
    
         
            +
                require 'rbbt/sources/tfacts'
         
     | 
| 
      
 76 
     | 
    
         
            +
                file = TFacts.regulators
         
     | 
| 
      
 77 
     | 
    
         
            +
                tsv = Association.index(file,  :type => :flat, :source => "Transcription Factor Associated Gene Name=~Associated Gene Name", :merge => true)
         
     | 
| 
      
 78 
     | 
    
         
            +
                assert tsv.match("TP53").length > 10
         
     | 
| 
       36 
79 
     | 
    
         
             
              end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
       37 
82 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,68 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rbbt/util/misc'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rbbt/association'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rbbt/association/open'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class TestAssociationOpen < Test::Unit::TestCase
         
     | 
| 
      
 7 
     | 
    
         
            +
               
         
     | 
| 
      
 8 
     | 
    
         
            +
              EFFECT =<<-END
         
     | 
| 
      
 9 
     | 
    
         
            +
            #: :sep=" "#:type=:double
         
     | 
| 
      
 10 
     | 
    
         
            +
            #SG TG Effect directed?
         
     | 
| 
      
 11 
     | 
    
         
            +
            MDM2 TP53 inhibition false
         
     | 
| 
      
 12 
     | 
    
         
            +
            TP53 NFKB1|GLI1 activation|activation true|true
         
     | 
| 
      
 13 
     | 
    
         
            +
              END
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              EFFECT_OPTIONS = {
         
     | 
| 
      
 16 
     | 
    
         
            +
                :source => "SG=~Associated Gene Name",
         
     | 
| 
      
 17 
     | 
    
         
            +
                :target => "TG=~Associated Gene Name=>Ensembl Gene ID",
         
     | 
| 
      
 18 
     | 
    
         
            +
                :persist => false,
         
     | 
| 
      
 19 
     | 
    
         
            +
                :identifiers => datafile_test('identifiers'),
         
     | 
| 
      
 20 
     | 
    
         
            +
                :namespace => "Hsa"
         
     | 
| 
      
 21 
     | 
    
         
            +
              }
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              EFFECT_TSV = TSV.open EFFECT, EFFECT_OPTIONS.dup
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def test_open_no_persist
         
     | 
| 
      
 26 
     | 
    
         
            +
                tsv = Association.open(EFFECT_TSV, EFFECT_OPTIONS, :persist => false)
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert_equal "ENSG00000141510", tsv["MDM2"]["Ensembl Gene ID"].first
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal ["false"], tsv["MDM2"]["directed?"]
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              def test_open_no_persist_undirected
         
     | 
| 
      
 32 
     | 
    
         
            +
                tsv = Association.open(EFFECT_TSV, :source => "SG=~Gene", :target => "TG=~Gene", :undirected => true, :persist => false)
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal "TP53", tsv["MDM2"]["Gene"].first
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert tsv["TP53"]["Gene"].include? "MDM2"
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              def test_open_persist
         
     | 
| 
      
 38 
     | 
    
         
            +
                tsv = Association.open(EFFECT_TSV, EFFECT_OPTIONS, :persist => true, :update => true)
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert_equal "ENSG00000141510", tsv["MDM2"]["Ensembl Gene ID"].first
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal ["false"], tsv["MDM2"]["directed?"]
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              def test_open_no_persist_string
         
     | 
| 
      
 44 
     | 
    
         
            +
                tsv = Association.open(EFFECT, EFFECT_OPTIONS.merge(:source => "TG", :target => "SG=~Associated Gene Name"), :persist => false)
         
     | 
| 
      
 45 
     | 
    
         
            +
                tsv.include? "TP53"
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_equal ["MDM2"], tsv["TP53"]["Associated Gene Name"]
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
              def test_index_no_persist_string
         
     | 
| 
      
 50 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:source => "TG", :target => "SG=~Associated Gene Name"), :persist => false)
         
     | 
| 
      
 51 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_equal "inhibition", tsv["TP53~MDM2"]["Effect"]
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
              def test_index_persist_string
         
     | 
| 
      
 56 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:source => "SG", :target => "TG=~Associated Gene Name"), :persist => true)
         
     | 
| 
      
 57 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal "inhibition", tsv["MDM2~TP53"]["Effect"]
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert_equal %w(TP53~GLI1 TP53~NFKB1), tsv.match("TP53").sort
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              def test_index_persist_reverse
         
     | 
| 
      
 63 
     | 
    
         
            +
                tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:source => "TG", :target => "SG=~Associated Gene Name"), :persist => true).reverse
         
     | 
| 
      
 64 
     | 
    
         
            +
                tsv.unnamed = false
         
     | 
| 
      
 65 
     | 
    
         
            +
                assert_equal "inhibition", tsv["MDM2~TP53"]["Effect"]
         
     | 
| 
      
 66 
     | 
    
         
            +
                assert_equal %w(MDM2~TP53), tsv.match("MDM2")
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,108 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rbbt/util/misc'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rbbt/association'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rbbt/association'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rbbt/association/util'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class TestAssociationUtil < Test::Unit::TestCase
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              def test_specs
         
     | 
| 
      
 10 
     | 
    
         
            +
                spec = Association.parse_field_specification "=~Associated Gene Name=>Ensembl Gene ID"
         
     | 
| 
      
 11 
     | 
    
         
            +
                assert_equal [nil, "Associated Gene Name", "Ensembl Gene ID"], spec
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                spec = Association.parse_field_specification "TG=~Associated Gene Name=>Ensembl Gene ID"
         
     | 
| 
      
 14 
     | 
    
         
            +
                assert_equal ["TG", "Associated Gene Name", "Ensembl Gene ID"], spec
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                spec = Association.parse_field_specification "TG=~Associated Gene Name"
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_equal ["TG", "Associated Gene Name", nil], spec
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                spec = Association.parse_field_specification "Associated Gene Name=>Ensembl Gene ID"
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal ["Associated Gene Name", nil, "Ensembl Gene ID"], spec
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              def test_normalize_specs
         
     | 
| 
      
 24 
     | 
    
         
            +
                spec = Association.normalize_specs "TG=~Associated Gene Name=>Ensembl Gene ID", %w(SG TG Effect directed?)
         
     | 
| 
      
 25 
     | 
    
         
            +
                assert_equal ["TG", "Associated Gene Name", "Ensembl Gene ID"], spec
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                spec = Association.normalize_specs "Ensembl Gene ID", %w(SG TG Effect directed?)
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal ["Ensembl Gene ID", nil, nil], spec
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                spec = Association.normalize_specs "Ensembl Gene ID"
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert_equal ["Ensembl Gene ID", nil, nil], spec
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              def test_process_specs
         
     | 
| 
      
 35 
     | 
    
         
            +
                spec = Association.extract_specs %w(SG TG Effect directed?), :target => "TG=~Associated Gene Name=>Ensembl Gene ID"
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal ["TG", "Associated Gene Name", "Ensembl Gene ID"], spec[:target]
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_equal ["SG", nil, nil], spec[:source]
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                spec = Association.extract_specs %w(SG TG Effect directed?)
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal ["SG", nil, nil], spec[:source]
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal ["TG", nil,nil], spec[:target]
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                spec = Association.extract_specs %w(SG TG Effect directed?), :source => "TG"
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_equal ["TG", nil, nil], spec[:source]
         
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal ["SG", nil,nil], spec[:target]
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                spec = Association.extract_specs %w(SG TG Effect directed?), :source => "SG"
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal ["SG", nil, nil], spec[:source]
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal ["TG", nil,nil], spec[:target]
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                spec = Association.extract_specs %w(SG TG Effect directed?), :target => "SG"
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_equal ["TG", nil, nil], spec[:source]
         
     | 
| 
      
 53 
     | 
    
         
            +
                assert_equal ["SG", nil,nil], spec[:target]
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              def test_headers
         
     | 
| 
      
 57 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect)
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal 0, spec[0]
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert_equal 1, spec[1][0]
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :source => "SG"
         
     | 
| 
      
 62 
     | 
    
         
            +
                assert_equal 0, spec[0]
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert_equal 1, spec[1][0]
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "TG"
         
     | 
| 
      
 66 
     | 
    
         
            +
                assert_equal 0, spec[0]
         
     | 
| 
      
 67 
     | 
    
         
            +
                assert_equal 1, spec[1][0]
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "TG", :source => "SG"
         
     | 
| 
      
 70 
     | 
    
         
            +
                assert_equal 0, spec[0]
         
     | 
| 
      
 71 
     | 
    
         
            +
                assert_equal 1, spec[1][0]
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :source => "TG"
         
     | 
| 
      
 74 
     | 
    
         
            +
                assert_equal 1, spec[0]
         
     | 
| 
      
 75 
     | 
    
         
            +
                assert_equal 0, spec[1][0]
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "SG"
         
     | 
| 
      
 78 
     | 
    
         
            +
                assert_equal 1, spec[0]
         
     | 
| 
      
 79 
     | 
    
         
            +
                assert_equal 0, spec[1][0]
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "SG", :source => "TG"
         
     | 
| 
      
 82 
     | 
    
         
            +
                assert_equal 1, spec[0]
         
     | 
| 
      
 83 
     | 
    
         
            +
                assert_equal 0, spec[1][0]
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "SG", :source => "TG=~Associated Gene Name=>Ensembl Gene ID"
         
     | 
| 
      
 86 
     | 
    
         
            +
                assert_equal 1, spec[0]
         
     | 
| 
      
 87 
     | 
    
         
            +
                assert_equal 0, spec[1][0]
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "SG=~Associated Gene Name=>Ensembl Gene ID", :source => "TG=~Associated Gene Name=>Ensembl Gene ID"
         
     | 
| 
      
 90 
     | 
    
         
            +
                assert_equal 1, spec[0]
         
     | 
| 
      
 91 
     | 
    
         
            +
                assert_equal 0, spec[1][0]
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "SG=~Associated Gene Name", :source => "TG=~Associated Gene Name=>Ensembl Gene ID"
         
     | 
| 
      
 94 
     | 
    
         
            +
                assert_equal 1, spec[0]
         
     | 
| 
      
 95 
     | 
    
         
            +
                assert_equal 0, spec[1][0]
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "TG=~Associated Gene Name", :source => "SG=~Associated Gene Name", :target_format => "Ensembl Gene ID"
         
     | 
| 
      
 98 
     | 
    
         
            +
                assert_equal 0, spec[0]
         
     | 
| 
      
 99 
     | 
    
         
            +
                assert_equal "Ensembl Gene ID", spec[5]
         
     | 
| 
      
 100 
     | 
    
         
            +
                assert_equal nil, spec[4]
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                spec = Association.headers  %w(SG TG Effect directed?), %w(Effect), :target => "TG=~Associated Gene Name", :source => "SG=~Associated Gene Name", :source_format => "Ensembl Gene ID"
         
     | 
| 
      
 104 
     | 
    
         
            +
                assert_equal 0, spec[0]
         
     | 
| 
      
 105 
     | 
    
         
            +
                assert_equal "Ensembl Gene ID", spec[4]
         
     | 
| 
      
 106 
     | 
    
         
            +
                assert_equal nil, spec[5]
         
     | 
| 
      
 107 
     | 
    
         
            +
              end
         
     | 
| 
      
 108 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,40 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rbbt-util'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rbbt/entity'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rbbt/entity/identifiers'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            module Gene
         
     | 
| 
      
 7 
     | 
    
         
            +
              extend Entity
         
     | 
| 
      
 8 
     | 
    
         
            +
            end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            require 'rbbt/sources/kegg'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'rbbt/sources/organism'
         
     | 
| 
      
 12 
     | 
    
         
            +
            Gene.add_identifiers Organism.identifiers("NAMESPACE"), "Ensembl Gene ID", "Associated Gene Name"
         
     | 
| 
      
 13 
     | 
    
         
            +
            Gene.add_identifiers KEGG.identifiers
         
     | 
| 
      
 14 
     | 
    
         
            +
            Gene.add_identifiers Organism.identifiers("NAMESPACE"), "Ensembl Gene ID", "Associated Gene Name"
         
     | 
| 
      
 15 
     | 
    
         
            +
            Gene.add_identifiers KEGG.identifiers
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            class TestEntityIdentifiers < Test::Unit::TestCase
         
     | 
| 
      
 18 
     | 
    
         
            +
              def test_name
         
     | 
| 
      
 19 
     | 
    
         
            +
                Gene.add_identifiers datafile_test('identifiers'), "Ensembl Gene ID", "Associated Gene Name"
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal "TP53", Gene.setup("ENSG00000141510").name
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              def test_name_organism
         
     | 
| 
      
 24 
     | 
    
         
            +
                assert_equal "TP53", Gene.setup("ENSG00000141510", "Ensembl Gene ID", "Hsa/feb2014").name
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              def test_identifier_files
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert Gene.identifier_files.any?
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              def test_Entity_identifier_files
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert Entity.identifier_files("Ensembl Gene ID").any?
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              def test_translate_kegg
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_match "hsa", Gene.setup("ENSG00000141510", "Ensembl Gene ID", "Hsa/feb2014").to("KEGG Gene ID")
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_match "TP53", Gene.setup("ENSG00000141510", "Ensembl Gene ID", "Hsa/feb2014").to("KEGG Gene ID").to(:name)
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -0,0 +1,45 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path(File.dirname(__FILE__) + '../../../test_helper')
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rbbt/util/tmpfile'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rbbt/knowledge_base'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rbbt/knowledge_base/query'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class TestKnowledgeBaseQuery < Test::Unit::TestCase
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              EFFECT =StringIO.new <<-END
         
     | 
| 
      
 10 
     | 
    
         
            +
            #: :sep=" "#:type=:double
         
     | 
| 
      
 11 
     | 
    
         
            +
            #SG TG Effect
         
     | 
| 
      
 12 
     | 
    
         
            +
            MDM2 TP53 inhibition
         
     | 
| 
      
 13 
     | 
    
         
            +
            TP53 NFKB1|GLI1 activation|activation true|true
         
     | 
| 
      
 14 
     | 
    
         
            +
              END
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              EFFECT_OPTIONS = {
         
     | 
| 
      
 17 
     | 
    
         
            +
                :source => "SG=~Associated Gene Name",
         
     | 
| 
      
 18 
     | 
    
         
            +
                :target => "TG=~Associated Gene Name=>Ensembl Gene ID",
         
     | 
| 
      
 19 
     | 
    
         
            +
                :persist => false,
         
     | 
| 
      
 20 
     | 
    
         
            +
                :identifiers => datafile_test('identifiers'),
         
     | 
| 
      
 21 
     | 
    
         
            +
                :undirected => true,
         
     | 
| 
      
 22 
     | 
    
         
            +
                :namespace => "Hsa"
         
     | 
| 
      
 23 
     | 
    
         
            +
              }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              EFFECT_TSV = TSV.open EFFECT, EFFECT_OPTIONS.dup 
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              KNOWLEDGE_BASE = KnowledgeBase.new '/tmp/kb.foo2', "Hsa"
         
     | 
| 
      
 28 
     | 
    
         
            +
              KNOWLEDGE_BASE.format = {"Gene" => "Ensembl Gene ID"}
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              KNOWLEDGE_BASE.register :effects, EFFECT_TSV, EFFECT_OPTIONS.dup
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              def test_subset_all_persist
         
     | 
| 
      
 33 
     | 
    
         
            +
                Misc.benchmark(1000) do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  assert_equal 6, KNOWLEDGE_BASE.subset(:effects, :all).length
         
     | 
| 
      
 35 
     | 
    
         
            +
                  assert_equal 4, KNOWLEDGE_BASE.subset(:effects, :all).target_entity.uniq.length
         
     | 
| 
      
 36 
     | 
    
         
            +
                  assert_equal %w(Effect), KNOWLEDGE_BASE.subset(:effects, :all).info.first.keys 
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              def test_subset_all_persist_format
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert KNOWLEDGE_BASE.subset(:effects, :all).target_entity.reject{|e| e =~ /^ENS/}.empty?
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,52 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path(File.dirname(__FILE__) + '../../../test_helper')
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rbbt/util/tmpfile'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rbbt/knowledge_base'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rbbt/knowledge_base/registry'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class TestKnowledgeBaseRegistry < Test::Unit::TestCase
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              EFFECT =StringIO.new <<-END
         
     | 
| 
      
 11 
     | 
    
         
            +
            #: :sep=" "#:type=:double
         
     | 
| 
      
 12 
     | 
    
         
            +
            #SG TG Effect
         
     | 
| 
      
 13 
     | 
    
         
            +
            MDM2 TP53 inhibition
         
     | 
| 
      
 14 
     | 
    
         
            +
            TP53 NFKB1|GLI1 activation|activation true|true
         
     | 
| 
      
 15 
     | 
    
         
            +
              END
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              EFFECT_OPTIONS = {
         
     | 
| 
      
 18 
     | 
    
         
            +
                :source => "SG=~Associated Gene Name",
         
     | 
| 
      
 19 
     | 
    
         
            +
                :target => "TG=~Associated Gene Name=>Ensembl Gene ID",
         
     | 
| 
      
 20 
     | 
    
         
            +
                :persist => false,
         
     | 
| 
      
 21 
     | 
    
         
            +
                :identifiers => datafile_test('identifiers'),
         
     | 
| 
      
 22 
     | 
    
         
            +
                :undirected => true,
         
     | 
| 
      
 23 
     | 
    
         
            +
                :namespace => "Hsa"
         
     | 
| 
      
 24 
     | 
    
         
            +
              }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              EFFECT_TSV = TSV.open EFFECT, EFFECT_OPTIONS.dup 
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              KNOWLEDGE_BASE = KnowledgeBase.new '/tmp/kb.foo2'
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              KNOWLEDGE_BASE.register :effects, EFFECT_TSV, EFFECT_OPTIONS.dup
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              def test_database
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal "Associated Gene Name", KNOWLEDGE_BASE.get_database(:effects, :source_format => "Associated Gene Name").key_field
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              def test_index
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert KNOWLEDGE_BASE.get_index(:effects, :source_format => "Associated Gene Name", :target_format => "Ensembl Gene ID", :persist => false).include? "MDM2~ENSG00000141510"
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              def test_index_persist
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert KNOWLEDGE_BASE.get_index(:effects, :source_format => "Associated Gene Name", :target_format => "Ensembl Gene ID", :persist => true).include? "MDM2~ENSG00000141510"
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def test_index_flat
         
     | 
| 
      
 46 
     | 
    
         
            +
                require 'rbbt/sources/tfacts'
         
     | 
| 
      
 47 
     | 
    
         
            +
                file = TFacts.regulators
         
     | 
| 
      
 48 
     | 
    
         
            +
                KNOWLEDGE_BASE.register :tfacts, file,  :type => :flat, :source => "Transcription Factor Associated Gene Name=~Associated Gene Name", :merge => true
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert KNOWLEDGE_BASE.subset(:tfacts, :source => ["TP53"], :target => :all).length > 10
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
            end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
         @@ -6,7 +6,9 @@ require 'rbbt/workflow' 
     | 
|
| 
       6 
6 
     | 
    
         
             
            require 'rbbt/entity'
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            require 'rbbt/association'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'rbbt/association/open'
         
     | 
| 
       9 
10 
     | 
    
         
             
            require 'rbbt/knowledge_base'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'rbbt/entity'
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         | 
| 
       12 
14 
     | 
    
         
             
            TEST_ASSOCIATIONS =<<-EOF
         
     | 
| 
         @@ -57,9 +59,6 @@ class TestAssociations < Test::Unit::TestCase 
     | 
|
| 
       57 
59 
     | 
    
         
             
                assert_equal ["aa"], database["TP53"].first
         
     | 
| 
       58 
60 
     | 
    
         
             
              end
         
     | 
| 
       59 
61 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
              def test_reciprocal
         
     | 
| 
       61 
     | 
    
         
            -
              end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
62 
     | 
    
         | 
| 
       64 
63 
     | 
    
         
             
              def __test_ICGC
         
     | 
| 
       65 
64 
     | 
    
         
             
                assoc = Association.open(Open.open('ftp://data.dcc.icgc.org/current/Chronic_Lymphocytic_Leukemia-ISC_MICINN-ES/simple_somatic_mutation.CLLE-ES.tsv.gz'),
         
     | 
| 
         @@ -100,4 +99,5 @@ class TestAssociations < Test::Unit::TestCase 
     | 
|
| 
       100 
99 
     | 
    
         
             
                assert_equal [tp53.ensembl], database["aa"].first
         
     | 
| 
       101 
100 
     | 
    
         
             
              end
         
     | 
| 
       102 
101 
     | 
    
         | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
       103 
103 
     | 
    
         
             
            end
         
     |