Snitkin-Lab-Umich / regentrans

regentrans: R package for investigating regional pathogen transmission using genomic data
Other
5 stars 1 forks source link

Add code to get pairwise day differences between isolates #58

Closed zenalapp closed 2 years ago

zenalapp commented 3 years ago

A function would probably be better, but we could also just include in vignette.

Example code (there might be a more elegant way):

# isolate_dat contains columns with isolate_id and collection_date

date_info <- isolate_dat %>% dplyr::select(isolate_id, collection_date)

date_diff_mat <- sapply(date_info$isolate_id, function(x){
  sapply(date_info$isolate_id, function(y){
    as.numeric(abs(date_info$collection_date[date_info$isolate_id == x] -
                     date_info$collection_date[date_info$isolate_id == y]))
  })
})

date_diff_long <- regentrans::make_long_form(date_diff_mat, col_names = c('isolate1', 'isolate2', 'days_diff'), remove_zeros = FALSE) %>% dplyr::filter(isolate1 != isolate2)
zenalapp commented 2 years ago

Done