let ensure_one_flowcell_max files =
let open Pvem_lwt_unix.Deferred_result in
let flowcell_re = Re.compile (Re_posix.re {re|.*(\..+)?\.fastq\.gz|re}) in
let flowcells =
Pvem_lwt_unix.Deferred_list.while_sequential files
~f:(fun f -> match Re.Group.all (Re.exec flowcell_re f) with
| [|_; flowcell|] -> return flowcell
| _ -> fail (`Re_group_error
"Re.Group.all returned an unexpected number of groups."))
in
flowcells >>| List.dedup >>= fun flowcells ->
if List.length flowcells > 1
then fail (`Multiple_flowcells flowcells)
else return files