@@ -13,43 +13,17 @@ log_threshold(INFO)
1313source(snakemake @ params [[" design" ]])
1414
1515# Read inputs
16- demix <- read_csv(snakemake @ input [[" summary_demixing" ]])
17-
18- # DATA PROCESSING
19- log_info(" Obtaining main lineages" )
20- main_lineages <- demix %> %
21- group_by(sample ) %> %
22- top_n(1 , abundances ) %> %
23- ungroup() %> %
24- pull(lineages ) %> %
25- unique()
26-
27- # Obtain sample names ordered by CollectionDate
28- metadata <- read_csv(snakemake @ input [[" metadata" ]])
29- date_order <- metadata %> %
30- arrange(CollectionDate ) %> %
31- filter(ID %in% demix $ sample ) %> %
32- pull(ID ) %> %
33- unique()
34-
35- # PLOT
36- log_info(" Plotting summary demixing" )
37- demix_plot <- demix %> %
38- mutate(
39- lineages = case_when(
40- lineages %in% main_lineages ~ lineages
41- )
42- ) %> %
43- group_by(lineages , sample ) %> %
16+ log_info(" Plotting" )
17+ p <- read_csv(snakemake @ input $ data ) %> %
4418 mutate(
45- abundances = sum(abundances )
19+ sample = reorder(sample , CollectionDate ),
20+ lineage = ifelse(is_main , lineage , NA )
4621 ) %> %
47- unique() %> %
4822 ggplot() +
4923 aes(
50- x = factor ( sample , date_order ) ,
51- y = as.numeric( abundances ) ,
52- fill = lineages
24+ x = sample ,
25+ y = abundance ,
26+ fill = lineage
5327 ) +
5428 scale_fill_viridis_d(
5529 na.value = " gray50" ,
@@ -68,34 +42,12 @@ demix_plot <- demix %>%
6842 fill = " Lineage"
6943 )
7044
45+ log_info(" Saving plot" )
7146ggsave(
72- filename = snakemake @ output [[" fig " ]],
73- plot = demix_plot ,
47+ filename = snakemake @ output [[" plot " ]],
48+ plot = p ,
7449 width = 159.2 ,
7550 height = 119.4 ,
7651 units = " mm" ,
7752 dpi = 250
7853)
79-
80-
81- # PLOT TABLES
82- log_info(" Saving plot table" )
83- demix %> %
84- mutate(
85- lineages = case_when(
86- lineages %in% main_lineages ~ lineages ,
87- TRUE ~ " Other"
88- )
89- ) %> %
90- group_by(sample , lineages ) %> %
91- summarise(abundances = sum(abundances )) %> %
92- ungroup() %> %
93- left_join(
94- select(
95- metadata ,
96- ID ,
97- CollectionDate
98- ),
99- by = c(" sample" = " ID" )
100- ) %> %
101- write.csv(snakemake @ output [[" table" ]], row.names = FALSE )
0 commit comments