michaelbarton / cost_in_evolution

This URL has Read+Write access

cost_in_evolution / spec / fixtures / generate_fixtures.rb
100644 43 lines (31 sloc) 1.063 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'pathname'
 
ROOT = Pathname.new(File.join(File.join(File.dirname(__FILE__),'..','..'))).cleanpath.to_s
$:.unshift(ROOT)
 
require 'config/environment'
 
FIXTURES_DIR = Pathname.new(File.join(File.join(File.dirname(__FILE__)))).cleanpath.to_s
 
def dump_models(models)
  hash = models.inject(Hash.new) do |hash,model|
    hash[model.id] = model.attributes
    hash
  end
  File.open(File.join(FIXTURES_DIR,"#{models.first.class.table_name}.yml"),'w') do |file|
    file.puts(YAML.dump(hash))
  end
end
 
dump_models(Condition.all)
dump_models(CostType.all)
dump_models(AminoAcid.all)
dump_models(AminoAcidCost.all)
 
gene = Gene.find_by_name('YDL177C')
dump_models([gene])
 
align = gene.alignments
dump_models(align)
dump_models(align.first.gene_mutations)
 
codons = align.first.alignment_codons
dump_models(codons)
 
mutations = codons.map{|c| c.site_mutation}
dump_models(mutations)
 
frequencies = codons.map{|c| c.amino_acid_frequencies}.flatten
dump_models(frequencies)
 
codon_costs = codons.map{|c| c.alignment_codon_costs}.flatten
dump_models(codon_costs)