Skip to content

Instantly share code, notes, and snippets.

View michaelbarton's full-sized avatar

Michael Barton michaelbarton

View GitHub Profile
desc 'Loads all the alignment codon data'
task :load_alignment_codons => :clear_alignment_codons do
starfish = %x|which starfish|.strip
loader = PROJECT_ROOT + '/model/starfish/load_alignment_codons.rb'
p = lambda{ system( "qsub -cwd -j y -V #{starfish} #{loader}") }
p.call
sleep(120)
16.times { p.call }
end
BLAST protein YDL177C
BLAST dna YDL177C
# Given the location of an SQL query file, this method will
# execute the query on the database, and print each line to
# the supplied target file.
# This method relies on the MySQL adapter for the fetch_fields
# method, but should not suffer in performance from pulling
# large amounts of data into memory.
public
def export_csv_from_sql(sql_file,target_file)
# Example activerecord interator based on using an indexed 'id' column.
# See http://schuerig.de/michael/blog/index.php/2007/02/03/ar-enumerable/
# and http://weblog.jamisbuck.org/2007/4/6/faking-cursors-in-activerecord
class << ActiveRecord::Base
def each(chunk_size=1000)
(0..self.last.id / chunk_size).each do |offset|
self.find(:all,
:limit => chunk_size,
:conditions => ["id > ?", offset * chunk_size]).each do |i|
require 'fileutils'
require 'find'
class Latex < Thor
desc "build","builds thesis document"
method_options :src => 'src',
:dest => 'out',
:tmp => 'tmp'
def build(file)
- Example where
- cost of alanine is being considered
- in glucose limitation
- at biomass flux of 0.5
- Set all exchange fluxes to have a lower bound of -10000.
- Effectively unlimited nutrients with respect to biomass flux
- Set biomass flux reaction rate to have upper and lower bounds of 0.05
# Reasons to use rails approach for bioinformatics
## Generic Ruby
* Modules like enumerable are great for sorting data
## Activerecord
* Simple to add indexes to enforce uniqueness of data
task :environment do
require 'database'
require 'logger'
@log = Logger.new('log/analysis.log')
end
namespace :db do
desc 'Create database'
task :create => :environment do
require 'database'
gene = Gene.find(2)
gene.alignment_sequences.each do |a|
puts "#{a.species.letter}#{gene.name} #{a.protein}"
end
Can I over-ride task :environment in test_helper.rb to test rake tasks?
I have a series of rake tasks in a Rakefile which I'd like to test as part of my specs etc. Each task is defined in the form:
task :do_somthing => :environment do
# Do something with the database here
end
Where the :environment task sets up an ActiveRecord/DataMapper database connection and classes. I'm not using this as part of Rails but I have a series of tests which I like to run as part of BDD.