Stage 9: More plots
Optional: scatter plots, a line along the protein, and a heatmap that shows thousands of values at once.
These plots answer "what goes with what?" and "where along the protein?". They use the same pattern as before: draw, label, show. Skip this stage if you are short of time; the plots in Stage 8 are enough for most work.
Two measurements against each other
sns.scatterplot(data=miss, x="se", y="score", alpha=0.4)
plt.title("Do noisier measurements score differently?")
plt.xlabel("standard error")
plt.ylabel("abundance score")
plt.show()Along the protein
Position goes on the x-axis and the average score on the y-axis. Dips show where changes hurt the most.
by_position = miss.groupby("position")["score"].mean()
plt.plot(by_position.index, by_position.values)
plt.title("Average score along the protein")
plt.xlabel("position")
plt.ylabel("average abundance score")
plt.show()A heatmap
One small square for every swap: the position along the bottom, the new amino acid up the side, and the colour for the score. Vertical stripes mean "this position dislikes every change". Grey squares were not measured.
grid = miss.pivot_table(index="alt", columns="position", values="score")
grid.columns = grid.columns.astype(int)
plt.figure(figsize=(12, 5))
sns.heatmap(grid, cmap="viridis", vmin=0, vmax=1.2, xticklabels=25)
plt.title("Score for every amino acid swap")
plt.xlabel("position")
plt.ylabel("new amino acid")
plt.show()Windows along the protein
Group neighbouring positions into windows of 10: position // 10 * 10 turns 123 into 120. Then summarise each window.
miss["window"] = miss["position"] // 10 * 10
counts = miss.groupby("window").size()
means = miss.groupby("window")["score"].mean()
means[counts >= 30].sort_values().head()Now practise in Colab
You have read the ideas. Next, try them. The notebook repeats the code above with a few blanks for you to fill in, then ends with small exercises. It covers Stages 8 and 9, so scroll to the section with this stage's number. Run the cells in order.
Open the practice notebookYou need a free Google account. When it opens, choose File, then Save a copy in Drive, so your work is yours.
Exercises
These are also in the notebook. Try each one yourself before you open the solution.
Does a noisier measurement score differently?
se (x) against score (y) for the missense variants. Describe what you see in one sentence.Show a solution (try it first)
Your numbers will depend on the real table, so there is no fixed output to compare with.
sns.scatterplot(data=miss, x="se", y="score", alpha=0.4)
plt.xlabel("standard error")
plt.ylabel("abundance score")
plt.show()Check your understanding
First star
Using only missense rows, group by the new amino acid (alt) and take the average score. Which new amino acid, written as its three letters like Ala, has the lowest average?
Stuck? Nudge and solution
miss.groupby("alt")["score"].mean().idxmin().
print(miss.groupby("alt")["score"].mean().idxmin())Second star
In windows of 10 positions, among windows with at least 30 missense variants, which window has the lowest average score? Answer with the window's starting number.
Stuck? Nudge and solution
The last code cell already does it: means[counts >= 30] keeps windows with enough variants, and .idxmin() finds the lowest.
print(means[counts >= 30].idxmin())Special thanks to Nilay!