Skip to content

Instantly share code, notes, and snippets.

@geetduggal
Last active April 15, 2020 21:21
Show Gist options
  • Save geetduggal/ca0786137ef6109315cc7a729593bd81 to your computer and use it in GitHub Desktop.
Save geetduggal/ca0786137ef6109315cc7a729593bd81 to your computer and use it in GitHub Desktop.
workflow bam_chrom_counter {
File bam
Int i
call slice_bam {
input : bam = bam
}
scatter (slice in slice_bam.slices) {
call count_bam {
input: bam = slice
}
}
output {
File bai = slice_bam.bai
Array[Int] counts = count_bam.count
}
}
task slice_bam {
File bam
Int num_chrom = 22
command <<<
set -ex
samtools index ${bam}
mkdir slices/
for i in `seq ${num_chrom}`; do
samtools view -b ${bam} -o slices/$i.bam $i
done
>>>
runtime {
docker: "quay.io/ucsc_cgl/samtools"
}
output {
File bai = "${bam}.bai"
Array[File] slices = glob("slices/*.bam")
}
}
task count_bam {
File bam
command <<<
samtools view -c ${bam}
>>>
runtime {
docker: "quay.io/ucsc_cgl/samtools"
}
output {
Int count = read_int(stdout())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment