Skip to content

Commit ddbe7dc

Browse files
authored
add mafft_and_snp_annotated.wdl (#194)
* add mafft_and_snp_annotated.wdl * rename workflow * Update .dockstore.yml * replace s/^1/$chr_name/g in annotate_vcf_snpeff The vcf output by snp-sites usus "1" as the chromosome name for its output, while snpEff expects the chromosome name to match that of the reference. This renames the chr name in annotate_vcf_snpeff so snpEff succeeds. This will fail for multi-chr vcfs. * remove txt output from merge_vcfs_and_annotate
1 parent dce92a1 commit ddbe7dc

4 files changed

Lines changed: 112 additions & 11 deletions

File tree

.dockstore.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ workflows:
180180
primaryDescriptorPath: /pipes/WDL/workflows/mafft_and_snp.wdl
181181
testParameterFiles:
182182
- empty.json
183+
- name: mafft_and_snp_annotated
184+
subclass: WDL
185+
primaryDescriptorPath: /pipes/WDL/workflows/mafft_and_snp_annotated.wdl
186+
testParameterFiles:
187+
- empty.json
183188
- name: mafft_and_trim
184189
subclass: WDL
185190
primaryDescriptorPath: /pipes/WDL/workflows/mafft_and_trim.wdl

pipes/WDL/tasks/tasks_intrahost.wdl

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,53 @@ task annotate_vcf_snpeff {
150150
fi
151151
echo "snpRefAccessions: $snpRefAccessions"
152152
153+
vcf_to_use=""
153154
if (file "${in_vcf}" | grep -q "gzip" ) ; then
154155
echo "${in_vcf} is already compressed"
156+
vcf_to_use="${in_vcf}"
155157
else
156158
echo "${in_vcf} is not compressed; gzipping..."
157159
bgzip "${in_vcf}"
160+
vcf_to_use="${in_vcf}.gz"
158161
fi
162+
163+
# renames the seq id using the first sequence in the alignment
164+
ref_name=$(head -n1 "~{ref_fasta}" | sed -E 's/^>([^[:space:]]+).*$/\1/g')
165+
ref_name_no_version=$(head -n1 "~{ref_fasta}" | sed -E 's/^>([^[:space:]\.]+).*$/\1/g')
166+
# copy the input or just created gzipped vcf file
167+
cp "$vcf_to_use" "temp.vcf.gz"
168+
# ensure uncompressed
169+
bgzip -d "temp.vcf.gz"
170+
# rename chr field (first col) in vcf
171+
cat "temp.vcf" | sed "s/^1/$ref_name_no_version/" > "temp2.vcf"
172+
173+
# output the vcf, removing the reference sequence if present as a sample name
174+
bgzip "temp2.vcf"
175+
tabix -p vcf "temp2.vcf.gz"
176+
bcftools index "temp2.vcf.gz"
177+
bcftools view -s "^$ref_name" "temp2.vcf.gz" > "temp3.vcf"
178+
rm "temp2.vcf.gz"
179+
vcf_to_use="temp3.vcf"
180+
181+
# compress vcf
182+
bgzip -c "$vcf_to_use" > "$vcf_to_use.gz"
183+
vcf_to_use="$vcf_to_use.gz"
184+
185+
# index vcf
159186
echo "Creating vcf index"
160-
tabix -p vcf "${in_vcf}"
161-
187+
bcftools index "$vcf_to_use"
188+
tabix -p vcf "$vcf_to_use"
189+
162190
interhost.py snpEff \
163-
"${in_vcf}" \
191+
"$vcf_to_use" \
164192
$snpRefAccessions \
165193
"${output_basename}.annot.vcf.gz" \
166194
${'--emailAddress=' + emailAddress}
167-
168-
intrahost.py iSNV_table \
169-
"${output_basename}.annot.vcf.gz" \
170-
"${output_basename}.annot.txt.gz"
171-
172-
tabix -p vcf "${output_basename}.annot.vcf.gz"
173195
}
174196

175197
output {
176198
File annot_vcf_gz = "${output_basename}.annot.vcf.gz"
177199
File annot_vcf_gz_tbi = "${output_basename}.annot.vcf.gz.tbi"
178-
File annot_txt_gz = "${output_basename}.annot.txt.gz"
179200
String viralngs_version = read_string("VERSION")
180201
}
181202
runtime {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version 1.0
2+
3+
import "../tasks/tasks_nextstrain.wdl" as nextstrain
4+
import "../tasks/tasks_intrahost.wdl" as intrahost
5+
6+
workflow mafft_and_snp_annotated {
7+
meta {
8+
description: "Align assemblies with mafft and find SNPs with snp-sites."
9+
author: "Broad Viral Genomics"
10+
email: "viral-ngs@broadinstitute.org"
11+
}
12+
13+
input {
14+
Array[File] assembly_fastas
15+
File ref_fasta
16+
Int min_unambig_genome
17+
Boolean run_iqtree=false
18+
}
19+
20+
parameter_meta {
21+
assembly_fastas: {
22+
description: "Set of assembled genomes to align and build trees. These must represent a single chromosome/segment of a genome only. Fastas may be one-sequence-per-individual or a concatenated multi-fasta (unaligned) or a mixture of the two. They may be compressed (gz, bz2, zst, lz4), uncompressed, or a mixture.",
23+
patterns: ["*.fasta", "*.fa", "*.fasta.gz", "*.fasta.zst"]
24+
}
25+
ref_fasta: {
26+
description: "A reference assembly (not included in assembly_fastas) to align assembly_fastas against. Typically from NCBI RefSeq or similar. Uncompressed.",
27+
patterns: ["*.fasta", "*.fa"]
28+
}
29+
min_unambig_genome: {
30+
description: "Minimum number of called bases in genome to pass prefilter."
31+
}
32+
}
33+
34+
call nextstrain.gzcat {
35+
input:
36+
infiles = assembly_fastas,
37+
output_name = "all_samples_combined_assembly.fasta.gz"
38+
}
39+
call nextstrain.filter_sequences_by_length {
40+
input:
41+
sequences_fasta = gzcat.combined,
42+
min_non_N = min_unambig_genome
43+
}
44+
call nextstrain.mafft_one_chr as mafft {
45+
input:
46+
sequences = filter_sequences_by_length.filtered_fasta,
47+
ref_fasta = ref_fasta,
48+
basename = "all_samples_aligned.fasta"
49+
}
50+
call nextstrain.snp_sites {
51+
input:
52+
msa_fasta = mafft.aligned_sequences
53+
}
54+
55+
call intrahost.annotate_vcf_snpeff as annotate_vcf {
56+
input:
57+
ref_fasta = ref_fasta,
58+
in_vcf = snp_sites.snps_vcf
59+
}
60+
61+
if(run_iqtree) {
62+
call nextstrain.draft_augur_tree {
63+
input:
64+
msa_or_vcf = mafft.aligned_sequences
65+
}
66+
}
67+
68+
output {
69+
File combined_assemblies = filter_sequences_by_length.filtered_fasta
70+
File multiple_alignment = mafft.aligned_sequences
71+
File unmasked_snps = snp_sites.snps_vcf
72+
File unmasked_snps_annotated = annotate_vcf.annot_vcf_gz
73+
File unmasked_snps_annotated_tbi = annotate_vcf.annot_vcf_gz_tbi
74+
File? ml_tree = draft_augur_tree.aligned_tree
75+
}
76+
}

pipes/WDL/workflows/merge_vcfs_and_annotate.wdl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ workflow merge_vcfs_and_annotate {
3333
File merged_vcf_gz_tbi = merge_vcfs.merged_vcf_gz_tbi
3434
File merged_annot_vcf_gz = annotate_vcf.annot_vcf_gz
3535
File merged_annot_vcf_gz_tbi = annotate_vcf.annot_vcf_gz_tbi
36-
File merged_annot_txt_gz = annotate_vcf.annot_txt_gz
3736
}
3837
}

0 commit comments

Comments
 (0)