You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/rosalind/06-hamm.md
+69-14Lines changed: 69 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,9 @@
4
4
5
5
!!! warning "The Problem"
6
6
7
-
Given two strings s and t of equal length, the Hamming distance between s and t, denoted dH(s,t), is the number of corresponding symbols that differ in s and t.
7
+
Given two strings s and t of equal length,
8
+
the Hamming distance between s and t, denoted dH(s,t),
9
+
is the number of corresponding symbols that differ in s and t.
8
10
9
11
10
12
Given: Two DNA strings s and t of equal length (not exceeding 1 kbp).
@@ -25,9 +27,11 @@
25
27
```
26
28
27
29
28
-
To calculate the Hamming Distance between two strings/sequences, the two strings/DNA sequences must be the same length.
30
+
To calculate the Hamming Distance between two strings/sequences,
31
+
the two strings/DNA sequences must be the same length.
29
32
30
-
The simplest way to solve this problem is to compare the corresponding values in each string for each index and then sum the mismatches. This is the fastest and most idiomatic Julia solution, as it leverages vector math.
33
+
The simplest way to solve this problem is to compare the corresponding values in each string for each index and then sum the mismatches.
34
+
This is the fastest and most idiomatic Julia solution, as it leverages vector math.
Another way we can approach this would be to use the for-loop. This method will be a bit slower.
47
+
Another way we can approach this would be to use the for-loop.
48
+
For loops are traditionally slower and clunkier (especially in Python).
49
+
However, Julia can often optimize for-loops like this,
50
+
which is one of the things that makes it so powerful.
51
+
It has multiple processing units that can run the same task parallelly.
46
52
47
-
We can calculate the Hamming Distance by looping over the characters in one of the strings and checking if the corresponding character at the same index in the other string matches.
53
+
We can calculate the Hamming Distance by looping over the characters in one of the strings
54
+
and checking if the corresponding character at the same index in the other string matches.
48
55
49
-
Each mismatch will cause 1 to be added to a `counter` variable. At the end of the loop, we can return the total value of the `counter` variable.
56
+
Each mismatch will cause 1 to be added to a `counter` variable.
57
+
At the end of the loop, we can return the total value of the `counter` variable.
50
58
51
59
52
60
@@ -101,22 +109,43 @@ bio_hamming[1]
101
109
```
102
110
103
111
104
-
The BioAlignments `hamming_distance` function requires three input variables -- the first of which allows the user to control the `type` of the returned hamming distance value.
112
+
The BioAlignments `hamming_distance` function requires three input variables --
113
+
the first of which allows the user to control the `type` of the returned hamming distance value.
105
114
106
-
In the above example, `Int64` is provided as the first input variable, but `Float64` or `Int8` are also acceptable inputs. The second two input variables are the two sequences that are being compared.
115
+
In the above example, `Int64` is provided as the first input variable,
116
+
but `Float64` or `Int8` are also acceptable inputs.
117
+
The second two input variables are the two sequences that are being compared.
107
118
108
-
There are two outputs of this function: the actual Hamming Distance value and the Alignment Anchor. The Alignment Anchor is a one-dimensional array (vector) that is the same length as the length of the input strings.
119
+
There are two outputs of this function:
120
+
the actual Hamming Distance value and the Alignment Anchor.
121
+
The Alignment Anchor is a one-dimensional array (vector) that is the same length as the length of the input strings.
109
122
110
-
Each value in the vector is also an AlignmentAnchor with three fields: sequence position, reference position, and an operation code ('0' for start, '=' for match, 'X' for mismatch).
123
+
Each value in the vector is also an AlignmentAnchor with three fields:
124
+
sequence position, reference position, and an operation code
Another package that calculates the Hamming distance is the [Distances package](https://github.com/JuliaStats/Distances.jl). We can call its `hamming` function on our two test sequences:
147
+
Another package that calculates the Hamming distance is the [Distances package](https://github.com/JuliaStats/Distances.jl).
148
+
We can call its `hamming` function on our two test sequences:
0 commit comments