<p>What is fed into <code>ComplexHeatmap</code> is what it outputs! So if one of your genes has a <code>Missense_Mutation</code> as well as a <code>Frame_Shift_Del</code> and you would like to plot its value, of course you will have a category and color that is different than those of <code>Missense_Mutation</code> or <code>Frame_Shift_Del</code>, that is only natural.</p>
<p>What you can do is to create additional variables like <code>your_gene_Missense_Mutation</code> or <code>your_gene_Frame_Shift_Del</code> each with 0 or 1 to indicate if a particular mutation type is present or not for a particular gene (you can think of it like one-hot-encoding). With a lot of different levels, the resulting heatmap could be difficult to interpret though.</p>
<p>Another simpler alternative would be a using a &quot;universal label&quot; if your gene has multiple mutations. Basically if the cell contains a <code>;</code>, its value will be changed to something like <code>mixed_mutation_status</code> and instead of <code>multiple &quot;mutation_type_1; mutation_type_2; ...</code> like categories, you will just have one <code>mixed_mutation_status</code> on top of <code>Missense_Mutation</code>, <code>Frame_Shift_Del</code>, ...</p>

CC BY-SA 4.0
2020-07-03T16:26:59.130Z
The `mixed_mutation_status` is indeed how maftools does it - it calls it `multi-hit`. Although, in this case, the same mutation can be both `missense` and `splice_site` if it's a mutation at an exonic spllice site. OP should first pick among the many possible consequences of a mutation wherever possible, and then apply a logic where multiple mutations still exist in the same gene.
Ram RS
CC BY-SA 4.0
2020-07-02T10:57:01.407Z
2020-07-02T10:57:01.407Z
haci
<p>So right now my observations in the dataset I've processed is stored as sample identifier columns and gene rows: an example of this would be for sample 1 and gene TRIM21 the observation is Missense Mutation;Frame Shift Deletion. I'm having issues separating the two alterations and instead of being able to show the gene in the sample having 2 different alterations, I end up having to generate a new colour classification (being that the gene in the specific sample exhibits specifically both a missense mutation and a frame shift deletion instead of being able to represent the observation with just colours and missense and frame shift deletion colours alone). Here is an a screenshot of what my matrix looks like: <a href="https://i.sstatic.net/i6i1H.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/i6i1H.png" alt="enter image description here" /></a></p>
<p>As an example here is some test code generating the test plot:</p>
<pre><code>library(ComplexHeatmap)

test_labels &lt;- c(&quot;Missense_Mutation&quot;, &quot;Splice_Site&quot;, &quot;Frame_Shift_Del&quot;,
                 &quot;Splice_Region&quot;,&quot;Missense_Mutation;Splice_Site&quot;, &quot;Splice_Site;Frame_Shift_Del&quot;, 
                 &quot;Splice_Site;Missense_Mutation&quot;, &quot;Frame_Shift_Del;Splice_Site&quot;)
                           

plot &lt;- Heatmap(test, row_names_side = &quot;left&quot;,
        row_names_gp = gpar(cex = 0.7), 
        column_names_gp = gpar(cex = 0.7), 
        heatmap_legend_param = list(title = &quot;Alterations&quot;, 
                                    at = test_labels, labels = test_labels), show_heatmap_legend = TRUE)

plot
</code></pre>
<p>I've attached a screenshot of my actual plot and as you will be able to see, this ends up creating multiple different classifications: <a href="https://i.sstatic.net/Zr5QE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Zr5QE.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2020-07-01T21:52:48.760Z
Dear John, I am sure your post makes sense to someone, but makes little sense to me. I can see in your tags you are using Bioconductor ... that is a good start. Perhaps you can post your code and explain the data set. I see that the red is stuff you don' twant us to see
M__
CC BY-SA 4.0
2020-07-01T22:27:04.910Z
Hi Michael, thanks for responding! This is specific to a package in Bioconductor: https://jokergoo.github.io/ComplexHeatmap-reference/book/index.html. I would add my code, but I would also need to provide the exact dataset as well as the data processing I've already done, which is a decently long script. Essentially, the data set is represents samples (columns) and genes (rows), and observations correspond to what the alteration present in the specific gene in the specific patient sample. As you can see, sometimes observations are separated by ";".
John Abercrombie
CC BY-SA 4.0
2020-07-01T22:28:12.880Z
This is a pretty specific question I realize, as I am using the Heatmap function in the vignette and it doesn't exactly cover how I'd be able to parse what I'd like to.
John Abercrombie
CC BY-SA 4.0
2020-07-01T22:29:46.070Z
Thanks. Don't need to provide your data set ... a dumbie data set is fine - we understand patient confidentiality issues. Putting some code there would be useful.
M__
CC BY-SA 4.0
2020-07-01T22:49:23.510Z
I've updated my question with some sample code! You'll see in the legend, e.g. "Missense_Mutation;Splice_Site" is given its own category instead of being recognized separately as "Missense_Mutation" and "Splice_Site".
John Abercrombie
CC BY-SA 4.0
2020-07-01T23:40:18.967Z
What color do you expect when the algorithm encounters a value that is neither `Missense` nor `Frame-shift` but `Missense;Frame-shift`? Are you looking for the cell to be split into 2 colors if that happens?
Ram RS
CC BY-SA 4.0
2020-07-01T23:43:47.243Z
Because if that's the case, eyeballing will be extremely difficult with each cell looking a different height (or width) and the plot showing jarring patterns. Pick the most severe consequence and plot those alone, or use `cell_fun` to create a plot that IMO would be a mess and beats all reason for visualization.
Ram RS
<bioconductor><mutations><heatmap><complexheatmap>
Is there a way to customize what observations are plotted in ComplexHeatmap?
# Is there a way to customize what observations are plotted in ComplexHeatmap?

(Asked by: username_0 on 2020-07-01)

So right now my observations in the dataset I've processed is stored as sample identifier columns and gene rows: an example of this would be for sample 1 and gene TRIM21 the observation is Missense Mutation;Frame Shift Deletion. I'm having issues separating the two alterations and instead of being able to show the gene in the sample having 2 different alterations, I end up having to generate a new colour classification (being that the gene in the specific sample exhibits specifically both a missense mutation and a frame shift deletion instead of being able to represent the observation with just colours and missense and frame shift deletion colours alone). Here is an a screenshot of what my matrix looks like: 
As an example here is some test code generating the test plot:
library(ComplexHeatmap)

test_labels <- c("Missense_Mutation", "Splice_Site", "Frame_Shift_Del",
                 "Splice_Region","Missense_Mutation;Splice_Site", "Splice_Site;Frame_Shift_Del", 
                 "Splice_Site;Missense_Mutation", "Frame_Shift_Del;Splice_Site")
                           

plot <- Heatmap(test, row_names_side = "left",
        row_names_gp = gpar(cex = 0.7), 
        column_names_gp = gpar(cex = 0.7), 
        heatmap_legend_param = list(title = "Alterations", 
                                    at = test_labels, labels = test_labels), show_heatmap_legend = TRUE)

plot

I've attached a screenshot of my actual plot and as you will be able to see, this ends up creating multiple different classifications:

**Tags:** bioconductor, mutations, heatmap, complexheatmap
> **Comments:**
> **username_1**: Dear John, I am sure your post makes sense to someone, but makes little sense to me. I can see in your tags you are using Bioconductor ... that is a good start. Perhaps you can post your code and explain the data set. I see that the red is stuff you don' twant us to see  
> **username_0**: Hi Michael, thanks for responding! This is specific to a package in Bioconductor: https://jokergoo.github.io/ComplexHeatmap-reference/book/index.html. I would add my code, but I would also need to provide the exact dataset as well as the data processing I've already done, which is a decently long script. Essentially, the data set is represents samples (columns) and genes (rows), and observations correspond to what the alteration present in the specific gene in the specific patient sample. As you can see, sometimes observations are separated by ";".  
> **username_0**: This is a pretty specific question I realize, as I am using the Heatmap function in the vignette and it doesn't exactly cover how I'd be able to parse what I'd like to.  
> **username_1**: Thanks. Don't need to provide your data set ... a dumbie data set is fine - we understand patient confidentiality issues. Putting some code there would be useful.  
> **username_0**: I've updated my question with some sample code! You'll see in the legend, e.g. "Missense_Mutation;Splice_Site" is given its own category instead of being recognized separately as "Missense_Mutation" and "Splice_Site".  
> **username_2**: What color do you expect when the algorithm encounters a value that is neither `Missense` nor `Frame-shift` but `Missense;Frame-shift`? Are you looking for the cell to be split into 2 colors if that happens?  
> **username_2**: Because if that's the case, eyeballing will be extremely difficult with each cell looking a different height (or width) and the plot showing jarring patterns. Pick the most severe consequence and plot those alone, or use `cell_fun` to create a plot that IMO would be a mess and beats all reason for visualization.  

---

## 1 answers

### Answer by username_3 on 2020-07-02. Score: 1 | Accepted answer

What is fed into `ComplexHeatmap` is what it outputs! So if one of your genes has a `Missense_Mutation` as well as a `Frame_Shift_Del` and you would like to plot its value, of course you will have a category and color that is different than those of `Missense_Mutation` or `Frame_Shift_Del`, that is only natural.

What you can do is to create additional variables like `your_gene_Missense_Mutation` or `your_gene_Frame_Shift_Del` each with 0 or 1 to indicate if a particular mutation type is present or not for a particular gene (you can think of it like one-hot-encoding). With a lot of different levels, the resulting heatmap could be difficult to interpret though.

Another simpler alternative would be a using a "universal label" if your gene has multiple mutations. Basically if the cell contains a `;`, its value will be changed to something like `mixed_mutation_status` and instead of `multiple "mutation_type_1; mutation_type_2; ...` like categories, you will just have one `mixed_mutation_status` on top of `Missense_Mutation`, `Frame_Shift_Del`, ...

> **Comments:**
> **username_2**: The `mixed_mutation_status` is indeed how maftools does it - it calls it `multi-hit`. Although, in this case, the same mutation can be both `missense` and `splice_site` if it's a mutation at an exonic spllice site. OP should first pick among the many possible consequences of a mutation wherever possible, and then apply a logic where multiple mutations still exist in the same gene.  

---

