wwood-bioruby 1.2.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +205 -0
- data/README_DEV.rdoc +285 -0
- data/VERSION.yml +4 -0
- data/bin/bioruby +44 -0
- data/bin/br_biofetch.rb +47 -0
- data/bin/br_bioflat.rb +293 -0
- data/bin/br_biogetseq.rb +45 -0
- data/bin/br_pmfetch.rb +421 -0
- data/lib/bio.rb +306 -0
- data/lib/bio/alignment.rb +2518 -0
- data/lib/bio/appl/bl2seq/report.rb +334 -0
- data/lib/bio/appl/blast.rb +505 -0
- data/lib/bio/appl/blast/ddbj.rb +142 -0
- data/lib/bio/appl/blast/format0.rb +1438 -0
- data/lib/bio/appl/blast/format8.rb +83 -0
- data/lib/bio/appl/blast/genomenet.rb +263 -0
- data/lib/bio/appl/blast/ncbioptions.rb +220 -0
- data/lib/bio/appl/blast/remote.rb +105 -0
- data/lib/bio/appl/blast/report.rb +767 -0
- data/lib/bio/appl/blast/rexml.rb +144 -0
- data/lib/bio/appl/blast/rpsblast.rb +277 -0
- data/lib/bio/appl/blast/wublast.rb +635 -0
- data/lib/bio/appl/blast/xmlparser.rb +236 -0
- data/lib/bio/appl/blat/report.rb +530 -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 +235 -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/paml/baseml.rb +95 -0
- data/lib/bio/appl/paml/baseml/report.rb +32 -0
- data/lib/bio/appl/paml/codeml.rb +242 -0
- data/lib/bio/appl/paml/codeml/rates.rb +67 -0
- data/lib/bio/appl/paml/codeml/report.rb +67 -0
- data/lib/bio/appl/paml/common.rb +348 -0
- data/lib/bio/appl/paml/common_report.rb +38 -0
- data/lib/bio/appl/paml/yn00.rb +103 -0
- data/lib/bio/appl/paml/yn00/report.rb +32 -0
- data/lib/bio/appl/phylip/alignment.rb +133 -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 +542 -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 +231 -0
- data/lib/bio/command.rb +593 -0
- data/lib/bio/compat/features.rb +157 -0
- data/lib/bio/compat/references.rb +128 -0
- data/lib/bio/data/aa.rb +353 -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/biosql/biosql_to_biosequence.rb +67 -0
- data/lib/bio/db/biosql/sequence.rb +508 -0
- data/lib/bio/db/embl/common.rb +352 -0
- data/lib/bio/db/embl/embl.rb +500 -0
- data/lib/bio/db/embl/embl_to_biosequence.rb +85 -0
- data/lib/bio/db/embl/format_embl.rb +190 -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 +597 -0
- data/lib/bio/db/fasta.rb +410 -0
- data/lib/bio/db/fasta/defline.rb +532 -0
- data/lib/bio/db/fasta/fasta_to_biosequence.rb +63 -0
- data/lib/bio/db/fasta/format_fasta.rb +97 -0
- data/lib/bio/db/genbank/common.rb +307 -0
- data/lib/bio/db/genbank/ddbj.rb +22 -0
- data/lib/bio/db/genbank/format_genbank.rb +187 -0
- data/lib/bio/db/genbank/genbank.rb +250 -0
- data/lib/bio/db/genbank/genbank_to_biosequence.rb +86 -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 +1846 -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 +166 -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 +326 -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 +456 -0
- data/lib/bio/db/soft.rb +404 -0
- data/lib/bio/db/transfac.rb +375 -0
- data/lib/bio/db/url.rb +42 -0
- data/lib/bio/feature.rb +139 -0
- data/lib/bio/io/biosql/biodatabase.rb +64 -0
- data/lib/bio/io/biosql/bioentry.rb +29 -0
- data/lib/bio/io/biosql/bioentry_dbxref.rb +11 -0
- data/lib/bio/io/biosql/bioentry_path.rb +12 -0
- data/lib/bio/io/biosql/bioentry_qualifier_value.rb +10 -0
- data/lib/bio/io/biosql/bioentry_reference.rb +10 -0
- data/lib/bio/io/biosql/bioentry_relationship.rb +10 -0
- data/lib/bio/io/biosql/biosequence.rb +11 -0
- data/lib/bio/io/biosql/comment.rb +7 -0
- data/lib/bio/io/biosql/config/database.yml +20 -0
- data/lib/bio/io/biosql/dbxref.rb +13 -0
- data/lib/bio/io/biosql/dbxref_qualifier_value.rb +12 -0
- data/lib/bio/io/biosql/location.rb +32 -0
- data/lib/bio/io/biosql/location_qualifier_value.rb +11 -0
- data/lib/bio/io/biosql/ontology.rb +10 -0
- data/lib/bio/io/biosql/reference.rb +9 -0
- data/lib/bio/io/biosql/seqfeature.rb +32 -0
- data/lib/bio/io/biosql/seqfeature_dbxref.rb +11 -0
- data/lib/bio/io/biosql/seqfeature_path.rb +11 -0
- data/lib/bio/io/biosql/seqfeature_qualifier_value.rb +20 -0
- data/lib/bio/io/biosql/seqfeature_relationship.rb +11 -0
- data/lib/bio/io/biosql/taxon.rb +12 -0
- data/lib/bio/io/biosql/taxon_name.rb +9 -0
- data/lib/bio/io/biosql/term.rb +27 -0
- data/lib/bio/io/biosql/term_dbxref.rb +11 -0
- data/lib/bio/io/biosql/term_path.rb +12 -0
- data/lib/bio/io/biosql/term_relationship.rb +13 -0
- data/lib/bio/io/biosql/term_relationship_term.rb +11 -0
- data/lib/bio/io/biosql/term_synonym.rb +10 -0
- data/lib/bio/io/das.rb +461 -0
- data/lib/bio/io/dbget.rb +194 -0
- data/lib/bio/io/ddbjxml.rb +638 -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 +195 -0
- data/lib/bio/io/flatfile.rb +482 -0
- data/lib/bio/io/flatfile/autodetection.rb +545 -0
- data/lib/bio/io/flatfile/bdb.rb +253 -0
- data/lib/bio/io/flatfile/buffer.rb +237 -0
- data/lib/bio/io/flatfile/index.rb +1381 -0
- data/lib/bio/io/flatfile/indexer.rb +805 -0
- data/lib/bio/io/flatfile/splitter.rb +297 -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 +733 -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 +186 -0
- data/lib/bio/location.rb +867 -0
- data/lib/bio/map.rb +410 -0
- data/lib/bio/pathway.rb +960 -0
- data/lib/bio/reference.rb +602 -0
- data/lib/bio/sequence.rb +456 -0
- data/lib/bio/sequence/aa.rb +152 -0
- data/lib/bio/sequence/adapter.rb +108 -0
- data/lib/bio/sequence/common.rb +310 -0
- data/lib/bio/sequence/compat.rb +123 -0
- data/lib/bio/sequence/dblink.rb +54 -0
- data/lib/bio/sequence/format.rb +358 -0
- data/lib/bio/sequence/format_raw.rb +23 -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 +852 -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 +200 -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/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/blast/blastp-multi.m7 +188 -0
- data/test/data/command/echoarg2.bat +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/paml/codeml/control_file.txt +30 -0
- data/test/data/paml/codeml/output.txt +78 -0
- data/test/data/paml/codeml/rates +217 -0
- data/test/data/prosite/prosite.dat +2233 -0
- data/test/data/refseq/nm_126355.entret +64 -0
- data/test/data/rpsblast/misc.rpsblast +193 -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/appl/test_pts1.rb +115 -0
- data/test/functional/bio/io/test_ensembl.rb +229 -0
- data/test/functional/bio/io/test_soapwsdl.rb +52 -0
- data/test/functional/bio/sequence/test_output_embl.rb +51 -0
- data/test/functional/bio/test_command.rb +301 -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_ncbioptions.rb +112 -0
- data/test/unit/bio/appl/blast/test_report.rb +1135 -0
- data/test/unit/bio/appl/blast/test_rpsblast.rb +398 -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/paml/codeml/test_rates.rb +45 -0
- data/test/unit/bio/appl/paml/codeml/test_report.rb +45 -0
- data/test/unit/bio/appl/paml/test_codeml.rb +174 -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 +277 -0
- data/test/unit/bio/appl/test_fasta.rb +130 -0
- data/test/unit/bio/appl/test_psort.rb +57 -0
- data/test/unit/bio/appl/test_pts1.rb +77 -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_embl_to_bioseq.rb +203 -0
- data/test/unit/bio/db/embl/test_sptr.rb +1812 -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 +1190 -0
- data/test/unit/bio/db/test_lasergene.rb +95 -0
- data/test/unit/bio/db/test_medline.rb +127 -0
- data/test/unit/bio/db/test_newick.rb +293 -0
- data/test/unit/bio/db/test_nexus.rb +364 -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/db/test_url.rb +36 -0
- data/test/unit/bio/io/flatfile/test_autodetection.rb +375 -0
- data/test/unit/bio/io/flatfile/test_buffer.rb +251 -0
- data/test/unit/bio/io/flatfile/test_splitter.rb +369 -0
- data/test/unit/bio/io/test_ddbjxml.rb +80 -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 +505 -0
- data/test/unit/bio/io/test_soapwsdl.rb +32 -0
- data/test/unit/bio/sequence/test_aa.rb +115 -0
- data/test/unit/bio/sequence/test_common.rb +373 -0
- data/test/unit/bio/sequence/test_compat.rb +69 -0
- data/test/unit/bio/sequence/test_dblink.rb +58 -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 +349 -0
- data/test/unit/bio/test_db.rb +96 -0
- data/test/unit/bio/test_feature.rb +144 -0
- data/test/unit/bio/test_location.rb +599 -0
- data/test/unit/bio/test_map.rb +230 -0
- data/test/unit/bio/test_pathway.rb +499 -0
- data/test/unit/bio/test_reference.rb +252 -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 +543 -0
@@ -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,499 @@
|
|
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:$
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
libpath = Pathname.new(File.join(File.dirname(__FILE__), [".."]*3, "lib")).cleanpath.to_s
|
13
|
+
$:.unshift(libpath) unless $:.include?(libpath)
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
require 'bio/pathway'
|
17
|
+
|
18
|
+
module Bio
|
19
|
+
|
20
|
+
class TestMyGraph < Test::Unit::TestCase
|
21
|
+
def test_cliquishness
|
22
|
+
graph = Pathway.new([
|
23
|
+
Relation.new(1, 3, 1),
|
24
|
+
Relation.new(2, 3, 1),
|
25
|
+
Relation.new(1, 5, 1),
|
26
|
+
Relation.new(2, 6, 1),
|
27
|
+
Relation.new(3, 6, 1),
|
28
|
+
Relation.new(4, 6, 1),
|
29
|
+
Relation.new(5, 6, 1),
|
30
|
+
], true)
|
31
|
+
assert_equal(0, graph.cliquishness(1), "1's cliquishness wrong")
|
32
|
+
assert_equal(1, graph.cliquishness(2), "2's cliquishness wrong")
|
33
|
+
assert_in_delta(0.33, graph.cliquishness(3), 0.01, "3's cliquishness wrong")
|
34
|
+
# Because cliquishness (clustering coefficient) for a node
|
35
|
+
# that has only one neighbor node is undefined, test for
|
36
|
+
# node 4 is commented out.
|
37
|
+
#assert_equal(1, graph.cliquishness(4), "4's cliquishness wrong")
|
38
|
+
assert_equal(0, graph.cliquishness(5), "5's cliquishness wrong")
|
39
|
+
assert_in_delta(0.16, graph.cliquishness(6), 0.01, "6's cliquishness wrong")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class TestRelation < Test::Unit::TestCase
|
44
|
+
def test_comparison_operator
|
45
|
+
r1 = Relation.new('a', 'b', 1)
|
46
|
+
r2 = Relation.new('b', 'a', 1)
|
47
|
+
r3 = Relation.new('b', 'a', 2)
|
48
|
+
r4 = Relation.new('a', 'b', 1)
|
49
|
+
assert(r1 === r2, "r1 === r2 not true, === not symmetric wrt nodes")
|
50
|
+
assert(!(r1 === r3), "r1 === r3 not false, === does not take edge into account")
|
51
|
+
assert(r1 === r4, "r1 === r4 not true, === is not reflexive wrt nodes")
|
52
|
+
assert_equal([r1, r3], [ r1, r2, r3, r4 ].uniq, "uniq did not have expected effect")
|
53
|
+
assert(r1.eql?(r2), "r1 not eql r2")
|
54
|
+
assert(!r3.eql?(r2), "r3 eql to r2")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class TestSampleGraph < Test::Unit::TestCase
|
59
|
+
|
60
|
+
TheInfinity = 1/0.0
|
61
|
+
|
62
|
+
# Sample Graph :
|
63
|
+
# +----------------+
|
64
|
+
# | |
|
65
|
+
# v |
|
66
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
67
|
+
# | | | ^ |
|
68
|
+
# v | v | |
|
69
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
70
|
+
# | | | | |
|
71
|
+
# v | | v |
|
72
|
+
# (v)----->(w)<---+ (z)----+
|
73
|
+
|
74
|
+
def setup
|
75
|
+
@data = [
|
76
|
+
[ 'q', 's', 1, ],
|
77
|
+
[ 'q', 't', 1, ],
|
78
|
+
[ 'q', 'w', 1, ],
|
79
|
+
[ 'r', 'u', 1, ],
|
80
|
+
[ 'r', 'y', 1, ],
|
81
|
+
[ 's', 'v', 1, ],
|
82
|
+
[ 't', 'x', 1, ],
|
83
|
+
[ 't', 'y', 1, ],
|
84
|
+
[ 'u', 'y', 1, ],
|
85
|
+
[ 'v', 'w', 1, ],
|
86
|
+
[ 'w', 's', 1, ],
|
87
|
+
[ 'x', 'z', 1, ],
|
88
|
+
[ 'y', 'q', 1, ],
|
89
|
+
[ 'z', 'x', 1, ],
|
90
|
+
]
|
91
|
+
|
92
|
+
@graph = Pathway.new(@data.collect { |x| Relation.new(*x) })
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_to_matrix
|
96
|
+
matrix = @graph.to_matrix(0)
|
97
|
+
index = @graph.index
|
98
|
+
# expected values
|
99
|
+
source_matrix =
|
100
|
+
[
|
101
|
+
#v w x y z q r s t u
|
102
|
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0], #v
|
103
|
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0], #w
|
104
|
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0], #x
|
105
|
+
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0], #y
|
106
|
+
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0], #z
|
107
|
+
[0, 1, 0, 0, 0, 0, 0, 1, 1, 0], #q
|
108
|
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1], #r
|
109
|
+
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], #s
|
110
|
+
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0], #t
|
111
|
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0] #u
|
112
|
+
]
|
113
|
+
source_index = {
|
114
|
+
"v"=>0, "w"=>1, "x"=>2, "y"=>3, "z"=>4,
|
115
|
+
"q"=>5, "r"=>6, "s"=>7, "t"=>8, "u"=>9
|
116
|
+
}
|
117
|
+
# test index size
|
118
|
+
assert_equal(10, source_index.size)
|
119
|
+
# test index keys
|
120
|
+
assert_equal(source_index.keys.sort, index.keys.sort)
|
121
|
+
# test index values
|
122
|
+
assert_equal(source_index.values.sort, index.values.sort)
|
123
|
+
# prepare expected matrix
|
124
|
+
ary = Array.new(index.size)
|
125
|
+
ary.collect! { |a| Array.new(index.size) }
|
126
|
+
index.each do |row_k, row_v|
|
127
|
+
src_row = source_index[row_k]
|
128
|
+
index.each do |col_k, col_v|
|
129
|
+
src_col = source_index[col_k]
|
130
|
+
ary[row_v][col_v] = source_matrix[src_row][src_col]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
expected_matrix = Matrix.rows(ary)
|
134
|
+
# test the matrix
|
135
|
+
assert_equal(expected_matrix, matrix, "matrix wrong")
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_to_matrix_fixed_index
|
139
|
+
# begin workaround removing depencency to order of Hash#each
|
140
|
+
%w( v w x y z q r s t u ).each_with_index do |x, i|
|
141
|
+
@graph.index[x] = i
|
142
|
+
end
|
143
|
+
# end workaround removing depencency to order of Hash#each
|
144
|
+
assert_equal(Matrix[
|
145
|
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
146
|
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
|
147
|
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
148
|
+
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
|
149
|
+
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
|
150
|
+
[0, 1, 0, 0, 0, 0, 0, 1, 1, 0],
|
151
|
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
|
152
|
+
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
153
|
+
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
|
154
|
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
|
155
|
+
], @graph.to_matrix(0), "matrix wrong")
|
156
|
+
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")
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_dump_matrix
|
160
|
+
# begin workaround removing depencency to order of Hash#each
|
161
|
+
%w( v w x y z q r s t u ).each_with_index do |x, i|
|
162
|
+
@graph.index[x] = i
|
163
|
+
end
|
164
|
+
# end workaround removing depencency to order of Hash#each
|
165
|
+
dumped = "[" +
|
166
|
+
"# v, w, x, y, z, q, r, s, t, u\n" +
|
167
|
+
" [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],\n" + # v
|
168
|
+
" [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],\n" + # w
|
169
|
+
" [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],\n" + # x
|
170
|
+
" [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],\n" + # y
|
171
|
+
" [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],\n" + # z
|
172
|
+
" [0, 1, 0, 0, 0, 0, 0, 1, 1, 0],\n" + # q
|
173
|
+
" [0, 0, 0, 1, 0, 0, 0, 0, 0, 1],\n" + # r
|
174
|
+
" [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n" + # s
|
175
|
+
" [0, 0, 1, 1, 0, 0, 0, 0, 0, 0],\n" + # t
|
176
|
+
" [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]\n]" # u
|
177
|
+
assert_equal(dumped, @graph.dump_matrix(0))
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_dump_list
|
181
|
+
# begin workaround removing depencency to order of Hash#each
|
182
|
+
%w( v w x y z q r s t u ).each_with_index do |x, i|
|
183
|
+
@graph.index[x] = i
|
184
|
+
end
|
185
|
+
# end workaround removing depencency to order of Hash#each
|
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
|
+
subgraph = @graph.subgraph
|
203
|
+
# begin workaround removing depencency to order of Hash#each
|
204
|
+
%w( v w q s ).each_with_index do |x, i|
|
205
|
+
subgraph.index[x] = i
|
206
|
+
end
|
207
|
+
# end workaround removing depencency to order of Hash#each
|
208
|
+
dumped =
|
209
|
+
"v => w (1)\n" +
|
210
|
+
"w => s (1)\n" +
|
211
|
+
"q => w (1), s (1)\n" +
|
212
|
+
"s => v (1)\n"
|
213
|
+
assert_equal(dumped, subgraph.dump_list)
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_extract_subgraph_by_list
|
217
|
+
subgraph = @graph.subgraph(['q', 't', 'x', 'y', 'z'])
|
218
|
+
# begin workaround removing depencency to order of Hash#each
|
219
|
+
%w( x y z q t ).each_with_index do |x, i|
|
220
|
+
subgraph.index[x] = i
|
221
|
+
end
|
222
|
+
# end workaround removing depencency to order of Hash#each
|
223
|
+
dumped =
|
224
|
+
"x => z (1)\n" +
|
225
|
+
"y => q (1)\n" +
|
226
|
+
"z => x (1)\n" +
|
227
|
+
"q => t (1)\n" +
|
228
|
+
"t => x (1), y (1)\n"
|
229
|
+
assert_equal(dumped, subgraph.dump_list)
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_extract_subgraph_retains_disconnected_nodes
|
233
|
+
assert_equal(4, @graph.subgraph(['r', 's', 'v', 'w']).nodes, "wrong number of nodes")
|
234
|
+
end
|
235
|
+
|
236
|
+
# Sample Graph :
|
237
|
+
# +----------------+
|
238
|
+
# | |
|
239
|
+
# v |
|
240
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
241
|
+
# | | | ^ |
|
242
|
+
# v | v | |
|
243
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
244
|
+
# | | | | |
|
245
|
+
# v | | v |
|
246
|
+
# (v)----->(w)<---+ (z)----+
|
247
|
+
|
248
|
+
def test_undirected_cliquishness
|
249
|
+
@graph.undirected
|
250
|
+
assert_in_delta(0.33, @graph.cliquishness('q'), 0.01)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_small_world_aka_node_degree_histogram
|
254
|
+
expected = {1=>7, 2=>2, 3=>1}
|
255
|
+
expected.default = 0
|
256
|
+
assert_equal(expected, @graph.small_world)
|
257
|
+
end
|
258
|
+
|
259
|
+
# Sample Graph :
|
260
|
+
# +----------------+
|
261
|
+
# | |
|
262
|
+
# v |
|
263
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
264
|
+
# | | | ^ |
|
265
|
+
# v | v | |
|
266
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
267
|
+
# | | | | |
|
268
|
+
# v | | v |
|
269
|
+
# (v)----->(w)<---+ (z)----+
|
270
|
+
|
271
|
+
def test_breadth_first_search
|
272
|
+
distances, predecessors = @graph.breadth_first_search('q')
|
273
|
+
assert_equal({
|
274
|
+
"v"=>2,
|
275
|
+
"w"=>1,
|
276
|
+
"x"=>2,
|
277
|
+
"y"=>2,
|
278
|
+
"z"=>3,
|
279
|
+
"q"=>0,
|
280
|
+
"s"=>1,
|
281
|
+
"t"=>1}, distances, "distances wrong")
|
282
|
+
assert_equal({
|
283
|
+
"v"=>"s",
|
284
|
+
"w"=>"q",
|
285
|
+
"x"=>"t",
|
286
|
+
"y"=>"t",
|
287
|
+
"z"=>"x",
|
288
|
+
"q"=>nil,
|
289
|
+
"s"=>"q",
|
290
|
+
"t"=>"q"}, predecessors, "predecessors wrong")
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_bfs_shortest_path
|
294
|
+
step, path = @graph.bfs_shortest_path('y', 'w')
|
295
|
+
assert_equal(2, step, "wrong # of steps")
|
296
|
+
assert_equal(["y", "q", "w"], path, "wrong path")
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_depth_first_search
|
300
|
+
# fixing node order to aviod dependency of Hash#each_key
|
301
|
+
%w( v w x y z q r s t u ).each_with_index do |x, i|
|
302
|
+
@graph.index[x] = i
|
303
|
+
end
|
304
|
+
# exec dfs
|
305
|
+
timestamp, tree, back, cross, forward =
|
306
|
+
@graph.depth_first_search
|
307
|
+
assert_equal({
|
308
|
+
"v"=>[1, 6],
|
309
|
+
"w"=>[2, 5],
|
310
|
+
"x"=>[7, 10],
|
311
|
+
"y"=>[11, 16],
|
312
|
+
"z"=>[8, 9],
|
313
|
+
"q"=>[12, 15],
|
314
|
+
"r"=>[17, 20],
|
315
|
+
"s"=>[3, 4],
|
316
|
+
"t"=>[13, 14],
|
317
|
+
"u"=>[18, 19]}, timestamp, "timestamps wrong")
|
318
|
+
assert_equal({
|
319
|
+
"w"=>"v",
|
320
|
+
"z"=>"x",
|
321
|
+
"q"=>"y",
|
322
|
+
"s"=>"w",
|
323
|
+
"t"=>"q",
|
324
|
+
"u"=>"r"}, tree, "tree edges wrong")
|
325
|
+
assert_equal({
|
326
|
+
"z"=>"x",
|
327
|
+
"s"=>"v",
|
328
|
+
"t"=>"y"}, back, "back edges wrong")
|
329
|
+
assert_equal({
|
330
|
+
"q"=>"s",
|
331
|
+
"r"=>"y",
|
332
|
+
"t"=>"x",
|
333
|
+
"u"=>"y"}, cross, "cross edges wrong")
|
334
|
+
assert_equal({}, forward, "forward edges wrong")
|
335
|
+
end
|
336
|
+
|
337
|
+
# Sample Graph :
|
338
|
+
# +----------------+
|
339
|
+
# | |
|
340
|
+
# v |
|
341
|
+
# +---------(q)-->(t)------->(y)<----(r)
|
342
|
+
# | | | ^ |
|
343
|
+
# v | v | |
|
344
|
+
# +--(s)<--+ | (x)<---+ (u)<-----+
|
345
|
+
# | | | | |
|
346
|
+
# v | | v |
|
347
|
+
# (v)----->(w)<---+ (z)----+
|
348
|
+
|
349
|
+
def test_dijkstra
|
350
|
+
distances, predecessors = @graph.dijkstra('q')
|
351
|
+
assert_equal({
|
352
|
+
"v"=>2,
|
353
|
+
"w"=>1,
|
354
|
+
"x"=>2,
|
355
|
+
"y"=>2,
|
356
|
+
"z"=>3,
|
357
|
+
"q"=>0,
|
358
|
+
"r"=>TheInfinity,
|
359
|
+
"s"=>1,
|
360
|
+
"t"=>1,
|
361
|
+
"u"=>TheInfinity}, 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
|
+
|
375
|
+
def test_bellman_ford
|
376
|
+
distances, predecessors = @graph.bellman_ford('q')
|
377
|
+
assert_equal({
|
378
|
+
"v"=>2,
|
379
|
+
"w"=>1,
|
380
|
+
"x"=>2,
|
381
|
+
"y"=>2,
|
382
|
+
"z"=>3,
|
383
|
+
"q"=>0,
|
384
|
+
"r"=>TheInfinity,
|
385
|
+
"s"=>1,
|
386
|
+
"t"=>1,
|
387
|
+
"u"=>TheInfinity}, distances, "distances wrong")
|
388
|
+
assert_equal({
|
389
|
+
"v"=>"s",
|
390
|
+
"w"=>"q",
|
391
|
+
"x"=>"t",
|
392
|
+
"y"=>"t",
|
393
|
+
"z"=>"x",
|
394
|
+
"q"=>nil,
|
395
|
+
"r"=>nil,
|
396
|
+
"s"=>"q",
|
397
|
+
"t"=>"q",
|
398
|
+
"u"=>nil}, predecessors, "predecessors wrong")
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
class TestTopologicalSort < Test::Unit::TestCase
|
403
|
+
|
404
|
+
#
|
405
|
+
# Professor Bumstead topologically sorts his clothing when getting dressed.
|
406
|
+
#
|
407
|
+
# "undershorts" "socks"
|
408
|
+
# | | |
|
409
|
+
# v | v "watch"
|
410
|
+
# "pants" --+-------> "shoes"
|
411
|
+
# |
|
412
|
+
# v
|
413
|
+
# "belt" <----- "shirt" ----> "tie" ----> "jacket"
|
414
|
+
# | ^
|
415
|
+
# `---------------------------------------'
|
416
|
+
#
|
417
|
+
|
418
|
+
def test_dfs_topological_sort
|
419
|
+
dag = Pathway.new([
|
420
|
+
Relation.new("undershorts", "pants", true),
|
421
|
+
Relation.new("undershorts", "shoes", true),
|
422
|
+
Relation.new("socks", "shoes", true),
|
423
|
+
Relation.new("watch", "watch", true),
|
424
|
+
Relation.new("pants", "belt", true),
|
425
|
+
Relation.new("pants", "shoes", true),
|
426
|
+
Relation.new("shirt", "belt", true),
|
427
|
+
Relation.new("shirt", "tie", true),
|
428
|
+
Relation.new("tie", "jacket", true),
|
429
|
+
Relation.new("belt", "jacket", true),
|
430
|
+
])
|
431
|
+
sorted = dag.dfs_topological_sort
|
432
|
+
assert(sorted.index("socks") < sorted.index("shoes"), "socks >= shoes")
|
433
|
+
assert(sorted.index("undershorts") < sorted.index("pants"), "undershorts >= pants")
|
434
|
+
assert(sorted.index("undershorts") < sorted.index("shoes"), "undershorts >= shoes")
|
435
|
+
assert(sorted.index("pants") < sorted.index("shoes"), "pants >= shoes")
|
436
|
+
assert(sorted.index("pants") < sorted.index("belt"), "pants >= belt")
|
437
|
+
assert(sorted.index("shirt") < sorted.index("belt"), "shirt >= belt")
|
438
|
+
assert(sorted.index("shirt") < sorted.index("tie"), "shirt >= tie")
|
439
|
+
assert(sorted.index("belt") < sorted.index("jacket"), "belt >= jacket")
|
440
|
+
assert(sorted.index("tie") < sorted.index("jacket"), "tie >= jacket")
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
#TODO: verify the below
|
445
|
+
class TestWeightedGraph < Test::Unit::TestCase
|
446
|
+
|
447
|
+
# 'a' --> 'b'
|
448
|
+
# | 1 | 3
|
449
|
+
# |5 v
|
450
|
+
# `----> 'c'
|
451
|
+
|
452
|
+
def setup
|
453
|
+
r1 = Relation.new('a', 'b', 1)
|
454
|
+
r2 = Relation.new('a', 'c', 5)
|
455
|
+
r3 = Relation.new('b', 'c', 3)
|
456
|
+
@w_graph = Pathway.new([r1, r2, r3])
|
457
|
+
end
|
458
|
+
|
459
|
+
def test_dijkstra_on_weighted_graph
|
460
|
+
distances, predecessors = @w_graph.dijkstra('a')
|
461
|
+
assert_equal({
|
462
|
+
"a"=>0,
|
463
|
+
"b"=>1,
|
464
|
+
"c"=>4}, distances, "distances wrong")
|
465
|
+
assert_equal({
|
466
|
+
"a"=>nil,
|
467
|
+
"b"=>"a",
|
468
|
+
"c"=>"b"}, predecessors, "predecessors wrong")
|
469
|
+
end
|
470
|
+
|
471
|
+
def test_bellman_ford_on_negative_weighted_graph
|
472
|
+
|
473
|
+
# ,-- 'a' --> 'b'
|
474
|
+
# | | 1 | 3
|
475
|
+
# | |5 v
|
476
|
+
# | `----> 'c'
|
477
|
+
# | ^
|
478
|
+
# |2 | -5
|
479
|
+
# `--> 'd' ----'
|
480
|
+
|
481
|
+
r4 = Relation.new('a', 'd', 2)
|
482
|
+
r5 = Relation.new('d', 'c', -5)
|
483
|
+
@w_graph.append(r4)
|
484
|
+
@w_graph.append(r5)
|
485
|
+
distances, predecessors = @w_graph.bellman_ford('a')
|
486
|
+
assert_equal({
|
487
|
+
"a"=>0,
|
488
|
+
"b"=>1,
|
489
|
+
"c"=>-3,
|
490
|
+
"d"=>2}, distances, "distances wrong")
|
491
|
+
assert_equal({
|
492
|
+
"a"=>nil,
|
493
|
+
"b"=>"a",
|
494
|
+
"c"=>"d",
|
495
|
+
"d"=>"a"}, predecessors, "predecessors wrong")
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|