let align
~reference_build
~fastq
~(result_prefix:string)
~(run_with : Machine.t)
?(configuration=Configuration.Align.default)
() =
let open KEDSL in
let reference_fasta =
Machine.get_reference_genome run_with reference_build
|> Reference_genome.fasta in
let in_work_dir =
Program.shf "cd %s" Filename.(quote (dirname result_prefix)) in
let star_tool = Machine.get_tool run_with Machine.Tool.Default.star in
let star_index = index ~reference_build ~run_with in
let reference_dir = (Filename.dirname reference_fasta#product#path) in
let star_index_dir = sprintf "%s/star-index/" reference_dir in
let result = sprintf "%sAligned.out.bam" result_prefix in
let r1_path, r2_path_opt = fastq#product#paths in
let name = sprintf "star-rna-align-%s" (Filename.basename r1_path) in
let processors = Machine.max_processors run_with in
let star_base_command = sprintf
"STAR --outSAMtype BAM Unsorted --outSAMstrandField intronMotif --outSAMattributes NH HI NM MD --outFilterIntronMotifs RemoveNoncanonical --genomeDir %s --runThreadN %d --outFileNamePrefix %s --outSAMattrRGline %s %s --readFilesIn %s"
(Filename.quote star_index_dir)
processors
result_prefix
(sprintf "ID:%s SM:\"%s\""
(Filename.basename r1_path)
fastq#product#sample_name)
(Configuration.Align.render configuration
|> String.concat ~sep:" ")
(Filename.quote r1_path)
in
let base_star_target ~star_command =
workflow_node ~name
(bam_file
~host:(Machine.(as_host run_with))
~reference_build
result)
~edges:[
on_failure_activate (Remove.file ~run_with result);
depends_on reference_fasta;
depends_on star_index;
depends_on fastq;
depends_on Machine.Tool.(ensure star_tool);
]
~tags:[Target_tags.aligner]
~make:(Machine.run_big_program run_with ~processors ~name
~self_ids:["star"; "align"]
Program.(
Machine.Tool.(init star_tool)
&& in_work_dir
&& sh star_command
))
in
match r2_path_opt with
| Some read2 ->
let star_command =
String.concat ~sep:" " [
star_base_command;
(Filename.quote read2);
] in
base_star_target ~star_command
| None ->
let star_command = star_base_command in
base_star_target ~star_command