Last active
September 5, 2015 17:48
-
-
Save djvs/28f2da2eb15b2f3a9db5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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