R/m067.phen.update_id.R

Defines functions m067.update.dat_04 m067.update.dat_03 m067.update.dat_02 m067.update.dat_01

#-----------------------
# Update `m067.phen`
#-----------------------


### update 'general'----------------------------------------------------

# update 'm067_dat' in 'dat_imp[[1]]'
m067.update.dat_01 <- function(dat_imp)
{
# update class of the variable 'dat_imp[[1]]'
  dat_imp[[1]] <- dat_imp[[1]] %>%
    mutate(
    pid = as.character(pid),
    t_point = factor(time, levels = c('M0', 'M3', 'M20', 'M21', 'M32')),
    site = tolower(site),
    country = tolower(city),
    agec = factor(
        ifelse(agec == '5-17m', '5_17m',
        ifelse(agec == '6-12w', '6_12w', 'NA')),
        levels = c('6_12w', '5_17m')),
    vaccine_t = factor(
        ifelse(vaccine == 'Control', 'C3C',
        ifelse(str_detect(vaccine, 'with'), 'R3R',
        ifelse(str_detect(vaccine , 'without'), 'R3C', 'NA'))),
        levels = c('C3C', 'C3R', 'R3R')),
    vaccine_t2 = factor(vaccine2c, levels = c('comparator', 'rtss')),
    cc_12 = factor(casecon_m12, levels = c('control', 'case')),
		cc_18 = factor(casecon_m18, levels = c('control', 'case')),
    pid_exclude = factor(pids_to_exclude, levels = c('0', '1')),
    pbmc_cells = as.numeric(pbmc_cells)) %>%
    filter(site %in% c('bagamoyo', 'lambarene', 'manhica'),
      pid_exclude == '0',
      t_point %in% c('M21', 'M32')) %>%
      droplevels()

    # create interaction
    dat_imp[[1]]$pid_point <- interaction(dat_imp[[1]]$pid, dat_imp[[1]]$t_point, sep = '_')

# select variables
  dat_imp [[1]] <- dat_imp[[1]] %>%
    select(pid, t_point, pid_point, site, agec, country, vaccine_t, vaccine_t2,
    cc_12, cc_18, pbmc_cells, pid_exclude)

# return
  return(dat_imp)
}


### update 'bagamoyo'----------------------------------------------------


# update 'm067_dat' in 'dat_imp[[2]]' (bagamoyo)
m067.update.dat_02 <- function(dat_imp)
{
# update class of the variable 'dat_imp[[2]]'
  dat_imp[[2]] <- dat_imp[[2]] %>%
  	mutate(
  	pid = as.character(pid),
    sid_bgmy = as.character(
      ifelse(!is.na(sid_ori), paste0('B_', sid_ori), 'NA')),
    comment_bgmy = factor(comment),
    t_point = factor(t_point, levels = c('M0', 'M3', 'M20', 'M21', 'M32'))) %>%
    filter(t_point %in% c('M21', 'M32')) %>%
    droplevels()

    # create interaction
    dat_imp[[2]]$pid_point <- interaction(dat_imp[[2]]$pid, dat_imp[[2]]$t_point, sep = '_')

# select variables
  dat_imp [[2]] <- dat_imp[[2]] %>%
    select(pid, t_point, pid_point, sid_bgmy, comment)

# return
  return(dat_imp)
}


### update 'manhica'----------------------------------------------------

# update 'm067_dat' in 'dat_imp[[5]]' (manhiça)
m067.update.dat_03 <- function(dat_imp)
{
# update class of the variable 'dat_imp[[5]]'
  dat_imp[[5]] <- dat_imp[[5]] %>%
  	mutate(
  	pid = as.character(pid),
    sid_mnhc = as.character(
      ifelse(!is.na(sid_ori), paste0('B_', sid_ori), 'NA')),
    t_point = factor(t_point, levels = c('M0', 'M3', 'M20', 'M21', 'M32'))) %>%
    filter(t_point %in% c('M21', 'M32')) %>%
    droplevels()

    # create interaction
    dat_imp[[5]]$pid_point <- interaction(dat_imp[[5]]$pid, dat_imp[[5]]$t_point, sep = '_')

  # select variables
    dat_imp [[5]] <- dat_imp[[5]] %>%
      select(pid, t_point, pid_point, sid_mnhc)

# return
  return(dat_imp)
}


### update 'lambarene'----------------------------------------------------


# update 'm067_dat' in 'dat_imp[[8]]' (lambarene)
m067.update.dat_04 <- function(dat_imp)
{
# update class of the variable 'dat_imp[[8]]'
  dat_imp[[8]] <- dat_imp[[8]] %>%
  	mutate(
  	pid = factor(pid),
    sid = factor(sid),
    site = factor(site),
    comment_lmbr = factor(comment),
    t_point = factor(t_point, levels = c('M0', 'M3', 'M20', 'M21', 'M32'))) %>%
    filter(t_point %in% c('M21', 'M32')) %>%
		select(row, pid, sid, t_point, comment)

# update to 'merge'
  dat_imp[[8]] <- dat_imp[[8]] %>%
  mutate(pid_m067 = as.character(sid),
    sid_m067 = paste0('L_', pid),
    comment = factor(comment)) %>%
  filter(!is.na(t_point)) %>%
  filter(!is.na(sid_m067)) %>%
  filter(!is.na(pid_m067)) %>%
  droplevels() %>%
  select(everything(), -sid, -pid)

  # create interaction
  dat_imp[[8]]$pid_point <- interaction(dat_imp[[8]]$pid, dat_imp[[8]]$t_point, sep = '_')

# select variables
  dat_imp [[8]] <- dat_imp[[8]] %>%
    select(row, pid = pid_m067,t_point, pid_point, sid_lmbrn = sid_m067, comment)

# return
  return(dat_imp)
}
mvazquezs/m067tools documentation built on April 19, 2019, 7:07 p.m.