Skip to content

Commit

Permalink
Fix #1041
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonAlien committed Oct 16, 2024
1 parent 6c5293a commit 6276e23
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 30 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: maftools
Title: Summarize, Analyze and Visualize MAF Files
Version: 2.21.1
Version: 2.21.2
Date: 2021-04-30
Authors@R:
person(given = "Anand",
Expand Down
1 change: 1 addition & 0 deletions R/gisticOncoPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#' @param annotationFontSize font size for annotations. Default 1.2
#' @param gene_mar Default 5
#' @param barcode_mar Default 6
#' @param right_mar Default 2.5
#' @param sepwd_genes Default 0.5
#' @param sepwd_samples Default 0.25
#' @param bgCol Default "#CCCCCC"
Expand Down
8 changes: 5 additions & 3 deletions R/oncoPathway.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' Oncogenic signalling and SMG pathways are derived from TCGA cohorts. See references for details.
#' @param maf an \code{\link{MAF}} object generated by \code{\link{read.maf}}
#' @param pathdb Either `sigpw` or `smgbp`, `sigpw` uses known oncogenic signalling pathways (Sanchez/Vega et al) whereas `smgbp` uses pan cancer significantly mutated genes classified according to biological process (Bailey et al). Default \code{smgbp}
#' @param pathways Can be a two column data.frame/tsv-file with pathway-name and genes involved in them. Default `NULL`. This argument is mutually exclusive with \code{pathdb}
#' @param pathways Can be a two column data.frame/tsv-file with gene names and pathway-name involved in them. Default `NULL`. This argument is mutually exclusive with \code{pathdb}
#' @param plotType Can be 'treemap' or 'bar'. Set NA to suppress plotting. Default NA
#' @param fontSize Default 1
#' @param panelWidths Default c(2, 4, 4)
Expand All @@ -28,10 +28,12 @@ pathways = function(maf, pathdb = "sigpw", pathways = NULL, fontSize = 1, panelW
pathways = match.arg(arg = pathdb, choices = c("sigpw", "smgbp"))
}else{
if(is.data.frame(pathways)){
colnames(pathways)[1:2] = c("Pathway", "Gene")
colnames(pathways)[1:2] = c("Gene", "Pathway")
pathways = pathways[,.(Pathway, Gene)]
} else if(file.exists(pathways)){
pathways = data.table::fread(file = pathways)
colnames(pathways)[1:2] = c("Pathway", "Gene")
colnames(pathways)[1:2] = c("Gene", "Pathway")
pathways = pathways[,.(Pathway, Gene)]
}
}

Expand Down
60 changes: 38 additions & 22 deletions R/oncoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,12 @@ oncoplot = oncoplot = function(maf, top = 20, minMut = NULL, genes = NULL, alter
pathways = data.table::copy(pathways)
colnames(pathways)[1:2] = c('Gene', 'Pathway')
data.table::setDT(x = pathways)
pathways = pathways[!duplicated(Gene)][,.(Gene, Pathway)]
if(!is.null(selectedPathways)){
pathways = pathways[Pathway %in% selectedPathways]
}
}else if(file.exists(pathways)){
pathways = data.table::fread(file = pathways)
colnames(pathways)[1:2] = c('Gene', 'Pathway')
data.table::setDT(x = pathways)
pathways = pathways[!duplicated(Gene)][,.(Gene, Pathway)]
if(!is.null(selectedPathways)){
pathways = pathways[Pathway %in% selectedPathways]
}
}else{
pathways = match.arg(arg = pathways, choices = c("sigpw", "smgbp"))
pathwayLoad = get_pw_summary(maf = maf, pathways = pathways)

if(pathways == "sigpw"){
pathdb <- system.file("extdata", "oncogenic_sig_patwhays.tsv", package = "maftools")
Expand All @@ -172,23 +163,45 @@ oncoplot = oncoplot = function(maf, top = 20, minMut = NULL, genes = NULL, alter
}

pathways = data.table::fread(file = pathdb, skip = "Gene")
pathways = pathways[!duplicated(Gene)][,.(Gene, Pathway)]
#pathways$Pathway = gsub(pattern = " ", replacement = "_", x = pathways$Pathway)
}

#Convert to characters in case of factors
pathways$Gene = as.character(pathways$Gene)
pathways$Pathway = as.character(pathways$Pathway)

if(is.null(selectedPathways)){
message("Drawing upto top ", topPathways, " mutated pathways")
print(pathwayLoad)
if(ncol(pathwayLoad) >= topPathways){
pathways = pathways[Pathway %in% pathwayLoad[1:topPathways, Pathway]]
}else{
pathways = pathways[Pathway %in% pathwayLoad[, Pathway]]
}
if(is.null(selectedPathways)){
pathwayLoad = get_pw_summary(maf = maf, pathways = pathways[,.(Pathway, Gene)])
message("Drawing upto top ", topPathways, " mutated pathways")
if(ncol(pathwayLoad) >= topPathways){
pathways = pathways[Pathway %in% pathwayLoad[1:topPathways, Pathway]]
}else{
pathways = pathways[Pathway %in% selectedPathways]
pathways = pathways[Pathway %in% pathwayLoad[, Pathway]]
}
}else{
pws_missing = setdiff(selectedPathways, pathways[,.N,Pathway][,Pathway])
if(length(pws_missing) > 0){
warning("Could not find the following pathways: ", paste(pws_missing, collapse = ", "), immediate. = TRUE)
}
pathways = pathways[Pathway %in% selectedPathways]
if(nrow(pathways) == 0){
stop("Zero pathways to plot!")
}
}

#Make sure pathway names are distinct from the gene names
dup_pw_names = intersect(pathways$Pathway, pathways$Gene)
if(length(dup_pw_names) > 0){
warning("Found following pathways with the same name as gene symbols. Renamed them with the suffix _pw\n", paste(dup_pw_names, collapse = ", "), immediate. = TRUE)
unique_pw_names = setdiff(pathways$Pathway, dup_pw_names)
pw_named_list = setNames(nm = c(unique_pw_names, dup_pw_names), object = c(unique_pw_names, paste0(dup_pw_names, "_pw")))
pathways$Pathway = unname(obj = pw_named_list[pathways$Pathway])
}

if(nrow(pathways[duplicated(Gene)]) > 0){
warning("Duplicated genes found across multiple pathways! This might cause issue while plotting.", immediate. = TRUE)
# pathways = pathways[!duplicated(Gene)]
}

genes = as.character(pathways$Gene)

om = createOncoMatrix(m = maf, g = genes, cbio = cBioPortal)
Expand Down Expand Up @@ -410,10 +423,15 @@ oncoplot = oncoplot = function(maf, top = 20, minMut = NULL, genes = NULL, alter
nm = lapply(seq_along(temp_dat), function(i){
x = numMat[temp_dat[[i]]$Gene,, drop = FALSE]
x = rbind(x, apply(x, 2, function(y) ifelse(test = sum(y) == 0, yes = 0, no = 99)))
if(names(temp_dat)[i] %in% rownames(x)){
stop("pathway name ", names(temp_dat)[i], " is same as one of its member genes! Please rename it.\ne.g, ", names(temp_dat)[i], " to ", names(temp_dat)[i], "_pw")
}
rownames(x)[nrow(x)] = names(temp_dat)[i]
x
})

numMat = do.call(rbind, nm)

#Add pathway information to the character matrix
mat_origin_path = rownames(numMat)[!rownames(numMat) %in% rownames(mat_origin)]

Expand All @@ -422,7 +440,6 @@ oncoplot = oncoplot = function(maf, top = 20, minMut = NULL, genes = NULL, alter
mat_origin_path[mat_origin_path == "99"] = "pathway"
mat_origin_path = mat_origin_path[,colnames(mat_origin), drop = FALSE]
if(collapsePathway){
#print(mat_origin_path)
mat_origin = mat_origin_path
numMat = numMat[rownames(mat_origin),, drop = FALSE]
row_ord = names(sort(apply(numMat, 1, function(x) length(x[x == 0])), decreasing = FALSE))
Expand All @@ -433,7 +450,6 @@ oncoplot = oncoplot = function(maf, top = 20, minMut = NULL, genes = NULL, alter
if(sortByAnnotation){
numMat = sortByAnnotation(numMat = numMat, maf = maf, anno = annotation, annoOrder = annotationOrder, group = groupAnnotationBySize, isNumeric = FALSE)
}
#return(numMat)
}else{
mat_origin = rbind(mat_origin, mat_origin_path)
}
Expand Down
7 changes: 5 additions & 2 deletions inst/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CHANGES IN VERSION 2.21.1
(GitHub master branch - version bumped from 2.18.1 to 2.20.1 to match BC release branch)
# CHANGES IN VERSION 2.21.2

## BUG FIXES
- Bug fix in using `selectedPathways` in `oncoplot()`. Issue: [1041](https://github.com/PoisonAlien/maftools/issues/1041)
- Add an error message when bai files are missing `sampleSwaps()`. Issue: [1028](https://github.com/PoisonAlien/maftools/issues/1028)
- Bug fix in `tmb` while handling multiple MAFs. Issue: [1018](https://github.com/PoisonAlien/maftools/issues/1018)
- Handle missing `NA`s while sub-setting for ranges. Issue: [1013](https://github.com/PoisonAlien/maftools/issues/1013)
Expand All @@ -17,6 +17,9 @@
- Changed default signature database to SBS_v3.4 (from legacy)
- Update `tmb` function

## BREAKING CHNAGES
- Column order required for `pathways()` function changed from Pathway,Gene to Gene,Pathway. Issue: [1041](https://github.com/PoisonAlien/maftools/issues/1041)

## NEW FUNCTIONS
- `gisticCompare()` for comparing two GISTIC objects
- `segSummarize()` for summarizing DNAcopy segments
2 changes: 2 additions & 0 deletions man/gisticOncoPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/pathways.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/oncoplots.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ oncoplot(maf = laml, pathways = "sigpw", gene_mar = 8, fontSize = 0.6, topPathwa
oncoplot(
maf = laml.plus.gistic,
draw_titv = TRUE,
pathways = pathways,
pathways = pathways, topPathways = 5,
clinicalFeatures = c('FAB_classification', 'days_to_last_followup'),
sortByAnnotation = TRUE,
additionalFeature = c("Tumor_Seq_Allele2", "C"),
Expand Down

0 comments on commit 6276e23

Please sign in to comment.