let concat : Annotated_file.t -> Annotated_file.t =
fun l ->
begin match get_list (AF.get_file l) with
| Fastq one :: [] ->
Fastq one
|> AF.with_provenance "concat" ["single-element", AF.get_provenance l]
| Fastq first_fastq :: _ as lfq ->
let fqs = List.map lfq ~f:get_fastq in
let r1s = List.map fqs ~f:(KEDSL.read_1_file_node) in
let r2s = List.filter_map fqs ~f:KEDSL.read_2_file_node in
let concat_files ~read l =
let result_path =
Name_file.in_directory
Config.work_dir
~readable_suffix:(
sprintf "%s-Read%d-Concat.fastq"
first_fastq#product#escaped_sample_name read) (
first_fastq#product#escaped_sample_name
:: first_fastq#product#fragment_id_forced
:: List.map l ~f:(fun wf -> wf#product#path)
)
in
Workflow_utilities.Cat.concat ~run_with l ~result_path in
let read_1 = concat_files r1s ~read:1 in
let read_2 =
match r2s with [] -> None | more -> Some (concat_files more ~read:2)
in
Fastq (
KEDSL.fastq_node_of_single_file_nodes ~host
~name:first_fastq#product#sample_name
~fragment_id:"edsl-concat"
read_1 read_2
)
|> AF.with_provenance "concat" ["fastq-list", AF.get_provenance l]
| other ->
ksprintf failwith "To_workflow.concat: not implemented"
end