Skip to content

Lesson 4 practice questions

Question 1

Create a volcano plot for the differential expression analysis results for the hcc1395 data (hint: import hcc1395_deg_chr22_with_significance.csv)

Solution

import pandas
import matplotlib.pyplot as plt
import seaborn
hcc1395_deg_chr22=pandas.read_csv("./hcc1395_deg_chr22_with_significance.csv")
plot1=seaborn.scatterplot(hcc1395_deg_chr22,x="log2FoldChange", y="-log10PAdj", hue="significance")
plt.show()

Question 2

Label the two most differential expressed genes in the volcano plot. As a hint, first import hcc1395_deg_chr22_top_genes.csv.

Solution

hcc1395_deg_chr22_top_genes=pandas.read_csv("./hcc1395_deg_chr22_top_genes.csv")
plot1=seaborn.scatterplot(hcc1395_deg_chr22,x="log2FoldChange", y="-log10PAdj", hue="significance")
for i, gene_name in enumerate(hcc1395_deg_chr22_top_genes["name"]):
    plot1.text(hcc1395_deg_chr22_top_genes["log2FoldChange"][i], 
              hcc1395_deg_chr22_top_genes["-log10PAdj"][i],gene_name)
plt.show()

Question 3

Import hcc1395_top_deg_normalized_counts.csv and create an expression heatmap. Use the Viridis color palette.

Solution

hcc1395_top_deg_normalized_counts=pandas.read_csv("./hcc1395_top_deg_normalized_counts.csv", index_col=0)
plot2=seaborn.clustermap(hcc1395_top_deg_normalized_counts,z_score=0,cmap="viridis",
                        figsize=(8,8),vmin=-1.5, vmax=1.5,cbar_kws=({"label": "z score"}))
plt.show()

Question 4

Add a bar on the top of the heatmap that shows which treatment group the samples belong to.

Solution

samples=pandas.Series({"hcc1395_normal_rep1":"orangered", "hcc1395_normal_rep2":"orangered", "hcc1395_normal_rep3":"orangered", "hcc1395_tumor_rep1":"blue", "hcc1395_tumor_rep2":"blue", "hcc1395_tumor_rep3":"blue"})
column_colors = hcc1395_top_deg_normalized_counts.columns.map(samples)
plot2=seaborn.clustermap(hcc1395_top_deg_normalized_counts,z_score=0,cmap="viridis",
                        figsize=(8,8),vmin=-1.5, vmax=1.5,cbar_kws=({"label": "z score"}),
                        col_colors=column_colors, cbar_pos=(0.05,0.8,0.025,0.15))
plot2.ax_heatmap.set_xticklabels(plot2.ax_heatmap.get_xmajorticklabels(),fontsize=12,rotation=90)
plot2.ax_cbar.tick_params(labelsize=12)
plot2.ax_col_colors.set_title("treatment",x=1.09,y=-0.3)
plt.show()