Class: Bio::Ngs::OntologyCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/bio/ngs/ontology.rb

Overview

Class to handle collection of Bio::Ngs::Ontology objects. It provides a method to store all the gene-GO associations into the Ontology db

Instance Method Summary collapse

Methods inherited from Array

#/

Instance Method Details

#to_db(yaml_file = nil) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bio/ngs/ontology.rb', line 84

def to_db(yaml_file=nil)
  db = Bio::Ngs::Db.new :ontology, yaml_file
  genes = []
  ontologies = []
  go = {}
  Go.find_by_sql("SELECT id, go_id FROM go").each {|g| go[g.go_id] = g.id}
  self.each_with_index do |gene,index|
    raise ArgumentError "OntologyCollection can store only Bio::Ngs::Ontology objects!" if gene.class != Bio::Ngs::Ontology
    genes << [index+1,gene.gene_id,gene.library]
    gene.go.each {|o| ontologies << [index+1,go[o]] if go[o]}
  end
  db.insert_many(:genes,"INSERT INTO genes(id,gene_id,library) VALUES(?,?,?)",genes)
  db.insert_many(:gene_gos,"INSERT INTO gene_gos(gene_id,go_id) VALUES(?,?)",ontologies)        
end