require 'pp'
require 'maasha/biopieces'
+# Class containing methods to construct a taxonomic tree for the classification of
+# organisms. Currently only works with GreenGenes type of entries.
class TaxTree
+ # Method to initialize a new TaxTree object.
def initialize
@tree = TaxNode.new("root", "Root", 0, 0, 0.0)
end
end
end
+ # Method to merge two TaxTrees.
def merge(tree)
node = @tree
end
end
+ # Method to flatten a TaxTree turning this into a list by recursive depth first traversal.
def flatten(node = @tree, list = [])
list << TaxNode.new(node.level, node.name, node.count, node.size, node.score)
list
end
+ # Method to recursively trim a TaxTree show that it only contains a unbranched tree,
+ # which gives the lowest common ancestor.
def lowest_common_ancestor(node = @tree)
node.children = {} if node.children.size > 1
end
end
+ # Method for iterating over a TaxTree.
def each
self.flatten.each do |node|
yield node
private
+ # Method containing a helper hash to expand the phylogenetic level name.
def expand_level(level)
hash = {
'd' => "domain",
hash[level]
end
+ # Nested class for TaxTree nodes.
class TaxNode
attr_accessor :level, :name, :count, :size, :score, :children
@children = {}
end
+ # Method to convert a TaxNode to a Biopiece record.
def to_bp
record = {}
record[:REC_TYPE] = "Classification"
casts = []
casts << {:long=>'LCA', :short=>'l', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
-casts << {:long=>'size', :short=>'s', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
+casts << {:long=>'size', :short=>'s', :type=>'uint', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
options = Biopieces.options_parse(ARGV, casts)