module BioTable::Merge
Public Class Methods
merge_tables(tables, options)
click to toggle source
# File lib/bio-table/merge.rb, line 5 def self.merge_tables(tables, options) logger = Bio::Log::LoggerPlus['bio-table'] logger.info("Merging tables") headers = tables.first.header[0..0] + tables.map { |t| t.header[1..-1].map{|n| (options[:keep_headers] ? n : t.name+'-'+n) }}.flatten t = Table.new(headers) # index tables on rownames idxs = [] tables.each do |t| idxs << Indexer::create_index(t,[0]) end # create a full list of rownames all_rownames = idxs.map { |idx| idx.keys }.flatten.uniq # walk the tables and merge fields all_rownames.each do | rowname | row = TableRow.new(rowname) fields = tables.map { |t| fields = t.find_fields(rowname) row.append(fields) } t.push(row) end t end