-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_cancer_response.R
More file actions
42 lines (41 loc) · 1.01 KB
/
extract_cancer_response.R
File metadata and controls
42 lines (41 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#' Convenience function for extracting cancer (response)
#' categories corresponding to all tumors
#' in a maf file for use in a hidden genome classifier
#'
#' @inheritParams variant_screen_mi
#'
#' @param maf mutation annotation file --
#' a data frame-like object with at least two columns -- one providing
#' sample ids of tumor and one providing the associated cancer categories
#'
#' @return
#'
#' Returns a character vector containing cancer sites as determined
#' from cancer_col in maf, and named according to sample_id_col in maf.
#'
#' @examples
#' data("impact")
#' cancer_resp <- extract_cancer_response(
#' maf = impact,
#' cancer_col = "CANCER_SITE",
#' sample_id_col = "patient_id"
#' )
#' head(cancer_resp)
#'
#' @export
extract_cancer_response <- function(
maf,
cancer_col = "cancer",
sample_id_col = "sample",
...
) {
dt <- unique(
data.table::as.data.table(
maf
)[,
c(cancer_col, sample_id_col),
with = FALSE
]
)
setNames(dt[[cancer_col]], dt[[sample_id_col]])
}