Skip to content

Commit 258e305

Browse files
authored
Merge pull request #32 from biosustain/fix_nb
🎨 remove duplication and improve view
2 parents 3da596a + 9eb6033 commit 258e305

3 files changed

Lines changed: 49 additions & 27 deletions

File tree

2_data_analysis.ipynb

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -552,28 +552,40 @@
552552
"id": "ae74387d",
553553
"metadata": {},
554554
"source": [
555-
"# Analytical Plots\n",
556-
"- data distribution (e.g. histogram)\n",
555+
"# Quality Control Plots (protein level)\n",
556+
"- data distribution (histogram and boxplot) to identify drift\n",
557557
"- coefficient of variation (CV)\n",
558558
"- number of identified proteins per sample"
559559
]
560560
},
561+
{
562+
"cell_type": "markdown",
563+
"id": "9d7e3e1f",
564+
"metadata": {},
565+
"source": [
566+
"## Data distribution (histogram)"
567+
]
568+
},
561569
{
562570
"cell_type": "code",
563571
"execution_count": null,
564572
"id": "c2de94d3",
565573
"metadata": {},
566574
"outputs": [],
567575
"source": [
568-
"_min_int, _max_int = proteins.min().min(), proteins.max().max()\n",
569-
"bins = range(int(_min_int), int(_max_int) + 1, 1)\n",
570-
"ax = proteins.T.hist(layout=(2, 4), bins=bins, sharex=True, sharey=True, figsize=(8, 4))\n",
571-
"\n",
572576
"min_int, max_int = int(proteins.min().min()), int(proteins.max().max())\n",
573577
"bins = range(min_int, max_int+1, 1)\n",
574578
"ax = proteins.T.hist(layout=(2, 4), bins=bins, sharex=True, sharey=True, figsize=(8, 4))"
575579
]
576580
},
581+
{
582+
"cell_type": "markdown",
583+
"id": "34cba269",
584+
"metadata": {},
585+
"source": [
586+
"## Data distribution (boxplot)"
587+
]
588+
},
577589
{
578590
"cell_type": "code",
579591
"execution_count": null,
@@ -596,7 +608,7 @@
596608
"id": "d39bedbb",
597609
"metadata": {},
598610
"source": [
599-
"# Coefficient of Variation (CV)\n",
611+
"## Coefficient of Variation (CV)\n",
600612
"- CV = standard deviation / mean\n",
601613
" $$ CV = \\frac{\\sigma}{\\mu} $$\n",
602614
"- per group\n",
@@ -687,7 +699,10 @@
687699
"source": [
688700
"# Hierarchical Clustering of normalized data\n",
689701
"- using completely observed data only\n",
690-
"Checkout the [recipe on normalization methods](https://analytics-core.readthedocs.io/latest/api_examples/normalization_analysis.html)."
702+
"Checkout the \n",
703+
"[recipe on normalization methods](https://analytics-core.readthedocs.io/latest/api_examples/normalization_analysis.html).\n",
704+
"\n",
705+
"Let's see the effect of normalization on the clustering."
691706
]
692707
},
693708
{
@@ -1073,7 +1088,7 @@
10731088
" pval_col=\"padj\", # toggle if it does not work\n",
10741089
" correction_alpha=0.2, # adjust the p-value to see more or less results\n",
10751090
")\n",
1076-
"enriched"
1091+
"enriched.set_index('identifiers')"
10771092
]
10781093
},
10791094
{
@@ -1153,7 +1168,9 @@
11531168
" out_dir_subsection / \"1_differently_regulated_as_in_paper.csv\",\n",
11541169
" index=False,\n",
11551170
")\n",
1156-
"view"
1171+
"view.set_index(\"identifier\")[['pvalue', 'log2FC', 'padj', 'rejected', 'mean(group1)', 'mean(group2)',\n",
1172+
" 'std(group1)', 'std(group2)', 'test', 'correction', \n",
1173+
" 'group1', 'group2', 'FC', '-log10 pvalue', 'Method']]"
11571174
]
11581175
},
11591176
{
@@ -1201,10 +1218,9 @@
12011218
"view = view.set_index(\"identifier\").join(proteins_meta.set_index(\"ProteinName\"))\n",
12021219
"view.to_csv(\n",
12031220
" out_dir_subsection / \"2_highlighted_proteins_in_figure3.csv\",\n",
1204-
" index=False,\n",
1221+
" index=True,\n",
12051222
")\n",
12061223
"sel_cols = [\n",
1207-
" \"identifier\",\n",
12081224
" \"GeneName\",\n",
12091225
" \"log2FC\",\n",
12101226
" \"pvalue\",\n",
@@ -1214,7 +1230,7 @@
12141230
" \"group2\",\n",
12151231
" \"Method\",\n",
12161232
"]\n",
1217-
"view.reset_index()[sel_cols].sort_values(\"log2FC\", ascending=False)"
1233+
"view[sel_cols].sort_values(\"log2FC\", ascending=False)"
12181234
]
12191235
},
12201236
{

2_data_analysis.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,22 @@
315315
)
316316

317317
# %% [markdown]
318-
# # Analytical Plots
319-
# - data distribution (e.g. histogram)
318+
# # Quality Control Plots (protein level)
319+
# - data distribution (histogram and boxplot) to identify drift
320320
# - coefficient of variation (CV)
321321
# - number of identified proteins per sample
322322

323-
# %%
324-
_min_int, _max_int = proteins.min().min(), proteins.max().max()
325-
bins = range(int(_min_int), int(_max_int) + 1, 1)
326-
ax = proteins.T.hist(layout=(2, 4), bins=bins, sharex=True, sharey=True, figsize=(8, 4))
323+
# %% [markdown]
324+
# ## Data distribution (histogram)
327325

326+
# %%
328327
min_int, max_int = int(proteins.min().min()), int(proteins.max().max())
329328
bins = range(min_int, max_int+1, 1)
330329
ax = proteins.T.hist(layout=(2, 4), bins=bins, sharex=True, sharey=True, figsize=(8, 4))
331330

331+
# %% [markdown]
332+
# ## Data distribution (boxplot)
333+
332334
# %%
333335
fig, ax = plt.subplots(figsize=(8, 4))
334336
proteins.T.boxplot(ax=ax)
@@ -340,7 +342,7 @@
340342
print(f"Saved boxplot to {fname}")
341343

342344
# %% [markdown]
343-
# # Coefficient of Variation (CV)
345+
# ## Coefficient of Variation (CV)
344346
# - CV = standard deviation / mean
345347
# $$ CV = \frac{\sigma}{\mu} $$
346348
# - per group
@@ -396,7 +398,10 @@
396398
# %% [markdown]
397399
# # Hierarchical Clustering of normalized data
398400
# - using completely observed data only
399-
# Checkout the [recipe on normalization methods](https://analytics-core.readthedocs.io/latest/api_examples/normalization_analysis.html).
401+
# Checkout the
402+
# [recipe on normalization methods](https://analytics-core.readthedocs.io/latest/api_examples/normalization_analysis.html).
403+
#
404+
# Let's see the effect of normalization on the clustering.
400405

401406
# %%
402407
normalization_method = "median"
@@ -617,7 +622,7 @@
617622
pval_col="padj", # toggle if it does not work
618623
correction_alpha=0.2, # adjust the p-value to see more or less results
619624
)
620-
enriched
625+
enriched.set_index('identifiers')
621626

622627
# %% [markdown]
623628
# Plot the enrichment scores for the up- and down-regulated proteins separately.
@@ -657,7 +662,9 @@
657662
out_dir_subsection / "1_differently_regulated_as_in_paper.csv",
658663
index=False,
659664
)
660-
view
665+
view.set_index("identifier")[['pvalue', 'log2FC', 'padj', 'rejected', 'mean(group1)', 'mean(group2)',
666+
'std(group1)', 'std(group2)', 'test', 'correction',
667+
'group1', 'group2', 'FC', '-log10 pvalue', 'Method']]
661668

662669
# %% [markdown]
663670
# Let's find the proteins highlighted in the volcano plot in Figure 3 in the
@@ -678,10 +685,9 @@
678685
view = view.set_index("identifier").join(proteins_meta.set_index("ProteinName"))
679686
view.to_csv(
680687
out_dir_subsection / "2_highlighted_proteins_in_figure3.csv",
681-
index=False,
688+
index=True,
682689
)
683690
sel_cols = [
684-
"identifier",
685691
"GeneName",
686692
"log2FC",
687693
"pvalue",
@@ -691,7 +697,7 @@
691697
"group2",
692698
"Method",
693699
]
694-
view.reset_index()[sel_cols].sort_values("log2FC", ascending=False)
700+
view[sel_cols].sort_values("log2FC", ascending=False)
695701

696702
# %% [markdown]
697703
# - See normalized data.

material/instructions_statistics_PXD04621.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ A deployed version of the report can be accessed online at the following link:
6969

7070
### Download the VueGen HTML report
7171

72-
- [html report](pmultiqc_report/multiqc_report_pmultiqc.html)
72+
- [html report](./streamlit_report/quarto_report_PXD04621.html)
7373

7474
See instructions on [biosustain/dsp_course_proteomics_intro_report](https://github.com/biosustain/dsp_course_proteomics_intro_report).
7575

0 commit comments

Comments
 (0)