Skip to content

Commit b79c1c7

Browse files
committed
Fix missing reference record in afwdist results
Renames outgroup params for distance tree rules
1 parent 677f51f commit b79c1c7

6 files changed

Lines changed: 21 additions & 17 deletions

File tree

workflow/rules/distances.smk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rule extract_afwdist_variants:
2222
rule afwdist_weighted_distances:
2323
conda: "../envs/afwdist.yaml"
2424
params:
25-
extra_args = ""
25+
extra_args = "",
2626
input:
2727
variants = OUTDIR/f"{OUTPUT_NAME}.variants.afwdist.csv",
2828
reference = OUTDIR/f"{OUTPUT_NAME}.ancestor.fasta",
@@ -41,7 +41,7 @@ rule afwdist_weighted_distances:
4141
rule format_afwdist_results:
4242
conda: "../envs/biopython.yaml"
4343
params:
44-
samples = sorted(iter_samples()),
44+
samples = sorted(iter_samples()) + [config["ALIGNMENT_REFERENCE"]],
4545
input:
4646
distances = OUTDIR/f"{OUTPUT_NAME}.distances.raw.csv",
4747
output:

workflow/rules/report.smk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ rule allele_freq_tree_data:
260260
conda: "../envs/renv.yaml"
261261
params:
262262
use_bionj = config["USE_BIONJ"],
263-
ref_name = config["ALIGNMENT_REFERENCE"],
263+
outgroup_id = config["ALIGNMENT_REFERENCE"],
264264
input:
265265
dist = OUTDIR/f"{OUTPUT_NAME}.distances.csv",
266266
output:
@@ -275,7 +275,7 @@ rule allele_freq_tree_plot:
275275
conda: "../envs/renv.yaml"
276276
params:
277277
design = config["PLOTS"],
278-
ref_name = config["ALIGNMENT_REFERENCE"],
278+
outgroup_id = config["ALIGNMENT_REFERENCE"],
279279
plot_height_mm = 119.4,
280280
plot_width_mm = 159.2,
281281
input:
@@ -293,7 +293,7 @@ rule allele_freq_tree_plot:
293293
rule time_signal_data:
294294
conda: "../envs/renv.yaml"
295295
params:
296-
ref_name = config["ALIGNMENT_REFERENCE"],
296+
outgroup_id = config["ALIGNMENT_REFERENCE"],
297297
input:
298298
tree = report(REPORT_DIR_TABLES/"allele_freq_tree.nwk"),
299299
metadata = config["METADATA"],

workflow/scripts/format_afwdist_results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
logging.info("Initializing formatted output")
1515
output = pd.DataFrame(
16+
data=0.0,
1617
columns=snakemake.params.samples,
1718
index=snakemake.params.samples,
1819
dtype="float64"

workflow/scripts/report/allele_freq_tree_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tree <- matrix %>%
4646
as.matrix() %>%
4747
as.dist() %>%
4848
tree_method() %>%
49-
root(snakemake@params$ref_name, resolve.root = TRUE)
49+
root(snakemake@params$outgroup_id, resolve.root = TRUE)
5050

5151
# Resolve possible negative edge lengths in tree
5252
log_info("Resolving negative edge lengths")

workflow/scripts/report/allele_freq_tree_plot.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ metadata <- read_csv(snakemake@input$metadata)
2525

2626
# Extract names from records
2727
log_debug("Reading FASTA")
28-
study_names <- read.dna(
28+
study_records <- read.dna(
2929
snakemake@input$study_fasta,
3030
format = "fasta",
3131
as.matrix = FALSE,
3232
)
3333
log_debug("Extracting names")
34-
study_names <- study_names[
35-
!startsWith(names(study_names), snakemake@params$ref_name)
34+
study_records <- study_records[
35+
!startsWith(names(study_records), snakemake@params$outgroup_id)
3636
]
37-
study_names <- names(study_names)
37+
study_names <- names(study_records)
3838

3939
# Obtain sample names ordered by CollectionDate
4040
log_debug("Sorting names by collection date")
@@ -59,19 +59,21 @@ tree_tiplab <- data.frame(
5959
) %>%
6060
ungroup() %>%
6161
add_row(
62-
ID = snakemake@params$ref_name,
62+
ID = snakemake@params$outgroup_id,
6363
order = 0,
64-
tip_label = snakemake@params$ref_name
64+
tip_label = snakemake@params$outgroup_id
6565
)
6666

6767
# Read distance tree and root
6868
log_info("Reading tree")
6969
tree <- read.tree(snakemake@input$tree) %>%
70-
root(snakemake@params$ref_name, resolve.root = TRUE)
70+
root(snakemake@params$outgroup_id, resolve.root = TRUE)
7171

7272
# Plot
7373
log_info("Plotting distance tree")
74-
max.tip.length <- max(node.depth.edgelength(tree)[1:length(tree$tip.label)])
74+
max.tip.length <- max(
75+
node.depth.edgelength(tree)[seq_along(length(tree$tip.label))]
76+
)
7577
p <- ggtree(tree) %<+% tree_tiplab +
7678
geom_tiplab(aes(label = tip_label)) +
7779
geom_treescale(1.1 * max.tip.length) +

workflow/scripts/report/time_signal_data.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ log_threshold(INFO)
1818
# Read distance tree and root
1919
log_info("Reading tree")
2020
tree <- read.tree(snakemake@input$tree) %>%
21-
root(snakemake@params$ref_name, resolve.root = TRUE)
21+
root(snakemake@params$outgroup_id, resolve.root = TRUE)
2222

2323
# Read metadata
2424
log_info("Reading metadata")
@@ -33,14 +33,15 @@ time.signal <- distRoot(
3333
) %>%
3434
as.data.frame() %>%
3535
rownames_to_column(var = "ID") %>%
36-
filter(ID != snakemake@params$ref_name) %>%
36+
filter(ID != snakemake@params$outgroup_id) %>%
3737
rename(distance = ".") %>%
3838
left_join(
3939
select(
4040
metadata,
4141
ID,
4242
CollectionDate
43-
)
43+
),
44+
by = "ID"
4445
) %>%
4546
mutate(
4647
date_interval = as.numeric(

0 commit comments

Comments
 (0)