Skip to content

Commit c8fbe11

Browse files
Merge pull request #127 from AxelitoMartin/development
Development
2 parents 826f135 + 1dbdafd commit c8fbe11

86 files changed

Lines changed: 531 additions & 461 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

R/get_tmb.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#' get_tmb
2-
#' \lifecycle{experimental}
2+
#' \%lifecycle{experimental}
33
#' Function to calculate the tumor mutation burden of individual patients in a MAF file. Note that this can only be applied to
44
#' samples sequenced using one of the IMPACT panels. Other samples will be annotated as missing.
55
#' @param patients a character vector that let's the user specify the patients to be used to create the matrix.

R/make-bin-mat.R

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#' binmat
2+
#' \%lifecycle{stable}
23
#' Enables creation of a binary matrix from a maf file with
34
#' a predefined list of patients (rows are patients and columns are genes)
45
#' @param patients a character vector that let's the user specify the patients to be used to create the matrix.
@@ -15,14 +16,17 @@
1516
#' Default is NULL.
1617
#' @param cna.binary A boolean argument specifying if the cna events should be enforced as binary. In which case separate columns for
1718
#' amplifications and deletions will be created.
18-
#' @param cna.relax for cna data only enables to count both gains and shallow deletions as amplifications and deletions respectively.
19+
#' @param cna.relax By default this argument is set to FALSE, where only deep deletions (-2) and amplifications (2) will be annotated as events.
20+
#' When set to FTRUE all deletions (-1 shallow and -2 deep) are counted as an event same for all gains (1 gain, 2 amplification) as an event.
1921
#' @param specify.plat boolean specifying if specific IMPACT platforms should be considered. When TRUE NAs will fill the cells for genes
2022
#' of patients that were not sequenced on that plaform. Default is TRUE.
2123
#' @param set.plat character argument specifying which IMPACT platform the data should be reduced to if specify.plat is set to TRUE.
2224
#' Options are "341" and "410". Default is NULL.
2325
#' @param rm.empty boolean specifying if columns with no events founds should be removed. Default is TRUE.
2426
#' @param pathway boolean specifying if pathway annotation should be applied. If TRUE, the function will return a supplementary binary
2527
#' dataframe with columns being each pathway and each row being a sample. Default is FALSE.
28+
#' @param recode.aliases bolean specifying if automated gene name alias matching should be done. Default is TRUE. When TRUE
29+
#' the function will check for genes that may have more than 1 name in your data using the aliases im gnomeR::impact_gene_info alias column
2630
#' @param col.names character vector of the necessary columns to be used. By default: col.names = c(Tumor_Sample_Barcode = NULL,
2731
#' Hugo_Symbol = NULL, Variant_Classification = NULL, Mutation_Status = NULL, Variant_Type = NULL)
2832
#' @param oncokb boolean specfiying if maf file should be oncokb annotated. Default is FALSE.
@@ -56,6 +60,7 @@
5660
binmat <- function(patients=NULL, maf = NULL, mut.type = "SOMATIC",SNP.only = FALSE,include.silent = FALSE,
5761
fusion = NULL,cna = NULL,cna.binary = TRUE,cna.relax = FALSE, specify.plat = TRUE,
5862
set.plat = NULL,rm.empty = TRUE, pathway = FALSE,
63+
recode.aliases = TRUE,
5964
col.names = c(Tumor_Sample_Barcode = NULL, Hugo_Symbol = NULL,
6065
Variant_Classification = NULL, Mutation_Status = NULL, Variant_Type = NULL),
6166
oncokb = FALSE, keep_onco = c("Oncogenic","Likely Oncogenic","Predicted Oncogenic"), token = '',...){
@@ -121,7 +126,7 @@ binmat <- function(patients=NULL, maf = NULL, mut.type = "SOMATIC",SNP.only = FA
121126
if(!is.null(maf)){
122127

123128
# quick data checks #
124-
maf <- check_maf_input(maf)
129+
maf <- check_maf_input(maf, recode.aliases= recode.aliases)
125130
# if(is.na(match("Tumor_Sample_Barcode",colnames(maf))))
126131
# stop("The MAF file inputted is missing a patient name column. (Tumor_Sample_Barcode)")
127132
# if(is.na(match("Hugo_Symbol",colnames(maf))))
@@ -149,7 +154,7 @@ binmat <- function(patients=NULL, maf = NULL, mut.type = "SOMATIC",SNP.only = FA
149154
maf <- structure(maf,class = c("data.frame","maf"))
150155
# getting mutation binary matrix #
151156
mut <- createbin(obj = maf, patients = patients, mut.type = mut.type, cna.binary = cna.binary,cna.relax = cna.relax,
152-
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat)
157+
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat, recode.aliases = recode.aliases)
153158

154159
}
155160

@@ -164,7 +169,7 @@ binmat <- function(patients=NULL, maf = NULL, mut.type = "SOMATIC",SNP.only = FA
164169
# filter/define patients #
165170
# if(is.null(patients)) patients <- as.character(unique(fusion$Tumor_Sample_Barcode))
166171
fusion <- createbin(obj = fusion, patients = patients, mut.type = mut.type, cna.binary = cna.binary,
167-
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat)
172+
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat, recode.aliases = recode.aliases)
168173
if(!is.null(mut)){
169174
mut <- as.data.frame(cbind(mut,fusion))
170175
rownames(mut) <- patients}
@@ -205,14 +210,15 @@ binmat <- function(patients=NULL, maf = NULL, mut.type = "SOMATIC",SNP.only = FA
205210
cna <- structure(cna,class = c("data.frame","cna"))
206211
# if(is.null(patients)) patients <- gsub("\\.","-",as.character(colnames(cna)))[-1]
207212
cna <- createbin(obj = cna, patients = patients, mut.type = mut.type, cna.binary = cna.binary,cna.relax = cna.relax,
208-
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat)
213+
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat, recode.aliases = recode.aliases)
209214

210215
}
211216

212217
else{
213218
# if(is.null(patients)) patients <- unique(cna$sampleId)
214219
cna <- createbin(obj = cna, patients = patients, mut.type = mut.type, cna.binary = cna.binary,cna.relax = cna.relax,
215-
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat)
220+
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat,
221+
recode.aliases = recode.aliases)
216222
}
217223
}
218224

@@ -285,7 +291,7 @@ binmat <- function(patients=NULL, maf = NULL, mut.type = "SOMATIC",SNP.only = FA
285291
# colnames(cna) <- gsub("\\.","-",colnames(cna))
286292
# }
287293
cna <- createbin(obj = cna, patients = patients, mut.type = mut.type, cna.binary = cna.binary,cna.relax = cna.relax,
288-
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat)
294+
SNP.only = SNP.only, include.silent = include.silent, specify.plat = specify.plat, recode.aliases = recode.aliases)
289295
}
290296
if(!is.null(mut)){
291297
mut <- as.data.frame(cbind(mut,cna))
@@ -375,8 +381,7 @@ binmat <- function(patients=NULL, maf = NULL, mut.type = "SOMATIC",SNP.only = FA
375381
unique_genes <- unique(gsub(".Del|.Amp|.fus|.cna","",colnames(mut)))
376382
missing_genes <- unique_genes[which(!(unique_genes %in% impact_gene_info$hugo_symbol))]
377383
if(length(missing_genes) > 0 && specify.plat)
378-
warning(paste0("Some genes in the final matrix were not part of the official IMPACT panel and thus couldn't be annotate
379-
for missing status. If you wish to have a complete list of genes in IMPACT please see 'impact_gene_info'. ",
384+
warning(paste0("The following genes in the final matrix were not part of the official IMPACT panel and thus couldn't be annotated for missing status. To see a complete list of genes in IMPACT please see 'impact_gene_info': ",
380385
paste0(missing_genes,collapse = ", ")
381386
)
382387
)
@@ -389,7 +394,7 @@ binmat <- function(patients=NULL, maf = NULL, mut.type = "SOMATIC",SNP.only = FA
389394
##############################################
390395

391396

392-
createbin <- function(obj, patients, mut.type, cna.binary, SNP.only,include.silent, cna.relax, specify.plat){
397+
createbin <- function(obj, patients, mut.type, cna.binary, SNP.only,include.silent, cna.relax, specify.plat, recode.aliases){
393398
UseMethod("createbin")
394399
}
395400

@@ -402,7 +407,7 @@ createbin.default <- function(obj) {
402407
############# MUTATION MATRIX ################
403408
##############################################
404409

405-
createbin.maf <- function(obj, patients, mut.type, cna.binary, SNP.only, include.silent, cna.relax, specify.plat){
410+
createbin.maf <- function(obj, patients, mut.type, cna.binary, SNP.only, include.silent, cna.relax, specify.plat, recode.aliases = recode.aliases){
406411
maf <- as_tibble(obj)
407412
maf$Hugo_Symbol <- as.character(maf$Hugo_Symbol)
408413

@@ -444,7 +449,9 @@ createbin.maf <- function(obj, patients, mut.type, cna.binary, SNP.only, include
444449
############# FUSION MATRIX ###############
445450
###########################################
446451

447-
createbin.fusion <- function(obj, patients, mut.type,cna.binary, SNP.only,include.silent, cna.relax, specify.plat){
452+
createbin.fusion <- function(obj, patients, mut.type,cna.binary,
453+
SNP.only,include.silent, cna.relax,
454+
specify.plat, recode.aliases){
448455
fusion <- as_tibble(obj)
449456
# quick data checks #
450457
if(length(match("Tumor_Sample_Barcode",colnames(fusion))) == 0)
@@ -457,10 +464,28 @@ createbin.fusion <- function(obj, patients, mut.type,cna.binary, SNP.only,includ
457464
alias_table <- tidyr::unnest(impact_gene_info, cols = alias) %>%
458465
select(hugo_symbol, alias)
459466

460-
# recode aliases
461-
fusion$Hugo_Symbol_Old <- fusion$Hugo_Symbol
462-
fusion$Hugo_Symbol <- purrr::map_chr(fusion$Hugo_Symbol, ~resolve_alias(.x,
463-
alias_table = alias_table))
467+
# recode aliases ---
468+
if(recode.aliases == TRUE) {
469+
470+
fusion$Hugo_Symbol_Old <- fusion$Hugo_Symbol
471+
fusion$Hugo_Symbol <- purrr::map_chr(fusion$Hugo_Symbol, ~resolve_alias(.x,
472+
alias_table = alias_table))
473+
474+
message <- fusion %>%
475+
dplyr::filter(Hugo_Symbol_Old != Hugo_Symbol) %>%
476+
dplyr::select(Hugo_Symbol_Old, Hugo_Symbol) %>%
477+
dplyr::distinct()
478+
479+
if(nrow(message) > 0) {
480+
warning(paste0("FUSION DATA: To ensure gene with multiple names/aliases are correctly grouped together, the
481+
following genes in your fusion data have been recoded. You can supress this with recode.aliases = FALSE \n \n",
482+
purrr::map2(message$Hugo_Symbol_Old,
483+
message$Hugo_Symbol,
484+
~paste0(.x, " recoded to ", .y, " \n"))))
485+
}
486+
}
487+
488+
464489

465490
fusion <- as_tibble(fusion) %>%
466491
filter(.data$Tumor_Sample_Barcode %in% patients)
@@ -472,8 +497,10 @@ createbin.fusion <- function(obj, patients, mut.type,cna.binary, SNP.only,includ
472497

473498
for(i in patients){
474499
genes <- fusion$Hugo_Symbol[fusion$Tumor_Sample_Barcode %in% i]
475-
if(length(genes) != 0){fusion.out[match(i,rownames(fusion.out)),
476-
match(unique(as.character(genes)),colnames(fusion.out))] <- 1}
500+
if(length(genes) != 0)
501+
fusion.out[match(i,rownames(fusion.out)),
502+
match(unique(as.character(genes)),colnames(fusion.out))] <- 1
503+
477504
}
478505
colnames(fusion.out) <- paste0(colnames(fusion.out),".fus")
479506
return(fusion.out)
@@ -484,7 +511,9 @@ createbin.fusion <- function(obj, patients, mut.type,cna.binary, SNP.only,includ
484511
############# COPY NUMBER MATRIX ###############
485512
################################################
486513

487-
createbin.cna <- function(obj, patients, mut.type,cna.binary, SNP.only,include.silent, cna.relax, specify.plat){
514+
createbin.cna <- function(obj, patients, mut.type,cna.binary,
515+
SNP.only,include.silent, cna.relax,
516+
specify.plat, recode.aliases){
488517
cna <- obj
489518
cna <- as.data.frame(tibble::as_tibble(cna))
490519
cna$Hugo_Symbol <- as.character(cna$Hugo_Symbol)
@@ -493,10 +522,28 @@ createbin.cna <- function(obj, patients, mut.type,cna.binary, SNP.only,include.s
493522
alias_table <- tidyr::unnest(impact_gene_info, cols = alias) %>%
494523
select(hugo_symbol, alias)
495524

496-
# recode aliases
497-
# cna$Hugo_Symbol_Old <- cna$Hugo_Symbol
498-
cna$Hugo_Symbol <- purrr::map_chr(cna$Hugo_Symbol, ~resolve_alias(.x,
499-
alias_table = alias_table))
525+
# recode aliases ---
526+
if(recode.aliases == TRUE) {
527+
528+
cna$Hugo_Symbol_Old <- cna$Hugo_Symbol
529+
cna$Hugo_Symbol <- purrr::map_chr(cna$Hugo_Symbol, ~resolve_alias(.x,
530+
alias_table = alias_table))
531+
532+
message <- cna %>%
533+
dplyr::filter(Hugo_Symbol_Old != Hugo_Symbol) %>%
534+
dplyr::select(Hugo_Symbol_Old, Hugo_Symbol) %>%
535+
dplyr::distinct()
536+
537+
if(nrow(message) > 0) {
538+
warning(paste0("CNA DATA: To ensure gene with multiple names/aliases are correctly grouped together, the
539+
following genes in your CNA data have been recoded. You can supress this with recode.aliases = FALSE. \n \n",
540+
purrr::map2(message$Hugo_Symbol_Old,
541+
message$Hugo_Symbol,
542+
~paste0(.x, " recoded to ", .y, " \n"))))
543+
}
544+
}
545+
546+
500547
dups <- cna$Hugo_Symbol[duplicated(cna$Hugo_Symbol)]
501548
if(length(dups) > 0){
502549
for(i in dups){
@@ -572,7 +619,8 @@ createbin.cna <- function(obj, patients, mut.type,cna.binary, SNP.only,include.s
572619
}
573620

574621
### cna from API ###
575-
createbin.api <- function(obj, patients, mut.type,cna.binary, SNP.only,include.silent, cna.relax, specify.plat){
622+
createbin.api <- function(obj, patients, mut.type,cna.binary,
623+
SNP.only,include.silent, cna.relax, specify.plat, recode.aliases){
576624
cna <- as.data.frame(obj)
577625

578626
cna <- as.data.frame(tibble::as_tibble(cna))

R/make-custom-pathway.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#' custom_pathway
2+
#' \%lifecycle{stable}
23
#' Enables creation of a custom pathway binary matrix from a binmat() `object`. Similarly to the internal file 'pathways.csv', this function takes as input
34
#' a data frame containing the name of the pathways of interest, and for each pathways a character vector of the genes of interest. Note that the different
45
#' events to be considered in each pathways must be considered separetely. For example, if one wishes to consider TP53 deletions in a given pathway, one must

R/oncokb.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#' OncoKB annotate
2-
#'
2+
#' \%lifecycle{stable}
33
#' Enables oncokb annotation of MAF, fusions and CNA files. This is performed using the OncoKB annotator found at https://github.com/oncokb/oncokb-annotator.
44
#' See details there for file formats.
55
#'

R/plot-oncoprint.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ plot_oncoPrint <- function(gen.dat,clin.dat=NULL,ordered=NULL){
6464
# get all values #
6565
clin.factors <- unique(unlist(apply(mat,2,unique)))
6666
clin.factors <- clin.factors[-stats::na.omit(match(c("MUT;","AMP;","DEL;","FUS;"," ","MIS;",
67-
"MUT;FUS;","MUT;DEL;","MUT;AMP;"),clin.factors))]
67+
"MUT;FUS;","MUT;DEL;","MUT;AMP;","MUT;DEL;FUS;",
68+
"DEL;FUS;","MUT;AMP;FUS;",
69+
"AMP;FUS;"),clin.factors))]
6870
if(length(clin.factors) == 0){
6971
col = c("MUT" = "#008000", "AMP" = "red", "DEL" = "blue", "FUS" = "orange","MIS" = "black")
7072
alter_fun = list(

R/utils.R

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#' Checks MAF input to ensure column names are correct and renamed genes are corrected
22
#'
33
#' @param maf Raw maf dataframe containing alteration data
4-
#'
4+
#' @param ... Further arguments parsed through binmat() (recode.aliases).
55
#' @return a corrected maf file or an error if problems with maf
66
#' @export
77
#'
88
#' @examples
99
#'
10-
#' check_maf_input(mut)
10+
#' check_maf_input(mut,recode.aliases = TRUE)
1111
#'
12-
check_maf_input <- function(maf) {
12+
check_maf_input <- function(maf, ...) {
13+
14+
arguments <- list(...)
1315

1416
# data checks for maf files
1517
if(is.na(match("Tumor_Sample_Barcode",colnames(maf))))
@@ -63,27 +65,31 @@ check_maf_input <- function(maf) {
6365
if(!is.character(maf$Tumor_Sample_Barcode)) maf$Tumor_Sample_Barcode <-
6466
as.character(maf$Tumor_Sample_Barcode)
6567

68+
if(arguments$recode.aliases == TRUE) {
69+
6670
# get table of gene aliases
67-
alias_table <- tidyr::unnest(impact_gene_info, cols = alias) %>%
68-
dplyr::select(hugo_symbol, alias)
69-
70-
# recode aliases
71-
maf$Hugo_Symbol_Old <- maf$Hugo_Symbol
72-
maf$Hugo_Symbol <- purrr::map_chr(maf$Hugo_Symbol, ~resolve_alias(.x,
73-
alias_table = alias_table))
74-
75-
message <- maf %>%
76-
dplyr::filter(Hugo_Symbol_Old != Hugo_Symbol) %>%
77-
dplyr::select(Hugo_Symbol_Old, Hugo_Symbol) %>%
78-
dplyr::distinct()
79-
80-
if(nrow(message) > 0) {
81-
warning(paste0("To ensure gene with multiple names/aliases are correctly grouped together, the
82-
following genes in your maf dataframe have been recoded: \n",
83-
purrr::map2(message$Hugo_Symbol_Old,
84-
message$Hugo_Symbol,
85-
~paste0(.x, " recoded to ", .y, " \n"))))
71+
alias_table <- tidyr::unnest(impact_gene_info, cols = alias) %>%
72+
dplyr::select(hugo_symbol, alias)
73+
74+
# recode aliases
75+
maf$Hugo_Symbol_Old <- maf$Hugo_Symbol
76+
maf$Hugo_Symbol <- purrr::map_chr(maf$Hugo_Symbol, ~resolve_alias(.x,
77+
alias_table = alias_table))
78+
79+
message <- maf %>%
80+
dplyr::filter(Hugo_Symbol_Old != Hugo_Symbol) %>%
81+
dplyr::select(Hugo_Symbol_Old, Hugo_Symbol) %>%
82+
dplyr::distinct()
83+
84+
if(nrow(message) > 0) {
85+
warning(paste0("MUTATION DATA: To ensure gene with multiple names/aliases are correctly grouped together, the
86+
following genes in your maf dataframe have been recoded. You can supress this with recode.aliases = FALSE \n \n",
87+
purrr::map2(message$Hugo_Symbol_Old,
88+
message$Hugo_Symbol,
89+
~paste0(.x, " recoded to ", .y, " \n"))))
90+
}
8691
}
92+
8793
return(maf)
8894
}
8995

0 commit comments

Comments
 (0)