Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

All the k-mers/n-grams

--All the k-mers/n-grams
if object_id('dbo.n','IF')is not null drop function dbo.n; 
go
create function dbo.f(@s nvarchar(max),@ int)returns table as return
with v as(select 2 p,left(@s,@)g where len(@s)>=@ union all
select p+1,substring(@s,p,@)from v where len(@s)>p-2+@)select g from v
go
with t as(select s from(values('ATCGAAGGTCGT'),('AT'))t(s))
select s,g from t outer apply dbo.f(s,4)
 run  | edit  | history  | help 0