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,658 @@
|
|
1
|
+
#
|
2
|
+
# = bio/db/newick.rb - Newick Standard phylogenetic tree parser / formatter
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2004-2006
|
5
|
+
# Naohisa Goto <ng@bioruby.org>
|
6
|
+
# Daniel Amelang <dan@amelang.net>
|
7
|
+
# License:: The Ruby License
|
8
|
+
#
|
9
|
+
# $Id:$
|
10
|
+
#
|
11
|
+
# == Description
|
12
|
+
#
|
13
|
+
# This file contains parser and formatter of Newick and NHX.
|
14
|
+
#
|
15
|
+
# == References
|
16
|
+
#
|
17
|
+
# * http://evolution.genetics.washington.edu/phylip/newick_doc.html
|
18
|
+
# * http://www.phylosoft.org/forester/NHX.html
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'strscan'
|
22
|
+
require 'bio/tree'
|
23
|
+
|
24
|
+
module Bio
|
25
|
+
class Tree
|
26
|
+
|
27
|
+
#---
|
28
|
+
# newick output
|
29
|
+
#+++
|
30
|
+
|
31
|
+
# default options
|
32
|
+
DEFAULT_OPTIONS =
|
33
|
+
{ :indent => ' ' }
|
34
|
+
|
35
|
+
def __get_option(key, options)
|
36
|
+
if (r = options[key]) != nil then
|
37
|
+
r
|
38
|
+
elsif @options && (r = @options[key]) != nil then
|
39
|
+
r
|
40
|
+
else
|
41
|
+
DEFAULT_OPTIONS[key]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
private :__get_option
|
45
|
+
|
46
|
+
|
47
|
+
# formats Newick label (unquoted_label or quoted_label)
|
48
|
+
def __to_newick_format_label(str, options)
|
49
|
+
if __get_option(:parser, options) == :naive then
|
50
|
+
return str.to_s
|
51
|
+
end
|
52
|
+
str = str.to_s
|
53
|
+
if /([\(\)\,\:\[\]\_\'\x00-\x1f\x7f])/ =~ str then
|
54
|
+
# quoted_label
|
55
|
+
return "\'" + str.gsub(/\'/, "\'\'") + "\'"
|
56
|
+
end
|
57
|
+
# unquoted_label
|
58
|
+
return str.gsub(/ /, '_')
|
59
|
+
end
|
60
|
+
private :__to_newick_format_label
|
61
|
+
|
62
|
+
# formats leaf
|
63
|
+
def __to_newick_format_leaf(node, edge, options)
|
64
|
+
|
65
|
+
label = __to_newick_format_label(get_node_name(node), options)
|
66
|
+
|
67
|
+
dist = get_edge_distance_string(edge)
|
68
|
+
|
69
|
+
bs = get_node_bootstrap_string(node)
|
70
|
+
|
71
|
+
if __get_option(:branch_length_style, options) == :disabled
|
72
|
+
dist = nil
|
73
|
+
end
|
74
|
+
|
75
|
+
case __get_option(:bootstrap_style, options)
|
76
|
+
when :disabled
|
77
|
+
label + (dist ? ":#{dist}" : '')
|
78
|
+
when :molphy
|
79
|
+
label + (dist ? ":#{dist}" : '') + (bs ? "[#{bs}]" : '')
|
80
|
+
when :traditional
|
81
|
+
label + (bs ? bs : '') + (dist ? ":#{dist}" : '')
|
82
|
+
else
|
83
|
+
# default: same as molphy style
|
84
|
+
label + (dist ? ":#{dist}" : '') + (bs ? "[#{bs}]" : '')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
private :__to_newick_format_leaf
|
88
|
+
|
89
|
+
# formats leaf for NHX
|
90
|
+
def __to_newick_format_leaf_NHX(node, edge, options)
|
91
|
+
|
92
|
+
label = __to_newick_format_label(get_node_name(node), options)
|
93
|
+
|
94
|
+
dist = get_edge_distance_string(edge)
|
95
|
+
|
96
|
+
bs = get_node_bootstrap_string(node)
|
97
|
+
|
98
|
+
if __get_option(:branch_length_style, options) == :disabled
|
99
|
+
dist = nil
|
100
|
+
end
|
101
|
+
|
102
|
+
nhx = {}
|
103
|
+
|
104
|
+
# bootstrap
|
105
|
+
nhx[:B] = bs if bs and !(bs.empty?)
|
106
|
+
# EC number
|
107
|
+
nhx[:E] = node.ec_number if node.instance_eval {
|
108
|
+
defined?(@ec_number) && self.ec_number
|
109
|
+
}
|
110
|
+
# scientific name
|
111
|
+
nhx[:S] = node.scientific_name if node.instance_eval {
|
112
|
+
defined?(@scientific_name) && self.scientific_name
|
113
|
+
}
|
114
|
+
# taxonomy id
|
115
|
+
nhx[:T] = node.taxonomy_id if node.instance_eval {
|
116
|
+
defined?(@taxonomy_id) && self.taxonomy_id
|
117
|
+
}
|
118
|
+
|
119
|
+
# :D (gene duplication or speciation)
|
120
|
+
if node.instance_eval { defined?(@events) && !(self.events.empty?) } then
|
121
|
+
if node.events.include?(:gene_duplication)
|
122
|
+
nhx[:D] = 'Y'
|
123
|
+
elsif node.events.include?(:speciation)
|
124
|
+
nhx[:D] = 'N'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# log likelihood
|
129
|
+
nhx[:L] = edge.log_likelihood if edge.instance_eval {
|
130
|
+
defined?(@log_likelihood) && self.log_likelihood }
|
131
|
+
# width
|
132
|
+
nhx[:W] = edge.width if edge.instance_eval {
|
133
|
+
defined?(@width) && self.width }
|
134
|
+
|
135
|
+
# merges other parameters
|
136
|
+
flag = node.instance_eval { defined? @nhx_parameters }
|
137
|
+
nhx.merge!(node.nhx_parameters) if flag
|
138
|
+
flag = edge.instance_eval { defined? @nhx_parameters }
|
139
|
+
nhx.merge!(edge.nhx_parameters) if flag
|
140
|
+
|
141
|
+
nhx_string = nhx.keys.sort{ |a,b| a.to_s <=> b.to_s }.collect do |key|
|
142
|
+
"#{key.to_s}=#{nhx[key].to_s}"
|
143
|
+
end.join(':')
|
144
|
+
nhx_string = "[&&NHX:" + nhx_string + "]" unless nhx_string.empty?
|
145
|
+
|
146
|
+
label + (dist ? ":#{dist}" : '') + nhx_string
|
147
|
+
end
|
148
|
+
private :__to_newick_format_leaf_NHX
|
149
|
+
|
150
|
+
#
|
151
|
+
def __to_newick(parents, source, depth, format_leaf,
|
152
|
+
options, &block)
|
153
|
+
result = []
|
154
|
+
if indent_string = __get_option(:indent, options) then
|
155
|
+
indent0 = indent_string * depth
|
156
|
+
indent = indent_string * (depth + 1)
|
157
|
+
newline = "\n"
|
158
|
+
else
|
159
|
+
indent0 = indent = newline = ''
|
160
|
+
end
|
161
|
+
out_edges = self.out_edges(source)
|
162
|
+
if block_given? then
|
163
|
+
out_edges.sort! { |edge1, edge2| yield(edge1[1], edge2[1]) }
|
164
|
+
else
|
165
|
+
out_edges.sort! do |edge1, edge2|
|
166
|
+
o1 = edge1[1].order_number
|
167
|
+
o2 = edge2[1].order_number
|
168
|
+
if o1 and o2 then
|
169
|
+
o1 <=> o2
|
170
|
+
else
|
171
|
+
edge1[1].name.to_s <=> edge2[1].name.to_s
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
out_edges.each do |src, tgt, edge|
|
176
|
+
if parents.include?(tgt) then
|
177
|
+
;;
|
178
|
+
elsif self.out_degree(tgt) == 1 then
|
179
|
+
result << indent + __send__(format_leaf, tgt, edge, options)
|
180
|
+
else
|
181
|
+
result <<
|
182
|
+
__to_newick([ src ].concat(parents), tgt, depth + 1,
|
183
|
+
format_leaf, options) +
|
184
|
+
__send__(format_leaf, tgt, edge, options)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
indent0 + "(" + newline + result.join(',' + newline) +
|
188
|
+
(result.size > 0 ? newline : '') + indent0 + ')'
|
189
|
+
end
|
190
|
+
private :__to_newick
|
191
|
+
|
192
|
+
# Returns a newick formatted string.
|
193
|
+
# If block is given, the order of the node is sorted
|
194
|
+
# (as the same manner as Enumerable#sort).
|
195
|
+
#
|
196
|
+
# Available options:
|
197
|
+
# <tt>:indent</tt>::
|
198
|
+
# indent string; set false to disable (default: ' ')
|
199
|
+
# <tt>:bootstrap_style</tt>::
|
200
|
+
# <tt>:disabled</tt> disables bootstrap representations.
|
201
|
+
# <tt>:traditional</tt> for traditional style.
|
202
|
+
# <tt>:molphy</tt> for Molphy style (default).
|
203
|
+
def output_newick(options = {}, &block) #:yields: node1, node2
|
204
|
+
root = @root
|
205
|
+
root ||= self.nodes.first
|
206
|
+
return '();' unless root
|
207
|
+
__to_newick([], root, 0, :__to_newick_format_leaf, options, &block) +
|
208
|
+
__to_newick_format_leaf(root, Edge.new, options) +
|
209
|
+
";\n"
|
210
|
+
end
|
211
|
+
|
212
|
+
alias newick output_newick
|
213
|
+
|
214
|
+
|
215
|
+
# Returns a NHX (New Hampshire eXtended) formatted string.
|
216
|
+
# If block is given, the order of the node is sorted
|
217
|
+
# (as the same manner as Enumerable#sort).
|
218
|
+
#
|
219
|
+
# Available options:
|
220
|
+
# <tt>:indent</tt>::
|
221
|
+
# indent string; set false to disable (default: ' ')
|
222
|
+
#
|
223
|
+
def output_nhx(options = {}, &block) #:yields: node1, node2
|
224
|
+
root = @root
|
225
|
+
root ||= self.nodes.first
|
226
|
+
return '();' unless root
|
227
|
+
__to_newick([], root, 0,
|
228
|
+
:__to_newick_format_leaf_NHX, options, &block) +
|
229
|
+
__to_newick_format_leaf_NHX(root, Edge.new, options) +
|
230
|
+
";\n"
|
231
|
+
end
|
232
|
+
|
233
|
+
# Returns formatted text (or something) of the tree
|
234
|
+
# Currently supported format is: :newick, :nhx
|
235
|
+
def output(format, *arg, &block)
|
236
|
+
case format
|
237
|
+
when :newick
|
238
|
+
output_newick(*arg, &block)
|
239
|
+
when :nhx
|
240
|
+
output_nhx(*arg, &block)
|
241
|
+
when :phylip_distance_matrix
|
242
|
+
output_phylip_distance_matrix(*arg, &block)
|
243
|
+
else
|
244
|
+
raise 'Unknown format'
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
#---
|
249
|
+
# This method isn't suitable to written in this file?
|
250
|
+
#+++
|
251
|
+
|
252
|
+
# Generates phylip-style distance matrix as a string.
|
253
|
+
# if nodes is not given, all leaves in the tree are used.
|
254
|
+
# If the names of some of the given (or default) nodes
|
255
|
+
# are not defined or are empty, the names are automatically generated.
|
256
|
+
def output_phylip_distance_matrix(nodes = nil, options = {})
|
257
|
+
nodes = self.leaves unless nodes
|
258
|
+
names = nodes.collect do |x|
|
259
|
+
y = get_node_name(x)
|
260
|
+
y = sprintf("%x", x.__id__.abs) if y.empty?
|
261
|
+
y
|
262
|
+
end
|
263
|
+
m = self.distance_matrix(nodes)
|
264
|
+
Bio::Phylip::DistanceMatrix.generate(m, names, options)
|
265
|
+
end
|
266
|
+
|
267
|
+
end #class Tree
|
268
|
+
|
269
|
+
#---
|
270
|
+
# newick parser
|
271
|
+
#+++
|
272
|
+
|
273
|
+
# Newick standard phylogenetic tree parser class.
|
274
|
+
#
|
275
|
+
# This is alpha version. Incompatible changes may be made frequently.
|
276
|
+
class Newick
|
277
|
+
|
278
|
+
# delemiter of the entry
|
279
|
+
DELIMITER = RS = ";"
|
280
|
+
|
281
|
+
# parse error class
|
282
|
+
class ParseError < RuntimeError; end
|
283
|
+
|
284
|
+
# same as Bio::Tree::Edge
|
285
|
+
Edge = Bio::Tree::Edge
|
286
|
+
|
287
|
+
# same as Bio::Tree::Node
|
288
|
+
Node = Bio::Tree::Node
|
289
|
+
|
290
|
+
# Creates a new Newick object.
|
291
|
+
# _options_ for parsing can be set.
|
292
|
+
#
|
293
|
+
# Available options:
|
294
|
+
# <tt>:bootstrap_style</tt>::
|
295
|
+
# <tt>:traditional</tt> for traditional bootstrap style,
|
296
|
+
# <tt>:molphy</tt> for molphy style,
|
297
|
+
# <tt>:disabled</tt> to ignore bootstrap strings.
|
298
|
+
# For details of default actions, please read the notes below.
|
299
|
+
# <tt>:parser</tt>::
|
300
|
+
# <tt>:naive</tt> for using naive parser, compatible with
|
301
|
+
# BioRuby 1.1.0, which ignores quoted strings and
|
302
|
+
# do not convert underscores to spaces.
|
303
|
+
#
|
304
|
+
# Notes for bootstrap style:
|
305
|
+
# Molphy-style bootstrap values may always be parsed, even if
|
306
|
+
# the <tt>options[:bootstrap_style]</tt> is set to
|
307
|
+
# <tt>:traditional</tt> or <tt>:disabled</tt>.
|
308
|
+
#
|
309
|
+
# Note for default or traditional bootstrap style:
|
310
|
+
# By default, if all of the internal node's names are numeric
|
311
|
+
# and there are no NHX and no molphy-style boostrap values,
|
312
|
+
# the names of internal nodes are regarded as bootstrap values.
|
313
|
+
# <tt>options[:bootstrap_style] = :disabled</tt> or <tt>:molphy</tt>
|
314
|
+
# to disable the feature (or at least one NHX tag exists).
|
315
|
+
def initialize(str, options = nil)
|
316
|
+
str = str.sub(/\;(.*)/m, ';')
|
317
|
+
@original_string = str
|
318
|
+
@entry_overrun = $1
|
319
|
+
@options = (options or {})
|
320
|
+
end
|
321
|
+
|
322
|
+
# parser options
|
323
|
+
# (in some cases, options can be automatically set by the parser)
|
324
|
+
attr_reader :options
|
325
|
+
|
326
|
+
# original string before parsing
|
327
|
+
attr_reader :original_string
|
328
|
+
|
329
|
+
# string after this entry
|
330
|
+
attr_reader :entry_overrun
|
331
|
+
|
332
|
+
# Gets the tree.
|
333
|
+
# Returns a Bio::Tree object.
|
334
|
+
def tree
|
335
|
+
if !defined?(@tree)
|
336
|
+
@tree = __parse_newick(@original_string, @options)
|
337
|
+
else
|
338
|
+
@tree
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
# Re-parses the tree from the original string.
|
343
|
+
# Returns self.
|
344
|
+
# This method is useful after changing parser options.
|
345
|
+
def reparse
|
346
|
+
remove_instance_variable(:tree)
|
347
|
+
self.tree
|
348
|
+
self
|
349
|
+
end
|
350
|
+
|
351
|
+
private
|
352
|
+
|
353
|
+
# gets a option
|
354
|
+
def __get_option(key, options)
|
355
|
+
options[key] or (@options ? @options[key] : nil)
|
356
|
+
end
|
357
|
+
|
358
|
+
# Parses newick formatted leaf (or internal node) name.
|
359
|
+
def __parse_newick_leaf(leaf_tokens, node, edge, options)
|
360
|
+
t = leaf_tokens.shift
|
361
|
+
if !t.kind_of?(Symbol) then
|
362
|
+
node.name = t
|
363
|
+
t = leaf_tokens.shift
|
364
|
+
end
|
365
|
+
|
366
|
+
if t == :':' then
|
367
|
+
t = leaf_tokens.shift
|
368
|
+
if !t.kind_of?(Symbol) then
|
369
|
+
edge.distance_string = t if t and !(t.strip.empty?)
|
370
|
+
t = leaf_tokens.shift
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
if t == :'[' then
|
375
|
+
btokens = leaf_tokens
|
376
|
+
case __get_option(:original_format, options)
|
377
|
+
when :nhx
|
378
|
+
# regarded as NHX string which might be broken
|
379
|
+
__parse_nhx(btokens, node, edge)
|
380
|
+
when :traditional
|
381
|
+
# simply ignored
|
382
|
+
else
|
383
|
+
case btokens[0].to_s.strip
|
384
|
+
when ''
|
385
|
+
# not automatically determined
|
386
|
+
when /\A\&\&NHX/
|
387
|
+
# NHX string
|
388
|
+
# force to set NHX mode
|
389
|
+
@options[:original_format] = :nhx
|
390
|
+
__parse_nhx(btokens, node, edge)
|
391
|
+
else
|
392
|
+
# Molphy-style boostrap values
|
393
|
+
# let molphy mode if nothing determined
|
394
|
+
@options[:original_format] ||= :molphy
|
395
|
+
bstr = ''
|
396
|
+
while t = btokens.shift and t != :']'
|
397
|
+
bstr.concat t.to_s
|
398
|
+
end
|
399
|
+
node.bootstrap_string = bstr
|
400
|
+
end #case btokens[0]
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
if !btokens and !leaf_tokens.empty? then
|
405
|
+
# syntax error?
|
406
|
+
end
|
407
|
+
node.name ||= '' # compatibility for older BioRuby
|
408
|
+
|
409
|
+
# returns true
|
410
|
+
true
|
411
|
+
end
|
412
|
+
|
413
|
+
# Parses NHX (New Hampshire eXtended) string
|
414
|
+
def __parse_nhx(btokens, node, edge)
|
415
|
+
btokens.shift if btokens[0] == '&&NHX'
|
416
|
+
btokens.each do |str|
|
417
|
+
break if str == :']'
|
418
|
+
next if str.kind_of?(Symbol)
|
419
|
+
tag, val = str.split(/\=/, 2)
|
420
|
+
case tag
|
421
|
+
when 'B'
|
422
|
+
node.bootstrap_string = val
|
423
|
+
when 'D'
|
424
|
+
case val
|
425
|
+
when 'Y'
|
426
|
+
node.events.push :gene_duplication
|
427
|
+
when 'N'
|
428
|
+
node.events.push :speciation
|
429
|
+
end
|
430
|
+
when 'E'
|
431
|
+
node.ec_number = val
|
432
|
+
when 'L'
|
433
|
+
edge.log_likelihood = val.to_f
|
434
|
+
when 'S'
|
435
|
+
node.scientific_name = val
|
436
|
+
when 'T'
|
437
|
+
node.taxonomy_id = val
|
438
|
+
when 'W'
|
439
|
+
edge.width = val.to_i
|
440
|
+
when 'XB'
|
441
|
+
edge.nhx_parameters[:XB] = val
|
442
|
+
when 'O', 'SO'
|
443
|
+
node.nhx_parameters[tag.to_sym] = val.to_i
|
444
|
+
else # :Co, :SN, :Sw, :XN, and others
|
445
|
+
node.nhx_parameters[tag.to_sym] = val
|
446
|
+
end
|
447
|
+
end #each
|
448
|
+
true
|
449
|
+
end
|
450
|
+
|
451
|
+
# splits string to tokens
|
452
|
+
def __parse_newick_tokenize(str, options)
|
453
|
+
str = str.chop if str[-1..-1] == ';'
|
454
|
+
# http://evolution.genetics.washington.edu/phylip/newick_doc.html
|
455
|
+
# quoted_label ==> ' string_of_printing_characters '
|
456
|
+
# single quote in quoted_label is '' (two single quotes)
|
457
|
+
#
|
458
|
+
|
459
|
+
if __get_option(:parser, options) == :naive then
|
460
|
+
ary = str.split(/([\(\)\,\:\[\]])/)
|
461
|
+
ary.collect! { |x| x.strip!; x.empty? ? nil : x }
|
462
|
+
ary.compact!
|
463
|
+
ary.collect! do |x|
|
464
|
+
if /\A([\(\)\,\:\[\]])\z/ =~ x then
|
465
|
+
x.intern
|
466
|
+
else
|
467
|
+
x
|
468
|
+
end
|
469
|
+
end
|
470
|
+
return ary
|
471
|
+
end
|
472
|
+
|
473
|
+
tokens = []
|
474
|
+
ss = StringScanner.new(str)
|
475
|
+
|
476
|
+
while !(ss.eos?)
|
477
|
+
if ss.scan(/\s+/) then
|
478
|
+
# do nothing
|
479
|
+
|
480
|
+
elsif ss.scan(/[\(\)\,\:\[\]]/) then
|
481
|
+
# '(' or ')' or ',' or ':' or '[' or ']'
|
482
|
+
t = ss.matched
|
483
|
+
tokens.push t.intern
|
484
|
+
|
485
|
+
elsif ss.scan(/\'/) then
|
486
|
+
# quoted_label
|
487
|
+
t = ''
|
488
|
+
while true
|
489
|
+
if ss.scan(/([^\']*)\'/) then
|
490
|
+
t.concat ss[1]
|
491
|
+
if ss.scan(/\'/) then
|
492
|
+
# single quote in quoted_label
|
493
|
+
t.concat ss.matched
|
494
|
+
else
|
495
|
+
break
|
496
|
+
end
|
497
|
+
else
|
498
|
+
# incomplete quoted_label?
|
499
|
+
break
|
500
|
+
end
|
501
|
+
end #while true
|
502
|
+
unless ss.match?(/\s*[\(\)\,\:\[\]]/) or ss.match?(/\s*\z/) then
|
503
|
+
# label continues? (illegal, but try to rescue)
|
504
|
+
if ss.scan(/[^\(\)\,\:\[\]]+/) then
|
505
|
+
t.concat ss.matched.lstrip
|
506
|
+
end
|
507
|
+
end
|
508
|
+
tokens.push t
|
509
|
+
|
510
|
+
elsif ss.scan(/[^\(\)\,\:\[\]]+/) then
|
511
|
+
# unquoted_label
|
512
|
+
t = ss.matched.strip
|
513
|
+
t.gsub!(/[\r\n]/, '')
|
514
|
+
# unquoted underscore should be converted to blank
|
515
|
+
t.gsub!(/\_/, ' ')
|
516
|
+
tokens.push t unless t.empty?
|
517
|
+
|
518
|
+
else
|
519
|
+
# unquoted_label in end of string
|
520
|
+
t = ss.rest.strip
|
521
|
+
t.gsub!(/[\r\n]/, '')
|
522
|
+
# unquoted underscore should be converted to blank
|
523
|
+
t.gsub!(/\_/, ' ')
|
524
|
+
tokens.push t unless t.empty?
|
525
|
+
ss.terminate
|
526
|
+
|
527
|
+
end
|
528
|
+
end #while !(ss.eos?)
|
529
|
+
|
530
|
+
tokens
|
531
|
+
end
|
532
|
+
|
533
|
+
# get tokens for a leaf
|
534
|
+
def __parse_newick_get_tokens_for_leaf(ary)
|
535
|
+
r = []
|
536
|
+
while t = ary[0] and t != :',' and t != :')' and t != :'('
|
537
|
+
r.push ary.shift
|
538
|
+
end
|
539
|
+
r
|
540
|
+
end
|
541
|
+
|
542
|
+
# Parses newick formatted string.
|
543
|
+
def __parse_newick(str, options = {})
|
544
|
+
# initializing
|
545
|
+
root = Node.new
|
546
|
+
cur_node = root
|
547
|
+
edges = []
|
548
|
+
nodes = [ root ]
|
549
|
+
internal_nodes = []
|
550
|
+
node_stack = []
|
551
|
+
# preparation of tokens
|
552
|
+
ary = __parse_newick_tokenize(str, options)
|
553
|
+
previous_token = nil
|
554
|
+
# main loop
|
555
|
+
while token = ary.shift
|
556
|
+
#p token
|
557
|
+
case token
|
558
|
+
when :','
|
559
|
+
if previous_token == :',' or previous_token == :'(' then
|
560
|
+
# there is a leaf whose name is empty.
|
561
|
+
ary.unshift(token)
|
562
|
+
ary.unshift('')
|
563
|
+
token = nil
|
564
|
+
end
|
565
|
+
when :'('
|
566
|
+
node = Node.new
|
567
|
+
nodes << node
|
568
|
+
internal_nodes << node
|
569
|
+
node_stack.push(cur_node)
|
570
|
+
cur_node = node
|
571
|
+
when :')'
|
572
|
+
if previous_token == :',' or previous_token == :'(' then
|
573
|
+
# there is a leaf whose name is empty.
|
574
|
+
ary.unshift(token)
|
575
|
+
ary.unshift('')
|
576
|
+
token = nil
|
577
|
+
else
|
578
|
+
edge = Edge.new
|
579
|
+
leaf_tokens = __parse_newick_get_tokens_for_leaf(ary)
|
580
|
+
token = nil
|
581
|
+
if leaf_tokens.size > 0 then
|
582
|
+
__parse_newick_leaf(leaf_tokens, cur_node, edge, options)
|
583
|
+
end
|
584
|
+
parent = node_stack.pop
|
585
|
+
raise ParseError, 'unmatched parentheses' unless parent
|
586
|
+
edges << Bio::Relation.new(parent, cur_node, edge)
|
587
|
+
cur_node = parent
|
588
|
+
end
|
589
|
+
else
|
590
|
+
leaf = Node.new
|
591
|
+
edge = Edge.new
|
592
|
+
ary.unshift(token)
|
593
|
+
leaf_tokens = __parse_newick_get_tokens_for_leaf(ary)
|
594
|
+
token = nil
|
595
|
+
__parse_newick_leaf(leaf_tokens, leaf, edge, options)
|
596
|
+
nodes << leaf
|
597
|
+
edges << Bio::Relation.new(cur_node, leaf, edge)
|
598
|
+
end #case
|
599
|
+
previous_token = token
|
600
|
+
end #while
|
601
|
+
raise ParseError, 'unmatched parentheses' unless node_stack.empty?
|
602
|
+
bsopt = __get_option(:bootstrap_style, options)
|
603
|
+
ofmt = __get_option(:original_format, options)
|
604
|
+
unless bsopt == :disabled or bsopt == :molphy or
|
605
|
+
ofmt == :nhx or ofmt == :molphy then
|
606
|
+
# If all of the internal node's names are numeric,
|
607
|
+
# the names are regarded as bootstrap values.
|
608
|
+
flag = false
|
609
|
+
internal_nodes.each do |inode|
|
610
|
+
if inode.name and !inode.name.to_s.strip.empty? then
|
611
|
+
if /\A[\+\-]?\d*\.?\d*\z/ =~ inode.name
|
612
|
+
flag = true
|
613
|
+
else
|
614
|
+
flag = false
|
615
|
+
break
|
616
|
+
end
|
617
|
+
end
|
618
|
+
end
|
619
|
+
if flag then
|
620
|
+
@options[:bootstrap_style] = :traditional
|
621
|
+
@options[:original_format] = :traditional
|
622
|
+
internal_nodes.each do |inode|
|
623
|
+
if inode.name then
|
624
|
+
inode.bootstrap_string = inode.name
|
625
|
+
inode.name = nil
|
626
|
+
end
|
627
|
+
end
|
628
|
+
end
|
629
|
+
end
|
630
|
+
# Sets nodes order numbers
|
631
|
+
nodes.each_with_index do |xnode, i|
|
632
|
+
xnode.order_number = i
|
633
|
+
end
|
634
|
+
# If the root implicitly prepared by the program is a leaf and
|
635
|
+
# there are no additional information for the edge from the root to
|
636
|
+
# the first internal node, the root is removed.
|
637
|
+
if rel = edges[-1] and rel.node == [ root, internal_nodes[0] ] and
|
638
|
+
rel.relation.instance_eval {
|
639
|
+
!defined?(@distance) and !defined?(@log_likelihood) and
|
640
|
+
!defined?(@width) and !defined?(@nhx_parameters) } and
|
641
|
+
edges.find_all { |x| x.node.include?(root) }.size == 1
|
642
|
+
nodes.shift
|
643
|
+
edges.pop
|
644
|
+
end
|
645
|
+
# Let the tree into instance variables
|
646
|
+
tree = Bio::Tree.new
|
647
|
+
tree.instance_eval {
|
648
|
+
@pathway.relations.concat(edges)
|
649
|
+
@pathway.to_list
|
650
|
+
}
|
651
|
+
tree.root = nodes[0]
|
652
|
+
tree.options.update(@options)
|
653
|
+
tree
|
654
|
+
end
|
655
|
+
end #class Newick
|
656
|
+
|
657
|
+
end #module Bio
|
658
|
+
|