← Lab 8

1 · Quicker figures

The Lab 7 figures in fewer lines: pandas for a quick look, seaborn to compare groups.

pandas and seaborn, both on top of matplotlib
df["SOX10"].plot.hist(bins=40, ax=ax)
a column draws its own histogram
medians.nsmallest(8).plot.barh(ax=ax)
a groupby result draws itself too
sns.scatterplot(data=skin, x="BRAF", y="SOX10")
name the columns; seaborn finds the numbers
df.loc[is_skin, "group"] = "skin"
a label column: relabel only the rows you pick
sns.boxplot(...) · sns.stripplot(...)
one box per group, every cell line as a dot
def group_figure(table, gene): ... return fig
a function that returns the figure, as the project asks
In the notebook
  • ▸a pandas histogram of BRAF
  • ▸median BRAF per lineage as bars
  • ▸a seaborn scatter of the skin lines
  • ▸broken: why every row says skin
  • ▸MDM2 in three groups, box plus dots
  • ▸group_figure(table, gene), then save it

About 40 minutes. group_figure is the three-group figure your project needs.

2 · Real, or chance?

Is a difference bigger than chance? One test, one function, many genes.

scipy.stats
df.sample(73)
a random group, to see what chance does
mannwhitneyu(a, b).pvalue
could this difference be chance?
p < 0.05
the cut-off; difference first, then p
def compare(a, b): return {...}
medians, difference, p and significant, by name
pd.DataFrame(rows)
a list of dictionaries becomes a table, one row per gene
spearmanr(x, y).statistic · sns.regplot
do two columns move together?
In the notebook
  • ▸500 random groups vs the real skin difference
  • ▸BRAF and PAX8: significant, or not?
  • ▸broken: comparing the whole result with 0.05
  • ▸NRAS: real but small
  • ▸compare(a, b), then nine genes in one table
  • ▸MITF and SOX10: a Spearman correlation

About 40 minutes. compare() is the core of your project's statistics.

Learn more, free

Two notebooks are enough seaborn and statistics for your project. If you want more, these are the next steps.

seaborn: one course
  • ▸Scatter, line, count and bar plots
  • ▸Colour and style by a third column
  • ▸Many panels from one call
Statistics: a track
  • ▸Distributions, and when a t-test is fine
  • ▸Hypothesis testing, step by step
  • ▸Many tests at once: why false alarms add up