Skip to content

Commit

Permalink
Move rules for exporting auspice json to its own smk file
Browse files Browse the repository at this point in the history
Part of work to update this repo to match the pathogen-repo-template.
  • Loading branch information
j23414 committed Dec 18, 2023
1 parent 2ed2103 commit a37480e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 54 deletions.
55 changes: 1 addition & 54 deletions phylogenetic/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,7 @@ include: "workflow/snakemake_rules/usvi.smk"
include: "workflow/snakemake_rules/prepare_sequences.smk"
include: "workflow/snakemake_rules/construct_phylogeny.smk"
include: "workflow/snakemake_rules/annotate_phylogeny.smk"

rule export:
"""Exporting data files for for auspice"""
input:
tree = "results/tree.nwk",
metadata = "data/metadata_all.tsv",
branch_lengths = "results/branch_lengths.json",
traits = "results/traits.json",
nt_muts = "results/nt_muts.json",
aa_muts = "results/aa_muts.json",
colors = files.colors,
auspice_config = files.auspice_config,
description = files.description
output:
auspice_json = "results/raw_zika.json",
root_sequence = "results/raw_zika_root-sequence.json",
params:
strain_id = config.get("strain_id_field", "strain"),
shell:
"""
augur export v2 \
--tree {input.tree} \
--metadata {input.metadata} \
--metadata-id-columns {params.strain_id} \
--node-data {input.branch_lengths} {input.traits} {input.nt_muts} {input.aa_muts} \
--colors {input.colors} \
--auspice-config {input.auspice_config} \
--description {input.description} \
--include-root-sequence \
--output {output.auspice_json}
"""

rule final_strain_name:
input:
auspice_json="results/raw_zika.json",
metadata="data/metadata_all.tsv",
root_sequence="results/raw_zika_root-sequence.json",
output:
auspice_json="auspice/zika.json",
root_sequence="auspice/zika_root-sequence.json",
params:
strain_id=config["strain_id_field"],
display_strain_field=config.get("display_strain_field", "strain"),
shell:
"""
python3 scripts/set_final_strain_name.py \
--metadata {input.metadata} \
--metadata-id-columns {params.strain_id} \
--input-auspice-json {input.auspice_json} \
--display-strain-name {params.display_strain_field} \
--output {output.auspice_json}
cp {input.root_sequence} {output.root_sequence}
"""
include: "workflow/snakemake_rules/export.smk"

rule clean:
"""Removing directories: {params}"""
Expand Down
80 changes: 80 additions & 0 deletions phylogenetic/workflow/snakemake_rules/export.smk
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
This part of the workflow collects the phylogenetic tree and annotations to
export a Nextstrain dataset.
REQUIRED INPUTS:
metadata = data/metadata_all.tsv
tree = results/tree.nwk
branch_lengths = results/branch_lengths.json
node_data = results/*.json
OUTPUTS:
auspice_json = auspice/${build_name}.json
There are optional sidecar JSON files that can be exported as part of the dataset.
See Nextstrain's data format docs for more details on sidecar files:
https://docs.nextstrain.org/page/reference/data-formats.html
This part of the workflow usually includes the following steps:
- augur export v2
- augur frequencies
See Augur's usage docs for these commands for more details.
"""

rule export:
"""Exporting data files for for auspice"""
input:
tree = "results/tree.nwk",
metadata = "data/metadata_all.tsv",
branch_lengths = "results/branch_lengths.json",
traits = "results/traits.json",
nt_muts = "results/nt_muts.json",
aa_muts = "results/aa_muts.json",
colors = files.colors,
auspice_config = files.auspice_config,
description = files.description
output:
auspice_json = "results/raw_zika.json",
root_sequence = "results/raw_zika_root-sequence.json",
params:
strain_id = config.get("strain_id_field", "strain"),
shell:
"""
augur export v2 \
--tree {input.tree} \
--metadata {input.metadata} \
--metadata-id-columns {params.strain_id} \
--node-data {input.branch_lengths} {input.traits} {input.nt_muts} {input.aa_muts} \
--colors {input.colors} \
--auspice-config {input.auspice_config} \
--description {input.description} \
--include-root-sequence \
--output {output.auspice_json}
"""

rule final_strain_name:
input:
auspice_json="results/raw_zika.json",
metadata="data/metadata_all.tsv",
root_sequence="results/raw_zika_root-sequence.json",
output:
auspice_json="auspice/zika.json",
root_sequence="auspice/zika_root-sequence.json",
params:
strain_id=config["strain_id_field"],
display_strain_field=config.get("display_strain_field", "strain"),
shell:
"""
python3 scripts/set_final_strain_name.py \
--metadata {input.metadata} \
--metadata-id-columns {params.strain_id} \
--input-auspice-json {input.auspice_json} \
--display-strain-name {params.display_strain_field} \
--output {output.auspice_json}
cp {input.root_sequence} {output.root_sequence}
"""

0 comments on commit a37480e

Please sign in to comment.