jandot-bio 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/bioruby +44 -0
- data/bin/br_biofetch.rb +47 -0
- data/bin/br_bioflat.rb +282 -0
- data/bin/br_biogetseq.rb +45 -0
- data/bin/br_pmfetch.rb +421 -0
- data/doc/Changes-0.7.rd +369 -0
- data/doc/KEGG_API.rd +1843 -0
- data/doc/KEGG_API.rd.ja +1834 -0
- data/doc/Tutorial.rd +1296 -0
- data/doc/Tutorial.rd.ja +2640 -0
- data/etc/bioinformatics/seqdatabase.ini +210 -0
- data/lib/bio.rb +279 -0
- data/lib/bio/alignment.rb +2518 -0
- data/lib/bio/appl/bl2seq/report.rb +334 -0
- data/lib/bio/appl/blast.rb +351 -0
- data/lib/bio/appl/blast/format0.rb +1438 -0
- data/lib/bio/appl/blast/format8.rb +83 -0
- data/lib/bio/appl/blast/report.rb +516 -0
- data/lib/bio/appl/blast/rexml.rb +135 -0
- data/lib/bio/appl/blast/rpsblast.rb +176 -0
- data/lib/bio/appl/blast/wublast.rb +550 -0
- data/lib/bio/appl/blast/xmlparser.rb +228 -0
- data/lib/bio/appl/blat/report.rb +489 -0
- data/lib/bio/appl/clustalw.rb +219 -0
- data/lib/bio/appl/clustalw/report.rb +152 -0
- data/lib/bio/appl/emboss.rb +203 -0
- data/lib/bio/appl/fasta.rb +237 -0
- data/lib/bio/appl/fasta/format10.rb +325 -0
- data/lib/bio/appl/gcg/msf.rb +212 -0
- data/lib/bio/appl/gcg/seq.rb +195 -0
- data/lib/bio/appl/genscan/report.rb +552 -0
- data/lib/bio/appl/hmmer.rb +126 -0
- data/lib/bio/appl/hmmer/report.rb +683 -0
- data/lib/bio/appl/iprscan/report.rb +374 -0
- data/lib/bio/appl/mafft.rb +259 -0
- data/lib/bio/appl/mafft/report.rb +226 -0
- data/lib/bio/appl/muscle.rb +52 -0
- data/lib/bio/appl/phylip/alignment.rb +129 -0
- data/lib/bio/appl/phylip/distance_matrix.rb +96 -0
- data/lib/bio/appl/probcons.rb +41 -0
- data/lib/bio/appl/psort.rb +548 -0
- data/lib/bio/appl/psort/report.rb +457 -0
- data/lib/bio/appl/pts1.rb +263 -0
- data/lib/bio/appl/sim4.rb +124 -0
- data/lib/bio/appl/sim4/report.rb +485 -0
- data/lib/bio/appl/sosui/report.rb +151 -0
- data/lib/bio/appl/spidey/report.rb +593 -0
- data/lib/bio/appl/targetp/report.rb +267 -0
- data/lib/bio/appl/tcoffee.rb +55 -0
- data/lib/bio/appl/tmhmm/report.rb +222 -0
- data/lib/bio/command.rb +337 -0
- data/lib/bio/data/aa.rb +349 -0
- data/lib/bio/data/codontable.rb +722 -0
- data/lib/bio/data/na.rb +223 -0
- data/lib/bio/db.rb +329 -0
- data/lib/bio/db/aaindex.rb +357 -0
- data/lib/bio/db/embl/common.rb +336 -0
- data/lib/bio/db/embl/embl.rb +402 -0
- data/lib/bio/db/embl/sptr.rb +1283 -0
- data/lib/bio/db/embl/swissprot.rb +42 -0
- data/lib/bio/db/embl/trembl.rb +41 -0
- data/lib/bio/db/embl/uniprot.rb +42 -0
- data/lib/bio/db/fantom.rb +599 -0
- data/lib/bio/db/fasta.rb +907 -0
- data/lib/bio/db/genbank/common.rb +290 -0
- data/lib/bio/db/genbank/ddbj.rb +22 -0
- data/lib/bio/db/genbank/genbank.rb +215 -0
- data/lib/bio/db/genbank/genpept.rb +60 -0
- data/lib/bio/db/genbank/refseq.rb +18 -0
- data/lib/bio/db/gff.rb +174 -0
- data/lib/bio/db/go.rb +481 -0
- data/lib/bio/db/kegg/brite.rb +41 -0
- data/lib/bio/db/kegg/compound.rb +131 -0
- data/lib/bio/db/kegg/drug.rb +98 -0
- data/lib/bio/db/kegg/enzyme.rb +148 -0
- data/lib/bio/db/kegg/expression.rb +155 -0
- data/lib/bio/db/kegg/genes.rb +263 -0
- data/lib/bio/db/kegg/genome.rb +241 -0
- data/lib/bio/db/kegg/glycan.rb +170 -0
- data/lib/bio/db/kegg/keggtab.rb +357 -0
- data/lib/bio/db/kegg/kgml.rb +256 -0
- data/lib/bio/db/kegg/orthology.rb +136 -0
- data/lib/bio/db/kegg/reaction.rb +82 -0
- data/lib/bio/db/kegg/taxonomy.rb +331 -0
- data/lib/bio/db/lasergene.rb +209 -0
- data/lib/bio/db/litdb.rb +107 -0
- data/lib/bio/db/medline.rb +323 -0
- data/lib/bio/db/nbrf.rb +191 -0
- data/lib/bio/db/newick.rb +658 -0
- data/lib/bio/db/nexus.rb +1854 -0
- data/lib/bio/db/pdb.rb +29 -0
- data/lib/bio/db/pdb/atom.rb +77 -0
- data/lib/bio/db/pdb/chain.rb +210 -0
- data/lib/bio/db/pdb/chemicalcomponent.rb +224 -0
- data/lib/bio/db/pdb/model.rb +148 -0
- data/lib/bio/db/pdb/pdb.rb +1911 -0
- data/lib/bio/db/pdb/residue.rb +176 -0
- data/lib/bio/db/pdb/utils.rb +399 -0
- data/lib/bio/db/prosite.rb +597 -0
- data/lib/bio/db/rebase.rb +457 -0
- data/lib/bio/db/soft.rb +404 -0
- data/lib/bio/db/transfac.rb +375 -0
- data/lib/bio/feature.rb +226 -0
- data/lib/bio/io/das.rb +461 -0
- data/lib/bio/io/dbget.rb +194 -0
- data/lib/bio/io/ddbjxml.rb +581 -0
- data/lib/bio/io/ebisoap.rb +158 -0
- data/lib/bio/io/ensembl.rb +229 -0
- data/lib/bio/io/fastacmd.rb +163 -0
- data/lib/bio/io/fetch.rb +181 -0
- data/lib/bio/io/flatfile.rb +1309 -0
- data/lib/bio/io/flatfile/bdb.rb +253 -0
- data/lib/bio/io/flatfile/index.rb +1371 -0
- data/lib/bio/io/flatfile/indexer.rb +787 -0
- data/lib/bio/io/higet.rb +73 -0
- data/lib/bio/io/hinv.rb +442 -0
- data/lib/bio/io/keggapi.rb +805 -0
- data/lib/bio/io/ncbirest.rb +256 -0
- data/lib/bio/io/ncbisoap.rb +155 -0
- data/lib/bio/io/pubmed.rb +307 -0
- data/lib/bio/io/registry.rb +292 -0
- data/lib/bio/io/soapwsdl.rb +119 -0
- data/lib/bio/io/sql.rb +365 -0
- data/lib/bio/location.rb +772 -0
- data/lib/bio/map.rb +410 -0
- data/lib/bio/pathway.rb +854 -0
- data/lib/bio/reference.rb +623 -0
- data/lib/bio/sequence.rb +475 -0
- data/lib/bio/sequence/aa.rb +125 -0
- data/lib/bio/sequence/common.rb +333 -0
- data/lib/bio/sequence/compat.rb +123 -0
- data/lib/bio/sequence/format.rb +181 -0
- data/lib/bio/sequence/generic.rb +24 -0
- data/lib/bio/sequence/na.rb +491 -0
- data/lib/bio/shell.rb +44 -0
- data/lib/bio/shell/core.rb +578 -0
- data/lib/bio/shell/demo.rb +146 -0
- data/lib/bio/shell/interface.rb +218 -0
- data/lib/bio/shell/irb.rb +95 -0
- data/lib/bio/shell/object.rb +71 -0
- data/lib/bio/shell/plugin/blast.rb +42 -0
- data/lib/bio/shell/plugin/codon.rb +218 -0
- data/lib/bio/shell/plugin/das.rb +58 -0
- data/lib/bio/shell/plugin/emboss.rb +23 -0
- data/lib/bio/shell/plugin/entry.rb +105 -0
- data/lib/bio/shell/plugin/flatfile.rb +101 -0
- data/lib/bio/shell/plugin/keggapi.rb +181 -0
- data/lib/bio/shell/plugin/midi.rb +430 -0
- data/lib/bio/shell/plugin/obda.rb +45 -0
- data/lib/bio/shell/plugin/psort.rb +56 -0
- data/lib/bio/shell/plugin/seq.rb +247 -0
- data/lib/bio/shell/plugin/soap.rb +87 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/bioruby_generator.rb +29 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_classes.rhtml +4 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_log.rhtml +27 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_methods.rhtml +11 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_modules.rhtml +4 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_variables.rhtml +7 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-bg.gif +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-gem.png +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-link.gif +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.css +368 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.rhtml +47 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb +144 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_helper.rb +47 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/commands.rhtml +8 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/history.rhtml +10 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/index.rhtml +26 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/spinner.gif +0 -0
- data/lib/bio/shell/script.rb +25 -0
- data/lib/bio/shell/setup.rb +109 -0
- data/lib/bio/shell/web.rb +102 -0
- data/lib/bio/tree.rb +850 -0
- data/lib/bio/util/color_scheme.rb +191 -0
- data/lib/bio/util/color_scheme/buried.rb +59 -0
- data/lib/bio/util/color_scheme/helix.rb +59 -0
- data/lib/bio/util/color_scheme/hydropathy.rb +64 -0
- data/lib/bio/util/color_scheme/nucleotide.rb +31 -0
- data/lib/bio/util/color_scheme/strand.rb +59 -0
- data/lib/bio/util/color_scheme/taylor.rb +50 -0
- data/lib/bio/util/color_scheme/turn.rb +59 -0
- data/lib/bio/util/color_scheme/zappo.rb +50 -0
- data/lib/bio/util/contingency_table.rb +370 -0
- data/lib/bio/util/restriction_enzyme.rb +228 -0
- data/lib/bio/util/restriction_enzyme/analysis.rb +249 -0
- data/lib/bio/util/restriction_enzyme/analysis_basic.rb +217 -0
- data/lib/bio/util/restriction_enzyme/cut_symbol.rb +107 -0
- data/lib/bio/util/restriction_enzyme/double_stranded.rb +321 -0
- data/lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb +130 -0
- data/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb +103 -0
- data/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb +38 -0
- data/lib/bio/util/restriction_enzyme/double_stranded/cut_locations.rb +76 -0
- data/lib/bio/util/restriction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb +107 -0
- data/lib/bio/util/restriction_enzyme/enzymes.yaml +7061 -0
- data/lib/bio/util/restriction_enzyme/range/cut_range.rb +24 -0
- data/lib/bio/util/restriction_enzyme/range/cut_ranges.rb +47 -0
- data/lib/bio/util/restriction_enzyme/range/horizontal_cut_range.rb +67 -0
- data/lib/bio/util/restriction_enzyme/range/sequence_range.rb +257 -0
- data/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb +242 -0
- data/lib/bio/util/restriction_enzyme/range/sequence_range/fragment.rb +51 -0
- data/lib/bio/util/restriction_enzyme/range/sequence_range/fragments.rb +41 -0
- data/lib/bio/util/restriction_enzyme/range/vertical_cut_range.rb +77 -0
- data/lib/bio/util/restriction_enzyme/single_strand.rb +199 -0
- data/lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb +135 -0
- data/lib/bio/util/restriction_enzyme/single_strand_complement.rb +23 -0
- data/lib/bio/util/restriction_enzyme/string_formatting.rb +111 -0
- data/lib/bio/util/sirna.rb +288 -0
- data/sample/any2fasta.rb +59 -0
- data/sample/biofetch.rb +475 -0
- data/sample/color_scheme_na.rb +91 -0
- data/sample/dbget +37 -0
- data/sample/enzymes.rb +78 -0
- data/sample/fasta2tab.rb +99 -0
- data/sample/fastagrep.rb +72 -0
- data/sample/fastasort.rb +54 -0
- data/sample/fsplit.rb +51 -0
- data/sample/gb2fasta.rb +30 -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 +303 -0
- data/sample/gt2fasta.rb +47 -0
- data/sample/na2aa.rb +34 -0
- data/sample/pmfetch.rb +42 -0
- data/sample/pmsearch.rb +42 -0
- data/sample/psortplot_html.rb +214 -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/HMMER/hmmpfam.out +64 -0
- data/test/data/HMMER/hmmsearch.out +88 -0
- data/test/data/SOSUI/sample.report +11 -0
- data/test/data/TMHMM/sample.report +21 -0
- data/test/data/aaindex/DAYM780301 +30 -0
- data/test/data/aaindex/PRAM900102 +20 -0
- data/test/data/bl2seq/cd8a_cd8b_blastp.bl2seq +53 -0
- data/test/data/bl2seq/cd8a_p53_e-5blastp.bl2seq +37 -0
- data/test/data/blast/2.2.15.blastp.m7 +876 -0
- data/test/data/blast/b0002.faa +15 -0
- data/test/data/blast/b0002.faa.m0 +128 -0
- data/test/data/blast/b0002.faa.m7 +65 -0
- data/test/data/blast/b0002.faa.m8 +1 -0
- data/test/data/embl/AB090716.embl +65 -0
- data/test/data/embl/AB090716.embl.rel89 +63 -0
- data/test/data/fasta/example1.txt +75 -0
- data/test/data/fasta/example2.txt +21 -0
- data/test/data/genscan/sample.report +63 -0
- data/test/data/iprscan/merged.raw +32 -0
- data/test/data/iprscan/merged.txt +74 -0
- data/test/data/prosite/prosite.dat +2233 -0
- data/test/data/refseq/nm_126355.entret +64 -0
- data/test/data/soft/GDS100_partial.soft +92 -0
- data/test/data/soft/GSE3457_family_partial.soft +874 -0
- data/test/data/uniprot/p53_human.uniprot +1456 -0
- data/test/functional/bio/io/test_ensembl.rb +186 -0
- data/test/functional/bio/io/test_soapwsdl.rb +52 -0
- data/test/runner.rb +14 -0
- data/test/unit/bio/appl/bl2seq/test_report.rb +134 -0
- data/test/unit/bio/appl/blast/test_report.rb +417 -0
- data/test/unit/bio/appl/blast/test_xmlparser.rb +388 -0
- data/test/unit/bio/appl/genscan/test_report.rb +182 -0
- data/test/unit/bio/appl/hmmer/test_report.rb +342 -0
- data/test/unit/bio/appl/iprscan/test_report.rb +338 -0
- data/test/unit/bio/appl/mafft/test_report.rb +63 -0
- data/test/unit/bio/appl/sosui/test_report.rb +81 -0
- data/test/unit/bio/appl/targetp/test_report.rb +146 -0
- data/test/unit/bio/appl/test_blast.rb +163 -0
- data/test/unit/bio/appl/test_fasta.rb +130 -0
- data/test/unit/bio/appl/test_pts1.rb +140 -0
- data/test/unit/bio/appl/tmhmm/test_report.rb +126 -0
- data/test/unit/bio/data/test_aa.rb +90 -0
- data/test/unit/bio/data/test_codontable.rb +107 -0
- data/test/unit/bio/data/test_na.rb +80 -0
- data/test/unit/bio/db/embl/test_common.rb +117 -0
- data/test/unit/bio/db/embl/test_embl.rb +214 -0
- data/test/unit/bio/db/embl/test_embl_rel89.rb +219 -0
- data/test/unit/bio/db/embl/test_sptr.rb +1775 -0
- data/test/unit/bio/db/embl/test_uniprot.rb +31 -0
- data/test/unit/bio/db/kegg/test_genes.rb +45 -0
- data/test/unit/bio/db/pdb/test_pdb.rb +152 -0
- data/test/unit/bio/db/test_aaindex.rb +197 -0
- data/test/unit/bio/db/test_fasta.rb +250 -0
- data/test/unit/bio/db/test_gff.rb +127 -0
- data/test/unit/bio/db/test_lasergene.rb +95 -0
- data/test/unit/bio/db/test_newick.rb +293 -0
- data/test/unit/bio/db/test_nexus.rb +360 -0
- data/test/unit/bio/db/test_prosite.rb +1437 -0
- data/test/unit/bio/db/test_rebase.rb +101 -0
- data/test/unit/bio/db/test_soft.rb +138 -0
- data/test/unit/bio/io/test_ddbjxml.rb +75 -0
- data/test/unit/bio/io/test_ensembl.rb +109 -0
- data/test/unit/bio/io/test_fastacmd.rb +42 -0
- data/test/unit/bio/io/test_flatfile.rb +237 -0
- data/test/unit/bio/io/test_soapwsdl.rb +32 -0
- data/test/unit/bio/sequence/test_aa.rb +103 -0
- data/test/unit/bio/sequence/test_common.rb +174 -0
- data/test/unit/bio/sequence/test_compat.rb +69 -0
- data/test/unit/bio/sequence/test_na.rb +330 -0
- data/test/unit/bio/shell/plugin/test_seq.rb +185 -0
- data/test/unit/bio/test_alignment.rb +1025 -0
- data/test/unit/bio/test_command.rb +288 -0
- data/test/unit/bio/test_db.rb +96 -0
- data/test/unit/bio/test_feature.rb +116 -0
- data/test/unit/bio/test_location.rb +39 -0
- data/test/unit/bio/test_map.rb +230 -0
- data/test/unit/bio/test_pathway.rb +473 -0
- data/test/unit/bio/test_reference.rb +224 -0
- data/test/unit/bio/test_sequence.rb +329 -0
- data/test/unit/bio/test_shell.rb +18 -0
- data/test/unit/bio/test_tree.rb +593 -0
- data/test/unit/bio/util/restriction_enzyme/analysis/test_calculated_cuts.rb +299 -0
- data/test/unit/bio/util/restriction_enzyme/analysis/test_cut_ranges.rb +103 -0
- data/test/unit/bio/util/restriction_enzyme/analysis/test_sequence_range.rb +240 -0
- data/test/unit/bio/util/restriction_enzyme/double_stranded/test_aligned_strands.rb +101 -0
- data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_location_pair.rb +75 -0
- data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_location_pair_in_enzyme_notation.rb +73 -0
- data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_locations.rb +53 -0
- data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_locations_in_enzyme_notation.rb +104 -0
- data/test/unit/bio/util/restriction_enzyme/single_strand/test_cut_locations_in_enzyme_notation.rb +83 -0
- data/test/unit/bio/util/restriction_enzyme/test_analysis.rb +246 -0
- data/test/unit/bio/util/restriction_enzyme/test_cut_symbol.rb +44 -0
- data/test/unit/bio/util/restriction_enzyme/test_double_stranded.rb +115 -0
- data/test/unit/bio/util/restriction_enzyme/test_single_strand.rb +147 -0
- data/test/unit/bio/util/restriction_enzyme/test_single_strand_complement.rb +147 -0
- data/test/unit/bio/util/restriction_enzyme/test_string_formatting.rb +60 -0
- data/test/unit/bio/util/test_color_scheme.rb +33 -0
- data/test/unit/bio/util/test_contingency_table.rb +94 -0
- data/test/unit/bio/util/test_restriction_enzyme.rb +42 -0
- data/test/unit/bio/util/test_sirna.rb +245 -0
- metadata +479 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# test/unit/bio/test_location.rb - Unit test for Bio::Location
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2004
|
5
|
+
# Moses Hohman <mmhohman@northwestern.edu>
|
6
|
+
# License:: The Ruby License
|
7
|
+
#
|
8
|
+
# $Id: test_location.rb,v 1.4 2007/04/05 23:35:42 trevor Exp $
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 2, 'lib')).cleanpath.to_s
|
13
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
require 'bio/location'
|
17
|
+
|
18
|
+
module Bio
|
19
|
+
class TestLocation < Test::Unit::TestCase
|
20
|
+
def test_hat
|
21
|
+
loc = Locations.new('754^755')
|
22
|
+
assert_equal([754, 755], loc.span, "span wrong")
|
23
|
+
assert_equal(754..755, loc.range, "range wrong")
|
24
|
+
assert_equal(1, loc[0].strand, "strand wrong")
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_complement
|
28
|
+
loc = Locations.new('complement(53^54)')
|
29
|
+
assert_equal([53, 54], loc.span, "span wrong")
|
30
|
+
assert_equal(53..54, loc.range, "range wrong")
|
31
|
+
assert_equal(-1, loc[0].strand, "strand wrong")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_replace_single_base
|
35
|
+
loc = Locations.new('replace(4792^4793,"a")')
|
36
|
+
assert_equal("a", loc[0].sequence)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
#
|
2
|
+
# = test/unit/bio/test_map.rb - Unit test for Bio::Map
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2006
|
5
|
+
# Jan Aerts <jan.aerts@bbsrc.ac.uk>
|
6
|
+
# License:: The Ruby License
|
7
|
+
#
|
8
|
+
# $Id:
|
9
|
+
|
10
|
+
require 'pathname'
|
11
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3, 'lib')).cleanpath.to_s
|
12
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
13
|
+
|
14
|
+
require 'test/unit'
|
15
|
+
require 'bio/map'
|
16
|
+
|
17
|
+
module Bio
|
18
|
+
class TestMapSimple < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
@marker1 = Bio::Map::Marker.new('marker1')
|
21
|
+
@marker2 = Bio::Map::Marker.new('marker2')
|
22
|
+
@map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 500, 'some_unit')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_attributes
|
26
|
+
assert_equal("marker1", @marker1.name)
|
27
|
+
assert_equal("marker2", @marker2.name)
|
28
|
+
assert_equal([], @marker1.mappings_as_marker)
|
29
|
+
assert_equal([], @marker2.mappings_as_marker)
|
30
|
+
assert_equal("map1", @map1.name)
|
31
|
+
assert_equal("some_unit", @map1.units)
|
32
|
+
assert_equal("some_type", @map1.type)
|
33
|
+
assert_equal([], @map1.mappings_as_map)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class TestMapping < Test::Unit::TestCase
|
38
|
+
def setup
|
39
|
+
@marker1 = Bio::Map::Marker.new('marker1')
|
40
|
+
@marker2 = Bio::Map::Marker.new('marker2')
|
41
|
+
@marker3 = Bio::Map::Marker.new('marker3')
|
42
|
+
@map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 'some_unit')
|
43
|
+
@map2 = Bio::Map::SimpleMap.new('map2', 'some_other_type', 'some_other_unit')
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_add_mapping_as_map
|
47
|
+
@map1.add_mapping_as_map(@marker2, '5')
|
48
|
+
assert_equal(1, @map1.mappings_as_map.length)
|
49
|
+
assert_equal(1, @marker2.mappings_as_marker.length)
|
50
|
+
assert_equal(0, @marker1.mappings_as_marker.length)
|
51
|
+
assert_kind_of(Bio::Locations, @map1.mappings_as_map[0].location)
|
52
|
+
assert_kind_of(Bio::Locations, @marker2.mappings_as_marker[0].location)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_add_mapping_as_marker
|
56
|
+
@marker1.add_mapping_as_marker(@map1, '5')
|
57
|
+
assert_equal(1, @map1.mappings_as_map.length, 'Mapping as map')
|
58
|
+
assert_equal(1, @marker1.mappings_as_marker.length, 'Mapping as marker')
|
59
|
+
assert_kind_of(Bio::Locations, @map1.mappings_as_map[0].location)
|
60
|
+
assert_kind_of(Bio::Locations, @marker1.mappings_as_marker[0].location)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_mapped_to?
|
64
|
+
@marker1.add_mapping_as_marker(@map1, '5')
|
65
|
+
assert_equal(true, @marker1.mapped_to?(@map1))
|
66
|
+
assert_equal(false, @marker3.mapped_to?(@map1))
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_contains_marker?
|
70
|
+
@marker1.add_mapping_as_marker(@map1, '5')
|
71
|
+
assert_equal(true, @map1.contains_marker?(@marker1))
|
72
|
+
assert_equal(false, @map1.contains_marker?(@marker3))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_mappings_as_map_each
|
76
|
+
@map1.add_mapping_as_map(@marker1, '5')
|
77
|
+
@marker2.add_mapping_as_marker(@map1, '7')
|
78
|
+
mappings = 0
|
79
|
+
@map1.mappings_as_map.each do |mapping|
|
80
|
+
mappings += 1
|
81
|
+
end
|
82
|
+
assert_equal(2, mappings)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_mappings_as_marker_each
|
86
|
+
@map1.add_mapping_as_map(@marker1, '5')
|
87
|
+
@marker1.add_mapping_as_marker(@map1, '7')
|
88
|
+
mappings = 0
|
89
|
+
@marker1.mappings_as_marker.each do |mapping|
|
90
|
+
mappings += 1
|
91
|
+
end
|
92
|
+
assert_equal(2, mappings)
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_multiple_mappings_between_same_marker_and_map
|
97
|
+
@map1.add_mapping_as_map(@marker1, '5')
|
98
|
+
@map1.add_mapping_as_map(@marker1, '37')
|
99
|
+
@marker1.add_mapping_as_marker(@map1, '53')
|
100
|
+
assert_equal(3, @marker1.mappings_as_marker.length)
|
101
|
+
|
102
|
+
@marker1.add_mapping_as_marker(@map1, '53') # This mapping should _not_ be added, because it's already defined.
|
103
|
+
assert_equal(3, @marker1.mappings_as_marker.length)
|
104
|
+
|
105
|
+
@map1.add_mapping_as_map(@marker1, '53')
|
106
|
+
assert_equal(3, @marker1.mappings_as_marker.length)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_positions_on
|
110
|
+
@map1.add_mapping_as_map(@marker1, '5')
|
111
|
+
assert_equal(1, @marker1.mappings_as_marker.length)
|
112
|
+
assert_equal('5', @marker1.positions_on(@map1).collect{|p| p.first.from.to_s}.join(',')) # FIXME: Test is not correct (uses Location.first)
|
113
|
+
@map1.add_mapping_as_map(@marker1, '37')
|
114
|
+
assert_equal('5,37', @marker1.positions_on(@map1).collect{|p| p.first.from.to_s}.sort{|a,b| a.to_i <=> b.to_i}.join(',')) # FIXME: Test is not correct (uses Location.first)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_mappings_on
|
118
|
+
@map1.add_mapping_as_map(@marker1, '5')
|
119
|
+
@map1.add_mapping_as_map(@marker1, '37')
|
120
|
+
assert_equal('5,37', @marker1.mappings_on(@map1).sort{|a,b| a.location[0].from.to_i <=> b.location[0].from.to_i}.collect{|m| m.location[0].from}.join(',')) # FIXME: Test is not correct (uses Location.first)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_mapping_location_comparison
|
124
|
+
@map1.add_mapping_as_map(@marker1, '5')
|
125
|
+
@map1.add_mapping_as_map(@marker2, '5')
|
126
|
+
@map1.add_mapping_as_map(@marker3, '17')
|
127
|
+
|
128
|
+
mapping1 = @marker1.mappings_on(@map1)[0]
|
129
|
+
mapping2 = @marker2.mappings_on(@map1)[0]
|
130
|
+
mapping3 = @marker3.mappings_on(@map1)[0]
|
131
|
+
assert_equal(true, mapping1 == mapping2)
|
132
|
+
assert_equal(false, mapping1 < mapping2)
|
133
|
+
assert_equal(false, mapping1 > mapping2)
|
134
|
+
assert_equal(false, mapping1 == mapping3)
|
135
|
+
assert_equal(true, mapping1 < mapping3)
|
136
|
+
assert_equal(false, mapping1 > mapping3)
|
137
|
+
|
138
|
+
@map2.add_mapping_as_map(@marker1, '23')
|
139
|
+
mapping4 = @marker1.mappings_on(@map2)[0]
|
140
|
+
assert_raise(RuntimeError) { mapping2 < mapping4 }
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_raise_error_kind_of
|
144
|
+
marker_without_class = 'marker1'
|
145
|
+
assert_raise(RuntimeError) { @map1.add_mapping_as_map(marker_without_class, '5') }
|
146
|
+
assert_raise(RuntimeError) { @map1.contains_marker?(marker_without_class) }
|
147
|
+
|
148
|
+
map_without_class = 'map1'
|
149
|
+
assert_raise(RuntimeError) { @marker1.add_mapping_as_marker(map_without_class, '5') }
|
150
|
+
assert_raise(RuntimeError) { @marker1.mapped_to?(map_without_class) }
|
151
|
+
assert_raise(RuntimeError) { @marker1.positions_on(map_without_class) }
|
152
|
+
assert_raise(RuntimeError) { @marker1.mappings_on(map_without_class) }
|
153
|
+
|
154
|
+
@map1.add_mapping_as_map(@marker1, '5')
|
155
|
+
mapping1 = @marker1.mappings_on(@map1)[0]
|
156
|
+
assert_raise(RuntimeError) { mapping1 > 'some_mapping' }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class CloneToActLikeMap
|
161
|
+
include Bio::Map::ActsLikeMap
|
162
|
+
def initialize
|
163
|
+
@mappings_as_map = Array.new
|
164
|
+
end
|
165
|
+
attr_accessor :mappings_as_map
|
166
|
+
end
|
167
|
+
|
168
|
+
class TestActsLikeMap < Test::Unit::TestCase
|
169
|
+
def setup
|
170
|
+
@clone = CloneToActLikeMap.new
|
171
|
+
end
|
172
|
+
def test_mixin
|
173
|
+
assert_instance_of(CloneToActLikeMap, @clone)
|
174
|
+
assert_respond_to(@clone, 'contains_marker?')
|
175
|
+
assert_respond_to(@clone, 'add_mapping_as_map')
|
176
|
+
assert_equal(0, @clone.mappings_as_map.length)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
class CloneToActLikeMarker
|
181
|
+
include Bio::Map::ActsLikeMarker
|
182
|
+
def initialize
|
183
|
+
@mappings_as_marker = Array.new
|
184
|
+
end
|
185
|
+
attr_accessor :mappings_as_marker
|
186
|
+
end
|
187
|
+
|
188
|
+
class TestActsLikeMarker < Test::Unit::TestCase
|
189
|
+
def setup
|
190
|
+
@clone = CloneToActLikeMarker.new
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_mixin
|
194
|
+
assert_instance_of(CloneToActLikeMarker, @clone)
|
195
|
+
assert_respond_to(@clone, 'mapped_to?')
|
196
|
+
assert_respond_to(@clone, 'add_mapping_as_marker')
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
class CloneToActLikeMapAndMarker
|
201
|
+
include Bio::Map::ActsLikeMap
|
202
|
+
include Bio::Map::ActsLikeMarker
|
203
|
+
def initialize
|
204
|
+
@mappings_as_map = Array.new
|
205
|
+
@mappings_as_marker = Array.new
|
206
|
+
end
|
207
|
+
attr_accessor :mappings_as_map, :mappings_as_marker
|
208
|
+
end
|
209
|
+
|
210
|
+
class TestActsLikeMapAndMarker < Test::Unit::TestCase
|
211
|
+
def setup
|
212
|
+
@clone_a = CloneToActLikeMapAndMarker.new
|
213
|
+
@clone_b = CloneToActLikeMapAndMarker.new
|
214
|
+
@clone_a.add_mapping_as_map(@clone_b, nil)
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_mixin
|
218
|
+
assert_instance_of(CloneToActLikeMapAndMarker, @clone_a)
|
219
|
+
assert_respond_to(@clone_a, 'contains_marker?')
|
220
|
+
assert_respond_to(@clone_a, 'add_mapping_as_map')
|
221
|
+
assert_respond_to(@clone_a, 'mapped_to?')
|
222
|
+
assert_respond_to(@clone_a, 'add_mapping_as_marker')
|
223
|
+
|
224
|
+
assert_equal(1, @clone_a.mappings_as_map.length)
|
225
|
+
assert_equal(0, @clone_a.mappings_as_marker.length)
|
226
|
+
assert_equal(0, @clone_b.mappings_as_map.length)
|
227
|
+
assert_equal(1, @clone_b.mappings_as_marker.length)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,473 @@
|
|
1
|
+
#
|
2
|
+
# test/bio/tc_pathway.rb - Unit test for Bio::Pathway
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2004
|
5
|
+
# Moses Hohman <mmhohman@northwestern.edu>
|
6
|
+
# License:: The Ruby License
|
7
|
+
#
|
8
|
+
# $Id: test_pathway.rb,v 1.5 2007/04/05 23:35:42 trevor Exp $
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), [".."]*2, "lib")).cleanpath.to_s
|
13
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
require 'bio/pathway'
|
17
|
+
|
18
|
+
class Float
|
19
|
+
NaN = 0/0.0
|
20
|
+
Infinity = 1/0.0
|
21
|
+
end
|
22
|
+
|
23
|
+
class Array
|
24
|
+
def sum
|
25
|
+
inject { | sum, val | sum += val }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module Bio
|
30
|
+
class Pathway
|
31
|
+
# bug in subgraph: does not include nodes w/o edges
|
32
|
+
def subgraph(list = nil)
|
33
|
+
if list
|
34
|
+
@label.clear
|
35
|
+
list.each { |node| @label[node] = true }
|
36
|
+
end
|
37
|
+
sub_graph = Pathway.new([], @undirected)
|
38
|
+
@graph.each do |from, hash|
|
39
|
+
next unless @label[from]
|
40
|
+
sub_graph.graph[from] = {}
|
41
|
+
hash.each do |to, relation|
|
42
|
+
next unless @label[to]
|
43
|
+
sub_graph.graph[from][to] = relation
|
44
|
+
end
|
45
|
+
end
|
46
|
+
sub_graph
|
47
|
+
end
|
48
|
+
|
49
|
+
# bug in cliquishness: subgraph of neighbors does not include nodes w/o edges
|
50
|
+
def subgraph_adjacency_matrix(nodes)
|
51
|
+
adjacency_matrix = to_matrix(0).to_a
|
52
|
+
node_indices = nodes.collect { |x| @index[x] }
|
53
|
+
subgraph = adjacency_matrix.values_at(*(node_indices))
|
54
|
+
subgraph.collect! { |row| row.values_at(*(node_indices)) }
|
55
|
+
end
|
56
|
+
|
57
|
+
# bug in cliquishness: subgraph of neighbors does not include nodes w/o edges
|
58
|
+
# Throws exception if graph is directed
|
59
|
+
def cliquishness(node)
|
60
|
+
raise "Cannot calculate cliquishness in directed graph" if not undirected?
|
61
|
+
neighbors = @graph[node].keys
|
62
|
+
return Float::NaN if neighbors.size==0
|
63
|
+
return 1 if neighbors.size==1
|
64
|
+
# divide by two to avoid double-counting
|
65
|
+
num_neighbor_edges = subgraph_adjacency_matrix(neighbors).flatten.sum/2
|
66
|
+
num_complete_edges = neighbors.size*(neighbors.size-1)/2
|
67
|
+
num_neighbor_edges.to_f / num_complete_edges.to_f
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class TestMyGraph < Test::Unit::TestCase
|
72
|
+
def test_cliquishness
|
73
|
+
graph = Pathway.new([
|
74
|
+
Relation.new(1, 3, 1),
|
75
|
+
Relation.new(2, 3, 1),
|
76
|
+
Relation.new(1, 5, 1),
|
77
|
+
Relation.new(2, 6, 1),
|
78
|
+
Relation.new(3, 6, 1),
|
79
|
+
Relation.new(4, 6, 1),
|
80
|
+
Relation.new(5, 6, 1),
|
81
|
+
], true)
|
82
|
+
assert_equal(0, graph.cliquishness(1), "1's cliquishness wrong")
|
83
|
+
assert_equal(1, graph.cliquishness(2), "2's cliquishness wrong")
|
84
|
+
assert_in_delta(0.33, graph.cliquishness(3), 0.01, "3's cliquishness wrong")
|
85
|
+
assert_equal(1, graph.cliquishness(4), "4's cliquishness wrong")
|
86
|
+
assert_equal(0, graph.cliquishness(5), "5's cliquishness wrong")
|
87
|
+
assert_in_delta(0.16, graph.cliquishness(6), 0.01, "6's cliquishness wrong")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class TestRelation < Test::Unit::TestCase
|
92
|
+
def test_comparison_operator
|
93
|
+
r1 = Relation.new('a', 'b', 1)
|
94
|
+
r2 = Relation.new('b', 'a', 1)
|
95
|
+
r3 = Relation.new('b', 'a', 2)
|
96
|
+
r4 = Relation.new('a', 'b', 1)
|
97
|
+
assert(r1 === r2, "r1 === r2 not true, === not symmetric wrt nodes")
|
98
|
+
assert(!(r1 === r3), "r1 === r3 not false, === does not take edge into account")
|
99
|
+
assert(r1 === r4, "r1 === r4 not true, === is not reflexive wrt nodes")
|
100
|
+
assert_equal([r1, r3], [ r1, r2, r3, r4 ].uniq, "uniq did not have expected effect")
|
101
|
+
assert(r1.eql?(r2), "r1 not eql r2")
|
102
|
+
assert(!r3.eql?(r2), "r3 eql to r2")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class TestSampleGraph < Test::Unit::TestCase
|
107
|
+
|
108
|
+
# Sample Graph :
|
109
|
+
# +----------------+
|
110
|
+
# | |
|
111
|
+
# v |
|
112
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
113
|
+
# | | | ^ |
|
114
|
+
# v | v | |
|
115
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
116
|
+
# | | | | |
|
117
|
+
# v | | v |
|
118
|
+
# (v)----->(w)<---+ (z)----+
|
119
|
+
|
120
|
+
def setup
|
121
|
+
@data = [
|
122
|
+
[ 'q', 's', 1, ],
|
123
|
+
[ 'q', 't', 1, ],
|
124
|
+
[ 'q', 'w', 1, ],
|
125
|
+
[ 'r', 'u', 1, ],
|
126
|
+
[ 'r', 'y', 1, ],
|
127
|
+
[ 's', 'v', 1, ],
|
128
|
+
[ 't', 'x', 1, ],
|
129
|
+
[ 't', 'y', 1, ],
|
130
|
+
[ 'u', 'y', 1, ],
|
131
|
+
[ 'v', 'w', 1, ],
|
132
|
+
[ 'w', 's', 1, ],
|
133
|
+
[ 'x', 'z', 1, ],
|
134
|
+
[ 'y', 'q', 1, ],
|
135
|
+
[ 'z', 'x', 1, ],
|
136
|
+
]
|
137
|
+
|
138
|
+
@graph = Pathway.new(@data.collect { |x| Relation.new(*x) })
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_to_matrix
|
142
|
+
assert_equal(Matrix[
|
143
|
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
144
|
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
|
145
|
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
146
|
+
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
|
147
|
+
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
|
148
|
+
[0, 1, 0, 0, 0, 0, 0, 1, 1, 0],
|
149
|
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
|
150
|
+
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
151
|
+
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
|
152
|
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
|
153
|
+
], @graph.to_matrix(0), "matrix wrong")
|
154
|
+
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")
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_dump_matrix
|
158
|
+
dumped = "[" +
|
159
|
+
"# v, w, x, y, z, q, r, s, t, u\n" +
|
160
|
+
" [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],\n" + # v
|
161
|
+
" [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],\n" + # w
|
162
|
+
" [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],\n" + # x
|
163
|
+
" [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],\n" + # y
|
164
|
+
" [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],\n" + # z
|
165
|
+
" [0, 1, 0, 0, 0, 0, 0, 1, 1, 0],\n" + # q
|
166
|
+
" [0, 0, 0, 1, 0, 0, 0, 0, 0, 1],\n" + # r
|
167
|
+
" [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n" + # s
|
168
|
+
" [0, 0, 1, 1, 0, 0, 0, 0, 0, 0],\n" + # t
|
169
|
+
" [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]\n]" # u
|
170
|
+
assert_equal(dumped, @graph.dump_matrix(0))
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_dump_list
|
174
|
+
dumped = "v => w (1)\n" +
|
175
|
+
"w => s (1)\n" +
|
176
|
+
"x => z (1)\n" +
|
177
|
+
"y => q (1)\n" +
|
178
|
+
"z => x (1)\n" +
|
179
|
+
"q => w (1), s (1), t (1)\n" +
|
180
|
+
"r => y (1), u (1)\n" +
|
181
|
+
"s => v (1)\n" +
|
182
|
+
"t => x (1), y (1)\n" +
|
183
|
+
"u => y (1)\n"
|
184
|
+
assert_equal(dumped, @graph.dump_list)
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_extract_subgraph_by_label
|
188
|
+
hash = { 'q' => "L1", 's' => "L2", 'v' => "L3", 'w' => "L4" }
|
189
|
+
@graph.label = hash
|
190
|
+
dumped =
|
191
|
+
"v => w (1)\n" +
|
192
|
+
"w => s (1)\n" +
|
193
|
+
"q => w (1), s (1)\n" +
|
194
|
+
"s => v (1)\n"
|
195
|
+
assert_equal(dumped, @graph.subgraph.dump_list)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_extract_subgraph_by_list
|
199
|
+
dumped =
|
200
|
+
"x => z (1)\n" +
|
201
|
+
"y => q (1)\n" +
|
202
|
+
"z => x (1)\n" +
|
203
|
+
"q => t (1)\n" +
|
204
|
+
"t => x (1), y (1)\n"
|
205
|
+
assert_equal(dumped, @graph.subgraph(['q', 't', 'x', 'y', 'z']).dump_list)
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_extract_subgraph_retains_disconnected_nodes
|
209
|
+
assert_equal(4, @graph.subgraph(['r', 's', 'v', 'w']).nodes, "wrong number of nodes")
|
210
|
+
end
|
211
|
+
|
212
|
+
# Sample Graph :
|
213
|
+
# +----------------+
|
214
|
+
# | |
|
215
|
+
# v |
|
216
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
217
|
+
# | | | ^ |
|
218
|
+
# v | v | |
|
219
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
220
|
+
# | | | | |
|
221
|
+
# v | | v |
|
222
|
+
# (v)----->(w)<---+ (z)----+
|
223
|
+
|
224
|
+
def test_cliquishness_raises_exception_for_directed_graph
|
225
|
+
assert_raises (RuntimeError) { @graph.cliquishness('q') }
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_undirected_cliquishness
|
229
|
+
@graph.undirected
|
230
|
+
assert_in_delta(0.33, @graph.cliquishness('q'), 0.01)
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_small_world_aka_node_degree_histogram
|
234
|
+
expected = {1=>7, 2=>2, 3=>1}
|
235
|
+
expected.default = 0
|
236
|
+
assert_equal(expected, @graph.small_world)
|
237
|
+
end
|
238
|
+
|
239
|
+
# Sample Graph :
|
240
|
+
# +----------------+
|
241
|
+
# | |
|
242
|
+
# v |
|
243
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
244
|
+
# | | | ^ |
|
245
|
+
# v | v | |
|
246
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
247
|
+
# | | | | |
|
248
|
+
# v | | v |
|
249
|
+
# (v)----->(w)<---+ (z)----+
|
250
|
+
|
251
|
+
def test_breadth_first_search
|
252
|
+
distances, predecessors = @graph.breadth_first_search('q')
|
253
|
+
assert_equal({
|
254
|
+
"v"=>2,
|
255
|
+
"w"=>1,
|
256
|
+
"x"=>2,
|
257
|
+
"y"=>2,
|
258
|
+
"z"=>3,
|
259
|
+
"q"=>0,
|
260
|
+
"s"=>1,
|
261
|
+
"t"=>1}, distances, "distances wrong")
|
262
|
+
assert_equal({
|
263
|
+
"v"=>"s",
|
264
|
+
"w"=>"q",
|
265
|
+
"x"=>"t",
|
266
|
+
"y"=>"t",
|
267
|
+
"z"=>"x",
|
268
|
+
"q"=>nil,
|
269
|
+
"s"=>"q",
|
270
|
+
"t"=>"q"}, predecessors, "predecessors wrong")
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_bfs_shortest_path
|
274
|
+
step, path = @graph.bfs_shortest_path('y', 'w')
|
275
|
+
assert_equal(2, step, "wrong # of steps")
|
276
|
+
assert_equal(["y", "q", "w"], path, "wrong path")
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_depth_first_search
|
280
|
+
timestamp, tree, back, cross, forward = @graph.depth_first_search
|
281
|
+
assert_equal({
|
282
|
+
"v"=>[1, 6],
|
283
|
+
"w"=>[2, 5],
|
284
|
+
"x"=>[7, 10],
|
285
|
+
"y"=>[11, 16],
|
286
|
+
"z"=>[8, 9],
|
287
|
+
"q"=>[12, 15],
|
288
|
+
"r"=>[17, 20],
|
289
|
+
"s"=>[3, 4],
|
290
|
+
"t"=>[13, 14],
|
291
|
+
"u"=>[18, 19]}, timestamp, "timestamps wrong")
|
292
|
+
assert_equal({
|
293
|
+
"w"=>"v",
|
294
|
+
"z"=>"x",
|
295
|
+
"q"=>"y",
|
296
|
+
"s"=>"w",
|
297
|
+
"t"=>"q",
|
298
|
+
"u"=>"r"}, tree, "tree edges wrong")
|
299
|
+
assert_equal({
|
300
|
+
"z"=>"x",
|
301
|
+
"s"=>"v",
|
302
|
+
"t"=>"y"}, back, "back edges wrong")
|
303
|
+
assert_equal({
|
304
|
+
"q"=>"s",
|
305
|
+
"r"=>"y",
|
306
|
+
"t"=>"x",
|
307
|
+
"u"=>"y"}, cross, "cross edges wrong")
|
308
|
+
assert_equal({}, forward, "forward edges wrong")
|
309
|
+
end
|
310
|
+
|
311
|
+
# Sample Graph :
|
312
|
+
# +----------------+
|
313
|
+
# | |
|
314
|
+
# v |
|
315
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
316
|
+
# | | | ^ |
|
317
|
+
# v | v | |
|
318
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
319
|
+
# | | | | |
|
320
|
+
# v | | v |
|
321
|
+
# (v)----->(w)<---+ (z)----+
|
322
|
+
|
323
|
+
def test_dijkstra
|
324
|
+
distances, predecessors = @graph.dijkstra('q')
|
325
|
+
assert_equal({
|
326
|
+
"v"=>2,
|
327
|
+
"w"=>1,
|
328
|
+
"x"=>2,
|
329
|
+
"y"=>2,
|
330
|
+
"z"=>3,
|
331
|
+
"q"=>0,
|
332
|
+
"r"=>Float::Infinity,
|
333
|
+
"s"=>1,
|
334
|
+
"t"=>1,
|
335
|
+
"u"=>Float::Infinity}, distances, "distances wrong")
|
336
|
+
assert_equal({
|
337
|
+
"v"=>"s",
|
338
|
+
"w"=>"q",
|
339
|
+
"x"=>"t",
|
340
|
+
"y"=>"t",
|
341
|
+
"z"=>"x",
|
342
|
+
"q"=>nil,
|
343
|
+
"r"=>nil,
|
344
|
+
"s"=>"q",
|
345
|
+
"t"=>"q",
|
346
|
+
"u"=>nil}, predecessors, "predecessors wrong")
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_bellman_ford
|
350
|
+
distances, predecessors = @graph.bellman_ford('q')
|
351
|
+
assert_equal({
|
352
|
+
"v"=>2,
|
353
|
+
"w"=>1,
|
354
|
+
"x"=>2,
|
355
|
+
"y"=>2,
|
356
|
+
"z"=>3,
|
357
|
+
"q"=>0,
|
358
|
+
"r"=>Float::Infinity,
|
359
|
+
"s"=>1,
|
360
|
+
"t"=>1,
|
361
|
+
"u"=>Float::Infinity}, distances, "distances wrong")
|
362
|
+
assert_equal({
|
363
|
+
"v"=>"s",
|
364
|
+
"w"=>"q",
|
365
|
+
"x"=>"t",
|
366
|
+
"y"=>"t",
|
367
|
+
"z"=>"x",
|
368
|
+
"q"=>nil,
|
369
|
+
"r"=>nil,
|
370
|
+
"s"=>"q",
|
371
|
+
"t"=>"q",
|
372
|
+
"u"=>nil}, predecessors, "predecessors wrong")
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
class TestTopologicalSort < Test::Unit::TestCase
|
377
|
+
|
378
|
+
#
|
379
|
+
# Professor Bumstead topologically sorts his clothing when getting dressed.
|
380
|
+
#
|
381
|
+
# "undershorts" "socks"
|
382
|
+
# | | |
|
383
|
+
# v | v "watch"
|
384
|
+
# "pants" --+-------> "shoes"
|
385
|
+
# |
|
386
|
+
# v
|
387
|
+
# "belt" <----- "shirt" ----> "tie" ----> "jacket"
|
388
|
+
# | ^
|
389
|
+
# `---------------------------------------'
|
390
|
+
#
|
391
|
+
|
392
|
+
def test_dfs_topological_sort
|
393
|
+
dag = Pathway.new([
|
394
|
+
Relation.new("undershorts", "pants", true),
|
395
|
+
Relation.new("undershorts", "shoes", true),
|
396
|
+
Relation.new("socks", "shoes", true),
|
397
|
+
Relation.new("watch", "watch", true),
|
398
|
+
Relation.new("pants", "belt", true),
|
399
|
+
Relation.new("pants", "shoes", true),
|
400
|
+
Relation.new("shirt", "belt", true),
|
401
|
+
Relation.new("shirt", "tie", true),
|
402
|
+
Relation.new("tie", "jacket", true),
|
403
|
+
Relation.new("belt", "jacket", true),
|
404
|
+
])
|
405
|
+
sorted = dag.dfs_topological_sort
|
406
|
+
assert(sorted.index("socks") < sorted.index("shoes"), "socks >= shoes")
|
407
|
+
assert(sorted.index("undershorts") < sorted.index("pants"), "undershorts >= pants")
|
408
|
+
assert(sorted.index("undershorts") < sorted.index("shoes"), "undershorts >= shoes")
|
409
|
+
assert(sorted.index("pants") < sorted.index("shoes"), "pants >= shoes")
|
410
|
+
assert(sorted.index("pants") < sorted.index("belt"), "pants >= belt")
|
411
|
+
assert(sorted.index("shirt") < sorted.index("belt"), "shirt >= belt")
|
412
|
+
assert(sorted.index("shirt") < sorted.index("tie"), "shirt >= tie")
|
413
|
+
assert(sorted.index("belt") < sorted.index("jacket"), "belt >= jacket")
|
414
|
+
assert(sorted.index("tie") < sorted.index("jacket"), "tie >= jacket")
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
#TODO: verify the below
|
419
|
+
class TestWeightedGraph < Test::Unit::TestCase
|
420
|
+
|
421
|
+
# 'a' --> 'b'
|
422
|
+
# | 1 | 3
|
423
|
+
# |5 v
|
424
|
+
# `----> 'c'
|
425
|
+
|
426
|
+
def setup
|
427
|
+
r1 = Relation.new('a', 'b', 1)
|
428
|
+
r2 = Relation.new('a', 'c', 5)
|
429
|
+
r3 = Relation.new('b', 'c', 3)
|
430
|
+
@w_graph = Pathway.new([r1, r2, r3])
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_dijkstra_on_weighted_graph
|
434
|
+
distances, predecessors = @w_graph.dijkstra('a')
|
435
|
+
assert_equal({
|
436
|
+
"a"=>0,
|
437
|
+
"b"=>1,
|
438
|
+
"c"=>4}, distances, "distances wrong")
|
439
|
+
assert_equal({
|
440
|
+
"a"=>nil,
|
441
|
+
"b"=>"a",
|
442
|
+
"c"=>"b"}, predecessors, "predecessors wrong")
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_bellman_ford_on_negative_weighted_graph
|
446
|
+
|
447
|
+
# ,-- 'a' --> 'b'
|
448
|
+
# | | 1 | 3
|
449
|
+
# | |5 v
|
450
|
+
# | `----> 'c'
|
451
|
+
# | ^
|
452
|
+
# |2 | -5
|
453
|
+
# `--> 'd' ----'
|
454
|
+
|
455
|
+
r4 = Relation.new('a', 'd', 2)
|
456
|
+
r5 = Relation.new('d', 'c', -5)
|
457
|
+
@w_graph.append(r4)
|
458
|
+
@w_graph.append(r5)
|
459
|
+
distances, predecessors = @w_graph.bellman_ford('a')
|
460
|
+
assert_equal({
|
461
|
+
"a"=>0,
|
462
|
+
"b"=>1,
|
463
|
+
"c"=>-3,
|
464
|
+
"d"=>2}, distances, "distances wrong")
|
465
|
+
assert_equal({
|
466
|
+
"a"=>nil,
|
467
|
+
"b"=>"a",
|
468
|
+
"c"=>"d",
|
469
|
+
"d"=>"a"}, predecessors, "predecessors wrong")
|
470
|
+
end
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|