Skip to content

Commit

Permalink
address #363
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonAlien committed Aug 22, 2023
1 parent 465a8e6 commit 265f8d0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
75 changes: 54 additions & 21 deletions R/oncoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1148,37 +1148,70 @@ oncoplot = oncoplot = function(maf, top = 20, minMut = NULL, genes = NULL, alter

x_axp = 0+lep$rect$w

#print(annotation)
#return(annotationColor)

if(!is.null(clinicalFeatures)){
#Check which of the clinicalFeatures are of numeric
ann_classes = lapply(names(annotationColor), function(ac){
temp_anno = data.table::copy(maf@clinical.data)
data.table::setDF(temp_anno)
ac_idx = which(colnames(temp_anno) == ac)
is.numeric(temp_anno[,ac_idx])
})
num_start = 0.1 #numeric legend starts from here
num_width = 0.1
num_incr = 0.2

for(i in 1:ncol(annotation)){
#x = unique(annotation[,i])
x = annotationColor[[i]]
is_num = ann_classes[[i]]
xt = names(x)
if("NA" %in% xt){
xt = xt[!xt %in% "NA"]
xt = sort(xt, decreasing = FALSE)
xt = c(xt, "NA")
x = x[xt]
}else{
xt = sort(xt, decreasing = FALSE)
x = x[xt]
}

if(length(x) <= 4){
n_col = 1
if(is_num){
x_range = as.numeric(names(x))
x_range = x_range[!is.na(x_range)]
x_range = x_range[!is.infinite(x_range)]
x_range = range(x_range)

image(
y = c(0.1, 0.2),
x = seq(num_start, num_start+num_width, length.out = 200),
z = t(matrix(seq(0,1,length.out = 200), nrow= 1)),
col = x, xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = NA, ylab = NA, add = TRUE
)
text(x = c(num_start, num_start+num_width), y = 0.2, labels = x_range, pos = 3)
text(x = num_start+(num_width/2), y = 0.1, labels = clinicalFeatures[i], pos = 1, adj = 1)
num_start = num_start + num_incr

}else{
n_col = (length(x) %/% 4)+1
}
names(x)[is.na(names(x))] = "NA"
if("NA" %in% xt){
xt = xt[!xt %in% "NA"]
xt = sort(xt, decreasing = FALSE)
xt = c(xt, "NA")
x = x[xt]
}else{
xt = sort(xt, decreasing = FALSE)
x = x[xt]
}

lep = legend(x = x_axp, y = 1, legend = names(x),
col = x, border = NA,
ncol= n_col, pch = 15, xpd = TRUE, xjust = 0, bty = "n",
cex = annotationFontSize, title = rev(names(annotation))[i],
title.adj = 0)
x_axp = x_axp + lep$rect$w
if(length(x) <= 4){
n_col = 1
}else{
n_col = (length(x) %/% 4)+1
}
names(x)[is.na(names(x))] = "NA"

}
lep = legend(x = x_axp, y = 1, legend = names(x),
col = x, border = NA,
ncol= n_col, pch = 15, xpd = TRUE, xjust = 0, bty = "n",
cex = annotationFontSize, title = rev(names(annotation))[i],
title.adj = 0)
x_axp = x_axp + lep$rect$w

}
}
}

if(removeNonMutated){
Expand Down
1 change: 1 addition & 0 deletions inst/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Added `sortByM1` and `sortByM2` argument to `coOncoplot`. Issue: [888](https://github.com/PoisonAlien/maftools/issues/888)
- Added arguments `leftBarVline`, `leftBarVlineCol`, `rightBarVline`, `rightBarVlineCol` `topBarHline` `topBarHlineCol` to `oncoplot`. Issue: [874](https://github.com/PoisonAlien/maftools/issues/874)
- Added `revPal` argument to `somaticInteractions`. Issue: [859](https://github.com/PoisonAlien/maftools/issues/859)
- Fix legend and color codes for numeric annotations in `oncoplot`. Issue: [363](https://github.com/PoisonAlien/maftools/issues/363)

# CHANGES IN VERSION 2.16.0
(Bioconductor release version)
Expand Down

0 comments on commit 265f8d0

Please sign in to comment.