-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathExamplePositionMatchAlgorithm.java
More file actions
51 lines (46 loc) · 1.4 KB
/
ExamplePositionMatchAlgorithm.java
File metadata and controls
51 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* A simple example similarity algorithm.
*
* This algorithm counts the number of matching characters
* in corresponding positions up to the length of the shorter sequence.
*
* @author Dr. Jody Paul
* @version 2026-03-10
*/
public class ExamplePositionMatchAlgorithm implements SequenceScoringAlgorithm {
/**
* Returns the display name of this algorithm.
* @return the algorithm name
*/
@Override
public String getName() {
return "Exact Position Matches";
}
/**
* Counts matching positions between two DNA sequences up to the
* length of the shorter sequence.
*
* @param databaseSequence a DNA sequence from the database
* @param querySequence the query DNA sequence
* @return the number of matching positions
*/
@Override
public double score(String databaseSequence, String querySequence) {
int minLength = Math.min(databaseSequence.length(), querySequence.length());
int matches = 0;
for (int i = 0; i < minLength; i++) {
if (databaseSequence.charAt(i) == querySequence.charAt(i)) {
matches++;
}
}
return matches;
}
/**
* Indicate that larger scores are better matches.
* @return true because more matching positions means a better match
*/
@Override
public boolean higherScoreIsBetter() {
return true;
}
}