Atharva Bhagwat

Stage 7: Summarising by region

0Plan
Stage 7Core
★★★

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:

run this
regions = pd.read_csv("https://atharvabhagwat.dev/assets/data/pten-region-annotations.csv")
regions

Label 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:

run this
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.

run this
miss = df[df["record_type"] == "missense"].copy()
len(miss)

Summarise by region, with counts

run this
by_region = miss.groupby("region")["score"].agg(["count", "mean", "median"])
by_region

Summarise by position

run this
by_position = miss.groupby("position")["score"].mean()
by_position.sort_values().head(10)      # the ten positions with the lowest average

Read 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:

  1. How big is each group? A median from 12 variants and one from 1,500 are not equally trustworthy.
  2. 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.
  3. 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

Using the missense table 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.

one solution
print(miss.groupby("alt")["score"].mean().sort_values())

Write your reading of the table

Look at your 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)
one solution
# (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.

one way to get it
print(by_region.loc["phosphatase_domain", "mean"])

Special thanks to Nilay!