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/09-subs.md
+17-35Lines changed: 17 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ Let's start off with the most verbose solution.
40
40
We can loop over every character within the input string and
41
41
check if we can find the substring in the subsequent characters.
42
42
43
-
In the first solution,
43
+
In other words,
44
44
we will check each index for an exact match to the substring we are searching for.
45
45
46
46
```julia
@@ -74,20 +74,20 @@ end
74
74
75
75
haystack(search_string, dataset)
76
76
```
77
-
We can also use the [`findnext`](https://docs.julialang.org/en/v1/base/strings/#Base.findnext) function in Julia.
78
77
79
-
There are similar `findfirst` and `findlast` functions,
80
-
but since we want to find all matches,
81
-
we will use `findnext`.
78
+
### Biojulia solution
79
+
80
+
The BioSequences package has a helpful function [`findall`](https://github.com/BioJulia/BioSequences.jl/blob/b626dbcaad76217b248449e6aa2cc1650e95660c/src/BioSequences.jl#L261-L316),
81
+
which returns the indices of all exact string matches.
82
82
83
-
Currently, there isn't a `findall` function that allows us to avoid a loop.
84
-
We'll still also loop over every character in the string,
85
-
as there could be overlapping substrings.
83
+
It isn't included in the documentation about exact string search [here](https://biojulia.dev/BioSequences.jl/v2.0/sequence_search/#Exact-search-1),
84
+
but the function exists!
86
85
86
+
BioSequences has other helpful exact string search functions like `findfirst`, `firstnext`, and `findlast`.
87
87
88
88
89
89
```julia
90
-
functionhaystack_findnext(substring, string)
90
+
functionhaystack_findall(substring, string)
91
91
# check if the strings are empty
92
92
ifisempty(substring) ||isempty(string)
93
93
throw(ErrorException("empty sequences"))
@@ -98,29 +98,19 @@ function haystack_findnext(substring, string)
0 commit comments