lib/pets/cohort.rb in pets-0.2.4 vs lib/pets/cohort.rb in pets-0.2.5

- old
+ new

@@ -22,15 +22,10 @@ ont = Ontology.new(file: ont_file, load_file: true) end else ont = Ontology.new ont.read(ont_file) - if !excluded_terms_file.nil? - ont.add_removable_terms(read_excluded_ont_file(excluded_terms_file)) - ont.remove_removable() - ont.build_index() - end end @@ont[ont_name] = ont end def self.read_excluded_ont_file(file) @@ -42,16 +37,18 @@ end def initialize() @profiles = {} @vars = {} + @extra_attr = {} @var_idx = Genomic_Feature.new([]) end - def add_record(rec) #[id, [profile], [[chr1, start1, stop1],[chr1, start1, stop1]]] + def add_record(rec, extra_attr = nil) #[id, [profile], [[chr1, start1, stop1],[chr1, start1, stop1]]] id, profile, vars = rec @profiles[id] = profile.map{|t| t.to_sym} if !profile.nil? + @extra_attr[id] = extra_attr if !extra_attr.nil? add_gen_feat(id, vars) if !vars.nil? end def delete(id) @profiles.delete(id) @@ -109,11 +106,11 @@ def get_general_profile(thr=0) # TODO move funcionality to semtools term_count = Hash.new(0) each_profile do |id, prof| prof.each do |term| - general_profile[prof] += 1 + term_count[term] += 1 end end records = @profiles.length general_profile = [] term_count.each do |term, count| @@ -269,10 +266,15 @@ }] } @profiles.each do |id, terms| phenopacket = {metaData: metaData} - phenopacket[:subject] = {id: id} + query_sex = @extra_attr.dig(id, :sex) + sex = query_sex.nil? ? 'UNKNOWN_SEX' : query_sex + phenopacket[:subject] = { + id: id, + sex: sex + } phenotypicFeatures = [] terms.each do |term| term_name = ont.translate_id(term) phenotypicFeatures << { type: { id: term, label: term_name},