bio 0.7.0
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.
- data/bin/bioruby +107 -0
- data/bin/br_biofetch.rb +59 -0
- data/bin/br_bioflat.rb +294 -0
- data/bin/br_biogetseq.rb +57 -0
- data/bin/br_pmfetch.rb +431 -0
- data/doc/BioRuby.rd.ja +225 -0
- data/doc/Changes-0.7.rd +236 -0
- data/doc/Design.rd.ja +341 -0
- data/doc/KEGG_API.rd +1437 -0
- data/doc/KEGG_API.rd.ja +1399 -0
- data/doc/TODO.rd.ja +138 -0
- data/doc/Tutorial.rd +1138 -0
- data/doc/Tutorial.rd.ja +2110 -0
- data/etc/bioinformatics/seqdatabase.ini +210 -0
- data/lib/bio.rb +256 -0
- data/lib/bio/alignment.rb +1906 -0
- data/lib/bio/appl/bl2seq/report.rb +350 -0
- data/lib/bio/appl/blast.rb +269 -0
- data/lib/bio/appl/blast/format0.rb +1402 -0
- data/lib/bio/appl/blast/format8.rb +95 -0
- data/lib/bio/appl/blast/report.rb +652 -0
- data/lib/bio/appl/blast/rexml.rb +151 -0
- data/lib/bio/appl/blast/wublast.rb +553 -0
- data/lib/bio/appl/blast/xmlparser.rb +222 -0
- data/lib/bio/appl/blat/report.rb +392 -0
- data/lib/bio/appl/clustalw.rb +191 -0
- data/lib/bio/appl/clustalw/report.rb +154 -0
- data/lib/bio/appl/emboss.rb +68 -0
- data/lib/bio/appl/fasta.rb +262 -0
- data/lib/bio/appl/fasta/format10.rb +428 -0
- data/lib/bio/appl/fasta/format6.rb +37 -0
- data/lib/bio/appl/genscan/report.rb +570 -0
- data/lib/bio/appl/hmmer.rb +129 -0
- data/lib/bio/appl/hmmer/report.rb +556 -0
- data/lib/bio/appl/mafft.rb +222 -0
- data/lib/bio/appl/mafft/report.rb +119 -0
- data/lib/bio/appl/psort.rb +555 -0
- data/lib/bio/appl/psort/report.rb +473 -0
- data/lib/bio/appl/sim4.rb +134 -0
- data/lib/bio/appl/sim4/report.rb +501 -0
- data/lib/bio/appl/sosui/report.rb +166 -0
- data/lib/bio/appl/spidey/report.rb +604 -0
- data/lib/bio/appl/targetp/report.rb +283 -0
- data/lib/bio/appl/tmhmm/report.rb +238 -0
- data/lib/bio/command.rb +166 -0
- data/lib/bio/data/aa.rb +354 -0
- data/lib/bio/data/codontable.rb +740 -0
- data/lib/bio/data/na.rb +226 -0
- data/lib/bio/db.rb +340 -0
- data/lib/bio/db/aaindex.rb +280 -0
- data/lib/bio/db/embl/common.rb +332 -0
- data/lib/bio/db/embl/embl.rb +446 -0
- data/lib/bio/db/embl/sptr.rb +954 -0
- data/lib/bio/db/embl/swissprot.rb +32 -0
- data/lib/bio/db/embl/trembl.rb +31 -0
- data/lib/bio/db/embl/uniprot.rb +32 -0
- data/lib/bio/db/fantom.rb +604 -0
- data/lib/bio/db/fasta.rb +869 -0
- data/lib/bio/db/genbank/common.rb +299 -0
- data/lib/bio/db/genbank/ddbj.rb +34 -0
- data/lib/bio/db/genbank/genbank.rb +354 -0
- data/lib/bio/db/genbank/genpept.rb +73 -0
- data/lib/bio/db/genbank/refseq.rb +31 -0
- data/lib/bio/db/gff.rb +106 -0
- data/lib/bio/db/go.rb +497 -0
- data/lib/bio/db/kegg/brite.rb +51 -0
- data/lib/bio/db/kegg/cell.rb +88 -0
- data/lib/bio/db/kegg/compound.rb +130 -0
- data/lib/bio/db/kegg/enzyme.rb +125 -0
- data/lib/bio/db/kegg/expression.rb +173 -0
- data/lib/bio/db/kegg/genes.rb +293 -0
- data/lib/bio/db/kegg/genome.rb +362 -0
- data/lib/bio/db/kegg/glycan.rb +213 -0
- data/lib/bio/db/kegg/keggtab.rb +418 -0
- data/lib/bio/db/kegg/kgml.rb +299 -0
- data/lib/bio/db/kegg/ko.rb +178 -0
- data/lib/bio/db/kegg/reaction.rb +97 -0
- data/lib/bio/db/litdb.rb +131 -0
- data/lib/bio/db/medline.rb +317 -0
- data/lib/bio/db/nbrf.rb +199 -0
- data/lib/bio/db/pdb.rb +38 -0
- data/lib/bio/db/pdb/atom.rb +60 -0
- data/lib/bio/db/pdb/chain.rb +117 -0
- data/lib/bio/db/pdb/model.rb +106 -0
- data/lib/bio/db/pdb/pdb.rb +1682 -0
- data/lib/bio/db/pdb/residue.rb +122 -0
- data/lib/bio/db/pdb/utils.rb +234 -0
- data/lib/bio/db/prosite.rb +616 -0
- data/lib/bio/db/rebase.rb +417 -0
- data/lib/bio/db/transfac.rb +387 -0
- data/lib/bio/feature.rb +201 -0
- data/lib/bio/io/brdb.rb +103 -0
- data/lib/bio/io/das.rb +471 -0
- data/lib/bio/io/dbget.rb +212 -0
- data/lib/bio/io/ddbjxml.rb +614 -0
- data/lib/bio/io/fastacmd.rb +123 -0
- data/lib/bio/io/fetch.rb +114 -0
- data/lib/bio/io/flatfile.rb +496 -0
- data/lib/bio/io/flatfile/bdb.rb +266 -0
- data/lib/bio/io/flatfile/index.rb +1308 -0
- data/lib/bio/io/flatfile/indexer.rb +778 -0
- data/lib/bio/io/higet.rb +92 -0
- data/lib/bio/io/keggapi.rb +863 -0
- data/lib/bio/io/pubmed.rb +189 -0
- data/lib/bio/io/registry.rb +308 -0
- data/lib/bio/io/soapwsdl.rb +114 -0
- data/lib/bio/io/sql.rb +428 -0
- data/lib/bio/location.rb +650 -0
- data/lib/bio/pathway.rb +991 -0
- data/lib/bio/reference.rb +308 -0
- data/lib/bio/sequence.rb +593 -0
- data/lib/bio/shell.rb +51 -0
- data/lib/bio/shell/core.rb +512 -0
- data/lib/bio/shell/plugin/codon.rb +228 -0
- data/lib/bio/shell/plugin/entry.rb +85 -0
- data/lib/bio/shell/plugin/flatfile.rb +119 -0
- data/lib/bio/shell/plugin/keggapi.rb +187 -0
- data/lib/bio/shell/plugin/midi.rb +448 -0
- data/lib/bio/shell/plugin/obda.rb +63 -0
- data/lib/bio/shell/plugin/seq.rb +238 -0
- data/lib/bio/shell/session.rb +214 -0
- data/lib/bio/util/color_scheme.rb +214 -0
- data/lib/bio/util/color_scheme/buried.rb +78 -0
- data/lib/bio/util/color_scheme/helix.rb +78 -0
- data/lib/bio/util/color_scheme/hydropathy.rb +83 -0
- data/lib/bio/util/color_scheme/nucleotide.rb +50 -0
- data/lib/bio/util/color_scheme/strand.rb +78 -0
- data/lib/bio/util/color_scheme/taylor.rb +69 -0
- data/lib/bio/util/color_scheme/turn.rb +78 -0
- data/lib/bio/util/color_scheme/zappo.rb +69 -0
- data/lib/bio/util/contingency_table.rb +337 -0
- data/lib/bio/util/sirna.rb +306 -0
- data/lib/bioruby.rb +34 -0
- data/sample/biofetch.rb +475 -0
- data/sample/color_scheme_na.rb +99 -0
- data/sample/dbget +37 -0
- data/sample/fasta2tab.rb +99 -0
- data/sample/fsplit.rb +51 -0
- data/sample/gb2fasta.rb +31 -0
- data/sample/gb2tab.rb +325 -0
- data/sample/gbtab2mysql.rb +161 -0
- data/sample/genes2nuc.rb +33 -0
- data/sample/genes2pep.rb +33 -0
- data/sample/genes2tab.rb +81 -0
- data/sample/genome2rb.rb +29 -0
- data/sample/genome2tab.rb +76 -0
- data/sample/goslim.rb +311 -0
- data/sample/gt2fasta.rb +47 -0
- data/sample/pmfetch.rb +42 -0
- data/sample/pmsearch.rb +42 -0
- data/sample/psortplot_html.rb +222 -0
- data/sample/ssearch2tab.rb +96 -0
- data/sample/tdiary.rb +158 -0
- data/sample/tfastx2tab.rb +100 -0
- data/sample/vs-genes.rb +212 -0
- data/test/data/SOSUI/sample.report +11 -0
- data/test/data/TMHMM/sample.report +21 -0
- data/test/data/blast/eco:b0002.faa +15 -0
- data/test/data/blast/eco:b0002.faa.m0 +128 -0
- data/test/data/blast/eco:b0002.faa.m7 +65 -0
- data/test/data/blast/eco:b0002.faa.m8 +1 -0
- data/test/data/embl/AB090716.embl +65 -0
- data/test/data/genscan/sample.report +63 -0
- data/test/data/prosite/prosite.dat +2233 -0
- data/test/data/refseq/nm_126355.entret +64 -0
- data/test/data/uniprot/p53_human.uniprot +1456 -0
- data/test/runner.rb +10 -0
- data/test/unit/bio/appl/blast/test_report.rb +427 -0
- data/test/unit/bio/appl/blast/test_xmlparser.rb +400 -0
- data/test/unit/bio/appl/genscan/test_report.rb +195 -0
- data/test/unit/bio/appl/sosui/test_report.rb +94 -0
- data/test/unit/bio/appl/targetp/test_report.rb +159 -0
- data/test/unit/bio/appl/test_blast.rb +159 -0
- data/test/unit/bio/appl/test_fasta.rb +142 -0
- data/test/unit/bio/appl/tmhmm/test_report.rb +139 -0
- data/test/unit/bio/data/test_aa.rb +103 -0
- data/test/unit/bio/data/test_codontable.rb +120 -0
- data/test/unit/bio/data/test_na.rb +89 -0
- data/test/unit/bio/db/embl/test_common.rb +130 -0
- data/test/unit/bio/db/embl/test_embl.rb +227 -0
- data/test/unit/bio/db/embl/test_sptr.rb +268 -0
- data/test/unit/bio/db/embl/test_uniprot.rb +44 -0
- data/test/unit/bio/db/kegg/test_genes.rb +58 -0
- data/test/unit/bio/db/test_fasta.rb +263 -0
- data/test/unit/bio/db/test_gff.rb +140 -0
- data/test/unit/bio/db/test_prosite.rb +1450 -0
- data/test/unit/bio/io/test_ddbjxml.rb +87 -0
- data/test/unit/bio/io/test_soapwsdl.rb +45 -0
- data/test/unit/bio/shell/plugin/test_seq.rb +175 -0
- data/test/unit/bio/test_alignment.rb +1028 -0
- data/test/unit/bio/test_command.rb +71 -0
- data/test/unit/bio/test_db.rb +109 -0
- data/test/unit/bio/test_feature.rb +128 -0
- data/test/unit/bio/test_location.rb +51 -0
- data/test/unit/bio/test_pathway.rb +485 -0
- data/test/unit/bio/test_sequence.rb +386 -0
- data/test/unit/bio/test_shell.rb +31 -0
- data/test/unit/bio/util/test_color_scheme.rb +45 -0
- data/test/unit/bio/util/test_contingency_table.rb +106 -0
- data/test/unit/bio/util/test_sirna.rb +258 -0
- metadata +295 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# test/unit/bio/test_command.rb - Unit test for external command execution methods
|
3
|
+
#
|
4
|
+
# Copyright (C) 2005 Mitsuteru Nakao <n@bioruby.org>
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
# $Id: test_command.rb,v 1.1 2005/10/27 15:11:51 nakao Exp $
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'pathname'
|
24
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3, 'lib')).cleanpath.to_s
|
25
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
26
|
+
|
27
|
+
|
28
|
+
require 'test/unit'
|
29
|
+
require 'bio/command'
|
30
|
+
|
31
|
+
module Bio
|
32
|
+
class TestCommandTools < Test::Unit::TestCase
|
33
|
+
|
34
|
+
def test_command_tools_constants
|
35
|
+
Bio::Command::Tools::UNSAFE_CHARS_UNIX
|
36
|
+
Bio::Command::Tools::QUOTE_CHARS_WINDOWS
|
37
|
+
Bio::Command::Tools::UNESCAPABLE_CHARS
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_escape_shell_windows
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_escape_shell_unix
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_escape_shell
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_make_command_line
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_make_command_line_windows
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_make_command_line_unix
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_call_commandline_local
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_call_commandline_local_popen
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_call_commandline_local_open3
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_errorlog
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#
|
2
|
+
# test/unit/bio/test_db.rb - Unit test for Bio::DB
|
3
|
+
#
|
4
|
+
# Copyright (C) 2005 Mitsuteru Nakao <n@bioruby.org>
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
# $Id: test_db.rb,v 1.2 2005/11/23 11:44:12 nakao Exp $
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'pathname'
|
24
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3, 'lib')).cleanpath.to_s
|
25
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
26
|
+
|
27
|
+
require 'test/unit'
|
28
|
+
require 'bio/db'
|
29
|
+
|
30
|
+
module Bio
|
31
|
+
class TestDB < Test::Unit::TestCase
|
32
|
+
def setup
|
33
|
+
|
34
|
+
@obj = Bio::DB.new
|
35
|
+
@obj.instance_eval { @orig = {"TAG" => "TAG value1\n value2"} }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_open
|
39
|
+
assert(Bio::DB.respond_to?(:open))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_entry_id
|
43
|
+
assert_raises(NotImplementedError) { @obj.entry_id }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_tags
|
47
|
+
assert_equal(["TAG"], @obj.tags)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_exists
|
51
|
+
assert_equal(true, @obj.exists?("TAG"))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_get
|
55
|
+
assert_equal("TAG value1\n value2", @obj.get("TAG"))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_fetch
|
59
|
+
assert(@obj.fetch("TAG"))
|
60
|
+
assert(@obj.fetch("TAG", 1))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
class TestNCBIDB < Test::Unit::TestCase
|
66
|
+
def setup
|
67
|
+
entry =<<END
|
68
|
+
LOCUS locus
|
69
|
+
END
|
70
|
+
@obj = Bio::NCBIDB.new(entry, 10)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_fetch
|
74
|
+
assert_equal('locus', @obj.fetch("LOCUS"))
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_p_toptag2array
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_p_subtag2array
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_p_entry2hash
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# class TestKEGGDB < Test::Unit::TestCase
|
88
|
+
# end
|
89
|
+
|
90
|
+
class TestEMBLDB < Test::Unit::TestCase
|
91
|
+
def setup
|
92
|
+
@entry =<<END
|
93
|
+
ID id
|
94
|
+
XX
|
95
|
+
CC cc1
|
96
|
+
CC cc2
|
97
|
+
END
|
98
|
+
@obj = Bio::EMBLDB.new(@entry, 2)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_fetch
|
102
|
+
assert_equal('id', @obj.fetch("ID"))
|
103
|
+
assert_equal('cc1 cc2', @obj.fetch("CC"))
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_p_entry2hash
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
#
|
2
|
+
# test/unit/bio/test_feature.rb - Unit test for Features/Feature classes
|
3
|
+
#
|
4
|
+
# Copyright (C) 2005 Mitsuteru Nakao <n@bioruby.org>
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
# $Id: test_feature.rb,v 1.2 2005/11/23 11:47:12 nakao Exp $
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'pathname'
|
24
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3 , 'lib')).cleanpath.to_s
|
25
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
26
|
+
|
27
|
+
require 'test/unit'
|
28
|
+
require 'bio/feature'
|
29
|
+
|
30
|
+
|
31
|
+
module Bio
|
32
|
+
|
33
|
+
class TestQualifier < Test::Unit::TestCase
|
34
|
+
def setup
|
35
|
+
qualifier = 'gene'
|
36
|
+
value = 'CDS'
|
37
|
+
@obj = Bio::Feature::Qualifier.new(qualifier, value)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_qualifier
|
41
|
+
assert_equal('gene', @obj.qualifier)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_value
|
45
|
+
assert_equal('CDS', @obj.value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
class TestFeature < Test::Unit::TestCase
|
51
|
+
def setup
|
52
|
+
@qualifier = Bio::Feature::Qualifier.new('organism', 'Arabidopsis thaliana')
|
53
|
+
feature = "source"
|
54
|
+
position = '1..615'
|
55
|
+
qualifiers = [@qualifier]
|
56
|
+
@obj = Bio::Feature.new(feature, position, qualifiers)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_new
|
60
|
+
assert(Bio::Feature.new)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_feature
|
64
|
+
assert_equal("source", @obj.feature)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_position
|
68
|
+
assert_equal('1..615', @obj.position)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_qualifiers
|
72
|
+
assert_equal([@qualifier], @obj.qualifiers)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_locations
|
76
|
+
assert_equal(1, @obj.locations.first.from)
|
77
|
+
assert_equal(615, @obj.locations.first.to)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_append_nil
|
81
|
+
assert(@obj.append(nil))
|
82
|
+
assert_equal(1, @obj.qualifiers.size)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_append
|
86
|
+
qualifier = Bio::Feature::Qualifier.new('db_xref', 'taxon:3702')
|
87
|
+
assert(@obj.append(qualifier))
|
88
|
+
assert_equal('db_xref', @obj.qualifiers.last.qualifier)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_each
|
92
|
+
@obj.each do |qua|
|
93
|
+
assert_equal('Arabidopsis thaliana', qua.value)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_assoc
|
98
|
+
@obj.append(Bio::Feature::Qualifier.new("organism", "Arabidopsis thaliana"))
|
99
|
+
assert_equal({"organism" => "Arabidopsis thaliana"}, @obj.assoc)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class TestFeatures < Test::Unit::TestCase
|
104
|
+
def setup
|
105
|
+
@obj = Bio::Features.new([Bio::Feature.new('gene', '1..615', [])])
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_features
|
109
|
+
assert_equal(1, @obj.features.size)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_append
|
113
|
+
assert(@obj.append(Bio::Feature.new('gene', '1..615', [])))
|
114
|
+
assert_equal(2, @obj.features.size)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_each
|
118
|
+
@obj.each do |feature|
|
119
|
+
assert_equal('gene', feature.feature)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_arg # def [](*arg)
|
124
|
+
assert_equal('gene', @obj[0].feature)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# test/unit/bio/test_location.rb - Unit test for Bio::Location
|
3
|
+
#
|
4
|
+
# Copyright (C) 2004 Moses Hohman <mmhohman@northwestern.edu>
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
# $Id: test_location.rb,v 1.2 2005/09/24 03:12:55 nakao Exp $
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'pathname'
|
24
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 2, 'lib')).cleanpath.to_s
|
25
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
26
|
+
|
27
|
+
require 'test/unit'
|
28
|
+
require 'bio/location'
|
29
|
+
|
30
|
+
module Bio
|
31
|
+
class TestLocation < Test::Unit::TestCase
|
32
|
+
def test_hat
|
33
|
+
loc = Locations.new('754^755')
|
34
|
+
assert_equal([754, 755], loc.span, "span wrong")
|
35
|
+
assert_equal(754..755, loc.range, "range wrong")
|
36
|
+
assert_equal(1, loc[0].strand, "strand wrong")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_complement
|
40
|
+
loc = Locations.new('complement(53^54)')
|
41
|
+
assert_equal([53, 54], loc.span, "span wrong")
|
42
|
+
assert_equal(53..54, loc.range, "range wrong")
|
43
|
+
assert_equal(-1, loc[0].strand, "strand wrong")
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_replace_single_base
|
47
|
+
loc = Locations.new('replace(4792^4793,"a")')
|
48
|
+
assert_equal("a", loc[0].sequence)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,485 @@
|
|
1
|
+
#
|
2
|
+
# test/bio/tc_pathway.rb - Unit test for Bio::Pathway
|
3
|
+
#
|
4
|
+
# Copyright (C) 2004 Moses Hohman <mmhohman@northwestern.edu>
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
# $Id: test_pathway.rb,v 1.3 2005/12/18 16:50:56 k Exp $
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'pathname'
|
24
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), [".."]*2, "lib")).cleanpath.to_s
|
25
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
26
|
+
|
27
|
+
require 'test/unit'
|
28
|
+
require 'bio/pathway'
|
29
|
+
|
30
|
+
class Float
|
31
|
+
NaN = 0/0.0
|
32
|
+
Infinity = 1/0.0
|
33
|
+
end
|
34
|
+
|
35
|
+
class Array
|
36
|
+
def sum
|
37
|
+
inject { | sum, val | sum += val }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Bio
|
42
|
+
class Pathway
|
43
|
+
# bug in subgraph: does not include nodes w/o edges
|
44
|
+
def subgraph(list = nil)
|
45
|
+
if list
|
46
|
+
@label.clear
|
47
|
+
list.each { |node| @label[node] = true }
|
48
|
+
end
|
49
|
+
sub_graph = Pathway.new([], @undirected)
|
50
|
+
@graph.each do |from, hash|
|
51
|
+
next unless @label[from]
|
52
|
+
sub_graph.graph[from] = {}
|
53
|
+
hash.each do |to, relation|
|
54
|
+
next unless @label[to]
|
55
|
+
sub_graph.graph[from][to] = relation
|
56
|
+
end
|
57
|
+
end
|
58
|
+
sub_graph
|
59
|
+
end
|
60
|
+
|
61
|
+
# bug in cliquishness: subgraph of neighbors does not include nodes w/o edges
|
62
|
+
def subgraph_adjacency_matrix(nodes)
|
63
|
+
adjacency_matrix = to_matrix(0).to_a
|
64
|
+
node_indices = nodes.collect { |x| @index[x] }
|
65
|
+
subgraph = adjacency_matrix.values_at(*(node_indices))
|
66
|
+
subgraph.collect! { |row| row.values_at(*(node_indices)) }
|
67
|
+
end
|
68
|
+
|
69
|
+
# bug in cliquishness: subgraph of neighbors does not include nodes w/o edges
|
70
|
+
# Throws exception if graph is directed
|
71
|
+
def cliquishness(node)
|
72
|
+
raise "Cannot calculate cliquishness in directed graph" if not undirected?
|
73
|
+
neighbors = @graph[node].keys
|
74
|
+
return Float::NaN if neighbors.size==0
|
75
|
+
return 1 if neighbors.size==1
|
76
|
+
# divide by two to avoid double-counting
|
77
|
+
num_neighbor_edges = subgraph_adjacency_matrix(neighbors).flatten.sum/2
|
78
|
+
num_complete_edges = neighbors.size*(neighbors.size-1)/2
|
79
|
+
num_neighbor_edges.to_f / num_complete_edges.to_f
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class TestMyGraph < Test::Unit::TestCase
|
84
|
+
def test_cliquishness
|
85
|
+
graph = Pathway.new([
|
86
|
+
Relation.new(1, 3, 1),
|
87
|
+
Relation.new(2, 3, 1),
|
88
|
+
Relation.new(1, 5, 1),
|
89
|
+
Relation.new(2, 6, 1),
|
90
|
+
Relation.new(3, 6, 1),
|
91
|
+
Relation.new(4, 6, 1),
|
92
|
+
Relation.new(5, 6, 1),
|
93
|
+
], true)
|
94
|
+
assert_equal(0, graph.cliquishness(1), "1's cliquishness wrong")
|
95
|
+
assert_equal(1, graph.cliquishness(2), "2's cliquishness wrong")
|
96
|
+
assert_in_delta(0.33, graph.cliquishness(3), 0.01, "3's cliquishness wrong")
|
97
|
+
assert_equal(1, graph.cliquishness(4), "4's cliquishness wrong")
|
98
|
+
assert_equal(0, graph.cliquishness(5), "5's cliquishness wrong")
|
99
|
+
assert_in_delta(0.16, graph.cliquishness(6), 0.01, "6's cliquishness wrong")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class TestRelation < Test::Unit::TestCase
|
104
|
+
def test_comparison_operator
|
105
|
+
r1 = Relation.new('a', 'b', 1)
|
106
|
+
r2 = Relation.new('b', 'a', 1)
|
107
|
+
r3 = Relation.new('b', 'a', 2)
|
108
|
+
r4 = Relation.new('a', 'b', 1)
|
109
|
+
assert(r1 === r2, "r1 === r2 not true, === not symmetric wrt nodes")
|
110
|
+
assert(!(r1 === r3), "r1 === r3 not false, === does not take edge into account")
|
111
|
+
assert(r1 === r4, "r1 === r4 not true, === is not reflexive wrt nodes")
|
112
|
+
assert_equal([r1, r3], [ r1, r2, r3, r4 ].uniq, "uniq did not have expected effect")
|
113
|
+
assert(r1.eql?(r2), "r1 not eql r2")
|
114
|
+
assert(!r3.eql?(r2), "r3 eql to r2")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class TestSampleGraph < Test::Unit::TestCase
|
119
|
+
|
120
|
+
# Sample Graph :
|
121
|
+
# +----------------+
|
122
|
+
# | |
|
123
|
+
# v |
|
124
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
125
|
+
# | | | ^ |
|
126
|
+
# v | v | |
|
127
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
128
|
+
# | | | | |
|
129
|
+
# v | | v |
|
130
|
+
# (v)----->(w)<---+ (z)----+
|
131
|
+
|
132
|
+
def setup
|
133
|
+
@data = [
|
134
|
+
[ 'q', 's', 1, ],
|
135
|
+
[ 'q', 't', 1, ],
|
136
|
+
[ 'q', 'w', 1, ],
|
137
|
+
[ 'r', 'u', 1, ],
|
138
|
+
[ 'r', 'y', 1, ],
|
139
|
+
[ 's', 'v', 1, ],
|
140
|
+
[ 't', 'x', 1, ],
|
141
|
+
[ 't', 'y', 1, ],
|
142
|
+
[ 'u', 'y', 1, ],
|
143
|
+
[ 'v', 'w', 1, ],
|
144
|
+
[ 'w', 's', 1, ],
|
145
|
+
[ 'x', 'z', 1, ],
|
146
|
+
[ 'y', 'q', 1, ],
|
147
|
+
[ 'z', 'x', 1, ],
|
148
|
+
]
|
149
|
+
|
150
|
+
@graph = Pathway.new(@data.collect { |x| Relation.new(*x) })
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_to_matrix
|
154
|
+
assert_equal(Matrix[
|
155
|
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
156
|
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
|
157
|
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
158
|
+
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
|
159
|
+
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
|
160
|
+
[0, 1, 0, 0, 0, 0, 0, 1, 1, 0],
|
161
|
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
|
162
|
+
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
163
|
+
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
|
164
|
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
|
165
|
+
], @graph.to_matrix(0), "matrix wrong")
|
166
|
+
assert_equal({"v"=>0,"w"=>1,"x"=>2,"y"=>3,"z"=>4,"q"=>5,"r"=>6,"s"=>7,"t"=>8,"u"=>9}, @graph.index, "node --> matrix index order wrong")
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_dump_matrix
|
170
|
+
dumped = "[" +
|
171
|
+
"# v, w, x, y, z, q, r, s, t, u\n" +
|
172
|
+
" [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],\n" + # v
|
173
|
+
" [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],\n" + # w
|
174
|
+
" [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],\n" + # x
|
175
|
+
" [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],\n" + # y
|
176
|
+
" [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],\n" + # z
|
177
|
+
" [0, 1, 0, 0, 0, 0, 0, 1, 1, 0],\n" + # q
|
178
|
+
" [0, 0, 0, 1, 0, 0, 0, 0, 0, 1],\n" + # r
|
179
|
+
" [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n" + # s
|
180
|
+
" [0, 0, 1, 1, 0, 0, 0, 0, 0, 0],\n" + # t
|
181
|
+
" [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]\n]" # u
|
182
|
+
assert_equal(dumped, @graph.dump_matrix(0))
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_dump_list
|
186
|
+
dumped = "v => w (1)\n" +
|
187
|
+
"w => s (1)\n" +
|
188
|
+
"x => z (1)\n" +
|
189
|
+
"y => q (1)\n" +
|
190
|
+
"z => x (1)\n" +
|
191
|
+
"q => w (1), s (1), t (1)\n" +
|
192
|
+
"r => y (1), u (1)\n" +
|
193
|
+
"s => v (1)\n" +
|
194
|
+
"t => x (1), y (1)\n" +
|
195
|
+
"u => y (1)\n"
|
196
|
+
assert_equal(dumped, @graph.dump_list)
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_extract_subgraph_by_label
|
200
|
+
hash = { 'q' => "L1", 's' => "L2", 'v' => "L3", 'w' => "L4" }
|
201
|
+
@graph.label = hash
|
202
|
+
dumped =
|
203
|
+
"v => w (1)\n" +
|
204
|
+
"w => s (1)\n" +
|
205
|
+
"q => w (1), s (1)\n" +
|
206
|
+
"s => v (1)\n"
|
207
|
+
assert_equal(dumped, @graph.subgraph.dump_list)
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_extract_subgraph_by_list
|
211
|
+
dumped =
|
212
|
+
"x => z (1)\n" +
|
213
|
+
"y => q (1)\n" +
|
214
|
+
"z => x (1)\n" +
|
215
|
+
"q => t (1)\n" +
|
216
|
+
"t => x (1), y (1)\n"
|
217
|
+
assert_equal(dumped, @graph.subgraph(['q', 't', 'x', 'y', 'z']).dump_list)
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_extract_subgraph_retains_disconnected_nodes
|
221
|
+
assert_equal(4, @graph.subgraph(['r', 's', 'v', 'w']).nodes, "wrong number of nodes")
|
222
|
+
end
|
223
|
+
|
224
|
+
# Sample Graph :
|
225
|
+
# +----------------+
|
226
|
+
# | |
|
227
|
+
# v |
|
228
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
229
|
+
# | | | ^ |
|
230
|
+
# v | v | |
|
231
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
232
|
+
# | | | | |
|
233
|
+
# v | | v |
|
234
|
+
# (v)----->(w)<---+ (z)----+
|
235
|
+
|
236
|
+
def test_cliquishness_raises_exception_for_directed_graph
|
237
|
+
assert_raises (RuntimeError) { @graph.cliquishness('q') }
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_undirected_cliquishness
|
241
|
+
@graph.undirected
|
242
|
+
assert_in_delta(0.33, @graph.cliquishness('q'), 0.01)
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_small_world_aka_node_degree_histogram
|
246
|
+
expected = {1=>7, 2=>2, 3=>1}
|
247
|
+
expected.default = 0
|
248
|
+
assert_equal(expected, @graph.small_world)
|
249
|
+
end
|
250
|
+
|
251
|
+
# Sample Graph :
|
252
|
+
# +----------------+
|
253
|
+
# | |
|
254
|
+
# v |
|
255
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
256
|
+
# | | | ^ |
|
257
|
+
# v | v | |
|
258
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
259
|
+
# | | | | |
|
260
|
+
# v | | v |
|
261
|
+
# (v)----->(w)<---+ (z)----+
|
262
|
+
|
263
|
+
def test_breadth_first_search
|
264
|
+
distances, predecessors = @graph.breadth_first_search('q')
|
265
|
+
assert_equal({
|
266
|
+
"v"=>2,
|
267
|
+
"w"=>1,
|
268
|
+
"x"=>2,
|
269
|
+
"y"=>2,
|
270
|
+
"z"=>3,
|
271
|
+
"q"=>0,
|
272
|
+
"s"=>1,
|
273
|
+
"t"=>1}, distances, "distances wrong")
|
274
|
+
assert_equal({
|
275
|
+
"v"=>"s",
|
276
|
+
"w"=>"q",
|
277
|
+
"x"=>"t",
|
278
|
+
"y"=>"t",
|
279
|
+
"z"=>"x",
|
280
|
+
"q"=>nil,
|
281
|
+
"s"=>"q",
|
282
|
+
"t"=>"q"}, predecessors, "predecessors wrong")
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_bfs_shortest_path
|
286
|
+
step, path = @graph.bfs_shortest_path('y', 'w')
|
287
|
+
assert_equal(2, step, "wrong # of steps")
|
288
|
+
assert_equal(["y", "q", "w"], path, "wrong path")
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_depth_first_search
|
292
|
+
timestamp, tree, back, cross, forward = @graph.depth_first_search
|
293
|
+
assert_equal({
|
294
|
+
"v"=>[1, 6],
|
295
|
+
"w"=>[2, 5],
|
296
|
+
"x"=>[7, 10],
|
297
|
+
"y"=>[11, 16],
|
298
|
+
"z"=>[8, 9],
|
299
|
+
"q"=>[12, 15],
|
300
|
+
"r"=>[17, 20],
|
301
|
+
"s"=>[3, 4],
|
302
|
+
"t"=>[13, 14],
|
303
|
+
"u"=>[18, 19]}, timestamp, "timestamps wrong")
|
304
|
+
assert_equal({
|
305
|
+
"w"=>"v",
|
306
|
+
"z"=>"x",
|
307
|
+
"q"=>"y",
|
308
|
+
"s"=>"w",
|
309
|
+
"t"=>"q",
|
310
|
+
"u"=>"r"}, tree, "tree edges wrong")
|
311
|
+
assert_equal({
|
312
|
+
"z"=>"x",
|
313
|
+
"s"=>"v",
|
314
|
+
"t"=>"y"}, back, "back edges wrong")
|
315
|
+
assert_equal({
|
316
|
+
"q"=>"s",
|
317
|
+
"r"=>"y",
|
318
|
+
"t"=>"x",
|
319
|
+
"u"=>"y"}, cross, "cross edges wrong")
|
320
|
+
assert_equal({}, forward, "forward edges wrong")
|
321
|
+
end
|
322
|
+
|
323
|
+
# Sample Graph :
|
324
|
+
# +----------------+
|
325
|
+
# | |
|
326
|
+
# v |
|
327
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
328
|
+
# | | | ^ |
|
329
|
+
# v | v | |
|
330
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
331
|
+
# | | | | |
|
332
|
+
# v | | v |
|
333
|
+
# (v)----->(w)<---+ (z)----+
|
334
|
+
|
335
|
+
def test_dijkstra
|
336
|
+
distances, predecessors = @graph.dijkstra('q')
|
337
|
+
assert_equal({
|
338
|
+
"v"=>2,
|
339
|
+
"w"=>1,
|
340
|
+
"x"=>2,
|
341
|
+
"y"=>2,
|
342
|
+
"z"=>3,
|
343
|
+
"q"=>0,
|
344
|
+
"r"=>Float::Infinity,
|
345
|
+
"s"=>1,
|
346
|
+
"t"=>1,
|
347
|
+
"u"=>Float::Infinity}, distances, "distances wrong")
|
348
|
+
assert_equal({
|
349
|
+
"v"=>"s",
|
350
|
+
"w"=>"q",
|
351
|
+
"x"=>"t",
|
352
|
+
"y"=>"t",
|
353
|
+
"z"=>"x",
|
354
|
+
"q"=>nil,
|
355
|
+
"r"=>nil,
|
356
|
+
"s"=>"q",
|
357
|
+
"t"=>"q",
|
358
|
+
"u"=>nil}, predecessors, "predecessors wrong")
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_bellman_ford
|
362
|
+
distances, predecessors = @graph.bellman_ford('q')
|
363
|
+
assert_equal({
|
364
|
+
"v"=>2,
|
365
|
+
"w"=>1,
|
366
|
+
"x"=>2,
|
367
|
+
"y"=>2,
|
368
|
+
"z"=>3,
|
369
|
+
"q"=>0,
|
370
|
+
"r"=>Float::Infinity,
|
371
|
+
"s"=>1,
|
372
|
+
"t"=>1,
|
373
|
+
"u"=>Float::Infinity}, distances, "distances wrong")
|
374
|
+
assert_equal({
|
375
|
+
"v"=>"s",
|
376
|
+
"w"=>"q",
|
377
|
+
"x"=>"t",
|
378
|
+
"y"=>"t",
|
379
|
+
"z"=>"x",
|
380
|
+
"q"=>nil,
|
381
|
+
"r"=>nil,
|
382
|
+
"s"=>"q",
|
383
|
+
"t"=>"q",
|
384
|
+
"u"=>nil}, predecessors, "predecessors wrong")
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
class TestTopologicalSort < Test::Unit::TestCase
|
389
|
+
|
390
|
+
#
|
391
|
+
# Professor Bumstead topologically sorts his clothing when getting dressed.
|
392
|
+
#
|
393
|
+
# "undershorts" "socks"
|
394
|
+
# | | |
|
395
|
+
# v | v "watch"
|
396
|
+
# "pants" --+-------> "shoes"
|
397
|
+
# |
|
398
|
+
# v
|
399
|
+
# "belt" <----- "shirt" ----> "tie" ----> "jacket"
|
400
|
+
# | ^
|
401
|
+
# `---------------------------------------'
|
402
|
+
#
|
403
|
+
|
404
|
+
def test_dfs_topological_sort
|
405
|
+
dag = Pathway.new([
|
406
|
+
Relation.new("undershorts", "pants", true),
|
407
|
+
Relation.new("undershorts", "shoes", true),
|
408
|
+
Relation.new("socks", "shoes", true),
|
409
|
+
Relation.new("watch", "watch", true),
|
410
|
+
Relation.new("pants", "belt", true),
|
411
|
+
Relation.new("pants", "shoes", true),
|
412
|
+
Relation.new("shirt", "belt", true),
|
413
|
+
Relation.new("shirt", "tie", true),
|
414
|
+
Relation.new("tie", "jacket", true),
|
415
|
+
Relation.new("belt", "jacket", true),
|
416
|
+
])
|
417
|
+
sorted = dag.dfs_topological_sort
|
418
|
+
assert(sorted.index("socks") < sorted.index("shoes"), "socks >= shoes")
|
419
|
+
assert(sorted.index("undershorts") < sorted.index("pants"), "undershorts >= pants")
|
420
|
+
assert(sorted.index("undershorts") < sorted.index("shoes"), "undershorts >= shoes")
|
421
|
+
assert(sorted.index("pants") < sorted.index("shoes"), "pants >= shoes")
|
422
|
+
assert(sorted.index("pants") < sorted.index("belt"), "pants >= belt")
|
423
|
+
assert(sorted.index("shirt") < sorted.index("belt"), "shirt >= belt")
|
424
|
+
assert(sorted.index("shirt") < sorted.index("tie"), "shirt >= tie")
|
425
|
+
assert(sorted.index("belt") < sorted.index("jacket"), "belt >= jacket")
|
426
|
+
assert(sorted.index("tie") < sorted.index("jacket"), "tie >= jacket")
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
#TODO: verify the below
|
431
|
+
class TestWeightedGraph < Test::Unit::TestCase
|
432
|
+
|
433
|
+
# 'a' --> 'b'
|
434
|
+
# | 1 | 3
|
435
|
+
# |5 v
|
436
|
+
# `----> 'c'
|
437
|
+
|
438
|
+
def setup
|
439
|
+
r1 = Relation.new('a', 'b', 1)
|
440
|
+
r2 = Relation.new('a', 'c', 5)
|
441
|
+
r3 = Relation.new('b', 'c', 3)
|
442
|
+
@w_graph = Pathway.new([r1, r2, r3])
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_dijkstra_on_weighted_graph
|
446
|
+
distances, predecessors = @w_graph.dijkstra('a')
|
447
|
+
assert_equal({
|
448
|
+
"a"=>0,
|
449
|
+
"b"=>1,
|
450
|
+
"c"=>4}, distances, "distances wrong")
|
451
|
+
assert_equal({
|
452
|
+
"a"=>nil,
|
453
|
+
"b"=>"a",
|
454
|
+
"c"=>"b"}, predecessors, "predecessors wrong")
|
455
|
+
end
|
456
|
+
|
457
|
+
def test_bellman_ford_on_negative_weighted_graph
|
458
|
+
|
459
|
+
# ,-- 'a' --> 'b'
|
460
|
+
# | | 1 | 3
|
461
|
+
# | |5 v
|
462
|
+
# | `----> 'c'
|
463
|
+
# | ^
|
464
|
+
# |2 | -5
|
465
|
+
# `--> 'd' ----'
|
466
|
+
|
467
|
+
r4 = Relation.new('a', 'd', 2)
|
468
|
+
r5 = Relation.new('d', 'c', -5)
|
469
|
+
@w_graph.append(r4)
|
470
|
+
@w_graph.append(r5)
|
471
|
+
distances, predecessors = @w_graph.bellman_ford('a')
|
472
|
+
assert_equal({
|
473
|
+
"a"=>0,
|
474
|
+
"b"=>1,
|
475
|
+
"c"=>-3,
|
476
|
+
"d"=>2}, distances, "distances wrong")
|
477
|
+
assert_equal({
|
478
|
+
"a"=>nil,
|
479
|
+
"b"=>"a",
|
480
|
+
"c"=>"d",
|
481
|
+
"d"=>"a"}, predecessors, "predecessors wrong")
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|