Stage 7: Summarising by region
Label each variant with the part of the protein it falls in, summarise by group, and read the result like a scientist.
Stage 7 gave you one row per variant. Questions usually live at a coarser level: per position, per region, per kind. PTEN has two folded parts, a phosphatase domain (the enzyme part) and a C2 domain (which helps the protein attach to membranes), followed by a floppy tail with no fixed shape. A second small table lists those stretches with their start and end positions:
regions = pd.read_csv("https://atharvabhagwat.dev/assets/data/pten-region-annotations.csv")
regionsLabel each row with its region
.between(14, 185) gives True for positions from 14 to 185, including both ends. Use it to fill a new column, one region at a time:
df["region"] = "other"
df.loc[df["position"].between(14, 185), "region"] = "phosphatase_domain"
df.loc[df["position"].between(190, 350), "region"] = "c2_domain"
df.loc[df["position"].between(352, 403), "region"] = "disordered_tail"
df["region"].value_counts()The numbers come from the regions table above. (Rows with no position, and positions between regions, stay as other.)
Keep only one kind of variant
Different kinds answer different questions. To ask "how do single amino acid swaps affect abundance?", keep only the missense rows and give that table a name. .copy() makes it a separate table you can add columns to.
miss = df[df["record_type"] == "missense"].copy()
len(miss)Summarise by region, with counts
by_region = miss.groupby("region")["score"].agg(["count", "mean", "median"])
by_regionSummarise by position
by_position = miss.groupby("position")["score"].mean()
by_position.sort_values().head(10) # the ten positions with the lowest averageRead the table like a scientist
Numbers become findings only when you ask what they mean. Before the last puzzle of this stage, look at by_region and ask three questions:
- How big is each group? A median from 12 variants and one from 1,500 are not equally trustworthy.
- Does the pattern make biological sense? Folded domains need an exact shape, so changing their amino acids often destabilises them. A floppy tail has no shape to lose.
- What can abundance not tell you? A region can tolerate changes in abundance and still be essential for function.
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 6 and 7, 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.
Summarise by amino acid
miss, find the average score for each new amino acid (alt), sorted from lowest to highest.Show a solution (try it first)
Your numbers will depend on the real table, so there is no fixed output to compare with.
print(miss.groupby("alt")["score"].mean().sort_values())Write your reading of the table
by_region table and write three sentences in a text cell: which region looks most affected, whether that makes biological sense, and how the number of variants in each region changes how much you trust it.Show a solution (try it first)
# (describe what you see)Check your understanding
First star
Using only missense rows, what is the average score in the phosphatase_domain, to 3 decimal places?
Stuck? Nudge and solution
Look at the mean column of by_region, or filter miss on region yourself.
print(by_region.loc["phosphatase_domain", "mean"])Second star
Among the three named regions (phosphatase_domain, c2_domain, disordered_tail), which has the lowest median score? Type the region name.
Stuck? Nudge and solution
Look at the median column of by_region, and ignore the row called other.
print(by_region.drop("other")["median"].idxmin())Third star
Write your interpretation (about four sentences). Using your own by_region table: which region looks most and which least tolerant of changes, does that make biological sense for a folded domain versus a floppy tail, and how does the number of variants in each region affect how much you trust the comparison?
A model answer (use your own numbers)
"The ___ has the lowest median score (___, n = ___) and the ___ the highest (___, n = ___). That fits the idea that folded domains must keep a precise shape, so many amino acid swaps there destabilise the protein, while a floppy tail has no fixed structure to lose. The regions have very different numbers of variants, so a median from a small group is less reliable and I would not over-read a small gap. Also, abundance is only one property: a region that keeps the protein stable might still matter for activity."
Did you cover
- Named the extreme regions with a number and a count?
- Gave a biological reason and judged whether it fits?
- Said how group size changes your confidence?
- Noted what abundance cannot tell you?
Stuck? How to start
Start from the numbers: name the regions and quote a median and a count for each. Then give one biological reason and one reason to be careful.
Special thanks to Nilay!