-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
4 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
require_relative 'strand' | ||
|
||
class Hamming | ||
class SequenceLengthError < ArgumentError; end | ||
|
||
def self.compute(sequence1, sequence2) | ||
strand1 = Strand.new(sequence1.chars) | ||
strand2 = Strand.new(sequence2.chars) | ||
|
||
new(strand1, strand2).distance | ||
end | ||
|
||
def distance | ||
sequence1.zip(sequence2).count { |m1, m2| m1 != m2 } | ||
end | ||
|
||
private | ||
|
||
attr_reader :sequence1, :sequence2 | ||
|
||
def initialize(sequence1, sequence2) | ||
unless sequence1.length == sequence2.length | ||
raise SequenceLengthError, 'sequences must have the same length' | ||
end | ||
def self.compute(strand1, strand2) | ||
raise ArgumentError unless strand1.length == strand2.length | ||
raise ArgumentError if (strand1 + strand2) =~ /^[ACTG]$/ | ||
|
||
@sequence1 = sequence1 | ||
@sequence2 = sequence2 | ||
strand1.chars.zip(strand2.chars).count { |n1, n2| n1 != n2 } | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.