diff --git a/src/main.go b/src/main.go index a948e39..4934b65 100644 --- a/src/main.go +++ b/src/main.go @@ -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 @@ -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) diff --git a/src/test.sh b/src/test.sh index ebad0c8..afd8cc0 100644 --- a/src/test.sh +++ b/src/test.sh @@ -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 +