### Home Classes Methods

### In Files

- lib/bio/tree/output.rb
- lib/bio/tree.rb

### Parent

Object

### Namespace

- CLASS Bio::Tree::Edge
- CLASS Bio::Tree::NoPathError
- CLASS Bio::Tree::Node

### Methods

- ::new
- #add_edge
- #add_node
- #adjacency_matrix
- #adjacent_nodes
- #ancestors
- #children
- #clear
- #clear_node
- #collect_edge!
- #collect_node!
- #concat
- #descendents
- #distance
- #distance_matrix
- #each_edge
- #each_edge_in_path
- #each_node
- #each_out_edge
- #edges
- #get_edge
- #get_edge_distance
- #get_edge_distance_string
- #get_edge_merged
- #get_node_bootstrap
- #get_node_bootstrap_string
- #get_node_by_name
- #get_node_name
- #include?
- #insert_node
- #leaves
- #lowest_common_ancestor
- #newick
- #nodes
- #number_of_edges
- #number_of_nodes
- #out_degree
- #out_edges
- #output
- #output_newick
- #output_nhx
- #output_phylip_distance_matrix
- #parent
- #path
- #remove_edge
- #remove_edge_if
- #remove_node
- #remove_node_if
- #remove_nonsense_nodes
- #subtree
- #subtree_with_all_paths
- #total_distance

### Files

- KNOWN_ISSUES.rdoc
- README.rdoc
- README_DEV.rdoc
- RELEASE_NOTES.rdoc
- Changes-1.3.rdoc
- RELEASE_NOTES-1.4.0.rdoc
- RELEASE_NOTES-1.4.1.rdoc
- RELEASE_NOTES-1.4.2.rdoc

### Class/Module Index

Quicksearch

- Bio
- Bio::AAindex
- Bio::AAindex1
- Bio::AAindex2
- Bio::Abif
- Bio::Abif::DirectoryEntry
- Bio::Alignment
- Bio::Alignment::ArrayExtension
- Bio::Alignment::EnumerableExtension
- Bio::Alignment::FactoryTemplate
- Bio::Alignment::FactoryTemplate::FileInFileOut
- Bio::Alignment::FactoryTemplate::FileInFileOutWithTree
- Bio::Alignment::FactoryTemplate::FileInStdoutOut
- Bio::Alignment::FactoryTemplate::Simple
- Bio::Alignment::FactoryTemplate::StdinInFileOut
- Bio::Alignment::FactoryTemplate::WrapInputStdin
- Bio::Alignment::FactoryTemplate::WrapInputTempfile
- Bio::Alignment::FactoryTemplate::WrapOutputStdout
- Bio::Alignment::FactoryTemplate::WrapOutputTempfile
- Bio::Alignment::GAP
- Bio::Alignment::HashExtension
- Bio::Alignment::MultiFastaFormat
- Bio::Alignment::OriginalAlignment
- Bio::Alignment::OriginalPrivate
- Bio::Alignment::Output
- Bio::Alignment::PropertyMethods
- Bio::Alignment::SequenceArray
- Bio::Alignment::SequenceHash
- Bio::Alignment::Site
- Bio::Alignment::SiteMethods
- Bio::AminoAcid
- Bio::AminoAcid::Data
- Bio::Blast
- Bio::Blast::Bl2seq
- Bio::Blast::Bl2seq::Report
- Bio::Blast::Bl2seq::Report::HSP
- Bio::Blast::Bl2seq::Report::Hit
- Bio::Blast::Bl2seq::Report::Iteration
- Bio::Blast::Default
- Bio::Blast::Default::Report
- Bio::Blast::Default::Report::HSP
- Bio::Blast::Default::Report::Hit
- Bio::Blast::Default::Report::Iteration
- Bio::Blast::Default::Report_TBlast
- Bio::Blast::Fastacmd
- Bio::Blast::NCBIOptions
- Bio::Blast::RPSBlast
- Bio::Blast::RPSBlast::RPSBlastSplitter
- Bio::Blast::RPSBlast::Report
- Bio::Blast::RPSBlast::Report::FLATFILE_SPLITTER
- Bio::Blast::RPSBlast::Report::Iteration
- Bio::Blast::Remote
- Bio::Blast::Remote::DDBJ
- Bio::Blast::Remote::DDBJ::Information
- Bio::Blast::Remote::Ddbj
- Bio::Blast::Remote::GenomeNet
- Bio::Blast::Remote::GenomeNet::Information
- Bio::Blast::Remote::Genomenet
- Bio::Blast::Remote::Information
- Bio::Blast::Report
- Bio::Blast::Report::BlastXmlSplitter
- Bio::Blast::Report::FLATFILE_SPLITTER
- Bio::Blast::Report::Hit
- Bio::Blast::Report::Hsp
- Bio::Blast::Report::Iteration
- Bio::Blast::Report_tab
- Bio::Blast::WU
- Bio::Blast::WU::Report
- Bio::Blast::WU::Report::HSP
- Bio::Blast::WU::Report::Hit
- Bio::Blast::WU::Report::Iteration
- Bio::Blast::WU::Report_TBlast
- Bio::Blat
- Bio::Blat::Report
- Bio::Blat::Report::Hit
- Bio::Blat::Report::SegmentPair
- Bio::Blat::Report::SeqDesc
- Bio::ClustalW
- Bio::ClustalW::Report
- Bio::CodonTable
- Bio::ColorScheme
- Bio::Command
- Bio::Command::Tmpdir
- Bio::Command::Tmpdir::Remover
- Bio::ContingencyTable
- Bio::DAS
- Bio::DAS::DNA
- Bio::DAS::DSN
- Bio::DAS::ENTRY_POINT
- Bio::DAS::FEATURE
- Bio::DAS::GFF
- Bio::DAS::GROUP
- Bio::DAS::LINK
- Bio::DAS::SEGMENT
- Bio::DAS::SEQUENCE
- Bio::DAS::TARGET
- Bio::DAS::TYPE
- Bio::DAS::TYPES
- Bio::DB
- Bio::DBGET
- Bio::DDBJ
- Bio::DDBJ::REST
- Bio::DDBJ::REST::Blast
- Bio::DDBJ::REST::ClustalW
- Bio::DDBJ::REST::DDBJ
- Bio::DDBJ::REST::Mafft
- Bio::DDBJ::REST::RequestManager
- Bio::DDBJ::REST::WABItemplate
- Bio::DDBJ::XML
- Bio::DDBJ::XML::Blast
- Bio::DDBJ::XML::ClustalW
- Bio::DDBJ::XML::DDBJ
- Bio::DDBJ::XML::Fasta
- Bio::DDBJ::XML::GetEntry
- Bio::DDBJ::XML::Gib
- Bio::DDBJ::XML::Gtop
- Bio::DDBJ::XML::PML
- Bio::DDBJ::XML::RequestManager
- Bio::DDBJ::XML::RequestManager::REST
- Bio::DDBJ::XML::SRS
- Bio::DDBJ::XML::TxSearch
- Bio::EBI
- Bio::EBI::SOAP
- Bio::EBI::SOAP::Citation
- Bio::EBI::SOAP::ClustalW
- Bio::EBI::SOAP::Dbfetch
- Bio::EBI::SOAP::Emboss
- Bio::EBI::SOAP::Fasta
- Bio::EBI::SOAP::InterProScan
- Bio::EBI::SOAP::MPsrch
- Bio::EBI::SOAP::MSD
- Bio::EBI::SOAP::Muscle
- Bio::EBI::SOAP::Ontology
- Bio::EBI::SOAP::ScanPS
- Bio::EBI::SOAP::TCoffee
- Bio::EBI::SOAP::WUBlast
- Bio::EMBL
- Bio::EMBLDB
- Bio::EMBLDB::Common
- Bio::EMBOSS
- Bio::Ensembl
- Bio::Ensembl::Base
- Bio::Ensembl::Human
- Bio::Ensembl::Mouse
- Bio::FANTOM
- Bio::FANTOM::MaXML
- Bio::FANTOM::MaXML::Annotation
- Bio::FANTOM::MaXML::Annotation::DataSrc
- Bio::FANTOM::MaXML::Annotations
- Bio::FANTOM::MaXML::Cluster
- Bio::FANTOM::MaXML::Sequence
- Bio::FANTOM::MaXML::Sequences
- Bio::Fasta
- Bio::Fasta::Report
- Bio::Fasta::Report::FLATFILE_SPLITTER
- Bio::Fasta::Report::FastaFormat10Splitter
- Bio::Fasta::Report::Hit
- Bio::Fasta::Report::Hit::Query
- Bio::Fasta::Report::Hit::Target
- Bio::Fasta::Report::Program
- Bio::FastaDefline
- Bio::FastaFormat
- Bio::FastaNumericFormat
- Bio::Fastq
- Bio::Fastq::Error
- Bio::Fastq::Error::Diff_ids
- Bio::Fastq::Error::Long_qual
- Bio::Fastq::Error::No_atmark
- Bio::Fastq::Error::No_ids
- Bio::Fastq::Error::No_qual
- Bio::Fastq::Error::No_seq
- Bio::Fastq::Error::Qual_char
- Bio::Fastq::Error::Qual_range
- Bio::Fastq::Error::Seq_char
- Bio::Fastq::Error::Short_qual
- Bio::Fastq::Error::Skipped_unformatted_lines
- Bio::Fastq::FormatData
- Bio::Fastq::FormatData::FASTQ_ILLUMINA
- Bio::Fastq::FormatData::FASTQ_SANGER
- Bio::Fastq::FormatData::FASTQ_SOLEXA
- Bio::Feature
- Bio::Feature::Qualifier
- Bio::Features
- Bio::Fetch
- Bio::FlatFile
- Bio::FlatFile::AutoDetect
- Bio::FlatFile::AutoDetect::RuleDebug
- Bio::FlatFile::AutoDetect::RuleProc
- Bio::FlatFile::AutoDetect::RuleRegexp
- Bio::FlatFile::AutoDetect::RuleRegexp2
- Bio::FlatFile::AutoDetect::RuleSpecial
- Bio::FlatFile::AutoDetect::RuleTemplate
- Bio::FlatFile::AutoDetect::RulesArray
- Bio::FlatFile::BufferedInputStream
- Bio::FlatFile::Splitter
- Bio::FlatFile::Splitter::Default
- Bio::FlatFile::Splitter::LineOriented
- Bio::FlatFile::Splitter::Template
- Bio::FlatFile::UnknownDataFormatError
- Bio::FlatFileIndex
- Bio::FlatFileIndex::BDB_1
- Bio::FlatFileIndex::BDB_1::BDBMappingFile
- Bio::FlatFileIndex::BDB_1::PrimaryNameSpace
- Bio::FlatFileIndex::BDB_1::SecondaryNameSpace
- Bio::FlatFileIndex::BDBdefault
- Bio::FlatFileIndex::BDBwrapper
- Bio::FlatFileIndex::DEBUG
- Bio::FlatFileIndex::DataBank
- Bio::FlatFileIndex::FileID
- Bio::FlatFileIndex::FileIDs
- Bio::FlatFileIndex::Flat_1
- Bio::FlatFileIndex::Flat_1::FlatMappingFile
- Bio::FlatFileIndex::Flat_1::PrimaryNameSpace
- Bio::FlatFileIndex::Flat_1::Record
- Bio::FlatFileIndex::Flat_1::SecondaryNameSpace
- Bio::FlatFileIndex::Indexer
- Bio::FlatFileIndex::Indexer::NameSpace
- Bio::FlatFileIndex::Indexer::NameSpaces
- Bio::FlatFileIndex::Indexer::Parser
- Bio::FlatFileIndex::Indexer::Parser::BlastDefaultParser
- Bio::FlatFileIndex::Indexer::Parser::EMBLParser
- Bio::FlatFileIndex::Indexer::Parser::FastaFormatParser
- Bio::FlatFileIndex::Indexer::Parser::GenBankParser
- Bio::FlatFileIndex::Indexer::Parser::GenPeptParser
- Bio::FlatFileIndex::Indexer::Parser::MaXMLClusterParser
- Bio::FlatFileIndex::Indexer::Parser::MaXMLSequenceParser
- Bio::FlatFileIndex::Indexer::Parser::PDBChemicalComponentParser
- Bio::FlatFileIndex::Indexer::Parser::SPTRParser
- Bio::FlatFileIndex::Indexer::Parser::TemplateParser
- Bio::FlatFileIndex::NameSpaces
- Bio::FlatFileIndex::Results
- Bio::FlatFileIndex::Template
- Bio::FlatFileIndex::Template::NameSpace
- Bio::GCG
- Bio::GCG::Msf
- Bio::GCG::Seq
- Bio::GFF
- Bio::GFF::GFF2
- Bio::GFF::GFF2::Escape
- Bio::GFF::GFF2::MetaData
- Bio::GFF::GFF2::Record
- Bio::GFF::GFF2::Record::Value
- Bio::GFF::GFF3
- Bio::GFF::GFF3::Escape
- Bio::GFF::GFF3::Record
- Bio::GFF::GFF3::Record::Gap
- Bio::GFF::GFF3::Record::Gap::Code
- Bio::GFF::GFF3::Record::Target
- Bio::GFF::GFF3::RecordBoundary
- Bio::GFF::GFF3::SequenceRegion
- Bio::GFF::Record
- Bio::GO
- Bio::GO::External2go
- Bio::GO::GeneAssociation
- Bio::GO::Ontology
- Bio::GenBank
- Bio::GenBank::Locus
- Bio::GenPept
- Bio::GenPept::Locus
- Bio::Genscan
- Bio::Genscan::Report
- Bio::Genscan::Report::Exon
- Bio::Genscan::Report::Gene
- Bio::HGC
- Bio::HGC::HiGet
- Bio::HMMER
- Bio::HMMER::Report
- Bio::HMMER::Report::Hit
- Bio::HMMER::Report::Hsp
- Bio::Hinv
- Bio::Hinv::Acc2hit
- Bio::Hinv::Common
- Bio::Hinv::Hit2acc
- Bio::Hinv::HitCnt
- Bio::Hinv::HitDefinition
- Bio::Hinv::HitPubmedId
- Bio::Hinv::HitXML
- Bio::Hinv::Hix2hit
- Bio::Hinv::HixCnt
- Bio::Hinv::HixRepresent
- Bio::Hinv::HixXML
- Bio::Hinv::IdSearch
- Bio::Hinv::KeywordSearch
- Bio::Iprscan
- Bio::Iprscan::Report
- Bio::Iprscan::Report::Match
- Bio::KEGG
- Bio::KEGG::API
- Bio::KEGG::BRITE
- Bio::KEGG::COMPOUND
- Bio::KEGG::Common
- Bio::KEGG::Common::DblinksAsHash
- Bio::KEGG::Common::GenesAsHash
- Bio::KEGG::Common::ModulesAsHash
- Bio::KEGG::Common::OrthologsAsHash
- Bio::KEGG::Common::PathwaysAsHash
- Bio::KEGG::Common::References
- Bio::KEGG::Common::StringsAsHash
- Bio::KEGG::DRUG
- Bio::KEGG::ENZYME
- Bio::KEGG::EXPRESSION
- Bio::KEGG::GENES
- Bio::KEGG::GENOME
- Bio::KEGG::GLYCAN
- Bio::KEGG::KGML
- Bio::KEGG::KGML::Entry
- Bio::KEGG::KGML::Graphics
- Bio::KEGG::KGML::Product
- Bio::KEGG::KGML::Reaction
- Bio::KEGG::KGML::Relation
- Bio::KEGG::KGML::Substrate
- Bio::KEGG::KGML::SubstrateProduct
- Bio::KEGG::Keggtab
- Bio::KEGG::Keggtab::DB
- Bio::KEGG::MODULE
- Bio::KEGG::ORTHOLOGY
- Bio::KEGG::PATHWAY
- Bio::KEGG::REACTION
- Bio::KEGG::Taxonomy
- Bio::KEGGDB
- Bio::LITDB
- Bio::Lasergene
- Bio::Location
- Bio::Locations
- Bio::MAFFT
- Bio::MAFFT::Report
- Bio::MEDLINE
- Bio::Map
- Bio::Map::ActsLikeMap
- Bio::Map::ActsLikeMarker
- Bio::Map::Mapping
- Bio::Map::Marker
- Bio::Map::SimpleMap
- Bio::Meme
- Bio::Meme::Mast
- Bio::Meme::Mast::Report
- Bio::Meme::Motif
- Bio::Muscle
- Bio::Muscle::DEFAULT_PARSER
- Bio::NBRF
- Bio::NCBI
- Bio::NCBI::REST
- Bio::NCBI::REST::EFetch
- Bio::NCBI::REST::EFetch::Methods
- Bio::NCBI::REST::ESearch
- Bio::NCBI::REST::ESearch::Methods
- Bio::NCBI::SOAP
- Bio::NCBI::SOAP::EFetch
- Bio::NCBI::SOAP::EFetchLite
- Bio::NCBI::SOAP::EUtils
- Bio::NCBI::SOAP::EUtilsLite
- Bio::NCBIDB
- Bio::NCBIDB::Common
- Bio::Newick
- Bio::Newick::ParseError
- Bio::Nexus
- Bio::Nexus::CharactersBlock
- Bio::Nexus::DataBlock
- Bio::Nexus::DistancesBlock
- Bio::Nexus::GenericBlock
- Bio::Nexus::NexusMatrix
- Bio::Nexus::NexusMatrix::NexusMatrixError
- Bio::Nexus::NexusParseError
- Bio::Nexus::TaxaBlock
- Bio::Nexus::TreesBlock
- Bio::Nexus::Util
- Bio::NucleicAcid
- Bio::NucleicAcid::Data
- Bio::PAML
- Bio::PAML::Baseml
- Bio::PAML::Baseml::Report
- Bio::PAML::Codeml
- Bio::PAML::Codeml::Model
- Bio::PAML::Codeml::PositiveSite
- Bio::PAML::Codeml::PositiveSites
- Bio::PAML::Codeml::Rates
- Bio::PAML::Codeml::Report
- Bio::PAML::Codeml::ReportError
- Bio::PAML::Codeml::ReportSingle
- Bio::PAML::Common
- Bio::PAML::Common::Report
- Bio::PAML::Yn00
- Bio::PAML::Yn00::Report
- Bio::PDB
- Bio::PDB::AtomFinder
- Bio::PDB::Chain
- Bio::PDB::ChainFinder
- Bio::PDB::ChemicalComponent
- Bio::PDB::ChemicalComponent::Record
- Bio::PDB::Coordinate
- Bio::PDB::DataType
- Bio::PDB::DataType::ConstLikeMethod
- Bio::PDB::DataType::Pdb_AChar
- Bio::PDB::DataType::Pdb_Atom
- Bio::PDB::DataType::Pdb_Character
- Bio::PDB::DataType::Pdb_Date
- Bio::PDB::DataType::Pdb_IDcode
- Bio::PDB::DataType::Pdb_Integer
- Bio::PDB::DataType::Pdb_LString
- Bio::PDB::DataType::Pdb_List
- Bio::PDB::DataType::Pdb_Real
- Bio::PDB::DataType::Pdb_Residue_name
- Bio::PDB::DataType::Pdb_SList
- Bio::PDB::DataType::Pdb_Specification_list
- Bio::PDB::DataType::Pdb_String
- Bio::PDB::DataType::Pdb_StringRJ
- Bio::PDB::DataType::Pdb_SymOP
- Bio::PDB::HetatmFinder
- Bio::PDB::Heterogen
- Bio::PDB::HeterogenFinder
- Bio::PDB::Model
- Bio::PDB::ModelFinder
- Bio::PDB::Record
- Bio::PDB::Record::ANISOU
- Bio::PDB::Record::ATOM
- Bio::PDB::Record::HETATM
- Bio::PDB::Record::Jrnl
- Bio::PDB::Record::Remark1
- Bio::PDB::Record::Remark2
- Bio::PDB::Residue
- Bio::PDB::ResidueFinder
- Bio::PDB::Utils
- Bio::PROSITE
- Bio::PSORT
- Bio::PSORT::CGIDriver
- Bio::PSORT::IPSORT
- Bio::PSORT::PSORT1
- Bio::PSORT::PSORT1::Remote
- Bio::PSORT::PSORT1::Report
- Bio::PSORT::PSORT2
- Bio::PSORT::PSORT2::Remote
- Bio::PSORT::PSORT2::Report
- Bio::PSORT::PSORTB
- Bio::PSORT::WoLF_PSORT
- Bio::PTS1
- Bio::PTS1::Report
- Bio::Pathway
- Bio::Phylip
- Bio::Phylip::DistanceMatrix
- Bio::Phylip::PhylipFormat
- Bio::PhyloXML
- Bio::PhyloXML::Accession
- Bio::PhyloXML::Annotation
- Bio::PhyloXML::BinaryCharacters
- Bio::PhyloXML::BranchColor
- Bio::PhyloXML::CladeRelation
- Bio::PhyloXML::Confidence
- Bio::PhyloXML::Date
- Bio::PhyloXML::Distribution
- Bio::PhyloXML::DomainArchitecture
- Bio::PhyloXML::Events
- Bio::PhyloXML::Id
- Bio::PhyloXML::Node
- Bio::PhyloXML::Other
- Bio::PhyloXML::Parser
- Bio::PhyloXML::Point
- Bio::PhyloXML::Polygon
- Bio::PhyloXML::Property
- Bio::PhyloXML::ProteinDomain
- Bio::PhyloXML::Reference
- Bio::PhyloXML::Sequence
- Bio::PhyloXML::SequenceRelation
- Bio::PhyloXML::Taxonomy
- Bio::PhyloXML::Tree
- Bio::PhyloXML::Uri
- Bio::PhyloXML::Writer
- Bio::Probcons
- Bio::PubMed
- Bio::REBASE
- Bio::RefSeq
- Bio::Reference
- Bio::References
- Bio::Registry
- Bio::Registry::DB
- Bio::RestrictionEnzyme
- Bio::RestrictionEnzyme::Analysis
- Bio::RestrictionEnzyme::CutSymbol
- Bio::RestrictionEnzyme::CutSymbol::CutSymbol__
- Bio::RestrictionEnzyme::DenseIntArray
- Bio::RestrictionEnzyme::DoubleStranded
- Bio::RestrictionEnzyme::DoubleStranded::AlignedStrands
- Bio::RestrictionEnzyme::DoubleStranded::CutLocationPair
- Bio::RestrictionEnzyme::DoubleStranded::CutLocationPairInEnzymeNotation
- Bio::RestrictionEnzyme::DoubleStranded::CutLocations
- Bio::RestrictionEnzyme::DoubleStranded::CutLocationsInEnzymeNotation
- Bio::RestrictionEnzyme::DoubleStranded::EnzymeAction
- Bio::RestrictionEnzyme::Fragments
- Bio::RestrictionEnzyme::Range
- Bio::RestrictionEnzyme::Range::CutRange
- Bio::RestrictionEnzyme::Range::CutRanges
- Bio::RestrictionEnzyme::Range::HorizontalCutRange
- Bio::RestrictionEnzyme::Range::SequenceRange
- Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts
- Bio::RestrictionEnzyme::Range::SequenceRange::Fragment
- Bio::RestrictionEnzyme::Range::SequenceRange::Fragments
- Bio::RestrictionEnzyme::Range::VerticalCutRange
- Bio::RestrictionEnzyme::SingleStrand
- Bio::RestrictionEnzyme::SingleStrand::CutLocationsInEnzymeNotation
- Bio::RestrictionEnzyme::SingleStrandComplement
- Bio::RestrictionEnzyme::SortedNumArray
- Bio::RestrictionEnzyme::StringFormatting
- Bio::SOAPWSDL
- Bio::SOFT
- Bio::SOSUI
- Bio::SOSUI::Report
- Bio::SOSUI::Report::TMH
- Bio::SPTR
- Bio::SQL
- Bio::SQL::Biodatabase
- Bio::SQL::Bioentry
- Bio::SQL::BioentryDbxref
- Bio::SQL::BioentryPath
- Bio::SQL::BioentryQualifierValue
- Bio::SQL::BioentryReference
- Bio::SQL::BioentryRelationship
- Bio::SQL::Biosequence
- Bio::SQL::Comment
- Bio::SQL::Dbxref
- Bio::SQL::DbxrefQualifierValue
- Bio::SQL::DummyBase
- Bio::SQL::Location
- Bio::SQL::LocationQualifierValue
- Bio::SQL::Ontology
- Bio::SQL::Reference
- Bio::SQL::Seqfeature
- Bio::SQL::SeqfeatureDbxref
- Bio::SQL::SeqfeaturePath
- Bio::SQL::SeqfeatureQualifierValue
- Bio::SQL::SeqfeatureRelationship
- Bio::SQL::Sequence
- Bio::SQL::Taxon
- Bio::SQL::TaxonName
- Bio::SQL::Term
- Bio::SQL::TermDbxref
- Bio::SQL::TermPath
- Bio::SQL::TermRelationship
- Bio::SQL::TermRelationshipTerm
- Bio::SQL::TermSynonym
- Bio::SangerChromatogram
- Bio::Scf
- Bio::Sequence
- Bio::Sequence::AA
- Bio::Sequence::Adapter
- Bio::Sequence::Adapter::BioSQL
- Bio::Sequence::Adapter::EMBL
- Bio::Sequence::Adapter::FastaFormat
- Bio::Sequence::Adapter::FastaNumericFormat
- Bio::Sequence::Adapter::Fastq
- Bio::Sequence::Adapter::GenBank
- Bio::Sequence::Adapter::SangerChromatogram
- Bio::Sequence::Common
- Bio::Sequence::DBLink
- Bio::Sequence::Format
- Bio::Sequence::Format::AminoFormatter
- Bio::Sequence::Format::Formatter
- Bio::Sequence::Format::Formatter::Fasta
- Bio::Sequence::Format::Formatter::Fasta_ncbi
- Bio::Sequence::Format::Formatter::Fasta_numeric
- Bio::Sequence::Format::Formatter::Fastq
- Bio::Sequence::Format::Formatter::Fastq_illumina
- Bio::Sequence::Format::Formatter::Fastq_sanger
- Bio::Sequence::Format::Formatter::Fastq_solexa
- Bio::Sequence::Format::Formatter::Qual
- Bio::Sequence::Format::Formatter::Raw
- Bio::Sequence::Format::FormatterBase
- Bio::Sequence::Format::INSDFeatureHelper
- Bio::Sequence::Format::NucFormatter
- Bio::Sequence::Format::NucFormatter::Embl
- Bio::Sequence::Format::NucFormatter::Genbank
- Bio::Sequence::NA
- Bio::Sequence::NA::MidiTrack
- Bio::Sequence::QualityScore
- Bio::Sequence::QualityScore::Converter
- Bio::Sequence::QualityScore::Phred
- Bio::Sequence::QualityScore::Solexa
- Bio::Sequence::SequenceMasker
- Bio::Shell
- Bio::Shell::ColoredCodonTable
- Bio::Shell::Core
- Bio::Shell::Demo
- Bio::Shell::Ghost
- Bio::Shell::Irb
- Bio::Shell::Private
- Bio::Shell::Script
- Bio::Shell::Setup
- Bio::Shell::Web
- Bio::Shell::Web::Results
- Bio::SiRNA
- Bio::SiRNA::Pair
- Bio::SiRNA::ShRNA
- Bio::Sim4
- Bio::Sim4::Report
- Bio::Sim4::Report::Hit
- Bio::Sim4::Report::Segment
- Bio::Sim4::Report::SegmentPair
- Bio::Sim4::Report::SeqDesc
- Bio::Spidey
- Bio::Spidey::Report
- Bio::Spidey::Report::Hit
- Bio::Spidey::Report::Segment
- Bio::Spidey::Report::SegmentPair
- Bio::Spidey::Report::SeqDesc
- Bio::SwissProt
- Bio::TMHMM
- Bio::TMHMM::Report
- Bio::TMHMM::TMH
- Bio::TRANSFAC
- Bio::TRANSFAC::CELL
- Bio::TRANSFAC::CLASS
- Bio::TRANSFAC::FACTOR
- Bio::TRANSFAC::GENE
- Bio::TRANSFAC::MATRIX
- Bio::TRANSFAC::SITE
- Bio::TargetP
- Bio::TargetP::Report
- Bio::Taxonomy
- Bio::Tcoffee
- Bio::Tcoffee::DEFAULT_PARSER
- Bio::TogoWS
- Bio::TogoWS::AccessWait
- Bio::TogoWS::REST
- Bio::TrEMBL
- Bio::Tree
- Bio::Tree::Edge
- Bio::Tree::NoPathError
- Bio::Tree::Node
- Bio::UniProt
- BiorubyController
- BiorubyGenerator
- BiorubyHelper
- Hash
- Object
- String

No matching classes.

# Bio::Tree

This is the class for phylogenetic tree. It stores a phylogenetic tree.

Internally, it is based on Bio::Pathway class. However, users cannot handle Bio::Pathway object directly.

This is alpha version. Incompatible changes may be made frequently.

### Constants

DEFAULT_OPTIONS

  default options

### Attributes

options[RW]

tree options; mainly used for tree output

root[RW]

root node of this tree (even if unrooted tree, it is used by some methods)

### Public Class Methods

new(tree = nil) click to toggle source

Creates a new phylogenetic tree. When no arguments are given, it creates a new empty tree. When a Tree object is given, it copies the tree. Note that the new tree shares Node and Edge objects with the given tree.

    # File lib/bio/tree.rb, line 258
    def initialize(tree = nil)
      # creates an undirected adjacency list graph
      @pathway = Bio::Pathway.new([], true)
      @root = nil
      @options = {}
      _init_cache
      self.concat(tree) if tree
    end

### Public Instance Methods

add_edge(source, target, edge = Edge.new) click to toggle source

Adds a new edge to the tree. Returns the newly added edge. If the edge already exists, it is overwritten with new one.

    # File lib/bio/tree.rb, line 380
    def add_edge(source, target, edge = Edge.new)
      _clear_cache
      @pathway.append(Bio::Relation.new(source, target, edge))
      edge
    end

add_node(node) click to toggle source

Adds a node to the tree. Returns self. If the node already exists, it does nothing.

    # File lib/bio/tree.rb, line 402
    def add_node(node)
      _clear_cache
      @pathway.graph[node] ||= {}
      self
    end

adjacency_matrix(nodes = nil, default_value = nil, diagonal_value = nil) click to toggle source

Shows the adjacency matrix representation of the tree. It shows matrix only for given nodes. If nodes is nil or is ommitted, it acts the same as tree.adjacency_matrix(tree.nodes). If a block is given, for each edge, it yields source, target, and edge, and uses the returned value of the block. Without blocks, it uses edge. Returns a matrix object.

    # File lib/bio/tree.rb, line 822
    def adjacency_matrix(nodes = nil,
                         default_value = nil,
                         diagonal_value = nil) #:yields: source, target, edge
      nodes ||= self.nodes
      size = nodes.size
      hash = {}
      nodes.each_with_index { |x, i| hash[x] = i }
      # prepares an matrix
      matrix = Array.new(size, nil)
      matrix.collect! { |x| Array.new(size, default_value) }
      (0...size).each { |i| matrix[i][i] = diagonal_value }
      # fills the matrix from each edge
      self.each_edge do |source, target, edge|
        i_source = hash[source]
        i_target = hash[target]
        if i_source and i_target then
          val = block_given? ? (yield source, target, edge) : edge
          matrix[i_source][i_target] = val
          matrix[i_target][i_source] = val
        end
      end
      Matrix.rows(matrix, false)
    end

adjacent_nodes(node) click to toggle source

Returns an array of adjacent nodes of the given node.

    # File lib/bio/tree.rb, line 331
    def adjacent_nodes(node)
      h = @pathway.graph[node]
      h ? h.keys : []
    end

ancestors(node, root = nil) click to toggle source

Gets all ancestral nodes of the node. If root isn't specified or root is `nil`, @root is used. Returns an array of `Node`s. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 757
    def ancestors(node, root = nil)
      root ||= @root
      (self.path(root, node) - [ node ]).reverse
    end

children(node, root = nil) click to toggle source

Gets the adjacent children nodes of the node. If root isn't specified or root is `nil`, @root is used. Returns an array of `Node`s. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 701
    def children(node, root = nil)
      root ||= @root
      c = self.adjacent_nodes(node)
      c.delete(self.parent(node, root))
      c
    end

clear() click to toggle source

Clears all nodes and edges. Returns self. Note that options and root are also cleared.

    # File lib/bio/tree.rb, line 289
    def clear
      initialize
      self
    end

clear_node(node) click to toggle source

Removes all edges connected with the node. Returns self. If the node does not exist, raises IndexError.

    # File lib/bio/tree.rb, line 417
    def clear_node(node)
      unless self.include?(node)
        raise IndexError, 'the node does not exist'
      end
      _clear_cache
      @pathway.relations.delete_if do |rel|
        rel.node.include?(node)
      end
      @pathway.graph[node].each_key do |k|
        @pathway.graph[k].delete(node)
      end
      @pathway.graph[node].clear
      self
    end

collect_edge!() click to toggle source

Replaces each edge by each block's return value. Returns self.

    # File lib/bio/tree.rb, line 527
    def collect_edge! #:yields: source, target, edge
      _clear_cache
      @pathway.relations.each do |rel|
        newedge = yield rel.node[0], rel.node[1], rel.relation
        rel.edge = newedge
        @pathway.append(rel, false)
      end
      self
    end

collect_node!() click to toggle source

Replaces each node by each block's return value. Returns self.

    # File lib/bio/tree.rb, line 506
    def collect_node! #:yields: node
      _clear_cache
      tr = {}
      self.each_node do |node|
        tr[node] = yield node
      end
      # replaces nodes in @pathway.relations
      @pathway.relations.each do |rel|
        rel.node.collect! { |node| tr[node] }
      end
      # re-generates @pathway from relations
      @pathway.to_list
      # adds orphan nodes
      tr.each_value do |newnode|
        @pathway.graph[newnode] ||= {}
      end
      self
    end

concat(other) click to toggle source

Concatenates the other tree. If the same edge exists, the edge in other is used. Returns self. The result is unspecified if other isn't a Tree object. Note that the Node and Edge objects in the other tree are shared in the concatinated tree.

    # File lib/bio/tree.rb, line 595
    def concat(other)
      #raise TypeError unless other.kind_of?(self.class)
      _clear_cache
      other.each_node do |node|
        self.add_node(node)
      end
      other.each_edge do |node1, node2, edge|
        self.add_edge(node1, node2, edge)
      end
      self
    end

descendents(node, root = nil) click to toggle source

Gets all descendent nodes of the node. If root isn't specified or root is `nil`, @root is used. Returns an array of `Node`s. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 712
    def descendents(node, root = nil)
      root ||= @root
      distance, route = @pathway.breadth_first_search(root)
      d = distance[node]
      result = []
      distance.each do |key, val|
        if val > d then
          x = key
          while x = route[x]
            if x == node then
              result << key
              break
            end
            break if distance[x] <= d
          end
        end
      end
      result
    end

distance(node1, node2) click to toggle source

Returns distance between node1 and node2. It would raise error if the edges didn't contain distance values. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 640
    def distance(node1, node2)
      distance = 0
      self.each_edge_in_path(node1, node2) do |source, target, edge|
        distance += get_edge_distance(edge)
      end
      distance
    end

distance_matrix(nodes = nil) click to toggle source

Calculates distance matrix of given nodes. If nodes is nil, or is ommited, it acts the same as tree.distance_matrix(tree.leaves). Returns a matrix object. The result is unspecified for cyclic trees. Note 1: The diagonal values of the matrix are 0. Note 2: If the distance cannot be calculated, nil will be set.

    # File lib/bio/tree.rb, line 793
    def distance_matrix(nodes = nil)
      nodes ||= self.leaves
      matrix = []
      nodes.each_index do |i|
        row = []
        nodes.each_index do |j|
          if i == j then
            distance = 0
          elsif r = matrix[j] and val = r[i] then
            distance = val
          else
            distance = (self.distance(nodes[i], nodes[j]) rescue nil)
          end
          row << distance
        end
        matrix << row
      end
      Matrix.rows(matrix, false)
    end

each_edge() click to toggle source

Iterates over each edges of this tree.

    # File lib/bio/tree.rb, line 311
    def each_edge #:yields: source, target, edge
      @pathway.relations.each do |rel|
        yield rel.node[0], rel.node[1], rel.relation
      end
      self
    end

each_edge_in_path(node1, node2) click to toggle source

Iterates over each edge from node1 to node2. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 626
    def each_edge_in_path(node1, node2)
      path = self.path(node1, node2)
      source = path.shift
      path.each do |target|
        edge = self.get_edge(source, target)
        yield source, target, edge
        source = target
      end
      self
    end

each_node() click to toggle source

Iterates over each node of this tree.

    # File lib/bio/tree.rb, line 305
    def each_node(&x) #:yields: node
      @pathway.graph.each_key(&x)
      self
    end

each_out_edge(source) click to toggle source

Iterates over each connected edges of the given node. Returns self.

The reason why the method name is "each_out_edge" is that it comes from the Boost Graph Library.

    # File lib/bio/tree.rb, line 355
    def each_out_edge(source) #:yields: source, target, edge
      h = @pathway.graph[source]
      h.each { |key, val| yield source, key, val } if h
      self
    end

edges() click to toggle source

Returns all edges an array of [ node0, node1, edge ]

    # File lib/bio/tree.rb, line 319
    def edges
      @pathway.relations.collect do |rel|
        [ rel.node[0], rel.node[1], rel.relation ]
      end
    end

get_edge(source, target) click to toggle source

Returns an edge from source to target. If source and target are not adjacent nodes, returns nil.

    # File lib/bio/tree.rb, line 372
    def get_edge(source, target)
      h = @pathway.graph[source]
      h ? h[target] : nil
    end

get_edge_distance(edge) click to toggle source

Gets distance value from the given edge. Returns float or any other numeric value or nil.

    # File lib/bio/tree.rb, line 100
    def get_edge_distance(edge)
      begin
        dist = edge.distance
      rescue NoMethodError
        dist = edge
      end
      dist
    end

get_edge_distance_string(edge) click to toggle source

Gets distance string from the given edge. Returns a string or nil.

    # File lib/bio/tree.rb, line 111
    def get_edge_distance_string(edge)
      begin
        dist = edge.distance_string
      rescue NoMethodError
        dist = (edge ? edge.to_s : nil)
      end
      dist
    end

get_edge_merged(edge1, edge2) click to toggle source

Returns edge1 + edge2

    # File lib/bio/tree.rb, line 121
    def get_edge_merged(edge1, edge2)
      dist1 = get_edge_distance(edge1)
      dist2 = get_edge_distance(edge2)
      if dist1 and dist2 then
        Edge.new(dist1 + dist2)
      elsif dist1 then
        Edge.new(dist1)
      elsif dist2 then
        Edge.new(dist2)
      else
        Edge.new
      end
    end

get_node_bootstrap(node) click to toggle source

    # File lib/bio/tree.rb, line 237
    def get_node_bootstrap(node)
      begin
        node.bootstrap
      rescue NoMethodError
        nil
      end
    end

get_node_bootstrap_string(node) click to toggle source

    # File lib/bio/tree.rb, line 245
    def get_node_bootstrap_string(node)
      begin
        node.bootstrap_string
      rescue NoMethodError
        nil
      end
    end

get_node_by_name(str) click to toggle source

Finds a node in the tree by given name and returns the node. If the node does not found, returns nil. If multiple nodes with the same name exist, the result would be one of those (unspecified).

    # File lib/bio/tree.rb, line 390
    def get_node_by_name(str)
      self.each_node do |node|
        if get_node_name(node) == str
          return node
        end
      end
      nil
    end

get_node_name(node) click to toggle source

Gets node name

    # File lib/bio/tree.rb, line 229
    def get_node_name(node)
      begin
        node.name
      rescue NoMethodError
        node.to_s
      end
    end

include?(node) click to toggle source

If the node exists, returns true. Otherwise, returns false.

    # File lib/bio/tree.rb, line 410
    def include?(node)
      @pathway.graph[node] ? true : false
    end

insert_node(node1, node2, new_node, new_distance = nil) click to toggle source

Insert a new node between adjacent nodes node1 and node2. The old edge between node1 and node2 are changed to the edge between new_node and node2. The edge between node1 and new_node is newly created.

If new_distance is specified, the distance between node1 and new_node is set to new_distance, and distance between new_node and node2 is set to `tree.get_edge(node1, node2).distance - new_distance`.

Returns self. If node1 and node2 are not adjacent, raises IndexError.

If new_node already exists in the tree, the tree would become circular. In addition, if the edge between new_node and node1 (or node2) already exists, it will be erased.

    # File lib/bio/tree.rb, line 890
    def insert_node(node1, node2, new_node, new_distance = nil)
      unless edge = self.get_edge(node1, node2) then
        raise IndexError, 'nodes not found or two nodes are not adjacent'
      end
      _clear_cache
      new_edge = Edge.new(new_distance)
      self.remove_edge(node1, node2)
      self.add_edge(node1, new_node, new_edge)
      if new_distance and old_distance = get_edge_distance(edge) then
        old_distance -= new_distance
        begin
          edge.distance = old_distance
        rescue NoMethodError
          edge = old_distance
        end
      end
      self.add_edge(new_node, node2, edge)
      self
    end

leaves(node = nil, root = nil) click to toggle source

If node is nil, returns an array of all leaves (nodes connected with one edge). Otherwise, gets all descendent leaf nodes of the node. If root isn't specified or root is `nil`, @root is used. Returns an array of `Node`s. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 738
    def leaves(node = nil, root = nil)
      unless node then
        nodes = []
        self.each_node do |x|
          nodes << x if self.out_degree(x) == 1
        end
        return nodes
      else
        root ||= @root
        self.descendents(node, root).find_all do |x|
          self.adjacent_nodes(x).size == 1
        end
      end
    end

lowest_common_ancestor(node1, node2, root = nil) click to toggle source

Gets the lowest common ancestor of the two nodes. If root isn't specified or root is `nil`, @root is used. Returns a `Node` object or nil. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 766
    def lowest_common_ancestor(node1, node2, root = nil)
      root ||= @root
      distance, route = @pathway.breadth_first_search(root)
      x = node1; r1 = []
      begin; r1 << x; end while x = route[x]
      x = node2; r2 = []
      begin; r2 << x; end while x = route[x]
      return (r1 & r2).first
    end

newick(options = {}) click to toggle source
Alias for: output_newick
nodes() click to toggle source

Returns all nodes as an array.

    # File lib/bio/tree.rb, line 295
    def nodes
      @pathway.graph.keys
    end

number_of_edges() click to toggle source

Returns number of edges in the tree.

    # File lib/bio/tree.rb, line 326
    def number_of_edges
      @pathway.relations.size
    end

number_of_nodes() click to toggle source

Number of nodes.

    # File lib/bio/tree.rb, line 300
    def number_of_nodes
      @pathway.nodes
    end

out_degree(source) click to toggle source

Returns number of edges in the given node.

The reason why the method name is "out_degree" is that it comes from the Boost Graph Library.

    # File lib/bio/tree.rb, line 365
    def out_degree(source)
      h = @pathway.graph[source]
      h ? h.size : 0
    end

out_edges(source) click to toggle source

Returns all connected edges with adjacent nodes. Returns an array of the array [ source, target, edge ].

The reason why the method name is "out_edges" is that it comes from the Boost Graph Library.

    # File lib/bio/tree.rb, line 341
    def out_edges(source)
      h = @pathway.graph[source]
      if h
        h.collect { |key, val| [ source, key, val ] }
      else
        []
      end
    end

output(format, *arg, &block) click to toggle source

Returns formatted text (or something) of the tree Currently supported format is: :newick, :nhx

    # File lib/bio/tree/output.rb, line 230
    def output(format, *arg, &block)
      case format
      when :newick
        output_newick(*arg, &block)
      when :nhx
        output_nhx(*arg, &block)
      when :phylip_distance_matrix
        output_phylip_distance_matrix(*arg, &block)
      else
        raise 'Unknown format'
      end
    end

output_newick(options = {}) click to toggle source

Returns a newick formatted string. If block is given, the order of the node is sorted (as the same manner as Enumerable#sort).

Available options:

`:indent` | indent string; set false to disable (default: ' ')
`:bootstrap_style` | `:disabled` disables bootstrap representations. `:traditional` for traditional style. `:molphy` for Molphy style (default).

    # File lib/bio/tree/output.rb, line 198
    def output_newick(options = {}, &block) #:yields: node1, node2
      root = @root
      root ||= self.nodes.first
      return '();' unless root
      __to_newick([], root, 0, :__to_newick_format_leaf, options, &block) +
        __to_newick_format_leaf(root, Edge.new, options) +
        ";\n"
    end

Also aliased as: newick
output_nhx(options = {}) click to toggle source

Returns a NHX (New Hampshire eXtended) formatted string. If block is given, the order of the node is sorted (as the same manner as Enumerable#sort).

Available options:

`:indent` | indent string; set false to disable (default: ' ')

    # File lib/bio/tree/output.rb, line 218
    def output_nhx(options = {}, &block) #:yields: node1, node2
      root = @root
      root ||= self.nodes.first
      return '();' unless root
      __to_newick([], root, 0,
                  :__to_newick_format_leaf_NHX, options, &block) +
        __to_newick_format_leaf_NHX(root, Edge.new, options) +
        ";\n"
    end

output_phylip_distance_matrix(nodes = nil, options = {}) click to toggle source

Generates phylip-style distance matrix as a string. if nodes is not given, all leaves in the tree are used. If the names of some of the given (or default) nodes are not defined or are empty, the names are automatically generated.

    # File lib/bio/tree/output.rb, line 251
    def output_phylip_distance_matrix(nodes = nil, options = {})
      nodes = self.leaves unless nodes
      names = nodes.collect do |x|
        y = get_node_name(x)
        y = sprintf("%x", x.__id__.abs) if y.empty?
        y
      end
      m = self.distance_matrix(nodes)
      Bio::Phylip::DistanceMatrix.generate(m, names, options)
    end

parent(node, root = nil) click to toggle source

Gets the parent node of the node. If root isn't specified or root is `nil`, @root is used. Returns an `Node` object or nil. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 687
    def parent(node, root = nil)
      root ||= @root
      raise IndexError, 'can not get parent for unrooted tree' unless root
      unless ret = _get_cached_parent(node, root) then
        ret = self.path(root, node)[-2]
        _cache_parent(node, ret, root)
      end
      ret
    end

path(node1, node2) click to toggle source

Gets path from node1 to node2. Retruns an array of nodes, including node1 and node2. If node1 and/or node2 do not exist, IndexError is raised. If node1 and node2 are not connected, NoPathError is raised. The result is unspecified for cyclic trees.

    # File lib/bio/tree.rb, line 612
    def path(node1, node2)
      raise IndexError, 'node1 not found' unless @pathway.graph[node1]
      raise IndexError, 'node2 not found' unless @pathway.graph[node2]
      return [ node1 ] if node1 == node2
      return [ node1, node2 ] if @pathway.graph[node1][node2]
      step, path = @pathway.bfs_shortest_path(node1, node2)
      unless path[0] == node1 and path[-1] == node2 then
        raise NoPathError, 'node1 and node2 are not connected'
      end
      path
    end

remove_edge(source, target) click to toggle source

# Removes an edge between source and target. # Returns self. # If the edge does not exist, raises IndexError. +

    # File lib/bio/tree.rb, line 465
    def remove_edge(source, target)
      unless self.get_edge(source, target) then
        raise IndexError, 'edge not found'
      end
      _clear_cache
      fwd = [ source, target ]
      rev = [ target, source ]
      @pathway.relations.delete_if do |rel|
        rel.node == fwd or rel.node == rev
      end
      h = @pathway.graph[source]
      h.delete(target) if h
      h = @pathway.graph[target]
      h.delete(source) if h
      self
    end

remove_edge_if() click to toggle source

Removes each edge if the block returns not nil. Returns self.

    # File lib/bio/tree.rb, line 484
    def remove_edge_if #:yields: source, target, edge
      _clear_cache
      removed_rel = []
      @pathway.relations.delete_if do |rel|
        if yield rel.node[0], rel.node[1], rel.edge then
          removed_rel << rel
          true
        end
      end
      removed_rel.each do |rel|
        source = rel.node[0]
        target = rel.node[1]
        h = @pathway.graph[source]
        h.delete(target) if h
        h = @pathway.graph[target]
        h.delete(source) if h
      end
      self
    end

remove_node(node) click to toggle source

Removes the given node from the tree. All edges connected with the node are also removed. Returns self. If the node does not exist, raises IndexError.

    # File lib/bio/tree.rb, line 436
    def remove_node(node)
      #_clear_cache #done in clear_node(node)
      self.clear_node(node)
      @pathway.graph.delete(node)
      self
    end

remove_node_if() click to toggle source

Removes each node if the block returns not nil. All edges connected with the removed nodes are also removed. Returns self.

    # File lib/bio/tree.rb, line 446
    def remove_node_if
      #_clear_cache #done in clear_node(node)
      all = self.nodes
      all.each do |node|
        if yield node then
          self.clear_node(node)
          @pathway.graph.delete(node)
        end
      end
      self
    end

remove_nonsense_nodes() click to toggle source

Removes all nodes that are not branches nor leaves. That is, removes nodes connected with exactly two edges. For each removed node, two adjacent edges are merged and a new edge are created. Returns removed nodes. Note that orphan nodes are still kept unchanged.

    # File lib/bio/tree.rb, line 852
    def remove_nonsense_nodes
      _clear_cache
      hash = {}
      self.each_node do |node|
        hash[node] = true if @pathway.graph[node].size == 2
      end
      hash.each_key do |node|
        adjs = @pathway.graph[node].keys
        edges = @pathway.graph[node].values
        new_edge = get_edge_merged(edges[0], edges[1])
        @pathway.graph[adjs[0]].delete(node)
        @pathway.graph[adjs[1]].delete(node)
        @pathway.graph.delete(node)
        @pathway.append(Bio::Relation.new(adjs[0], adjs[1], new_edge))
      end
      #@pathway.to_relations
      @pathway.relations.reject! do |rel|
        hash[rel.node[0]] or hash[rel.node[1]]
      end
      return hash.keys
    end

subtree(nodes) click to toggle source

Gets the sub-tree consisted of given nodes. nodes must be an array of nodes. Nodes that do not exist in the original tree are ignored. Returns a Tree object. Note that the sub-tree shares Node and Edge objects with the original tree.

    # File lib/bio/tree.rb, line 543
    def subtree(nodes)
      nodes = nodes.find_all do |x|
        @pathway.graph[x]
      end
      return self.class.new if nodes.empty?
      # creates subtree
      new_tree = self.class.new
      nodes.each do |x|
        new_tree.add_node(x)
      end
      self.each_edge do |node1, node2, edge|
        if new_tree.include?(node1) and new_tree.include?(node2) then
          new_tree.add_edge(node1, node2, edge)
        end
      end
      return new_tree
    end

subtree_with_all_paths(nodes) click to toggle source

Gets the sub-tree consisted of given nodes and all internal nodes connected between given nodes. nodes must be an array of nodes. Nodes that do not exist in the original tree are ignored. Returns a Tree object. The result is unspecified for cyclic trees. Note that the sub-tree shares Node and Edge objects with the original tree.

    # File lib/bio/tree.rb, line 569
    def subtree_with_all_paths(nodes)
      hash = {}
      nodes.each { |x| hash[x] = true }
      nodes.each_index do |i|
        node1 = nodes[i]
        (0...i).each do |j|
          node2 = nodes[j]
          unless node1 == node2 then
            begin
              path = self.path(node1, node2)
            rescue IndexError, NoPathError
              path = []
            end
            path.each { |x| hash[x] = true }
          end
        end
      end
      self.subtree(hash.keys)
    end

total_distance() click to toggle source

Returns total distance of all edges. It would raise error if some edges didn't contain distance values.

    # File lib/bio/tree.rb, line 778
    def total_distance
      distance = 0
      self.each_edge do |source, target, edge|
        distance += get_edge_distance(edge)
      end
      distance
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.