Skip to content

Instantly share code, notes, and snippets.

@michaelbarton
Created September 14, 2009 08:56
Show Gist options
  • Save michaelbarton/186568 to your computer and use it in GitHub Desktop.
Save michaelbarton/186568 to your computer and use it in GitHub Desktop.
#! /usr/local/bin/ruby
require 'rubygems'
require 'fastercsv'
layout = Hash.new
FasterCSV.open(ARGV.first, :headers => true).each do |row|
row.headers.each do |header|
layout[header] ||= Hash.new
layout[header][row['amino_acid']] = row[header].to_i
end
end
numbers = {'nitrogen' => 1, 'carbon' => 2, 'oxygen' => 2, 'hydrogen' => 4}
numbers.keys.each do |atom|
layout[atom].keys.each do |acid|
layout[atom][acid] = layout[atom][acid] + numbers[atom]
end
end
puts YAML.dump(layout)
#! /usr/local/bin/ruby
require 'rubygems'
weights = { 'carbon' => 12.011, 'nitrogen' => 14.007,
'oxygen' => 15.999, 'hydrogen' => 1.0079,
'sulphur' => 32.065 }
composition = YAML.load(File.open(ARGV.first).read)
weights.keys.each do |atom|
composition[atom].keys.each do |acid|
composition[atom][acid] = composition[atom][acid] * weights[atom]
end
end
puts YAML.dump(composition)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment