Ontology & Initialisation data seed for Chado-On-Rails

A CHADO instance without the use of ontologies is relatively useless, even for basic things such as running some tests in rails. Fixtures are great for minimalistic testing data but the required ontologies exceed those limits easily.

This great blog post by Matthias Marschall and this thread @ stackoverflow give some very good advice, how to load the required data without the usage of fixtures. The basic idea is simple:  Dump the loaded ontologies  from Postgresql/CHADO. Overwrite a Rake task with system calls that load the sql files and finaly run the rake command to populate the db.  Hence the above mentioned solution presents a convienient way to make use of the ontologies while testing an application that relies on CHADO.

A basic example to solve the situation could look something like this:

Create a file in lib/tasks/load_seed.rake with:

namespace :db do
  namespace :seed do

    desc "load the dumped seed data from db/*.sql into the test database"
    task :load => :environment do
      config = ActiveRecord::Base.configurations['test']
      system("psql --username=#{config['username']} #{config['database']} < db/db_ontologies.sql")
      system("psql --username=#{config['username']} #{config['database']} < db/db_initialize.sql")

To populate the test database with the data run


, in addition to

rake db:test:prepare


rake db:test:load

I’m using a single sql dump of the ontologies needed, since the download, conversion and load of the ontologies every time  db:seed:load is called would require an enormous amount of time.

(In this post I’m assuming that the database used is Postgresql and that the sql-file db_ontology.sql  represents a data dump of the chado instance  + ontologies loaded. db_initialize.sql is equal to gmod/load/etc/initialize.sql. See the CHADO installation manuel for more information.)

Tags: , , , , ,

No comments yet.

Leave a Reply