let faidx ~(run_with:Machine.t) fasta =
let open KEDSL in
let samtools = Machine.get_tool run_with Machine.Tool.Default.samtools in
let src = fasta#product#path in
let dest = sprintf "%s.%s" src "fai" in
let program =
Program.(Machine.Tool.(init samtools) && exec ["samtools"; "faidx"; src]) in
let name = sprintf "samtools-faidx-%s" Filename.(basename src) in
let make = Machine.run_program ~name run_with program in
let host = Machine.(as_host run_with) in
workflow_node
(single_file dest ~host) ~name ~make
~edges:[
depends_on fasta;
depends_on Machine.Tool.(ensure samtools);
on_failure_activate (Remove.file ~run_with dest);
]