let trim (specification: [`beginning of int|`ending of int]) =
let items = Queue.create () in
let name =
sprintf "(fastq_trimmer %s)"
(match specification with
| `beginning i -> sprintf "B:%d" i
| `ending i -> sprintf "E:%d" i) in
Biocaml_transform.make ~name ()
~feed:(fun r -> Queue.enqueue items r)
~next:(fun stopped ->
begin match Queue.dequeue items with
| Some r ->
let rlgth = String.length r.sequence in
begin match specification with
| `beginning i when i < rlgth ->
output_ok
{ r with sequence = String.sub r.sequence ~pos:i ~len:(rlgth - i);
qualities = String.sub r.qualities ~pos:i ~len:(rlgth - i) }
| `ending i when i < rlgth ->
output_ok
{ r with sequence = String.sub r.sequence ~pos:0 ~len:(rlgth - i);
qualities = String.sub r.qualities ~pos:0 ~len:(rlgth - i) }
| _ ->
output_error (`invalid_size rlgth)
end
| None -> if stopped then `end_of_stream else `not_ready
end)