Open drhmoosavi opened 5 months ago
I could fix the problem but the barplot for color combontions are not shown properly now.
Here is my revised code:
mutation_colors = c(
nonsynonymousSNV = "#196F3D",
frameshiftdeletion = "#283593",
frameshiftinsertion = "#EF6C00",
stopgain = "#7D1D67",
stopgain_stopgain = "#7D1D67",
frameshiftdeletion_frameshiftdeletion = "#283593"
)
alter_fun = list(
nonsynonymousSNV = alter_graphic("rect", fill = mutation_colors["nonsynonymousSNV"], col = "white", horiz_margin = unit(0,"mm"), vertical_margin = unit(0,"mm")),
frameshiftinsertion = alter_graphic("rect", fill = mutation_colors["frameshiftinsertion"], col = "white", horiz_margin = unit(0,"mm"), vertical_margin = unit(0,"mm")),
frameshiftdeletion = alter_graphic("rect", fill = mutation_colors["frameshiftdeletion"],col = "white", horiz_margin = unit(0,"mm"), vertical_margin = unit(0,"mm")),
frameshiftdeletion_frameshiftdeletion = alter_graphic("rect", fill = mutation_colors["frameshiftdeletion_frameshiftdeletion"],col = "white", horiz_margin = unit(0,"mm"), vertical_margin = unit(0,"mm")),
stopgain = alter_graphic("rect", fill = mutation_colors["stopgain"], col = "white", horiz_margin = unit(0,"mm"), vertical_margin = unit(0,"mm")),
stopgain_stopgain = alter_graphic("rect", fill = mutation_colors["stopgain_stopgain"], col = "white", horiz_margin = unit(0,"mm"), vertical_margin = unit(0,"mm")),
stopgain_nonsynonymousSNV = function(x, y, w, h) {
# First mutation type (triangle)
grid.polygon(
unit.c(x - 0.5*w, x - 0.5*w, x + 0.5*w),
unit.c(y - 0.5*h, y + 0.5*h, y - 0.5*h),
gp = gpar(fill = mutation_colors["stopgain"], col = "white")) # fill
# Second mutation type (triangle)
grid.polygon(
unit.c(x + 0.5*w, x + 0.5*w, x - 0.5*w),
unit.c(y + 0.5*h, y - 0.5*h, y + 0.5*h),
gp = gpar(fill = mutation_colors["nonsynonymousSNV"], col= "white", lwd =1)) # fill
},
stopgain_frameshiftinsertion = function(x, y, w, h) {
# First mutation type (triangle)
grid.polygon(
unit.c(x - 0.5*w, x - 0.5*w, x + 0.5*w),
unit.c(y - 0.5*h, y + 0.5*h, y - 0.5*h),
gp = gpar(fill = mutation_colors["stopgain"], col = "white")) # fill
# Second mutation type (triangle)
grid.polygon(
unit.c(x + 0.5*w, x + 0.5*w, x - 0.5*w),
unit.c(y + 0.5*h, y - 0.5*h, y + 0.5*h),
gp = gpar(fill = mutation_colors["frameshiftinsertion"], col= "white", lwd =1)) # fill
},
stopgain_frameshiftdeletion = function(x, y, w, h) {
# First mutation type (triangle)
grid.polygon(
unit.c(x - 0.5*w, x - 0.5*w, x + 0.5*w),
unit.c(y - 0.5*h, y + 0.5*h, y - 0.5*h),
gp = gpar(fill = mutation_colors["stopgain"], col = "white")) # fill
# Second mutation type (triangle)
grid.polygon(
unit.c(x + 0.5*w, x + 0.5*w, x - 0.5*w),
unit.c(y + 0.5*h, y - 0.5*h, y + 0.5*h),
gp = gpar(fill = mutation_colors["frameshiftdeletion"], col= "white", lwd =1)) # fill
},
background = function(x, y, w, h) {
grid.rect(x, y, w, h, gp = gpar(fill = "gray80", col= "white", lwd =1))
}
)
In my matrix I have combinations of values in the mutation_colors vector seperated using " ; ". For example, I have instances of "stopgain;frameshiftdeletion" and "stopgain;frameshiftinsertion". How do I make the alter function to produce correct color coding for this combinations? It currently procuded combinations that dose not exist, for example it has made a 2-color squre for "nonsynonymousSNV+frameshiftdeletion+frameshiftinsertion", which is not in the input matrix. Also, I was wondering if I could have the entire squre filled with designated color for any of the 4 simple mutation types in the mutation_color vector, instead of having a rectangle ?