Skip to content

Instantly share code, notes, and snippets.

@mythosil
Created June 28, 2011 11:40
Show Gist options
  • Save mythosil/1050970 to your computer and use it in GitHub Desktop.
Save mythosil/1050970 to your computer and use it in GitHub Desktop.
calculate and plot hydropathy score
require 'gruff'
f = open(ARGV[0])
seq = f.read.delete(" \n").upcase
f.close
hydropathy_index = {
'A' => 1.8,
'B' => -3.5,
'C' => 2.5,
'D' => -3.5,
'E' => -3.5,
'F' => 2.8,
'G' => -0.4,
'H' => -3.2,
'I' => 4.5,
'K' => -3.9,
'L' => 3.8,
'M' => 1.9,
'N' => -3.5,
'P' => -1.6,
'Q' => -3.5,
'R' => -4.5,
'S' => -0.8,
'T' => -0.7,
'U' => 0.0,
'V' => 4.2,
'W' => -0.9,
'Y' => -1.3,
'X' => -0.49,
'Z' => -3.5,
}
scores = Array.new
len = seq.length
3.upto(len-4) do |i|
score = 0.0
(i-3).upto(i+3) do |j|
score += hydropathy_index[seq[j]]
end
score /= 7.0
#puts sprintf("%3.1f", score)
scores.push(score)
end
hscore = scores.inject(0.0){|sum, s| sum + s} / scores.length
puts "Score: ", hscore
thres = [-0.4] * scores.length
g = Gruff::Line.new
g.title = "Hydropathy"
g.data("Score", scores)
g.data("Threshold", thres)
g.write("hydrophobicity_graph.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment