def go_for_graph(sequences_by_ontologies, fpkm = {}) container = {} go_data = [ [:function_go, 'F:'], [:component_go, 'C:'], [:process_go, 'P:'] ] go_data.each do |key, prefix| go_ontology = sequences_by_ontologies.select{|go, seq_ids| go =~ /^#{prefix}/} go_names = [] go_vals = [] go_ontology.each do |go_name, seq_names| go_label = go_name.gsub(prefix, '') if fpkm.empty? go_vals << seq_names.length go_names << go_label else sum = seq_names.map{|seq_name| fpkm[seq_name].first }.inject { |sum, n| sum + n } if sum > 0 go_vals << sum go_names << go_label end end end go_table = [] go_names.each_with_index do |name, index| go_table << [name, go_vals[index]] end go_table.sort!{|v1, v2| v2[1] <=> v1[1]} go_table.unshift([key.to_s, 'GO']) if !go_names.empty? container[key] = go_table else container[key] = [ [key.to_s, 'GO'], ['No_data', 1] ] end end return container end