Skip to content

Commit

Permalink
fixed regex pattern and additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
gwirn committed Aug 25, 2023
1 parent bd89f48 commit c0ba594
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
22 changes: 18 additions & 4 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func fMatrix(str1, str2 string, gapP, mismatchP, match int) ([][]int, int, int)
}

/*
Trace back the path thorough the distance matrix recursively
Trace back the path through the distance matrix recursively
:parameters
* btDistMat: distance matrix to trace back the alignment
Expand Down Expand Up @@ -190,9 +190,23 @@ func showSearch(pattern, searchString string, inAlgn1, inAlgn2 []rune, color str
quality := (lenMatch - (numIns - numGapRunePattern)) / (lenPattern - numGapRunePattern)

if quality >= qualityCutOff {
// search for aligned section in the search string
a2RePat := strings.ReplaceAll(string(inAlgn2), "-", "*-?")
m := regexp.MustCompile(a2RePat)
// search for aligned section in the search string and build regex pattern
var rePatBuilder strings.Builder
splitAlgn2 := strings.Split(string(inAlgn2), "-")
partsNum := len(splitAlgn2)
lastPartInd := partsNum-1
for i := 0; i < partsNum; i++ {
if len(splitAlgn2[i]) > 0 {
// to avoid trailing *-?
if i != lastPartInd {
rePatBuilder.WriteString(splitAlgn2[i])
rePatBuilder.WriteString("*-?")
} else {
rePatBuilder.WriteString(splitAlgn2[i])
}
}
}
m := regexp.MustCompile(rePatBuilder.String())
allInd := m.FindAllSubmatchIndex([]byte(searchString), -1)
// number of all matches
numInds := len(allInd)
Expand Down
27 changes: 21 additions & 6 deletions src/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,31 @@ else
echo "PASS: Pattern matching for input from StdIn "
fi

if [[ ! $(go run main.go wold ../testFiles/* | grep world | wc -l) -eq 6 ]];then
echo "FAILED: Reduced 'world' -> 'wold'"
if [[ ! $(go run main.go -quality 75 wold ../testFiles/* | grep world | wc -l) -eq 6 ]];then
echo "FAILED: Deletion 'world' -> 'wold'"
exit 1
else
echo "PASS: Reduced 'world' -> 'wold'"
echo "PASS: Deletion 'world' -> 'wold'"
fi

if [[ ! $(go run main.go wod ../testFiles/* | grep world | wc -l) -eq 0 && ! $(go run main.go wod ../testFiles/* | wc -l) -eq 0 ]];then
echo "FAILED: Reduced 'world' -> 'wold'"
if [[ ! $(go run main.go -quality 75 wod ../testFiles/* | grep ../testFiles/testFile | wc -l) -eq 2 ]];then
echo "FAILED: Deletion 'world' -> 'wod'"
exit 1
else
echo "PASS: Reduced 'world' -> 'wod'"
echo "PASS: Deletion 'world' -> 'wod'"
fi

if [[ ! $(go run main.go -quality 75 lixxne ../testFiles/testFile* | grep line | wc -l) -eq 6 ]];then
echo "FAILED: Insertion 'line' -> 'lixxne'"
exit 1
else
echo "PASS: Insertion 'line' -> 'lixxne'"
fi

if [[ ! $(go run main.go -quality 75 lixxxne ../testFiles/* | grep ../testFiles/testFile | wc -l) -eq 2 ]];then
echo "FAILED: Insertion 'line' -> 'lixxxne'"
exit 1
else
echo "PASS: Insertion 'line' -> 'lixxxne'"
fi

0 comments on commit c0ba594

Please sign in to comment.