Bioinformatics/Subsequence: Difference between revisions
Content added Content deleted
Line 74: | Line 74: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Note: match_all() is due to become a builtin in the next release, so the version below may or may not need renaming/deleting before it will run. |
Note: match_all() is due to become a builtin in the next release, so the version below may or may not need renaming/deleting before it will run.<br> |
||
Currently only searches for non-overlapped sequences, but it should be pretty obviuous how to change that, in which case the next underline will simply partially overwrite the previous, so you'll get eg "<=<==>". |
|||
<lang Phix>constant cheat = false |
<lang Phix>constant cheat = false |
||
Line 119: | Line 120: | ||
end procedure |
end procedure |
||
function match_all(object needle, sequence haystack) |
function match_all(object needle, sequence haystack, bool bOverlap = false) |
||
if atom(needle) then return find_all(needle,haystack) end if |
|||
integer start = 1 |
integer start = 1 |
||
sequence res = {} |
sequence res = {} |
||
Line 126: | Line 128: | ||
if start=0 then exit end if |
if start=0 then exit end if |
||
res = append(res,start) |
res = append(res,start) |
||
start += length(needle) |
start += iff(bOverlap?1:length(needle)) |
||
end while |
end while |
||
return res |
return res |