Skip to content

Commit

Permalink
pathway bug fixe
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonAlien committed Oct 18, 2023
1 parent 6803bac commit 7a27eba
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vignettes/.html
.renviron
.rprofile
.rproj
.Rproj
.rproj.user
.rhistory
.rapp.history
Expand Down
23 changes: 19 additions & 4 deletions R/mafCompare.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#' @param m2Name optional name for second cohort
#' @param minMut Consider only genes with minimum this number of samples mutated in atleast one of the cohort for analysis. Helful to ignore single mutated genes. Default 5.
#' @param useCNV whether to include copy number events. Default TRUE if available.. Not applicable when `pathways = TRUE`
#' @param pathways Summarize genes by pathways before comparing. Default `FALSE`
#' @param custom_pw Optional. Can be a two column data.frame/tsv-file with pathway-name and genes involved in them. Default `NULL`, uses a predefined list of pathways. Applicable only when `pathways = TRUE`
#' @param pathways Summarize genes by pathways before comparing. Can be 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{NULL}
#' @param custom_pw Optional. 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 pseudoCount If TRUE, adds 1 to the contingency table with 0's to avoid `Inf` values in the estimated odds-ratio.
#' @return result list
#' @examples
Expand All @@ -22,7 +22,7 @@
#' @seealso \code{\link{forestPlot}}
#' @seealso \code{\link{lollipopPlot2}}

mafCompare = function(m1, m2, m1Name = NULL, m2Name = NULL, minMut = 5, useCNV = TRUE, pathways = FALSE, custom_pw = NULL, pseudoCount = FALSE){
mafCompare = function(m1, m2, m1Name = NULL, m2Name = NULL, minMut = 5, useCNV = TRUE, pathways = NULL, custom_pw = NULL, pseudoCount = FALSE){

m1.gs <- getGeneSummary(x = m1)
m2.gs <- getGeneSummary(x = m2)
Expand All @@ -43,13 +43,28 @@ mafCompare = function(m1, m2, m1Name = NULL, m2Name = NULL, minMut = 5, useCNV =
SampleSize = c(m1.sampleSize, m2.sampleSize)
)

if(pathways){
if(!is.null(custom_pw)){

if(is.data.frame(custom_pw)){
colnames(custom_pw)[1:2] = c("Pathway", "Gene")
} else if(file.exists(custom_pw)){
custom_pw = data.table::fread(file = custom_pw)
colnames(custom_pw)[1:2] = c("Pathway", "Gene")
}

m1_pw = get_pw_summary(maf = m1, pathways = custom_pw)[,.(Pathway, Mutated_samples)]
m2_pw = get_pw_summary(maf = m2, pathways = custom_pw)[,.(Pathway, Mutated_samples)]

m.gs.meged = merge(m1_pw, m2_pw, by = "Pathway", all = TRUE)
m.gs.meged = as.data.frame(m.gs.meged)

}else if(!is.null(pathways)){
pw_db = match.arg(arg = pathways, choices = c("sigpw", "smgbp"))
m1_pw = get_pw_summary(maf = m1, pathways = pw_db)[,.(Pathway, Mutated_samples)]
m2_pw = get_pw_summary(maf = m2, pathways = pw_db)[,.(Pathway, Mutated_samples)]

m.gs.meged = merge(m1_pw, m2_pw, by = "Pathway", all = TRUE)
m.gs.meged = as.data.frame(m.gs.meged)
}else{
if(useCNV){
m1.genes = as.character(m1.gs[AlteredSamples >= minMut,Hugo_Symbol])
Expand Down
7 changes: 3 additions & 4 deletions R/oncoPathway.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#' @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)
#' @param fontsize Defalt 1
#' @param col Default #f39c12
#' @return fraction of altered pathway. attr genes contain pathway contents
#' @seealso \code{\link{plotPathways}}
Expand All @@ -28,10 +27,10 @@ pathways = function(maf, pathdb = "sigpw", pathways = NULL, fontSize = 1, panelW
if(is.null(pathways)){
pathways = match.arg(arg = pathdb, choices = c("sigpw", "smgbp"))
}else{
if(file.exists(pathways)){
pathways = data.table::fread(file = pathways)
if(is.data.frame(pathways)){
colnames(pathways)[1:2] = c("Pathway", "Gene")
}else if(is.data.frame(pathways)){
} else if(file.exists(pathways)){
pathways = data.table::fread(file = pathways)
colnames(pathways)[1:2] = c("Pathway", "Gene")
}
}
Expand Down
13 changes: 8 additions & 5 deletions R/oncomatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,12 @@ update_colors = function(x, y){

#Get pathway summary from an MAF
get_pw_summary = function(maf, pathways = NULL){
if(pathways %in% c("sigpw", "smgbp")){

if(is(pathways, class2 = "data.frame")){
pathdb = data.table::copy(x = pathways)
colnames(pathdb)[1:2] = c("Pathway", "Gene")
data.table::setDT(x = pathdb)
}else if(pathways %in% c("sigpw", "smgbp")){
if(pathways == "sigpw"){
pathdb <- system.file("extdata", "oncogenic_sig_patwhays.tsv", package = "maftools")
message("Summarizing signalling pathways [Sanchez-Vega et al., https://doi.org/10.1016/j.cell.2018.03.035]")
Expand All @@ -691,11 +696,9 @@ get_pw_summary = function(maf, pathways = NULL){
}
pathdb = data.table::fread(file = pathdb)
colnames(pathdb)[1:2] = c("Pathway", "Gene")
}else{
pathdb = data.table::copy(x = pathways)
colnames(pathdb)[1:2] = c("Pathway", "Gene")
data.table::setDT(x = pathdb)
}


pathdb_size = pathdb[,.N,Pathway]
pathdb = split(pathdb, as.factor(pathdb$Pathway))

Expand Down
17 changes: 0 additions & 17 deletions R/plotPathways.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#' Plot oncogenic pathways
#' @references Sanchez-Vega F, Mina M, Armenia J, Chatila WK, Luna A, La KC, Dimitriadoy S, Liu DL, Kantheti HS, Saghafinia S et al. 2018. Oncogenic Signaling Pathways in The Cancer Genome Atlas. Cell 173: 321-337 e310
#'
#' @details
#' Draws oncoplot of oncogenic pathway.
#' @param maf an \code{\link{MAF}} object generated by \code{\link{read.maf}}
#' @param pathways Name of pathways to be drawn
#' @param pathdb A tsv file or a data frame containing pathway to gene mappings. If not provided uses the default resource. Data must contain at least two columns with pathway name and gene names. Optionally a third column with OG or TSG information can be added.
#' @param fullPathway Include all genes from the pathway. Defaulr FALS only plots mutated genes
#' @param removeNonMutated Default TRUE
#' @param tsgCol Color for tumro suppressor genes. Default red
#' @param ogCol Color for onco genes. Default royalblue
#' @param fontSize Default 0.6
#' @param showTumorSampleBarcodes logical to include sample names.
#' @param SampleNamefontSize font size for sample names. Default 10
#' @param sampleOrder Manually speify sample names for oncolplot ordering. Default NULL.

plotPathways = function(maf, pathways = NULL, fullPathway = FALSE, pathdb = NULL,
removeNonMutated = TRUE, tsgCol = "red", ogCol = "royalblue", fontSize = 0.6, showTumorSampleBarcodes = FALSE, sampleOrder = NULL, SampleNamefontSize = 0.6){

Expand Down
1 change: 1 addition & 0 deletions inst/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `readGistic` can take gistic output directory as an input. PR by [biosunsci](https://github.com/biosunsci) [954](https://github.com/PoisonAlien/maftools/pull/954)

## BUG FIXES
- Bug fixes while processing custom pathways
- Bug fix in `oncoplot` for drawing borders. [958](https://github.com/PoisonAlien/maftools/issues/958)
- Bug fix in `plotSignatures` for hardcoded axis limits. [949](https://github.com/PoisonAlien/maftools/issues/949)
- Bug fix in `mafSurvival` legend when samples argument is give. [937](https://github.com/PoisonAlien/maftools/issues/937)
Expand Down
6 changes: 3 additions & 3 deletions man/mafCompare.Rd

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

2 changes: 0 additions & 2 deletions man/pathways.Rd

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

0 comments on commit 7a27eba

Please sign in to comment.