Skip to content

Commit

Permalink
Add option to append current kSNP3 run to an existing tree (#122)
Browse files Browse the repository at this point in the history
* save SNPs_all output file for appending new files to existing tree

* add option to pass snps_all file to append trees to an existing one

* fix dyslexia
  • Loading branch information
cimendes authored Jul 20, 2023
1 parent affc302 commit 878afcd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tasks/phylogenetic_inference/task_ksnp3.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ task ksnp3 {
String cluster_name
Int kmer_size = 19
String ksnp3_args = "" # add -ML to calculate a maximum likelihood tree or -NJ to calculate a neighbor-joining tree
File? previous_ksnp3_snps
String docker_image = "quay.io/staphb/ksnp3:3.1"
Int memory = 8
Int cpu = 4
Expand Down Expand Up @@ -48,12 +49,21 @@ task ksnp3 {
cat ksnp3_input.tsv

# run ksnp3 on input assemblies
kSNP3 -in ksnp3_input.tsv -outdir ksnp3 -k ~{kmer_size} -core -vcf ~{ksnp3_args}
kSNP3 \
-in ksnp3_input.tsv \
-outdir ksnp3 \
-k ~{kmer_size} \
-core -vcf \
~{'-SNPs_all ' + previous_ksnp3_snps} \
~{ksnp3_args}

# rename ksnp3 outputs with cluster name
# sometimes the core nwk and fasta outputs do not have content
mv -v ksnp3/core_SNPs_matrix.fasta ksnp3/~{cluster_name}_core_SNPs_matrix.fasta
mv -v ksnp3/tree.core.tre ksnp3/~{cluster_name}_core.nwk

# to allow appending new genomes to an existing tree, save the SNPs_all file
mv -v ksnp3/SNPs_all ksnp3/~{cluster_name}_SNPs_all

if [ -s ksnp3/~{cluster_name}_core_SNPs_matrix.fasta ]; then # is the file not-empty?
echo "The core SNP matrix was produced" | tee SKIP_SNP_DIST # then do NOT skip
Expand Down Expand Up @@ -82,6 +92,7 @@ task ksnp3 {
File? ksnp3_ml_tree = "ksnp3/~{cluster_name}_ML.nwk"
File? ksnp3_nj_tree = "ksnp3/~{cluster_name}_NJ.nwk"
File number_snps = "ksnp3/COUNT_SNPs"
File ksnp3_snps_all = "ksnp3/~{cluster_name}_SNPs_all"
File ksnp3_input = "ksnp3_input.tsv"
String skip_core_snp_dists = read_string("SKIP_SNP_DIST")
Array[File] ksnp_outs = glob("ksnp3/*")
Expand Down
1 change: 1 addition & 0 deletions workflows/phylogenetics/wf_ksnp3.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ workflow ksnp3_workflow {
String ksnp3_snp_dists_version = pan_snp_dists.snp_dists_version
File ksnp3_core_vcf = ksnp3_task.ksnp3_core_vcf
String ksnp3_core_snp_matrix_status = ksnp3_task.skip_core_snp_dists
File ksnp3_snps = ksnp3_task.ksnp3_snps_all
# ordered matrixes and reordered trees
File? ksnp3_core_snp_matrix = core_reorder_matrix.ordered_matrix
File? ksnp3_core_tree = core_reorder_matrix.tree
Expand Down

0 comments on commit 878afcd

Please sign in to comment.