Skip to content

Instantly share code, notes, and snippets.

@djvs
Last active September 5, 2015 17:48
Show Gist options
  • Save djvs/28f2da2eb15b2f3a9db5 to your computer and use it in GitHub Desktop.
Save djvs/28f2da2eb15b2f3a9db5 to your computer and use it in GitHub Desktop.
# ruby script to compare text-based gene sequences, will delete all non-alphabetical characters and do a straight array comparison, assuming equal size
#
# invocation: ruby 'compare gene sequences.rb' file1.txt file2.txt
puts "comparing: #{ARGV}"
s1=File.read(ARGV[0]).gsub(/[^a-z]/,"")
s2=File.read(ARGV[1]).gsub(/[^a-z]/,"")
a1 = s1.split("")
a2 = s2.split("")
puts "sequence 1: #{s1.length} nts long"
puts "sequence 2: #{s2.length} nts long"
mg = a1.zip(a2)
bad = 0
good = 0
mg.each do |x|
if x[0] == x[1]
good += 1
else
bad += 1
end
end
puts "genes differing : #{bad}"
puts "genes the same : #{good}"
puts "percent similar : #{(good.to_f / (bad + good).to_f) * 100}%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment