Calculate and assign flags based on infection history
cg_annotate_antigenic_history.Rd
Calculate and assign flags based on infection history
Usage
cg_annotate_antigenic_history(
cg,
episode_number = episode_number,
dose_number = dose_number,
episode_variant_summarised = episode_variant_summarised,
ag_col = antigenic_history
)
Arguments
- cg
a chronogram
- episode_number
a character vector to identify the episode_number column. Default is "episode_number".
- dose_number
a character vector to identify the column containing the number of doses received on that day. Default is "dose_number".
- episode_variant_summarised
a character vector to identify the column summarising the variant call. Default is "episode_variant_summarised".
- ag_col
column with infection flag
Examples
library(dplyr)
data("built_smallstudy")
cg <- built_smallstudy$chronogram
## add infections to chronogram ##
cg <- cg_add_experiment(
cg,
built_smallstudy$infections_to_add
)
## annotate infections ##
cg <- cg_annotate_episodes_find(
cg,
infection_cols = c("LFT", "PCR", "symptoms"),
infection_present = c("pos", "Post", "^severe")
)
#> Parsed: infection_cols and infection_present
#>
#> Searching in the [[column]], for the "text":
#>
#> Loading required namespace: stringr
#> stringr::str_detect(.data[["LFT"]], "pos") ~ "yes"
#>
#> stringr::str_detect(.data[["PCR"]], "Post") ~ "yes"
#>
#> stringr::str_detect(.data[["symptoms"]], "^severe") ~ "yes"
#>
#>
#> ...detecting will be exact.
#> Capitals, spelling etc must be precise
#>
#> Joining with `by = join_by(calendar_date, elig_study_id)`
## annotate vaccines ##
cg <- cg %>% cg_annotate_vaccines_count(
## the prefix to the dose columns: ##
dose = dose,
## the output column name: ##
dose_counter = dose_number,
## the prefix to the date columns: ##
vaccine_date_stem = date_dose,
## use 14d to 'star' after a dose ##
intermediate_days = 14)
#> Using stem: date_dose
#> Found vaccine dates
#> date_dose_1
#>
#> date_dose_2
## annotate exposures ##
cg <- cg %>% cg_annotate_exposures_count(
episode_number = episode_number,
dose_number = dose_number,
## we have not considered episodes of seroconversion
N_seroconversion_episode_number = NULL
)
## assign variants ##
cg <- cg %>%
mutate(
episode_variant =
case_when(
# "is an episode" & "PCR positive" -> Delta #
(!is.na(episode_number)) & PCR == "Pos" ~ "Delta",
# "is an episode" & "PCR unavailable" -> Anc/Delta #
(!is.na(episode_number)) & PCR == "not tested" ~ "Anc/Alpha"
)
)
## ^ this gives a variant call on a SINGLE row of each episode
## fill the variant call ##
cg <- cg %>% cg_annotate_episodes_fill(
col_to_fill = episode_variant,
col_to_return = episode_variant_filled,
.direction = "updown",
episode_numbers_col = episode_number
)
#> Joining with `by = join_by(elig_study_id, episode_number)`
cg <- cg %>%
mutate(
episode_variant_summarised = episode_variant_filled
) %>%
cg_annotate_antigenic_history(
episode_number = episode_number,
dose_number = dose_number,
episode_variant_summarised = episode_variant_summarised,
ag_col = antigenic_history
)
## and finally:
summary(factor(cg$antigenic_history))
#> D0_Anc/Alpha D2_Anc/Alpha,D2_Delta D2_not_infected
#> 649 649 649