list
end
+ # Method to recursively remove branches in taxonomic tree where the child count is less than or
+ # equal to a given minimum.
+ def debranch(min_count = nil)
+ node = self
+
+ node.children.each do |name, child|
+ node.children.delete(name) if child.count <= min_count
+ end
+
+ node.children.each_value do |child|
+ child.debranch(min_count)
+ end
+ end
+
# Method to recursively trim a taxonomic tree so that it only contains an unbranched tree,
# which gives the lowest common ancestor.
- def lowest_common_ancestor(node = self)
+ def lowest_common_ancestor
+ node = self
+
node.children = {} if node.children.size > 1
- node.children.each do |name, child|
- lowest_common_ancestor(child)
+ node.children.each_value do |child|
+ child.lowest_common_ancestor
end
end
end
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=>'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=>'min_count', :short=>'m', :type=>'uint', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
options = Biopieces.options_parse(ARGV, casts)
if options[:LCA]
tax_hash.each_value do |tree|
+ tree.debranch(options[:min_count]) if options[:min_count]
tree.lowest_common_ancestor
end