lib/tree_clusters.rb in tree_clusters-0.5.2 vs lib/tree_clusters.rb in tree_clusters-0.6.0
- old
+ new
@@ -147,15 +147,12 @@
reverse
metadata.each do |md_cat, leaf2mdtag|
already_checked = Set.new
single_tag_clades = {}
- p [md_cat, leaf2mdtag]
clades.each do |clade|
- p [clade.name, clade.all_leaves]
-
assert clade.all_leaves.count > 1,
"A clade cannot also be a leaf"
unless clade.all_leaves.all? do |leaf|
already_checked.include? leaf
@@ -216,9 +213,48 @@
end
end
end
metadata
+ end
+
+ def read_attrs_file fname
+
+ attr_names = Set.new
+ File.open(fname, "rt").each_line.with_index do |line, idx|
+ unless idx.zero?
+ _, attr_name, _ = line.chomp.split "\t"
+
+ attr_names << attr_name
+ end
+ end
+
+ attr_names = attr_names.to_a.sort
+
+ attrs = TreeClusters::Attrs.new
+
+ File.open(fname, "rt").each_line.with_index do |line, idx|
+ unless idx.zero?
+ leaf, attr_name, attr_val = line.chomp.split "\t"
+
+ if attrs.has_key? leaf
+ if attrs[leaf].has_key? attr_name
+ attrs[leaf][attr_name] << attr_val
+ else
+ attrs[leaf][attr_name] = Set.new([attr_val])
+ end
+ else
+ attrs[leaf] = {}
+
+ attr_names.each do |name|
+ attrs[leaf][name] = Set.new
+ end
+ attrs[leaf][attr_name] << attr_val
+ end
+ end
+ end
+
+ [attr_names, attrs]
end
# A Hash table for genome/leaf/taxa attributes
class Attrs < Hash