Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippy_Variants: Calculate % reads aligned #616

Merged
merged 8 commits into from
Oct 3, 2024
14 changes: 12 additions & 2 deletions tasks/gene_typing/variant_detection/task_snippy_variants.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ task snippy_variants {
# Compress output dir
tar -cvzf "./~{samplename}_snippy_variants_outdir.tar" "./~{samplename}"

# compute number of reads aligned to reference
samtools view -c "~{samplename}/~{samplename}.bam" > READS_ALIGNED_TO_REFERENCE
# compute number of reads aligned to reference (excluding unmapped reads)
samtools view -c -F 4 "~{samplename}/~{samplename}.bam" > READS_ALIGNED_TO_REFERENCE

# create coverage stats file
samtools coverage "~{samplename}/~{samplename}.bam" -o "~{samplename}/~{samplename}_coverage.tsv"
Expand Down Expand Up @@ -93,6 +93,15 @@ task snippy_variants {
echo $reference_length_passed_depth $reference_length | awk '{ print ($1/$2)*100 }' > PERCENT_REF_COVERAGE
fi

# Compute percentage of reads aligned
reads_aligned=$(cat READS_ALIGNED_TO_REFERENCE)
total_reads=$(samtools view -c "~{samplename}/~{samplename}.bam")
if [ "$total_reads" -eq 0 ]; then
echo "Could not compute percent reads aligned: total reads is 0" > PERCENT_READS_ALIGNED
else
echo $reads_aligned $total_reads | awk '{ print ($1/$2)*100 }' > PERCENT_READS_ALIGNED
fi

>>>
output {
String snippy_variants_version = read_string("VERSION")
Expand All @@ -111,6 +120,7 @@ task snippy_variants {
String snippy_variants_ref_length = read_string("REFERENCE_LENGTH")
String snippy_variants_ref_length_passed_depth = read_string("REFERENCE_LENGTH_PASSED_DEPTH")
String snippy_variants_percent_ref_coverage = read_string("PERCENT_REF_COVERAGE")
String snippy_variants_percent_read_aligned = read_string("PERCENT_READS_ALIGNED")
fraser-combe marked this conversation as resolved.
Show resolved Hide resolved
}
runtime {
docker: "~{docker}"
Expand Down